@orpc/server 0.0.0-next.4220427 → 0.0.0-next.43889a7
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/{chunk-V3I7RIRY.js → chunk-26GHKV43.js} +6 -7
- package/dist/{chunk-DNG2IB3R.js → chunk-LDIL7OEP.js} +40 -50
- package/dist/fetch.js +4 -4
- package/dist/hono.js +5 -5
- package/dist/index.js +687 -181
- package/dist/next.js +5 -5
- package/dist/node.js +10 -10
- package/dist/src/adapters/fetch/orpc-handler.d.ts +4 -4
- package/dist/src/adapters/fetch/types.d.ts +3 -3
- package/dist/src/adapters/hono/middleware.d.ts +3 -3
- package/dist/src/adapters/next/serve.d.ts +3 -3
- package/dist/src/adapters/node/orpc-handler.d.ts +5 -5
- package/dist/src/adapters/node/types.d.ts +3 -3
- package/dist/src/builder-with-errors-middlewares.d.ts +49 -0
- package/dist/src/builder-with-errors.d.ts +49 -0
- package/dist/src/builder-with-middlewares.d.ts +49 -0
- package/dist/src/builder.d.ts +33 -23
- package/dist/src/config.d.ts +6 -0
- package/dist/src/context.d.ts +10 -0
- package/dist/src/error.d.ts +1 -1
- package/dist/src/hidden.d.ts +2 -2
- package/dist/src/implementer-chainable.d.ts +11 -5
- package/dist/src/index.d.ts +5 -4
- package/dist/src/lazy-decorated.d.ts +4 -6
- package/dist/src/middleware-decorated.d.ts +5 -5
- package/dist/src/middleware.d.ts +19 -15
- package/dist/src/procedure-builder-with-input.d.ts +35 -0
- package/dist/src/procedure-builder-with-output.d.ts +34 -0
- package/dist/src/procedure-builder.d.ts +23 -19
- package/dist/src/procedure-client.d.ts +8 -21
- package/dist/src/procedure-decorated.d.ts +21 -11
- package/dist/src/procedure-implementer.d.ts +14 -10
- package/dist/src/procedure-utils.d.ts +17 -0
- package/dist/src/procedure.d.ts +16 -12
- package/dist/src/router-builder.d.ts +20 -16
- package/dist/src/router-client.d.ts +7 -6
- package/dist/src/router-implementer.d.ts +12 -10
- package/dist/src/router.d.ts +4 -4
- package/dist/src/types.d.ts +0 -3
- package/package.json +3 -3
- package/dist/src/utils.d.ts +0 -3
@@ -4,7 +4,7 @@ import {
|
|
4
4
|
getRouterChild,
|
5
5
|
isProcedure,
|
6
6
|
unlazy
|
7
|
-
} from "./chunk-
|
7
|
+
} from "./chunk-LDIL7OEP.js";
|
8
8
|
|
9
9
|
// src/adapters/fetch/super-json.ts
|
10
10
|
var super_json_exports = {};
|
@@ -238,7 +238,7 @@ var ORPCProcedureMatcher = class {
|
|
238
238
|
// src/adapters/fetch/orpc-handler.ts
|
239
239
|
import { ORPCError as ORPCError2 } from "@orpc/contract";
|
240
240
|
import { executeWithHooks, trim as trim2 } from "@orpc/shared";
|
241
|
-
var
|
241
|
+
var RPCHandler = class {
|
242
242
|
constructor(router, options) {
|
243
243
|
this.options = options;
|
244
244
|
this.procedureMatcher = options?.procedureMatcher ?? new ORPCProcedureMatcher(router);
|
@@ -247,7 +247,7 @@ var ORPCHandler = class {
|
|
247
247
|
procedureMatcher;
|
248
248
|
payloadCodec;
|
249
249
|
async handle(request, ...[options]) {
|
250
|
-
const context = options?.context;
|
250
|
+
const context = options?.context ?? {};
|
251
251
|
const execute = async () => {
|
252
252
|
const url = new URL(request.url);
|
253
253
|
const pathname = `/${trim2(url.pathname.replace(options?.prefix ?? "", ""), "/")}`;
|
@@ -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-26GHKV43.js.map
|
@@ -4,18 +4,6 @@ var __export = (target, all) => {
|
|
4
4
|
__defProp(target, name, { get: all[name], enumerable: true });
|
5
5
|
};
|
6
6
|
|
7
|
-
// src/utils.ts
|
8
|
-
function mergeContext(a, b) {
|
9
|
-
if (!a)
|
10
|
-
return b;
|
11
|
-
if (!b)
|
12
|
-
return a;
|
13
|
-
return {
|
14
|
-
...a,
|
15
|
-
...b
|
16
|
-
};
|
17
|
-
}
|
18
|
-
|
19
7
|
// src/procedure.ts
|
20
8
|
import { isContractProcedure } from "@orpc/contract";
|
21
9
|
var Procedure = class {
|
@@ -36,9 +24,6 @@ function isProcedure(item) {
|
|
36
24
|
import { ORPCError } from "@orpc/contract";
|
37
25
|
function createORPCErrorConstructorMap(errors) {
|
38
26
|
const constructors = {};
|
39
|
-
if (!errors) {
|
40
|
-
return constructors;
|
41
|
-
}
|
42
27
|
for (const code in errors) {
|
43
28
|
const config = errors[code];
|
44
29
|
if (!config) {
|
@@ -86,38 +71,35 @@ function flatLazy(lazied) {
|
|
86
71
|
return lazy(flattenLoader);
|
87
72
|
}
|
88
73
|
|
74
|
+
// src/middleware.ts
|
75
|
+
function middlewareOutputFn(output) {
|
76
|
+
return { output, context: {} };
|
77
|
+
}
|
78
|
+
|
89
79
|
// src/procedure-client.ts
|
90
80
|
import { ORPCError as ORPCError2, validateORPCError, ValidationError } from "@orpc/contract";
|
91
81
|
import { executeWithHooks, toError, value } from "@orpc/shared";
|
92
|
-
function createProcedureClient(options) {
|
82
|
+
function createProcedureClient(lazyableProcedure, ...[options]) {
|
93
83
|
return async (...[input, callerOptions]) => {
|
94
|
-
const path = options
|
95
|
-
const { default: procedure } = await unlazy(
|
96
|
-
const context = await value(options
|
97
|
-
const
|
84
|
+
const path = options?.path ?? [];
|
85
|
+
const { default: procedure } = await unlazy(lazyableProcedure);
|
86
|
+
const context = await value(options?.context ?? {}, callerOptions?.context);
|
87
|
+
const errors = createORPCErrorConstructorMap(procedure["~orpc"].contract["~orpc"].errorMap);
|
88
|
+
const executeOptions = {
|
89
|
+
input,
|
90
|
+
context,
|
91
|
+
errors,
|
98
92
|
path,
|
99
93
|
procedure,
|
100
94
|
signal: callerOptions?.signal
|
101
95
|
};
|
102
|
-
const executeWithValidation = async () => {
|
103
|
-
const validInput = await validateInput(procedure, input);
|
104
|
-
const output = await executeMiddlewareChain({
|
105
|
-
context,
|
106
|
-
input: validInput,
|
107
|
-
path,
|
108
|
-
procedure,
|
109
|
-
signal: callerOptions?.signal,
|
110
|
-
errors: createORPCErrorConstructorMap(procedure["~orpc"].contract["~orpc"].errorMap)
|
111
|
-
});
|
112
|
-
return validateOutput(procedure, output);
|
113
|
-
};
|
114
96
|
try {
|
115
97
|
const output = await executeWithHooks({
|
116
98
|
hooks: options,
|
117
99
|
input,
|
118
100
|
context,
|
119
|
-
meta,
|
120
|
-
execute:
|
101
|
+
meta: executeOptions,
|
102
|
+
execute: () => executeProcedureInternal(procedure, executeOptions)
|
121
103
|
});
|
122
104
|
return output;
|
123
105
|
} catch (e) {
|
@@ -160,21 +142,29 @@ async function validateOutput(procedure, output) {
|
|
160
142
|
}
|
161
143
|
return result.value;
|
162
144
|
}
|
163
|
-
async function
|
164
|
-
const middlewares =
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
145
|
+
async function executeProcedureInternal(procedure, options) {
|
146
|
+
const middlewares = procedure["~orpc"].middlewares;
|
147
|
+
const inputValidationIndex = Math.min(Math.max(0, procedure["~orpc"].inputValidationIndex), middlewares.length);
|
148
|
+
const outputValidationIndex = Math.min(Math.max(0, procedure["~orpc"].outputValidationIndex), middlewares.length);
|
149
|
+
let currentIndex = 0;
|
150
|
+
let currentContext = options.context;
|
151
|
+
let currentInput = options.input;
|
152
|
+
const next = async (...[nextOptions]) => {
|
153
|
+
const index = currentIndex;
|
154
|
+
currentIndex += 1;
|
155
|
+
currentContext = { ...currentContext, ...nextOptions?.context };
|
156
|
+
if (index === inputValidationIndex) {
|
157
|
+
currentInput = await validateInput(procedure, currentInput);
|
158
|
+
}
|
159
|
+
const mid = middlewares[index];
|
160
|
+
const result = mid ? await mid({ ...options, context: currentContext, next }, currentInput, middlewareOutputFn) : { output: await procedure["~orpc"].handler({ ...options, context: currentContext, input: currentInput }), context: currentContext };
|
161
|
+
if (index === outputValidationIndex) {
|
162
|
+
const validatedOutput = await validateOutput(procedure, result.output);
|
163
|
+
return {
|
164
|
+
...result,
|
165
|
+
output: validatedOutput
|
166
|
+
};
|
173
167
|
}
|
174
|
-
const result = {
|
175
|
-
output: await opt.procedure["~orpc"].handler({ ...opt, context: currentContext }),
|
176
|
-
context: currentContext
|
177
|
-
};
|
178
168
|
return result;
|
179
169
|
};
|
180
170
|
return (await next({})).output;
|
@@ -212,7 +202,6 @@ function getRouterChild(router, ...path) {
|
|
212
202
|
|
213
203
|
export {
|
214
204
|
__export,
|
215
|
-
mergeContext,
|
216
205
|
Procedure,
|
217
206
|
isProcedure,
|
218
207
|
createORPCErrorConstructorMap,
|
@@ -221,7 +210,8 @@ export {
|
|
221
210
|
isLazy,
|
222
211
|
unlazy,
|
223
212
|
flatLazy,
|
213
|
+
middlewareOutputFn,
|
224
214
|
createProcedureClient,
|
225
215
|
getRouterChild
|
226
216
|
};
|
227
|
-
//# sourceMappingURL=chunk-
|
217
|
+
//# sourceMappingURL=chunk-LDIL7OEP.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-26GHKV43.js";
|
8
|
+
import "./chunk-LDIL7OEP.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,17 +1,17 @@
|
|
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-26GHKV43.js";
|
8
|
+
import "./chunk-LDIL7OEP.js";
|
9
9
|
|
10
10
|
// src/adapters/hono/middleware.ts
|
11
11
|
import { value } from "@orpc/shared";
|
12
12
|
function createMiddleware(handler, ...[options]) {
|
13
13
|
return async (c, next) => {
|
14
|
-
const context = await value(options?.context, c);
|
14
|
+
const context = await value(options?.context ?? {}, c);
|
15
15
|
const { matched, response } = await handler.handle(c.req.raw, { ...options, context });
|
16
16
|
if (matched) {
|
17
17
|
c.res = response;
|
@@ -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
|
};
|