@fuzdev/fuz_app 0.168.0 → 0.169.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 +1 -1
- package/dist/actions/action_codegen.d.ts +9 -7
- package/dist/actions/action_codegen.d.ts.map +1 -1
- package/dist/actions/action_codegen.js +20 -15
- package/dist/actions/action_event_data.d.ts +16 -16
- package/dist/actions/heartbeat.d.ts +1 -1
- package/dist/auth/account_action_specs.d.ts +11 -11
- package/dist/auth/account_action_specs.js +1 -1
- package/dist/auth/account_route_schema.d.ts +18 -18
- package/dist/auth/account_route_schema.js +1 -1
- package/dist/auth/account_routes.js +1 -1
- package/dist/auth/account_schema.d.ts +38 -40
- package/dist/auth/account_schema.d.ts.map +1 -1
- package/dist/auth/account_schema.js +7 -8
- package/dist/auth/actor_lookup_action_specs.d.ts +7 -7
- package/dist/auth/actor_lookup_action_specs.js +1 -1
- package/dist/auth/actor_search_action_specs.d.ts +6 -6
- package/dist/auth/actor_search_action_specs.js +1 -1
- package/dist/auth/admin_action_specs.d.ts +166 -166
- package/dist/auth/admin_action_specs.js +1 -1
- package/dist/auth/app_settings_schema.d.ts +3 -3
- package/dist/auth/app_settings_schema.d.ts.map +1 -1
- package/dist/auth/app_settings_schema.js +1 -1
- package/dist/auth/audit_log_route_schema.d.ts +1 -1
- package/dist/auth/audit_log_route_schema.js +1 -1
- package/dist/auth/audit_log_schema.d.ts +61 -61
- package/dist/auth/audit_log_schema.d.ts.map +1 -1
- package/dist/auth/audit_log_schema.js +1 -1
- package/dist/auth/bootstrap_route_schema.d.ts +4 -4
- package/dist/auth/bootstrap_route_schema.js +1 -1
- package/dist/auth/cell_action_specs.d.ts +424 -424
- package/dist/auth/cell_action_specs.js +1 -1
- package/dist/auth/cell_audit_action_specs.d.ts +14 -14
- package/dist/auth/cell_audit_action_specs.js +1 -1
- package/dist/auth/cell_audit_metadata.d.ts +8 -8
- package/dist/auth/cell_audit_metadata.js +1 -1
- package/dist/auth/cell_field_action_specs.d.ts +55 -55
- package/dist/auth/cell_field_action_specs.js +1 -1
- package/dist/auth/cell_field_audit_metadata.d.ts +4 -4
- package/dist/auth/cell_field_audit_metadata.js +1 -1
- package/dist/auth/cell_grant_action_specs.d.ts +61 -61
- package/dist/auth/cell_grant_action_specs.js +1 -1
- package/dist/auth/cell_grant_audit_metadata.d.ts +10 -10
- package/dist/auth/cell_grant_audit_metadata.js +1 -1
- package/dist/auth/cell_item_action_specs.d.ts +76 -76
- package/dist/auth/cell_item_action_specs.js +1 -1
- package/dist/auth/cell_item_audit_metadata.d.ts +5 -5
- package/dist/auth/cell_item_audit_metadata.js +1 -1
- package/dist/auth/invite_schema.d.ts +11 -11
- package/dist/auth/invite_schema.d.ts.map +1 -1
- package/dist/auth/invite_schema.js +1 -1
- package/dist/auth/name_schema.js +1 -1
- package/dist/auth/password.js +1 -1
- package/dist/auth/role_grant_offer_action_specs.d.ts +182 -182
- package/dist/auth/role_grant_offer_action_specs.js +1 -1
- package/dist/auth/role_grant_offer_notifications.d.ts +107 -107
- package/dist/auth/role_grant_offer_notifications.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_notifications.js +1 -1
- package/dist/auth/role_grant_offer_schema.d.ts +9 -9
- package/dist/auth/role_grant_offer_schema.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_schema.js +1 -1
- package/dist/auth/self_service_role_action_specs.d.ts +2 -2
- package/dist/auth/self_service_role_action_specs.js +1 -1
- package/dist/auth/signup_route_schema.d.ts +2 -2
- package/dist/auth/signup_route_schema.js +1 -1
- package/dist/auth/token_scope.d.ts +8 -8
- package/dist/db/file_fact_url.d.ts +1 -1
- package/dist/http/CLAUDE.md +7 -7
- package/dist/http/auth_shape.d.ts +15 -32
- package/dist/http/auth_shape.d.ts.map +1 -1
- package/dist/http/auth_shape.js +31 -38
- package/dist/http/db_routes.d.ts +1 -1
- package/dist/http/db_routes.d.ts.map +1 -1
- package/dist/http/db_routes.js +1 -1
- package/dist/http/error_schemas.d.ts +18 -18
- package/dist/http/jsonrpc.d.ts +11 -11
- package/dist/http/schema_helpers.d.ts +2 -2
- package/dist/http/schema_helpers.d.ts.map +1 -1
- package/dist/http/schema_helpers.js +8 -7
- package/dist/primitive_schemas.d.ts +173 -115
- package/dist/primitive_schemas.d.ts.map +1 -1
- package/dist/primitive_schemas.js +134 -158
- package/dist/schema_issues.d.ts +10 -7
- package/dist/schema_issues.d.ts.map +1 -1
- package/dist/schema_issues.js +38 -8
- package/dist/server/serve_fact_route.js +1 -1
- package/dist/server/surface_route.js +1 -1
- package/dist/testing/CLAUDE.md +3 -3
- package/dist/testing/cross_backend/conformance_case.d.ts +96 -114
- package/dist/testing/cross_backend/conformance_case.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_case.js +0 -256
- package/dist/testing/cross_backend/fact_serving.js +1 -1
- package/dist/testing/cross_backend/setup.d.ts +1 -1
- package/dist/testing/cross_backend/setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/setup.js +3 -4
- package/dist/testing/cross_backend/testing_origin_check.d.ts +8 -8
- package/dist/testing/cross_backend/testing_reset_actions.d.ts +608 -201
- package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_reset_actions.js +46 -55
- package/dist/testing/cross_backend/ws_outbound_overflow.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_outbound_overflow.js +35 -0
- package/dist/testing/rpc_helpers.d.ts +1 -1
- package/dist/testing/rpc_helpers.d.ts.map +1 -1
- package/dist/testing/rpc_helpers.js +0 -1
- package/dist/testing/schema_generators.js +1 -13
- package/dist/testing/schema_introspect.d.ts +438 -78
- package/dist/testing/schema_introspect.d.ts.map +1 -1
- package/dist/testing/schema_introspect.js +26 -26
- package/dist/testing/transports/bootstrap.d.ts +1 -1
- package/dist/testing/transports/bootstrap.d.ts.map +1 -1
- package/dist/testing/transports/bootstrap.js +1 -1
- package/dist/ui/BootstrapForm.svelte +1 -2
- package/dist/ui/BootstrapForm.svelte.d.ts.map +1 -1
- package/dist/ui/SignupForm.svelte +1 -2
- package/dist/ui/SignupForm.svelte.d.ts.map +1 -1
- package/dist/ui/admin_accounts_state.svelte.d.ts +5 -5
- package/dist/ui/admin_accounts_state.svelte.d.ts.map +1 -1
- package/dist/ui/admin_invites_state.svelte.d.ts +1 -1
- package/dist/ui/admin_invites_state.svelte.d.ts.map +1 -1
- package/dist/ui/admin_sessions_state.svelte.d.ts +2 -2
- package/dist/ui/admin_sessions_state.svelte.d.ts.map +1 -1
- package/dist/ui/role_grant_offers_state.svelte.d.ts +1 -1
- package/dist/zod.d.ts +18 -3
- package/dist/zod.d.ts.map +1 -1
- package/dist/zod.js +26 -3
- package/dist/zod_schemas.d.ts +100 -0
- package/dist/zod_schemas.d.ts.map +1 -0
- package/dist/zod_schemas.js +157 -0
- package/package.json +5 -5
- package/dist/primitive_schemas_fuz.d.ts +0 -178
- package/dist/primitive_schemas_fuz.d.ts.map +0 -1
- package/dist/primitive_schemas_fuz.js +0 -149
|
@@ -1,96 +1,44 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Reusable validator-schema primitives
|
|
3
|
-
* `
|
|
4
|
-
*
|
|
5
|
-
* the
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
2
|
+
* Reusable validator-schema primitives, in `@fuzdev/fuz_schema` —
|
|
3
|
+
* `bounded_string`, `Username` with `UsernameCanonical` and
|
|
4
|
+
* `UsernameProvided`, `Email`, the branded `Uuid` with its factory,
|
|
5
|
+
* `Timestamp`, the hash schemas `FactHashSchema` and `Blake3Hash`, and
|
|
6
|
+
* `ActingActor`. Lives at the top level (not inside `auth/` or `http/`)
|
|
7
|
+
* because these shapes don't depend on or imply any domain — accounts hold a
|
|
8
|
+
* username and email, but invites, password resets, cells, and other surfaces
|
|
9
|
+
* all reach for the same primitives without going through auth. A URL is
|
|
10
|
+
* `Url` from `@fuzdev/fuz_util/url.ts`.
|
|
11
|
+
*
|
|
12
|
+
* The Zod forms a consumer's Zod schema embeds — `ZodUuid`,
|
|
13
|
+
* `ZodUuidWithDefault`, `ZodFactHashSchema`, `ZodUsername`,
|
|
14
|
+
* `ZodActingActor` — are in `zod_schemas.ts`, built on the grammars here and
|
|
15
|
+
* sharing their output types, so a value parsed by either goes where the
|
|
16
|
+
* other's is taken.
|
|
15
17
|
*
|
|
16
18
|
* Client-safe: nothing here imports `@fuzdev/blake3-wasm`, so wire schemas
|
|
17
19
|
* that validate a hash don't pull the WASM binary into a bundle.
|
|
18
20
|
*
|
|
19
21
|
* @module
|
|
20
22
|
*/
|
|
21
|
-
import {
|
|
23
|
+
import { meta } from '@fuzdev/fuz_schema/meta.ts';
|
|
24
|
+
import { brand, check, iso_datetime, max_length, message, min_length, optional, pipe, regex, string, to_lower_case, transform, uuid, with_default_fn } from '@fuzdev/fuz_schema/schema.ts';
|
|
22
25
|
import { FACT_HASH_EXACT } from '@fuzdev/fuz_util/hash_schemas.ts';
|
|
23
26
|
/**
|
|
24
27
|
* A string schema whose length is bounded in UTF-16 code units — what
|
|
25
28
|
* `String.length` measures, and what the Rust spine counts
|
|
26
29
|
* (`encode_utf16().count()`), so an astral-plane character costs two on both.
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* installed Zod they count code units or Unicode code points, and the peer
|
|
32
|
-
* range admits both. The schema still carries them — they are what puts
|
|
33
|
-
* `minLength` / `maxLength` in the generated JSON Schema — and a check beside
|
|
34
|
-
* them settles the verdict on `String.length`: it adds the over-`max` or
|
|
35
|
-
* under-`min` issue when Zod raised none, and withdraws one Zod raised for a
|
|
36
|
-
* string that is within the bound in units. The issue it adds has the fields
|
|
37
|
-
* of Zod's own and, like Zod's, lets the checks chained after it run, so a
|
|
38
|
-
* refusal reads the same whichever count Zod used.
|
|
39
|
-
*
|
|
40
|
-
* Returns a plain `ZodString`, so format checks, `.brand()`, `.nullish()` and
|
|
41
|
-
* `.meta()` chain as usual. Don't chain a further `.min()` / `.max()` — pass
|
|
42
|
-
* the bound here.
|
|
30
|
+
* fuz_schema's `min_length` / `max_length` read `String.length`. Every length
|
|
31
|
+
* bound on a wire string in the package is built here. Its JSON Schema
|
|
32
|
+
* carries `minLength` / `maxLength`; `max_message` replaces fuz_schema's
|
|
33
|
+
* message on the over-`max` issue.
|
|
43
34
|
*
|
|
44
|
-
* @param options - the bounds, in UTF-16 code units
|
|
35
|
+
* @param options - the bounds, in UTF-16 code units, and the max message
|
|
45
36
|
* @returns the bounded string schema
|
|
46
37
|
*/
|
|
47
38
|
export const bounded_string = (options) => {
|
|
48
39
|
const { min, max, max_message } = options;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
schema = schema.min(min);
|
|
52
|
-
schema = max_message === undefined ? schema.max(max) : schema.max(max, max_message);
|
|
53
|
-
return schema.check((ctx) => {
|
|
54
|
-
const { length } = ctx.value;
|
|
55
|
-
const { issues } = ctx;
|
|
56
|
-
const too_big = issues.findIndex((i) => i.code === 'too_big' && i.origin === 'string' && i.maximum === max);
|
|
57
|
-
if (length > max) {
|
|
58
|
-
if (too_big === -1) {
|
|
59
|
-
issues.push({
|
|
60
|
-
origin: 'string',
|
|
61
|
-
code: 'too_big',
|
|
62
|
-
maximum: max,
|
|
63
|
-
inclusive: true,
|
|
64
|
-
input: ctx.value,
|
|
65
|
-
// as on Zod's own length issues: the checks chained after still run
|
|
66
|
-
continue: true,
|
|
67
|
-
// `path` ahead of `message`, the key order of Zod's finalized issue
|
|
68
|
-
...(max_message !== undefined && { path: [], message: max_message })
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
else if (too_big !== -1) {
|
|
73
|
-
issues.splice(too_big, 1);
|
|
74
|
-
}
|
|
75
|
-
if (min === undefined)
|
|
76
|
-
return;
|
|
77
|
-
const too_small = issues.findIndex((i) => i.code === 'too_small' && i.origin === 'string' && i.minimum === min);
|
|
78
|
-
if (length < min) {
|
|
79
|
-
if (too_small === -1) {
|
|
80
|
-
issues.push({
|
|
81
|
-
origin: 'string',
|
|
82
|
-
code: 'too_small',
|
|
83
|
-
minimum: min,
|
|
84
|
-
inclusive: true,
|
|
85
|
-
input: ctx.value,
|
|
86
|
-
continue: true
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
else if (too_small !== -1) {
|
|
91
|
-
issues.splice(too_small, 1);
|
|
92
|
-
}
|
|
93
|
-
});
|
|
40
|
+
const max_step = max_message === undefined ? max_length(max) : message(max_length(max), max_message);
|
|
41
|
+
return min === undefined ? pipe(string, max_step) : pipe(string, min_length(min), max_step);
|
|
94
42
|
};
|
|
95
43
|
/** Minimum username length (must have start + middle + end characters). */
|
|
96
44
|
export const USERNAME_LENGTH_MIN = 3;
|
|
@@ -108,15 +56,45 @@ export const USERNAME_PROVIDED_LENGTH_MAX = 255;
|
|
|
108
56
|
* Username for account creation — starts with letter, alphanumeric/dash/underscore middle, ends with alphanumeric. No @ or . allowed.
|
|
109
57
|
*
|
|
110
58
|
* Canonicalized to lowercase at parse time. The regex rejects whitespace
|
|
111
|
-
* outright, so
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
59
|
+
* outright, so no trim is needed. Storage is canonical across every creation
|
|
60
|
+
* site (bootstrap, signup, admin-create, invite acceptance) because the
|
|
61
|
+
* schema is the single source of truth — eliminates the per-caller
|
|
62
|
+
* `trim().toLowerCase()` ritual and keeps the `LOWER(username) = LOWER($1)`
|
|
63
|
+
* lookup contract simple. A string outside the bounds and off the grammar
|
|
64
|
+
* gets the length issue alone.
|
|
65
|
+
*/
|
|
66
|
+
export const Username = pipe(bounded_string({ min: USERNAME_LENGTH_MIN, max: USERNAME_LENGTH_MAX }), regex(USERNAME_REGEX), to_lower_case);
|
|
67
|
+
/**
|
|
68
|
+
* A username's canonical grammar, `USERNAME_REGEX` in lowercase: a lowercase
|
|
69
|
+
* letter, then lowercase letters, digits, `_` or `-`, ending in a lowercase
|
|
70
|
+
* letter or digit. What `Username` outputs, and what an `account` row holds
|
|
71
|
+
* (its `account_username_lowercase` CHECK).
|
|
72
|
+
*/
|
|
73
|
+
export const USERNAME_CANONICAL_REGEX = /^[a-z][0-9a-z_-]*[0-9a-z]$/;
|
|
74
|
+
/**
|
|
75
|
+
* A username as an account row holds it, the `username` of an output: the
|
|
76
|
+
* bounds of `Username` and `USERNAME_CANONICAL_REGEX`, no transform. A
|
|
77
|
+
* username in any other case fails, where `Username` lowercases it.
|
|
78
|
+
*/
|
|
79
|
+
export const UsernameCanonical = pipe(bounded_string({ min: USERNAME_LENGTH_MIN, max: USERNAME_LENGTH_MAX }), regex(USERNAME_CANONICAL_REGEX));
|
|
80
|
+
/**
|
|
81
|
+
* Username submitted for login or lookup — minimal validation, for
|
|
82
|
+
* forward-compatibility if the creation grammar changes: at least one and at
|
|
83
|
+
* most `USERNAME_PROVIDED_LENGTH_MAX` UTF-16 code units, measured before
|
|
84
|
+
* trimming, holding a character that isn't whitespace.
|
|
85
|
+
*
|
|
86
|
+
* Canonicalized to `.trim().toLowerCase()` at parse time, so login's
|
|
87
|
+
* per-account rate-limit key and its lookup see one value whatever the casing
|
|
88
|
+
* or surrounding whitespace, as `Username` canonicalizes what is stored.
|
|
89
|
+
*
|
|
90
|
+
* A whitespace-only identifier is refused, not canonicalized to `""` and left
|
|
91
|
+
* to fall through to a lookup-miss 401: an empty identifier is malformed
|
|
92
|
+
* input, not a wrong credential, and the Rust spine's `account_login` refuses
|
|
93
|
+
* it too. JS `\s` is exactly the set `trim` removes (ECMA-262's WhiteSpace and
|
|
94
|
+
* LineTerminator), so the `regex` ahead of the transform refuses what would
|
|
95
|
+
* trim to nothing.
|
|
116
96
|
*/
|
|
117
|
-
export const
|
|
118
|
-
.regex(USERNAME_REGEX)
|
|
119
|
-
.transform((s) => s.toLowerCase());
|
|
97
|
+
export const UsernameProvided = pipe(bounded_string({ min: 1, max: USERNAME_PROVIDED_LENGTH_MAX }), message(regex(/\S/), 'Username must not be empty after trimming whitespace'), transform((s) => s.trim().toLowerCase()));
|
|
120
98
|
/**
|
|
121
99
|
* Maximum email length in **bytes** — RFC 5321 §4.5.3.1.3 path-length limit
|
|
122
100
|
* (the limit is octets). `Email` bounds the UTF-8 byte length, matching the
|
|
@@ -145,13 +123,13 @@ export const EMAIL_LENGTH_MAX = 254;
|
|
|
145
123
|
* language, is quadratic: it tries every `.` as the split.
|
|
146
124
|
*/
|
|
147
125
|
export const EMAIL_REGEX = /^[^\s\u0085@]+@[^\s\u0085@.]+\.[^\s\u0085@]*[^\s\u0085@.]$/;
|
|
148
|
-
/** The message of an email over `EMAIL_LENGTH_MAX` bytes, on
|
|
126
|
+
/** The message of an email over `EMAIL_LENGTH_MAX` bytes, on `Email`. */
|
|
149
127
|
export const EMAIL_LENGTH_MESSAGE = `Email must be at most ${EMAIL_LENGTH_MAX} bytes`;
|
|
150
128
|
/** UTF-8 encoder for the `EMAIL_LENGTH_MAX` byte (octet) bound. */
|
|
151
129
|
const utf8_encoder = new TextEncoder();
|
|
152
130
|
/**
|
|
153
|
-
* Whether `s` is at most `EMAIL_LENGTH_MAX` bytes in UTF-8, the bound
|
|
154
|
-
*
|
|
131
|
+
* Whether `s` is at most `EMAIL_LENGTH_MAX` bytes in UTF-8, the bound `Email`
|
|
132
|
+
* checks.
|
|
155
133
|
*
|
|
156
134
|
* `s.length` (UTF-16 units) is a cheap upper bound that short-circuits the
|
|
157
135
|
* `encode` on absurd inputs: a valid (<= 254-byte) address is necessarily
|
|
@@ -164,29 +142,26 @@ const utf8_encoder = new TextEncoder();
|
|
|
164
142
|
export const is_email_within_length_max = (s) => s.length <= EMAIL_LENGTH_MAX && utf8_encoder.encode(s).length <= EMAIL_LENGTH_MAX;
|
|
165
143
|
/**
|
|
166
144
|
* Email validation. Every current consumer pairs it with `Username` (signup,
|
|
167
|
-
* invites, audit log), so the two live together with the other
|
|
168
|
-
* primitives.
|
|
145
|
+
* invites, audit log), so the two live together with the other primitives.
|
|
169
146
|
*
|
|
170
147
|
* Deliberately permissive — a structural shape check (`EMAIL_REGEX` plus the
|
|
171
148
|
* `EMAIL_LENGTH_MAX` byte bound), not RFC 5322 conformance or deliverability
|
|
172
|
-
* (real delivery is proven by a confirmation email).
|
|
173
|
-
*
|
|
174
|
-
* `
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
149
|
+
* (real delivery is proven by a confirmation email). The rule is one explicit
|
|
150
|
+
* regex the Rust spine's `is_valid_email` mirrors, looser than Zod's
|
|
151
|
+
* `z.email()` (2+ char TLD, no consecutive dots), which rejected addresses
|
|
152
|
+
* like `a@b.c`. The length bound is the UTF-8 **byte** count (RFC 5321
|
|
153
|
+
* measures octets), so a multibyte address is bounded identically to the
|
|
154
|
+
* Rust spine's `s.len()`. No transform: case is preserved and surrounding
|
|
155
|
+
* whitespace is rejected (not trimmed), so storage is verbatim and the
|
|
156
|
+
* case-insensitive lookup rides the DB-side `LOWER(email)`.
|
|
157
|
+
*
|
|
158
|
+
* The `max_length` ahead of the grammar refuses a string past the bound in
|
|
159
|
+
* UTF-16 code units, which is past it in bytes too, before the regex reads
|
|
160
|
+
* it, and the `check` after it the multibyte address within the units but
|
|
161
|
+
* past the bytes, both with `EMAIL_LENGTH_MESSAGE`. Its JSON Schema carries
|
|
162
|
+
* the bound as `maxLength`.
|
|
185
163
|
*/
|
|
186
|
-
export const Email =
|
|
187
|
-
.string()
|
|
188
|
-
.refine(is_email_within_length_max, { message: EMAIL_LENGTH_MESSAGE, abort: true })
|
|
189
|
-
.regex(EMAIL_REGEX);
|
|
164
|
+
export const Email = pipe(string, message(max_length(EMAIL_LENGTH_MAX), EMAIL_LENGTH_MESSAGE), regex(EMAIL_REGEX), message(check(is_email_within_length_max), EMAIL_LENGTH_MESSAGE));
|
|
190
165
|
/** Returns a new random (v4) `Uuid`. */
|
|
191
166
|
export const create_uuid = () => crypto.randomUUID();
|
|
192
167
|
/**
|
|
@@ -195,65 +170,66 @@ export const create_uuid = () => crypto.randomUUID();
|
|
|
195
170
|
* the max UUID. It is `z.uuid()`'s own but for the max UUID, which `z.uuid()`
|
|
196
171
|
* spells in lowercase only, where RFC 9562 §4 reads a UUID case-insensitively.
|
|
197
172
|
* The same source as the pattern fuz_schema's `uuid` renders to JSON Schema,
|
|
198
|
-
* which a test holds it to,
|
|
199
|
-
* `is_valid_uuid`.
|
|
173
|
+
* which a test holds it to, the `pattern` of `ZodUuid`, and the grammar of
|
|
174
|
+
* the Rust spine's `is_valid_uuid`.
|
|
200
175
|
*/
|
|
201
|
-
const UUID_REGEX = /^(?:[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|[fF]{8}-[fF]{4}-[fF]{4}-[fF]{4}-[fF]{12})$/;
|
|
176
|
+
export const UUID_REGEX = /^(?:[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|[fF]{8}-[fF]{4}-[fF]{4}-[fF]{4}-[fF]{12})$/;
|
|
202
177
|
/**
|
|
203
|
-
* Branded UUID schema
|
|
204
|
-
*
|
|
205
|
-
* compares equal to the same id read back
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
* any case. Issues and JSON Schema keep `format: 'uuid'`; only the `pattern`
|
|
209
|
-
* differs from a bare `z.uuid()`'s, rendered or on a Zod issue (the wire
|
|
210
|
-
* issue drops it).
|
|
211
|
-
*
|
|
212
|
-
* `pattern` is a `$ZodUUIDDef` field that `z.uuid()` honors (its default
|
|
213
|
-
* applies only when none is given) but whose public params type omits it,
|
|
214
|
-
* hence the cast on the params.
|
|
215
|
-
*
|
|
216
|
-
* `.toLowerCase()` rather than `.transform()`: an overwrite keeps the output
|
|
217
|
-
* type and stays invisible to `z.toJSONSchema`, where a transform would leave
|
|
218
|
-
* no input schema to render.
|
|
219
|
-
*
|
|
220
|
-
* The output type is fuz_schema's `Branded<string, 'Uuid'>`, the twin's, by a
|
|
221
|
-
* cast as on `FactHashSchema`: Zod's `.brand('Uuid')` would output Zod's own
|
|
222
|
-
* brand, which a fuz_schema `Uuid` isn't assignable to.
|
|
178
|
+
* Branded UUID schema: a UUID of RFC 9562 in either case, fuz_schema's `uuid`
|
|
179
|
+
* (whose grammar is `UUID_REGEX`), output in lowercase — the form Postgres renders a `uuid` in and every id
|
|
180
|
+
* the server mints — so a parsed id compares equal to the same id read back
|
|
181
|
+
* from the database. The Rust spine canonicalizes the same way. The brand
|
|
182
|
+
* goes outside the `to_lower_case`, which outputs a new string.
|
|
223
183
|
*/
|
|
224
|
-
export const Uuid =
|
|
225
|
-
.uuid({ pattern: UUID_REGEX })
|
|
226
|
-
.toLowerCase();
|
|
184
|
+
export const Uuid = brand(pipe(string, uuid, to_lower_case), 'Uuid');
|
|
227
185
|
/** `Uuid` that defaults to a fresh `create_uuid()` when the input is `undefined`. */
|
|
228
|
-
export const UuidWithDefault = Uuid
|
|
186
|
+
export const UuidWithDefault = with_default_fn(Uuid, create_uuid);
|
|
229
187
|
/**
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
* the `
|
|
234
|
-
* `iso_datetime` is this grammar with the seconds required and the fraction
|
|
235
|
-
* capped at 9 digits.
|
|
188
|
+
* A timestamp on the wire: a date and time of RFC 3339 in UTC, fuz_schema's
|
|
189
|
+
* `iso_datetime`, which both spines' `YYYY-MM-DDTHH:MM:SSZ`
|
|
190
|
+
* (`iso8601_timestamp_column`) and a `toISOString()` stamp satisfy. Not
|
|
191
|
+
* branded, unlike the Zod `Datetime` of `zod_schemas.ts`.
|
|
236
192
|
*/
|
|
237
|
-
export const
|
|
238
|
-
/** Returns an ISO 8601 datetime string for the current time. */
|
|
239
|
-
export const get_datetime_now = () => new Date().toISOString();
|
|
240
|
-
/** `Datetime` that defaults to `get_datetime_now()` when the input is `undefined`. */
|
|
241
|
-
export const DatetimeNow = Datetime.default(get_datetime_now);
|
|
193
|
+
export const Timestamp = pipe(string, iso_datetime);
|
|
242
194
|
/**
|
|
243
|
-
*
|
|
195
|
+
* A `blake3:`-prefixed fact hash on the wire: `FACT_HASH_EXACT`, its output
|
|
244
196
|
* `FactHash` from `@fuzdev/fuz_util/hash_schemas.ts` — the type
|
|
245
|
-
* `fact_hash_bytes`, `fact_hash_stream`, and `FactStore`
|
|
197
|
+
* `fact_hash_bytes`, `fact_hash_stream`, and `FactStore` take — so a parsed
|
|
246
198
|
* value passes straight to them. Client-side (cell payloads) and server-side
|
|
247
|
-
* (DB-row hashes) consumers reuse this same schema.
|
|
248
|
-
*
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
199
|
+
* (DB-row hashes) consumers reuse this same schema. Its JSON Schema is the
|
|
200
|
+
* `pattern`.
|
|
201
|
+
*/
|
|
202
|
+
export const FactHashSchema = brand(pipe(string, regex(FACT_HASH_EXACT)), 'FactHash');
|
|
203
|
+
/** A BLAKE3 hex hash's grammar: 64 lowercase hex characters (256-bit output). */
|
|
204
|
+
export const BLAKE3_HASH_REGEX = /^[0-9a-f]{64}$/;
|
|
205
|
+
/** The message of a string off `BLAKE3_HASH_REGEX`. */
|
|
206
|
+
export const BLAKE3_HASH_MESSAGE = 'Expected a 64-character lowercase hex blake3 hash';
|
|
207
|
+
/**
|
|
208
|
+
* A BLAKE3 hex hash: `BLAKE3_HASH_REGEX`, whose issue carries
|
|
209
|
+
* `BLAKE3_HASH_MESSAGE`. A value that is no string gets fuz_schema's message.
|
|
210
|
+
*/
|
|
211
|
+
export const Blake3Hash = pipe(string, message(regex(BLAKE3_HASH_REGEX), BLAKE3_HASH_MESSAGE));
|
|
212
|
+
/** The `description` of `ActingActor`, which `ZodActingActor` carries too. */
|
|
213
|
+
export const ACTING_ACTOR_DESCRIPTION = 'Actor on the authenticated account that this request acts as. Omit on single-actor accounts; required on multi-actor.';
|
|
214
|
+
/**
|
|
215
|
+
* `acting` field shared by every input that needs the caller's acting actor.
|
|
216
|
+
* Declaring `acting: ActingActor` on a route or action input signals to the
|
|
217
|
+
* dispatcher's authorization phase to resolve an actor against the
|
|
218
|
+
* authenticated account: it runs `resolve_acting_actor`, builds the
|
|
219
|
+
* actor-bound `RequestContext`, and loads role_grants before auth guards fire.
|
|
220
|
+
*
|
|
221
|
+
* Resolution rules: omitted + 1 actor → use it; omitted + multiple actors →
|
|
222
|
+
* `actor_required` with the available list; supplied + on the account → use
|
|
223
|
+
* it; supplied + foreign actor → `actor_not_on_account`.
|
|
224
|
+
*
|
|
225
|
+
* Account-grain routes — input doesn't declare `acting` and auth doesn't
|
|
226
|
+
* require role_grants — skip resolution entirely; their `RequestContext.actor`
|
|
227
|
+
* is `null` and the audit envelope's `actor_id` stays null.
|
|
228
|
+
*
|
|
229
|
+
* Paired with `RouteAuth` (`http/auth_shape.ts`) by registry-time invariant
|
|
230
|
+
* 2: `auth.actor !== 'none'` ⟺ input (or query, on REST GETs) declares
|
|
231
|
+
* `acting?: ActingActor`. The dispatcher finds it by reference
|
|
232
|
+
* (`input_schema_declares_acting`), so an input declares this export, not a
|
|
233
|
+
* copy of it; a Zod input declares `ZodActingActor` (`zod_schemas.ts`).
|
|
256
234
|
*/
|
|
257
|
-
export const
|
|
258
|
-
.string()
|
|
259
|
-
.regex(FACT_HASH_EXACT);
|
|
235
|
+
export const ActingActor = meta(optional(Uuid), { description: ACTING_ACTOR_DESCRIPTION });
|
package/dist/schema_issues.d.ts
CHANGED
|
@@ -9,14 +9,15 @@
|
|
|
9
9
|
*
|
|
10
10
|
* @module
|
|
11
11
|
*/
|
|
12
|
-
import { z } from 'zod';
|
|
12
|
+
import type { z } from 'zod';
|
|
13
13
|
import { SchemaError, type AnySchema, type Infer, type InferInput, type Schema, type SchemaIssue } from '@fuzdev/fuz_schema/schema.ts';
|
|
14
14
|
import type { Result } from '@fuzdev/fuz_util/result.ts';
|
|
15
15
|
/** A schema of either library: a Zod schema or a `@fuzdev/fuz_schema` one. */
|
|
16
16
|
export type ValidationSchema = z.ZodType | AnySchema;
|
|
17
17
|
/**
|
|
18
|
-
* Whether `value` is a Zod schema
|
|
19
|
-
*
|
|
18
|
+
* Whether `value` is a Zod schema of the classic API, as `z.ZodType`'s
|
|
19
|
+
* `instanceof` reads it (`zod_has_trait`): by the schema's traits, so a schema
|
|
20
|
+
* made by another copy of Zod is one too. Imports no Zod at runtime.
|
|
20
21
|
*
|
|
21
22
|
* @param value - any value
|
|
22
23
|
*/
|
|
@@ -116,8 +117,10 @@ export interface UnknownKeyTarget {
|
|
|
116
117
|
*/
|
|
117
118
|
export declare const unknown_key_targets: (issues: ReadonlyArray<AnyIssue>) => Array<UnknownKeyTarget> | null;
|
|
118
119
|
/**
|
|
119
|
-
* A failed parse's issues as text
|
|
120
|
-
*
|
|
120
|
+
* A failed parse's issues as text. Zod issues read as `z.prettifyError`
|
|
121
|
+
* writes them — shortest path first, each `✖ message` and, when it has a
|
|
122
|
+
* path, ` → at path` — without importing Zod at runtime; fuz_schema issues
|
|
123
|
+
* are their `format_issue` lines.
|
|
121
124
|
*
|
|
122
125
|
* @param issues - a failed parse's issues, all of one library
|
|
123
126
|
*/
|
|
@@ -139,16 +142,16 @@ export declare const is_schema_validation_error: (err: unknown) => err is z.ZodE
|
|
|
139
142
|
* Loose: a client reads it, and a newer server may add fields.
|
|
140
143
|
*/
|
|
141
144
|
export declare const WireIssue: Schema<{
|
|
145
|
+
kind: string;
|
|
142
146
|
message: string;
|
|
143
147
|
path: (string | number)[];
|
|
144
148
|
expected: string;
|
|
145
|
-
kind: string;
|
|
146
149
|
received: string;
|
|
147
150
|
} & Record<string, unknown>, {
|
|
151
|
+
kind: string;
|
|
148
152
|
message: string;
|
|
149
153
|
path: (string | number)[];
|
|
150
154
|
expected: string;
|
|
151
|
-
kind: string;
|
|
152
155
|
received: string;
|
|
153
156
|
} & Record<string, unknown>, "loose_object", {
|
|
154
157
|
/** The fuz_schema kind of the check that failed, or `unknown_key` / `missing_key`. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema_issues.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/schema_issues.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"schema_issues.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/schema_issues.ts"],"names":[],"mappings":"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"}
|
package/dist/schema_issues.js
CHANGED
|
@@ -9,15 +9,16 @@
|
|
|
9
9
|
*
|
|
10
10
|
* @module
|
|
11
11
|
*/
|
|
12
|
-
import { z } from 'zod';
|
|
13
12
|
import { array, format_issue, is_schema, loose_object, number, parse, SchemaError, string, union } from '@fuzdev/fuz_schema/schema.ts';
|
|
13
|
+
import { zod_has_trait } from './zod.js';
|
|
14
14
|
/**
|
|
15
|
-
* Whether `value` is a Zod schema
|
|
16
|
-
*
|
|
15
|
+
* Whether `value` is a Zod schema of the classic API, as `z.ZodType`'s
|
|
16
|
+
* `instanceof` reads it (`zod_has_trait`): by the schema's traits, so a schema
|
|
17
|
+
* made by another copy of Zod is one too. Imports no Zod at runtime.
|
|
17
18
|
*
|
|
18
19
|
* @param value - any value
|
|
19
20
|
*/
|
|
20
|
-
export const is_zod_schema = (value) => value
|
|
21
|
+
export const is_zod_schema = (value) => zod_has_trait(value, 'ZodType');
|
|
21
22
|
/**
|
|
22
23
|
* Throw unless `value` is a Zod schema, naming `label` — what a reader of a
|
|
23
24
|
* spec's schema calls once it has ruled out a `@fuzdev/fuz_schema` schema
|
|
@@ -125,9 +126,31 @@ export const unknown_key_targets = (issues) => {
|
|
|
125
126
|
}
|
|
126
127
|
return targets;
|
|
127
128
|
};
|
|
129
|
+
// a Zod issue path as `z.prettifyError` writes it: identifier keys dotted,
|
|
130
|
+
// numbers, symbols and other keys bracketed
|
|
131
|
+
const format_zod_path = (path) => {
|
|
132
|
+
const segments = [];
|
|
133
|
+
for (const seg of path) {
|
|
134
|
+
const key = typeof seg === 'object' && seg !== null ? seg.key : seg;
|
|
135
|
+
if (typeof key === 'number')
|
|
136
|
+
segments.push(`[${key}]`);
|
|
137
|
+
else if (typeof key === 'symbol')
|
|
138
|
+
segments.push(`[${JSON.stringify(String(key))}]`);
|
|
139
|
+
else if (/[^\w$]/.test(key))
|
|
140
|
+
segments.push(`[${JSON.stringify(key)}]`);
|
|
141
|
+
else {
|
|
142
|
+
if (segments.length)
|
|
143
|
+
segments.push('.');
|
|
144
|
+
segments.push(key);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return segments.join('');
|
|
148
|
+
};
|
|
128
149
|
/**
|
|
129
|
-
* A failed parse's issues as text
|
|
130
|
-
*
|
|
150
|
+
* A failed parse's issues as text. Zod issues read as `z.prettifyError`
|
|
151
|
+
* writes them — shortest path first, each `✖ message` and, when it has a
|
|
152
|
+
* path, ` → at path` — without importing Zod at runtime; fuz_schema issues
|
|
153
|
+
* are their `format_issue` lines.
|
|
131
154
|
*
|
|
132
155
|
* @param issues - a failed parse's issues, all of one library
|
|
133
156
|
*/
|
|
@@ -136,7 +159,14 @@ export const format_issues = (issues) => {
|
|
|
136
159
|
if (!first)
|
|
137
160
|
return '';
|
|
138
161
|
if (is_zod_issue(first)) {
|
|
139
|
-
|
|
162
|
+
const lines = [];
|
|
163
|
+
const sorted = [...issues].sort((a, b) => (a.path ?? []).length - (b.path ?? []).length);
|
|
164
|
+
for (const issue of sorted) {
|
|
165
|
+
lines.push(`✖ ${issue.message}`);
|
|
166
|
+
if (issue.path?.length)
|
|
167
|
+
lines.push(` → at ${format_zod_path(issue.path)}`);
|
|
168
|
+
}
|
|
169
|
+
return lines.join('\n');
|
|
140
170
|
}
|
|
141
171
|
return issues.map(format_issue).join('\n');
|
|
142
172
|
};
|
|
@@ -147,7 +177,7 @@ export const format_issues = (issues) => {
|
|
|
147
177
|
*
|
|
148
178
|
* @param err - a caught value
|
|
149
179
|
*/
|
|
150
|
-
export const is_schema_validation_error = (err) => err
|
|
180
|
+
export const is_schema_validation_error = (err) => zod_has_trait(err, 'ZodError') || err instanceof SchemaError;
|
|
151
181
|
/**
|
|
152
182
|
* A `@fuzdev/fuz_schema` `loose_object`: a validation issue as an error
|
|
153
183
|
* response carries it, for either schema library — fuz_schema's `SchemaIssue`
|
|
@@ -133,7 +133,7 @@
|
|
|
133
133
|
import { open } from 'node:fs/promises';
|
|
134
134
|
import { Readable } from 'node:stream';
|
|
135
135
|
import { join } from 'node:path';
|
|
136
|
-
import { ActingActor, FactHashSchema, Uuid } from '../
|
|
136
|
+
import { ActingActor, FactHashSchema, Uuid } from '../primitive_schemas.js';
|
|
137
137
|
import { literal, object } from '@fuzdev/fuz_schema/schema.ts';
|
|
138
138
|
import { build_request_context, get_public_account_id, get_request_context, has_scoped_role } from '../auth/request_context.js';
|
|
139
139
|
import { ROLE_ADMIN } from '../auth/role_schema.js';
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
import { array, literal, loose_object, object } from '@fuzdev/fuz_schema/schema.ts';
|
|
11
11
|
import { define_route } from '../http/route_spec.js';
|
|
12
12
|
import { route_ok } from '../http/route_result.js';
|
|
13
|
-
import { ActingActor } from '../
|
|
13
|
+
import { ActingActor } from '../primitive_schemas.js';
|
|
14
14
|
import { ROLE_ADMIN } from '../auth/role_schema.js';
|
|
15
15
|
/**
|
|
16
16
|
* Create the admin-only route spec that serves the `AppSurface` as JSON.
|
package/dist/testing/CLAUDE.md
CHANGED
|
@@ -255,7 +255,7 @@ middleware never sets `TEST_CONTEXT_PRESET_KEY`, and only the symbol counts
|
|
|
255
255
|
### `schema_introspect.ts` — `query_schema_snapshot`
|
|
256
256
|
|
|
257
257
|
- `query_schema_snapshot(db, options?)` — introspects a live DB into a deterministic `SchemaSnapshot` via `pg_catalog` + `information_schema`. Throws on pglet when the snapshot holds an index, unless `accept_pglet_index_definitions` is passed: pglet's `indexdef` omits index modifiers, so its index definitions read as false differences against PostgreSQL and false agreement between two pglet schemas. Captures tables, columns (with `udt_name` to distinguish int4/int8), indexes (`indexdef`), constraints (`pg_get_constraintdef`), sequences, and enum types (`pg_enum` labels in declared `enumsortorder`, so a `cell_visibility` label-set/order drift is gated). The `schema_version` migration tracker is always excluded — it's framework bookkeeping, not domain schema; twin impls keep it identical (same namespaces, names and partitioning), which `query_migration_tracker` + `assert_migration_trackers_equal` gate separately. Twinned by `fuz_db::query_schema_snapshot` (Rust); the `_testing_schema_snapshot` RPC's wire validator is the shared `SchemaSnapshot`, so the enum field must serialize on both sides.
|
|
258
|
-
- `SchemaSnapshot` — the
|
|
258
|
+
- `SchemaSnapshot` — the schema is canonical (a fuz_schema `strip_object`, co-located in `schema_introspect.ts` with its parts; the cross-impl `_testing_schema_snapshot` RPC action reuses it as its wire validator, and the type is `Infer`'d from it). Fully JSON-serializable; every collection deterministically sorted on capture so structural equality is stable across runs.
|
|
259
259
|
- `query_migration_tracker(db)` / `MigrationTracker` — the migration-_identity_ twin of the snapshot: reads the `schema_version` tracker rows (`[{namespace, name, sequence}]`) the snapshot deliberately _excludes_. `MigrationTracker` is the `_testing_migration_tracker` RPC's wire validator; pairs with `assert_migration_trackers_equal` to gate that the two spines record byte-identical migration identity (the swap-freely invariant), catching a migration-name or namespace-partitioning drift the provenance-agnostic schema snapshot can't see.
|
|
260
260
|
|
|
261
261
|
### `schema_parity.ts` — `assert_schema_snapshots_equal`
|
|
@@ -276,7 +276,7 @@ spine and the Rust `testing_spine_stub` mount the same method set with the same
|
|
|
276
276
|
per-method auth shape.
|
|
277
277
|
|
|
278
278
|
- `cross_backend/action_manifest.ts` — `ActionManifest` / `ActionManifestEntry`
|
|
279
|
-
|
|
279
|
+
fuz_schema schema (the `_testing_action_manifest` wire validator) + `build_action_manifest(specs)`,
|
|
280
280
|
which normalizes each spec to `{method, input, side_effects, account, actor, roles,
|
|
281
281
|
credential_types, rate_limit}` (`input` is `'void'` for a `z.void()` or
|
|
282
282
|
fuz_schema `s.void` input, by `is_void_schema`, else `'object'` — the Rust
|
|
@@ -1444,7 +1444,7 @@ conformance cases assert _expected behavior_ — the security negatives
|
|
|
1444
1444
|
(must be refused / must not leak / found-vs-not-found same shape) a
|
|
1445
1445
|
wire-shape check passes green on even when behavior is wrong.
|
|
1446
1446
|
|
|
1447
|
-
- `conformance_case.ts` — `ConformanceCase`
|
|
1447
|
+
- `conformance_case.ts` — the `ConformanceCase` type (types only; nothing parses a case):
|
|
1448
1448
|
`{name, request: {method, params?, params_json?, as, acting?, verb?}, expect: {status,
|
|
1449
1449
|
error_reason?, fields?, headers?, equivalence_group?}, note?, xfail?}`. A case is **data** — `method`
|
|
1450
1450
|
resolves its `input`/`output` from the live registry (RPC) or `RouteSpec`
|