@temporary-name/server 1.9.3-alpha.1a5ff4923d25c9d83e80d717687ebc859f5312f2 → 1.9.3-alpha.205fb2d0874fa3b8bbf83112a63016937380442e

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.
Files changed (46) hide show
  1. package/dist/adapters/aws-lambda/index.d.mts +5 -7
  2. package/dist/adapters/aws-lambda/index.d.ts +5 -7
  3. package/dist/adapters/aws-lambda/index.mjs +5 -6
  4. package/dist/adapters/fetch/index.d.mts +8 -86
  5. package/dist/adapters/fetch/index.d.ts +8 -86
  6. package/dist/adapters/fetch/index.mjs +17 -157
  7. package/dist/adapters/node/index.d.mts +9 -64
  8. package/dist/adapters/node/index.d.ts +9 -64
  9. package/dist/adapters/node/index.mjs +15 -122
  10. package/dist/handler/index.d.mts +28 -0
  11. package/dist/handler/index.d.ts +28 -0
  12. package/dist/handler/index.mjs +8 -0
  13. package/dist/helpers/index.mjs +3 -29
  14. package/dist/index.d.mts +366 -213
  15. package/dist/index.d.ts +366 -213
  16. package/dist/index.mjs +484 -178
  17. package/dist/openapi/index.d.mts +18 -53
  18. package/dist/openapi/index.d.ts +18 -53
  19. package/dist/openapi/index.mjs +391 -368
  20. package/dist/shared/server.B5ntjz_x.d.mts +800 -0
  21. package/dist/shared/server.B5ntjz_x.d.ts +800 -0
  22. package/dist/shared/server.BGG3eatg.mjs +315 -0
  23. package/dist/shared/server.BM9lK_Yv.mjs +523 -0
  24. package/dist/shared/server.BxyeakF-.d.mts +39 -0
  25. package/dist/shared/server.C1RJffw4.mjs +30 -0
  26. package/dist/shared/server.CjPiuQYH.d.mts +51 -0
  27. package/dist/shared/server.CjPiuQYH.d.ts +51 -0
  28. package/dist/shared/server.CmNVzZVe.mjs +156 -0
  29. package/dist/shared/server.Coz0LFSE.d.ts +39 -0
  30. package/dist/shared/server.X8F6e8eV.mjs +499 -0
  31. package/package.json +13 -31
  32. package/dist/adapters/standard/index.d.mts +0 -31
  33. package/dist/adapters/standard/index.d.ts +0 -31
  34. package/dist/adapters/standard/index.mjs +0 -9
  35. package/dist/plugins/index.d.mts +0 -160
  36. package/dist/plugins/index.d.ts +0 -160
  37. package/dist/plugins/index.mjs +0 -288
  38. package/dist/shared/server.B--sAUhn.mjs +0 -254
  39. package/dist/shared/server.BCcLYvdF.d.mts +0 -56
  40. package/dist/shared/server.CHV9AQHl.mjs +0 -412
  41. package/dist/shared/server.CdeqmULw.d.ts +0 -56
  42. package/dist/shared/server.DHezmW6C.d.mts +0 -23
  43. package/dist/shared/server.Da-qLzdU.d.ts +0 -23
  44. package/dist/shared/server.DecvGKtb.d.mts +0 -242
  45. package/dist/shared/server.DecvGKtb.d.ts +0 -242
  46. package/dist/shared/server.Kxw442A9.mjs +0 -247
@@ -1,288 +0,0 @@
1
- import { runWithSpan, value, setSpanError, isAsyncIteratorObject, AsyncIteratorClass, clone, ORPCError } from '@temporary-name/shared';
2
- import { flattenHeader } from '@temporary-name/standard-server';
3
- import { parseBatchRequest, toBatchResponse } from '@temporary-name/standard-server/batch';
4
- import { toFetchHeaders } from '@temporary-name/standard-server-fetch';
5
-
6
- class BatchHandlerPlugin {
7
- maxSize;
8
- mapRequestItem;
9
- successStatus;
10
- headers;
11
- order = 5e6;
12
- constructor(options = {}) {
13
- this.maxSize = options.maxSize ?? 10;
14
- this.mapRequestItem = options.mapRequestItem ?? ((request, { request: batchRequest }) => ({
15
- ...request,
16
- headers: {
17
- ...batchRequest.headers,
18
- ...request.headers
19
- }
20
- }));
21
- this.successStatus = options.successStatus ?? 207;
22
- this.headers = options.headers ?? {};
23
- }
24
- init(options) {
25
- options.rootInterceptors ??= [];
26
- options.rootInterceptors.unshift(async (options2) => {
27
- const xHeader = flattenHeader(options2.request.headers["x-orpc-batch"]);
28
- if (xHeader === void 0) {
29
- return options2.next();
30
- }
31
- let isParsing = false;
32
- try {
33
- return await runWithSpan({ name: "handle_batch_request" }, async (span) => {
34
- const mode = xHeader === "buffered" ? "buffered" : "streaming";
35
- isParsing = true;
36
- const parsed = parseBatchRequest({ ...options2.request, body: await options2.request.body() });
37
- isParsing = false;
38
- span?.setAttribute("batch.mode", mode);
39
- span?.setAttribute("batch.size", parsed.length);
40
- const maxSize = await value(this.maxSize, options2);
41
- if (parsed.length > maxSize) {
42
- const message = "Batch request size exceeds the maximum allowed size";
43
- setSpanError(span, message);
44
- return {
45
- matched: true,
46
- response: {
47
- status: 413,
48
- headers: {},
49
- body: message
50
- }
51
- };
52
- }
53
- const responses = parsed.map((request, index) => {
54
- const mapped = this.mapRequestItem(request, options2);
55
- return options2.next({ ...options2, request: { ...mapped, body: () => Promise.resolve(mapped.body) } }).then(({ response: response2, matched }) => {
56
- span?.addEvent(`response.${index}.${matched ? "success" : "not_matched"}`);
57
- if (matched) {
58
- if (response2.body instanceof Blob || response2.body instanceof FormData || isAsyncIteratorObject(response2.body)) {
59
- return {
60
- index,
61
- status: 500,
62
- headers: {},
63
- body: "Batch responses do not support file/blob, or event-iterator. Please call this procedure separately outside of the batch request."
64
- };
65
- }
66
- return { ...response2, index };
67
- }
68
- return { index, status: 404, headers: {}, body: "No procedure matched" };
69
- }).catch((err) => {
70
- Promise.reject(err);
71
- return { index, status: 500, headers: {}, body: "Internal server error" };
72
- });
73
- });
74
- await Promise.race(responses);
75
- const status = await value(this.successStatus, responses, options2);
76
- const headers = await value(this.headers, responses, options2);
77
- const promises = [...responses];
78
- const response = await toBatchResponse({
79
- status,
80
- headers,
81
- mode,
82
- body: new AsyncIteratorClass(
83
- async () => {
84
- const handling = promises.filter((p) => p !== void 0);
85
- if (handling.length <= 0) {
86
- return { done: true, value: void 0 };
87
- }
88
- const value2 = await Promise.race(handling);
89
- promises[value2.index] = void 0;
90
- return { done: false, value: value2 };
91
- },
92
- async () => {
93
- }
94
- )
95
- });
96
- return {
97
- matched: true,
98
- response
99
- };
100
- });
101
- } catch (cause) {
102
- if (isParsing) {
103
- return {
104
- matched: true,
105
- response: {
106
- status: 400,
107
- headers: {},
108
- body: "Invalid batch request, this could be caused by a malformed request body or a missing header"
109
- }
110
- };
111
- }
112
- throw cause;
113
- }
114
- });
115
- }
116
- }
117
-
118
- class CORSPlugin {
119
- options;
120
- order = 9e6;
121
- constructor(options = {}) {
122
- const defaults = {
123
- origin: (origin) => origin,
124
- allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"]
125
- };
126
- this.options = {
127
- ...defaults,
128
- ...options
129
- };
130
- }
131
- init(options) {
132
- options.rootInterceptors ??= [];
133
- options.rootInterceptors.unshift(async (interceptorOptions) => {
134
- if (interceptorOptions.request.method === "OPTIONS") {
135
- const resHeaders = {};
136
- if (this.options.maxAge !== void 0) {
137
- resHeaders["access-control-max-age"] = this.options.maxAge.toString();
138
- }
139
- if (this.options.allowMethods?.length) {
140
- resHeaders["access-control-allow-methods"] = flattenHeader(this.options.allowMethods);
141
- }
142
- const allowHeaders = this.options.allowHeaders ?? interceptorOptions.request.headers["access-control-request-headers"];
143
- if (typeof allowHeaders === "string" || allowHeaders?.length) {
144
- resHeaders["access-control-allow-headers"] = flattenHeader(allowHeaders);
145
- }
146
- return {
147
- matched: true,
148
- response: {
149
- status: 204,
150
- headers: resHeaders,
151
- body: void 0
152
- }
153
- };
154
- }
155
- return interceptorOptions.next();
156
- });
157
- options.rootInterceptors.unshift(async (interceptorOptions) => {
158
- const result = await interceptorOptions.next();
159
- if (!result.matched) {
160
- return result;
161
- }
162
- const origin = flattenHeader(interceptorOptions.request.headers.origin) ?? "";
163
- const allowedOrigin = await value(this.options.origin, origin, interceptorOptions);
164
- const allowedOriginArr = Array.isArray(allowedOrigin) ? allowedOrigin : [allowedOrigin];
165
- if (allowedOriginArr.includes("*")) {
166
- result.response.headers["access-control-allow-origin"] = "*";
167
- } else {
168
- if (allowedOriginArr.includes(origin)) {
169
- result.response.headers["access-control-allow-origin"] = origin;
170
- }
171
- result.response.headers.vary = interceptorOptions.request.headers.vary ?? "origin";
172
- }
173
- const allowedTimingOrigin = await value(this.options.timingOrigin, origin, interceptorOptions);
174
- const allowedTimingOriginArr = Array.isArray(allowedTimingOrigin) ? allowedTimingOrigin : [allowedTimingOrigin];
175
- if (allowedTimingOriginArr.includes("*")) {
176
- result.response.headers["timing-allow-origin"] = "*";
177
- } else if (allowedTimingOriginArr.includes(origin)) {
178
- result.response.headers["timing-allow-origin"] = origin;
179
- }
180
- if (this.options.credentials) {
181
- result.response.headers["access-control-allow-credentials"] = "true";
182
- }
183
- if (this.options.exposeHeaders?.length) {
184
- result.response.headers["access-control-expose-headers"] = flattenHeader(this.options.exposeHeaders);
185
- }
186
- return result;
187
- });
188
- }
189
- }
190
-
191
- class RequestHeadersPlugin {
192
- init(options) {
193
- options.rootInterceptors ??= [];
194
- options.rootInterceptors.push((interceptorOptions) => {
195
- const reqHeaders = interceptorOptions.context.reqHeaders ?? toFetchHeaders(interceptorOptions.request.headers);
196
- return interceptorOptions.next({
197
- ...interceptorOptions,
198
- context: {
199
- ...interceptorOptions.context,
200
- reqHeaders
201
- }
202
- });
203
- });
204
- }
205
- }
206
-
207
- class ResponseHeadersPlugin {
208
- init(options) {
209
- options.rootInterceptors ??= [];
210
- options.rootInterceptors.push(async (interceptorOptions) => {
211
- const resHeaders = interceptorOptions.context.resHeaders ?? new Headers();
212
- const result = await interceptorOptions.next({
213
- ...interceptorOptions,
214
- context: {
215
- ...interceptorOptions.context,
216
- resHeaders
217
- }
218
- });
219
- if (!result.matched) {
220
- return result;
221
- }
222
- const responseHeaders = clone(result.response.headers);
223
- for (const [key, value] of resHeaders) {
224
- if (Array.isArray(responseHeaders[key])) {
225
- responseHeaders[key].push(value);
226
- } else if (responseHeaders[key] !== void 0) {
227
- responseHeaders[key] = [responseHeaders[key], value];
228
- } else {
229
- responseHeaders[key] = value;
230
- }
231
- }
232
- return {
233
- ...result,
234
- response: {
235
- ...result.response,
236
- headers: responseHeaders
237
- }
238
- };
239
- });
240
- }
241
- }
242
-
243
- const SIMPLE_CSRF_PROTECTION_CONTEXT_SYMBOL = Symbol("SIMPLE_CSRF_PROTECTION_CONTEXT");
244
- class SimpleCsrfProtectionHandlerPlugin {
245
- headerName;
246
- headerValue;
247
- exclude;
248
- error;
249
- constructor(options = {}) {
250
- this.headerName = options.headerName ?? "x-csrf-token";
251
- this.headerValue = options.headerValue ?? "orpc";
252
- this.exclude = options.exclude ?? false;
253
- this.error = options.error ?? new ORPCError("CSRF_TOKEN_MISMATCH", {
254
- status: 403,
255
- message: "Invalid CSRF token"
256
- });
257
- }
258
- order = 8e6;
259
- init(options) {
260
- options.rootInterceptors ??= [];
261
- options.clientInterceptors ??= [];
262
- options.rootInterceptors.unshift(async (options2) => {
263
- const headerName = await value(this.headerName, options2);
264
- const headerValue = await value(this.headerValue, options2);
265
- return options2.next({
266
- ...options2,
267
- context: {
268
- ...options2.context,
269
- [SIMPLE_CSRF_PROTECTION_CONTEXT_SYMBOL]: options2.request.headers[headerName] === headerValue
270
- }
271
- });
272
- });
273
- options.clientInterceptors.unshift(async (options2) => {
274
- if (typeof options2.context[SIMPLE_CSRF_PROTECTION_CONTEXT_SYMBOL] !== "boolean") {
275
- throw new TypeError(
276
- "[SimpleCsrfProtectionHandlerPlugin] CSRF protection context has been corrupted or modified by another plugin or interceptor"
277
- );
278
- }
279
- const excluded = await value(this.exclude, options2);
280
- if (!excluded && !options2.context[SIMPLE_CSRF_PROTECTION_CONTEXT_SYMBOL]) {
281
- throw this.error;
282
- }
283
- return options2.next();
284
- });
285
- }
286
- }
287
-
288
- export { BatchHandlerPlugin, CORSPlugin, RequestHeadersPlugin, ResponseHeadersPlugin, SimpleCsrfProtectionHandlerPlugin };
@@ -1,254 +0,0 @@
1
- import { stringifyJSON, isObject, isORPCErrorStatus, tryDecodeURIComponent, toHttpPath, toArray, intercept, runWithSpan, ORPC_NAME, isAsyncIteratorObject, asyncIteratorWithSpan, setSpanError, ORPCError, toORPCError } from '@temporary-name/shared';
2
- import { flattenHeader } from '@temporary-name/standard-server';
3
- import { c as createProcedureClient } from './server.CHV9AQHl.mjs';
4
- import { fallbackContractConfig } from '@temporary-name/contract';
5
- import { d as deserialize, b as bracketNotationDeserialize, s as serialize, a as standardizeHTTPPath } from './server.Kxw442A9.mjs';
6
- import { traverseContractProcedures, isProcedure, getLazyMeta, unlazy, getRouter, createContractedProcedure } from '@temporary-name/server';
7
- import { createRouter, addRoute, findRoute } from 'rou3';
8
-
9
- async function decode(request, pathParams) {
10
- return {
11
- path: pathParams ?? {},
12
- query: bracketNotationDeserialize(Array.from(request.url.searchParams.entries())),
13
- headers: request.headers,
14
- body: deserialize(await request.body()) ?? {}
15
- };
16
- }
17
- function encode(output, procedure) {
18
- const successStatus = fallbackContractConfig(
19
- "defaultSuccessStatus",
20
- procedure["~orpc"].route.successStatus
21
- );
22
- const outputStructure = fallbackContractConfig(
23
- "defaultOutputStructure",
24
- procedure["~orpc"].route.outputStructure
25
- );
26
- if (outputStructure === "compact") {
27
- return {
28
- status: successStatus,
29
- headers: {},
30
- body: serialize(output)
31
- };
32
- }
33
- if (!isDetailedOutput(output)) {
34
- throw new Error(`
35
- Invalid "detailed" output structure:
36
- \u2022 Expected an object with optional properties:
37
- - status (number 200-399)
38
- - headers (Record<string, string | string[]>)
39
- - body (any)
40
- \u2022 No extra keys allowed.
41
-
42
- Actual value:
43
- ${stringifyJSON(output)}
44
- `);
45
- }
46
- return {
47
- status: output.status ?? successStatus,
48
- headers: output.headers ?? {},
49
- body: serialize(output.body)
50
- };
51
- }
52
- function encodeError(error) {
53
- return {
54
- status: error.status,
55
- headers: {},
56
- body: serialize(error.toJSON(), { outputFormat: "plain" })
57
- };
58
- }
59
- function isDetailedOutput(output) {
60
- if (!isObject(output)) {
61
- return false;
62
- }
63
- if (output.headers && !isObject(output.headers)) {
64
- return false;
65
- }
66
- if (output.status !== void 0 && (typeof output.status !== "number" || !Number.isInteger(output.status) || isORPCErrorStatus(output.status))) {
67
- return false;
68
- }
69
- return true;
70
- }
71
-
72
- function resolveFriendlyStandardHandleOptions(options) {
73
- return {
74
- ...options,
75
- context: options.context ?? {}
76
- // Context only optional if all fields are optional
77
- };
78
- }
79
- function toRou3Pattern(path) {
80
- return standardizeHTTPPath(path).replace(/\/\{\+([^}]+)\}/g, "/**:$1").replace(/\/\{([^}]+)\}/g, "/:$1");
81
- }
82
- function decodeParams(params) {
83
- return Object.fromEntries(
84
- Object.entries(params).map(([key, value]) => [key, tryDecodeURIComponent(value)])
85
- );
86
- }
87
-
88
- class StandardOpenAPIMatcher {
89
- tree = createRouter();
90
- pendingRouters = [];
91
- init(router, path = []) {
92
- const laziedOptions = traverseContractProcedures({ router, path }, (traverseOptions) => {
93
- const { path: path2, contract } = traverseOptions;
94
- const method = fallbackContractConfig("defaultMethod", contract["~orpc"].route.method);
95
- const httpPath = toRou3Pattern(contract["~orpc"].route.path ?? toHttpPath(path2));
96
- if (isProcedure(contract)) {
97
- addRoute(this.tree, method, httpPath, {
98
- path: path2,
99
- contract,
100
- procedure: contract,
101
- // this mean dev not used contract-first so we can used contract as procedure directly
102
- router
103
- });
104
- } else {
105
- addRoute(this.tree, method, httpPath, {
106
- path: path2,
107
- contract,
108
- procedure: void 0,
109
- router
110
- });
111
- }
112
- });
113
- this.pendingRouters.push(
114
- ...laziedOptions.map((option) => ({
115
- ...option,
116
- httpPathPrefix: toHttpPath(option.path),
117
- laziedPrefix: getLazyMeta(option.router).prefix
118
- }))
119
- );
120
- }
121
- async match(method, pathname) {
122
- if (this.pendingRouters.length) {
123
- const newPendingRouters = [];
124
- for (const pendingRouter of this.pendingRouters) {
125
- if (!pendingRouter.laziedPrefix || pathname.startsWith(pendingRouter.laziedPrefix) || pathname.startsWith(pendingRouter.httpPathPrefix)) {
126
- const { default: router } = await unlazy(pendingRouter.router);
127
- this.init(router, pendingRouter.path);
128
- } else {
129
- newPendingRouters.push(pendingRouter);
130
- }
131
- }
132
- this.pendingRouters = newPendingRouters;
133
- }
134
- const match = findRoute(this.tree, method, pathname);
135
- if (!match) {
136
- return void 0;
137
- }
138
- if (!match.data.procedure) {
139
- const { default: maybeProcedure } = await unlazy(getRouter(match.data.router, match.data.path));
140
- if (!isProcedure(maybeProcedure)) {
141
- throw new Error(`
142
- [Contract-First] Missing or invalid implementation for procedure at path: ${toHttpPath(match.data.path)}.
143
- Ensure that the procedure is correctly defined and matches the expected contract.
144
- `);
145
- }
146
- match.data.procedure = createContractedProcedure(maybeProcedure, match.data.contract);
147
- }
148
- return {
149
- path: match.data.path,
150
- procedure: match.data.procedure,
151
- params: match.params ? decodeParams(match.params) : void 0
152
- };
153
- }
154
- }
155
-
156
- class CompositeStandardHandlerPlugin {
157
- plugins;
158
- constructor(plugins = []) {
159
- this.plugins = [...plugins].sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
160
- }
161
- init(options, router) {
162
- for (const plugin of this.plugins) {
163
- plugin.init?.(options, router);
164
- }
165
- }
166
- }
167
-
168
- class StandardHandler {
169
- interceptors;
170
- clientInterceptors;
171
- rootInterceptors;
172
- matcher;
173
- constructor(router, options) {
174
- this.matcher = new StandardOpenAPIMatcher();
175
- const plugins = new CompositeStandardHandlerPlugin(options.plugins);
176
- plugins.init(options, router);
177
- this.interceptors = toArray(options.interceptors);
178
- this.clientInterceptors = toArray(options.clientInterceptors);
179
- this.rootInterceptors = toArray(options.rootInterceptors);
180
- this.matcher.init(router);
181
- }
182
- async handle(request, options) {
183
- const prefix = options.prefix?.replace(/\/$/, "") || void 0;
184
- if (prefix && !request.url.pathname.startsWith(`${prefix}/`) && request.url.pathname !== prefix) {
185
- return { matched: false, response: void 0 };
186
- }
187
- return intercept(this.rootInterceptors, { ...options, request, prefix }, async (interceptorOptions) => {
188
- return runWithSpan({ name: `${request.method} ${request.url.pathname}` }, async (span) => {
189
- let step;
190
- try {
191
- return await intercept(
192
- this.interceptors,
193
- interceptorOptions,
194
- async ({ request: request2, context, prefix: prefix2 }) => {
195
- const method = request2.method;
196
- const url = request2.url;
197
- const pathname = prefix2 ? url.pathname.replace(prefix2, "") : url.pathname;
198
- const match = await runWithSpan(
199
- { name: "find_procedure" },
200
- () => this.matcher.match(method, `/${pathname.replace(/^\/|\/$/g, "")}`)
201
- );
202
- if (!match) {
203
- return { matched: false, response: void 0 };
204
- }
205
- span?.updateName(`${ORPC_NAME}.${match.path.join("/")}`);
206
- span?.setAttribute("rpc.system", ORPC_NAME);
207
- span?.setAttribute("rpc.method", match.path.join("."));
208
- step = "decode_input";
209
- const input = await runWithSpan({ name: "decode_input" }, () => decode(request2, match.params));
210
- step = void 0;
211
- if (isAsyncIteratorObject(input.body)) {
212
- input.body = asyncIteratorWithSpan(
213
- { name: "consume_event_iterator_input", signal: request2.signal },
214
- input.body
215
- );
216
- }
217
- const client = createProcedureClient(match.procedure, {
218
- context,
219
- path: match.path,
220
- interceptors: this.clientInterceptors
221
- });
222
- step = "call_procedure";
223
- const output = await client(input, {
224
- signal: request2.signal,
225
- lastEventId: flattenHeader(request2.headers["last-event-id"])
226
- });
227
- step = void 0;
228
- const response = encode(output, match.procedure);
229
- return {
230
- matched: true,
231
- response
232
- };
233
- }
234
- );
235
- } catch (e) {
236
- if (step !== "call_procedure") {
237
- setSpanError(span, e);
238
- }
239
- const error = step === "decode_input" && !(e instanceof ORPCError) ? new ORPCError("BAD_REQUEST", {
240
- message: `Malformed request. Ensure the request body is properly formatted and the 'Content-Type' header is set correctly.`,
241
- cause: e
242
- }) : toORPCError(e);
243
- const response = encodeError(error);
244
- return {
245
- matched: true,
246
- response
247
- };
248
- }
249
- });
250
- });
251
- }
252
- }
253
-
254
- export { CompositeStandardHandlerPlugin as C, StandardHandler as S, encodeError as a, StandardOpenAPIMatcher as b, decodeParams as c, decode as d, encode as e, resolveFriendlyStandardHandleOptions as r, toRou3Pattern as t };
@@ -1,56 +0,0 @@
1
- import { Meta } from '@temporary-name/contract';
2
- import { HTTPPath, Interceptor } from '@temporary-name/shared';
3
- import { StandardLazyRequest, StandardResponse } from '@temporary-name/standard-server';
4
- import { C as Context, R as Router, H as ProcedureClientInterceptorOptions } from './server.DecvGKtb.mjs';
5
-
6
- interface StandardHandlerPlugin<T extends Context> {
7
- order?: number;
8
- init?(options: StandardHandlerOptions<T>, router: Router<any, T>): void;
9
- }
10
- declare class CompositeStandardHandlerPlugin<T extends Context, TPlugin extends StandardHandlerPlugin<T>> implements StandardHandlerPlugin<T> {
11
- protected readonly plugins: TPlugin[];
12
- constructor(plugins?: readonly TPlugin[]);
13
- init(options: StandardHandlerOptions<T>, router: Router<any, T>): void;
14
- }
15
-
16
- interface StandardHandleOptions<T extends Context> {
17
- prefix?: HTTPPath;
18
- context: T;
19
- }
20
- type StandardHandleResult = {
21
- matched: true;
22
- response: StandardResponse;
23
- } | {
24
- matched: false;
25
- response: undefined;
26
- };
27
- interface StandardHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
28
- request: StandardLazyRequest;
29
- }
30
- interface StandardHandlerOptions<TContext extends Context> {
31
- plugins?: StandardHandlerPlugin<TContext>[];
32
- /**
33
- * Interceptors at the request level, helpful when you want catch errors
34
- */
35
- interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, Promise<StandardHandleResult>>[];
36
- /**
37
- * Interceptors at the root level, helpful when you want override the request/response
38
- */
39
- rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, Promise<StandardHandleResult>>[];
40
- /**
41
- *
42
- * Interceptors for procedure client.
43
- */
44
- clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, Record<never, never>, Meta>, Promise<unknown>>[];
45
- }
46
- declare class StandardHandler<T extends Context> {
47
- private readonly interceptors;
48
- private readonly clientInterceptors;
49
- private readonly rootInterceptors;
50
- private readonly matcher;
51
- constructor(router: Router<any, T>, options: NoInfer<StandardHandlerOptions<T>>);
52
- handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
53
- }
54
-
55
- export { CompositeStandardHandlerPlugin as C, StandardHandler as e };
56
- export type { StandardHandlerInterceptorOptions as S, StandardHandlerPlugin as a, StandardHandlerOptions as b, StandardHandleOptions as c, StandardHandleResult as d };