@fuzdev/fuz_app 0.169.0 → 0.171.0
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/dist/actions/CLAUDE.md +19 -21
- package/dist/actions/action_codegen.d.ts +27 -18
- package/dist/actions/action_codegen.d.ts.map +1 -1
- package/dist/actions/action_codegen.js +90 -90
- package/dist/actions/action_event.d.ts +0 -8
- package/dist/actions/action_event.d.ts.map +1 -1
- package/dist/actions/action_event.js +7 -6
- package/dist/actions/action_event_data.d.ts +4 -4
- package/dist/actions/action_rpc.d.ts +1 -1
- package/dist/actions/action_rpc.d.ts.map +1 -1
- package/dist/actions/action_rpc.js +6 -7
- package/dist/actions/action_spec.d.ts +8 -10
- package/dist/actions/action_spec.d.ts.map +1 -1
- package/dist/actions/action_spec.js +1 -1
- package/dist/actions/action_types.d.ts +4 -4
- package/dist/actions/action_types.d.ts.map +1 -1
- package/dist/actions/action_types.js +2 -2
- package/dist/actions/broadcast_api.d.ts +2 -2
- package/dist/actions/broadcast_api.js +4 -4
- package/dist/actions/compile_action_registry.d.ts +6 -7
- package/dist/actions/compile_action_registry.d.ts.map +1 -1
- package/dist/actions/compile_action_registry.js +8 -9
- package/dist/actions/peer_ping.d.ts.map +1 -1
- package/dist/actions/peer_ping.js +3 -2
- package/dist/actions/perform_action.d.ts +6 -6
- package/dist/actions/perform_action.d.ts.map +1 -1
- package/dist/actions/perform_action.js +11 -10
- package/dist/actions/socket.svelte.d.ts +1 -1
- package/dist/actions/socket.svelte.js +2 -2
- package/dist/actions/ws_socket_session.d.ts.map +1 -1
- package/dist/actions/ws_socket_session.js +2 -1
- package/dist/auth/CLAUDE.md +11 -11
- package/dist/auth/admin_action_specs.d.ts +24 -24
- package/dist/auth/audit_emitter.d.ts +6 -7
- package/dist/auth/audit_emitter.d.ts.map +1 -1
- package/dist/auth/audit_emitter.js +11 -22
- package/dist/auth/audit_log_ddl.d.ts +1 -1
- package/dist/auth/audit_log_ddl.js +1 -1
- package/dist/auth/audit_log_queries.d.ts +0 -13
- package/dist/auth/audit_log_queries.d.ts.map +1 -1
- package/dist/auth/audit_log_queries.js +3 -3
- package/dist/auth/audit_log_schema.d.ts +14 -15
- package/dist/auth/audit_log_schema.d.ts.map +1 -1
- package/dist/auth/audit_log_schema.js +1 -1
- package/dist/auth/auth_ddl.d.ts +1 -1
- package/dist/auth/auth_ddl.js +1 -1
- package/dist/auth/cell_action_specs.d.ts +54 -54
- package/dist/auth/cell_actions.d.ts +2 -2
- package/dist/auth/cell_actions.js +5 -5
- package/dist/auth/middleware.d.ts +6 -2
- package/dist/auth/middleware.d.ts.map +1 -1
- package/dist/auth/middleware.js +14 -2
- package/dist/auth/request_context.d.ts.map +1 -1
- package/dist/auth/request_context.js +7 -9
- package/dist/auth/role_grant_offer_action_specs.d.ts +6 -6
- package/dist/auth/role_grant_offer_ddl.d.ts +1 -1
- package/dist/auth/role_grant_offer_ddl.js +1 -1
- package/dist/auth/role_grant_offer_notifications.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_notifications.js +2 -3
- package/dist/auth/self_service_role_actions.d.ts +1 -1
- package/dist/auth/self_service_role_actions.js +1 -1
- package/dist/env/env_schemas.d.ts +1 -2
- package/dist/env/env_schemas.d.ts.map +1 -1
- package/dist/env/env_schemas.js +3 -4
- package/dist/http/CLAUDE.md +30 -31
- package/dist/http/auth_shape.d.ts +14 -32
- package/dist/http/auth_shape.d.ts.map +1 -1
- package/dist/http/auth_shape.js +14 -49
- package/dist/http/error_schemas.d.ts +18 -18
- package/dist/http/json_text.d.ts +53 -0
- package/dist/http/json_text.d.ts.map +1 -0
- package/dist/http/json_text.js +152 -0
- package/dist/http/jsonrpc_helpers.js +1 -1
- package/dist/http/route_error_check.d.ts +2 -2
- package/dist/http/route_error_check.d.ts.map +1 -1
- package/dist/http/route_error_check.js +2 -3
- package/dist/http/route_errors.d.ts +4 -4
- package/dist/http/route_errors.d.ts.map +1 -1
- package/dist/http/route_errors.js +0 -13
- package/dist/http/route_result.d.ts +2 -1
- package/dist/http/route_result.d.ts.map +1 -1
- package/dist/http/route_spec.d.ts +34 -37
- package/dist/http/route_spec.d.ts.map +1 -1
- package/dist/http/route_spec.js +31 -31
- package/dist/http/schema_helpers.d.ts +77 -68
- package/dist/http/schema_helpers.d.ts.map +1 -1
- package/dist/http/schema_helpers.js +54 -77
- package/dist/http/surface.d.ts.map +1 -1
- package/dist/http/surface.js +6 -8
- package/dist/primitive_schemas.d.ts +9 -17
- package/dist/primitive_schemas.d.ts.map +1 -1
- package/dist/primitive_schemas.js +9 -17
- package/dist/realtime/sse.d.ts +3 -3
- package/dist/realtime/sse.d.ts.map +1 -1
- package/dist/realtime/sse.js +2 -2
- package/dist/schema_issues.d.ts +39 -147
- package/dist/schema_issues.d.ts.map +1 -1
- package/dist/schema_issues.js +39 -352
- package/dist/schema_meta.d.ts +63 -136
- package/dist/schema_meta.d.ts.map +1 -1
- package/dist/schema_meta.js +37 -184
- package/dist/sensitivity.d.ts +3 -5
- package/dist/sensitivity.d.ts.map +1 -1
- package/dist/sensitivity.js +3 -5
- package/dist/testing/CLAUDE.md +20 -22
- package/dist/testing/adversarial_headers.js +2 -2
- package/dist/testing/adversarial_input_cases.d.ts +19 -18
- package/dist/testing/adversarial_input_cases.d.ts.map +1 -1
- package/dist/testing/adversarial_input_cases.js +31 -46
- package/dist/testing/assertions.d.ts +2 -2
- package/dist/testing/assertions.d.ts.map +1 -1
- package/dist/testing/assertions.js +3 -3
- package/dist/testing/cross_backend/account_lifecycle.js +2 -2
- package/dist/testing/cross_backend/action_manifest.d.ts +10 -9
- package/dist/testing/cross_backend/action_manifest.d.ts.map +1 -1
- package/dist/testing/cross_backend/action_manifest.js +4 -3
- package/dist/testing/cross_backend/cell_crud.js +1 -1
- package/dist/testing/cross_backend/conformance_rpc_auth.d.ts +0 -62
- package/dist/testing/cross_backend/conformance_rpc_auth.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_table.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_table.js +3 -3
- package/dist/testing/cross_backend/cross_rpc.d.ts +3 -4
- package/dist/testing/cross_backend/cross_rpc.d.ts.map +1 -1
- package/dist/testing/cross_backend/cross_rpc.js +4 -4
- package/dist/testing/cross_backend/differential.js +2 -2
- package/dist/testing/cross_backend/identity_parity.d.ts.map +1 -1
- package/dist/testing/cross_backend/identity_parity.js +16 -11
- package/dist/testing/cross_backend/origin_conformance.d.ts +9 -9
- package/dist/testing/cross_backend/query_shape.js +1 -1
- package/dist/testing/cross_backend/rpc_success_fixtures.d.ts.map +1 -1
- package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts +1 -1
- package/dist/testing/cross_backend/setup.d.ts +25 -3
- package/dist/testing/cross_backend/setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/setup.js +4 -4
- package/dist/testing/cross_backend/sse_round_trip.js +2 -2
- package/dist/testing/cross_backend/testing_origin_check.d.ts +4 -4
- package/dist/testing/cross_backend/token_lifetime.js +3 -3
- package/dist/testing/cross_backend/wire_shapes.js +1 -1
- package/dist/testing/cross_backend/ws_envelope.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_envelope.js +8 -0
- package/dist/testing/cross_backend/ws_round_trip.js +1 -1
- package/dist/testing/data_exposure.d.ts.map +1 -1
- package/dist/testing/data_exposure.js +1 -1
- package/dist/testing/integration.js +2 -2
- package/dist/testing/integration_helpers.d.ts.map +1 -1
- package/dist/testing/integration_helpers.js +2 -2
- package/dist/testing/middleware.d.ts.map +1 -1
- package/dist/testing/middleware.js +2 -2
- package/dist/testing/rpc_attack_surface.js +1 -1
- package/dist/testing/rpc_envelope_cases.d.ts +10 -3
- package/dist/testing/rpc_envelope_cases.d.ts.map +1 -1
- package/dist/testing/rpc_envelope_cases.js +22 -1
- package/dist/testing/rpc_helpers.d.ts +12 -14
- package/dist/testing/rpc_helpers.d.ts.map +1 -1
- package/dist/testing/rpc_helpers.js +9 -10
- package/dist/testing/schema_generators.d.ts +67 -60
- package/dist/testing/schema_generators.d.ts.map +1 -1
- package/dist/testing/schema_generators.js +154 -159
- package/dist/testing/sse_round_trip.d.ts.map +1 -1
- package/dist/testing/sse_round_trip.js +2 -2
- package/dist/testing/surface_invariants.d.ts +1 -1
- package/dist/testing/surface_invariants.js +1 -1
- package/dist/ui/form_state.svelte.d.ts +1 -1
- package/dist/ui/form_state.svelte.js +1 -1
- package/package.json +5 -7
- package/dist/zod.d.ts +0 -116
- package/dist/zod.d.ts.map +0 -1
- package/dist/zod.js +0 -218
- package/dist/zod_schemas.d.ts +0 -100
- package/dist/zod_schemas.d.ts.map +0 -1
- package/dist/zod_schemas.js +0 -157
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fuzdev/fuz_app",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.171.0",
|
|
4
4
|
"description": "fullstack app library",
|
|
5
5
|
"glyph": "🗝",
|
|
6
6
|
"logo": "logo.svg",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"@electric-sql/pglite": ">=0.4",
|
|
38
38
|
"@fuzdev/blake3-wasm": ">=0.2.0",
|
|
39
39
|
"@fuzdev/fuz_css": ">=0.72.0",
|
|
40
|
-
"@fuzdev/fuz_schema": "^0.5.
|
|
40
|
+
"@fuzdev/fuz_schema": "^0.5.6",
|
|
41
41
|
"@fuzdev/fuz_util": ">=0.79.0",
|
|
42
42
|
"@fuzdev/pglet-wasm": ">=0.1.2",
|
|
43
43
|
"@hono/bun": ">=1",
|
|
@@ -50,8 +50,7 @@
|
|
|
50
50
|
"hono": ">=4",
|
|
51
51
|
"pg": ">=8",
|
|
52
52
|
"svelte": "^5",
|
|
53
|
-
"ws": ">=8"
|
|
54
|
-
"zod": "^4.6"
|
|
53
|
+
"ws": ">=8"
|
|
55
54
|
},
|
|
56
55
|
"peerDependenciesMeta": {
|
|
57
56
|
"@electric-sql/pglite": {
|
|
@@ -96,7 +95,7 @@
|
|
|
96
95
|
"@fuzdev/blake3-wasm": "^0.2.0",
|
|
97
96
|
"@fuzdev/fuz_code": "^0.56.0",
|
|
98
97
|
"@fuzdev/fuz_css": "^0.73.0",
|
|
99
|
-
"@fuzdev/fuz_schema": "^0.5.
|
|
98
|
+
"@fuzdev/fuz_schema": "^0.5.6",
|
|
100
99
|
"@fuzdev/fuz_ui": "^0.222.1",
|
|
101
100
|
"@fuzdev/fuz_util": "^0.79.1",
|
|
102
101
|
"@fuzdev/gro": "^0.225.0",
|
|
@@ -130,8 +129,7 @@
|
|
|
130
129
|
"typescript-eslint": "^8.71.1",
|
|
131
130
|
"vite": "^8.3.4",
|
|
132
131
|
"vitest": "^5.0.0",
|
|
133
|
-
"ws": "^8.20.1"
|
|
134
|
-
"zod": "^4.6.7"
|
|
132
|
+
"ws": "^8.20.1"
|
|
135
133
|
},
|
|
136
134
|
"sideEffects": [
|
|
137
135
|
"**/*.css"
|
package/dist/zod.d.ts
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Zod schema introspection utilities.
|
|
3
|
-
*
|
|
4
|
-
* Generic helpers for walking, unwrapping, and extracting field info from Zod schemas,
|
|
5
|
-
* and `zod_has_trait`, the structural `instanceof`. Used by adversarial input
|
|
6
|
-
* testing, test-data generation, auth-shape checks, and the dual-library layer
|
|
7
|
-
* (`schema_issues.ts`, `http/schema_helpers.ts`). Imports Zod's types only, so
|
|
8
|
-
* an importer loads no Zod.
|
|
9
|
-
*
|
|
10
|
-
* @module
|
|
11
|
-
*/
|
|
12
|
-
import type { z } from 'zod';
|
|
13
|
-
/**
|
|
14
|
-
* Whether `value` carries the Zod trait `trait` — what Zod's own
|
|
15
|
-
* `instanceof` reads (`value._zod.traits.has(trait)`), so it answers as
|
|
16
|
-
* `value instanceof z[trait]` would, a schema made by another copy of Zod
|
|
17
|
-
* included, without importing Zod at runtime. The classic API's names are the
|
|
18
|
-
* classes' (`'ZodType'`, `'ZodObject'`, `'ZodNull'`, `'ZodError'`), the core's
|
|
19
|
-
* `$`-prefixed (`'$ZodType'`).
|
|
20
|
-
*
|
|
21
|
-
* @param value - any value
|
|
22
|
-
* @param trait - the Zod class name to test for
|
|
23
|
-
* @returns whether `value` is an instance of that Zod class
|
|
24
|
-
*/
|
|
25
|
-
export declare const zod_has_trait: (value: unknown, trait: string) => boolean;
|
|
26
|
-
/**
|
|
27
|
-
* Unwrap Zod wrappers (optional, default, nullable, pipe, transform)
|
|
28
|
-
* to get the base type definition.
|
|
29
|
-
*
|
|
30
|
-
* @returns the innermost non-wrapper type definition
|
|
31
|
-
*/
|
|
32
|
-
export declare const zod_unwrap_def: (schema: z.ZodType) => z.core.$ZodTypeDef;
|
|
33
|
-
/**
|
|
34
|
-
* Get the base type name for a Zod schema, unwrapping all wrappers.
|
|
35
|
-
*
|
|
36
|
-
* @returns base type name (e.g. `'string'`, `'object'`, `'uuid'`)
|
|
37
|
-
*/
|
|
38
|
-
export declare const zod_get_base_type: (schema: z.ZodType) => string;
|
|
39
|
-
/**
|
|
40
|
-
* Unwrap a schema through every wrapper type (optional, nullable, default,
|
|
41
|
-
* transform, pipe, prefault) to reach the innermost schema. Like `zod_unwrap_def`
|
|
42
|
-
* but returns the schema (so callers can `.shape`, `instanceof`-check, etc.)
|
|
43
|
-
* instead of the def.
|
|
44
|
-
*
|
|
45
|
-
* @returns the innermost non-wrapper schema
|
|
46
|
-
*/
|
|
47
|
-
export declare const zod_get_innermost_type: (schema: z.ZodType) => z.ZodType;
|
|
48
|
-
/**
|
|
49
|
-
* Every layer of a schema, from the schema itself through each wrapper
|
|
50
|
-
* (optional, nullable, default, transform, pipe, prefault) to the innermost
|
|
51
|
-
* non-wrapper — for reading `.meta()` a wrapper does not carry over from the
|
|
52
|
-
* schema it wraps.
|
|
53
|
-
*
|
|
54
|
-
* @returns the layers, outermost first, ending at `zod_get_innermost_type(schema)`
|
|
55
|
-
*/
|
|
56
|
-
export declare const zod_get_schema_layers: (schema: z.ZodType) => Array<z.ZodType>;
|
|
57
|
-
/**
|
|
58
|
-
* Get all property keys from an object schema, unwrapping wrappers.
|
|
59
|
-
* Returns an empty array if the innermost type is not an object.
|
|
60
|
-
*
|
|
61
|
-
* @param schema - Zod schema (typically a `ZodObject` with possible wrappers)
|
|
62
|
-
*/
|
|
63
|
-
export declare const zod_get_schema_keys: <T extends z.ZodType>(schema: T) => Array<keyof z.infer<T> & string>;
|
|
64
|
-
/**
|
|
65
|
-
* Get the field schema for a key in an object schema, returning `undefined` if
|
|
66
|
-
* the schema is not an object or the key is not one of its own fields (a name
|
|
67
|
-
* the shape only inherits, such as `constructor` or `toString`, included).
|
|
68
|
-
*
|
|
69
|
-
* @param schema - Zod schema (typically a `ZodObject` with possible wrappers)
|
|
70
|
-
* @param key - the property name
|
|
71
|
-
* @returns the field's schema, or `undefined`
|
|
72
|
-
*/
|
|
73
|
-
export declare const zod_maybe_get_field_schema: (schema: z.ZodType, key: string) => z.ZodType | undefined;
|
|
74
|
-
/**
|
|
75
|
-
* Get the field schema for a key in an object schema.
|
|
76
|
-
*
|
|
77
|
-
* @param schema - Zod schema (typically a `ZodObject` with possible wrappers)
|
|
78
|
-
* @throws Error if the schema is not an object or the key is missing
|
|
79
|
-
*/
|
|
80
|
-
export declare const zod_get_field_schema: (schema: z.ZodType, key: string) => z.ZodType;
|
|
81
|
-
/**
|
|
82
|
-
* Unwrap a schema to find the inner `ZodObject`, or `null` if not an object schema.
|
|
83
|
-
* Handles wrappers like `z.strictObject({...}).default({...})`.
|
|
84
|
-
*/
|
|
85
|
-
export declare const zod_unwrap_to_object: (schema: z.ZodType) => z.ZodObject | null;
|
|
86
|
-
/**
|
|
87
|
-
* What the testing generators read of one field of an object schema, of
|
|
88
|
-
* either library: `zod_extract_fields` reads a `ZodObject`'s, and
|
|
89
|
-
* `to_object_schema_view` (`testing/schema_generators.ts`) a schema's of
|
|
90
|
-
* either library.
|
|
91
|
-
*/
|
|
92
|
-
export interface SchemaFieldInfo {
|
|
93
|
-
/** The field's key. */
|
|
94
|
-
name: string;
|
|
95
|
-
/**
|
|
96
|
-
* The innermost type's name in Zod's vocabulary (`zod_get_base_type`):
|
|
97
|
-
* `'string'`, `'number'`, `'boolean'`, `'array'`, `'object'`, `'null'`,
|
|
98
|
-
* `'void'`, `'union'`, `'literal'`, `'enum'`, and so on. A
|
|
99
|
-
* `@fuzdev/fuz_schema` field reads its innermost kind, an object of any
|
|
100
|
-
* strictness as `'object'`, a `literal(null)` as `'null'`, a
|
|
101
|
-
* `literal(undefined)` (`s.void`) as `'void'`, a `one_of` as `'enum'`, and
|
|
102
|
-
* a `variant` as `'union'`.
|
|
103
|
-
*/
|
|
104
|
-
base_type: string;
|
|
105
|
-
/** Whether the key must be present: no outermost `.optional()` in Zod, no `optional` layer in fuz_schema. */
|
|
106
|
-
required: boolean;
|
|
107
|
-
/** Whether the parse fills the key in when it is missing. */
|
|
108
|
-
has_default: boolean;
|
|
109
|
-
/** Whether a wrapping layer accepts `null`. */
|
|
110
|
-
nullable: boolean;
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Extract field metadata from a Zod object schema.
|
|
114
|
-
*/
|
|
115
|
-
export declare const zod_extract_fields: (schema: z.ZodObject) => Array<SchemaFieldInfo>;
|
|
116
|
-
//# sourceMappingURL=zod.d.ts.map
|
package/dist/zod.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"zod.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/zod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,aAAa,GAAI,OAAO,OAAO,EAAE,OAAO,MAAM,KAAG,OAM7D,CAAC;AAgCF;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,QAAQ,CAAC,CAAC,OAAO,KAAG,CAAC,CAAC,IAAI,CAAC,WAOzD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,GAAI,QAAQ,CAAC,CAAC,OAAO,KAAG,MAAqC,CAAC;AAgC5F;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,GAAI,QAAQ,CAAC,CAAC,OAAO,KAAG,CAAC,CAAC,OAM5D,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,GAAI,QAAQ,CAAC,CAAC,OAAO,KAAG,KAAK,CAAC,CAAC,CAAC,OAAO,CAUxE,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,GAAI,CAAC,SAAS,CAAC,CAAC,OAAO,EACtD,QAAQ,CAAC,KACP,KAAK,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM,CAGjC,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,0BAA0B,GACtC,QAAQ,CAAC,CAAC,OAAO,EACjB,KAAK,MAAM,KACT,CAAC,CAAC,OAAO,GAAG,SAGd,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,GAAI,QAAQ,CAAC,CAAC,OAAO,EAAE,KAAK,MAAM,KAAG,CAAC,CAAC,OAIvE,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,oBAAoB,GAAI,QAAQ,CAAC,CAAC,OAAO,KAAG,CAAC,CAAC,SAAS,GAAG,IAUtE,CAAC;AAIF;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC/B,uBAAuB;IACvB,IAAI,EAAE,MAAM,CAAC;IACb;;;;;;;;OAQG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB,6GAA6G;IAC7G,QAAQ,EAAE,OAAO,CAAC;IAClB,6DAA6D;IAC7D,WAAW,EAAE,OAAO,CAAC;IACrB,+CAA+C;IAC/C,QAAQ,EAAE,OAAO,CAAC;CAClB;AAED;;GAEG;AACH,eAAO,MAAM,kBAAkB,GAAI,QAAQ,CAAC,CAAC,SAAS,KAAG,KAAK,CAAC,eAAe,CAa7E,CAAC"}
|
package/dist/zod.js
DELETED
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Zod schema introspection utilities.
|
|
3
|
-
*
|
|
4
|
-
* Generic helpers for walking, unwrapping, and extracting field info from Zod schemas,
|
|
5
|
-
* and `zod_has_trait`, the structural `instanceof`. Used by adversarial input
|
|
6
|
-
* testing, test-data generation, auth-shape checks, and the dual-library layer
|
|
7
|
-
* (`schema_issues.ts`, `http/schema_helpers.ts`). Imports Zod's types only, so
|
|
8
|
-
* an importer loads no Zod.
|
|
9
|
-
*
|
|
10
|
-
* @module
|
|
11
|
-
*/
|
|
12
|
-
/**
|
|
13
|
-
* Whether `value` carries the Zod trait `trait` — what Zod's own
|
|
14
|
-
* `instanceof` reads (`value._zod.traits.has(trait)`), so it answers as
|
|
15
|
-
* `value instanceof z[trait]` would, a schema made by another copy of Zod
|
|
16
|
-
* included, without importing Zod at runtime. The classic API's names are the
|
|
17
|
-
* classes' (`'ZodType'`, `'ZodObject'`, `'ZodNull'`, `'ZodError'`), the core's
|
|
18
|
-
* `$`-prefixed (`'$ZodType'`).
|
|
19
|
-
*
|
|
20
|
-
* @param value - any value
|
|
21
|
-
* @param trait - the Zod class name to test for
|
|
22
|
-
* @returns whether `value` is an instance of that Zod class
|
|
23
|
-
*/
|
|
24
|
-
export const zod_has_trait = (value, trait) => {
|
|
25
|
-
if (value === null || (typeof value !== 'object' && typeof value !== 'function'))
|
|
26
|
-
return false;
|
|
27
|
-
const internals = value._zod;
|
|
28
|
-
if (internals === null || typeof internals !== 'object')
|
|
29
|
-
return false;
|
|
30
|
-
const traits = internals.traits;
|
|
31
|
-
return traits instanceof Set && traits.has(trait);
|
|
32
|
-
};
|
|
33
|
-
//
|
|
34
|
-
// Schema Introspection
|
|
35
|
-
//
|
|
36
|
-
/**
|
|
37
|
-
* Unwrap nested schema types (optional, default, nullable, etc).
|
|
38
|
-
*
|
|
39
|
-
* @returns inner schema if wrapped, undefined otherwise
|
|
40
|
-
*/
|
|
41
|
-
const zod_to_subschema = (def) => {
|
|
42
|
-
if ('innerType' in def) {
|
|
43
|
-
return def.innerType;
|
|
44
|
-
}
|
|
45
|
-
else if ('in' in def) {
|
|
46
|
-
return def.in;
|
|
47
|
-
}
|
|
48
|
-
else if ('schema' in def) {
|
|
49
|
-
return def.schema;
|
|
50
|
-
}
|
|
51
|
-
return undefined;
|
|
52
|
-
};
|
|
53
|
-
/** Zod wrapper type names that `zod_unwrap_def` traverses through. */
|
|
54
|
-
const ZOD_WRAPPER_TYPES = new Set([
|
|
55
|
-
'optional',
|
|
56
|
-
'nullable',
|
|
57
|
-
'default',
|
|
58
|
-
'transform',
|
|
59
|
-
'pipe',
|
|
60
|
-
'prefault'
|
|
61
|
-
]);
|
|
62
|
-
/**
|
|
63
|
-
* Unwrap Zod wrappers (optional, default, nullable, pipe, transform)
|
|
64
|
-
* to get the base type definition.
|
|
65
|
-
*
|
|
66
|
-
* @returns the innermost non-wrapper type definition
|
|
67
|
-
*/
|
|
68
|
-
export const zod_unwrap_def = (schema) => {
|
|
69
|
-
const { def } = schema;
|
|
70
|
-
if (ZOD_WRAPPER_TYPES.has(def.type)) {
|
|
71
|
-
const sub = zod_to_subschema(def);
|
|
72
|
-
if (sub)
|
|
73
|
-
return zod_unwrap_def(sub);
|
|
74
|
-
}
|
|
75
|
-
return def;
|
|
76
|
-
};
|
|
77
|
-
/**
|
|
78
|
-
* Get the base type name for a Zod schema, unwrapping all wrappers.
|
|
79
|
-
*
|
|
80
|
-
* @returns base type name (e.g. `'string'`, `'object'`, `'uuid'`)
|
|
81
|
-
*/
|
|
82
|
-
export const zod_get_base_type = (schema) => zod_unwrap_def(schema).type;
|
|
83
|
-
/**
|
|
84
|
-
* Check if a schema is optional at the outermost level.
|
|
85
|
-
*/
|
|
86
|
-
const zod_is_optional = (schema) => schema.def.type === 'optional';
|
|
87
|
-
/**
|
|
88
|
-
* Check if a schema accepts null at any wrapping level.
|
|
89
|
-
*/
|
|
90
|
-
const zod_is_nullable = (schema) => {
|
|
91
|
-
const { def } = schema;
|
|
92
|
-
if (def.type === 'nullable')
|
|
93
|
-
return true;
|
|
94
|
-
if (ZOD_WRAPPER_TYPES.has(def.type)) {
|
|
95
|
-
const sub = zod_to_subschema(def);
|
|
96
|
-
if (sub)
|
|
97
|
-
return zod_is_nullable(sub);
|
|
98
|
-
}
|
|
99
|
-
return false;
|
|
100
|
-
};
|
|
101
|
-
/**
|
|
102
|
-
* Check if a schema has a default value at any wrapping level.
|
|
103
|
-
* Distinguishes "no default" from "default is undefined".
|
|
104
|
-
*/
|
|
105
|
-
const zod_has_default = (schema) => {
|
|
106
|
-
const { def } = schema;
|
|
107
|
-
if ('defaultValue' in def)
|
|
108
|
-
return true;
|
|
109
|
-
const sub = zod_to_subschema(def);
|
|
110
|
-
if (sub)
|
|
111
|
-
return zod_has_default(sub);
|
|
112
|
-
return false;
|
|
113
|
-
};
|
|
114
|
-
/**
|
|
115
|
-
* Unwrap a schema through every wrapper type (optional, nullable, default,
|
|
116
|
-
* transform, pipe, prefault) to reach the innermost schema. Like `zod_unwrap_def`
|
|
117
|
-
* but returns the schema (so callers can `.shape`, `instanceof`-check, etc.)
|
|
118
|
-
* instead of the def.
|
|
119
|
-
*
|
|
120
|
-
* @returns the innermost non-wrapper schema
|
|
121
|
-
*/
|
|
122
|
-
export const zod_get_innermost_type = (schema) => {
|
|
123
|
-
if (ZOD_WRAPPER_TYPES.has(schema.def.type)) {
|
|
124
|
-
const sub = zod_to_subschema(schema.def);
|
|
125
|
-
if (sub)
|
|
126
|
-
return zod_get_innermost_type(sub);
|
|
127
|
-
}
|
|
128
|
-
return schema;
|
|
129
|
-
};
|
|
130
|
-
/**
|
|
131
|
-
* Every layer of a schema, from the schema itself through each wrapper
|
|
132
|
-
* (optional, nullable, default, transform, pipe, prefault) to the innermost
|
|
133
|
-
* non-wrapper — for reading `.meta()` a wrapper does not carry over from the
|
|
134
|
-
* schema it wraps.
|
|
135
|
-
*
|
|
136
|
-
* @returns the layers, outermost first, ending at `zod_get_innermost_type(schema)`
|
|
137
|
-
*/
|
|
138
|
-
export const zod_get_schema_layers = (schema) => {
|
|
139
|
-
const layers = [schema];
|
|
140
|
-
let s = schema;
|
|
141
|
-
while (ZOD_WRAPPER_TYPES.has(s.def.type)) {
|
|
142
|
-
const sub = zod_to_subschema(s.def);
|
|
143
|
-
if (!sub)
|
|
144
|
-
break;
|
|
145
|
-
layers.push(sub);
|
|
146
|
-
s = sub;
|
|
147
|
-
}
|
|
148
|
-
return layers;
|
|
149
|
-
};
|
|
150
|
-
/**
|
|
151
|
-
* Get all property keys from an object schema, unwrapping wrappers.
|
|
152
|
-
* Returns an empty array if the innermost type is not an object.
|
|
153
|
-
*
|
|
154
|
-
* @param schema - Zod schema (typically a `ZodObject` with possible wrappers)
|
|
155
|
-
*/
|
|
156
|
-
export const zod_get_schema_keys = (schema) => {
|
|
157
|
-
const obj = zod_unwrap_to_object(schema);
|
|
158
|
-
return obj ? Object.keys(obj.shape) : [];
|
|
159
|
-
};
|
|
160
|
-
/**
|
|
161
|
-
* Get the field schema for a key in an object schema, returning `undefined` if
|
|
162
|
-
* the schema is not an object or the key is not one of its own fields (a name
|
|
163
|
-
* the shape only inherits, such as `constructor` or `toString`, included).
|
|
164
|
-
*
|
|
165
|
-
* @param schema - Zod schema (typically a `ZodObject` with possible wrappers)
|
|
166
|
-
* @param key - the property name
|
|
167
|
-
* @returns the field's schema, or `undefined`
|
|
168
|
-
*/
|
|
169
|
-
export const zod_maybe_get_field_schema = (schema, key) => {
|
|
170
|
-
const shape = zod_unwrap_to_object(schema)?.shape;
|
|
171
|
-
return shape && Object.hasOwn(shape, key) ? shape[key] : undefined;
|
|
172
|
-
};
|
|
173
|
-
/**
|
|
174
|
-
* Get the field schema for a key in an object schema.
|
|
175
|
-
*
|
|
176
|
-
* @param schema - Zod schema (typically a `ZodObject` with possible wrappers)
|
|
177
|
-
* @throws Error if the schema is not an object or the key is missing
|
|
178
|
-
*/
|
|
179
|
-
export const zod_get_field_schema = (schema, key) => {
|
|
180
|
-
const field = zod_maybe_get_field_schema(schema, key);
|
|
181
|
-
if (!field)
|
|
182
|
-
throw new Error(`Field "${key}" not found in schema`);
|
|
183
|
-
return field;
|
|
184
|
-
};
|
|
185
|
-
/**
|
|
186
|
-
* Unwrap a schema to find the inner `ZodObject`, or `null` if not an object schema.
|
|
187
|
-
* Handles wrappers like `z.strictObject({...}).default({...})`.
|
|
188
|
-
*/
|
|
189
|
-
export const zod_unwrap_to_object = (schema) => {
|
|
190
|
-
const def = zod_unwrap_def(schema);
|
|
191
|
-
if (def.type !== 'object')
|
|
192
|
-
return null;
|
|
193
|
-
let s = schema;
|
|
194
|
-
while (s.def.type !== 'object') {
|
|
195
|
-
const sub = zod_to_subschema(s.def);
|
|
196
|
-
if (!sub)
|
|
197
|
-
return null;
|
|
198
|
-
s = sub;
|
|
199
|
-
}
|
|
200
|
-
return s;
|
|
201
|
-
};
|
|
202
|
-
/**
|
|
203
|
-
* Extract field metadata from a Zod object schema.
|
|
204
|
-
*/
|
|
205
|
-
export const zod_extract_fields = (schema) => {
|
|
206
|
-
const fields = [];
|
|
207
|
-
for (const [name, field_schema] of Object.entries(schema.shape)) {
|
|
208
|
-
const field = field_schema;
|
|
209
|
-
fields.push({
|
|
210
|
-
name,
|
|
211
|
-
base_type: zod_get_base_type(field),
|
|
212
|
-
required: !zod_is_optional(field),
|
|
213
|
-
has_default: zod_has_default(field),
|
|
214
|
-
nullable: zod_is_nullable(field)
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
return fields;
|
|
218
|
-
};
|
package/dist/zod_schemas.d.ts
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The Zod forms of the primitives a consumer's Zod schema embeds: `ZodUuid`,
|
|
3
|
-
* `ZodUuidWithDefault`, `ZodFactHashSchema`, `ZodUsername`, `ZodEmail`, and
|
|
4
|
-
* `ZodActingActor`, each built on the grammar of its `@fuzdev/fuz_schema`
|
|
5
|
-
* twin in `primitive_schemas.ts` and sharing its output type, so a value
|
|
6
|
-
* parsed by either goes where the other's is taken; and the branded
|
|
7
|
-
* `Datetime`, with `DatetimeNow` and `get_datetime_now`, which has no twin
|
|
8
|
-
* (`Timestamp` is the wire timestamp).
|
|
9
|
-
*
|
|
10
|
-
* fuz_app's own schemas are fuz_schema; this module is for apps whose schemas
|
|
11
|
-
* are still Zod, which the action and route layers accept. It is the one
|
|
12
|
-
* fuz_app module that imports Zod at runtime, so only an importer of it loads
|
|
13
|
-
* Zod.
|
|
14
|
-
*
|
|
15
|
-
* @module
|
|
16
|
-
*/
|
|
17
|
-
import { z } from 'zod';
|
|
18
|
-
import type { Branded } from '@fuzdev/fuz_schema/schema.ts';
|
|
19
|
-
import { type FactHash } from '@fuzdev/fuz_util/hash_schemas.ts';
|
|
20
|
-
/**
|
|
21
|
-
* The Zod form of `Username`: the same bounds and grammar, output in
|
|
22
|
-
* lowercase. Every input gets the same verdict and output from both; a string
|
|
23
|
-
* outside the bounds and off the grammar gets the grammar issue after the
|
|
24
|
-
* length one, where `Username` gives the length issue alone.
|
|
25
|
-
*/
|
|
26
|
-
export declare const ZodUsername: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
27
|
-
export type ZodUsername = z.infer<typeof ZodUsername>;
|
|
28
|
-
/**
|
|
29
|
-
* The Zod form of `Email`: at most `EMAIL_LENGTH_MAX` UTF-8 bytes, then
|
|
30
|
-
* `EMAIL_REGEX`, no transform. Every input gets the same verdict and output
|
|
31
|
-
* from both. The byte bound runs first and aborts, so an address past it gets
|
|
32
|
-
* the length issue alone, a Zod `custom` issue with `EMAIL_LENGTH_MESSAGE`,
|
|
33
|
-
* and is never read by the regex; its JSON Schema is the `pattern` alone,
|
|
34
|
-
* where `Email`'s adds the bound as `maxLength`.
|
|
35
|
-
*/
|
|
36
|
-
export declare const ZodEmail: z.ZodString;
|
|
37
|
-
export type ZodEmail = z.infer<typeof ZodEmail>;
|
|
38
|
-
/**
|
|
39
|
-
* The Zod form of `Uuid`: `z.uuid()` with `UUID_REGEX` as its `pattern` — the
|
|
40
|
-
* max UUID in any case, as RFC 9562 §4 and the Rust spine's `is_valid_uuid`
|
|
41
|
-
* read it — output in lowercase. Every input gets the same verdict and output
|
|
42
|
-
* from both, and their JSON Schema is the same. Issues and JSON Schema keep
|
|
43
|
-
* `format: 'uuid'`; only the `pattern` differs from a bare `z.uuid()`'s.
|
|
44
|
-
*
|
|
45
|
-
* `pattern` is a `$ZodUUIDDef` field that `z.uuid()` honors (its default
|
|
46
|
-
* applies only when none is given) but whose public params type omits it,
|
|
47
|
-
* hence the cast on the params.
|
|
48
|
-
*
|
|
49
|
-
* `.toLowerCase()` rather than `.transform()`: an overwrite keeps the output
|
|
50
|
-
* type and stays invisible to JSON Schema, where a transform would leave no
|
|
51
|
-
* input schema to render.
|
|
52
|
-
*
|
|
53
|
-
* The output type is fuz_schema's `Branded<string, 'Uuid'>`, `Uuid`'s, by a
|
|
54
|
-
* cast: Zod's `.brand('Uuid')` would output Zod's own brand, which a
|
|
55
|
-
* fuz_schema `Uuid` isn't assignable to.
|
|
56
|
-
*/
|
|
57
|
-
export declare const ZodUuid: z.ZodUUID & z.ZodType<Branded<string, 'Uuid'>, string>;
|
|
58
|
-
export type ZodUuid = z.infer<typeof ZodUuid>;
|
|
59
|
-
/** `ZodUuid` that defaults to a fresh `create_uuid()` when the input is `undefined`. */
|
|
60
|
-
export declare const ZodUuidWithDefault: z.ZodDefault<z.ZodUUID & z.ZodType<Branded<string, "Uuid">, string, z.core.$ZodTypeInternals<Branded<string, "Uuid">, string>>>;
|
|
61
|
-
export type ZodUuidWithDefault = z.infer<typeof ZodUuidWithDefault>;
|
|
62
|
-
/**
|
|
63
|
-
* Branded datetime schema, zod's default `z.iso.datetime()`: an RFC 3339 date
|
|
64
|
-
* and time in UTC with a real calendar date, `Z` and no offset, and a fraction
|
|
65
|
-
* of any length or none. Zod 4.6 requires the seconds; earlier zod 4, which
|
|
66
|
-
* the `zod` peer range admits, also takes `HH:MMZ`. `Timestamp` is this
|
|
67
|
-
* grammar with the seconds required and the fraction capped at 9 digits, and
|
|
68
|
-
* not branded.
|
|
69
|
-
*/
|
|
70
|
-
export declare const Datetime: z.core.$ZodBranded<z.ZodISODateTime, "Datetime", "out">;
|
|
71
|
-
export type Datetime = z.infer<typeof Datetime>;
|
|
72
|
-
/** Returns an ISO 8601 datetime string for the current time. */
|
|
73
|
-
export declare const get_datetime_now: () => Datetime;
|
|
74
|
-
/** `Datetime` that defaults to `get_datetime_now()` when the input is `undefined`. */
|
|
75
|
-
export declare const DatetimeNow: z.ZodDefault<z.core.$ZodBranded<z.ZodISODateTime, "Datetime", "out">>;
|
|
76
|
-
export type DatetimeNow = z.infer<typeof DatetimeNow>;
|
|
77
|
-
/**
|
|
78
|
-
* The Zod form of `FactHashSchema`: `FACT_HASH_EXACT`, its output fuz_util's
|
|
79
|
-
* `FactHash`, so a parsed value passes straight to `fact_hash_bytes`,
|
|
80
|
-
* `fact_hash_stream`, and `FactStore`. The two agree on every input, and
|
|
81
|
-
* their JSON Schema is the same `pattern`.
|
|
82
|
-
*
|
|
83
|
-
* The output type is a cast over a plain regex check: Zod's
|
|
84
|
-
* `.brand('FactHash')` would output Zod's own brand, which doesn't fit
|
|
85
|
-
* fuz_util's fuz_schema-branded `FactHash`, and a `.transform` or `z.custom`
|
|
86
|
-
* that produced the right type has no JSON Schema form. The cast costs
|
|
87
|
-
* nothing at runtime and keeps the `ZodString` API and the `pattern`, so
|
|
88
|
-
* `.meta()`, `.nullable()`, and `z.array()` compose as before.
|
|
89
|
-
*/
|
|
90
|
-
export declare const ZodFactHashSchema: z.ZodString & z.ZodType<FactHash, string>;
|
|
91
|
-
/**
|
|
92
|
-
* The Zod form of `ActingActor`, for a Zod input that needs the caller's
|
|
93
|
-
* acting actor: an optional `ZodUuid` carrying `ACTING_ACTOR_DESCRIPTION`.
|
|
94
|
-
* `ActingActor`'s doc has the resolution rules. The dispatcher finds it by
|
|
95
|
-
* reference, as it does `ActingActor`, so an input declares this export, not
|
|
96
|
-
* a copy of it.
|
|
97
|
-
*/
|
|
98
|
-
export declare const ZodActingActor: z.ZodOptional<z.ZodUUID & z.ZodType<Branded<string, "Uuid">, string, z.core.$ZodTypeInternals<Branded<string, "Uuid">, string>>>;
|
|
99
|
-
export type ZodActingActor = z.infer<typeof ZodActingActor>;
|
|
100
|
-
//# sourceMappingURL=zod_schemas.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"zod_schemas.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/zod_schemas.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAmB,KAAK,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAyElF;;;;;GAKG;AACH,eAAO,MAAM,WAAW,wDAEW,CAAC;AACpC,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAEtD;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,aAGD,CAAC;AACrB,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,QAAQ,CAAC,CAAC;AAEhD;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,OAAO,EAAE,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAEF,CAAC;AAC1E,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,OAAO,CAAC,CAAC;AAE9C,wFAAwF;AACxF,eAAO,MAAM,kBAAkB,iIAA+B,CAAC;AAC/D,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAEpE;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,yDAAqC,CAAC;AAC3D,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,QAAQ,CAAC,CAAC;AAEhD,gEAAgE;AAChE,eAAO,MAAM,gBAAgB,QAAO,QAAgD,CAAC;AAErF,sFAAsF;AACtF,eAAO,MAAM,WAAW,uEAAqC,CAAC;AAC9D,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAEtD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,iBAAiB,EAAE,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,MAAM,CAEH,CAAC;AAEtE;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,kIAAqE,CAAC;AACjG,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC"}
|
package/dist/zod_schemas.js
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The Zod forms of the primitives a consumer's Zod schema embeds: `ZodUuid`,
|
|
3
|
-
* `ZodUuidWithDefault`, `ZodFactHashSchema`, `ZodUsername`, `ZodEmail`, and
|
|
4
|
-
* `ZodActingActor`, each built on the grammar of its `@fuzdev/fuz_schema`
|
|
5
|
-
* twin in `primitive_schemas.ts` and sharing its output type, so a value
|
|
6
|
-
* parsed by either goes where the other's is taken; and the branded
|
|
7
|
-
* `Datetime`, with `DatetimeNow` and `get_datetime_now`, which has no twin
|
|
8
|
-
* (`Timestamp` is the wire timestamp).
|
|
9
|
-
*
|
|
10
|
-
* fuz_app's own schemas are fuz_schema; this module is for apps whose schemas
|
|
11
|
-
* are still Zod, which the action and route layers accept. It is the one
|
|
12
|
-
* fuz_app module that imports Zod at runtime, so only an importer of it loads
|
|
13
|
-
* Zod.
|
|
14
|
-
*
|
|
15
|
-
* @module
|
|
16
|
-
*/
|
|
17
|
-
import { z } from 'zod';
|
|
18
|
-
import { FACT_HASH_EXACT } from '@fuzdev/fuz_util/hash_schemas.ts';
|
|
19
|
-
import { ACTING_ACTOR_DESCRIPTION, create_uuid, EMAIL_LENGTH_MESSAGE, EMAIL_REGEX, is_email_within_length_max, USERNAME_LENGTH_MAX, USERNAME_LENGTH_MIN, USERNAME_REGEX, UUID_REGEX } from './primitive_schemas.js';
|
|
20
|
-
import { register_zod_acting_actor } from './http/auth_shape.js';
|
|
21
|
-
/**
|
|
22
|
-
* A Zod string bounded in UTF-16 code units, `ZodUsername`'s length check.
|
|
23
|
-
*
|
|
24
|
-
* Zod's `.min()` / `.max()` alone don't pin the unit: depending on the
|
|
25
|
-
* installed Zod they count code units or Unicode code points, and the peer
|
|
26
|
-
* range admits both. The schema still carries them — they are what puts
|
|
27
|
-
* `minLength` / `maxLength` in the generated JSON Schema — and a check beside
|
|
28
|
-
* them settles the verdict on `String.length`: it adds the over-`max` or
|
|
29
|
-
* under-`min` issue when Zod raised none, and withdraws one Zod raised for a
|
|
30
|
-
* string that is within the bound in units. The issue it adds has the fields
|
|
31
|
-
* of Zod's own and, like Zod's, lets the checks chained after it run, so a
|
|
32
|
-
* refusal reads the same whichever count Zod used.
|
|
33
|
-
*/
|
|
34
|
-
const zod_bounded_string = (min, max) => z
|
|
35
|
-
.string()
|
|
36
|
-
.min(min)
|
|
37
|
-
.max(max)
|
|
38
|
-
.check((ctx) => {
|
|
39
|
-
const { length } = ctx.value;
|
|
40
|
-
const { issues } = ctx;
|
|
41
|
-
const too_big = issues.findIndex((i) => i.code === 'too_big' && i.origin === 'string' && i.maximum === max);
|
|
42
|
-
if (length > max) {
|
|
43
|
-
if (too_big === -1) {
|
|
44
|
-
issues.push({
|
|
45
|
-
origin: 'string',
|
|
46
|
-
code: 'too_big',
|
|
47
|
-
maximum: max,
|
|
48
|
-
inclusive: true,
|
|
49
|
-
input: ctx.value,
|
|
50
|
-
// as on Zod's own length issues: the checks chained after still run
|
|
51
|
-
continue: true
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
else if (too_big !== -1) {
|
|
56
|
-
issues.splice(too_big, 1);
|
|
57
|
-
}
|
|
58
|
-
const too_small = issues.findIndex((i) => i.code === 'too_small' && i.origin === 'string' && i.minimum === min);
|
|
59
|
-
if (length < min) {
|
|
60
|
-
if (too_small === -1) {
|
|
61
|
-
issues.push({
|
|
62
|
-
origin: 'string',
|
|
63
|
-
code: 'too_small',
|
|
64
|
-
minimum: min,
|
|
65
|
-
inclusive: true,
|
|
66
|
-
input: ctx.value,
|
|
67
|
-
continue: true
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
else if (too_small !== -1) {
|
|
72
|
-
issues.splice(too_small, 1);
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
/**
|
|
76
|
-
* The Zod form of `Username`: the same bounds and grammar, output in
|
|
77
|
-
* lowercase. Every input gets the same verdict and output from both; a string
|
|
78
|
-
* outside the bounds and off the grammar gets the grammar issue after the
|
|
79
|
-
* length one, where `Username` gives the length issue alone.
|
|
80
|
-
*/
|
|
81
|
-
export const ZodUsername = zod_bounded_string(USERNAME_LENGTH_MIN, USERNAME_LENGTH_MAX)
|
|
82
|
-
.regex(USERNAME_REGEX)
|
|
83
|
-
.transform((s) => s.toLowerCase());
|
|
84
|
-
/**
|
|
85
|
-
* The Zod form of `Email`: at most `EMAIL_LENGTH_MAX` UTF-8 bytes, then
|
|
86
|
-
* `EMAIL_REGEX`, no transform. Every input gets the same verdict and output
|
|
87
|
-
* from both. The byte bound runs first and aborts, so an address past it gets
|
|
88
|
-
* the length issue alone, a Zod `custom` issue with `EMAIL_LENGTH_MESSAGE`,
|
|
89
|
-
* and is never read by the regex; its JSON Schema is the `pattern` alone,
|
|
90
|
-
* where `Email`'s adds the bound as `maxLength`.
|
|
91
|
-
*/
|
|
92
|
-
export const ZodEmail = z
|
|
93
|
-
.string()
|
|
94
|
-
.refine(is_email_within_length_max, { message: EMAIL_LENGTH_MESSAGE, abort: true })
|
|
95
|
-
.regex(EMAIL_REGEX);
|
|
96
|
-
/**
|
|
97
|
-
* The Zod form of `Uuid`: `z.uuid()` with `UUID_REGEX` as its `pattern` — the
|
|
98
|
-
* max UUID in any case, as RFC 9562 §4 and the Rust spine's `is_valid_uuid`
|
|
99
|
-
* read it — output in lowercase. Every input gets the same verdict and output
|
|
100
|
-
* from both, and their JSON Schema is the same. Issues and JSON Schema keep
|
|
101
|
-
* `format: 'uuid'`; only the `pattern` differs from a bare `z.uuid()`'s.
|
|
102
|
-
*
|
|
103
|
-
* `pattern` is a `$ZodUUIDDef` field that `z.uuid()` honors (its default
|
|
104
|
-
* applies only when none is given) but whose public params type omits it,
|
|
105
|
-
* hence the cast on the params.
|
|
106
|
-
*
|
|
107
|
-
* `.toLowerCase()` rather than `.transform()`: an overwrite keeps the output
|
|
108
|
-
* type and stays invisible to JSON Schema, where a transform would leave no
|
|
109
|
-
* input schema to render.
|
|
110
|
-
*
|
|
111
|
-
* The output type is fuz_schema's `Branded<string, 'Uuid'>`, `Uuid`'s, by a
|
|
112
|
-
* cast: Zod's `.brand('Uuid')` would output Zod's own brand, which a
|
|
113
|
-
* fuz_schema `Uuid` isn't assignable to.
|
|
114
|
-
*/
|
|
115
|
-
export const ZodUuid = z
|
|
116
|
-
.uuid({ pattern: UUID_REGEX })
|
|
117
|
-
.toLowerCase();
|
|
118
|
-
/** `ZodUuid` that defaults to a fresh `create_uuid()` when the input is `undefined`. */
|
|
119
|
-
export const ZodUuidWithDefault = ZodUuid.default(create_uuid);
|
|
120
|
-
/**
|
|
121
|
-
* Branded datetime schema, zod's default `z.iso.datetime()`: an RFC 3339 date
|
|
122
|
-
* and time in UTC with a real calendar date, `Z` and no offset, and a fraction
|
|
123
|
-
* of any length or none. Zod 4.6 requires the seconds; earlier zod 4, which
|
|
124
|
-
* the `zod` peer range admits, also takes `HH:MMZ`. `Timestamp` is this
|
|
125
|
-
* grammar with the seconds required and the fraction capped at 9 digits, and
|
|
126
|
-
* not branded.
|
|
127
|
-
*/
|
|
128
|
-
export const Datetime = z.iso.datetime().brand('Datetime');
|
|
129
|
-
/** Returns an ISO 8601 datetime string for the current time. */
|
|
130
|
-
export const get_datetime_now = () => new Date().toISOString();
|
|
131
|
-
/** `Datetime` that defaults to `get_datetime_now()` when the input is `undefined`. */
|
|
132
|
-
export const DatetimeNow = Datetime.default(get_datetime_now);
|
|
133
|
-
/**
|
|
134
|
-
* The Zod form of `FactHashSchema`: `FACT_HASH_EXACT`, its output fuz_util's
|
|
135
|
-
* `FactHash`, so a parsed value passes straight to `fact_hash_bytes`,
|
|
136
|
-
* `fact_hash_stream`, and `FactStore`. The two agree on every input, and
|
|
137
|
-
* their JSON Schema is the same `pattern`.
|
|
138
|
-
*
|
|
139
|
-
* The output type is a cast over a plain regex check: Zod's
|
|
140
|
-
* `.brand('FactHash')` would output Zod's own brand, which doesn't fit
|
|
141
|
-
* fuz_util's fuz_schema-branded `FactHash`, and a `.transform` or `z.custom`
|
|
142
|
-
* that produced the right type has no JSON Schema form. The cast costs
|
|
143
|
-
* nothing at runtime and keeps the `ZodString` API and the `pattern`, so
|
|
144
|
-
* `.meta()`, `.nullable()`, and `z.array()` compose as before.
|
|
145
|
-
*/
|
|
146
|
-
export const ZodFactHashSchema = z
|
|
147
|
-
.string()
|
|
148
|
-
.regex(FACT_HASH_EXACT);
|
|
149
|
-
/**
|
|
150
|
-
* The Zod form of `ActingActor`, for a Zod input that needs the caller's
|
|
151
|
-
* acting actor: an optional `ZodUuid` carrying `ACTING_ACTOR_DESCRIPTION`.
|
|
152
|
-
* `ActingActor`'s doc has the resolution rules. The dispatcher finds it by
|
|
153
|
-
* reference, as it does `ActingActor`, so an input declares this export, not
|
|
154
|
-
* a copy of it.
|
|
155
|
-
*/
|
|
156
|
-
export const ZodActingActor = ZodUuid.optional().meta({ description: ACTING_ACTOR_DESCRIPTION });
|
|
157
|
-
register_zod_acting_actor(ZodActingActor);
|