@temporary-name/server 1.9.3-alpha.afd18ec2afa743b08cf1b5c2eb6252ded18a1f43 → 1.9.3-alpha.b7ce8fb6e9463a26fd2564cb172dc612ae4de52d

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 (34) 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 +5 -7
  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 +5 -7
  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 +5 -7
  10. package/dist/adapters/standard/index.d.mts +20 -78
  11. package/dist/adapters/standard/index.d.ts +20 -78
  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 -2
  17. package/dist/openapi/index.d.ts +1 -2
  18. package/dist/openapi/index.mjs +63 -88
  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._YqJjI50.mjs → server.CVBLzkro.mjs} +57 -99
  25. package/dist/shared/server.ClhVCxfg.mjs +413 -0
  26. package/dist/shared/{server.CQyYNJ1H.d.ts → server.D6Qs_UcF.d.mts} +2 -4
  27. package/dist/shared/{server.SLLuK6_v.d.ts → server.DFptr1Nz.d.ts} +2 -2
  28. package/dist/shared/{server.C1fnTLq0.d.mts → server.DpoO_ER_.d.ts} +2 -4
  29. package/dist/shared/server.JtIZ8YG7.mjs +237 -0
  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
  34. package/dist/shared/server.DhdDYN-Z.mjs +0 -261
@@ -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 { s as standardizeHTTPPath, b as StandardOpenAPIJsonSerializer, g as getDynamicParams, a as StandardOpenAPISerializer, S as StandardBracketNotationSerializer } from '../shared/server.DhdDYN-Z.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';
@@ -380,10 +380,8 @@ class CompositeSchemaConverter {
380
380
  class OpenAPIGeneratorError extends Error {
381
381
  }
382
382
  class OpenAPIGenerator {
383
- serializer;
384
383
  converter;
385
384
  constructor(options = {}) {
386
- this.serializer = new StandardOpenAPIJsonSerializer();
387
385
  this.converter = new CompositeSchemaConverter(toArray(options.schemaConverters));
388
386
  }
389
387
  /**
@@ -464,7 +462,7 @@ ${e.message}`
464
462
  ${errors.join("\n\n")}`
465
463
  );
466
464
  }
467
- return this.serializer.serialize(doc)[0];
465
+ return jsonSerialize(doc)[0];
468
466
  }
469
467
  async #resolveCommonSchemas(doc, commonSchemas) {
470
468
  let undefinedErrorJsonSchema = {
@@ -532,94 +530,77 @@ ${errors.join("\n\n")}`
532
530
  }
533
531
  async #request(doc, ref, def, baseSchemaConvertOptions) {
534
532
  const method = fallbackContractConfig("defaultMethod", def.route.method);
535
- const details = getEventIteratorSchemaDetails(def.inputSchema);
536
- if (details) {
537
- ref.requestBody = {
538
- required: true,
539
- content: toOpenAPIEventIteratorContent(
540
- await this.converter.convert(details.yields, { ...baseSchemaConvertOptions, strategy: "input" }),
541
- await this.converter.convert(details.returns, { ...baseSchemaConvertOptions, strategy: "input" })
542
- )
543
- };
544
- return;
545
- }
546
533
  const dynamicParams = getDynamicParams(def.route.path)?.map((v) => v.name);
547
- const inputStructure = fallbackContractConfig("defaultInputStructure", def.route.inputStructure);
548
- let [required, schema] = await this.converter.convert(def.inputSchema, {
534
+ const [_pathRequired, pathSchema] = await this.converter.convert(def.schemas.pathSchema, {
549
535
  ...baseSchemaConvertOptions,
550
536
  strategy: "input",
551
- minStructureDepthForRef: dynamicParams?.length || inputStructure === "detailed" ? 1 : 0
537
+ minStructureDepthForRef: 1
552
538
  });
553
- if (isAnySchema(schema) && !dynamicParams?.length) {
554
- return;
555
- }
556
- if (inputStructure === "compact") {
557
- if (dynamicParams?.length) {
558
- const error2 = new OpenAPIGeneratorError(
559
- 'When input structure is "compact", and path has dynamic params, input schema must be an object with all dynamic params as required.'
560
- );
561
- if (!isObjectSchema(schema)) {
562
- throw error2;
563
- }
564
- const [paramsSchema, rest] = separateObjectSchema(schema, dynamicParams);
565
- schema = rest;
566
- required = rest.required ? rest.required.length !== 0 : false;
567
- if (!checkParamsSchema(paramsSchema, dynamicParams)) {
568
- throw error2;
569
- }
570
- ref.parameters ??= [];
571
- 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;
572
546
  }
573
- if (method === "GET") {
574
- const resolvedSchema = resolveOpenAPIJsonSchemaRef(doc, schema);
575
- if (!isObjectSchema(resolvedSchema)) {
576
- throw new OpenAPIGeneratorError(
577
- 'When method is "GET", input schema must satisfy: object | any | unknown'
578
- );
579
- }
580
- ref.parameters ??= [];
581
- ref.parameters.push(...toOpenAPIParameters(resolvedSchema, "query"));
582
- } else {
583
- ref.requestBody = {
584
- required,
585
- content: toOpenAPIContent(schema)
586
- };
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;
587
561
  }
588
- return;
589
- }
590
- const error = new OpenAPIGeneratorError(
591
- 'When input structure is "detailed", input schema must satisfy: { params?: Record<string, unknown>, query?: Record<string, unknown>, headers?: Record<string, unknown>, body?: unknown }'
592
- );
593
- if (!isObjectSchema(schema)) {
594
- throw error;
595
562
  }
596
- const resolvedParamSchema = schema.properties?.params !== void 0 ? resolveOpenAPIJsonSchemaRef(doc, schema.properties.params) : void 0;
597
- if (dynamicParams?.length && (resolvedParamSchema === void 0 || !isObjectSchema(resolvedParamSchema) || !checkParamsSchema(resolvedParamSchema, dynamicParams))) {
598
- throw new OpenAPIGeneratorError(
599
- 'When input structure is "detailed" and path has dynamic params, the "params" schema must be an object with all dynamic params as required.'
600
- );
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"));
601
575
  }
602
- for (const from of ["params", "query", "headers"]) {
603
- const fromSchema = schema.properties?.[from];
604
- if (fromSchema !== void 0) {
605
- const resolvedSchema = resolveOpenAPIJsonSchemaRef(doc, fromSchema);
606
- if (!isObjectSchema(resolvedSchema)) {
607
- 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;
608
594
  }
609
- const parameterIn = from === "params" ? "path" : from === "headers" ? "header" : "query";
610
- ref.parameters ??= [];
611
- ref.parameters.push(...toOpenAPIParameters(resolvedSchema, parameterIn));
595
+ ref.requestBody = {
596
+ required: bodyRequired,
597
+ content: toOpenAPIContent(bodySchema)
598
+ };
612
599
  }
613
600
  }
614
- if (schema.properties?.body !== void 0) {
615
- ref.requestBody = {
616
- required: schema.required?.includes("body"),
617
- content: toOpenAPIContent(schema.properties.body)
618
- };
619
- }
620
601
  }
621
602
  async #successResponse(doc, ref, def, baseSchemaConvertOptions) {
622
- const outputSchema = def.outputSchema;
603
+ const outputSchema = def.schemas.outputSchema;
623
604
  const status = fallbackContractConfig("defaultSuccessStatus", def.route.successStatus);
624
605
  const description = fallbackContractConfig("defaultSuccessDescription", def.route?.successDescription);
625
606
  const eventIteratorSchemaDetails = getEventIteratorSchemaDetails(outputSchema);
@@ -757,19 +738,13 @@ ${errors.join("\n\n")}`
757
738
 
758
739
  function createJsonifiedRouterClient(router, ...rest) {
759
740
  const options = resolveMaybeOptionalOptions(rest);
760
- const serializer = new StandardOpenAPISerializer(
761
- new StandardOpenAPIJsonSerializer(),
762
- new StandardBracketNotationSerializer()
763
- );
764
741
  options.interceptors ??= [];
765
742
  options.interceptors.unshift(async (options2) => {
766
743
  try {
767
- return serializer.deserialize(serializer.serialize(await options2.next()));
744
+ return deserialize(serialize(await options2.next()));
768
745
  } catch (e) {
769
746
  if (e instanceof ORPCError) {
770
- throw createORPCErrorFromJson(
771
- serializer.deserialize(serializer.serialize(e.toJSON(), { outputFormat: "plain" }))
772
- );
747
+ throw createORPCErrorFromJson(deserialize(serialize(e.toJSON(), { outputFormat: "plain" })));
773
748
  }
774
749
  throw e;
775
750
  }
@@ -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 };