@temporary-name/server 1.9.3-alpha.16e8a4f82a5b0af6e22263774a4af4e6f9afd8bc → 1.9.3-alpha.21b0289906d115f2f3db137ea407a6d8d50b5ad6

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 +4 -6
  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 +4 -6
  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 +4 -6
  10. package/dist/adapters/standard/index.d.mts +20 -32
  11. package/dist/adapters/standard/index.d.ts +20 -32
  12. package/dist/adapters/standard/index.mjs +4 -6
  13. package/dist/index.d.mts +69 -339
  14. package/dist/index.d.ts +69 -339
  15. package/dist/index.mjs +132 -357
  16. package/dist/openapi/index.d.mts +1 -1
  17. package/dist/openapi/index.d.ts +1 -1
  18. package/dist/openapi/index.mjs +60 -77
  19. package/dist/plugins/index.d.mts +3 -4
  20. package/dist/plugins/index.d.ts +3 -4
  21. package/dist/shared/{server.BeuTpcmO.d.mts → server.7aL9gcoU.d.mts} +2 -2
  22. package/dist/shared/server.BL2R5jcp.d.mts +228 -0
  23. package/dist/shared/server.BL2R5jcp.d.ts +228 -0
  24. package/dist/shared/{server.DLsti1Pv.mjs → server.CttFCjkj.mjs} +57 -95
  25. package/dist/shared/{server.CQyYNJ1H.d.ts → server.D6Qs_UcF.d.mts} +2 -4
  26. package/dist/shared/{server.SLLuK6_v.d.ts → server.DFptr1Nz.d.ts} +2 -2
  27. package/dist/shared/server.DmGicgbG.mjs +413 -0
  28. package/dist/shared/{server.C1fnTLq0.d.mts → server.DpoO_ER_.d.ts} +2 -4
  29. package/dist/shared/{server.BEHw7Eyx.mjs → server.JtIZ8YG7.mjs} +1 -11
  30. package/package.json +10 -9
  31. package/dist/shared/server.BKSOrA6h.d.mts +0 -192
  32. package/dist/shared/server.BKSOrA6h.d.ts +0 -192
  33. package/dist/shared/server.BKh8I1Ny.mjs +0 -239
@@ -1,7 +1,7 @@
1
1
  import { isProcedure, resolveContractProcedures, ORPCError, createRouterClient } from '@temporary-name/server';
2
- import { fallbackContractConfig, getEventIteratorSchemaDetails } from '@temporary-name/contract';
2
+ import { standardizeHTTPPath, fallbackContractConfig, getDynamicParams, getEventIteratorSchemaDetails } from '@temporary-name/contract';
3
3
  import { isObject, stringifyJSON, findDeepMatches, toArray, clone, value, toHttpPath, isORPCErrorStatus, fallbackORPCErrorStatus, fallbackORPCErrorMessage, resolveMaybeOptionalOptions, createORPCErrorFromJson } from '@temporary-name/shared';
4
- import { a as standardizeHTTPPath, j as jsonSerialize, g as getDynamicParams, d as deserialize, s as serialize } from '../shared/server.BEHw7Eyx.mjs';
4
+ import { j as jsonSerialize, d as deserialize, s as serialize } from '../shared/server.JtIZ8YG7.mjs';
5
5
  import '@temporary-name/standard-server';
6
6
  import { TypeName } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
7
7
  export { ContentEncoding as JSONSchemaContentEncoding, Format as JSONSchemaFormat, TypeName as JSONSchemaTypeName } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
@@ -530,94 +530,77 @@ ${errors.join("\n\n")}`
530
530
  }
531
531
  async #request(doc, ref, def, baseSchemaConvertOptions) {
532
532
  const method = fallbackContractConfig("defaultMethod", def.route.method);
533
- const details = getEventIteratorSchemaDetails(def.inputSchema);
534
- if (details) {
535
- ref.requestBody = {
536
- required: true,
537
- content: toOpenAPIEventIteratorContent(
538
- await this.converter.convert(details.yields, { ...baseSchemaConvertOptions, strategy: "input" }),
539
- await this.converter.convert(details.returns, { ...baseSchemaConvertOptions, strategy: "input" })
540
- )
541
- };
542
- return;
543
- }
544
533
  const dynamicParams = getDynamicParams(def.route.path)?.map((v) => v.name);
545
- const inputStructure = fallbackContractConfig("defaultInputStructure", def.route.inputStructure);
546
- let [required, schema] = await this.converter.convert(def.inputSchema, {
534
+ const [_pathRequired, pathSchema] = await this.converter.convert(def.schemas.pathSchema, {
547
535
  ...baseSchemaConvertOptions,
548
536
  strategy: "input",
549
- minStructureDepthForRef: dynamicParams?.length || inputStructure === "detailed" ? 1 : 0
537
+ minStructureDepthForRef: 1
550
538
  });
551
- if (isAnySchema(schema) && !dynamicParams?.length) {
552
- return;
553
- }
554
- if (inputStructure === "compact") {
555
- if (dynamicParams?.length) {
556
- const error2 = new OpenAPIGeneratorError(
557
- 'When input structure is "compact", and path has dynamic params, input schema must be an object with all dynamic params as required.'
558
- );
559
- if (!isObjectSchema(schema)) {
560
- throw error2;
561
- }
562
- const [paramsSchema, rest] = separateObjectSchema(schema, dynamicParams);
563
- schema = rest;
564
- required = rest.required ? rest.required.length !== 0 : false;
565
- if (!checkParamsSchema(paramsSchema, dynamicParams)) {
566
- throw error2;
567
- }
568
- ref.parameters ??= [];
569
- ref.parameters.push(...toOpenAPIParameters(paramsSchema, "path"));
539
+ if (dynamicParams?.length) {
540
+ const error = new OpenAPIGeneratorError(
541
+ // TODO: fix this error
542
+ 'When input structure is "compact", and path has dynamic params, input schema must be an object with all dynamic params as required.'
543
+ );
544
+ if (!isObjectSchema(pathSchema)) {
545
+ throw error;
570
546
  }
571
- if (method === "GET") {
572
- const resolvedSchema = resolveOpenAPIJsonSchemaRef(doc, schema);
573
- if (!isObjectSchema(resolvedSchema)) {
574
- throw new OpenAPIGeneratorError(
575
- 'When method is "GET", input schema must satisfy: object | any | unknown'
576
- );
577
- }
578
- ref.parameters ??= [];
579
- ref.parameters.push(...toOpenAPIParameters(resolvedSchema, "query"));
580
- } else {
581
- ref.requestBody = {
582
- required,
583
- content: toOpenAPIContent(schema)
584
- };
547
+ if (!checkParamsSchema(pathSchema, dynamicParams)) {
548
+ throw error;
549
+ }
550
+ ref.parameters ??= [];
551
+ ref.parameters.push(...toOpenAPIParameters(pathSchema, "path"));
552
+ } else {
553
+ const error = new OpenAPIGeneratorError("Params set via path do not match those on the route");
554
+ if (!isObjectSchema(pathSchema)) {
555
+ console.log("FOO", pathSchema);
556
+ throw error;
557
+ }
558
+ if (!checkParamsSchema(pathSchema, [])) {
559
+ console.log("BAR", pathSchema);
560
+ throw error;
585
561
  }
586
- return;
587
- }
588
- const error = new OpenAPIGeneratorError(
589
- 'When input structure is "detailed", input schema must satisfy: { params?: Record<string, unknown>, query?: Record<string, unknown>, headers?: Record<string, unknown>, body?: unknown }'
590
- );
591
- if (!isObjectSchema(schema)) {
592
- throw error;
593
562
  }
594
- const resolvedParamSchema = schema.properties?.params !== void 0 ? resolveOpenAPIJsonSchemaRef(doc, schema.properties.params) : void 0;
595
- if (dynamicParams?.length && (resolvedParamSchema === void 0 || !isObjectSchema(resolvedParamSchema) || !checkParamsSchema(resolvedParamSchema, dynamicParams))) {
596
- throw new OpenAPIGeneratorError(
597
- 'When input structure is "detailed" and path has dynamic params, the "params" schema must be an object with all dynamic params as required.'
598
- );
563
+ const [_queryRequired, querySchema] = await this.converter.convert(def.schemas.querySchema, {
564
+ ...baseSchemaConvertOptions,
565
+ strategy: "input",
566
+ minStructureDepthForRef: 0
567
+ });
568
+ if (!isAnySchema(querySchema)) {
569
+ const resolvedSchema = resolveOpenAPIJsonSchemaRef(doc, querySchema);
570
+ if (!isObjectSchema(resolvedSchema)) {
571
+ throw new OpenAPIGeneratorError("Query param schema must satisfy: object | any | unknown");
572
+ }
573
+ ref.parameters ??= [];
574
+ ref.parameters.push(...toOpenAPIParameters(resolvedSchema, "query"));
599
575
  }
600
- for (const from of ["params", "query", "headers"]) {
601
- const fromSchema = schema.properties?.[from];
602
- if (fromSchema !== void 0) {
603
- const resolvedSchema = resolveOpenAPIJsonSchemaRef(doc, fromSchema);
604
- if (!isObjectSchema(resolvedSchema)) {
605
- throw error;
576
+ if (method !== "GET") {
577
+ const details = getEventIteratorSchemaDetails(def.schemas.bodySchema);
578
+ if (details) {
579
+ ref.requestBody = {
580
+ required: true,
581
+ content: toOpenAPIEventIteratorContent(
582
+ await this.converter.convert(details.yields, { ...baseSchemaConvertOptions, strategy: "input" }),
583
+ await this.converter.convert(details.returns, { ...baseSchemaConvertOptions, strategy: "input" })
584
+ )
585
+ };
586
+ } else {
587
+ const [bodyRequired, bodySchema] = await this.converter.convert(def.schemas.bodySchema, {
588
+ ...baseSchemaConvertOptions,
589
+ strategy: "input",
590
+ minStructureDepthForRef: 0
591
+ });
592
+ if (isAnySchema(bodySchema)) {
593
+ return;
606
594
  }
607
- const parameterIn = from === "params" ? "path" : from === "headers" ? "header" : "query";
608
- ref.parameters ??= [];
609
- ref.parameters.push(...toOpenAPIParameters(resolvedSchema, parameterIn));
595
+ ref.requestBody = {
596
+ required: bodyRequired,
597
+ content: toOpenAPIContent(bodySchema)
598
+ };
610
599
  }
611
600
  }
612
- if (schema.properties?.body !== void 0) {
613
- ref.requestBody = {
614
- required: schema.required?.includes("body"),
615
- content: toOpenAPIContent(schema.properties.body)
616
- };
617
- }
618
601
  }
619
602
  async #successResponse(doc, ref, def, baseSchemaConvertOptions) {
620
- const outputSchema = def.outputSchema;
603
+ const outputSchema = def.schemas.outputSchema;
621
604
  const status = fallbackContractConfig("defaultSuccessStatus", def.route.successStatus);
622
605
  const description = fallbackContractConfig("defaultSuccessDescription", def.route?.successDescription);
623
606
  const eventIteratorSchemaDetails = getEventIteratorSchemaDetails(outputSchema);
@@ -1,8 +1,7 @@
1
- import { Value, Promisable, ORPCError } from '@temporary-name/shared';
2
- import { StandardRequest, StandardHeaders } from '@temporary-name/standard-server';
1
+ import { Value, Promisable, StandardRequest, StandardHeaders, ORPCError } from '@temporary-name/shared';
3
2
  import { BatchResponseBodyItem } from '@temporary-name/standard-server/batch';
4
- import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.C1fnTLq0.mjs';
5
- import { C as Context, E as ProcedureClientInterceptorOptions } from '../shared/server.BKSOrA6h.mjs';
3
+ import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.D6Qs_UcF.mjs';
4
+ import { C as Context, G as ProcedureClientInterceptorOptions } from '../shared/server.BL2R5jcp.mjs';
6
5
  import { Meta } from '@temporary-name/contract';
7
6
 
8
7
  interface BatchHandlerOptions<T extends Context> {
@@ -1,8 +1,7 @@
1
- import { Value, Promisable, ORPCError } from '@temporary-name/shared';
2
- import { StandardRequest, StandardHeaders } from '@temporary-name/standard-server';
1
+ import { Value, Promisable, StandardRequest, StandardHeaders, ORPCError } from '@temporary-name/shared';
3
2
  import { BatchResponseBodyItem } from '@temporary-name/standard-server/batch';
4
- import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.CQyYNJ1H.js';
5
- import { C as Context, E as ProcedureClientInterceptorOptions } from '../shared/server.BKSOrA6h.js';
3
+ import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.DpoO_ER_.js';
4
+ import { C as Context, G as ProcedureClientInterceptorOptions } from '../shared/server.BL2R5jcp.js';
6
5
  import { Meta } from '@temporary-name/contract';
7
6
 
8
7
  interface BatchHandlerOptions<T extends Context> {
@@ -1,6 +1,6 @@
1
1
  import { HTTPPath } from '@temporary-name/shared';
2
- import { C as Context } from './server.BKSOrA6h.mjs';
3
- import { c as StandardHandleOptions } from './server.C1fnTLq0.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;
@@ -0,0 +1,228 @@
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
+
4
+ type Context = Record<PropertyKey, any>;
5
+ type MergedInitialContext<TInitial extends Context, TAdditional extends Context, TCurrent extends Context> = TInitial & Omit<TAdditional, keyof TCurrent>;
6
+ type MergedCurrentContext<T extends Context, U extends Context> = Omit<T, keyof U> & U;
7
+ declare function mergeCurrentContext<T extends Context, U extends Context>(context: T, other: U): MergedCurrentContext<T, U>;
8
+
9
+ type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'defined' | 'status'>;
10
+ type ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> = (...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>) => ORPCError<TCode, TInData>;
11
+ type ORPCErrorConstructorMap<T extends ErrorMap> = {
12
+ [K in keyof T]: K extends ORPCErrorCode ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, InferSchemaInput<UInputSchema>> : never : never;
13
+ };
14
+ declare function createORPCErrorConstructorMap<T extends ErrorMap>(errors: T): ORPCErrorConstructorMap<T>;
15
+
16
+ interface ProcedureHandlerOptions<TCurrentContext extends Context, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
17
+ context: TCurrentContext;
18
+ path: readonly string[];
19
+ procedure: Procedure<Context, Context, Schemas, ErrorMap, TMeta>;
20
+ signal?: AbortSignal;
21
+ request?: StandardLazyRequest;
22
+ lastEventId: string | undefined;
23
+ errors: TErrorConstructorMap;
24
+ }
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>;
31
+ }
32
+ interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TSchemas, TErrorMap, TMeta> {
33
+ __initialContext?: (type: TInitialContext) => unknown;
34
+ middlewares: readonly AnyMiddleware[];
35
+ inputValidationIndex: number;
36
+ outputValidationIndex: number;
37
+ handler: ProcedureHandler<TCurrentContext, any, any, any, any>;
38
+ }
39
+ /**
40
+ * This class represents a procedure.
41
+ *
42
+ * @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
43
+ */
44
+ declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TErrorMap extends ErrorMap, TMeta extends Meta> {
45
+ /**
46
+ * This property holds the defined options.
47
+ */
48
+ '~orpc': ProcedureDef<TInitialContext, TCurrentContext, TSchemas, TErrorMap, TMeta>;
49
+ constructor(def: ProcedureDef<TInitialContext, TCurrentContext, TSchemas, TErrorMap, TMeta>);
50
+ }
51
+ type AnyProcedure = Procedure<any, any, Schemas, any, any>;
52
+ declare function isProcedure(item: unknown): item is AnyProcedure;
53
+
54
+ type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
55
+ output: TOutput;
56
+ context: TOutContext;
57
+ }>;
58
+ interface MiddlewareNextFn<TOutput> {
59
+ <U extends Context = {}>(options?: {
60
+ context?: U;
61
+ }): MiddlewareResult<U, TOutput>;
62
+ }
63
+ interface MiddlewareOutputFn<TOutput> {
64
+ (output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
65
+ }
66
+ interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> extends ProcedureHandlerOptions<TInContext, TErrorConstructorMap, TMeta> {
67
+ next: MiddlewareNextFn<TOutput>;
68
+ }
69
+ /**
70
+ * A function that represents a middleware.
71
+ *
72
+ * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
73
+ */
74
+ interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
75
+ (options: MiddlewareOptions<TInContext, TOutput, TErrorConstructorMap, TMeta>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
76
+ }
77
+ type AnyMiddleware = Middleware<any, any, any, any, any, any>;
78
+ interface MapInputMiddleware<TInput, TMappedInput> {
79
+ (input: TInput): TMappedInput;
80
+ }
81
+ declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
82
+
83
+ /**
84
+ * Represents a router, which defines a hierarchical structure of procedures.
85
+ *
86
+ * @info A procedure is a router too.
87
+ * @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#contract-router Contract Router Docs}
88
+ */
89
+ type Router<T extends AnyContractRouter, TInitialContext extends Context> = T extends ContractProcedure<infer USchemas, infer UErrorMap, infer UMeta> ? Procedure<TInitialContext, any, USchemas, UErrorMap, UMeta> : {
90
+ [K in keyof T]: T[K] extends AnyContractRouter ? Lazyable<Router<T[K], TInitialContext>> : never;
91
+ };
92
+ type AnyRouter = Router<any, any>;
93
+ type InferRouterInitialContext<T extends AnyRouter> = T extends Router<any, infer UInitialContext> ? UInitialContext : never;
94
+ /**
95
+ * Infer all initial context of the router.
96
+ *
97
+ * @info A procedure is a router too.
98
+ * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
99
+ */
100
+ type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any> ? UInitialContext : {
101
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never;
102
+ };
103
+ /**
104
+ * Infer all current context of the router.
105
+ *
106
+ * @info A procedure is a router too.
107
+ * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
108
+ */
109
+ type InferRouterCurrentContexts<T extends AnyRouter> = T extends Procedure<any, infer UCurrentContext, any, any, any> ? UCurrentContext : {
110
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterCurrentContexts<U> : never;
111
+ };
112
+ /**
113
+ * Infer all router inputs
114
+ *
115
+ * @info A procedure is a router too.
116
+ * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
117
+ */
118
+ type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer USchemas, any, any> ? InferProcedureClientInputs<USchemas> : {
119
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never;
120
+ };
121
+ /**
122
+ * Infer all router outputs
123
+ *
124
+ * @info A procedure is a router too.
125
+ * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
126
+ */
127
+ type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, infer USchemas, any, any> ? InferSchemaOutput<USchemas['outputSchema']> : {
128
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
129
+ };
130
+
131
+ declare function getRouter<T extends Lazyable<AnyRouter | undefined>>(router: T, path: readonly string[]): T extends Lazy<any> ? Lazy<AnyRouter | undefined> : Lazyable<AnyRouter | undefined>;
132
+ type AccessibleLazyRouter<T extends Lazyable<AnyRouter | undefined>> = T extends Lazy<infer U extends AnyRouter | undefined | Lazy<AnyRouter | undefined>> ? AccessibleLazyRouter<U> : T extends AnyProcedure | undefined ? Lazy<T> : Lazy<T> & {
133
+ [K in keyof T]: T[K] extends Lazyable<AnyRouter> ? AccessibleLazyRouter<T[K]> : never;
134
+ };
135
+ declare function createAccessibleLazyRouter<T extends Lazy<AnyRouter | undefined>>(lazied: T): AccessibleLazyRouter<T>;
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> : {
137
+ [K in keyof T]: T[K] extends Lazyable<AnyRouter> ? EnhancedRouter<T[K], TInitialContext, TCurrentContext, TErrorMap> : never;
138
+ };
139
+ interface EnhanceRouterOptions<TErrorMap extends ErrorMap> extends EnhanceRouteOptions {
140
+ middlewares: readonly AnyMiddleware[];
141
+ errorMap: TErrorMap;
142
+ dedupeLeadingMiddlewares: boolean;
143
+ }
144
+ declare function enhanceRouter<T extends Lazyable<AnyRouter>, TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap>(router: T, options: EnhanceRouterOptions<TErrorMap>): EnhancedRouter<T, TInitialContext, TCurrentContext, TErrorMap>;
145
+ interface TraverseContractProceduresOptions {
146
+ router: AnyContractRouter | AnyRouter;
147
+ path: readonly string[];
148
+ }
149
+ interface TraverseContractProcedureCallbackOptions {
150
+ contract: AnyContractProcedure | AnyProcedure;
151
+ path: readonly string[];
152
+ }
153
+ /**
154
+ * @deprecated Use `TraverseContractProcedureCallbackOptions` instead.
155
+ */
156
+ type ContractProcedureCallbackOptions = TraverseContractProcedureCallbackOptions;
157
+ interface LazyTraverseContractProceduresOptions {
158
+ router: Lazy<AnyRouter>;
159
+ path: readonly string[];
160
+ }
161
+ declare function traverseContractProcedures(options: TraverseContractProceduresOptions, callback: (options: TraverseContractProcedureCallbackOptions) => void, lazyOptions?: LazyTraverseContractProceduresOptions[]): LazyTraverseContractProceduresOptions[];
162
+ declare function resolveContractProcedures(options: TraverseContractProceduresOptions, callback: (options: TraverseContractProcedureCallbackOptions) => void): Promise<void>;
163
+ type UnlaziedRouter<T extends AnyRouter> = T extends AnyProcedure ? T : {
164
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? UnlaziedRouter<U> : never;
165
+ };
166
+ declare function unlazyRouter<T extends AnyRouter>(router: T): Promise<UnlaziedRouter<T>>;
167
+
168
+ declare const LAZY_SYMBOL: unique symbol;
169
+ interface LazyMeta {
170
+ prefix?: HTTPPath;
171
+ }
172
+ interface Lazy<T> {
173
+ [LAZY_SYMBOL]: {
174
+ loader: () => Promise<{
175
+ default: T;
176
+ }>;
177
+ meta: LazyMeta;
178
+ };
179
+ }
180
+ type Lazyable<T> = T | Lazy<T>;
181
+ /**
182
+ * @internal
183
+ */
184
+ declare function lazyInternal<T>(loader: () => Promise<{
185
+ default: T;
186
+ }>, meta?: LazyMeta): Lazy<T>;
187
+ /**
188
+ * Creates a lazy-loaded item.
189
+ *
190
+ * @warning The `prefix` in `meta` only holds metadata and does not apply the prefix to the lazy router, use `os.prefix(...).lazyRoute(...)` instead.
191
+ */
192
+ declare function lazy<T extends Router<ContractRouter<{}>, any>>(prefix: HTTPPath, loader: () => Promise<{
193
+ default: T;
194
+ }>): EnhancedRouter<Lazy<T>, {}, {}, {}>;
195
+ declare function isLazy(item: unknown): item is Lazy<any>;
196
+ declare function getLazyMeta(lazied: Lazy<any>): LazyMeta;
197
+ declare function unlazy<T extends Lazyable<any>>(lazied: T): Promise<{
198
+ default: T extends Lazy<infer U> ? U : T;
199
+ }>;
200
+
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
+ };
208
+ }
209
+ type CreateProcedureClientOptions<TInitialContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext> = {
210
+ /**
211
+ * This is helpful for logging and analytics.
212
+ */
213
+ path?: readonly string[];
214
+ interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TErrorMap, TMeta>, PromiseWithError<InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>>[];
215
+ } & (Record<never, never> extends TInitialContext ? {
216
+ context?: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
217
+ } : {
218
+ context: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
219
+ });
220
+ /**
221
+ * Create Server-side client from a procedure.
222
+ *
223
+ * @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
224
+ */
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>;
226
+
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 };