@temporary-name/server 1.9.3-alpha.e2d8d164da72fb570c2b14a4fa956c80f9e33cdc → 1.9.3-alpha.ec3bfb9dce56198911349c322c970208b21b50db

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 (42) hide show
  1. package/dist/adapters/aws-lambda/index.d.mts +4 -6
  2. package/dist/adapters/aws-lambda/index.d.ts +4 -6
  3. package/dist/adapters/aws-lambda/index.mjs +4 -4
  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 +16 -155
  7. package/dist/adapters/node/index.d.mts +8 -63
  8. package/dist/adapters/node/index.d.ts +8 -63
  9. package/dist/adapters/node/index.mjs +14 -120
  10. package/dist/adapters/standard/index.d.mts +10 -7
  11. package/dist/adapters/standard/index.d.ts +10 -7
  12. package/dist/adapters/standard/index.mjs +4 -4
  13. package/dist/helpers/index.mjs +3 -29
  14. package/dist/index.d.mts +121 -239
  15. package/dist/index.d.ts +121 -239
  16. package/dist/index.mjs +167 -352
  17. package/dist/openapi/index.d.mts +12 -28
  18. package/dist/openapi/index.d.ts +12 -28
  19. package/dist/openapi/index.mjs +59 -112
  20. package/dist/shared/server.C1RJffw4.mjs +30 -0
  21. package/dist/shared/server.CQIFwyhc.mjs +40 -0
  22. package/dist/shared/server.CVhIyQ4x.d.mts +41 -0
  23. package/dist/shared/server.CYa9puL2.mjs +403 -0
  24. package/dist/shared/server.ChOv1yG3.mjs +319 -0
  25. package/dist/shared/server.Cj3_Lp61.d.mts +373 -0
  26. package/dist/shared/server.Cj3_Lp61.d.ts +373 -0
  27. package/dist/shared/server.Cza0RB3u.mjs +160 -0
  28. package/dist/shared/server.D8RAzJ_p.d.ts +41 -0
  29. package/dist/shared/server.YUvuxHty.mjs +48 -0
  30. package/package.json +10 -28
  31. package/dist/plugins/index.d.mts +0 -160
  32. package/dist/plugins/index.d.ts +0 -160
  33. package/dist/plugins/index.mjs +0 -288
  34. package/dist/shared/server.B93y_8tj.d.mts +0 -23
  35. package/dist/shared/server.BYYf0Wn6.mjs +0 -202
  36. package/dist/shared/server.C3RuMHWl.d.mts +0 -192
  37. package/dist/shared/server.C3RuMHWl.d.ts +0 -192
  38. package/dist/shared/server.CT1xhSmE.d.mts +0 -56
  39. package/dist/shared/server.CqTex_jI.mjs +0 -265
  40. package/dist/shared/server.D_fags8X.d.ts +0 -23
  41. package/dist/shared/server.Kxw442A9.mjs +0 -247
  42. package/dist/shared/server.cjcgLdr1.d.ts +0 -56
@@ -1,265 +0,0 @@
1
- import { isObject, stringifyJSON, isORPCErrorStatus, tryDecodeURIComponent, value, 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.BYYf0Wn6.mjs';
4
- import { fallbackContractConfig } from '@temporary-name/contract';
5
- import { d as deserialize, s as serialize, b as bracketNotationDeserialize, 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
- const deserializeSearchParams = () => {
11
- return bracketNotationDeserialize(Array.from(request.url.searchParams.entries()));
12
- };
13
- const data = request.method === "GET" ? deserializeSearchParams() : deserialize(await request.body());
14
- if (data === void 0) {
15
- return pathParams;
16
- }
17
- if (isObject(data)) {
18
- return {
19
- ...pathParams,
20
- ...data
21
- };
22
- }
23
- return data;
24
- }
25
- function encode(output, procedure) {
26
- const successStatus = fallbackContractConfig(
27
- "defaultSuccessStatus",
28
- procedure["~orpc"].route.successStatus
29
- );
30
- const outputStructure = fallbackContractConfig(
31
- "defaultOutputStructure",
32
- procedure["~orpc"].route.outputStructure
33
- );
34
- if (outputStructure === "compact") {
35
- return {
36
- status: successStatus,
37
- headers: {},
38
- body: serialize(output)
39
- };
40
- }
41
- if (!isDetailedOutput(output)) {
42
- throw new Error(`
43
- Invalid "detailed" output structure:
44
- \u2022 Expected an object with optional properties:
45
- - status (number 200-399)
46
- - headers (Record<string, string | string[]>)
47
- - body (any)
48
- \u2022 No extra keys allowed.
49
-
50
- Actual value:
51
- ${stringifyJSON(output)}
52
- `);
53
- }
54
- return {
55
- status: output.status ?? successStatus,
56
- headers: output.headers ?? {},
57
- body: serialize(output.body)
58
- };
59
- }
60
- function encodeError(error) {
61
- return {
62
- status: error.status,
63
- headers: {},
64
- body: serialize(error.toJSON(), { outputFormat: "plain" })
65
- };
66
- }
67
- function isDetailedOutput(output) {
68
- if (!isObject(output)) {
69
- return false;
70
- }
71
- if (output.headers && !isObject(output.headers)) {
72
- return false;
73
- }
74
- if (output.status !== void 0 && (typeof output.status !== "number" || !Number.isInteger(output.status) || isORPCErrorStatus(output.status))) {
75
- return false;
76
- }
77
- return true;
78
- }
79
-
80
- function resolveFriendlyStandardHandleOptions(options) {
81
- return {
82
- ...options,
83
- context: options.context ?? {}
84
- // Context only optional if all fields are optional
85
- };
86
- }
87
- function toRou3Pattern(path) {
88
- return standardizeHTTPPath(path).replace(/\/\{\+([^}]+)\}/g, "/**:$1").replace(/\/\{([^}]+)\}/g, "/:$1");
89
- }
90
- function decodeParams(params) {
91
- return Object.fromEntries(
92
- Object.entries(params).map(([key, value]) => [key, tryDecodeURIComponent(value)])
93
- );
94
- }
95
-
96
- class StandardOpenAPIMatcher {
97
- tree = createRouter();
98
- pendingRouters = [];
99
- init(router, path = []) {
100
- const laziedOptions = traverseContractProcedures({ router, path }, (traverseOptions) => {
101
- if (!value(true, traverseOptions)) {
102
- return;
103
- }
104
- const { path: path2, contract } = traverseOptions;
105
- const method = fallbackContractConfig("defaultMethod", contract["~orpc"].route.method);
106
- const httpPath = toRou3Pattern(contract["~orpc"].route.path ?? toHttpPath(path2));
107
- if (isProcedure(contract)) {
108
- addRoute(this.tree, method, httpPath, {
109
- path: path2,
110
- contract,
111
- procedure: contract,
112
- // this mean dev not used contract-first so we can used contract as procedure directly
113
- router
114
- });
115
- } else {
116
- addRoute(this.tree, method, httpPath, {
117
- path: path2,
118
- contract,
119
- procedure: void 0,
120
- router
121
- });
122
- }
123
- });
124
- this.pendingRouters.push(
125
- ...laziedOptions.map((option) => ({
126
- ...option,
127
- httpPathPrefix: toHttpPath(option.path),
128
- laziedPrefix: getLazyMeta(option.router).prefix
129
- }))
130
- );
131
- }
132
- async match(method, pathname) {
133
- if (this.pendingRouters.length) {
134
- const newPendingRouters = [];
135
- for (const pendingRouter of this.pendingRouters) {
136
- if (!pendingRouter.laziedPrefix || pathname.startsWith(pendingRouter.laziedPrefix) || pathname.startsWith(pendingRouter.httpPathPrefix)) {
137
- const { default: router } = await unlazy(pendingRouter.router);
138
- this.init(router, pendingRouter.path);
139
- } else {
140
- newPendingRouters.push(pendingRouter);
141
- }
142
- }
143
- this.pendingRouters = newPendingRouters;
144
- }
145
- const match = findRoute(this.tree, method, pathname);
146
- if (!match) {
147
- return void 0;
148
- }
149
- if (!match.data.procedure) {
150
- const { default: maybeProcedure } = await unlazy(getRouter(match.data.router, match.data.path));
151
- if (!isProcedure(maybeProcedure)) {
152
- throw new Error(`
153
- [Contract-First] Missing or invalid implementation for procedure at path: ${toHttpPath(match.data.path)}.
154
- Ensure that the procedure is correctly defined and matches the expected contract.
155
- `);
156
- }
157
- match.data.procedure = createContractedProcedure(maybeProcedure, match.data.contract);
158
- }
159
- return {
160
- path: match.data.path,
161
- procedure: match.data.procedure,
162
- params: match.params ? decodeParams(match.params) : void 0
163
- };
164
- }
165
- }
166
-
167
- class CompositeStandardHandlerPlugin {
168
- plugins;
169
- constructor(plugins = []) {
170
- this.plugins = [...plugins].sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
171
- }
172
- init(options, router) {
173
- for (const plugin of this.plugins) {
174
- plugin.init?.(options, router);
175
- }
176
- }
177
- }
178
-
179
- class StandardHandler {
180
- interceptors;
181
- clientInterceptors;
182
- rootInterceptors;
183
- matcher;
184
- constructor(router, options) {
185
- this.matcher = new StandardOpenAPIMatcher();
186
- const plugins = new CompositeStandardHandlerPlugin(options.plugins);
187
- plugins.init(options, router);
188
- this.interceptors = toArray(options.interceptors);
189
- this.clientInterceptors = toArray(options.clientInterceptors);
190
- this.rootInterceptors = toArray(options.rootInterceptors);
191
- this.matcher.init(router);
192
- }
193
- async handle(request, options) {
194
- const prefix = options.prefix?.replace(/\/$/, "") || void 0;
195
- if (prefix && !request.url.pathname.startsWith(`${prefix}/`) && request.url.pathname !== prefix) {
196
- return { matched: false, response: void 0 };
197
- }
198
- return intercept(this.rootInterceptors, { ...options, request, prefix }, async (interceptorOptions) => {
199
- return runWithSpan({ name: `${request.method} ${request.url.pathname}` }, async (span) => {
200
- let step;
201
- try {
202
- return await intercept(
203
- this.interceptors,
204
- interceptorOptions,
205
- async ({ request: request2, context, prefix: prefix2 }) => {
206
- const method = request2.method;
207
- const url = request2.url;
208
- const pathname = prefix2 ? url.pathname.replace(prefix2, "") : url.pathname;
209
- const match = await runWithSpan(
210
- { name: "find_procedure" },
211
- () => this.matcher.match(method, `/${pathname.replace(/^\/|\/$/g, "")}`)
212
- );
213
- if (!match) {
214
- return { matched: false, response: void 0 };
215
- }
216
- span?.updateName(`${ORPC_NAME}.${match.path.join("/")}`);
217
- span?.setAttribute("rpc.system", ORPC_NAME);
218
- span?.setAttribute("rpc.method", match.path.join("."));
219
- step = "decode_input";
220
- let input = await runWithSpan({ name: "decode_input" }, () => decode(request2, match.params));
221
- step = void 0;
222
- if (isAsyncIteratorObject(input)) {
223
- input = asyncIteratorWithSpan(
224
- { name: "consume_event_iterator_input", signal: request2.signal },
225
- input
226
- );
227
- }
228
- const client = createProcedureClient(match.procedure, {
229
- context,
230
- path: match.path,
231
- interceptors: this.clientInterceptors
232
- });
233
- step = "call_procedure";
234
- const output = await client(input, {
235
- signal: request2.signal,
236
- lastEventId: flattenHeader(request2.headers["last-event-id"])
237
- });
238
- step = void 0;
239
- const response = encode(output, match.procedure);
240
- return {
241
- matched: true,
242
- response
243
- };
244
- }
245
- );
246
- } catch (e) {
247
- if (step !== "call_procedure") {
248
- setSpanError(span, e);
249
- }
250
- const error = step === "decode_input" && !(e instanceof ORPCError) ? new ORPCError("BAD_REQUEST", {
251
- message: `Malformed request. Ensure the request body is properly formatted and the 'Content-Type' header is set correctly.`,
252
- cause: e
253
- }) : toORPCError(e);
254
- const response = encodeError(error);
255
- return {
256
- matched: true,
257
- response
258
- };
259
- }
260
- });
261
- });
262
- }
263
- }
264
-
265
- 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,23 +0,0 @@
1
- import { HTTPPath } from '@temporary-name/shared';
2
- import { C as Context } from './server.C3RuMHWl.js';
3
- import { c as StandardHandleOptions } from './server.cjcgLdr1.js';
4
-
5
- type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
6
- context?: T;
7
- } : {
8
- context: T;
9
- });
10
- declare function resolveFriendlyStandardHandleOptions<T extends Context>(options: FriendlyStandardHandleOptions<T>): StandardHandleOptions<T>;
11
- /**
12
- * {@link https://github.com/unjs/rou3}
13
- *
14
- * @internal
15
- */
16
- declare function toRou3Pattern(path: HTTPPath): string;
17
- /**
18
- * @internal
19
- */
20
- declare function decodeParams(params: Record<string, string>): Record<string, string>;
21
-
22
- export { decodeParams as d, resolveFriendlyStandardHandleOptions as r, toRou3Pattern as t };
23
- export type { FriendlyStandardHandleOptions as F };
@@ -1,247 +0,0 @@
1
- import { isObject, NullProtoObj, isAsyncIteratorObject, isORPCErrorJson, createORPCErrorFromJson, toORPCError } from '@temporary-name/shared';
2
- import { mapEventIterator, ErrorEvent } from '@temporary-name/standard-server';
3
-
4
- function bracketNotationSerialize(data, segments = [], result = []) {
5
- if (Array.isArray(data)) {
6
- data.forEach((item, i) => {
7
- bracketNotationSerialize(item, [...segments, i], result);
8
- });
9
- } else if (isObject(data)) {
10
- for (const key in data) {
11
- bracketNotationSerialize(data[key], [...segments, key], result);
12
- }
13
- } else {
14
- result.push([stringifyPath(segments), data]);
15
- }
16
- return result;
17
- }
18
- function bracketNotationDeserialize(serialized, { maxArrayIndex = 9999 } = {}) {
19
- if (serialized.length === 0) {
20
- return {};
21
- }
22
- const arrayPushStyles = /* @__PURE__ */ new WeakSet();
23
- const ref = { value: [] };
24
- for (const [path, value] of serialized) {
25
- const segments = parsePath(path);
26
- let currentRef = ref;
27
- let nextSegment = "value";
28
- segments.forEach((segment, i) => {
29
- if (!Array.isArray(currentRef[nextSegment]) && !isObject(currentRef[nextSegment])) {
30
- currentRef[nextSegment] = [];
31
- }
32
- if (i !== segments.length - 1) {
33
- if (Array.isArray(currentRef[nextSegment]) && !isValidArrayIndex(segment, maxArrayIndex)) {
34
- if (arrayPushStyles.has(currentRef[nextSegment])) {
35
- arrayPushStyles.delete(currentRef[nextSegment]);
36
- currentRef[nextSegment] = pushStyleArrayToObject(currentRef[nextSegment]);
37
- } else {
38
- currentRef[nextSegment] = arrayToObject(currentRef[nextSegment]);
39
- }
40
- }
41
- } else {
42
- if (Array.isArray(currentRef[nextSegment])) {
43
- if (segment === "") {
44
- if (currentRef[nextSegment].length && !arrayPushStyles.has(currentRef[nextSegment])) {
45
- currentRef[nextSegment] = arrayToObject(currentRef[nextSegment]);
46
- }
47
- } else {
48
- if (arrayPushStyles.has(currentRef[nextSegment])) {
49
- arrayPushStyles.delete(currentRef[nextSegment]);
50
- currentRef[nextSegment] = pushStyleArrayToObject(currentRef[nextSegment]);
51
- } else if (!isValidArrayIndex(segment, maxArrayIndex)) {
52
- currentRef[nextSegment] = arrayToObject(currentRef[nextSegment]);
53
- }
54
- }
55
- }
56
- }
57
- currentRef = currentRef[nextSegment];
58
- nextSegment = segment;
59
- });
60
- if (Array.isArray(currentRef) && nextSegment === "") {
61
- arrayPushStyles.add(currentRef);
62
- currentRef.push(value);
63
- } else if (nextSegment in currentRef) {
64
- if (Array.isArray(currentRef[nextSegment])) {
65
- currentRef[nextSegment].push(value);
66
- } else {
67
- currentRef[nextSegment] = [currentRef[nextSegment], value];
68
- }
69
- } else {
70
- currentRef[nextSegment] = value;
71
- }
72
- }
73
- return ref.value;
74
- }
75
- function stringifyPath(segments) {
76
- return segments.map((segment) => {
77
- return segment.toString().replace(/[\\[\]]/g, (match) => {
78
- switch (match) {
79
- case "\\":
80
- return "\\\\";
81
- case "[":
82
- return "\\[";
83
- case "]":
84
- return "\\]";
85
- /* v8 ignore next 2 */
86
- default:
87
- return match;
88
- }
89
- });
90
- }).reduce((result, segment, i) => {
91
- if (i === 0) {
92
- return segment;
93
- }
94
- return `${result}[${segment}]`;
95
- }, "");
96
- }
97
- function parsePath(path) {
98
- const segments = [];
99
- let inBrackets = false;
100
- let currentSegment = "";
101
- let backslashCount = 0;
102
- for (let i = 0; i < path.length; i++) {
103
- const char = path[i];
104
- const nextChar = path[i + 1];
105
- if (inBrackets && char === "]" && (nextChar === void 0 || nextChar === "[") && backslashCount % 2 === 0) {
106
- if (nextChar === void 0) {
107
- inBrackets = false;
108
- }
109
- segments.push(currentSegment);
110
- currentSegment = "";
111
- i++;
112
- } else if (segments.length === 0 && char === "[" && backslashCount % 2 === 0) {
113
- inBrackets = true;
114
- segments.push(currentSegment);
115
- currentSegment = "";
116
- } else if (char === "\\") {
117
- backslashCount++;
118
- } else {
119
- currentSegment += "\\".repeat(backslashCount / 2) + char;
120
- backslashCount = 0;
121
- }
122
- }
123
- return inBrackets || segments.length === 0 ? [path] : segments;
124
- }
125
- function isValidArrayIndex(value, maxIndex) {
126
- return /^0$|^[1-9]\d*$/.test(value) && Number(value) <= maxIndex;
127
- }
128
- function arrayToObject(array) {
129
- const obj = new NullProtoObj();
130
- array.forEach((item, i) => {
131
- obj[i] = item;
132
- });
133
- return obj;
134
- }
135
- function pushStyleArrayToObject(array) {
136
- const obj = new NullProtoObj();
137
- obj[""] = array.length === 1 ? array[0] : array;
138
- return obj;
139
- }
140
-
141
- function jsonSerialize(data, hasBlobRef = { value: false }) {
142
- if (data instanceof Blob) {
143
- hasBlobRef.value = true;
144
- return [data, hasBlobRef.value];
145
- }
146
- if (data instanceof Set) {
147
- return jsonSerialize(Array.from(data), hasBlobRef);
148
- }
149
- if (data instanceof Map) {
150
- return jsonSerialize(Array.from(data.entries()), hasBlobRef);
151
- }
152
- if (Array.isArray(data)) {
153
- const json = data.map((v) => v === void 0 ? null : jsonSerialize(v, hasBlobRef)[0]);
154
- return [json, hasBlobRef.value];
155
- }
156
- if (isObject(data)) {
157
- const json = {};
158
- for (const k in data) {
159
- if (k === "toJSON" && typeof data[k] === "function") {
160
- continue;
161
- }
162
- json[k] = jsonSerialize(data[k], hasBlobRef)[0];
163
- }
164
- return [json, hasBlobRef.value];
165
- }
166
- if (typeof data === "bigint" || data instanceof RegExp || data instanceof URL) {
167
- return [data.toString(), hasBlobRef.value];
168
- }
169
- if (data instanceof Date) {
170
- return [Number.isNaN(data.getTime()) ? null : data.toISOString(), hasBlobRef.value];
171
- }
172
- if (Number.isNaN(data)) {
173
- return [null, hasBlobRef.value];
174
- }
175
- return [data, hasBlobRef.value];
176
- }
177
-
178
- function serialize(data, options = {}) {
179
- if (isAsyncIteratorObject(data) && !options.outputFormat) {
180
- return mapEventIterator(data, {
181
- value: async (value) => _serialize(value, { outputFormat: "plain" }),
182
- error: async (e) => {
183
- return new ErrorEvent({
184
- data: _serialize(toORPCError(e).toJSON(), { outputFormat: "plain" }),
185
- cause: e
186
- });
187
- }
188
- });
189
- }
190
- return _serialize(data, options);
191
- }
192
- function _serialize(data, options) {
193
- const [json, hasBlob] = jsonSerialize(data);
194
- if (options.outputFormat === "plain") {
195
- return json;
196
- }
197
- if (options.outputFormat === "URLSearchParams") {
198
- const params = new URLSearchParams();
199
- for (const [path, value] of bracketNotationSerialize(json)) {
200
- if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
201
- params.append(path, value.toString());
202
- }
203
- }
204
- return params;
205
- }
206
- if (json instanceof Blob || json === void 0 || !hasBlob) {
207
- return json;
208
- }
209
- const form = new FormData();
210
- for (const [path, value] of bracketNotationSerialize(json)) {
211
- if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
212
- form.append(path, value.toString());
213
- } else if (value instanceof Blob) {
214
- form.append(path, value);
215
- }
216
- }
217
- return form;
218
- }
219
- function deserialize(data) {
220
- if (data instanceof URLSearchParams || data instanceof FormData) {
221
- return bracketNotationDeserialize(Array.from(data.entries()));
222
- }
223
- if (isAsyncIteratorObject(data)) {
224
- return mapEventIterator(data, {
225
- value: async (value) => value,
226
- error: async (e) => {
227
- if (e instanceof ErrorEvent && isORPCErrorJson(e.data)) {
228
- return createORPCErrorFromJson(e.data, { cause: e });
229
- }
230
- return e;
231
- }
232
- });
233
- }
234
- return data;
235
- }
236
-
237
- function standardizeHTTPPath(path) {
238
- return `/${path.replace(/\/{2,}/g, "/").replace(/^\/|\/$/g, "")}`;
239
- }
240
- function getDynamicParams(path) {
241
- return path ? standardizeHTTPPath(path).match(/\/\{[^}]+\}/g)?.map((v) => ({
242
- raw: v,
243
- name: v.match(/\{\+?([^}]+)\}/)[1]
244
- })) : void 0;
245
- }
246
-
247
- export { standardizeHTTPPath as a, bracketNotationDeserialize as b, deserialize as d, getDynamicParams as g, jsonSerialize as j, serialize as s };
@@ -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, E as ProcedureClientInterceptorOptions } from './server.C3RuMHWl.js';
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 };