import "./chunk-G3PMV62Z.js"; // node_modules/superjson/dist/double-indexed-kv.js var DoubleIndexedKV = class { constructor() { this.keyToValue = /* @__PURE__ */ new Map(); this.valueToKey = /* @__PURE__ */ new Map(); } set(key, value) { this.keyToValue.set(key, value); this.valueToKey.set(value, key); } getByKey(key) { return this.keyToValue.get(key); } getByValue(value) { return this.valueToKey.get(value); } clear() { this.keyToValue.clear(); this.valueToKey.clear(); } }; // node_modules/superjson/dist/registry.js var Registry = class { constructor(generateIdentifier) { this.generateIdentifier = generateIdentifier; this.kv = new DoubleIndexedKV(); } register(value, identifier) { if (this.kv.getByValue(value)) { return; } if (!identifier) { identifier = this.generateIdentifier(value); } this.kv.set(identifier, value); } clear() { this.kv.clear(); } getIdentifier(value) { return this.kv.getByValue(value); } getValue(identifier) { return this.kv.getByKey(identifier); } }; // node_modules/superjson/dist/class-registry.js var ClassRegistry = class extends Registry { constructor() { super((c) => c.name); this.classToAllowedProps = /* @__PURE__ */ new Map(); } register(value, options) { if (typeof options === "object") { if (options.allowProps) { this.classToAllowedProps.set(value, options.allowProps); } super.register(value, options.identifier); } else { super.register(value, options); } } getAllowedProps(value) { return this.classToAllowedProps.get(value); } }; // node_modules/superjson/dist/util.js function valuesOfObj(record) { if ("values" in Object) { return Object.values(record); } const values = []; for (const key in record) { if (record.hasOwnProperty(key)) { values.push(record[key]); } } return values; } function find(record, predicate) { const values = valuesOfObj(record); if ("find" in values) { return values.find(predicate); } const valuesNotNever = values; for (let i = 0; i < valuesNotNever.length; i++) { const value = valuesNotNever[i]; if (predicate(value)) { return value; } } return void 0; } function forEach(record, run) { Object.entries(record).forEach(([key, value]) => run(value, key)); } function includes(arr, value) { return arr.indexOf(value) !== -1; } function findArr(record, predicate) { for (let i = 0; i < record.length; i++) { const value = record[i]; if (predicate(value)) { return value; } } return void 0; } // node_modules/superjson/dist/custom-transformer-registry.js var CustomTransformerRegistry = class { constructor() { this.transfomers = {}; } register(transformer) { this.transfomers[transformer.name] = transformer; } findApplicable(v) { return find(this.transfomers, (transformer) => transformer.isApplicable(v)); } findByName(name) { return this.transfomers[name]; } }; // node_modules/superjson/dist/is.js var getType = (payload) => Object.prototype.toString.call(payload).slice(8, -1); var isUndefined = (payload) => typeof payload === "undefined"; var isNull = (payload) => payload === null; var isPlainObject = (payload) => { if (typeof payload !== "object" || payload === null) return false; if (payload === Object.prototype) return false; if (Object.getPrototypeOf(payload) === null) return true; return Object.getPrototypeOf(payload) === Object.prototype; }; var isEmptyObject = (payload) => isPlainObject(payload) && Object.keys(payload).length === 0; var isArray = (payload) => Array.isArray(payload); var isString = (payload) => typeof payload === "string"; var isNumber = (payload) => typeof payload === "number" && !isNaN(payload); var isBoolean = (payload) => typeof payload === "boolean"; var isRegExp = (payload) => payload instanceof RegExp; var isMap = (payload) => payload instanceof Map; var isSet = (payload) => payload instanceof Set; var isSymbol = (payload) => getType(payload) === "Symbol"; var isDate = (payload) => payload instanceof Date && !isNaN(payload.valueOf()); var isError = (payload) => payload instanceof Error; var isNaNValue = (payload) => typeof payload === "number" && isNaN(payload); var isPrimitive = (payload) => isBoolean(payload) || isNull(payload) || isUndefined(payload) || isNumber(payload) || isString(payload) || isSymbol(payload); var isBigint = (payload) => typeof payload === "bigint"; var isInfinite = (payload) => payload === Infinity || payload === -Infinity; var isTypedArray = (payload) => ArrayBuffer.isView(payload) && !(payload instanceof DataView); var isURL = (payload) => payload instanceof URL; // node_modules/superjson/dist/pathstringifier.js var escapeKey = (key) => key.replace(/\\/g, "\\\\").replace(/\./g, "\\."); var stringifyPath = (path) => path.map(String).map(escapeKey).join("."); var parsePath = (string, legacyPaths) => { const result = []; let segment = ""; for (let i = 0; i < string.length; i++) { let char = string.charAt(i); if (!legacyPaths && char === "\\") { const escaped = string.charAt(i + 1); if (escaped === "\\") { segment += "\\"; i++; continue; } else if (escaped !== ".") { throw Error("invalid path"); } } const isEscapedDot = char === "\\" && string.charAt(i + 1) === "."; if (isEscapedDot) { segment += "."; i++; continue; } const isEndOfSegment = char === "."; if (isEndOfSegment) { result.push(segment); segment = ""; continue; } segment += char; } const lastSegment = segment; result.push(lastSegment); return result; }; // node_modules/superjson/dist/transformer.js function simpleTransformation(isApplicable, annotation, transform, untransform) { return { isApplicable, annotation, transform, untransform }; } var simpleRules = [ simpleTransformation(isUndefined, "undefined", () => null, () => void 0), simpleTransformation(isBigint, "bigint", (v) => v.toString(), (v) => { if (typeof BigInt !== "undefined") { return BigInt(v); } console.error("Please add a BigInt polyfill."); return v; }), simpleTransformation(isDate, "Date", (v) => v.toISOString(), (v) => new Date(v)), simpleTransformation(isError, "Error", (v, superJson) => { const baseError = { name: v.name, message: v.message }; if ("cause" in v) { baseError.cause = v.cause; } superJson.allowedErrorProps.forEach((prop) => { baseError[prop] = v[prop]; }); return baseError; }, (v, superJson) => { const e = new Error(v.message, { cause: v.cause }); e.name = v.name; e.stack = v.stack; superJson.allowedErrorProps.forEach((prop) => { e[prop] = v[prop]; }); return e; }), simpleTransformation(isRegExp, "regexp", (v) => "" + v, (regex) => { const body = regex.slice(1, regex.lastIndexOf("/")); const flags = regex.slice(regex.lastIndexOf("/") + 1); return new RegExp(body, flags); }), simpleTransformation( isSet, "set", // (sets only exist in es6+) // eslint-disable-next-line es5/no-es6-methods (v) => [...v.values()], (v) => new Set(v) ), simpleTransformation(isMap, "map", (v) => [...v.entries()], (v) => new Map(v)), simpleTransformation((v) => isNaNValue(v) || isInfinite(v), "number", (v) => { if (isNaNValue(v)) { return "NaN"; } if (v > 0) { return "Infinity"; } else { return "-Infinity"; } }, Number), simpleTransformation((v) => v === 0 && 1 / v === -Infinity, "number", () => { return "-0"; }, Number), simpleTransformation(isURL, "URL", (v) => v.toString(), (v) => new URL(v)) ]; function compositeTransformation(isApplicable, annotation, transform, untransform) { return { isApplicable, annotation, transform, untransform }; } var symbolRule = compositeTransformation((s, superJson) => { if (isSymbol(s)) { const isRegistered = !!superJson.symbolRegistry.getIdentifier(s); return isRegistered; } return false; }, (s, superJson) => { const identifier = superJson.symbolRegistry.getIdentifier(s); return ["symbol", identifier]; }, (v) => v.description, (_, a, superJson) => { const value = superJson.symbolRegistry.getValue(a[1]); if (!value) { throw new Error("Trying to deserialize unknown symbol"); } return value; }); var constructorToName = [ Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array, Uint8ClampedArray ].reduce((obj, ctor) => { obj[ctor.name] = ctor; return obj; }, {}); var typedArrayRule = compositeTransformation(isTypedArray, (v) => ["typed-array", v.constructor.name], (v) => [...v], (v, a) => { const ctor = constructorToName[a[1]]; if (!ctor) { throw new Error("Trying to deserialize unknown typed array"); } return new ctor(v); }); function isInstanceOfRegisteredClass(potentialClass, superJson) { if (potentialClass?.constructor) { const isRegistered = !!superJson.classRegistry.getIdentifier(potentialClass.constructor); return isRegistered; } return false; } var classRule = compositeTransformation(isInstanceOfRegisteredClass, (clazz, superJson) => { const identifier = superJson.classRegistry.getIdentifier(clazz.constructor); return ["class", identifier]; }, (clazz, superJson) => { const allowedProps = superJson.classRegistry.getAllowedProps(clazz.constructor); if (!allowedProps) { return { ...clazz }; } const result = {}; allowedProps.forEach((prop) => { result[prop] = clazz[prop]; }); return result; }, (v, a, superJson) => { const clazz = superJson.classRegistry.getValue(a[1]); if (!clazz) { throw new Error(`Trying to deserialize unknown class '${a[1]}' - check https://github.com/blitz-js/superjson/issues/116#issuecomment-773996564`); } return Object.assign(Object.create(clazz.prototype), v); }); var customRule = compositeTransformation((value, superJson) => { return !!superJson.customTransformerRegistry.findApplicable(value); }, (value, superJson) => { const transformer = superJson.customTransformerRegistry.findApplicable(value); return ["custom", transformer.name]; }, (value, superJson) => { const transformer = superJson.customTransformerRegistry.findApplicable(value); return transformer.serialize(value); }, (v, a, superJson) => { const transformer = superJson.customTransformerRegistry.findByName(a[1]); if (!transformer) { throw new Error("Trying to deserialize unknown custom value"); } return transformer.deserialize(v); }); var compositeRules = [classRule, symbolRule, customRule, typedArrayRule]; var transformValue = (value, superJson) => { const applicableCompositeRule = findArr(compositeRules, (rule) => rule.isApplicable(value, superJson)); if (applicableCompositeRule) { return { value: applicableCompositeRule.transform(value, superJson), type: applicableCompositeRule.annotation(value, superJson) }; } const applicableSimpleRule = findArr(simpleRules, (rule) => rule.isApplicable(value, superJson)); if (applicableSimpleRule) { return { value: applicableSimpleRule.transform(value, superJson), type: applicableSimpleRule.annotation }; } return void 0; }; var simpleRulesByAnnotation = {}; simpleRules.forEach((rule) => { simpleRulesByAnnotation[rule.annotation] = rule; }); var untransformValue = (json, type, superJson) => { if (isArray(type)) { switch (type[0]) { case "symbol": return symbolRule.untransform(json, type, superJson); case "class": return classRule.untransform(json, type, superJson); case "custom": return customRule.untransform(json, type, superJson); case "typed-array": return typedArrayRule.untransform(json, type, superJson); default: throw new Error("Unknown transformation: " + type); } } else { const transformation = simpleRulesByAnnotation[type]; if (!transformation) { throw new Error("Unknown transformation: " + type); } return transformation.untransform(json, superJson); } }; // node_modules/superjson/dist/accessDeep.js var getNthKey = (value, n) => { if (n > value.size) throw new Error("index out of bounds"); const keys = value.keys(); while (n > 0) { keys.next(); n--; } return keys.next().value; }; function validatePath(path) { if (includes(path, "__proto__")) { throw new Error("__proto__ is not allowed as a property"); } if (includes(path, "prototype")) { throw new Error("prototype is not allowed as a property"); } if (includes(path, "constructor")) { throw new Error("constructor is not allowed as a property"); } } var getDeep = (object, path) => { validatePath(path); for (let i = 0; i < path.length; i++) { const key = path[i]; if (isSet(object)) { object = getNthKey(object, +key); } else if (isMap(object)) { const row = +key; const type = +path[++i] === 0 ? "key" : "value"; const keyOfRow = getNthKey(object, row); switch (type) { case "key": object = keyOfRow; break; case "value": object = object.get(keyOfRow); break; } } else { object = object[key]; } } return object; }; var setDeep = (object, path, mapper) => { validatePath(path); if (path.length === 0) { return mapper(object); } let parent = object; for (let i = 0; i < path.length - 1; i++) { const key = path[i]; if (isArray(parent)) { const index = +key; parent = parent[index]; } else if (isPlainObject(parent)) { parent = parent[key]; } else if (isSet(parent)) { const row = +key; parent = getNthKey(parent, row); } else if (isMap(parent)) { const isEnd = i === path.length - 2; if (isEnd) { break; } const row = +key; const type = +path[++i] === 0 ? "key" : "value"; const keyOfRow = getNthKey(parent, row); switch (type) { case "key": parent = keyOfRow; break; case "value": parent = parent.get(keyOfRow); break; } } } const lastKey = path[path.length - 1]; if (isArray(parent)) { parent[+lastKey] = mapper(parent[+lastKey]); } else if (isPlainObject(parent)) { parent[lastKey] = mapper(parent[lastKey]); } if (isSet(parent)) { const oldValue = getNthKey(parent, +lastKey); const newValue = mapper(oldValue); if (oldValue !== newValue) { parent.delete(oldValue); parent.add(newValue); } } if (isMap(parent)) { const row = +path[path.length - 2]; const keyToRow = getNthKey(parent, row); const type = +lastKey === 0 ? "key" : "value"; switch (type) { case "key": { const newKey = mapper(keyToRow); parent.set(newKey, parent.get(keyToRow)); if (newKey !== keyToRow) { parent.delete(keyToRow); } break; } case "value": { parent.set(keyToRow, mapper(parent.get(keyToRow))); break; } } } return object; }; // node_modules/superjson/dist/plainer.js var enableLegacyPaths = (version) => version < 1; function traverse(tree, walker2, version, origin = []) { if (!tree) { return; } const legacyPaths = enableLegacyPaths(version); if (!isArray(tree)) { forEach(tree, (subtree, key) => traverse(subtree, walker2, version, [ ...origin, ...parsePath(key, legacyPaths) ])); return; } const [nodeValue, children] = tree; if (children) { forEach(children, (child, key) => { traverse(child, walker2, version, [ ...origin, ...parsePath(key, legacyPaths) ]); }); } walker2(nodeValue, origin); } function applyValueAnnotations(plain, annotations, version, superJson) { traverse(annotations, (type, path) => { plain = setDeep(plain, path, (v) => untransformValue(v, type, superJson)); }, version); return plain; } function applyReferentialEqualityAnnotations(plain, annotations, version) { const legacyPaths = enableLegacyPaths(version); function apply(identicalPaths, path) { const object = getDeep(plain, parsePath(path, legacyPaths)); identicalPaths.map((path2) => parsePath(path2, legacyPaths)).forEach((identicalObjectPath) => { plain = setDeep(plain, identicalObjectPath, () => object); }); } if (isArray(annotations)) { const [root, other] = annotations; root.forEach((identicalPath) => { plain = setDeep(plain, parsePath(identicalPath, legacyPaths), () => plain); }); if (other) { forEach(other, apply); } } else { forEach(annotations, apply); } return plain; } var isDeep = (object, superJson) => isPlainObject(object) || isArray(object) || isMap(object) || isSet(object) || isError(object) || isInstanceOfRegisteredClass(object, superJson); function addIdentity(object, path, identities) { const existingSet = identities.get(object); if (existingSet) { existingSet.push(path); } else { identities.set(object, [path]); } } function generateReferentialEqualityAnnotations(identitites, dedupe) { const result = {}; let rootEqualityPaths = void 0; identitites.forEach((paths) => { if (paths.length <= 1) { return; } if (!dedupe) { paths = paths.map((path) => path.map(String)).sort((a, b) => a.length - b.length); } const [representativePath, ...identicalPaths] = paths; if (representativePath.length === 0) { rootEqualityPaths = identicalPaths.map(stringifyPath); } else { result[stringifyPath(representativePath)] = identicalPaths.map(stringifyPath); } }); if (rootEqualityPaths) { if (isEmptyObject(result)) { return [rootEqualityPaths]; } else { return [rootEqualityPaths, result]; } } else { return isEmptyObject(result) ? void 0 : result; } } var walker = (object, identities, superJson, dedupe, path = [], objectsInThisPath = [], seenObjects = /* @__PURE__ */ new Map()) => { const primitive = isPrimitive(object); if (!primitive) { addIdentity(object, path, identities); const seen = seenObjects.get(object); if (seen) { return dedupe ? { transformedValue: null } : seen; } } if (!isDeep(object, superJson)) { const transformed2 = transformValue(object, superJson); const result2 = transformed2 ? { transformedValue: transformed2.value, annotations: [transformed2.type] } : { transformedValue: object }; if (!primitive) { seenObjects.set(object, result2); } return result2; } if (includes(objectsInThisPath, object)) { return { transformedValue: null }; } const transformationResult = transformValue(object, superJson); const transformed = transformationResult?.value ?? object; const transformedValue = isArray(transformed) ? [] : {}; const innerAnnotations = {}; forEach(transformed, (value, index) => { if (index === "__proto__" || index === "constructor" || index === "prototype") { throw new Error(`Detected property ${index}. This is a prototype pollution risk, please remove it from your object.`); } const recursiveResult = walker(value, identities, superJson, dedupe, [...path, index], [...objectsInThisPath, object], seenObjects); transformedValue[index] = recursiveResult.transformedValue; if (isArray(recursiveResult.annotations)) { innerAnnotations[escapeKey(index)] = recursiveResult.annotations; } else if (isPlainObject(recursiveResult.annotations)) { forEach(recursiveResult.annotations, (tree, key) => { innerAnnotations[escapeKey(index) + "." + key] = tree; }); } }); const result = isEmptyObject(innerAnnotations) ? { transformedValue, annotations: !!transformationResult ? [transformationResult.type] : void 0 } : { transformedValue, annotations: !!transformationResult ? [transformationResult.type, innerAnnotations] : innerAnnotations }; if (!primitive) { seenObjects.set(object, result); } return result; }; // node_modules/is-what/dist/getType.js function getType2(payload) { return Object.prototype.toString.call(payload).slice(8, -1); } // node_modules/is-what/dist/isArray.js function isArray2(payload) { return getType2(payload) === "Array"; } // node_modules/is-what/dist/isPlainObject.js function isPlainObject2(payload) { if (getType2(payload) !== "Object") return false; const prototype = Object.getPrototypeOf(payload); return !!prototype && prototype.constructor === Object && prototype === Object.prototype; } // node_modules/is-what/dist/isNull.js function isNull2(payload) { return getType2(payload) === "Null"; } // node_modules/is-what/dist/isOneOf.js function isOneOf(a, b, c, d, e) { return (value) => a(value) || b(value) || !!c && c(value) || !!d && d(value) || !!e && e(value); } // node_modules/is-what/dist/isUndefined.js function isUndefined2(payload) { return getType2(payload) === "Undefined"; } // node_modules/is-what/dist/isNullOrUndefined.js var isNullOrUndefined = isOneOf(isNull2, isUndefined2); // node_modules/copy-anything/dist/index.js function assignProp(carry, key, newVal, originalObject, includeNonenumerable) { const propType = {}.propertyIsEnumerable.call(originalObject, key) ? "enumerable" : "nonenumerable"; if (propType === "enumerable") carry[key] = newVal; if (includeNonenumerable && propType === "nonenumerable") { Object.defineProperty(carry, key, { value: newVal, enumerable: false, writable: true, configurable: true }); } } function copy(target, options = {}) { if (isArray2(target)) { return target.map((item) => copy(item, options)); } if (!isPlainObject2(target)) { return target; } const props = Object.getOwnPropertyNames(target); const symbols = Object.getOwnPropertySymbols(target); return [...props, ...symbols].reduce((carry, key) => { if (key === "__proto__") return carry; if (isArray2(options.props) && !options.props.includes(key)) { return carry; } const val = target[key]; const newVal = copy(val, options); assignProp(carry, key, newVal, target, options.nonenumerable); return carry; }, {}); } // node_modules/superjson/dist/index.js var SuperJSON = class { /** * @param dedupeReferentialEqualities If true, SuperJSON will make sure only one instance of referentially equal objects are serialized and the rest are replaced with `null`. */ constructor({ dedupe = false } = {}) { this.classRegistry = new ClassRegistry(); this.symbolRegistry = new Registry((s) => s.description ?? ""); this.customTransformerRegistry = new CustomTransformerRegistry(); this.allowedErrorProps = []; this.dedupe = dedupe; } serialize(object) { const identities = /* @__PURE__ */ new Map(); const output = walker(object, identities, this, this.dedupe); const res = { json: output.transformedValue }; if (output.annotations) { res.meta = { ...res.meta, values: output.annotations }; } const equalityAnnotations = generateReferentialEqualityAnnotations(identities, this.dedupe); if (equalityAnnotations) { res.meta = { ...res.meta, referentialEqualities: equalityAnnotations }; } if (res.meta) res.meta.v = 1; return res; } deserialize(payload, options) { const { json, meta } = payload; let result = options?.inPlace ? json : copy(json); if (meta?.values) { result = applyValueAnnotations(result, meta.values, meta.v ?? 0, this); } if (meta?.referentialEqualities) { result = applyReferentialEqualityAnnotations(result, meta.referentialEqualities, meta.v ?? 0); } return result; } stringify(object) { return JSON.stringify(this.serialize(object)); } parse(string) { return this.deserialize(JSON.parse(string), { inPlace: true }); } registerClass(v, options) { this.classRegistry.register(v, options); } registerSymbol(v, identifier) { this.symbolRegistry.register(v, identifier); } registerCustom(transformer, name) { this.customTransformerRegistry.register({ name, ...transformer }); } allowErrorProps(...props) { this.allowedErrorProps.push(...props); } }; SuperJSON.defaultInstance = new SuperJSON(); SuperJSON.serialize = SuperJSON.defaultInstance.serialize.bind(SuperJSON.defaultInstance); SuperJSON.deserialize = SuperJSON.defaultInstance.deserialize.bind(SuperJSON.defaultInstance); SuperJSON.stringify = SuperJSON.defaultInstance.stringify.bind(SuperJSON.defaultInstance); SuperJSON.parse = SuperJSON.defaultInstance.parse.bind(SuperJSON.defaultInstance); SuperJSON.registerClass = SuperJSON.defaultInstance.registerClass.bind(SuperJSON.defaultInstance); SuperJSON.registerSymbol = SuperJSON.defaultInstance.registerSymbol.bind(SuperJSON.defaultInstance); SuperJSON.registerCustom = SuperJSON.defaultInstance.registerCustom.bind(SuperJSON.defaultInstance); SuperJSON.allowErrorProps = SuperJSON.defaultInstance.allowErrorProps.bind(SuperJSON.defaultInstance); var dist_default = SuperJSON; var serialize = SuperJSON.serialize; var deserialize = SuperJSON.deserialize; var stringify = SuperJSON.stringify; var parse = SuperJSON.parse; var registerClass = SuperJSON.registerClass; var registerCustom = SuperJSON.registerCustom; var registerSymbol = SuperJSON.registerSymbol; var allowErrorProps = SuperJSON.allowErrorProps; export { SuperJSON, allowErrorProps, dist_default as default, deserialize, parse, registerClass, registerCustom, registerSymbol, serialize, stringify }; //# sourceMappingURL=superjson.js.map