@orpc/server 0.0.0-next.b42ba03 → 0.0.0-next.b47b94e

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 (97) hide show
  1. package/README.md +128 -0
  2. package/dist/adapters/bun-ws/index.d.mts +35 -0
  3. package/dist/adapters/bun-ws/index.d.ts +35 -0
  4. package/dist/adapters/bun-ws/index.mjs +50 -0
  5. package/dist/adapters/crossws/index.d.mts +30 -0
  6. package/dist/adapters/crossws/index.d.ts +30 -0
  7. package/dist/adapters/crossws/index.mjs +50 -0
  8. package/dist/adapters/fetch/index.d.mts +78 -0
  9. package/dist/adapters/fetch/index.d.ts +78 -0
  10. package/dist/adapters/fetch/index.mjs +110 -0
  11. package/dist/adapters/node/index.d.mts +77 -0
  12. package/dist/adapters/node/index.d.ts +77 -0
  13. package/dist/adapters/node/index.mjs +95 -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/adapters/websocket/index.d.mts +27 -0
  18. package/dist/adapters/websocket/index.d.ts +27 -0
  19. package/dist/adapters/websocket/index.mjs +37 -0
  20. package/dist/adapters/ws/index.d.mts +28 -0
  21. package/dist/adapters/ws/index.d.ts +28 -0
  22. package/dist/adapters/ws/index.mjs +37 -0
  23. package/dist/index.d.mts +829 -0
  24. package/dist/index.d.ts +829 -0
  25. package/dist/index.mjs +474 -0
  26. package/dist/plugins/index.d.mts +156 -0
  27. package/dist/plugins/index.d.ts +156 -0
  28. package/dist/plugins/index.mjs +251 -0
  29. package/dist/shared/server.BRoxSiSC.d.mts +12 -0
  30. package/dist/shared/server.BVwwTHyO.mjs +9 -0
  31. package/dist/shared/server.BW-nUGgA.mjs +36 -0
  32. package/dist/shared/server.BjiJH9Vo.d.ts +10 -0
  33. package/dist/shared/server.Cy1vfSiG.d.ts +12 -0
  34. package/dist/shared/server.DG7Tamti.mjs +367 -0
  35. package/dist/shared/server.DPWk5pjW.d.mts +192 -0
  36. package/dist/shared/server.DPWk5pjW.d.ts +192 -0
  37. package/dist/shared/server.QUe9N8P4.d.mts +10 -0
  38. package/dist/shared/server.SxlTJfG2.mjs +183 -0
  39. package/dist/shared/server.YZzrREz9.d.ts +74 -0
  40. package/dist/shared/server.eWLxY3lq.d.mts +74 -0
  41. package/package.json +57 -36
  42. package/dist/chunk-2OH4QMZ4.js +0 -145
  43. package/dist/chunk-BFGSRNYZ.js +0 -319
  44. package/dist/chunk-EDQKEHUX.js +0 -377
  45. package/dist/chunk-XFBAK67J.js +0 -128
  46. package/dist/fetch.js +0 -16
  47. package/dist/hono.js +0 -40
  48. package/dist/index.js +0 -404
  49. package/dist/next.js +0 -37
  50. package/dist/node.js +0 -170
  51. package/dist/plugins.js +0 -11
  52. package/dist/src/adapters/fetch/index.d.ts +0 -4
  53. package/dist/src/adapters/fetch/rpc-handler.d.ts +0 -10
  54. package/dist/src/adapters/fetch/types.d.ts +0 -13
  55. package/dist/src/adapters/fetch/utils.d.ts +0 -5
  56. package/dist/src/adapters/hono/index.d.ts +0 -3
  57. package/dist/src/adapters/hono/middleware.d.ts +0 -13
  58. package/dist/src/adapters/next/index.d.ts +0 -3
  59. package/dist/src/adapters/next/serve.d.ts +0 -20
  60. package/dist/src/adapters/node/index.d.ts +0 -4
  61. package/dist/src/adapters/node/rpc-handler.d.ts +0 -10
  62. package/dist/src/adapters/node/types.d.ts +0 -21
  63. package/dist/src/adapters/node/utils.d.ts +0 -5
  64. package/dist/src/adapters/standard/handler.d.ts +0 -51
  65. package/dist/src/adapters/standard/index.d.ts +0 -7
  66. package/dist/src/adapters/standard/rpc-codec.d.ts +0 -15
  67. package/dist/src/adapters/standard/rpc-handler.d.ts +0 -8
  68. package/dist/src/adapters/standard/rpc-matcher.d.ts +0 -10
  69. package/dist/src/adapters/standard/rpc-serializer.d.ts +0 -16
  70. package/dist/src/adapters/standard/types.d.ts +0 -44
  71. package/dist/src/builder-variants.d.ts +0 -74
  72. package/dist/src/builder.d.ts +0 -57
  73. package/dist/src/config.d.ts +0 -6
  74. package/dist/src/context.d.ts +0 -9
  75. package/dist/src/hidden.d.ts +0 -8
  76. package/dist/src/implementer-procedure.d.ts +0 -30
  77. package/dist/src/implementer-variants.d.ts +0 -17
  78. package/dist/src/implementer.d.ts +0 -28
  79. package/dist/src/index.d.ts +0 -23
  80. package/dist/src/lazy-utils.d.ts +0 -6
  81. package/dist/src/lazy.d.ts +0 -22
  82. package/dist/src/middleware-decorated.d.ts +0 -10
  83. package/dist/src/middleware-utils.d.ts +0 -5
  84. package/dist/src/middleware.d.ts +0 -37
  85. package/dist/src/plugins/base.d.ts +0 -13
  86. package/dist/src/plugins/cors.d.ts +0 -19
  87. package/dist/src/plugins/index.d.ts +0 -4
  88. package/dist/src/plugins/response-headers.d.ts +0 -10
  89. package/dist/src/procedure-client.d.ts +0 -31
  90. package/dist/src/procedure-decorated.d.ts +0 -21
  91. package/dist/src/procedure-utils.d.ts +0 -17
  92. package/dist/src/procedure.d.ts +0 -29
  93. package/dist/src/router-accessible-lazy.d.ts +0 -8
  94. package/dist/src/router-client.d.ts +0 -11
  95. package/dist/src/router.d.ts +0 -29
  96. package/dist/src/utils.d.ts +0 -24
  97. package/dist/standard.js +0 -17
package/dist/index.js DELETED
@@ -1,404 +0,0 @@
1
- import {
2
- LAZY_LOADER_SYMBOL,
3
- Procedure,
4
- adaptRouter,
5
- addMiddleware,
6
- convertPathToHttpPath,
7
- createAccessibleLazyRouter,
8
- createContractedProcedure,
9
- createLazyProcedureFormAnyLazy,
10
- createProcedureClient,
11
- deepSetLazyRouterPrefix,
12
- eachAllContractProcedure,
13
- eachContractProcedure,
14
- flatLazy,
15
- getLazyRouterPrefix,
16
- getRouterChild,
17
- getRouterContract,
18
- isLazy,
19
- isProcedure,
20
- lazy,
21
- middlewareOutputFn,
22
- setRouterContract,
23
- unlazy
24
- } from "./chunk-EDQKEHUX.js";
25
-
26
- // src/builder.ts
27
- import { mergeErrorMap as mergeErrorMap2, mergeMeta as mergeMeta2, mergePrefix, mergeRoute as mergeRoute2, mergeTags } from "@orpc/contract";
28
-
29
- // src/config.ts
30
- var DEFAULT_CONFIG = {
31
- initialInputValidationIndex: 0,
32
- initialOutputValidationIndex: 0
33
- };
34
- function fallbackConfig(key, value) {
35
- if (value === void 0) {
36
- return DEFAULT_CONFIG[key];
37
- }
38
- return value;
39
- }
40
-
41
- // src/middleware-decorated.ts
42
- function decorateMiddleware(middleware) {
43
- const decorated = middleware;
44
- decorated.mapInput = (mapInput) => {
45
- const mapped = decorateMiddleware(
46
- (options, input, ...rest) => middleware(options, mapInput(input), ...rest)
47
- );
48
- return mapped;
49
- };
50
- decorated.concat = (concatMiddleware, mapInput) => {
51
- const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
52
- const concatted = decorateMiddleware((options, input, output, ...rest) => {
53
- const next = async (...[nextOptions]) => {
54
- return mapped({ ...options, context: { ...nextOptions?.context, ...options.context } }, input, output, ...rest);
55
- };
56
- const merged = middleware({ ...options, next }, input, output, ...rest);
57
- return merged;
58
- });
59
- return concatted;
60
- };
61
- return decorated;
62
- }
63
-
64
- // src/procedure-decorated.ts
65
- import { mergeErrorMap, mergeMeta, mergeRoute } from "@orpc/contract";
66
- var DecoratedProcedure = class _DecoratedProcedure extends Procedure {
67
- errors(errors) {
68
- return new _DecoratedProcedure({
69
- ...this["~orpc"],
70
- errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
71
- });
72
- }
73
- meta(meta) {
74
- return new _DecoratedProcedure({
75
- ...this["~orpc"],
76
- meta: mergeMeta(this["~orpc"].meta, meta)
77
- });
78
- }
79
- route(route) {
80
- return new _DecoratedProcedure({
81
- ...this["~orpc"],
82
- route: mergeRoute(this["~orpc"].route, route)
83
- });
84
- }
85
- use(middleware, mapInput) {
86
- const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
87
- return new _DecoratedProcedure({
88
- ...this["~orpc"],
89
- middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
90
- });
91
- }
92
- /**
93
- * Make this procedure callable (works like a function while still being a procedure).
94
- */
95
- callable(...rest) {
96
- return Object.assign(createProcedureClient(this, ...rest), {
97
- "~type": "Procedure",
98
- "~orpc": this["~orpc"]
99
- });
100
- }
101
- /**
102
- * Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
103
- */
104
- actionable(...rest) {
105
- return this.callable(...rest);
106
- }
107
- };
108
-
109
- // src/builder.ts
110
- var Builder = class _Builder {
111
- "~orpc";
112
- constructor(def) {
113
- this["~orpc"] = def;
114
- }
115
- /**
116
- * Reset config
117
- */
118
- $config(config) {
119
- const inputValidationCount = this["~orpc"].inputValidationIndex - fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex);
120
- const outputValidationCount = this["~orpc"].outputValidationIndex - fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex);
121
- return new _Builder({
122
- ...this["~orpc"],
123
- config,
124
- inputValidationIndex: fallbackConfig("initialInputValidationIndex", config.initialInputValidationIndex) + inputValidationCount,
125
- outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config.initialOutputValidationIndex) + outputValidationCount
126
- });
127
- }
128
- /**
129
- * Reset initial context
130
- */
131
- $context() {
132
- return new _Builder({
133
- ...this["~orpc"],
134
- middlewares: [],
135
- inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex),
136
- outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex)
137
- });
138
- }
139
- /**
140
- * Reset initial meta
141
- */
142
- $meta(initialMeta) {
143
- return new _Builder({
144
- ...this["~orpc"],
145
- meta: initialMeta
146
- });
147
- }
148
- /**
149
- * Reset initial route
150
- */
151
- $route(initialRoute) {
152
- return new _Builder({
153
- ...this["~orpc"],
154
- route: initialRoute
155
- });
156
- }
157
- middleware(middleware) {
158
- return decorateMiddleware(middleware);
159
- }
160
- errors(errors) {
161
- return new _Builder({
162
- ...this["~orpc"],
163
- errorMap: mergeErrorMap2(this["~orpc"].errorMap, errors)
164
- });
165
- }
166
- use(middleware, mapInput) {
167
- const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
168
- return new _Builder({
169
- ...this["~orpc"],
170
- middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
171
- });
172
- }
173
- meta(meta) {
174
- return new _Builder({
175
- ...this["~orpc"],
176
- meta: mergeMeta2(this["~orpc"].meta, meta)
177
- });
178
- }
179
- route(route) {
180
- return new _Builder({
181
- ...this["~orpc"],
182
- route: mergeRoute2(this["~orpc"].route, route)
183
- });
184
- }
185
- input(schema) {
186
- return new _Builder({
187
- ...this["~orpc"],
188
- inputSchema: schema,
189
- inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex) + this["~orpc"].middlewares.length
190
- });
191
- }
192
- output(schema) {
193
- return new _Builder({
194
- ...this["~orpc"],
195
- outputSchema: schema,
196
- outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex) + this["~orpc"].middlewares.length
197
- });
198
- }
199
- handler(handler) {
200
- return new DecoratedProcedure({
201
- ...this["~orpc"],
202
- handler
203
- });
204
- }
205
- prefix(prefix) {
206
- return new _Builder({
207
- ...this["~orpc"],
208
- prefix: mergePrefix(this["~orpc"].prefix, prefix)
209
- });
210
- }
211
- tag(...tags) {
212
- return new _Builder({
213
- ...this["~orpc"],
214
- tags: mergeTags(this["~orpc"].tags, tags)
215
- });
216
- }
217
- router(router) {
218
- return adaptRouter(router, this["~orpc"]);
219
- }
220
- lazy(loader) {
221
- return adaptRouter(flatLazy(lazy(loader)), this["~orpc"]);
222
- }
223
- };
224
- var os = new Builder({
225
- config: {},
226
- route: {},
227
- meta: {},
228
- errorMap: {},
229
- inputSchema: void 0,
230
- outputSchema: void 0,
231
- inputValidationIndex: fallbackConfig("initialInputValidationIndex"),
232
- outputValidationIndex: fallbackConfig("initialOutputValidationIndex"),
233
- middlewares: []
234
- });
235
-
236
- // src/context.ts
237
- function mergeContext(context, other) {
238
- return { ...context, ...other };
239
- }
240
-
241
- // src/implementer.ts
242
- import { isContractProcedure } from "@orpc/contract";
243
- function implementerInternal(contract, config, middlewares) {
244
- if (isContractProcedure(contract)) {
245
- const impl2 = new Builder({
246
- ...contract["~orpc"],
247
- config,
248
- middlewares,
249
- inputValidationIndex: fallbackConfig("initialInputValidationIndex", config?.initialInputValidationIndex) + middlewares.length,
250
- outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config?.initialOutputValidationIndex) + middlewares.length
251
- });
252
- return impl2;
253
- }
254
- const impl = new Proxy(contract, {
255
- get: (target, key) => {
256
- let method;
257
- if (key === "middleware") {
258
- method = (mid) => decorateMiddleware(mid);
259
- } else if (key === "use") {
260
- method = (mid) => {
261
- return implementerInternal(
262
- contract,
263
- config,
264
- addMiddleware(middlewares, mid)
265
- );
266
- };
267
- } else if (key === "router") {
268
- method = (router) => {
269
- const adapted = adaptRouter(router, {
270
- middlewares,
271
- errorMap: {}
272
- });
273
- return setRouterContract(adapted, contract);
274
- };
275
- } else if (key === "lazy") {
276
- method = (loader) => {
277
- const adapted = adaptRouter(flatLazy(lazy(loader)), {
278
- middlewares,
279
- errorMap: {}
280
- });
281
- return setRouterContract(adapted, contract);
282
- };
283
- }
284
- const next = Reflect.get(target, key);
285
- if (!next || typeof next !== "function" && typeof next !== "object") {
286
- return method ?? next;
287
- }
288
- const nextImpl = implementerInternal(next, config, middlewares);
289
- if (method) {
290
- return new Proxy(method, {
291
- get(_, key2) {
292
- return Reflect.get(nextImpl, key2);
293
- }
294
- });
295
- }
296
- return nextImpl;
297
- }
298
- });
299
- return impl;
300
- }
301
- function implement(contract, config = {}) {
302
- const implInternal = implementerInternal(contract, config, []);
303
- const impl = new Proxy(implInternal, {
304
- get: (target, key) => {
305
- let method;
306
- if (key === "$context") {
307
- method = () => impl;
308
- } else if (key === "$config") {
309
- method = (config2) => implement(contract, config2);
310
- }
311
- const next = Reflect.get(target, key);
312
- if (!next || typeof next !== "function" && typeof next !== "object") {
313
- return method ?? next;
314
- }
315
- if (method) {
316
- return new Proxy(method, {
317
- get(_, key2) {
318
- return Reflect.get(next, key2);
319
- }
320
- });
321
- }
322
- return next;
323
- }
324
- });
325
- return impl;
326
- }
327
-
328
- // src/procedure-utils.ts
329
- function call(procedure, input, ...rest) {
330
- return createProcedureClient(procedure, ...rest)(input);
331
- }
332
-
333
- // src/router-client.ts
334
- function createRouterClient(router, ...rest) {
335
- if (isProcedure(router)) {
336
- const caller = createProcedureClient(router, ...rest);
337
- return caller;
338
- }
339
- const procedureCaller = isLazy(router) ? createProcedureClient(createLazyProcedureFormAnyLazy(router), ...rest) : {};
340
- const recursive = new Proxy(procedureCaller, {
341
- get(target, key) {
342
- if (typeof key !== "string") {
343
- return Reflect.get(target, key);
344
- }
345
- const next = getRouterChild(router, key);
346
- if (!next) {
347
- return Reflect.get(target, key);
348
- }
349
- const [options] = rest;
350
- return createRouterClient(next, {
351
- ...options,
352
- path: [...options?.path ?? [], key]
353
- });
354
- }
355
- });
356
- return recursive;
357
- }
358
-
359
- // src/index.ts
360
- import { isDefinedError, ORPCError, safe, type, ValidationError } from "@orpc/contract";
361
- import { onError, onFinish, onStart, onSuccess } from "@orpc/shared";
362
- export {
363
- Builder,
364
- DecoratedProcedure,
365
- LAZY_LOADER_SYMBOL,
366
- ORPCError,
367
- Procedure,
368
- ValidationError,
369
- adaptRouter,
370
- call,
371
- convertPathToHttpPath,
372
- createAccessibleLazyRouter,
373
- createContractedProcedure,
374
- createLazyProcedureFormAnyLazy,
375
- createProcedureClient,
376
- createRouterClient,
377
- decorateMiddleware,
378
- deepSetLazyRouterPrefix,
379
- eachAllContractProcedure,
380
- eachContractProcedure,
381
- fallbackConfig,
382
- flatLazy,
383
- getLazyRouterPrefix,
384
- getRouterChild,
385
- getRouterContract,
386
- implement,
387
- implementerInternal,
388
- isDefinedError,
389
- isLazy,
390
- isProcedure,
391
- lazy,
392
- mergeContext,
393
- middlewareOutputFn,
394
- onError,
395
- onFinish,
396
- onStart,
397
- onSuccess,
398
- os,
399
- safe,
400
- setRouterContract,
401
- type,
402
- unlazy
403
- };
404
- //# sourceMappingURL=index.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