@orpc/server 0.0.0-next.31590a1 → 0.0.0-next.32cb70c

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/chunk-ESTRJAOX.js +299 -0
  2. package/dist/{chunk-NOA3GBJQ.js → chunk-KK4SDLC7.js} +9 -69
  3. package/dist/chunk-WUOGVGWG.js +1 -0
  4. package/dist/fetch.js +9 -12
  5. package/dist/hono.js +13 -25
  6. package/dist/index.js +2 -16
  7. package/dist/next.js +10 -13
  8. package/dist/node.js +61 -149
  9. package/dist/src/adapters/fetch/index.d.ts +4 -2
  10. package/dist/src/adapters/fetch/orpc-handler.d.ts +20 -0
  11. package/dist/src/adapters/fetch/orpc-payload-codec.d.ts +16 -0
  12. package/dist/src/adapters/fetch/orpc-procedure-matcher.d.ts +12 -0
  13. package/dist/src/adapters/fetch/super-json.d.ts +12 -0
  14. package/dist/src/adapters/fetch/types.d.ts +10 -2
  15. package/dist/src/adapters/hono/middleware.d.ts +2 -3
  16. package/dist/src/adapters/next/serve.d.ts +2 -3
  17. package/dist/src/adapters/node/index.d.ts +3 -2
  18. package/dist/src/adapters/node/orpc-handler.d.ts +12 -0
  19. package/dist/src/adapters/node/request-listener.d.ts +28 -0
  20. package/dist/src/adapters/node/types.d.ts +14 -13
  21. package/dist/src/implementer-variants.d.ts +5 -6
  22. package/dist/src/implementer.d.ts +6 -7
  23. package/dist/src/index.d.ts +1 -3
  24. package/package.json +3 -17
  25. package/dist/chunk-CVIWJKJC.js +0 -308
  26. package/dist/chunk-EYGVJA7A.js +0 -136
  27. package/dist/chunk-OXB4YX67.js +0 -111
  28. package/dist/plugins.js +0 -11
  29. package/dist/src/adapters/fetch/rpc-handler.d.ts +0 -10
  30. package/dist/src/adapters/fetch/utils.d.ts +0 -6
  31. package/dist/src/adapters/node/rpc-handler.d.ts +0 -10
  32. package/dist/src/adapters/node/utils.d.ts +0 -5
  33. package/dist/src/adapters/standard/handler.d.ts +0 -47
  34. package/dist/src/adapters/standard/index.d.ts +0 -7
  35. package/dist/src/adapters/standard/rpc-codec.d.ts +0 -15
  36. package/dist/src/adapters/standard/rpc-handler.d.ts +0 -8
  37. package/dist/src/adapters/standard/rpc-matcher.d.ts +0 -10
  38. package/dist/src/adapters/standard/rpc-serializer.d.ts +0 -16
  39. package/dist/src/adapters/standard/types.d.ts +0 -44
  40. package/dist/src/plugins/base.d.ts +0 -11
  41. package/dist/src/plugins/cors.d.ts +0 -18
  42. package/dist/src/plugins/index.d.ts +0 -4
  43. package/dist/src/plugins/response-headers.d.ts +0 -10
  44. package/dist/src/utils.d.ts +0 -24
  45. package/dist/standard.js +0 -17
@@ -1,308 +0,0 @@
1
- import {
2
- convertPathToHttpPath,
3
- createContractedProcedure,
4
- createProcedureClient,
5
- eachContractProcedure,
6
- getRouterChild,
7
- isProcedure,
8
- unlazy
9
- } from "./chunk-NOA3GBJQ.js";
10
- import {
11
- CompositePlugin
12
- } from "./chunk-OXB4YX67.js";
13
-
14
- // src/adapters/standard/handler.ts
15
- import { 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
- const handleOptions = options ?? {};
29
- handleOptions.context ??= {};
30
- return intercept(
31
- this.options.interceptorsRoot ?? [],
32
- { request, ...handleOptions },
33
- async (interceptorRootOptions) => {
34
- try {
35
- return await intercept(
36
- this.options.interceptors ?? [],
37
- interceptorRootOptions,
38
- async ({ request: request2, context }) => {
39
- const method = request2.method;
40
- const url = request2.url;
41
- const pathname = `/${trim(url.pathname.replace(options?.prefix ?? "", ""), "/")}`;
42
- const match = await this.matcher.match(method, pathname);
43
- if (!match) {
44
- return { matched: false, response: void 0 };
45
- }
46
- const client = createProcedureClient(match.procedure, {
47
- context,
48
- path: match.path
49
- });
50
- const input = await this.codec.decode(request2, match.params, match.procedure);
51
- const output = await client(input, { signal: request2.signal });
52
- const response = this.codec.encode(output, match.procedure);
53
- return {
54
- matched: true,
55
- response
56
- };
57
- }
58
- );
59
- } catch (e) {
60
- const error = toORPCError(e);
61
- const response = this.codec.encodeError(error);
62
- return {
63
- matched: true,
64
- response
65
- };
66
- }
67
- }
68
- );
69
- }
70
- };
71
-
72
- // src/adapters/standard/rpc-serializer.ts
73
- import { findDeepMatches, isPlainObject, set } from "@orpc/shared";
74
- var RPCSerializer = class {
75
- serialize(data) {
76
- if (data instanceof Blob) {
77
- return data;
78
- }
79
- const serializedJSON = serializeRPCJson(data);
80
- const { maps, values: blobs } = findDeepMatches((v) => v instanceof Blob, serializedJSON.json);
81
- if (blobs.length === 0) {
82
- return serializedJSON;
83
- }
84
- const form = new FormData();
85
- form.set("data", JSON.stringify(serializedJSON));
86
- form.set("maps", JSON.stringify(maps));
87
- for (const i in blobs) {
88
- form.set(i, blobs[i]);
89
- }
90
- return form;
91
- }
92
- deserialize(serialized) {
93
- if (serialized instanceof Blob) {
94
- return serialized;
95
- }
96
- if (!(serialized instanceof FormData)) {
97
- return deserializeRPCJson(serialized);
98
- }
99
- const data = JSON.parse(serialized.get("data"));
100
- const maps = JSON.parse(serialized.get("maps"));
101
- for (const i in maps) {
102
- data.json = set(data.json, maps[i], serialized.get(i));
103
- }
104
- return deserializeRPCJson(data);
105
- }
106
- };
107
- function serializeRPCJson(value, segments = [], meta = []) {
108
- if (typeof value === "bigint") {
109
- meta.push(["bigint", segments]);
110
- return { json: value.toString(), meta };
111
- }
112
- if (value instanceof Date) {
113
- meta.push(["date", segments]);
114
- const data = Number.isNaN(value.getTime()) ? "Invalid Date" : value.toISOString();
115
- return { json: data, meta };
116
- }
117
- if (Number.isNaN(value)) {
118
- meta.push(["nan", segments]);
119
- return { json: "NaN", meta };
120
- }
121
- if (value instanceof RegExp) {
122
- meta.push(["regexp", segments]);
123
- return { json: value.toString(), meta };
124
- }
125
- if (value instanceof URL) {
126
- meta.push(["url", segments]);
127
- return { json: value.toString(), meta };
128
- }
129
- if (isPlainObject(value)) {
130
- const json = {};
131
- for (const k in value) {
132
- json[k] = serializeRPCJson(value[k], [...segments, k], meta).json;
133
- }
134
- return { json, meta };
135
- }
136
- if (Array.isArray(value)) {
137
- const json = value.map((v, i) => {
138
- if (v === void 0) {
139
- meta.push(["undefined", [...segments, i]]);
140
- return null;
141
- }
142
- return serializeRPCJson(v, [...segments, i], meta).json;
143
- });
144
- return { json, meta };
145
- }
146
- if (value instanceof Set) {
147
- const result = serializeRPCJson(Array.from(value), segments, meta);
148
- meta.push(["set", segments]);
149
- return result;
150
- }
151
- if (value instanceof Map) {
152
- const result = serializeRPCJson(Array.from(value.entries()), segments, meta);
153
- meta.push(["map", segments]);
154
- return result;
155
- }
156
- return { json: value, meta };
157
- }
158
- function deserializeRPCJson({
159
- json,
160
- meta
161
- }) {
162
- if (meta.length === 0) {
163
- return json;
164
- }
165
- const ref = { data: json };
166
- for (const [type, segments] of meta) {
167
- let currentRef = ref;
168
- let preSegment = "data";
169
- for (let i = 0; i < segments.length; i++) {
170
- currentRef = currentRef[preSegment];
171
- preSegment = segments[i];
172
- }
173
- switch (type) {
174
- case "nan":
175
- currentRef[preSegment] = Number.NaN;
176
- break;
177
- case "bigint":
178
- currentRef[preSegment] = BigInt(currentRef[preSegment]);
179
- break;
180
- case "date":
181
- currentRef[preSegment] = new Date(currentRef[preSegment]);
182
- break;
183
- case "regexp": {
184
- const [, pattern, flags] = currentRef[preSegment].match(/^\/(.*)\/([a-z]*)$/);
185
- currentRef[preSegment] = new RegExp(pattern, flags);
186
- break;
187
- }
188
- case "url":
189
- currentRef[preSegment] = new URL(currentRef[preSegment]);
190
- break;
191
- case "undefined":
192
- currentRef[preSegment] = void 0;
193
- break;
194
- case "map":
195
- currentRef[preSegment] = new Map(currentRef[preSegment]);
196
- break;
197
- case "set":
198
- currentRef[preSegment] = new Set(currentRef[preSegment]);
199
- break;
200
- /* v8 ignore next 3 */
201
- default: {
202
- const _expected = type;
203
- }
204
- }
205
- }
206
- return ref.data;
207
- }
208
-
209
- // src/adapters/standard/rpc-codec.ts
210
- var RPCCodec = class {
211
- serializer;
212
- constructor(options = {}) {
213
- this.serializer = options.serializer ?? new RPCSerializer();
214
- }
215
- async decode(request, _params, _procedure) {
216
- const serialized = request.method === "GET" ? JSON.parse(request.url.searchParams.getAll("data").at(-1)) : await request.body();
217
- return this.serializer.deserialize(serialized);
218
- }
219
- encode(output, _procedure) {
220
- return {
221
- status: 200,
222
- headers: {},
223
- body: this.serializer.serialize(output)
224
- };
225
- }
226
- encodeError(error) {
227
- return {
228
- status: error.status,
229
- headers: {},
230
- body: this.serializer.serialize(error.toJSON())
231
- };
232
- }
233
- };
234
-
235
- // src/adapters/standard/rpc-matcher.ts
236
- var RPCMatcher = class {
237
- tree = {};
238
- pendingRouters = [];
239
- init(router, path = []) {
240
- const laziedOptions = eachContractProcedure({
241
- router,
242
- path
243
- }, ({ path: path2, contract }) => {
244
- const httpPath = convertPathToHttpPath(path2);
245
- if (isProcedure(contract)) {
246
- this.tree[httpPath] = {
247
- path: path2,
248
- contract,
249
- procedure: contract,
250
- // this mean dev not used contract-first so we can used contract as procedure directly
251
- router
252
- };
253
- } else {
254
- this.tree[httpPath] = {
255
- path: path2,
256
- contract,
257
- procedure: void 0,
258
- router
259
- };
260
- }
261
- });
262
- this.pendingRouters.push(...laziedOptions.map((option) => ({
263
- ...option,
264
- httpPathPrefix: convertPathToHttpPath(option.path)
265
- })));
266
- }
267
- async match(_method, pathname) {
268
- if (this.pendingRouters.length) {
269
- const newPendingRouters = [];
270
- for (const pendingRouter of this.pendingRouters) {
271
- if (pathname.startsWith(pendingRouter.httpPathPrefix)) {
272
- const { default: router } = await unlazy(pendingRouter.lazied);
273
- this.init(router, pendingRouter.path);
274
- } else {
275
- newPendingRouters.push(pendingRouter);
276
- }
277
- }
278
- this.pendingRouters = newPendingRouters;
279
- }
280
- const match = this.tree[pathname];
281
- if (!match) {
282
- return void 0;
283
- }
284
- if (!match.procedure) {
285
- const { default: maybeProcedure } = await unlazy(getRouterChild(match.router, ...match.path));
286
- if (!isProcedure(maybeProcedure)) {
287
- throw new Error(`
288
- [Contract-First] Missing or invalid implementation for procedure at path: ${convertPathToHttpPath(match.path)}.
289
- Ensure that the procedure is correctly defined and matches the expected contract.
290
- `);
291
- }
292
- match.procedure = createContractedProcedure(match.contract, maybeProcedure);
293
- }
294
- return {
295
- path: match.path,
296
- procedure: match.procedure
297
- };
298
- }
299
- };
300
-
301
- export {
302
- StandardHandler,
303
- RPCSerializer,
304
- serializeRPCJson,
305
- RPCCodec,
306
- RPCMatcher
307
- };
308
- //# sourceMappingURL=chunk-CVIWJKJC.js.map
@@ -1,136 +0,0 @@
1
- import {
2
- RPCCodec,
3
- RPCMatcher,
4
- StandardHandler
5
- } from "./chunk-CVIWJKJC.js";
6
-
7
- // src/adapters/fetch/utils.ts
8
- import { once } from "@orpc/shared";
9
- import cd from "content-disposition";
10
- function fetchHeadersToStandardHeaders(headers) {
11
- const standardHeaders = {};
12
- for (const [key, value] of headers) {
13
- if (Array.isArray(standardHeaders[key])) {
14
- standardHeaders[key].push(value);
15
- } else if (standardHeaders[key] !== void 0) {
16
- standardHeaders[key] = [standardHeaders[key], value];
17
- } else {
18
- standardHeaders[key] = value;
19
- }
20
- }
21
- return standardHeaders;
22
- }
23
- async function fetchReToStandardBody(re) {
24
- if (!re.body) {
25
- return void 0;
26
- }
27
- const contentDisposition = re.headers.get("content-disposition");
28
- const fileName = contentDisposition ? cd.parse(contentDisposition).parameters.filename : void 0;
29
- if (fileName) {
30
- const blob2 = await re.blob();
31
- return new File([blob2], fileName, {
32
- type: blob2.type
33
- });
34
- }
35
- const contentType = re.headers.get("content-type");
36
- if (!contentType || contentType.startsWith("application/json")) {
37
- const text = await re.text();
38
- if (!text) {
39
- return void 0;
40
- }
41
- return JSON.parse(text);
42
- }
43
- if (contentType.startsWith("multipart/form-data")) {
44
- return await re.formData();
45
- }
46
- if (contentType.startsWith("application/x-www-form-urlencoded")) {
47
- return new URLSearchParams(await re.text());
48
- }
49
- if (contentType.startsWith("text/")) {
50
- return await re.text();
51
- }
52
- const blob = await re.blob();
53
- return new File([blob], "blob", {
54
- type: blob.type
55
- });
56
- }
57
- function fetchRequestToStandardRequest(request) {
58
- const url = new URL(request.url);
59
- return {
60
- raw: { request },
61
- url,
62
- signal: request.signal,
63
- method: request.method,
64
- body: once(() => {
65
- return fetchReToStandardBody(request);
66
- }),
67
- get headers() {
68
- const headers = fetchHeadersToStandardHeaders(request.headers);
69
- Object.defineProperty(this, "headers", { value: headers, writable: true });
70
- return headers;
71
- },
72
- set headers(value) {
73
- Object.defineProperty(this, "headers", { value, writable: true });
74
- }
75
- };
76
- }
77
- function standardResponseToFetchHeaders(response) {
78
- const fetchHeaders = new Headers();
79
- for (const [key, value] of Object.entries(response.headers)) {
80
- if (Array.isArray(value)) {
81
- for (const v of value) {
82
- fetchHeaders.append(key, v);
83
- }
84
- } else if (value !== void 0) {
85
- fetchHeaders.append(key, value);
86
- }
87
- }
88
- if (response.body instanceof Blob && !fetchHeaders.has("content-disposition")) {
89
- fetchHeaders.set("content-disposition", cd(response.body instanceof File ? response.body.name : "blob"));
90
- } else if (!(response.body instanceof Blob) && !(response.body instanceof URLSearchParams) && !(response.body instanceof FormData) && response.body !== void 0 && !fetchHeaders.has("content-type")) {
91
- fetchHeaders.set("content-type", "application/json");
92
- }
93
- return fetchHeaders;
94
- }
95
- function standardBodyToFetchBody(body) {
96
- if (body instanceof Blob || body instanceof FormData || body instanceof URLSearchParams) {
97
- return body;
98
- }
99
- return JSON.stringify(body);
100
- }
101
- function standardResponseToFetchResponse(response) {
102
- return new Response(standardBodyToFetchBody(response.body), {
103
- headers: standardResponseToFetchHeaders(response),
104
- status: response.status
105
- });
106
- }
107
-
108
- // src/adapters/fetch/rpc-handler.ts
109
- var RPCHandler = class {
110
- standardHandler;
111
- constructor(router, options) {
112
- const matcher = options?.matcher ?? new RPCMatcher();
113
- const codec = options?.codec ?? new RPCCodec();
114
- this.standardHandler = new StandardHandler(router, matcher, codec, options);
115
- }
116
- async handle(request, ...rest) {
117
- const standardRequest = fetchRequestToStandardRequest(request);
118
- const result = await this.standardHandler.handle(standardRequest, ...rest);
119
- if (!result.matched) {
120
- return result;
121
- }
122
- return {
123
- matched: true,
124
- response: standardResponseToFetchResponse(result.response)
125
- };
126
- }
127
- };
128
-
129
- export {
130
- fetchReToStandardBody,
131
- fetchRequestToStandardRequest,
132
- standardBodyToFetchBody,
133
- standardResponseToFetchResponse,
134
- RPCHandler
135
- };
136
- //# sourceMappingURL=chunk-EYGVJA7A.js.map
@@ -1,111 +0,0 @@
1
- // src/plugins/base.ts
2
- var CompositePlugin = class {
3
- constructor(plugins = []) {
4
- this.plugins = plugins;
5
- }
6
- init(options) {
7
- for (const plugin of this.plugins) {
8
- plugin.init?.(options);
9
- }
10
- }
11
- };
12
-
13
- // src/plugins/cors.ts
14
- import { value } from "@orpc/shared";
15
- var CORSPlugin = class {
16
- options;
17
- constructor(options) {
18
- const defaults = {
19
- origin: "*",
20
- allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"]
21
- };
22
- this.options = {
23
- ...defaults,
24
- ...options
25
- };
26
- }
27
- init(options) {
28
- options.interceptorsRoot ??= [];
29
- options.interceptorsRoot.unshift(async (interceptorOptions) => {
30
- if (interceptorOptions.request.method === "OPTIONS") {
31
- const resHeaders = {};
32
- if (this.options.maxAge !== void 0) {
33
- resHeaders["access-control-max-age"] = this.options.maxAge.toString();
34
- }
35
- if (this.options.allowMethods?.length) {
36
- resHeaders["access-control-allow-methods"] = this.options.allowMethods.join(",");
37
- }
38
- const allowHeaders = this.options.allowHeaders ?? interceptorOptions.request.headers["access-control-request-headers"];
39
- if (Array.isArray(allowHeaders) && allowHeaders.length) {
40
- resHeaders["access-control-allow-headers"] = allowHeaders.join(",");
41
- } else if (typeof allowHeaders === "string") {
42
- resHeaders["access-control-allow-headers"] = allowHeaders;
43
- }
44
- return {
45
- matched: true,
46
- response: {
47
- status: 204,
48
- headers: resHeaders,
49
- body: void 0
50
- }
51
- };
52
- }
53
- return interceptorOptions.next();
54
- });
55
- options.interceptorsRoot.unshift(async (interceptorOptions) => {
56
- const result = await interceptorOptions.next();
57
- if (!result.matched) {
58
- return result;
59
- }
60
- const origin = Array.isArray(interceptorOptions.request.headers.origin) ? interceptorOptions.request.headers.origin.join(",") : interceptorOptions.request.headers.origin || "";
61
- const allowedOrigin = await value(this.options.origin, origin, interceptorOptions);
62
- const allowedOriginArr = Array.isArray(allowedOrigin) ? allowedOrigin : [allowedOrigin];
63
- if (allowedOriginArr.includes(origin)) {
64
- result.response.headers["access-control-allow-origin"] = origin;
65
- }
66
- if (!allowedOriginArr.includes("*")) {
67
- result.response.headers.vary = interceptorOptions.request.headers.vary ?? "origin";
68
- }
69
- if (this.options.credentials) {
70
- result.response.headers["access-control-allow-credentials"] = "true";
71
- }
72
- if (this.options.exposeHeaders?.length) {
73
- result.response.headers["access-control-expose-headers"] = this.options.exposeHeaders.join(",");
74
- }
75
- return result;
76
- });
77
- }
78
- };
79
-
80
- // src/plugins/response-headers.ts
81
- var ResponseHeadersPlugin = class {
82
- init(options) {
83
- options.interceptorsRoot ??= [];
84
- options.interceptorsRoot.push(async (interceptorOptions) => {
85
- const headers = new Headers();
86
- interceptorOptions.context.resHeaders = headers;
87
- const result = await interceptorOptions.next();
88
- if (!result.matched) {
89
- return result;
90
- }
91
- const responseHeaders = result.response.headers;
92
- for (const [key, value2] of headers) {
93
- if (Array.isArray(responseHeaders[key])) {
94
- responseHeaders[key].push(value2);
95
- } else if (responseHeaders[key] !== void 0) {
96
- responseHeaders[key] = [responseHeaders[key], value2];
97
- } else {
98
- responseHeaders[key] = value2;
99
- }
100
- }
101
- return result;
102
- });
103
- }
104
- };
105
-
106
- export {
107
- CompositePlugin,
108
- CORSPlugin,
109
- ResponseHeadersPlugin
110
- };
111
- //# sourceMappingURL=chunk-OXB4YX67.js.map
package/dist/plugins.js DELETED
@@ -1,11 +0,0 @@
1
- import {
2
- CORSPlugin,
3
- CompositePlugin,
4
- ResponseHeadersPlugin
5
- } from "./chunk-OXB4YX67.js";
6
- export {
7
- CORSPlugin,
8
- CompositePlugin,
9
- ResponseHeadersPlugin
10
- };
11
- //# sourceMappingURL=plugins.js.map
@@ -1,10 +0,0 @@
1
- import type { Context } from '../../context';
2
- import type { Router } from '../../router';
3
- import type { RPCHandlerOptions, StandardHandleRest } from '../standard';
4
- import type { FetchHandler, FetchHandleResult } from './types';
5
- export declare class RPCHandler<T extends Context> implements FetchHandler<T> {
6
- private readonly standardHandler;
7
- constructor(router: Router<T, any>, options?: NoInfer<RPCHandlerOptions<T>>);
8
- handle(request: Request, ...rest: StandardHandleRest<T>): Promise<FetchHandleResult>;
9
- }
10
- //# sourceMappingURL=rpc-handler.d.ts.map
@@ -1,6 +0,0 @@
1
- import type { StandardBody, StandardRequest, StandardResponse } from '../standard';
2
- export declare function fetchReToStandardBody(re: Request | Response): Promise<StandardBody>;
3
- export declare function fetchRequestToStandardRequest(request: Request): StandardRequest;
4
- export declare function standardBodyToFetchBody(body: StandardBody): Blob | FormData | URLSearchParams | string | undefined;
5
- export declare function standardResponseToFetchResponse(response: StandardResponse): Response;
6
- //# sourceMappingURL=utils.d.ts.map
@@ -1,10 +0,0 @@
1
- import type { Context } from '../../context';
2
- import type { Router } from '../../router';
3
- import type { RPCHandlerOptions, StandardHandleRest } from '../standard';
4
- import type { NodeHttpHandler, NodeHttpHandleResult, NodeHttpRequest, NodeHttpResponse } from './types';
5
- export declare class RPCHandler<T extends Context> implements NodeHttpHandler<T> {
6
- private readonly standardHandler;
7
- constructor(router: Router<T, any>, options?: NoInfer<RPCHandlerOptions<T>>);
8
- handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest: StandardHandleRest<T>): Promise<NodeHttpHandleResult>;
9
- }
10
- //# sourceMappingURL=rpc-handler.d.ts.map
@@ -1,5 +0,0 @@
1
- import type { StandardRequest, StandardResponse } from '../standard';
2
- import type { NodeHttpRequest, NodeHttpResponse } from './types';
3
- export declare function nodeHttpToStandardRequest(req: NodeHttpRequest, res: NodeHttpResponse): StandardRequest;
4
- export declare function nodeHttpResponseSendStandardResponse(res: NodeHttpResponse, standardResponse: StandardResponse): Promise<void>;
5
- //# sourceMappingURL=utils.d.ts.map
@@ -1,47 +0,0 @@
1
- import type { HTTPPath } from '@orpc/contract';
2
- import type { Interceptor } from '@orpc/shared';
3
- import type { Context } from '../../context';
4
- import type { Plugin } from '../../plugins';
5
- import type { Router } from '../../router';
6
- import type { StandardCodec, StandardMatcher, StandardRequest, StandardResponse } from './types';
7
- export type StandardHandleOptions<T extends Context> = {
8
- prefix?: HTTPPath;
9
- } & (Record<never, never> extends T ? {
10
- context?: T;
11
- } : {
12
- context: T;
13
- });
14
- export type WellStandardHandleOptions<T extends Context> = StandardHandleOptions<T> & {
15
- context: T;
16
- };
17
- export type StandardHandleRest<T extends Context> = [options: StandardHandleOptions<T>] | (Record<never, never> extends T ? [] : never);
18
- export type StandardHandleResult = {
19
- matched: true;
20
- response: StandardResponse;
21
- } | {
22
- matched: false;
23
- response: undefined;
24
- };
25
- export type StandardHandlerInterceptorOptions<TContext extends Context> = WellStandardHandleOptions<TContext> & {
26
- request: StandardRequest;
27
- };
28
- export interface StandardHandlerOptions<TContext extends Context> {
29
- plugins?: Plugin<TContext>[];
30
- /**
31
- * Interceptors at the request level, helpful when you want catch errors
32
- */
33
- interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
34
- /**
35
- * Interceptors at the root level, helpful when you want override the response
36
- */
37
- interceptorsRoot?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
38
- }
39
- export declare class StandardHandler<TContext extends Context> {
40
- private readonly matcher;
41
- private readonly codec;
42
- private readonly options;
43
- private readonly plugin;
44
- constructor(router: Router<TContext, any>, matcher: StandardMatcher, codec: StandardCodec, options?: NoInfer<StandardHandlerOptions<TContext>>);
45
- handle(request: StandardRequest, ...[options]: StandardHandleRest<TContext>): Promise<StandardHandleResult>;
46
- }
47
- //# 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,15 +0,0 @@
1
- import type { ORPCError } from '@orpc/contract';
2
- import type { AnyProcedure } from '../../procedure';
3
- import type { StandardCodec, StandardParams, StandardRequest, StandardResponse } from './types';
4
- import { RPCSerializer } from './rpc-serializer';
5
- export interface StandardCodecOptions {
6
- serializer?: RPCSerializer;
7
- }
8
- export declare class RPCCodec implements StandardCodec {
9
- private readonly serializer;
10
- constructor(options?: StandardCodecOptions);
11
- decode(request: StandardRequest, _params: StandardParams | undefined, _procedure: AnyProcedure): Promise<unknown>;
12
- encode(output: unknown, _procedure: AnyProcedure): StandardResponse;
13
- encodeError(error: ORPCError<any, any>): StandardResponse;
14
- }
15
- //# 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