@orpc/server 0.0.0-next.ca29a36 → 0.0.0-next.cac5dd3

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