@dads-framework/http 0.0.0-stage → 0.2.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/LICENSE.md +21 -0
- package/README.md +295 -2
- package/dist/http.tsbuildinfo +1 -0
- package/dist/index.d.ts +56 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/create-http-app.d.ts +108 -0
- package/dist/lib/create-http-app.d.ts.map +1 -0
- package/dist/lib/create-http-app.js +181 -0
- package/dist/lib/create-http-app.js.map +1 -0
- package/dist/lib/http-errors.d.ts +52 -0
- package/dist/lib/http-errors.d.ts.map +1 -0
- package/dist/lib/http-errors.js +66 -0
- package/dist/lib/http-errors.js.map +1 -0
- package/dist/lib/mcp/mcp-tool.d.ts +94 -0
- package/dist/lib/mcp/mcp-tool.d.ts.map +1 -0
- package/dist/lib/mcp/mcp-tool.js +11 -0
- package/dist/lib/mcp/mcp-tool.js.map +1 -0
- package/dist/lib/object-value.d.ts +3 -0
- package/dist/lib/object-value.d.ts.map +1 -0
- package/dist/lib/object-value.js +5 -0
- package/dist/lib/object-value.js.map +1 -0
- package/dist/lib/openapi/build-document.d.ts +27 -0
- package/dist/lib/openapi/build-document.d.ts.map +1 -0
- package/dist/lib/openapi/build-document.js +192 -0
- package/dist/lib/openapi/build-document.js.map +1 -0
- package/dist/lib/openapi/logic/add-discriminators.d.ts +16 -0
- package/dist/lib/openapi/logic/add-discriminators.d.ts.map +1 -0
- package/dist/lib/openapi/logic/add-discriminators.js +235 -0
- package/dist/lib/openapi/logic/add-discriminators.js.map +1 -0
- package/dist/lib/openapi/logic/by-code-point.d.ts +2 -0
- package/dist/lib/openapi/logic/by-code-point.d.ts.map +1 -0
- package/dist/lib/openapi/logic/by-code-point.js +6 -0
- package/dist/lib/openapi/logic/by-code-point.js.map +1 -0
- package/dist/lib/openapi/logic/capitalize-initial.d.ts +2 -0
- package/dist/lib/openapi/logic/capitalize-initial.d.ts.map +1 -0
- package/dist/lib/openapi/logic/capitalize-initial.js +4 -0
- package/dist/lib/openapi/logic/capitalize-initial.js.map +1 -0
- package/dist/lib/openapi/logic/document-record.d.ts +5 -0
- package/dist/lib/openapi/logic/document-record.d.ts.map +1 -0
- package/dist/lib/openapi/logic/document-record.js +14 -0
- package/dist/lib/openapi/logic/document-record.js.map +1 -0
- package/dist/lib/openapi/logic/list-order.d.ts +23 -0
- package/dist/lib/openapi/logic/list-order.d.ts.map +1 -0
- package/dist/lib/openapi/logic/list-order.js +102 -0
- package/dist/lib/openapi/logic/list-order.js.map +1 -0
- package/dist/lib/openapi/logic/open-response-objects.d.ts +14 -0
- package/dist/lib/openapi/logic/open-response-objects.d.ts.map +1 -0
- package/dist/lib/openapi/logic/open-response-objects.js +130 -0
- package/dist/lib/openapi/logic/open-response-objects.js.map +1 -0
- package/dist/lib/openapi/logic/openapi-parts.d.ts +37 -0
- package/dist/lib/openapi/logic/openapi-parts.d.ts.map +1 -0
- package/dist/lib/openapi/logic/openapi-parts.js +243 -0
- package/dist/lib/openapi/logic/openapi-parts.js.map +1 -0
- package/dist/lib/openapi/logic/schema-components.d.ts +5 -0
- package/dist/lib/openapi/logic/schema-components.d.ts.map +1 -0
- package/dist/lib/openapi/logic/schema-components.js +47 -0
- package/dist/lib/openapi/logic/schema-components.js.map +1 -0
- package/dist/lib/request-log/authorization-warning-faults.d.ts +30 -0
- package/dist/lib/request-log/authorization-warning-faults.d.ts.map +1 -0
- package/dist/lib/request-log/authorization-warning-faults.js +35 -0
- package/dist/lib/request-log/authorization-warning-faults.js.map +1 -0
- package/dist/lib/request-log/capture-request-record.d.ts +50 -0
- package/dist/lib/request-log/capture-request-record.d.ts.map +1 -0
- package/dist/lib/request-log/capture-request-record.js +132 -0
- package/dist/lib/request-log/capture-request-record.js.map +1 -0
- package/dist/lib/request-log/request-log-sink.d.ts +31 -0
- package/dist/lib/request-log/request-log-sink.d.ts.map +1 -0
- package/dist/lib/request-log/request-log-sink.js +26 -0
- package/dist/lib/request-log/request-log-sink.js.map +1 -0
- package/dist/lib/request-log/request-outcome.d.ts +53 -0
- package/dist/lib/request-log/request-outcome.d.ts.map +1 -0
- package/dist/lib/request-log/request-outcome.js +96 -0
- package/dist/lib/request-log/request-outcome.js.map +1 -0
- package/dist/lib/request-log/request-record.d.ts +114 -0
- package/dist/lib/request-log/request-record.d.ts.map +1 -0
- package/dist/lib/request-log/request-record.js +231 -0
- package/dist/lib/request-log/request-record.js.map +1 -0
- package/dist/lib/request-pipeline/assert-no-app-site-serving.d.ts +8 -0
- package/dist/lib/request-pipeline/assert-no-app-site-serving.d.ts.map +1 -0
- package/dist/lib/request-pipeline/assert-no-app-site-serving.js +15 -0
- package/dist/lib/request-pipeline/assert-no-app-site-serving.js.map +1 -0
- package/dist/lib/request-pipeline/carry-audit-actor.d.ts +71 -0
- package/dist/lib/request-pipeline/carry-audit-actor.d.ts.map +1 -0
- package/dist/lib/request-pipeline/carry-audit-actor.js +79 -0
- package/dist/lib/request-pipeline/carry-audit-actor.js.map +1 -0
- package/dist/lib/request-pipeline/carry-authorization-consistency.d.ts +4 -0
- package/dist/lib/request-pipeline/carry-authorization-consistency.d.ts.map +1 -0
- package/dist/lib/request-pipeline/carry-authorization-consistency.js +21 -0
- package/dist/lib/request-pipeline/carry-authorization-consistency.js.map +1 -0
- package/dist/lib/request-pipeline/enforce-access.d.ts +146 -0
- package/dist/lib/request-pipeline/enforce-access.d.ts.map +1 -0
- package/dist/lib/request-pipeline/enforce-access.js +238 -0
- package/dist/lib/request-pipeline/enforce-access.js.map +1 -0
- package/dist/lib/request-pipeline/enforce-scope.d.ts +23 -0
- package/dist/lib/request-pipeline/enforce-scope.d.ts.map +1 -0
- package/dist/lib/request-pipeline/enforce-scope.js +58 -0
- package/dist/lib/request-pipeline/enforce-scope.js.map +1 -0
- package/dist/lib/request-pipeline/envelope.d.ts +17 -0
- package/dist/lib/request-pipeline/envelope.d.ts.map +1 -0
- package/dist/lib/request-pipeline/envelope.js +4 -0
- package/dist/lib/request-pipeline/envelope.js.map +1 -0
- package/dist/lib/request-pipeline/error-handler.d.ts +14 -0
- package/dist/lib/request-pipeline/error-handler.d.ts.map +1 -0
- package/dist/lib/request-pipeline/error-handler.js +138 -0
- package/dist/lib/request-pipeline/error-handler.js.map +1 -0
- package/dist/lib/request-pipeline/feature-state-preview.d.ts +79 -0
- package/dist/lib/request-pipeline/feature-state-preview.d.ts.map +1 -0
- package/dist/lib/request-pipeline/feature-state-preview.js +77 -0
- package/dist/lib/request-pipeline/feature-state-preview.js.map +1 -0
- package/dist/lib/request-pipeline/feature-state.d.ts +70 -0
- package/dist/lib/request-pipeline/feature-state.d.ts.map +1 -0
- package/dist/lib/request-pipeline/feature-state.js +46 -0
- package/dist/lib/request-pipeline/feature-state.js.map +1 -0
- package/dist/lib/request-pipeline/logic/is-write-method.d.ts +2 -0
- package/dist/lib/request-pipeline/logic/is-write-method.d.ts.map +1 -0
- package/dist/lib/request-pipeline/logic/is-write-method.js +7 -0
- package/dist/lib/request-pipeline/logic/is-write-method.js.map +1 -0
- package/dist/lib/request-pipeline/logic/read-request-source.d.ts +19 -0
- package/dist/lib/request-pipeline/logic/read-request-source.d.ts.map +1 -0
- package/dist/lib/request-pipeline/logic/read-request-source.js +40 -0
- package/dist/lib/request-pipeline/logic/read-request-source.js.map +1 -0
- package/dist/lib/request-pipeline/logic/single-request-header.d.ts +3 -0
- package/dist/lib/request-pipeline/logic/single-request-header.d.ts.map +1 -0
- package/dist/lib/request-pipeline/logic/single-request-header.js +16 -0
- package/dist/lib/request-pipeline/logic/single-request-header.js.map +1 -0
- package/dist/lib/request-pipeline/machine-credential-access.d.ts +19 -0
- package/dist/lib/request-pipeline/machine-credential-access.d.ts.map +1 -0
- package/dist/lib/request-pipeline/machine-credential-access.js +28 -0
- package/dist/lib/request-pipeline/machine-credential-access.js.map +1 -0
- package/dist/lib/request-pipeline/rate-limit.d.ts +15 -0
- package/dist/lib/request-pipeline/rate-limit.d.ts.map +1 -0
- package/dist/lib/request-pipeline/rate-limit.js +40 -0
- package/dist/lib/request-pipeline/rate-limit.js.map +1 -0
- package/dist/lib/request-pipeline/raw-route-byte-body.d.ts +19 -0
- package/dist/lib/request-pipeline/raw-route-byte-body.d.ts.map +1 -0
- package/dist/lib/request-pipeline/raw-route-byte-body.js +26 -0
- package/dist/lib/request-pipeline/raw-route-byte-body.js.map +1 -0
- package/dist/lib/request-pipeline/refuse-visible-record-list.d.ts +16 -0
- package/dist/lib/request-pipeline/refuse-visible-record-list.d.ts.map +1 -0
- package/dist/lib/request-pipeline/refuse-visible-record-list.js +33 -0
- package/dist/lib/request-pipeline/refuse-visible-record-list.js.map +1 -0
- package/dist/lib/request-pipeline/register-routes.d.ts +50 -0
- package/dist/lib/request-pipeline/register-routes.d.ts.map +1 -0
- package/dist/lib/request-pipeline/register-routes.js +217 -0
- package/dist/lib/request-pipeline/register-routes.js.map +1 -0
- package/dist/lib/request-pipeline/request-id.d.ts +22 -0
- package/dist/lib/request-pipeline/request-id.d.ts.map +1 -0
- package/dist/lib/request-pipeline/request-id.js +26 -0
- package/dist/lib/request-pipeline/request-id.js.map +1 -0
- package/dist/lib/request-pipeline/request-language-response.d.ts +14 -0
- package/dist/lib/request-pipeline/request-language-response.d.ts.map +1 -0
- package/dist/lib/request-pipeline/request-language-response.js +47 -0
- package/dist/lib/request-pipeline/request-language-response.js.map +1 -0
- package/dist/lib/request-pipeline/request-locale.d.ts +38 -0
- package/dist/lib/request-pipeline/request-locale.d.ts.map +1 -0
- package/dist/lib/request-pipeline/request-locale.js +102 -0
- package/dist/lib/request-pipeline/request-locale.js.map +1 -0
- package/dist/lib/request-pipeline/request-origin.d.ts +17 -0
- package/dist/lib/request-pipeline/request-origin.d.ts.map +1 -0
- package/dist/lib/request-pipeline/request-origin.js +38 -0
- package/dist/lib/request-pipeline/request-origin.js.map +1 -0
- package/dist/lib/request-pipeline/request-trace.d.ts +10 -0
- package/dist/lib/request-pipeline/request-trace.d.ts.map +1 -0
- package/dist/lib/request-pipeline/request-trace.js +24 -0
- package/dist/lib/request-pipeline/request-trace.js.map +1 -0
- package/dist/lib/request-pipeline/route-rate-limit.d.ts +19 -0
- package/dist/lib/request-pipeline/route-rate-limit.d.ts.map +1 -0
- package/dist/lib/request-pipeline/route-rate-limit.js +32 -0
- package/dist/lib/request-pipeline/route-rate-limit.js.map +1 -0
- package/dist/lib/request-pipeline/run-route.d.ts +9 -0
- package/dist/lib/request-pipeline/run-route.d.ts.map +1 -0
- package/dist/lib/request-pipeline/run-route.js +42 -0
- package/dist/lib/request-pipeline/run-route.js.map +1 -0
- package/dist/lib/request-pipeline/with-deadline.d.ts +12 -0
- package/dist/lib/request-pipeline/with-deadline.d.ts.map +1 -0
- package/dist/lib/request-pipeline/with-deadline.js +55 -0
- package/dist/lib/request-pipeline/with-deadline.js.map +1 -0
- package/dist/lib/route/access.d.ts +143 -0
- package/dist/lib/route/access.d.ts.map +1 -0
- package/dist/lib/route/access.js +97 -0
- package/dist/lib/route/access.js.map +1 -0
- package/dist/lib/route/capabilities.d.ts +100 -0
- package/dist/lib/route/capabilities.d.ts.map +1 -0
- package/dist/lib/route/capabilities.js +42 -0
- package/dist/lib/route/capabilities.js.map +1 -0
- package/dist/lib/route/define-raw-route.d.ts +81 -0
- package/dist/lib/route/define-raw-route.d.ts.map +1 -0
- package/dist/lib/route/define-raw-route.js +5 -0
- package/dist/lib/route/define-raw-route.js.map +1 -0
- package/dist/lib/route/delete-route.d.ts +26 -0
- package/dist/lib/route/delete-route.d.ts.map +1 -0
- package/dist/lib/route/delete-route.js +6 -0
- package/dist/lib/route/delete-route.js.map +1 -0
- package/dist/lib/route/get-route.d.ts +43 -0
- package/dist/lib/route/get-route.d.ts.map +1 -0
- package/dist/lib/route/get-route.js +18 -0
- package/dist/lib/route/get-route.js.map +1 -0
- package/dist/lib/route/list-result.d.ts +11 -0
- package/dist/lib/route/list-result.d.ts.map +1 -0
- package/dist/lib/route/list-result.js +8 -0
- package/dist/lib/route/list-result.js.map +1 -0
- package/dist/lib/route/list-route.d.ts +60 -0
- package/dist/lib/route/list-route.d.ts.map +1 -0
- package/dist/lib/route/list-route.js +68 -0
- package/dist/lib/route/list-route.js.map +1 -0
- package/dist/lib/route/patch-route.d.ts +27 -0
- package/dist/lib/route/patch-route.d.ts.map +1 -0
- package/dist/lib/route/patch-route.js +8 -0
- package/dist/lib/route/patch-route.js.map +1 -0
- package/dist/lib/route/post-no-content-route.d.ts +18 -0
- package/dist/lib/route/post-no-content-route.d.ts.map +1 -0
- package/dist/lib/route/post-no-content-route.js +8 -0
- package/dist/lib/route/post-no-content-route.js.map +1 -0
- package/dist/lib/route/post-route.d.ts +34 -0
- package/dist/lib/route/post-route.d.ts.map +1 -0
- package/dist/lib/route/post-route.js +23 -0
- package/dist/lib/route/post-route.js.map +1 -0
- package/dist/lib/route/route-definition.d.ts +224 -0
- package/dist/lib/route/route-definition.d.ts.map +1 -0
- package/dist/lib/route/route-definition.js +32 -0
- package/dist/lib/route/route-definition.js.map +1 -0
- package/dist/lib/route/route-execution.d.ts +47 -0
- package/dist/lib/route/route-execution.d.ts.map +1 -0
- package/dist/lib/route/route-execution.js +162 -0
- package/dist/lib/route/route-execution.js.map +1 -0
- package/dist/lib/route/route-group.d.ts +21 -0
- package/dist/lib/route/route-group.d.ts.map +1 -0
- package/dist/lib/route/route-group.js +18 -0
- package/dist/lib/route/route-group.js.map +1 -0
- package/dist/lib/route/route-guards.test-support.d.ts +2 -0
- package/dist/lib/route/route-guards.test-support.d.ts.map +1 -0
- package/dist/lib/route/route-guards.test-support.js +2 -0
- package/dist/lib/route/route-guards.test-support.js.map +1 -0
- package/dist/lib/route/sse-route.d.ts +54 -0
- package/dist/lib/route/sse-route.d.ts.map +1 -0
- package/dist/lib/route/sse-route.js +63 -0
- package/dist/lib/route/sse-route.js.map +1 -0
- package/dist/lib/route/web-socket-route.d.ts +45 -0
- package/dist/lib/route/web-socket-route.d.ts.map +1 -0
- package/dist/lib/route/web-socket-route.js +180 -0
- package/dist/lib/route/web-socket-route.js.map +1 -0
- package/dist/lib/route-catalog/route-catalog-parts.d.ts +27 -0
- package/dist/lib/route-catalog/route-catalog-parts.d.ts.map +1 -0
- package/dist/lib/route-catalog/route-catalog-parts.js +87 -0
- package/dist/lib/route-catalog/route-catalog-parts.js.map +1 -0
- package/dist/protocol-mounts/index.d.ts +19 -0
- package/dist/protocol-mounts/index.d.ts.map +1 -0
- package/dist/protocol-mounts/index.js +19 -0
- package/dist/protocol-mounts/index.js.map +1 -0
- package/dist/protocol-mounts/lib/mcp/json-rpc.d.ts +54 -0
- package/dist/protocol-mounts/lib/mcp/json-rpc.d.ts.map +1 -0
- package/dist/protocol-mounts/lib/mcp/json-rpc.js +53 -0
- package/dist/protocol-mounts/lib/mcp/json-rpc.js.map +1 -0
- package/dist/protocol-mounts/lib/mcp/mcp-endpoint.d.ts +31 -0
- package/dist/protocol-mounts/lib/mcp/mcp-endpoint.d.ts.map +1 -0
- package/dist/protocol-mounts/lib/mcp/mcp-endpoint.js +179 -0
- package/dist/protocol-mounts/lib/mcp/mcp-endpoint.js.map +1 -0
- package/dist/protocol-mounts/lib/mcp/mcp-methods.d.ts +68 -0
- package/dist/protocol-mounts/lib/mcp/mcp-methods.d.ts.map +1 -0
- package/dist/protocol-mounts/lib/mcp/mcp-methods.js +201 -0
- package/dist/protocol-mounts/lib/mcp/mcp-methods.js.map +1 -0
- package/dist/protocol-mounts/lib/mcp/protected-resource-metadata.d.ts +18 -0
- package/dist/protocol-mounts/lib/mcp/protected-resource-metadata.d.ts.map +1 -0
- package/dist/protocol-mounts/lib/mcp/protected-resource-metadata.js +34 -0
- package/dist/protocol-mounts/lib/mcp/protected-resource-metadata.js.map +1 -0
- package/dist/protocol-mounts/lib/protocol-mount/mount-fetch-handler.d.ts +57 -0
- package/dist/protocol-mounts/lib/protocol-mount/mount-fetch-handler.d.ts.map +1 -0
- package/dist/protocol-mounts/lib/protocol-mount/mount-fetch-handler.js +100 -0
- package/dist/protocol-mounts/lib/protocol-mount/mount-fetch-handler.js.map +1 -0
- package/dist/protocol-mounts/lib/protocol-mount/to-web-request.d.ts +14 -0
- package/dist/protocol-mounts/lib/protocol-mount/to-web-request.d.ts.map +1 -0
- package/dist/protocol-mounts/lib/protocol-mount/to-web-request.js +60 -0
- package/dist/protocol-mounts/lib/protocol-mount/to-web-request.js.map +1 -0
- package/dist/testing/build-test-app.d.ts +47 -0
- package/dist/testing/build-test-app.d.ts.map +1 -0
- package/dist/testing/build-test-app.js +79 -0
- package/dist/testing/build-test-app.js.map +1 -0
- package/dist/testing/index.d.ts +3 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +3 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/parse-inject-response.d.ts +32 -0
- package/dist/testing/parse-inject-response.d.ts.map +1 -0
- package/dist/testing/parse-inject-response.js +39 -0
- package/dist/testing/parse-inject-response.js.map +1 -0
- package/package.json +55 -4
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Route capabilities — the kit's answer to middleware (design locked with
|
|
3
|
+
* Bryton, 2026-07-09): NAMED, TYPED fields instead of anonymous hook
|
|
4
|
+
* chains. Every capability is declared data, visible on the route, resolved
|
|
5
|
+
* through a three-rung ladder:
|
|
6
|
+
*
|
|
7
|
+
* route field > group capabilities > app default (registerRoutes)
|
|
8
|
+
*
|
|
9
|
+
* "What applies to this route" is answerable by reading at most three named
|
|
10
|
+
* places. Capabilities grow here BY NEED, each with an engine and tests in
|
|
11
|
+
* the kit — never as user-supplied functions.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* route > group > app, field by field, except `cloudOnly`: when a more
|
|
15
|
+
* specific rung than the reason's overrides `site` with another label, the
|
|
16
|
+
* reason explains a label the route no longer has, so it is dropped. A rung
|
|
17
|
+
* that repeats `cloud_only` keeps the reason.
|
|
18
|
+
*/
|
|
19
|
+
export function resolveCapabilities(app, group, route) {
|
|
20
|
+
const merged = { ...app, ...group, ...route };
|
|
21
|
+
const rungs = [app, group, route];
|
|
22
|
+
const siteRung = lastRungSetting(rungs, (rung) => rung.site !== undefined);
|
|
23
|
+
const reasonRung = lastRungSetting(rungs, (rung) => rung.cloudOnly !== undefined);
|
|
24
|
+
const labelOverridden = reasonRung < siteRung && merged.site !== "cloud_only";
|
|
25
|
+
return labelOverridden ? withoutCloudOnlyLabel(merged) : merged;
|
|
26
|
+
}
|
|
27
|
+
/** The capabilities with the cloud-only reason removed, not set to undefined. */
|
|
28
|
+
function withoutCloudOnlyLabel(capabilities) {
|
|
29
|
+
const copy = { ...capabilities };
|
|
30
|
+
delete copy.cloudOnly;
|
|
31
|
+
return copy;
|
|
32
|
+
}
|
|
33
|
+
/** The index of the most specific rung for which `sets` holds; -1 for none. */
|
|
34
|
+
function lastRungSetting(rungs, sets) {
|
|
35
|
+
let found = -1;
|
|
36
|
+
rungs.forEach((rung, index) => {
|
|
37
|
+
if (rung !== undefined && sets(rung))
|
|
38
|
+
found = index;
|
|
39
|
+
});
|
|
40
|
+
return found;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=capabilities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capabilities.js","sourceRoot":"","sources":["../../../src/lib/route/capabilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AA4FH;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CACjC,GAAkC,EAClC,KAAoC,EACpC,KAAoC;IAEpC,MAAM,MAAM,GAAsB,EAAE,GAAG,GAAG,EAAE,GAAG,KAAK,EAAE,GAAG,KAAK,EAAE,CAAC;IACjE,MAAM,KAAK,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IAClC,MAAM,QAAQ,GAAG,eAAe,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;IAC3E,MAAM,UAAU,GAAG,eAAe,CAChC,KAAK,EACL,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,KAAK,SAAS,CACvC,CAAC;IACF,MAAM,eAAe,GAAG,UAAU,GAAG,QAAQ,IAAI,MAAM,CAAC,IAAI,KAAK,YAAY,CAAC;IAC9E,OAAO,eAAe,CAAC,CAAC,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;AAClE,CAAC;AAED,iFAAiF;AACjF,SAAS,qBAAqB,CAC5B,YAA+B;IAE/B,MAAM,IAAI,GAAG,EAAE,GAAG,YAAY,EAAE,CAAC;IACjC,OAAO,IAAI,CAAC,SAAS,CAAC;IACtB,OAAO,IAAI,CAAC;AACd,CAAC;AAED,+EAA+E;AAC/E,SAAS,eAAe,CACtB,KAAiD,EACjD,IAA0C;IAE1C,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC;IACf,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QAC5B,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,IAAI,CAAC;YAAE,KAAK,GAAG,KAAK,CAAC;IACtD,CAAC,CAAC,CAAC;IACH,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { FastifyReply, FastifyRequest } from "fastify";
|
|
2
|
+
import type { z } from "zod";
|
|
3
|
+
import type { SubjectRef } from "@dads-framework/access/runtime";
|
|
4
|
+
import type { RouteAccess } from "./access.js";
|
|
5
|
+
import type { RouteCapabilities } from "./capabilities.js";
|
|
6
|
+
import type { HttpMethod, RouteLogger } from "./route-definition.js";
|
|
7
|
+
/**
|
|
8
|
+
* The kit's ONE sanctioned escape hatch — for responses the typed verbs
|
|
9
|
+
* cannot express: SSE, streamed downloads, multipart. The bar for using it
|
|
10
|
+
* (docs/architecture/http-edge.md): the kit can't express what you need AND
|
|
11
|
+
* growing the kit was considered first. Raw routes still declare `access`
|
|
12
|
+
* (enforced identically — denied checks are 404, anonymous is 401) and
|
|
13
|
+
* still flow through the error envelope if they throw before streaming.
|
|
14
|
+
*
|
|
15
|
+
* Deliberately NOT under the handler deadline: streams are legitimately
|
|
16
|
+
* long-lived. A raw route owns its own lifetime and backpressure.
|
|
17
|
+
*/
|
|
18
|
+
/** What a raw handler receives — Fastify surfaces on purpose, only here. */
|
|
19
|
+
export type RawRouteContext = {
|
|
20
|
+
readonly request: FastifyRequest;
|
|
21
|
+
readonly reply: FastifyReply;
|
|
22
|
+
readonly subject: SubjectRef | null;
|
|
23
|
+
/** Real account identity for audit and user-owned operations. */
|
|
24
|
+
readonly authenticatedSubject: SubjectRef | null;
|
|
25
|
+
readonly requestId: string;
|
|
26
|
+
readonly log: RouteLogger;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Hand-declared OpenAPI operation body for this route — the one exception
|
|
30
|
+
* to generated-only, marked `x-raw-route: true` in the artifact so contract
|
|
31
|
+
* review can see it.
|
|
32
|
+
*/
|
|
33
|
+
export type RawOpenApiOperation = Record<string, unknown>;
|
|
34
|
+
/**
|
|
35
|
+
* Contract schemas the hand-declared operation points at by `$ref`, keyed by
|
|
36
|
+
* component name. The builder converts them exactly as it converts a typed
|
|
37
|
+
* verb's schemas, so a raw route that answers JSON still documents ONE shape
|
|
38
|
+
* source instead of a hand-written body (docs/architecture/api-documentation.md).
|
|
39
|
+
* Without this, a `$ref` a raw route names is a dangling pointer — nothing else
|
|
40
|
+
* registers it.
|
|
41
|
+
*/
|
|
42
|
+
export type RawOpenApiComponents = Readonly<Record<string, z.ZodType>>;
|
|
43
|
+
export type RawRouteConfig = {
|
|
44
|
+
readonly method: HttpMethod;
|
|
45
|
+
readonly path: string;
|
|
46
|
+
readonly summary: string;
|
|
47
|
+
readonly access: RouteAccess;
|
|
48
|
+
/** Route-rung of the capability ladder (route > group > app). */
|
|
49
|
+
readonly capabilities?: RouteCapabilities;
|
|
50
|
+
/**
|
|
51
|
+
* Maximum request body bytes for this route; omitted retains the
|
|
52
|
+
* application limit. Only a route whose body type the app agreed to
|
|
53
|
+
* receive (`rawBodyContentTypes`, `byteBodyContentTypes`) gets a body at all.
|
|
54
|
+
*/
|
|
55
|
+
readonly bodyLimitBytes?: number;
|
|
56
|
+
/**
|
|
57
|
+
* Receive the body as the exact bytes (a `Buffer`) whatever `Content-Type`
|
|
58
|
+
* the client sent, `application/json` and `text/plain` included: this
|
|
59
|
+
* route's requests are parsed as `application/octet-stream` and the sent
|
|
60
|
+
* type stays readable through `contentTypeSentWithBytes`. For a route that
|
|
61
|
+
* stores a file's bytes as a browser sends them. Still needs the app to
|
|
62
|
+
* name a byte parser (`byteBodyContentTypes`); without one the route
|
|
63
|
+
* answers 415.
|
|
64
|
+
*/
|
|
65
|
+
readonly bodyAsBytes?: boolean;
|
|
66
|
+
readonly openapi: RawOpenApiOperation;
|
|
67
|
+
/** Component schemas the `openapi` block refs; omit for byte-stream routes. */
|
|
68
|
+
readonly openapiComponents?: RawOpenApiComponents;
|
|
69
|
+
readonly handler: (ctx: RawRouteContext) => Promise<void>;
|
|
70
|
+
};
|
|
71
|
+
/** A raw route before grouping — unregistrable until routeGroup stamps it. */
|
|
72
|
+
export type RawRouteBlueprint = RawRouteConfig & {
|
|
73
|
+
readonly kind: "raw-route";
|
|
74
|
+
};
|
|
75
|
+
export type RawRouteDefinition = RawRouteBlueprint & {
|
|
76
|
+
readonly tag: string;
|
|
77
|
+
readonly capabilities: RouteCapabilities;
|
|
78
|
+
};
|
|
79
|
+
/** Declare a raw route. `access` is required — same wall as every verb. */
|
|
80
|
+
export declare function defineRawRoute(config: RawRouteConfig): RawRouteBlueprint;
|
|
81
|
+
//# sourceMappingURL=define-raw-route.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-raw-route.d.ts","sourceRoot":"","sources":["../../../src/lib/route/define-raw-route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EA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G;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC;;;;;;;;OAQG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC;IAC/B,QAAQ,CAAC,OAAO,EAAE,mBAAmB,CAAC;IACtC,+EAA+E;IAC/E,QAAQ,CAAC,iBAAiB,CAAC,EAAE,oBAAoB,CAAC;IAClD,QAAQ,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3D,CAAC;AAEF,8EAA8E;AAC9E,MAAM,MAAM,iBAAiB,GAAG,cAAc,GAAG;IAC/C,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,iBAAiB,GAAG;IACnD,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,YAAY,EAAE,iBAAiB,CAAC;CAC1C,CAAC;AAEF,2EAA2E;AAC3E,wBAAgB,cAAc,CAAC,MAAM,EAAE,cAAc,GAAG,iBAAiB,CAExE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-raw-route.js","sourceRoot":"","sources":["../../../src/lib/route/define-raw-route.ts"],"names":[],"mappings":"AAsFA,2EAA2E;AAC3E,MAAM,UAAU,cAAc,CAAC,MAAsB;IACnD,OAAO,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
import type { SubjectRef } from "@dads-framework/access/runtime";
|
|
3
|
+
import type { PermissionAccess, PublicAccess, RouteAccess, SessionAccess } from "./access.js";
|
|
4
|
+
import { type PathParamsShape, type RouteBlueprint, type RouteHandlerContext, type SchemaOutput, type VerbCommon, type VerbParams } from "./route-definition.js";
|
|
5
|
+
/**
|
|
6
|
+
* DELETE — THE no-content shape: no response schema exists on this config,
|
|
7
|
+
* the handler returns nothing, the kit answers 204 with no body. A DELETE
|
|
8
|
+
* that needs to return data is a kit-growth conversation, not a variant.
|
|
9
|
+
* An optional request `body` is allowed when the resource identity alone is
|
|
10
|
+
* not enough (e.g. revoke a named relation for a subject).
|
|
11
|
+
*/
|
|
12
|
+
export type DeleteRouteConfig<Path extends string, Access extends RouteAccess, Subject, ParamsSchema extends z.ZodType<PathParamsShape<Path>> | undefined, BodySchema extends z.ZodType | undefined = undefined> = VerbCommon<"DELETE", Path, Access> & {
|
|
13
|
+
readonly body?: BodySchema;
|
|
14
|
+
handler(ctx: RouteHandlerContext<SchemaOutput<ParamsSchema>, undefined, SchemaOutput<BodySchema>, Subject>): Promise<void> | void;
|
|
15
|
+
} & VerbParams<Path, ParamsSchema>;
|
|
16
|
+
/** Parsed inputs and subject available to a named DELETE handler module. */
|
|
17
|
+
export type DeleteRouteHandlerContext<Params, Body, Subject> = RouteHandlerContext<Params, undefined, Body, Subject>;
|
|
18
|
+
type DeleteRouteFn = {
|
|
19
|
+
/** Guarded DELETE — the handler's subject is non-null by construction. */
|
|
20
|
+
<Path extends string, Access extends SessionAccess | PermissionAccess, ParamsSchema extends z.ZodType<PathParamsShape<Path>> | undefined = undefined, BodySchema extends z.ZodType | undefined = undefined>(config: DeleteRouteConfig<Path, Access, SubjectRef, ParamsSchema, BodySchema>): RouteBlueprint;
|
|
21
|
+
/** Public DELETE — the handler must deal with a null subject. */
|
|
22
|
+
<Path extends string, Access extends PublicAccess, ParamsSchema extends z.ZodType<PathParamsShape<Path>> | undefined = undefined, BodySchema extends z.ZodType | undefined = undefined>(config: DeleteRouteConfig<Path, Access, SubjectRef | null, ParamsSchema, BodySchema>): RouteBlueprint;
|
|
23
|
+
};
|
|
24
|
+
export declare const deleteRoute: DeleteRouteFn;
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=delete-route.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":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MAAM,SAAS,aAAa,GAAG,gBAAgB,EAC/C,YAAY,SAAS,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,GAAG,SAAS,GAC/D,SAAS,EACX,UAAU,SAAS,CAAC,CAAC,OAAO,GAAG,SAAS,GAAG,SAAS,EAEpD,MAAM,EAAE,iBAAiB,CACvB,IAAI,EACJ,MAAM,EACN,UAAU,EACV,YAAY,EACZ,UAAU,CACX,GACA,cAAc,CAAC;IAClB,iEAAiE;IACjE,CACE,IAAI,SAAS,MAAM,EACnB,MAAM,SAAS,YAAY,EAC3B,YAAY,SAAS,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,GAAG,SAAS,GAC/D,SAAS,EACX,UAAU,SAAS,CAAC,CAAC,OAAO,GAAG,SAAS,GAAG,SAAS,EAEpD,MAAM,EAAE,iBAAiB,CACvB,IAAI,EACJ,MAAM,EACN,UAAU,GAAG,IAAI,EACjB,YAAY,EACZ,UAAU,CACX,GACA,cAAc,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,aAMtB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete-route.js","sourceRoot":"","sources":["../../../src/lib/route/delete-route.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,wBAAwB,EACxB,gBAAgB,GAQjB,MAAM,uBAAuB,CAAC;AAkE/B,MAAM,CAAC,MAAM,WAAW,GAAkB,CACxC,MAAiC,EACjB,EAAE,CAClB,wBAAwB,CAAC;IACvB,GAAG,MAAM;IACT,GAAG,gBAAgB,CAAC,MAAM,EAAE,QAAQ,CAAC;CACtC,CAAC,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
import type { ScopeAnswer, SubjectRef } from "@dads-framework/access/runtime";
|
|
3
|
+
import type { PermissionAccess, PublicAccess, RouteAccess, ScopedAccess, SessionAccess } from "./access.js";
|
|
4
|
+
import { type HandlerResult, type PathParamsShape, type RouteBlueprint, type RouteHandlerContext, type SchemaOutput, type VerbCommon, type VerbParams } from "./route-definition.js";
|
|
5
|
+
/**
|
|
6
|
+
* A getRoute response cannot be an array — collections are `listRoute`
|
|
7
|
+
* (paginated by construction). The tuple brand surfaces in the compile
|
|
8
|
+
* error as the explanation.
|
|
9
|
+
*/
|
|
10
|
+
type NonArrayResponse<S> = S extends z.ZodArray<z.ZodType> ? ["collections use listRoute — getRoute responses cannot be arrays"] : unknown;
|
|
11
|
+
/**
|
|
12
|
+
* GET — a single read. The config has NO `body` key (excess-property
|
|
13
|
+
* compile error) and the response cannot be an array (that is a
|
|
14
|
+
* collection — use `listRoute`). Status is always 200.
|
|
15
|
+
*/
|
|
16
|
+
export type GetRouteConfig<Path extends string, Access extends RouteAccess, Subject, ResponseSchema extends z.ZodType, ParamsSchema extends z.ZodType<PathParamsShape<Path>> | undefined, QuerySchema extends z.ZodType | undefined, MetaSchema extends z.ZodType | undefined, BodySchema extends z.ZodType | undefined, Context extends object = Record<never, never>> = VerbCommon<"GET", Path, Access> & {
|
|
17
|
+
readonly response: ResponseSchema & NonArrayResponse<ResponseSchema>;
|
|
18
|
+
/** Declares `{ data, meta }` responses; shapes the handler's return. */
|
|
19
|
+
readonly meta?: MetaSchema;
|
|
20
|
+
readonly query?: QuerySchema;
|
|
21
|
+
handler(ctx: RouteHandlerContext<SchemaOutput<ParamsSchema>, SchemaOutput<QuerySchema>, SchemaOutput<BodySchema>, Subject> & Context): Promise<HandlerResult<ResponseSchema, MetaSchema>> | HandlerResult<ResponseSchema, MetaSchema>;
|
|
22
|
+
} & VerbParams<Path, ParamsSchema>;
|
|
23
|
+
/** Parsed inputs and subject available to a named GET handler module. */
|
|
24
|
+
export type GetRouteHandlerContext<Params, Query, Subject> = RouteHandlerContext<Params, Query, undefined, Subject>;
|
|
25
|
+
/** Data shape a named GET handler returns before the kit envelopes it. */
|
|
26
|
+
export type GetRouteHandlerResult<ResponseSchema extends z.ZodType, MetaSchema extends z.ZodType | undefined = undefined> = HandlerResult<ResponseSchema, MetaSchema>;
|
|
27
|
+
/**
|
|
28
|
+
* A GET with no path parameters answers a question about a set (desk counts,
|
|
29
|
+
* a summary), so it may be scoped like a list. A GET-one (`/things/:id`)
|
|
30
|
+
* never is: one record is a `requires` check.
|
|
31
|
+
*/
|
|
32
|
+
type GetRouteAccess<Path extends string> = SessionAccess | PermissionAccess | PublicAccess | (Path extends `${string}:${string}` ? never : ScopedAccess);
|
|
33
|
+
type GetRouteSubject<Access extends GetRouteAccess<string>> = Access extends PublicAccess ? SubjectRef | null : SubjectRef;
|
|
34
|
+
type GetRouteContext<Access extends GetRouteAccess<string>> = Access extends ScopedAccess ? {
|
|
35
|
+
readonly scope: ScopeAnswer;
|
|
36
|
+
} : Record<never, never>;
|
|
37
|
+
/**
|
|
38
|
+
* GET subject nullability follows the declared access: guarded handlers get a
|
|
39
|
+
* subject, while public handlers must account for an anonymous request.
|
|
40
|
+
*/
|
|
41
|
+
export declare function getRoute<Path extends string, Access extends GetRouteAccess<Path>, ResponseSchema extends z.ZodType, ParamsSchema extends z.ZodType<PathParamsShape<Path>> | undefined = undefined, QuerySchema extends z.ZodType | undefined = undefined, MetaSchema extends z.ZodType | undefined = undefined, BodySchema extends z.ZodType | undefined = undefined>(config: GetRouteConfig<Path, Access, GetRouteSubject<Access>, ResponseSchema, ParamsSchema, QuerySchema, MetaSchema, BodySchema, GetRouteContext<Access>>): RouteBlueprint;
|
|
42
|
+
export {};
|
|
43
|
+
//# sourceMappingURL=get-route.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-route.d.ts","sourceRoot":"","sources":["../../../src/lib/route/get-route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAE9E,OAAO,KAAK,EAC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C,GAAG,SAAS,GAAG,SAAS,EAC7E,WAAW,SAAS,CAAC,CAAC,OAAO,GAAG,SAAS,GAAG,SAAS,EACrD,UAAU,SAAS,CAAC,CAAC,OAAO,GAAG,SAAS,GAAG,SAAS,EACpD,UAAU,SAAS,CAAC,CAAC,OAAO,GAAG,SAAS,GAAG,SAAS,EAEpD,MAAM,EAAE,cAAc,CACpB,IAAI,EACJ,MAAM,EACN,eAAe,CAAC,MAAM,CAAC,EACvB,cAAc,EACd,YAAY,EACZ,WAAW,EACX,UAAU,EACV,UAAU,EACV,eAAe,CAAC,MAAM,CAAC,CACxB,GACA,cAAc,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { HttpWiringError } from "../http-errors.js";
|
|
2
|
+
import { buildDefinition, resolveVerbRoute, } from "./route-definition.js";
|
|
3
|
+
export function getRoute(config) {
|
|
4
|
+
const resolved = resolveVerbRoute(config, "GET");
|
|
5
|
+
return buildDefinition({
|
|
6
|
+
...config,
|
|
7
|
+
...resolved,
|
|
8
|
+
handler: (ctx) => {
|
|
9
|
+
if (config.access.kind === "scoped" && ctx.scope === undefined) {
|
|
10
|
+
// No answers means no scope to render: refuse rather than answer
|
|
11
|
+
// unscoped. An empty answer is still an answer and reaches the SQL.
|
|
12
|
+
throw new HttpWiringError(`scoped route ${resolved.path} ran without a scope answer`);
|
|
13
|
+
}
|
|
14
|
+
return config.handler(ctx);
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=get-route.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-route.js","sourceRoot":"","sources":["../../../src/lib/route/get-route.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAQpD,OAAO,EACL,eAAe,EACf,gBAAgB,GASjB,MAAM,uBAAuB,CAAC;AAmG/B,MAAM,UAAU,QAAQ,CAAC,MAAwB;IAC/C,MAAM,QAAQ,GAAG,gBAAgB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACjD,OAAO,eAAe,CAAC;QACrB,GAAG,MAAM;QACT,GAAG,QAAQ;QACX,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;YACf,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,QAAQ,IAAI,GAAG,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;gBAC/D,iEAAiE;gBACjE,oEAAoE;gBACpE,MAAM,IAAI,eAAe,CACvB,gBAAgB,QAAQ,CAAC,IAAI,6BAA6B,CAC3D,CAAC;YACJ,CAAC;YACD,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC7B,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** A paged reader result before a route handler maps database rows to API items. */
|
|
2
|
+
export type ListPage<Row> = {
|
|
3
|
+
readonly rows: readonly Row[];
|
|
4
|
+
readonly total: number;
|
|
5
|
+
};
|
|
6
|
+
/** Convert a reader's rows page into the items result required by listRoute. */
|
|
7
|
+
export declare function mapListResult<Row, Item>(page: ListPage<Row>, mapper: (row: Row) => Item): {
|
|
8
|
+
readonly items: readonly Item[];
|
|
9
|
+
readonly total: number;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=list-result.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list-result.d.ts","sourceRoot":"","sources":["../../../src/lib/route/list-result.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,MAAM,MAAM,QAAQ,CAAC,GAAG,IAAI;IAC1B,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,EAAE,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,gFAAgF;AAChF,wBAAgB,aAAa,CAAC,GAAG,EAAE,IAAI,EACrC,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC,EACnB,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,GACzB;IAAE,QAAQ,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAK7D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list-result.js","sourceRoot":"","sources":["../../../src/lib/route/list-result.ts"],"names":[],"mappings":"AAMA,gFAAgF;AAChF,MAAM,UAAU,aAAa,CAC3B,IAAmB,EACnB,MAA0B;IAE1B,OAAO;QACL,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC1C,KAAK,EAAE,IAAI,CAAC,KAAK;KAClB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { ScopeAnswer, SubjectRef } from "@dads-framework/access/runtime";
|
|
3
|
+
import { type PaginationMeta } from "@dads-framework/contract";
|
|
4
|
+
import type { PermissionAccess, PublicAccess, RouteAccess, ScopedAccess, SessionAccess, VisibilityAccess } from "./access.js";
|
|
5
|
+
import { type PathParamsShape, type RouteBlueprint, type RouteHandlerContext, type SchemaOutput, type VerbCommon, type VerbParams } from "./route-definition.js";
|
|
6
|
+
/**
|
|
7
|
+
* LIST — the collection verb (locked with Bryton, 2026-07-09). Pagination
|
|
8
|
+
* is COMPILE-ENFORCED: the query schema's output must carry
|
|
9
|
+
* `page`/`perPage` (extend `paginationQuerySchema`), and the kit assembles
|
|
10
|
+
* the `{ data, meta }` envelope itself — handlers return `{ items, total }`
|
|
11
|
+
* and never echo page/perPage (that ceremony was the old boilerplate).
|
|
12
|
+
* `getRoute` refuses array responses, so a collection cannot dodge this.
|
|
13
|
+
*/
|
|
14
|
+
/** What a list handler returns — the kit builds data + meta from it. */
|
|
15
|
+
export type ListResult<ItemSchema extends z.ZodType> = {
|
|
16
|
+
readonly items: readonly z.input<ItemSchema>[];
|
|
17
|
+
readonly total: number;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* A list's own meta beyond `{ total, page, perPage }`: a route that declares
|
|
21
|
+
* a `meta` schema (extending `paginationMetaSchema`) returns its other
|
|
22
|
+
* fields as `meta`; the kit still fills the page window and total.
|
|
23
|
+
*/
|
|
24
|
+
export type ListMetaSchema = z.ZodType<PaginationMeta>;
|
|
25
|
+
type ListMetaExtra<MetaSchema extends ListMetaSchema | undefined> = MetaSchema extends ListMetaSchema ? {
|
|
26
|
+
readonly meta: Omit<z.input<MetaSchema>, keyof PaginationMeta>;
|
|
27
|
+
} : unknown;
|
|
28
|
+
/** Parsed inputs and subject available to a named list handler module. */
|
|
29
|
+
export type ListRouteHandlerContext<Params, Query, Subject, Context extends object = Record<never, never>> = RouteHandlerContext<Params, Query, undefined, Subject> & Context;
|
|
30
|
+
/** The one result shape a named list handler returns before the kit envelopes it. */
|
|
31
|
+
export type ListRouteHandlerResult<ItemSchema extends z.ZodType> = ListResult<ItemSchema>;
|
|
32
|
+
/** The query must parse to at least `{ page, perPage }`. */
|
|
33
|
+
type PaginatedQuerySchema = z.ZodType<{
|
|
34
|
+
page: number;
|
|
35
|
+
perPage: number;
|
|
36
|
+
}>;
|
|
37
|
+
export type ListRouteConfig<Path extends string, Access extends RouteAccess, Subject, ItemSchema extends z.ZodType, QuerySchema extends PaginatedQuerySchema, ParamsSchema extends z.ZodType<PathParamsShape<Path>> | undefined, BodySchema extends z.ZodType | undefined, Ctx extends object = Record<never, never>, MetaSchema extends ListMetaSchema | undefined = undefined> = VerbCommon<"GET", Path, Access> & {
|
|
38
|
+
/** The ELEMENT schema — the kit wraps it in an array for the wire. */
|
|
39
|
+
readonly item: ItemSchema;
|
|
40
|
+
/** Must extend paginationQuerySchema (page/perPage compile-enforced). */
|
|
41
|
+
readonly query: QuerySchema;
|
|
42
|
+
/** Optional: a meta schema extending `paginationMetaSchema`; the handler returns its extra fields. */
|
|
43
|
+
readonly meta?: MetaSchema;
|
|
44
|
+
readonly handler: (ctx: RouteHandlerContext<SchemaOutput<ParamsSchema>, SchemaOutput<QuerySchema>, SchemaOutput<BodySchema>, Subject> & Ctx) => Promise<ListResult<ItemSchema> & ListMetaExtra<MetaSchema>> | (ListResult<ItemSchema> & ListMetaExtra<MetaSchema>);
|
|
45
|
+
} & VerbParams<Path, ParamsSchema>;
|
|
46
|
+
type ListRouteAccess = SessionAccess | PermissionAccess | VisibilityAccess | ScopedAccess | PublicAccess;
|
|
47
|
+
type ListRouteSubject<Access extends ListRouteAccess> = Access extends PublicAccess ? SubjectRef | null : SubjectRef;
|
|
48
|
+
type ListRouteContext<Access extends ListRouteAccess> = Access extends VisibilityAccess ? {
|
|
49
|
+
readonly visibleIds: readonly string[];
|
|
50
|
+
} : Access extends ScopedAccess ? {
|
|
51
|
+
readonly scope: ScopeAnswer;
|
|
52
|
+
} : Record<never, never>;
|
|
53
|
+
/**
|
|
54
|
+
* LIST handler context follows the declared access. Public handlers accept a
|
|
55
|
+
* nullable subject; visibility handlers additionally receive visible ids, and
|
|
56
|
+
* scoped handlers the scope answers they render with `scopePredicate`.
|
|
57
|
+
*/
|
|
58
|
+
export declare function listRoute<Path extends string, Access extends ListRouteAccess, ItemSchema extends z.ZodType, QuerySchema extends PaginatedQuerySchema, ParamsSchema extends z.ZodType<PathParamsShape<Path>> | undefined = undefined, BodySchema extends z.ZodType | undefined = undefined, MetaSchema extends ListMetaSchema | undefined = undefined>(config: ListRouteConfig<Path, Access, ListRouteSubject<Access>, ItemSchema, QuerySchema, ParamsSchema, BodySchema, ListRouteContext<Access>, MetaSchema>): RouteBlueprint;
|
|
59
|
+
export {};
|
|
60
|
+
//# sourceMappingURL=list-route.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list-route.d.ts","sourceRoot":"","sources":["../../../src/lib/route/list-route.ts"],"names":[],"mappings":"AA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AU,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;AA2CnC,KAAK,eAAe,GAChB,aAAa,GACb,gBAAgB,GAChB,gBAAgB,GAChB,YAAY,GACZ,YAAY,CAAC;AAEjB,KAAK,gBAAgB,CAAC,MAAM,SAAS,eAAe,IAClD,MAAM,SAAS,YAAY,GAAG,UAAU,GAAG,IAAI,GAAG,UAAU,CAAC;AAE/D,KAAK,gBAAgB,CAAC,MAAM,SAAS,eAAe,IAClD,MAAM,SAAS,gBAAgB,GAC3B;IAAE,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,GAC1C,MAAM,SAAS,YAAY,GACzB;IAAE,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAA;CAAE,GAC/B,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AAE7B;;;;GAIG;AACH,wBAAgB,SAAS,CACvB,IAAI,SAAS,MAAM,EACnB,MAAM,SAAS,eAAe,EAC9B,UAAU,SAAS,CAAC,CAAC,OAAO,EAC5B,WAAW,SAAS,oBAAoB,EACxC,YAAY,SAAS,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,GAAG,SAAS,GAAG,SAAS,EAC7E,UAAU,SAAS,CAAC,CAAC,OAAO,GAAG,SAAS,GAAG,SAAS,EACpD,UAAU,SAAS,cAAc,GAAG,SAAS,GAAG,SAAS,EAEzD,MAAM,EAAE,eAAe,CACrB,IAAI,EACJ,MAAM,EACN,gBAAgB,CAAC,MAAM,CAAC,EACxB,UAAU,EACV,WAAW,EACX,YAAY,EACZ,UAAU,EACV,gBAAgB,CAAC,MAAM,CAAC,EACxB,UAAU,CACX,GACA,cAAc,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { paginationMetaSchema, } from "@dads-framework/contract";
|
|
3
|
+
import { HttpWiringError } from "../http-errors.js";
|
|
4
|
+
import { buildDefinition, resolveVerbRoute, } from "./route-definition.js";
|
|
5
|
+
/** A handler's extra meta, when its route declared a meta schema; the response schema checks it. */
|
|
6
|
+
function extraMetaOf(result) {
|
|
7
|
+
if (!("meta" in result))
|
|
8
|
+
return {};
|
|
9
|
+
const { meta } = result;
|
|
10
|
+
return typeof meta === "object" && meta !== null ? meta : {};
|
|
11
|
+
}
|
|
12
|
+
/** Reads the page window back out of the parsed query for the meta echo. */
|
|
13
|
+
function pageWindowOf(query) {
|
|
14
|
+
if (typeof query === "object" &&
|
|
15
|
+
query !== null &&
|
|
16
|
+
"page" in query &&
|
|
17
|
+
"perPage" in query &&
|
|
18
|
+
typeof query.page === "number" &&
|
|
19
|
+
typeof query.perPage === "number") {
|
|
20
|
+
return { page: query.page, perPage: query.perPage };
|
|
21
|
+
}
|
|
22
|
+
// The query schema's output type guarantees these — reaching this line
|
|
23
|
+
// means the schema lied about its output (a wiring bug, loud 500).
|
|
24
|
+
throw new HttpWiringError("listRoute query parsed without page/perPage — the query schema must extend paginationQuerySchema");
|
|
25
|
+
}
|
|
26
|
+
export function listRoute(config) {
|
|
27
|
+
const resolvedRoute = resolveVerbRoute(config, "GET");
|
|
28
|
+
return buildDefinition({
|
|
29
|
+
...resolvedRoute,
|
|
30
|
+
summary: config.summary,
|
|
31
|
+
access: config.access,
|
|
32
|
+
...(config.capabilities === undefined
|
|
33
|
+
? {}
|
|
34
|
+
: { capabilities: config.capabilities }),
|
|
35
|
+
...(config.params === undefined ? {} : { params: config.params }),
|
|
36
|
+
query: config.query,
|
|
37
|
+
response: z.array(config.item),
|
|
38
|
+
meta: config.meta ?? paginationMetaSchema,
|
|
39
|
+
handler: async (ctx) => {
|
|
40
|
+
if (config.access.kind === "visibility") {
|
|
41
|
+
const visibleIds = ctx.visibleIds ?? [];
|
|
42
|
+
if (visibleIds.length === 0) {
|
|
43
|
+
// Fail-closed by construction: an empty visible set is an empty
|
|
44
|
+
// page — the handler (and its reader) never see an empty IN ().
|
|
45
|
+
return { data: [], meta: { total: 0, ...pageWindowOf(ctx.query) } };
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (config.access.kind === "scoped" && ctx.scope === undefined) {
|
|
49
|
+
// No answers means no scope to render: refuse rather than list
|
|
50
|
+
// unscoped. An empty answer is still an answer and reaches the SQL.
|
|
51
|
+
throw new HttpWiringError(`scoped list route ${resolvedRoute.path} ran without a scope answer`);
|
|
52
|
+
}
|
|
53
|
+
const result = await config.handler(ctx);
|
|
54
|
+
if (typeof result !== "object" ||
|
|
55
|
+
result === null ||
|
|
56
|
+
!("items" in result) ||
|
|
57
|
+
!("total" in result)) {
|
|
58
|
+
throw new HttpWiringError(`list route ${resolvedRoute.path} must return { items, total }`);
|
|
59
|
+
}
|
|
60
|
+
const window = pageWindowOf(ctx.query);
|
|
61
|
+
return {
|
|
62
|
+
data: result.items,
|
|
63
|
+
meta: { ...extraMetaOf(result), total: result.total, ...window },
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=list-route.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list-route.js","sourceRoot":"","sources":["../../../src/lib/route/list-route.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAEL,oBAAoB,GAErB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAUpD,OAAO,EACL,eAAe,EAEf,gBAAgB,GAMjB,MAAM,uBAAuB,CAAC;AA4E/B,oGAAoG;AACpG,SAAS,WAAW,CAAC,MAAc;IACjC,IAAI,CAAC,CAAC,MAAM,IAAI,MAAM,CAAC;QAAE,OAAO,EAAE,CAAC;IACnC,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC;IACxB,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAA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ubjectRef } from "@dads-framework/access/runtime";
|
|
3
|
+
import type { PermissionAccess, PublicAccess, RouteAccess, SessionAccess } from "./access.js";
|
|
4
|
+
import { type PathParamsShape, type RouteBlueprint, type RouteHandlerContext, type SchemaOutput, type VerbCommon, type VerbParams } from "./route-definition.js";
|
|
5
|
+
/**
|
|
6
|
+
* PATCH (partial update) and PUT (replacement) — `body` is REQUIRED (a
|
|
7
|
+
* body-less mutation is a compile error) and the config has NO `query`,
|
|
8
|
+
* `meta`, or `status` keys: declaring them is an excess-property error.
|
|
9
|
+
* Always 200.
|
|
10
|
+
*/
|
|
11
|
+
export type MutateRouteConfig<Path extends string, Access extends RouteAccess, Subject, ResponseSchema extends z.ZodType, ParamsSchema extends z.ZodType<PathParamsShape<Path>> | undefined, BodySchema extends z.ZodType, QuerySchema extends z.ZodType | undefined, Method extends "PATCH" | "PUT" = "PATCH" | "PUT"> = VerbCommon<Method, Path, Access> & {
|
|
12
|
+
readonly response: ResponseSchema;
|
|
13
|
+
readonly body: BodySchema;
|
|
14
|
+
readonly handler: (ctx: RouteHandlerContext<SchemaOutput<ParamsSchema>, SchemaOutput<QuerySchema>, SchemaOutput<BodySchema>, Subject>) => Promise<z.input<ResponseSchema>> | z.input<ResponseSchema>;
|
|
15
|
+
} & VerbParams<Path, ParamsSchema>;
|
|
16
|
+
/** Parsed inputs and subject available to a named PATCH or PUT handler. */
|
|
17
|
+
export type MutateRouteHandlerContext<Params, Body, Subject> = RouteHandlerContext<Params, undefined, Body, Subject>;
|
|
18
|
+
/** Data shape a named PATCH or PUT handler returns before enveloping. */
|
|
19
|
+
export type MutateRouteHandlerResult<ResponseSchema extends z.ZodType> = z.input<ResponseSchema>;
|
|
20
|
+
type MutateRouteAccess = SessionAccess | PermissionAccess | PublicAccess;
|
|
21
|
+
type MutateRouteSubject<Access extends MutateRouteAccess> = Access extends PublicAccess ? SubjectRef | null : SubjectRef;
|
|
22
|
+
/** PATCH handler subject nullability follows the declared access. */
|
|
23
|
+
export declare function patchRoute<Path extends string, Access extends MutateRouteAccess, ResponseSchema extends z.ZodType, BodySchema extends z.ZodType, ParamsSchema extends z.ZodType<PathParamsShape<Path>> | undefined = undefined, QuerySchema extends z.ZodType | undefined = undefined>(config: MutateRouteConfig<Path, Access, MutateRouteSubject<Access>, ResponseSchema, ParamsSchema, BodySchema, QuerySchema, "PATCH">): RouteBlueprint;
|
|
24
|
+
/** PUT handler subject nullability follows the declared access. */
|
|
25
|
+
export declare function putRoute<Path extends string, Access extends MutateRouteAccess, ResponseSchema extends z.ZodType, BodySchema extends z.ZodType, ParamsSchema extends z.ZodType<PathParamsShape<Path>> | undefined = undefined, QuerySchema extends z.ZodType | undefined = undefined>(config: MutateRouteConfig<Path, Access, MutateRouteSubject<Access>, ResponseSchema, ParamsSchema, BodySchema, QuerySchema, "PUT">): RouteBlueprint;
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=patch-route.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patch-route.d.ts","sourceRoot":"","sources":["../../../src/lib/route/patch-route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,KAAK,EACV,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,aAAa,EACd,MAAM,aAAa,CAAC;AACrB,OAAO,EAIL,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,UAAU,EAChB,MAAM,uBAAuB,CAAC;AAE/B;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,CAC3B,IAAI,SAAS,MAAM,EACnB,MAAM,SAAS,WAAW,EAC1B,OAAO,EACP,cAAc,SAAS,CAAC,CAAC,OAAO,EAChC,YAAY,SAAS,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC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AAO,EAChC,UAAU,SAAS,CAAC,CAAC,OAAO,EAC5B,YAAY,SAAS,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,GAAG,SAAS,GAAG,SAAS,EAC7E,WAAW,SAAS,CAAC,CAAC,OAAO,GAAG,SAAS,GAAG,SAAS,EAErD,MAAM,EAAE,iBAAiB,CACvB,IAAI,EACJ,MAAM,EACN,kBAAkB,CAAC,MAAM,CAAC,EAC1B,cAAc,EACd,YAAY,EACZ,UAAU,EACV,WAAW,EACX,OAAO,CACR,GACA,cAAc,CAAC;AAKlB,mEAAmE;AACnE,wBAAgB,QAAQ,CACtB,IAAI,SAAS,MAAM,EACnB,MAAM,SAAS,iBAAiB,EAChC,cAAc,SAAS,CAAC,CAAC,OAAO,EAChC,UAAU,SAAS,CAAC,CAAC,OAAO,EAC5B,YAAY,SAAS,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,GAAG,SAAS,GAAG,SAAS,EAC7E,WAAW,SAAS,CAAC,CAAC,OAAO,GAAG,SAAS,GAAG,SAAS,EAErD,MAAM,EAAE,iBAAiB,CACvB,IAAI,EACJ,MAAM,EACN,kBAAkB,CAAC,MAAM,CAAC,EAC1B,cAAc,EACd,YAAY,EACZ,UAAU,EACV,WAAW,EACX,KAAK,CACN,GACA,cAAc,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { buildDefinition, resolveVerbRoute, } from "./route-definition.js";
|
|
2
|
+
export function patchRoute(config) {
|
|
3
|
+
return buildDefinition({ ...config, ...resolveVerbRoute(config, "PATCH") });
|
|
4
|
+
}
|
|
5
|
+
export function putRoute(config) {
|
|
6
|
+
return buildDefinition({ ...config, ...resolveVerbRoute(config, "PUT") });
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=patch-route.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patch-route.js","sourceRoot":"","sources":["../../../src/lib/route/patch-route.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,eAAe,EACf,gBAAgB,GAQjB,MAAM,uBAAuB,CAAC;AA+D/B,MAAM,UAAU,UAAU,CAAC,MAAwB;IACjD,OAAO,eAAe,CAAC,EAAE,GAAG,MAAM,EAAE,GAAG,gBAAgB,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;AAC9E,CAAC;AAsBD,MAAM,UAAU,QAAQ,CAAC,MAAwB;IAC/C,OAAO,eAAe,CAAC,EAAE,GAAG,MAAM,EAAE,GAAG,gBAAgB,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC;AAC5E,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
import type { SubjectRef } from "@dads-framework/access/runtime";
|
|
3
|
+
import type { PermissionAccess, SessionAccess } from "./access.js";
|
|
4
|
+
import { type PathParamsShape, type RouteBlueprint, type RouteHandlerContext, type SchemaOutput, type VerbCommon, type VerbParams } from "./route-definition.js";
|
|
5
|
+
/**
|
|
6
|
+
* A guarded POST that accepts a report and answers 204 with no body: no
|
|
7
|
+
* response schema exists on this config, and the handler returns nothing.
|
|
8
|
+
* For a caller that only tells the server something (a device's periodic
|
|
9
|
+
* check-in) and must learn nothing back. A POST that creates a resource or
|
|
10
|
+
* returns a result is `postRoute`.
|
|
11
|
+
*/
|
|
12
|
+
export type PostNoContentRouteConfig<Path extends string, Access extends SessionAccess | PermissionAccess, ParamsSchema extends z.ZodType<PathParamsShape<Path>> | undefined, BodySchema extends z.ZodType | undefined> = VerbCommon<"POST", Path, Access> & {
|
|
13
|
+
readonly body?: BodySchema;
|
|
14
|
+
handler(ctx: RouteHandlerContext<SchemaOutput<ParamsSchema>, undefined, SchemaOutput<BodySchema>, SubjectRef>): Promise<void> | void;
|
|
15
|
+
} & VerbParams<Path, ParamsSchema>;
|
|
16
|
+
/** Guarded no-content POST — the handler's subject is non-null by construction. */
|
|
17
|
+
export declare function postNoContentRoute<Path extends string, Access extends SessionAccess | PermissionAccess, ParamsSchema extends z.ZodType<PathParamsShape<Path>> | undefined = undefined, BodySchema extends z.ZodType | undefined = undefined>(config: PostNoContentRouteConfig<Path, Access, ParamsSchema, BodySchema>): RouteBlueprint;
|
|
18
|
+
//# sourceMappingURL=post-no-content-route.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"post-no-content-route.d.ts","sourceRoot":"","sources":["../../../src/lib/route/post-no-content-route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,EAIL,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,UAAU,EAChB,MAAM,uBAAuB,CAAC;AAE/B;;;;;;GAMG;AACH,MAAM,MAAM,wBAAwB,CAClC,IAAI,SAAS,MAAM,EACnB,MAAM,SAAS,aAAa,GAAG,gBAAgB,EAC/C,YAAY,SAAS,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,GAAG,SAAS,EACjE,UAAU,SAAS,CAAC,CAAC,OAAO,GAAG,SAAS,IACtC,UAAU,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG;IACrC,QAAQ,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC;IAC3B,OAAO,CACL,GAAG,EAAE,mBAAmB,CACtB,YAAY,CAAC,YAAY,CAAC,EAC1B,SAAS,EACT,YAAY,CAAC,UAAU,CAAC,EACxB,UAAU,CACX,GACA,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CACzB,GAAG,UAAU,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;AAEnC,mFAAmF;AACnF,wBAAgB,kBAAkB,CAChC,IAAI,SAAS,MAAM,EACnB,MAAM,SAAS,aAAa,GAAG,gBAAgB,EAC/C,YAAY,SAAS,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,GAAG,SAAS,GAAG,SAAS,EAC7E,UAAU,SAAS,CAAC,CAAC,OAAO,GAAG,SAAS,GAAG,SAAS,EAEpD,MAAM,EAAE,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,UAAU,CAAC,GACvE,cAAc,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { buildNoContentDefinition, resolveVerbRoute, } from "./route-definition.js";
|
|
2
|
+
export function postNoContentRoute(config) {
|
|
3
|
+
return buildNoContentDefinition({
|
|
4
|
+
...config,
|
|
5
|
+
...resolveVerbRoute(config, "POST"),
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=post-no-content-route.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"post-no-content-route.js","sourceRoot":"","sources":["../../../src/lib/route/post-no-content-route.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,wBAAwB,EACxB,gBAAgB,GAQjB,MAAM,uBAAuB,CAAC;AAmC/B,MAAM,UAAU,kBAAkB,CAChC,MAAiC;IAEjC,OAAO,wBAAwB,CAAC;QAC9B,GAAG,MAAM;QACT,GAAG,gBAAgB,CAAC,MAAM,EAAE,MAAM,CAAC;KACpC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
import type { SubjectRef } from "@dads-framework/access/runtime";
|
|
3
|
+
import type { PermissionAccess, PublicAccess, RouteAccess, SessionAccess } from "./access.js";
|
|
4
|
+
import { type HandlerResult, type PathParamsShape, type ResourceFreePostPolicy, type RouteBlueprint, type RouteHandlerContext, type SchemaOutput, type VerbCommon, type VerbParams } from "./route-definition.js";
|
|
5
|
+
/**
|
|
6
|
+
* POST — creates and commands. Answers 201 by default; command-style posts
|
|
7
|
+
* whose result is a report (not a created resource) override to 200.
|
|
8
|
+
*/
|
|
9
|
+
export type PostRouteConfig<Path extends string, Access extends RouteAccess, Subject, ResponseSchema extends z.ZodType, ParamsSchema extends z.ZodType<PathParamsShape<Path>> | undefined, QuerySchema extends z.ZodType | undefined, BodySchema extends z.ZodType | undefined, MetaSchema extends z.ZodType | undefined> = VerbCommon<"POST", Path, Access> & {
|
|
10
|
+
readonly response: ResponseSchema;
|
|
11
|
+
readonly meta?: MetaSchema;
|
|
12
|
+
/** 202 when the POST only accepts work that runs later. */
|
|
13
|
+
readonly status?: 200 | 201 | 202;
|
|
14
|
+
readonly query?: QuerySchema;
|
|
15
|
+
readonly body?: BodySchema;
|
|
16
|
+
handler(ctx: RouteHandlerContext<SchemaOutput<ParamsSchema>, SchemaOutput<QuerySchema>, SchemaOutput<BodySchema>, Subject>): Promise<HandlerResult<ResponseSchema, MetaSchema>> | HandlerResult<ResponseSchema, MetaSchema>;
|
|
17
|
+
} & VerbParams<Path, ParamsSchema> & PostResourcePolicy<Access, BodySchema>;
|
|
18
|
+
type PostResourcePolicy<Access extends RouteAccess, BodySchema> = {
|
|
19
|
+
readonly resourcePolicy?: never;
|
|
20
|
+
} | (Access extends PublicAccess ? {
|
|
21
|
+
readonly resourcePolicy: ResourceFreePostPolicy;
|
|
22
|
+
readonly status: 200;
|
|
23
|
+
readonly body: NonNullable<BodySchema>;
|
|
24
|
+
} : never);
|
|
25
|
+
/** Parsed inputs and subject available to a named POST handler module. */
|
|
26
|
+
export type PostRouteHandlerContext<Params, Query, Body, Subject> = RouteHandlerContext<Params, Query, Body, Subject>;
|
|
27
|
+
/** Data shape a named POST handler returns before the kit envelopes it. */
|
|
28
|
+
export type PostRouteHandlerResult<ResponseSchema extends z.ZodType, MetaSchema extends z.ZodType | undefined = undefined> = HandlerResult<ResponseSchema, MetaSchema>;
|
|
29
|
+
/** Guarded POST — the handler's subject is non-null by construction. */
|
|
30
|
+
export declare function postRoute<Path extends string, Access extends SessionAccess | PermissionAccess, ResponseSchema extends z.ZodType, ParamsSchema extends z.ZodType<PathParamsShape<Path>> | undefined = undefined, QuerySchema extends z.ZodType | undefined = undefined, BodySchema extends z.ZodType | undefined = undefined, MetaSchema extends z.ZodType | undefined = undefined>(config: PostRouteConfig<Path, Access, SubjectRef, ResponseSchema, ParamsSchema, QuerySchema, BodySchema, MetaSchema>): RouteBlueprint;
|
|
31
|
+
/** Public POST — the handler must deal with a null subject. */
|
|
32
|
+
export declare function postRoute<Path extends string, Access extends PublicAccess, ResponseSchema extends z.ZodType, ParamsSchema extends z.ZodType<PathParamsShape<Path>> | undefined = undefined, QuerySchema extends z.ZodType | undefined = undefined, BodySchema extends z.ZodType | undefined = undefined, MetaSchema extends z.ZodType | undefined = undefined>(config: PostRouteConfig<Path, Access, SubjectRef | null, ResponseSchema, ParamsSchema, QuerySchema, BodySchema, MetaSchema>): RouteBlueprint;
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=post-route.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"post-route.d.ts","sourceRoot":"","sources":["../../../src/lib/route/post-route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAEjE,OAAO,KAAK,EACV,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,aAAa,EACd,MAAM,aAAa,CAAC;AACrB,OAAO,EAIL,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,UAAU,EAChB,MAAM,uBAAuB,CAAC;AAE/B;;;GAGG;AACH,MAAM,MA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C,GAAG,SAAS,GAAG,SAAS,EAC7E,WAAW,SAAS,CAAC,CAAC,OAAO,GAAG,SAAS,GAAG,SAAS,EACrD,UAAU,SAAS,CAAC,CAAC,OAAO,GAAG,SAAS,GAAG,SAAS,EACpD,UAAU,SAAS,CAAC,CAAC,OAAO,GAAG,SAAS,GAAG,SAAS,EAEpD,MAAM,EAAE,eAAe,CACrB,IAAI,EACJ,MAAM,EACN,UAAU,GAAG,IAAI,EACjB,cAAc,EACd,YAAY,EACZ,WAAW,EACX,UAAU,EACV,UAAU,CACX,GACA,cAAc,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { HttpWiringError } from "../http-errors.js";
|
|
2
|
+
import { buildDefinition, resolveVerbRoute, } from "./route-definition.js";
|
|
3
|
+
export function postRoute(config) {
|
|
4
|
+
const route = buildDefinition({
|
|
5
|
+
...config,
|
|
6
|
+
...resolveVerbRoute(config, "POST"),
|
|
7
|
+
});
|
|
8
|
+
const policy = config.resourcePolicy;
|
|
9
|
+
if (policy === undefined)
|
|
10
|
+
return route;
|
|
11
|
+
assertPublicTelemetry(route, policy);
|
|
12
|
+
return { ...route, resourcePolicy: policy };
|
|
13
|
+
}
|
|
14
|
+
function assertPublicTelemetry(route, policy) {
|
|
15
|
+
if (route.access.kind !== "public" ||
|
|
16
|
+
route.status !== 200 ||
|
|
17
|
+
route.schemas.body === undefined ||
|
|
18
|
+
policy.kind !== "resource-free" ||
|
|
19
|
+
policy.purpose !== "append-only-telemetry") {
|
|
20
|
+
throw new HttpWiringError("A resource-free telemetry POST requires public access, status 200, and a body schema");
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=post-route.js.map
|