better-call 0.0.0-experimental.01ff4b77
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +265 -0
- package/dist/capability.cjs +417 -0
- package/dist/capability.cjs.map +1 -0
- package/dist/capability.d.cts +189 -0
- package/dist/capability.d.mts +189 -0
- package/dist/capability.mjs +401 -0
- package/dist/capability.mjs.map +1 -0
- package/dist/error.cjs +76 -0
- package/dist/error.cjs.map +1 -0
- package/dist/error.d.cts +51 -0
- package/dist/error.d.mts +51 -0
- package/dist/error.mjs +72 -0
- package/dist/error.mjs.map +1 -0
- package/dist/fn.cjs +350 -0
- package/dist/fn.cjs.map +1 -0
- package/dist/fn.d.cts +378 -0
- package/dist/fn.d.mts +378 -0
- package/dist/fn.mjs +350 -0
- package/dist/fn.mjs.map +1 -0
- package/dist/index.cjs +43 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +50 -0
- package/dist/index.d.mts +50 -0
- package/dist/index.mjs +24 -0
- package/dist/index.mjs.map +1 -0
- package/dist/module.cjs +176 -0
- package/dist/module.cjs.map +1 -0
- package/dist/module.d.cts +283 -0
- package/dist/module.d.mts +283 -0
- package/dist/module.mjs +166 -0
- package/dist/module.mjs.map +1 -0
- package/dist/plugins/db.cjs +24 -0
- package/dist/plugins/db.cjs.map +1 -0
- package/dist/plugins/db.d.cts +18 -0
- package/dist/plugins/db.d.mts +18 -0
- package/dist/plugins/db.mjs +19 -0
- package/dist/plugins/db.mjs.map +1 -0
- package/dist/plugins/http/attrs.cjs +91 -0
- package/dist/plugins/http/attrs.cjs.map +1 -0
- package/dist/plugins/http/attrs.d.cts +26 -0
- package/dist/plugins/http/attrs.d.mts +26 -0
- package/dist/plugins/http/attrs.mjs +87 -0
- package/dist/plugins/http/attrs.mjs.map +1 -0
- package/dist/plugins/http/cookie.cjs +117 -0
- package/dist/plugins/http/cookie.cjs.map +1 -0
- package/dist/plugins/http/cookie.d.cts +637 -0
- package/dist/plugins/http/cookie.d.mts +637 -0
- package/dist/plugins/http/cookie.mjs +113 -0
- package/dist/plugins/http/cookie.mjs.map +1 -0
- package/dist/plugins/http/error.cjs +39 -0
- package/dist/plugins/http/error.cjs.map +1 -0
- package/dist/plugins/http/error.d.cts +38 -0
- package/dist/plugins/http/error.d.mts +38 -0
- package/dist/plugins/http/error.mjs +35 -0
- package/dist/plugins/http/error.mjs.map +1 -0
- package/dist/plugins/http/handle.cjs +73 -0
- package/dist/plugins/http/handle.cjs.map +1 -0
- package/dist/plugins/http/handle.d.cts +955 -0
- package/dist/plugins/http/handle.d.mts +955 -0
- package/dist/plugins/http/handle.mjs +72 -0
- package/dist/plugins/http/handle.mjs.map +1 -0
- package/dist/plugins/http/redirect.cjs +82 -0
- package/dist/plugins/http/redirect.cjs.map +1 -0
- package/dist/plugins/http/redirect.d.cts +67 -0
- package/dist/plugins/http/redirect.d.mts +67 -0
- package/dist/plugins/http/redirect.mjs +79 -0
- package/dist/plugins/http/redirect.mjs.map +1 -0
- package/dist/plugins/http/request.cjs +63 -0
- package/dist/plugins/http/request.cjs.map +1 -0
- package/dist/plugins/http/request.d.cts +142 -0
- package/dist/plugins/http/request.d.mts +142 -0
- package/dist/plugins/http/request.mjs +61 -0
- package/dist/plugins/http/request.mjs.map +1 -0
- package/dist/plugins/http/response.cjs +13 -0
- package/dist/plugins/http/response.cjs.map +1 -0
- package/dist/plugins/http/response.d.cts +18 -0
- package/dist/plugins/http/response.d.mts +18 -0
- package/dist/plugins/http/response.mjs +13 -0
- package/dist/plugins/http/response.mjs.map +1 -0
- package/dist/plugins/http.cjs +64 -0
- package/dist/plugins/http.cjs.map +1 -0
- package/dist/plugins/http.d.cts +945 -0
- package/dist/plugins/http.d.mts +945 -0
- package/dist/plugins/http.mjs +37 -0
- package/dist/plugins/http.mjs.map +1 -0
- package/dist/plugins/read-only.cjs +19 -0
- package/dist/plugins/read-only.cjs.map +1 -0
- package/dist/plugins/read-only.d.cts +17 -0
- package/dist/plugins/read-only.d.mts +17 -0
- package/dist/plugins/read-only.mjs +19 -0
- package/dist/plugins/read-only.mjs.map +1 -0
- package/dist/schema.cjs +245 -0
- package/dist/schema.cjs.map +1 -0
- package/dist/schema.d.cts +411 -0
- package/dist/schema.d.mts +411 -0
- package/dist/schema.mjs +235 -0
- package/dist/schema.mjs.map +1 -0
- package/dist/scope.d.cts +31 -0
- package/dist/scope.d.mts +31 -0
- package/dist/storage.cjs +308 -0
- package/dist/storage.cjs.map +1 -0
- package/dist/storage.d.cts +220 -0
- package/dist/storage.d.mts +220 -0
- package/dist/storage.mjs +302 -0
- package/dist/storage.mjs.map +1 -0
- package/dist/types.d.cts +8 -0
- package/dist/types.d.mts +8 -0
- package/dist/var.cjs +186 -0
- package/dist/var.cjs.map +1 -0
- package/dist/var.d.cts +46 -0
- package/dist/var.d.mts +46 -0
- package/dist/var.mjs +177 -0
- package/dist/var.mjs.map +1 -0
- package/package.json +114 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { clientSchema, fromJsonBody, rejectServerOnly, serverOnly, wireInput } from "./http/attrs.mjs";
|
|
2
|
+
import { res, toResponse } from "./http/response.mjs";
|
|
3
|
+
import { fromRequest, req, toHttpRequest } from "./http/request.mjs";
|
|
4
|
+
import { cookieOptions, cookieShape, deleteCookie, getCookie, setCookie } from "./http/cookie.mjs";
|
|
5
|
+
import { applyError, err, errorStatus, kHttpErr, statusOf } from "./http/error.mjs";
|
|
6
|
+
import { Redirect, applyRedirect, asResponse, redirect } from "./http/redirect.mjs";
|
|
7
|
+
import { createHandler, handler } from "./http/handle.mjs";
|
|
8
|
+
//#region src/plugins/http/index.ts
|
|
9
|
+
const http = {
|
|
10
|
+
req,
|
|
11
|
+
res,
|
|
12
|
+
cookieOptions,
|
|
13
|
+
fromRequest,
|
|
14
|
+
handler,
|
|
15
|
+
createHandler,
|
|
16
|
+
getCookie,
|
|
17
|
+
setCookie,
|
|
18
|
+
deleteCookie,
|
|
19
|
+
err,
|
|
20
|
+
statusOf,
|
|
21
|
+
errorStatus,
|
|
22
|
+
applyError,
|
|
23
|
+
redirect,
|
|
24
|
+
applyRedirect,
|
|
25
|
+
asResponse,
|
|
26
|
+
toResponse,
|
|
27
|
+
Redirect,
|
|
28
|
+
serverOnly,
|
|
29
|
+
clientSchema,
|
|
30
|
+
rejectServerOnly,
|
|
31
|
+
wireInput,
|
|
32
|
+
fromJsonBody
|
|
33
|
+
};
|
|
34
|
+
//#endregion
|
|
35
|
+
export { Redirect, applyError, applyRedirect, asResponse, clientSchema, cookieOptions, cookieShape, createHandler, deleteCookie, err, errorStatus, fromJsonBody, fromRequest, getCookie, handler, http, kHttpErr, redirect, rejectServerOnly, req, res, serverOnly, setCookie, statusOf, toHttpRequest, toResponse, wireInput };
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=http.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.mjs","names":[],"sources":["../../src/plugins/http/index.ts"],"sourcesContent":["import {\n\tclientSchema,\n\tfromJsonBody,\n\trejectServerOnly,\n\tserverOnly,\n\twireInput,\n} from \"./attrs\";\nimport { cookieOptions, deleteCookie, getCookie, setCookie } from \"./cookie\";\nimport { applyError, err, errorStatus, statusOf } from \"./error\";\nimport { createHandler, handler } from \"./handle\";\nimport { applyRedirect, asResponse, Redirect, redirect } from \"./redirect\";\nimport { fromRequest, req } from \"./request\";\nimport { res, toResponse } from \"./response\";\n\nexport {\n\tclientSchema,\n\tfromJsonBody,\n\trejectServerOnly,\n\tserverOnly,\n\twireInput,\n} from \"./attrs\";\nexport type { CookieOptions } from \"./cookie\";\nexport {\n\tcookieOptions,\n\tcookieShape,\n\tdeleteCookie,\n\tgetCookie,\n\tsetCookie,\n} from \"./cookie\";\nexport type { HttpErrMeta } from \"./error\";\nexport {\n\tapplyError,\n\terr,\n\terrorStatus,\n\tkHttpErr,\n\tstatusOf,\n} from \"./error\";\nexport type { CreateHandlerContext, CreateHandlerOptions } from \"./handle\";\nexport { createHandler, handler } from \"./handle\";\nexport type { RedirectStatus } from \"./redirect\";\nexport {\n\tapplyRedirect,\n\tasResponse,\n\tRedirect,\n\tredirect,\n} from \"./redirect\";\nexport type { HttpRequest } from \"./request\";\nexport { fromRequest, req, toHttpRequest } from \"./request\";\nexport type { HttpResponse } from \"./response\";\nexport { res, toResponse } from \"./response\";\n\nexport const http = {\n\treq,\n\tres,\n\tcookieOptions,\n\tfromRequest,\n\thandler,\n\tcreateHandler,\n\tgetCookie,\n\tsetCookie,\n\tdeleteCookie,\n\terr,\n\tstatusOf,\n\terrorStatus,\n\tapplyError,\n\tredirect,\n\tapplyRedirect,\n\tasResponse,\n\ttoResponse,\n\tRedirect,\n\tserverOnly,\n\tclientSchema,\n\trejectServerOnly,\n\twireInput,\n\tfromJsonBody,\n};\n"],"mappings":";;;;;;;;AAmDA,MAAa,OAAO;CACnB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_error = require("../error.cjs");
|
|
3
|
+
//#region src/plugins/read-only.ts
|
|
4
|
+
/**
|
|
5
|
+
* Mount via `use: [readOnly]` and this fn - plus EVERYTHING it calls,
|
|
6
|
+
* any depth, interceptors included - cannot write vars: every set throws,
|
|
7
|
+
* naming the offender. Nothing here is privileged: var writes are events,
|
|
8
|
+
* and this module is one `v.on` listener.
|
|
9
|
+
*
|
|
10
|
+
* Pairs with the `readonly: true` fn option, which adds the TYPE half
|
|
11
|
+
* (vars readonly on `c`, declared writers uncallable).
|
|
12
|
+
*/
|
|
13
|
+
const readOnly = { _readOnly: require("../index.cjs").v.on("var.set.*", (c) => {
|
|
14
|
+
throw new require_error.ValidationError(`${c.fn}.readonly`, `readonly scope: attempted to set var "${c.name}"`);
|
|
15
|
+
}) };
|
|
16
|
+
//#endregion
|
|
17
|
+
exports.readOnly = readOnly;
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=read-only.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-only.cjs","names":["v","ValidationError"],"sources":["../../src/plugins/read-only.ts"],"sourcesContent":["import { ValidationError, v } from \"../index\";\n\n/**\n * Mount via `use: [readOnly]` and this fn - plus EVERYTHING it calls,\n * any depth, interceptors included - cannot write vars: every set throws,\n * naming the offender. Nothing here is privileged: var writes are events,\n * and this module is one `v.on` listener.\n *\n * Pairs with the `readonly: true` fn option, which adds the TYPE half\n * (vars readonly on `c`, declared writers uncallable).\n */\nexport const readOnly = {\n\t_readOnly: v.on(\"var.set.*\", (c) => {\n\t\tthrow new ValidationError(\n\t\t\t`${c.fn}.readonly`,\n\t\t\t`readonly scope: attempted to set var \"${c.name}\"`,\n\t\t);\n\t}),\n};\n"],"mappings":";;;;;;;;;;;;AAWA,MAAa,WAAW,EACvB,iCAAWA,CAAAA,CAAAA,EAAE,GAAG,cAAc,MAAM;CACnC,MAAM,IAAIC,cAAAA,gBACT,GAAG,EAAE,GAAG,YACR,yCAAyC,EAAE,KAAK,EACjD;AACD,CAAC,EACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { OnEntry } from "../module.cjs";
|
|
2
|
+
//#region src/plugins/read-only.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Mount via `use: [readOnly]` and this fn - plus EVERYTHING it calls,
|
|
5
|
+
* any depth, interceptors included - cannot write vars: every set throws,
|
|
6
|
+
* naming the offender. Nothing here is privileged: var writes are events,
|
|
7
|
+
* and this module is one `v.on` listener.
|
|
8
|
+
*
|
|
9
|
+
* Pairs with the `readonly: true` fn option, which adds the TYPE half
|
|
10
|
+
* (vars readonly on `c`, declared writers uncallable).
|
|
11
|
+
*/
|
|
12
|
+
declare const readOnly: {
|
|
13
|
+
_readOnly: OnEntry<"var.set.*", unknown>;
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
|
16
|
+
export { readOnly };
|
|
17
|
+
//# sourceMappingURL=read-only.d.cts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { OnEntry } from "../module.mjs";
|
|
2
|
+
//#region src/plugins/read-only.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Mount via `use: [readOnly]` and this fn - plus EVERYTHING it calls,
|
|
5
|
+
* any depth, interceptors included - cannot write vars: every set throws,
|
|
6
|
+
* naming the offender. Nothing here is privileged: var writes are events,
|
|
7
|
+
* and this module is one `v.on` listener.
|
|
8
|
+
*
|
|
9
|
+
* Pairs with the `readonly: true` fn option, which adds the TYPE half
|
|
10
|
+
* (vars readonly on `c`, declared writers uncallable).
|
|
11
|
+
*/
|
|
12
|
+
declare const readOnly: {
|
|
13
|
+
_readOnly: OnEntry<"var.set.*", unknown>;
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
|
16
|
+
export { readOnly };
|
|
17
|
+
//# sourceMappingURL=read-only.d.mts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ValidationError } from "../error.mjs";
|
|
2
|
+
import { v } from "../index.mjs";
|
|
3
|
+
//#region src/plugins/read-only.ts
|
|
4
|
+
/**
|
|
5
|
+
* Mount via `use: [readOnly]` and this fn - plus EVERYTHING it calls,
|
|
6
|
+
* any depth, interceptors included - cannot write vars: every set throws,
|
|
7
|
+
* naming the offender. Nothing here is privileged: var writes are events,
|
|
8
|
+
* and this module is one `v.on` listener.
|
|
9
|
+
*
|
|
10
|
+
* Pairs with the `readonly: true` fn option, which adds the TYPE half
|
|
11
|
+
* (vars readonly on `c`, declared writers uncallable).
|
|
12
|
+
*/
|
|
13
|
+
const readOnly = { _readOnly: v.on("var.set.*", (c) => {
|
|
14
|
+
throw new ValidationError(`${c.fn}.readonly`, `readonly scope: attempted to set var "${c.name}"`);
|
|
15
|
+
}) };
|
|
16
|
+
//#endregion
|
|
17
|
+
export { readOnly };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=read-only.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-only.mjs","names":[],"sources":["../../src/plugins/read-only.ts"],"sourcesContent":["import { ValidationError, v } from \"../index\";\n\n/**\n * Mount via `use: [readOnly]` and this fn - plus EVERYTHING it calls,\n * any depth, interceptors included - cannot write vars: every set throws,\n * naming the offender. Nothing here is privileged: var writes are events,\n * and this module is one `v.on` listener.\n *\n * Pairs with the `readonly: true` fn option, which adds the TYPE half\n * (vars readonly on `c`, declared writers uncallable).\n */\nexport const readOnly = {\n\t_readOnly: v.on(\"var.set.*\", (c) => {\n\t\tthrow new ValidationError(\n\t\t\t`${c.fn}.readonly`,\n\t\t\t`readonly scope: attempted to set var \"${c.name}\"`,\n\t\t);\n\t}),\n};\n"],"mappings":";;;;;;;;;;;;AAWA,MAAa,WAAW,EACvB,WAAW,EAAE,GAAG,cAAc,MAAM;CACnC,MAAM,IAAI,gBACT,GAAG,EAAE,GAAG,YACR,yCAAyC,EAAE,KAAK,EACjD;AACD,CAAC,EACF"}
|
package/dist/schema.cjs
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_error = require("./error.cjs");
|
|
3
|
+
//#region src/schema.ts
|
|
4
|
+
/** The runtime unwrap: `def` is the documented schema (falls back to
|
|
5
|
+
* `validation`), `validation` is what the exit check runs - undefined
|
|
6
|
+
* means no check. A bare schema is both. */
|
|
7
|
+
const outputContract = (output) => {
|
|
8
|
+
if (output === void 0) return {};
|
|
9
|
+
if (output !== null && typeof output === "object" && !Array.isArray(output) && !isType(output) && !isVar(output) && !isFnSchema(output)) {
|
|
10
|
+
const keys = Object.keys(output);
|
|
11
|
+
if (keys.length > 0 && keys.every((k) => k === "def" || k === "validation")) {
|
|
12
|
+
const { def, validation } = output;
|
|
13
|
+
return {
|
|
14
|
+
def: def ?? validation,
|
|
15
|
+
validation
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
def: output,
|
|
21
|
+
validation: output
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
const isType = (value) => typeof value?.name === "string";
|
|
25
|
+
/** A handler-less `v.fn(...)` builder doubles as a schema: the value it
|
|
26
|
+
* describes is a FN with the declared signature. The builder FN itself is
|
|
27
|
+
* branded too, so bare `v.fn` reads as "any function". */
|
|
28
|
+
const isFnSchema = (value) => typeof value?.$fnSchema === "object" && value.$fnSchema !== null;
|
|
29
|
+
const asType = (value) => isVar(value) ? asType(value.schema ?? {}) : isFnSchema(value) ? {
|
|
30
|
+
name: "function",
|
|
31
|
+
fnInput: value.$fnSchema.input,
|
|
32
|
+
...value.optional ? { optional: true } : {},
|
|
33
|
+
...value.default !== void 0 ? { default: value.default } : {}
|
|
34
|
+
} : isType(value) ? value : value === null ? { name: "null" } : value === void 0 ? { name: "undefined" } : typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? {
|
|
35
|
+
name: typeof value,
|
|
36
|
+
enum: [value]
|
|
37
|
+
} : {
|
|
38
|
+
name: "object",
|
|
39
|
+
shape: value
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Replace the whole `$attrs` bag. On a var, rebinds `customize` so a later
|
|
43
|
+
* customize keeps these attrs (the original closure closes over pre-attr
|
|
44
|
+
* options and would otherwise drop them).
|
|
45
|
+
*/
|
|
46
|
+
const withAttrBag = (schema, bag) => {
|
|
47
|
+
if (isVar(schema)) {
|
|
48
|
+
const v = schema;
|
|
49
|
+
return {
|
|
50
|
+
...v,
|
|
51
|
+
$attrs: bag,
|
|
52
|
+
customize: (opts) => withAttrBag(v.customize(opts), bag)
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
...asType(schema),
|
|
57
|
+
$attrs: bag
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Attach plugin attributes under `namespace`, deep-merging with any
|
|
62
|
+
* already on the schema. Returns a new type def (or var) with the same
|
|
63
|
+
* value type. Core never reads these - only plugin edges do.
|
|
64
|
+
*
|
|
65
|
+
* Passed a var, attributes land on the var itself (`$attrs`) and the
|
|
66
|
+
* `$var` / `name` / `schema` identity is preserved; `customize` is rebound
|
|
67
|
+
* so attrs survive further customization.
|
|
68
|
+
*/
|
|
69
|
+
const withAttrs = (schema, namespace, attrs) => {
|
|
70
|
+
const prev = attrsOf(schema) ?? {};
|
|
71
|
+
return withAttrBag(schema, {
|
|
72
|
+
...prev,
|
|
73
|
+
[namespace]: {
|
|
74
|
+
...prev[namespace] ?? {},
|
|
75
|
+
...attrs
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
function attrsOf(schema, namespace) {
|
|
80
|
+
if (schema === null || schema === void 0) return void 0;
|
|
81
|
+
const bag = isVar(schema) ? schema.$attrs : asType(schema).$attrs;
|
|
82
|
+
if (!bag) return void 0;
|
|
83
|
+
return namespace === void 0 ? bag : bag[namespace];
|
|
84
|
+
}
|
|
85
|
+
const typeOf = (value) => value === null ? "null" : Array.isArray(value) ? "array" : Number.isNaN(value) ? "NaN" : typeof value;
|
|
86
|
+
const isVar = (value) => value?.$var === true;
|
|
87
|
+
const EMAIL = /^(?!\.)(?!.*\.\.)([a-z0-9_'+\-.]*)[a-z0-9_+-]@([a-z0-9][a-z0-9-]*\.)+[a-z]{2,}$/;
|
|
88
|
+
const fail = (path, message) => {
|
|
89
|
+
throw new require_error.ValidationError(path, message);
|
|
90
|
+
};
|
|
91
|
+
/** Constraint checks, run after the value's type is known to be right. */
|
|
92
|
+
const applyRules = (def, value, path) => {
|
|
93
|
+
if (def.enum && !def.enum.includes(value)) fail(path, `expected one of ${def.enum.join(", ")}, received ${value}`);
|
|
94
|
+
if (typeof value === "string") {
|
|
95
|
+
if (def.length !== void 0 && value.length !== def.length) fail(path, `expected length ${def.length}, received ${value.length}`);
|
|
96
|
+
if (def.min !== void 0 && value.length < def.min) fail(path, `expected at least ${def.min} characters, received ${value.length}`);
|
|
97
|
+
if (def.max !== void 0 && value.length > def.max) fail(path, `expected at most ${def.max} characters, received ${value.length}`);
|
|
98
|
+
if (def.regex && !def.regex.test(value)) fail(path, `does not match ${def.regex}`);
|
|
99
|
+
if (def.email && !EMAIL.test(value)) fail(path, "expected an email address");
|
|
100
|
+
if (def.url) try {
|
|
101
|
+
new URL(value);
|
|
102
|
+
} catch {
|
|
103
|
+
fail(path, "expected a URL");
|
|
104
|
+
}
|
|
105
|
+
if (def.startsWith !== void 0 && !value.startsWith(def.startsWith)) fail(path, `expected to start with "${def.startsWith}"`);
|
|
106
|
+
if (def.endsWith !== void 0 && !value.endsWith(def.endsWith)) fail(path, `expected to end with "${def.endsWith}"`);
|
|
107
|
+
}
|
|
108
|
+
if (Array.isArray(value)) {
|
|
109
|
+
if (def.length !== void 0 && value.length !== def.length) fail(path, `expected length ${def.length}, received ${value.length}`);
|
|
110
|
+
if (def.min !== void 0 && value.length < def.min) fail(path, `expected at least ${def.min} items, received ${value.length}`);
|
|
111
|
+
if (def.max !== void 0 && value.length > def.max) fail(path, `expected at most ${def.max} items, received ${value.length}`);
|
|
112
|
+
}
|
|
113
|
+
if (typeof value === "number") {
|
|
114
|
+
if (def.int && !Number.isInteger(value)) fail(path, `expected an integer, received ${value}`);
|
|
115
|
+
if (def.min !== void 0 && value < def.min) fail(path, `expected >= ${def.min}, received ${value}`);
|
|
116
|
+
if (def.max !== void 0 && value > def.max) fail(path, `expected <= ${def.max}, received ${value}`);
|
|
117
|
+
}
|
|
118
|
+
if (def.check) {
|
|
119
|
+
const result = def.check(value);
|
|
120
|
+
if (result !== true) fail(path, typeof result === "string" ? result : "failed check");
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
const validate = (def, value, path) => {
|
|
124
|
+
if (value === void 0 || value === null && def.optional) {
|
|
125
|
+
if (def.default !== void 0) value = typeof def.default === "function" && def.name !== "function" ? def.default() : def.default;
|
|
126
|
+
else if (def.optional) return value;
|
|
127
|
+
else if (def.name === "object" && def.shape !== void 0) value = {};
|
|
128
|
+
}
|
|
129
|
+
if (isVar(def)) {
|
|
130
|
+
if (value === void 0) return void 0;
|
|
131
|
+
const schema = def.schema;
|
|
132
|
+
return schema === void 0 ? value : validate(schema, value, path);
|
|
133
|
+
}
|
|
134
|
+
if (def.name === "any") return def.transform ? def.transform(value) : value;
|
|
135
|
+
if (def.name === "date") {
|
|
136
|
+
if (!(value instanceof Date)) throw new require_error.ValidationError(path, `expected date, received ${typeOf(value)}`);
|
|
137
|
+
return def.transform ? def.transform(value) : value;
|
|
138
|
+
}
|
|
139
|
+
if (def.name === "function") {
|
|
140
|
+
if (typeof value !== "function") throw new require_error.ValidationError(path, `expected function, received ${typeOf(value)}`);
|
|
141
|
+
const inner = def.fnInput;
|
|
142
|
+
if (inner === void 0 || value.$fn === true) return value;
|
|
143
|
+
const innerType = asType(inner);
|
|
144
|
+
return (input, parent) => value(validate(innerType, input, `${path}()`), parent);
|
|
145
|
+
}
|
|
146
|
+
if (def.name === "array") {
|
|
147
|
+
if (!Array.isArray(value)) throw new require_error.ValidationError(path, `expected array, received ${typeOf(value)}`);
|
|
148
|
+
applyRules(def, value, path);
|
|
149
|
+
if (def.shape === void 0) return def.transform ? def.transform(value) : value;
|
|
150
|
+
const elementType = asType(def.shape);
|
|
151
|
+
const items = [];
|
|
152
|
+
const problems = [];
|
|
153
|
+
for (let index = 0; index < value.length; index++) try {
|
|
154
|
+
items.push(validate(elementType, value[index], `${path}[${index}]`));
|
|
155
|
+
} catch (thrown) {
|
|
156
|
+
if (!(thrown instanceof require_error.ValidationError)) throw thrown;
|
|
157
|
+
problems.push(...thrown.issues);
|
|
158
|
+
}
|
|
159
|
+
const firstProblem = problems[0];
|
|
160
|
+
if (firstProblem) throw new require_error.ValidationError(firstProblem.path, firstProblem.message, problems);
|
|
161
|
+
return def.transform ? def.transform(items) : items;
|
|
162
|
+
}
|
|
163
|
+
if (def.name === "object") {
|
|
164
|
+
if (typeOf(value) !== "object") throw new require_error.ValidationError(path, `expected object, received ${typeOf(value)}`);
|
|
165
|
+
if (def.shape === void 0) return def.transform ? def.transform(value) : value;
|
|
166
|
+
const parsed = {};
|
|
167
|
+
const issues = [];
|
|
168
|
+
for (const [field, child] of Object.entries(def.shape)) try {
|
|
169
|
+
const parsedField = validate(asType(child), value[field], `${path}.${field}`);
|
|
170
|
+
if (parsedField !== void 0) parsed[field] = parsedField;
|
|
171
|
+
} catch (thrown) {
|
|
172
|
+
if (!(thrown instanceof require_error.ValidationError)) throw thrown;
|
|
173
|
+
issues.push(...thrown.issues);
|
|
174
|
+
}
|
|
175
|
+
const firstIssue = issues[0];
|
|
176
|
+
if (firstIssue) throw new require_error.ValidationError(firstIssue.path, firstIssue.message, issues);
|
|
177
|
+
return def.transform ? def.transform(parsed) : parsed;
|
|
178
|
+
}
|
|
179
|
+
if (def.name === "union") {
|
|
180
|
+
const options = def.shape;
|
|
181
|
+
if (!Array.isArray(options) || options.length === 0) throw new require_error.ValidationError(path, "expected a non-empty union");
|
|
182
|
+
const issues = [];
|
|
183
|
+
let parsed;
|
|
184
|
+
let matched = false;
|
|
185
|
+
for (const member of options) try {
|
|
186
|
+
parsed = validate(asType(member), value, path);
|
|
187
|
+
matched = true;
|
|
188
|
+
break;
|
|
189
|
+
} catch (thrown) {
|
|
190
|
+
if (!(thrown instanceof require_error.ValidationError)) throw thrown;
|
|
191
|
+
issues.push(...thrown.issues);
|
|
192
|
+
}
|
|
193
|
+
if (!matched) {
|
|
194
|
+
const firstIssue = issues[0];
|
|
195
|
+
if (firstIssue) throw new require_error.ValidationError(firstIssue.path, firstIssue.message, issues);
|
|
196
|
+
throw new require_error.ValidationError(path, `expected union, received ${typeOf(value)}`);
|
|
197
|
+
}
|
|
198
|
+
applyRules(def, parsed, path);
|
|
199
|
+
return def.transform ? def.transform(parsed) : parsed;
|
|
200
|
+
}
|
|
201
|
+
if (typeOf(value) !== def.name) throw new require_error.ValidationError(path, `expected ${def.name}, received ${typeOf(value)}`);
|
|
202
|
+
if (def.email && typeof value === "string") value = value.trim().toLowerCase();
|
|
203
|
+
applyRules(def, value, path);
|
|
204
|
+
return def.transform ? def.transform(value) : value;
|
|
205
|
+
};
|
|
206
|
+
/** Builds the runtime object; the declared return type is the contract. */
|
|
207
|
+
const build = (name, options, extra) => ({
|
|
208
|
+
name,
|
|
209
|
+
...extra,
|
|
210
|
+
...options
|
|
211
|
+
});
|
|
212
|
+
const vTypes = {
|
|
213
|
+
/** An `enum` narrows both sides to the literal union: `v.string({
|
|
214
|
+
* enum: ["a", "b"] })` types as `"a" | "b"`, not `string`. */
|
|
215
|
+
string: ((options) => build("string", options)),
|
|
216
|
+
number: ((options) => build("number", options)),
|
|
217
|
+
boolean: ((options) => build("boolean", options)),
|
|
218
|
+
/** A Date INSTANCE - checked with `instanceof`, never parsed. */
|
|
219
|
+
date: ((options) => build("date", options)),
|
|
220
|
+
/** Passthrough - validated as-is, never coerced or stripped. */
|
|
221
|
+
any: ((options) => build("any", options)),
|
|
222
|
+
/** With a SHAPE every field validates; with NO shape (`v.object()`)
|
|
223
|
+
* any object passes, as-is. */
|
|
224
|
+
object: ((shape, options) => build("object", options, shape === void 0 ? {} : { shape })),
|
|
225
|
+
/** With an ELEMENT every item validates - all failures report
|
|
226
|
+
* together, like object fields; with NO element (`v.array()`) any
|
|
227
|
+
* array passes, as-is. `min`/`max`/`length` count items. */
|
|
228
|
+
array: ((element, options) => build("array", options, element === void 0 ? {} : { shape: element })),
|
|
229
|
+
/** Try each option in order - first successful parse wins. All
|
|
230
|
+
* failing branches report together when none match. */
|
|
231
|
+
union: ((members, options) => build("union", options, { shape: members }))
|
|
232
|
+
};
|
|
233
|
+
//#endregion
|
|
234
|
+
exports.asType = asType;
|
|
235
|
+
exports.attrsOf = attrsOf;
|
|
236
|
+
exports.isFnSchema = isFnSchema;
|
|
237
|
+
exports.isType = isType;
|
|
238
|
+
exports.isVar = isVar;
|
|
239
|
+
exports.outputContract = outputContract;
|
|
240
|
+
exports.typeOf = typeOf;
|
|
241
|
+
exports.vTypes = vTypes;
|
|
242
|
+
exports.validate = validate;
|
|
243
|
+
exports.withAttrs = withAttrs;
|
|
244
|
+
|
|
245
|
+
//# sourceMappingURL=schema.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.cjs","names":["ValidationError"],"sources":["../src/schema.ts"],"sourcesContent":["import { type Issue, ValidationError } from \"./error\";\nimport type { LiteralString, Prettify } from \"./types\";\n\nexport type Rules = {\n\t/** Strings: length. Numbers: value. */\n\tmin?: number;\n\t/** Strings: length. Numbers: value. */\n\tmax?: number;\n\t/** Strings only: exact length. */\n\tlength?: number;\n\tregex?: RegExp;\n\t/** Strings only. Trims and lowercases before the format check. */\n\temail?: boolean;\n\turl?: boolean;\n\tstartsWith?: string;\n\tendsWith?: string;\n\t/** Numbers only. */\n\tint?: boolean;\n\t/** Allowed values. */\n\tenum?: readonly unknown[];\n\t/** Escape hatch - return true, or a message to fail with. */\n\tcheck?: (value: any) => boolean | string;\n};\n\n/** Plugin-owned field metadata. Outer key is the plugin namespace\n * (`\"http\"`, `\"db\"`, …); core never interprets the contents. */\nexport type AttrBag = Record<string, Record<string, unknown>>;\n\nexport interface TypeDefination<T, O, D = never> extends Rules {\n\tname: LiteralString;\n\ttype?: T;\n\toutput?: O;\n\tshape?: unknown;\n\t/** `function` types only: the declared input of the expected fn -\n\t * plain closures get it validated at their door on every call. */\n\tfnInput?: unknown;\n\t/** Used when the incoming value is `undefined`. A zero-arg function\n\t * is called (fresh value per validate) except on `function` schemas,\n\t * where the default IS the fn. */\n\tdefault?: D | (() => D);\n\t/** When true, `undefined` and `null` pass straight through unvalidated. */\n\toptional?: boolean;\n\ttransform?: (value: any) => O;\n\t/** Opaque plugin attributes - ignored by validate / Infer*. */\n\t$attrs?: AttrBag;\n}\n\nexport type TypeOptions<T, O> = {\n\ttransform?: (value: T) => O;\n\t/** Accepted on every helper; overloads refine the output when `true`. */\n\toptional?: boolean;\n};\n\n/**\n * `optional` widens the output with `| undefined | null`; `default` keeps\n * it narrow because a value is always produced. Declaring both means\n * optional to send, never absent.\n *\n * Helpers select among these via option-shape overloads rather than `Opt` /\n * `D` type parameters: providing a partial type argument (e.g.\n * `v.string<\"a\" | \"b\">`) would lock remaining params to their defaults, so\n * `{ optional: true }` would fail to type-check.\n */\ntype OutOf<O, D, Opt> = [Opt] extends [true]\n\t? [D] extends [never]\n\t\t? O | undefined | null\n\t\t: O\n\t: O;\n\n/**\n * Recover a type's output `O`. Plain `infer O` from\n * `TypeDefination<any, infer O, …>` drops `| undefined` because `output?`\n * is optional and TypeScript attributes the undefined to the property.\n * When the third type arg is `undefined` (optional, no default), put\n * `| undefined | null` back so handlers see the same absence validate\n * produces at runtime.\n */\ntype OutputOf<F> =\n\tF extends TypeDefination<any, infer O, infer D>\n\t\t? [D] extends [never]\n\t\t\t? O\n\t\t\t: undefined extends D\n\t\t\t\t? O | undefined | null\n\t\t\t\t: O\n\t\t: never;\n\ntype StringOptions<E extends string, O> = TypeOptions<E, O> &\n\tPick<\n\t\tRules,\n\t\t| \"min\"\n\t\t| \"max\"\n\t\t| \"length\"\n\t\t| \"regex\"\n\t\t| \"email\"\n\t\t| \"url\"\n\t\t| \"startsWith\"\n\t\t| \"endsWith\"\n\t\t| \"check\"\n\t> & { enum?: readonly E[] };\n\ntype ArrayOptions<E, O> = TypeOptions<FieldOut<E>[], O> &\n\tPick<Rules, \"min\" | \"max\" | \"length\" | \"check\">;\n\ntype UnionOptions<T extends readonly unknown[], O> = TypeOptions<\n\tFieldOut<T[number]>,\n\tO\n> &\n\tPick<Rules, \"check\">;\n\ntype NumberOptions<O> = TypeOptions<number, O> &\n\tPick<Rules, \"min\" | \"max\" | \"int\" | \"check\"> & {\n\t\tenum?: readonly number[];\n\t};\n\nexport type InferType<T> =\n\tT extends TypeDefination<infer T2, any, any> ? T2 : never;\n\nexport type InferOutput<T> =\n\tT extends TypeDefination<any, any, any> ? OutputOf<T> : never;\n\nexport type DefineInput<I> = Prettify<{\n\t[K in keyof I]: FieldIn<I[K]>;\n}>;\n\n/** Keys whose field is OPTIONAL with no default: absent from the output\n * too, so they mark `?`. A defaulted field always produces a value and\n * stays required. */\ntype OutOptional<O> = {\n\t[K in keyof O]: [DefaultOf<O[K]>] extends [never]\n\t\t? never\n\t\t: [DefaultOf<O[K]>] extends [undefined]\n\t\t\t? K\n\t\t\t: never;\n}[keyof O];\n\nexport type DefineOutput<O> = Prettify<\n\t{ [K in keyof O as K extends OutOptional<O> ? never : K]: FieldOut<O[K]> } & {\n\t\t[K in keyof O as K extends OutOptional<O> ? K : never]?: FieldOut<O[K]>;\n\t}\n>;\n\n/**\n * A handler-less `v.fn({ input, output })` used as a schema describes\n * \"a fn from `input` to `output`\" - the VALUE is the fn itself. Two\n * views of the same signature:\n *\n * `SchemaFnIn` is the PROVIDER's side - what a caller must hand over.\n * Like any handler, their fn receives the PARSED input (validation runs\n * at its door) and returns the declared output, sync or async.\n *\n * `SchemaFnOut` is the CONSUMER's side (`c.input.x`) - the handler calls\n * it with RAW args, exactly like calling the fn it stands in for.\n *\n * No declared input means the signature is UNSPECIFIED, not zero-arg -\n * any fn fits (`create: v.fn`), so the args stay open.\n */\ntype SchemaFnIn<FI, FO> = (\n\t...args: unknown extends FI ? any[] : [input: InferInput<FI>]\n) => unknown extends FO\n\t? any\n\t: InferInput<OutputSchemaOf<FO>> | Promise<InferInput<OutputSchemaOf<FO>>>;\n\ntype SchemaFnOut<FI, FO> = (\n\t...args: unknown extends FI ? any[] : [input: InferArgs<FI>]\n) => unknown extends FO\n\t? any\n\t: InferInput<OutputSchemaOf<FO>> | Promise<InferInput<OutputSchemaOf<FO>>>;\n\n/**\n * A fn schema whose input IS a var carries that var's name as an optional\n * phantom (`$fnVar`, tuple-wrapped so a plain fn can never false-match).\n * Scope resolution reads it to WIDEN the fn's args with everything the\n * scope mounts on that var - see `WidenSchemaFns`. Optional, so any plain\n * closure still satisfies the type.\n */\nexport type FnVarBrand<FI> = FI extends {\n\t$var: true;\n\tname: infer N extends string;\n}\n\t? { readonly $fnVar?: [N] }\n\t: unknown;\n\n/**\n * A declared `output` comes in two forms: a bare schema (the signature\n * AND the exit check), or the wrapper `{ def?, validation? }` splitting\n * what the fn PROMISES from what gets CHECKED - `{ def }` documents\n * without paying runtime validation, `{ def, validation }` checks with a\n * different (usually looser) schema than it documents. The wrapper is\n * recognized by its keys, so an output that IS an object with only\n * `def`/`validation` fields must be written `v.object({...})`.\n *\n * `OutputSchemaOf` is the type-level unwrap - the schema the fn's return\n * type (and its rendered signature) comes from.\n */\nexport type OutputSchemaOf<O> =\n\tExclude<keyof O, \"def\" | \"validation\"> extends never\n\t\t? O extends { def: infer D }\n\t\t\t? D\n\t\t\t: O extends { validation: infer Vl }\n\t\t\t\t? Vl\n\t\t\t\t: O\n\t\t: O;\n\n/** The runtime unwrap: `def` is the documented schema (falls back to\n * `validation`), `validation` is what the exit check runs - undefined\n * means no check. A bare schema is both. */\nexport const outputContract = (\n\toutput: unknown,\n): { def?: unknown; validation?: unknown } => {\n\tif (output === undefined) return {};\n\tif (\n\t\toutput !== null &&\n\t\ttypeof output === \"object\" &&\n\t\t!Array.isArray(output) &&\n\t\t!isType(output) &&\n\t\t!isVar(output) &&\n\t\t!isFnSchema(output)\n\t) {\n\t\tconst keys = Object.keys(output);\n\t\tif (\n\t\t\tkeys.length > 0 &&\n\t\t\tkeys.every((k) => k === \"def\" || k === \"validation\")\n\t\t) {\n\t\t\tconst { def, validation } = output as {\n\t\t\t\tdef?: unknown;\n\t\t\t\tvalidation?: unknown;\n\t\t\t};\n\t\t\treturn { def: def ?? validation, validation };\n\t\t}\n\t}\n\treturn { def: output, validation: output };\n};\n\n/**\n * One input field, in five flavours:\n * - a `v.var()`, whose shape comes from the var's own `schema`\n * - a handler-less `v.fn(...)` builder, which types the field as a FN\n * - a type from `v.string()` / `v.object()` / ...\n * - a bare nested record, which recurses\n * - anything else (e.g. `null`, `\"lit\"`) kept as itself - so\n * `v.union([user, null])` infers `User | null`, not just `User`\n *\n * The record case has to come after TypeDefination: a TypeDefination is\n * itself a record, and so is a builder.\n */\ntype FieldOut<F> = F extends { $var: true; schema?: infer S }\n\t? InferInput<NonNullable<S>>\n\t: F extends { $fnSchema: { input?: infer FI; output?: infer FO } }\n\t\t? FnSchemaOut<F, SchemaFnOut<FI, FO> & FnVarBrand<FI>>\n\t\t: F extends TypeDefination<any, any, any>\n\t\t\t? OutputOf<F>\n\t\t\t: F extends Record<string, unknown>\n\t\t\t\t? Prettify<{ [K in keyof F]: FieldOut<F[K]> }>\n\t\t\t\t: F;\n\ntype FieldIn<F> = F extends { $var: true; schema?: infer S }\n\t? InferArgs<NonNullable<S>>\n\t: F extends { $fnSchema: { input?: infer FI; output?: infer FO } }\n\t\t? SchemaFnIn<FI, FO> & FnVarBrand<FI>\n\t\t: F extends TypeDefination<infer T, any, infer D>\n\t\t\t? undefined extends D\n\t\t\t\t? T | null\n\t\t\t\t: T\n\t\t\t: F extends Record<string, unknown>\n\t\t\t\t? ArgsShape<F>\n\t\t\t\t: F;\n\n/**\n * `optional: true` on `v.fn.type` widens the same way a type's `optional`\n * does: absent without a default means the value may be `undefined` or\n * `null`.\n */\ntype FnSchemaOut<F, Fn> = F extends { optional: true }\n\t? F extends { default: infer _D }\n\t\t? Fn\n\t\t: Fn | undefined | null\n\t: Fn;\n\n/**\n * A field's declared default, looked through a var to its schema. Only a\n * TYPE's default counts - a var's own default is its initial value, not a\n * licence to omit the input. The `$fnSchema` guard mirrors `asType`'s\n * ordering: a bare `v.fn` is CALLABLE, and any callable duck-matches\n * TypeDefination (`.name` comes with every function), which would read a\n * phantom default off it and wrongly mark the field optional. `v.fn.type`\n * may still declare `optional` / `default` on the carrier itself.\n */\ntype DefaultOf<F> = F extends { $var: true; schema?: infer S }\n\t? NonNullable<S> extends TypeDefination<any, any, infer D>\n\t\t? D\n\t\t: never\n\t: F extends { $fnSchema: unknown }\n\t\t? F extends { optional: true }\n\t\t\t? F extends { default: infer D }\n\t\t\t\t? D\n\t\t\t\t: undefined\n\t\t\t: F extends { default: infer D }\n\t\t\t\t? D\n\t\t\t\t: never\n\t\t: F extends TypeDefination<any, any, infer D>\n\t\t\t? D\n\t\t\t: never;\n\ntype Defaulted<I> = {\n\t[K in keyof I]: [DefaultOf<I[K]>] extends [never] ? never : K;\n}[keyof I];\n\n/** Defaulted keys are optional to send, but always present in the handler. */\ntype ArgsShape<I> = Prettify<\n\t{ [K in keyof I as K extends Defaulted<I> ? never : K]: FieldIn<I[K]> } & {\n\t\t[K in keyof I as K extends Defaulted<I> ? K : never]?: FieldIn<I[K]>;\n\t}\n>;\n\n/**\n * Post-transform shape - what a handler sees. The `$var` branch must come\n * first: a var's `name` property duck-matches TypeDefination, and falling\n * into that branch reads the var's VALUE type instead of its schema. A\n * TUPLE input maps position by position - the fn takes that many args.\n */\nexport type InferInput<I> = I extends { $var: true; schema?: infer S }\n\t? InferInput<NonNullable<S>>\n\t: I extends { $fnSchema: { input?: infer FI; output?: infer FO } }\n\t\t? SchemaFnOut<FI, FO> & FnVarBrand<FI>\n\t\t: I extends readonly unknown[]\n\t\t\t? { -readonly [K in keyof I]: InferInput<I[K]> }\n\t\t\t: I extends TypeDefination<any, any, any>\n\t\t\t\t? OutputOf<I>\n\t\t\t\t: Prettify<{ [K in keyof I]: FieldOut<I[K]> }>;\n\n/** Pre-transform shape - what a caller sends. Same branch order. */\nexport type InferArgs<I> = I extends { $var: true; schema?: infer S }\n\t? InferArgs<NonNullable<S>>\n\t: I extends { $fnSchema: { input?: infer FI; output?: infer FO } }\n\t\t? SchemaFnIn<FI, FO> & FnVarBrand<FI>\n\t\t: I extends readonly unknown[]\n\t\t\t? { -readonly [K in keyof I]: InferArgs<I[K]> }\n\t\t\t: I extends TypeDefination<infer T, any, infer D>\n\t\t\t\t? undefined extends D\n\t\t\t\t\t? T | null\n\t\t\t\t\t: T\n\t\t\t\t: ArgsShape<I>;\n\nexport const isType = (value: any): value is TypeDefination<any, any> =>\n\ttypeof value?.name === \"string\";\n\n/** A handler-less `v.fn(...)` builder doubles as a schema: the value it\n * describes is a FN with the declared signature. The builder FN itself is\n * branded too, so bare `v.fn` reads as \"any function\". */\nexport const isFnSchema = (\n\tvalue: any,\n): value is {\n\t$fnSchema: { input?: unknown; output?: unknown };\n\toptional?: boolean;\n\tdefault?: unknown;\n} => typeof value?.$fnSchema === \"object\" && value.$fnSchema !== null;\n\nexport const asType = (value: any): TypeDefination<any, any> =>\n\t// A var's own `name` (\"user\") would duck-match isType, so unwrap first -\n\t// and a builder is a record, so it must be caught before the fallback.\n\tisVar(value)\n\t\t? asType(value.schema ?? {})\n\t\t: isFnSchema(value)\n\t\t\t? ({\n\t\t\t\t\tname: \"function\",\n\t\t\t\t\tfnInput: value.$fnSchema.input,\n\t\t\t\t\t...(value.optional ? { optional: true } : {}),\n\t\t\t\t\t...(value.default !== undefined ? { default: value.default } : {}),\n\t\t\t\t} as TypeDefination<any, any>)\n\t\t\t: isType(value)\n\t\t\t\t? value\n\t\t\t\t: // Bare literals in `v.union([schema, null])` / `[\"a\", \"b\"]`:\n\t\t\t\t\t// map to a type whose `name` matches `typeOf`, with `enum`\n\t\t\t\t\t// pinning the exact value for string/number/boolean.\n\t\t\t\t\tvalue === null\n\t\t\t\t\t? ({ name: \"null\" } as TypeDefination<null, null>)\n\t\t\t\t\t: value === undefined\n\t\t\t\t\t\t? ({ name: \"undefined\" } as TypeDefination<undefined, undefined>)\n\t\t\t\t\t\t: typeof value === \"string\" ||\n\t\t\t\t\t\t\t\ttypeof value === \"number\" ||\n\t\t\t\t\t\t\t\ttypeof value === \"boolean\"\n\t\t\t\t\t\t\t? ({\n\t\t\t\t\t\t\t\t\tname: typeof value,\n\t\t\t\t\t\t\t\t\tenum: [value],\n\t\t\t\t\t\t\t\t} as TypeDefination<any, any>)\n\t\t\t\t\t\t\t: { name: \"object\", shape: value };\n\n/**\n * Replace the whole `$attrs` bag. On a var, rebinds `customize` so a later\n * customize keeps these attrs (the original closure closes over pre-attr\n * options and would otherwise drop them).\n */\nconst withAttrBag = <S>(schema: S, bag: AttrBag): S => {\n\tif (isVar(schema)) {\n\t\tconst v = schema as {\n\t\t\t$attrs?: AttrBag;\n\t\t\tcustomize: (opts: any) => unknown;\n\t\t\t[key: string]: unknown;\n\t\t};\n\t\treturn {\n\t\t\t...v,\n\t\t\t$attrs: bag,\n\t\t\tcustomize: (opts: any) => withAttrBag(v.customize(opts) as S, bag),\n\t\t} as S;\n\t}\n\treturn { ...asType(schema), $attrs: bag } as S;\n};\n\n/**\n * Attach plugin attributes under `namespace`, deep-merging with any\n * already on the schema. Returns a new type def (or var) with the same\n * value type. Core never reads these - only plugin edges do.\n *\n * Passed a var, attributes land on the var itself (`$attrs`) and the\n * `$var` / `name` / `schema` identity is preserved; `customize` is rebound\n * so attrs survive further customization.\n */\nexport const withAttrs = <S>(\n\tschema: S,\n\tnamespace: string,\n\tattrs: Record<string, unknown>,\n): S => {\n\tconst prev = (attrsOf(schema) ?? {}) as AttrBag;\n\treturn withAttrBag(schema, {\n\t\t...prev,\n\t\t[namespace]: { ...(prev[namespace] ?? {}), ...attrs },\n\t});\n};\n\n/** Read the whole attr bag, or one plugin namespace. */\nexport function attrsOf(schema: unknown): AttrBag | undefined;\nexport function attrsOf(\n\tschema: unknown,\n\tnamespace: string,\n): Record<string, unknown> | undefined;\nexport function attrsOf(\n\tschema: unknown,\n\tnamespace?: string,\n): AttrBag | Record<string, unknown> | undefined {\n\tif (schema === null || schema === undefined) return undefined;\n\t// Vars carry whole-var attrs on themselves; field attrs live on the\n\t// schema type def. Do not unwrap through asType or var identity is\n\t// lost and whole-var attrs become invisible.\n\tconst bag = isVar(schema)\n\t\t? (schema as { $attrs?: AttrBag }).$attrs\n\t\t: asType(schema).$attrs;\n\tif (!bag) return undefined;\n\treturn namespace === undefined ? bag : bag[namespace];\n}\n\nexport const typeOf = (value: unknown) =>\n\tvalue === null\n\t\t? \"null\"\n\t\t: Array.isArray(value)\n\t\t\t? \"array\"\n\t\t\t: Number.isNaN(value)\n\t\t\t\t? \"NaN\"\n\t\t\t\t: typeof value;\n\nexport const isVar = (value: any): boolean => value?.$var === true;\n\n// Zod's email regex\n// The author has written about this explicitly: trying to accept every technically valid email address leads to overly complex,\n// hard-to-maintain, and sometimes ReDoS-vulnerable regexes that still reject real-world addresses people actually use.\n// Zod prioritizes a practical filter that works well for the vast majority of real user-entered emails.\nconst EMAIL =\n\t/^(?!\\.)(?!.*\\.\\.)([a-z0-9_'+\\-.]*)[a-z0-9_+-]@([a-z0-9][a-z0-9-]*\\.)+[a-z]{2,}$/;\n\nconst fail = (path: string, message: string): never => {\n\tthrow new ValidationError(path, message);\n};\n\n/** Constraint checks, run after the value's type is known to be right. */\nconst applyRules = (def: Rules, value: any, path: string) => {\n\tif (def.enum && !def.enum.includes(value)) {\n\t\tfail(path, `expected one of ${def.enum.join(\", \")}, received ${value}`);\n\t}\n\tif (typeof value === \"string\") {\n\t\tif (def.length !== undefined && value.length !== def.length) {\n\t\t\tfail(path, `expected length ${def.length}, received ${value.length}`);\n\t\t}\n\t\tif (def.min !== undefined && value.length < def.min) {\n\t\t\tfail(\n\t\t\t\tpath,\n\t\t\t\t`expected at least ${def.min} characters, received ${value.length}`,\n\t\t\t);\n\t\t}\n\t\tif (def.max !== undefined && value.length > def.max) {\n\t\t\tfail(\n\t\t\t\tpath,\n\t\t\t\t`expected at most ${def.max} characters, received ${value.length}`,\n\t\t\t);\n\t\t}\n\t\tif (def.regex && !def.regex.test(value)) {\n\t\t\tfail(path, `does not match ${def.regex}`);\n\t\t}\n\t\tif (def.email && !EMAIL.test(value))\n\t\t\tfail(path, \"expected an email address\");\n\t\tif (def.url) {\n\t\t\ttry {\n\t\t\t\tnew URL(value);\n\t\t\t} catch {\n\t\t\t\tfail(path, \"expected a URL\");\n\t\t\t}\n\t\t}\n\t\tif (def.startsWith !== undefined && !value.startsWith(def.startsWith)) {\n\t\t\tfail(path, `expected to start with \"${def.startsWith}\"`);\n\t\t}\n\t\tif (def.endsWith !== undefined && !value.endsWith(def.endsWith)) {\n\t\t\tfail(path, `expected to end with \"${def.endsWith}\"`);\n\t\t}\n\t}\n\tif (Array.isArray(value)) {\n\t\tif (def.length !== undefined && value.length !== def.length) {\n\t\t\tfail(path, `expected length ${def.length}, received ${value.length}`);\n\t\t}\n\t\tif (def.min !== undefined && value.length < def.min) {\n\t\t\tfail(\n\t\t\t\tpath,\n\t\t\t\t`expected at least ${def.min} items, received ${value.length}`,\n\t\t\t);\n\t\t}\n\t\tif (def.max !== undefined && value.length > def.max) {\n\t\t\tfail(path, `expected at most ${def.max} items, received ${value.length}`);\n\t\t}\n\t}\n\tif (typeof value === \"number\") {\n\t\tif (def.int && !Number.isInteger(value)) {\n\t\t\tfail(path, `expected an integer, received ${value}`);\n\t\t}\n\t\tif (def.min !== undefined && value < def.min) {\n\t\t\tfail(path, `expected >= ${def.min}, received ${value}`);\n\t\t}\n\t\tif (def.max !== undefined && value > def.max) {\n\t\t\tfail(path, `expected <= ${def.max}, received ${value}`);\n\t\t}\n\t}\n\tif (def.check) {\n\t\tconst result = def.check(value);\n\t\tif (result !== true) {\n\t\t\tfail(path, typeof result === \"string\" ? result : \"failed check\");\n\t\t}\n\t}\n};\n\nexport const validate = (\n\tdef: TypeDefination<any, any, any>,\n\tvalue: unknown,\n\tpath: string,\n): any => {\n\t// `undefined` / (when optional) `null` fall back to the declared\n\t// default before anything else, then to `optional`, which passes the\n\t// absence through untouched. A shaped object with no default treats\n\t// omit as `{}` so all-optional fields can be left off the call without\n\t// a dummy payload. Non-optional `null` falls through to the type check.\n\tif (value === undefined || (value === null && def.optional)) {\n\t\tif (def.default !== undefined) {\n\t\t\t// Factories produce a fresh value each time - needed for Date /\n\t\t\t// object / array defaults. Skip on `function` schemas: there the\n\t\t\t// default IS the fn.\n\t\t\tvalue =\n\t\t\t\ttypeof def.default === \"function\" && def.name !== \"function\"\n\t\t\t\t\t? (def.default as () => unknown)()\n\t\t\t\t\t: def.default;\n\t\t} else if (def.optional) return value;\n\t\telse if (def.name === \"object\" && def.shape !== undefined) value = {};\n\t}\n\t// A var used as an input field validates against its own schema. An\n\t// absent value is left alone so the var keeps its default.\n\tif (isVar(def)) {\n\t\tif (value === undefined) return undefined;\n\t\tconst schema = (def as any).schema;\n\t\treturn schema === undefined ? value : validate(schema, value, path);\n\t}\n\tif (def.name === \"any\") {\n\t\treturn def.transform ? def.transform(value) : value;\n\t}\n\tif (def.name === \"date\") {\n\t\tif (!(value instanceof Date)) {\n\t\t\tthrow new ValidationError(\n\t\t\t\tpath,\n\t\t\t\t`expected date, received ${typeOf(value)}`,\n\t\t\t);\n\t\t}\n\t\treturn def.transform ? def.transform(value) : value;\n\t}\n\tif (def.name === \"function\") {\n\t\tif (typeof value !== \"function\") {\n\t\t\tthrow new ValidationError(\n\t\t\t\tpath,\n\t\t\t\t`expected function, received ${typeOf(value)}`,\n\t\t\t);\n\t\t}\n\t\t// A branded fn (`$fn`) validates its own declared input at its own\n\t\t// door; a plain closure gets THIS schema's input validated for it.\n\t\tconst inner = def.fnInput;\n\t\tif (inner === undefined || (value as { $fn?: boolean }).$fn === true) {\n\t\t\treturn value;\n\t\t}\n\t\tconst innerType = asType(inner);\n\t\treturn (input?: unknown, parent?: unknown) =>\n\t\t\t(value as (i: unknown, p: unknown) => unknown)(\n\t\t\t\tvalidate(innerType, input, `${path}()`),\n\t\t\t\tparent,\n\t\t\t);\n\t}\n\tif (def.name === \"array\") {\n\t\tif (!Array.isArray(value)) {\n\t\t\tthrow new ValidationError(\n\t\t\t\tpath,\n\t\t\t\t`expected array, received ${typeOf(value)}`,\n\t\t\t);\n\t\t}\n\t\tapplyRules(def, value, path);\n\t\t// No declared element (`v.array()`): ANY array - passed through\n\t\t// as-is, elements untouched.\n\t\tif (def.shape === undefined) {\n\t\t\treturn def.transform ? def.transform(value) : value;\n\t\t}\n\t\t// Every element validates - ALL failures report together, not\n\t\t// just the first, mirroring object fields.\n\t\tconst elementType = asType(def.shape);\n\t\tconst items: unknown[] = [];\n\t\tconst problems: Issue[] = [];\n\t\tfor (let index = 0; index < value.length; index++) {\n\t\t\ttry {\n\t\t\t\titems.push(validate(elementType, value[index], `${path}[${index}]`));\n\t\t\t} catch (thrown) {\n\t\t\t\tif (!(thrown instanceof ValidationError)) throw thrown;\n\t\t\t\tproblems.push(...thrown.issues);\n\t\t\t}\n\t\t}\n\t\tconst firstProblem = problems[0];\n\t\tif (firstProblem) {\n\t\t\tthrow new ValidationError(\n\t\t\t\tfirstProblem.path,\n\t\t\t\tfirstProblem.message,\n\t\t\t\tproblems,\n\t\t\t);\n\t\t}\n\t\treturn def.transform ? def.transform(items) : items;\n\t}\n\tif (def.name === \"object\") {\n\t\tif (typeOf(value) !== \"object\") {\n\t\t\tthrow new ValidationError(\n\t\t\t\tpath,\n\t\t\t\t`expected object, received ${typeOf(value)}`,\n\t\t\t);\n\t\t}\n\t\t// No declared shape (`v.object()`): ANY object - passed through\n\t\t// as-is, nothing stripped.\n\t\tif (def.shape === undefined) {\n\t\t\treturn def.transform ? def.transform(value) : value;\n\t\t}\n\t\t// Every field validates - ALL failures report together, not just\n\t\t// the first. Three bad fields is one error with three issues.\n\t\tconst parsed: Record<string, unknown> = {};\n\t\tconst issues: Issue[] = [];\n\t\tfor (const [field, child] of Object.entries(\n\t\t\tdef.shape as Record<string, unknown>,\n\t\t)) {\n\t\t\ttry {\n\t\t\t\tconst parsedField = validate(\n\t\t\t\t\tasType(child),\n\t\t\t\t\t(value as Record<string, unknown>)[field],\n\t\t\t\t\t`${path}.${field}`,\n\t\t\t\t);\n\t\t\t\t// An absent optional field stays ABSENT - materializing the key\n\t\t\t\t// as `undefined` would clobber values it gets spread over.\n\t\t\t\tif (parsedField !== undefined) parsed[field] = parsedField;\n\t\t\t} catch (thrown) {\n\t\t\t\tif (!(thrown instanceof ValidationError)) throw thrown;\n\t\t\t\tissues.push(...thrown.issues);\n\t\t\t}\n\t\t}\n\t\tconst firstIssue = issues[0];\n\t\tif (firstIssue) {\n\t\t\tthrow new ValidationError(firstIssue.path, firstIssue.message, issues);\n\t\t}\n\t\treturn def.transform ? def.transform(parsed) : parsed;\n\t}\n\tif (def.name === \"union\") {\n\t\t// Try each option in order - first success wins. All failures\n\t\t// report together so callers see every branch's issues.\n\t\tconst options = def.shape;\n\t\tif (!Array.isArray(options) || options.length === 0) {\n\t\t\tthrow new ValidationError(path, \"expected a non-empty union\");\n\t\t}\n\t\tconst issues: Issue[] = [];\n\t\tlet parsed: unknown;\n\t\tlet matched = false;\n\t\tfor (const member of options) {\n\t\t\ttry {\n\t\t\t\tparsed = validate(asType(member), value, path);\n\t\t\t\tmatched = true;\n\t\t\t\tbreak;\n\t\t\t} catch (thrown) {\n\t\t\t\tif (!(thrown instanceof ValidationError)) throw thrown;\n\t\t\t\tissues.push(...thrown.issues);\n\t\t\t}\n\t\t}\n\t\tif (!matched) {\n\t\t\tconst firstIssue = issues[0];\n\t\t\tif (firstIssue) {\n\t\t\t\tthrow new ValidationError(firstIssue.path, firstIssue.message, issues);\n\t\t\t}\n\t\t\tthrow new ValidationError(\n\t\t\t\tpath,\n\t\t\t\t`expected union, received ${typeOf(value)}`,\n\t\t\t);\n\t\t}\n\t\tapplyRules(def, parsed, path);\n\t\treturn def.transform ? def.transform(parsed) : parsed;\n\t}\n\tif (typeOf(value) !== def.name) {\n\t\tthrow new ValidationError(\n\t\t\tpath,\n\t\t\t`expected ${def.name}, received ${typeOf(value)}`,\n\t\t);\n\t}\n\t// Canonicalize before rules so padded / mixed-case addresses pass the\n\t// email regex and handlers always see the normalized form.\n\tif (def.email && typeof value === \"string\") {\n\t\tvalue = value.trim().toLowerCase();\n\t}\n\tapplyRules(def, value, path);\n\treturn def.transform ? def.transform(value) : value;\n};\n\n/** Builds the runtime object; the declared return type is the contract. */\nconst build = (name: string, options: any, extra?: any): any => ({\n\tname,\n\t...extra,\n\t...options,\n});\n\n/** A default may be the value itself or a factory that mints it fresh on\n * each validate - `() => new Date()`, `() => []`, …. */\ntype DefaultInput<T> = T | (() => T);\n\n/**\n * Call signatures for the type helpers. Option-shape overloads replace\n * `Opt` / `D` type parameters so a partial type argument (literal narrowing)\n * does not lock `optional` / `default` to their defaults.\n */\ntype StringFn = {\n\t<const E extends string, O = E>(\n\t\toptions: StringOptions<E, O> & {\n\t\t\toptional: true;\n\t\t\tdefault: DefaultInput<string>;\n\t\t},\n\t): TypeDefination<E, O, string>;\n\t<const E extends string, O = E>(\n\t\toptions: StringOptions<E, O> & { optional: true },\n\t): TypeDefination<E, OutOf<O, never, true>, undefined>;\n\t<const E extends string, O = E>(\n\t\toptions: StringOptions<E, O> & { default: DefaultInput<string> },\n\t): TypeDefination<E, O, string>;\n\t<const E extends string, O = E>(\n\t\toptions?: StringOptions<E, O>,\n\t): TypeDefination<E, O, never>;\n};\n\ntype NumberFn = {\n\t<O = number>(\n\t\toptions: NumberOptions<O> & {\n\t\t\toptional: true;\n\t\t\tdefault: DefaultInput<number>;\n\t\t},\n\t): TypeDefination<number, O, number>;\n\t<O = number>(\n\t\toptions: NumberOptions<O> & { optional: true },\n\t): TypeDefination<number, OutOf<O, never, true>, undefined>;\n\t<O = number>(\n\t\toptions: NumberOptions<O> & { default: DefaultInput<number> },\n\t): TypeDefination<number, O, number>;\n\t<O = number>(options?: NumberOptions<O>): TypeDefination<number, O, never>;\n};\n\ntype BooleanFn = {\n\t<O = boolean>(\n\t\toptions: TypeOptions<boolean, O> & {\n\t\t\toptional: true;\n\t\t\tdefault: DefaultInput<boolean>;\n\t\t},\n\t): TypeDefination<boolean, O, boolean>;\n\t<O = boolean>(\n\t\toptions: TypeOptions<boolean, O> & { optional: true },\n\t): TypeDefination<boolean, OutOf<O, never, true>, undefined>;\n\t<O = boolean>(\n\t\toptions: TypeOptions<boolean, O> & { default: DefaultInput<boolean> },\n\t): TypeDefination<boolean, O, boolean>;\n\t<O = boolean>(\n\t\toptions?: TypeOptions<boolean, O>,\n\t): TypeDefination<boolean, O, never>;\n};\n\ntype DateFn = {\n\t<O = Date>(\n\t\toptions: TypeOptions<Date, O> & {\n\t\t\toptional: true;\n\t\t\tdefault: DefaultInput<Date>;\n\t\t},\n\t): TypeDefination<Date, O, Date>;\n\t<O = Date>(\n\t\toptions: TypeOptions<Date, O> & { optional: true },\n\t): TypeDefination<Date, OutOf<O, never, true>, undefined>;\n\t<O = Date>(\n\t\toptions: TypeOptions<Date, O> & { default: DefaultInput<Date> },\n\t): TypeDefination<Date, O, Date>;\n\t<O = Date>(options?: TypeOptions<Date, O>): TypeDefination<Date, O, never>;\n};\n\ntype AnyFn = {\n\t<T = unknown>(\n\t\toptions: TypeOptions<T, T> & { optional: true; default: DefaultInput<T> },\n\t): TypeDefination<T, T, T>;\n\t<T = unknown>(\n\t\toptions: TypeOptions<T, T> & { optional: true },\n\t): TypeDefination<T, OutOf<T, never, true>, undefined>;\n\t<T = unknown>(\n\t\toptions: TypeOptions<T, T> & { default: DefaultInput<T> },\n\t): TypeDefination<T, T, T>;\n\t<T = unknown>(options?: TypeOptions<T, T>): TypeDefination<T, T, never>;\n};\n\n/**\n * Object defaults may be partial: nested fields still run through\n * validate (so their own defaults apply). An empty `{}` is always\n * fine at the type level - parent `optional` / `default` must not\n * demand that every required child be listed in the default.\n */\ntype ObjectDefault<S> = DefaultInput<Partial<ArgsShape<S>>>;\n\ntype ObjectFn = {\n\t<S, O = DefineOutput<S>>(\n\t\tshape: S,\n\t\toptions: TypeOptions<DefineOutput<S>, O> & {\n\t\t\toptional: true;\n\t\t\tdefault: ObjectDefault<S>;\n\t\t},\n\t): TypeDefination<ArgsShape<S>, O, ArgsShape<S>>;\n\t<S, O = DefineOutput<S>>(\n\t\tshape: S,\n\t\toptions: TypeOptions<DefineOutput<S>, O> & { optional: true },\n\t): TypeDefination<ArgsShape<S>, OutOf<O, never, true>, undefined>;\n\t<S, O = DefineOutput<S>>(\n\t\tshape: S,\n\t\toptions: TypeOptions<DefineOutput<S>, O> & {\n\t\t\tdefault: ObjectDefault<S>;\n\t\t},\n\t): TypeDefination<ArgsShape<S>, O, ArgsShape<S>>;\n\t<S, O = DefineOutput<S>>(\n\t\tshape: S,\n\t\toptions?: TypeOptions<DefineOutput<S>, O>,\n\t): TypeDefination<ArgsShape<S>, O, never>;\n\t(): TypeDefination<Record<string, any>, Record<string, any>>;\n};\n\ntype ArrayFn = {\n\t<E, O = FieldOut<E>[]>(\n\t\telement: E,\n\t\toptions: ArrayOptions<E, O> & {\n\t\t\toptional: true;\n\t\t\t// Defaults are validated as inputs, so they use FieldIn.\n\t\t\tdefault: DefaultInput<FieldIn<E>[]>;\n\t\t},\n\t): TypeDefination<FieldIn<E>[], O, FieldIn<E>[]>;\n\t<E, O = FieldOut<E>[]>(\n\t\telement: E,\n\t\toptions: ArrayOptions<E, O> & { optional: true },\n\t): TypeDefination<FieldIn<E>[], OutOf<O, never, true>, undefined>;\n\t<E, O = FieldOut<E>[]>(\n\t\telement: E,\n\t\toptions: ArrayOptions<E, O> & { default: DefaultInput<FieldIn<E>[]> },\n\t): TypeDefination<FieldIn<E>[], O, FieldIn<E>[]>;\n\t<E, O = FieldOut<E>[]>(\n\t\telement: E,\n\t\toptions?: ArrayOptions<E, O>,\n\t): TypeDefination<FieldIn<E>[], O, never>;\n\t(\n\t\telement?: undefined,\n\t\toptions?: ArrayOptions<undefined, any[]> & {\n\t\t\toptional: true;\n\t\t\tdefault: DefaultInput<any[]>;\n\t\t},\n\t): TypeDefination<any[], any[], any[]>;\n\t(\n\t\telement?: undefined,\n\t\toptions?: ArrayOptions<undefined, any[]> & { optional: true },\n\t): TypeDefination<any[], any[] | undefined | null, undefined>;\n\t(\n\t\telement?: undefined,\n\t\toptions?: ArrayOptions<undefined, any[]> & {\n\t\t\tdefault: DefaultInput<any[]>;\n\t\t},\n\t): TypeDefination<any[], any[], any[]>;\n\t(\n\t\telement?: undefined,\n\t\toptions?: ArrayOptions<undefined, any[]>,\n\t): TypeDefination<any[], any[], never>;\n};\n\ntype UnionFn = {\n\t<const T extends readonly [unknown, ...unknown[]], O = FieldOut<T[number]>>(\n\t\tmembers: T,\n\t\toptions: UnionOptions<T, O> & {\n\t\t\toptional: true;\n\t\t\tdefault: DefaultInput<FieldIn<T[number]>>;\n\t\t},\n\t): TypeDefination<FieldIn<T[number]>, O, FieldIn<T[number]>>;\n\t<const T extends readonly [unknown, ...unknown[]], O = FieldOut<T[number]>>(\n\t\tmembers: T,\n\t\toptions: UnionOptions<T, O> & { optional: true },\n\t): TypeDefination<FieldIn<T[number]>, OutOf<O, never, true>, undefined>;\n\t<const T extends readonly [unknown, ...unknown[]], O = FieldOut<T[number]>>(\n\t\tmembers: T,\n\t\toptions: UnionOptions<T, O> & {\n\t\t\tdefault: DefaultInput<FieldIn<T[number]>>;\n\t\t},\n\t): TypeDefination<FieldIn<T[number]>, O, FieldIn<T[number]>>;\n\t<const T extends readonly [unknown, ...unknown[]], O = FieldOut<T[number]>>(\n\t\tmembers: T,\n\t\toptions?: UnionOptions<T, O>,\n\t): TypeDefination<FieldIn<T[number]>, O, never>;\n};\n\nexport const vTypes = {\n\t/** An `enum` narrows both sides to the literal union: `v.string({\n\t * enum: [\"a\", \"b\"] })` types as `\"a\" | \"b\"`, not `string`. */\n\tstring: ((options?: any) => build(\"string\", options)) as StringFn,\n\tnumber: ((options?: any) => build(\"number\", options)) as NumberFn,\n\tboolean: ((options?: any) => build(\"boolean\", options)) as BooleanFn,\n\t/** A Date INSTANCE - checked with `instanceof`, never parsed. */\n\tdate: ((options?: any) => build(\"date\", options)) as DateFn,\n\t/** Passthrough - validated as-is, never coerced or stripped. */\n\tany: ((options?: any) => build(\"any\", options)) as AnyFn,\n\t/** With a SHAPE every field validates; with NO shape (`v.object()`)\n\t * any object passes, as-is. */\n\tobject: ((shape?: any, options?: any) =>\n\t\tbuild(\"object\", options, shape === undefined ? {} : { shape })) as ObjectFn,\n\t/** With an ELEMENT every item validates - all failures report\n\t * together, like object fields; with NO element (`v.array()`) any\n\t * array passes, as-is. `min`/`max`/`length` count items. */\n\tarray: ((element?: any, options?: any) =>\n\t\tbuild(\n\t\t\t\"array\",\n\t\t\toptions,\n\t\t\telement === undefined ? {} : { shape: element },\n\t\t)) as ArrayFn,\n\t/** Try each option in order - first successful parse wins. All\n\t * failing branches report together when none match. */\n\tunion: ((members: any, options?: any) =>\n\t\tbuild(\"union\", options, { shape: members })) as UnionFn,\n};\n"],"mappings":";;;;;;AA8MA,MAAa,kBACZ,WAC6C;CAC7C,IAAI,WAAW,KAAA,GAAW,OAAO,CAAC;CAClC,IACC,WAAW,QACX,OAAO,WAAW,YAClB,CAAC,MAAM,QAAQ,MAAM,KACrB,CAAC,OAAO,MAAM,KACd,CAAC,MAAM,MAAM,KACb,CAAC,WAAW,MAAM,GACjB;EACD,MAAM,OAAO,OAAO,KAAK,MAAM;EAC/B,IACC,KAAK,SAAS,KACd,KAAK,OAAO,MAAM,MAAM,SAAS,MAAM,YAAY,GAClD;GACD,MAAM,EAAE,KAAK,eAAe;GAI5B,OAAO;IAAE,KAAK,OAAO;IAAY;GAAW;EAC7C;CACD;CACA,OAAO;EAAE,KAAK;EAAQ,YAAY;CAAO;AAC1C;AAgHA,MAAa,UAAU,UACtB,OAAO,OAAO,SAAS;;;;AAKxB,MAAa,cACZ,UAKI,OAAO,OAAO,cAAc,YAAY,MAAM,cAAc;AAEjE,MAAa,UAAU,UAGtB,MAAM,KAAK,IACR,OAAO,MAAM,UAAU,CAAC,CAAC,IACzB,WAAW,KAAK,IACd;CACD,MAAM;CACN,SAAS,MAAM,UAAU;CACzB,GAAI,MAAM,WAAW,EAAE,UAAU,KAAK,IAAI,CAAC;CAC3C,GAAI,MAAM,YAAY,KAAA,IAAY,EAAE,SAAS,MAAM,QAAQ,IAAI,CAAC;AACjE,IACC,OAAO,KAAK,IACX,QAID,UAAU,OACP,EAAE,MAAM,OAAO,IAChB,UAAU,KAAA,IACR,EAAE,MAAM,YAAY,IACrB,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