schemas/libraries/valibot/download_compiled/unminified.js
//#region ../node_modules/.pnpm/valibot@1.2.0_typescript@6.0.0-beta/node_modules/valibot/dist/index.mjs let store$4; /** * Returns the global configuration. * * @param config The config to merge. * * @returns The configuration. */ /* @__NO_SIDE_EFFECTS__ */ function getGlobalConfig(config$1) { return { lang: config$1?.lang ?? store$4?.lang, message: config$1?.message, abortEarly: config$1?.abortEarly ?? store$4?.abortEarly, abortPipeEarly: config$1?.abortPipeEarly ?? store$4?.abortPipeEarly }; } let store$3; /** * Returns a global error message. * * @param lang The language of the message. * * @returns The error message. */ /* @__NO_SIDE_EFFECTS__ */ function getGlobalMessage(lang) { return store$3?.get(lang); } let store$2; /** * Returns a schema error message. * * @param lang The language of the message. * * @returns The error message. */ /* @__NO_SIDE_EFFECTS__ */ function getSchemaMessage(lang) { return store$2?.get(lang); } let store$1; /** * Returns a specific error message. * * @param reference The identifier reference. * @param lang The language of the message. * * @returns The error message. */ /* @__NO_SIDE_EFFECTS__ */ function getSpecificMessage(reference, lang) { return store$1?.get(reference)?.get(lang); } /** * Stringifies an unknown input to a literal or type string. * * @param input The unknown input. * * @returns A literal or type string. * * @internal */ /* @__NO_SIDE_EFFECTS__ */ function _stringify(input) { const type = typeof input; if (type === "string") return `"${input}"`; if (type === "number" || type === "bigint" || type === "boolean") return `${input}`; if (type === "object" || type === "function") return (input && Object.getPrototypeOf(input)?.constructor?.name) ?? "null"; return type; } /** * Adds an issue to the dataset. * * @param context The issue context. * @param label The issue label. * @param dataset The input dataset. * @param config The configuration. * @param other The optional props. * * @internal */ function _addIssue(context, label, dataset, config$1, other) { const input = other && "input" in other ? other.input : dataset.value; const expected = other?.expected ?? context.expects ?? null; const received = other?.received ?? /* @__PURE__ */ _stringify(input); const issue = { kind: context.kind, type: context.type, input, expected, received, message: `Invalid ${label}: ${expected ? `Expected ${expected} but r` : "R"}eceived ${received}`, requirement: context.requirement, path: other?.path, issues: other?.issues, lang: config$1.lang, abortEarly: config$1.abortEarly, abortPipeEarly: config$1.abortPipeEarly }; const isSchema = context.kind === "schema"; const message$1 = other?.message ?? context.message ?? /* @__PURE__ */ getSpecificMessage(context.reference, issue.lang) ?? (isSchema ? /* @__PURE__ */ getSchemaMessage(issue.lang) : null) ?? config$1.message ?? /* @__PURE__ */ getGlobalMessage(issue.lang); if (message$1 !== void 0) issue.message = typeof message$1 === "function" ? message$1(issue) : message$1; if (isSchema) dataset.typed = false; if (dataset.issues) dataset.issues.push(issue); else dataset.issues = [issue]; } /** * Returns the Standard Schema properties. * * @param context The schema context. * * @returns The Standard Schema properties. */ /* @__NO_SIDE_EFFECTS__ */ function _getStandardProps(context) { return { version: 1, vendor: "valibot", validate(value$1) { return context["~run"]({ value: value$1 }, /* @__PURE__ */ getGlobalConfig()); } }; } /** * Joins multiple `expects` values with the given separator. * * @param values The `expects` values. * @param separator The separator. * * @returns The joined `expects` property. * * @internal */ /* @__NO_SIDE_EFFECTS__ */ function _joinExpects(values$1, separator) { const list = [...new Set(values$1)]; if (list.length > 1) return `(${list.join(` ${separator} `)})`; return list[0] ?? "never"; } /** * A Valibot error with useful information. */ var ValiError = class extends Error { /** * Creates a Valibot error with useful information. * * @param issues The error issues. */ constructor(issues) { super(issues[0].message); this.name = "ValiError"; this.issues = issues; } }; /* @__NO_SIDE_EFFECTS__ */ function maxLength(requirement, message$1) { return { kind: "validation", type: "max_length", reference: maxLength, async: false, expects: `<=${requirement}`, requirement, message: message$1, "~run"(dataset, config$1) { if (dataset.typed && dataset.value.length > this.requirement) _addIssue(this, "length", dataset, config$1, { received: `${dataset.value.length}` }); return dataset; } }; } /* @__NO_SIDE_EFFECTS__ */ function maxValue(requirement, message$1) { return { kind: "validation", type: "max_value", reference: maxValue, async: false, expects: `<=${requirement instanceof Date ? requirement.toJSON() : /* @__PURE__ */ _stringify(requirement)}`, requirement, message: message$1, "~run"(dataset, config$1) { if (dataset.typed && !(dataset.value <= this.requirement)) _addIssue(this, "value", dataset, config$1, { received: dataset.value instanceof Date ? dataset.value.toJSON() : /* @__PURE__ */ _stringify(dataset.value) }); return dataset; } }; } /* @__NO_SIDE_EFFECTS__ */ function minLength(requirement, message$1) { return { kind: "validation", type: "min_length", reference: minLength, async: false, expects: `>=${requirement}`, requirement, message: message$1, "~run"(dataset, config$1) { if (dataset.typed && dataset.value.length < this.requirement) _addIssue(this, "length", dataset, config$1, { received: `${dataset.value.length}` }); return dataset; } }; } /* @__NO_SIDE_EFFECTS__ */ function minValue(requirement, message$1) { return { kind: "validation", type: "min_value", reference: minValue, async: false, expects: `>=${requirement instanceof Date ? requirement.toJSON() : /* @__PURE__ */ _stringify(requirement)}`, requirement, message: message$1, "~run"(dataset, config$1) { if (dataset.typed && !(dataset.value >= this.requirement)) _addIssue(this, "value", dataset, config$1, { received: dataset.value instanceof Date ? dataset.value.toJSON() : /* @__PURE__ */ _stringify(dataset.value) }); return dataset; } }; } /* @__NO_SIDE_EFFECTS__ */ function url(message$1) { return { kind: "validation", type: "url", reference: url, async: false, expects: null, requirement(input) { try { new URL(input); return true; } catch { return false; } }, message: message$1, "~run"(dataset, config$1) { if (dataset.typed && !this.requirement(dataset.value)) _addIssue(this, "URL", dataset, config$1); return dataset; } }; } /** * Returns the fallback value of the schema. * * @param schema The schema to get it from. * @param dataset The output dataset if available. * @param config The config if available. * * @returns The fallback value. */ /* @__NO_SIDE_EFFECTS__ */ function getFallback(schema, dataset, config$1) { return typeof schema.fallback === "function" ? schema.fallback(dataset, config$1) : schema.fallback; } /** * Returns the default value of the schema. * * @param schema The schema to get it from. * @param dataset The input dataset if available. * @param config The config if available. * * @returns The default value. */ /* @__NO_SIDE_EFFECTS__ */ function getDefault(schema, dataset, config$1) { return typeof schema.default === "function" ? schema.default(dataset, config$1) : schema.default; } /* @__NO_SIDE_EFFECTS__ */ function array(item, message$1) { return { kind: "schema", type: "array", reference: array, expects: "Array", async: false, item, message: message$1, get "~standard"() { return /* @__PURE__ */ _getStandardProps(this); }, "~run"(dataset, config$1) { const input = dataset.value; if (Array.isArray(input)) { dataset.typed = true; dataset.value = []; for (let key = 0; key < input.length; key++) { const value$1 = input[key]; const itemDataset = this.item["~run"]({ value: value$1 }, config$1); if (itemDataset.issues) { const pathItem = { type: "array", origin: "value", input, key, value: value$1 }; for (const issue of itemDataset.issues) { if (issue.path) issue.path.unshift(pathItem); else issue.path = [pathItem]; dataset.issues?.push(issue); } if (!dataset.issues) dataset.issues = itemDataset.issues; if (config$1.abortEarly) { dataset.typed = false; break; } } if (!itemDataset.typed) dataset.typed = false; dataset.value.push(itemDataset.value); } } else _addIssue(this, "type", dataset, config$1); return dataset; } }; } /* @__NO_SIDE_EFFECTS__ */ function date(message$1) { return { kind: "schema", type: "date", reference: date, expects: "Date", async: false, message: message$1, get "~standard"() { return /* @__PURE__ */ _getStandardProps(this); }, "~run"(dataset, config$1) { if (dataset.value instanceof Date) if (!isNaN(dataset.value)) dataset.typed = true; else _addIssue(this, "type", dataset, config$1, { received: "\"Invalid Date\"" }); else _addIssue(this, "type", dataset, config$1); return dataset; } }; } /* @__NO_SIDE_EFFECTS__ */ function nullable(wrapped, default_) { return { kind: "schema", type: "nullable", reference: nullable, expects: `(${wrapped.expects} | null)`, async: false, wrapped, default: default_, get "~standard"() { return /* @__PURE__ */ _getStandardProps(this); }, "~run"(dataset, config$1) { if (dataset.value === null) { if (this.default !== void 0) dataset.value = /* @__PURE__ */ getDefault(this, dataset, config$1); if (dataset.value === null) { dataset.typed = true; return dataset; } } return this.wrapped["~run"](dataset, config$1); } }; } /* @__NO_SIDE_EFFECTS__ */ function number(message$1) { return { kind: "schema", type: "number", reference: number, expects: "number", async: false, message: message$1, get "~standard"() { return /* @__PURE__ */ _getStandardProps(this); }, "~run"(dataset, config$1) { if (typeof dataset.value === "number" && !isNaN(dataset.value)) dataset.typed = true; else _addIssue(this, "type", dataset, config$1); return dataset; } }; } /* @__NO_SIDE_EFFECTS__ */ function object(entries$1, message$1) { return { kind: "schema", type: "object", reference: object, expects: "Object", async: false, entries: entries$1, message: message$1, get "~standard"() { return /* @__PURE__ */ _getStandardProps(this); }, "~run"(dataset, config$1) { const input = dataset.value; if (input && typeof input === "object") { dataset.typed = true; dataset.value = {}; for (const key in this.entries) { const valueSchema = this.entries[key]; if (key in input || (valueSchema.type === "exact_optional" || valueSchema.type === "optional" || valueSchema.type === "nullish") && valueSchema.default !== void 0) { const value$1 = key in input ? input[key] : /* @__PURE__ */ getDefault(valueSchema); const valueDataset = valueSchema["~run"]({ value: value$1 }, config$1); if (valueDataset.issues) { const pathItem = { type: "object", origin: "value", input, key, value: value$1 }; for (const issue of valueDataset.issues) { if (issue.path) issue.path.unshift(pathItem); else issue.path = [pathItem]; dataset.issues?.push(issue); } if (!dataset.issues) dataset.issues = valueDataset.issues; if (config$1.abortEarly) { dataset.typed = false; break; } } if (!valueDataset.typed) dataset.typed = false; dataset.value[key] = valueDataset.value; } else if (valueSchema.fallback !== void 0) dataset.value[key] = /* @__PURE__ */ getFallback(valueSchema); else if (valueSchema.type !== "exact_optional" && valueSchema.type !== "optional" && valueSchema.type !== "nullish") { _addIssue(this, "key", dataset, config$1, { input: void 0, expected: `"${key}"`, path: [{ type: "object", origin: "key", input, key, value: input[key] }] }); if (config$1.abortEarly) break; } } } else _addIssue(this, "type", dataset, config$1); return dataset; } }; } /* @__NO_SIDE_EFFECTS__ */ function picklist(options, message$1) { return { kind: "schema", type: "picklist", reference: picklist, expects: /* @__PURE__ */ _joinExpects(options.map(_stringify), "|"), async: false, options, message: message$1, get "~standard"() { return /* @__PURE__ */ _getStandardProps(this); }, "~run"(dataset, config$1) { if (this.options.includes(dataset.value)) dataset.typed = true; else _addIssue(this, "type", dataset, config$1); return dataset; } }; } /* @__NO_SIDE_EFFECTS__ */ function string(message$1) { return { kind: "schema", type: "string", reference: string, expects: "string", async: false, message: message$1, get "~standard"() { return /* @__PURE__ */ _getStandardProps(this); }, "~run"(dataset, config$1) { if (typeof dataset.value === "string") dataset.typed = true; else _addIssue(this, "type", dataset, config$1); return dataset; } }; } /** * Parses an unknown input based on a schema. * * @param schema The schema to be used. * @param input The input to be parsed. * @param config The parse configuration. * * @returns The parsed input. */ function parse(schema, input, config$1) { const dataset = schema["~run"]({ value: input }, /* @__PURE__ */ getGlobalConfig(config$1)); if (dataset.issues) throw new ValiError(dataset.issues); return dataset.value; } /* @__NO_SIDE_EFFECTS__ */ function pipe(...pipe$1) { return { ...pipe$1[0], pipe: pipe$1, get "~standard"() { return /* @__PURE__ */ _getStandardProps(this); }, "~run"(dataset, config$1) { for (const item of pipe$1) if (item.kind !== "metadata") { if (dataset.issues && (item.kind === "schema" || item.kind === "transformation")) { dataset.typed = false; break; } if (!dataset.issues || !config$1.abortEarly && !config$1.abortPipeEarly) dataset = item["~run"](dataset, config$1); } return dataset; } }; } //#endregion //#region ../schemas/libraries/valibot/download.ts const imageSchema = object({ id: number(), created: date(), title: pipe(string(), minLength(1), maxLength(100)), type: picklist(["jpg", "png"]), size: number(), url: pipe(string(), url()) }); const ratingSchema = object({ id: number(), stars: pipe(number(), minValue(1), maxValue(5)), title: pipe(string(), minLength(1), maxLength(100)), text: pipe(string(), minLength(1), maxLength(1e3)), images: array(imageSchema) }); const productSchema = object({ id: number(), created: date(), title: pipe(string(), minLength(1), maxLength(100)), brand: pipe(string(), minLength(1), maxLength(30)), description: pipe(string(), minLength(1), maxLength(500)), price: pipe(number(), minValue(1), maxValue(1e4)), discount: nullable(pipe(number(), minValue(1), maxValue(100))), quantity: pipe(number(), minValue(1), maxValue(10)), tags: array(pipe(string(), minLength(1), maxLength(30))), images: array(imageSchema), ratings: array(ratingSchema) }); parse(productSchema, {}); //#endregion