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