@orpc/server 0.0.0-next.9125edb → 0.0.0-next.924a598

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 (82) hide show
  1. package/README.md +120 -0
  2. package/dist/adapters/fetch/index.d.mts +28 -0
  3. package/dist/adapters/fetch/index.d.ts +28 -0
  4. package/dist/adapters/fetch/index.mjs +9 -0
  5. package/dist/adapters/hono/index.d.mts +21 -0
  6. package/dist/adapters/hono/index.d.ts +21 -0
  7. package/dist/{hono.js → adapters/hono/index.mjs} +11 -13
  8. package/dist/adapters/next/index.d.mts +28 -0
  9. package/dist/adapters/next/index.d.ts +28 -0
  10. package/dist/{next.js → adapters/next/index.mjs} +11 -13
  11. package/dist/adapters/node/index.d.mts +36 -0
  12. package/dist/adapters/node/index.d.ts +36 -0
  13. package/dist/adapters/node/index.mjs +32 -0
  14. package/dist/adapters/standard/index.d.mts +26 -0
  15. package/dist/adapters/standard/index.d.ts +26 -0
  16. package/dist/adapters/standard/index.mjs +6 -0
  17. package/dist/index.d.mts +278 -0
  18. package/dist/index.d.ts +278 -0
  19. package/dist/{index.js → index.mjs} +93 -151
  20. package/dist/plugins/index.d.mts +31 -0
  21. package/dist/plugins/index.d.ts +31 -0
  22. package/dist/{chunk-XI6WGCB3.js → plugins/index.mjs} +17 -39
  23. package/dist/shared/server.BXfgvxK8.d.ts +8 -0
  24. package/dist/{chunk-XP6YRLY2.js → shared/server.B_5ZADvP.mjs} +179 -194
  25. package/dist/shared/server.D1vPuPwc.mjs +29 -0
  26. package/dist/shared/server.DKCNBSd-.d.mts +8 -0
  27. package/dist/shared/server.DisswUB5.mjs +158 -0
  28. package/dist/shared/server.Dj89-yLZ.d.ts +75 -0
  29. package/dist/shared/server.DnmJuN02.d.mts +144 -0
  30. package/dist/shared/server.DnmJuN02.d.ts +144 -0
  31. package/dist/shared/server.DpIMjOfC.d.mts +75 -0
  32. package/dist/shared/server.Q6ZmnTgO.mjs +12 -0
  33. package/package.json +29 -33
  34. package/dist/chunk-GBEB77SU.js +0 -32
  35. package/dist/chunk-GBL3M2PB.js +0 -325
  36. package/dist/fetch.js +0 -10
  37. package/dist/node.js +0 -31
  38. package/dist/plugins.js +0 -11
  39. package/dist/src/adapters/fetch/index.d.ts +0 -3
  40. package/dist/src/adapters/fetch/rpc-handler.d.ts +0 -11
  41. package/dist/src/adapters/fetch/types.d.ts +0 -14
  42. package/dist/src/adapters/hono/index.d.ts +0 -3
  43. package/dist/src/adapters/hono/middleware.d.ts +0 -12
  44. package/dist/src/adapters/next/index.d.ts +0 -3
  45. package/dist/src/adapters/next/serve.d.ts +0 -19
  46. package/dist/src/adapters/node/index.d.ts +0 -3
  47. package/dist/src/adapters/node/rpc-handler.d.ts +0 -11
  48. package/dist/src/adapters/node/types.d.ts +0 -22
  49. package/dist/src/adapters/standard/handler.d.ts +0 -51
  50. package/dist/src/adapters/standard/index.d.ts +0 -7
  51. package/dist/src/adapters/standard/rpc-codec.d.ts +0 -16
  52. package/dist/src/adapters/standard/rpc-handler.d.ts +0 -8
  53. package/dist/src/adapters/standard/rpc-matcher.d.ts +0 -10
  54. package/dist/src/adapters/standard/rpc-serializer.d.ts +0 -16
  55. package/dist/src/adapters/standard/types.d.ts +0 -20
  56. package/dist/src/builder-variants.d.ts +0 -74
  57. package/dist/src/builder.d.ts +0 -57
  58. package/dist/src/config.d.ts +0 -6
  59. package/dist/src/context.d.ts +0 -9
  60. package/dist/src/hidden.d.ts +0 -8
  61. package/dist/src/implementer-procedure.d.ts +0 -31
  62. package/dist/src/implementer-variants.d.ts +0 -17
  63. package/dist/src/implementer.d.ts +0 -28
  64. package/dist/src/index.d.ts +0 -23
  65. package/dist/src/lazy-utils.d.ts +0 -6
  66. package/dist/src/lazy.d.ts +0 -22
  67. package/dist/src/middleware-decorated.d.ts +0 -10
  68. package/dist/src/middleware-utils.d.ts +0 -5
  69. package/dist/src/middleware.d.ts +0 -36
  70. package/dist/src/plugins/base.d.ts +0 -13
  71. package/dist/src/plugins/cors.d.ts +0 -19
  72. package/dist/src/plugins/index.d.ts +0 -4
  73. package/dist/src/plugins/response-headers.d.ts +0 -10
  74. package/dist/src/procedure-client.d.ts +0 -30
  75. package/dist/src/procedure-decorated.d.ts +0 -22
  76. package/dist/src/procedure-utils.d.ts +0 -18
  77. package/dist/src/procedure.d.ts +0 -29
  78. package/dist/src/router-accessible-lazy.d.ts +0 -8
  79. package/dist/src/router-client.d.ts +0 -11
  80. package/dist/src/router.d.ts +0 -30
  81. package/dist/src/utils.d.ts +0 -24
  82. package/dist/standard.js +0 -17
@@ -1,325 +0,0 @@
1
- import {
2
- convertPathToHttpPath,
3
- createContractedProcedure,
4
- createProcedureClient,
5
- eachContractProcedure,
6
- getRouterChild,
7
- isProcedure,
8
- unlazy
9
- } from "./chunk-XP6YRLY2.js";
10
- import {
11
- CompositePlugin
12
- } from "./chunk-XI6WGCB3.js";
13
-
14
- // src/adapters/standard/handler.ts
15
- import { ORPCError, toORPCError } from "@orpc/contract";
16
- import { intercept, trim } from "@orpc/shared";
17
- var StandardHandler = class {
18
- constructor(router, matcher, codec, options = {}) {
19
- this.matcher = matcher;
20
- this.codec = codec;
21
- this.options = options;
22
- this.plugin = new CompositePlugin(options?.plugins);
23
- this.plugin.init(this.options);
24
- this.matcher.init(router);
25
- }
26
- plugin;
27
- handle(request, ...[options]) {
28
- return intercept(
29
- this.options.interceptorsRoot ?? [],
30
- {
31
- request,
32
- ...options,
33
- context: options?.context ?? {}
34
- // context is optional only when all fields are optional so we can safely force it to have a context
35
- },
36
- async (interceptorOptions) => {
37
- let isDecoding = false;
38
- try {
39
- return await intercept(
40
- this.options.interceptors ?? [],
41
- interceptorOptions,
42
- async (interceptorOptions2) => {
43
- const method = interceptorOptions2.request.method;
44
- const url = interceptorOptions2.request.url;
45
- const pathname = `/${trim(url.pathname.replace(interceptorOptions2.prefix ?? "", ""), "/")}`;
46
- const match = await this.matcher.match(method, pathname);
47
- if (!match) {
48
- return { matched: false, response: void 0 };
49
- }
50
- const clientOptions = {
51
- context: interceptorOptions2.context,
52
- path: match.path
53
- };
54
- this.plugin.beforeCreateProcedureClient(clientOptions, interceptorOptions2);
55
- const client = createProcedureClient(match.procedure, clientOptions);
56
- isDecoding = true;
57
- const input = await this.codec.decode(request, match.params, match.procedure);
58
- isDecoding = false;
59
- const output = await client(input, { signal: request.signal });
60
- const response = this.codec.encode(output, match.procedure);
61
- return {
62
- matched: true,
63
- response
64
- };
65
- }
66
- );
67
- } catch (e) {
68
- const error = isDecoding ? new ORPCError("BAD_REQUEST", {
69
- message: `Malformed request. Ensure the request body is properly formatted and the 'Content-Type' header is set correctly.`,
70
- cause: e
71
- }) : toORPCError(e);
72
- const response = this.codec.encodeError(error);
73
- return {
74
- matched: true,
75
- response
76
- };
77
- }
78
- }
79
- );
80
- }
81
- };
82
-
83
- // src/adapters/standard/rpc-serializer.ts
84
- import { findDeepMatches, isObject, set } from "@orpc/shared";
85
- var RPCSerializer = class {
86
- serialize(data) {
87
- if (data === void 0) {
88
- return void 0;
89
- }
90
- if (data instanceof Blob) {
91
- return data;
92
- }
93
- const serializedJSON = serializeRPCJson(data);
94
- const { maps, values: blobs } = findDeepMatches((v) => v instanceof Blob, serializedJSON.json);
95
- if (blobs.length === 0) {
96
- return serializedJSON;
97
- }
98
- const form = new FormData();
99
- form.set("data", JSON.stringify(serializedJSON));
100
- form.set("maps", JSON.stringify(maps));
101
- for (const i in blobs) {
102
- form.set(i, blobs[i]);
103
- }
104
- return form;
105
- }
106
- deserialize(serialized) {
107
- if (serialized === void 0) {
108
- return void 0;
109
- }
110
- if (serialized instanceof Blob) {
111
- return serialized;
112
- }
113
- if (!(serialized instanceof FormData)) {
114
- return deserializeRPCJson(serialized);
115
- }
116
- const data = JSON.parse(serialized.get("data"));
117
- const maps = JSON.parse(serialized.get("maps"));
118
- for (const i in maps) {
119
- data.json = set(data.json, maps[i], serialized.get(i));
120
- }
121
- return deserializeRPCJson(data);
122
- }
123
- };
124
- function serializeRPCJson(value, segments = [], meta = []) {
125
- if (typeof value === "bigint") {
126
- meta.push(["bigint", segments]);
127
- return { json: value.toString(), meta };
128
- }
129
- if (value instanceof Date) {
130
- meta.push(["date", segments]);
131
- const data = Number.isNaN(value.getTime()) ? "Invalid Date" : value.toISOString();
132
- return { json: data, meta };
133
- }
134
- if (Number.isNaN(value)) {
135
- meta.push(["nan", segments]);
136
- return { json: "NaN", meta };
137
- }
138
- if (value instanceof RegExp) {
139
- meta.push(["regexp", segments]);
140
- return { json: value.toString(), meta };
141
- }
142
- if (value instanceof URL) {
143
- meta.push(["url", segments]);
144
- return { json: value.toString(), meta };
145
- }
146
- if (isObject(value)) {
147
- const json = {};
148
- for (const k in value) {
149
- json[k] = serializeRPCJson(value[k], [...segments, k], meta).json;
150
- }
151
- return { json, meta };
152
- }
153
- if (Array.isArray(value)) {
154
- const json = value.map((v, i) => {
155
- if (v === void 0) {
156
- meta.push(["undefined", [...segments, i]]);
157
- return null;
158
- }
159
- return serializeRPCJson(v, [...segments, i], meta).json;
160
- });
161
- return { json, meta };
162
- }
163
- if (value instanceof Set) {
164
- const result = serializeRPCJson(Array.from(value), segments, meta);
165
- meta.push(["set", segments]);
166
- return result;
167
- }
168
- if (value instanceof Map) {
169
- const result = serializeRPCJson(Array.from(value.entries()), segments, meta);
170
- meta.push(["map", segments]);
171
- return result;
172
- }
173
- return { json: value, meta };
174
- }
175
- function deserializeRPCJson({
176
- json,
177
- meta
178
- }) {
179
- if (meta.length === 0) {
180
- return json;
181
- }
182
- const ref = { data: json };
183
- for (const [type, segments] of meta) {
184
- let currentRef = ref;
185
- let preSegment = "data";
186
- for (let i = 0; i < segments.length; i++) {
187
- currentRef = currentRef[preSegment];
188
- preSegment = segments[i];
189
- }
190
- switch (type) {
191
- case "nan":
192
- currentRef[preSegment] = Number.NaN;
193
- break;
194
- case "bigint":
195
- currentRef[preSegment] = BigInt(currentRef[preSegment]);
196
- break;
197
- case "date":
198
- currentRef[preSegment] = new Date(currentRef[preSegment]);
199
- break;
200
- case "regexp": {
201
- const [, pattern, flags] = currentRef[preSegment].match(/^\/(.*)\/([a-z]*)$/);
202
- currentRef[preSegment] = new RegExp(pattern, flags);
203
- break;
204
- }
205
- case "url":
206
- currentRef[preSegment] = new URL(currentRef[preSegment]);
207
- break;
208
- case "undefined":
209
- currentRef[preSegment] = void 0;
210
- break;
211
- case "map":
212
- currentRef[preSegment] = new Map(currentRef[preSegment]);
213
- break;
214
- case "set":
215
- currentRef[preSegment] = new Set(currentRef[preSegment]);
216
- break;
217
- /* v8 ignore next 3 */
218
- default: {
219
- const _expected = type;
220
- }
221
- }
222
- }
223
- return ref.data;
224
- }
225
-
226
- // src/adapters/standard/rpc-codec.ts
227
- var RPCCodec = class {
228
- serializer;
229
- constructor(options = {}) {
230
- this.serializer = options.serializer ?? new RPCSerializer();
231
- }
232
- async decode(request, _params, _procedure) {
233
- const serialized = request.method === "GET" ? JSON.parse(request.url.searchParams.getAll("data").at(-1)) : await request.body();
234
- return this.serializer.deserialize(serialized);
235
- }
236
- encode(output, _procedure) {
237
- return {
238
- status: 200,
239
- headers: {},
240
- body: this.serializer.serialize(output)
241
- };
242
- }
243
- encodeError(error) {
244
- return {
245
- status: error.status,
246
- headers: {},
247
- body: this.serializer.serialize(error.toJSON())
248
- };
249
- }
250
- };
251
-
252
- // src/adapters/standard/rpc-matcher.ts
253
- var RPCMatcher = class {
254
- tree = {};
255
- pendingRouters = [];
256
- init(router, path = []) {
257
- const laziedOptions = eachContractProcedure({
258
- router,
259
- path
260
- }, ({ path: path2, contract }) => {
261
- const httpPath = convertPathToHttpPath(path2);
262
- if (isProcedure(contract)) {
263
- this.tree[httpPath] = {
264
- path: path2,
265
- contract,
266
- procedure: contract,
267
- // this mean dev not used contract-first so we can used contract as procedure directly
268
- router
269
- };
270
- } else {
271
- this.tree[httpPath] = {
272
- path: path2,
273
- contract,
274
- procedure: void 0,
275
- router
276
- };
277
- }
278
- });
279
- this.pendingRouters.push(...laziedOptions.map((option) => ({
280
- ...option,
281
- httpPathPrefix: convertPathToHttpPath(option.path)
282
- })));
283
- }
284
- async match(_method, pathname) {
285
- if (this.pendingRouters.length) {
286
- const newPendingRouters = [];
287
- for (const pendingRouter of this.pendingRouters) {
288
- if (pathname.startsWith(pendingRouter.httpPathPrefix)) {
289
- const { default: router } = await unlazy(pendingRouter.lazied);
290
- this.init(router, pendingRouter.path);
291
- } else {
292
- newPendingRouters.push(pendingRouter);
293
- }
294
- }
295
- this.pendingRouters = newPendingRouters;
296
- }
297
- const match = this.tree[pathname];
298
- if (!match) {
299
- return void 0;
300
- }
301
- if (!match.procedure) {
302
- const { default: maybeProcedure } = await unlazy(getRouterChild(match.router, ...match.path));
303
- if (!isProcedure(maybeProcedure)) {
304
- throw new Error(`
305
- [Contract-First] Missing or invalid implementation for procedure at path: ${convertPathToHttpPath(match.path)}.
306
- Ensure that the procedure is correctly defined and matches the expected contract.
307
- `);
308
- }
309
- match.procedure = createContractedProcedure(match.contract, maybeProcedure);
310
- }
311
- return {
312
- path: match.path,
313
- procedure: match.procedure
314
- };
315
- }
316
- };
317
-
318
- export {
319
- StandardHandler,
320
- RPCSerializer,
321
- serializeRPCJson,
322
- RPCCodec,
323
- RPCMatcher
324
- };
325
- //# sourceMappingURL=chunk-GBL3M2PB.js.map
package/dist/fetch.js DELETED
@@ -1,10 +0,0 @@
1
- import {
2
- RPCHandler
3
- } from "./chunk-GBEB77SU.js";
4
- import "./chunk-GBL3M2PB.js";
5
- import "./chunk-XP6YRLY2.js";
6
- import "./chunk-XI6WGCB3.js";
7
- export {
8
- RPCHandler
9
- };
10
- //# sourceMappingURL=fetch.js.map
package/dist/node.js DELETED
@@ -1,31 +0,0 @@
1
- import {
2
- RPCCodec,
3
- RPCMatcher,
4
- StandardHandler
5
- } from "./chunk-GBL3M2PB.js";
6
- import "./chunk-XP6YRLY2.js";
7
- import "./chunk-XI6WGCB3.js";
8
-
9
- // src/adapters/node/rpc-handler.ts
10
- import { sendStandardResponse, toStandardRequest } from "@orpc/server-standard-node";
11
- var RPCHandler = class {
12
- standardHandler;
13
- constructor(router, options) {
14
- const codec = options?.codec ?? new RPCCodec();
15
- const matcher = options?.matcher ?? new RPCMatcher();
16
- this.standardHandler = new StandardHandler(router, matcher, codec, options);
17
- }
18
- async handle(req, res, ...rest) {
19
- const standardRequest = toStandardRequest(req, res);
20
- const result = await this.standardHandler.handle(standardRequest, ...rest);
21
- if (!result.matched) {
22
- return { matched: false };
23
- }
24
- await sendStandardResponse(res, result.response);
25
- return { matched: true };
26
- }
27
- };
28
- export {
29
- RPCHandler
30
- };
31
- //# sourceMappingURL=node.js.map
package/dist/plugins.js DELETED
@@ -1,11 +0,0 @@
1
- import {
2
- CORSPlugin,
3
- CompositePlugin,
4
- ResponseHeadersPlugin
5
- } from "./chunk-XI6WGCB3.js";
6
- export {
7
- CORSPlugin,
8
- CompositePlugin,
9
- ResponseHeadersPlugin
10
- };
11
- //# sourceMappingURL=plugins.js.map
@@ -1,3 +0,0 @@
1
- export * from './rpc-handler';
2
- export * from './types';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1,11 +0,0 @@
1
- import type { MaybeOptionalOptions } from '@orpc/shared';
2
- import type { Context } from '../../context';
3
- import type { Router } from '../../router';
4
- import type { RPCHandlerOptions, StandardHandleOptions } from '../standard';
5
- import type { FetchHandler, FetchHandleResult } from './types';
6
- export declare class RPCHandler<T extends Context> implements FetchHandler<T> {
7
- private readonly standardHandler;
8
- constructor(router: Router<T, any>, options?: NoInfer<RPCHandlerOptions<T>>);
9
- handle(request: Request, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<FetchHandleResult>;
10
- }
11
- //# sourceMappingURL=rpc-handler.d.ts.map
@@ -1,14 +0,0 @@
1
- import type { MaybeOptionalOptions } from '@orpc/shared';
2
- import type { Context } from '../../context';
3
- import type { StandardHandleOptions } from '../standard';
4
- export type FetchHandleResult = {
5
- matched: true;
6
- response: Response;
7
- } | {
8
- matched: false;
9
- response: undefined;
10
- };
11
- export interface FetchHandler<T extends Context> {
12
- handle(request: Request, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<FetchHandleResult>;
13
- }
14
- //# sourceMappingURL=types.d.ts.map
@@ -1,3 +0,0 @@
1
- export * from '../fetch';
2
- export * from './middleware';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1,12 +0,0 @@
1
- import type { MaybeOptionalOptions, Value } from '@orpc/shared';
2
- import type { Context as HonoContext, MiddlewareHandler } from 'hono';
3
- import type { Context } from '../../context';
4
- import type { FetchHandler } from '../fetch';
5
- import type { StandardHandleOptions } from '../standard';
6
- export type CreateMiddlewareOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
7
- context?: Value<T, [HonoContext]>;
8
- } : {
9
- context: Value<T, [HonoContext]>;
10
- });
11
- export declare function createMiddleware<T extends Context>(handler: FetchHandler<T>, ...[options]: MaybeOptionalOptions<CreateMiddlewareOptions<T>>): MiddlewareHandler;
12
- //# sourceMappingURL=middleware.d.ts.map
@@ -1,3 +0,0 @@
1
- export * from '../fetch';
2
- export * from './serve';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1,19 +0,0 @@
1
- import type { MaybeOptionalOptions, Value } from '@orpc/shared';
2
- import type { NextRequest } from 'next/server';
3
- import type { Context } from '../../context';
4
- import type { FetchHandler } from '../fetch';
5
- import type { StandardHandleOptions } from '../standard';
6
- export type ServeOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
7
- context?: Value<T, [NextRequest]>;
8
- } : {
9
- context: Value<T, [NextRequest]>;
10
- });
11
- export interface ServeResult {
12
- GET(req: NextRequest): Promise<Response>;
13
- POST(req: NextRequest): Promise<Response>;
14
- PUT(req: NextRequest): Promise<Response>;
15
- PATCH(req: NextRequest): Promise<Response>;
16
- DELETE(req: NextRequest): Promise<Response>;
17
- }
18
- export declare function serve<T extends Context>(handler: FetchHandler<T>, ...[options]: MaybeOptionalOptions<ServeOptions<T>>): ServeResult;
19
- //# sourceMappingURL=serve.d.ts.map
@@ -1,3 +0,0 @@
1
- export * from './rpc-handler';
2
- export * from './types';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1,11 +0,0 @@
1
- import type { MaybeOptionalOptions } from '@orpc/shared';
2
- import type { Context } from '../../context';
3
- import type { Router } from '../../router';
4
- import type { RPCHandlerOptions, StandardHandleOptions } from '../standard';
5
- import type { NodeHttpHandler, NodeHttpHandleResult, NodeHttpRequest, NodeHttpResponse } from './types';
6
- export declare class RPCHandler<T extends Context> implements NodeHttpHandler<T> {
7
- private readonly standardHandler;
8
- constructor(router: Router<T, any>, options?: NoInfer<RPCHandlerOptions<T>>);
9
- handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<NodeHttpHandleResult>;
10
- }
11
- //# sourceMappingURL=rpc-handler.d.ts.map
@@ -1,22 +0,0 @@
1
- import type { MaybeOptionalOptions } from '@orpc/shared';
2
- import type { IncomingMessage, ServerResponse } from 'node:http';
3
- import type { Http2ServerRequest, Http2ServerResponse } from 'node:http2';
4
- import type { Context } from '../../context';
5
- import type { StandardHandleOptions } from '../standard';
6
- export type NodeHttpRequest = (IncomingMessage | Http2ServerRequest) & {
7
- /**
8
- * Replace `req.url` with `req.originalUrl` when `req.originalUrl` is available.
9
- * This is useful for `express.js` middleware.
10
- */
11
- originalUrl?: string;
12
- };
13
- export type NodeHttpResponse = ServerResponse | Http2ServerResponse;
14
- export type NodeHttpHandleResult = {
15
- matched: true;
16
- } | {
17
- matched: false;
18
- };
19
- export interface NodeHttpHandler<T extends Context> {
20
- handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<NodeHttpHandleResult>;
21
- }
22
- //# sourceMappingURL=types.d.ts.map
@@ -1,51 +0,0 @@
1
- import type { ErrorMap, HTTPPath, Meta, Schema } from '@orpc/contract';
2
- import type { StandardRequest, StandardResponse } from '@orpc/server-standard';
3
- import type { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
4
- import type { Context } from '../../context';
5
- import type { Plugin } from '../../plugins';
6
- import type { CreateProcedureClientOptions } from '../../procedure-client';
7
- import type { Router } from '../../router';
8
- import type { StandardCodec, StandardMatcher } from './types';
9
- export type StandardHandleOptions<T extends Context> = {
10
- prefix?: HTTPPath;
11
- } & (Record<never, never> extends T ? {
12
- context?: T;
13
- } : {
14
- context: T;
15
- });
16
- export type WellStandardHandleOptions<T extends Context> = StandardHandleOptions<T> & {
17
- context: T;
18
- };
19
- export type StandardHandleResult = {
20
- matched: true;
21
- response: StandardResponse;
22
- } | {
23
- matched: false;
24
- response: undefined;
25
- };
26
- export type StandardHandlerInterceptorOptions<TContext extends Context> = WellStandardHandleOptions<TContext> & {
27
- request: StandardRequest;
28
- };
29
- export type WellCreateProcedureClientOptions<TContext extends Context> = CreateProcedureClientOptions<TContext, Schema, Schema, unknown, ErrorMap, Meta, Record<never, never>> & {
30
- context: TContext;
31
- };
32
- export interface StandardHandlerOptions<TContext extends Context> {
33
- plugins?: Plugin<TContext>[];
34
- /**
35
- * Interceptors at the request level, helpful when you want catch errors
36
- */
37
- interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
38
- /**
39
- * Interceptors at the root level, helpful when you want override the response
40
- */
41
- interceptorsRoot?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
42
- }
43
- export declare class StandardHandler<T extends Context> {
44
- private readonly matcher;
45
- private readonly codec;
46
- private readonly options;
47
- private readonly plugin;
48
- constructor(router: Router<T, any>, matcher: StandardMatcher, codec: StandardCodec, options?: NoInfer<StandardHandlerOptions<T>>);
49
- handle(request: StandardRequest, ...[options]: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<StandardHandleResult>;
50
- }
51
- //# sourceMappingURL=handler.d.ts.map
@@ -1,7 +0,0 @@
1
- export * from './handler';
2
- export * from './rpc-codec';
3
- export * from './rpc-handler';
4
- export * from './rpc-matcher';
5
- export * from './rpc-serializer';
6
- export * from './types';
7
- //# sourceMappingURL=index.d.ts.map
@@ -1,16 +0,0 @@
1
- import type { ORPCError } from '@orpc/contract';
2
- import type { StandardRequest, StandardResponse } from '@orpc/server-standard';
3
- import type { AnyProcedure } from '../../procedure';
4
- import type { StandardCodec, StandardParams } from './types';
5
- import { RPCSerializer } from './rpc-serializer';
6
- export interface StandardCodecOptions {
7
- serializer?: RPCSerializer;
8
- }
9
- export declare class RPCCodec implements StandardCodec {
10
- private readonly serializer;
11
- constructor(options?: StandardCodecOptions);
12
- decode(request: StandardRequest, _params: StandardParams | undefined, _procedure: AnyProcedure): Promise<unknown>;
13
- encode(output: unknown, _procedure: AnyProcedure): StandardResponse;
14
- encodeError(error: ORPCError<any, any>): StandardResponse;
15
- }
16
- //# sourceMappingURL=rpc-codec.d.ts.map
@@ -1,8 +0,0 @@
1
- import type { Context } from '../../context';
2
- import type { StandardHandlerOptions } from './handler';
3
- import type { StandardCodec, StandardMatcher } from './types';
4
- export interface RPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T> {
5
- matcher?: StandardMatcher;
6
- codec?: StandardCodec;
7
- }
8
- //# sourceMappingURL=rpc-handler.d.ts.map
@@ -1,10 +0,0 @@
1
- import type { HTTPPath } from '@orpc/contract';
2
- import type { StandardMatcher, StandardMatchResult } from './types';
3
- import { type AnyRouter } from '../../router';
4
- export declare class RPCMatcher implements StandardMatcher {
5
- private readonly tree;
6
- private pendingRouters;
7
- init(router: AnyRouter, path?: string[]): void;
8
- match(_method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
9
- }
10
- //# sourceMappingURL=rpc-matcher.d.ts.map
@@ -1,16 +0,0 @@
1
- import type { Segment } from '@orpc/shared';
2
- export type RPCSerializedJsonMeta = ['bigint' | 'date' | 'nan' | 'undefined' | 'set' | 'map' | 'regexp' | 'url', Segment[]][];
3
- export type RPCSerialized = {
4
- json: unknown;
5
- meta: RPCSerializedJsonMeta;
6
- } | FormData | Blob | undefined;
7
- export type RPCSerializedFormDataMaps = Segment[][];
8
- export declare class RPCSerializer {
9
- serialize(data: unknown): RPCSerialized;
10
- deserialize(serialized: RPCSerialized): unknown;
11
- }
12
- export declare function serializeRPCJson(value: unknown, segments?: Segment[], meta?: RPCSerializedJsonMeta): {
13
- json: unknown;
14
- meta: RPCSerializedJsonMeta;
15
- };
16
- //# sourceMappingURL=rpc-serializer.d.ts.map
@@ -1,20 +0,0 @@
1
- import type { HTTPPath, ORPCError } from '@orpc/contract';
2
- import type { StandardRequest, StandardResponse } from '@orpc/server-standard';
3
- import type { AnyProcedure } from '../../procedure';
4
- import type { AnyRouter } from '../../router';
5
- export type StandardParams = Record<string, string>;
6
- export type StandardMatchResult = {
7
- path: string[];
8
- procedure: AnyProcedure;
9
- params?: StandardParams;
10
- } | undefined;
11
- export interface StandardMatcher {
12
- init(router: AnyRouter): void;
13
- match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
14
- }
15
- export interface StandardCodec {
16
- encode(output: unknown, procedure: AnyProcedure): StandardResponse;
17
- encodeError(error: ORPCError<any, any>): StandardResponse;
18
- decode(request: StandardRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
19
- }
20
- //# sourceMappingURL=types.d.ts.map