@fuzdev/fuz_app 0.169.0 → 0.171.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions/CLAUDE.md +19 -21
- package/dist/actions/action_codegen.d.ts +27 -18
- package/dist/actions/action_codegen.d.ts.map +1 -1
- package/dist/actions/action_codegen.js +90 -90
- package/dist/actions/action_event.d.ts +0 -8
- package/dist/actions/action_event.d.ts.map +1 -1
- package/dist/actions/action_event.js +7 -6
- package/dist/actions/action_event_data.d.ts +4 -4
- package/dist/actions/action_rpc.d.ts +1 -1
- package/dist/actions/action_rpc.d.ts.map +1 -1
- package/dist/actions/action_rpc.js +6 -7
- package/dist/actions/action_spec.d.ts +8 -10
- package/dist/actions/action_spec.d.ts.map +1 -1
- package/dist/actions/action_spec.js +1 -1
- package/dist/actions/action_types.d.ts +4 -4
- package/dist/actions/action_types.d.ts.map +1 -1
- package/dist/actions/action_types.js +2 -2
- package/dist/actions/broadcast_api.d.ts +2 -2
- package/dist/actions/broadcast_api.js +4 -4
- package/dist/actions/compile_action_registry.d.ts +6 -7
- package/dist/actions/compile_action_registry.d.ts.map +1 -1
- package/dist/actions/compile_action_registry.js +8 -9
- package/dist/actions/peer_ping.d.ts.map +1 -1
- package/dist/actions/peer_ping.js +3 -2
- package/dist/actions/perform_action.d.ts +6 -6
- package/dist/actions/perform_action.d.ts.map +1 -1
- package/dist/actions/perform_action.js +11 -10
- package/dist/actions/socket.svelte.d.ts +1 -1
- package/dist/actions/socket.svelte.js +2 -2
- package/dist/actions/ws_socket_session.d.ts.map +1 -1
- package/dist/actions/ws_socket_session.js +2 -1
- package/dist/auth/CLAUDE.md +11 -11
- package/dist/auth/admin_action_specs.d.ts +24 -24
- package/dist/auth/audit_emitter.d.ts +6 -7
- package/dist/auth/audit_emitter.d.ts.map +1 -1
- package/dist/auth/audit_emitter.js +11 -22
- package/dist/auth/audit_log_ddl.d.ts +1 -1
- package/dist/auth/audit_log_ddl.js +1 -1
- package/dist/auth/audit_log_queries.d.ts +0 -13
- package/dist/auth/audit_log_queries.d.ts.map +1 -1
- package/dist/auth/audit_log_queries.js +3 -3
- package/dist/auth/audit_log_schema.d.ts +14 -15
- package/dist/auth/audit_log_schema.d.ts.map +1 -1
- package/dist/auth/audit_log_schema.js +1 -1
- package/dist/auth/auth_ddl.d.ts +1 -1
- package/dist/auth/auth_ddl.js +1 -1
- package/dist/auth/cell_action_specs.d.ts +54 -54
- package/dist/auth/cell_actions.d.ts +2 -2
- package/dist/auth/cell_actions.js +5 -5
- package/dist/auth/middleware.d.ts +6 -2
- package/dist/auth/middleware.d.ts.map +1 -1
- package/dist/auth/middleware.js +14 -2
- package/dist/auth/request_context.d.ts.map +1 -1
- package/dist/auth/request_context.js +7 -9
- package/dist/auth/role_grant_offer_action_specs.d.ts +6 -6
- package/dist/auth/role_grant_offer_ddl.d.ts +1 -1
- package/dist/auth/role_grant_offer_ddl.js +1 -1
- package/dist/auth/role_grant_offer_notifications.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_notifications.js +2 -3
- package/dist/auth/self_service_role_actions.d.ts +1 -1
- package/dist/auth/self_service_role_actions.js +1 -1
- package/dist/env/env_schemas.d.ts +1 -2
- package/dist/env/env_schemas.d.ts.map +1 -1
- package/dist/env/env_schemas.js +3 -4
- package/dist/http/CLAUDE.md +30 -31
- package/dist/http/auth_shape.d.ts +14 -32
- package/dist/http/auth_shape.d.ts.map +1 -1
- package/dist/http/auth_shape.js +14 -49
- package/dist/http/error_schemas.d.ts +18 -18
- package/dist/http/json_text.d.ts +53 -0
- package/dist/http/json_text.d.ts.map +1 -0
- package/dist/http/json_text.js +152 -0
- package/dist/http/jsonrpc_helpers.js +1 -1
- package/dist/http/route_error_check.d.ts +2 -2
- package/dist/http/route_error_check.d.ts.map +1 -1
- package/dist/http/route_error_check.js +2 -3
- package/dist/http/route_errors.d.ts +4 -4
- package/dist/http/route_errors.d.ts.map +1 -1
- package/dist/http/route_errors.js +0 -13
- package/dist/http/route_result.d.ts +2 -1
- package/dist/http/route_result.d.ts.map +1 -1
- package/dist/http/route_spec.d.ts +34 -37
- package/dist/http/route_spec.d.ts.map +1 -1
- package/dist/http/route_spec.js +31 -31
- package/dist/http/schema_helpers.d.ts +77 -68
- package/dist/http/schema_helpers.d.ts.map +1 -1
- package/dist/http/schema_helpers.js +54 -77
- package/dist/http/surface.d.ts.map +1 -1
- package/dist/http/surface.js +6 -8
- package/dist/primitive_schemas.d.ts +9 -17
- package/dist/primitive_schemas.d.ts.map +1 -1
- package/dist/primitive_schemas.js +9 -17
- package/dist/realtime/sse.d.ts +3 -3
- package/dist/realtime/sse.d.ts.map +1 -1
- package/dist/realtime/sse.js +2 -2
- package/dist/schema_issues.d.ts +39 -147
- package/dist/schema_issues.d.ts.map +1 -1
- package/dist/schema_issues.js +39 -352
- package/dist/schema_meta.d.ts +63 -136
- package/dist/schema_meta.d.ts.map +1 -1
- package/dist/schema_meta.js +37 -184
- package/dist/sensitivity.d.ts +3 -5
- package/dist/sensitivity.d.ts.map +1 -1
- package/dist/sensitivity.js +3 -5
- package/dist/testing/CLAUDE.md +20 -22
- package/dist/testing/adversarial_headers.js +2 -2
- package/dist/testing/adversarial_input_cases.d.ts +19 -18
- package/dist/testing/adversarial_input_cases.d.ts.map +1 -1
- package/dist/testing/adversarial_input_cases.js +31 -46
- package/dist/testing/assertions.d.ts +2 -2
- package/dist/testing/assertions.d.ts.map +1 -1
- package/dist/testing/assertions.js +3 -3
- package/dist/testing/cross_backend/account_lifecycle.js +2 -2
- package/dist/testing/cross_backend/action_manifest.d.ts +10 -9
- package/dist/testing/cross_backend/action_manifest.d.ts.map +1 -1
- package/dist/testing/cross_backend/action_manifest.js +4 -3
- package/dist/testing/cross_backend/cell_crud.js +1 -1
- package/dist/testing/cross_backend/conformance_rpc_auth.d.ts +0 -62
- package/dist/testing/cross_backend/conformance_rpc_auth.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_table.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_table.js +3 -3
- package/dist/testing/cross_backend/cross_rpc.d.ts +3 -4
- package/dist/testing/cross_backend/cross_rpc.d.ts.map +1 -1
- package/dist/testing/cross_backend/cross_rpc.js +4 -4
- package/dist/testing/cross_backend/differential.js +2 -2
- package/dist/testing/cross_backend/identity_parity.d.ts.map +1 -1
- package/dist/testing/cross_backend/identity_parity.js +16 -11
- package/dist/testing/cross_backend/origin_conformance.d.ts +9 -9
- package/dist/testing/cross_backend/query_shape.js +1 -1
- package/dist/testing/cross_backend/rpc_success_fixtures.d.ts.map +1 -1
- package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts +1 -1
- package/dist/testing/cross_backend/setup.d.ts +25 -3
- package/dist/testing/cross_backend/setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/setup.js +4 -4
- package/dist/testing/cross_backend/sse_round_trip.js +2 -2
- package/dist/testing/cross_backend/testing_origin_check.d.ts +4 -4
- package/dist/testing/cross_backend/token_lifetime.js +3 -3
- package/dist/testing/cross_backend/wire_shapes.js +1 -1
- package/dist/testing/cross_backend/ws_envelope.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_envelope.js +8 -0
- package/dist/testing/cross_backend/ws_round_trip.js +1 -1
- package/dist/testing/data_exposure.d.ts.map +1 -1
- package/dist/testing/data_exposure.js +1 -1
- package/dist/testing/integration.js +2 -2
- package/dist/testing/integration_helpers.d.ts.map +1 -1
- package/dist/testing/integration_helpers.js +2 -2
- package/dist/testing/middleware.d.ts.map +1 -1
- package/dist/testing/middleware.js +2 -2
- package/dist/testing/rpc_attack_surface.js +1 -1
- package/dist/testing/rpc_envelope_cases.d.ts +10 -3
- package/dist/testing/rpc_envelope_cases.d.ts.map +1 -1
- package/dist/testing/rpc_envelope_cases.js +22 -1
- package/dist/testing/rpc_helpers.d.ts +12 -14
- package/dist/testing/rpc_helpers.d.ts.map +1 -1
- package/dist/testing/rpc_helpers.js +9 -10
- package/dist/testing/schema_generators.d.ts +67 -60
- package/dist/testing/schema_generators.d.ts.map +1 -1
- package/dist/testing/schema_generators.js +154 -159
- package/dist/testing/sse_round_trip.d.ts.map +1 -1
- package/dist/testing/sse_round_trip.js +2 -2
- package/dist/testing/surface_invariants.d.ts +1 -1
- package/dist/testing/surface_invariants.js +1 -1
- package/dist/ui/form_state.svelte.d.ts +1 -1
- package/dist/ui/form_state.svelte.js +1 -1
- package/package.json +5 -7
- package/dist/zod.d.ts +0 -116
- package/dist/zod.d.ts.map +0 -1
- package/dist/zod.js +0 -218
- package/dist/zod_schemas.d.ts +0 -100
- package/dist/zod_schemas.d.ts.map +0 -1
- package/dist/zod_schemas.js +0 -157
|
@@ -9,16 +9,15 @@
|
|
|
9
9
|
* which checks the handler's results against the route.
|
|
10
10
|
*
|
|
11
11
|
* Input/output schemas align with SAES `ActionSpec` conventions, and each is
|
|
12
|
-
* a
|
|
13
|
-
* - `input`: the request body schema (`
|
|
12
|
+
* a `@fuzdev/fuz_schema` schema (`AnySchema`):
|
|
13
|
+
* - `input`: the request body schema (`literal(null)` for no body)
|
|
14
14
|
* - `output`: the success response body schema
|
|
15
|
-
* - a strict object for inputs (reject unknown keys): `
|
|
15
|
+
* - a strict object for inputs (reject unknown keys): `object`
|
|
16
16
|
*
|
|
17
17
|
* @module
|
|
18
18
|
*/
|
|
19
19
|
import type { Context, Hono, MiddlewareHandler } from 'hono';
|
|
20
|
-
import type
|
|
21
|
-
import { type AnySchema } from '@fuzdev/fuz_schema/schema.ts';
|
|
20
|
+
import { type AnySchema, type InferInput, type Infer } from '@fuzdev/fuz_schema/schema.ts';
|
|
22
21
|
import type { Logger } from '@fuzdev/fuz_util/log.ts';
|
|
23
22
|
import type { Db } from '../db/db.js';
|
|
24
23
|
import { type RestErrorDef, type REST_AUTHENTICATION_REQUIRED, type REST_CREDENTIAL_TYPE_REQUIRED, type REST_INSUFFICIENT_PERMISSIONS, type REST_INTERNAL_ERROR, type REST_RATE_LIMIT_EXCEEDED, type REST_SERVICE_UNAVAILABLE, type REST_TOKEN_SCOPE_REQUIRED } from './error_schemas.js';
|
|
@@ -26,7 +25,6 @@ import type { RateLimitKey } from '../rate_limiter.js';
|
|
|
26
25
|
import type { MiddlewareSpec } from './middleware_spec.js';
|
|
27
26
|
import type { ReadonlyJson, RouteFailOf, RouteOk, RouteRaw, RouteResult } from './route_result.js';
|
|
28
27
|
import { type RouteAuth } from './auth_shape.js';
|
|
29
|
-
import { type ValidationInput, type ValidationOutput, type ValidationSchema } from '../schema_issues.js';
|
|
30
28
|
/**
|
|
31
29
|
* Two-phase auth guard set returned by `AuthGuardResolver`.
|
|
32
30
|
*
|
|
@@ -127,9 +125,9 @@ declare const ROUTE_SPEC_BRAND: unique symbol;
|
|
|
127
125
|
* A single route definition — the unit of the surface map.
|
|
128
126
|
*
|
|
129
127
|
* `input` and `output` schemas align with SAES `ActionSpec` naming. Every
|
|
130
|
-
* schema field takes a
|
|
131
|
-
* `
|
|
132
|
-
*
|
|
128
|
+
* schema field takes a `@fuzdev/fuz_schema` schema, validated through
|
|
129
|
+
* `parse`. Use `literal(null)` for routes with no request body (GET, DELETE
|
|
130
|
+
* without body).
|
|
133
131
|
*/
|
|
134
132
|
export interface RouteSpec {
|
|
135
133
|
method: RouteMethod;
|
|
@@ -139,30 +137,29 @@ export interface RouteSpec {
|
|
|
139
137
|
handler: RouteHandler;
|
|
140
138
|
description: string;
|
|
141
139
|
/**
|
|
142
|
-
* URL path parameter schema. Use `
|
|
143
|
-
* `
|
|
144
|
-
*
|
|
140
|
+
* URL path parameter schema. Use an `object` with string fields matching
|
|
141
|
+
* `:param` segments. It must be an object schema under any wrappers
|
|
142
|
+
* (`get_schema_entries`);
|
|
145
143
|
* `apply_route_specs` throws on one that isn't.
|
|
146
144
|
*
|
|
147
145
|
* REST-only — actions dispatch through a single JSON-RPC endpoint and encode
|
|
148
146
|
* everything in `input`, so `params` doesn't appear on `ActionSpec`.
|
|
149
147
|
*/
|
|
150
|
-
params?:
|
|
148
|
+
params?: AnySchema;
|
|
151
149
|
/**
|
|
152
|
-
* URL query parameter schema. Use `
|
|
153
|
-
*
|
|
154
|
-
* schema, as for `params`.
|
|
150
|
+
* URL query parameter schema. Use an `object` with string fields; it must
|
|
151
|
+
* be an object schema, as for `params`.
|
|
155
152
|
*/
|
|
156
|
-
query?:
|
|
157
|
-
/** Request body schema. Use `
|
|
158
|
-
input:
|
|
153
|
+
query?: AnySchema;
|
|
154
|
+
/** Request body schema. Use `literal(null)` for routes with no body. */
|
|
155
|
+
input: AnySchema;
|
|
159
156
|
/** Success response body schema. */
|
|
160
|
-
output:
|
|
157
|
+
output: AnySchema;
|
|
161
158
|
/**
|
|
162
159
|
* Marks a route whose request and/or response carries **raw bytes or a
|
|
163
160
|
* streaming protocol** rather than JSON — git smart-HTTP, file-store
|
|
164
161
|
* binary uploads/downloads, raw internal callbacks. Disambiguates the
|
|
165
|
-
* overloaded `input:
|
|
162
|
+
* overloaded `input: literal(null)`, which otherwise can't distinguish "no
|
|
166
163
|
* body" (`GET /health`) from "raw bytes" (a binary upload).
|
|
167
164
|
*
|
|
168
165
|
* A `raw_body` `POST` takes any `Content-Type` a browser can't send
|
|
@@ -267,9 +264,9 @@ export type RouteHandlerDerivedErrors<TAuth extends RouteAuth, TRateLimit> = (TA
|
|
|
267
264
|
* allows — its `errors`, the derived ones a handler may give
|
|
268
265
|
* (`RouteHandlerDerivedErrors`), and the catch layers' (`RouteAlwaysErrors`).
|
|
269
266
|
*/
|
|
270
|
-
export type RouteHandlerResult<TErrors extends ReadonlyArray<RestErrorDef>, TOutput extends
|
|
267
|
+
export type RouteHandlerResult<TErrors extends ReadonlyArray<RestErrorDef>, TOutput extends AnySchema, TAuth extends RouteAuth, TRateLimit> = RouteOk<ReadonlyJson<InferInput<TOutput>>> | RouteRaw | RouteFailOf<TErrors[number] | RouteAlwaysErrors | RouteHandlerDerivedErrors<TAuth, TRateLimit>>;
|
|
271
268
|
/** A route handler checked against its route; see `RouteHandlerResult`. */
|
|
272
|
-
export type TypedRouteHandler<TErrors extends ReadonlyArray<RestErrorDef>, TOutput extends
|
|
269
|
+
export type TypedRouteHandler<TErrors extends ReadonlyArray<RestErrorDef>, TOutput extends AnySchema, TAuth extends RouteAuth, TRateLimit> = (c: Context, route: RouteContext) => RouteHandlerResult<TErrors, TOutput, TAuth, TRateLimit> | Promise<RouteHandlerResult<TErrors, TOutput, TAuth, TRateLimit>>;
|
|
273
270
|
/** The fields of a route that carry no type parameter. */
|
|
274
271
|
type RouteShapePlain = Omit<RouteSpec, 'handler' | 'errors' | 'output' | 'auth' | 'rate_limit' | typeof ROUTE_SPEC_BRAND>;
|
|
275
272
|
/**
|
|
@@ -277,7 +274,7 @@ type RouteShapePlain = Omit<RouteSpec, 'handler' | 'errors' | 'output' | 'auth'
|
|
|
277
274
|
* kept: what `define_route_shape` returns and `attach_route_handler` takes,
|
|
278
275
|
* the hono-free half of a route a cross-process suite builds its surface from.
|
|
279
276
|
*/
|
|
280
|
-
export type RouteShape<TErrors extends ReadonlyArray<RestErrorDef> = ReadonlyArray<RestErrorDef>, TOutput extends
|
|
277
|
+
export type RouteShape<TErrors extends ReadonlyArray<RestErrorDef> = ReadonlyArray<RestErrorDef>, TOutput extends AnySchema = AnySchema, TAuth extends RouteAuth = RouteAuth, TRateLimit extends RateLimitKey | undefined = RateLimitKey | undefined> = RouteShapePlain & {
|
|
281
278
|
auth: TAuth;
|
|
282
279
|
output: TOutput;
|
|
283
280
|
errors?: TErrors;
|
|
@@ -299,7 +296,7 @@ export type KnownRouteErrors<TErrors extends ReadonlyArray<RestErrorDef>> = stri
|
|
|
299
296
|
* @param spec - the route, its handler returning `route_ok`, `route_fail`, or `route_raw`
|
|
300
297
|
* @returns `spec`
|
|
301
298
|
*/
|
|
302
|
-
export declare const define_route: <const TErrors extends ReadonlyArray<RestErrorDef> = [], TOutput extends
|
|
299
|
+
export declare const define_route: <const TErrors extends ReadonlyArray<RestErrorDef> = [], TOutput extends AnySchema = AnySchema, const TAuth extends RouteAuth = RouteAuth, TRateLimit extends RateLimitKey | undefined = undefined>(spec: RouteShape<TErrors, TOutput, TAuth, TRateLimit> & {
|
|
303
300
|
errors?: KnownRouteErrors<TErrors>;
|
|
304
301
|
handler: TypedRouteHandler<TErrors, TOutput, TAuth, TRateLimit>;
|
|
305
302
|
}) => RouteSpec;
|
|
@@ -310,7 +307,7 @@ export declare const define_route: <const TErrors extends ReadonlyArray<RestErro
|
|
|
310
307
|
* @param shape - the route without `handler`
|
|
311
308
|
* @returns `shape`
|
|
312
309
|
*/
|
|
313
|
-
export declare const define_route_shape: <const TErrors extends ReadonlyArray<RestErrorDef> = [], TOutput extends
|
|
310
|
+
export declare const define_route_shape: <const TErrors extends ReadonlyArray<RestErrorDef> = [], TOutput extends AnySchema = AnySchema, const TAuth extends RouteAuth = RouteAuth, TRateLimit extends RateLimitKey | undefined = undefined>(shape: RouteShape<TErrors, TOutput, TAuth, TRateLimit> & {
|
|
314
311
|
errors?: KnownRouteErrors<TErrors>;
|
|
315
312
|
}) => RouteShape<TErrors, TOutput, TAuth, TRateLimit>;
|
|
316
313
|
/**
|
|
@@ -321,7 +318,7 @@ export declare const define_route_shape: <const TErrors extends ReadonlyArray<Re
|
|
|
321
318
|
* @param handler - the handler, returning `route_ok`, `route_fail`, or `route_raw`
|
|
322
319
|
* @returns a new spec, `shape` with `handler`
|
|
323
320
|
*/
|
|
324
|
-
export declare const attach_route_handler: <TErrors extends ReadonlyArray<RestErrorDef>, TOutput extends
|
|
321
|
+
export declare const attach_route_handler: <TErrors extends ReadonlyArray<RestErrorDef>, TOutput extends AnySchema, TAuth extends RouteAuth, TRateLimit extends RateLimitKey | undefined>(shape: RouteShape<TErrors, TOutput, TAuth, TRateLimit> & {
|
|
325
322
|
errors?: KnownRouteErrors<TErrors>;
|
|
326
323
|
}, handler: TypedRouteHandler<TErrors, TOutput, TAuth, TRateLimit>) => RouteSpec;
|
|
327
324
|
/**
|
|
@@ -332,15 +329,15 @@ export declare const attach_route_handler: <TErrors extends ReadonlyArray<RestEr
|
|
|
332
329
|
*
|
|
333
330
|
* @param c - the Hono context
|
|
334
331
|
* @param result - the handler's result
|
|
335
|
-
* @throws TypeError when `result` is not a result `route_ok`, `route_fail`, or `route_raw` made: a `Response`, a success without a value, a failure without its status or definition, a raw result without a response, `undefined` or `null`
|
|
332
|
+
* @throws TypeError when `result` is not a result `route_ok`, `route_fail`, or `route_raw` made: a `Response`, a success without a value or with a function or symbol for one, a failure without its status or definition, a raw result without a response, `undefined` or `null`
|
|
336
333
|
*/
|
|
337
334
|
export declare const to_route_response: (c: Context, result: RouteResult) => Response;
|
|
338
335
|
/**
|
|
339
336
|
* Get validated input from the Hono context.
|
|
340
337
|
*
|
|
341
338
|
* Call after the input validation middleware has run. Pass the route's
|
|
342
|
-
* `input` schema
|
|
343
|
-
* directly (`
|
|
339
|
+
* `input` schema to infer the typed shape
|
|
340
|
+
* directly (`Infer`):
|
|
344
341
|
*
|
|
345
342
|
* ```ts
|
|
346
343
|
* const input = get_route_input(c, my_route_spec.input);
|
|
@@ -352,7 +349,7 @@ export declare const to_route_response: (c: Context, result: RouteResult) => Res
|
|
|
352
349
|
* const input = get_route_input<MyInput>(c);
|
|
353
350
|
* ```
|
|
354
351
|
*/
|
|
355
|
-
export declare function get_route_input<S extends
|
|
352
|
+
export declare function get_route_input<S extends AnySchema>(c: Context, schema: S): Infer<S>;
|
|
356
353
|
export declare function get_route_input<T = unknown>(c: Context): T;
|
|
357
354
|
/**
|
|
358
355
|
* Get validated URL path params from the Hono context.
|
|
@@ -361,7 +358,7 @@ export declare function get_route_input<T = unknown>(c: Context): T;
|
|
|
361
358
|
* `params` schema to infer the typed shape, or supply an explicit type
|
|
362
359
|
* argument. See `get_route_input` for the two call shapes.
|
|
363
360
|
*/
|
|
364
|
-
export declare function get_route_params<S extends
|
|
361
|
+
export declare function get_route_params<S extends AnySchema>(c: Context, schema: S): Infer<S>;
|
|
365
362
|
export declare function get_route_params<T = unknown>(c: Context): T;
|
|
366
363
|
/**
|
|
367
364
|
* Get validated URL query params from the Hono context.
|
|
@@ -370,7 +367,7 @@ export declare function get_route_params<T = unknown>(c: Context): T;
|
|
|
370
367
|
* `query` schema to infer the typed shape, or supply an explicit type
|
|
371
368
|
* argument. See `get_route_input` for the two call shapes.
|
|
372
369
|
*/
|
|
373
|
-
export declare function get_route_query<S extends
|
|
370
|
+
export declare function get_route_query<S extends AnySchema>(c: Context, schema: S): Infer<S>;
|
|
374
371
|
export declare function get_route_query<T = unknown>(c: Context): T;
|
|
375
372
|
/**
|
|
376
373
|
* Apply named middleware specs to a Hono app.
|
|
@@ -416,10 +413,10 @@ export declare const apply_middleware_specs: (app: Hono, specs: Array<Middleware
|
|
|
416
413
|
* registries (`compile_action_registry`) share the same helper with
|
|
417
414
|
* `input` only — `ActionSpec` has no `query` shape.
|
|
418
415
|
*
|
|
419
|
-
* Every schema slot (`params`, `query`, `input`, `output`) must hold a
|
|
420
|
-
*
|
|
416
|
+
* Every schema slot (`params`, `query`, `input`, `output`) must hold a
|
|
417
|
+
* `@fuzdev/fuz_schema` schema (`assert_validation_schema`), and every
|
|
421
418
|
* `errors` entry an error definition (`rest_error`): anything else throws
|
|
422
|
-
* naming the route and the slot. A
|
|
419
|
+
* naming the route and the slot. A `params` or `query`
|
|
423
420
|
* must be an object schema (`get_schema_entries`), as the path params and
|
|
424
421
|
* query string are an object: one that isn't throws naming the route.
|
|
425
422
|
*
|
|
@@ -431,7 +428,7 @@ export declare const apply_middleware_specs: (app: Hono, specs: Array<Middleware
|
|
|
431
428
|
* @param authorize - optional authorization phase; runs after the pre-authorization guards and before the post-authorization guards
|
|
432
429
|
* @param db - used for transaction wrapping and `RouteContext`
|
|
433
430
|
* @mutates `app`
|
|
434
|
-
* @throws Error if two specs share the same `method` + `path` (each combination must be unique), if a schema slot holds a value
|
|
431
|
+
* @throws Error if two specs share the same `method` + `path` (each combination must be unique), if a schema slot holds a value that is no schema or an `errors` entry is not a definition, if any spec violates a cross-axis auth invariant or the actor-acting biconditional, or if a `params` or `query` is not an object schema
|
|
435
432
|
*/
|
|
436
433
|
export declare const apply_route_specs: (app: Hono, specs: Array<RouteSpec>, resolve_auth_guards: AuthGuardResolver, log: Logger, db: Db, authorize?: AuthorizationHandler) => void;
|
|
437
434
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route_spec.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/route_spec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAW,IAAI,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"route_spec.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/route_spec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAW,IAAI,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAGtE,OAAO,EAEN,KAAK,SAAS,EAEd,KAAK,UAAU,EACf,KAAK,KAAK,EACV,MAAM,8BAA8B,CAAC;AAEtC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAGtC,OAAO,EACN,KAAK,YAAY,EACjB,KAAK,4BAA4B,EACjC,KAAK,6BAA6B,EAClC,KAAK,6BAA6B,EAClC,KAAK,mBAAmB,EACxB,KAAK,wBAAwB,EAC7B,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,EAQ9B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAYvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;A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,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;AACtF,wBAAgB,eAAe,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC;AA2K5D;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GAAI,KAAK,IAAI,EAAE,OAAO,KAAK,CAAC,cAAc,CAAC,KAAG,IAIhF,CAAC;AAsGF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,eAAO,MAAM,iBAAiB,GAC7B,KAAK,IAAI,EACT,OAAO,KAAK,CAAC,SAAS,CAAC,EACvB,qBAAqB,iBAAiB,EACtC,KAAK,MAAM,EACX,IAAI,EAAE,EACN,YAAY,oBAAoB,KAC9B,IA+EF,CAAC;AAkCF;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAAI,QAAQ,MAAM,EAAE,OAAO,KAAK,CAAC,SAAS,CAAC,KAAG,KAAK,CAAC,SAAS,CAK3F,CAAC"}
|
package/dist/http/route_spec.js
CHANGED
|
@@ -9,15 +9,15 @@
|
|
|
9
9
|
* which checks the handler's results against the route.
|
|
10
10
|
*
|
|
11
11
|
* Input/output schemas align with SAES `ActionSpec` conventions, and each is
|
|
12
|
-
* a
|
|
13
|
-
* - `input`: the request body schema (`
|
|
12
|
+
* a `@fuzdev/fuz_schema` schema (`AnySchema`):
|
|
13
|
+
* - `input`: the request body schema (`literal(null)` for no body)
|
|
14
14
|
* - `output`: the success response body schema
|
|
15
|
-
* - a strict object for inputs (reject unknown keys): `
|
|
15
|
+
* - a strict object for inputs (reject unknown keys): `object`
|
|
16
16
|
*
|
|
17
17
|
* @module
|
|
18
18
|
*/
|
|
19
19
|
import { DEV } from 'esm-env';
|
|
20
|
-
import { is_schema } from '@fuzdev/fuz_schema/schema.ts';
|
|
20
|
+
import { is_schema, parse } from '@fuzdev/fuz_schema/schema.ts';
|
|
21
21
|
import { get_schema_entries } from '@fuzdev/fuz_schema/introspect.ts';
|
|
22
22
|
import { format_route_key } from './surface_query.js';
|
|
23
23
|
import { is_db_checkout_error } from '../db/db_checkout_error.js';
|
|
@@ -28,7 +28,8 @@ import { is_null_schema } from './schema_helpers.js';
|
|
|
28
28
|
import { is_json_response } from './route_error_check.js';
|
|
29
29
|
import { dispatch_with_post_commit_rollback } from './pending_effects.js';
|
|
30
30
|
import { assert_route_auth_acting_biconditional, assert_route_auth_invariants } from './auth_shape.js';
|
|
31
|
-
import { assert_validation_schema,
|
|
31
|
+
import { assert_validation_schema, to_wire_issues } from '../schema_issues.js';
|
|
32
|
+
import { read_json_body } from './json_text.js';
|
|
32
33
|
/**
|
|
33
34
|
* Define a route: its handler is checked against the route's `output`,
|
|
34
35
|
* `errors`, `auth`, and `rate_limit` (`TypedRouteHandler`), and the spec is
|
|
@@ -69,15 +70,18 @@ export const attach_route_handler = (shape, handler) => ({ ...shape, handler });
|
|
|
69
70
|
*
|
|
70
71
|
* @param c - the Hono context
|
|
71
72
|
* @param result - the handler's result
|
|
72
|
-
* @throws TypeError when `result` is not a result `route_ok`, `route_fail`, or `route_raw` made: a `Response`, a success without a value, a failure without its status or definition, a raw result without a response, `undefined` or `null`
|
|
73
|
+
* @throws TypeError when `result` is not a result `route_ok`, `route_fail`, or `route_raw` made: a `Response`, a success without a value or with a function or symbol for one, a failure without its status or definition, a raw result without a response, `undefined` or `null`
|
|
73
74
|
*/
|
|
74
75
|
export const to_route_response = (c, result) => {
|
|
75
76
|
// each branch checks the field it reads, so a malformed or nullish result
|
|
76
77
|
// falls through to the throw — a `Response` has its own `ok` and `status`,
|
|
77
|
-
// but no `value` or `def
|
|
78
|
+
// but no `value` or `def`. A function or symbol value is no JSON value:
|
|
79
|
+
// `JSON.stringify` writes nothing for it, which would answer an empty 200
|
|
78
80
|
if (result?.ok === true) {
|
|
79
|
-
|
|
81
|
+
const type = typeof result.value;
|
|
82
|
+
if (type !== 'undefined' && type !== 'function' && type !== 'symbol') {
|
|
80
83
|
return c.json(result.value);
|
|
84
|
+
}
|
|
81
85
|
}
|
|
82
86
|
else if (result?.ok === 'raw') {
|
|
83
87
|
if (result.response instanceof Response)
|
|
@@ -141,21 +145,18 @@ const create_input_validation = (input_schema, method) => {
|
|
|
141
145
|
if (is_null_schema(input_schema))
|
|
142
146
|
return [];
|
|
143
147
|
const validate = async (c, next) => {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
body = await c.req.json();
|
|
147
|
-
}
|
|
148
|
-
catch {
|
|
148
|
+
const read = await read_json_body(c.req);
|
|
149
|
+
if (!read.ok)
|
|
149
150
|
return c.json({ error: ERROR_INVALID_JSON_BODY }, 400);
|
|
150
|
-
|
|
151
|
+
const body = read.value;
|
|
151
152
|
if (typeof body !== 'object' || body === null || Array.isArray(body)) {
|
|
152
153
|
return c.json({ error: ERROR_INVALID_JSON_BODY }, 400);
|
|
153
154
|
}
|
|
154
|
-
const result =
|
|
155
|
+
const result = parse(input_schema, body);
|
|
155
156
|
if (!result.ok) {
|
|
156
157
|
return c.json({
|
|
157
158
|
error: ERROR_INVALID_REQUEST_BODY,
|
|
158
|
-
issues: dev_only(() => to_wire_issues(result.issues
|
|
159
|
+
issues: dev_only(() => to_wire_issues(result.issues))
|
|
159
160
|
}, 400);
|
|
160
161
|
}
|
|
161
162
|
c.set('validated_input', result.value);
|
|
@@ -177,11 +178,11 @@ const create_params_validation = (params_schema) => {
|
|
|
177
178
|
return [];
|
|
178
179
|
const validate = async (c, next) => {
|
|
179
180
|
const raw_params = c.req.param();
|
|
180
|
-
const result =
|
|
181
|
+
const result = parse(params_schema, raw_params);
|
|
181
182
|
if (!result.ok) {
|
|
182
183
|
return c.json({
|
|
183
184
|
error: ERROR_INVALID_ROUTE_PARAMS,
|
|
184
|
-
issues: dev_only(() => to_wire_issues(result.issues
|
|
185
|
+
issues: dev_only(() => to_wire_issues(result.issues))
|
|
185
186
|
}, 400);
|
|
186
187
|
}
|
|
187
188
|
c.set('validated_params', result.value);
|
|
@@ -203,11 +204,11 @@ const create_query_validation = (query_schema) => {
|
|
|
203
204
|
return [];
|
|
204
205
|
const validate = async (c, next) => {
|
|
205
206
|
const raw_query = c.req.query();
|
|
206
|
-
const result =
|
|
207
|
+
const result = parse(query_schema, raw_query);
|
|
207
208
|
if (!result.ok) {
|
|
208
209
|
return c.json({
|
|
209
210
|
error: ERROR_INVALID_QUERY_PARAMS,
|
|
210
|
-
issues: dev_only(() => to_wire_issues(result.issues
|
|
211
|
+
issues: dev_only(() => to_wire_issues(result.issues))
|
|
211
212
|
}, 400);
|
|
212
213
|
}
|
|
213
214
|
c.set('validated_query', result.value);
|
|
@@ -223,8 +224,8 @@ const create_query_validation = (query_schema) => {
|
|
|
223
224
|
* never throws. Non-2xx responses are the DEV error check's
|
|
224
225
|
* (`create_dev_route_error_check`), which `create_app_server` mounts
|
|
225
226
|
* outermost so it sees what every layer answers. Non-JSON responses (SSE,
|
|
226
|
-
* binary) are skipped. The schema is
|
|
227
|
-
*
|
|
227
|
+
* binary) are skipped. The schema is parsed with `parse`; the log carries
|
|
228
|
+
* its issues. In production,
|
|
228
229
|
* returns the handler unchanged.
|
|
229
230
|
*/
|
|
230
231
|
const wrap_output_validation = (handler, output_schema, log) => {
|
|
@@ -247,7 +248,7 @@ const wrap_output_validation = (handler, output_schema, log) => {
|
|
|
247
248
|
// clone() or json() failed on a response claiming application/json
|
|
248
249
|
return response;
|
|
249
250
|
}
|
|
250
|
-
const result =
|
|
251
|
+
const result = parse(output_schema, body);
|
|
251
252
|
if (!result.ok) {
|
|
252
253
|
log.error(`Output schema mismatch: ${c.req.method} ${c.req.path}`, result.issues);
|
|
253
254
|
}
|
|
@@ -399,10 +400,10 @@ const build_rest_error_body = (err) => {
|
|
|
399
400
|
* registries (`compile_action_registry`) share the same helper with
|
|
400
401
|
* `input` only — `ActionSpec` has no `query` shape.
|
|
401
402
|
*
|
|
402
|
-
* Every schema slot (`params`, `query`, `input`, `output`) must hold a
|
|
403
|
-
*
|
|
403
|
+
* Every schema slot (`params`, `query`, `input`, `output`) must hold a
|
|
404
|
+
* `@fuzdev/fuz_schema` schema (`assert_validation_schema`), and every
|
|
404
405
|
* `errors` entry an error definition (`rest_error`): anything else throws
|
|
405
|
-
* naming the route and the slot. A
|
|
406
|
+
* naming the route and the slot. A `params` or `query`
|
|
406
407
|
* must be an object schema (`get_schema_entries`), as the path params and
|
|
407
408
|
* query string are an object: one that isn't throws naming the route.
|
|
408
409
|
*
|
|
@@ -414,7 +415,7 @@ const build_rest_error_body = (err) => {
|
|
|
414
415
|
* @param authorize - optional authorization phase; runs after the pre-authorization guards and before the post-authorization guards
|
|
415
416
|
* @param db - used for transaction wrapping and `RouteContext`
|
|
416
417
|
* @mutates `app`
|
|
417
|
-
* @throws Error if two specs share the same `method` + `path` (each combination must be unique), if a schema slot holds a value
|
|
418
|
+
* @throws Error if two specs share the same `method` + `path` (each combination must be unique), if a schema slot holds a value that is no schema or an `errors` entry is not a definition, if any spec violates a cross-axis auth invariant or the actor-acting biconditional, or if a `params` or `query` is not an object schema
|
|
418
419
|
*/
|
|
419
420
|
export const apply_route_specs = (app, specs, resolve_auth_guards, log, db, authorize) => {
|
|
420
421
|
const registered = new Set();
|
|
@@ -473,7 +474,7 @@ export const apply_route_specs = (app, specs, resolve_auth_guards, log, db, auth
|
|
|
473
474
|
app.on(spec.method, [spec.path], ...content_type_check, ...params_validation, ...query_validation, ...pre_authorization_guards, ...authorization, ...post_authorization_guards, ...input_validation, handler);
|
|
474
475
|
}
|
|
475
476
|
};
|
|
476
|
-
// throws unless every schema slot holds a
|
|
477
|
+
// throws unless every schema slot holds a fuz_schema schema and every
|
|
477
478
|
// `errors` entry is a definition; `params` and `query` may be absent
|
|
478
479
|
const assert_schema_slots = (spec, route_key) => {
|
|
479
480
|
const label = `Route "${route_key}"`;
|
|
@@ -494,10 +495,9 @@ const assert_schema_slots = (spec, route_key) => {
|
|
|
494
495
|
}
|
|
495
496
|
}
|
|
496
497
|
};
|
|
497
|
-
// throws unless a
|
|
498
|
-
// wrappers; a Zod one is a `z.ZodObject` by its type
|
|
498
|
+
// throws unless a `params` / `query` is an object schema under any wrappers
|
|
499
499
|
const assert_object_slot = (schema, slot, route_key) => {
|
|
500
|
-
if (schema === undefined ||
|
|
500
|
+
if (schema === undefined || get_schema_entries(schema))
|
|
501
501
|
return;
|
|
502
502
|
throw new Error(`Route "${route_key}": ${slot} is a @fuzdev/fuz_schema '${schema.kind}' schema, not an object schema`);
|
|
503
503
|
};
|