@fuzdev/fuz_app 0.169.0 → 0.170.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 +17 -19
- package/dist/actions/action_codegen.d.ts +25 -18
- package/dist/actions/action_codegen.d.ts.map +1 -1
- package/dist/actions/action_codegen.js +83 -67
- 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.js +1 -1
- 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/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/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/request_context.js +2 -2
- 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 +29 -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/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_spec.d.ts +33 -36
- package/dist/http/route_spec.d.ts.map +1 -1
- package/dist/http/route_spec.js +21 -22
- package/dist/http/schema_helpers.d.ts +75 -67
- 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 +29 -42
- 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.js +9 -9
- 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_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 +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 -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 +150 -145
- 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
|
@@ -280,40 +280,40 @@ export declare const to_error_schemas: (defs: Iterable<RestErrorDef>) => ErrorSc
|
|
|
280
280
|
export declare const REST_INVALID_REQUEST_BODY: RestErrorDef<400, "invalid_request_body", {
|
|
281
281
|
readonly issues: Schema<({
|
|
282
282
|
kind: string;
|
|
283
|
-
message: string;
|
|
284
283
|
path: (string | number)[];
|
|
285
284
|
expected: string;
|
|
286
285
|
received: string;
|
|
286
|
+
message: string;
|
|
287
287
|
} & Record<string, unknown>)[] | undefined, ({
|
|
288
288
|
kind: string;
|
|
289
|
-
message: string;
|
|
290
289
|
path: (string | number)[];
|
|
291
290
|
expected: string;
|
|
292
291
|
received: string;
|
|
292
|
+
message: string;
|
|
293
293
|
} & Record<string, unknown>)[] | undefined, "optional", import("@fuzdev/fuz_schema/schema.ts").SchemaWrapperDef<Schema<({
|
|
294
294
|
kind: string;
|
|
295
|
-
message: string;
|
|
296
295
|
path: (string | number)[];
|
|
297
296
|
expected: string;
|
|
298
297
|
received: string;
|
|
298
|
+
message: string;
|
|
299
299
|
} & Record<string, unknown>)[], ({
|
|
300
300
|
kind: string;
|
|
301
|
-
message: string;
|
|
302
301
|
path: (string | number)[];
|
|
303
302
|
expected: string;
|
|
304
303
|
received: string;
|
|
304
|
+
message: string;
|
|
305
305
|
} & Record<string, unknown>)[], "array", Schema<{
|
|
306
306
|
kind: string;
|
|
307
|
-
message: string;
|
|
308
307
|
path: (string | number)[];
|
|
309
308
|
expected: string;
|
|
310
309
|
received: string;
|
|
310
|
+
message: string;
|
|
311
311
|
} & Record<string, unknown>, {
|
|
312
312
|
kind: string;
|
|
313
|
-
message: string;
|
|
314
313
|
path: (string | number)[];
|
|
315
314
|
expected: string;
|
|
316
315
|
received: string;
|
|
316
|
+
message: string;
|
|
317
317
|
} & Record<string, unknown>, "loose_object", {
|
|
318
318
|
kind: Schema<string, string, "string", undefined>;
|
|
319
319
|
path: Schema<(string | number)[], (string | number)[], "array", Schema<string | number, string | number, "union", readonly [Schema<string, string, "string", undefined>, Schema<number, number, "number", undefined>]>>;
|
|
@@ -326,40 +326,40 @@ export declare const REST_INVALID_JSON_BODY: RestErrorDef<400, "invalid_json_bod
|
|
|
326
326
|
export declare const REST_INVALID_ROUTE_PARAMS: RestErrorDef<400, "invalid_route_params", {
|
|
327
327
|
readonly issues: Schema<({
|
|
328
328
|
kind: string;
|
|
329
|
-
message: string;
|
|
330
329
|
path: (string | number)[];
|
|
331
330
|
expected: string;
|
|
332
331
|
received: string;
|
|
332
|
+
message: string;
|
|
333
333
|
} & Record<string, unknown>)[] | undefined, ({
|
|
334
334
|
kind: string;
|
|
335
|
-
message: string;
|
|
336
335
|
path: (string | number)[];
|
|
337
336
|
expected: string;
|
|
338
337
|
received: string;
|
|
338
|
+
message: string;
|
|
339
339
|
} & Record<string, unknown>)[] | undefined, "optional", import("@fuzdev/fuz_schema/schema.ts").SchemaWrapperDef<Schema<({
|
|
340
340
|
kind: string;
|
|
341
|
-
message: string;
|
|
342
341
|
path: (string | number)[];
|
|
343
342
|
expected: string;
|
|
344
343
|
received: string;
|
|
344
|
+
message: string;
|
|
345
345
|
} & Record<string, unknown>)[], ({
|
|
346
346
|
kind: string;
|
|
347
|
-
message: string;
|
|
348
347
|
path: (string | number)[];
|
|
349
348
|
expected: string;
|
|
350
349
|
received: string;
|
|
350
|
+
message: string;
|
|
351
351
|
} & Record<string, unknown>)[], "array", Schema<{
|
|
352
352
|
kind: string;
|
|
353
|
-
message: string;
|
|
354
353
|
path: (string | number)[];
|
|
355
354
|
expected: string;
|
|
356
355
|
received: string;
|
|
356
|
+
message: string;
|
|
357
357
|
} & Record<string, unknown>, {
|
|
358
358
|
kind: string;
|
|
359
|
-
message: string;
|
|
360
359
|
path: (string | number)[];
|
|
361
360
|
expected: string;
|
|
362
361
|
received: string;
|
|
362
|
+
message: string;
|
|
363
363
|
} & Record<string, unknown>, "loose_object", {
|
|
364
364
|
kind: Schema<string, string, "string", undefined>;
|
|
365
365
|
path: Schema<(string | number)[], (string | number)[], "array", Schema<string | number, string | number, "union", readonly [Schema<string, string, "string", undefined>, Schema<number, number, "number", undefined>]>>;
|
|
@@ -371,40 +371,40 @@ export declare const REST_INVALID_ROUTE_PARAMS: RestErrorDef<400, "invalid_route
|
|
|
371
371
|
export declare const REST_INVALID_QUERY_PARAMS: RestErrorDef<400, "invalid_query_params", {
|
|
372
372
|
readonly issues: Schema<({
|
|
373
373
|
kind: string;
|
|
374
|
-
message: string;
|
|
375
374
|
path: (string | number)[];
|
|
376
375
|
expected: string;
|
|
377
376
|
received: string;
|
|
377
|
+
message: string;
|
|
378
378
|
} & Record<string, unknown>)[] | undefined, ({
|
|
379
379
|
kind: string;
|
|
380
|
-
message: string;
|
|
381
380
|
path: (string | number)[];
|
|
382
381
|
expected: string;
|
|
383
382
|
received: string;
|
|
383
|
+
message: string;
|
|
384
384
|
} & Record<string, unknown>)[] | undefined, "optional", import("@fuzdev/fuz_schema/schema.ts").SchemaWrapperDef<Schema<({
|
|
385
385
|
kind: string;
|
|
386
|
-
message: string;
|
|
387
386
|
path: (string | number)[];
|
|
388
387
|
expected: string;
|
|
389
388
|
received: string;
|
|
389
|
+
message: string;
|
|
390
390
|
} & Record<string, unknown>)[], ({
|
|
391
391
|
kind: string;
|
|
392
|
-
message: string;
|
|
393
392
|
path: (string | number)[];
|
|
394
393
|
expected: string;
|
|
395
394
|
received: string;
|
|
395
|
+
message: string;
|
|
396
396
|
} & Record<string, unknown>)[], "array", Schema<{
|
|
397
397
|
kind: string;
|
|
398
|
-
message: string;
|
|
399
398
|
path: (string | number)[];
|
|
400
399
|
expected: string;
|
|
401
400
|
received: string;
|
|
401
|
+
message: string;
|
|
402
402
|
} & Record<string, unknown>, {
|
|
403
403
|
kind: string;
|
|
404
|
-
message: string;
|
|
405
404
|
path: (string | number)[];
|
|
406
405
|
expected: string;
|
|
407
406
|
received: string;
|
|
407
|
+
message: string;
|
|
408
408
|
} & Record<string, unknown>, "loose_object", {
|
|
409
409
|
kind: Schema<string, string, "string", undefined>;
|
|
410
410
|
path: Schema<(string | number)[], (string | number)[], "array", Schema<string | number, string | number, "union", readonly [Schema<string, string, "string", undefined>, Schema<number, number, "number", undefined>]>>;
|
|
@@ -183,7 +183,7 @@ export const classify_jsonrpc_message = (json) => {
|
|
|
183
183
|
id,
|
|
184
184
|
error: jsonrpc_error_messages.invalid_request(dev_only(() => {
|
|
185
185
|
const parsed = parse(JsonrpcRequest, frame);
|
|
186
|
-
return { issues: parsed.ok ? [] : to_wire_issues(parsed.issues
|
|
186
|
+
return { issues: parsed.ok ? [] : to_wire_issues(parsed.issues) };
|
|
187
187
|
}))
|
|
188
188
|
};
|
|
189
189
|
};
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
*
|
|
24
24
|
* @module
|
|
25
25
|
*/
|
|
26
|
+
import { type SchemaIssue } from '@fuzdev/fuz_schema/schema.ts';
|
|
26
27
|
import { type RestErrorDef } from './error_schemas.js';
|
|
27
28
|
import type { RouteErrorMap } from './route_errors.js';
|
|
28
|
-
import { type AnyIssue } from '../schema_issues.js';
|
|
29
29
|
/**
|
|
30
30
|
* The errors any route can answer with and none declares: the catch layer's
|
|
31
31
|
* 500 `internal_error` for a generic throw, and a failed pool checkout's 503
|
|
@@ -56,7 +56,7 @@ export type RouteErrorCheck = {
|
|
|
56
56
|
} | {
|
|
57
57
|
ok: false;
|
|
58
58
|
kind: 'schema_mismatch';
|
|
59
|
-
issues: Array<
|
|
59
|
+
issues: Array<SchemaIssue>;
|
|
60
60
|
};
|
|
61
61
|
/**
|
|
62
62
|
* Check a JSON error body against its route's error map.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route_error_check.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/route_error_check.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;
|
|
1
|
+
{"version":3,"file":"route_error_check.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/route_error_check.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAa,KAAK,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAE3E,OAAO,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dev/fuz_schema/schema.ts';
|
|
27
27
|
import { REST_INTERNAL_ERROR, REST_SERVICE_UNAVAILABLE } from './error_schemas.js';
|
|
28
28
|
import { is_jsonrpc_error_response } from './jsonrpc_helpers.js';
|
|
29
|
-
import { parse_any } from '../schema_issues.js';
|
|
30
29
|
/**
|
|
31
30
|
* The errors any route can answer with and none declares: the catch layer's
|
|
32
31
|
* 500 `internal_error` for a generic throw, and a failed pool checkout's 503
|
|
@@ -71,7 +70,7 @@ export const check_route_error = (errors, status, body, jsonrpc) => {
|
|
|
71
70
|
const schema = errors.schemas[status];
|
|
72
71
|
if (!schema)
|
|
73
72
|
return { ok: false, kind: 'undeclared_status' };
|
|
74
|
-
const result =
|
|
73
|
+
const result = parse(schema, body);
|
|
75
74
|
return result.ok ? { ok: true } : { ok: false, kind: 'schema_mismatch', issues: result.issues };
|
|
76
75
|
};
|
|
77
76
|
/**
|
|
@@ -11,12 +11,12 @@
|
|
|
11
11
|
*
|
|
12
12
|
* @module
|
|
13
13
|
*/
|
|
14
|
+
import type { AnySchema } from '@fuzdev/fuz_schema/schema.ts';
|
|
14
15
|
import type { RouteAuth } from './auth_shape.js';
|
|
15
16
|
import type { RouteMethod } from './route_spec.js';
|
|
16
17
|
import { type ErrorSchemas, type RestErrorDef } from './error_schemas.js';
|
|
17
18
|
import type { MiddlewareSpec } from './middleware_spec.js';
|
|
18
19
|
import type { RateLimitKey } from '../rate_limiter.js';
|
|
19
|
-
import type { ValidationSchema } from '../schema_issues.js';
|
|
20
20
|
/**
|
|
21
21
|
* A route's error map: every error definition the route can answer with, and
|
|
22
22
|
* the status map they group into. Built by `resolve_route_error_map`, and read by
|
|
@@ -38,9 +38,9 @@ export interface RouteErrorMapSpec {
|
|
|
38
38
|
readonly method: RouteMethod;
|
|
39
39
|
readonly path: string;
|
|
40
40
|
readonly auth: RouteAuth;
|
|
41
|
-
readonly input:
|
|
42
|
-
readonly params?:
|
|
43
|
-
readonly query?:
|
|
41
|
+
readonly input: AnySchema;
|
|
42
|
+
readonly params?: AnySchema;
|
|
43
|
+
readonly query?: AnySchema;
|
|
44
44
|
readonly rate_limit?: RateLimitKey;
|
|
45
45
|
readonly errors?: ReadonlyArray<RestErrorDef>;
|
|
46
46
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route_errors.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/route_errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;
|
|
1
|
+
{"version":3,"file":"route_errors.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/route_errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAE9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAIN,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAG3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC7B;;;;OAIG;IACH,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;IAC3C,gGAAgG;IAChG,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;CAC/B;AAED,4DAA4D;AAC5D,MAAM,WAAW,iBAAiB;IACjC,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC;IAC5B,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC;IAC3B,QAAQ,CAAC,UAAU,CAAC,EAAE,YAAY,CAAC;IACnC,QAAQ,CAAC,MAAM,CAAC,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;CAC9C;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,uBAAuB,GACnC,MAAM,iBAAiB,EACvB,mBAAmB,aAAa,CAAC,IAAI,CAAC,cAAc,EAAE,MAAM,GAAG,YAAY,GAAG,QAAQ,CAAC,CAAC,GAAG,IAAI,KAC7F,aAiBF,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,4BAA4B,GACxC,aAAa,aAAa,CAAC,iBAAiB,CAAC,EAC7C,mBAAmB,aAAa,CAAC,IAAI,CAAC,cAAc,EAAE,MAAM,GAAG,YAAY,GAAG,QAAQ,CAAC,CAAC,GAAG,IAAI,KAC7F,GAAG,CAAC,MAAM,EAAE,aAAa,CAM3B,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,mBAAmB,GAC/B,kBAAkB,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,GAAG,IAAI,GAAG,SAAS,EACvE,MAAM,iBAAiB,KACrB,aAQF,CAAC"}
|
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A route's error map: every error definition it can answer with — derived
|
|
3
|
-
* from its slots (`derive_route_errors`), declared by each middleware layer
|
|
4
|
-
* that runs on it, and its own `errors` — and the status map they group into.
|
|
5
|
-
*
|
|
6
|
-
* Built once per app (`resolve_app_route_error_maps`, carried as
|
|
7
|
-
* `AppSurfaceSpec.route_error_maps`) and read by every reader of a route's
|
|
8
|
-
* declared errors: the surface, the DEV error check, the test helpers, error
|
|
9
|
-
* coverage, and the attack-surface suite. The maps are keyed `METHOD path`
|
|
10
|
-
* (`format_route_key`).
|
|
11
|
-
*
|
|
12
|
-
* @module
|
|
13
|
-
*/
|
|
14
1
|
import { dedupe_rest_errors, derive_route_errors, to_error_schemas } from './error_schemas.js';
|
|
15
2
|
import { is_null_schema, middleware_spec_applies } from './schema_helpers.js';
|
|
16
3
|
import { format_route_key } from './surface_query.js';
|
|
@@ -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
|
/**
|
|
@@ -339,8 +336,8 @@ export declare const to_route_response: (c: Context, result: RouteResult) => Res
|
|
|
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,M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}
|
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,7 @@ 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
32
|
/**
|
|
33
33
|
* Define a route: its handler is checked against the route's `output`,
|
|
34
34
|
* `errors`, `auth`, and `rate_limit` (`TypedRouteHandler`), and the spec is
|
|
@@ -151,11 +151,11 @@ const create_input_validation = (input_schema, method) => {
|
|
|
151
151
|
if (typeof body !== 'object' || body === null || Array.isArray(body)) {
|
|
152
152
|
return c.json({ error: ERROR_INVALID_JSON_BODY }, 400);
|
|
153
153
|
}
|
|
154
|
-
const result =
|
|
154
|
+
const result = parse(input_schema, body);
|
|
155
155
|
if (!result.ok) {
|
|
156
156
|
return c.json({
|
|
157
157
|
error: ERROR_INVALID_REQUEST_BODY,
|
|
158
|
-
issues: dev_only(() => to_wire_issues(result.issues
|
|
158
|
+
issues: dev_only(() => to_wire_issues(result.issues))
|
|
159
159
|
}, 400);
|
|
160
160
|
}
|
|
161
161
|
c.set('validated_input', result.value);
|
|
@@ -177,11 +177,11 @@ const create_params_validation = (params_schema) => {
|
|
|
177
177
|
return [];
|
|
178
178
|
const validate = async (c, next) => {
|
|
179
179
|
const raw_params = c.req.param();
|
|
180
|
-
const result =
|
|
180
|
+
const result = parse(params_schema, raw_params);
|
|
181
181
|
if (!result.ok) {
|
|
182
182
|
return c.json({
|
|
183
183
|
error: ERROR_INVALID_ROUTE_PARAMS,
|
|
184
|
-
issues: dev_only(() => to_wire_issues(result.issues
|
|
184
|
+
issues: dev_only(() => to_wire_issues(result.issues))
|
|
185
185
|
}, 400);
|
|
186
186
|
}
|
|
187
187
|
c.set('validated_params', result.value);
|
|
@@ -203,11 +203,11 @@ const create_query_validation = (query_schema) => {
|
|
|
203
203
|
return [];
|
|
204
204
|
const validate = async (c, next) => {
|
|
205
205
|
const raw_query = c.req.query();
|
|
206
|
-
const result =
|
|
206
|
+
const result = parse(query_schema, raw_query);
|
|
207
207
|
if (!result.ok) {
|
|
208
208
|
return c.json({
|
|
209
209
|
error: ERROR_INVALID_QUERY_PARAMS,
|
|
210
|
-
issues: dev_only(() => to_wire_issues(result.issues
|
|
210
|
+
issues: dev_only(() => to_wire_issues(result.issues))
|
|
211
211
|
}, 400);
|
|
212
212
|
}
|
|
213
213
|
c.set('validated_query', result.value);
|
|
@@ -223,8 +223,8 @@ const create_query_validation = (query_schema) => {
|
|
|
223
223
|
* never throws. Non-2xx responses are the DEV error check's
|
|
224
224
|
* (`create_dev_route_error_check`), which `create_app_server` mounts
|
|
225
225
|
* outermost so it sees what every layer answers. Non-JSON responses (SSE,
|
|
226
|
-
* binary) are skipped. The schema is
|
|
227
|
-
*
|
|
226
|
+
* binary) are skipped. The schema is parsed with `parse`; the log carries
|
|
227
|
+
* its issues. In production,
|
|
228
228
|
* returns the handler unchanged.
|
|
229
229
|
*/
|
|
230
230
|
const wrap_output_validation = (handler, output_schema, log) => {
|
|
@@ -247,7 +247,7 @@ const wrap_output_validation = (handler, output_schema, log) => {
|
|
|
247
247
|
// clone() or json() failed on a response claiming application/json
|
|
248
248
|
return response;
|
|
249
249
|
}
|
|
250
|
-
const result =
|
|
250
|
+
const result = parse(output_schema, body);
|
|
251
251
|
if (!result.ok) {
|
|
252
252
|
log.error(`Output schema mismatch: ${c.req.method} ${c.req.path}`, result.issues);
|
|
253
253
|
}
|
|
@@ -399,10 +399,10 @@ const build_rest_error_body = (err) => {
|
|
|
399
399
|
* registries (`compile_action_registry`) share the same helper with
|
|
400
400
|
* `input` only — `ActionSpec` has no `query` shape.
|
|
401
401
|
*
|
|
402
|
-
* Every schema slot (`params`, `query`, `input`, `output`) must hold a
|
|
403
|
-
*
|
|
402
|
+
* Every schema slot (`params`, `query`, `input`, `output`) must hold a
|
|
403
|
+
* `@fuzdev/fuz_schema` schema (`assert_validation_schema`), and every
|
|
404
404
|
* `errors` entry an error definition (`rest_error`): anything else throws
|
|
405
|
-
* naming the route and the slot. A
|
|
405
|
+
* naming the route and the slot. A `params` or `query`
|
|
406
406
|
* must be an object schema (`get_schema_entries`), as the path params and
|
|
407
407
|
* query string are an object: one that isn't throws naming the route.
|
|
408
408
|
*
|
|
@@ -414,7 +414,7 @@ const build_rest_error_body = (err) => {
|
|
|
414
414
|
* @param authorize - optional authorization phase; runs after the pre-authorization guards and before the post-authorization guards
|
|
415
415
|
* @param db - used for transaction wrapping and `RouteContext`
|
|
416
416
|
* @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
|
|
417
|
+
* @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
418
|
*/
|
|
419
419
|
export const apply_route_specs = (app, specs, resolve_auth_guards, log, db, authorize) => {
|
|
420
420
|
const registered = new Set();
|
|
@@ -473,7 +473,7 @@ export const apply_route_specs = (app, specs, resolve_auth_guards, log, db, auth
|
|
|
473
473
|
app.on(spec.method, [spec.path], ...content_type_check, ...params_validation, ...query_validation, ...pre_authorization_guards, ...authorization, ...post_authorization_guards, ...input_validation, handler);
|
|
474
474
|
}
|
|
475
475
|
};
|
|
476
|
-
// throws unless every schema slot holds a
|
|
476
|
+
// throws unless every schema slot holds a fuz_schema schema and every
|
|
477
477
|
// `errors` entry is a definition; `params` and `query` may be absent
|
|
478
478
|
const assert_schema_slots = (spec, route_key) => {
|
|
479
479
|
const label = `Route "${route_key}"`;
|
|
@@ -494,10 +494,9 @@ const assert_schema_slots = (spec, route_key) => {
|
|
|
494
494
|
}
|
|
495
495
|
}
|
|
496
496
|
};
|
|
497
|
-
// throws unless a
|
|
498
|
-
// wrappers; a Zod one is a `z.ZodObject` by its type
|
|
497
|
+
// throws unless a `params` / `query` is an object schema under any wrappers
|
|
499
498
|
const assert_object_slot = (schema, slot, route_key) => {
|
|
500
|
-
if (schema === undefined ||
|
|
499
|
+
if (schema === undefined || get_schema_entries(schema))
|
|
501
500
|
return;
|
|
502
501
|
throw new Error(`Route "${route_key}": ${slot} is a @fuzdev/fuz_schema '${schema.kind}' schema, not an object schema`);
|
|
503
502
|
};
|