@temporary-name/server 1.9.3-alpha.d9b25e999833b2b788712bccd5957f10e42416b0 → 1.9.3-alpha.df53e70739ea63d3ba6cfa5052b30dae1e12de46
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 +3 -3
- package/dist/adapters/fetch/index.d.mts +3 -3
- package/dist/adapters/fetch/index.d.ts +3 -3
- package/dist/adapters/fetch/index.mjs +3 -3
- package/dist/adapters/node/index.d.mts +3 -3
- package/dist/adapters/node/index.d.ts +3 -3
- package/dist/adapters/node/index.mjs +3 -3
- package/dist/adapters/standard/index.d.mts +4 -4
- package/dist/adapters/standard/index.d.ts +4 -4
- package/dist/adapters/standard/index.mjs +3 -3
- package/dist/index.d.mts +45 -76
- package/dist/index.d.ts +45 -76
- package/dist/index.mjs +15 -205
- 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.B93y_8tj.d.mts → server.B-pKBQ0r.d.mts} +2 -2
- package/dist/shared/{server.D_fags8X.d.ts → server.BQV-lt_s.d.ts} +2 -2
- package/dist/shared/{server.BYYf0Wn6.mjs → server.BdGbIyq8.mjs} +199 -5
- package/dist/shared/{server.cjcgLdr1.d.ts → server.DAzElr6Q.d.ts} +1 -1
- package/dist/shared/{server.C3RuMHWl.d.mts → server.Do2Whl-h.d.mts} +107 -64
- package/dist/shared/{server.C3RuMHWl.d.ts → server.Do2Whl-h.d.ts} +107 -64
- package/dist/shared/{server.CT1xhSmE.d.mts → server.KIlJQ8K_.d.mts} +1 -1
- package/dist/shared/{server.BEHw7Eyx.mjs → server.Kxw442A9.mjs} +1 -1
- package/dist/shared/{server.BeBVpcA9.mjs → server.SmOM3Fae.mjs} +17 -42
- package/package.json +10 -10
package/dist/index.d.ts
CHANGED
|
@@ -1,79 +1,42 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { ContractProcedure, ContractProcedureDef, ContractRouter, ErrorMap, ErrorMapItem, InferSchemaInput, InferSchemaOutput,
|
|
1
|
+
import { Schemas, ErrorMap, Meta, ContractProcedure, MergedErrorMap, Route, AnySchema, InferSchemaOutput, InferSchemaInput, ContractRouter, ContractProcedureDef, UnknownSchemas, AnyContractRouter, InferContractRouterErrorMap, InferContractRouterMeta, AnyContractProcedure, ErrorFromErrorMap, Schema } from '@temporary-name/contract';
|
|
2
|
+
export { ContractProcedure, ContractProcedureDef, ContractRouter, ErrorMap, ErrorMapItem, InferSchemaInput, InferSchemaOutput, MergedErrorMap, Meta, OutputStructure, Route, Schema, ValidationError, eventIterator, validateORPCError } from '@temporary-name/contract';
|
|
3
3
|
import { ClientContext, MaybeOptionalOptions, IntersectPick, HTTPPath, ClientOptions, ClientPromiseResult } from '@temporary-name/shared';
|
|
4
4
|
export { AsyncIteratorClass, ClientContext, EventPublisher, EventPublisherOptions, EventPublisherSubscribeIteratorOptions, HTTPMethod, HTTPPath, IntersectPick, ORPCError, Registry, ThrowableError, asyncIteratorToStream as eventIteratorToStream, isDefinedError, onError, onFinish, onStart, onSuccess, safe, streamToAsyncIteratorClass as streamToEventIterator } from '@temporary-name/shared';
|
|
5
5
|
import { SchemaClass } from '@temporary-name/zod';
|
|
6
|
-
import { C as Context, P as Procedure, a as CreateProcedureClientOptions, b as ProcedureClient,
|
|
7
|
-
export {
|
|
6
|
+
import { C as Context, P as Procedure, a as CreateProcedureClientOptions, b as ProcedureClient, M as Middleware, O as ORPCErrorConstructorMap, c as MergedInitialContext, d as MergedCurrentContext, e as ProcedureHandler, E as EnhanceRouterOptions, R as Router, f as EnhancedRouter, g as MapInputMiddleware, A as AnyMiddleware, L as Lazy, h as AnyProcedure, i as Lazyable, j as AnyRouter, I as InferRouterInitialContext } from './shared/server.Do2Whl-h.js';
|
|
7
|
+
export { U as AccessibleLazyRouter, Z as ContractProcedureCallbackOptions, N as InferRouterCurrentContexts, K as InferRouterInitialContexts, Q as InferRouterInputs, S as InferRouterOutputs, o as LAZY_SYMBOL, p as LazyMeta, _ as LazyTraverseContractProceduresOptions, x as MiddlewareNextFn, w as MiddlewareNextFnOptions, z as MiddlewareOptions, y as MiddlewareOutputFn, v as MiddlewareResult, l as ORPCErrorConstructorMapItem, k as ORPCErrorConstructorMapItemOptions, H as ProcedureClientInterceptorOptions, F as ProcedureDef, D as ProcedureHandlerOptions, Y as TraverseContractProcedureCallbackOptions, X as TraverseContractProceduresOptions, a1 as UnlaziedRouter, V as createAccessibleLazyRouter, n as createORPCErrorConstructorMap, J as createProcedureClient, W as enhanceRouter, t as getLazyMeta, T as getRouter, s as isLazy, G as isProcedure, r as lazy, q as lazyInternal, m as mergeCurrentContext, B as middlewareOutputFn, a0 as resolveContractProcedures, $ as traverseContractProcedures, u as unlazy, a2 as unlazyRouter } from './shared/server.Do2Whl-h.js';
|
|
8
8
|
export { getEventMeta, withEventMeta } from '@temporary-name/standard-server';
|
|
9
9
|
|
|
10
|
-
declare class DecoratedProcedure<TInitialContext extends Context, TCurrentContext extends Context,
|
|
10
|
+
declare class DecoratedProcedure<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TErrorMap extends ErrorMap, TMeta extends Meta> extends Procedure<TInitialContext, TCurrentContext, TSchemas, TErrorMap, TMeta> {
|
|
11
11
|
/**
|
|
12
12
|
* Make this procedure callable (works like a function while still being a procedure).
|
|
13
13
|
*
|
|
14
14
|
* @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
|
|
15
15
|
*/
|
|
16
|
-
callable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext,
|
|
16
|
+
callable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TSchemas['outputSchema'], TErrorMap, TMeta, TClientContext>>): DecoratedProcedure<TInitialContext, TCurrentContext, TSchemas, TErrorMap, TMeta> & ProcedureClient<TClientContext, TSchemas, TErrorMap>;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
declare
|
|
20
|
-
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> & {
|
|
21
|
-
[K in keyof T]: T[K] extends Lazyable<AnyRouter> ? AccessibleLazyRouter<T[K]> : never;
|
|
22
|
-
};
|
|
23
|
-
declare function createAccessibleLazyRouter<T extends Lazy<AnyRouter | undefined>>(lazied: T): AccessibleLazyRouter<T>;
|
|
24
|
-
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> : {
|
|
25
|
-
[K in keyof T]: T[K] extends Lazyable<AnyRouter> ? EnhancedRouter<T[K], TInitialContext, TCurrentContext, TErrorMap> : never;
|
|
26
|
-
};
|
|
27
|
-
interface EnhanceRouterOptions<TErrorMap extends ErrorMap> extends EnhanceRouteOptions {
|
|
28
|
-
middlewares: readonly AnyMiddleware[];
|
|
29
|
-
errorMap: TErrorMap;
|
|
30
|
-
dedupeLeadingMiddlewares: boolean;
|
|
31
|
-
}
|
|
32
|
-
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>;
|
|
33
|
-
interface TraverseContractProceduresOptions {
|
|
34
|
-
router: AnyContractRouter | AnyRouter;
|
|
35
|
-
path: readonly string[];
|
|
36
|
-
}
|
|
37
|
-
interface TraverseContractProcedureCallbackOptions {
|
|
38
|
-
contract: AnyContractProcedure | AnyProcedure;
|
|
39
|
-
path: readonly string[];
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* @deprecated Use `TraverseContractProcedureCallbackOptions` instead.
|
|
43
|
-
*/
|
|
44
|
-
type ContractProcedureCallbackOptions = TraverseContractProcedureCallbackOptions;
|
|
45
|
-
interface LazyTraverseContractProceduresOptions {
|
|
46
|
-
router: Lazy<AnyRouter>;
|
|
47
|
-
path: readonly string[];
|
|
48
|
-
}
|
|
49
|
-
declare function traverseContractProcedures(options: TraverseContractProceduresOptions, callback: (options: TraverseContractProcedureCallbackOptions) => void, lazyOptions?: LazyTraverseContractProceduresOptions[]): LazyTraverseContractProceduresOptions[];
|
|
50
|
-
declare function resolveContractProcedures(options: TraverseContractProceduresOptions, callback: (options: TraverseContractProcedureCallbackOptions) => void): Promise<void>;
|
|
51
|
-
type UnlaziedRouter<T extends AnyRouter> = T extends AnyProcedure ? T : {
|
|
52
|
-
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? UnlaziedRouter<U> : never;
|
|
53
|
-
};
|
|
54
|
-
declare function unlazyRouter<T extends AnyRouter>(router: T): Promise<UnlaziedRouter<T>>;
|
|
55
|
-
|
|
56
|
-
declare class ProcedureBuilder<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TGateName extends string> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
19
|
+
declare class ProcedureBuilder<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TErrorMap extends ErrorMap, TMeta extends Meta, TGateName extends string> extends ContractProcedure<TSchemas, TErrorMap, TMeta> {
|
|
57
20
|
z: SchemaClass;
|
|
58
21
|
/**
|
|
59
22
|
* This property holds the defined options.
|
|
60
23
|
*/
|
|
61
|
-
'~orpc': BuilderDef<
|
|
62
|
-
constructor(def: BuilderDef<
|
|
24
|
+
'~orpc': BuilderDef<TSchemas, TErrorMap, TMeta>;
|
|
25
|
+
constructor(def: BuilderDef<TSchemas, TErrorMap, TMeta>);
|
|
63
26
|
/**
|
|
64
27
|
* Adds type-safe custom errors to the contract.
|
|
65
28
|
* The provided errors are spared-merged with any existing errors in the contract.
|
|
66
29
|
*
|
|
67
30
|
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
68
31
|
*/
|
|
69
|
-
errors<U extends ErrorMap>(errors: U): ProcedureBuilder<TInitialContext, TCurrentContext,
|
|
32
|
+
errors<U extends ErrorMap>(errors: U): ProcedureBuilder<TInitialContext, TCurrentContext, TSchemas, MergedErrorMap<TErrorMap, U>, TMeta, TGateName>;
|
|
70
33
|
/**
|
|
71
34
|
* Sets or updates the metadata for the contract.
|
|
72
35
|
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
73
36
|
*
|
|
74
37
|
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
75
38
|
*/
|
|
76
|
-
meta(meta: TMeta): ProcedureBuilder<TInitialContext, TCurrentContext,
|
|
39
|
+
meta(meta: TMeta): ProcedureBuilder<TInitialContext, TCurrentContext, TSchemas, TErrorMap, TMeta, TGateName>;
|
|
77
40
|
/**
|
|
78
41
|
* Sets or updates the route definition for the contract.
|
|
79
42
|
* The provided route is spared-merged with any existing route in the contract.
|
|
@@ -82,19 +45,25 @@ declare class ProcedureBuilder<TInitialContext extends Context, TCurrentContext
|
|
|
82
45
|
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
83
46
|
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
84
47
|
*/
|
|
85
|
-
route(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext,
|
|
48
|
+
route(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TSchemas, TErrorMap, TMeta, TGateName>;
|
|
86
49
|
/**
|
|
87
50
|
* Defines the input validation schema.
|
|
88
51
|
*
|
|
89
52
|
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
|
|
90
53
|
*/
|
|
91
|
-
input<USchema extends AnySchema>(schema: USchema): ProcedureBuilder<TInitialContext, TCurrentContext,
|
|
54
|
+
input<USchema extends AnySchema>(schema: USchema): ProcedureBuilder<TInitialContext, TCurrentContext, {
|
|
55
|
+
inputSchema: USchema;
|
|
56
|
+
outputSchema: TSchemas['outputSchema'];
|
|
57
|
+
}, TErrorMap, TMeta, TGateName>;
|
|
92
58
|
/**
|
|
93
59
|
* Defines the output validation schema.
|
|
94
60
|
*
|
|
95
61
|
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
|
|
96
62
|
*/
|
|
97
|
-
output<USchema extends AnySchema>(schema: USchema): ProcedureBuilder<TInitialContext, TCurrentContext,
|
|
63
|
+
output<USchema extends AnySchema>(schema: USchema): ProcedureBuilder<TInitialContext, TCurrentContext, {
|
|
64
|
+
inputSchema: TSchemas['inputSchema'];
|
|
65
|
+
outputSchema: USchema;
|
|
66
|
+
}, TErrorMap, TMeta, TGateName>;
|
|
98
67
|
/**
|
|
99
68
|
* Uses a middleware to modify the context or improve the pipeline.
|
|
100
69
|
*
|
|
@@ -102,18 +71,18 @@ declare class ProcedureBuilder<TInitialContext extends Context, TCurrentContext
|
|
|
102
71
|
* @note The current context must be satisfy middleware dependent-context
|
|
103
72
|
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
104
73
|
*/
|
|
105
|
-
use<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ProcedureBuilder<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>,
|
|
74
|
+
use<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ProcedureBuilder<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TSchemas, TErrorMap, TMeta, TGateName>;
|
|
106
75
|
useGating<const TInferredGateName extends string>(gates: TInferredGateName[], isGateEnabled: (gate: TInferredGateName, ctx: TCurrentContext) => boolean): BuilderWithMiddlewares<MergedInitialContext<TInitialContext, Context, TCurrentContext>, MergedCurrentContext<TCurrentContext, {
|
|
107
76
|
isGateEnabled: typeof isGateEnabled;
|
|
108
|
-
}>,
|
|
77
|
+
}>, TSchemas, TErrorMap, TMeta, TInferredGateName>;
|
|
109
78
|
/**
|
|
110
79
|
* Defines the handler of the procedure.
|
|
111
80
|
*
|
|
112
81
|
* @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
|
|
113
82
|
*/
|
|
114
|
-
handler(handler: ProcedureHandler<TCurrentContext, InferSchemaOutput<
|
|
83
|
+
handler(handler: ProcedureHandler<TCurrentContext, InferSchemaOutput<TSchemas['inputSchema']>, InferSchemaInput<TSchemas['outputSchema']>, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TSchemas, TErrorMap, TMeta>;
|
|
115
84
|
}
|
|
116
|
-
declare class BuilderWithMiddlewares<TInitialContext extends Context, TCurrentContext extends Context,
|
|
85
|
+
declare class BuilderWithMiddlewares<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TErrorMap extends ErrorMap, TMeta extends Meta, TGateName extends string> extends ProcedureBuilder<TInitialContext, TCurrentContext, TSchemas, TErrorMap, TMeta, TGateName> {
|
|
117
86
|
/**
|
|
118
87
|
* Prefixes all procedures in the router.
|
|
119
88
|
* The provided prefix is post-appended to any existing router prefix.
|
|
@@ -122,7 +91,7 @@ declare class BuilderWithMiddlewares<TInitialContext extends Context, TCurrentCo
|
|
|
122
91
|
*
|
|
123
92
|
* @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
|
124
93
|
*/
|
|
125
|
-
prefix(prefix: HTTPPath): BuilderWithMiddlewares<TInitialContext, TCurrentContext,
|
|
94
|
+
prefix(prefix: HTTPPath): BuilderWithMiddlewares<TInitialContext, TCurrentContext, TSchemas, TErrorMap, TMeta, TGateName>;
|
|
126
95
|
/**
|
|
127
96
|
* Adds tags to all procedures in the router.
|
|
128
97
|
* This helpful when you want to group procedures together in the OpenAPI specification.
|
|
@@ -137,7 +106,7 @@ declare class BuilderWithMiddlewares<TInitialContext extends Context, TCurrentCo
|
|
|
137
106
|
*/
|
|
138
107
|
router<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, TErrorMap>;
|
|
139
108
|
}
|
|
140
|
-
interface RouterBuilder<TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap, TMeta extends Meta> extends Pick<BuilderWithMiddlewares<TInitialContext, TCurrentContext, any,
|
|
109
|
+
interface RouterBuilder<TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap, TMeta extends Meta> extends Pick<BuilderWithMiddlewares<TInitialContext, TCurrentContext, any, TErrorMap, TMeta, any>, 'prefix' | 'tag' | 'router'> {
|
|
141
110
|
/**
|
|
142
111
|
* This property holds the defined options.
|
|
143
112
|
*/
|
|
@@ -166,18 +135,18 @@ interface DecoratedMiddleware<TInContext extends Context, TOutContext extends Co
|
|
|
166
135
|
}
|
|
167
136
|
declare function decorateMiddleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta>(middleware: Middleware<TInContext, TOutContext, TInput, TOutput, TErrorConstructorMap, TMeta>): DecoratedMiddleware<TInContext, TOutContext, TInput, TOutput, TErrorConstructorMap, TMeta>;
|
|
168
137
|
|
|
169
|
-
interface BuilderDef<
|
|
138
|
+
interface BuilderDef<TSchemas extends Schemas, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TSchemas, TErrorMap, TMeta>, EnhanceRouterOptions<TErrorMap> {
|
|
170
139
|
middlewares: readonly AnyMiddleware[];
|
|
171
140
|
inputValidationIndex: number;
|
|
172
141
|
outputValidationIndex: number;
|
|
173
142
|
}
|
|
174
|
-
declare class Builder<TInitialContext extends Context, TCurrentContext extends Context,
|
|
143
|
+
declare class Builder<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TErrorMap extends ErrorMap, TMeta extends Meta, TGateName extends string> extends BuilderWithMiddlewares<TInitialContext, TCurrentContext, TSchemas, TErrorMap, TMeta, TGateName> {
|
|
175
144
|
/**
|
|
176
145
|
* Set or override the initial context.
|
|
177
146
|
*
|
|
178
147
|
* @see {@link https://orpc.unnoq.com/docs/context Context Docs}
|
|
179
148
|
*/
|
|
180
|
-
$context<U extends Context>(): Builder<U, U,
|
|
149
|
+
$context<U extends Context>(): Builder<U, U, TSchemas, TErrorMap, TMeta, TGateName>;
|
|
181
150
|
/**
|
|
182
151
|
* Creates a middleware.
|
|
183
152
|
*
|
|
@@ -186,7 +155,7 @@ declare class Builder<TInitialContext extends Context, TCurrentContext extends C
|
|
|
186
155
|
middleware<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, TInput, TOutput = any>(// = any here is important to make middleware can be used in any output by default
|
|
187
156
|
middleware: Middleware<TInitialContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<TErrorMap>, TMeta>): DecoratedMiddleware<TInitialContext, UOutContext, TInput, TOutput, any, TMeta>;
|
|
188
157
|
}
|
|
189
|
-
type ApiBuilder<TMeta extends Meta> = Builder<Record<never, never>, Record<never, never>,
|
|
158
|
+
type ApiBuilder<TMeta extends Meta> = Builder<Record<never, never>, Record<never, never>, UnknownSchemas, Record<never, never>, TMeta, never>;
|
|
190
159
|
interface ApiBuilderOpts<TMeta extends Meta> {
|
|
191
160
|
meta?: TMeta;
|
|
192
161
|
}
|
|
@@ -196,7 +165,7 @@ declare const os: ApiBuilder<Record<never, never>>;
|
|
|
196
165
|
/**
|
|
197
166
|
* Like `DecoratedProcedure`, but removed all method that can change the contract.
|
|
198
167
|
*/
|
|
199
|
-
interface ImplementedProcedure<TInitialContext extends Context, TCurrentContext extends Context,
|
|
168
|
+
interface ImplementedProcedure<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TErrorMap extends ErrorMap, TMeta extends Meta> extends Procedure<TInitialContext, TCurrentContext, TSchemas, TErrorMap, TMeta> {
|
|
200
169
|
/**
|
|
201
170
|
* Uses a middleware to modify the context or improve the pipeline.
|
|
202
171
|
*
|
|
@@ -205,7 +174,7 @@ interface ImplementedProcedure<TInitialContext extends Context, TCurrentContext
|
|
|
205
174
|
* @note The current context must be satisfy middleware dependent-context
|
|
206
175
|
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
207
176
|
*/
|
|
208
|
-
use<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, InferSchemaOutput<
|
|
177
|
+
use<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, InferSchemaOutput<TSchemas['inputSchema']>, InferSchemaInput<TSchemas['outputSchema']>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ImplementedProcedure<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TSchemas, TErrorMap, TMeta>;
|
|
209
178
|
/**
|
|
210
179
|
* Uses a middleware to modify the context or improve the pipeline.
|
|
211
180
|
*
|
|
@@ -214,19 +183,19 @@ interface ImplementedProcedure<TInitialContext extends Context, TCurrentContext
|
|
|
214
183
|
* @note The current context must be satisfy middleware dependent-context
|
|
215
184
|
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
216
185
|
*/
|
|
217
|
-
use<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInput, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, UInput, InferSchemaInput<
|
|
186
|
+
use<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInput, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, UInput, InferSchemaInput<TSchemas['outputSchema']>, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<InferSchemaOutput<TSchemas['inputSchema']>, UInput>): ImplementedProcedure<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TSchemas, TErrorMap, TMeta>;
|
|
218
187
|
/**
|
|
219
188
|
* Make this procedure callable (works like a function while still being a procedure).
|
|
220
189
|
*
|
|
221
190
|
* @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
|
|
222
191
|
*/
|
|
223
|
-
callable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext,
|
|
192
|
+
callable<TClientContext extends ClientContext>(...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TSchemas['outputSchema'], TErrorMap, TMeta, TClientContext>>): ImplementedProcedure<TInitialContext, TCurrentContext, TSchemas, TErrorMap, TMeta> & ProcedureClient<TClientContext, TSchemas, TErrorMap>;
|
|
224
193
|
}
|
|
225
194
|
/**
|
|
226
195
|
* Like `ProcedureBuilderWithoutHandler`, but removed all method that can change the contract.
|
|
227
196
|
*/
|
|
228
|
-
interface ProcedureImplementer<TInitialContext extends Context, TCurrentContext extends Context,
|
|
229
|
-
'~orpc': BuilderDef<
|
|
197
|
+
interface ProcedureImplementer<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
|
198
|
+
'~orpc': BuilderDef<TSchemas, TErrorMap, TMeta>;
|
|
230
199
|
/**
|
|
231
200
|
* Uses a middleware to modify the context or improve the pipeline.
|
|
232
201
|
*
|
|
@@ -235,7 +204,7 @@ interface ProcedureImplementer<TInitialContext extends Context, TCurrentContext
|
|
|
235
204
|
* @note The current context must be satisfy middleware dependent-context
|
|
236
205
|
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
237
206
|
*/
|
|
238
|
-
'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, InferSchemaOutput<
|
|
207
|
+
'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, InferSchemaOutput<TSchemas['inputSchema']>, InferSchemaInput<TSchemas['outputSchema']>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ProcedureImplementer<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TSchemas, TErrorMap, TMeta>;
|
|
239
208
|
/**
|
|
240
209
|
* Uses a middleware to modify the context or improve the pipeline.
|
|
241
210
|
*
|
|
@@ -244,13 +213,13 @@ interface ProcedureImplementer<TInitialContext extends Context, TCurrentContext
|
|
|
244
213
|
* @note The current context must be satisfy middleware dependent-context
|
|
245
214
|
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
246
215
|
*/
|
|
247
|
-
'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInput, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, UInput, InferSchemaInput<
|
|
216
|
+
'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInput, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, UInput, InferSchemaInput<TSchemas['outputSchema']>, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<InferSchemaOutput<TSchemas['inputSchema']>, UInput>): ProcedureImplementer<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TSchemas, TErrorMap, TMeta>;
|
|
248
217
|
/**
|
|
249
218
|
* Defines the handler of the procedure.
|
|
250
219
|
*
|
|
251
220
|
* @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
|
|
252
221
|
*/
|
|
253
|
-
'handler'(handler: ProcedureHandler<TCurrentContext, InferSchemaOutput<
|
|
222
|
+
'handler'(handler: ProcedureHandler<TCurrentContext, InferSchemaOutput<TSchemas['inputSchema']>, InferSchemaInput<TSchemas['outputSchema']>, TErrorMap, TMeta>): ImplementedProcedure<TInitialContext, TCurrentContext, TSchemas, TErrorMap, TMeta>;
|
|
254
223
|
}
|
|
255
224
|
|
|
256
225
|
interface RouterImplementerWithMiddlewares<T extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> {
|
|
@@ -270,7 +239,7 @@ interface RouterImplementerWithMiddlewares<T extends AnyContractRouter, TInitial
|
|
|
270
239
|
*/
|
|
271
240
|
router<U extends Router<T, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, Record<never, never>>;
|
|
272
241
|
}
|
|
273
|
-
type ImplementerInternalWithMiddlewares<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = TContract extends ContractProcedure<infer
|
|
242
|
+
type ImplementerInternalWithMiddlewares<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = TContract extends ContractProcedure<infer USchemas, infer UErrorMap, infer UMeta> ? ProcedureImplementer<TInitialContext, TCurrentContext, USchemas, UErrorMap, UMeta> : RouterImplementerWithMiddlewares<TContract, TInitialContext, TCurrentContext> & {
|
|
274
243
|
[K in keyof TContract]: TContract[K] extends AnyContractRouter ? ImplementerInternalWithMiddlewares<TContract[K], TInitialContext, TCurrentContext> : never;
|
|
275
244
|
};
|
|
276
245
|
|
|
@@ -308,7 +277,7 @@ interface RouterImplementer<T extends AnyContractRouter, TInitialContext extends
|
|
|
308
277
|
default: U;
|
|
309
278
|
}>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, Record<never, never>>;
|
|
310
279
|
}
|
|
311
|
-
type ImplementerInternal<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = TContract extends ContractProcedure<infer
|
|
280
|
+
type ImplementerInternal<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = TContract extends ContractProcedure<infer USchemas, infer UErrorMap, infer UMeta> ? ProcedureImplementer<TInitialContext, TCurrentContext, USchemas, UErrorMap, UMeta> : RouterImplementer<TContract, TInitialContext, TCurrentContext> & {
|
|
312
281
|
[K in keyof TContract]: TContract[K] extends AnyContractRouter ? ImplementerInternal<TContract[K], TInitialContext, TCurrentContext> : never;
|
|
313
282
|
};
|
|
314
283
|
declare function implementerInternal<T extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context>(contract: T, middlewares: AnyMiddleware[]): ImplementerInternal<T, TInitialContext, TCurrentContext>;
|
|
@@ -343,9 +312,9 @@ declare function createContractedProcedure(procedure: AnyProcedure, contract: An
|
|
|
343
312
|
* ```
|
|
344
313
|
*
|
|
345
314
|
*/
|
|
346
|
-
declare function call<TInitialContext extends Context,
|
|
315
|
+
declare function call<TInitialContext extends Context, TSchemas extends Schemas, TErrorMap extends ErrorMap, TMeta extends Meta>(procedure: Lazyable<Procedure<TInitialContext, any, TSchemas, TErrorMap, TMeta>>, input: InferSchemaInput<TSchemas['inputSchema']>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TSchemas['outputSchema'], TErrorMap, TMeta, Record<never, never>> & Omit<ClientOptions<Record<never, never>>, 'context'>>): ClientPromiseResult<InferSchemaOutput<TSchemas['outputSchema']>, ErrorFromErrorMap<TErrorMap>>;
|
|
347
316
|
|
|
348
|
-
type RouterClient<TRouter extends AnyRouter, TClientContext extends ClientContext = Record<never, never>> = TRouter extends Procedure<any, any, infer
|
|
317
|
+
type RouterClient<TRouter extends AnyRouter, TClientContext extends ClientContext = Record<never, never>> = TRouter extends Procedure<any, any, infer USchemas, infer UErrorMap, any> ? ProcedureClient<TClientContext, USchemas, UErrorMap> : {
|
|
349
318
|
[K in keyof TRouter]: TRouter[K] extends Lazyable<infer U extends AnyRouter> ? RouterClient<U, TClientContext> : never;
|
|
350
319
|
};
|
|
351
320
|
/**
|
|
@@ -358,5 +327,5 @@ declare function createRouterClient<T extends AnyRouter, TClientContext extends
|
|
|
358
327
|
declare function setHiddenRouterContract<T extends Lazyable<AnyRouter>>(router: T, contract: AnyContractRouter): T;
|
|
359
328
|
declare function getHiddenRouterContract(router: Lazyable<AnyRouter | AnyContractRouter>): AnyContractRouter | undefined;
|
|
360
329
|
|
|
361
|
-
export { AnyMiddleware, AnyProcedure, AnyRouter, Builder, BuilderWithMiddlewares, Context, CreateProcedureClientOptions, DecoratedProcedure, InferRouterInitialContext, Lazy, Lazyable, MapInputMiddleware, MergedCurrentContext, MergedInitialContext, Middleware, ORPCErrorConstructorMap, Procedure, ProcedureBuilder, ProcedureClient, ProcedureHandler, Router, addMiddleware, call,
|
|
362
|
-
export type {
|
|
330
|
+
export { AnyMiddleware, AnyProcedure, AnyRouter, Builder, BuilderWithMiddlewares, Context, CreateProcedureClientOptions, DecoratedProcedure, EnhanceRouterOptions, EnhancedRouter, InferRouterInitialContext, Lazy, Lazyable, MapInputMiddleware, MergedCurrentContext, MergedInitialContext, Middleware, ORPCErrorConstructorMap, Procedure, ProcedureBuilder, ProcedureClient, ProcedureHandler, Router, addMiddleware, call, createApiBuilder, createAssertedLazyProcedure, createContractedProcedure, createRouterClient, decorateMiddleware, getHiddenRouterContract, implement, implementerInternal, isStartWithMiddlewares, mergeMiddlewares, os, setHiddenRouterContract };
|
|
331
|
+
export type { ApiBuilder, BuilderDef, DecoratedMiddleware, ImplementedProcedure, Implementer, ImplementerInternal, ImplementerInternalWithMiddlewares, ProcedureImplementer, RouterBuilder, RouterClient, RouterImplementer, RouterImplementerWithMiddlewares };
|
package/dist/index.mjs
CHANGED
|
@@ -1,52 +1,12 @@
|
|
|
1
|
+
import { mergePrefix, mergeTags, ContractProcedure, mergeErrorMap, mergeMeta, mergeRoute, prefixRoute, unknownSchemas, isContractProcedure, getContractRouter } from '@temporary-name/contract';
|
|
2
|
+
export { ValidationError, eventIterator, validateORPCError } from '@temporary-name/contract';
|
|
1
3
|
import { onError, resolveMaybeOptionalOptions } from '@temporary-name/shared';
|
|
2
4
|
export { AsyncIteratorClass, EventPublisher, ORPCError, asyncIteratorToStream as eventIteratorToStream, isDefinedError, onError, onFinish, onStart, onSuccess, safe, streamToAsyncIteratorClass as streamToEventIterator } from '@temporary-name/shared';
|
|
3
|
-
import { isContractProcedure, mergePrefix, mergeErrorMap, enhanceRoute, mergeTags, ContractProcedure, mergeMeta, mergeRoute, prefixRoute, getContractRouter } from '@temporary-name/contract';
|
|
4
|
-
export { ValidationError, eventIterator, validateORPCError } from '@temporary-name/contract';
|
|
5
5
|
import { SchemaClass, gatingContext } from '@temporary-name/zod';
|
|
6
|
-
import { c as createProcedureClient,
|
|
7
|
-
export { L as LAZY_SYMBOL,
|
|
6
|
+
import { P as Procedure, c as createProcedureClient, e as enhanceRouter, a as addMiddleware, s as setHiddenRouterContract, l as lazyInternal, g as getLazyMeta, u as unlazy, i as isProcedure, b as isLazy, d as getRouter } from './shared/server.BdGbIyq8.mjs';
|
|
7
|
+
export { L as LAZY_SYMBOL, p as createAccessibleLazyRouter, f as createORPCErrorConstructorMap, o as getHiddenRouterContract, k as isStartWithMiddlewares, h as lazy, m as mergeCurrentContext, n as mergeMiddlewares, j as middlewareOutputFn, r as resolveContractProcedures, t as traverseContractProcedures, q as unlazyRouter } from './shared/server.BdGbIyq8.mjs';
|
|
8
8
|
export { getEventMeta, withEventMeta } from '@temporary-name/standard-server';
|
|
9
9
|
|
|
10
|
-
function isStartWithMiddlewares(middlewares, compare) {
|
|
11
|
-
if (compare.length > middlewares.length) {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
for (let i = 0; i < middlewares.length; i++) {
|
|
15
|
-
if (compare[i] === void 0) {
|
|
16
|
-
return true;
|
|
17
|
-
}
|
|
18
|
-
if (middlewares[i] !== compare[i]) {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
function mergeMiddlewares(first, second, options) {
|
|
25
|
-
if (options.dedupeLeading && isStartWithMiddlewares(second, first)) {
|
|
26
|
-
return second;
|
|
27
|
-
}
|
|
28
|
-
return [...first, ...second];
|
|
29
|
-
}
|
|
30
|
-
function addMiddleware(middlewares, addition) {
|
|
31
|
-
return [...middlewares, addition];
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
class Procedure {
|
|
35
|
-
/**
|
|
36
|
-
* This property holds the defined options.
|
|
37
|
-
*/
|
|
38
|
-
"~orpc";
|
|
39
|
-
constructor(def) {
|
|
40
|
-
this["~orpc"] = def;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
function isProcedure(item) {
|
|
44
|
-
if (item instanceof Procedure) {
|
|
45
|
-
return true;
|
|
46
|
-
}
|
|
47
|
-
return isContractProcedure(item) && "middlewares" in item["~orpc"] && "handler" in item["~orpc"];
|
|
48
|
-
}
|
|
49
|
-
|
|
50
10
|
class DecoratedProcedure extends Procedure {
|
|
51
11
|
/**
|
|
52
12
|
* Make this procedure callable (works like a function while still being a procedure).
|
|
@@ -66,152 +26,6 @@ class DecoratedProcedure extends Procedure {
|
|
|
66
26
|
}
|
|
67
27
|
}
|
|
68
28
|
|
|
69
|
-
const HIDDEN_ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_HIDDEN_ROUTER_CONTRACT");
|
|
70
|
-
function setHiddenRouterContract(router, contract) {
|
|
71
|
-
return new Proxy(router, {
|
|
72
|
-
get(target, key) {
|
|
73
|
-
if (key === HIDDEN_ROUTER_CONTRACT_SYMBOL) {
|
|
74
|
-
return contract;
|
|
75
|
-
}
|
|
76
|
-
return Reflect.get(target, key);
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
function getHiddenRouterContract(router) {
|
|
81
|
-
return router[HIDDEN_ROUTER_CONTRACT_SYMBOL];
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function getRouter(router, path) {
|
|
85
|
-
let current = router;
|
|
86
|
-
for (let i = 0; i < path.length; i++) {
|
|
87
|
-
const segment = path[i];
|
|
88
|
-
if (!current) {
|
|
89
|
-
return void 0;
|
|
90
|
-
}
|
|
91
|
-
if (isProcedure(current)) {
|
|
92
|
-
return void 0;
|
|
93
|
-
}
|
|
94
|
-
if (!isLazy(current)) {
|
|
95
|
-
current = current[segment];
|
|
96
|
-
continue;
|
|
97
|
-
}
|
|
98
|
-
const lazied = current;
|
|
99
|
-
const rest = path.slice(i);
|
|
100
|
-
return lazy(async () => {
|
|
101
|
-
const unwrapped = await unlazy(lazied);
|
|
102
|
-
const next = getRouter(unwrapped.default, rest);
|
|
103
|
-
return unlazy(next);
|
|
104
|
-
}, getLazyMeta(lazied));
|
|
105
|
-
}
|
|
106
|
-
return current;
|
|
107
|
-
}
|
|
108
|
-
function createAccessibleLazyRouter(lazied) {
|
|
109
|
-
const recursive = new Proxy(lazied, {
|
|
110
|
-
get(target, key) {
|
|
111
|
-
if (typeof key !== "string") {
|
|
112
|
-
return Reflect.get(target, key);
|
|
113
|
-
}
|
|
114
|
-
const next = getRouter(lazied, [key]);
|
|
115
|
-
return createAccessibleLazyRouter(next);
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
return recursive;
|
|
119
|
-
}
|
|
120
|
-
function enhanceRouter(router, options) {
|
|
121
|
-
if (isLazy(router)) {
|
|
122
|
-
const laziedMeta = getLazyMeta(router);
|
|
123
|
-
const enhancedPrefix = laziedMeta?.prefix ? mergePrefix(options.prefix, laziedMeta?.prefix) : options.prefix;
|
|
124
|
-
const enhanced2 = lazy(
|
|
125
|
-
async () => {
|
|
126
|
-
const { default: unlaziedRouter } = await unlazy(router);
|
|
127
|
-
const enhanced3 = enhanceRouter(unlaziedRouter, options);
|
|
128
|
-
return unlazy(enhanced3);
|
|
129
|
-
},
|
|
130
|
-
{
|
|
131
|
-
...laziedMeta,
|
|
132
|
-
prefix: enhancedPrefix
|
|
133
|
-
}
|
|
134
|
-
);
|
|
135
|
-
const accessible = createAccessibleLazyRouter(enhanced2);
|
|
136
|
-
return accessible;
|
|
137
|
-
}
|
|
138
|
-
if (isProcedure(router)) {
|
|
139
|
-
const newMiddlewares = mergeMiddlewares(options.middlewares, router["~orpc"].middlewares, {
|
|
140
|
-
dedupeLeading: options.dedupeLeadingMiddlewares
|
|
141
|
-
});
|
|
142
|
-
const newMiddlewareAdded = newMiddlewares.length - router["~orpc"].middlewares.length;
|
|
143
|
-
const enhanced2 = new Procedure({
|
|
144
|
-
...router["~orpc"],
|
|
145
|
-
route: enhanceRoute(router["~orpc"].route, options),
|
|
146
|
-
errorMap: mergeErrorMap(options.errorMap, router["~orpc"].errorMap),
|
|
147
|
-
middlewares: newMiddlewares,
|
|
148
|
-
inputValidationIndex: router["~orpc"].inputValidationIndex + newMiddlewareAdded,
|
|
149
|
-
outputValidationIndex: router["~orpc"].outputValidationIndex + newMiddlewareAdded
|
|
150
|
-
});
|
|
151
|
-
return enhanced2;
|
|
152
|
-
}
|
|
153
|
-
const enhanced = {};
|
|
154
|
-
for (const key in router) {
|
|
155
|
-
enhanced[key] = enhanceRouter(router[key], options);
|
|
156
|
-
}
|
|
157
|
-
return enhanced;
|
|
158
|
-
}
|
|
159
|
-
function traverseContractProcedures(options, callback, lazyOptions = []) {
|
|
160
|
-
let currentRouter = options.router;
|
|
161
|
-
const hiddenContract = getHiddenRouterContract(options.router);
|
|
162
|
-
if (hiddenContract !== void 0) {
|
|
163
|
-
currentRouter = hiddenContract;
|
|
164
|
-
}
|
|
165
|
-
if (isLazy(currentRouter)) {
|
|
166
|
-
lazyOptions.push({
|
|
167
|
-
router: currentRouter,
|
|
168
|
-
path: options.path
|
|
169
|
-
});
|
|
170
|
-
} else if (isContractProcedure(currentRouter)) {
|
|
171
|
-
callback({
|
|
172
|
-
contract: currentRouter,
|
|
173
|
-
path: options.path
|
|
174
|
-
});
|
|
175
|
-
} else {
|
|
176
|
-
for (const key in currentRouter) {
|
|
177
|
-
traverseContractProcedures(
|
|
178
|
-
{
|
|
179
|
-
router: currentRouter[key],
|
|
180
|
-
path: [...options.path, key]
|
|
181
|
-
},
|
|
182
|
-
callback,
|
|
183
|
-
lazyOptions
|
|
184
|
-
);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
return lazyOptions;
|
|
188
|
-
}
|
|
189
|
-
async function resolveContractProcedures(options, callback) {
|
|
190
|
-
const pending = [options];
|
|
191
|
-
for (const options2 of pending) {
|
|
192
|
-
const lazyOptions = traverseContractProcedures(options2, callback);
|
|
193
|
-
for (const options3 of lazyOptions) {
|
|
194
|
-
const { default: router } = await unlazy(options3.router);
|
|
195
|
-
pending.push({
|
|
196
|
-
router,
|
|
197
|
-
path: options3.path
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
async function unlazyRouter(router) {
|
|
203
|
-
if (isProcedure(router)) {
|
|
204
|
-
return router;
|
|
205
|
-
}
|
|
206
|
-
const unlazied = {};
|
|
207
|
-
for (const key in router) {
|
|
208
|
-
const item = router[key];
|
|
209
|
-
const { default: unlaziedRouter } = await unlazy(item);
|
|
210
|
-
unlazied[key] = await unlazyRouter(unlaziedRouter);
|
|
211
|
-
}
|
|
212
|
-
return unlazied;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
29
|
class ProcedureBuilder extends ContractProcedure {
|
|
216
30
|
z;
|
|
217
31
|
constructor(def) {
|
|
@@ -265,7 +79,10 @@ class ProcedureBuilder extends ContractProcedure {
|
|
|
265
79
|
input(schema) {
|
|
266
80
|
return new ProcedureBuilder({
|
|
267
81
|
...this["~orpc"],
|
|
268
|
-
|
|
82
|
+
schemas: {
|
|
83
|
+
...this["~orpc"].schemas,
|
|
84
|
+
inputSchema: schema
|
|
85
|
+
},
|
|
269
86
|
inputValidationIndex: this["~orpc"].middlewares.length
|
|
270
87
|
});
|
|
271
88
|
}
|
|
@@ -277,7 +94,10 @@ class ProcedureBuilder extends ContractProcedure {
|
|
|
277
94
|
output(schema) {
|
|
278
95
|
return new ProcedureBuilder({
|
|
279
96
|
...this["~orpc"],
|
|
280
|
-
|
|
97
|
+
schemas: {
|
|
98
|
+
...this["~orpc"].schemas,
|
|
99
|
+
outputSchema: schema
|
|
100
|
+
},
|
|
281
101
|
outputValidationIndex: this["~orpc"].middlewares.length
|
|
282
102
|
});
|
|
283
103
|
}
|
|
@@ -417,6 +237,7 @@ function createApiBuilder(opts = {}) {
|
|
|
417
237
|
console.dir(error, { depth: null });
|
|
418
238
|
})
|
|
419
239
|
],
|
|
240
|
+
schemas: unknownSchemas,
|
|
420
241
|
// NB: this is a relic from orpc -- I'm not convinced there's a need for this (or if there is, that it's
|
|
421
242
|
// the best solution). For now I've removed the interface to configure it externally.
|
|
422
243
|
dedupeLeadingMiddlewares: true
|
|
@@ -458,17 +279,6 @@ function implementerInternal(contract, middlewares) {
|
|
|
458
279
|
});
|
|
459
280
|
return setHiddenRouterContract(adapted, contract);
|
|
460
281
|
};
|
|
461
|
-
} else if (key === "lazyRoute") {
|
|
462
|
-
method = (loader) => {
|
|
463
|
-
const adapted = enhanceRouter(lazy(loader), {
|
|
464
|
-
middlewares,
|
|
465
|
-
errorMap: {},
|
|
466
|
-
prefix: void 0,
|
|
467
|
-
tags: void 0,
|
|
468
|
-
dedupeLeadingMiddlewares: true
|
|
469
|
-
});
|
|
470
|
-
return setHiddenRouterContract(adapted, contract);
|
|
471
|
-
};
|
|
472
282
|
}
|
|
473
283
|
const next = getContractRouter(target, [key]);
|
|
474
284
|
if (!next) {
|
|
@@ -510,7 +320,7 @@ function implement(contract) {
|
|
|
510
320
|
}
|
|
511
321
|
|
|
512
322
|
function createAssertedLazyProcedure(lazied) {
|
|
513
|
-
const lazyProcedure =
|
|
323
|
+
const lazyProcedure = lazyInternal(async () => {
|
|
514
324
|
const { default: maybeProcedure } = await unlazy(lazied);
|
|
515
325
|
if (!isProcedure(maybeProcedure)) {
|
|
516
326
|
throw new Error(`
|
|
@@ -561,4 +371,4 @@ function createRouterClient(router, ...rest) {
|
|
|
561
371
|
return recursive;
|
|
562
372
|
}
|
|
563
373
|
|
|
564
|
-
export { Builder, BuilderWithMiddlewares, DecoratedProcedure, Procedure, ProcedureBuilder, addMiddleware, call,
|
|
374
|
+
export { Builder, BuilderWithMiddlewares, DecoratedProcedure, Procedure, ProcedureBuilder, addMiddleware, call, createApiBuilder, createAssertedLazyProcedure, createContractedProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, getLazyMeta, getRouter, implement, implementerInternal, isLazy, isProcedure, lazyInternal, os, setHiddenRouterContract, unlazy };
|