@orpc/server 0.27.0 → 0.29.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/{chunk-3BAPJGK6.js → chunk-VY6NXNQT.js} +7 -8
- package/dist/{chunk-E7GUWVR4.js → chunk-XDC42C3C.js} +60 -19
- package/dist/fetch.js +4 -4
- package/dist/hono.js +4 -4
- package/dist/index.js +130 -101
- package/dist/next.js +4 -4
- package/dist/node.js +6 -6
- package/dist/src/adapters/fetch/orpc-handler.d.ts +3 -3
- package/dist/src/adapters/fetch/orpc-payload-codec.d.ts +1 -1
- package/dist/src/adapters/node/orpc-handler.d.ts +3 -3
- 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 -2
- package/dist/src/lazy-decorated.d.ts +3 -6
- package/dist/src/middleware-decorated.d.ts +6 -5
- package/dist/src/middleware.d.ts +7 -5
- package/dist/src/procedure-builder.d.ts +17 -15
- package/dist/src/procedure-client.d.ts +8 -20
- package/dist/src/procedure-decorated.d.ts +22 -10
- package/dist/src/procedure-implementer.d.ts +12 -11
- package/dist/src/procedure-utils.d.ts +17 -0
- package/dist/src/procedure.d.ts +27 -14
- 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/package.json +3 -3
@@ -4,7 +4,7 @@ import {
|
|
4
4
|
getRouterChild,
|
5
5
|
isProcedure,
|
6
6
|
unlazy
|
7
|
-
} from "./chunk-
|
7
|
+
} from "./chunk-XDC42C3C.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,9 +236,9 @@ 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
|
-
|
241
|
-
var ORPCHandler = class {
|
241
|
+
var RPCHandler = class {
|
242
242
|
constructor(router, options) {
|
243
243
|
this.options = options;
|
244
244
|
this.procedureMatcher = options?.procedureMatcher ?? new ORPCProcedureMatcher(router);
|
@@ -256,9 +256,8 @@ var ORPCHandler = class {
|
|
256
256
|
return { matched: false, response: void 0 };
|
257
257
|
}
|
258
258
|
const input = await this.payloadCodec.decode(request);
|
259
|
-
const client = createProcedureClient({
|
259
|
+
const client = createProcedureClient(match.procedure, {
|
260
260
|
context,
|
261
|
-
procedure: match.procedure,
|
262
261
|
path: match.path
|
263
262
|
});
|
264
263
|
const output = await client(input, { signal: request.signal });
|
@@ -297,6 +296,6 @@ export {
|
|
297
296
|
super_json_exports,
|
298
297
|
ORPCPayloadCodec,
|
299
298
|
ORPCProcedureMatcher,
|
300
|
-
|
299
|
+
RPCHandler
|
301
300
|
};
|
302
|
-
//# sourceMappingURL=chunk-
|
301
|
+
//# sourceMappingURL=chunk-VY6NXNQT.js.map
|
@@ -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,13 +87,13 @@ function flatLazy(lazied) {
|
|
60
87
|
}
|
61
88
|
|
62
89
|
// src/procedure-client.ts
|
63
|
-
import {
|
64
|
-
import {
|
65
|
-
function createProcedureClient(options) {
|
90
|
+
import { ORPCError as ORPCError2, validateORPCError, ValidationError } from "@orpc/contract";
|
91
|
+
import { executeWithHooks, toError, value } from "@orpc/shared";
|
92
|
+
function createProcedureClient(lazyableProcedure, ...[options]) {
|
66
93
|
return async (...[input, callerOptions]) => {
|
67
|
-
const path = options
|
68
|
-
const { default: procedure } = await unlazy(
|
69
|
-
const context = await value(options
|
94
|
+
const path = options?.path ?? [];
|
95
|
+
const { default: procedure } = await unlazy(lazyableProcedure);
|
96
|
+
const context = await value(options?.context, callerOptions?.context);
|
70
97
|
const meta = {
|
71
98
|
path,
|
72
99
|
procedure,
|
@@ -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-XDC42C3C.js.map
|
package/dist/fetch.js
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
import "./chunk-WUOGVGWG.js";
|
2
2
|
import {
|
3
|
-
ORPCHandler,
|
4
3
|
ORPCPayloadCodec,
|
5
4
|
ORPCProcedureMatcher,
|
5
|
+
RPCHandler,
|
6
6
|
super_json_exports
|
7
|
-
} from "./chunk-
|
8
|
-
import "./chunk-
|
7
|
+
} from "./chunk-VY6NXNQT.js";
|
8
|
+
import "./chunk-XDC42C3C.js";
|
9
9
|
export {
|
10
|
-
ORPCHandler,
|
11
10
|
ORPCPayloadCodec,
|
12
11
|
ORPCProcedureMatcher,
|
12
|
+
RPCHandler,
|
13
13
|
super_json_exports as SuperJSON
|
14
14
|
};
|
15
15
|
//# sourceMappingURL=fetch.js.map
|
package/dist/hono.js
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
import "./chunk-WUOGVGWG.js";
|
2
2
|
import {
|
3
|
-
ORPCHandler,
|
4
3
|
ORPCPayloadCodec,
|
5
4
|
ORPCProcedureMatcher,
|
5
|
+
RPCHandler,
|
6
6
|
super_json_exports
|
7
|
-
} from "./chunk-
|
8
|
-
import "./chunk-
|
7
|
+
} from "./chunk-VY6NXNQT.js";
|
8
|
+
import "./chunk-XDC42C3C.js";
|
9
9
|
|
10
10
|
// src/adapters/hono/middleware.ts
|
11
11
|
import { value } from "@orpc/shared";
|
@@ -21,9 +21,9 @@ function createMiddleware(handler, ...[options]) {
|
|
21
21
|
};
|
22
22
|
}
|
23
23
|
export {
|
24
|
-
ORPCHandler,
|
25
24
|
ORPCPayloadCodec,
|
26
25
|
ORPCProcedureMatcher,
|
26
|
+
RPCHandler,
|
27
27
|
super_json_exports as SuperJSON,
|
28
28
|
createMiddleware
|
29
29
|
};
|
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,14 +10,14 @@ import {
|
|
9
10
|
lazy,
|
10
11
|
mergeContext,
|
11
12
|
unlazy
|
12
|
-
} from "./chunk-
|
13
|
+
} from "./chunk-XDC42C3C.js";
|
13
14
|
|
14
15
|
// src/builder.ts
|
15
16
|
import { ContractProcedure } from "@orpc/contract";
|
16
17
|
|
17
18
|
// src/implementer-chainable.ts
|
18
19
|
import { isContractProcedure } from "@orpc/contract";
|
19
|
-
import { createCallableObject } from "@orpc/shared";
|
20
|
+
import { createCallableObject as createCallableObject2 } from "@orpc/shared";
|
20
21
|
|
21
22
|
// src/middleware-decorated.ts
|
22
23
|
function decorateMiddleware(middleware) {
|
@@ -43,58 +44,72 @@ function decorateMiddleware(middleware) {
|
|
43
44
|
|
44
45
|
// src/procedure-decorated.ts
|
45
46
|
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
|
-
|
47
|
+
import { createCallableObject } from "@orpc/shared";
|
48
|
+
var DecoratedProcedure = class _DecoratedProcedure extends Procedure {
|
49
|
+
static decorate(procedure) {
|
50
|
+
if (procedure instanceof _DecoratedProcedure) {
|
51
|
+
return procedure;
|
52
|
+
}
|
53
|
+
return new _DecoratedProcedure(procedure["~orpc"]);
|
54
|
+
}
|
55
|
+
prefix(prefix) {
|
56
|
+
return new _DecoratedProcedure({
|
57
|
+
...this["~orpc"],
|
58
|
+
contract: DecoratedContractProcedure.decorate(this["~orpc"].contract).prefix(prefix)
|
59
|
+
});
|
60
|
+
}
|
61
|
+
route(route) {
|
62
|
+
return new _DecoratedProcedure({
|
63
|
+
...this["~orpc"],
|
64
|
+
contract: DecoratedContractProcedure.decorate(this["~orpc"].contract).route(route)
|
65
|
+
});
|
66
|
+
}
|
67
|
+
use(middleware, mapInput) {
|
67
68
|
const middleware_ = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
68
|
-
return
|
69
|
-
...
|
70
|
-
middlewares: [...
|
71
|
-
})
|
72
|
-
}
|
73
|
-
|
74
|
-
return
|
75
|
-
...
|
76
|
-
contract: DecoratedContractProcedure.decorate(
|
77
|
-
})
|
78
|
-
}
|
79
|
-
|
80
|
-
|
69
|
+
return new _DecoratedProcedure({
|
70
|
+
...this["~orpc"],
|
71
|
+
middlewares: [...this["~orpc"].middlewares ?? [], middleware_]
|
72
|
+
});
|
73
|
+
}
|
74
|
+
unshiftTag(...tags) {
|
75
|
+
return new _DecoratedProcedure({
|
76
|
+
...this["~orpc"],
|
77
|
+
contract: DecoratedContractProcedure.decorate(this["~orpc"].contract).unshiftTag(...tags)
|
78
|
+
});
|
79
|
+
}
|
80
|
+
unshiftMiddleware(...middlewares) {
|
81
|
+
const castedMiddlewares = middlewares;
|
82
|
+
if (this["~orpc"].middlewares?.length) {
|
81
83
|
let min = 0;
|
82
|
-
for (let i = 0; i <
|
83
|
-
const index =
|
84
|
+
for (let i = 0; i < this["~orpc"].middlewares.length; i++) {
|
85
|
+
const index = castedMiddlewares.indexOf(this["~orpc"].middlewares[i], min);
|
84
86
|
if (index === -1) {
|
85
|
-
|
87
|
+
castedMiddlewares.push(...this["~orpc"].middlewares.slice(i));
|
86
88
|
break;
|
87
89
|
}
|
88
90
|
min = index + 1;
|
89
91
|
}
|
90
92
|
}
|
91
|
-
return
|
92
|
-
...
|
93
|
-
middlewares
|
94
|
-
})
|
95
|
-
}
|
96
|
-
|
97
|
-
|
93
|
+
return new _DecoratedProcedure({
|
94
|
+
...this["~orpc"],
|
95
|
+
middlewares: castedMiddlewares
|
96
|
+
});
|
97
|
+
}
|
98
|
+
/**
|
99
|
+
* Make this procedure callable (works like a function while still being a procedure).
|
100
|
+
* **Note**: this only takes effect when this method is called at the end of the chain.
|
101
|
+
*/
|
102
|
+
callable(...rest) {
|
103
|
+
return createCallableObject(this, createProcedureClient(this, ...rest));
|
104
|
+
}
|
105
|
+
/**
|
106
|
+
* Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
|
107
|
+
* **Note**: this only takes effect when this method is called at the end of the chain.
|
108
|
+
*/
|
109
|
+
actionable(...rest) {
|
110
|
+
return this.callable(...rest);
|
111
|
+
}
|
112
|
+
};
|
98
113
|
|
99
114
|
// src/procedure-implementer.ts
|
100
115
|
var ProcedureImplementer = class _ProcedureImplementer {
|
@@ -111,11 +126,11 @@ var ProcedureImplementer = class _ProcedureImplementer {
|
|
111
126
|
});
|
112
127
|
}
|
113
128
|
handler(handler) {
|
114
|
-
return
|
129
|
+
return new DecoratedProcedure({
|
115
130
|
middlewares: this["~orpc"].middlewares,
|
116
131
|
contract: this["~orpc"].contract,
|
117
132
|
handler
|
118
|
-
})
|
133
|
+
});
|
119
134
|
}
|
120
135
|
};
|
121
136
|
|
@@ -153,31 +168,10 @@ function getLazyRouterPrefix(obj) {
|
|
153
168
|
return obj[LAZY_ROUTER_PREFIX_SYMBOL];
|
154
169
|
}
|
155
170
|
|
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
171
|
// src/lazy-decorated.ts
|
173
172
|
function decorateLazy(lazied) {
|
174
173
|
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, {
|
174
|
+
const recursive = new Proxy(flattenLazy, {
|
181
175
|
get(target, key) {
|
182
176
|
if (typeof key !== "string") {
|
183
177
|
return Reflect.get(target, key);
|
@@ -244,7 +238,7 @@ function adapt(item, options) {
|
|
244
238
|
return adaptedLazy;
|
245
239
|
}
|
246
240
|
if (isProcedure(item)) {
|
247
|
-
let decorated =
|
241
|
+
let decorated = DecoratedProcedure.decorate(item);
|
248
242
|
if (options.tags?.length) {
|
249
243
|
decorated = decorated.unshiftTag(...options.tags);
|
250
244
|
}
|
@@ -312,7 +306,7 @@ function createChainableImplementer(contract, middlewares) {
|
|
312
306
|
if (!next) {
|
313
307
|
return method.bind(routerImplementer);
|
314
308
|
}
|
315
|
-
return
|
309
|
+
return createCallableObject2(next, method.bind(routerImplementer));
|
316
310
|
}
|
317
311
|
});
|
318
312
|
return merged;
|
@@ -346,6 +340,12 @@ var ProcedureBuilder = class _ProcedureBuilder {
|
|
346
340
|
contract: DecoratedContractProcedure2.decorate(this["~orpc"].contract).output(schema, example)
|
347
341
|
});
|
348
342
|
}
|
343
|
+
errors(errors) {
|
344
|
+
return new _ProcedureBuilder({
|
345
|
+
...this["~orpc"],
|
346
|
+
contract: DecoratedContractProcedure2.decorate(this["~orpc"].contract).errors(errors)
|
347
|
+
});
|
348
|
+
}
|
349
349
|
use(middleware, mapInput) {
|
350
350
|
if (!mapInput) {
|
351
351
|
return new ProcedureImplementer({
|
@@ -359,11 +359,11 @@ var ProcedureBuilder = class _ProcedureBuilder {
|
|
359
359
|
}).use(middleware, mapInput);
|
360
360
|
}
|
361
361
|
handler(handler) {
|
362
|
-
return
|
362
|
+
return new DecoratedProcedure({
|
363
363
|
middlewares: this["~orpc"].middlewares,
|
364
364
|
contract: this["~orpc"].contract,
|
365
365
|
handler
|
366
|
-
})
|
366
|
+
});
|
367
367
|
}
|
368
368
|
};
|
369
369
|
|
@@ -392,7 +392,8 @@ var Builder = class _Builder {
|
|
392
392
|
contract: new ContractProcedure({
|
393
393
|
route,
|
394
394
|
InputSchema: void 0,
|
395
|
-
OutputSchema: void 0
|
395
|
+
OutputSchema: void 0,
|
396
|
+
errorMap: void 0
|
396
397
|
})
|
397
398
|
});
|
398
399
|
}
|
@@ -402,7 +403,8 @@ var Builder = class _Builder {
|
|
402
403
|
contract: new ContractProcedure({
|
403
404
|
OutputSchema: void 0,
|
404
405
|
InputSchema: schema,
|
405
|
-
inputExample: example
|
406
|
+
inputExample: example,
|
407
|
+
errorMap: void 0
|
406
408
|
})
|
407
409
|
});
|
408
410
|
}
|
@@ -412,19 +414,31 @@ var Builder = class _Builder {
|
|
412
414
|
contract: new ContractProcedure({
|
413
415
|
InputSchema: void 0,
|
414
416
|
OutputSchema: schema,
|
415
|
-
outputExample: example
|
417
|
+
outputExample: example,
|
418
|
+
errorMap: void 0
|
419
|
+
})
|
420
|
+
});
|
421
|
+
}
|
422
|
+
errors(errors) {
|
423
|
+
return new ProcedureBuilder({
|
424
|
+
middlewares: this["~orpc"].middlewares,
|
425
|
+
contract: new ContractProcedure({
|
426
|
+
InputSchema: void 0,
|
427
|
+
OutputSchema: void 0,
|
428
|
+
errorMap: errors
|
416
429
|
})
|
417
430
|
});
|
418
431
|
}
|
419
432
|
handler(handler) {
|
420
|
-
return
|
433
|
+
return new DecoratedProcedure({
|
421
434
|
middlewares: this["~orpc"].middlewares,
|
422
435
|
contract: new ContractProcedure({
|
423
436
|
InputSchema: void 0,
|
424
|
-
OutputSchema: void 0
|
437
|
+
OutputSchema: void 0,
|
438
|
+
errorMap: void 0
|
425
439
|
}),
|
426
440
|
handler
|
427
|
-
})
|
441
|
+
});
|
428
442
|
}
|
429
443
|
prefix(prefix) {
|
430
444
|
return new RouterBuilder({
|
@@ -449,36 +463,47 @@ var Builder = class _Builder {
|
|
449
463
|
}
|
450
464
|
};
|
451
465
|
|
466
|
+
// src/procedure-utils.ts
|
467
|
+
function call(procedure, input, ...rest) {
|
468
|
+
return createProcedureClient(procedure, ...rest)(input);
|
469
|
+
}
|
470
|
+
|
471
|
+
// src/lazy-utils.ts
|
472
|
+
function createLazyProcedureFormAnyLazy(lazied) {
|
473
|
+
const lazyProcedure = lazy(async () => {
|
474
|
+
const { default: maybeProcedure } = await unlazy(flatLazy(lazied));
|
475
|
+
if (!isProcedure(maybeProcedure)) {
|
476
|
+
throw new Error(`
|
477
|
+
Expected a lazy<procedure> but got lazy<unknown>.
|
478
|
+
This should be caught by TypeScript compilation.
|
479
|
+
Please report this issue if this makes you feel uncomfortable.
|
480
|
+
`);
|
481
|
+
}
|
482
|
+
return { default: maybeProcedure };
|
483
|
+
});
|
484
|
+
return lazyProcedure;
|
485
|
+
}
|
486
|
+
|
452
487
|
// 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
|
-
});
|
488
|
+
function createRouterClient(router, ...rest) {
|
489
|
+
if (isProcedure(router)) {
|
490
|
+
const caller = createProcedureClient(router, ...rest);
|
461
491
|
return caller;
|
462
492
|
}
|
463
|
-
const procedureCaller = isLazy(
|
464
|
-
...options,
|
465
|
-
procedure: createLazyProcedureFormAnyLazy(options.router),
|
466
|
-
context: options.context,
|
467
|
-
path: options.path
|
468
|
-
}) : {};
|
493
|
+
const procedureCaller = isLazy(router) ? createProcedureClient(createLazyProcedureFormAnyLazy(router), ...rest) : {};
|
469
494
|
const recursive = new Proxy(procedureCaller, {
|
470
495
|
get(target, key) {
|
471
496
|
if (typeof key !== "string") {
|
472
497
|
return Reflect.get(target, key);
|
473
498
|
}
|
474
|
-
const next = getRouterChild(
|
499
|
+
const next = getRouterChild(router, key);
|
475
500
|
if (!next) {
|
476
501
|
return Reflect.get(target, key);
|
477
502
|
}
|
478
|
-
|
503
|
+
const [options] = rest;
|
504
|
+
return createRouterClient(next, {
|
479
505
|
...options,
|
480
|
-
|
481
|
-
path: [...options.path ?? [], key]
|
506
|
+
path: [...options?.path ?? [], key]
|
482
507
|
});
|
483
508
|
}
|
484
509
|
});
|
@@ -486,35 +511,39 @@ function createRouterClient(options) {
|
|
486
511
|
}
|
487
512
|
|
488
513
|
// src/index.ts
|
489
|
-
import { configGlobal, fallbackToGlobalConfig } from "@orpc/contract";
|
490
|
-
export * from "@orpc/shared/error";
|
514
|
+
import { configGlobal, fallbackToGlobalConfig, isDefinedError, ORPCError, safe } from "@orpc/contract";
|
491
515
|
var os = new Builder({});
|
492
516
|
export {
|
493
517
|
Builder,
|
518
|
+
DecoratedProcedure,
|
494
519
|
LAZY_LOADER_SYMBOL,
|
520
|
+
ORPCError,
|
495
521
|
Procedure,
|
496
522
|
ProcedureBuilder,
|
497
523
|
ProcedureImplementer,
|
498
524
|
RouterBuilder,
|
499
525
|
RouterImplementer,
|
526
|
+
call,
|
500
527
|
configGlobal,
|
501
528
|
createChainableImplementer,
|
529
|
+
createORPCErrorConstructorMap,
|
502
530
|
createProcedureClient,
|
503
531
|
createRouterClient,
|
504
532
|
decorateLazy,
|
505
533
|
decorateMiddleware,
|
506
|
-
decorateProcedure,
|
507
534
|
deepSetLazyRouterPrefix,
|
508
535
|
fallbackToGlobalConfig,
|
509
536
|
flatLazy,
|
510
537
|
getLazyRouterPrefix,
|
511
538
|
getRouterChild,
|
512
539
|
getRouterContract,
|
540
|
+
isDefinedError,
|
513
541
|
isLazy,
|
514
542
|
isProcedure,
|
515
543
|
lazy,
|
516
544
|
mergeContext,
|
517
545
|
os,
|
546
|
+
safe,
|
518
547
|
setRouterContract,
|
519
548
|
unlazy
|
520
549
|
};
|
package/dist/next.js
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
import "./chunk-WUOGVGWG.js";
|
2
2
|
import {
|
3
|
-
ORPCHandler,
|
4
3
|
ORPCPayloadCodec,
|
5
4
|
ORPCProcedureMatcher,
|
5
|
+
RPCHandler,
|
6
6
|
super_json_exports
|
7
|
-
} from "./chunk-
|
8
|
-
import "./chunk-
|
7
|
+
} from "./chunk-VY6NXNQT.js";
|
8
|
+
import "./chunk-XDC42C3C.js";
|
9
9
|
|
10
10
|
// src/adapters/next/serve.ts
|
11
11
|
import { value } from "@orpc/shared";
|
@@ -27,9 +27,9 @@ function serve(handler, ...[options]) {
|
|
27
27
|
};
|
28
28
|
}
|
29
29
|
export {
|
30
|
-
ORPCHandler,
|
31
30
|
ORPCPayloadCodec,
|
32
31
|
ORPCProcedureMatcher,
|
32
|
+
RPCHandler,
|
33
33
|
super_json_exports as SuperJSON,
|
34
34
|
serve
|
35
35
|
};
|
package/dist/node.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import {
|
2
|
-
|
3
|
-
} from "./chunk-
|
4
|
-
import "./chunk-
|
2
|
+
RPCHandler
|
3
|
+
} from "./chunk-VY6NXNQT.js";
|
4
|
+
import "./chunk-XDC42C3C.js";
|
5
5
|
|
6
6
|
// src/adapters/node/request-listener.ts
|
7
7
|
function createRequest(req, res) {
|
@@ -61,10 +61,10 @@ async function sendResponse(res, response) {
|
|
61
61
|
}
|
62
62
|
|
63
63
|
// src/adapters/node/orpc-handler.ts
|
64
|
-
var
|
64
|
+
var RPCHandler2 = class {
|
65
65
|
orpcFetchHandler;
|
66
66
|
constructor(router, options) {
|
67
|
-
this.orpcFetchHandler = new
|
67
|
+
this.orpcFetchHandler = new RPCHandler(router, options);
|
68
68
|
}
|
69
69
|
async handle(req, res, ...[options]) {
|
70
70
|
const request = createRequest(req, res);
|
@@ -79,7 +79,7 @@ var ORPCHandler2 = class {
|
|
79
79
|
}
|
80
80
|
};
|
81
81
|
export {
|
82
|
-
|
82
|
+
RPCHandler2 as RPCHandler,
|
83
83
|
createHeaders,
|
84
84
|
createRequest,
|
85
85
|
sendResponse
|