@temporary-name/server 1.9.3-alpha.6ef4729e23affbe6454d37025d1dfc4d998b0649 → 1.9.3-alpha.72daecd600ae901064d3c4f8ab780582c1335ffe

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 (45) hide show
  1. package/dist/adapters/aws-lambda/index.d.mts +11 -7
  2. package/dist/adapters/aws-lambda/index.d.ts +11 -7
  3. package/dist/adapters/aws-lambda/index.mjs +11 -4
  4. package/dist/adapters/fetch/index.d.mts +15 -87
  5. package/dist/adapters/fetch/index.d.ts +15 -87
  6. package/dist/adapters/fetch/index.mjs +22 -161
  7. package/dist/adapters/node/index.d.mts +15 -64
  8. package/dist/adapters/node/index.d.ts +15 -64
  9. package/dist/adapters/node/index.mjs +20 -126
  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 +373 -546
  15. package/dist/index.d.ts +373 -546
  16. package/dist/index.mjs +547 -470
  17. package/dist/openapi/index.d.mts +185 -0
  18. package/dist/openapi/index.d.ts +185 -0
  19. package/dist/openapi/index.mjs +782 -0
  20. package/dist/shared/server.BwcJq6aP.d.mts +808 -0
  21. package/dist/shared/server.BwcJq6aP.d.ts +808 -0
  22. package/dist/shared/server.C1RJffw4.mjs +30 -0
  23. package/dist/shared/server.CjPiuQYH.d.mts +51 -0
  24. package/dist/shared/server.CjPiuQYH.d.ts +51 -0
  25. package/dist/shared/server.D1LXM1bf.mjs +523 -0
  26. package/dist/shared/server.DEC2sW8B.mjs +496 -0
  27. package/dist/shared/server.Deg5phAY.d.ts +39 -0
  28. package/dist/shared/server.H11763QX.mjs +315 -0
  29. package/dist/shared/server.gSXsB9Bn.mjs +156 -0
  30. package/dist/shared/server.hAH-LVh_.d.mts +39 -0
  31. package/package.json +20 -31
  32. package/dist/adapters/standard/index.d.mts +0 -16
  33. package/dist/adapters/standard/index.d.ts +0 -16
  34. package/dist/adapters/standard/index.mjs +0 -101
  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.BEQrAa3A.mjs +0 -207
  39. package/dist/shared/server.Bo94xDTv.d.mts +0 -73
  40. package/dist/shared/server.Btxrgkj5.d.ts +0 -73
  41. package/dist/shared/server.C1YnHvvf.d.mts +0 -192
  42. package/dist/shared/server.C1YnHvvf.d.ts +0 -192
  43. package/dist/shared/server.D6K9uoPI.mjs +0 -35
  44. package/dist/shared/server.DZ5BIITo.mjs +0 -9
  45. package/dist/shared/server.X0YaZxSJ.mjs +0 -13
@@ -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,207 +0,0 @@
1
- import { validateORPCError, ValidationError } from '@temporary-name/contract';
2
- import { resolveMaybeOptionalOptions, ORPCError, toArray, value, runWithSpan, intercept, isAsyncIteratorObject, overlayProxy, asyncIteratorWithSpan } from '@temporary-name/shared';
3
- import { HibernationEventIterator, mapEventIterator } from '@temporary-name/standard-server';
4
- import { g as gatingContext, w as withoutGatedFields } from './server.D6K9uoPI.mjs';
5
-
6
- const LAZY_SYMBOL = Symbol("ORPC_LAZY_SYMBOL");
7
- function lazy(loader, meta = {}) {
8
- return {
9
- [LAZY_SYMBOL]: {
10
- loader,
11
- meta
12
- }
13
- };
14
- }
15
- function isLazy(item) {
16
- return (typeof item === "object" || typeof item === "function") && item !== null && LAZY_SYMBOL in item;
17
- }
18
- function getLazyMeta(lazied) {
19
- return lazied[LAZY_SYMBOL].meta;
20
- }
21
- function unlazy(lazied) {
22
- return isLazy(lazied) ? lazied[LAZY_SYMBOL].loader() : Promise.resolve({ default: lazied });
23
- }
24
-
25
- function mergeCurrentContext(context, other) {
26
- return { ...context, ...other };
27
- }
28
-
29
- function createORPCErrorConstructorMap(errors) {
30
- const proxy = new Proxy(errors, {
31
- get(target, code) {
32
- if (typeof code !== "string") {
33
- return Reflect.get(target, code);
34
- }
35
- const item = (...rest) => {
36
- const options = resolveMaybeOptionalOptions(rest);
37
- const config = errors[code];
38
- return new ORPCError(code, {
39
- defined: Boolean(config),
40
- status: config?.status,
41
- message: options.message ?? config?.message,
42
- data: options.data,
43
- cause: options.cause
44
- });
45
- };
46
- return item;
47
- }
48
- });
49
- return proxy;
50
- }
51
-
52
- function middlewareOutputFn(output) {
53
- return { output, context: {} };
54
- }
55
-
56
- function createProcedureClient(lazyableProcedure, ...rest) {
57
- const options = resolveMaybeOptionalOptions(rest);
58
- return async (...[input, callerOptions]) => {
59
- const path = toArray(options.path);
60
- const { default: procedure } = await unlazy(lazyableProcedure);
61
- const clientContext = callerOptions?.context ?? {};
62
- const context = await value(options.context ?? {}, clientContext);
63
- const errors = createORPCErrorConstructorMap(procedure["~orpc"].errorMap);
64
- const validateError = async (e) => {
65
- if (e instanceof ORPCError) {
66
- return await validateORPCError(procedure["~orpc"].errorMap, e);
67
- }
68
- return e;
69
- };
70
- try {
71
- const output = await runWithSpan({ name: "call_procedure", signal: callerOptions?.signal }, (span) => {
72
- span?.setAttribute("procedure.path", [...path]);
73
- return intercept(
74
- toArray(options.interceptors),
75
- {
76
- context,
77
- input,
78
- // input only optional when it undefinable so we can safely cast it
79
- errors,
80
- path,
81
- procedure,
82
- signal: callerOptions?.signal,
83
- lastEventId: callerOptions?.lastEventId
84
- },
85
- (interceptorOptions) => executeProcedureInternal(interceptorOptions.procedure, interceptorOptions)
86
- );
87
- });
88
- if (isAsyncIteratorObject(output)) {
89
- if (output instanceof HibernationEventIterator) {
90
- return output;
91
- }
92
- return overlayProxy(
93
- output,
94
- mapEventIterator(
95
- asyncIteratorWithSpan(
96
- { name: "consume_event_iterator_output", signal: callerOptions?.signal },
97
- output
98
- ),
99
- {
100
- value: (v) => v,
101
- error: (e) => validateError(e)
102
- }
103
- )
104
- );
105
- }
106
- return output;
107
- } catch (e) {
108
- throw await validateError(e);
109
- }
110
- };
111
- }
112
- async function validateInput(procedure, input) {
113
- const schema = procedure["~orpc"].inputSchema;
114
- if (!schema) {
115
- return input;
116
- }
117
- return runWithSpan({ name: "validate_input" }, async () => {
118
- const result = await schema["~standard"].validate(input);
119
- if (result.issues) {
120
- throw new ORPCError("BAD_REQUEST", {
121
- message: "Input validation failed",
122
- data: {
123
- issues: result.issues
124
- },
125
- cause: new ValidationError({
126
- message: "Input validation failed",
127
- issues: result.issues,
128
- data: input
129
- })
130
- });
131
- }
132
- return result.value;
133
- });
134
- }
135
- async function validateOutput(schema, output) {
136
- return runWithSpan({ name: "validate_output" }, async () => {
137
- const result = await schema["~standard"].validate(output);
138
- if (result.issues) {
139
- throw new ORPCError("INTERNAL_SERVER_ERROR", {
140
- message: "Output validation failed",
141
- cause: new ValidationError({
142
- message: "Output validation failed",
143
- issues: result.issues,
144
- data: output
145
- })
146
- });
147
- }
148
- return result.value;
149
- });
150
- }
151
- async function executeProcedureInternal(procedure, options) {
152
- const middlewares = procedure["~orpc"].middlewares;
153
- const inputValidationIndex = Math.min(
154
- Math.max(0, procedure["~orpc"].inputValidationIndex),
155
- middlewares.length
156
- );
157
- const outputValidationIndex = Math.min(
158
- Math.max(0, procedure["~orpc"].outputValidationIndex),
159
- middlewares.length
160
- );
161
- const next = async (index, context, input) => {
162
- let currentInput = input;
163
- if (index === inputValidationIndex) {
164
- currentInput = await validateInput(procedure, currentInput);
165
- }
166
- const mid = middlewares[index];
167
- const output = mid ? await runWithSpan({ name: `middleware.${mid.name}`, signal: options.signal }, async (span) => {
168
- span?.setAttribute("middleware.index", index);
169
- span?.setAttribute("middleware.name", mid.name);
170
- const result = await mid(
171
- {
172
- ...options,
173
- context,
174
- next: async (...[nextOptions]) => {
175
- const nextContext = nextOptions?.context ?? {};
176
- return {
177
- output: await next(index + 1, mergeCurrentContext(context, nextContext), currentInput),
178
- context: nextContext
179
- };
180
- }
181
- },
182
- currentInput,
183
- middlewareOutputFn
184
- );
185
- return result.output;
186
- }) : await runWithSpan(
187
- { name: "handler", signal: options.signal },
188
- () => procedure["~orpc"].handler({ ...options, context, input: currentInput })
189
- );
190
- if (index === outputValidationIndex) {
191
- const schema = procedure["~orpc"].outputSchema;
192
- if (!schema) {
193
- return output;
194
- }
195
- const validated = await validateOutput(schema, output);
196
- const isGateEnabled = gatingContext.getStore();
197
- if (!validated || !isGateEnabled) {
198
- return validated;
199
- }
200
- return withoutGatedFields(validated, schema, isGateEnabled);
201
- }
202
- return output;
203
- };
204
- return next(0, options.context, options.input);
205
- }
206
-
207
- export { LAZY_SYMBOL as L, createORPCErrorConstructorMap as a, middlewareOutputFn as b, createProcedureClient as c, getLazyMeta as g, isLazy as i, lazy as l, mergeCurrentContext as m, unlazy as u };
@@ -1,73 +0,0 @@
1
- import { Meta } from '@temporary-name/contract';
2
- import { HTTPPath, ORPCError, Interceptor } from '@temporary-name/shared';
3
- import { StandardResponse, StandardLazyRequest } from '@temporary-name/standard-server';
4
- import { C as Context, R as Router, A as AnyRouter, a as AnyProcedure, P as ProcedureClientInterceptorOptions } from './server.C1YnHvvf.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
- type StandardParams = Record<string, string>;
17
- type StandardMatchResult = {
18
- path: readonly string[];
19
- procedure: AnyProcedure;
20
- params?: StandardParams;
21
- } | undefined;
22
- interface StandardMatcher {
23
- init(router: AnyRouter): void;
24
- match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
25
- }
26
- interface StandardCodec {
27
- encode(output: unknown, procedure: AnyProcedure): StandardResponse;
28
- encodeError(error: ORPCError<any, any>): StandardResponse;
29
- decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
30
- }
31
-
32
- interface StandardHandleOptions<T extends Context> {
33
- prefix?: HTTPPath;
34
- context: T;
35
- }
36
- type StandardHandleResult = {
37
- matched: true;
38
- response: StandardResponse;
39
- } | {
40
- matched: false;
41
- response: undefined;
42
- };
43
- interface StandardHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
44
- request: StandardLazyRequest;
45
- }
46
- interface StandardHandlerOptions<TContext extends Context> {
47
- plugins?: StandardHandlerPlugin<TContext>[];
48
- /**
49
- * Interceptors at the request level, helpful when you want catch errors
50
- */
51
- interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, Promise<StandardHandleResult>>[];
52
- /**
53
- * Interceptors at the root level, helpful when you want override the request/response
54
- */
55
- rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, Promise<StandardHandleResult>>[];
56
- /**
57
- *
58
- * Interceptors for procedure client.
59
- */
60
- clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, Record<never, never>, Meta>, Promise<unknown>>[];
61
- }
62
- declare class StandardHandler<T extends Context> {
63
- private readonly matcher;
64
- private readonly codec;
65
- private readonly interceptors;
66
- private readonly clientInterceptors;
67
- private readonly rootInterceptors;
68
- constructor(router: Router<any, T>, matcher: StandardMatcher, codec: StandardCodec, options: NoInfer<StandardHandlerOptions<T>>);
69
- handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
70
- }
71
-
72
- export { CompositeStandardHandlerPlugin as C, StandardHandler as S };
73
- export type { StandardHandlerPlugin as a, StandardHandleOptions as b, StandardHandlerInterceptorOptions as c, StandardHandlerOptions as d, StandardHandleResult as e, StandardParams as f, StandardMatchResult as g, StandardMatcher as h, StandardCodec as i };
@@ -1,73 +0,0 @@
1
- import { Meta } from '@temporary-name/contract';
2
- import { HTTPPath, ORPCError, Interceptor } from '@temporary-name/shared';
3
- import { StandardResponse, StandardLazyRequest } from '@temporary-name/standard-server';
4
- import { C as Context, R as Router, A as AnyRouter, a as AnyProcedure, P as ProcedureClientInterceptorOptions } from './server.C1YnHvvf.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
- type StandardParams = Record<string, string>;
17
- type StandardMatchResult = {
18
- path: readonly string[];
19
- procedure: AnyProcedure;
20
- params?: StandardParams;
21
- } | undefined;
22
- interface StandardMatcher {
23
- init(router: AnyRouter): void;
24
- match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
25
- }
26
- interface StandardCodec {
27
- encode(output: unknown, procedure: AnyProcedure): StandardResponse;
28
- encodeError(error: ORPCError<any, any>): StandardResponse;
29
- decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
30
- }
31
-
32
- interface StandardHandleOptions<T extends Context> {
33
- prefix?: HTTPPath;
34
- context: T;
35
- }
36
- type StandardHandleResult = {
37
- matched: true;
38
- response: StandardResponse;
39
- } | {
40
- matched: false;
41
- response: undefined;
42
- };
43
- interface StandardHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
44
- request: StandardLazyRequest;
45
- }
46
- interface StandardHandlerOptions<TContext extends Context> {
47
- plugins?: StandardHandlerPlugin<TContext>[];
48
- /**
49
- * Interceptors at the request level, helpful when you want catch errors
50
- */
51
- interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, Promise<StandardHandleResult>>[];
52
- /**
53
- * Interceptors at the root level, helpful when you want override the request/response
54
- */
55
- rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, Promise<StandardHandleResult>>[];
56
- /**
57
- *
58
- * Interceptors for procedure client.
59
- */
60
- clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, Record<never, never>, Meta>, Promise<unknown>>[];
61
- }
62
- declare class StandardHandler<T extends Context> {
63
- private readonly matcher;
64
- private readonly codec;
65
- private readonly interceptors;
66
- private readonly clientInterceptors;
67
- private readonly rootInterceptors;
68
- constructor(router: Router<any, T>, matcher: StandardMatcher, codec: StandardCodec, options: NoInfer<StandardHandlerOptions<T>>);
69
- handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
70
- }
71
-
72
- export { CompositeStandardHandlerPlugin as C, StandardHandler as S };
73
- export type { StandardHandlerPlugin as a, StandardHandleOptions as b, StandardHandlerInterceptorOptions as c, StandardHandlerOptions as d, StandardHandleResult as e, StandardParams as f, StandardMatchResult as g, StandardMatcher as h, StandardCodec as i };