barebones docker | pocketbase | hono | svelte
This commit is contained in:
@@ -0,0 +1,714 @@
|
||||
import { a as is_plain_object$1, c as is_valid_array_len, d as valid_array_indices, f as MAX_ARRAY_INDEX, i as get_type, l as stringify_key, n as DevalueError, o as is_primitive, r as enumerable_symbols, s as is_valid_array_index, u as stringify_string } from "./uneval.js";
|
||||
import { HttpError, SvelteKitError } from "@sveltejs/kit/internal";
|
||||
//#region ../node_modules/.pnpm/@sveltejs+kit@3.0.0-next.4_@sveltejs+vite-plugin-svelte@7.1.2_svelte@5.56.3_vite@8.0.16_831df308509456bf75377b19fdb5b8d4/node_modules/@sveltejs/kit/src/utils/functions.js
|
||||
function noop() {}
|
||||
/**
|
||||
* @template T
|
||||
* @param {() => T} fn
|
||||
*/
|
||||
function once(fn) {
|
||||
let done = false;
|
||||
/** @type T */
|
||||
let result;
|
||||
return () => {
|
||||
if (done) return result;
|
||||
done = true;
|
||||
return result = fn();
|
||||
};
|
||||
}
|
||||
//#endregion
|
||||
//#region ../node_modules/.pnpm/devalue@5.8.1/node_modules/devalue/src/base64.js
|
||||
/** @type {(array_buffer: ArrayBuffer) => string} */
|
||||
function encode_native(array_buffer) {
|
||||
return new Uint8Array(array_buffer).toBase64();
|
||||
}
|
||||
/** @type {(base64: string) => ArrayBuffer} */
|
||||
function decode_native(base64) {
|
||||
return Uint8Array.fromBase64(base64).buffer;
|
||||
}
|
||||
/** @type {(array_buffer: ArrayBuffer) => string} */
|
||||
function encode_buffer(array_buffer) {
|
||||
return Buffer.from(array_buffer).toString("base64");
|
||||
}
|
||||
/** @type {(base64: string) => ArrayBuffer} */
|
||||
function decode_buffer(base64) {
|
||||
return Uint8Array.from(Buffer.from(base64, "base64")).buffer;
|
||||
}
|
||||
/** @type {(array_buffer: ArrayBuffer) => string} */
|
||||
function encode_legacy(array_buffer) {
|
||||
const array = new Uint8Array(array_buffer);
|
||||
let binary = "";
|
||||
const chunk_size = 32768;
|
||||
for (let i = 0; i < array.length; i += chunk_size) {
|
||||
const chunk = array.subarray(i, i + chunk_size);
|
||||
binary += String.fromCharCode.apply(null, chunk);
|
||||
}
|
||||
return btoa(binary);
|
||||
}
|
||||
/** @type {(base64: string) => ArrayBuffer} */
|
||||
function decode_legacy(base64) {
|
||||
const binary_string = atob(base64);
|
||||
const len = binary_string.length;
|
||||
const array = new Uint8Array(len);
|
||||
for (let i = 0; i < len; i++) array[i] = binary_string.charCodeAt(i);
|
||||
return array.buffer;
|
||||
}
|
||||
var native = typeof Uint8Array.fromBase64 === "function";
|
||||
var buffer = typeof process === "object" && process.versions?.node !== void 0;
|
||||
var encode64 = native ? encode_native : buffer ? encode_buffer : encode_legacy;
|
||||
var decode64 = native ? decode_native : buffer ? decode_buffer : decode_legacy;
|
||||
//#endregion
|
||||
//#region ../node_modules/.pnpm/devalue@5.8.1/node_modules/devalue/src/parse.js
|
||||
/**
|
||||
* Revive a value serialized with `devalue.stringify`
|
||||
* @param {string} serialized
|
||||
* @param {Record<string, (value: any) => any>} [revivers]
|
||||
*/
|
||||
function parse(serialized, revivers) {
|
||||
return unflatten(JSON.parse(serialized), revivers);
|
||||
}
|
||||
/**
|
||||
* Revive a value flattened with `devalue.stringify`
|
||||
* @param {number | any[]} parsed
|
||||
* @param {Record<string, (value: any) => any>} [revivers]
|
||||
*/
|
||||
function unflatten(parsed, revivers) {
|
||||
if (typeof parsed === "number") return hydrate(parsed, true);
|
||||
if (!Array.isArray(parsed) || parsed.length === 0) throw new Error("Invalid input");
|
||||
const values = parsed;
|
||||
const hydrated = Array(values.length);
|
||||
/**
|
||||
* A set of values currently being hydrated with custom revivers,
|
||||
* used to detect invalid cyclical dependencies
|
||||
* @type {Set<number> | null}
|
||||
*/
|
||||
let hydrating = null;
|
||||
/**
|
||||
* @param {number} index
|
||||
* @returns {any}
|
||||
*/
|
||||
function hydrate(index, standalone = false) {
|
||||
if (index === -1) return void 0;
|
||||
if (index === -3) return NaN;
|
||||
if (index === -4) return Infinity;
|
||||
if (index === -5) return -Infinity;
|
||||
if (index === -6) return -0;
|
||||
if (standalone || typeof index !== "number") throw new Error(`Invalid input`);
|
||||
if (index in hydrated) return hydrated[index];
|
||||
const value = values[index];
|
||||
if (!value || typeof value !== "object") hydrated[index] = value;
|
||||
else if (Array.isArray(value)) if (typeof value[0] === "string") {
|
||||
const type = value[0];
|
||||
const reviver = revivers && Object.hasOwn(revivers, type) ? revivers[type] : void 0;
|
||||
if (reviver) {
|
||||
let i = value[1];
|
||||
if (typeof i !== "number") i = values.push(value[1]) - 1;
|
||||
hydrating ??= /* @__PURE__ */ new Set();
|
||||
if (hydrating.has(i)) throw new Error("Invalid circular reference");
|
||||
hydrating.add(i);
|
||||
hydrated[index] = reviver(hydrate(i));
|
||||
hydrating.delete(i);
|
||||
return hydrated[index];
|
||||
}
|
||||
switch (type) {
|
||||
case "Date":
|
||||
hydrated[index] = new Date(value[1]);
|
||||
break;
|
||||
case "Set":
|
||||
const set = /* @__PURE__ */ new Set();
|
||||
hydrated[index] = set;
|
||||
for (let i = 1; i < value.length; i += 1) set.add(hydrate(value[i]));
|
||||
break;
|
||||
case "Map":
|
||||
const map = /* @__PURE__ */ new Map();
|
||||
hydrated[index] = map;
|
||||
for (let i = 1; i < value.length; i += 2) map.set(hydrate(value[i]), hydrate(value[i + 1]));
|
||||
break;
|
||||
case "RegExp":
|
||||
hydrated[index] = new RegExp(value[1], value[2]);
|
||||
break;
|
||||
case "Object": {
|
||||
const wrapped_index = value[1];
|
||||
if (typeof values[wrapped_index] === "object" && values[wrapped_index][0] !== "BigInt") throw new Error("Invalid input");
|
||||
hydrated[index] = Object(hydrate(wrapped_index));
|
||||
break;
|
||||
}
|
||||
case "BigInt":
|
||||
hydrated[index] = BigInt(value[1]);
|
||||
break;
|
||||
case "null":
|
||||
const obj = Object.create(null);
|
||||
hydrated[index] = obj;
|
||||
for (let i = 1; i < value.length; i += 2) {
|
||||
if (value[i] === "__proto__") throw new Error("Cannot parse an object with a `__proto__` property");
|
||||
obj[value[i]] = hydrate(value[i + 1]);
|
||||
}
|
||||
break;
|
||||
case "Int8Array":
|
||||
case "Uint8Array":
|
||||
case "Uint8ClampedArray":
|
||||
case "Int16Array":
|
||||
case "Uint16Array":
|
||||
case "Float16Array":
|
||||
case "Int32Array":
|
||||
case "Uint32Array":
|
||||
case "Float32Array":
|
||||
case "Float64Array":
|
||||
case "BigInt64Array":
|
||||
case "BigUint64Array":
|
||||
case "DataView": {
|
||||
if (values[value[1]][0] !== "ArrayBuffer") throw new Error("Invalid data");
|
||||
const TypedArrayConstructor = globalThis[type];
|
||||
const buffer = hydrate(value[1]);
|
||||
hydrated[index] = value[2] !== void 0 ? new TypedArrayConstructor(buffer, value[2], value[3]) : new TypedArrayConstructor(buffer);
|
||||
break;
|
||||
}
|
||||
case "ArrayBuffer": {
|
||||
const base64 = value[1];
|
||||
if (typeof base64 !== "string") throw new Error("Invalid ArrayBuffer encoding");
|
||||
hydrated[index] = decode64(base64);
|
||||
break;
|
||||
}
|
||||
case "Temporal.Duration":
|
||||
case "Temporal.Instant":
|
||||
case "Temporal.PlainDate":
|
||||
case "Temporal.PlainTime":
|
||||
case "Temporal.PlainDateTime":
|
||||
case "Temporal.PlainMonthDay":
|
||||
case "Temporal.PlainYearMonth":
|
||||
case "Temporal.ZonedDateTime": {
|
||||
const temporalName = type.slice(9);
|
||||
hydrated[index] = Temporal[temporalName].from(value[1]);
|
||||
break;
|
||||
}
|
||||
case "URL":
|
||||
hydrated[index] = new URL(value[1]);
|
||||
break;
|
||||
case "URLSearchParams":
|
||||
hydrated[index] = new URLSearchParams(value[1]);
|
||||
break;
|
||||
default: throw new Error(`Unknown type ${type}`);
|
||||
}
|
||||
} else if (value[0] === -7) {
|
||||
const len = value[1];
|
||||
if (!is_valid_array_len(len)) throw new Error("Invalid input");
|
||||
/** @type {any[]} */
|
||||
const array = [];
|
||||
hydrated[index] = array;
|
||||
array[MAX_ARRAY_INDEX] = void 0;
|
||||
delete array[MAX_ARRAY_INDEX];
|
||||
for (let i = 2; i < value.length; i += 2) {
|
||||
const idx = value[i];
|
||||
if (!is_valid_array_index(idx) || idx >= len) throw new Error("Invalid input");
|
||||
array[idx] = hydrate(value[i + 1]);
|
||||
}
|
||||
array.length = len;
|
||||
} else {
|
||||
const array = new Array(value.length);
|
||||
hydrated[index] = array;
|
||||
for (let i = 0; i < value.length; i += 1) {
|
||||
const n = value[i];
|
||||
if (n === -2) continue;
|
||||
array[i] = hydrate(n);
|
||||
}
|
||||
}
|
||||
else {
|
||||
/** @type {Record<string, any>} */
|
||||
const object = {};
|
||||
hydrated[index] = object;
|
||||
for (const key of Object.keys(value)) {
|
||||
if (key === "__proto__") throw new Error("Cannot parse an object with a `__proto__` property");
|
||||
const n = value[key];
|
||||
object[key] = hydrate(n);
|
||||
}
|
||||
}
|
||||
return hydrated[index];
|
||||
}
|
||||
return hydrate(0);
|
||||
}
|
||||
//#endregion
|
||||
//#region ../node_modules/.pnpm/devalue@5.8.1/node_modules/devalue/src/stringify.js
|
||||
/**
|
||||
* Turn a value into a JSON string that can be parsed with `devalue.parse`
|
||||
* @param {any} value
|
||||
* @param {Record<string, (value: any) => any>} [reducers]
|
||||
*/
|
||||
function stringify$1(value, reducers) {
|
||||
const stringified = run(false, value, reducers);
|
||||
return typeof stringified === "string" ? stringified : `[${stringified.join(",")}]`;
|
||||
}
|
||||
/**
|
||||
* @param {boolean} async
|
||||
* @param {any} value
|
||||
* @param {Record<string, (value: any) => any>} [reducers]
|
||||
*/
|
||||
function run(async, value, reducers) {
|
||||
/** @type {any[]} */
|
||||
const stringified = [];
|
||||
/** @type {Map<any, number>} */
|
||||
const indexes = /* @__PURE__ */ new Map();
|
||||
/** @type {Array<{ key: string, fn: (value: any) => any }>} */
|
||||
const custom = [];
|
||||
if (reducers) for (const key of Object.getOwnPropertyNames(reducers)) custom.push({
|
||||
key,
|
||||
fn: reducers[key]
|
||||
});
|
||||
/** @type {string[]} */
|
||||
const keys = [];
|
||||
let p = 0;
|
||||
/**
|
||||
* @param {any} thing
|
||||
* @param {number} [index]
|
||||
*/
|
||||
function flatten(thing, index) {
|
||||
if (thing === void 0) return -1;
|
||||
if (Number.isNaN(thing)) return -3;
|
||||
if (thing === Infinity) return -4;
|
||||
if (thing === -Infinity) return -5;
|
||||
if (thing === 0 && 1 / thing < 0) return -6;
|
||||
if (indexes.has(thing)) return indexes.get(thing);
|
||||
index ??= p++;
|
||||
indexes.set(thing, index);
|
||||
for (const { key, fn } of custom) {
|
||||
const value = fn(thing);
|
||||
if (value) {
|
||||
stringified[index] = `["${key}",${flatten(value)}]`;
|
||||
return index;
|
||||
}
|
||||
}
|
||||
if (typeof thing === "function") throw new DevalueError(`Cannot stringify a function`, keys, thing, value);
|
||||
else if (typeof thing === "symbol") throw new DevalueError(`Cannot stringify a Symbol primitive`, keys, thing, value);
|
||||
/** @type {string | Promise<any>} */
|
||||
let str = "";
|
||||
if (is_primitive(thing)) str = stringify_primitive(thing);
|
||||
else if (typeof thing.then === "function") {
|
||||
if (!async) throw new DevalueError(`Cannot stringify a Promise or thenable — use stringifyAsync instead`, keys, thing, value);
|
||||
str = Promise.resolve(thing).then((value) => {
|
||||
const i = flatten(value, index);
|
||||
if (i < 0) stringified[index] = i;
|
||||
});
|
||||
} else {
|
||||
const type = get_type(thing);
|
||||
switch (type) {
|
||||
case "Number":
|
||||
case "String":
|
||||
case "Boolean":
|
||||
case "BigInt":
|
||||
str = `["Object",${flatten(thing.valueOf())}]`;
|
||||
break;
|
||||
case "Date":
|
||||
str = `["Date","${!isNaN(thing.getDate()) ? thing.toISOString() : ""}"]`;
|
||||
break;
|
||||
case "URL":
|
||||
str = `["URL",${stringify_string(thing.toString())}]`;
|
||||
break;
|
||||
case "URLSearchParams":
|
||||
str = `["URLSearchParams",${stringify_string(thing.toString())}]`;
|
||||
break;
|
||||
case "RegExp":
|
||||
const { source, flags } = thing;
|
||||
str = flags ? `["RegExp",${stringify_string(source)},"${flags}"]` : `["RegExp",${stringify_string(source)}]`;
|
||||
break;
|
||||
case "Array": {
|
||||
let mostly_dense = false;
|
||||
str = "[";
|
||||
for (let i = 0; i < thing.length; i += 1) {
|
||||
if (i > 0) str += ",";
|
||||
if (Object.hasOwn(thing, i)) {
|
||||
keys.push(`[${i}]`);
|
||||
str += flatten(thing[i]);
|
||||
keys.pop();
|
||||
} else if (mostly_dense) str += -2;
|
||||
else {
|
||||
const populated_keys = valid_array_indices(thing);
|
||||
const population = populated_keys.length;
|
||||
const d = String(thing.length).length;
|
||||
if ((thing.length - population) * 3 > 4 + d + population * (d + 1)) {
|
||||
str = "[-7," + thing.length;
|
||||
for (let j = 0; j < populated_keys.length; j++) {
|
||||
const key = populated_keys[j];
|
||||
keys.push(`[${key}]`);
|
||||
str += "," + key + "," + flatten(thing[key]);
|
||||
keys.pop();
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
mostly_dense = true;
|
||||
str += -2;
|
||||
}
|
||||
}
|
||||
}
|
||||
str += "]";
|
||||
break;
|
||||
}
|
||||
case "Set":
|
||||
str = "[\"Set\"";
|
||||
for (const value of thing) str += `,${flatten(value)}`;
|
||||
str += "]";
|
||||
break;
|
||||
case "Map":
|
||||
str = "[\"Map\"";
|
||||
for (const [key, value] of thing) {
|
||||
keys.push(`.get(${is_primitive(key) ? stringify_primitive(key) : "..."})`);
|
||||
str += `,${flatten(key)},${flatten(value)}`;
|
||||
keys.pop();
|
||||
}
|
||||
str += "]";
|
||||
break;
|
||||
case "Int8Array":
|
||||
case "Uint8Array":
|
||||
case "Uint8ClampedArray":
|
||||
case "Int16Array":
|
||||
case "Uint16Array":
|
||||
case "Float16Array":
|
||||
case "Int32Array":
|
||||
case "Uint32Array":
|
||||
case "Float32Array":
|
||||
case "Float64Array":
|
||||
case "BigInt64Array":
|
||||
case "BigUint64Array":
|
||||
case "DataView": {
|
||||
/** @type {import("./types.js").TypedArray} */
|
||||
const typedArray = thing;
|
||||
str = "[\"" + type + "\"," + flatten(typedArray.buffer);
|
||||
if (typedArray.byteLength !== typedArray.buffer.byteLength) str += `,${typedArray.byteOffset},${typedArray.length}`;
|
||||
str += "]";
|
||||
break;
|
||||
}
|
||||
case "ArrayBuffer":
|
||||
str = `["ArrayBuffer","${encode64(thing)}"]`;
|
||||
break;
|
||||
case "Temporal.Duration":
|
||||
case "Temporal.Instant":
|
||||
case "Temporal.PlainDate":
|
||||
case "Temporal.PlainTime":
|
||||
case "Temporal.PlainDateTime":
|
||||
case "Temporal.PlainMonthDay":
|
||||
case "Temporal.PlainYearMonth":
|
||||
case "Temporal.ZonedDateTime":
|
||||
str = `["${type}",${stringify_string(thing.toString())}]`;
|
||||
break;
|
||||
default:
|
||||
if (!is_plain_object$1(thing)) throw new DevalueError(`Cannot stringify arbitrary non-POJOs`, keys, thing, value);
|
||||
if (enumerable_symbols(thing).length > 0) throw new DevalueError(`Cannot stringify POJOs with symbolic keys`, keys, thing, value);
|
||||
if (Object.getPrototypeOf(thing) === null) {
|
||||
str = "[\"null\"";
|
||||
for (const key of Object.keys(thing)) {
|
||||
if (key === "__proto__") throw new DevalueError(`Cannot stringify objects with __proto__ keys`, keys, thing, value);
|
||||
keys.push(stringify_key(key));
|
||||
str += `,${stringify_string(key)},${flatten(thing[key])}`;
|
||||
keys.pop();
|
||||
}
|
||||
str += "]";
|
||||
} else {
|
||||
str = "{";
|
||||
let started = false;
|
||||
for (const key of Object.keys(thing)) {
|
||||
if (key === "__proto__") throw new DevalueError(`Cannot stringify objects with __proto__ keys`, keys, thing, value);
|
||||
if (started) str += ",";
|
||||
started = true;
|
||||
keys.push(stringify_key(key));
|
||||
str += `${stringify_string(key)}:${flatten(thing[key])}`;
|
||||
keys.pop();
|
||||
}
|
||||
str += "}";
|
||||
}
|
||||
}
|
||||
}
|
||||
stringified[index] = str;
|
||||
return index;
|
||||
}
|
||||
const index = flatten(value);
|
||||
if (index < 0) return `${index}`;
|
||||
return stringified;
|
||||
}
|
||||
/**
|
||||
* @param {any} thing
|
||||
* @returns {string}
|
||||
*/
|
||||
function stringify_primitive(thing) {
|
||||
const type = typeof thing;
|
||||
if (type === "string") return stringify_string(thing);
|
||||
if (thing === void 0) return (-1).toString();
|
||||
if (thing === 0 && 1 / thing < 0) return (-6).toString();
|
||||
if (type === "bigint") return `["BigInt","${thing}"]`;
|
||||
return String(thing);
|
||||
}
|
||||
//#endregion
|
||||
//#region ../node_modules/.pnpm/@sveltejs+kit@3.0.0-next.4_@sveltejs+vite-plugin-svelte@7.1.2_svelte@5.56.3_vite@8.0.16_831df308509456bf75377b19fdb5b8d4/node_modules/@sveltejs/kit/src/runtime/utils.js
|
||||
var text_encoder = new TextEncoder();
|
||||
/**
|
||||
* Like node's path.relative, but without using node
|
||||
* @param {string} from
|
||||
* @param {string} to
|
||||
*/
|
||||
function get_relative_path(from, to) {
|
||||
const from_parts = from.split(/[/\\]/);
|
||||
const to_parts = to.split(/[/\\]/);
|
||||
from_parts.pop();
|
||||
while (from_parts[0] === to_parts[0]) {
|
||||
from_parts.shift();
|
||||
to_parts.shift();
|
||||
}
|
||||
let i = from_parts.length;
|
||||
while (i--) from_parts[i] = "..";
|
||||
return from_parts.concat(to_parts).join("/");
|
||||
}
|
||||
/**
|
||||
* @param {Uint8Array} bytes
|
||||
* @returns {string}
|
||||
*/
|
||||
function base64_encode(bytes) {
|
||||
if (globalThis.Buffer) return globalThis.Buffer.from(bytes).toString("base64");
|
||||
let binary = "";
|
||||
for (let i = 0; i < bytes.length; i++) binary += String.fromCharCode(bytes[i]);
|
||||
return btoa(binary);
|
||||
}
|
||||
/**
|
||||
* @param {string} encoded
|
||||
* @returns {Uint8Array}
|
||||
*/
|
||||
function base64_decode(encoded) {
|
||||
if (globalThis.Buffer) {
|
||||
const buffer = globalThis.Buffer.from(encoded, "base64");
|
||||
return new Uint8Array(buffer);
|
||||
}
|
||||
const binary = atob(encoded);
|
||||
const bytes = new Uint8Array(binary.length);
|
||||
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
|
||||
return bytes;
|
||||
}
|
||||
//#endregion
|
||||
//#region ../node_modules/.pnpm/@sveltejs+kit@3.0.0-next.4_@sveltejs+vite-plugin-svelte@7.1.2_svelte@5.56.3_vite@8.0.16_831df308509456bf75377b19fdb5b8d4/node_modules/@sveltejs/kit/src/utils/error.js
|
||||
/**
|
||||
* @param {unknown} err
|
||||
* @return {Error}
|
||||
*/
|
||||
function coalesce_to_error(err) {
|
||||
return err instanceof Error || err && err.name && err.message ? err : new Error(JSON.stringify(err));
|
||||
}
|
||||
/**
|
||||
* This is an identity function that exists to make TypeScript less
|
||||
* paranoid about people throwing things that aren't errors, which
|
||||
* frankly is not something we should care about
|
||||
* @param {unknown} error
|
||||
*/
|
||||
function normalize_error(error) {
|
||||
return error;
|
||||
}
|
||||
/**
|
||||
* @param {unknown} error
|
||||
*/
|
||||
function get_status(error) {
|
||||
return error instanceof HttpError || error instanceof SvelteKitError ? error.status : 500;
|
||||
}
|
||||
/**
|
||||
* @param {unknown} error
|
||||
*/
|
||||
function get_message(error) {
|
||||
return error instanceof SvelteKitError ? error.text : "Internal Error";
|
||||
}
|
||||
//#endregion
|
||||
//#region ../node_modules/.pnpm/@sveltejs+kit@3.0.0-next.4_@sveltejs+vite-plugin-svelte@7.1.2_svelte@5.56.3_vite@8.0.16_831df308509456bf75377b19fdb5b8d4/node_modules/@sveltejs/kit/src/runtime/shared.js
|
||||
/** @import { Transport } from '@sveltejs/kit' */
|
||||
/**
|
||||
* @param {string} route_id
|
||||
* @param {string} dep
|
||||
*/
|
||||
function validate_depends(route_id, dep) {
|
||||
const match = /^(moz-icon|view-source|jar):/.exec(dep);
|
||||
if (match) console.warn(`${route_id}: Calling \`depends('${dep}')\` will throw an error in Firefox because \`${match[1]}\` is a special URI scheme`);
|
||||
}
|
||||
var INVALIDATED_PARAM = "x-sveltekit-invalidated";
|
||||
var TRAILING_SLASH_PARAM = "x-sveltekit-trailing-slash";
|
||||
/**
|
||||
* @param {any} data
|
||||
* @param {string} [location_description]
|
||||
*/
|
||||
function validate_load_response(data, location_description) {
|
||||
if (data != null && Object.getPrototypeOf(data) !== Object.prototype) throw new Error(`a load function ${location_description} returned ${typeof data !== "object" ? `a ${typeof data}` : data instanceof Response ? "a Response object" : Array.isArray(data) ? "an array" : "a non-plain object"}, but must return a plain object at the top level (i.e. \`return {...}\`)`);
|
||||
}
|
||||
/**
|
||||
* Try to `devalue.stringify` the data object using the provided transport encoders.
|
||||
* @param {any} data
|
||||
* @param {Transport} transport
|
||||
*/
|
||||
function stringify(data, transport) {
|
||||
return stringify$1(data, Object.fromEntries(Object.entries(transport).map(([k, v]) => [k, v.encode])));
|
||||
}
|
||||
var object_proto_names = /* @__PURE__ */ Object.getOwnPropertyNames(Object.prototype).sort().join("\0");
|
||||
/**
|
||||
* @param {unknown} thing
|
||||
* @returns {thing is Record<PropertyKey, unknown>}
|
||||
*/
|
||||
function is_plain_object(thing) {
|
||||
if (typeof thing !== "object" || thing === null) return false;
|
||||
const proto = Object.getPrototypeOf(thing);
|
||||
return proto === Object.prototype || proto === null || Object.getPrototypeOf(proto) === null || Object.getOwnPropertyNames(proto).sort().join("\0") === object_proto_names;
|
||||
}
|
||||
/**
|
||||
* @param {Record<string, any>} value
|
||||
* @param {Map<object, any>} clones
|
||||
*/
|
||||
function to_sorted(value, clones) {
|
||||
const clone = Object.getPrototypeOf(value) === null ? Object.create(null) : {};
|
||||
clones.set(value, clone);
|
||||
Object.defineProperty(clone, remote_arg_marker, { value: true });
|
||||
for (const key of Object.keys(value).sort()) {
|
||||
const property = value[key];
|
||||
Object.defineProperty(clone, key, {
|
||||
value: clones.get(property) ?? property,
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
writable: true
|
||||
});
|
||||
}
|
||||
return clone;
|
||||
}
|
||||
var remote_object = "__skrao";
|
||||
var remote_map = "__skram";
|
||||
var remote_set = "__skras";
|
||||
var remote_file = "__skraf";
|
||||
var remote_regex_guard = "__skrag";
|
||||
var remote_arg_marker = Symbol(remote_object);
|
||||
/**
|
||||
* @param {Transport} transport
|
||||
* @param {boolean} sort
|
||||
* @param {Map<any, any>} remote_arg_clones
|
||||
*/
|
||||
function create_remote_arg_reducers(transport, sort, remote_arg_clones) {
|
||||
/** @type {Record<string, (value: unknown) => unknown>} */
|
||||
const remote_fns_reducers = {
|
||||
/** @param {unknown} value */
|
||||
[remote_regex_guard]: (value) => {
|
||||
if (value instanceof RegExp) throw new Error("Regular expressions are not valid remote function arguments");
|
||||
} };
|
||||
if (sort) {
|
||||
/** @type {(value: unknown) => Array<[unknown, unknown]> | undefined} */
|
||||
remote_fns_reducers[remote_map] = (value) => {
|
||||
if (!(value instanceof Map)) return;
|
||||
/** @type {Array<[string, string]>} */
|
||||
const entries = [];
|
||||
for (const [key, val] of value) entries.push([stringify(key), stringify(val)]);
|
||||
return entries.sort(([a1, a2], [b1, b2]) => {
|
||||
if (a1 < b1) return -1;
|
||||
if (a1 > b1) return 1;
|
||||
if (a2 < b2) return -1;
|
||||
if (a2 > b2) return 1;
|
||||
return 0;
|
||||
});
|
||||
};
|
||||
/** @type {(value: unknown) => unknown[] | undefined} */
|
||||
remote_fns_reducers[remote_set] = (value) => {
|
||||
if (!(value instanceof Set)) return;
|
||||
/** @type {string[]} */
|
||||
const items = [];
|
||||
for (const item of value) items.push(stringify(item));
|
||||
items.sort();
|
||||
return items;
|
||||
};
|
||||
/** @type {(value: unknown) => Record<PropertyKey, unknown> | undefined} */
|
||||
remote_fns_reducers[remote_object] = (value) => {
|
||||
if (!is_plain_object(value)) return;
|
||||
if (Object.hasOwn(value, remote_arg_marker)) return;
|
||||
if (remote_arg_clones.has(value)) return remote_arg_clones.get(value);
|
||||
return to_sorted(value, remote_arg_clones);
|
||||
};
|
||||
}
|
||||
const all_reducers = {
|
||||
...Object.fromEntries(Object.entries(transport).map(([k, v]) => [k, v.encode])),
|
||||
...remote_fns_reducers
|
||||
};
|
||||
/** @type {(value: unknown) => string} */
|
||||
const stringify = (value) => stringify$1(value, all_reducers);
|
||||
return all_reducers;
|
||||
}
|
||||
/** @param {Transport} transport */
|
||||
function create_remote_arg_revivers(transport) {
|
||||
const remote_fns_revivers = {
|
||||
/** @type {(value: unknown) => unknown} */
|
||||
[remote_object]: (value) => value,
|
||||
/** @type {(value: unknown) => Map<unknown, unknown>} */
|
||||
[remote_map]: (value) => {
|
||||
if (!Array.isArray(value)) throw new Error("Invalid data for Map reviver");
|
||||
const map = /* @__PURE__ */ new Map();
|
||||
for (const item of value) {
|
||||
if (!Array.isArray(item) || item.length !== 2 || typeof item[0] !== "string" || typeof item[1] !== "string") throw new Error("Invalid data for Map reviver");
|
||||
const [key, val] = item;
|
||||
map.set(parse$1(key), parse$1(val));
|
||||
}
|
||||
return map;
|
||||
},
|
||||
/** @type {(value: unknown) => Set<unknown>} */
|
||||
[remote_set]: (value) => {
|
||||
if (!Array.isArray(value)) throw new Error("Invalid data for Set reviver");
|
||||
const set = /* @__PURE__ */ new Set();
|
||||
for (const item of value) {
|
||||
if (typeof item !== "string") throw new Error("Invalid data for Set reviver");
|
||||
set.add(parse$1(item));
|
||||
}
|
||||
return set;
|
||||
},
|
||||
/** @type {(value: any) => File} */
|
||||
[remote_file]: (value) => {
|
||||
if (!value || typeof value !== "object" || typeof value.name !== "string" || typeof value.type !== "string" || typeof value.size !== "number" || typeof value.lastModified !== "number" || !(value.data instanceof ArrayBuffer)) throw new Error("Invalid data for File reviver");
|
||||
const { data, name, ...meta } = value;
|
||||
return new File([data], name, meta);
|
||||
}
|
||||
};
|
||||
const all_revivers = {
|
||||
...Object.fromEntries(Object.entries(transport).map(([k, v]) => [k, v.decode])),
|
||||
...remote_fns_revivers
|
||||
};
|
||||
/** @type {(data: string) => unknown} */
|
||||
const parse$1 = (data) => parse(data, all_revivers);
|
||||
return all_revivers;
|
||||
}
|
||||
/**
|
||||
* Stringifies the argument (if any) for a remote function in such a way that
|
||||
* it is both a valid URL and a valid file name (necessary for prerendering).
|
||||
* @param {any} value
|
||||
* @param {Transport} transport
|
||||
*/
|
||||
function stringify_remote_arg(value, transport) {
|
||||
if (value === void 0) return "";
|
||||
return url_friendly_base64_encode(stringify$1(value, create_remote_arg_reducers(transport, true, /* @__PURE__ */ new Map())));
|
||||
}
|
||||
/**
|
||||
* Base64-encodes `string` in such a way that the result is safe to use
|
||||
* as both a URI component and a filename
|
||||
* @param {string} string
|
||||
*/
|
||||
function url_friendly_base64_encode(string) {
|
||||
return base64_encode(text_encoder.encode(string)).replaceAll("=", "").replaceAll("+", "-").replaceAll("/", "_");
|
||||
}
|
||||
/**
|
||||
* Parses the argument (if any) for a remote function
|
||||
* @param {string} string
|
||||
* @param {Transport} transport
|
||||
*/
|
||||
function parse_remote_arg(string, transport) {
|
||||
if (!string) return void 0;
|
||||
return parse(new TextDecoder().decode(base64_decode(string.replaceAll("-", "+").replaceAll("_", "/"))), create_remote_arg_revivers(transport));
|
||||
}
|
||||
/**
|
||||
* @param {string} id
|
||||
* @param {string} payload
|
||||
*/
|
||||
function create_remote_key(id, payload) {
|
||||
return id + "/" + payload;
|
||||
}
|
||||
/**
|
||||
* @param {string} key
|
||||
* @returns {{ id: string; payload: string }}
|
||||
*/
|
||||
function split_remote_key(key) {
|
||||
const i = key.lastIndexOf("/");
|
||||
if (i === -1) throw new Error(`Invalid remote key: ${key}`);
|
||||
return {
|
||||
id: key.slice(0, i),
|
||||
payload: key.slice(i + 1)
|
||||
};
|
||||
}
|
||||
//#endregion
|
||||
export { stringify$1 as _, split_remote_key as a, once as b, validate_depends as c, get_message as d, get_status as f, text_encoder as g, get_relative_path as h, parse_remote_arg as i, validate_load_response as l, base64_encode as m, TRAILING_SLASH_PARAM as n, stringify as o, normalize_error as p, create_remote_key as r, stringify_remote_arg as s, INVALIDATED_PARAM as t, coalesce_to_error as u, parse as v, noop as y };
|
||||
Reference in New Issue
Block a user