@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
@@ -154,44 +154,32 @@ async function validateOutput(procedure, output) {
|
|
154
154
|
}
|
155
155
|
return result.value;
|
156
156
|
}
|
157
|
-
function
|
157
|
+
async function executeProcedureInternal(procedure, options) {
|
158
|
+
const middlewares = procedure["~orpc"].middlewares;
|
159
|
+
const inputValidationIndex = Math.min(Math.max(0, procedure["~orpc"].inputValidationIndex), middlewares.length);
|
160
|
+
const outputValidationIndex = Math.min(Math.max(0, procedure["~orpc"].outputValidationIndex), middlewares.length);
|
158
161
|
let currentIndex = 0;
|
159
|
-
let currentContext =
|
160
|
-
|
161
|
-
|
162
|
+
let currentContext = options.context;
|
163
|
+
let currentInput = options.input;
|
164
|
+
const next = async (nextOptions) => {
|
165
|
+
const index = currentIndex;
|
162
166
|
currentIndex += 1;
|
163
167
|
currentContext = mergeContext(currentContext, nextOptions.context);
|
164
|
-
if (
|
165
|
-
|
168
|
+
if (index === inputValidationIndex) {
|
169
|
+
currentInput = await validateInput(procedure, currentInput);
|
166
170
|
}
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
const result2 = await executeMiddlewareChain(procedure["~orpc"].postMiddlewares, {
|
178
|
-
...options,
|
179
|
-
context,
|
180
|
-
next: async ({ context: context2 }) => {
|
181
|
-
return middlewareOutputFn(
|
182
|
-
await executeHandler(context2, validatedInput)
|
183
|
-
);
|
184
|
-
}
|
185
|
-
}, validatedInput);
|
186
|
-
const validatedOutput = await validateOutput(procedure, result2.output);
|
187
|
-
return { ...result2, output: validatedOutput };
|
171
|
+
const mid = middlewares[index];
|
172
|
+
const result = mid ? await mid({ ...options, context: currentContext, next }, currentInput, middlewareOutputFn) : { output: await procedure["~orpc"].handler({ ...options, context: currentContext, input: currentInput }), context: currentContext };
|
173
|
+
if (index === outputValidationIndex) {
|
174
|
+
const validatedOutput = await validateOutput(procedure, result.output);
|
175
|
+
return {
|
176
|
+
...result,
|
177
|
+
output: validatedOutput
|
178
|
+
};
|
179
|
+
}
|
180
|
+
return result;
|
188
181
|
};
|
189
|
-
|
190
|
-
...options,
|
191
|
-
context: options.context,
|
192
|
-
next: ({ context }) => executePostMiddlewares(context, options.input)
|
193
|
-
}, options.input);
|
194
|
-
return result.output;
|
182
|
+
return (await next({})).output;
|
195
183
|
}
|
196
184
|
|
197
185
|
// src/router.ts
|
@@ -239,4 +227,4 @@ export {
|
|
239
227
|
createProcedureClient,
|
240
228
|
getRouterChild
|
241
229
|
};
|
242
|
-
//# sourceMappingURL=chunk-
|
230
|
+
//# sourceMappingURL=chunk-GK2Z6B6W.js.map
|
@@ -4,7 +4,7 @@ import {
|
|
4
4
|
getRouterChild,
|
5
5
|
isProcedure,
|
6
6
|
unlazy
|
7
|
-
} from "./chunk-
|
7
|
+
} from "./chunk-GK2Z6B6W.js";
|
8
8
|
|
9
9
|
// src/adapters/fetch/super-json.ts
|
10
10
|
var super_json_exports = {};
|
@@ -298,4 +298,4 @@ export {
|
|
298
298
|
ORPCProcedureMatcher,
|
299
299
|
RPCHandler
|
300
300
|
};
|
301
|
-
//# sourceMappingURL=chunk-
|
301
|
+
//# sourceMappingURL=chunk-SXUFCJBY.js.map
|
package/dist/fetch.js
CHANGED
package/dist/hono.js
CHANGED
@@ -4,8 +4,8 @@ import {
|
|
4
4
|
ORPCProcedureMatcher,
|
5
5
|
RPCHandler,
|
6
6
|
super_json_exports
|
7
|
-
} from "./chunk-
|
8
|
-
import "./chunk-
|
7
|
+
} from "./chunk-SXUFCJBY.js";
|
8
|
+
import "./chunk-GK2Z6B6W.js";
|
9
9
|
|
10
10
|
// src/adapters/hono/middleware.ts
|
11
11
|
import { value } from "@orpc/shared";
|