@orpc/server 0.30.0 → 0.31.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/{chunk-SA7HGGVY.js → chunk-GK2Z6B6W.js} +22 -34
- package/dist/{chunk-2HRHHZJD.js → chunk-SXUFCJBY.js} +2 -2
- package/dist/fetch.js +2 -2
- package/dist/hono.js +2 -2
- package/dist/index.js +501 -105
- package/dist/next.js +2 -2
- package/dist/node.js +2 -2
- package/dist/src/builder-with-errors-middlewares.d.ts +50 -0
- package/dist/src/builder-with-errors.d.ts +49 -0
- package/dist/src/builder-with-middlewares.d.ts +47 -0
- package/dist/src/builder.d.ts +28 -23
- package/dist/src/context.d.ts +11 -0
- package/dist/src/implementer-chainable.d.ts +5 -1
- package/dist/src/index.d.ts +2 -2
- package/dist/src/middleware-decorated.d.ts +2 -1
- package/dist/src/procedure-builder-with-input.d.ts +34 -0
- package/dist/src/procedure-builder-with-output.d.ts +33 -0
- package/dist/src/procedure-builder.d.ts +18 -15
- package/dist/src/procedure-decorated.d.ts +5 -6
- package/dist/src/procedure-implementer.d.ts +6 -4
- package/dist/src/procedure.d.ts +4 -3
- package/dist/src/router-builder.d.ts +4 -2
- package/dist/src/router-implementer.d.ts +2 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
@@ -11,14 +11,22 @@ import {
|
|
11
11
|
mergeContext,
|
12
12
|
middlewareOutputFn,
|
13
13
|
unlazy
|
14
|
-
} from "./chunk-
|
14
|
+
} from "./chunk-GK2Z6B6W.js";
|
15
15
|
|
16
16
|
// src/builder.ts
|
17
|
+
import { ContractProcedure as ContractProcedure4 } from "@orpc/contract";
|
18
|
+
|
19
|
+
// src/builder-with-errors.ts
|
20
|
+
import { ContractProcedure as ContractProcedure2 } from "@orpc/contract";
|
21
|
+
|
22
|
+
// src/builder-with-errors-middlewares.ts
|
17
23
|
import { ContractProcedure } from "@orpc/contract";
|
18
24
|
|
19
|
-
// src/
|
20
|
-
import {
|
21
|
-
|
25
|
+
// src/procedure-builder.ts
|
26
|
+
import { ContractProcedureBuilder, DecoratedContractProcedure as DecoratedContractProcedure4 } from "@orpc/contract";
|
27
|
+
|
28
|
+
// src/procedure-builder-with-input.ts
|
29
|
+
import { ContractProcedureBuilderWithInput, DecoratedContractProcedure as DecoratedContractProcedure2 } from "@orpc/contract";
|
22
30
|
|
23
31
|
// src/middleware-decorated.ts
|
24
32
|
function decorateMiddleware(middleware) {
|
@@ -45,7 +53,6 @@ function decorateMiddleware(middleware) {
|
|
45
53
|
|
46
54
|
// src/procedure-decorated.ts
|
47
55
|
import { DecoratedContractProcedure } from "@orpc/contract";
|
48
|
-
import { createCallableObject } from "@orpc/shared";
|
49
56
|
var DecoratedProcedure = class _DecoratedProcedure extends Procedure {
|
50
57
|
static decorate(procedure) {
|
51
58
|
if (procedure instanceof _DecoratedProcedure) {
|
@@ -75,7 +82,7 @@ var DecoratedProcedure = class _DecoratedProcedure extends Procedure {
|
|
75
82
|
const middleware_ = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
76
83
|
return new _DecoratedProcedure({
|
77
84
|
...this["~orpc"],
|
78
|
-
|
85
|
+
middlewares: [...this["~orpc"].middlewares, middleware_]
|
79
86
|
});
|
80
87
|
}
|
81
88
|
unshiftTag(...tags) {
|
@@ -86,32 +93,36 @@ var DecoratedProcedure = class _DecoratedProcedure extends Procedure {
|
|
86
93
|
}
|
87
94
|
unshiftMiddleware(...middlewares) {
|
88
95
|
const castedMiddlewares = middlewares;
|
89
|
-
if (this["~orpc"].
|
96
|
+
if (this["~orpc"].middlewares.length) {
|
90
97
|
let min = 0;
|
91
|
-
for (let i = 0; i < this["~orpc"].
|
92
|
-
const index = castedMiddlewares.indexOf(this["~orpc"].
|
98
|
+
for (let i = 0; i < this["~orpc"].middlewares.length; i++) {
|
99
|
+
const index = castedMiddlewares.indexOf(this["~orpc"].middlewares[i], min);
|
93
100
|
if (index === -1) {
|
94
|
-
castedMiddlewares.push(...this["~orpc"].
|
101
|
+
castedMiddlewares.push(...this["~orpc"].middlewares.slice(i));
|
95
102
|
break;
|
96
103
|
}
|
97
104
|
min = index + 1;
|
98
105
|
}
|
99
106
|
}
|
107
|
+
const numNewMiddlewares = castedMiddlewares.length - this["~orpc"].middlewares.length;
|
100
108
|
return new _DecoratedProcedure({
|
101
109
|
...this["~orpc"],
|
102
|
-
|
110
|
+
inputValidationIndex: this["~orpc"].inputValidationIndex + numNewMiddlewares,
|
111
|
+
outputValidationIndex: this["~orpc"].outputValidationIndex + numNewMiddlewares,
|
112
|
+
middlewares: castedMiddlewares
|
103
113
|
});
|
104
114
|
}
|
105
115
|
/**
|
106
116
|
* 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
117
|
*/
|
109
118
|
callable(...rest) {
|
110
|
-
return
|
119
|
+
return Object.assign(createProcedureClient(this, ...rest), {
|
120
|
+
"~type": "Procedure",
|
121
|
+
"~orpc": this["~orpc"]
|
122
|
+
});
|
111
123
|
}
|
112
124
|
/**
|
113
125
|
* 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
126
|
*/
|
116
127
|
actionable(...rest) {
|
117
128
|
return this.callable(...rest);
|
@@ -129,14 +140,141 @@ var ProcedureImplementer = class _ProcedureImplementer {
|
|
129
140
|
const mappedMiddleware = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
130
141
|
return new _ProcedureImplementer({
|
131
142
|
...this["~orpc"],
|
132
|
-
|
143
|
+
middlewares: [...this["~orpc"].middlewares, mappedMiddleware]
|
144
|
+
});
|
145
|
+
}
|
146
|
+
handler(handler) {
|
147
|
+
return new DecoratedProcedure({
|
148
|
+
...this["~orpc"],
|
149
|
+
handler
|
150
|
+
});
|
151
|
+
}
|
152
|
+
};
|
153
|
+
|
154
|
+
// src/procedure-builder-with-input.ts
|
155
|
+
var ProcedureBuilderWithInput = class _ProcedureBuilderWithInput {
|
156
|
+
"~type" = "ProcedureBuilderWithInput";
|
157
|
+
"~orpc";
|
158
|
+
constructor(def) {
|
159
|
+
this["~orpc"] = def;
|
160
|
+
}
|
161
|
+
errors(errors) {
|
162
|
+
return new _ProcedureBuilderWithInput({
|
163
|
+
...this["~orpc"],
|
164
|
+
contract: DecoratedContractProcedure2.decorate(this["~orpc"].contract).errors(errors)
|
165
|
+
});
|
166
|
+
}
|
167
|
+
route(route) {
|
168
|
+
return new _ProcedureBuilderWithInput({
|
169
|
+
...this["~orpc"],
|
170
|
+
contract: DecoratedContractProcedure2.decorate(this["~orpc"].contract).route(route)
|
171
|
+
});
|
172
|
+
}
|
173
|
+
use(middleware, mapInput) {
|
174
|
+
const maybeWithMapInput = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
175
|
+
return new _ProcedureBuilderWithInput({
|
176
|
+
...this["~orpc"],
|
177
|
+
outputValidationIndex: this["~orpc"].outputValidationIndex + 1,
|
178
|
+
middlewares: [...this["~orpc"].middlewares, maybeWithMapInput]
|
179
|
+
});
|
180
|
+
}
|
181
|
+
output(schema, example) {
|
182
|
+
return new ProcedureImplementer({
|
183
|
+
...this["~orpc"],
|
184
|
+
contract: new ContractProcedureBuilderWithInput(this["~orpc"].contract["~orpc"]).output(schema, example)
|
185
|
+
});
|
186
|
+
}
|
187
|
+
handler(handler) {
|
188
|
+
return new DecoratedProcedure({
|
189
|
+
...this["~orpc"],
|
190
|
+
handler
|
191
|
+
});
|
192
|
+
}
|
193
|
+
};
|
194
|
+
|
195
|
+
// src/procedure-builder-with-output.ts
|
196
|
+
import { ContractProcedureBuilderWithOutput, DecoratedContractProcedure as DecoratedContractProcedure3 } from "@orpc/contract";
|
197
|
+
var ProcedureBuilderWithOutput = class _ProcedureBuilderWithOutput {
|
198
|
+
"~type" = "ProcedureBuilderWithOutput";
|
199
|
+
"~orpc";
|
200
|
+
constructor(def) {
|
201
|
+
this["~orpc"] = def;
|
202
|
+
}
|
203
|
+
errors(errors) {
|
204
|
+
return new _ProcedureBuilderWithOutput({
|
205
|
+
...this["~orpc"],
|
206
|
+
contract: DecoratedContractProcedure3.decorate(this["~orpc"].contract).errors(errors)
|
207
|
+
});
|
208
|
+
}
|
209
|
+
route(route) {
|
210
|
+
return new _ProcedureBuilderWithOutput({
|
211
|
+
...this["~orpc"],
|
212
|
+
contract: DecoratedContractProcedure3.decorate(this["~orpc"].contract).route(route)
|
213
|
+
});
|
214
|
+
}
|
215
|
+
use(middleware) {
|
216
|
+
return new _ProcedureBuilderWithOutput({
|
217
|
+
...this["~orpc"],
|
218
|
+
inputValidationIndex: this["~orpc"].inputValidationIndex + 1,
|
219
|
+
middlewares: [...this["~orpc"].middlewares, middleware]
|
220
|
+
});
|
221
|
+
}
|
222
|
+
input(schema, example) {
|
223
|
+
return new ProcedureImplementer({
|
224
|
+
...this["~orpc"],
|
225
|
+
contract: new ContractProcedureBuilderWithOutput(this["~orpc"].contract["~orpc"]).input(schema, example)
|
226
|
+
});
|
227
|
+
}
|
228
|
+
handler(handler) {
|
229
|
+
return new DecoratedProcedure({
|
230
|
+
...this["~orpc"],
|
231
|
+
handler
|
232
|
+
});
|
233
|
+
}
|
234
|
+
};
|
235
|
+
|
236
|
+
// src/procedure-builder.ts
|
237
|
+
var ProcedureBuilder = class _ProcedureBuilder {
|
238
|
+
"~type" = "ProcedureBuilder";
|
239
|
+
"~orpc";
|
240
|
+
constructor(def) {
|
241
|
+
this["~orpc"] = def;
|
242
|
+
}
|
243
|
+
errors(errors) {
|
244
|
+
return new _ProcedureBuilder({
|
245
|
+
...this["~orpc"],
|
246
|
+
contract: DecoratedContractProcedure4.decorate(this["~orpc"].contract).errors(errors)
|
247
|
+
});
|
248
|
+
}
|
249
|
+
route(route) {
|
250
|
+
return new _ProcedureBuilder({
|
251
|
+
...this["~orpc"],
|
252
|
+
contract: DecoratedContractProcedure4.decorate(this["~orpc"].contract).route(route)
|
253
|
+
});
|
254
|
+
}
|
255
|
+
use(middleware) {
|
256
|
+
return new _ProcedureBuilder({
|
257
|
+
...this["~orpc"],
|
258
|
+
inputValidationIndex: this["~orpc"].inputValidationIndex + 1,
|
259
|
+
outputValidationIndex: this["~orpc"].outputValidationIndex + 1,
|
260
|
+
middlewares: [...this["~orpc"].middlewares, middleware]
|
261
|
+
});
|
262
|
+
}
|
263
|
+
input(schema, example) {
|
264
|
+
return new ProcedureBuilderWithInput({
|
265
|
+
...this["~orpc"],
|
266
|
+
contract: new ContractProcedureBuilder(this["~orpc"].contract["~orpc"]).input(schema, example)
|
267
|
+
});
|
268
|
+
}
|
269
|
+
output(schema, example) {
|
270
|
+
return new ProcedureBuilderWithOutput({
|
271
|
+
...this["~orpc"],
|
272
|
+
contract: new ContractProcedureBuilder(this["~orpc"].contract["~orpc"]).output(schema, example)
|
133
273
|
});
|
134
274
|
}
|
135
275
|
handler(handler) {
|
136
276
|
return new DecoratedProcedure({
|
137
|
-
|
138
|
-
preMiddlewares: this["~orpc"].preMiddlewares,
|
139
|
-
contract: this["~orpc"].contract,
|
277
|
+
...this["~orpc"],
|
140
278
|
handler
|
141
279
|
});
|
142
280
|
}
|
@@ -277,6 +415,213 @@ function adapt(item, options) {
|
|
277
415
|
return adapted;
|
278
416
|
}
|
279
417
|
|
418
|
+
// src/builder-with-errors-middlewares.ts
|
419
|
+
var BuilderWithErrorsMiddlewares = class _BuilderWithErrorsMiddlewares {
|
420
|
+
"~type" = "BuilderWithErrorsMiddlewares";
|
421
|
+
"~orpc";
|
422
|
+
constructor(def) {
|
423
|
+
this["~orpc"] = def;
|
424
|
+
}
|
425
|
+
errors(errors) {
|
426
|
+
return new _BuilderWithErrorsMiddlewares({
|
427
|
+
...this["~orpc"],
|
428
|
+
errorMap: {
|
429
|
+
...this["~orpc"].errorMap,
|
430
|
+
...errors
|
431
|
+
}
|
432
|
+
});
|
433
|
+
}
|
434
|
+
use(middleware) {
|
435
|
+
return new _BuilderWithErrorsMiddlewares({
|
436
|
+
...this["~orpc"],
|
437
|
+
inputValidationIndex: this["~orpc"].inputValidationIndex + 1,
|
438
|
+
outputValidationIndex: this["~orpc"].outputValidationIndex + 1,
|
439
|
+
middlewares: [...this["~orpc"].middlewares, middleware]
|
440
|
+
// FIXME: I believe we can remove `as any` here
|
441
|
+
});
|
442
|
+
}
|
443
|
+
route(route) {
|
444
|
+
return new ProcedureBuilder({
|
445
|
+
...this["~orpc"],
|
446
|
+
contract: new ContractProcedure({
|
447
|
+
route,
|
448
|
+
InputSchema: void 0,
|
449
|
+
OutputSchema: void 0,
|
450
|
+
errorMap: this["~orpc"].errorMap
|
451
|
+
})
|
452
|
+
});
|
453
|
+
}
|
454
|
+
input(schema, example) {
|
455
|
+
return new ProcedureBuilderWithInput({
|
456
|
+
...this["~orpc"],
|
457
|
+
contract: new ContractProcedure({
|
458
|
+
OutputSchema: void 0,
|
459
|
+
InputSchema: schema,
|
460
|
+
inputExample: example,
|
461
|
+
errorMap: this["~orpc"].errorMap
|
462
|
+
})
|
463
|
+
});
|
464
|
+
}
|
465
|
+
output(schema, example) {
|
466
|
+
return new ProcedureBuilderWithOutput({
|
467
|
+
...this["~orpc"],
|
468
|
+
contract: new ContractProcedure({
|
469
|
+
InputSchema: void 0,
|
470
|
+
OutputSchema: schema,
|
471
|
+
outputExample: example,
|
472
|
+
errorMap: this["~orpc"].errorMap
|
473
|
+
})
|
474
|
+
});
|
475
|
+
}
|
476
|
+
handler(handler) {
|
477
|
+
return new DecoratedProcedure({
|
478
|
+
...this["~orpc"],
|
479
|
+
contract: new ContractProcedure({
|
480
|
+
InputSchema: void 0,
|
481
|
+
OutputSchema: void 0,
|
482
|
+
errorMap: this["~orpc"].errorMap
|
483
|
+
}),
|
484
|
+
handler
|
485
|
+
});
|
486
|
+
}
|
487
|
+
prefix(prefix) {
|
488
|
+
return new RouterBuilder({
|
489
|
+
...this["~orpc"],
|
490
|
+
prefix
|
491
|
+
});
|
492
|
+
}
|
493
|
+
tag(...tags) {
|
494
|
+
return new RouterBuilder({
|
495
|
+
...this["~orpc"],
|
496
|
+
tags
|
497
|
+
});
|
498
|
+
}
|
499
|
+
router(router) {
|
500
|
+
return new RouterBuilder(this["~orpc"]).router(router);
|
501
|
+
}
|
502
|
+
lazy(loader) {
|
503
|
+
return new RouterBuilder(this["~orpc"]).lazy(loader);
|
504
|
+
}
|
505
|
+
};
|
506
|
+
|
507
|
+
// src/builder-with-errors.ts
|
508
|
+
var BuilderWithErrors = class _BuilderWithErrors {
|
509
|
+
"~type" = "BuilderWithErrors";
|
510
|
+
"~orpc";
|
511
|
+
constructor(def) {
|
512
|
+
this["~orpc"] = def;
|
513
|
+
}
|
514
|
+
context() {
|
515
|
+
return this;
|
516
|
+
}
|
517
|
+
errors(errors) {
|
518
|
+
return new _BuilderWithErrors({
|
519
|
+
...this["~orpc"],
|
520
|
+
errorMap: {
|
521
|
+
...this["~orpc"].errorMap,
|
522
|
+
...errors
|
523
|
+
}
|
524
|
+
});
|
525
|
+
}
|
526
|
+
middleware(middleware) {
|
527
|
+
return decorateMiddleware(middleware);
|
528
|
+
}
|
529
|
+
use(middleware) {
|
530
|
+
return new BuilderWithErrorsMiddlewares({
|
531
|
+
...this["~orpc"],
|
532
|
+
inputValidationIndex: 1,
|
533
|
+
outputValidationIndex: 1,
|
534
|
+
middlewares: [middleware]
|
535
|
+
// FIXME: I believe we can remove `as any` here
|
536
|
+
});
|
537
|
+
}
|
538
|
+
route(route) {
|
539
|
+
return new ProcedureBuilder({
|
540
|
+
middlewares: [],
|
541
|
+
inputValidationIndex: 0,
|
542
|
+
outputValidationIndex: 0,
|
543
|
+
contract: new ContractProcedure2({
|
544
|
+
route,
|
545
|
+
InputSchema: void 0,
|
546
|
+
OutputSchema: void 0,
|
547
|
+
errorMap: this["~orpc"].errorMap
|
548
|
+
})
|
549
|
+
});
|
550
|
+
}
|
551
|
+
input(schema, example) {
|
552
|
+
return new ProcedureBuilderWithInput({
|
553
|
+
middlewares: [],
|
554
|
+
inputValidationIndex: 0,
|
555
|
+
outputValidationIndex: 0,
|
556
|
+
contract: new ContractProcedure2({
|
557
|
+
OutputSchema: void 0,
|
558
|
+
InputSchema: schema,
|
559
|
+
inputExample: example,
|
560
|
+
errorMap: this["~orpc"].errorMap
|
561
|
+
})
|
562
|
+
});
|
563
|
+
}
|
564
|
+
output(schema, example) {
|
565
|
+
return new ProcedureBuilderWithOutput({
|
566
|
+
middlewares: [],
|
567
|
+
inputValidationIndex: 0,
|
568
|
+
outputValidationIndex: 0,
|
569
|
+
contract: new ContractProcedure2({
|
570
|
+
InputSchema: void 0,
|
571
|
+
OutputSchema: schema,
|
572
|
+
outputExample: example,
|
573
|
+
errorMap: this["~orpc"].errorMap
|
574
|
+
})
|
575
|
+
});
|
576
|
+
}
|
577
|
+
handler(handler) {
|
578
|
+
return new DecoratedProcedure({
|
579
|
+
middlewares: [],
|
580
|
+
inputValidationIndex: 0,
|
581
|
+
outputValidationIndex: 0,
|
582
|
+
contract: new ContractProcedure2({
|
583
|
+
InputSchema: void 0,
|
584
|
+
OutputSchema: void 0,
|
585
|
+
errorMap: this["~orpc"].errorMap
|
586
|
+
}),
|
587
|
+
handler
|
588
|
+
});
|
589
|
+
}
|
590
|
+
prefix(prefix) {
|
591
|
+
return new RouterBuilder({
|
592
|
+
middlewares: [],
|
593
|
+
errorMap: this["~orpc"].errorMap,
|
594
|
+
prefix
|
595
|
+
});
|
596
|
+
}
|
597
|
+
tag(...tags) {
|
598
|
+
return new RouterBuilder({
|
599
|
+
middlewares: [],
|
600
|
+
errorMap: this["~orpc"].errorMap,
|
601
|
+
tags
|
602
|
+
});
|
603
|
+
}
|
604
|
+
router(router) {
|
605
|
+
return new RouterBuilder({
|
606
|
+
middlewares: [],
|
607
|
+
...this["~orpc"]
|
608
|
+
}).router(router);
|
609
|
+
}
|
610
|
+
lazy(loader) {
|
611
|
+
return new RouterBuilder({
|
612
|
+
middlewares: [],
|
613
|
+
...this["~orpc"]
|
614
|
+
}).lazy(loader);
|
615
|
+
}
|
616
|
+
};
|
617
|
+
|
618
|
+
// src/builder-with-middlewares.ts
|
619
|
+
import { ContractProcedure as ContractProcedure3 } from "@orpc/contract";
|
620
|
+
|
621
|
+
// src/implementer-chainable.ts
|
622
|
+
import { isContractProcedure } from "@orpc/contract";
|
623
|
+
import { createCallableObject } from "@orpc/shared";
|
624
|
+
|
280
625
|
// src/router-implementer.ts
|
281
626
|
var RouterImplementer = class _RouterImplementer {
|
282
627
|
"~type" = "RouterImplementer";
|
@@ -309,20 +654,24 @@ var RouterImplementer = class _RouterImplementer {
|
|
309
654
|
};
|
310
655
|
|
311
656
|
// src/implementer-chainable.ts
|
312
|
-
function createChainableImplementer(contract,
|
657
|
+
function createChainableImplementer(contract, options) {
|
313
658
|
if (isContractProcedure(contract)) {
|
314
659
|
const implementer = new ProcedureImplementer({
|
315
660
|
contract,
|
316
|
-
|
317
|
-
|
661
|
+
middlewares: options.middlewares,
|
662
|
+
inputValidationIndex: options.inputValidationIndex,
|
663
|
+
outputValidationIndex: options.outputValidationIndex
|
318
664
|
});
|
319
665
|
return implementer;
|
320
666
|
}
|
321
667
|
const chainable = {};
|
322
668
|
for (const key in contract) {
|
323
|
-
chainable[key] = createChainableImplementer(contract[key],
|
669
|
+
chainable[key] = createChainableImplementer(contract[key], options);
|
324
670
|
}
|
325
|
-
const routerImplementer = new RouterImplementer({
|
671
|
+
const routerImplementer = new RouterImplementer({
|
672
|
+
contract,
|
673
|
+
middlewares: options.middlewares
|
674
|
+
});
|
326
675
|
const merged = new Proxy(chainable, {
|
327
676
|
get(target, key) {
|
328
677
|
const next = Reflect.get(target, key);
|
@@ -333,170 +682,219 @@ function createChainableImplementer(contract, middlewares = []) {
|
|
333
682
|
if (!next) {
|
334
683
|
return method.bind(routerImplementer);
|
335
684
|
}
|
336
|
-
return
|
685
|
+
return createCallableObject(next, method.bind(routerImplementer));
|
337
686
|
}
|
338
687
|
});
|
339
688
|
return merged;
|
340
689
|
}
|
341
690
|
|
342
|
-
// src/
|
343
|
-
|
344
|
-
|
345
|
-
} from "@orpc/contract";
|
346
|
-
var ProcedureBuilder = class _ProcedureBuilder {
|
347
|
-
"~type" = "ProcedureBuilder";
|
691
|
+
// src/builder-with-middlewares.ts
|
692
|
+
var BuilderWithMiddlewares = class _BuilderWithMiddlewares {
|
693
|
+
"~type" = "BuilderHasMiddlewares";
|
348
694
|
"~orpc";
|
349
695
|
constructor(def) {
|
350
696
|
this["~orpc"] = def;
|
351
697
|
}
|
352
|
-
|
353
|
-
return new
|
698
|
+
use(middleware) {
|
699
|
+
return new _BuilderWithMiddlewares({
|
354
700
|
...this["~orpc"],
|
355
|
-
|
701
|
+
inputValidationIndex: this["~orpc"].inputValidationIndex + 1,
|
702
|
+
outputValidationIndex: this["~orpc"].outputValidationIndex + 1,
|
703
|
+
middlewares: [...this["~orpc"].middlewares, middleware]
|
356
704
|
});
|
357
705
|
}
|
358
|
-
|
359
|
-
return new
|
706
|
+
errors(errors) {
|
707
|
+
return new BuilderWithErrorsMiddlewares({
|
360
708
|
...this["~orpc"],
|
361
|
-
|
709
|
+
errorMap: errors
|
362
710
|
});
|
363
711
|
}
|
364
|
-
|
365
|
-
return new
|
712
|
+
route(route) {
|
713
|
+
return new ProcedureBuilder({
|
366
714
|
...this["~orpc"],
|
367
|
-
contract:
|
715
|
+
contract: new ContractProcedure3({
|
716
|
+
route,
|
717
|
+
InputSchema: void 0,
|
718
|
+
OutputSchema: void 0,
|
719
|
+
errorMap: {}
|
720
|
+
})
|
368
721
|
});
|
369
722
|
}
|
370
|
-
|
371
|
-
return new
|
723
|
+
input(schema, example) {
|
724
|
+
return new ProcedureBuilderWithInput({
|
372
725
|
...this["~orpc"],
|
373
|
-
contract:
|
726
|
+
contract: new ContractProcedure3({
|
727
|
+
OutputSchema: void 0,
|
728
|
+
InputSchema: schema,
|
729
|
+
inputExample: example,
|
730
|
+
errorMap: {}
|
731
|
+
})
|
374
732
|
});
|
375
733
|
}
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
preMiddlewares: this["~orpc"].middlewares,
|
387
|
-
postMiddlewares: []
|
388
|
-
}).use(middleware, mapInput);
|
734
|
+
output(schema, example) {
|
735
|
+
return new ProcedureBuilderWithOutput({
|
736
|
+
...this["~orpc"],
|
737
|
+
contract: new ContractProcedure3({
|
738
|
+
InputSchema: void 0,
|
739
|
+
OutputSchema: schema,
|
740
|
+
outputExample: example,
|
741
|
+
errorMap: {}
|
742
|
+
})
|
743
|
+
});
|
389
744
|
}
|
390
745
|
handler(handler) {
|
391
746
|
return new DecoratedProcedure({
|
392
|
-
|
393
|
-
|
394
|
-
|
747
|
+
...this["~orpc"],
|
748
|
+
contract: new ContractProcedure3({
|
749
|
+
InputSchema: void 0,
|
750
|
+
OutputSchema: void 0,
|
751
|
+
errorMap: {}
|
752
|
+
}),
|
395
753
|
handler
|
396
754
|
});
|
397
755
|
}
|
756
|
+
prefix(prefix) {
|
757
|
+
return new RouterBuilder({
|
758
|
+
middlewares: this["~orpc"].middlewares,
|
759
|
+
errorMap: {},
|
760
|
+
prefix
|
761
|
+
});
|
762
|
+
}
|
763
|
+
tag(...tags) {
|
764
|
+
return new RouterBuilder({
|
765
|
+
middlewares: this["~orpc"].middlewares,
|
766
|
+
errorMap: {},
|
767
|
+
tags
|
768
|
+
});
|
769
|
+
}
|
770
|
+
router(router) {
|
771
|
+
return new RouterBuilder({
|
772
|
+
errorMap: {},
|
773
|
+
...this["~orpc"]
|
774
|
+
}).router(router);
|
775
|
+
}
|
776
|
+
lazy(loader) {
|
777
|
+
return new RouterBuilder({
|
778
|
+
errorMap: {},
|
779
|
+
...this["~orpc"]
|
780
|
+
}).lazy(loader);
|
781
|
+
}
|
782
|
+
contract(contract) {
|
783
|
+
return createChainableImplementer(contract, this["~orpc"]);
|
784
|
+
}
|
398
785
|
};
|
399
786
|
|
400
787
|
// src/builder.ts
|
401
|
-
var Builder = class
|
788
|
+
var Builder = class {
|
402
789
|
"~type" = "Builder";
|
403
790
|
"~orpc";
|
404
791
|
constructor(def) {
|
405
792
|
this["~orpc"] = def;
|
406
793
|
}
|
407
|
-
// TODO: separate it
|
408
794
|
context() {
|
409
|
-
return
|
410
|
-
middlewares: [],
|
411
|
-
errorMap: {}
|
412
|
-
});
|
795
|
+
return this;
|
413
796
|
}
|
414
|
-
|
415
|
-
return
|
416
|
-
...this["~orpc"],
|
417
|
-
middlewares: [...this["~orpc"].middlewares, middleware]
|
418
|
-
});
|
797
|
+
middleware(middleware) {
|
798
|
+
return decorateMiddleware(middleware);
|
419
799
|
}
|
420
800
|
errors(errors) {
|
421
|
-
return new
|
422
|
-
|
423
|
-
errorMap: {
|
424
|
-
...this["~orpc"].errorMap,
|
425
|
-
...errors
|
426
|
-
}
|
801
|
+
return new BuilderWithErrors({
|
802
|
+
errorMap: errors
|
427
803
|
});
|
428
804
|
}
|
429
|
-
|
430
|
-
|
431
|
-
|
805
|
+
use(middleware) {
|
806
|
+
return new BuilderWithMiddlewares({
|
807
|
+
...this["~orpc"],
|
808
|
+
inputValidationIndex: 1,
|
809
|
+
outputValidationIndex: 1,
|
810
|
+
middlewares: [middleware]
|
811
|
+
// FIXME: I believe we can remove `as any` here
|
812
|
+
});
|
432
813
|
}
|
433
814
|
route(route) {
|
434
815
|
return new ProcedureBuilder({
|
435
|
-
middlewares:
|
436
|
-
|
816
|
+
middlewares: [],
|
817
|
+
inputValidationIndex: 0,
|
818
|
+
outputValidationIndex: 0,
|
819
|
+
contract: new ContractProcedure4({
|
437
820
|
route,
|
438
821
|
InputSchema: void 0,
|
439
822
|
OutputSchema: void 0,
|
440
|
-
errorMap:
|
823
|
+
errorMap: {}
|
441
824
|
})
|
442
825
|
});
|
443
826
|
}
|
444
827
|
input(schema, example) {
|
445
|
-
return new
|
446
|
-
middlewares:
|
447
|
-
|
828
|
+
return new ProcedureBuilderWithInput({
|
829
|
+
middlewares: [],
|
830
|
+
inputValidationIndex: 0,
|
831
|
+
outputValidationIndex: 0,
|
832
|
+
contract: new ContractProcedure4({
|
448
833
|
OutputSchema: void 0,
|
449
834
|
InputSchema: schema,
|
450
835
|
inputExample: example,
|
451
|
-
errorMap:
|
836
|
+
errorMap: {}
|
452
837
|
})
|
453
838
|
});
|
454
839
|
}
|
455
840
|
output(schema, example) {
|
456
|
-
return new
|
457
|
-
middlewares:
|
458
|
-
|
841
|
+
return new ProcedureBuilderWithOutput({
|
842
|
+
middlewares: [],
|
843
|
+
inputValidationIndex: 0,
|
844
|
+
outputValidationIndex: 0,
|
845
|
+
contract: new ContractProcedure4({
|
459
846
|
InputSchema: void 0,
|
460
847
|
OutputSchema: schema,
|
461
848
|
outputExample: example,
|
462
|
-
errorMap:
|
849
|
+
errorMap: {}
|
463
850
|
})
|
464
851
|
});
|
465
852
|
}
|
466
853
|
handler(handler) {
|
467
854
|
return new DecoratedProcedure({
|
468
|
-
|
469
|
-
|
470
|
-
|
855
|
+
middlewares: [],
|
856
|
+
inputValidationIndex: 0,
|
857
|
+
outputValidationIndex: 0,
|
858
|
+
contract: new ContractProcedure4({
|
471
859
|
InputSchema: void 0,
|
472
860
|
OutputSchema: void 0,
|
473
|
-
errorMap:
|
861
|
+
errorMap: {}
|
474
862
|
}),
|
475
863
|
handler
|
476
864
|
});
|
477
865
|
}
|
478
866
|
prefix(prefix) {
|
479
867
|
return new RouterBuilder({
|
480
|
-
middlewares:
|
481
|
-
errorMap:
|
868
|
+
middlewares: [],
|
869
|
+
errorMap: {},
|
482
870
|
prefix
|
483
871
|
});
|
484
872
|
}
|
485
873
|
tag(...tags) {
|
486
874
|
return new RouterBuilder({
|
487
|
-
middlewares:
|
488
|
-
errorMap:
|
875
|
+
middlewares: [],
|
876
|
+
errorMap: {},
|
489
877
|
tags
|
490
878
|
});
|
491
879
|
}
|
492
880
|
router(router) {
|
493
|
-
return new RouterBuilder(
|
881
|
+
return new RouterBuilder({
|
882
|
+
middlewares: [],
|
883
|
+
errorMap: []
|
884
|
+
}).router(router);
|
494
885
|
}
|
495
886
|
lazy(loader) {
|
496
|
-
return new RouterBuilder(
|
887
|
+
return new RouterBuilder({
|
888
|
+
middlewares: [],
|
889
|
+
errorMap: {}
|
890
|
+
}).lazy(loader);
|
497
891
|
}
|
498
892
|
contract(contract) {
|
499
|
-
return createChainableImplementer(contract,
|
893
|
+
return createChainableImplementer(contract, {
|
894
|
+
middlewares: [],
|
895
|
+
inputValidationIndex: 0,
|
896
|
+
outputValidationIndex: 0
|
897
|
+
});
|
500
898
|
}
|
501
899
|
};
|
502
900
|
|
@@ -548,11 +946,8 @@ function createRouterClient(router, ...rest) {
|
|
548
946
|
}
|
549
947
|
|
550
948
|
// src/index.ts
|
551
|
-
import { configGlobal, fallbackToGlobalConfig, isDefinedError, ORPCError, safe } from "@orpc/contract";
|
552
|
-
var os = new Builder({
|
553
|
-
middlewares: [],
|
554
|
-
errorMap: {}
|
555
|
-
});
|
949
|
+
import { configGlobal, fallbackToGlobalConfig, isDefinedError, ORPCError, safe, type } from "@orpc/contract";
|
950
|
+
var os = new Builder({});
|
556
951
|
export {
|
557
952
|
Builder,
|
558
953
|
DecoratedProcedure,
|
@@ -586,6 +981,7 @@ export {
|
|
586
981
|
os,
|
587
982
|
safe,
|
588
983
|
setRouterContract,
|
984
|
+
type,
|
589
985
|
unlazy
|
590
986
|
};
|
591
987
|
//# sourceMappingURL=index.js.map
|