@fuzdev/fuz_app 0.155.1 → 0.157.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 +27 -14
- package/dist/actions/action_codegen.d.ts +10 -3
- package/dist/actions/action_codegen.d.ts.map +1 -1
- package/dist/actions/action_codegen.js +52 -13
- package/dist/actions/action_event.d.ts.map +1 -1
- package/dist/actions/action_event.js +13 -11
- package/dist/actions/action_rpc.d.ts +4 -3
- package/dist/actions/action_rpc.d.ts.map +1 -1
- package/dist/actions/action_rpc.js +4 -3
- package/dist/actions/action_spec.d.ts +102 -206
- package/dist/actions/action_spec.d.ts.map +1 -1
- package/dist/actions/action_spec.js +18 -96
- 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.map +1 -1
- package/dist/actions/broadcast_api.js +6 -5
- package/dist/actions/compile_action_registry.d.ts +11 -6
- package/dist/actions/compile_action_registry.d.ts.map +1 -1
- package/dist/actions/compile_action_registry.js +15 -9
- package/dist/actions/perform_action.d.ts +4 -4
- package/dist/actions/perform_action.d.ts.map +1 -1
- package/dist/actions/perform_action.js +11 -11
- package/dist/auth/CLAUDE.md +1 -1
- package/dist/auth/account_action_specs.d.ts +50 -23
- package/dist/auth/account_action_specs.d.ts.map +1 -1
- package/dist/auth/account_action_specs.js +18 -8
- package/dist/auth/account_route_schema.d.ts +10 -10
- package/dist/auth/account_schema.d.ts +21 -21
- package/dist/auth/actor_lookup_action_specs.d.ts +7 -7
- package/dist/auth/actor_search_action_specs.d.ts +6 -6
- package/dist/auth/admin_action_specs.d.ts +98 -98
- package/dist/auth/app_settings_schema.d.ts +2 -2
- package/dist/auth/audit_log_route_schema.d.ts +1 -1
- package/dist/auth/audit_log_schema.d.ts +44 -44
- package/dist/auth/auth_guard_resolver.d.ts +2 -2
- package/dist/auth/auth_guard_resolver.js +2 -2
- package/dist/auth/bootstrap_route_schema.d.ts +4 -4
- package/dist/auth/cell_action_specs.d.ts +241 -241
- package/dist/auth/cell_actions.js +3 -3
- package/dist/auth/cell_audit_action_specs.d.ts +14 -14
- package/dist/auth/cell_audit_metadata.d.ts +6 -6
- package/dist/auth/cell_field_action_specs.d.ts +38 -38
- package/dist/auth/cell_field_audit_metadata.d.ts +4 -4
- package/dist/auth/cell_grant_action_specs.d.ts +61 -61
- package/dist/auth/cell_grant_audit_metadata.d.ts +10 -10
- package/dist/auth/cell_item_action_specs.d.ts +50 -50
- package/dist/auth/cell_item_audit_metadata.d.ts +5 -5
- package/dist/auth/invite_schema.d.ts +6 -6
- package/dist/auth/role_grant_offer_action_specs.d.ts +120 -120
- package/dist/auth/role_grant_offer_notifications.d.ts +66 -66
- package/dist/auth/role_grant_offer_schema.d.ts +6 -6
- package/dist/auth/self_service_role_action_specs.d.ts +2 -2
- package/dist/auth/signup_route_schema.d.ts +2 -2
- package/dist/http/CLAUDE.md +26 -17
- package/dist/http/auth_shape.d.ts +51 -17
- package/dist/http/auth_shape.d.ts.map +1 -1
- package/dist/http/auth_shape.js +101 -52
- package/dist/http/error_schemas.d.ts +15 -8
- package/dist/http/error_schemas.d.ts.map +1 -1
- package/dist/http/error_schemas.js +4 -9
- package/dist/http/jsonrpc_errors.d.ts +11 -4
- package/dist/http/jsonrpc_errors.d.ts.map +1 -1
- package/dist/http/jsonrpc_errors.js +11 -4
- package/dist/http/jsonrpc_helpers.d.ts.map +1 -1
- package/dist/http/jsonrpc_helpers.js +2 -1
- package/dist/http/route_spec.d.ts +37 -19
- package/dist/http/route_spec.d.ts.map +1 -1
- package/dist/http/route_spec.js +54 -24
- package/dist/http/schema_helpers.d.ts +27 -24
- package/dist/http/schema_helpers.d.ts.map +1 -1
- package/dist/http/schema_helpers.js +24 -19
- package/dist/http/surface.d.ts.map +1 -1
- package/dist/http/surface.js +7 -3
- package/dist/primitive_schemas.d.ts +16 -5
- package/dist/primitive_schemas.d.ts.map +1 -1
- package/dist/primitive_schemas.js +26 -4
- package/dist/primitive_schemas_fuz.d.ts +67 -0
- package/dist/primitive_schemas_fuz.d.ts.map +1 -0
- package/dist/primitive_schemas_fuz.js +47 -0
- package/dist/realtime/sse.d.ts +3 -3
- package/dist/realtime/sse.d.ts.map +1 -1
- package/dist/realtime/sse.js +4 -4
- package/dist/schema_issues.d.ts +91 -4
- package/dist/schema_issues.d.ts.map +1 -1
- package/dist/schema_issues.js +262 -1
- package/dist/schema_meta.d.ts +24 -8
- package/dist/schema_meta.d.ts.map +1 -1
- package/dist/schema_meta.js +31 -10
- package/dist/server/serve_fact_route.d.ts.map +1 -1
- package/dist/server/serve_fact_route.js +2 -1
- package/dist/testing/CLAUDE.md +23 -17
- package/dist/testing/admin_integration.d.ts.map +1 -1
- package/dist/testing/admin_integration.js +3 -2
- package/dist/testing/adversarial_404.d.ts +2 -2
- package/dist/testing/adversarial_404.d.ts.map +1 -1
- package/dist/testing/adversarial_404.js +8 -5
- package/dist/testing/adversarial_input.js +1 -1
- package/dist/testing/adversarial_input_cases.d.ts +18 -23
- package/dist/testing/adversarial_input_cases.d.ts.map +1 -1
- package/dist/testing/adversarial_input_cases.js +51 -46
- package/dist/testing/assertions.d.ts +6 -5
- package/dist/testing/assertions.d.ts.map +1 -1
- package/dist/testing/assertions.js +9 -4
- package/dist/testing/cross_backend/action_manifest.d.ts +2 -1
- package/dist/testing/cross_backend/action_manifest.d.ts.map +1 -1
- package/dist/testing/cross_backend/action_manifest.js +3 -3
- package/dist/testing/cross_backend/cell_crud.d.ts.map +1 -1
- package/dist/testing/cross_backend/cell_crud.js +3 -8
- package/dist/testing/cross_backend/conformance_table.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_table.js +5 -4
- package/dist/testing/cross_backend/cross_rpc.d.ts +4 -2
- package/dist/testing/cross_backend/cross_rpc.d.ts.map +1 -1
- package/dist/testing/cross_backend/cross_rpc.js +6 -4
- package/dist/testing/cross_backend/rpc_success_fixtures.d.ts.map +1 -1
- package/dist/testing/cross_backend/sse_round_trip.d.ts.map +1 -1
- package/dist/testing/cross_backend/sse_round_trip.js +3 -2
- package/dist/testing/cross_backend/testing_reset_actions.d.ts +8 -8
- package/dist/testing/error_coverage.d.ts +9 -17
- package/dist/testing/error_coverage.d.ts.map +1 -1
- package/dist/testing/error_coverage.js +20 -3
- package/dist/testing/integration_helpers.d.ts.map +1 -1
- package/dist/testing/integration_helpers.js +7 -6
- package/dist/testing/rpc_envelope_cases.d.ts +3 -3
- package/dist/testing/rpc_envelope_cases.d.ts.map +1 -1
- package/dist/testing/rpc_envelope_cases.js +1 -1
- package/dist/testing/rpc_helpers.d.ts +12 -8
- package/dist/testing/rpc_helpers.d.ts.map +1 -1
- package/dist/testing/rpc_helpers.js +18 -15
- package/dist/testing/schema_generators.d.ts +75 -40
- package/dist/testing/schema_generators.d.ts.map +1 -1
- package/dist/testing/schema_generators.js +273 -99
- package/dist/testing/sse_round_trip.d.ts.map +1 -1
- package/dist/testing/sse_round_trip.js +4 -3
- package/dist/ui/admin_accounts_state.svelte.d.ts +10 -10
- 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 +6 -6
- package/dist/zod.d.ts +23 -5
- package/dist/zod.d.ts.map +1 -1
- package/dist/zod.js +2 -2
- package/package.json +6 -6
package/dist/actions/CLAUDE.md
CHANGED
|
@@ -23,10 +23,18 @@ the pair invariant.
|
|
|
23
23
|
|
|
24
24
|
## Action specs (`actions/action_spec.ts`)
|
|
25
25
|
|
|
26
|
-
Canonical source of truth.
|
|
26
|
+
Canonical source of truth. Specs are plain objects typed by TS interfaces
|
|
27
|
+
(`ActionSpec` and its three kinds, `ActionSpecUnion`), written with
|
|
28
|
+
`satisfies` so their literals survive; nothing parses a spec at runtime, so
|
|
29
|
+
every required field is spelled — no defaults. `input` / `output` are a
|
|
30
|
+
`ValidationSchema`, Zod or `@fuzdev/fuz_schema`. `ActionKind`,
|
|
31
|
+
`ActionInitiator` and `ActionEventPhase` stay Zod enums (`ActionEventData`
|
|
32
|
+
validates with them), built from the const lists `ACTION_KINDS`,
|
|
33
|
+
`ACTION_INITIATORS` and `ACTION_EVENT_PHASES`; `is_action_spec` reads
|
|
34
|
+
`ACTION_KINDS`. Three concrete kinds discriminate on `kind`:
|
|
27
35
|
|
|
28
36
|
- `request_response` — `auth: RouteAuth` (non-null), `side_effects` arbitrary, `output` arbitrary, `async: true`.
|
|
29
|
-
- `remote_notification` — `auth: null`, `side_effects: true`, `output
|
|
37
|
+
- `remote_notification` — `auth: null`, `side_effects: true`, `output` a void schema (`z.ZodVoid` or fuz_schema's `s.void`), `async: true`.
|
|
30
38
|
- `local_call` — `auth: null`, `side_effects` arbitrary, `output` arbitrary, `async` boolean.
|
|
31
39
|
|
|
32
40
|
`RouteAuth` is the flat record
|
|
@@ -36,7 +44,9 @@ surface drives routes and SAES. Cross-axis invariants: roles imply
|
|
|
36
44
|
`actor: 'required'`; `account: 'none'` implies `actor: 'none'` (no
|
|
37
45
|
accountless actors in v1); the unrestricted leaf
|
|
38
46
|
(`account: 'none', actor: 'none'`) cannot declare roles or credential
|
|
39
|
-
gates
|
|
47
|
+
gates — checked at registration time via `assert_route_auth_invariants`, on
|
|
48
|
+
action and route specs alike (a spec is a plain object nothing parses). The
|
|
49
|
+
biconditional `actor !== 'none' ⟺ input declares acting?: ActingActor`
|
|
40
50
|
is enforced at registration time via `assert_route_auth_acting_biconditional`.
|
|
41
51
|
`required_scope` is the one axis actions cannot use — see §Registry compile.
|
|
42
52
|
|
|
@@ -78,10 +88,11 @@ non-`remote_notification` kind.
|
|
|
78
88
|
`create_rpc_endpoint` and `register_action_ws`. Validates these checks in
|
|
79
89
|
order and returns the `Map<method, RpcAction>` the dispatchers use:
|
|
80
90
|
|
|
91
|
+
- **Auth-shape cross-axis invariants** — roles imply a required actor, no accountless actor, nothing to gate on unrestricted auth (via `assert_route_auth_invariants`).
|
|
81
92
|
- **Auth-shape biconditional** — `actor !== 'none' ⟺ input declares acting?: ActingActor` (via `assert_route_auth_acting_biconditional`).
|
|
82
93
|
- **No `auth.required_scope`** — the slot is route-spec-only; nothing mounts a guard from it on an action, so declaring it would be a control that silently does nothing. Narrowed tokens are gated per method by the scope check in `perform_action`, which derives the `rpc:<method>` capability from `spec.method` rather than trusting a hand-written one.
|
|
83
94
|
- **Rate-limit account axis** — `rate_limit: 'account' | 'both'` requires `auth.account === 'required'`.
|
|
84
|
-
- **JSON-RPC §4.2 wire validity** — `request_response` specs with a handler may not use `z.null()` for input (use `z.void()` for nullary), nor
|
|
95
|
+
- **JSON-RPC §4.2 wire validity** — `request_response` specs with a handler may not use a null schema (`z.null()`, fuz_schema `literal(null)`) for input (use a void schema, `z.void()` or fuz_schema `s.void`, for nullary), nor a void schema for output (a response always carries a `result`, which clients validate against `spec.output`; use a null schema when there's nothing to return). Both are detected by shape (`is_null_schema` / `is_void_schema`), so a `meta` copy counts.
|
|
85
96
|
- **Unique method names** across the array.
|
|
86
97
|
|
|
87
98
|
Only `request_response` specs with a handler reach the dispatch map;
|
|
@@ -126,11 +137,11 @@ and options on each function's TSDoc.
|
|
|
126
137
|
- `get_executor_phases(spec, executor)` — phases an executor participates in for the spec.
|
|
127
138
|
- `get_handler_return_type` — TS type a phase handler must return; side-effect imports `ActionOutputs`.
|
|
128
139
|
- `generate_phase_handlers` — per-action typed handler-map fragment.
|
|
129
|
-
- `generate_frontend_actions_api` — typed `FrontendActionsApi` interface.
|
|
140
|
+
- `generate_frontend_actions_api` — typed `FrontendActionsApi` interface. A void or null input of either library (`is_void_schema`, `is_null_schema`) emits `input?: void`; otherwise each method's `input?:` follows `action_input_is_optional` (parsed with `parse_any`) — the schema accepts `undefined`, or accepts `{}` and is not marked `.meta({empty_input_handler_guarded: true})` (`SchemaFieldMeta`, read by `is_empty_input_handler_guarded` in `schema_meta.ts` — set on `cell_get`, `cell_field_list` and `cell_item_list`, whose `{}` reaches a handler guard that refuses it with a declared reason, so their input stays required; a consumer marks its own the same way); an input-shape invariant test reads the same rule.
|
|
130
141
|
- `generate_action_method_enums` — up to nine `z.enum` + `z.infer` pairs.
|
|
131
142
|
- `generate_typed_action_event_alias` — fixed-shape `TypedActionEvent<TMethod, TPhase, TStep>` alias.
|
|
132
143
|
- `generate_action_specs_record` — `ActionSpecs` runtime const + interface + `action_specs` array.
|
|
133
|
-
- `generate_action_inputs_outputs` — `ActionInputs` + `ActionOutputs` runtime consts + interfaces.
|
|
144
|
+
- `generate_action_inputs_outputs` — `ActionInputs` + `ActionOutputs` runtime consts + interfaces, each schema typed as its output: `z.infer<typeof …>` for a Zod schema, fuz_schema's `Infer<typeof …>` for a `@fuzdev/fuz_schema` one, importing `z` and `Infer` only when a schema of that library is present; a schema of neither throws naming the method.
|
|
134
145
|
- `generate_action_event_datas` — `ActionEventDatas` interface; per-spec variants.
|
|
135
146
|
- `generate_frontend_action_handlers` — `FrontendActionHandlers` interface (Tier 2 only).
|
|
136
147
|
- `generate_backend_actions_api` — `BackendActionsApi` interface + `broadcast_action_specs` array.
|
|
@@ -248,8 +259,9 @@ interface RpcAction {
|
|
|
248
259
|
### `rpc_action(spec, handler)` — typed binder
|
|
249
260
|
|
|
250
261
|
`rpc_action<TSpec extends RequestResponseActionSpec>(spec, handler)` pins
|
|
251
|
-
the handler's input / output types to `
|
|
252
|
-
`
|
|
262
|
+
the handler's input / output types to `ValidationOutput<TSpec['input']>` /
|
|
263
|
+
`ValidationOutput<TSpec['output']>` (`schema_issues.ts`: fuz_schema's `Infer`
|
|
264
|
+
or Zod's `z.output`, per spec) and tightens `ctx.auth` per the conditional
|
|
253
265
|
`HandlerForSpec<TSpec>`:
|
|
254
266
|
|
|
255
267
|
- `auth.actor === 'required'` → `ctx.auth: RequestActorContext`.
|
|
@@ -281,7 +293,7 @@ Pipeline (401 → authz → 403 → 429 → 400 → handler):
|
|
|
281
293
|
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
294
|
3. Post-authorization auth (403) — credential-type gate, then token scope, then role
|
|
283
295
|
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` parses them (`parse_any`, `schema_issues.ts` — a Zod or fuz_schema schema) with
|
|
296
|
+
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 void / `?? {}` rules; a void input (`is_void_schema`: `z.void()` or fuz_schema `s.void`) 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 issues DEV-only, as `WireIssue`s (`to_wire_issues`)
|
|
285
297
|
6. Dispatch + DEV output validation + error normalization — `spec.side_effects` picks transaction vs pool. `ThrownJsonrpcError` preserves code + data; generic throws become `internal_error`
|
|
286
298
|
|
|
287
299
|
`PerformActionInput` carries `auth` (the request's `ResolvedAuth`, `null` for
|
|
@@ -1086,9 +1098,10 @@ methods) go to `environment.log`; unset falls back to `console_action_log`
|
|
|
1086
1098
|
(warn/error to `console`, debug dropped) so failures are never silent, and
|
|
1087
1099
|
`log: null` opts out (`resolve_action_log`). An inbound request or notification
|
|
1088
1100
|
reads its params through the server dispatch core's normalizer
|
|
1089
|
-
(`to_input_params`): for a `z.void()`
|
|
1090
|
-
the no-arg call; for any other input,
|
|
1091
|
-
all-optional object input accepts a
|
|
1101
|
+
(`to_input_params`): for a void input (`z.void()` or fuz_schema `s.void`),
|
|
1102
|
+
absent, `null`, and `{}` alike are the no-arg call; for any other input,
|
|
1103
|
+
absent or `null` params are `{}` (so an all-optional object input accepts a
|
|
1104
|
+
call that omits them).
|
|
1092
1105
|
|
|
1093
1106
|
**Naming.** `ActionDispatcher` is the (frontend) send/receive coordinator class.
|
|
1094
1107
|
"ActionPeer" — unbackticked throughout the peer/ping + `request_client` docs — is
|
|
@@ -1238,8 +1251,8 @@ specs. Counterpart to `register_action_ws`: that handles frontend-initiated
|
|
|
1238
1251
|
request-scoped dispatch, this handles backend-initiated broadcast.
|
|
1239
1252
|
Request-scoped streaming stays on `ctx.notify` inside a handler.
|
|
1240
1253
|
|
|
1241
|
-
Per-method call: validates input against `spec.input
|
|
1242
|
-
failure), wraps in `JsonrpcNotification`, and sends it on `registry` — a
|
|
1254
|
+
Per-method call: validates input against `spec.input`, Zod or fuz_schema
|
|
1255
|
+
(`parse_any`; logs + returns on failure), wraps in `JsonrpcNotification`, and sends it on `registry` — a
|
|
1243
1256
|
`BroadcastTarget`, `Pick<ConnectionRegistry, 'broadcast' |
|
|
1244
1257
|
'broadcast_filtered'>`, typically `app_server.ws_endpoints[path]` or the
|
|
1245
1258
|
registry a `WsEndpointSpec` supplies. No `Transports` collection and no fallback:
|
|
@@ -122,10 +122,12 @@ export declare const generate_phase_handlers: (spec: ActionSpecUnion, executor:
|
|
|
122
122
|
* or accepts `{}` (what an omitted input is validated as) and is not marked
|
|
123
123
|
* `empty_input_handler_guarded` (`SchemaFieldMeta`, read by
|
|
124
124
|
* `is_empty_input_handler_guarded`). The rule codegen emits `input?:` by and
|
|
125
|
-
* the input-shape invariant tests read.
|
|
125
|
+
* the input-shape invariant tests read. The input is a Zod or a
|
|
126
|
+
* `@fuzdev/fuz_schema` schema, parsed with `parse_any`.
|
|
126
127
|
*
|
|
127
128
|
* @param spec - the action spec
|
|
128
129
|
* @returns whether the typed surface makes the input optional
|
|
130
|
+
* @throws Error when the input is neither a Zod nor a fuz_schema schema
|
|
129
131
|
*/
|
|
130
132
|
export declare const action_input_is_optional: (spec: Pick<ActionSpecUnion, "input">) => boolean;
|
|
131
133
|
/** Discriminator for `generate_action_method_enums` — which method-set enums to emit. */
|
|
@@ -190,15 +192,20 @@ export declare const generate_action_specs_record: (specs: ReadonlyArray<ActionS
|
|
|
190
192
|
/**
|
|
191
193
|
* Emit `ActionInputs` + `ActionOutputs` runtime consts and matching interfaces.
|
|
192
194
|
* The runtime consts reference `specs.{method}_action_spec.input` /
|
|
193
|
-
* `.output`; the interfaces
|
|
195
|
+
* `.output`; the interfaces type each as its schema's output: `z.infer` for a
|
|
196
|
+
* Zod schema, `Infer` for a `@fuzdev/fuz_schema` one.
|
|
194
197
|
*
|
|
195
|
-
* Adds `import {z} from 'zod';`
|
|
198
|
+
* Adds `import {z} from 'zod';` when any schema is Zod's,
|
|
199
|
+
* `import type {Infer} from '@fuzdev/fuz_schema/schema.ts';` when any is
|
|
200
|
+
* fuz_schema's, and the `* as specs` namespace import.
|
|
196
201
|
*
|
|
197
202
|
* @param options.qualify_spec - per-spec qualified identifier callback for
|
|
198
203
|
* multi-source consumers. The helper appends `.input` / `.output` to the
|
|
199
204
|
* callback's return value. When set, the helper skips the default
|
|
200
205
|
* `* as specs` import — the consumer manages its own namespace imports —
|
|
201
206
|
* and `specs_module` is ignored. Single-source consumers omit it.
|
|
207
|
+
* @throws Error naming the method when an input or output is neither a Zod
|
|
208
|
+
* nor a fuz_schema schema
|
|
202
209
|
*/
|
|
203
210
|
export declare const generate_action_inputs_outputs: (specs: ReadonlyArray<ActionSpecUnion>, imports: ImportBuilder, options?: {
|
|
204
211
|
specs_module?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action_codegen.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/actions/action_codegen.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"action_codegen.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/actions/action_codegen.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAG1E;;;;;;;GAOG;AACH,eAAO,MAAM,uBAAuB,+CAAgD,CAAC;AAErF,8FAA8F;AAC9F,MAAM,MAAM,oBAAoB,GAAG,CAAC,OAAO,uBAAuB,CAAC,CAAC,MAAM,CAAC,CAAC;AAI5E;;;;;;;;;;GAUG;AACH,eAAO,MAAM,yBAAyB,GAAI,QAAQ,MAAM,KAAG,MAAM,IAAI,oBACrC,CAAC;AAEjC,UAAU,UAAU;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,WAAW,CAAC;CACrC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,aAAa;;IACzB,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAa;IAE1D;;;;;OAKG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAQrC;;;;;;OAMG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAI1C,QAAQ,CAAC,IAAI,E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e,CAAC,CAAC;CAiC1C,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,gBAAgB,GAAI,OAAO;IACvC,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,aAAa,CAAC;IACvB,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CAC9B,KAAG,MAYH,CAAC"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { UnreachableError } from '@fuzdev/fuz_util/error.ts';
|
|
2
|
-
import {
|
|
2
|
+
import { is_schema } from '@fuzdev/fuz_schema/schema.ts';
|
|
3
3
|
import { is_empty_input_handler_guarded } from '../schema_meta.js';
|
|
4
|
+
import { is_null_schema, is_void_schema } from '../http/schema_helpers.js';
|
|
5
|
+
import { assert_zod_schema, parse_any } from '../schema_issues.js';
|
|
4
6
|
import { ActionRegistry } from './action_registry.js';
|
|
5
7
|
/**
|
|
6
8
|
* Method names of fuz_app's protocol actions — `heartbeat` (auth-aware client
|
|
@@ -323,17 +325,33 @@ const to_action_property_key = (method) => /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(met
|
|
|
323
325
|
* or accepts `{}` (what an omitted input is validated as) and is not marked
|
|
324
326
|
* `empty_input_handler_guarded` (`SchemaFieldMeta`, read by
|
|
325
327
|
* `is_empty_input_handler_guarded`). The rule codegen emits `input?:` by and
|
|
326
|
-
* the input-shape invariant tests read.
|
|
328
|
+
* the input-shape invariant tests read. The input is a Zod or a
|
|
329
|
+
* `@fuzdev/fuz_schema` schema, parsed with `parse_any`.
|
|
327
330
|
*
|
|
328
331
|
* @param spec - the action spec
|
|
329
332
|
* @returns whether the typed surface makes the input optional
|
|
333
|
+
* @throws Error when the input is neither a Zod nor a fuz_schema schema
|
|
330
334
|
*/
|
|
331
335
|
export const action_input_is_optional = (spec) => {
|
|
332
|
-
if (spec.input
|
|
336
|
+
if (parse_any(spec.input, undefined).ok)
|
|
333
337
|
return true;
|
|
334
338
|
if (is_empty_input_handler_guarded(spec.input))
|
|
335
339
|
return false;
|
|
336
|
-
return spec.input
|
|
340
|
+
return parse_any(spec.input, {}).ok;
|
|
341
|
+
};
|
|
342
|
+
/**
|
|
343
|
+
* Which library a spec's input or output schema is of — the type it is
|
|
344
|
+
* emitted as follows from it: `z.infer` for Zod, fuz_schema's `Infer` for
|
|
345
|
+
* `@fuzdev/fuz_schema`, each the schema's output type.
|
|
346
|
+
*
|
|
347
|
+
* @throws Error naming the method and the schema when it is of neither library
|
|
348
|
+
*/
|
|
349
|
+
const to_spec_schema_library = (spec, which) => {
|
|
350
|
+
const schema = spec[which];
|
|
351
|
+
if (is_schema(schema))
|
|
352
|
+
return 'fuz_schema';
|
|
353
|
+
assert_zod_schema(schema, `action '${spec.method}' ${which}`);
|
|
354
|
+
return 'zod';
|
|
337
355
|
};
|
|
338
356
|
/**
|
|
339
357
|
* Generates one method line of the typed `FrontendActionsApi` interface for a
|
|
@@ -365,18 +383,23 @@ export const action_input_is_optional = (spec) => {
|
|
|
365
383
|
* may omit the argument) when either (a) the schema accepts `undefined` —
|
|
366
384
|
* `z.optional(z.strictObject(...))` and similar wrappers — or (b) the
|
|
367
385
|
* schema accepts the empty object `{}` — `z.strictObject({acting:
|
|
368
|
-
ActingActor})` and other all-optional-fields strict objects. The second
|
|
386
|
+
* ActingActor})` and other all-optional-fields strict objects. The second
|
|
369
387
|
* probe mirrors the dispatcher's HTTP convention (`raw_params ?? {}` for
|
|
370
388
|
* non-`z.void()` schemas in `actions/action_rpc.ts` / `http/route_spec.ts`):
|
|
371
389
|
* if a request with no params reaches the handler, this is the value the
|
|
372
390
|
* schema is asked to validate. A schema with required fields fails both
|
|
373
391
|
* probes and stays `input:` (required at the typed surface). Refinements
|
|
374
|
-
* and transforms run as part of `
|
|
392
|
+
* and transforms run as part of the parse (`parse_any`), so their accept/reject
|
|
375
393
|
* decisions feed into the optional/required choice naturally. An input
|
|
376
394
|
* marked `empty_input_handler_guarded` is the exception: its schema accepts
|
|
377
395
|
* `{}` but the handler refuses it, so it stays `input:`
|
|
378
396
|
* (`action_input_is_optional` is the one rule).
|
|
379
397
|
*
|
|
398
|
+
* **No-input detection.** A void or null input — `z.void()`, `z.null()`, or
|
|
399
|
+
* a `@fuzdev/fuz_schema` `literal(undefined)` (`s.void`) or `literal(null)`,
|
|
400
|
+
* read by shape (`is_void_schema`, `is_null_schema`) — emits `input?: void`
|
|
401
|
+
* and no `ActionInputs` import.
|
|
402
|
+
*
|
|
380
403
|
* @param options.sync_returns_value - When true (default), sync `local_call`
|
|
381
404
|
* methods return the output value directly; when false they're wrapped in
|
|
382
405
|
* `Result<{value, error}>` like async methods. Set to `false` if your
|
|
@@ -384,12 +407,14 @@ ActingActor})` and other all-optional-fields strict objects. The second
|
|
|
384
407
|
* @param options.collections_path - Import path that `ActionInputs` /
|
|
385
408
|
* `ActionOutputs` resolve to. Defaults to `'./action_collections.ts'`.
|
|
386
409
|
* @returns one line like `foo: (input: ActionInputs['foo'], options?: RpcClientCallOptions) => Promise<Result<...>>;`
|
|
410
|
+
* @throws Error naming the method when the input is neither a Zod nor a
|
|
411
|
+
* fuz_schema schema
|
|
387
412
|
*/
|
|
388
413
|
const generate_actions_api_method_signature = (spec, imports, options) => {
|
|
389
414
|
const sync_returns_value = options?.sync_returns_value ?? true;
|
|
390
415
|
const collections_path = options?.collections_path ?? DEFAULT_COLLECTIONS_PATH;
|
|
391
|
-
|
|
392
|
-
const has_input =
|
|
416
|
+
to_spec_schema_library(spec, 'input');
|
|
417
|
+
const has_input = !is_null_schema(spec.input) && !is_void_schema(spec.input);
|
|
393
418
|
const input_optional = has_input && action_input_is_optional(spec);
|
|
394
419
|
const input_param = has_input
|
|
395
420
|
? `input${input_optional ? '?' : ''}: ActionInputs['${spec.method}']`
|
|
@@ -619,15 +644,20 @@ export const action_specs: Array<ActionSpecUnion> = Object.values(ActionSpecs);`
|
|
|
619
644
|
/**
|
|
620
645
|
* Emit `ActionInputs` + `ActionOutputs` runtime consts and matching interfaces.
|
|
621
646
|
* The runtime consts reference `specs.{method}_action_spec.input` /
|
|
622
|
-
* `.output`; the interfaces
|
|
647
|
+
* `.output`; the interfaces type each as its schema's output: `z.infer` for a
|
|
648
|
+
* Zod schema, `Infer` for a `@fuzdev/fuz_schema` one.
|
|
623
649
|
*
|
|
624
|
-
* Adds `import {z} from 'zod';`
|
|
650
|
+
* Adds `import {z} from 'zod';` when any schema is Zod's,
|
|
651
|
+
* `import type {Infer} from '@fuzdev/fuz_schema/schema.ts';` when any is
|
|
652
|
+
* fuz_schema's, and the `* as specs` namespace import.
|
|
625
653
|
*
|
|
626
654
|
* @param options.qualify_spec - per-spec qualified identifier callback for
|
|
627
655
|
* multi-source consumers. The helper appends `.input` / `.output` to the
|
|
628
656
|
* callback's return value. When set, the helper skips the default
|
|
629
657
|
* `* as specs` import — the consumer manages its own namespace imports —
|
|
630
658
|
* and `specs_module` is ignored. Single-source consumers omit it.
|
|
659
|
+
* @throws Error naming the method when an input or output is neither a Zod
|
|
660
|
+
* nor a fuz_schema schema
|
|
631
661
|
*/
|
|
632
662
|
export const generate_action_inputs_outputs = (specs, imports, options) => {
|
|
633
663
|
const filtered = filter_protocol_actions(specs, options?.include_protocol_actions);
|
|
@@ -650,19 +680,28 @@ export interface ActionInputs {}
|
|
|
650
680
|
export const ActionOutputs = {} as const;
|
|
651
681
|
export interface ActionOutputs {}`;
|
|
652
682
|
}
|
|
653
|
-
|
|
683
|
+
const libraries = filtered.map((s) => ({
|
|
684
|
+
input: to_spec_schema_library(s, 'input'),
|
|
685
|
+
output: to_spec_schema_library(s, 'output')
|
|
686
|
+
}));
|
|
687
|
+
const uses = (library) => libraries.some((l) => l.input === library || l.output === library);
|
|
688
|
+
if (uses('zod'))
|
|
689
|
+
imports.add('zod', 'z');
|
|
690
|
+
if (uses('fuz_schema'))
|
|
691
|
+
imports.add_type('@fuzdev/fuz_schema/schema.ts', 'Infer');
|
|
654
692
|
const qualify = resolve_spec_qualifier(imports, options);
|
|
693
|
+
const infer = (library) => library === 'zod' ? 'z.infer' : 'Infer';
|
|
655
694
|
const inputs_value = filtered
|
|
656
695
|
.map((s) => `\t${to_action_property_key(s.method)}: ${qualify(s)}.input,`)
|
|
657
696
|
.join('\n');
|
|
658
697
|
const inputs_type = filtered
|
|
659
|
-
.map((s) => `\t${to_action_property_key(s.method)}:
|
|
698
|
+
.map((s, i) => `\t${to_action_property_key(s.method)}: ${infer(libraries[i].input)}<typeof ${qualify(s)}.input>;`)
|
|
660
699
|
.join('\n');
|
|
661
700
|
const outputs_value = filtered
|
|
662
701
|
.map((s) => `\t${to_action_property_key(s.method)}: ${qualify(s)}.output,`)
|
|
663
702
|
.join('\n');
|
|
664
703
|
const outputs_type = filtered
|
|
665
|
-
.map((s) => `\t${to_action_property_key(s.method)}:
|
|
704
|
+
.map((s, i) => `\t${to_action_property_key(s.method)}: ${infer(libraries[i].output)}<typeof ${qualify(s)}.output>;`)
|
|
666
705
|
.join('\n');
|
|
667
706
|
return `/**
|
|
668
707
|
* Action parameter schemas indexed by method name.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action_event.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/actions/action_event.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,KAAK,EAAE,gBAAgB,EAAc,eAAe,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"action_event.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/actions/action_event.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,KAAK,EAAE,gBAAgB,EAAc,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAyBtF,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,MA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;;;;;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;CAkMzD;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"}
|
|
@@ -12,7 +12,7 @@ import { create_jsonrpc_request, create_jsonrpc_response, create_jsonrpc_error_r
|
|
|
12
12
|
import { dev_only, jsonrpc_error_messages, to_thrown_jsonrpc_error, UNKNOWN_ERROR_MESSAGE } from '../http/jsonrpc_errors.js';
|
|
13
13
|
import { safe_parse_dropping_unknown_keys } from '../http/schema_helpers.js';
|
|
14
14
|
import { resolve_issues_invalid_reason } from '../schema_meta.js';
|
|
15
|
-
import { format_issues, parse_any } from '../schema_issues.js';
|
|
15
|
+
import { format_issues, parse_any, to_wire_issues } 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
|
|
@@ -21,16 +21,15 @@ import { validate_step_transition, validate_phase_transition, should_validate_ou
|
|
|
21
21
|
*/
|
|
22
22
|
export const ERROR_RESPONSE_OUTPUT_INVALID = 'response_output_invalid';
|
|
23
23
|
/**
|
|
24
|
-
* `error.data` for a local input parse failure: the issues
|
|
25
|
-
* `invalid_reason` of the first issue's field — the reason
|
|
26
|
-
* answer the same input with, so a caller matching
|
|
27
|
-
* value whichever side refused.
|
|
24
|
+
* `error.data` for a local input parse failure: the issues as `WireIssue`s,
|
|
25
|
+
* and the declared `invalid_reason` of the first issue's field — the reason
|
|
26
|
+
* the server would answer the same input with, so a caller matching
|
|
27
|
+
* `data.reason` reads one value whichever side refused.
|
|
28
28
|
*/
|
|
29
29
|
const to_local_invalid_params_data = (input, issues, value) => {
|
|
30
30
|
const reason = resolve_issues_invalid_reason(input, issues, value);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
: { validation_errors: issues, reason };
|
|
31
|
+
const validation_errors = to_wire_issues(issues, value);
|
|
32
|
+
return reason === undefined ? { validation_errors } : { validation_errors, reason };
|
|
34
33
|
};
|
|
35
34
|
/**
|
|
36
35
|
* Action event that manages the lifecycle of an action through its state machine.
|
|
@@ -127,7 +126,10 @@ export class ActionEvent {
|
|
|
127
126
|
this.#transition_step('parsed', { output: parsed.value });
|
|
128
127
|
}
|
|
129
128
|
else {
|
|
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)}`, {
|
|
129
|
+
this.#transition_to_error_phase('receive_error', jsonrpc_error_messages.internal_error(`response failed output validation for ${this.spec.method}: ${format_issues(parsed.issues)}`, {
|
|
130
|
+
reason: ERROR_RESPONSE_OUTPUT_INVALID,
|
|
131
|
+
validation_errors: to_wire_issues(parsed.issues, this.#data.output)
|
|
132
|
+
}));
|
|
131
133
|
}
|
|
132
134
|
return this;
|
|
133
135
|
}
|
|
@@ -314,7 +316,7 @@ export class ActionEvent {
|
|
|
314
316
|
const message = to_error_message(error) || UNKNOWN_ERROR_MESSAGE;
|
|
315
317
|
const answers_remote = this.#data.kind === 'request_response' &&
|
|
316
318
|
(this.#data.phase === 'receive_request' || this.#data.phase === 'send_response');
|
|
317
|
-
return jsonrpc_error_messages.internal_error(answers_remote ? dev_only(message) : message);
|
|
319
|
+
return jsonrpc_error_messages.internal_error(answers_remote ? dev_only(() => message) : message);
|
|
318
320
|
}
|
|
319
321
|
/**
|
|
320
322
|
* Determine which error phase to transition to based on current phase.
|
|
@@ -375,7 +377,7 @@ export class ActionEvent {
|
|
|
375
377
|
this.#transition_step('handled', { output: parsed.value });
|
|
376
378
|
}
|
|
377
379
|
else {
|
|
378
|
-
this.#fail(jsonrpc_error_messages.validation_error(`failed to parse output: ${format_issues(parsed.issues)}`, { output, validation_errors: parsed.issues }));
|
|
380
|
+
this.#fail(jsonrpc_error_messages.validation_error(`failed to parse output: ${format_issues(parsed.issues)}`, { output, validation_errors: to_wire_issues(parsed.issues, output) }));
|
|
379
381
|
}
|
|
380
382
|
}
|
|
381
383
|
else {
|
|
@@ -90,9 +90,10 @@ export interface CreateRpcEndpointOptions {
|
|
|
90
90
|
* @param options - endpoint path, actions, logger, and the two action rate limiters
|
|
91
91
|
* @returns route specs (GET + POST) ready for `apply_route_specs`
|
|
92
92
|
* @throws Error if two actions share the same `spec.method` (registration-time
|
|
93
|
-
* duplicate detection); also throws if any action's `spec.input` is
|
|
94
|
-
* `z.null()` (JSON-RPC 2.0 §4.2 forbids
|
|
95
|
-
* `
|
|
93
|
+
* duplicate detection); also throws if any action's `spec.input` is a null
|
|
94
|
+
* schema (`z.null()` or fuz_schema `literal(null)`; JSON-RPC 2.0 §4.2 forbids
|
|
95
|
+
* `params: null` on the wire — use a void schema for parameterless methods)
|
|
96
|
+
* or its `spec.output` is a void schema.
|
|
96
97
|
*/
|
|
97
98
|
export declare const create_rpc_endpoint: (options: CreateRpcEndpointOptions) => Array<RouteSpec>;
|
|
98
99
|
//# sourceMappingURL=action_rpc.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action_rpc.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/actions/action_rpc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAMH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAGtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAqB,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAgB1E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGtD;;;GAGG;AACH,eAAO,MAAM,qBAAqB,aAAa,CAAC;AAEhD,yCAAyC;AACzC,MAAM,WAAW,wBAAwB;IACxC,sDAAsD;IACtD,IAAI,EAAE,MAAM,CAAC;IACb,4BAA4B;IAC5B,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;IAC1B,2CAA2C;IAC3C,GAAG,EAAE,MAAM,CAAC;IACZ;;;;;;;;OAQG;IACH,sBAAsB,EAAE,WAAW,GAAG,IAAI,CAAC;IAC3C;;;;;;;OAOG;IACH,2BAA2B,EAAE,WAAW,GAAG,IAAI,CAAC;CAChD;AAED
|
|
1
|
+
{"version":3,"file":"action_rpc.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/actions/action_rpc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAMH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAGtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAqB,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAgB1E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGtD;;;GAGG;AACH,eAAO,MAAM,qBAAqB,aAAa,CAAC;AAEhD,yCAAyC;AACzC,MAAM,WAAW,wBAAwB;IACxC,sDAAsD;IACtD,IAAI,EAAE,MAAM,CAAC;IACb,4BAA4B;IAC5B,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;IAC1B,2CAA2C;IAC3C,GAAG,EAAE,MAAM,CAAC;IACZ;;;;;;;;OAQG;IACH,sBAAsB,EAAE,WAAW,GAAG,IAAI,CAAC;IAC3C;;;;;;;OAOG;IACH,2BAA2B,EAAE,WAAW,GAAG,IAAI,CAAC;CAChD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,eAAO,MAAM,mBAAmB,GAAI,SAAS,wBAAwB,KAAG,KAAK,CAAC,SAAS,CAuNtF,CAAC"}
|
|
@@ -70,9 +70,10 @@ export const RPC_GET_CACHE_CONTROL = 'no-store';
|
|
|
70
70
|
* @param options - endpoint path, actions, logger, and the two action rate limiters
|
|
71
71
|
* @returns route specs (GET + POST) ready for `apply_route_specs`
|
|
72
72
|
* @throws Error if two actions share the same `spec.method` (registration-time
|
|
73
|
-
* duplicate detection); also throws if any action's `spec.input` is
|
|
74
|
-
* `z.null()` (JSON-RPC 2.0 §4.2 forbids
|
|
75
|
-
* `
|
|
73
|
+
* duplicate detection); also throws if any action's `spec.input` is a null
|
|
74
|
+
* schema (`z.null()` or fuz_schema `literal(null)`; JSON-RPC 2.0 §4.2 forbids
|
|
75
|
+
* `params: null` on the wire — use a void schema for parameterless methods)
|
|
76
|
+
* or its `spec.output` is a void schema.
|
|
76
77
|
*/
|
|
77
78
|
export const create_rpc_endpoint = (options) => {
|
|
78
79
|
const { path: endpoint_path, actions, log, action_ip_rate_limiter, action_account_rate_limiter } = options;
|