@orpc/server 0.0.0-next.97446ff → 0.0.0-next.9914009
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-3EVCPLVI.js +301 -0
- package/dist/chunk-OUPZ7QGV.js +245 -0
- package/dist/chunk-WUOGVGWG.js +1 -0
- package/dist/fetch.js +11 -108
- package/dist/hono.js +30 -0
- package/dist/index.js +166 -122
- package/dist/next.js +36 -0
- package/dist/node.js +87 -0
- package/dist/src/adapters/fetch/index.d.ts +6 -0
- 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/adapters/fetch/orpc-procedure-matcher.d.ts +12 -0
- package/dist/src/adapters/fetch/super-json.d.ts +12 -0
- 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 +11 -10
- package/dist/src/error.d.ts +10 -0
- package/dist/src/implementer-chainable.d.ts +2 -2
- package/dist/src/index.d.ts +3 -1
- 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 -16
- package/dist/src/procedure-decorated.d.ts +22 -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 +4 -4
- package/dist/src/router-client.d.ts +7 -6
- package/dist/src/router-implementer.d.ts +2 -2
- package/dist/src/router.d.ts +4 -4
- package/dist/src/types.d.ts +2 -0
- package/package.json +22 -10
- package/dist/chunk-FN62GL22.js +0 -182
- package/dist/src/fetch/handle-request.d.ts +0 -7
- package/dist/src/fetch/index.d.ts +0 -4
- package/dist/src/fetch/orpc-handler.d.ts +0 -3
- package/dist/src/fetch/types.d.ts +0 -28
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,32 +9,33 @@ import {
|
|
8
9
|
isProcedure,
|
9
10
|
lazy,
|
10
11
|
mergeContext,
|
12
|
+
middlewareOutputFn,
|
11
13
|
unlazy
|
12
|
-
} from "./chunk-
|
14
|
+
} from "./chunk-OUPZ7QGV.js";
|
13
15
|
|
14
16
|
// src/builder.ts
|
15
17
|
import { ContractProcedure } from "@orpc/contract";
|
16
18
|
|
17
19
|
// src/implementer-chainable.ts
|
18
20
|
import { isContractProcedure } from "@orpc/contract";
|
19
|
-
import { createCallableObject } from "@orpc/shared";
|
21
|
+
import { createCallableObject as createCallableObject2 } from "@orpc/shared";
|
20
22
|
|
21
23
|
// src/middleware-decorated.ts
|
22
24
|
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,72 @@ function decorateMiddleware(middleware) {
|
|
43
45
|
|
44
46
|
// src/procedure-decorated.ts
|
45
47
|
import { DecoratedContractProcedure } from "@orpc/contract";
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
return
|
56
|
-
...
|
57
|
-
contract: DecoratedContractProcedure.decorate(
|
58
|
-
})
|
59
|
-
}
|
60
|
-
|
61
|
-
return
|
62
|
-
...
|
63
|
-
contract: DecoratedContractProcedure.decorate(
|
64
|
-
})
|
65
|
-
}
|
66
|
-
|
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
|
+
use(middleware, mapInput) {
|
67
69
|
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
|
-
|
70
|
+
return new _DecoratedProcedure({
|
71
|
+
...this["~orpc"],
|
72
|
+
postMiddlewares: [...this["~orpc"].postMiddlewares, middleware_]
|
73
|
+
});
|
74
|
+
}
|
75
|
+
unshiftTag(...tags) {
|
76
|
+
return new _DecoratedProcedure({
|
77
|
+
...this["~orpc"],
|
78
|
+
contract: DecoratedContractProcedure.decorate(this["~orpc"].contract).unshiftTag(...tags)
|
79
|
+
});
|
80
|
+
}
|
81
|
+
unshiftMiddleware(...middlewares) {
|
82
|
+
const castedMiddlewares = middlewares;
|
83
|
+
if (this["~orpc"].preMiddlewares.length) {
|
81
84
|
let min = 0;
|
82
|
-
for (let i = 0; i <
|
83
|
-
const index =
|
85
|
+
for (let i = 0; i < this["~orpc"].preMiddlewares.length; i++) {
|
86
|
+
const index = castedMiddlewares.indexOf(this["~orpc"].preMiddlewares[i], min);
|
84
87
|
if (index === -1) {
|
85
|
-
|
88
|
+
castedMiddlewares.push(...this["~orpc"].preMiddlewares.slice(i));
|
86
89
|
break;
|
87
90
|
}
|
88
91
|
min = index + 1;
|
89
92
|
}
|
90
93
|
}
|
91
|
-
return
|
92
|
-
...
|
93
|
-
|
94
|
-
})
|
95
|
-
}
|
96
|
-
|
97
|
-
|
94
|
+
return new _DecoratedProcedure({
|
95
|
+
...this["~orpc"],
|
96
|
+
preMiddlewares: castedMiddlewares
|
97
|
+
});
|
98
|
+
}
|
99
|
+
/**
|
100
|
+
* Make this procedure callable (works like a function while still being a procedure).
|
101
|
+
* **Note**: this only takes effect when this method is called at the end of the chain.
|
102
|
+
*/
|
103
|
+
callable(...rest) {
|
104
|
+
return createCallableObject(this, createProcedureClient(this, ...rest));
|
105
|
+
}
|
106
|
+
/**
|
107
|
+
* Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
|
108
|
+
* **Note**: this only takes effect when this method is called at the end of the chain.
|
109
|
+
*/
|
110
|
+
actionable(...rest) {
|
111
|
+
return this.callable(...rest);
|
112
|
+
}
|
113
|
+
};
|
98
114
|
|
99
115
|
// src/procedure-implementer.ts
|
100
116
|
var ProcedureImplementer = class _ProcedureImplementer {
|
@@ -107,15 +123,16 @@ var ProcedureImplementer = class _ProcedureImplementer {
|
|
107
123
|
const mappedMiddleware = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
108
124
|
return new _ProcedureImplementer({
|
109
125
|
...this["~orpc"],
|
110
|
-
|
126
|
+
postMiddlewares: [...this["~orpc"].postMiddlewares, mappedMiddleware]
|
111
127
|
});
|
112
128
|
}
|
113
|
-
|
114
|
-
return
|
115
|
-
|
129
|
+
handler(handler) {
|
130
|
+
return new DecoratedProcedure({
|
131
|
+
postMiddlewares: this["~orpc"].postMiddlewares,
|
132
|
+
preMiddlewares: this["~orpc"].preMiddlewares,
|
116
133
|
contract: this["~orpc"].contract,
|
117
|
-
|
118
|
-
})
|
134
|
+
handler
|
135
|
+
});
|
119
136
|
}
|
120
137
|
};
|
121
138
|
|
@@ -153,31 +170,10 @@ function getLazyRouterPrefix(obj) {
|
|
153
170
|
return obj[LAZY_ROUTER_PREFIX_SYMBOL];
|
154
171
|
}
|
155
172
|
|
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
173
|
// src/lazy-decorated.ts
|
173
174
|
function decorateLazy(lazied) {
|
174
175
|
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, {
|
176
|
+
const recursive = new Proxy(flattenLazy, {
|
181
177
|
get(target, key) {
|
182
178
|
if (typeof key !== "string") {
|
183
179
|
return Reflect.get(target, key);
|
@@ -217,7 +213,7 @@ var RouterBuilder = class _RouterBuilder {
|
|
217
213
|
use(middleware) {
|
218
214
|
return new _RouterBuilder({
|
219
215
|
...this["~orpc"],
|
220
|
-
middlewares: [...this["~orpc"].middlewares
|
216
|
+
middlewares: [...this["~orpc"].middlewares, middleware]
|
221
217
|
});
|
222
218
|
}
|
223
219
|
router(router) {
|
@@ -244,7 +240,7 @@ function adapt(item, options) {
|
|
244
240
|
return adaptedLazy;
|
245
241
|
}
|
246
242
|
if (isProcedure(item)) {
|
247
|
-
let decorated =
|
243
|
+
let decorated = DecoratedProcedure.decorate(item);
|
248
244
|
if (options.tags?.length) {
|
249
245
|
decorated = decorated.unshiftTag(...options.tags);
|
250
246
|
}
|
@@ -289,11 +285,12 @@ var RouterImplementer = class _RouterImplementer {
|
|
289
285
|
};
|
290
286
|
|
291
287
|
// src/implementer-chainable.ts
|
292
|
-
function createChainableImplementer(contract, middlewares) {
|
288
|
+
function createChainableImplementer(contract, middlewares = []) {
|
293
289
|
if (isContractProcedure(contract)) {
|
294
290
|
const implementer = new ProcedureImplementer({
|
295
291
|
contract,
|
296
|
-
middlewares
|
292
|
+
preMiddlewares: middlewares,
|
293
|
+
postMiddlewares: []
|
297
294
|
});
|
298
295
|
return implementer;
|
299
296
|
}
|
@@ -312,7 +309,7 @@ function createChainableImplementer(contract, middlewares) {
|
|
312
309
|
if (!next) {
|
313
310
|
return method.bind(routerImplementer);
|
314
311
|
}
|
315
|
-
return
|
312
|
+
return createCallableObject2(next, method.bind(routerImplementer));
|
316
313
|
}
|
317
314
|
});
|
318
315
|
return merged;
|
@@ -346,24 +343,33 @@ var ProcedureBuilder = class _ProcedureBuilder {
|
|
346
343
|
contract: DecoratedContractProcedure2.decorate(this["~orpc"].contract).output(schema, example)
|
347
344
|
});
|
348
345
|
}
|
346
|
+
errors(errors) {
|
347
|
+
return new _ProcedureBuilder({
|
348
|
+
...this["~orpc"],
|
349
|
+
contract: DecoratedContractProcedure2.decorate(this["~orpc"].contract).errors(errors)
|
350
|
+
});
|
351
|
+
}
|
349
352
|
use(middleware, mapInput) {
|
350
353
|
if (!mapInput) {
|
351
354
|
return new ProcedureImplementer({
|
352
355
|
contract: this["~orpc"].contract,
|
353
|
-
|
356
|
+
preMiddlewares: this["~orpc"].middlewares,
|
357
|
+
postMiddlewares: []
|
354
358
|
}).use(middleware);
|
355
359
|
}
|
356
360
|
return new ProcedureImplementer({
|
357
361
|
contract: this["~orpc"].contract,
|
358
|
-
|
362
|
+
preMiddlewares: this["~orpc"].middlewares,
|
363
|
+
postMiddlewares: []
|
359
364
|
}).use(middleware, mapInput);
|
360
365
|
}
|
361
|
-
|
362
|
-
return
|
363
|
-
|
366
|
+
handler(handler) {
|
367
|
+
return new DecoratedProcedure({
|
368
|
+
preMiddlewares: this["~orpc"].middlewares,
|
369
|
+
postMiddlewares: [],
|
364
370
|
contract: this["~orpc"].contract,
|
365
|
-
|
366
|
-
})
|
371
|
+
handler
|
372
|
+
});
|
367
373
|
}
|
368
374
|
};
|
369
375
|
|
@@ -375,12 +381,14 @@ var Builder = class _Builder {
|
|
375
381
|
this["~orpc"] = def;
|
376
382
|
}
|
377
383
|
context() {
|
378
|
-
return new _Builder({
|
384
|
+
return new _Builder({
|
385
|
+
middlewares: []
|
386
|
+
});
|
379
387
|
}
|
380
388
|
use(middleware) {
|
381
389
|
return new _Builder({
|
382
390
|
...this["~orpc"],
|
383
|
-
middlewares: [...this["~orpc"].middlewares
|
391
|
+
middlewares: [...this["~orpc"].middlewares, middleware]
|
384
392
|
});
|
385
393
|
}
|
386
394
|
middleware(middleware) {
|
@@ -392,7 +400,8 @@ var Builder = class _Builder {
|
|
392
400
|
contract: new ContractProcedure({
|
393
401
|
route,
|
394
402
|
InputSchema: void 0,
|
395
|
-
OutputSchema: void 0
|
403
|
+
OutputSchema: void 0,
|
404
|
+
errorMap: void 0
|
396
405
|
})
|
397
406
|
});
|
398
407
|
}
|
@@ -402,7 +411,8 @@ var Builder = class _Builder {
|
|
402
411
|
contract: new ContractProcedure({
|
403
412
|
OutputSchema: void 0,
|
404
413
|
InputSchema: schema,
|
405
|
-
inputExample: example
|
414
|
+
inputExample: example,
|
415
|
+
errorMap: void 0
|
406
416
|
})
|
407
417
|
});
|
408
418
|
}
|
@@ -412,19 +422,32 @@ var Builder = class _Builder {
|
|
412
422
|
contract: new ContractProcedure({
|
413
423
|
InputSchema: void 0,
|
414
424
|
OutputSchema: schema,
|
415
|
-
outputExample: example
|
425
|
+
outputExample: example,
|
426
|
+
errorMap: void 0
|
416
427
|
})
|
417
428
|
});
|
418
429
|
}
|
419
|
-
|
420
|
-
return
|
430
|
+
errors(errors) {
|
431
|
+
return new ProcedureBuilder({
|
421
432
|
middlewares: this["~orpc"].middlewares,
|
422
433
|
contract: new ContractProcedure({
|
423
434
|
InputSchema: void 0,
|
424
|
-
OutputSchema: void 0
|
435
|
+
OutputSchema: void 0,
|
436
|
+
errorMap: errors
|
437
|
+
})
|
438
|
+
});
|
439
|
+
}
|
440
|
+
handler(handler) {
|
441
|
+
return new DecoratedProcedure({
|
442
|
+
preMiddlewares: this["~orpc"].middlewares,
|
443
|
+
postMiddlewares: [],
|
444
|
+
contract: new ContractProcedure({
|
445
|
+
InputSchema: void 0,
|
446
|
+
OutputSchema: void 0,
|
447
|
+
errorMap: void 0
|
425
448
|
}),
|
426
|
-
|
427
|
-
})
|
449
|
+
handler
|
450
|
+
});
|
428
451
|
}
|
429
452
|
prefix(prefix) {
|
430
453
|
return new RouterBuilder({
|
@@ -449,36 +472,47 @@ var Builder = class _Builder {
|
|
449
472
|
}
|
450
473
|
};
|
451
474
|
|
475
|
+
// src/procedure-utils.ts
|
476
|
+
function call(procedure, input, ...rest) {
|
477
|
+
return createProcedureClient(procedure, ...rest)(input);
|
478
|
+
}
|
479
|
+
|
480
|
+
// src/lazy-utils.ts
|
481
|
+
function createLazyProcedureFormAnyLazy(lazied) {
|
482
|
+
const lazyProcedure = lazy(async () => {
|
483
|
+
const { default: maybeProcedure } = await unlazy(flatLazy(lazied));
|
484
|
+
if (!isProcedure(maybeProcedure)) {
|
485
|
+
throw new Error(`
|
486
|
+
Expected a lazy<procedure> but got lazy<unknown>.
|
487
|
+
This should be caught by TypeScript compilation.
|
488
|
+
Please report this issue if this makes you feel uncomfortable.
|
489
|
+
`);
|
490
|
+
}
|
491
|
+
return { default: maybeProcedure };
|
492
|
+
});
|
493
|
+
return lazyProcedure;
|
494
|
+
}
|
495
|
+
|
452
496
|
// 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
|
-
});
|
497
|
+
function createRouterClient(router, ...rest) {
|
498
|
+
if (isProcedure(router)) {
|
499
|
+
const caller = createProcedureClient(router, ...rest);
|
461
500
|
return caller;
|
462
501
|
}
|
463
|
-
const procedureCaller = isLazy(
|
464
|
-
...options,
|
465
|
-
procedure: createLazyProcedureFormAnyLazy(options.router),
|
466
|
-
context: options.context,
|
467
|
-
path: options.path
|
468
|
-
}) : {};
|
502
|
+
const procedureCaller = isLazy(router) ? createProcedureClient(createLazyProcedureFormAnyLazy(router), ...rest) : {};
|
469
503
|
const recursive = new Proxy(procedureCaller, {
|
470
504
|
get(target, key) {
|
471
505
|
if (typeof key !== "string") {
|
472
506
|
return Reflect.get(target, key);
|
473
507
|
}
|
474
|
-
const next = getRouterChild(
|
508
|
+
const next = getRouterChild(router, key);
|
475
509
|
if (!next) {
|
476
510
|
return Reflect.get(target, key);
|
477
511
|
}
|
478
|
-
|
512
|
+
const [options] = rest;
|
513
|
+
return createRouterClient(next, {
|
479
514
|
...options,
|
480
|
-
|
481
|
-
path: [...options.path ?? [], key]
|
515
|
+
path: [...options?.path ?? [], key]
|
482
516
|
});
|
483
517
|
}
|
484
518
|
});
|
@@ -486,32 +520,42 @@ function createRouterClient(options) {
|
|
486
520
|
}
|
487
521
|
|
488
522
|
// src/index.ts
|
489
|
-
|
490
|
-
var os = new Builder({
|
523
|
+
import { configGlobal, fallbackToGlobalConfig, isDefinedError, ORPCError, safe } from "@orpc/contract";
|
524
|
+
var os = new Builder({
|
525
|
+
middlewares: []
|
526
|
+
});
|
491
527
|
export {
|
492
528
|
Builder,
|
529
|
+
DecoratedProcedure,
|
493
530
|
LAZY_LOADER_SYMBOL,
|
531
|
+
ORPCError,
|
494
532
|
Procedure,
|
495
533
|
ProcedureBuilder,
|
496
534
|
ProcedureImplementer,
|
497
535
|
RouterBuilder,
|
498
536
|
RouterImplementer,
|
537
|
+
call,
|
538
|
+
configGlobal,
|
499
539
|
createChainableImplementer,
|
540
|
+
createORPCErrorConstructorMap,
|
500
541
|
createProcedureClient,
|
501
542
|
createRouterClient,
|
502
543
|
decorateLazy,
|
503
544
|
decorateMiddleware,
|
504
|
-
decorateProcedure,
|
505
545
|
deepSetLazyRouterPrefix,
|
546
|
+
fallbackToGlobalConfig,
|
506
547
|
flatLazy,
|
507
548
|
getLazyRouterPrefix,
|
508
549
|
getRouterChild,
|
509
550
|
getRouterContract,
|
551
|
+
isDefinedError,
|
510
552
|
isLazy,
|
511
553
|
isProcedure,
|
512
554
|
lazy,
|
513
555
|
mergeContext,
|
556
|
+
middlewareOutputFn,
|
514
557
|
os,
|
558
|
+
safe,
|
515
559
|
setRouterContract,
|
516
560
|
unlazy
|
517
561
|
};
|
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-3EVCPLVI.js";
|
8
|
+
import "./chunk-OUPZ7QGV.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-3EVCPLVI.js";
|
4
|
+
import "./chunk-OUPZ7QGV.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
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import { type HTTPMethod } from '@orpc/contract';
|
2
|
+
export declare class ORPCPayloadCodec {
|
3
|
+
/**
|
4
|
+
* If method is GET, the payload will be encoded as query string.
|
5
|
+
* If method is GET and payload contain file, the method will be fallback to fallbackMethod. (fallbackMethod = GET will force to use GET method)
|
6
|
+
*/
|
7
|
+
encode(payload: unknown, method?: HTTPMethod, fallbackMethod?: HTTPMethod): {
|
8
|
+
query?: URLSearchParams;
|
9
|
+
body?: FormData | string;
|
10
|
+
headers?: Headers;
|
11
|
+
method: HTTPMethod;
|
12
|
+
};
|
13
|
+
decode(re: Request | Response): Promise<unknown>;
|
14
|
+
}
|
15
|
+
export type PublicORPCPayloadCodec = Pick<ORPCPayloadCodec, keyof ORPCPayloadCodec>;
|
16
|
+
//# sourceMappingURL=orpc-payload-codec.d.ts.map
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import type { ANY_PROCEDURE } from '../../procedure';
|
2
|
+
import { type ANY_ROUTER } from '../../router';
|
3
|
+
export declare class ORPCProcedureMatcher {
|
4
|
+
private readonly router;
|
5
|
+
constructor(router: ANY_ROUTER);
|
6
|
+
match(pathname: string): Promise<{
|
7
|
+
path: string[];
|
8
|
+
procedure: ANY_PROCEDURE;
|
9
|
+
} | undefined>;
|
10
|
+
}
|
11
|
+
export type PublicORPCProcedureMatcher = Pick<ORPCProcedureMatcher, keyof ORPCProcedureMatcher>;
|
12
|
+
//# sourceMappingURL=orpc-procedure-matcher.d.ts.map
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import type { Segment } from '@orpc/shared';
|
2
|
+
export type JSONExtraType = 'bigint' | 'date' | 'nan' | 'undefined' | 'set' | 'map' | 'regexp' | 'url';
|
3
|
+
export type JSONMeta = [JSONExtraType, Segment[]][];
|
4
|
+
export declare function serialize(value: unknown, segments?: Segment[], meta?: JSONMeta): {
|
5
|
+
data: unknown;
|
6
|
+
meta: JSONMeta;
|
7
|
+
};
|
8
|
+
export declare function deserialize({ data, meta, }: {
|
9
|
+
data: unknown;
|
10
|
+
meta: JSONMeta;
|
11
|
+
}): unknown;
|
12
|
+
//# sourceMappingURL=super-json.d.ts.map
|