@fuzdev/fuz_app 0.153.0 → 0.155.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.
Files changed (65) hide show
  1. package/dist/actions/CLAUDE.md +2 -2
  2. package/dist/actions/action_event.d.ts.map +1 -1
  3. package/dist/actions/action_event.js +14 -14
  4. package/dist/actions/peer_ping.js +3 -3
  5. package/dist/actions/perform_action.d.ts +12 -10
  6. package/dist/actions/perform_action.d.ts.map +1 -1
  7. package/dist/actions/perform_action.js +19 -16
  8. package/dist/auth/cell_actions.d.ts +6 -4
  9. package/dist/auth/cell_actions.d.ts.map +1 -1
  10. package/dist/auth/cell_actions.js +10 -9
  11. package/dist/env/env_schemas.d.ts +41 -0
  12. package/dist/env/env_schemas.d.ts.map +1 -0
  13. package/dist/env/env_schemas.js +55 -0
  14. package/dist/env/load.d.ts +23 -15
  15. package/dist/env/load.d.ts.map +1 -1
  16. package/dist/env/load.js +38 -22
  17. package/dist/http/CLAUDE.md +14 -8
  18. package/dist/http/schema_helpers.d.ts +102 -23
  19. package/dist/http/schema_helpers.d.ts.map +1 -1
  20. package/dist/http/schema_helpers.js +241 -38
  21. package/dist/http/surface.d.ts +20 -11
  22. package/dist/http/surface.d.ts.map +1 -1
  23. package/dist/http/surface.js +59 -32
  24. package/dist/primitive_schemas.d.ts +13 -4
  25. package/dist/primitive_schemas.d.ts.map +1 -1
  26. package/dist/primitive_schemas.js +13 -4
  27. package/dist/schema_issues.d.ts +96 -0
  28. package/dist/schema_issues.d.ts.map +1 -0
  29. package/dist/schema_issues.js +110 -0
  30. package/dist/schema_meta.d.ts +38 -13
  31. package/dist/schema_meta.d.ts.map +1 -1
  32. package/dist/schema_meta.js +63 -13
  33. package/dist/sensitivity.d.ts +34 -1
  34. package/dist/sensitivity.d.ts.map +1 -1
  35. package/dist/sensitivity.js +32 -2
  36. package/dist/server/app_server.d.ts +6 -5
  37. package/dist/server/app_server.d.ts.map +1 -1
  38. package/dist/server/app_server.js +0 -1
  39. package/dist/server/env.d.ts +52 -30
  40. package/dist/server/env.d.ts.map +1 -1
  41. package/dist/server/env.js +38 -43
  42. package/dist/testing/CLAUDE.md +23 -10
  43. package/dist/testing/adversarial_404.d.ts +15 -0
  44. package/dist/testing/adversarial_404.d.ts.map +1 -1
  45. package/dist/testing/adversarial_404.js +26 -19
  46. package/dist/testing/adversarial_input_cases.d.ts.map +1 -1
  47. package/dist/testing/adversarial_input_cases.js +2 -2
  48. package/dist/testing/app_server.js +2 -2
  49. package/dist/testing/cross_backend/cell_crud.d.ts.map +1 -1
  50. package/dist/testing/cross_backend/cell_crud.js +7 -5
  51. package/dist/testing/cross_backend/identity_parity.js +2 -2
  52. package/dist/testing/cross_backend/standard.d.ts +3 -2
  53. package/dist/testing/cross_backend/standard.d.ts.map +1 -1
  54. package/dist/testing/daemon_info.d.ts +7 -2
  55. package/dist/testing/daemon_info.d.ts.map +1 -1
  56. package/dist/testing/daemon_info.js +8 -3
  57. package/dist/testing/data_exposure.d.ts +43 -9
  58. package/dist/testing/data_exposure.d.ts.map +1 -1
  59. package/dist/testing/data_exposure.js +151 -35
  60. package/dist/testing/schema_generators.d.ts +21 -9
  61. package/dist/testing/schema_generators.d.ts.map +1 -1
  62. package/dist/testing/schema_generators.js +52 -47
  63. package/dist/testing/stubs.d.ts +2 -2
  64. package/dist/testing/stubs.d.ts.map +1 -1
  65. package/package.json +4 -4
@@ -281,7 +281,7 @@ Pipeline (401 → authz → 403 → 429 → 400 → handler):
281
281
  2. Authorization phase — `apply_authorization_phase` against `account_id` + `read_acting(auth, raw_params)`, which takes the selector off the raw params (malformed reads as omitted) since validation runs later. Test escape hatch via `preset.request_context`
282
282
  3. Post-authorization auth (403) — credential-type gate, then token scope, then role
283
283
  4. Rate limit (429) — throttle-requests semantics, ahead of validation so malformed params charge the budget and a throttled caller pays no schema work
284
- 5. Validate params (400) — first, object params holding an own `__proto__` key at any depth are refused on every input with `data.reason` `params_proto_key` (`json_has_own_proto_key` in `http/schema_helpers.ts`, an iterative walk; `ERROR_PARAMS_PROTO_KEY`; the Rust twin walks after its params-shape check, so a non-object `params` stays the schema's reasonless refusal); then `spec.input.safeParse` with `z.void()` / `?? {}` rules; a `z.void()` input reads absent, `null` (GET `?params=null`), and `{}` alike as the no-arg call (`to_input_params` in `http/schema_helpers.ts`, via `to_void_params`, the twin of the Rust `require_void_params`; the peer receive path in `ActionDispatcher` runs the same normalizer) and refuses any other shape. A refusal is `to_invalid_params_error`: the generic `invalid params`, `data.reason` when the first issue's field declares an `invalid_reason` in its `.meta()` and no issue sits on the input itself, such as an unknown key (`resolve_issues_invalid_reason`, `schema_meta.ts` — see ../../../docs/architecture.md §Error Schema System), and the Zod issues DEV-only
284
+ 5. Validate params (400) — first, object params holding an own `__proto__` key at any depth are refused on every input with `data.reason` `params_proto_key` (`json_has_own_proto_key` in `http/schema_helpers.ts`, an iterative walk; `ERROR_PARAMS_PROTO_KEY`; the Rust twin walks after its params-shape check, so a non-object `params` stays the schema's reasonless refusal); then `spec.input` parses them (`parse_any`, `schema_issues.ts` — a Zod or fuz_schema schema) with `z.void()` / `?? {}` rules; a `z.void()` input reads absent, `null` (GET `?params=null`), and `{}` alike as the no-arg call (`to_input_params` in `http/schema_helpers.ts`, via `to_void_params`, the twin of the Rust `require_void_params`; the peer receive path in `ActionDispatcher` runs the same normalizer) and refuses any other shape. A refusal is `to_invalid_params_error`: the generic `invalid params`, `data.reason` when the first issue's field declares an `invalid_reason` in its `.meta()` and no issue sits on the input itself, such as an unknown key (`resolve_issues_invalid_reason`, `schema_meta.ts` — see ../../../docs/architecture.md §Error Schema System), and the library's issues DEV-only
285
285
  6. Dispatch + DEV output validation + error normalization — `spec.side_effects` picks transaction vs pool. `ThrownJsonrpcError` preserves code + data; generic throws become `internal_error`
286
286
 
287
287
  `PerformActionInput` carries `auth` (the request's `ResolvedAuth`, `null` for
@@ -1072,7 +1072,7 @@ high-level shapes that span modules:
1072
1072
  - **39-variant discriminated union** — `ActionEventDataUnion<TMethod, TInput, TOutput>` across `kind` + `phase` + `step` (28 for `request_response`, 6 for `remote_notification`, 5 for `local_call`). Narrows `input` / `output` / `error` / `request` / `response` / `notification` / `progress` at each lifecycle point.
1073
1073
  - **Step transitions** — `initial → parsed | failed`, `parsed → handling | failed`, `handling → handled | failed`, `handled`/`failed` terminal. `validate_step_transition(from, to)` throws on illegal moves.
1074
1074
  - **Phase transitions** — chained: `send_request → receive_response`, `receive_request → send_response`; everything else terminal. `validate_phase_transition` enforces.
1075
- - **`ActionEvent.parse()`** — `initial → parsed` via `spec.input.safeParse`. Input validation failures **fail immediately** without routing through an error phase (client-side programming errors, not runtime conditions with handlers); their `invalid_params` `data` is `{validation_errors, reason?}`, `reason` the declared `invalid_reason` the server would answer. Handler errors DO route through `send_error` / `receive_error`. On `receive_response` with error response, transitions to `receive_error` instead of failing; a success response's `result` is validated against `spec.output` (always, not DEV-only — it's inbound data; undeclared keys are dropped rather than refused, so an older client survives an added response field) and `output` becomes the parsed value, or the event moves to `receive_error` with an `internal_error` carrying `data: {reason: ERROR_RESPONSE_OUTPUT_INVALID, validation_errors}` — a remote contract break, deliberately distinct from the `invalid_params` / `validation_error` of bad caller input.
1075
+ - **`ActionEvent.parse()`** — `initial → parsed` via `parse_any(spec.input, …)`. Input validation failures **fail immediately** without routing through an error phase (client-side programming errors, not runtime conditions with handlers); their `invalid_params` `data` is `{validation_errors, reason?}`, `reason` the declared `invalid_reason` the server would answer. Handler errors DO route through `send_error` / `receive_error`. On `receive_response` with error response, transitions to `receive_error` instead of failing; a success response's `result` is validated against `spec.output` (always, not DEV-only — it's inbound data; undeclared keys are dropped rather than refused, so an older client survives an added response field) and `output` becomes the parsed value, or the event moves to `receive_error` with an `internal_error` carrying `data: {reason: ERROR_RESPONSE_OUTPUT_INVALID, validation_errors}` — a remote contract break, deliberately distinct from the `invalid_params` / `validation_error` of bad caller input.
1076
1076
  - **Handler throws** — `ThrownJsonrpcError` keeps code/message/data; any other throw becomes `internal_error` carrying the thrown message. When the error answers a remote caller (`receive_request` / `send_response`), the raw message goes through `dev_only` like the server dispatch core.
1077
1077
  - **Protocol message creation is automatic** — transitioning `parsed → handling` on `send_request` materializes the outgoing `JsonrpcRequest` with a fresh `create_uuid()` id; on `send` (notification) it materializes the `JsonrpcNotification`.
1078
1078
 
@@ -1 +1 @@
1
- {"version":3,"file":"action_event.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/actions/action_event.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,OAAO,KAAK,EAAE,gBAAgB,EAAc,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAiBtF,OAAO,KAAK,EACX,cAAc,EACd,sBAAsB,EACtB,mBAAmB,EAGnB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AACvF,OAAO,KAAK,EAAmB,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAapF;;;;GAIG;AACH,eAAO,MAAM,6BAA6B,EAAG,yBAAkC,CAAC;AAmBhF,MAAM,MAAM,yBAAyB,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM,IAAI,CACxE,QAAQ,EAAE,oBAAoB,CAAC,OAAO,CAAC,EACvC,QAAQ,EAAE,oBAAoB,CAAC,OAAO,CAAC,EACvC,KAAK,EAAE,WAAW,CAAC,OAAO,CAAC,KACvB,IAAI,CAAC;AAEV;;GAEG;AACH,qBAAa,WAAW,CACvB,OAAO,SAAS,MAAM,GAAG,MAAM,EAC/B,MAAM,SAAS,gBAAgB,GAAG,gBAAgB,EAClD,KAAK,SAAS,eAAe,GAAG,eAAe;;IAK/C,QAAQ,CAAC,WAAW,EAAE,sBAAsB,CAAC;IAC7C;;;;;;OAMG;IACH,QAAQ,CAAC,IAAI,EAAE,eAAe,GAAG;QAAE,MAAM,EAAE,OAAO,CAAA;KAAE,CAAC;IAErD,IAAI,IAAI,IAAI,oBAAoB,CAAC,OAAO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;IAOpC,MAAM,IAAI,oBAAoB,CAAC,OAAO,CAAC;IAMvC;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ,EAAE,yBAAyB,CAAC,OAAO,CAAC,GAAG,MAAM,IAAI;IAKjE;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,oBAAoB,CAAC,OAAO,CAAC,GAAG,IAAI;IAUvD;;;;;;;;;;;;;;;;;OAiBG;IACH,KAAK,IAAI,IAAI;IAiEb;;;;;;;;;;OAUG;IAGG,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAsCnC;;;;;;;OAOG;IACH,WAAW,IAAI,IAAI;IA8BnB;;;;;;;;;;OAUG;IACH,UAAU,CAAC,KAAK,EAAE,gBAAgB,GAAG,IAAI;IAezC,WAAW,IAAI,OAAO;IAItB,eAAe,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI;IAIxC,WAAW,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI;IAQ1C,YAAY,CAAC,QAAQ,EAAE,sBAAsB,GAAG,IAAI;IAUpD,gBAAgB,CAAC,YAAY,EAAE,mBAAmB,GAAG,IAAI;CAgMzD;AAGD;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,GAAI,OAAO,SAAS,MAAM,GAAG,MAAM,EAClE,aAAa,sBAAsB,EACnC,MAAM,eAAe,EACrB,OAAO,OAAO,EACd,gBAAgB,gBAAgB,KAC9B,WAAW,CAAC,OAAO,CAmBrB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,6BAA6B,GAAI,OAAO,SAAS,MAAM,GAAG,MAAM,EAC5E,MAAM,oBAAoB,CAAC,OAAO,CAAC,EACnC,aAAa,sBAAsB,KACjC,WAAW,CAAC,OAAO,CAOrB,CAAC"}
@@ -6,13 +6,13 @@
6
6
  *
7
7
  * @module
8
8
  */
9
- import { z } from 'zod';
10
9
  import { create_uuid } from '../primitive_schemas.js';
11
10
  import { to_error_message } from '@fuzdev/fuz_util/error.ts';
12
11
  import { create_jsonrpc_request, create_jsonrpc_response, create_jsonrpc_error_response, create_jsonrpc_notification, to_jsonrpc_params, is_jsonrpc_error_response } from '../http/jsonrpc_helpers.js';
13
12
  import { dev_only, jsonrpc_error_messages, to_thrown_jsonrpc_error, UNKNOWN_ERROR_MESSAGE } from '../http/jsonrpc_errors.js';
14
13
  import { safe_parse_dropping_unknown_keys } from '../http/schema_helpers.js';
15
14
  import { resolve_issues_invalid_reason } from '../schema_meta.js';
15
+ import { format_issues, parse_any } from '../schema_issues.js';
16
16
  import { validate_step_transition, validate_phase_transition, should_validate_output, is_action_complete, create_initial_data, get_initial_phase, is_request_response, is_send_request_with_parsed_input, is_notification_send_with_parsed_input } from './action_event_helpers.js';
17
17
  /**
18
18
  * `error.data.reason` on the `internal_error` a client reports when a
@@ -26,8 +26,8 @@ export const ERROR_RESPONSE_OUTPUT_INVALID = 'response_output_invalid';
26
26
  * answer the same input with, so a caller matching `data.reason` reads one
27
27
  * value whichever side refused.
28
28
  */
29
- const to_local_invalid_params_data = (input, issues) => {
30
- const reason = resolve_issues_invalid_reason(input, issues);
29
+ const to_local_invalid_params_data = (input, issues, value) => {
30
+ const reason = resolve_issues_invalid_reason(input, issues, value);
31
31
  return reason === undefined
32
32
  ? { validation_errors: issues }
33
33
  : { validation_errors: issues, reason };
@@ -123,11 +123,11 @@ export class ActionEvent {
123
123
  // Input was already validated in the predecessor phase.
124
124
  if (this.#data.phase === 'receive_response') {
125
125
  const parsed = safe_parse_dropping_unknown_keys(this.spec.output, this.#data.output);
126
- if (parsed.success) {
127
- this.#transition_step('parsed', { output: parsed.data });
126
+ if (parsed.ok) {
127
+ this.#transition_step('parsed', { output: parsed.value });
128
128
  }
129
129
  else {
130
- this.#transition_to_error_phase('receive_error', jsonrpc_error_messages.internal_error(`response failed output validation for ${this.spec.method}: ${z.prettifyError(parsed.error)}`, { reason: ERROR_RESPONSE_OUTPUT_INVALID, validation_errors: parsed.error.issues }));
130
+ this.#transition_to_error_phase('receive_error', jsonrpc_error_messages.internal_error(`response failed output validation for ${this.spec.method}: ${format_issues(parsed.issues)}`, { reason: ERROR_RESPONSE_OUTPUT_INVALID, validation_errors: parsed.issues }));
131
131
  }
132
132
  return this;
133
133
  }
@@ -137,9 +137,9 @@ export class ActionEvent {
137
137
  return this;
138
138
  }
139
139
  }
140
- const parsed = this.spec.input.safeParse(this.#data.input);
141
- if (parsed.success) {
142
- this.#transition_step('parsed', { input: parsed.data });
140
+ const parsed = parse_any(this.spec.input, this.#data.input);
141
+ if (parsed.ok) {
142
+ this.#transition_step('parsed', { input: parsed.value });
143
143
  }
144
144
  else {
145
145
  // Input validation errors fail immediately without transitioning to error phases.
@@ -148,7 +148,7 @@ export class ActionEvent {
148
148
  // Handler errors (network, server, business logic) DO transition to error phases.
149
149
  this.#fail(
150
150
  // no need to protect this info
151
- jsonrpc_error_messages.invalid_params(`failed to parse input: ${z.prettifyError(parsed.error)}`, to_local_invalid_params_data(this.spec.input, parsed.error.issues)));
151
+ jsonrpc_error_messages.invalid_params(`failed to parse input: ${format_issues(parsed.issues)}`, to_local_invalid_params_data(this.spec.input, parsed.issues, this.#data.input)));
152
152
  }
153
153
  return this;
154
154
  }
@@ -370,12 +370,12 @@ export class ActionEvent {
370
370
  }
371
371
  #complete_handling(output) {
372
372
  if (output !== undefined && should_validate_output(this.spec.kind, this.#data.phase)) {
373
- const parsed = this.spec.output.safeParse(output);
374
- if (parsed.success) {
375
- this.#transition_step('handled', { output: parsed.data });
373
+ const parsed = parse_any(this.spec.output, output);
374
+ if (parsed.ok) {
375
+ this.#transition_step('handled', { output: parsed.value });
376
376
  }
377
377
  else {
378
- this.#fail(jsonrpc_error_messages.validation_error(`failed to parse output: ${z.prettifyError(parsed.error)}`, { output, validation_errors: parsed.error.issues }));
378
+ this.#fail(jsonrpc_error_messages.validation_error(`failed to parse output: ${format_issues(parsed.issues)}`, { output, validation_errors: parsed.issues }));
379
379
  }
380
380
  }
381
381
  else {
@@ -157,13 +157,13 @@ export const peer_ping_handler = async (input, ctx) => {
157
157
  throw peer_request_error_to_jsonrpc(outcome.error);
158
158
  // the reply is remote-authored — a newer client may add fields
159
159
  const parsed = safe_parse_dropping_unknown_keys(PingResponse, outcome.value);
160
- if (!parsed.success) {
160
+ if (!parsed.ok) {
161
161
  throw new ThrownJsonrpcError(JSONRPC_ERROR_CODES.validation_error, 'peer/ping reply failed validation', { reason: REASON_PEER_PING_INVALID_REPLY });
162
162
  }
163
- if (parsed.data.nonce !== nonce) {
163
+ if (parsed.value.nonce !== nonce) {
164
164
  throw new ThrownJsonrpcError(JSONRPC_ERROR_CODES.validation_error, 'peer/ping reply nonce mismatch', { reason: REASON_PEER_PING_NONCE_MISMATCH });
165
165
  }
166
- return parsed.data;
166
+ return parsed.value;
167
167
  };
168
168
  /**
169
169
  * Reusable responder for an inbound *server→client* `peer/ping` request — the
@@ -31,11 +31,11 @@
31
31
  * `__proto__` key at any depth (`json_has_own_proto_key`) are refused
32
32
  * with `data.reason` `params_proto_key` (`ERROR_PARAMS_PROTO_KEY`), on
33
33
  * every input schema, before it runs; then
34
- * `spec.input.safeParse(raw_params)` with
34
+ * `spec.input` parses the params (`parse_any`, Zod or fuz_schema) with
35
35
  * `z.void()` / `?? {}` rules (`to_input_params`). A refusal is the generic
36
36
  * `invalid params`, with `data.reason` when the first issue's field
37
- * declares an `invalid_reason` (`to_invalid_params_error`) and the Zod
38
- * issues under DEV only. Runs **after** the authority gates: a
37
+ * declares an `invalid_reason` (`to_invalid_params_error`) and the
38
+ * library's issues under DEV only. Runs **after** the authority gates: a
39
39
  * 400 describing the action's input shape to a caller those gates
40
40
  * refuse would confirm the method exists and describe how to call it,
41
41
  * to a channel that should have learned nothing. Coarse authority
@@ -61,11 +61,11 @@
61
61
  * @module
62
62
  */
63
63
  import type { Logger } from '@fuzdev/fuz_util/log.ts';
64
- import type { z } from 'zod';
65
64
  import type { Uuid } from '../primitive_schemas.js';
66
65
  import { type RequestContext } from '../auth/request_context.js';
67
66
  import { type ResolvedAuth } from '../auth/resolved_auth.js';
68
67
  import type { Db } from '../db/db.js';
68
+ import { type AnyIssue, type ValidationSchema } from '../schema_issues.js';
69
69
  import { type JsonrpcRequestId, type JsonrpcErrorObject } from '../http/jsonrpc.js';
70
70
  import type { RateLimiter } from '../rate_limiter.js';
71
71
  import type { RpcAction } from './action_types.js';
@@ -77,7 +77,7 @@ import type { RequestClient } from './peer_request.js';
77
77
  export interface PerformActionInput {
78
78
  /** The resolved spec + handler (transport does method lookup). */
79
79
  action: RpcAction;
80
- /** Raw params from the wire envelope (post-`JsonrpcRequest.parse`, pre-`spec.input.safeParse`). */
80
+ /** Raw params from the wire envelope (post-`JsonrpcRequest.parse`, pre-`parse_any(spec.input, …)`). */
81
81
  raw_params: unknown;
82
82
  /** JSON-RPC request id — echoed onto the response. */
83
83
  request_id: JsonrpcRequestId;
@@ -170,14 +170,16 @@ export declare const perform_action: (input: PerformActionInput, deps: PerformAc
170
170
  * The `invalid_params` error an input validation failure answers: the generic
171
171
  * `invalid params` message, `data.reason` when the field the first issue lands
172
172
  * on declares an `invalid_reason` and no issue sits on the input itself
173
- * (`resolve_issues_invalid_reason`), and the Zod issues under DEV only
174
- * (`dev_only`). With no declared reason, production sends no `data` at all.
173
+ * (`resolve_issues_invalid_reason`), and the library's issues under DEV
174
+ * only (`dev_only`). With no declared reason, production sends no `data` at
175
+ * all.
175
176
  *
176
- * @param input - the action's input schema
177
- * @param issues - the failed parse's issues, in Zod's order
177
+ * @param input - the action's input schema, Zod or fuz_schema
178
+ * @param issues - the failed parse's issues, in the library's order
179
+ * @param params - the value that was parsed
178
180
  * @returns the JSON-RPC error object
179
181
  */
180
- export declare const to_invalid_params_error: (input: z.ZodType, issues: ReadonlyArray<z.core.$ZodIssue>) => JsonrpcErrorObject;
182
+ export declare const to_invalid_params_error: (input: ValidationSchema, issues: ReadonlyArray<AnyIssue>, params: unknown) => JsonrpcErrorObject;
181
183
  /**
182
184
  * The credential-type 403 — one builder, so the dispatcher's gate below and a
183
185
  * handler that gates a credential channel on its input (`account_delete`'s
@@ -1 +1 @@
1
- {"version":3,"file":"perform_action.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/actions/perform_action.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EAGN,KAAK,cAAc,EACnB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAGN,KAAK,YAAY,EACjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAMtC,OAAO,EACN,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EAGvB,MAAM,oBAAoB,CAAC;AAiB5B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtD,OAAO,KAAK,EAAgC,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACjF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGvD;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IAClC,kEAAkE;IAClE,MAAM,EAAE,SAAS,CAAC;IAClB,mGAAmG;IACnG,UAAU,EAAE,OAAO,CAAC;IACpB,sDAAsD;IACtD,UAAU,EAAE,gBAAgB,CAAC;IAC7B;;;;;;OAMG;IACH,IAAI,EAAE,YAAY,GAAG,IAAI,CAAC;IAC1B,qEAAqE;IACrE,SAAS,EAAE,MAAM,CAAC;IAClB,oGAAoG;IACpG,MAAM,EAAE,WAAW,CAAC;IACpB,sFAAsF;IACtF,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;I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iB,KACrB,OAAO,CAAC,mBAAmB,CAuL7B,CAAC;AA4BF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,uBAAuB,GACnC,OAAO,gBAAgB,EACvB,QAAQ,aAAa,CAAC,QAAQ,CAAC,EAC/B,QAAQ,OAAO,KACb,kBAOF,CAAC;AA6DF;;;;;;;;GAQG;AACH,eAAO,MAAM,8BAA8B,GAC1C,2BAA2B,aAAa,CAAC,MAAM,CAAC,KAC9C,kBAIA,CAAC;AAqEJ,0FAA0F;AAC1F,MAAM,WAAW,sBAAsB;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,uEAAuE;IACvE,MAAM,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,uBAAuB,GACnC,IAAI,gBAAgB,EACpB,QAAQ,mBAAmB,EAC3B,QAAQ,MAAM,EACd,KAAK,MAAM,KACT,sBAkBF,CAAC"}
@@ -31,11 +31,11 @@
31
31
  * `__proto__` key at any depth (`json_has_own_proto_key`) are refused
32
32
  * with `data.reason` `params_proto_key` (`ERROR_PARAMS_PROTO_KEY`), on
33
33
  * every input schema, before it runs; then
34
- * `spec.input.safeParse(raw_params)` with
34
+ * `spec.input` parses the params (`parse_any`, Zod or fuz_schema) with
35
35
  * `z.void()` / `?? {}` rules (`to_input_params`). A refusal is the generic
36
36
  * `invalid params`, with `data.reason` when the first issue's field
37
- * declares an `invalid_reason` (`to_invalid_params_error`) and the Zod
38
- * issues under DEV only. Runs **after** the authority gates: a
37
+ * declares an `invalid_reason` (`to_invalid_params_error`) and the
38
+ * library's issues under DEV only. Runs **after** the authority gates: a
39
39
  * 400 describing the action's input shape to a caller those gates
40
40
  * refuse would confirm the method exists and describe how to call it,
41
41
  * to a channel that should have learned nothing. Coarse authority
@@ -65,6 +65,7 @@ import { apply_authorization_phase, has_any_scoped_role } from '../auth/request_
65
65
  import { resolved_auth_scope, resolved_auth_session_hash } from '../auth/resolved_auth.js';
66
66
  import { is_db_checkout_error } from '../db/db_checkout_error.js';
67
67
  import { resolve_issues_invalid_reason } from '../schema_meta.js';
68
+ import { parse_any } from '../schema_issues.js';
68
69
  import { json_has_own_proto_key, to_input_params } from '../http/schema_helpers.js';
69
70
  import { rate_limit_ip_key } from '../http/ip_canonical.js';
70
71
  import { dispatch_with_post_commit_rollback } from '../http/pending_effects.js';
@@ -184,11 +185,11 @@ export const perform_action = async (input, deps) => {
184
185
  return error_result(jsonrpc_error_messages.invalid_params('invalid params', { reason: ERROR_PARAMS_PROTO_KEY }));
185
186
  }
186
187
  const params = to_input_params(spec.input, raw_params);
187
- const parse_result = spec.input.safeParse(params);
188
- if (!parse_result.success) {
189
- return error_result(to_invalid_params_error(spec.input, parse_result.error.issues));
188
+ const parse_result = parse_any(spec.input, params);
189
+ if (!parse_result.ok) {
190
+ return error_result(to_invalid_params_error(spec.input, parse_result.issues, params));
190
191
  }
191
- const validated_input = parse_result.data;
192
+ const validated_input = parse_result.value;
192
193
  // step 6: dispatch — transaction for mutations, pool for reads.
193
194
  const use_transaction = spec.side_effects;
194
195
  const execute = async (effective_db) => {
@@ -210,9 +211,9 @@ export const perform_action = async (input, deps) => {
210
211
  const output = await handler(validated_input, action_context);
211
212
  // DEV-only output validation — logs on mismatch, never throws.
212
213
  if (DEV) {
213
- const output_result = spec.output.safeParse(output);
214
- if (!output_result.success) {
215
- log.error(`action output schema mismatch: ${spec.method}`, output_result.error.issues);
214
+ const output_result = parse_any(spec.output, output);
215
+ if (!output_result.ok) {
216
+ log.error(`action output schema mismatch: ${spec.method}`, output_result.issues);
216
217
  }
217
218
  }
218
219
  return { kind: 'ok', result: output };
@@ -258,15 +259,17 @@ const thrown_error_result = (err, context, log) => {
258
259
  * The `invalid_params` error an input validation failure answers: the generic
259
260
  * `invalid params` message, `data.reason` when the field the first issue lands
260
261
  * on declares an `invalid_reason` and no issue sits on the input itself
261
- * (`resolve_issues_invalid_reason`), and the Zod issues under DEV only
262
- * (`dev_only`). With no declared reason, production sends no `data` at all.
262
+ * (`resolve_issues_invalid_reason`), and the library's issues under DEV
263
+ * only (`dev_only`). With no declared reason, production sends no `data` at
264
+ * all.
263
265
  *
264
- * @param input - the action's input schema
265
- * @param issues - the failed parse's issues, in Zod's order
266
+ * @param input - the action's input schema, Zod or fuz_schema
267
+ * @param issues - the failed parse's issues, in the library's order
268
+ * @param params - the value that was parsed
266
269
  * @returns the JSON-RPC error object
267
270
  */
268
- export const to_invalid_params_error = (input, issues) => {
269
- const reason = resolve_issues_invalid_reason(input, issues);
271
+ export const to_invalid_params_error = (input, issues, params) => {
272
+ const reason = resolve_issues_invalid_reason(input, issues, params);
270
273
  const issues_data = dev_only({ issues });
271
274
  return jsonrpc_error_messages.invalid_params('invalid params', reason === undefined ? issues_data : { reason, ...issues_data });
272
275
  };
@@ -114,7 +114,8 @@ export type CellCreateVerdict = {
114
114
  * It runs after the manage and root-only gates, so it decides validity, never
115
115
  * authority: throw `jsonrpc_errors.invalid_params` with
116
116
  * `ERROR_CELL_POLICY_INVALID` (or a reason of the consumer's), or a
117
- * `ZodError`, which the handler turns into `invalid_params`. **Omitted
117
+ * `ZodError` or fuz_schema `SchemaError`, which the handler turns into
118
+ * `invalid_params`. **Omitted
118
119
  * refuses every policy** (`ERROR_CELL_POLICY_UNSUPPORTED`, the Rust trait's
119
120
  * default): an authorizer that reads no policy stores none.
120
121
  */
@@ -132,9 +133,10 @@ export interface CellCreateAuthorize {
132
133
  * existing cell's on an update carrying `data` (`kind` is write-once), the
133
134
  * source's for every row a clone writes (on the merged data). It accepts or
134
135
  * throws, never rewrites: the handler stores the caller's `data` as sent, and
135
- * it must not mutate it. A thrown `ZodError` becomes the standard
136
- * `invalid_params` JSON-RPC error so per-kind validation failures surface to
137
- * clients with code -32602 (not -32603 / internal); throw a `JsonrpcError`
136
+ * it must not mutate it. A thrown `ZodError` or fuz_schema `SchemaError`
137
+ * (`parse_or_throw`) becomes the standard `invalid_params` JSON-RPC error so
138
+ * per-kind validation failures surface to clients with code -32602 (not
139
+ * -32603 / internal); throw a `JsonrpcError`
138
140
  * (`jsonrpc_errors.invalid_params` with a reason) to choose the reason. When
139
141
  * omitted, payloads pass through as-is.
140
142
  *
@@ -1 +1 @@
1
- {"version":3,"file":"cell_actions.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/auth/cell_actions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AAIH,OAAO,EAGN,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAEN,KAAK,mBAAmB,EAExB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAEnD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EA4BN,KAAK,UAAU,EAef,KAAK,QAAQ,EAEb,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAUN,KAAK,OAAO,EACZ,MAAM,uBAAuB,CAAC;AA0C/B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEtD;;;;;GAKG;AACH,MAAM,WAAW,wBAAwB;IACxC,uFAAuF;IACvF,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,6HAA6H;IAC7H,IAAI,EAAE,QAAQ,CAAC;IACf,wHAAwH;IACxH,SAAS,EAAE,IAAI,GAAG,IAAI,CAAC;IACvB,wPAAwP;IACxP,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,wJAAwJ;IACxJ,OAAO,EAAE,IAAI,GAAG,IAAI,CAAC;IACrB,+fAA+f;IAC/f,WAAW,EAAE,UAAU,GAAG,IAAI,CAAC;CAC/B;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAAE,KAAK,EAAE,KAAK,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,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C;AA+CF,eAAO,MAAM,YAAY,GAAI,KAAK,OAAO,KAAG,QAiB1C,CAAC;AAsDH,2CAA2C;AAC3C,eAAO,MAAM,mBAAmB,GAAI,MAAM,cAAc,KAAG,KAAK,CAAC,SAAS,CAitBzE,CAAC"}
@@ -51,9 +51,9 @@
51
51
  *
52
52
  * @module
53
53
  */
54
- import { z } from 'zod';
55
54
  import { rpc_action } from '../actions/action_types.js';
56
55
  import { jsonrpc_errors, dev_only } from '../http/jsonrpc_errors.js';
56
+ import { is_schema_validation_error } from '../schema_issues.js';
57
57
  import { is_pg_unique_violation } from '../db/pg_error.js';
58
58
  import { has_scoped_role } from './request_context.js';
59
59
  import { ROLE_ADMIN } from './role_schema.js';
@@ -170,10 +170,11 @@ export const create_cell_actions = (deps) => {
170
170
  const { validate_data, authorize_create } = deps;
171
171
  /**
172
172
  * Run the optional `validate_data` deps callback and convert any thrown
173
- * `ZodError` into the standard `invalid_params` JSON-RPC error so per-
174
- * kind validation failures surface to clients with code -32602 (not
175
- * -32603 / internal). The dispatcher only auto-converts ZodError for
176
- * wire-level input schemas; sub-API validation runs inside the handler.
173
+ * `ZodError` or `SchemaError` (`is_schema_validation_error`) into the
174
+ * standard `invalid_params` JSON-RPC error so per-kind validation
175
+ * failures surface to clients with code -32602 (not -32603 / internal).
176
+ * The dispatcher only converts validation failures of wire-level input
177
+ * schemas; sub-API validation runs inside the handler.
177
178
  */
178
179
  const validate_data_or_throw = (kind, data) => {
179
180
  if (validate_data === undefined)
@@ -182,7 +183,7 @@ export const create_cell_actions = (deps) => {
182
183
  validate_data(kind, data);
183
184
  }
184
185
  catch (err) {
185
- if (err instanceof z.ZodError) {
186
+ if (is_schema_validation_error(err)) {
186
187
  throw jsonrpc_errors.invalid_params('cell.data shape validation failed', dev_only({ issues: err.issues }));
187
188
  }
188
189
  throw err;
@@ -191,8 +192,8 @@ export const create_cell_actions = (deps) => {
191
192
  /**
192
193
  * Validate a non-null policy write through the mounted authorizer's
193
194
  * `validate_policy` — `ERROR_CELL_POLICY_UNSUPPORTED` when there is none
194
- * (no authorizer, or one without the member). A thrown `ZodError` becomes
195
- * `invalid_params`, as `validate_data_or_throw` does.
195
+ * (no authorizer, or one without the member). A thrown `ZodError` or
196
+ * `SchemaError` becomes `invalid_params`, as `validate_data_or_throw` does.
196
197
  */
197
198
  const validate_policy_write = (policy) => {
198
199
  if (authorize_create?.validate_policy === undefined)
@@ -201,7 +202,7 @@ export const create_cell_actions = (deps) => {
201
202
  authorize_create.validate_policy(policy);
202
203
  }
203
204
  catch (err) {
204
- if (err instanceof z.ZodError) {
205
+ if (is_schema_validation_error(err)) {
205
206
  throw jsonrpc_errors.invalid_params('cell.policy validation failed', dev_only({ issues: err.issues }));
206
207
  }
207
208
  throw err;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * `@fuzdev/fuz_schema` schemas for env var values, matching the Rust spine's
3
+ * readers of the same vars.
4
+ *
5
+ * An env value is a string, so these take a string and output the value it
6
+ * spells: `env_integer` for whole numbers, `EnvStringbool` for booleans.
7
+ *
8
+ * @module
9
+ */
10
+ import { string, type PipeSchema } from '@fuzdev/fuz_schema/schema.ts';
11
+ import '../sensitivity.js';
12
+ /** Options of `env_integer`. */
13
+ export interface EnvIntegerOptions {
14
+ /** The least value accepted, default `0`. */
15
+ min?: number;
16
+ /** The greatest value accepted, default `Number.MAX_SAFE_INTEGER`. */
17
+ max?: number;
18
+ }
19
+ /**
20
+ * A whole number spelled in decimal digits, read the way the Rust spine reads
21
+ * one (`value.trim().parse::<u64>()`): trimmed of Unicode `White_Space` (the
22
+ * set Rust's `trim` strips, not `String.prototype.trim`'s), then decimal
23
+ * digits after at most one leading `+`, so a blank value, a `-`, a fraction,
24
+ * an exponent (`5e3`), and hex (`0x1F90`) are refused, and `+80` and leading
25
+ * zeros (`00080`) are not. The number must be a safe integer within `min` and
26
+ * `max`.
27
+ *
28
+ * @param options - the bounds, default `0` to `Number.MAX_SAFE_INTEGER`
29
+ */
30
+ export declare const env_integer: (options?: EnvIntegerOptions) => PipeSchema<number, typeof string>;
31
+ /**
32
+ * A boolean spelled as a word, matched case-insensitively and not trimmed:
33
+ * `true`, `1`, `yes`, `on`, `y`, or `enabled` for `true`, and `false`, `0`,
34
+ * `no`, `off`, `n`, or `disabled` for `false`. Anything else is refused,
35
+ * `''` and `' true'` included, so a typo doesn't silently flip a feature.
36
+ *
37
+ * The set and the case rule of Zod's `z.stringbool()` defaults, and the twin
38
+ * of the Rust spine's `parse_stringbool`.
39
+ */
40
+ export declare const EnvStringbool: PipeSchema<boolean, typeof string>;
41
+ //# sourceMappingURL=env_schemas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env_schemas.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/env/env_schemas.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAON,MAAM,EAEN,KAAK,UAAU,EACf,MAAM,8BAA8B,CAAC;AAGtC,OAAO,mBAAmB,CAAC;AAE3B,gCAAgC;AAChC,MAAM,WAAW,iBAAiB;IACjC,6CAA6C;IAC7C,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,sEAAsE;IACtE,GAAG,CAAC,EAAE,MAAM,CAAC;CACb;AAeD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,WAAW,GAAI,UAAU,iBAAiB,KAAG,UAAU,CAAC,MAAM,EAAE,OAAO,MAAM,CAMxF,CAAC;AAmBH;;;;;;;;GAQG;AACH,eAAO,MAAM,aAAa,EAAE,UAAU,CAAC,OAAO,EAAE,OAAO,MAAM,CAO5D,CAAC"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * `@fuzdev/fuz_schema` schemas for env var values, matching the Rust spine's
3
+ * readers of the same vars.
4
+ *
5
+ * An env value is a string, so these take a string and output the value it
6
+ * spells: `env_integer` for whole numbers, `EnvStringbool` for booleans.
7
+ *
8
+ * @module
9
+ */
10
+ import { check, max_value, min_value, pipe, regex, safe_integer, string, transform } from '@fuzdev/fuz_schema/schema.ts';
11
+ // declares `sensitivity` on fuz_schema's `SchemaMeta`, for consumers marking env fields
12
+ import '../sensitivity.js';
13
+ // Unicode `White_Space`, the set Rust's `str::trim` strips (`char::is_whitespace`);
14
+ // `String.prototype.trim` differs, stripping U+FEFF and keeping U+0085
15
+ const WHITE_SPACE_EDGES = /^[\t\n\v\f\r \u0085\u00A0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000]+|[\t\n\v\f\r \u0085\u00A0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000]+$/g;
16
+ // the trimmed value as a number, when it is decimal digits after at most one `+`
17
+ const EnvDigits = pipe(string, transform((v) => v.replace(WHITE_SPACE_EDGES, '')), regex(/^\+?\d+$/, 'decimal digits'), transform(Number));
18
+ /**
19
+ * A whole number spelled in decimal digits, read the way the Rust spine reads
20
+ * one (`value.trim().parse::<u64>()`): trimmed of Unicode `White_Space` (the
21
+ * set Rust's `trim` strips, not `String.prototype.trim`'s), then decimal
22
+ * digits after at most one leading `+`, so a blank value, a `-`, a fraction,
23
+ * an exponent (`5e3`), and hex (`0x1F90`) are refused, and `+80` and leading
24
+ * zeros (`00080`) are not. The number must be a safe integer within `min` and
25
+ * `max`.
26
+ *
27
+ * @param options - the bounds, default `0` to `Number.MAX_SAFE_INTEGER`
28
+ */
29
+ export const env_integer = (options) => pipe(EnvDigits, safe_integer, min_value(options?.min ?? 0), max_value(options?.max ?? Number.MAX_SAFE_INTEGER));
30
+ // the recognized spellings, lowercase, as Zod's `z.stringbool()` defaults and
31
+ // the Rust spine's `parse_stringbool` have them
32
+ const STRINGBOOL_VALUES = new Map([
33
+ ['true', true],
34
+ ['1', true],
35
+ ['yes', true],
36
+ ['on', true],
37
+ ['y', true],
38
+ ['enabled', true],
39
+ ['false', false],
40
+ ['0', false],
41
+ ['no', false],
42
+ ['off', false],
43
+ ['n', false],
44
+ ['disabled', false]
45
+ ]);
46
+ /**
47
+ * A boolean spelled as a word, matched case-insensitively and not trimmed:
48
+ * `true`, `1`, `yes`, `on`, `y`, or `enabled` for `true`, and `false`, `0`,
49
+ * `no`, `off`, `n`, or `disabled` for `false`. Anything else is refused,
50
+ * `''` and `' true'` included, so a typo doesn't silently flip a feature.
51
+ *
52
+ * The set and the case rule of Zod's `z.stringbool()` defaults, and the twin
53
+ * of the Rust spine's `parse_stringbool`.
54
+ */
55
+ export const EnvStringbool = pipe(string, check((v) => STRINGBOOL_VALUES.has(v.toLowerCase()), 'true|1|yes|on|y|enabled or false|0|no|off|n|disabled'), transform((v) => STRINGBOOL_VALUES.get(v.toLowerCase())));
@@ -1,36 +1,37 @@
1
1
  /**
2
- * Generic environment loading from Zod schemas.
2
+ * Generic environment loading from `@fuzdev/fuz_schema` object schemas.
3
3
  *
4
- * Provides `load_env` which iterates Zod schema keys, gets env values, and validates.
5
- * Apps handle error messages themselves (they're always app-specific).
4
+ * Provides `load_env`, which reads each key of an object schema with a
5
+ * getter and validates the values. Apps handle error messages themselves
6
+ * (they're always app-specific).
6
7
  *
7
8
  * @module
8
9
  */
9
- import { z } from 'zod';
10
+ import { type Infer, type Schema, type SchemaIssue } from '@fuzdev/fuz_schema/schema.ts';
10
11
  /**
11
12
  * Error thrown when environment validation fails.
12
13
  *
13
14
  * Contains structured information for apps to format their own error messages.
14
15
  */
15
16
  export declare class EnvValidationError extends Error {
16
- /** The raw env values that were read. */
17
+ /** The raw env values that were read, every key of the schema, unset ones as `undefined`. */
17
18
  readonly raw: Record<string, string | undefined>;
18
- /** The Zod validation error. */
19
- readonly zod_error: z.core.$ZodError;
19
+ /** The validation issues, which hold no env value, only the keys in their paths. */
20
+ readonly issues: Array<SchemaIssue>;
20
21
  /** True if every env var was undefined (nothing loaded). */
21
22
  readonly all_undefined: boolean;
22
- constructor(raw: Record<string, string | undefined>, zod_error: z.core.$ZodError);
23
+ constructor(raw: Record<string, string | undefined>, issues: Array<SchemaIssue>);
23
24
  /**
24
- * Format Zod validation issues as human-readable strings.
25
+ * Format the validation issues as human-readable strings.
25
26
  *
26
- * @returns array of formatted issue strings like `"PORT: Expected number"`
27
+ * @returns array of formatted issue strings like `"PORT: expected decimal digits, received string"`
27
28
  */
28
29
  format_issues(): Array<string>;
29
30
  }
30
31
  /**
31
32
  * Log formatted env validation issues to stderr.
32
33
  *
33
- * Handles the common case: labels each Zod issue with an optional prefix.
34
+ * Handles the common case: labels each issue with an optional prefix.
34
35
  * Callers who want app-specific "getting started" instructions should check
35
36
  * `error.all_undefined` before calling this.
36
37
  *
@@ -39,12 +40,19 @@ export declare class EnvValidationError extends Error {
39
40
  */
40
41
  export declare const log_env_validation_error: (error: EnvValidationError, label?: string) => void;
41
42
  /**
42
- * Load and validate env vars against a Zod schema.
43
+ * Load and validate env vars against a `@fuzdev/fuz_schema` object schema.
43
44
  *
44
- * @param schema - Zod object schema defining expected env vars
45
+ * Reads every key of the schema's entries with `get_env`. An unset var is
46
+ * left out of the object parsed, not given as `undefined`, so it reads as a
47
+ * missing key: a `pipe` that starts with an `optional` runs none of its
48
+ * steps for it, as it would for an absent key of any object. `raw` still
49
+ * lists it, as `undefined`.
50
+ *
51
+ * @param schema - an object schema (`object`, `strip_object`, ..., under any wrappers) of the expected env vars
45
52
  * @param get_env - function to read an env var by key
46
53
  * @returns validated env object
47
- * @throws EnvValidationError if Zod validation fails
54
+ * @throws TypeError if `schema` is not an object schema
55
+ * @throws EnvValidationError if validation fails
48
56
  */
49
- export declare const load_env: <T extends z.ZodObject>(schema: T, get_env: (key: string) => string | undefined) => z.infer<T>;
57
+ export declare const load_env: <T extends Schema<Record<string, unknown>, any>>(schema: T, get_env: (key: string) => string | undefined) => Infer<T>;
50
58
  //# sourceMappingURL=load.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"load.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/env/load.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;GAIG;AACH,qBAAa,kBAAmB,SAAQ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