@temporary-name/server 1.9.3-alpha.d751d322a9d105467b863db2bab6037dd277fd56 → 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 +14 -30
- package/dist/adapters/standard/index.d.ts +14 -30
- package/dist/adapters/standard/index.mjs +3 -3
- package/dist/index.d.mts +46 -96
- package/dist/index.d.ts +46 -96
- package/dist/index.mjs +15 -215
- 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.ChraIVaQ.d.mts → server.B-pKBQ0r.d.mts} +2 -2
- package/dist/shared/{server.8gkXYsTZ.d.ts → server.BQV-lt_s.d.ts} +2 -2
- package/dist/shared/{server.DcfsPloY.mjs → server.BdGbIyq8.mjs} +211 -17
- package/dist/shared/{server.B15EEOr0.d.ts → server.DAzElr6Q.d.ts} +1 -2
- package/dist/shared/{server.CZNLCQBm.d.mts → server.Do2Whl-h.d.mts} +114 -71
- package/dist/shared/{server.CZNLCQBm.d.ts → server.Do2Whl-h.d.ts} +114 -71
- package/dist/shared/{server.YXplw8TW.d.mts → server.KIlJQ8K_.d.mts} +1 -2
- package/dist/shared/{server.BEHw7Eyx.mjs → server.Kxw442A9.mjs} +1 -1
- package/dist/shared/{server.B9VxPdeK.mjs → server.SmOM3Fae.mjs} +58 -89
- 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
|
|
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.
|
|
@@ -136,17 +105,8 @@ declare class BuilderWithMiddlewares<TInitialContext extends Context, TCurrentCo
|
|
|
136
105
|
* @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
|
|
137
106
|
*/
|
|
138
107
|
router<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, TErrorMap>;
|
|
139
|
-
/**
|
|
140
|
-
* Create a lazy router
|
|
141
|
-
* And applies all of the previously defined options to the specified router.
|
|
142
|
-
*
|
|
143
|
-
* @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
|
|
144
|
-
*/
|
|
145
|
-
lazyRoute<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(loader: () => Promise<{
|
|
146
|
-
default: U;
|
|
147
|
-
}>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, TErrorMap>;
|
|
148
108
|
}
|
|
149
|
-
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'> {
|
|
150
110
|
/**
|
|
151
111
|
* This property holds the defined options.
|
|
152
112
|
*/
|
|
@@ -175,18 +135,18 @@ interface DecoratedMiddleware<TInContext extends Context, TOutContext extends Co
|
|
|
175
135
|
}
|
|
176
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>;
|
|
177
137
|
|
|
178
|
-
interface BuilderDef<
|
|
138
|
+
interface BuilderDef<TSchemas extends Schemas, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TSchemas, TErrorMap, TMeta>, EnhanceRouterOptions<TErrorMap> {
|
|
179
139
|
middlewares: readonly AnyMiddleware[];
|
|
180
140
|
inputValidationIndex: number;
|
|
181
141
|
outputValidationIndex: number;
|
|
182
142
|
}
|
|
183
|
-
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> {
|
|
184
144
|
/**
|
|
185
145
|
* Set or override the initial context.
|
|
186
146
|
*
|
|
187
147
|
* @see {@link https://orpc.unnoq.com/docs/context Context Docs}
|
|
188
148
|
*/
|
|
189
|
-
$context<U extends Context>(): Builder<U
|
|
149
|
+
$context<U extends Context>(): Builder<U, U, TSchemas, TErrorMap, TMeta, TGateName>;
|
|
190
150
|
/**
|
|
191
151
|
* Creates a middleware.
|
|
192
152
|
*
|
|
@@ -195,7 +155,7 @@ declare class Builder<TInitialContext extends Context, TCurrentContext extends C
|
|
|
195
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
|
|
196
156
|
middleware: Middleware<TInitialContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<TErrorMap>, TMeta>): DecoratedMiddleware<TInitialContext, UOutContext, TInput, TOutput, any, TMeta>;
|
|
197
157
|
}
|
|
198
|
-
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>;
|
|
199
159
|
interface ApiBuilderOpts<TMeta extends Meta> {
|
|
200
160
|
meta?: TMeta;
|
|
201
161
|
}
|
|
@@ -205,7 +165,7 @@ declare const os: ApiBuilder<Record<never, never>>;
|
|
|
205
165
|
/**
|
|
206
166
|
* Like `DecoratedProcedure`, but removed all method that can change the contract.
|
|
207
167
|
*/
|
|
208
|
-
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> {
|
|
209
169
|
/**
|
|
210
170
|
* Uses a middleware to modify the context or improve the pipeline.
|
|
211
171
|
*
|
|
@@ -214,7 +174,7 @@ interface ImplementedProcedure<TInitialContext extends Context, TCurrentContext
|
|
|
214
174
|
* @note The current context must be satisfy middleware dependent-context
|
|
215
175
|
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
216
176
|
*/
|
|
217
|
-
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>;
|
|
218
178
|
/**
|
|
219
179
|
* Uses a middleware to modify the context or improve the pipeline.
|
|
220
180
|
*
|
|
@@ -223,19 +183,19 @@ interface ImplementedProcedure<TInitialContext extends Context, TCurrentContext
|
|
|
223
183
|
* @note The current context must be satisfy middleware dependent-context
|
|
224
184
|
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
225
185
|
*/
|
|
226
|
-
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>;
|
|
227
187
|
/**
|
|
228
188
|
* Make this procedure callable (works like a function while still being a procedure).
|
|
229
189
|
*
|
|
230
190
|
* @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
|
|
231
191
|
*/
|
|
232
|
-
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>;
|
|
233
193
|
}
|
|
234
194
|
/**
|
|
235
195
|
* Like `ProcedureBuilderWithoutHandler`, but removed all method that can change the contract.
|
|
236
196
|
*/
|
|
237
|
-
interface ProcedureImplementer<TInitialContext extends Context, TCurrentContext extends Context,
|
|
238
|
-
'~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>;
|
|
239
199
|
/**
|
|
240
200
|
* Uses a middleware to modify the context or improve the pipeline.
|
|
241
201
|
*
|
|
@@ -244,7 +204,7 @@ interface ProcedureImplementer<TInitialContext extends Context, TCurrentContext
|
|
|
244
204
|
* @note The current context must be satisfy middleware dependent-context
|
|
245
205
|
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
246
206
|
*/
|
|
247
|
-
'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>;
|
|
248
208
|
/**
|
|
249
209
|
* Uses a middleware to modify the context or improve the pipeline.
|
|
250
210
|
*
|
|
@@ -253,13 +213,13 @@ interface ProcedureImplementer<TInitialContext extends Context, TCurrentContext
|
|
|
253
213
|
* @note The current context must be satisfy middleware dependent-context
|
|
254
214
|
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
255
215
|
*/
|
|
256
|
-
'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>;
|
|
257
217
|
/**
|
|
258
218
|
* Defines the handler of the procedure.
|
|
259
219
|
*
|
|
260
220
|
* @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
|
|
261
221
|
*/
|
|
262
|
-
'handler'(handler: ProcedureHandler<TCurrentContext, InferSchemaOutput<
|
|
222
|
+
'handler'(handler: ProcedureHandler<TCurrentContext, InferSchemaOutput<TSchemas['inputSchema']>, InferSchemaInput<TSchemas['outputSchema']>, TErrorMap, TMeta>): ImplementedProcedure<TInitialContext, TCurrentContext, TSchemas, TErrorMap, TMeta>;
|
|
263
223
|
}
|
|
264
224
|
|
|
265
225
|
interface RouterImplementerWithMiddlewares<T extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> {
|
|
@@ -278,18 +238,8 @@ interface RouterImplementerWithMiddlewares<T extends AnyContractRouter, TInitial
|
|
|
278
238
|
* @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
|
|
279
239
|
*/
|
|
280
240
|
router<U extends Router<T, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, Record<never, never>>;
|
|
281
|
-
/**
|
|
282
|
-
* Create a lazy router
|
|
283
|
-
* And applies all of the previously defined options to the specified router.
|
|
284
|
-
* And enforces the router match the contract.
|
|
285
|
-
*
|
|
286
|
-
* @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
|
|
287
|
-
*/
|
|
288
|
-
lazyRoute<U extends Router<T, TInitialContext>>(loader: () => Promise<{
|
|
289
|
-
default: U;
|
|
290
|
-
}>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, Record<never, never>>;
|
|
291
241
|
}
|
|
292
|
-
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> & {
|
|
293
243
|
[K in keyof TContract]: TContract[K] extends AnyContractRouter ? ImplementerInternalWithMiddlewares<TContract[K], TInitialContext, TCurrentContext> : never;
|
|
294
244
|
};
|
|
295
245
|
|
|
@@ -327,7 +277,7 @@ interface RouterImplementer<T extends AnyContractRouter, TInitialContext extends
|
|
|
327
277
|
default: U;
|
|
328
278
|
}>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, Record<never, never>>;
|
|
329
279
|
}
|
|
330
|
-
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> & {
|
|
331
281
|
[K in keyof TContract]: TContract[K] extends AnyContractRouter ? ImplementerInternal<TContract[K], TInitialContext, TCurrentContext> : never;
|
|
332
282
|
};
|
|
333
283
|
declare function implementerInternal<T extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context>(contract: T, middlewares: AnyMiddleware[]): ImplementerInternal<T, TInitialContext, TCurrentContext>;
|
|
@@ -337,7 +287,7 @@ type Implementer<TContract extends AnyContractRouter, TInitialContext extends Co
|
|
|
337
287
|
*
|
|
338
288
|
* @see {@link https://orpc.unnoq.com/docs/context Context Docs}
|
|
339
289
|
*/
|
|
340
|
-
$context<U extends Context>(): Implementer<TContract, U
|
|
290
|
+
$context<U extends Context>(): Implementer<TContract, U, U>;
|
|
341
291
|
} & ImplementerInternal<TContract, TInitialContext, TCurrentContext>;
|
|
342
292
|
declare function implement<T extends AnyContractRouter, TContext extends Context = Record<never, never>>(contract: T): Implementer<T, TContext, TContext>;
|
|
343
293
|
|
|
@@ -362,9 +312,9 @@ declare function createContractedProcedure(procedure: AnyProcedure, contract: An
|
|
|
362
312
|
* ```
|
|
363
313
|
*
|
|
364
314
|
*/
|
|
365
|
-
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>>;
|
|
366
316
|
|
|
367
|
-
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> : {
|
|
368
318
|
[K in keyof TRouter]: TRouter[K] extends Lazyable<infer U extends AnyRouter> ? RouterClient<U, TClientContext> : never;
|
|
369
319
|
};
|
|
370
320
|
/**
|
|
@@ -377,5 +327,5 @@ declare function createRouterClient<T extends AnyRouter, TClientContext extends
|
|
|
377
327
|
declare function setHiddenRouterContract<T extends Lazyable<AnyRouter>>(router: T, contract: AnyContractRouter): T;
|
|
378
328
|
declare function getHiddenRouterContract(router: Lazyable<AnyRouter | AnyContractRouter>): AnyContractRouter | undefined;
|
|
379
329
|
|
|
380
|
-
export { AnyMiddleware, AnyProcedure, AnyRouter, Builder, BuilderWithMiddlewares, Context, CreateProcedureClientOptions, DecoratedProcedure, InferRouterInitialContext, Lazy, Lazyable, MapInputMiddleware, MergedCurrentContext, MergedInitialContext, Middleware, ORPCErrorConstructorMap, Procedure, ProcedureBuilder, ProcedureClient, ProcedureHandler, Router, addMiddleware, call,
|
|
381
|
-
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
|
}
|
|
@@ -349,16 +169,6 @@ class BuilderWithMiddlewares extends ProcedureBuilder {
|
|
|
349
169
|
router(router) {
|
|
350
170
|
return enhanceRouter(router, this["~orpc"]);
|
|
351
171
|
}
|
|
352
|
-
/**
|
|
353
|
-
* Create a lazy router
|
|
354
|
-
* And applies all of the previously defined options to the specified router.
|
|
355
|
-
*
|
|
356
|
-
* @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
|
|
357
|
-
*/
|
|
358
|
-
lazyRoute(loader) {
|
|
359
|
-
const lazied = lazy(loader);
|
|
360
|
-
return enhanceRouter(lazied, this["~orpc"]);
|
|
361
|
-
}
|
|
362
172
|
}
|
|
363
173
|
|
|
364
174
|
function decorateMiddleware(middleware) {
|
|
@@ -427,6 +237,7 @@ function createApiBuilder(opts = {}) {
|
|
|
427
237
|
console.dir(error, { depth: null });
|
|
428
238
|
})
|
|
429
239
|
],
|
|
240
|
+
schemas: unknownSchemas,
|
|
430
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
|
|
431
242
|
// the best solution). For now I've removed the interface to configure it externally.
|
|
432
243
|
dedupeLeadingMiddlewares: true
|
|
@@ -468,17 +279,6 @@ function implementerInternal(contract, middlewares) {
|
|
|
468
279
|
});
|
|
469
280
|
return setHiddenRouterContract(adapted, contract);
|
|
470
281
|
};
|
|
471
|
-
} else if (key === "lazyRoute") {
|
|
472
|
-
method = (loader) => {
|
|
473
|
-
const adapted = enhanceRouter(lazy(loader), {
|
|
474
|
-
middlewares,
|
|
475
|
-
errorMap: {},
|
|
476
|
-
prefix: void 0,
|
|
477
|
-
tags: void 0,
|
|
478
|
-
dedupeLeadingMiddlewares: true
|
|
479
|
-
});
|
|
480
|
-
return setHiddenRouterContract(adapted, contract);
|
|
481
|
-
};
|
|
482
282
|
}
|
|
483
283
|
const next = getContractRouter(target, [key]);
|
|
484
284
|
if (!next) {
|
|
@@ -520,7 +320,7 @@ function implement(contract) {
|
|
|
520
320
|
}
|
|
521
321
|
|
|
522
322
|
function createAssertedLazyProcedure(lazied) {
|
|
523
|
-
const lazyProcedure =
|
|
323
|
+
const lazyProcedure = lazyInternal(async () => {
|
|
524
324
|
const { default: maybeProcedure } = await unlazy(lazied);
|
|
525
325
|
if (!isProcedure(maybeProcedure)) {
|
|
526
326
|
throw new Error(`
|
|
@@ -571,4 +371,4 @@ function createRouterClient(router, ...rest) {
|
|
|
571
371
|
return recursive;
|
|
572
372
|
}
|
|
573
373
|
|
|
574
|
-
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 };
|