@orpc/server 0.0.0-next.c29cb6d → 0.0.0-next.c4a591c
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.
- package/dist/chunk-2HRHHZJD.js +301 -0
- package/dist/chunk-SA7HGGVY.js +242 -0
- package/dist/chunk-WUOGVGWG.js +1 -0
- package/dist/fetch.js +10 -281
- package/dist/hono.js +30 -0
- package/dist/index.js +196 -123
- package/dist/next.js +36 -0
- package/dist/node.js +87 -0
- package/dist/src/{fetch → adapters/fetch}/index.d.ts +1 -1
- package/dist/src/adapters/fetch/orpc-handler.d.ts +20 -0
- package/dist/src/adapters/fetch/orpc-payload-codec.d.ts +16 -0
- package/dist/src/{fetch → adapters/fetch}/orpc-procedure-matcher.d.ts +2 -2
- package/dist/src/adapters/fetch/types.d.ts +21 -0
- package/dist/src/adapters/hono/index.d.ts +3 -0
- package/dist/src/adapters/hono/middleware.d.ts +12 -0
- package/dist/src/adapters/next/index.d.ts +3 -0
- package/dist/src/adapters/next/serve.d.ts +19 -0
- package/dist/src/adapters/node/index.d.ts +5 -0
- package/dist/src/adapters/node/orpc-handler.d.ts +12 -0
- package/dist/src/adapters/node/request-listener.d.ts +28 -0
- package/dist/src/adapters/node/types.d.ts +22 -0
- package/dist/src/builder.d.ts +24 -21
- package/dist/src/error.d.ts +10 -0
- package/dist/src/hidden.d.ts +2 -2
- package/dist/src/implementer-chainable.d.ts +3 -3
- package/dist/src/index.d.ts +4 -2
- package/dist/src/lazy-decorated.d.ts +3 -6
- package/dist/src/middleware-decorated.d.ts +6 -5
- package/dist/src/middleware.d.ts +21 -8
- package/dist/src/procedure-builder.d.ts +17 -15
- package/dist/src/procedure-client.d.ts +9 -21
- package/dist/src/procedure-decorated.d.ts +21 -10
- package/dist/src/procedure-implementer.d.ts +14 -12
- package/dist/src/procedure-utils.d.ts +17 -0
- package/dist/src/procedure.d.ts +34 -13
- package/dist/src/router-builder.d.ts +17 -15
- package/dist/src/router-client.d.ts +7 -6
- package/dist/src/router-implementer.d.ts +6 -6
- package/dist/src/router.d.ts +5 -5
- package/dist/src/types.d.ts +2 -0
- package/package.json +24 -8
- package/dist/chunk-YAVPFNPF.js +0 -182
- package/dist/src/fetch/composite-handler.d.ts +0 -8
- package/dist/src/fetch/orpc-handler.d.ts +0 -20
- package/dist/src/fetch/orpc-payload-codec.d.ts +0 -9
- package/dist/src/fetch/types.d.ts +0 -16
- /package/dist/src/{fetch → adapters/fetch}/super-json.d.ts +0 -0
package/dist/index.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import {
|
2
2
|
LAZY_LOADER_SYMBOL,
|
3
3
|
Procedure,
|
4
|
+
createORPCErrorConstructorMap,
|
4
5
|
createProcedureClient,
|
5
6
|
flatLazy,
|
6
7
|
getRouterChild,
|
@@ -8,8 +9,9 @@ import {
|
|
8
9
|
isProcedure,
|
9
10
|
lazy,
|
10
11
|
mergeContext,
|
12
|
+
middlewareOutputFn,
|
11
13
|
unlazy
|
12
|
-
} from "./chunk-
|
14
|
+
} from "./chunk-SA7HGGVY.js";
|
13
15
|
|
14
16
|
// src/builder.ts
|
15
17
|
import { ContractProcedure } from "@orpc/contract";
|
@@ -23,17 +25,17 @@ function decorateMiddleware(middleware) {
|
|
23
25
|
const decorated = middleware;
|
24
26
|
decorated.mapInput = (mapInput) => {
|
25
27
|
const mapped = decorateMiddleware(
|
26
|
-
(input, ...rest) => middleware(mapInput(input), ...rest)
|
28
|
+
(options, input, ...rest) => middleware(options, mapInput(input), ...rest)
|
27
29
|
);
|
28
30
|
return mapped;
|
29
31
|
};
|
30
32
|
decorated.concat = (concatMiddleware, mapInput) => {
|
31
33
|
const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
|
32
|
-
const concatted = decorateMiddleware((
|
33
|
-
const next = async (
|
34
|
-
return mapped(
|
34
|
+
const concatted = decorateMiddleware((options, input, output, ...rest) => {
|
35
|
+
const next = async (nextOptions) => {
|
36
|
+
return mapped({ ...options, context: mergeContext(nextOptions.context, options.context) }, input, output, ...rest);
|
35
37
|
};
|
36
|
-
const merged = middleware(
|
38
|
+
const merged = middleware({ ...options, next }, input, output, ...rest);
|
37
39
|
return merged;
|
38
40
|
});
|
39
41
|
return concatted;
|
@@ -43,58 +45,78 @@ function decorateMiddleware(middleware) {
|
|
43
45
|
|
44
46
|
// src/procedure-decorated.ts
|
45
47
|
import { DecoratedContractProcedure } from "@orpc/contract";
|
46
|
-
|
47
|
-
|
48
|
-
procedure
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
48
|
+
var DecoratedProcedure = class _DecoratedProcedure extends Procedure {
|
49
|
+
static decorate(procedure) {
|
50
|
+
if (procedure instanceof _DecoratedProcedure) {
|
51
|
+
return procedure;
|
52
|
+
}
|
53
|
+
return new _DecoratedProcedure(procedure["~orpc"]);
|
54
|
+
}
|
55
|
+
prefix(prefix) {
|
56
|
+
return new _DecoratedProcedure({
|
57
|
+
...this["~orpc"],
|
58
|
+
contract: DecoratedContractProcedure.decorate(this["~orpc"].contract).prefix(prefix)
|
59
|
+
});
|
60
|
+
}
|
61
|
+
route(route) {
|
62
|
+
return new _DecoratedProcedure({
|
63
|
+
...this["~orpc"],
|
64
|
+
contract: DecoratedContractProcedure.decorate(this["~orpc"].contract).route(route)
|
65
|
+
});
|
66
|
+
}
|
67
|
+
errors(errors) {
|
68
|
+
return new _DecoratedProcedure({
|
69
|
+
...this["~orpc"],
|
70
|
+
contract: DecoratedContractProcedure.decorate(this["~orpc"].contract).errors(errors)
|
71
|
+
});
|
72
|
+
}
|
73
|
+
use(middleware, mapInput) {
|
67
74
|
const middleware_ = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
68
|
-
return
|
69
|
-
...
|
70
|
-
|
71
|
-
})
|
72
|
-
}
|
73
|
-
|
74
|
-
return
|
75
|
-
...
|
76
|
-
contract: DecoratedContractProcedure.decorate(
|
77
|
-
})
|
78
|
-
}
|
79
|
-
|
80
|
-
|
75
|
+
return new _DecoratedProcedure({
|
76
|
+
...this["~orpc"],
|
77
|
+
postMiddlewares: [...this["~orpc"].postMiddlewares, middleware_]
|
78
|
+
});
|
79
|
+
}
|
80
|
+
unshiftTag(...tags) {
|
81
|
+
return new _DecoratedProcedure({
|
82
|
+
...this["~orpc"],
|
83
|
+
contract: DecoratedContractProcedure.decorate(this["~orpc"].contract).unshiftTag(...tags)
|
84
|
+
});
|
85
|
+
}
|
86
|
+
unshiftMiddleware(...middlewares) {
|
87
|
+
const castedMiddlewares = middlewares;
|
88
|
+
if (this["~orpc"].preMiddlewares.length) {
|
81
89
|
let min = 0;
|
82
|
-
for (let i = 0; i <
|
83
|
-
const index =
|
90
|
+
for (let i = 0; i < this["~orpc"].preMiddlewares.length; i++) {
|
91
|
+
const index = castedMiddlewares.indexOf(this["~orpc"].preMiddlewares[i], min);
|
84
92
|
if (index === -1) {
|
85
|
-
|
93
|
+
castedMiddlewares.push(...this["~orpc"].preMiddlewares.slice(i));
|
86
94
|
break;
|
87
95
|
}
|
88
96
|
min = index + 1;
|
89
97
|
}
|
90
98
|
}
|
91
|
-
return
|
92
|
-
...
|
93
|
-
|
94
|
-
})
|
95
|
-
}
|
96
|
-
|
97
|
-
|
99
|
+
return new _DecoratedProcedure({
|
100
|
+
...this["~orpc"],
|
101
|
+
preMiddlewares: castedMiddlewares
|
102
|
+
});
|
103
|
+
}
|
104
|
+
/**
|
105
|
+
* Make this procedure callable (works like a function while still being a procedure).
|
106
|
+
*/
|
107
|
+
callable(...rest) {
|
108
|
+
return Object.assign(createProcedureClient(this, ...rest), {
|
109
|
+
"~type": "Procedure",
|
110
|
+
"~orpc": this["~orpc"]
|
111
|
+
});
|
112
|
+
}
|
113
|
+
/**
|
114
|
+
* Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
|
115
|
+
*/
|
116
|
+
actionable(...rest) {
|
117
|
+
return this.callable(...rest);
|
118
|
+
}
|
119
|
+
};
|
98
120
|
|
99
121
|
// src/procedure-implementer.ts
|
100
122
|
var ProcedureImplementer = class _ProcedureImplementer {
|
@@ -107,15 +129,16 @@ var ProcedureImplementer = class _ProcedureImplementer {
|
|
107
129
|
const mappedMiddleware = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
108
130
|
return new _ProcedureImplementer({
|
109
131
|
...this["~orpc"],
|
110
|
-
|
132
|
+
postMiddlewares: [...this["~orpc"].postMiddlewares, mappedMiddleware]
|
111
133
|
});
|
112
134
|
}
|
113
|
-
|
114
|
-
return
|
115
|
-
|
135
|
+
handler(handler) {
|
136
|
+
return new DecoratedProcedure({
|
137
|
+
postMiddlewares: this["~orpc"].postMiddlewares,
|
138
|
+
preMiddlewares: this["~orpc"].preMiddlewares,
|
116
139
|
contract: this["~orpc"].contract,
|
117
|
-
|
118
|
-
})
|
140
|
+
handler
|
141
|
+
});
|
119
142
|
}
|
120
143
|
};
|
121
144
|
|
@@ -153,31 +176,10 @@ function getLazyRouterPrefix(obj) {
|
|
153
176
|
return obj[LAZY_ROUTER_PREFIX_SYMBOL];
|
154
177
|
}
|
155
178
|
|
156
|
-
// src/lazy-utils.ts
|
157
|
-
function createLazyProcedureFormAnyLazy(lazied) {
|
158
|
-
const lazyProcedure = lazy(async () => {
|
159
|
-
const { default: maybeProcedure } = await unlazy(flatLazy(lazied));
|
160
|
-
if (!isProcedure(maybeProcedure)) {
|
161
|
-
throw new Error(`
|
162
|
-
Expected a lazy<procedure> but got lazy<unknown>.
|
163
|
-
This should be caught by TypeScript compilation.
|
164
|
-
Please report this issue if this makes you feel uncomfortable.
|
165
|
-
`);
|
166
|
-
}
|
167
|
-
return { default: maybeProcedure };
|
168
|
-
});
|
169
|
-
return lazyProcedure;
|
170
|
-
}
|
171
|
-
|
172
179
|
// src/lazy-decorated.ts
|
173
180
|
function decorateLazy(lazied) {
|
174
181
|
const flattenLazy = flatLazy(lazied);
|
175
|
-
const
|
176
|
-
procedure: createLazyProcedureFormAnyLazy(flattenLazy),
|
177
|
-
context: void 0
|
178
|
-
});
|
179
|
-
Object.assign(procedureProcedureClient, flattenLazy);
|
180
|
-
const recursive = new Proxy(procedureProcedureClient, {
|
182
|
+
const recursive = new Proxy(flattenLazy, {
|
181
183
|
get(target, key) {
|
182
184
|
if (typeof key !== "string") {
|
183
185
|
return Reflect.get(target, key);
|
@@ -214,10 +216,19 @@ var RouterBuilder = class _RouterBuilder {
|
|
214
216
|
tags: [...this["~orpc"].tags ?? [], ...tags]
|
215
217
|
});
|
216
218
|
}
|
219
|
+
errors(errors) {
|
220
|
+
return new _RouterBuilder({
|
221
|
+
...this["~orpc"],
|
222
|
+
errorMap: {
|
223
|
+
...this["~orpc"].errorMap,
|
224
|
+
...errors
|
225
|
+
}
|
226
|
+
});
|
227
|
+
}
|
217
228
|
use(middleware) {
|
218
229
|
return new _RouterBuilder({
|
219
230
|
...this["~orpc"],
|
220
|
-
middlewares: [...this["~orpc"].middlewares
|
231
|
+
middlewares: [...this["~orpc"].middlewares, middleware]
|
221
232
|
});
|
222
233
|
}
|
223
234
|
router(router) {
|
@@ -244,7 +255,7 @@ function adapt(item, options) {
|
|
244
255
|
return adaptedLazy;
|
245
256
|
}
|
246
257
|
if (isProcedure(item)) {
|
247
|
-
let decorated =
|
258
|
+
let decorated = DecoratedProcedure.decorate(item);
|
248
259
|
if (options.tags?.length) {
|
249
260
|
decorated = decorated.unshiftTag(...options.tags);
|
250
261
|
}
|
@@ -254,6 +265,9 @@ function adapt(item, options) {
|
|
254
265
|
if (options.middlewares?.length) {
|
255
266
|
decorated = decorated.unshiftMiddleware(...options.middlewares);
|
256
267
|
}
|
268
|
+
if (Object.keys(options.errorMap).length) {
|
269
|
+
decorated = decorated.errors(options.errorMap);
|
270
|
+
}
|
257
271
|
return decorated;
|
258
272
|
}
|
259
273
|
const adapted = {};
|
@@ -277,23 +291,30 @@ var RouterImplementer = class _RouterImplementer {
|
|
277
291
|
});
|
278
292
|
}
|
279
293
|
router(router) {
|
280
|
-
const adapted = new RouterBuilder(
|
294
|
+
const adapted = new RouterBuilder({
|
295
|
+
...this["~orpc"],
|
296
|
+
errorMap: {}
|
297
|
+
}).router(router);
|
281
298
|
const contracted = setRouterContract(adapted, this["~orpc"].contract);
|
282
299
|
return contracted;
|
283
300
|
}
|
284
301
|
lazy(loader) {
|
285
|
-
const adapted = new RouterBuilder(
|
302
|
+
const adapted = new RouterBuilder({
|
303
|
+
...this["~orpc"],
|
304
|
+
errorMap: {}
|
305
|
+
}).lazy(loader);
|
286
306
|
const contracted = setRouterContract(adapted, this["~orpc"].contract);
|
287
307
|
return contracted;
|
288
308
|
}
|
289
309
|
};
|
290
310
|
|
291
311
|
// src/implementer-chainable.ts
|
292
|
-
function createChainableImplementer(contract, middlewares) {
|
312
|
+
function createChainableImplementer(contract, middlewares = []) {
|
293
313
|
if (isContractProcedure(contract)) {
|
294
314
|
const implementer = new ProcedureImplementer({
|
295
315
|
contract,
|
296
|
-
middlewares
|
316
|
+
preMiddlewares: middlewares,
|
317
|
+
postMiddlewares: []
|
297
318
|
});
|
298
319
|
return implementer;
|
299
320
|
}
|
@@ -346,24 +367,33 @@ var ProcedureBuilder = class _ProcedureBuilder {
|
|
346
367
|
contract: DecoratedContractProcedure2.decorate(this["~orpc"].contract).output(schema, example)
|
347
368
|
});
|
348
369
|
}
|
370
|
+
errors(errors) {
|
371
|
+
return new _ProcedureBuilder({
|
372
|
+
...this["~orpc"],
|
373
|
+
contract: DecoratedContractProcedure2.decorate(this["~orpc"].contract).errors(errors)
|
374
|
+
});
|
375
|
+
}
|
349
376
|
use(middleware, mapInput) {
|
350
377
|
if (!mapInput) {
|
351
378
|
return new ProcedureImplementer({
|
352
379
|
contract: this["~orpc"].contract,
|
353
|
-
|
380
|
+
preMiddlewares: this["~orpc"].middlewares,
|
381
|
+
postMiddlewares: []
|
354
382
|
}).use(middleware);
|
355
383
|
}
|
356
384
|
return new ProcedureImplementer({
|
357
385
|
contract: this["~orpc"].contract,
|
358
|
-
|
386
|
+
preMiddlewares: this["~orpc"].middlewares,
|
387
|
+
postMiddlewares: []
|
359
388
|
}).use(middleware, mapInput);
|
360
389
|
}
|
361
|
-
|
362
|
-
return
|
363
|
-
|
390
|
+
handler(handler) {
|
391
|
+
return new DecoratedProcedure({
|
392
|
+
preMiddlewares: this["~orpc"].middlewares,
|
393
|
+
postMiddlewares: [],
|
364
394
|
contract: this["~orpc"].contract,
|
365
|
-
|
366
|
-
})
|
395
|
+
handler
|
396
|
+
});
|
367
397
|
}
|
368
398
|
};
|
369
399
|
|
@@ -374,15 +404,29 @@ var Builder = class _Builder {
|
|
374
404
|
constructor(def) {
|
375
405
|
this["~orpc"] = def;
|
376
406
|
}
|
407
|
+
// TODO: separate it
|
377
408
|
context() {
|
378
|
-
return new _Builder({
|
409
|
+
return new _Builder({
|
410
|
+
middlewares: [],
|
411
|
+
errorMap: {}
|
412
|
+
});
|
379
413
|
}
|
380
414
|
use(middleware) {
|
381
415
|
return new _Builder({
|
382
416
|
...this["~orpc"],
|
383
|
-
middlewares: [...this["~orpc"].middlewares
|
417
|
+
middlewares: [...this["~orpc"].middlewares, middleware]
|
418
|
+
});
|
419
|
+
}
|
420
|
+
errors(errors) {
|
421
|
+
return new _Builder({
|
422
|
+
...this["~orpc"],
|
423
|
+
errorMap: {
|
424
|
+
...this["~orpc"].errorMap,
|
425
|
+
...errors
|
426
|
+
}
|
384
427
|
});
|
385
428
|
}
|
429
|
+
// TODO: not allow define middleware after has context, or anything else
|
386
430
|
middleware(middleware) {
|
387
431
|
return decorateMiddleware(middleware);
|
388
432
|
}
|
@@ -392,7 +436,8 @@ var Builder = class _Builder {
|
|
392
436
|
contract: new ContractProcedure({
|
393
437
|
route,
|
394
438
|
InputSchema: void 0,
|
395
|
-
OutputSchema: void 0
|
439
|
+
OutputSchema: void 0,
|
440
|
+
errorMap: this["~orpc"].errorMap
|
396
441
|
})
|
397
442
|
});
|
398
443
|
}
|
@@ -402,7 +447,8 @@ var Builder = class _Builder {
|
|
402
447
|
contract: new ContractProcedure({
|
403
448
|
OutputSchema: void 0,
|
404
449
|
InputSchema: schema,
|
405
|
-
inputExample: example
|
450
|
+
inputExample: example,
|
451
|
+
errorMap: this["~orpc"].errorMap
|
406
452
|
})
|
407
453
|
});
|
408
454
|
}
|
@@ -412,29 +458,34 @@ var Builder = class _Builder {
|
|
412
458
|
contract: new ContractProcedure({
|
413
459
|
InputSchema: void 0,
|
414
460
|
OutputSchema: schema,
|
415
|
-
outputExample: example
|
461
|
+
outputExample: example,
|
462
|
+
errorMap: this["~orpc"].errorMap
|
416
463
|
})
|
417
464
|
});
|
418
465
|
}
|
419
|
-
|
420
|
-
return
|
421
|
-
|
466
|
+
handler(handler) {
|
467
|
+
return new DecoratedProcedure({
|
468
|
+
preMiddlewares: this["~orpc"].middlewares,
|
469
|
+
postMiddlewares: [],
|
422
470
|
contract: new ContractProcedure({
|
423
471
|
InputSchema: void 0,
|
424
|
-
OutputSchema: void 0
|
472
|
+
OutputSchema: void 0,
|
473
|
+
errorMap: this["~orpc"].errorMap
|
425
474
|
}),
|
426
|
-
|
427
|
-
})
|
475
|
+
handler
|
476
|
+
});
|
428
477
|
}
|
429
478
|
prefix(prefix) {
|
430
479
|
return new RouterBuilder({
|
431
480
|
middlewares: this["~orpc"].middlewares,
|
481
|
+
errorMap: this["~orpc"].errorMap,
|
432
482
|
prefix
|
433
483
|
});
|
434
484
|
}
|
435
485
|
tag(...tags) {
|
436
486
|
return new RouterBuilder({
|
437
487
|
middlewares: this["~orpc"].middlewares,
|
488
|
+
errorMap: this["~orpc"].errorMap,
|
438
489
|
tags
|
439
490
|
});
|
440
491
|
}
|
@@ -449,36 +500,47 @@ var Builder = class _Builder {
|
|
449
500
|
}
|
450
501
|
};
|
451
502
|
|
503
|
+
// src/procedure-utils.ts
|
504
|
+
function call(procedure, input, ...rest) {
|
505
|
+
return createProcedureClient(procedure, ...rest)(input);
|
506
|
+
}
|
507
|
+
|
508
|
+
// src/lazy-utils.ts
|
509
|
+
function createLazyProcedureFormAnyLazy(lazied) {
|
510
|
+
const lazyProcedure = lazy(async () => {
|
511
|
+
const { default: maybeProcedure } = await unlazy(flatLazy(lazied));
|
512
|
+
if (!isProcedure(maybeProcedure)) {
|
513
|
+
throw new Error(`
|
514
|
+
Expected a lazy<procedure> but got lazy<unknown>.
|
515
|
+
This should be caught by TypeScript compilation.
|
516
|
+
Please report this issue if this makes you feel uncomfortable.
|
517
|
+
`);
|
518
|
+
}
|
519
|
+
return { default: maybeProcedure };
|
520
|
+
});
|
521
|
+
return lazyProcedure;
|
522
|
+
}
|
523
|
+
|
452
524
|
// src/router-client.ts
|
453
|
-
function createRouterClient(
|
454
|
-
if (isProcedure(
|
455
|
-
const caller = createProcedureClient(
|
456
|
-
...options,
|
457
|
-
procedure: options.router,
|
458
|
-
context: options.context,
|
459
|
-
path: options.path
|
460
|
-
});
|
525
|
+
function createRouterClient(router, ...rest) {
|
526
|
+
if (isProcedure(router)) {
|
527
|
+
const caller = createProcedureClient(router, ...rest);
|
461
528
|
return caller;
|
462
529
|
}
|
463
|
-
const procedureCaller = isLazy(
|
464
|
-
...options,
|
465
|
-
procedure: createLazyProcedureFormAnyLazy(options.router),
|
466
|
-
context: options.context,
|
467
|
-
path: options.path
|
468
|
-
}) : {};
|
530
|
+
const procedureCaller = isLazy(router) ? createProcedureClient(createLazyProcedureFormAnyLazy(router), ...rest) : {};
|
469
531
|
const recursive = new Proxy(procedureCaller, {
|
470
532
|
get(target, key) {
|
471
533
|
if (typeof key !== "string") {
|
472
534
|
return Reflect.get(target, key);
|
473
535
|
}
|
474
|
-
const next = getRouterChild(
|
536
|
+
const next = getRouterChild(router, key);
|
475
537
|
if (!next) {
|
476
538
|
return Reflect.get(target, key);
|
477
539
|
}
|
478
|
-
|
540
|
+
const [options] = rest;
|
541
|
+
return createRouterClient(next, {
|
479
542
|
...options,
|
480
|
-
|
481
|
-
path: [...options.path ?? [], key]
|
543
|
+
path: [...options?.path ?? [], key]
|
482
544
|
});
|
483
545
|
}
|
484
546
|
});
|
@@ -486,32 +548,43 @@ function createRouterClient(options) {
|
|
486
548
|
}
|
487
549
|
|
488
550
|
// src/index.ts
|
489
|
-
|
490
|
-
var os = new Builder({
|
551
|
+
import { configGlobal, fallbackToGlobalConfig, isDefinedError, ORPCError, safe } from "@orpc/contract";
|
552
|
+
var os = new Builder({
|
553
|
+
middlewares: [],
|
554
|
+
errorMap: {}
|
555
|
+
});
|
491
556
|
export {
|
492
557
|
Builder,
|
558
|
+
DecoratedProcedure,
|
493
559
|
LAZY_LOADER_SYMBOL,
|
560
|
+
ORPCError,
|
494
561
|
Procedure,
|
495
562
|
ProcedureBuilder,
|
496
563
|
ProcedureImplementer,
|
497
564
|
RouterBuilder,
|
498
565
|
RouterImplementer,
|
566
|
+
call,
|
567
|
+
configGlobal,
|
499
568
|
createChainableImplementer,
|
569
|
+
createORPCErrorConstructorMap,
|
500
570
|
createProcedureClient,
|
501
571
|
createRouterClient,
|
502
572
|
decorateLazy,
|
503
573
|
decorateMiddleware,
|
504
|
-
decorateProcedure,
|
505
574
|
deepSetLazyRouterPrefix,
|
575
|
+
fallbackToGlobalConfig,
|
506
576
|
flatLazy,
|
507
577
|
getLazyRouterPrefix,
|
508
578
|
getRouterChild,
|
509
579
|
getRouterContract,
|
580
|
+
isDefinedError,
|
510
581
|
isLazy,
|
511
582
|
isProcedure,
|
512
583
|
lazy,
|
513
584
|
mergeContext,
|
585
|
+
middlewareOutputFn,
|
514
586
|
os,
|
587
|
+
safe,
|
515
588
|
setRouterContract,
|
516
589
|
unlazy
|
517
590
|
};
|
package/dist/next.js
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
import "./chunk-WUOGVGWG.js";
|
2
|
+
import {
|
3
|
+
ORPCPayloadCodec,
|
4
|
+
ORPCProcedureMatcher,
|
5
|
+
RPCHandler,
|
6
|
+
super_json_exports
|
7
|
+
} from "./chunk-2HRHHZJD.js";
|
8
|
+
import "./chunk-SA7HGGVY.js";
|
9
|
+
|
10
|
+
// src/adapters/next/serve.ts
|
11
|
+
import { value } from "@orpc/shared";
|
12
|
+
function serve(handler, ...[options]) {
|
13
|
+
const main = async (req) => {
|
14
|
+
const context = await value(options?.context, req);
|
15
|
+
const { matched, response } = await handler.handle(req, { ...options, context });
|
16
|
+
if (matched) {
|
17
|
+
return response;
|
18
|
+
}
|
19
|
+
return new Response(`Cannot find a matching procedure for ${req.url}`, { status: 404 });
|
20
|
+
};
|
21
|
+
return {
|
22
|
+
GET: main,
|
23
|
+
POST: main,
|
24
|
+
PUT: main,
|
25
|
+
PATCH: main,
|
26
|
+
DELETE: main
|
27
|
+
};
|
28
|
+
}
|
29
|
+
export {
|
30
|
+
ORPCPayloadCodec,
|
31
|
+
ORPCProcedureMatcher,
|
32
|
+
RPCHandler,
|
33
|
+
super_json_exports as SuperJSON,
|
34
|
+
serve
|
35
|
+
};
|
36
|
+
//# sourceMappingURL=next.js.map
|
package/dist/node.js
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
import {
|
2
|
+
RPCHandler
|
3
|
+
} from "./chunk-2HRHHZJD.js";
|
4
|
+
import "./chunk-SA7HGGVY.js";
|
5
|
+
|
6
|
+
// src/adapters/node/request-listener.ts
|
7
|
+
function createRequest(req, res) {
|
8
|
+
const controller = new AbortController();
|
9
|
+
res.on("close", () => {
|
10
|
+
controller.abort();
|
11
|
+
});
|
12
|
+
const method = req.method ?? "GET";
|
13
|
+
const headers = createHeaders(req);
|
14
|
+
const protocol = "encrypted" in req.socket && req.socket.encrypted ? "https:" : "http:";
|
15
|
+
const host = headers.get("Host") ?? "localhost";
|
16
|
+
const url = new URL(req.originalUrl ?? req.url ?? "/", `${protocol}//${host}`);
|
17
|
+
const init = { method, headers, signal: controller.signal };
|
18
|
+
if (method !== "GET" && method !== "HEAD") {
|
19
|
+
init.body = new ReadableStream({
|
20
|
+
start(controller2) {
|
21
|
+
req.on("data", (chunk) => {
|
22
|
+
controller2.enqueue(new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength));
|
23
|
+
});
|
24
|
+
req.on("end", () => {
|
25
|
+
controller2.close();
|
26
|
+
});
|
27
|
+
}
|
28
|
+
});
|
29
|
+
init.duplex = "half";
|
30
|
+
}
|
31
|
+
return new Request(url, init);
|
32
|
+
}
|
33
|
+
function createHeaders(req) {
|
34
|
+
const headers = new Headers();
|
35
|
+
const rawHeaders = req.rawHeaders;
|
36
|
+
for (let i = 0; i < rawHeaders.length; i += 2) {
|
37
|
+
headers.append(rawHeaders[i], rawHeaders[i + 1]);
|
38
|
+
}
|
39
|
+
return headers;
|
40
|
+
}
|
41
|
+
async function sendResponse(res, response) {
|
42
|
+
const headers = {};
|
43
|
+
for (const [key, value] of response.headers) {
|
44
|
+
if (key in headers) {
|
45
|
+
if (Array.isArray(headers[key])) {
|
46
|
+
headers[key].push(value);
|
47
|
+
} else {
|
48
|
+
headers[key] = [headers[key], value];
|
49
|
+
}
|
50
|
+
} else {
|
51
|
+
headers[key] = value;
|
52
|
+
}
|
53
|
+
}
|
54
|
+
res.writeHead(response.status, headers);
|
55
|
+
if (response.body != null && res.req.method !== "HEAD") {
|
56
|
+
for await (const chunk of response.body) {
|
57
|
+
res.write(chunk);
|
58
|
+
}
|
59
|
+
}
|
60
|
+
res.end();
|
61
|
+
}
|
62
|
+
|
63
|
+
// src/adapters/node/orpc-handler.ts
|
64
|
+
var RPCHandler2 = class {
|
65
|
+
orpcFetchHandler;
|
66
|
+
constructor(router, options) {
|
67
|
+
this.orpcFetchHandler = new RPCHandler(router, options);
|
68
|
+
}
|
69
|
+
async handle(req, res, ...[options]) {
|
70
|
+
const request = createRequest(req, res);
|
71
|
+
const castedOptions = options ?? {};
|
72
|
+
const result = await this.orpcFetchHandler.handle(request, castedOptions);
|
73
|
+
if (result.matched === false) {
|
74
|
+
return { matched: false };
|
75
|
+
}
|
76
|
+
await options?.beforeSend?.(result.response, castedOptions.context);
|
77
|
+
await sendResponse(res, result.response);
|
78
|
+
return { matched: true };
|
79
|
+
}
|
80
|
+
};
|
81
|
+
export {
|
82
|
+
RPCHandler2 as RPCHandler,
|
83
|
+
createHeaders,
|
84
|
+
createRequest,
|
85
|
+
sendResponse
|
86
|
+
};
|
87
|
+
//# sourceMappingURL=node.js.map
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import type { Hooks } from '@orpc/shared';
|
2
|
+
import type { Router } from '../../router';
|
3
|
+
import type { Context } from '../../types';
|
4
|
+
import type { FetchHandler, FetchHandleRest, FetchHandleResult } from './types';
|
5
|
+
import { type PublicORPCPayloadCodec } from './orpc-payload-codec';
|
6
|
+
import { type PublicORPCProcedureMatcher } from './orpc-procedure-matcher';
|
7
|
+
export type RPCHandlerOptions<T extends Context> = Hooks<Request, FetchHandleResult, T, {
|
8
|
+
signal?: AbortSignal;
|
9
|
+
}> & {
|
10
|
+
procedureMatcher?: PublicORPCProcedureMatcher;
|
11
|
+
payloadCodec?: PublicORPCPayloadCodec;
|
12
|
+
};
|
13
|
+
export declare class RPCHandler<T extends Context> implements FetchHandler<T> {
|
14
|
+
private readonly options?;
|
15
|
+
private readonly procedureMatcher;
|
16
|
+
private readonly payloadCodec;
|
17
|
+
constructor(router: Router<T, any>, options?: NoInfer<RPCHandlerOptions<T>> | undefined);
|
18
|
+
handle(request: Request, ...[options]: FetchHandleRest<T>): Promise<FetchHandleResult>;
|
19
|
+
}
|
20
|
+
//# sourceMappingURL=orpc-handler.d.ts.map
|