@ddd-ts-kit/http 0.90.0 → 0.91.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/README.fr.md +222 -2
- package/README.md +217 -1
- package/dist/error/refusal-codes-by-status.d.ts +11 -0
- package/dist/error/refusal-codes-by-status.d.ts.map +1 -0
- package/dist/error/refusal-codes-by-status.js +48 -0
- package/dist/error/refusal-codes-by-status.js.map +1 -0
- package/dist/nest/controllers/arguments-of.d.ts +7 -0
- package/dist/nest/controllers/arguments-of.d.ts.map +1 -0
- package/dist/nest/controllers/arguments-of.js +21 -0
- package/dist/nest/controllers/arguments-of.js.map +1 -0
- package/dist/nest/controllers/assert-not-routed-by-nest.d.ts +8 -0
- package/dist/nest/controllers/assert-not-routed-by-nest.d.ts.map +1 -0
- package/dist/nest/controllers/assert-not-routed-by-nest.js +19 -0
- package/dist/nest/controllers/assert-not-routed-by-nest.js.map +1 -0
- package/dist/nest/controllers/controllers-binder.d.ts +6 -0
- package/dist/nest/controllers/controllers-binder.d.ts.map +1 -0
- package/dist/nest/controllers/controllers-binder.js +5 -0
- package/dist/nest/controllers/controllers-binder.js.map +1 -0
- package/dist/nest/controllers/controllers-module-options.d.ts +8 -0
- package/dist/nest/controllers/controllers-module-options.d.ts.map +1 -0
- package/dist/nest/controllers/controllers-module-options.js +2 -0
- package/dist/nest/controllers/controllers-module-options.js.map +1 -0
- package/dist/nest/controllers/create-controllers-module.d.ts +10 -0
- package/dist/nest/controllers/create-controllers-module.d.ts.map +1 -0
- package/dist/nest/controllers/create-controllers-module.js +28 -0
- package/dist/nest/controllers/create-controllers-module.js.map +1 -0
- package/dist/nest/controllers/current-actor.d.ts +6 -0
- package/dist/nest/controllers/current-actor.d.ts.map +1 -0
- package/dist/nest/controllers/current-actor.js +9 -0
- package/dist/nest/controllers/current-actor.js.map +1 -0
- package/dist/nest/controllers/dto-type.d.ts +3 -0
- package/dist/nest/controllers/dto-type.d.ts.map +1 -0
- package/dist/nest/controllers/dto-type.js +2 -0
- package/dist/nest/controllers/dto-type.js.map +1 -0
- package/dist/nest/controllers/injected-parameter.d.ts +4 -0
- package/dist/nest/controllers/injected-parameter.d.ts.map +1 -0
- package/dist/nest/controllers/injected-parameter.js +17 -0
- package/dist/nest/controllers/injected-parameter.js.map +1 -0
- package/dist/nest/controllers/is-nest-controller.d.ts +4 -0
- package/dist/nest/controllers/is-nest-controller.d.ts.map +1 -0
- package/dist/nest/controllers/is-nest-controller.js +7 -0
- package/dist/nest/controllers/is-nest-controller.js.map +1 -0
- package/dist/nest/controllers/keyed-schema.d.ts +8 -0
- package/dist/nest/controllers/keyed-schema.d.ts.map +1 -0
- package/dist/nest/controllers/keyed-schema.js +33 -0
- package/dist/nest/controllers/keyed-schema.js.map +1 -0
- package/dist/nest/controllers/kit-route-spec.d.ts +47 -0
- package/dist/nest/controllers/kit-route-spec.d.ts.map +1 -0
- package/dist/nest/controllers/kit-route-spec.js +2 -0
- package/dist/nest/controllers/kit-route-spec.js.map +1 -0
- package/dist/nest/controllers/kit-route.d.ts +18 -0
- package/dist/nest/controllers/kit-route.d.ts.map +1 -0
- package/dist/nest/controllers/kit-route.js +29 -0
- package/dist/nest/controllers/kit-route.js.map +1 -0
- package/dist/nest/controllers/kit-routes-options.d.ts +15 -0
- package/dist/nest/controllers/kit-routes-options.d.ts.map +1 -0
- package/dist/nest/controllers/kit-routes-options.js +2 -0
- package/dist/nest/controllers/kit-routes-options.js.map +1 -0
- package/dist/nest/controllers/kit-routes.d.ts +5 -0
- package/dist/nest/controllers/kit-routes.d.ts.map +1 -0
- package/dist/nest/controllers/kit-routes.js +8 -0
- package/dist/nest/controllers/kit-routes.js.map +1 -0
- package/dist/nest/controllers/nest-controller-class.d.ts +3 -0
- package/dist/nest/controllers/nest-controller-class.d.ts.map +1 -0
- package/dist/nest/controllers/nest-controller-class.js +2 -0
- package/dist/nest/controllers/nest-controller-class.js.map +1 -0
- package/dist/nest/controllers/nest-controller-route.d.ts +6 -0
- package/dist/nest/controllers/nest-controller-route.d.ts.map +1 -0
- package/dist/nest/controllers/nest-controller-route.js +12 -0
- package/dist/nest/controllers/nest-controller-route.js.map +1 -0
- package/dist/nest/controllers/nest-controller-routes-options.d.ts +14 -0
- package/dist/nest/controllers/nest-controller-routes-options.d.ts.map +1 -0
- package/dist/nest/controllers/nest-controller-routes-options.js +2 -0
- package/dist/nest/controllers/nest-controller-routes-options.js.map +1 -0
- package/dist/nest/controllers/nest-controller-routes.d.ts +12 -0
- package/dist/nest/controllers/nest-controller-routes.d.ts.map +1 -0
- package/dist/nest/controllers/nest-controller-routes.js +142 -0
- package/dist/nest/controllers/nest-controller-routes.js.map +1 -0
- package/dist/nest/controllers/nest-controllers-options.d.ts +7 -0
- package/dist/nest/controllers/nest-controllers-options.d.ts.map +1 -0
- package/dist/nest/controllers/nest-controllers-options.js +2 -0
- package/dist/nest/controllers/nest-controllers-options.js.map +1 -0
- package/dist/nest/controllers/nest-controllers.d.ts +21 -0
- package/dist/nest/controllers/nest-controllers.d.ts.map +1 -0
- package/dist/nest/controllers/nest-controllers.js +31 -0
- package/dist/nest/controllers/nest-controllers.js.map +1 -0
- package/dist/nest/controllers/nest-method.d.ts +17 -0
- package/dist/nest/controllers/nest-method.d.ts.map +1 -0
- package/dist/nest/controllers/nest-method.js +2 -0
- package/dist/nest/controllers/nest-method.js.map +1 -0
- package/dist/nest/controllers/nest-parameter.d.ts +10 -0
- package/dist/nest/controllers/nest-parameter.d.ts.map +1 -0
- package/dist/nest/controllers/nest-parameter.js +2 -0
- package/dist/nest/controllers/nest-parameter.js.map +1 -0
- package/dist/nest/controllers/nest-route-metadata.d.ts +22 -0
- package/dist/nest/controllers/nest-route-metadata.d.ts.map +1 -0
- package/dist/nest/controllers/nest-route-metadata.js +121 -0
- package/dist/nest/controllers/nest-route-metadata.js.map +1 -0
- package/dist/nest/controllers/nest-route-methods.d.ts +4 -0
- package/dist/nest/controllers/nest-route-methods.d.ts.map +1 -0
- package/dist/nest/controllers/nest-route-methods.js +12 -0
- package/dist/nest/controllers/nest-route-methods.js.map +1 -0
- package/dist/nest/controllers/nest-routes-registry.d.ts +18 -0
- package/dist/nest/controllers/nest-routes-registry.d.ts.map +1 -0
- package/dist/nest/controllers/nest-routes-registry.js +23 -0
- package/dist/nest/controllers/nest-routes-registry.js.map +1 -0
- package/dist/nest/controllers/prototype-of.d.ts +4 -0
- package/dist/nest/controllers/prototype-of.d.ts.map +1 -0
- package/dist/nest/controllers/prototype-of.js +10 -0
- package/dist/nest/controllers/prototype-of.js.map +1 -0
- package/dist/nest/controllers/provide-controllers.d.ts +12 -0
- package/dist/nest/controllers/provide-controllers.d.ts.map +1 -0
- package/dist/nest/controllers/provide-controllers.js +33 -0
- package/dist/nest/controllers/provide-controllers.js.map +1 -0
- package/dist/nest/controllers/reflected-metadata.d.ts +3 -0
- package/dist/nest/controllers/reflected-metadata.d.ts.map +1 -0
- package/dist/nest/controllers/reflected-metadata.js +11 -0
- package/dist/nest/controllers/reflected-metadata.js.map +1 -0
- package/dist/nest/controllers/request-schemas-of.d.ts +13 -0
- package/dist/nest/controllers/request-schemas-of.d.ts.map +1 -0
- package/dist/nest/controllers/request-schemas-of.js +49 -0
- package/dist/nest/controllers/request-schemas-of.js.map +1 -0
- package/dist/nest/controllers/route-context.d.ts +3 -0
- package/dist/nest/controllers/route-context.d.ts.map +1 -0
- package/dist/nest/controllers/route-context.js +6 -0
- package/dist/nest/controllers/route-context.js.map +1 -0
- package/dist/nest/controllers/schema-of.d.ts +6 -0
- package/dist/nest/controllers/schema-of.d.ts.map +1 -0
- package/dist/nest/controllers/schema-of.js +12 -0
- package/dist/nest/controllers/schema-of.js.map +1 -0
- package/dist/nest/controllers/summary-of.d.ts +3 -0
- package/dist/nest/controllers/summary-of.d.ts.map +1 -0
- package/dist/nest/controllers/summary-of.js +6 -0
- package/dist/nest/controllers/summary-of.js.map +1 -0
- package/dist/nest/controllers/with-answers.d.ts +10 -0
- package/dist/nest/controllers/with-answers.d.ts.map +1 -0
- package/dist/nest/controllers/with-answers.js +11 -0
- package/dist/nest/controllers/with-answers.js.map +1 -0
- package/dist/nest.d.ts +18 -0
- package/dist/nest.d.ts.map +1 -1
- package/dist/nest.js +11 -0
- package/dist/nest.js.map +1 -1
- package/dist/openapi/responses.d.ts.map +1 -1
- package/dist/openapi/responses.js +2 -41
- package/dist/openapi/responses.js.map +1 -1
- package/dist/orpc/orpc-protocol.d.ts +7 -0
- package/dist/orpc/orpc-protocol.d.ts.map +1 -0
- package/dist/orpc/orpc-protocol.js +13 -0
- package/dist/orpc/orpc-protocol.js.map +1 -0
- package/dist/orpc/orpc-router.d.ts +22 -0
- package/dist/orpc/orpc-router.d.ts.map +1 -0
- package/dist/orpc/orpc-router.js +43 -0
- package/dist/orpc/orpc-router.js.map +1 -0
- package/dist/orpc.d.ts +4 -0
- package/dist/orpc.d.ts.map +1 -0
- package/dist/orpc.js +2 -0
- package/dist/orpc.js.map +1 -0
- package/dist/pipeline/primed.d.ts +2 -1
- package/dist/pipeline/primed.d.ts.map +1 -1
- package/dist/pipeline/primed.js +14 -11
- package/dist/pipeline/primed.js.map +1 -1
- package/dist/rpc/rpc-answer.d.ts +18 -0
- package/dist/rpc/rpc-answer.d.ts.map +1 -0
- package/dist/rpc/rpc-answer.js +61 -0
- package/dist/rpc/rpc-answer.js.map +1 -0
- package/dist/rpc/rpc-context.d.ts +15 -0
- package/dist/rpc/rpc-context.d.ts.map +1 -0
- package/dist/rpc/rpc-context.js +2 -0
- package/dist/rpc/rpc-context.js.map +1 -0
- package/dist/rpc/rpc-input.d.ts +11 -0
- package/dist/rpc/rpc-input.d.ts.map +1 -0
- package/dist/rpc/rpc-input.js +2 -0
- package/dist/rpc/rpc-input.js.map +1 -0
- package/dist/rpc/rpc-refusal.d.ts +14 -0
- package/dist/rpc/rpc-refusal.d.ts.map +1 -0
- package/dist/rpc/rpc-refusal.js +2 -0
- package/dist/rpc/rpc-refusal.js.map +1 -0
- package/dist/rpc/rpc-request.d.ts +9 -0
- package/dist/rpc/rpc-request.d.ts.map +1 -0
- package/dist/rpc/rpc-request.js +28 -0
- package/dist/rpc/rpc-request.js.map +1 -0
- package/dist/trpc/route-refusal.d.ts +8 -0
- package/dist/trpc/route-refusal.d.ts.map +1 -0
- package/dist/trpc/route-refusal.js +10 -0
- package/dist/trpc/route-refusal.js.map +1 -0
- package/dist/trpc/trpc-error-shape.d.ts +17 -0
- package/dist/trpc/trpc-error-shape.d.ts.map +1 -0
- package/dist/trpc/trpc-error-shape.js +2 -0
- package/dist/trpc/trpc-error-shape.js.map +1 -0
- package/dist/trpc/trpc-protocol.d.ts +8 -0
- package/dist/trpc/trpc-protocol.d.ts.map +1 -0
- package/dist/trpc/trpc-protocol.js +43 -0
- package/dist/trpc/trpc-protocol.js.map +1 -0
- package/dist/trpc/trpc-router.d.ts +38 -0
- package/dist/trpc/trpc-router.d.ts.map +1 -0
- package/dist/trpc/trpc-router.js +44 -0
- package/dist/trpc/trpc-router.js.map +1 -0
- package/dist/trpc.d.ts +5 -0
- package/dist/trpc.d.ts.map +1 -0
- package/dist/trpc.js +2 -0
- package/dist/trpc.js.map +1 -0
- package/package.json +30 -7
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Readable } from 'node:stream';
|
|
2
|
+
import { toProblem } from '../error/to-problem.js';
|
|
3
|
+
import { NotAcceptableError } from '../representation/not-acceptable-error.js';
|
|
4
|
+
import { isAsyncIterable } from '../support/is-async-iterable.js';
|
|
5
|
+
import { isRecord } from '../support/is-record.js';
|
|
6
|
+
const FIRST_REFUSAL_STATUS = 400;
|
|
7
|
+
/**
|
|
8
|
+
* What a procedure returns for the answer of its route: the body of a success as JSON writes it,
|
|
9
|
+
* a binary body as a `Blob` when the protocol carries one. A refusal is thrown as the error of the
|
|
10
|
+
* protocol, with its problem document. A file and a list read as it comes are refused with 406 and
|
|
11
|
+
* closed: they are streamed because they may not fit in memory, and only the HTTP route streams them.
|
|
12
|
+
*/
|
|
13
|
+
export async function rpcAnswer(response, protocol, mapper) {
|
|
14
|
+
if (response.status >= FIRST_REFUSAL_STATUS) {
|
|
15
|
+
throw protocol.refuse(refusalOf(response));
|
|
16
|
+
}
|
|
17
|
+
const { body } = response;
|
|
18
|
+
const streamed = (what) => protocol.refuse(streamedRefusal(what, response, mapper));
|
|
19
|
+
if (body instanceof Readable) {
|
|
20
|
+
body.destroy();
|
|
21
|
+
throw streamed('a file');
|
|
22
|
+
}
|
|
23
|
+
// No representation writes it: the pipeline hands over a list read as it comes as the body itself.
|
|
24
|
+
if (isAsyncIterable(body)) {
|
|
25
|
+
await body[Symbol.asyncIterator]().return?.();
|
|
26
|
+
throw streamed('a list read as it comes');
|
|
27
|
+
}
|
|
28
|
+
if (body instanceof Uint8Array) {
|
|
29
|
+
if (!protocol.carriesBinary) {
|
|
30
|
+
throw streamed('a binary body');
|
|
31
|
+
}
|
|
32
|
+
return new Blob([body], { type: response.headers['content-type'] });
|
|
33
|
+
}
|
|
34
|
+
return isJson(response) && body !== undefined ? JSON.parse(JSON.stringify(body)) : body;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A JSON body is returned as the HTTP route writes it, a date as its text: what the contract, and
|
|
38
|
+
* the client generated from it, say it is, which the serializer of a protocol would otherwise keep a `Date`.
|
|
39
|
+
*/
|
|
40
|
+
function isJson(response) {
|
|
41
|
+
return /[/+]json\b/.test(response.headers['content-type'] ?? '');
|
|
42
|
+
}
|
|
43
|
+
/** A refusal the route answers itself, without a problem document, keeps its status and its body under the code `HTTP_<status>`. */
|
|
44
|
+
function refusalOf(response) {
|
|
45
|
+
const { body, status } = response;
|
|
46
|
+
if (!isProblem(body)) {
|
|
47
|
+
const code = `HTTP_${String(status)}`;
|
|
48
|
+
return { status, code, message: code, problem: undefined, body };
|
|
49
|
+
}
|
|
50
|
+
return { status, code: body.code, message: body.detail ?? body.title, problem: body, body };
|
|
51
|
+
}
|
|
52
|
+
function isProblem(body) {
|
|
53
|
+
return isRecord(body) && typeof body['code'] === 'string' && typeof body['title'] === 'string';
|
|
54
|
+
}
|
|
55
|
+
/** The problem the HTTP route would answer to an `Accept` it cannot meet, under the request id of the call. */
|
|
56
|
+
function streamedRefusal(what, response, mapper) {
|
|
57
|
+
const message = `This operation answers ${what}, which only its HTTP route carries.`;
|
|
58
|
+
const problem = toProblem(new NotAcceptableError(message), mapper, response.headers['x-request-id'] ?? '');
|
|
59
|
+
return { status: problem.status, code: problem.code, message, problem, body: problem };
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=rpc-answer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc-answer.js","sourceRoot":"","sources":["../../src/rpc/rpc-answer.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { RawHeaders } from '../route/raw-headers.js';
|
|
2
|
+
/**
|
|
3
|
+
* What the server hands to every procedure with the call, as the context of its RPC handler: the
|
|
4
|
+
* headers of the RPC request, which carry the credentials, the request and correlation ids and the
|
|
5
|
+
* tenant, as they do on a route.
|
|
6
|
+
*/
|
|
7
|
+
export interface RpcContext {
|
|
8
|
+
readonly headers: RawHeaders;
|
|
9
|
+
/**
|
|
10
|
+
* What `resolvePrincipal` reads. Left out, `{ headers }`: what `principalResolver` of
|
|
11
|
+
* `@ddd-ts-kit/auth` reads the bearer credential from.
|
|
12
|
+
*/
|
|
13
|
+
readonly raw?: unknown;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=rpc-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc-context.d.ts","sourceRoot":"","sources":["../../src/rpc/rpc-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEvD;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7B;;;OAGG;IACH,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;CACxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc-context.js","sourceRoot":"","sources":["../../src/rpc/rpc-context.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a procedure is called with: the parameters of its route by place and its body, the input of
|
|
3
|
+
* the operation in the client `ddd-ts-kit sdk` generates. Left out, nothing.
|
|
4
|
+
*/
|
|
5
|
+
export interface RpcInput {
|
|
6
|
+
readonly path?: unknown;
|
|
7
|
+
readonly query?: unknown;
|
|
8
|
+
readonly header?: Readonly<Record<string, unknown>>;
|
|
9
|
+
readonly body?: unknown;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=rpc-input.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc-input.d.ts","sourceRoot":"","sources":["../../src/rpc/rpc-input.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACpD,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;CACzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc-input.js","sourceRoot":"","sources":["../../src/rpc/rpc-input.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Problem } from '../error/problem.js';
|
|
2
|
+
/** A refusal of a route, as a procedure throws it in the error of its protocol. */
|
|
3
|
+
export interface RpcRefusal {
|
|
4
|
+
readonly status: number;
|
|
5
|
+
/** The code of the problem, or `HTTP_<status>` for a refusal the route answers without one. */
|
|
6
|
+
readonly code: string;
|
|
7
|
+
/** The sentence of the problem, its detail or else its title; the code for a refusal without one. */
|
|
8
|
+
readonly message: string;
|
|
9
|
+
/** Absent for a refusal the route answers without a problem document. */
|
|
10
|
+
readonly problem: Problem | undefined;
|
|
11
|
+
/** What the route answered: the problem, or its own body. */
|
|
12
|
+
readonly body: unknown;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=rpc-refusal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc-refusal.d.ts","sourceRoot":"","sources":["../../src/rpc/rpc-refusal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAEhD,mFAAmF;AACnF,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,+FAA+F;IAC/F,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,qGAAqG;IACrG,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,yEAAyE;IACzE,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,SAAS,CAAC;IACtC,6DAA6D;IAC7D,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;CACxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc-refusal.js","sourceRoot":"","sources":["../../src/rpc/rpc-refusal.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { RawRequest } from '../pipeline/raw-request.js';
|
|
2
|
+
import type { RpcContext } from './rpc-context.js';
|
|
3
|
+
/**
|
|
4
|
+
* The request the pipeline runs for a call: the parameters and the body of its input, the headers
|
|
5
|
+
* of the RPC request with those of its input over them. It accepts and sends JSON only, whatever
|
|
6
|
+
* the RPC request says: a representation other than JSON belongs to the HTTP routes.
|
|
7
|
+
*/
|
|
8
|
+
export declare function rpcRequest(input: unknown, context: RpcContext): RawRequest;
|
|
9
|
+
//# sourceMappingURL=rpc-request.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc-request.d.ts","sourceRoot":"","sources":["../../src/rpc/rpc-request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAG1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAOhD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,GAAG,UAAU,CAW1E"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { isRecord } from '../support/is-record.js';
|
|
2
|
+
const JSON_MEDIA_TYPE = 'application/json';
|
|
3
|
+
/** Headers that describe the RPC request itself, not the call it carries. */
|
|
4
|
+
const TRANSPORT_HEADERS = new Set(['content-length', 'content-type', 'transfer-encoding']);
|
|
5
|
+
/**
|
|
6
|
+
* The request the pipeline runs for a call: the parameters and the body of its input, the headers
|
|
7
|
+
* of the RPC request with those of its input over them. It accepts and sends JSON only, whatever
|
|
8
|
+
* the RPC request says: a representation other than JSON belongs to the HTTP routes.
|
|
9
|
+
*/
|
|
10
|
+
export function rpcRequest(input, context) {
|
|
11
|
+
const { path, query, header, body } = inputOf(input);
|
|
12
|
+
const headers = {
|
|
13
|
+
...Object.fromEntries(Object.entries(context.headers).filter(([name]) => !TRANSPORT_HEADERS.has(name))),
|
|
14
|
+
...headersOf(header),
|
|
15
|
+
accept: JSON_MEDIA_TYPE,
|
|
16
|
+
...(body === undefined ? {} : { 'content-type': JSON_MEDIA_TYPE }),
|
|
17
|
+
};
|
|
18
|
+
return { params: path ?? {}, query: query ?? {}, headers, body, raw: context.raw ?? { headers } };
|
|
19
|
+
}
|
|
20
|
+
function inputOf(input) {
|
|
21
|
+
return isRecord(input) ? input : {};
|
|
22
|
+
}
|
|
23
|
+
/** The names in lower case, as Node reads them; a value that is not a string is sent as its text. */
|
|
24
|
+
function headersOf(header) {
|
|
25
|
+
const entries = Object.entries(header ?? {}).filter(([, value]) => value !== undefined && value !== null);
|
|
26
|
+
return Object.fromEntries(entries.map(([name, value]) => [name.toLowerCase(), String(value)]));
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=rpc-request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc-request.js","sourceRoot":"","sources":["../../src/rpc/rpc-request.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAIhD,MAAM,eAAe,GAAG,kBAAkB,CAAC;AAC3C,6EAA6E;AAC7E,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC,CAAC,gBAAgB,EAAE,cAAc,EAAE,mBAAmB,CAAC,CAAC,CAAC;AAE3F;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,KAAc,EAAE,OAAmB;IAC5D,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;IAErD,MAAM,OAAO,GAAe;QAC1B,GAAG,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;QACvG,GAAG,SAAS,CAAC,MAAM,CAAC;QACpB,MAAM,EAAE,eAAe;QACvB,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,eAAe,EAAE,CAAC;KACnE,CAAC;IAEF,OAAO,EAAE,MAAM,EAAE,IAAI,IAAI,EAAE,EAAE,KAAK,EAAE,KAAK,IAAI,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC;AACpG,CAAC;AAED,SAAS,OAAO,CAAC,KAAc;IAC7B,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;AACtC,CAAC;AAED,qGAAqG;AACrG,SAAS,SAAS,CAAC,MAA0B;IAC3C,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC;IAE1G,OAAO,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AACjG,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Problem } from '../error/problem.js';
|
|
2
|
+
import type { RpcRefusal } from '../rpc/rpc-refusal.js';
|
|
3
|
+
/** The cause of the `TRPCError` of a refusal: what the error formatter of `trpcRouter` reads the problem from. */
|
|
4
|
+
export declare class RouteRefusal extends Error {
|
|
5
|
+
readonly problem: Problem | undefined;
|
|
6
|
+
constructor(refusal: RpcRefusal);
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=route-refusal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-refusal.d.ts","sourceRoot":"","sources":["../../src/trpc/route-refusal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,kHAAkH;AAClH,qBAAa,YAAa,SAAQ,KAAK;IACrC,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,SAAS,CAAC;IAEtC,YAAY,OAAO,EAAE,UAAU,EAI9B;CACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** The cause of the `TRPCError` of a refusal: what the error formatter of `trpcRouter` reads the problem from. */
|
|
2
|
+
export class RouteRefusal extends Error {
|
|
3
|
+
problem;
|
|
4
|
+
constructor(refusal) {
|
|
5
|
+
super(refusal.message);
|
|
6
|
+
this.name = 'RouteRefusal';
|
|
7
|
+
this.problem = refusal.problem;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=route-refusal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-refusal.js","sourceRoot":"","sources":["../../src/trpc/route-refusal.ts"],"names":[],"mappings":"AAGA,kHAAkH;AAClH,MAAM,OAAO,YAAa,SAAQ,KAAK;IAC5B,OAAO,CAAsB;IAEtC,YAAY,OAAmB;QAC7B,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IACjC,CAAC;CACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { TRPC_ERROR_CODE_KEY, TRPCErrorShape } from '@trpc/server';
|
|
2
|
+
import type { Problem } from '../error/problem.js';
|
|
3
|
+
/** The data of an error of `trpcRouter`, what `error.data` holds for a client. */
|
|
4
|
+
export interface TrpcErrorData {
|
|
5
|
+
readonly code: TRPC_ERROR_CODE_KEY;
|
|
6
|
+
readonly httpStatus: number;
|
|
7
|
+
readonly path?: string;
|
|
8
|
+
/**
|
|
9
|
+
* The problem document the route answered: its `code`, the one of the kit, its status, its
|
|
10
|
+
* issues. `null` for a refusal the route answers without one, and for an error of tRPC itself
|
|
11
|
+
* (an unknown procedure, a request it cannot read).
|
|
12
|
+
*/
|
|
13
|
+
readonly problem: Problem | null;
|
|
14
|
+
}
|
|
15
|
+
/** The error of `trpcRouter`, as a client of its type reads it. */
|
|
16
|
+
export type TrpcErrorShape = TRPCErrorShape<TrpcErrorData>;
|
|
17
|
+
//# sourceMappingURL=trpc-error-shape.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trpc-error-shape.d.ts","sourceRoot":"","sources":["../../src/trpc/trpc-error-shape.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACxE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAEhD,kFAAkF;AAClF,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAC;IACnC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB;;;;OAIG;IACH,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;CAClC;AAED,mEAAmE;AACnE,MAAM,MAAM,cAAc,GAAG,cAAc,CAAC,aAAa,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trpc-error-shape.js","sourceRoot":"","sources":["../../src/trpc/trpc-error-shape.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { RpcProtocol } from '../rpc/rpc-answer.js';
|
|
2
|
+
/**
|
|
3
|
+
* A refusal is a `TRPCError` of the code tRPC has for its status, `UNAUTHORIZED` for 401,
|
|
4
|
+
* `CONFLICT` for 409, whose cause carries the problem document: its code, the one of the kit, is
|
|
5
|
+
* what a client tells refusals apart by, as tRPC has a fixed set of codes of its own.
|
|
6
|
+
*/
|
|
7
|
+
export declare const TRPC_PROTOCOL: RpcProtocol;
|
|
8
|
+
//# sourceMappingURL=trpc-protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trpc-protocol.d.ts","sourceRoot":"","sources":["../../src/trpc/trpc-protocol.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AA8BrD;;;;GAIG;AACH,eAAO,MAAM,aAAa,EAAE,WAA2D,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { TRPCError } from '@trpc/server';
|
|
2
|
+
import { RouteRefusal } from './route-refusal.js';
|
|
3
|
+
const FIRST_SERVER_FAULT = 500;
|
|
4
|
+
/** The code of tRPC for each status it knows: a status it does not know is a bad request, or a server fault. */
|
|
5
|
+
const CODES_BY_STATUS = {
|
|
6
|
+
400: 'BAD_REQUEST',
|
|
7
|
+
401: 'UNAUTHORIZED',
|
|
8
|
+
402: 'PAYMENT_REQUIRED',
|
|
9
|
+
403: 'FORBIDDEN',
|
|
10
|
+
404: 'NOT_FOUND',
|
|
11
|
+
405: 'METHOD_NOT_SUPPORTED',
|
|
12
|
+
408: 'TIMEOUT',
|
|
13
|
+
409: 'CONFLICT',
|
|
14
|
+
412: 'PRECONDITION_FAILED',
|
|
15
|
+
413: 'PAYLOAD_TOO_LARGE',
|
|
16
|
+
415: 'UNSUPPORTED_MEDIA_TYPE',
|
|
17
|
+
422: 'UNPROCESSABLE_CONTENT',
|
|
18
|
+
428: 'PRECONDITION_REQUIRED',
|
|
19
|
+
429: 'TOO_MANY_REQUESTS',
|
|
20
|
+
499: 'CLIENT_CLOSED_REQUEST',
|
|
21
|
+
500: 'INTERNAL_SERVER_ERROR',
|
|
22
|
+
501: 'NOT_IMPLEMENTED',
|
|
23
|
+
502: 'BAD_GATEWAY',
|
|
24
|
+
503: 'SERVICE_UNAVAILABLE',
|
|
25
|
+
504: 'GATEWAY_TIMEOUT',
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* A refusal is a `TRPCError` of the code tRPC has for its status, `UNAUTHORIZED` for 401,
|
|
29
|
+
* `CONFLICT` for 409, whose cause carries the problem document: its code, the one of the kit, is
|
|
30
|
+
* what a client tells refusals apart by, as tRPC has a fixed set of codes of its own.
|
|
31
|
+
*/
|
|
32
|
+
export const TRPC_PROTOCOL = { refuse: trpcErrorOf, carriesBinary: false };
|
|
33
|
+
function trpcErrorOf(refusal) {
|
|
34
|
+
return new TRPCError({
|
|
35
|
+
code: codeOf(refusal.status),
|
|
36
|
+
message: refusal.message,
|
|
37
|
+
cause: new RouteRefusal(refusal),
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
function codeOf(status) {
|
|
41
|
+
return CODES_BY_STATUS[status] ?? (status < FIRST_SERVER_FAULT ? 'BAD_REQUEST' : 'INTERNAL_SERVER_ERROR');
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=trpc-protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trpc-protocol.js","sourceRoot":"","sources":["../../src/trpc/trpc-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA4B,MAAM,cAAc,CAAC;AAGnE,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAE/B,gHAAgH;AAChH,MAAM,eAAe,GAAkD;IACrE,GAAG,EAAE,aAAa;IAClB,GAAG,EAAE,cAAc;IACnB,GAAG,EAAE,kBAAkB;IACvB,GAAG,EAAE,WAAW;IAChB,GAAG,EAAE,WAAW;IAChB,GAAG,EAAE,sBAAsB;IAC3B,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,UAAU;IACf,GAAG,EAAE,qBAAqB;IAC1B,GAAG,EAAE,mBAAmB;IACxB,GAAG,EAAE,wBAAwB;IAC7B,GAAG,EAAE,uBAAuB;IAC5B,GAAG,EAAE,uBAAuB;IAC5B,GAAG,EAAE,mBAAmB;IACxB,GAAG,EAAE,uBAAuB;IAC5B,GAAG,EAAE,uBAAuB;IAC5B,GAAG,EAAE,iBAAiB;IACtB,GAAG,EAAE,aAAa;IAClB,GAAG,EAAE,qBAAqB;IAC1B,GAAG,EAAE,iBAAiB;CACvB,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAgB,EAAE,MAAM,EAAE,WAAW,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC;AAExF,SAAS,WAAW,CAAC,OAAmB;IACtC,OAAO,IAAI,SAAS,CAAC;QACnB,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;QAC5B,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,KAAK,EAAE,IAAI,YAAY,CAAC,OAAO,CAAC;KACjC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,MAAM,CAAC,MAAc;IAC5B,OAAO,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,kBAAkB,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC;AAC5G,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type TRPCBuiltRouter, type TRPCMutationProcedure, type TRPCQueryProcedure } from '@trpc/server';
|
|
2
|
+
import type { ExecuteOptions } from '../pipeline/execute-options.js';
|
|
3
|
+
import type { Route } from '../route/route.js';
|
|
4
|
+
import type { RpcContext } from '../rpc/rpc-context.js';
|
|
5
|
+
import type { TrpcErrorShape } from './trpc-error-shape.js';
|
|
6
|
+
/** One procedure of `trpcRouter`: its input and output are checked by the schemas of its route, not by tRPC. */
|
|
7
|
+
export type TrpcProcedure = TRPCQueryProcedure<{
|
|
8
|
+
input: unknown;
|
|
9
|
+
output: unknown;
|
|
10
|
+
meta: object;
|
|
11
|
+
}> | TRPCMutationProcedure<{
|
|
12
|
+
input: unknown;
|
|
13
|
+
output: unknown;
|
|
14
|
+
meta: object;
|
|
15
|
+
}>;
|
|
16
|
+
/** The root of `trpcRouter`: the context the server hands over, and the error a client reads. */
|
|
17
|
+
export interface TrpcRootTypes {
|
|
18
|
+
ctx: RpcContext;
|
|
19
|
+
meta: object;
|
|
20
|
+
errorShape: TrpcErrorShape;
|
|
21
|
+
transformer: false;
|
|
22
|
+
}
|
|
23
|
+
/** The procedures of `trpcRouter`, by the `operationId` of their route. */
|
|
24
|
+
export type TrpcRouter = TRPCBuiltRouter<TrpcRootTypes, Record<string, TrpcProcedure>>;
|
|
25
|
+
/**
|
|
26
|
+
* The routes as tRPC procedures, one per `operationId`, a query for a `GET` and a mutation for the
|
|
27
|
+
* other methods, for the adapters of `@trpc/server`: a typed client calls the use cases without
|
|
28
|
+
* paths or methods. Each call runs through `executeRoute` with the same options as the HTTP adapter
|
|
29
|
+
* (guards, principal, tenant, validation, permissions, error hook, tracing), and a refusal is a
|
|
30
|
+
* `TRPCError` whose `data.problem` is the problem document of the route, its `code` the one of the kit.
|
|
31
|
+
*
|
|
32
|
+
* What only HTTP carries stays with the routes: a route that receives a file or a raw body is not
|
|
33
|
+
* a procedure; an answer is JSON whatever the representations; its headers are not returned, so no
|
|
34
|
+
* cache keeps it and an `ETag` is not read through it; a file, a binary body or a streamed list is
|
|
35
|
+
* refused 406.
|
|
36
|
+
*/
|
|
37
|
+
export declare function trpcRouter(routes: readonly Route[], options?: ExecuteOptions): TrpcRouter;
|
|
38
|
+
//# sourceMappingURL=trpc-router.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trpc-router.d.ts","sourceRoot":"","sources":["../../src/trpc/trpc-router.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,eAAe,EAGpB,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACxB,MAAM,cAAc,CAAC;AAGtB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAGlE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAIzD,gHAAgH;AAChH,MAAM,MAAM,aAAa,GACrB,kBAAkB,CAAC;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,GACrE,qBAAqB,CAAC;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAE7E,iGAAiG;AACjG,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,UAAU,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,cAAc,CAAC;IAC3B,WAAW,EAAE,KAAK,CAAC;CACpB;AAED,2EAA2E;AAC3E,MAAM,MAAM,UAAU,GAAG,eAAe,CAAC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC;AAIvF;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,EAAE,OAAO,GAAE,cAAmB,GAAG,UAAU,CAU7F"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { initTRPC, } from '@trpc/server';
|
|
2
|
+
import { createErrorMapper } from '../error/create-error-mapper.js';
|
|
3
|
+
import { executeRoute } from '../pipeline/execute-route.js';
|
|
4
|
+
import { assertUniqueRoutes } from '../route/assert-unique-routes.js';
|
|
5
|
+
import { rpcAnswer } from '../rpc/rpc-answer.js';
|
|
6
|
+
import { rpcRequest } from '../rpc/rpc-request.js';
|
|
7
|
+
import { RouteRefusal } from './route-refusal.js';
|
|
8
|
+
import { TRPC_PROTOCOL } from './trpc-protocol.js';
|
|
9
|
+
const trpc = initTRPC.context().create({ errorFormatter: formatError });
|
|
10
|
+
/**
|
|
11
|
+
* The routes as tRPC procedures, one per `operationId`, a query for a `GET` and a mutation for the
|
|
12
|
+
* other methods, for the adapters of `@trpc/server`: a typed client calls the use cases without
|
|
13
|
+
* paths or methods. Each call runs through `executeRoute` with the same options as the HTTP adapter
|
|
14
|
+
* (guards, principal, tenant, validation, permissions, error hook, tracing), and a refusal is a
|
|
15
|
+
* `TRPCError` whose `data.problem` is the problem document of the route, its `code` the one of the kit.
|
|
16
|
+
*
|
|
17
|
+
* What only HTTP carries stays with the routes: a route that receives a file or a raw body is not
|
|
18
|
+
* a procedure; an answer is JSON whatever the representations; its headers are not returned, so no
|
|
19
|
+
* cache keeps it and an `ETag` is not read through it; a file, a binary body or a streamed list is
|
|
20
|
+
* refused 406.
|
|
21
|
+
*/
|
|
22
|
+
export function trpcRouter(routes, options = {}) {
|
|
23
|
+
assertUniqueRoutes(routes);
|
|
24
|
+
const mapper = options.errorMapper ?? createErrorMapper();
|
|
25
|
+
const served = routes.filter((route) => route.upload === undefined && route.rawBody !== true);
|
|
26
|
+
const execute = withoutRepresentations(options);
|
|
27
|
+
return trpc.router(Object.fromEntries(served.map((route) => [route.operationId, procedureOf(route, execute, mapper)])));
|
|
28
|
+
}
|
|
29
|
+
/** tRPC writes the answer: no representation is negotiated, and a list read as it comes stays the body, closed when refused. */
|
|
30
|
+
function withoutRepresentations({ representations, ...options }) {
|
|
31
|
+
return options;
|
|
32
|
+
}
|
|
33
|
+
function procedureOf(route, options, mapper) {
|
|
34
|
+
const procedure = trpc.procedure.input((input) => input);
|
|
35
|
+
const resolve = async ({ input, ctx }) => rpcAnswer(await executeRoute(route, rpcRequest(input, ctx), options), TRPC_PROTOCOL, mapper);
|
|
36
|
+
return route.method === 'GET' ? procedure.query(resolve) : procedure.mutation(resolve);
|
|
37
|
+
}
|
|
38
|
+
/** The data of the error, without the stack tRPC adds in development: the problem document is what the client reads. */
|
|
39
|
+
function formatError({ shape, error }) {
|
|
40
|
+
const { stack, ...data } = shape.data;
|
|
41
|
+
const problem = error.cause instanceof RouteRefusal ? (error.cause.problem ?? null) : null;
|
|
42
|
+
return { ...shape, data: { ...data, problem } };
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=trpc-router.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trpc-router.js","sourceRoot":"","sources":["../../src/trpc/trpc-router.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,GAMT,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAGjE,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAEnE,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAkBhD,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,EAAc,CAAC,MAAM,CAAC,EAAE,cAAc,EAAE,WAAW,EAAE,CAAC,CAAC;AAEpF;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,UAAU,CAAC,MAAwB,EAAE,OAAO,GAAmB,EAAE;IAC/E,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAE3B,MAAM,MAAM,GAAG,OAAO,CAAC,WAAW,IAAI,iBAAiB,EAAE,CAAC;IAC1D,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,KAAK,SAAS,IAAI,KAAK,CAAC,OAAO,KAAK,IAAI,CAAC,CAAC;IAC9F,MAAM,OAAO,GAAG,sBAAsB,CAAC,OAAO,CAAC,CAAC;IAEhD,OAAO,IAAI,CAAC,MAAM,CAChB,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,WAAW,EAAE,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CACpG,CAAC;AACJ,CAAC;AAED,gIAAgI;AAChI,SAAS,sBAAsB,CAAC,EAAE,eAAe,EAAE,GAAG,OAAO,EAAkB;IAC7E,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,WAAW,CAAC,KAAY,EAAE,OAAuB,EAAE,MAAmB;IAC7E,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC;IAElE,MAAM,OAAO,GAAG,KAAK,EAAE,EAAE,KAAK,EAAE,GAAG,EAAuC,EAAoB,EAAE,CAC9F,SAAS,CAAC,MAAM,YAAY,CAAC,KAAK,EAAE,UAAU,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,OAAO,CAAC,EAAE,aAAa,EAAE,MAAM,CAAC,CAAC;IAE/F,OAAO,KAAK,CAAC,MAAM,KAAK,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AACzF,CAAC;AAED,wHAAwH;AACxH,SAAS,WAAW,CAAC,EAAE,KAAK,EAAE,KAAK,EAAsD;IACvF,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC,IAAI,CAAC;IACtC,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,YAAY,YAAY,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAE3F,OAAO,EAAE,GAAG,KAAK,EAAE,IAAI,EAAE,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC;AAClD,CAAC"}
|
package/dist/trpc.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { RpcContext as TrpcContext } from './rpc/rpc-context.js';
|
|
2
|
+
export type { RpcInput as TrpcInput } from './rpc/rpc-input.js';
|
|
3
|
+
export type { TrpcErrorData, TrpcErrorShape } from './trpc/trpc-error-shape.js';
|
|
4
|
+
export { type TrpcProcedure, type TrpcRootTypes, type TrpcRouter, trpcRouter } from './trpc/trpc-router.js';
|
|
5
|
+
//# sourceMappingURL=trpc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trpc.d.ts","sourceRoot":"","sources":["../src/trpc.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,UAAU,IAAI,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACnE,YAAY,EAAE,QAAQ,IAAI,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC7D,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC7E,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,aAAa,EAAE,KAAK,UAAU,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/trpc.js
ADDED
package/dist/trpc.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trpc.js","sourceRoot":"","sources":["../src/trpc.ts"],"names":[],"mappings":"AAGA,OAAO,EAA2D,UAAU,EAAE,MAAM,oBAAoB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ddd-ts-kit/http",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Framework-agnostic route definitions with Express, Fastify, Hono and NestJS adapters and OpenAPI 3.1 generation.",
|
|
3
|
+
"version": "0.91.0",
|
|
4
|
+
"description": "Framework-agnostic route definitions with Express, Fastify, Hono and NestJS adapters, oRPC and tRPC procedures and OpenAPI 3.1 generation.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ddd",
|
|
7
7
|
"domain-driven-design",
|
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
"fastify",
|
|
13
13
|
"hono",
|
|
14
14
|
"nestjs",
|
|
15
|
+
"orpc",
|
|
16
|
+
"trpc",
|
|
15
17
|
"openapi",
|
|
16
18
|
"rest-api"
|
|
17
19
|
],
|
|
@@ -50,6 +52,14 @@
|
|
|
50
52
|
"types": "./dist/nest.d.ts",
|
|
51
53
|
"default": "./dist/nest.js"
|
|
52
54
|
},
|
|
55
|
+
"./orpc": {
|
|
56
|
+
"types": "./dist/orpc.d.ts",
|
|
57
|
+
"default": "./dist/orpc.js"
|
|
58
|
+
},
|
|
59
|
+
"./trpc": {
|
|
60
|
+
"types": "./dist/trpc.d.ts",
|
|
61
|
+
"default": "./dist/trpc.js"
|
|
62
|
+
},
|
|
53
63
|
"./openapi": {
|
|
54
64
|
"types": "./dist/openapi.d.ts",
|
|
55
65
|
"default": "./dist/openapi.js"
|
|
@@ -71,16 +81,18 @@
|
|
|
71
81
|
"dist"
|
|
72
82
|
],
|
|
73
83
|
"dependencies": {
|
|
74
|
-
"@ddd-ts-kit/kernel": "0.
|
|
75
|
-
"@ddd-ts-kit/validation": "0.
|
|
84
|
+
"@ddd-ts-kit/kernel": "0.91.0",
|
|
85
|
+
"@ddd-ts-kit/validation": "0.91.0"
|
|
76
86
|
},
|
|
77
87
|
"peerDependencies": {
|
|
78
88
|
"@nestjs/common": ">=11.0.0",
|
|
79
89
|
"@nestjs/core": ">=11.0.0",
|
|
90
|
+
"@orpc/server": "^1.15.0",
|
|
91
|
+
"@trpc/server": "^11.10.0",
|
|
92
|
+
"busboy": "^1.6.0",
|
|
80
93
|
"express": "^5.0.0",
|
|
81
94
|
"fastify": "^5.0.0",
|
|
82
|
-
"hono": "^4.0.0"
|
|
83
|
-
"busboy": "^1.6.0"
|
|
95
|
+
"hono": "^4.0.0"
|
|
84
96
|
},
|
|
85
97
|
"peerDependenciesMeta": {
|
|
86
98
|
"express": {
|
|
@@ -100,15 +112,26 @@
|
|
|
100
112
|
},
|
|
101
113
|
"busboy": {
|
|
102
114
|
"optional": true
|
|
115
|
+
},
|
|
116
|
+
"@orpc/server": {
|
|
117
|
+
"optional": true
|
|
118
|
+
},
|
|
119
|
+
"@trpc/server": {
|
|
120
|
+
"optional": true
|
|
103
121
|
}
|
|
104
122
|
},
|
|
105
123
|
"devDependencies": {
|
|
106
|
-
"@ddd-ts-kit/testing": "0.
|
|
124
|
+
"@ddd-ts-kit/testing": "0.91.0",
|
|
107
125
|
"@hono/node-server": "^2.1.4",
|
|
108
126
|
"@nestjs/common": "^12.2.0",
|
|
109
127
|
"@nestjs/core": "^12.2.0",
|
|
110
128
|
"@nestjs/platform-express": "^12.2.0",
|
|
111
129
|
"@nestjs/platform-fastify": "^12.2.0",
|
|
130
|
+
"@orpc/client": "^1.16.1",
|
|
131
|
+
"@orpc/contract": "^1.16.1",
|
|
132
|
+
"@orpc/server": "^1.16.1",
|
|
133
|
+
"@trpc/client": "^11.19.0",
|
|
134
|
+
"@trpc/server": "^11.19.0",
|
|
112
135
|
"@types/busboy": "^1.5.5",
|
|
113
136
|
"@types/express": "^5.0.0",
|
|
114
137
|
"busboy": "^1.6.0",
|