@orpc/server 0.0.0-next.0361c32 → 0.0.0-next.05d8f9b

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 (91) hide show
  1. package/README.md +131 -0
  2. package/dist/adapters/fetch/index.d.mts +58 -0
  3. package/dist/adapters/fetch/index.d.ts +58 -0
  4. package/dist/adapters/fetch/index.mjs +11 -0
  5. package/dist/adapters/hono/index.d.mts +22 -0
  6. package/dist/adapters/hono/index.d.ts +22 -0
  7. package/dist/adapters/hono/index.mjs +35 -0
  8. package/dist/adapters/next/index.d.mts +29 -0
  9. package/dist/adapters/next/index.d.ts +29 -0
  10. package/dist/adapters/next/index.mjs +32 -0
  11. package/dist/adapters/node/index.d.mts +57 -0
  12. package/dist/adapters/node/index.d.ts +57 -0
  13. package/dist/adapters/node/index.mjs +90 -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 +8 -0
  17. package/dist/index.d.mts +291 -0
  18. package/dist/index.d.ts +291 -0
  19. package/dist/{index.js → index.mjs} +115 -156
  20. package/dist/plugins/index.d.mts +124 -0
  21. package/dist/plugins/index.d.ts +124 -0
  22. package/dist/plugins/index.mjs +244 -0
  23. package/dist/shared/server.BVwwTHyO.mjs +9 -0
  24. package/dist/shared/server.BW-nUGgA.mjs +36 -0
  25. package/dist/shared/server.Bm0UqHzd.mjs +103 -0
  26. package/dist/shared/server.C37gDhSZ.mjs +364 -0
  27. package/dist/shared/server.C8NkqxHo.d.ts +17 -0
  28. package/dist/shared/server.CGCwEAt_.d.mts +10 -0
  29. package/dist/shared/server.DCQgF_JR.d.mts +17 -0
  30. package/dist/shared/server.DFFT_EZo.d.ts +73 -0
  31. package/dist/shared/server.DFuJLDuo.mjs +190 -0
  32. package/dist/shared/server.DLt5njUb.d.mts +143 -0
  33. package/dist/shared/server.DLt5njUb.d.ts +143 -0
  34. package/dist/shared/server.DOYDVeMX.d.mts +73 -0
  35. package/dist/shared/server._2UufoXA.d.ts +10 -0
  36. package/package.json +30 -32
  37. package/dist/chunk-2OH4QMZ4.js +0 -145
  38. package/dist/chunk-BFGSRNYZ.js +0 -319
  39. package/dist/chunk-EDQKEHUX.js +0 -377
  40. package/dist/chunk-XFBAK67J.js +0 -128
  41. package/dist/fetch.js +0 -16
  42. package/dist/hono.js +0 -40
  43. package/dist/next.js +0 -37
  44. package/dist/node.js +0 -170
  45. package/dist/plugins.js +0 -11
  46. package/dist/src/adapters/fetch/index.d.ts +0 -4
  47. package/dist/src/adapters/fetch/rpc-handler.d.ts +0 -10
  48. package/dist/src/adapters/fetch/types.d.ts +0 -13
  49. package/dist/src/adapters/fetch/utils.d.ts +0 -5
  50. package/dist/src/adapters/hono/index.d.ts +0 -3
  51. package/dist/src/adapters/hono/middleware.d.ts +0 -13
  52. package/dist/src/adapters/next/index.d.ts +0 -3
  53. package/dist/src/adapters/next/serve.d.ts +0 -20
  54. package/dist/src/adapters/node/index.d.ts +0 -4
  55. package/dist/src/adapters/node/rpc-handler.d.ts +0 -10
  56. package/dist/src/adapters/node/types.d.ts +0 -21
  57. package/dist/src/adapters/node/utils.d.ts +0 -5
  58. package/dist/src/adapters/standard/handler.d.ts +0 -51
  59. package/dist/src/adapters/standard/index.d.ts +0 -7
  60. package/dist/src/adapters/standard/rpc-codec.d.ts +0 -15
  61. package/dist/src/adapters/standard/rpc-handler.d.ts +0 -8
  62. package/dist/src/adapters/standard/rpc-matcher.d.ts +0 -10
  63. package/dist/src/adapters/standard/rpc-serializer.d.ts +0 -16
  64. package/dist/src/adapters/standard/types.d.ts +0 -44
  65. package/dist/src/builder-variants.d.ts +0 -74
  66. package/dist/src/builder.d.ts +0 -57
  67. package/dist/src/config.d.ts +0 -6
  68. package/dist/src/context.d.ts +0 -9
  69. package/dist/src/hidden.d.ts +0 -8
  70. package/dist/src/implementer-procedure.d.ts +0 -30
  71. package/dist/src/implementer-variants.d.ts +0 -17
  72. package/dist/src/implementer.d.ts +0 -28
  73. package/dist/src/index.d.ts +0 -23
  74. package/dist/src/lazy-utils.d.ts +0 -6
  75. package/dist/src/lazy.d.ts +0 -22
  76. package/dist/src/middleware-decorated.d.ts +0 -10
  77. package/dist/src/middleware-utils.d.ts +0 -5
  78. package/dist/src/middleware.d.ts +0 -37
  79. package/dist/src/plugins/base.d.ts +0 -13
  80. package/dist/src/plugins/cors.d.ts +0 -19
  81. package/dist/src/plugins/index.d.ts +0 -4
  82. package/dist/src/plugins/response-headers.d.ts +0 -10
  83. package/dist/src/procedure-client.d.ts +0 -31
  84. package/dist/src/procedure-decorated.d.ts +0 -21
  85. package/dist/src/procedure-utils.d.ts +0 -17
  86. package/dist/src/procedure.d.ts +0 -29
  87. package/dist/src/router-accessible-lazy.d.ts +0 -8
  88. package/dist/src/router-client.d.ts +0 -11
  89. package/dist/src/router.d.ts +0 -29
  90. package/dist/src/utils.d.ts +0 -24
  91. package/dist/standard.js +0 -17
@@ -1,128 +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
- beforeCreateProcedureClient(clientOptions, interceptorOptions) {
12
- for (const plugin of this.plugins) {
13
- plugin.beforeCreateProcedureClient?.(clientOptions, interceptorOptions);
14
- }
15
- }
16
- };
17
-
18
- // src/plugins/cors.ts
19
- import { value } from "@orpc/shared";
20
- var CORSPlugin = class {
21
- options;
22
- constructor(options) {
23
- const defaults = {
24
- origin: "*",
25
- allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"]
26
- };
27
- if (options?.credentials) {
28
- defaults.origin = (origin) => origin;
29
- }
30
- this.options = {
31
- ...defaults,
32
- ...options
33
- };
34
- }
35
- init(options) {
36
- options.interceptorsRoot ??= [];
37
- options.interceptorsRoot.unshift(async (interceptorOptions) => {
38
- if (interceptorOptions.request.method === "OPTIONS") {
39
- const resHeaders = {};
40
- if (this.options.maxAge !== void 0) {
41
- resHeaders["access-control-max-age"] = this.options.maxAge.toString();
42
- }
43
- if (this.options.allowMethods?.length) {
44
- resHeaders["access-control-allow-methods"] = this.options.allowMethods.join(",");
45
- }
46
- const allowHeaders = this.options.allowHeaders ?? interceptorOptions.request.headers["access-control-request-headers"];
47
- if (Array.isArray(allowHeaders) && allowHeaders.length) {
48
- resHeaders["access-control-allow-headers"] = allowHeaders.join(",");
49
- } else if (typeof allowHeaders === "string") {
50
- resHeaders["access-control-allow-headers"] = allowHeaders;
51
- }
52
- return {
53
- matched: true,
54
- response: {
55
- status: 204,
56
- headers: resHeaders,
57
- body: void 0
58
- }
59
- };
60
- }
61
- return interceptorOptions.next();
62
- });
63
- options.interceptorsRoot.unshift(async (interceptorOptions) => {
64
- const result = await interceptorOptions.next();
65
- if (!result.matched) {
66
- return result;
67
- }
68
- const origin = Array.isArray(interceptorOptions.request.headers.origin) ? interceptorOptions.request.headers.origin.join(",") : interceptorOptions.request.headers.origin || "";
69
- const allowedOrigin = await value(this.options.origin, origin, interceptorOptions);
70
- const allowedOriginArr = Array.isArray(allowedOrigin) ? allowedOrigin : [allowedOrigin];
71
- if (allowedOriginArr.includes("*")) {
72
- result.response.headers["access-control-allow-origin"] = "*";
73
- } else {
74
- if (allowedOriginArr.includes(origin)) {
75
- result.response.headers["access-control-allow-origin"] = origin;
76
- }
77
- result.response.headers.vary = interceptorOptions.request.headers.vary ?? "origin";
78
- }
79
- const allowedTimingOrigin = await value(this.options.timingOrigin, origin, interceptorOptions);
80
- const allowedTimingOriginArr = Array.isArray(allowedTimingOrigin) ? allowedTimingOrigin : [allowedTimingOrigin];
81
- if (allowedTimingOriginArr.includes("*")) {
82
- result.response.headers["timing-allow-origin"] = "*";
83
- } else if (allowedTimingOriginArr.includes(origin)) {
84
- result.response.headers["timing-allow-origin"] = origin;
85
- }
86
- if (this.options.credentials) {
87
- result.response.headers["access-control-allow-credentials"] = "true";
88
- }
89
- if (this.options.exposeHeaders?.length) {
90
- result.response.headers["access-control-expose-headers"] = this.options.exposeHeaders.join(",");
91
- }
92
- return result;
93
- });
94
- }
95
- };
96
-
97
- // src/plugins/response-headers.ts
98
- var ResponseHeadersPlugin = class {
99
- init(options) {
100
- options.interceptorsRoot ??= [];
101
- options.interceptorsRoot.push(async (interceptorOptions) => {
102
- const headers = new Headers();
103
- interceptorOptions.context.resHeaders = headers;
104
- const result = await interceptorOptions.next();
105
- if (!result.matched) {
106
- return result;
107
- }
108
- const responseHeaders = result.response.headers;
109
- for (const [key, value2] of headers) {
110
- if (Array.isArray(responseHeaders[key])) {
111
- responseHeaders[key].push(value2);
112
- } else if (responseHeaders[key] !== void 0) {
113
- responseHeaders[key] = [responseHeaders[key], value2];
114
- } else {
115
- responseHeaders[key] = value2;
116
- }
117
- }
118
- return result;
119
- });
120
- }
121
- };
122
-
123
- export {
124
- CompositePlugin,
125
- CORSPlugin,
126
- ResponseHeadersPlugin
127
- };
128
- //# sourceMappingURL=chunk-XFBAK67J.js.map
package/dist/fetch.js DELETED
@@ -1,16 +0,0 @@
1
- import {
2
- RPCHandler,
3
- fetchReToStandardBody,
4
- fetchRequestToStandardRequest,
5
- standardResponseToFetchResponse
6
- } from "./chunk-2OH4QMZ4.js";
7
- import "./chunk-BFGSRNYZ.js";
8
- import "./chunk-EDQKEHUX.js";
9
- import "./chunk-XFBAK67J.js";
10
- export {
11
- RPCHandler,
12
- fetchReToStandardBody,
13
- fetchRequestToStandardRequest,
14
- standardResponseToFetchResponse
15
- };
16
- //# sourceMappingURL=fetch.js.map
package/dist/hono.js DELETED
@@ -1,40 +0,0 @@
1
- import {
2
- RPCHandler,
3
- fetchReToStandardBody,
4
- fetchRequestToStandardRequest,
5
- standardResponseToFetchResponse
6
- } from "./chunk-2OH4QMZ4.js";
7
- import "./chunk-BFGSRNYZ.js";
8
- import "./chunk-EDQKEHUX.js";
9
- import "./chunk-XFBAK67J.js";
10
-
11
- // src/adapters/hono/middleware.ts
12
- import { value } from "@orpc/shared";
13
- function createMiddleware(handler, ...[options]) {
14
- return async (c, next) => {
15
- const bodyProps = /* @__PURE__ */ new Set(["arrayBuffer", "blob", "formData", "json", "text"]);
16
- const request = c.req.method === "GET" || c.req.method === "HEAD" ? c.req.raw : new Proxy(c.req.raw, {
17
- // https://github.com/honojs/middleware/blob/main/packages/trpc-server/src/index.ts#L39
18
- get(target, prop) {
19
- if (bodyProps.has(prop)) {
20
- return () => c.req[prop]();
21
- }
22
- return Reflect.get(target, prop, target);
23
- }
24
- });
25
- const context = await value(options?.context ?? {}, c);
26
- const { matched, response } = await handler.handle(request, { ...options, context });
27
- if (matched) {
28
- return c.newResponse(response.body, response);
29
- }
30
- await next();
31
- };
32
- }
33
- export {
34
- RPCHandler,
35
- createMiddleware,
36
- fetchReToStandardBody,
37
- fetchRequestToStandardRequest,
38
- standardResponseToFetchResponse
39
- };
40
- //# sourceMappingURL=hono.js.map
package/dist/next.js DELETED
@@ -1,37 +0,0 @@
1
- import {
2
- RPCHandler,
3
- fetchReToStandardBody,
4
- fetchRequestToStandardRequest,
5
- standardResponseToFetchResponse
6
- } from "./chunk-2OH4QMZ4.js";
7
- import "./chunk-BFGSRNYZ.js";
8
- import "./chunk-EDQKEHUX.js";
9
- import "./chunk-XFBAK67J.js";
10
-
11
- // src/adapters/next/serve.ts
12
- import { value } from "@orpc/shared";
13
- function serve(handler, ...[options]) {
14
- const main = async (req) => {
15
- const context = await value(options?.context ?? {}, req);
16
- const { matched, response } = await handler.handle(req, { ...options, context });
17
- if (matched) {
18
- return response;
19
- }
20
- return new Response(`Cannot find a matching procedure for ${req.url}`, { status: 404 });
21
- };
22
- return {
23
- GET: main,
24
- POST: main,
25
- PUT: main,
26
- PATCH: main,
27
- DELETE: main
28
- };
29
- }
30
- export {
31
- RPCHandler,
32
- fetchReToStandardBody,
33
- fetchRequestToStandardRequest,
34
- serve,
35
- standardResponseToFetchResponse
36
- };
37
- //# sourceMappingURL=next.js.map
package/dist/node.js DELETED
@@ -1,170 +0,0 @@
1
- import {
2
- RPCCodec,
3
- RPCMatcher,
4
- StandardHandler
5
- } from "./chunk-BFGSRNYZ.js";
6
- import "./chunk-EDQKEHUX.js";
7
- import "./chunk-XFBAK67J.js";
8
-
9
- // src/adapters/node/utils.ts
10
- import { Buffer, File } from "node:buffer";
11
- import { Readable } from "node:stream";
12
- import { once } from "@orpc/shared";
13
- import { contentDisposition, parse as parseContentDisposition } from "@tinyhttp/content-disposition";
14
- function nodeHttpToStandardRequest(req, res) {
15
- const method = req.method ?? "GET";
16
- const protocol = "encrypted" in req.socket && req.socket.encrypted ? "https:" : "http:";
17
- const host = req.headers.host ?? "localhost";
18
- const url = new URL(req.originalUrl ?? req.url ?? "/", `${protocol}//${host}`);
19
- return {
20
- raw: { request: req, response: res },
21
- method,
22
- url,
23
- headers: req.headers,
24
- body: once(() => {
25
- return nodeHttpRequestToStandardBody(req);
26
- }),
27
- get signal() {
28
- const signal = nodeHttpResponseToAbortSignal(res);
29
- Object.defineProperty(this, "signal", { value: signal, writable: true });
30
- return signal;
31
- },
32
- set signal(value) {
33
- Object.defineProperty(this, "signal", { value, writable: true });
34
- }
35
- };
36
- }
37
- function nodeHttpResponseSendStandardResponse(res, standardResponse) {
38
- return new Promise((resolve, reject) => {
39
- res.on("error", reject);
40
- res.on("finish", resolve);
41
- const resHeaders = standardResponse.headers;
42
- delete resHeaders["content-type"];
43
- delete resHeaders["content-disposition"];
44
- if (standardResponse.body === void 0) {
45
- res.writeHead(standardResponse.status, standardResponse.headers);
46
- res.end();
47
- return;
48
- }
49
- if (standardResponse.body instanceof Blob) {
50
- resHeaders["content-type"] = standardResponse.body.type;
51
- resHeaders["content-length"] = standardResponse.body.size.toString();
52
- resHeaders["content-disposition"] = contentDisposition(
53
- standardResponse.body instanceof File ? standardResponse.body.name : "blob",
54
- { type: "inline" }
55
- );
56
- res.writeHead(standardResponse.status, resHeaders);
57
- Readable.fromWeb(
58
- standardResponse.body.stream()
59
- // Conflict between types=node and lib=dom so we need to cast it
60
- ).pipe(res);
61
- return;
62
- }
63
- if (standardResponse.body instanceof FormData) {
64
- const response = new Response(standardResponse.body);
65
- resHeaders["content-type"] = response.headers.get("content-type");
66
- res.writeHead(standardResponse.status, resHeaders);
67
- Readable.fromWeb(
68
- response.body
69
- // Conflict between types=node and lib=dom so we need to cast it
70
- ).pipe(res);
71
- return;
72
- }
73
- if (standardResponse.body instanceof URLSearchParams) {
74
- resHeaders["content-type"] = "application/x-www-form-urlencoded";
75
- res.writeHead(standardResponse.status, resHeaders);
76
- res.end(standardResponse.body.toString());
77
- return;
78
- }
79
- resHeaders["content-type"] = "application/json";
80
- res.writeHead(standardResponse.status, resHeaders);
81
- res.end(JSON.stringify(standardResponse.body));
82
- });
83
- }
84
- async function nodeHttpRequestToStandardBody(req) {
85
- const method = req.method ?? "GET";
86
- if (method === "GET" || method === "HEAD") {
87
- return void 0;
88
- }
89
- const contentDisposition2 = req.headers["content-disposition"];
90
- const contentType = req.headers["content-type"];
91
- if (contentDisposition2) {
92
- const fileName = parseContentDisposition(contentDisposition2).parameters.filename;
93
- if (typeof fileName === "string") {
94
- return await streamToFile(req, fileName, contentType || "application/octet-stream");
95
- }
96
- }
97
- if (!contentType || contentType.startsWith("application/json")) {
98
- const text = await streamToString(req);
99
- if (!text) {
100
- return void 0;
101
- }
102
- return JSON.parse(text);
103
- }
104
- if (contentType.startsWith("multipart/form-data")) {
105
- return await streamToFormData(req, contentType);
106
- }
107
- if (contentType.startsWith("application/x-www-form-urlencoded")) {
108
- const text = await streamToString(req);
109
- return new URLSearchParams(text);
110
- }
111
- if (contentType.startsWith("text/")) {
112
- return await streamToString(req);
113
- }
114
- return streamToFile(req, "blob", contentType);
115
- }
116
- function streamToFormData(stream, contentType) {
117
- const response = new Response(stream, {
118
- // Conflict between types=node and lib=dom so we need to cast it
119
- headers: {
120
- "content-type": contentType
121
- }
122
- });
123
- return response.formData();
124
- }
125
- async function streamToString(stream) {
126
- let string = "";
127
- for await (const chunk of stream) {
128
- string += chunk.toString();
129
- }
130
- return string;
131
- }
132
- async function streamToFile(stream, fileName, contentType) {
133
- const chunks = [];
134
- for await (const chunk of stream) {
135
- chunks.push(chunk);
136
- }
137
- return new File([Buffer.concat(chunks)], fileName, { type: contentType });
138
- }
139
- function nodeHttpResponseToAbortSignal(res) {
140
- const controller = new AbortController();
141
- res.on("close", () => {
142
- controller.abort();
143
- });
144
- return controller.signal;
145
- }
146
-
147
- // src/adapters/node/rpc-handler.ts
148
- var RPCHandler = class {
149
- standardHandler;
150
- constructor(router, options) {
151
- const codec = options?.codec ?? new RPCCodec();
152
- const matcher = options?.matcher ?? new RPCMatcher();
153
- this.standardHandler = new StandardHandler(router, matcher, codec, options);
154
- }
155
- async handle(req, res, ...rest) {
156
- const standardRequest = nodeHttpToStandardRequest(req, res);
157
- const result = await this.standardHandler.handle(standardRequest, ...rest);
158
- if (!result.matched) {
159
- return { matched: false };
160
- }
161
- await nodeHttpResponseSendStandardResponse(res, result.response);
162
- return { matched: true };
163
- }
164
- };
165
- export {
166
- RPCHandler,
167
- nodeHttpResponseSendStandardResponse,
168
- nodeHttpToStandardRequest
169
- };
170
- //# sourceMappingURL=node.js.map
package/dist/plugins.js DELETED
@@ -1,11 +0,0 @@
1
- import {
2
- CORSPlugin,
3
- CompositePlugin,
4
- ResponseHeadersPlugin
5
- } from "./chunk-XFBAK67J.js";
6
- export {
7
- CORSPlugin,
8
- CompositePlugin,
9
- ResponseHeadersPlugin
10
- };
11
- //# sourceMappingURL=plugins.js.map
@@ -1,4 +0,0 @@
1
- export * from './rpc-handler';
2
- export * from './types';
3
- export * from './utils';
4
- //# sourceMappingURL=index.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 { 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,13 +0,0 @@
1
- import type { Context } from '../../context';
2
- import type { StandardHandleRest } from '../standard';
3
- export type FetchHandleResult = {
4
- matched: true;
5
- response: Response;
6
- } | {
7
- matched: false;
8
- response: undefined;
9
- };
10
- export interface FetchHandler<T extends Context> {
11
- handle(request: Request, ...rest: StandardHandleRest<T>): Promise<FetchHandleResult>;
12
- }
13
- //# sourceMappingURL=types.d.ts.map
@@ -1,5 +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 standardResponseToFetchResponse(response: StandardResponse): Response;
5
- //# sourceMappingURL=utils.d.ts.map
@@ -1,3 +0,0 @@
1
- export * from '../fetch';
2
- export * from './middleware';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1,13 +0,0 @@
1
- import type { Context as HonoContext, MiddlewareHandler } from 'hono';
2
- import type { Context } from '../../context';
3
- import type { FetchHandler } from '../fetch';
4
- import type { StandardHandleOptions } from '../standard';
5
- import { type Value } from '@orpc/shared';
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 type CreateMiddlewareRest<T extends Context> = [options: CreateMiddlewareOptions<T>] | (Record<never, never> extends T ? [] : never);
12
- export declare function createMiddleware<T extends Context>(handler: FetchHandler<T>, ...[options]: CreateMiddlewareRest<T>): MiddlewareHandler;
13
- //# sourceMappingURL=middleware.d.ts.map
@@ -1,3 +0,0 @@
1
- export * from '../fetch';
2
- export * from './serve';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1,20 +0,0 @@
1
- import type { NextRequest } from 'next/server';
2
- import type { Context } from '../../context';
3
- import type { FetchHandler } from '../fetch';
4
- import type { StandardHandleOptions } from '../standard';
5
- import { type Value } from '@orpc/shared';
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 type ServeRest<T extends Context> = [options: ServeOptions<T>] | (Record<never, never> extends T ? [] : never);
12
- export interface ServeResult {
13
- GET(req: NextRequest): Promise<Response>;
14
- POST(req: NextRequest): Promise<Response>;
15
- PUT(req: NextRequest): Promise<Response>;
16
- PATCH(req: NextRequest): Promise<Response>;
17
- DELETE(req: NextRequest): Promise<Response>;
18
- }
19
- export declare function serve<T extends Context>(handler: FetchHandler<T>, ...[options]: ServeRest<T>): ServeResult;
20
- //# sourceMappingURL=serve.d.ts.map
@@ -1,4 +0,0 @@
1
- export * from './rpc-handler';
2
- export * from './types';
3
- export * from './utils';
4
- //# sourceMappingURL=index.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,21 +0,0 @@
1
- import type { IncomingMessage, ServerResponse } from 'node:http';
2
- import type { Http2ServerRequest, Http2ServerResponse } from 'node:http2';
3
- import type { Context } from '../../context';
4
- import type { StandardHandleRest } from '../standard';
5
- export type NodeHttpRequest = (IncomingMessage | Http2ServerRequest) & {
6
- /**
7
- * Replace `req.url` with `req.originalUrl` when `req.originalUrl` is available.
8
- * This is useful for `express.js` middleware.
9
- */
10
- originalUrl?: string;
11
- };
12
- export type NodeHttpResponse = ServerResponse | Http2ServerResponse;
13
- export type NodeHttpHandleResult = {
14
- matched: true;
15
- } | {
16
- matched: false;
17
- };
18
- export interface NodeHttpHandler<T extends Context> {
19
- handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest: StandardHandleRest<T>): Promise<NodeHttpHandleResult>;
20
- }
21
- //# sourceMappingURL=types.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,51 +0,0 @@
1
- import type { ErrorMap, HTTPPath, Meta, Schema } 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 { CreateProcedureClientOptions } from '../../procedure-client';
6
- import type { Router } from '../../router';
7
- import type { StandardCodec, StandardMatcher, StandardRequest, StandardResponse } from './types';
8
- export type StandardHandleOptions<T extends Context> = {
9
- prefix?: HTTPPath;
10
- } & (Record<never, never> extends T ? {
11
- context?: T;
12
- } : {
13
- context: T;
14
- });
15
- export type WellStandardHandleOptions<T extends Context> = StandardHandleOptions<T> & {
16
- context: T;
17
- };
18
- export type StandardHandleRest<T extends Context> = [options: StandardHandleOptions<T>] | (Record<never, never> extends T ? [] : never);
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, unknown> & {
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<TContext extends Context> {
44
- private readonly matcher;
45
- private readonly codec;
46
- private readonly options;
47
- private readonly plugin;
48
- constructor(router: Router<TContext, any>, matcher: StandardMatcher, codec: StandardCodec, options?: NoInfer<StandardHandlerOptions<TContext>>);
49
- handle(request: StandardRequest, ...[options]: StandardHandleRest<TContext>): 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,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
@@ -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