@temporary-name/server 1.9.3-alpha.4225889dbc4c4adc76cdbabb804a30cd075c9d7a → 1.9.3-alpha.47c8371db8c45c361b1db0b785980cc77971e6e6

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 (31) 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/index.d.mts +51 -43
  14. package/dist/index.d.ts +51 -43
  15. package/dist/index.mjs +42 -14
  16. package/dist/openapi/index.d.mts +1 -1
  17. package/dist/openapi/index.d.ts +1 -1
  18. package/dist/openapi/index.mjs +52 -35
  19. package/dist/plugins/index.d.mts +4 -80
  20. package/dist/plugins/index.d.ts +4 -80
  21. package/dist/plugins/index.mjs +17 -189
  22. package/dist/shared/{server.BYnDyuDL.d.mts → server.7aL9gcoU.d.mts} +2 -2
  23. package/dist/shared/{server.WsFQIubj.d.mts → server.BL2R5jcp.d.mts} +36 -43
  24. package/dist/shared/{server.WsFQIubj.d.ts → server.BL2R5jcp.d.ts} +36 -43
  25. package/dist/shared/{server.CjkiSCui.mjs → server.C61o1Zch.mjs} +36 -19
  26. package/dist/shared/{server.C-tNYmY_.d.ts → server.D6Qs_UcF.d.mts} +2 -3
  27. package/dist/shared/{server.JI4dqTgD.d.ts → server.DFptr1Nz.d.ts} +2 -2
  28. package/dist/shared/{server.BlJrjUA9.d.mts → server.DpoO_ER_.d.ts} +2 -3
  29. package/dist/shared/{server.DdHBdcen.mjs → server.DwbIdsnK.mjs} +18 -26
  30. package/dist/shared/{server.Kxw442A9.mjs → server.JtIZ8YG7.mjs} +1 -11
  31. package/package.json +10 -10
@@ -1,58 +1,8 @@
1
1
  import { Value, Promisable, ORPCError } from '@temporary-name/shared';
2
- import { StandardRequest, StandardHeaders } from '@temporary-name/standard-server';
3
- import { BatchResponseBodyItem } from '@temporary-name/standard-server/batch';
4
- import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.C-tNYmY_.js';
5
- import { C as Context, H as ProcedureClientInterceptorOptions } from '../shared/server.WsFQIubj.js';
2
+ import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.DpoO_ER_.js';
3
+ import { C as Context, G as ProcedureClientInterceptorOptions } from '../shared/server.BL2R5jcp.js';
6
4
  import { Meta } from '@temporary-name/contract';
7
5
 
8
- interface BatchHandlerOptions<T extends Context> {
9
- /**
10
- * The max size of the batch allowed.
11
- *
12
- * @default 10
13
- */
14
- maxSize?: Value<Promisable<number>, [StandardHandlerInterceptorOptions<T>]>;
15
- /**
16
- * Map the request before processing it.
17
- *
18
- * @default merged back batch request headers into the request
19
- */
20
- mapRequestItem?(request: StandardRequest, batchOptions: StandardHandlerInterceptorOptions<T>): StandardRequest;
21
- /**
22
- * Success batch response status code.
23
- *
24
- * @default 207
25
- */
26
- successStatus?: Value<Promisable<number>, [
27
- responses: Promise<BatchResponseBodyItem>[],
28
- batchOptions: StandardHandlerInterceptorOptions<T>
29
- ]>;
30
- /**
31
- * success batch response headers.
32
- *
33
- * @default {}
34
- */
35
- headers?: Value<Promisable<StandardHeaders>, [
36
- responses: Promise<BatchResponseBodyItem>[],
37
- batchOptions: StandardHandlerInterceptorOptions<T>
38
- ]>;
39
- }
40
- /**
41
- * The Batch Requests Plugin allows you to combine multiple requests and responses into a single batch,
42
- * reducing the overhead of sending each one separately.
43
- *
44
- * @see {@link https://orpc.unnoq.com/docs/plugins/batch-requests Batch Requests Plugin Docs}
45
- */
46
- declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
47
- private readonly maxSize;
48
- private readonly mapRequestItem;
49
- private readonly successStatus;
50
- private readonly headers;
51
- order: number;
52
- constructor(options?: BatchHandlerOptions<T>);
53
- init(options: StandardHandlerOptions<T>): void;
54
- }
55
-
56
6
  interface CORSOptions<T extends Context> {
57
7
  origin?: Value<Promisable<string | readonly string[] | null | undefined>, [
58
8
  origin: string,
@@ -80,32 +30,6 @@ declare class CORSPlugin<T extends Context> implements StandardHandlerPlugin<T>
80
30
  init(options: StandardHandlerOptions<T>): void;
81
31
  }
82
32
 
83
- interface RequestHeadersPluginContext {
84
- reqHeaders?: Headers;
85
- }
86
- /**
87
- * The Request Headers Plugin injects a `reqHeaders` instance into the context,
88
- * allowing access to request headers in oRPC.
89
- *
90
- * @see {@link https://orpc.unnoq.com/docs/plugins/request-headers Request Headers Plugin Docs}
91
- */
92
- declare class RequestHeadersPlugin<T extends RequestHeadersPluginContext> implements StandardHandlerPlugin<T> {
93
- init(options: StandardHandlerOptions<T>): void;
94
- }
95
-
96
- interface ResponseHeadersPluginContext {
97
- resHeaders?: Headers;
98
- }
99
- /**
100
- * The Response Headers Plugin allows you to set response headers in oRPC.
101
- * It injects a resHeaders instance into the context, enabling you to modify response headers easily.
102
- *
103
- * @see {@link https://orpc.unnoq.com/docs/plugins/response-headers Response Headers Plugin Docs}
104
- */
105
- declare class ResponseHeadersPlugin<T extends ResponseHeadersPluginContext> implements StandardHandlerPlugin<T> {
106
- init(options: StandardHandlerOptions<T>): void;
107
- }
108
-
109
33
  interface SimpleCsrfProtectionHandlerPluginOptions<T extends Context> {
110
34
  /**
111
35
  * The name of the header to check.
@@ -156,5 +80,5 @@ declare class SimpleCsrfProtectionHandlerPlugin<T extends Context> implements St
156
80
  init(options: StandardHandlerOptions<T>): void;
157
81
  }
158
82
 
159
- export { BatchHandlerPlugin, CORSPlugin, RequestHeadersPlugin, ResponseHeadersPlugin, SimpleCsrfProtectionHandlerPlugin };
160
- export type { BatchHandlerOptions, CORSOptions, RequestHeadersPluginContext, ResponseHeadersPluginContext, SimpleCsrfProtectionHandlerPluginOptions };
83
+ export { CORSPlugin, SimpleCsrfProtectionHandlerPlugin };
84
+ export type { CORSOptions, SimpleCsrfProtectionHandlerPluginOptions };
@@ -1,119 +1,5 @@
1
- import { runWithSpan, value, setSpanError, isAsyncIteratorObject, AsyncIteratorClass, clone, ORPCError } from '@temporary-name/shared';
2
- import { flattenHeader } from '@temporary-name/standard-server';
3
- import { parseBatchRequest, toBatchResponse } from '@temporary-name/standard-server/batch';
4
- import { toFetchHeaders } from '@temporary-name/standard-server-fetch';
5
-
6
- class BatchHandlerPlugin {
7
- maxSize;
8
- mapRequestItem;
9
- successStatus;
10
- headers;
11
- order = 5e6;
12
- constructor(options = {}) {
13
- this.maxSize = options.maxSize ?? 10;
14
- this.mapRequestItem = options.mapRequestItem ?? ((request, { request: batchRequest }) => ({
15
- ...request,
16
- headers: {
17
- ...batchRequest.headers,
18
- ...request.headers
19
- }
20
- }));
21
- this.successStatus = options.successStatus ?? 207;
22
- this.headers = options.headers ?? {};
23
- }
24
- init(options) {
25
- options.rootInterceptors ??= [];
26
- options.rootInterceptors.unshift(async (options2) => {
27
- const xHeader = flattenHeader(options2.request.headers["x-orpc-batch"]);
28
- if (xHeader === void 0) {
29
- return options2.next();
30
- }
31
- let isParsing = false;
32
- try {
33
- return await runWithSpan({ name: "handle_batch_request" }, async (span) => {
34
- const mode = xHeader === "buffered" ? "buffered" : "streaming";
35
- isParsing = true;
36
- const parsed = parseBatchRequest({ ...options2.request, body: await options2.request.body() });
37
- isParsing = false;
38
- span?.setAttribute("batch.mode", mode);
39
- span?.setAttribute("batch.size", parsed.length);
40
- const maxSize = await value(this.maxSize, options2);
41
- if (parsed.length > maxSize) {
42
- const message = "Batch request size exceeds the maximum allowed size";
43
- setSpanError(span, message);
44
- return {
45
- matched: true,
46
- response: {
47
- status: 413,
48
- headers: {},
49
- body: message
50
- }
51
- };
52
- }
53
- const responses = parsed.map((request, index) => {
54
- const mapped = this.mapRequestItem(request, options2);
55
- return options2.next({ ...options2, request: { ...mapped, body: () => Promise.resolve(mapped.body) } }).then(({ response: response2, matched }) => {
56
- span?.addEvent(`response.${index}.${matched ? "success" : "not_matched"}`);
57
- if (matched) {
58
- if (response2.body instanceof Blob || response2.body instanceof FormData || isAsyncIteratorObject(response2.body)) {
59
- return {
60
- index,
61
- status: 500,
62
- headers: {},
63
- body: "Batch responses do not support file/blob, or event-iterator. Please call this procedure separately outside of the batch request."
64
- };
65
- }
66
- return { ...response2, index };
67
- }
68
- return { index, status: 404, headers: {}, body: "No procedure matched" };
69
- }).catch((err) => {
70
- Promise.reject(err);
71
- return { index, status: 500, headers: {}, body: "Internal server error" };
72
- });
73
- });
74
- await Promise.race(responses);
75
- const status = await value(this.successStatus, responses, options2);
76
- const headers = await value(this.headers, responses, options2);
77
- const promises = [...responses];
78
- const response = await toBatchResponse({
79
- status,
80
- headers,
81
- mode,
82
- body: new AsyncIteratorClass(
83
- async () => {
84
- const handling = promises.filter((p) => p !== void 0);
85
- if (handling.length <= 0) {
86
- return { done: true, value: void 0 };
87
- }
88
- const value2 = await Promise.race(handling);
89
- promises[value2.index] = void 0;
90
- return { done: false, value: value2 };
91
- },
92
- async () => {
93
- }
94
- )
95
- });
96
- return {
97
- matched: true,
98
- response
99
- };
100
- });
101
- } catch (cause) {
102
- if (isParsing) {
103
- return {
104
- matched: true,
105
- response: {
106
- status: 400,
107
- headers: {},
108
- body: "Invalid batch request, this could be caused by a malformed request body or a missing header"
109
- }
110
- };
111
- }
112
- throw cause;
113
- }
114
- });
115
- }
116
- }
1
+ import { value, ORPCError } from '@temporary-name/shared';
2
+ import { maybeSetHeader } from '@temporary-name/standard-server';
117
3
 
118
4
  class CORSPlugin {
119
5
  options;
@@ -132,17 +18,13 @@ class CORSPlugin {
132
18
  options.rootInterceptors ??= [];
133
19
  options.rootInterceptors.unshift(async (interceptorOptions) => {
134
20
  if (interceptorOptions.request.method === "OPTIONS") {
135
- const resHeaders = {};
21
+ const resHeaders = new Headers();
136
22
  if (this.options.maxAge !== void 0) {
137
- resHeaders["access-control-max-age"] = this.options.maxAge.toString();
138
- }
139
- if (this.options.allowMethods?.length) {
140
- resHeaders["access-control-allow-methods"] = flattenHeader(this.options.allowMethods);
141
- }
142
- const allowHeaders = this.options.allowHeaders ?? interceptorOptions.request.headers["access-control-request-headers"];
143
- if (typeof allowHeaders === "string" || allowHeaders?.length) {
144
- resHeaders["access-control-allow-headers"] = flattenHeader(allowHeaders);
23
+ resHeaders.set("access-control-max-age", this.options.maxAge.toString());
145
24
  }
25
+ maybeSetHeader(resHeaders, "access-control-allow-methods", this.options.allowMethods);
26
+ const allowHeaders = this.options.allowHeaders ?? interceptorOptions.request.headers.get("access-control-request-headers");
27
+ maybeSetHeader(resHeaders, "access-control-allow-headers", allowHeaders);
146
28
  return {
147
29
  matched: true,
148
30
  response: {
@@ -159,87 +41,33 @@ class CORSPlugin {
159
41
  if (!result.matched) {
160
42
  return result;
161
43
  }
162
- const origin = flattenHeader(interceptorOptions.request.headers.origin) ?? "";
44
+ const origin = interceptorOptions.request.headers.get("origin") ?? "";
163
45
  const allowedOrigin = await value(this.options.origin, origin, interceptorOptions);
164
46
  const allowedOriginArr = Array.isArray(allowedOrigin) ? allowedOrigin : [allowedOrigin];
165
47
  if (allowedOriginArr.includes("*")) {
166
- result.response.headers["access-control-allow-origin"] = "*";
48
+ result.response.headers.set("access-control-allow-origin", "*");
167
49
  } else {
168
50
  if (allowedOriginArr.includes(origin)) {
169
- result.response.headers["access-control-allow-origin"] = origin;
51
+ result.response.headers.set("access-control-allow-origin", origin);
170
52
  }
171
- result.response.headers.vary = interceptorOptions.request.headers.vary ?? "origin";
53
+ result.response.headers.set("vary", interceptorOptions.request.headers.get("vary") ?? "origin");
172
54
  }
173
55
  const allowedTimingOrigin = await value(this.options.timingOrigin, origin, interceptorOptions);
174
56
  const allowedTimingOriginArr = Array.isArray(allowedTimingOrigin) ? allowedTimingOrigin : [allowedTimingOrigin];
175
57
  if (allowedTimingOriginArr.includes("*")) {
176
- result.response.headers["timing-allow-origin"] = "*";
58
+ result.response.headers.set("timing-allow-origin", "*");
177
59
  } else if (allowedTimingOriginArr.includes(origin)) {
178
- result.response.headers["timing-allow-origin"] = origin;
60
+ result.response.headers.set("timing-allow-origin", origin);
179
61
  }
180
62
  if (this.options.credentials) {
181
- result.response.headers["access-control-allow-credentials"] = "true";
182
- }
183
- if (this.options.exposeHeaders?.length) {
184
- result.response.headers["access-control-expose-headers"] = flattenHeader(this.options.exposeHeaders);
63
+ result.response.headers.set("access-control-allow-credentials", "true");
185
64
  }
65
+ maybeSetHeader(result.response.headers, "access-control-expose-headers", this.options.exposeHeaders);
186
66
  return result;
187
67
  });
188
68
  }
189
69
  }
190
70
 
191
- class RequestHeadersPlugin {
192
- init(options) {
193
- options.rootInterceptors ??= [];
194
- options.rootInterceptors.push((interceptorOptions) => {
195
- const reqHeaders = interceptorOptions.context.reqHeaders ?? toFetchHeaders(interceptorOptions.request.headers);
196
- return interceptorOptions.next({
197
- ...interceptorOptions,
198
- context: {
199
- ...interceptorOptions.context,
200
- reqHeaders
201
- }
202
- });
203
- });
204
- }
205
- }
206
-
207
- class ResponseHeadersPlugin {
208
- init(options) {
209
- options.rootInterceptors ??= [];
210
- options.rootInterceptors.push(async (interceptorOptions) => {
211
- const resHeaders = interceptorOptions.context.resHeaders ?? new Headers();
212
- const result = await interceptorOptions.next({
213
- ...interceptorOptions,
214
- context: {
215
- ...interceptorOptions.context,
216
- resHeaders
217
- }
218
- });
219
- if (!result.matched) {
220
- return result;
221
- }
222
- const responseHeaders = clone(result.response.headers);
223
- for (const [key, value] of resHeaders) {
224
- if (Array.isArray(responseHeaders[key])) {
225
- responseHeaders[key].push(value);
226
- } else if (responseHeaders[key] !== void 0) {
227
- responseHeaders[key] = [responseHeaders[key], value];
228
- } else {
229
- responseHeaders[key] = value;
230
- }
231
- }
232
- return {
233
- ...result,
234
- response: {
235
- ...result.response,
236
- headers: responseHeaders
237
- }
238
- };
239
- });
240
- }
241
- }
242
-
243
71
  const SIMPLE_CSRF_PROTECTION_CONTEXT_SYMBOL = Symbol("SIMPLE_CSRF_PROTECTION_CONTEXT");
244
72
  class SimpleCsrfProtectionHandlerPlugin {
245
73
  headerName;
@@ -266,7 +94,7 @@ class SimpleCsrfProtectionHandlerPlugin {
266
94
  ...options2,
267
95
  context: {
268
96
  ...options2.context,
269
- [SIMPLE_CSRF_PROTECTION_CONTEXT_SYMBOL]: options2.request.headers[headerName] === headerValue
97
+ [SIMPLE_CSRF_PROTECTION_CONTEXT_SYMBOL]: options2.request.headers.get(headerName) === headerValue
270
98
  }
271
99
  });
272
100
  });
@@ -285,4 +113,4 @@ class SimpleCsrfProtectionHandlerPlugin {
285
113
  }
286
114
  }
287
115
 
288
- export { BatchHandlerPlugin, CORSPlugin, RequestHeadersPlugin, ResponseHeadersPlugin, SimpleCsrfProtectionHandlerPlugin };
116
+ export { CORSPlugin, SimpleCsrfProtectionHandlerPlugin };
@@ -1,6 +1,6 @@
1
1
  import { HTTPPath } from '@temporary-name/shared';
2
- import { C as Context } from './server.WsFQIubj.mjs';
3
- import { c as StandardHandleOptions } from './server.BlJrjUA9.mjs';
2
+ import { C as Context } from './server.BL2R5jcp.mjs';
3
+ import { c as StandardHandleOptions } from './server.D6Qs_UcF.mjs';
4
4
 
5
5
  type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
6
6
  context?: T;
@@ -1,5 +1,5 @@
1
- import { ErrorMap, ErrorMapItem, InferSchemaInput, AnySchema, Meta, ContractProcedureDef, AnyContractRouter, ContractProcedure, InferSchemaOutput, EnhanceRouteOptions, MergedErrorMap, AnyContractProcedure, ContractRouter, 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>;
@@ -13,19 +13,23 @@ type ORPCErrorConstructorMap<T extends ErrorMap> = {
13
13
  };
14
14
  declare function createORPCErrorConstructorMap<T extends ErrorMap>(errors: T): ORPCErrorConstructorMap<T>;
15
15
 
16
- interface ProcedureHandlerOptions<TCurrentContext extends Context, TInput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
16
+ interface ProcedureHandlerOptions<TCurrentContext extends Context, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
17
17
  context: TCurrentContext;
18
- input: TInput;
19
18
  path: readonly string[];
20
- procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
19
+ procedure: Procedure<Context, Context, Schemas, ErrorMap, TMeta>;
21
20
  signal?: AbortSignal;
21
+ request?: StandardLazyRequest;
22
22
  lastEventId: string | undefined;
23
23
  errors: TErrorConstructorMap;
24
24
  }
25
- interface ProcedureHandler<TCurrentContext extends Context, TInput, THandlerOutput, TErrorMap extends ErrorMap, TMeta extends Meta> {
26
- (opt: ProcedureHandlerOptions<TCurrentContext, TInput, ORPCErrorConstructorMap<TErrorMap>, TMeta>): Promisable<THandlerOutput>;
25
+ interface ProcedureHandler<TCurrentContext extends Context, TInput extends {
26
+ path: any;
27
+ query: any;
28
+ body: any;
29
+ }, THandlerOutput, TErrorMap extends ErrorMap, TMeta extends Meta> {
30
+ (input: TInput, opt: ProcedureHandlerOptions<TCurrentContext, ORPCErrorConstructorMap<TErrorMap>, TMeta>): Promisable<THandlerOutput>;
27
31
  }
28
- interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
32
+ interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TSchemas, TErrorMap, TMeta> {
29
33
  __initialContext?: (type: TInitialContext) => unknown;
30
34
  middlewares: readonly AnyMiddleware[];
31
35
  inputValidationIndex: number;
@@ -37,39 +41,30 @@ interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends
37
41
  *
38
42
  * @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
39
43
  */
40
- declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
44
+ declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TErrorMap extends ErrorMap, TMeta extends Meta> {
41
45
  /**
42
46
  * This property holds the defined options.
43
47
  */
44
- '~orpc': ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
45
- constructor(def: ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>);
48
+ '~orpc': ProcedureDef<TInitialContext, TCurrentContext, TSchemas, TErrorMap, TMeta>;
49
+ constructor(def: ProcedureDef<TInitialContext, TCurrentContext, TSchemas, TErrorMap, TMeta>);
46
50
  }
47
- type AnyProcedure = Procedure<any, any, AnySchema, AnySchema, any, any>;
51
+ type AnyProcedure = Procedure<any, any, Schemas, any, any>;
48
52
  declare function isProcedure(item: unknown): item is AnyProcedure;
49
53
 
50
54
  type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
51
55
  output: TOutput;
52
56
  context: TOutContext;
53
57
  }>;
54
- type MiddlewareNextFnOptions<TOutContext extends Context> = Record<never, never> extends TOutContext ? {
55
- context?: TOutContext;
56
- } : {
57
- context: TOutContext;
58
- };
59
58
  interface MiddlewareNextFn<TOutput> {
60
- <U extends Context = Record<never, never>>(...rest: MaybeOptionalOptions<MiddlewareNextFnOptions<U>>): MiddlewareResult<U, TOutput>;
59
+ <U extends Context = {}>(options?: {
60
+ context?: U;
61
+ }): MiddlewareResult<U, TOutput>;
61
62
  }
62
63
  interface MiddlewareOutputFn<TOutput> {
63
64
  (output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
64
65
  }
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, AnySchema, AnySchema, ErrorMap, TMeta>;
69
- signal?: AbortSignal;
70
- lastEventId: string | undefined;
66
+ interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> extends ProcedureHandlerOptions<TInContext, TErrorConstructorMap, TMeta> {
71
67
  next: MiddlewareNextFn<TOutput>;
72
- errors: TErrorConstructorMap;
73
68
  }
74
69
  /**
75
70
  * A function that represents a middleware.
@@ -91,7 +86,7 @@ declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<
91
86
  * @info A procedure is a router too.
92
87
  * @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#contract-router Contract Router Docs}
93
88
  */
94
- type Router<T extends AnyContractRouter, TInitialContext extends Context> = T extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? Procedure<TInitialContext, any, UInputSchema, UOutputSchema, UErrorMap, UMeta> : {
89
+ type Router<T extends AnyContractRouter, TInitialContext extends Context> = T extends ContractProcedure<infer USchemas, infer UErrorMap, infer UMeta> ? Procedure<TInitialContext, any, USchemas, UErrorMap, UMeta> : {
95
90
  [K in keyof T]: T[K] extends AnyContractRouter ? Lazyable<Router<T[K], TInitialContext>> : never;
96
91
  };
97
92
  type AnyRouter = Router<any, any>;
@@ -102,7 +97,7 @@ type InferRouterInitialContext<T extends AnyRouter> = T extends Router<any, infe
102
97
  * @info A procedure is a router too.
103
98
  * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
104
99
  */
105
- type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any, any> ? UInitialContext : {
100
+ type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any> ? UInitialContext : {
106
101
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never;
107
102
  };
108
103
  /**
@@ -111,7 +106,7 @@ type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer
111
106
  * @info A procedure is a router too.
112
107
  * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
113
108
  */
114
- type InferRouterCurrentContexts<T extends AnyRouter> = T extends Procedure<any, infer UCurrentContext, any, any, any, any> ? UCurrentContext : {
109
+ type InferRouterCurrentContexts<T extends AnyRouter> = T extends Procedure<any, infer UCurrentContext, any, any, any> ? UCurrentContext : {
115
110
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterCurrentContexts<U> : never;
116
111
  };
117
112
  /**
@@ -120,7 +115,7 @@ type InferRouterCurrentContexts<T extends AnyRouter> = T extends Procedure<any,
120
115
  * @info A procedure is a router too.
121
116
  * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
122
117
  */
123
- type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer UInputSchema, any, any, any> ? InferSchemaInput<UInputSchema> : {
118
+ type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer USchemas, any, any> ? InferProcedureClientInputs<USchemas> : {
124
119
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never;
125
120
  };
126
121
  /**
@@ -129,7 +124,7 @@ type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infe
129
124
  * @info A procedure is a router too.
130
125
  * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
131
126
  */
132
- type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any, infer UOutputSchema, any, any> ? InferSchemaOutput<UOutputSchema> : {
127
+ type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, infer USchemas, any, any> ? InferSchemaOutput<USchemas['outputSchema']> : {
133
128
  [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
134
129
  };
135
130
 
@@ -138,7 +133,7 @@ type AccessibleLazyRouter<T extends Lazyable<AnyRouter | undefined>> = T extends
138
133
  [K in keyof T]: T[K] extends Lazyable<AnyRouter> ? AccessibleLazyRouter<T[K]> : never;
139
134
  };
140
135
  declare function createAccessibleLazyRouter<T extends Lazy<AnyRouter | undefined>>(lazied: T): AccessibleLazyRouter<T>;
141
- type EnhancedRouter<T extends Lazyable<AnyRouter>, TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap> = T extends Lazy<infer U extends AnyRouter> ? AccessibleLazyRouter<EnhancedRouter<U, TInitialContext, TCurrentContext, TErrorMap>> : T extends (Procedure<infer UInitialContext, infer UCurrentContext, infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta>) ? Procedure<MergedInitialContext<TInitialContext, UInitialContext, TCurrentContext>, UCurrentContext, UInputSchema, UOutputSchema, MergedErrorMap<TErrorMap, UErrorMap>, UMeta> : {
136
+ type EnhancedRouter<T extends Lazyable<AnyRouter>, TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap> = T extends Lazy<infer U extends AnyRouter> ? AccessibleLazyRouter<EnhancedRouter<U, TInitialContext, TCurrentContext, TErrorMap>> : T extends (Procedure<infer UInitialContext, infer UCurrentContext, infer USchemas, infer UErrorMap, infer UMeta>) ? Procedure<MergedInitialContext<TInitialContext, UInitialContext, TCurrentContext>, UCurrentContext, USchemas, MergedErrorMap<TErrorMap, UErrorMap>, UMeta> : {
142
137
  [K in keyof T]: T[K] extends Lazyable<AnyRouter> ? EnhancedRouter<T[K], TInitialContext, TCurrentContext, TErrorMap> : never;
143
138
  };
144
139
  interface EnhanceRouterOptions<TErrorMap extends ErrorMap> extends EnhanceRouteOptions {
@@ -203,15 +198,13 @@ declare function unlazy<T extends Lazyable<any>>(lazied: T): Promise<{
203
198
  default: T extends Lazy<infer U> ? U : T;
204
199
  }>;
205
200
 
206
- type ProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, 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, AnySchema, AnySchema, ErrorMap, TMeta>;
213
- signal?: AbortSignal;
214
- lastEventId: string | undefined;
201
+ type ProcedureClient<TClientContext extends ClientContext, TSchemas extends Schemas, TErrorMap extends ErrorMap> = Client<TClientContext, InferProcedureClientInputs<TSchemas>, InferSchemaOutput<TSchemas['outputSchema']>, ErrorFromErrorMap<TErrorMap>>;
202
+ interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TErrorMap extends ErrorMap, TMeta extends Meta> extends ProcedureHandlerOptions<TInitialContext, ORPCErrorConstructorMap<TErrorMap>, TMeta> {
203
+ input: {
204
+ path: unknown;
205
+ query: unknown;
206
+ body: unknown;
207
+ };
215
208
  }
216
209
  type CreateProcedureClientOptions<TInitialContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext> = {
217
210
  /**
@@ -229,7 +222,7 @@ type CreateProcedureClientOptions<TInitialContext extends Context, TOutputSchema
229
222
  *
230
223
  * @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
231
224
  */
232
- declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TMeta>>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TMeta, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
225
+ 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
226
 
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 };
227
+ export { resolveContractProcedures as $, isProcedure as F, createProcedureClient as H, Procedure as P, getRouter as S, createAccessibleLazyRouter as U, enhanceRouter as V, traverseContractProcedures as _, unlazyRouter as a1, 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, middlewareOutputFn as z };
228
+ export type { AnyMiddleware as A, ProcedureHandlerOptions as B, Context as C, ProcedureDef as D, EnhanceRouterOptions as E, ProcedureClientInterceptorOptions as G, InferRouterInitialContext as I, InferRouterInitialContexts as J, InferRouterCurrentContexts as K, Lazy as L, Middleware as M, InferRouterInputs as N, ORPCErrorConstructorMap as O, InferRouterOutputs as Q, Router as R, AccessibleLazyRouter as T, TraverseContractProceduresOptions as W, TraverseContractProcedureCallbackOptions as X, ContractProcedureCallbackOptions as Y, LazyTraverseContractProceduresOptions as Z, CreateProcedureClientOptions as a, UnlaziedRouter as a0, 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, MiddlewareNextFn as w, MiddlewareOutputFn as x, MiddlewareOptions as y };