@orpc/server 0.27.0 → 0.28.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-E7GUWVR4.js → chunk-DNG2IB3R.js} +56 -15
- package/dist/{chunk-3BAPJGK6.js → chunk-V3I7RIRY.js} +4 -4
- package/dist/fetch.js +2 -2
- package/dist/hono.js +2 -2
- package/dist/index.js +31 -7
- package/dist/next.js +2 -2
- package/dist/node.js +2 -2
- package/dist/src/adapters/fetch/orpc-payload-codec.d.ts +1 -1
- package/dist/src/builder.d.ts +9 -8
- package/dist/src/error.d.ts +10 -0
- package/dist/src/implementer-chainable.d.ts +2 -2
- package/dist/src/index.d.ts +2 -2
- package/dist/src/lazy-decorated.d.ts +2 -2
- package/dist/src/middleware-decorated.d.ts +6 -5
- package/dist/src/middleware.d.ts +7 -5
- package/dist/src/procedure-builder.d.ts +15 -13
- package/dist/src/procedure-client.d.ts +9 -9
- package/dist/src/procedure-decorated.d.ts +10 -9
- package/dist/src/procedure-implementer.d.ts +11 -10
- package/dist/src/procedure.d.ts +27 -14
- package/dist/src/router-builder.d.ts +3 -3
- package/dist/src/router-client.d.ts +2 -2
- package/dist/src/router-implementer.d.ts +2 -2
- package/dist/src/router.d.ts +3 -3
- package/package.json +3 -3
@@ -32,6 +32,33 @@ function isProcedure(item) {
|
|
32
32
|
return (typeof item === "object" || typeof item === "function") && item !== null && "~type" in item && item["~type"] === "Procedure" && "~orpc" in item && typeof item["~orpc"] === "object" && item["~orpc"] !== null && "contract" in item["~orpc"] && isContractProcedure(item["~orpc"].contract) && "handler" in item["~orpc"] && typeof item["~orpc"].handler === "function";
|
33
33
|
}
|
34
34
|
|
35
|
+
// src/error.ts
|
36
|
+
import { ORPCError } from "@orpc/contract";
|
37
|
+
function createORPCErrorConstructorMap(errors) {
|
38
|
+
const constructors = {};
|
39
|
+
if (!errors) {
|
40
|
+
return constructors;
|
41
|
+
}
|
42
|
+
for (const code in errors) {
|
43
|
+
const config = errors[code];
|
44
|
+
if (!config) {
|
45
|
+
continue;
|
46
|
+
}
|
47
|
+
const constructor = (...[options]) => {
|
48
|
+
return new ORPCError({
|
49
|
+
code,
|
50
|
+
defined: true,
|
51
|
+
status: config.status,
|
52
|
+
message: options?.message ?? config.message,
|
53
|
+
data: options?.data,
|
54
|
+
cause: options?.cause
|
55
|
+
});
|
56
|
+
};
|
57
|
+
constructors[code] = constructor;
|
58
|
+
}
|
59
|
+
return constructors;
|
60
|
+
}
|
61
|
+
|
35
62
|
// src/lazy.ts
|
36
63
|
var LAZY_LOADER_SYMBOL = Symbol("ORPC_LAZY_LOADER");
|
37
64
|
function lazy(loader) {
|
@@ -60,8 +87,8 @@ function flatLazy(lazied) {
|
|
60
87
|
}
|
61
88
|
|
62
89
|
// src/procedure-client.ts
|
63
|
-
import {
|
64
|
-
import {
|
90
|
+
import { ORPCError as ORPCError2, validateORPCError, ValidationError } from "@orpc/contract";
|
91
|
+
import { executeWithHooks, toError, value } from "@orpc/shared";
|
65
92
|
function createProcedureClient(options) {
|
66
93
|
return async (...[input, callerOptions]) => {
|
67
94
|
const path = options.path ?? [];
|
@@ -79,17 +106,27 @@ function createProcedureClient(options) {
|
|
79
106
|
input: validInput,
|
80
107
|
path,
|
81
108
|
procedure,
|
82
|
-
signal: callerOptions?.signal
|
109
|
+
signal: callerOptions?.signal,
|
110
|
+
errors: createORPCErrorConstructorMap(procedure["~orpc"].contract["~orpc"].errorMap)
|
83
111
|
});
|
84
112
|
return validateOutput(procedure, output);
|
85
113
|
};
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
114
|
+
try {
|
115
|
+
const output = await executeWithHooks({
|
116
|
+
hooks: options,
|
117
|
+
input,
|
118
|
+
context,
|
119
|
+
meta,
|
120
|
+
execute: executeWithValidation
|
121
|
+
});
|
122
|
+
return output;
|
123
|
+
} catch (e) {
|
124
|
+
if (!(e instanceof ORPCError2)) {
|
125
|
+
throw toError(e);
|
126
|
+
}
|
127
|
+
const validated = await validateORPCError(procedure["~orpc"].contract["~orpc"].errorMap, e);
|
128
|
+
throw validated;
|
129
|
+
}
|
93
130
|
};
|
94
131
|
}
|
95
132
|
async function validateInput(procedure, input) {
|
@@ -98,10 +135,13 @@ async function validateInput(procedure, input) {
|
|
98
135
|
return input;
|
99
136
|
const result = await schema["~standard"].validate(input);
|
100
137
|
if (result.issues) {
|
101
|
-
throw new
|
138
|
+
throw new ORPCError2({
|
102
139
|
message: "Input validation failed",
|
103
140
|
code: "BAD_REQUEST",
|
104
|
-
|
141
|
+
data: {
|
142
|
+
issues: result.issues
|
143
|
+
},
|
144
|
+
cause: new ValidationError({ message: "Input validation failed", issues: result.issues })
|
105
145
|
});
|
106
146
|
}
|
107
147
|
return result.value;
|
@@ -112,10 +152,10 @@ async function validateOutput(procedure, output) {
|
|
112
152
|
return output;
|
113
153
|
const result = await schema["~standard"].validate(output);
|
114
154
|
if (result.issues) {
|
115
|
-
throw new
|
155
|
+
throw new ORPCError2({
|
116
156
|
message: "Output validation failed",
|
117
157
|
code: "INTERNAL_SERVER_ERROR",
|
118
|
-
issues: result.issues
|
158
|
+
cause: new ValidationError({ message: "Output validation failed", issues: result.issues })
|
119
159
|
});
|
120
160
|
}
|
121
161
|
return result.value;
|
@@ -175,6 +215,7 @@ export {
|
|
175
215
|
mergeContext,
|
176
216
|
Procedure,
|
177
217
|
isProcedure,
|
218
|
+
createORPCErrorConstructorMap,
|
178
219
|
LAZY_LOADER_SYMBOL,
|
179
220
|
lazy,
|
180
221
|
isLazy,
|
@@ -183,4 +224,4 @@ export {
|
|
183
224
|
createProcedureClient,
|
184
225
|
getRouterChild
|
185
226
|
};
|
186
|
-
//# sourceMappingURL=chunk-
|
227
|
+
//# sourceMappingURL=chunk-DNG2IB3R.js.map
|
@@ -4,7 +4,7 @@ import {
|
|
4
4
|
getRouterChild,
|
5
5
|
isProcedure,
|
6
6
|
unlazy
|
7
|
-
} from "./chunk-
|
7
|
+
} from "./chunk-DNG2IB3R.js";
|
8
8
|
|
9
9
|
// src/adapters/fetch/super-json.ts
|
10
10
|
var super_json_exports = {};
|
@@ -130,8 +130,8 @@ function deserialize({
|
|
130
130
|
}
|
131
131
|
|
132
132
|
// src/adapters/fetch/orpc-payload-codec.ts
|
133
|
+
import { ORPCError } from "@orpc/contract";
|
133
134
|
import { findDeepMatches, set } from "@orpc/shared";
|
134
|
-
import { ORPCError } from "@orpc/shared/error";
|
135
135
|
var ORPCPayloadCodec = class {
|
136
136
|
/**
|
137
137
|
* If method is GET, the payload will be encoded as query string.
|
@@ -236,8 +236,8 @@ var ORPCProcedureMatcher = class {
|
|
236
236
|
};
|
237
237
|
|
238
238
|
// src/adapters/fetch/orpc-handler.ts
|
239
|
+
import { ORPCError as ORPCError2 } from "@orpc/contract";
|
239
240
|
import { executeWithHooks, trim as trim2 } from "@orpc/shared";
|
240
|
-
import { ORPCError as ORPCError2 } from "@orpc/shared/error";
|
241
241
|
var ORPCHandler = class {
|
242
242
|
constructor(router, options) {
|
243
243
|
this.options = options;
|
@@ -299,4 +299,4 @@ export {
|
|
299
299
|
ORPCProcedureMatcher,
|
300
300
|
ORPCHandler
|
301
301
|
};
|
302
|
-
//# sourceMappingURL=chunk-
|
302
|
+
//# sourceMappingURL=chunk-V3I7RIRY.js.map
|
package/dist/fetch.js
CHANGED
package/dist/hono.js
CHANGED
@@ -4,8 +4,8 @@ import {
|
|
4
4
|
ORPCPayloadCodec,
|
5
5
|
ORPCProcedureMatcher,
|
6
6
|
super_json_exports
|
7
|
-
} from "./chunk-
|
8
|
-
import "./chunk-
|
7
|
+
} from "./chunk-V3I7RIRY.js";
|
8
|
+
import "./chunk-DNG2IB3R.js";
|
9
9
|
|
10
10
|
// src/adapters/hono/middleware.ts
|
11
11
|
import { value } from "@orpc/shared";
|
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,
|
@@ -9,7 +10,7 @@ import {
|
|
9
10
|
lazy,
|
10
11
|
mergeContext,
|
11
12
|
unlazy
|
12
|
-
} from "./chunk-
|
13
|
+
} from "./chunk-DNG2IB3R.js";
|
13
14
|
|
14
15
|
// src/builder.ts
|
15
16
|
import { ContractProcedure } from "@orpc/contract";
|
@@ -346,6 +347,12 @@ var ProcedureBuilder = class _ProcedureBuilder {
|
|
346
347
|
contract: DecoratedContractProcedure2.decorate(this["~orpc"].contract).output(schema, example)
|
347
348
|
});
|
348
349
|
}
|
350
|
+
errors(errors) {
|
351
|
+
return new _ProcedureBuilder({
|
352
|
+
...this["~orpc"],
|
353
|
+
contract: DecoratedContractProcedure2.decorate(this["~orpc"].contract).errors(errors)
|
354
|
+
});
|
355
|
+
}
|
349
356
|
use(middleware, mapInput) {
|
350
357
|
if (!mapInput) {
|
351
358
|
return new ProcedureImplementer({
|
@@ -392,7 +399,8 @@ var Builder = class _Builder {
|
|
392
399
|
contract: new ContractProcedure({
|
393
400
|
route,
|
394
401
|
InputSchema: void 0,
|
395
|
-
OutputSchema: void 0
|
402
|
+
OutputSchema: void 0,
|
403
|
+
errorMap: void 0
|
396
404
|
})
|
397
405
|
});
|
398
406
|
}
|
@@ -402,7 +410,8 @@ var Builder = class _Builder {
|
|
402
410
|
contract: new ContractProcedure({
|
403
411
|
OutputSchema: void 0,
|
404
412
|
InputSchema: schema,
|
405
|
-
inputExample: example
|
413
|
+
inputExample: example,
|
414
|
+
errorMap: void 0
|
406
415
|
})
|
407
416
|
});
|
408
417
|
}
|
@@ -412,7 +421,18 @@ var Builder = class _Builder {
|
|
412
421
|
contract: new ContractProcedure({
|
413
422
|
InputSchema: void 0,
|
414
423
|
OutputSchema: schema,
|
415
|
-
outputExample: example
|
424
|
+
outputExample: example,
|
425
|
+
errorMap: void 0
|
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
|
416
436
|
})
|
417
437
|
});
|
418
438
|
}
|
@@ -421,7 +441,8 @@ var Builder = class _Builder {
|
|
421
441
|
middlewares: this["~orpc"].middlewares,
|
422
442
|
contract: new ContractProcedure({
|
423
443
|
InputSchema: void 0,
|
424
|
-
OutputSchema: void 0
|
444
|
+
OutputSchema: void 0,
|
445
|
+
errorMap: void 0
|
425
446
|
}),
|
426
447
|
handler
|
427
448
|
}));
|
@@ -486,12 +507,12 @@ function createRouterClient(options) {
|
|
486
507
|
}
|
487
508
|
|
488
509
|
// src/index.ts
|
489
|
-
import { configGlobal, fallbackToGlobalConfig } from "@orpc/contract";
|
490
|
-
export * from "@orpc/shared/error";
|
510
|
+
import { configGlobal, fallbackToGlobalConfig, isDefinedError, ORPCError, safe } from "@orpc/contract";
|
491
511
|
var os = new Builder({});
|
492
512
|
export {
|
493
513
|
Builder,
|
494
514
|
LAZY_LOADER_SYMBOL,
|
515
|
+
ORPCError,
|
495
516
|
Procedure,
|
496
517
|
ProcedureBuilder,
|
497
518
|
ProcedureImplementer,
|
@@ -499,6 +520,7 @@ export {
|
|
499
520
|
RouterImplementer,
|
500
521
|
configGlobal,
|
501
522
|
createChainableImplementer,
|
523
|
+
createORPCErrorConstructorMap,
|
502
524
|
createProcedureClient,
|
503
525
|
createRouterClient,
|
504
526
|
decorateLazy,
|
@@ -510,11 +532,13 @@ export {
|
|
510
532
|
getLazyRouterPrefix,
|
511
533
|
getRouterChild,
|
512
534
|
getRouterContract,
|
535
|
+
isDefinedError,
|
513
536
|
isLazy,
|
514
537
|
isProcedure,
|
515
538
|
lazy,
|
516
539
|
mergeContext,
|
517
540
|
os,
|
541
|
+
safe,
|
518
542
|
setRouterContract,
|
519
543
|
unlazy
|
520
544
|
};
|
package/dist/next.js
CHANGED
@@ -4,8 +4,8 @@ import {
|
|
4
4
|
ORPCPayloadCodec,
|
5
5
|
ORPCProcedureMatcher,
|
6
6
|
super_json_exports
|
7
|
-
} from "./chunk-
|
8
|
-
import "./chunk-
|
7
|
+
} from "./chunk-V3I7RIRY.js";
|
8
|
+
import "./chunk-DNG2IB3R.js";
|
9
9
|
|
10
10
|
// src/adapters/next/serve.ts
|
11
11
|
import { value } from "@orpc/shared";
|
package/dist/node.js
CHANGED
package/dist/src/builder.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { ANY_CONTRACT_PROCEDURE, ContractRouter, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
1
|
+
import type { ANY_CONTRACT_PROCEDURE, ContractRouter, ErrorMap, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
2
|
import type { FlattenLazy } from './lazy';
|
3
3
|
import type { Middleware } from './middleware';
|
4
4
|
import type { DecoratedMiddleware } from './middleware-decorated';
|
@@ -11,19 +11,20 @@ import { ProcedureBuilder } from './procedure-builder';
|
|
11
11
|
import { type DecoratedProcedure } from './procedure-decorated';
|
12
12
|
import { RouterBuilder } from './router-builder';
|
13
13
|
export interface BuilderDef<TContext extends Context, TExtraContext extends Context> {
|
14
|
-
middlewares?: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any
|
14
|
+
middlewares?: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any, Record<string, unknown>>[];
|
15
15
|
}
|
16
16
|
export declare class Builder<TContext extends Context, TExtraContext extends Context> {
|
17
17
|
'~type': "Builder";
|
18
18
|
'~orpc': BuilderDef<TContext, TExtraContext>;
|
19
19
|
constructor(def: BuilderDef<TContext, TExtraContext>);
|
20
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
|
-
middleware<UExtraContext extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined, TInput = unknown, TOutput = any>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, TInput, TOutput
|
23
|
-
route(route: RouteOptions): ProcedureBuilder<TContext, TExtraContext, undefined, undefined>;
|
24
|
-
input<USchema extends Schema
|
25
|
-
output<USchema extends Schema
|
26
|
-
|
21
|
+
use<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, unknown, unknown, Record<string, unknown>>): Builder<TContext, MergeContext<TExtraContext, U>>;
|
22
|
+
middleware<UExtraContext extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined, TInput = unknown, TOutput = any>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, TInput, TOutput, Record<string, unknown>>): DecoratedMiddleware<MergeContext<TContext, TExtraContext>, UExtraContext, TInput, TOutput, Record<string, unknown>>;
|
23
|
+
route(route: RouteOptions): ProcedureBuilder<TContext, TExtraContext, undefined, undefined, undefined>;
|
24
|
+
input<USchema extends Schema>(schema: USchema, example?: SchemaInput<USchema>): ProcedureBuilder<TContext, TExtraContext, USchema, undefined, undefined>;
|
25
|
+
output<USchema extends Schema>(schema: USchema, example?: SchemaOutput<USchema>): ProcedureBuilder<TContext, TExtraContext, undefined, USchema, undefined>;
|
26
|
+
errors<UErrorMap extends ErrorMap>(errors: UErrorMap): ProcedureBuilder<TContext, TExtraContext, undefined, undefined, UErrorMap>;
|
27
|
+
handler<UFuncOutput = undefined>(handler: ProcedureHandler<TContext, TExtraContext, undefined, undefined, UFuncOutput, undefined>): DecoratedProcedure<TContext, TExtraContext, undefined, undefined, UFuncOutput, undefined>;
|
27
28
|
prefix(prefix: HTTPPath): RouterBuilder<TContext, TExtraContext>;
|
28
29
|
tag(...tags: string[]): RouterBuilder<TContext, TExtraContext>;
|
29
30
|
router<U extends Router<MergeContext<TContext, TExtraContext>, any>>(router: U): AdaptedRouter<TContext, U>;
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import type { ErrorMap, ErrorMapItem, ORPCErrorOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import { ORPCError } from '@orpc/contract';
|
3
|
+
export type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<any, TData>, 'defined' | 'code' | 'status'>;
|
4
|
+
export type ORPCErrorConstructorMapItemRest<TData> = [options: ORPCErrorConstructorMapItemOptions<TData>] | (undefined extends TData ? [] : never);
|
5
|
+
export type ORPCErrorConstructorMapItem<TCode extends string, TDataSchema extends Schema> = (...rest: ORPCErrorConstructorMapItemRest<SchemaInput<TDataSchema>>) => ORPCError<TCode, SchemaOutput<TDataSchema>>;
|
6
|
+
export type ORPCErrorConstructorMap<T extends ErrorMap> = T extends undefined ? Record<string, unknown> : {
|
7
|
+
[K in keyof T]: K extends string ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, UInputSchema> : never : never;
|
8
|
+
};
|
9
|
+
export declare function createORPCErrorConstructorMap<T extends ErrorMap>(errors: T): ORPCErrorConstructorMap<T>;
|
10
|
+
//# sourceMappingURL=error.d.ts.map
|
@@ -3,8 +3,8 @@ import type { Context, MergeContext, WELL_CONTEXT } from './types';
|
|
3
3
|
import { type ContractProcedure, type ContractRouter } from '@orpc/contract';
|
4
4
|
import { ProcedureImplementer } from './procedure-implementer';
|
5
5
|
import { RouterImplementer } from './router-implementer';
|
6
|
-
export type ChainableImplementer<TContext extends Context, TExtraContext extends Context, TContract extends ContractRouter> = TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema> ? ProcedureImplementer<TContext, TExtraContext, UInputSchema, UOutputSchema> : {
|
6
|
+
export type ChainableImplementer<TContext extends Context, TExtraContext extends Context, TContract extends ContractRouter> = TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap> ? ProcedureImplementer<TContext, TExtraContext, UInputSchema, UOutputSchema, UErrorMap> : {
|
7
7
|
[K in keyof TContract]: TContract[K] extends ContractRouter ? ChainableImplementer<TContext, TExtraContext, TContract[K]> : never;
|
8
8
|
} & Omit<RouterImplementer<TContext, TExtraContext, TContract>, '~type' | '~orpc'>;
|
9
|
-
export declare function createChainableImplementer<TContext extends Context = WELL_CONTEXT, TExtraContext extends Context = undefined, TContract extends ContractRouter = any>(contract: TContract, middlewares?: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any
|
9
|
+
export declare function createChainableImplementer<TContext extends Context = WELL_CONTEXT, TExtraContext extends Context = undefined, TContract extends ContractRouter = any>(contract: TContract, middlewares?: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any, Record<string, unknown>>[]): ChainableImplementer<TContext, TExtraContext, TContract>;
|
10
10
|
//# sourceMappingURL=implementer-chainable.d.ts.map
|
package/dist/src/index.d.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import type { WELL_CONTEXT } from './types';
|
2
2
|
import { Builder } from './builder';
|
3
3
|
export * from './builder';
|
4
|
+
export * from './error';
|
4
5
|
export * from './hidden';
|
5
6
|
export * from './implementer-chainable';
|
6
7
|
export * from './lazy';
|
@@ -18,7 +19,6 @@ export * from './router-client';
|
|
18
19
|
export * from './router-implementer';
|
19
20
|
export * from './types';
|
20
21
|
export * from './utils';
|
21
|
-
export { configGlobal, fallbackToGlobalConfig } from '@orpc/contract';
|
22
|
-
export * from '@orpc/shared/error';
|
22
|
+
export { configGlobal, fallbackToGlobalConfig, isDefinedError, ORPCError, safe } from '@orpc/contract';
|
23
23
|
export declare const os: Builder<WELL_CONTEXT, undefined>;
|
24
24
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1,9 +1,9 @@
|
|
1
|
-
import type { SchemaInput, SchemaOutput } from '@orpc/contract';
|
1
|
+
import type { ErrorFromErrorMap, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
2
|
import type { Lazy } from './lazy';
|
3
3
|
import type { Procedure } from './procedure';
|
4
4
|
import type { ProcedureClient } from './procedure-client';
|
5
5
|
import { type ANY_ROUTER } from './router';
|
6
|
-
export type DecoratedLazy<T> = T extends Lazy<infer U> ? DecoratedLazy<U> : Lazy<T> & (T extends Procedure<infer UContext, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput> ? undefined extends UContext ? ProcedureClient<SchemaInput<UInputSchema>, SchemaOutput<UOutputSchema, UFuncOutput>,
|
6
|
+
export type DecoratedLazy<T> = T extends Lazy<infer U> ? DecoratedLazy<U> : Lazy<T> & (T extends Procedure<infer UContext, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput, infer UErrorMap> ? undefined extends UContext ? ProcedureClient<unknown, SchemaInput<UInputSchema>, SchemaOutput<UOutputSchema, UFuncOutput>, ErrorFromErrorMap<UErrorMap>> : unknown : {
|
7
7
|
[K in keyof T]: T[K] extends object ? DecoratedLazy<T[K]> : never;
|
8
8
|
});
|
9
9
|
export declare function decorateLazy<T extends Lazy<ANY_ROUTER | undefined>>(lazied: T): DecoratedLazy<T>;
|
@@ -1,8 +1,9 @@
|
|
1
|
+
import type { ORPCErrorConstructorMap } from './error';
|
1
2
|
import type { MapInputMiddleware, Middleware } from './middleware';
|
2
|
-
import type { Context, MergeContext
|
3
|
-
export interface DecoratedMiddleware<TContext extends Context, TExtraContext extends Context, TInput, TOutput
|
4
|
-
concat: (<UExtraContext extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined, UInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, UInput & TInput, TOutput>) => DecoratedMiddleware<TContext, MergeContext<TExtraContext, UExtraContext>, UInput & TInput, TOutput>) & (<UExtraContext extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined, UInput = TInput, UMappedInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, UMappedInput, TOutput>, mapInput: MapInputMiddleware<UInput & TInput, UMappedInput>) => DecoratedMiddleware<TContext, MergeContext<TExtraContext, UExtraContext>, UInput & TInput, TOutput>);
|
5
|
-
mapInput: <UInput = unknown>(map: MapInputMiddleware<UInput, TInput>) => DecoratedMiddleware<TContext, TExtraContext, UInput, TOutput>;
|
3
|
+
import type { Context, MergeContext } from './types';
|
4
|
+
export interface DecoratedMiddleware<TContext extends Context, TExtraContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> extends Middleware<TContext, TExtraContext, TInput, TOutput, TErrorConstructorMap> {
|
5
|
+
concat: (<UExtraContext extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined, UInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, UInput & TInput, TOutput, TErrorConstructorMap>) => DecoratedMiddleware<TContext, MergeContext<TExtraContext, UExtraContext>, UInput & TInput, TOutput, TErrorConstructorMap>) & (<UExtraContext extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined, UInput = TInput, UMappedInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, UMappedInput, TOutput, TErrorConstructorMap>, mapInput: MapInputMiddleware<UInput & TInput, UMappedInput>) => DecoratedMiddleware<TContext, MergeContext<TExtraContext, UExtraContext>, UInput & TInput, TOutput, TErrorConstructorMap>);
|
6
|
+
mapInput: <UInput = unknown>(map: MapInputMiddleware<UInput, TInput>) => DecoratedMiddleware<TContext, TExtraContext, UInput, TOutput, TErrorConstructorMap>;
|
6
7
|
}
|
7
|
-
export declare function decorateMiddleware<TContext extends Context
|
8
|
+
export declare function decorateMiddleware<TContext extends Context, TExtraContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>>(middleware: Middleware<TContext, TExtraContext, TInput, TOutput, TErrorConstructorMap>): DecoratedMiddleware<TContext, TExtraContext, TInput, TOutput, TErrorConstructorMap>;
|
8
9
|
//# sourceMappingURL=middleware-decorated.d.ts.map
|
package/dist/src/middleware.d.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import type { Promisable } from '@orpc/shared';
|
2
|
+
import type { ORPCErrorConstructorMap } from './error';
|
2
3
|
import type { ANY_PROCEDURE } from './procedure';
|
3
|
-
import type { Context } from './types';
|
4
|
+
import type { AbortSignal, Context } from './types';
|
4
5
|
export type MiddlewareResult<TExtraContext extends Context, TOutput> = Promisable<{
|
5
6
|
output: TOutput;
|
6
7
|
context: TExtraContext;
|
@@ -15,17 +16,18 @@ export interface MiddlewareNextFn<TOutput> {
|
|
15
16
|
export interface MiddlewareOutputFn<TOutput> {
|
16
17
|
(output: TOutput): MiddlewareResult<undefined, TOutput>;
|
17
18
|
}
|
18
|
-
export interface MiddlewareOptions<TContext extends Context, TOutput
|
19
|
+
export interface MiddlewareOptions<TContext extends Context, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> {
|
19
20
|
context: TContext;
|
20
21
|
path: string[];
|
21
22
|
procedure: ANY_PROCEDURE;
|
22
23
|
signal?: AbortSignal;
|
23
24
|
next: MiddlewareNextFn<TOutput>;
|
25
|
+
errors: TErrorConstructorMap;
|
24
26
|
}
|
25
|
-
export interface Middleware<TContext extends Context, TExtraContext extends Context, TInput, TOutput
|
26
|
-
(options: MiddlewareOptions<TContext, TOutput>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TExtraContext, TOutput>>;
|
27
|
+
export interface Middleware<TContext extends Context, TExtraContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> {
|
28
|
+
(options: MiddlewareOptions<TContext, TOutput, TErrorConstructorMap>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TExtraContext, TOutput>>;
|
27
29
|
}
|
28
|
-
export type ANY_MIDDLEWARE = Middleware<any, any, any, any>;
|
30
|
+
export type ANY_MIDDLEWARE = Middleware<any, any, any, any, any>;
|
29
31
|
export interface MapInputMiddleware<TInput, TMappedInput> {
|
30
32
|
(input: TInput): TMappedInput;
|
31
33
|
}
|
@@ -1,22 +1,24 @@
|
|
1
|
+
import type { ContractProcedure, ErrorMap, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { ORPCErrorConstructorMap } from './error';
|
1
3
|
import type { MapInputMiddleware, Middleware } from './middleware';
|
2
4
|
import type { DecoratedProcedure } from './procedure-decorated';
|
3
5
|
import type { Context, MergeContext } from './types';
|
4
|
-
import { type ContractProcedure, type RouteOptions, type Schema, type SchemaInput, type SchemaOutput } from '@orpc/contract';
|
5
6
|
import { type ProcedureHandler } from './procedure';
|
6
7
|
import { ProcedureImplementer } from './procedure-implementer';
|
7
|
-
export interface ProcedureBuilderDef<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema> {
|
8
|
-
contract: ContractProcedure<TInputSchema, TOutputSchema>;
|
9
|
-
middlewares?: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any
|
8
|
+
export interface ProcedureBuilderDef<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> {
|
9
|
+
contract: ContractProcedure<TInputSchema, TOutputSchema, TErrorMap>;
|
10
|
+
middlewares?: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any, Record<string, unknown>>[];
|
10
11
|
}
|
11
|
-
export declare class ProcedureBuilder<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema> {
|
12
|
+
export declare class ProcedureBuilder<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> {
|
12
13
|
'~type': "ProcedureBuilder";
|
13
|
-
'~orpc': ProcedureBuilderDef<TContext, TExtraContext, TInputSchema, TOutputSchema>;
|
14
|
-
constructor(def: ProcedureBuilderDef<TContext, TExtraContext, TInputSchema, TOutputSchema>);
|
15
|
-
route(route: RouteOptions): ProcedureBuilder<TContext, TExtraContext, TInputSchema, TOutputSchema>;
|
16
|
-
input<U extends Schema
|
17
|
-
output<U extends Schema
|
18
|
-
|
19
|
-
use<
|
20
|
-
|
14
|
+
'~orpc': ProcedureBuilderDef<TContext, TExtraContext, TInputSchema, TOutputSchema, TErrorMap>;
|
15
|
+
constructor(def: ProcedureBuilderDef<TContext, TExtraContext, TInputSchema, TOutputSchema, TErrorMap>);
|
16
|
+
route(route: RouteOptions): ProcedureBuilder<TContext, TExtraContext, TInputSchema, TOutputSchema, TErrorMap>;
|
17
|
+
input<U extends Schema>(schema: U, example?: SchemaInput<U>): ProcedureBuilder<TContext, TExtraContext, U, TOutputSchema, TErrorMap>;
|
18
|
+
output<U extends Schema>(schema: U, example?: SchemaOutput<U>): ProcedureBuilder<TContext, TExtraContext, TInputSchema, U, TErrorMap>;
|
19
|
+
errors<UErrorMap extends ErrorMap>(errors: UErrorMap): ProcedureBuilder<TContext, TExtraContext, TInputSchema, TOutputSchema, UErrorMap>;
|
20
|
+
use<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>>): ProcedureImplementer<TContext, MergeContext<TExtraContext, U>, TInputSchema, TOutputSchema, TErrorMap>;
|
21
|
+
use<UExtra extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined, UInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtra, UInput, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UInput>): ProcedureImplementer<TContext, MergeContext<TExtraContext, UExtra>, TInputSchema, TOutputSchema, TErrorMap>;
|
22
|
+
handler<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap>;
|
21
23
|
}
|
22
24
|
//# sourceMappingURL=procedure-builder.d.ts.map
|
@@ -1,21 +1,21 @@
|
|
1
|
-
import type { Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
1
|
+
import type { Client, ErrorFromErrorMap, ErrorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
2
|
import type { Hooks, Value } from '@orpc/shared';
|
3
3
|
import type { Lazyable } from './lazy';
|
4
4
|
import type { Procedure } from './procedure';
|
5
|
-
import type { Context, Meta
|
6
|
-
export type ProcedureClientOptions<TClientContext> =
|
5
|
+
import type { AbortSignal, Context, Meta } from './types';
|
6
|
+
export type ProcedureClientOptions<TClientContext> = {
|
7
|
+
signal?: AbortSignal;
|
8
|
+
} & (undefined extends TClientContext ? {
|
7
9
|
context?: TClientContext;
|
8
10
|
} : {
|
9
11
|
context: TClientContext;
|
10
12
|
});
|
11
|
-
export
|
12
|
-
(...opts: [input: TInput, options: ProcedureClientOptions<TClientContext>] | (undefined extends TInput & TClientContext ? [] : never) | (undefined extends TClientContext ? [input: TInput] : never)): Promise<TOutput>;
|
13
|
-
}
|
13
|
+
export type ProcedureClient<TClientContext, TInput, TOutput, TError extends Error> = Client<TClientContext, TInput, TOutput, TError>;
|
14
14
|
/**
|
15
15
|
* Options for creating a procedure caller with comprehensive type safety
|
16
16
|
*/
|
17
|
-
export type CreateProcedureClientOptions<TContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema
|
18
|
-
procedure: Lazyable<Procedure<TContext, any, TInputSchema, TOutputSchema, THandlerOutput>>;
|
17
|
+
export type CreateProcedureClientOptions<TContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap> = {
|
18
|
+
procedure: Lazyable<Procedure<TContext, any, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>>;
|
19
19
|
/**
|
20
20
|
* This is helpful for logging and analytics.
|
21
21
|
*
|
@@ -30,5 +30,5 @@ export type CreateProcedureClientOptions<TContext extends Context, TInputSchema
|
|
30
30
|
} | (undefined extends TContext ? {
|
31
31
|
context?: undefined;
|
32
32
|
} : never)) & Hooks<unknown, SchemaOutput<TOutputSchema, THandlerOutput>, TContext, Meta>;
|
33
|
-
export declare function createProcedureClient<TContext extends Context
|
33
|
+
export declare function createProcedureClient<TContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap>(options: CreateProcedureClientOptions<TContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>): ProcedureClient<unknown, SchemaInput<TInputSchema>, SchemaOutput<TOutputSchema, THandlerOutput>, ErrorFromErrorMap<TErrorMap>>;
|
34
34
|
//# sourceMappingURL=procedure-client.d.ts.map
|
@@ -1,14 +1,15 @@
|
|
1
|
-
import type { HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
1
|
+
import type { ErrorFromErrorMap, ErrorMap, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { ORPCErrorConstructorMap } from './error';
|
2
3
|
import type { MapInputMiddleware, Middleware } from './middleware';
|
3
4
|
import type { ProcedureClient } from './procedure-client';
|
4
5
|
import type { Context, MergeContext } from './types';
|
5
6
|
import { Procedure } from './procedure';
|
6
|
-
export type DecoratedProcedure<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema
|
7
|
-
prefix: (prefix: HTTPPath) => DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput>;
|
8
|
-
route: (route: RouteOptions) => DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput>;
|
9
|
-
use: (<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema, THandlerOutput>>) => DecoratedProcedure<TContext, MergeContext<TExtraContext, U>, TInputSchema, TOutputSchema, THandlerOutput>) & (<UExtra extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined, UInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtra, UInput, SchemaInput<TOutputSchema, THandlerOutput>>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema, THandlerOutput>, UInput>) => DecoratedProcedure<TContext, MergeContext<TExtraContext, UExtra>, TInputSchema, TOutputSchema, THandlerOutput>);
|
10
|
-
unshiftTag: (...tags: string[]) => DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput>;
|
11
|
-
unshiftMiddleware: <U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(...middlewares: Middleware<TContext, U, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema, THandlerOutput>>[]) => DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput>;
|
12
|
-
} & (undefined extends TContext ? ProcedureClient<SchemaInput<TInputSchema>, SchemaOutput<TOutputSchema, THandlerOutput>,
|
13
|
-
export declare function decorateProcedure<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema
|
7
|
+
export type DecoratedProcedure<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap> = Procedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap> & {
|
8
|
+
prefix: (prefix: HTTPPath) => DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
9
|
+
route: (route: RouteOptions) => DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
10
|
+
use: (<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema, THandlerOutput>, ORPCErrorConstructorMap<TErrorMap>>) => DecoratedProcedure<TContext, MergeContext<TExtraContext, U>, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>) & (<UExtra extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined, UInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtra, UInput, SchemaInput<TOutputSchema, THandlerOutput>, ORPCErrorConstructorMap<TErrorMap>>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema, THandlerOutput>, UInput>) => DecoratedProcedure<TContext, MergeContext<TExtraContext, UExtra>, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>);
|
11
|
+
unshiftTag: (...tags: string[]) => DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
12
|
+
unshiftMiddleware: <U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(...middlewares: Middleware<TContext, U, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema, THandlerOutput>, ORPCErrorConstructorMap<TErrorMap>>[]) => DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
13
|
+
} & (undefined extends TContext ? ProcedureClient<unknown, SchemaInput<TInputSchema>, SchemaOutput<TOutputSchema, THandlerOutput>, ErrorFromErrorMap<TErrorMap>> : unknown);
|
14
|
+
export declare function decorateProcedure<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap>(procedure: Procedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
14
15
|
//# sourceMappingURL=procedure-decorated.d.ts.map
|
@@ -1,18 +1,19 @@
|
|
1
|
-
import type { ContractProcedure, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
1
|
+
import type { ContractProcedure, ErrorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { ORPCErrorConstructorMap } from './error';
|
2
3
|
import type { MapInputMiddleware, Middleware } from './middleware';
|
3
4
|
import type { ProcedureHandler } from './procedure';
|
4
5
|
import type { DecoratedProcedure } from './procedure-decorated';
|
5
6
|
import type { Context, MergeContext } from './types';
|
6
|
-
export type ProcedureImplementerDef<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema> = {
|
7
|
-
contract: ContractProcedure<TInputSchema, TOutputSchema>;
|
8
|
-
middlewares?: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>>[];
|
7
|
+
export type ProcedureImplementerDef<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> = {
|
8
|
+
contract: ContractProcedure<TInputSchema, TOutputSchema, TErrorMap>;
|
9
|
+
middlewares?: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>>[];
|
9
10
|
};
|
10
|
-
export declare class ProcedureImplementer<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema> {
|
11
|
+
export declare class ProcedureImplementer<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> {
|
11
12
|
'~type': "ProcedureImplementer";
|
12
|
-
'~orpc': ProcedureImplementerDef<TContext, TExtraContext, TInputSchema, TOutputSchema>;
|
13
|
-
constructor(def: ProcedureImplementerDef<TContext, TExtraContext, TInputSchema, TOutputSchema>);
|
14
|
-
use<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>>): ProcedureImplementer<TContext, MergeContext<TExtraContext, U>, TInputSchema, TOutputSchema>;
|
15
|
-
use<UExtra extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined, UInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtra, UInput, SchemaInput<TOutputSchema>>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UInput>): ProcedureImplementer<TContext, MergeContext<TExtraContext, UExtra>, TInputSchema, TOutputSchema>;
|
16
|
-
handler<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput>;
|
13
|
+
'~orpc': ProcedureImplementerDef<TContext, TExtraContext, TInputSchema, TOutputSchema, TErrorMap>;
|
14
|
+
constructor(def: ProcedureImplementerDef<TContext, TExtraContext, TInputSchema, TOutputSchema, TErrorMap>);
|
15
|
+
use<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>>): ProcedureImplementer<TContext, MergeContext<TExtraContext, U>, TInputSchema, TOutputSchema, TErrorMap>;
|
16
|
+
use<UExtra extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined, UInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtra, UInput, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UInput>): ProcedureImplementer<TContext, MergeContext<TExtraContext, UExtra>, TInputSchema, TOutputSchema, TErrorMap>;
|
17
|
+
handler<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap>;
|
17
18
|
}
|
18
19
|
//# sourceMappingURL=procedure-implementer.d.ts.map
|
package/dist/src/procedure.d.ts
CHANGED
@@ -1,30 +1,43 @@
|
|
1
|
+
import type { ContractProcedure, ErrorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
1
2
|
import type { Promisable } from '@orpc/shared';
|
3
|
+
import type { ORPCErrorConstructorMap } from './error';
|
2
4
|
import type { Lazy } from './lazy';
|
3
5
|
import type { Middleware } from './middleware';
|
4
6
|
import type { AbortSignal, Context, MergeContext } from './types';
|
5
|
-
|
6
|
-
|
7
|
-
context: TContext;
|
7
|
+
export interface ProcedureHandlerOptions<TContext extends Context, TExtraContext extends Context, TInput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> {
|
8
|
+
context: MergeContext<TContext, TExtraContext>;
|
8
9
|
input: TInput;
|
9
10
|
path: string[];
|
10
11
|
procedure: ANY_PROCEDURE;
|
11
12
|
signal?: AbortSignal;
|
13
|
+
errors: TErrorConstructorMap;
|
12
14
|
}
|
13
|
-
export interface ProcedureHandler<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema
|
14
|
-
(opt: ProcedureHandlerOptions<
|
15
|
+
export interface ProcedureHandler<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap> {
|
16
|
+
(opt: ProcedureHandlerOptions<TContext, TExtraContext, SchemaOutput<TInputSchema>, ORPCErrorConstructorMap<TErrorMap>>): Promisable<SchemaInput<TOutputSchema, THandlerOutput>>;
|
15
17
|
}
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
/**
|
19
|
+
* Why is `ErrorConstructorMap` passed to `Middleware` as `any`?
|
20
|
+
* Why is `ErrorMap` passed to `ProcedureHandler` as `any`?
|
21
|
+
*
|
22
|
+
* Passing `ErrorMap/ErrorConstructorMap` directly to `Middleware/ProcedureHandler`
|
23
|
+
* causes unexpected errors in the router (the root cause is unclear, but it occurs consistently).
|
24
|
+
* To avoid these issues, `any` is used as a workaround.
|
25
|
+
*
|
26
|
+
* This approach is still functional because `ProcedureDef` can infer the `ErrorMap` from `ContractProcedure`.
|
27
|
+
* The only downside is that direct access to them requires careful type checking to ensure safety.
|
28
|
+
*/
|
29
|
+
export interface ProcedureDef<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap> {
|
30
|
+
middlewares?: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, SchemaOutput<TInputSchema>, any, any>[];
|
31
|
+
contract: ContractProcedure<TInputSchema, TOutputSchema, TErrorMap>;
|
32
|
+
handler: ProcedureHandler<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, any>;
|
20
33
|
}
|
21
|
-
export declare class Procedure<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema
|
34
|
+
export declare class Procedure<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap> {
|
22
35
|
'~type': "Procedure";
|
23
|
-
'~orpc': ProcedureDef<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput>;
|
24
|
-
constructor(def: ProcedureDef<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput>);
|
36
|
+
'~orpc': ProcedureDef<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
37
|
+
constructor(def: ProcedureDef<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>);
|
25
38
|
}
|
26
|
-
export type ANY_PROCEDURE = Procedure<any, any, any, any, any>;
|
27
|
-
export type WELL_PROCEDURE = Procedure<Context, Context, Schema, Schema, unknown>;
|
39
|
+
export type ANY_PROCEDURE = Procedure<any, any, any, any, any, any>;
|
40
|
+
export type WELL_PROCEDURE = Procedure<Context, Context, Schema, Schema, unknown, any>;
|
28
41
|
export type ANY_LAZY_PROCEDURE = Lazy<ANY_PROCEDURE>;
|
29
42
|
export declare function isProcedure(item: unknown): item is ANY_PROCEDURE;
|
30
43
|
//# sourceMappingURL=procedure.d.ts.map
|
@@ -6,13 +6,13 @@ import type { ANY_ROUTER, Router } from './router';
|
|
6
6
|
import type { Context, MergeContext } from './types';
|
7
7
|
import { type DecoratedLazy } from './lazy-decorated';
|
8
8
|
import { type DecoratedProcedure } from './procedure-decorated';
|
9
|
-
export type AdaptedRouter<TContext extends Context, TRouter extends ANY_ROUTER> = TRouter extends Lazy<infer U extends ANY_ROUTER> ? DecoratedLazy<AdaptedRouter<TContext, U>> : TRouter extends Procedure<any, infer UExtraContext, infer UInputSchema, infer UOutputSchema, infer UFuncOutput> ? DecoratedProcedure<TContext, UExtraContext, UInputSchema, UOutputSchema, UFuncOutput> : {
|
9
|
+
export type AdaptedRouter<TContext extends Context, TRouter extends ANY_ROUTER> = TRouter extends Lazy<infer U extends ANY_ROUTER> ? DecoratedLazy<AdaptedRouter<TContext, U>> : TRouter extends Procedure<any, infer UExtraContext, infer UInputSchema, infer UOutputSchema, infer UFuncOutput, infer UErrorMap> ? DecoratedProcedure<TContext, UExtraContext, UInputSchema, UOutputSchema, UFuncOutput, UErrorMap> : {
|
10
10
|
[K in keyof TRouter]: TRouter[K] extends ANY_ROUTER ? AdaptedRouter<TContext, TRouter[K]> : never;
|
11
11
|
};
|
12
12
|
export type RouterBuilderDef<TContext extends Context, TExtraContext extends Context> = {
|
13
13
|
prefix?: HTTPPath;
|
14
14
|
tags?: readonly string[];
|
15
|
-
middlewares?: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any
|
15
|
+
middlewares?: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any, Record<string, unknown>>[];
|
16
16
|
};
|
17
17
|
export declare class RouterBuilder<TContext extends Context, TExtraContext extends Context> {
|
18
18
|
'~type': "RouterBuilder";
|
@@ -20,7 +20,7 @@ export declare class RouterBuilder<TContext extends Context, TExtraContext exten
|
|
20
20
|
constructor(def: RouterBuilderDef<TContext, TExtraContext>);
|
21
21
|
prefix(prefix: HTTPPath): RouterBuilder<TContext, TExtraContext>;
|
22
22
|
tag(...tags: string[]): RouterBuilder<TContext, TExtraContext>;
|
23
|
-
use<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, unknown, unknown
|
23
|
+
use<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, unknown, unknown, Record<string, unknown>>): RouterBuilder<TContext, MergeContext<TExtraContext, U>>;
|
24
24
|
router<U extends Router<MergeContext<TContext, TExtraContext>, any>>(router: U): AdaptedRouter<TContext, U>;
|
25
25
|
lazy<U extends Router<MergeContext<TContext, TExtraContext>, any>>(loader: () => Promise<{
|
26
26
|
default: U;
|
@@ -1,11 +1,11 @@
|
|
1
|
-
import type { ContractProcedure, ContractRouter, SchemaInput, SchemaOutput } from '@orpc/contract';
|
1
|
+
import type { ContractProcedure, ContractRouter, ErrorFromErrorMap, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
2
|
import type { Hooks, Value } from '@orpc/shared';
|
3
3
|
import type { Lazy } from './lazy';
|
4
4
|
import type { Procedure } from './procedure';
|
5
5
|
import type { ProcedureClient } from './procedure-client';
|
6
6
|
import type { Meta } from './types';
|
7
7
|
import { type ANY_ROUTER, type Router } from './router';
|
8
|
-
export type RouterClient<TRouter extends ANY_ROUTER | ContractRouter, TClientContext> = TRouter extends Lazy<infer U extends ANY_ROUTER | ContractRouter> ? RouterClient<U, TClientContext> : TRouter extends ContractProcedure<infer UInputSchema, infer UOutputSchema> | Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput> ? ProcedureClient<SchemaInput<UInputSchema>, SchemaOutput<UOutputSchema, UFuncOutput>,
|
8
|
+
export type RouterClient<TRouter extends ANY_ROUTER | ContractRouter, TClientContext> = TRouter extends Lazy<infer U extends ANY_ROUTER | ContractRouter> ? RouterClient<U, TClientContext> : TRouter extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap> | Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput, infer UErrorMap> ? ProcedureClient<TClientContext, SchemaInput<UInputSchema>, SchemaOutput<UOutputSchema, UFuncOutput>, ErrorFromErrorMap<UErrorMap>> : {
|
9
9
|
[K in keyof TRouter]: TRouter[K] extends ANY_ROUTER | ContractRouter ? RouterClient<TRouter[K], TClientContext> : never;
|
10
10
|
};
|
11
11
|
export type CreateRouterClientOptions<TRouter extends ANY_ROUTER> = {
|
@@ -5,14 +5,14 @@ import type { Router } from './router';
|
|
5
5
|
import type { AdaptedRouter } from './router-builder';
|
6
6
|
import type { Context, MergeContext } from './types';
|
7
7
|
export interface RouterImplementerDef<TContext extends Context, TExtraContext extends Context, TContract extends ContractRouter> {
|
8
|
-
middlewares?: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any
|
8
|
+
middlewares?: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any, Record<string, unknown>>[];
|
9
9
|
contract: TContract;
|
10
10
|
}
|
11
11
|
export declare class RouterImplementer<TContext extends Context, TExtraContext extends Context, TContract extends ContractRouter> {
|
12
12
|
'~type': "RouterImplementer";
|
13
13
|
'~orpc': RouterImplementerDef<TContext, TExtraContext, TContract>;
|
14
14
|
constructor(def: RouterImplementerDef<TContext, TExtraContext, TContract>);
|
15
|
-
use<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, unknown, unknown
|
15
|
+
use<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, unknown, unknown, Record<string, unknown>>): RouterImplementer<TContext, MergeContext<TExtraContext, U>, TContract>;
|
16
16
|
router<U extends Router<MergeContext<TContext, TExtraContext>, TContract>>(router: U): AdaptedRouter<TContext, U>;
|
17
17
|
lazy<U extends Router<MergeContext<TContext, TExtraContext>, TContract>>(loader: () => Promise<{
|
18
18
|
default: U;
|
package/dist/src/router.d.ts
CHANGED
@@ -2,14 +2,14 @@ import type { ContractProcedure, ContractRouter, SchemaInput, SchemaOutput } fro
|
|
2
2
|
import type { ANY_LAZY, Lazy, Lazyable } from './lazy';
|
3
3
|
import type { ANY_PROCEDURE, Procedure } from './procedure';
|
4
4
|
import type { Context } from './types';
|
5
|
-
export type Router<TContext extends Context, TContract extends ContractRouter> = Lazyable<TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema> ? Procedure<TContext, any, UInputSchema, UOutputSchema, any> : {
|
5
|
+
export type Router<TContext extends Context, TContract extends ContractRouter> = Lazyable<TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap> ? Procedure<TContext, any, UInputSchema, UOutputSchema, any, UErrorMap> : {
|
6
6
|
[K in keyof TContract]: TContract[K] extends ContractRouter ? Router<TContext, TContract[K]> : never;
|
7
7
|
}>;
|
8
8
|
export type ANY_ROUTER = Router<any, any>;
|
9
|
-
export type InferRouterInputs<T extends ANY_ROUTER> = T extends Lazy<infer U extends ANY_ROUTER> ? InferRouterInputs<U> : T extends Procedure<any, any, infer UInputSchema, any, any> ? SchemaInput<UInputSchema> : {
|
9
|
+
export type InferRouterInputs<T extends ANY_ROUTER> = T extends Lazy<infer U extends ANY_ROUTER> ? InferRouterInputs<U> : T extends Procedure<any, any, infer UInputSchema, any, any, any> ? SchemaInput<UInputSchema> : {
|
10
10
|
[K in keyof T]: T[K] extends ANY_ROUTER ? InferRouterInputs<T[K]> : never;
|
11
11
|
};
|
12
|
-
export type InferRouterOutputs<T extends ANY_ROUTER> = T extends Lazy<infer U extends ANY_ROUTER> ? InferRouterOutputs<U> : T extends Procedure<any, any, any, infer UOutputSchema, infer UFuncOutput> ? SchemaOutput<UOutputSchema, UFuncOutput> : {
|
12
|
+
export type InferRouterOutputs<T extends ANY_ROUTER> = T extends Lazy<infer U extends ANY_ROUTER> ? InferRouterOutputs<U> : T extends Procedure<any, any, any, infer UOutputSchema, infer UFuncOutput, any> ? SchemaOutput<UOutputSchema, UFuncOutput> : {
|
13
13
|
[K in keyof T]: T[K] extends ANY_ROUTER ? InferRouterOutputs<T[K]> : never;
|
14
14
|
};
|
15
15
|
export declare function getRouterChild<T extends ANY_ROUTER | Lazy<undefined>>(router: T, ...path: string[]): T extends ANY_LAZY ? Lazy<ANY_PROCEDURE | Record<string, ANY_ROUTER> | undefined> : ANY_ROUTER | Lazy<undefined> | undefined;
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orpc/server",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.
|
4
|
+
"version": "0.28.0",
|
5
5
|
"license": "MIT",
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
7
7
|
"repository": {
|
@@ -53,8 +53,8 @@
|
|
53
53
|
"next": ">=14.0.0"
|
54
54
|
},
|
55
55
|
"dependencies": {
|
56
|
-
"@orpc/contract": "0.
|
57
|
-
"@orpc/shared": "0.
|
56
|
+
"@orpc/contract": "0.28.0",
|
57
|
+
"@orpc/shared": "0.28.0"
|
58
58
|
},
|
59
59
|
"scripts": {
|
60
60
|
"build": "tsup --onSuccess='tsc -b --noCheck'",
|