@temporary-name/server 1.9.3-alpha.592ae1e02e18c5274906b132313b083116248636 → 1.9.3-alpha.5c041722542bb790586629fc98d4c72d9f6ee65e
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.
- package/dist/adapters/aws-lambda/index.d.mts +3 -3
- package/dist/adapters/aws-lambda/index.d.ts +3 -3
- package/dist/adapters/aws-lambda/index.mjs +4 -6
- package/dist/adapters/fetch/index.d.mts +3 -3
- package/dist/adapters/fetch/index.d.ts +3 -3
- package/dist/adapters/fetch/index.mjs +4 -6
- package/dist/adapters/node/index.d.mts +3 -3
- package/dist/adapters/node/index.d.ts +3 -3
- package/dist/adapters/node/index.mjs +4 -6
- package/dist/adapters/standard/index.d.mts +14 -30
- package/dist/adapters/standard/index.d.ts +14 -30
- package/dist/adapters/standard/index.mjs +4 -6
- package/dist/index.d.mts +60 -334
- package/dist/index.d.ts +60 -334
- package/dist/index.mjs +111 -354
- package/dist/openapi/index.mjs +30 -64
- package/dist/plugins/index.d.mts +2 -2
- package/dist/plugins/index.d.ts +2 -2
- package/dist/shared/{server.BKSOrA6h.d.mts → server.B5czSQQh.d.mts} +114 -71
- package/dist/shared/{server.BKSOrA6h.d.ts → server.B5czSQQh.d.ts} +114 -71
- package/dist/shared/server.BdGbIyq8.mjs +396 -0
- package/dist/shared/{server.BeuTpcmO.d.mts → server.Bk8Hmx7Z.d.mts} +2 -2
- package/dist/shared/{server.CQyYNJ1H.d.ts → server.C4l2ZA3m.d.ts} +1 -2
- package/dist/shared/{server.SLLuK6_v.d.ts → server.D7UjcuIv.d.ts} +2 -2
- package/dist/shared/{server.BEHw7Eyx.mjs → server.Kxw442A9.mjs} +1 -1
- package/dist/shared/{server.DLsti1Pv.mjs → server.SmOM3Fae.mjs} +58 -89
- package/dist/shared/{server.C1fnTLq0.d.mts → server.TgmlNh8r.d.mts} +1 -2
- package/package.json +10 -9
- package/dist/shared/server.BKh8I1Ny.mjs +0 -239
package/dist/openapi/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isProcedure, resolveContractProcedures, ORPCError, createRouterClient } from '@temporary-name/server';
|
|
2
2
|
import { fallbackContractConfig, 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.
|
|
4
|
+
import { a as standardizeHTTPPath, j as jsonSerialize, g as getDynamicParams, d as deserialize, s as serialize } from '../shared/server.Kxw442A9.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,7 +530,7 @@ ${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);
|
|
533
|
+
const details = getEventIteratorSchemaDetails(def.schemas.inputSchema);
|
|
534
534
|
if (details) {
|
|
535
535
|
ref.requestBody = {
|
|
536
536
|
required: true,
|
|
@@ -542,82 +542,48 @@ ${errors.join("\n\n")}`
|
|
|
542
542
|
return;
|
|
543
543
|
}
|
|
544
544
|
const dynamicParams = getDynamicParams(def.route.path)?.map((v) => v.name);
|
|
545
|
-
|
|
546
|
-
let [required, schema] = await this.converter.convert(def.inputSchema, {
|
|
545
|
+
let [required, schema] = await this.converter.convert(def.schemas.inputSchema, {
|
|
547
546
|
...baseSchemaConvertOptions,
|
|
548
547
|
strategy: "input",
|
|
549
|
-
minStructureDepthForRef: dynamicParams?.length
|
|
548
|
+
minStructureDepthForRef: dynamicParams?.length ? 1 : 0
|
|
550
549
|
});
|
|
551
550
|
if (isAnySchema(schema) && !dynamicParams?.length) {
|
|
552
551
|
return;
|
|
553
552
|
}
|
|
554
|
-
if (
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
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"));
|
|
553
|
+
if (dynamicParams?.length) {
|
|
554
|
+
const error = new OpenAPIGeneratorError(
|
|
555
|
+
'When input structure is "compact", and path has dynamic params, input schema must be an object with all dynamic params as required.'
|
|
556
|
+
);
|
|
557
|
+
if (!isObjectSchema(schema)) {
|
|
558
|
+
throw error;
|
|
570
559
|
}
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
);
|
|
577
|
-
}
|
|
578
|
-
ref.parameters ??= [];
|
|
579
|
-
ref.parameters.push(...toOpenAPIParameters(resolvedSchema, "query"));
|
|
580
|
-
} else {
|
|
581
|
-
ref.requestBody = {
|
|
582
|
-
required,
|
|
583
|
-
content: toOpenAPIContent(schema)
|
|
584
|
-
};
|
|
560
|
+
const [paramsSchema, rest] = separateObjectSchema(schema, dynamicParams);
|
|
561
|
+
schema = rest;
|
|
562
|
+
required = rest.required ? rest.required.length !== 0 : false;
|
|
563
|
+
if (!checkParamsSchema(paramsSchema, dynamicParams)) {
|
|
564
|
+
throw error;
|
|
585
565
|
}
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
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
|
-
);
|
|
599
|
-
}
|
|
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;
|
|
606
|
-
}
|
|
607
|
-
const parameterIn = from === "params" ? "path" : from === "headers" ? "header" : "query";
|
|
608
|
-
ref.parameters ??= [];
|
|
609
|
-
ref.parameters.push(...toOpenAPIParameters(resolvedSchema, parameterIn));
|
|
566
|
+
ref.parameters ??= [];
|
|
567
|
+
ref.parameters.push(...toOpenAPIParameters(paramsSchema, "path"));
|
|
568
|
+
}
|
|
569
|
+
if (method === "GET") {
|
|
570
|
+
const resolvedSchema = resolveOpenAPIJsonSchemaRef(doc, schema);
|
|
571
|
+
if (!isObjectSchema(resolvedSchema)) {
|
|
572
|
+
throw new OpenAPIGeneratorError(
|
|
573
|
+
'When method is "GET", input schema must satisfy: object | any | unknown'
|
|
574
|
+
);
|
|
610
575
|
}
|
|
611
|
-
|
|
612
|
-
|
|
576
|
+
ref.parameters ??= [];
|
|
577
|
+
ref.parameters.push(...toOpenAPIParameters(resolvedSchema, "query"));
|
|
578
|
+
} else {
|
|
613
579
|
ref.requestBody = {
|
|
614
|
-
required
|
|
615
|
-
content: toOpenAPIContent(schema
|
|
580
|
+
required,
|
|
581
|
+
content: toOpenAPIContent(schema)
|
|
616
582
|
};
|
|
617
583
|
}
|
|
618
584
|
}
|
|
619
585
|
async #successResponse(doc, ref, def, baseSchemaConvertOptions) {
|
|
620
|
-
const outputSchema = def.outputSchema;
|
|
586
|
+
const outputSchema = def.schemas.outputSchema;
|
|
621
587
|
const status = fallbackContractConfig("defaultSuccessStatus", def.route.successStatus);
|
|
622
588
|
const description = fallbackContractConfig("defaultSuccessDescription", def.route?.successDescription);
|
|
623
589
|
const eventIteratorSchemaDetails = getEventIteratorSchemaDetails(outputSchema);
|
package/dist/plugins/index.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Value, Promisable, ORPCError } from '@temporary-name/shared';
|
|
2
2
|
import { StandardRequest, StandardHeaders } from '@temporary-name/standard-server';
|
|
3
3
|
import { BatchResponseBodyItem } from '@temporary-name/standard-server/batch';
|
|
4
|
-
import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.
|
|
5
|
-
import { C as Context,
|
|
4
|
+
import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.TgmlNh8r.mjs';
|
|
5
|
+
import { C as Context, H as ProcedureClientInterceptorOptions } from '../shared/server.B5czSQQh.mjs';
|
|
6
6
|
import { Meta } from '@temporary-name/contract';
|
|
7
7
|
|
|
8
8
|
interface BatchHandlerOptions<T extends Context> {
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Value, Promisable, ORPCError } from '@temporary-name/shared';
|
|
2
2
|
import { StandardRequest, StandardHeaders } from '@temporary-name/standard-server';
|
|
3
3
|
import { BatchResponseBodyItem } from '@temporary-name/standard-server/batch';
|
|
4
|
-
import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.
|
|
5
|
-
import { C as Context,
|
|
4
|
+
import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.C4l2ZA3m.js';
|
|
5
|
+
import { C as Context, H as ProcedureClientInterceptorOptions } from '../shared/server.B5czSQQh.js';
|
|
6
6
|
import { Meta } from '@temporary-name/contract';
|
|
7
7
|
|
|
8
8
|
interface BatchHandlerOptions<T extends Context> {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ErrorMap, ErrorMapItem, InferSchemaInput,
|
|
2
|
-
import { ORPCErrorCode, MaybeOptionalOptions, ORPCErrorOptions, ORPCError,
|
|
1
|
+
import { ErrorMap, ErrorMapItem, InferSchemaInput, Schemas, Meta, ContractProcedureDef, AnyContractRouter, ContractProcedure, InferSchemaOutput, EnhanceRouteOptions, MergedErrorMap, AnyContractProcedure, ContractRouter, AnySchema, ErrorFromErrorMap } from '@temporary-name/contract';
|
|
2
|
+
import { ORPCErrorCode, MaybeOptionalOptions, ORPCErrorOptions, ORPCError, Promisable, HTTPPath, ClientContext, Interceptor, PromiseWithError, Value, Client } from '@temporary-name/shared';
|
|
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,38 +13,11 @@ type ORPCErrorConstructorMap<T extends ErrorMap> = {
|
|
|
13
13
|
};
|
|
14
14
|
declare function createORPCErrorConstructorMap<T extends ErrorMap>(errors: T): ORPCErrorConstructorMap<T>;
|
|
15
15
|
|
|
16
|
-
declare const LAZY_SYMBOL: unique symbol;
|
|
17
|
-
interface LazyMeta {
|
|
18
|
-
prefix?: HTTPPath;
|
|
19
|
-
}
|
|
20
|
-
interface Lazy<T> {
|
|
21
|
-
[LAZY_SYMBOL]: {
|
|
22
|
-
loader: () => Promise<{
|
|
23
|
-
default: T;
|
|
24
|
-
}>;
|
|
25
|
-
meta: LazyMeta;
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
type Lazyable<T> = T | Lazy<T>;
|
|
29
|
-
/**
|
|
30
|
-
* Creates a lazy-loaded item.
|
|
31
|
-
*
|
|
32
|
-
* @warning The `prefix` in `meta` only holds metadata and does not apply the prefix to the lazy router, use `os.prefix(...).lazyRoute(...)` instead.
|
|
33
|
-
*/
|
|
34
|
-
declare function lazy<T>(loader: () => Promise<{
|
|
35
|
-
default: T;
|
|
36
|
-
}>, meta?: LazyMeta): Lazy<T>;
|
|
37
|
-
declare function isLazy(item: unknown): item is Lazy<any>;
|
|
38
|
-
declare function getLazyMeta(lazied: Lazy<any>): LazyMeta;
|
|
39
|
-
declare function unlazy<T extends Lazyable<any>>(lazied: T): Promise<{
|
|
40
|
-
default: T extends Lazy<infer U> ? U : T;
|
|
41
|
-
}>;
|
|
42
|
-
|
|
43
16
|
interface ProcedureHandlerOptions<TCurrentContext extends Context, TInput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
|
44
17
|
context: TCurrentContext;
|
|
45
18
|
input: TInput;
|
|
46
19
|
path: readonly string[];
|
|
47
|
-
procedure: Procedure<Context, Context,
|
|
20
|
+
procedure: Procedure<Context, Context, Schemas, ErrorMap, TMeta>;
|
|
48
21
|
signal?: AbortSignal;
|
|
49
22
|
lastEventId: string | undefined;
|
|
50
23
|
errors: TErrorConstructorMap;
|
|
@@ -52,7 +25,7 @@ interface ProcedureHandlerOptions<TCurrentContext extends Context, TInput, TErro
|
|
|
52
25
|
interface ProcedureHandler<TCurrentContext extends Context, TInput, THandlerOutput, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
|
53
26
|
(opt: ProcedureHandlerOptions<TCurrentContext, TInput, ORPCErrorConstructorMap<TErrorMap>, TMeta>): Promisable<THandlerOutput>;
|
|
54
27
|
}
|
|
55
|
-
interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends Context,
|
|
28
|
+
interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TSchemas, TErrorMap, TMeta> {
|
|
56
29
|
__initialContext?: (type: TInitialContext) => unknown;
|
|
57
30
|
middlewares: readonly AnyMiddleware[];
|
|
58
31
|
inputValidationIndex: number;
|
|
@@ -64,14 +37,14 @@ interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends
|
|
|
64
37
|
*
|
|
65
38
|
* @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
|
|
66
39
|
*/
|
|
67
|
-
declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context,
|
|
40
|
+
declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
|
68
41
|
/**
|
|
69
42
|
* This property holds the defined options.
|
|
70
43
|
*/
|
|
71
|
-
'~orpc': ProcedureDef<TInitialContext, TCurrentContext,
|
|
72
|
-
constructor(def: ProcedureDef<TInitialContext, TCurrentContext,
|
|
44
|
+
'~orpc': ProcedureDef<TInitialContext, TCurrentContext, TSchemas, TErrorMap, TMeta>;
|
|
45
|
+
constructor(def: ProcedureDef<TInitialContext, TCurrentContext, TSchemas, TErrorMap, TMeta>);
|
|
73
46
|
}
|
|
74
|
-
type AnyProcedure = Procedure<any, any,
|
|
47
|
+
type AnyProcedure = Procedure<any, any, Schemas, any, any>;
|
|
75
48
|
declare function isProcedure(item: unknown): item is AnyProcedure;
|
|
76
49
|
|
|
77
50
|
type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
|
|
@@ -92,7 +65,7 @@ interface MiddlewareOutputFn<TOutput> {
|
|
|
92
65
|
interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
|
93
66
|
context: TInContext;
|
|
94
67
|
path: readonly string[];
|
|
95
|
-
procedure: Procedure<Context, Context,
|
|
68
|
+
procedure: Procedure<Context, Context, Schemas, ErrorMap, TMeta>;
|
|
96
69
|
signal?: AbortSignal;
|
|
97
70
|
lastEventId: string | undefined;
|
|
98
71
|
next: MiddlewareNextFn<TOutput>;
|
|
@@ -112,41 +85,13 @@ interface MapInputMiddleware<TInput, TMappedInput> {
|
|
|
112
85
|
}
|
|
113
86
|
declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
|
|
114
87
|
|
|
115
|
-
type ProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
|
|
116
|
-
interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
|
117
|
-
context: TInitialContext;
|
|
118
|
-
input: unknown;
|
|
119
|
-
errors: ORPCErrorConstructorMap<TErrorMap>;
|
|
120
|
-
path: readonly string[];
|
|
121
|
-
procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
|
|
122
|
-
signal?: AbortSignal;
|
|
123
|
-
lastEventId: string | undefined;
|
|
124
|
-
}
|
|
125
|
-
type CreateProcedureClientOptions<TInitialContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext> = {
|
|
126
|
-
/**
|
|
127
|
-
* This is helpful for logging and analytics.
|
|
128
|
-
*/
|
|
129
|
-
path?: readonly string[];
|
|
130
|
-
interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TErrorMap, TMeta>, PromiseWithError<InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>>[];
|
|
131
|
-
} & (Record<never, never> extends TInitialContext ? {
|
|
132
|
-
context?: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
|
|
133
|
-
} : {
|
|
134
|
-
context: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
|
|
135
|
-
});
|
|
136
|
-
/**
|
|
137
|
-
* Create Server-side client from a procedure.
|
|
138
|
-
*
|
|
139
|
-
* @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
|
|
140
|
-
*/
|
|
141
|
-
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>;
|
|
142
|
-
|
|
143
88
|
/**
|
|
144
89
|
* Represents a router, which defines a hierarchical structure of procedures.
|
|
145
90
|
*
|
|
146
91
|
* @info A procedure is a router too.
|
|
147
92
|
* @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#contract-router Contract Router Docs}
|
|
148
93
|
*/
|
|
149
|
-
type Router<T extends AnyContractRouter, TInitialContext extends Context> = T extends ContractProcedure<infer
|
|
94
|
+
type Router<T extends AnyContractRouter, TInitialContext extends Context> = T extends ContractProcedure<infer USchemas, infer UErrorMap, infer UMeta> ? Procedure<TInitialContext, any, USchemas, UErrorMap, UMeta> : {
|
|
150
95
|
[K in keyof T]: T[K] extends AnyContractRouter ? Lazyable<Router<T[K], TInitialContext>> : never;
|
|
151
96
|
};
|
|
152
97
|
type AnyRouter = Router<any, any>;
|
|
@@ -157,7 +102,7 @@ type InferRouterInitialContext<T extends AnyRouter> = T extends Router<any, infe
|
|
|
157
102
|
* @info A procedure is a router too.
|
|
158
103
|
* @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
|
|
159
104
|
*/
|
|
160
|
-
type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any
|
|
105
|
+
type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any> ? UInitialContext : {
|
|
161
106
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never;
|
|
162
107
|
};
|
|
163
108
|
/**
|
|
@@ -166,7 +111,7 @@ type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer
|
|
|
166
111
|
* @info A procedure is a router too.
|
|
167
112
|
* @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
|
|
168
113
|
*/
|
|
169
|
-
type InferRouterCurrentContexts<T extends AnyRouter> = T extends Procedure<any, infer UCurrentContext, any, any, any
|
|
114
|
+
type InferRouterCurrentContexts<T extends AnyRouter> = T extends Procedure<any, infer UCurrentContext, any, any, any> ? UCurrentContext : {
|
|
170
115
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterCurrentContexts<U> : never;
|
|
171
116
|
};
|
|
172
117
|
/**
|
|
@@ -175,7 +120,7 @@ type InferRouterCurrentContexts<T extends AnyRouter> = T extends Procedure<any,
|
|
|
175
120
|
* @info A procedure is a router too.
|
|
176
121
|
* @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
|
|
177
122
|
*/
|
|
178
|
-
type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer
|
|
123
|
+
type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer USchemas, any, any> ? InferSchemaInput<USchemas['inputSchema']> : {
|
|
179
124
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never;
|
|
180
125
|
};
|
|
181
126
|
/**
|
|
@@ -184,9 +129,107 @@ type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infe
|
|
|
184
129
|
* @info A procedure is a router too.
|
|
185
130
|
* @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
|
|
186
131
|
*/
|
|
187
|
-
type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any,
|
|
132
|
+
type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, infer USchemas, any, any> ? InferSchemaOutput<USchemas['outputSchema']> : {
|
|
188
133
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
|
|
189
134
|
};
|
|
190
135
|
|
|
191
|
-
|
|
192
|
-
|
|
136
|
+
declare function getRouter<T extends Lazyable<AnyRouter | undefined>>(router: T, path: readonly string[]): T extends Lazy<any> ? Lazy<AnyRouter | undefined> : Lazyable<AnyRouter | undefined>;
|
|
137
|
+
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> & {
|
|
138
|
+
[K in keyof T]: T[K] extends Lazyable<AnyRouter> ? AccessibleLazyRouter<T[K]> : never;
|
|
139
|
+
};
|
|
140
|
+
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 USchemas, infer UErrorMap, infer UMeta>) ? Procedure<MergedInitialContext<TInitialContext, UInitialContext, TCurrentContext>, UCurrentContext, USchemas, MergedErrorMap<TErrorMap, UErrorMap>, UMeta> : {
|
|
142
|
+
[K in keyof T]: T[K] extends Lazyable<AnyRouter> ? EnhancedRouter<T[K], TInitialContext, TCurrentContext, TErrorMap> : never;
|
|
143
|
+
};
|
|
144
|
+
interface EnhanceRouterOptions<TErrorMap extends ErrorMap> extends EnhanceRouteOptions {
|
|
145
|
+
middlewares: readonly AnyMiddleware[];
|
|
146
|
+
errorMap: TErrorMap;
|
|
147
|
+
dedupeLeadingMiddlewares: boolean;
|
|
148
|
+
}
|
|
149
|
+
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>;
|
|
150
|
+
interface TraverseContractProceduresOptions {
|
|
151
|
+
router: AnyContractRouter | AnyRouter;
|
|
152
|
+
path: readonly string[];
|
|
153
|
+
}
|
|
154
|
+
interface TraverseContractProcedureCallbackOptions {
|
|
155
|
+
contract: AnyContractProcedure | AnyProcedure;
|
|
156
|
+
path: readonly string[];
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* @deprecated Use `TraverseContractProcedureCallbackOptions` instead.
|
|
160
|
+
*/
|
|
161
|
+
type ContractProcedureCallbackOptions = TraverseContractProcedureCallbackOptions;
|
|
162
|
+
interface LazyTraverseContractProceduresOptions {
|
|
163
|
+
router: Lazy<AnyRouter>;
|
|
164
|
+
path: readonly string[];
|
|
165
|
+
}
|
|
166
|
+
declare function traverseContractProcedures(options: TraverseContractProceduresOptions, callback: (options: TraverseContractProcedureCallbackOptions) => void, lazyOptions?: LazyTraverseContractProceduresOptions[]): LazyTraverseContractProceduresOptions[];
|
|
167
|
+
declare function resolveContractProcedures(options: TraverseContractProceduresOptions, callback: (options: TraverseContractProcedureCallbackOptions) => void): Promise<void>;
|
|
168
|
+
type UnlaziedRouter<T extends AnyRouter> = T extends AnyProcedure ? T : {
|
|
169
|
+
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? UnlaziedRouter<U> : never;
|
|
170
|
+
};
|
|
171
|
+
declare function unlazyRouter<T extends AnyRouter>(router: T): Promise<UnlaziedRouter<T>>;
|
|
172
|
+
|
|
173
|
+
declare const LAZY_SYMBOL: unique symbol;
|
|
174
|
+
interface LazyMeta {
|
|
175
|
+
prefix?: HTTPPath;
|
|
176
|
+
}
|
|
177
|
+
interface Lazy<T> {
|
|
178
|
+
[LAZY_SYMBOL]: {
|
|
179
|
+
loader: () => Promise<{
|
|
180
|
+
default: T;
|
|
181
|
+
}>;
|
|
182
|
+
meta: LazyMeta;
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
type Lazyable<T> = T | Lazy<T>;
|
|
186
|
+
/**
|
|
187
|
+
* @internal
|
|
188
|
+
*/
|
|
189
|
+
declare function lazyInternal<T>(loader: () => Promise<{
|
|
190
|
+
default: T;
|
|
191
|
+
}>, meta?: LazyMeta): Lazy<T>;
|
|
192
|
+
/**
|
|
193
|
+
* Creates a lazy-loaded item.
|
|
194
|
+
*
|
|
195
|
+
* @warning The `prefix` in `meta` only holds metadata and does not apply the prefix to the lazy router, use `os.prefix(...).lazyRoute(...)` instead.
|
|
196
|
+
*/
|
|
197
|
+
declare function lazy<T extends Router<ContractRouter<{}>, any>>(prefix: HTTPPath, loader: () => Promise<{
|
|
198
|
+
default: T;
|
|
199
|
+
}>): EnhancedRouter<Lazy<T>, {}, {}, {}>;
|
|
200
|
+
declare function isLazy(item: unknown): item is Lazy<any>;
|
|
201
|
+
declare function getLazyMeta(lazied: Lazy<any>): LazyMeta;
|
|
202
|
+
declare function unlazy<T extends Lazyable<any>>(lazied: T): Promise<{
|
|
203
|
+
default: T extends Lazy<infer U> ? U : T;
|
|
204
|
+
}>;
|
|
205
|
+
|
|
206
|
+
type ProcedureClient<TClientContext extends ClientContext, TSchemas extends Schemas, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TSchemas['inputSchema']>, InferSchemaOutput<TSchemas['outputSchema']>, ErrorFromErrorMap<TErrorMap>>;
|
|
207
|
+
interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
|
208
|
+
context: TInitialContext;
|
|
209
|
+
input: unknown;
|
|
210
|
+
errors: ORPCErrorConstructorMap<TErrorMap>;
|
|
211
|
+
path: readonly string[];
|
|
212
|
+
procedure: Procedure<Context, Context, Schemas, ErrorMap, TMeta>;
|
|
213
|
+
signal?: AbortSignal;
|
|
214
|
+
lastEventId: string | undefined;
|
|
215
|
+
}
|
|
216
|
+
type CreateProcedureClientOptions<TInitialContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext> = {
|
|
217
|
+
/**
|
|
218
|
+
* This is helpful for logging and analytics.
|
|
219
|
+
*/
|
|
220
|
+
path?: readonly string[];
|
|
221
|
+
interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TErrorMap, TMeta>, PromiseWithError<InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>>[];
|
|
222
|
+
} & (Record<never, never> extends TInitialContext ? {
|
|
223
|
+
context?: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
|
|
224
|
+
} : {
|
|
225
|
+
context: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
|
|
226
|
+
});
|
|
227
|
+
/**
|
|
228
|
+
* Create Server-side client from a procedure.
|
|
229
|
+
*
|
|
230
|
+
* @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
|
|
231
|
+
*/
|
|
232
|
+
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
|
+
|
|
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 };
|