@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.
@@ -154,44 +154,32 @@ async function validateOutput(procedure, output) {
154
154
  }
155
155
  return result.value;
156
156
  }
157
- function executeMiddlewareChain(middlewares, opt, input) {
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 = opt.context;
160
- const executeMiddlewareChain2 = async (nextOptions) => {
161
- const mid = middlewares[currentIndex];
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 (mid) {
165
- return await mid({ ...opt, context: currentContext, next: executeMiddlewareChain2 }, input, middlewareOutputFn);
168
+ if (index === inputValidationIndex) {
169
+ currentInput = await validateInput(procedure, currentInput);
166
170
  }
167
- return opt.next({ context: currentContext });
168
- };
169
- return executeMiddlewareChain2({});
170
- }
171
- async function executeProcedureInternal(procedure, options) {
172
- const executeHandler = async (context, input) => {
173
- return await procedure["~orpc"].handler({ ...options, context, input });
174
- };
175
- const executePostMiddlewares = async (context, input) => {
176
- const validatedInput = await validateInput(procedure, input);
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
- const result = await executeMiddlewareChain(procedure["~orpc"].preMiddlewares, {
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-SA7HGGVY.js.map
230
+ //# sourceMappingURL=chunk-GK2Z6B6W.js.map
@@ -4,7 +4,7 @@ import {
4
4
  getRouterChild,
5
5
  isProcedure,
6
6
  unlazy
7
- } from "./chunk-SA7HGGVY.js";
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-2HRHHZJD.js.map
301
+ //# sourceMappingURL=chunk-SXUFCJBY.js.map
package/dist/fetch.js CHANGED
@@ -4,8 +4,8 @@ import {
4
4
  ORPCProcedureMatcher,
5
5
  RPCHandler,
6
6
  super_json_exports
7
- } from "./chunk-2HRHHZJD.js";
8
- import "./chunk-SA7HGGVY.js";
7
+ } from "./chunk-SXUFCJBY.js";
8
+ import "./chunk-GK2Z6B6W.js";
9
9
  export {
10
10
  ORPCPayloadCodec,
11
11
  ORPCProcedureMatcher,
package/dist/hono.js CHANGED
@@ -4,8 +4,8 @@ import {
4
4
  ORPCProcedureMatcher,
5
5
  RPCHandler,
6
6
  super_json_exports
7
- } from "./chunk-2HRHHZJD.js";
8
- import "./chunk-SA7HGGVY.js";
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";