@temporary-name/server 1.9.3-alpha.5c041722542bb790586629fc98d4c72d9f6ee65e → 1.9.3-alpha.5dc8b200530586870ac736830d4584e0333cfd05

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.
Files changed (33) hide show
  1. package/dist/adapters/aws-lambda/index.d.mts +3 -4
  2. package/dist/adapters/aws-lambda/index.d.ts +3 -4
  3. package/dist/adapters/aws-lambda/index.mjs +3 -3
  4. package/dist/adapters/fetch/index.d.mts +3 -4
  5. package/dist/adapters/fetch/index.d.ts +3 -4
  6. package/dist/adapters/fetch/index.mjs +3 -3
  7. package/dist/adapters/node/index.d.mts +3 -4
  8. package/dist/adapters/node/index.d.ts +3 -4
  9. package/dist/adapters/node/index.mjs +3 -3
  10. package/dist/adapters/standard/index.d.mts +10 -6
  11. package/dist/adapters/standard/index.d.ts +10 -6
  12. package/dist/adapters/standard/index.mjs +4 -4
  13. package/dist/helpers/index.mjs +3 -29
  14. package/dist/index.d.mts +29 -23
  15. package/dist/index.d.ts +29 -23
  16. package/dist/index.mjs +121 -15
  17. package/dist/openapi/index.d.mts +1 -1
  18. package/dist/openapi/index.d.ts +1 -1
  19. package/dist/openapi/index.mjs +51 -34
  20. package/dist/plugins/index.d.mts +4 -80
  21. package/dist/plugins/index.d.ts +4 -80
  22. package/dist/plugins/index.mjs +17 -189
  23. package/dist/shared/{server.C4l2ZA3m.d.ts → server.B-meye9-.d.ts} +2 -3
  24. package/dist/shared/{server.SmOM3Fae.mjs → server.Ba0Z2fNc.mjs} +18 -26
  25. package/dist/shared/server.C1RJffw4.mjs +30 -0
  26. package/dist/shared/{server.B5czSQQh.d.mts → server.DkYpsO6W.d.mts} +71 -55
  27. package/dist/shared/{server.B5czSQQh.d.ts → server.DkYpsO6W.d.ts} +71 -55
  28. package/dist/shared/{server.D7UjcuIv.d.ts → server.DwNnHUZP.d.ts} +2 -2
  29. package/dist/shared/{server.Bk8Hmx7Z.d.mts → server.I-tTl_ce.d.mts} +2 -2
  30. package/dist/shared/{server.Kxw442A9.mjs → server.JtIZ8YG7.mjs} +1 -11
  31. package/dist/shared/{server.BdGbIyq8.mjs → server.miXh-9wo.mjs} +38 -18
  32. package/dist/shared/{server.TgmlNh8r.d.mts → server.vLcMd_kA.d.mts} +2 -3
  33. package/package.json +10 -22
@@ -1,9 +1,12 @@
1
- import { ErrorMap, ErrorMapItem, InferSchemaInput, Schemas, Meta, ContractProcedureDef, AnyContractRouter, ContractProcedure, InferSchemaOutput, EnhanceRouteOptions, MergedErrorMap, AnyContractProcedure, ContractRouter, AnySchema, ErrorFromErrorMap } from '@temporary-name/contract';
2
- import { ORPCErrorCode, MaybeOptionalOptions, ORPCErrorOptions, ORPCError, Promisable, HTTPPath, ClientContext, Interceptor, PromiseWithError, Value, Client } from '@temporary-name/shared';
1
+ import { ErrorMap, ErrorMapItem, InferSchemaInput, Meta, Schemas, ContractProcedureDef, AnyContractRouter, ContractProcedure, InferProcedureClientInputs, InferSchemaOutput, EnhanceRouteOptions, MergedErrorMap, AnyContractProcedure, ContractRouter, AnySchema, ErrorFromErrorMap } from '@temporary-name/contract';
2
+ import { ORPCErrorCode, MaybeOptionalOptions, ORPCErrorOptions, ORPCError, Promisable, StandardLazyRequest, HTTPPath, ClientContext, Interceptor, PromiseWithError, Value, Client } from '@temporary-name/shared';
3
3
 
4
4
  type Context = Record<PropertyKey, any>;
5
5
  type MergedInitialContext<TInitial extends Context, TAdditional extends Context, TCurrent extends Context> = TInitial & Omit<TAdditional, keyof TCurrent>;
6
6
  type MergedCurrentContext<T extends Context, U extends Context> = Omit<T, keyof U> & U;
7
+ type BuildContextWithAuth<TContext extends Context, TAuthContext> = MergedCurrentContext<TContext, {
8
+ auth: TAuthContext | ('auth' extends keyof TContext ? TContext['auth'] : never);
9
+ }>;
7
10
  declare function mergeCurrentContext<T extends Context, U extends Context>(context: T, other: U): MergedCurrentContext<T, U>;
8
11
 
9
12
  type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'defined' | 'status'>;
@@ -13,21 +16,56 @@ type ORPCErrorConstructorMap<T extends ErrorMap> = {
13
16
  };
14
17
  declare function createORPCErrorConstructorMap<T extends ErrorMap>(errors: T): ORPCErrorConstructorMap<T>;
15
18
 
16
- interface ProcedureHandlerOptions<TCurrentContext extends Context, TInput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
19
+ type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
20
+ output: TOutput;
21
+ context: TOutContext;
22
+ }>;
23
+ interface MiddlewareNextFn<TOutput> {
24
+ <U extends Context = {}>(options?: {
25
+ context?: U;
26
+ }): MiddlewareResult<U, TOutput>;
27
+ }
28
+ interface MiddlewareOutputFn<TOutput> {
29
+ (output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
30
+ }
31
+ interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> extends ProcedureHandlerOptions<TInContext, TErrorConstructorMap, TMeta> {
32
+ next: MiddlewareNextFn<TOutput>;
33
+ }
34
+ /**
35
+ * A function that represents a middleware.
36
+ *
37
+ * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
38
+ */
39
+ interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
40
+ (options: MiddlewareOptions<TInContext, TOutput, TErrorConstructorMap, TMeta>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
41
+ }
42
+ type AnyMiddleware = Middleware<any, any, any, any, any, any>;
43
+ interface MapInputMiddleware<TInput, TMappedInput> {
44
+ (input: TInput): TMappedInput;
45
+ }
46
+ declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
47
+
48
+ type DefaultProcedureHandlerOptions = ProcedureHandlerOptions<Context, ORPCErrorConstructorMap<ErrorMap>, Meta>;
49
+ interface ProcedureHandlerOptions<TCurrentContext extends Context, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
17
50
  context: TCurrentContext;
18
- input: TInput;
19
51
  path: readonly string[];
20
52
  procedure: Procedure<Context, Context, Schemas, ErrorMap, TMeta>;
21
53
  signal?: AbortSignal;
54
+ request?: StandardLazyRequest;
22
55
  lastEventId: string | undefined;
23
56
  errors: TErrorConstructorMap;
24
57
  }
25
- interface ProcedureHandler<TCurrentContext extends Context, TInput, THandlerOutput, TErrorMap extends ErrorMap, TMeta extends Meta> {
26
- (opt: ProcedureHandlerOptions<TCurrentContext, TInput, ORPCErrorConstructorMap<TErrorMap>, TMeta>): Promisable<THandlerOutput>;
58
+ interface ProcedureHandler<TCurrentContext extends Context, TInput extends {
59
+ path: any;
60
+ query: any;
61
+ body: any;
62
+ }, THandlerOutput, TErrorMap extends ErrorMap, TMeta extends Meta> {
63
+ (input: TInput, opt: ProcedureHandlerOptions<TCurrentContext, ORPCErrorConstructorMap<TErrorMap>, TMeta>): Promisable<THandlerOutput>;
27
64
  }
28
65
  interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TSchemas, TErrorMap, TMeta> {
29
66
  __initialContext?: (type: TInitialContext) => unknown;
30
67
  middlewares: readonly AnyMiddleware[];
68
+ authConfigs: TypedAuthConfig[];
31
69
  inputValidationIndex: number;
32
70
  outputValidationIndex: number;
33
71
  handler: ProcedureHandler<TCurrentContext, any, any, any, any>;
@@ -47,43 +85,23 @@ declare class Procedure<TInitialContext extends Context, TCurrentContext extends
47
85
  type AnyProcedure = Procedure<any, any, Schemas, any, any>;
48
86
  declare function isProcedure(item: unknown): item is AnyProcedure;
49
87
 
50
- type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
51
- output: TOutput;
52
- context: TOutContext;
53
- }>;
54
- type MiddlewareNextFnOptions<TOutContext extends Context> = Record<never, never> extends TOutContext ? {
55
- context?: TOutContext;
56
- } : {
57
- context: TOutContext;
58
- };
59
- interface MiddlewareNextFn<TOutput> {
60
- <U extends Context = Record<never, never>>(...rest: MaybeOptionalOptions<MiddlewareNextFnOptions<U>>): MiddlewareResult<U, TOutput>;
61
- }
62
- interface MiddlewareOutputFn<TOutput> {
63
- (output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
64
- }
65
- interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
66
- context: TInContext;
67
- path: readonly string[];
68
- procedure: Procedure<Context, Context, Schemas, ErrorMap, TMeta>;
69
- signal?: AbortSignal;
70
- lastEventId: string | undefined;
71
- next: MiddlewareNextFn<TOutput>;
72
- errors: TErrorConstructorMap;
73
- }
74
- /**
75
- * A function that represents a middleware.
76
- *
77
- * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
78
- */
79
- interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
80
- (options: MiddlewareOptions<TInContext, TOutput, TErrorConstructorMap, TMeta>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
81
- }
82
- type AnyMiddleware = Middleware<any, any, any, any, any, any>;
83
- interface MapInputMiddleware<TInput, TMappedInput> {
84
- (input: TInput): TMappedInput;
85
- }
86
- declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
88
+ type ValidatedAuthContext = {};
89
+ interface BasicAuthConfig<TAuthContext extends ValidatedAuthContext, TCurrentContext extends Context, TMeta extends Meta> {
90
+ tokenPrefix?: string;
91
+ validate: (username: string, password: string, options: ProcedureHandlerOptions<TCurrentContext, ORPCErrorConstructorMap<any>, TMeta>) => Promisable<TAuthContext>;
92
+ }
93
+ interface TokenAuthConfig<TAuthContext extends ValidatedAuthContext, TCurrentContext extends Context, TMeta extends Meta> {
94
+ tokenPrefix?: string;
95
+ validate: (token: string, options: ProcedureHandlerOptions<TCurrentContext, ORPCErrorConstructorMap<any>, TMeta>) => Promisable<TAuthContext>;
96
+ }
97
+ interface NamedTokenAuthConfig<TAuthContext extends ValidatedAuthContext, TCurrentContext extends Context, TMeta extends Meta> extends TokenAuthConfig<TAuthContext, TCurrentContext, TMeta> {
98
+ name: string;
99
+ }
100
+ type AuthType = 'header' | 'query' | 'cookie' | 'bearer' | 'basic' | 'none';
101
+ type AuthConfig<TAuthType extends AuthType, TAuthContext extends ValidatedAuthContext = ValidatedAuthContext, TCurrentContext extends Context = Context, TMeta extends Meta = Meta> = TAuthType extends 'basic' ? BasicAuthConfig<TAuthContext, TCurrentContext, TMeta> : TAuthType extends 'bearer' ? TokenAuthConfig<TAuthContext, TCurrentContext, TMeta> : TAuthType extends 'header' ? NamedTokenAuthConfig<TAuthContext, TCurrentContext, TMeta> : TAuthType extends 'query' ? NamedTokenAuthConfig<TAuthContext, TCurrentContext, TMeta> : TAuthType extends 'cookie' ? NamedTokenAuthConfig<TAuthContext, TCurrentContext, TMeta> : TAuthType extends 'none' ? {} : never;
102
+ type TypedAuthConfig<TAuthType extends AuthType = AuthType> = {
103
+ type: TAuthType;
104
+ } & AuthConfig<TAuthType, object>;
87
105
 
88
106
  /**
89
107
  * Represents a router, which defines a hierarchical structure of procedures.
@@ -120,7 +138,7 @@ type InferRouterCurrentContexts<T extends AnyRouter> = T extends Procedure<any,
120
138
  * @info A procedure is a router too.
121
139
  * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
122
140
  */
123
- type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer USchemas, any, any> ? InferSchemaInput<USchemas['inputSchema']> : {
141
+ type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer USchemas, any, any> ? InferProcedureClientInputs<USchemas> : {
124
142
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never;
125
143
  };
126
144
  /**
@@ -203,15 +221,13 @@ declare function unlazy<T extends Lazyable<any>>(lazied: T): Promise<{
203
221
  default: T extends Lazy<infer U> ? U : T;
204
222
  }>;
205
223
 
206
- type ProcedureClient<TClientContext extends ClientContext, TSchemas extends Schemas, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TSchemas['inputSchema']>, InferSchemaOutput<TSchemas['outputSchema']>, ErrorFromErrorMap<TErrorMap>>;
207
- interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TErrorMap extends ErrorMap, TMeta extends Meta> {
208
- context: TInitialContext;
209
- input: unknown;
210
- errors: ORPCErrorConstructorMap<TErrorMap>;
211
- path: readonly string[];
212
- procedure: Procedure<Context, Context, Schemas, ErrorMap, TMeta>;
213
- signal?: AbortSignal;
214
- lastEventId: string | undefined;
224
+ type ProcedureClient<TClientContext extends ClientContext, TSchemas extends Schemas, TErrorMap extends ErrorMap> = Client<TClientContext, InferProcedureClientInputs<TSchemas>, InferSchemaOutput<TSchemas['outputSchema']>, ErrorFromErrorMap<TErrorMap>>;
225
+ interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TErrorMap extends ErrorMap, TMeta extends Meta> extends ProcedureHandlerOptions<TInitialContext, ORPCErrorConstructorMap<TErrorMap>, TMeta> {
226
+ input: {
227
+ path: unknown;
228
+ query: unknown;
229
+ body: unknown;
230
+ };
215
231
  }
216
232
  type CreateProcedureClientOptions<TInitialContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext> = {
217
233
  /**
@@ -231,5 +247,5 @@ type CreateProcedureClientOptions<TInitialContext extends Context, TOutputSchema
231
247
  */
232
248
  declare function createProcedureClient<TInitialContext extends Context, TSchemas extends Schemas, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TSchemas, TErrorMap, TMeta>>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TSchemas['outputSchema'], TErrorMap, TMeta, TClientContext>>): ProcedureClient<TClientContext, TSchemas, TErrorMap>;
233
249
 
234
- export { traverseContractProcedures as $, middlewareOutputFn as B, isProcedure as G, createProcedureClient as J, Procedure as P, getRouter as T, createAccessibleLazyRouter as V, enhanceRouter as W, resolveContractProcedures as a0, unlazyRouter as a2, mergeCurrentContext as m, createORPCErrorConstructorMap as n, LAZY_SYMBOL as o, lazyInternal as q, lazy as r, isLazy as s, getLazyMeta as t, unlazy as u };
235
- export type { AnyMiddleware as A, Context as C, ProcedureHandlerOptions as D, EnhanceRouterOptions as E, ProcedureDef as F, ProcedureClientInterceptorOptions as H, InferRouterInitialContext as I, InferRouterInitialContexts as K, Lazy as L, Middleware as M, InferRouterCurrentContexts as N, ORPCErrorConstructorMap as O, InferRouterInputs as Q, Router as R, InferRouterOutputs as S, AccessibleLazyRouter as U, TraverseContractProceduresOptions as X, TraverseContractProcedureCallbackOptions as Y, ContractProcedureCallbackOptions as Z, LazyTraverseContractProceduresOptions as _, CreateProcedureClientOptions as a, UnlaziedRouter as a1, ProcedureClient as b, MergedInitialContext as c, MergedCurrentContext as d, ProcedureHandler as e, EnhancedRouter as f, MapInputMiddleware as g, AnyProcedure as h, Lazyable as i, AnyRouter as j, ORPCErrorConstructorMapItemOptions as k, ORPCErrorConstructorMapItem as l, LazyMeta as p, MiddlewareResult as v, MiddlewareNextFnOptions as w, MiddlewareNextFn as x, MiddlewareOutputFn as y, MiddlewareOptions as z };
250
+ export { enhanceRouter as $, middlewareOutputFn as F, isProcedure as K, Procedure as P, createProcedureClient as Q, getRouter as Y, createAccessibleLazyRouter as _, traverseContractProcedures as a4, resolveContractProcedures as a5, unlazyRouter as a7, mergeCurrentContext as m, createORPCErrorConstructorMap as p, LAZY_SYMBOL as q, lazyInternal as s, lazy as t, isLazy as u, getLazyMeta as v, unlazy as w };
251
+ export type { AuthType as A, BuildContextWithAuth as B, Context as C, MiddlewareOptions as D, EnhanceRouterOptions as E, DefaultProcedureHandlerOptions as G, ProcedureHandlerOptions as H, InferRouterInitialContext as I, ProcedureDef as J, Lazy as L, Middleware as M, ProcedureClientInterceptorOptions as N, ORPCErrorConstructorMap as O, Router as R, InferRouterInitialContexts as S, TypedAuthConfig as T, InferRouterCurrentContexts as U, ValidatedAuthContext as V, InferRouterInputs as W, InferRouterOutputs as X, AccessibleLazyRouter as Z, CreateProcedureClientOptions as a, TraverseContractProceduresOptions as a0, TraverseContractProcedureCallbackOptions as a1, ContractProcedureCallbackOptions as a2, LazyTraverseContractProceduresOptions as a3, UnlaziedRouter as a6, ProcedureClient as b, MergedInitialContext as c, MergedCurrentContext as d, AuthConfig as e, ProcedureHandler as f, EnhancedRouter as g, MapInputMiddleware as h, AnyMiddleware as i, AnyProcedure as j, Lazyable as k, AnyRouter as l, ORPCErrorConstructorMapItemOptions as n, ORPCErrorConstructorMapItem as o, LazyMeta as r, MiddlewareResult as x, MiddlewareNextFn as y, MiddlewareOutputFn as z };
@@ -1,6 +1,6 @@
1
1
  import { HTTPPath } from '@temporary-name/shared';
2
- import { C as Context } from './server.B5czSQQh.js';
3
- import { c as StandardHandleOptions } from './server.C4l2ZA3m.js';
2
+ import { C as Context } from './server.DkYpsO6W.js';
3
+ import { c as StandardHandleOptions } from './server.B-meye9-.js';
4
4
 
5
5
  type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
6
6
  context?: T;
@@ -1,6 +1,6 @@
1
1
  import { HTTPPath } from '@temporary-name/shared';
2
- import { C as Context } from './server.B5czSQQh.mjs';
3
- import { c as StandardHandleOptions } from './server.TgmlNh8r.mjs';
2
+ import { C as Context } from './server.DkYpsO6W.mjs';
3
+ import { c as StandardHandleOptions } from './server.vLcMd_kA.mjs';
4
4
 
5
5
  type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
6
6
  context?: T;
@@ -234,14 +234,4 @@ function deserialize(data) {
234
234
  return data;
235
235
  }
236
236
 
237
- function standardizeHTTPPath(path) {
238
- return `/${path.replace(/\/{2,}/g, "/").replace(/^\/|\/$/g, "")}`;
239
- }
240
- function getDynamicParams(path) {
241
- return path ? standardizeHTTPPath(path).match(/\/\{[^}]+\}/g)?.map((v) => ({
242
- raw: v,
243
- name: v.match(/\{\+?([^}]+)\}/)[1]
244
- })) : void 0;
245
- }
246
-
247
- export { standardizeHTTPPath as a, bracketNotationDeserialize as b, deserialize as d, getDynamicParams as g, jsonSerialize as j, serialize as s };
237
+ export { bracketNotationDeserialize as b, deserialize as d, jsonSerialize as j, serialize as s };
@@ -1,7 +1,7 @@
1
1
  import { isContractProcedure, mergePrefix, mergeErrorMap, enhanceRoute, validateORPCError, ValidationError } from '@temporary-name/contract';
2
2
  import { resolveMaybeOptionalOptions, ORPCError, toArray, value, runWithSpan, intercept, isAsyncIteratorObject, overlayProxy, asyncIteratorWithSpan } from '@temporary-name/shared';
3
3
  import { HibernationEventIterator, mapEventIterator } from '@temporary-name/standard-server';
4
- import { safeParseAsync } from '@temporary-name/zod';
4
+ import { safeDecodeAsync, safeEncodeAsync } from '@temporary-name/zod';
5
5
 
6
6
  function isStartWithMiddlewares(middlewares, compare) {
7
7
  if (compare.length > middlewares.length) {
@@ -269,14 +269,17 @@ function createProcedureClient(lazyableProcedure, ...rest) {
269
269
  {
270
270
  context,
271
271
  input,
272
- // input only optional when it undefinable so we can safely cast it
273
272
  errors,
274
273
  path,
275
274
  procedure,
275
+ request: callerOptions?.request,
276
276
  signal: callerOptions?.signal,
277
277
  lastEventId: callerOptions?.lastEventId
278
278
  },
279
- (interceptorOptions) => executeProcedureInternal(interceptorOptions.procedure, interceptorOptions)
279
+ (interceptorOptions) => {
280
+ const { input: input2, ...opts } = interceptorOptions;
281
+ return executeProcedureInternal(interceptorOptions.procedure, input2, opts);
282
+ }
280
283
  );
281
284
  });
282
285
  if (isAsyncIteratorObject(output)) {
@@ -304,26 +307,40 @@ function createProcedureClient(lazyableProcedure, ...rest) {
304
307
  };
305
308
  }
306
309
  async function validateInput(procedure, input) {
307
- const schema = procedure["~orpc"].schemas.inputSchema;
308
- if (!schema) {
309
- return input;
310
- }
310
+ const schemas = procedure["~orpc"].schemas;
311
311
  return runWithSpan({ name: "validate_input" }, async () => {
312
- const result = await safeParseAsync(schema, input);
313
- if (!result.success) {
312
+ const resultBody = await safeDecodeAsync(schemas.bodySchema, input.body, { parseType: "body" });
313
+ const resultPath = await safeDecodeAsync(schemas.pathSchema, input.path, { parseType: "path" });
314
+ const resultQuery = await safeDecodeAsync(schemas.querySchema, input.query, { parseType: "query" });
315
+ const issues = [];
316
+ if (!resultBody.success) {
317
+ issues.push(...resultBody.error.issues.map((i) => ({ ...i, path: ["body", ...i.path] })));
318
+ }
319
+ if (!resultPath.success) {
320
+ issues.push(...resultPath.error.issues.map((i) => ({ ...i, path: ["path", ...i.path] })));
321
+ }
322
+ if (!resultQuery.success) {
323
+ issues.push(...resultQuery.error.issues.map((i) => ({ ...i, path: ["query", ...i.path] })));
324
+ }
325
+ if (issues.length > 0) {
314
326
  throw new ORPCError("BAD_REQUEST", {
315
327
  message: "Input validation failed",
316
328
  data: {
317
- issues: result.error.issues
329
+ issues
318
330
  },
319
331
  cause: new ValidationError({
320
332
  message: "Input validation failed",
321
- issues: result.error.issues,
333
+ issues,
322
334
  data: input
323
335
  })
324
336
  });
325
337
  }
326
- return result.data;
338
+ const results = {
339
+ body: resultBody.data,
340
+ path: resultPath.data,
341
+ query: resultQuery.data
342
+ };
343
+ return results;
327
344
  });
328
345
  }
329
346
  async function validateOutput(procedure, output) {
@@ -332,7 +349,7 @@ async function validateOutput(procedure, output) {
332
349
  return output;
333
350
  }
334
351
  return runWithSpan({ name: "validate_output" }, async () => {
335
- const result = await safeParseAsync(schema, output);
352
+ const result = await safeEncodeAsync(schema, output, { parseType: "output" });
336
353
  if (!result.success) {
337
354
  throw new ORPCError("INTERNAL_SERVER_ERROR", {
338
355
  message: "Output validation failed",
@@ -346,7 +363,7 @@ async function validateOutput(procedure, output) {
346
363
  return result.data;
347
364
  });
348
365
  }
349
- async function executeProcedureInternal(procedure, options) {
366
+ async function executeProcedureInternal(procedure, input, options) {
350
367
  const middlewares = procedure["~orpc"].middlewares;
351
368
  const inputValidationIndex = Math.min(
352
369
  Math.max(0, procedure["~orpc"].inputValidationIndex),
@@ -356,8 +373,8 @@ async function executeProcedureInternal(procedure, options) {
356
373
  Math.max(0, procedure["~orpc"].outputValidationIndex),
357
374
  middlewares.length
358
375
  );
359
- const next = async (index, context, input) => {
360
- let currentInput = input;
376
+ const next = async (index, context, input2) => {
377
+ let currentInput = input2;
361
378
  if (index === inputValidationIndex) {
362
379
  currentInput = await validateInput(procedure, currentInput);
363
380
  }
@@ -373,6 +390,9 @@ async function executeProcedureInternal(procedure, options) {
373
390
  const nextContext = nextOptions?.context ?? {};
374
391
  return {
375
392
  output: await next(index + 1, mergeCurrentContext(context, nextContext), currentInput),
393
+ // NB: Pretty sure this isn't used (or meant to be used) at runtime, it's just there
394
+ // to get type inference in the builder (via the caller returning the output of next() in
395
+ // the middleware function)
376
396
  context: nextContext
377
397
  };
378
398
  }
@@ -383,14 +403,14 @@ async function executeProcedureInternal(procedure, options) {
383
403
  return result.output;
384
404
  }) : await runWithSpan(
385
405
  { name: "handler", signal: options.signal },
386
- () => procedure["~orpc"].handler({ ...options, context, input: currentInput })
406
+ () => procedure["~orpc"].handler(currentInput, { ...options, context })
387
407
  );
388
408
  if (index === outputValidationIndex) {
389
409
  return await validateOutput(procedure, output);
390
410
  }
391
411
  return output;
392
412
  };
393
- return next(0, options.context, options.input);
413
+ return next(0, options.context, input);
394
414
  }
395
415
 
396
416
  export { LAZY_SYMBOL as L, Procedure as P, addMiddleware as a, isLazy as b, createProcedureClient as c, getRouter as d, enhanceRouter as e, createORPCErrorConstructorMap as f, getLazyMeta as g, lazy as h, isProcedure as i, middlewareOutputFn as j, isStartWithMiddlewares as k, lazyInternal as l, mergeCurrentContext as m, mergeMiddlewares as n, getHiddenRouterContract as o, createAccessibleLazyRouter as p, unlazyRouter as q, resolveContractProcedures as r, setHiddenRouterContract as s, traverseContractProcedures as t, unlazy as u };
@@ -1,7 +1,6 @@
1
1
  import { Meta } from '@temporary-name/contract';
2
- import { HTTPPath, Interceptor } from '@temporary-name/shared';
3
- import { StandardLazyRequest, StandardResponse } from '@temporary-name/standard-server';
4
- import { C as Context, R as Router, H as ProcedureClientInterceptorOptions } from './server.B5czSQQh.mjs';
2
+ import { HTTPPath, StandardLazyRequest, Interceptor, StandardResponse } from '@temporary-name/shared';
3
+ import { C as Context, R as Router, N as ProcedureClientInterceptorOptions } from './server.DkYpsO6W.mjs';
5
4
 
6
5
  interface StandardHandlerPlugin<T extends Context> {
7
6
  order?: number;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@temporary-name/server",
3
3
  "type": "module",
4
- "version": "1.9.3-alpha.5c041722542bb790586629fc98d4c72d9f6ee65e",
4
+ "version": "1.9.3-alpha.5dc8b200530586870ac736830d4584e0333cfd05",
5
5
  "license": "MIT",
6
6
  "homepage": "https://www.stainless.com/",
7
7
  "repository": {
@@ -57,31 +57,19 @@
57
57
  "files": [
58
58
  "dist"
59
59
  ],
60
- "peerDependencies": {
61
- "drizzle-orm": "^0.44.5",
62
- "drizzle-zod": "^0.8.3"
63
- },
64
- "peerDependenciesMeta": {
65
- "drizzle-orm": {
66
- "optional": true
67
- },
68
- "drizzle-zod": {
69
- "optional": true
70
- }
71
- },
72
60
  "dependencies": {
73
61
  "cookie": "^1.0.2",
74
62
  "rou3": "^0.7.7",
75
63
  "zod": "^4.1.12",
76
- "@temporary-name/interop": "1.9.3-alpha.5c041722542bb790586629fc98d4c72d9f6ee65e",
77
- "@temporary-name/json-schema": "1.9.3-alpha.5c041722542bb790586629fc98d4c72d9f6ee65e",
78
- "@temporary-name/shared": "1.9.3-alpha.5c041722542bb790586629fc98d4c72d9f6ee65e",
79
- "@temporary-name/standard-server": "1.9.3-alpha.5c041722542bb790586629fc98d4c72d9f6ee65e",
80
- "@temporary-name/standard-server-aws-lambda": "1.9.3-alpha.5c041722542bb790586629fc98d4c72d9f6ee65e",
81
- "@temporary-name/contract": "1.9.3-alpha.5c041722542bb790586629fc98d4c72d9f6ee65e",
82
- "@temporary-name/standard-server-fetch": "1.9.3-alpha.5c041722542bb790586629fc98d4c72d9f6ee65e",
83
- "@temporary-name/standard-server-node": "1.9.3-alpha.5c041722542bb790586629fc98d4c72d9f6ee65e",
84
- "@temporary-name/zod": "1.9.3-alpha.5c041722542bb790586629fc98d4c72d9f6ee65e"
64
+ "@temporary-name/contract": "1.9.3-alpha.5dc8b200530586870ac736830d4584e0333cfd05",
65
+ "@temporary-name/interop": "1.9.3-alpha.5dc8b200530586870ac736830d4584e0333cfd05",
66
+ "@temporary-name/shared": "1.9.3-alpha.5dc8b200530586870ac736830d4584e0333cfd05",
67
+ "@temporary-name/standard-server": "1.9.3-alpha.5dc8b200530586870ac736830d4584e0333cfd05",
68
+ "@temporary-name/standard-server-aws-lambda": "1.9.3-alpha.5dc8b200530586870ac736830d4584e0333cfd05",
69
+ "@temporary-name/standard-server-fetch": "1.9.3-alpha.5dc8b200530586870ac736830d4584e0333cfd05",
70
+ "@temporary-name/standard-server-node": "1.9.3-alpha.5dc8b200530586870ac736830d4584e0333cfd05",
71
+ "@temporary-name/zod": "1.9.3-alpha.5dc8b200530586870ac736830d4584e0333cfd05",
72
+ "@temporary-name/json-schema": "1.9.3-alpha.5dc8b200530586870ac736830d4584e0333cfd05"
85
73
  },
86
74
  "devDependencies": {
87
75
  "@types/supertest": "^6.0.3",