@temporary-name/server 1.9.3-alpha.30822ad82102dcf9276d473ba372416778807e52 → 1.9.3-alpha.32780b2c7ad58cf8dcbc93a40f13494185223e6e
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 +12 -6
- package/dist/adapters/aws-lambda/index.d.ts +12 -6
- package/dist/adapters/aws-lambda/index.mjs +12 -4
- package/dist/adapters/fetch/index.d.mts +12 -6
- package/dist/adapters/fetch/index.d.ts +12 -6
- package/dist/adapters/fetch/index.mjs +12 -11
- package/dist/adapters/node/index.d.mts +12 -6
- package/dist/adapters/node/index.d.ts +12 -6
- package/dist/adapters/node/index.mjs +12 -11
- package/dist/adapters/standard/index.d.mts +28 -13
- package/dist/adapters/standard/index.d.ts +28 -13
- package/dist/adapters/standard/index.mjs +8 -100
- package/dist/index.d.mts +66 -339
- package/dist/index.d.ts +66 -339
- package/dist/index.mjs +126 -355
- package/dist/openapi/index.d.mts +220 -0
- package/dist/openapi/index.d.ts +220 -0
- package/dist/openapi/index.mjs +759 -0
- package/dist/plugins/index.d.mts +2 -2
- package/dist/plugins/index.d.ts +2 -2
- package/dist/shared/{server.Btxrgkj5.d.ts → server.BRCH88Sb.d.mts} +7 -24
- package/dist/shared/server.Bb9Wxubg.d.ts +23 -0
- package/dist/shared/server.BbfNcgas.d.mts +23 -0
- package/dist/shared/{server.Bo94xDTv.d.mts → server.D24uJlXJ.d.ts} +7 -24
- package/dist/shared/server.DlRH_uit.mjs +409 -0
- package/dist/shared/server.Kxw442A9.mjs +247 -0
- package/dist/shared/{server.C1YnHvvf.d.ts → server.XpnxYU3D.d.mts} +128 -73
- package/dist/shared/{server.C1YnHvvf.d.mts → server.XpnxYU3D.d.ts} +128 -73
- package/dist/shared/server.u-02Z0mj.mjs +254 -0
- package/package.json +17 -10
- package/dist/shared/server.BEQrAa3A.mjs +0 -207
- package/dist/shared/server.D6K9uoPI.mjs +0 -35
- package/dist/shared/server.DZ5BIITo.mjs +0 -9
- package/dist/shared/server.X0YaZxSJ.mjs +0 -13
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ErrorMap, ErrorMapItem, InferSchemaInput,
|
|
2
|
-
import { ORPCErrorCode, MaybeOptionalOptions, ORPCErrorOptions, ORPCError,
|
|
1
|
+
import { ErrorMap, ErrorMapItem, InferSchemaInput, Schemas, Meta, ContractProcedureDef, AnyContractRouter, ContractProcedure, InferProcedureClientInputs, InferSchemaOutput, EnhanceRouteOptions, MergedErrorMap, AnyContractProcedure, ContractRouter, AnySchema, ErrorFromErrorMap } from '@temporary-name/contract';
|
|
2
|
+
import { ORPCErrorCode, MaybeOptionalOptions, ORPCErrorOptions, ORPCError, Promisable, HTTPPath, ClientContext, Interceptor, PromiseWithError, Value, Client } from '@temporary-name/shared';
|
|
3
3
|
|
|
4
4
|
type Context = Record<PropertyKey, any>;
|
|
5
5
|
type MergedInitialContext<TInitial extends Context, TAdditional extends Context, TCurrent extends Context> = TInitial & Omit<TAdditional, keyof TCurrent>;
|
|
@@ -13,46 +13,27 @@ type ORPCErrorConstructorMap<T extends ErrorMap> = {
|
|
|
13
13
|
};
|
|
14
14
|
declare function createORPCErrorConstructorMap<T extends ErrorMap>(errors: T): ORPCErrorConstructorMap<T>;
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
[LAZY_SYMBOL]: {
|
|
22
|
-
loader: () => Promise<{
|
|
23
|
-
default: T;
|
|
24
|
-
}>;
|
|
25
|
-
meta: LazyMeta;
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
type Lazyable<T> = T | Lazy<T>;
|
|
29
|
-
/**
|
|
30
|
-
* Creates a lazy-loaded item.
|
|
31
|
-
*
|
|
32
|
-
* @warning The `prefix` in `meta` only holds metadata and does not apply the prefix to the lazy router, use `os.prefix(...).lazyRoute(...)` instead.
|
|
33
|
-
*/
|
|
34
|
-
declare function lazy<T>(loader: () => Promise<{
|
|
35
|
-
default: T;
|
|
36
|
-
}>, meta?: LazyMeta): Lazy<T>;
|
|
37
|
-
declare function isLazy(item: unknown): item is Lazy<any>;
|
|
38
|
-
declare function getLazyMeta(lazied: Lazy<any>): LazyMeta;
|
|
39
|
-
declare function unlazy<T extends Lazyable<any>>(lazied: T): Promise<{
|
|
40
|
-
default: T extends Lazy<infer U> ? U : T;
|
|
41
|
-
}>;
|
|
42
|
-
|
|
43
|
-
interface ProcedureHandlerOptions<TCurrentContext extends Context, TInput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
|
16
|
+
interface ProcedureHandlerOptions<TCurrentContext extends Context, TInput extends {
|
|
17
|
+
path: any;
|
|
18
|
+
query: any;
|
|
19
|
+
body: any;
|
|
20
|
+
}, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
|
44
21
|
context: TCurrentContext;
|
|
45
22
|
input: TInput;
|
|
46
23
|
path: readonly string[];
|
|
47
|
-
procedure: Procedure<Context, Context,
|
|
24
|
+
procedure: Procedure<Context, Context, Schemas, ErrorMap, TMeta>;
|
|
48
25
|
signal?: AbortSignal;
|
|
49
26
|
lastEventId: string | undefined;
|
|
50
27
|
errors: TErrorConstructorMap;
|
|
51
28
|
}
|
|
52
|
-
interface ProcedureHandler<TCurrentContext extends Context, TInput
|
|
29
|
+
interface ProcedureHandler<TCurrentContext extends Context, TInput extends {
|
|
30
|
+
path: any;
|
|
31
|
+
query: any;
|
|
32
|
+
body: any;
|
|
33
|
+
}, THandlerOutput, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
|
53
34
|
(opt: ProcedureHandlerOptions<TCurrentContext, TInput, ORPCErrorConstructorMap<TErrorMap>, TMeta>): Promisable<THandlerOutput>;
|
|
54
35
|
}
|
|
55
|
-
interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends Context,
|
|
36
|
+
interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TSchemas, TErrorMap, TMeta> {
|
|
56
37
|
__initialContext?: (type: TInitialContext) => unknown;
|
|
57
38
|
middlewares: readonly AnyMiddleware[];
|
|
58
39
|
inputValidationIndex: number;
|
|
@@ -64,14 +45,14 @@ interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends
|
|
|
64
45
|
*
|
|
65
46
|
* @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
|
|
66
47
|
*/
|
|
67
|
-
declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context,
|
|
48
|
+
declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
|
68
49
|
/**
|
|
69
50
|
* This property holds the defined options.
|
|
70
51
|
*/
|
|
71
|
-
'~orpc': ProcedureDef<TInitialContext, TCurrentContext,
|
|
72
|
-
constructor(def: ProcedureDef<TInitialContext, TCurrentContext,
|
|
52
|
+
'~orpc': ProcedureDef<TInitialContext, TCurrentContext, TSchemas, TErrorMap, TMeta>;
|
|
53
|
+
constructor(def: ProcedureDef<TInitialContext, TCurrentContext, TSchemas, TErrorMap, TMeta>);
|
|
73
54
|
}
|
|
74
|
-
type AnyProcedure = Procedure<any, any,
|
|
55
|
+
type AnyProcedure = Procedure<any, any, Schemas, any, any>;
|
|
75
56
|
declare function isProcedure(item: unknown): item is AnyProcedure;
|
|
76
57
|
|
|
77
58
|
type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
|
|
@@ -92,7 +73,7 @@ interface MiddlewareOutputFn<TOutput> {
|
|
|
92
73
|
interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
|
93
74
|
context: TInContext;
|
|
94
75
|
path: readonly string[];
|
|
95
|
-
procedure: Procedure<Context, Context,
|
|
76
|
+
procedure: Procedure<Context, Context, Schemas, ErrorMap, TMeta>;
|
|
96
77
|
signal?: AbortSignal;
|
|
97
78
|
lastEventId: string | undefined;
|
|
98
79
|
next: MiddlewareNextFn<TOutput>;
|
|
@@ -112,41 +93,13 @@ interface MapInputMiddleware<TInput, TMappedInput> {
|
|
|
112
93
|
}
|
|
113
94
|
declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
|
|
114
95
|
|
|
115
|
-
type ProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
|
|
116
|
-
interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
|
117
|
-
context: TInitialContext;
|
|
118
|
-
input: unknown;
|
|
119
|
-
errors: ORPCErrorConstructorMap<TErrorMap>;
|
|
120
|
-
path: readonly string[];
|
|
121
|
-
procedure: Procedure<Context, Context, AnySchema, AnySchema, ErrorMap, TMeta>;
|
|
122
|
-
signal?: AbortSignal;
|
|
123
|
-
lastEventId: string | undefined;
|
|
124
|
-
}
|
|
125
|
-
type CreateProcedureClientOptions<TInitialContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext> = {
|
|
126
|
-
/**
|
|
127
|
-
* This is helpful for logging and analytics.
|
|
128
|
-
*/
|
|
129
|
-
path?: readonly string[];
|
|
130
|
-
interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TErrorMap, TMeta>, PromiseWithError<InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>>[];
|
|
131
|
-
} & (Record<never, never> extends TInitialContext ? {
|
|
132
|
-
context?: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
|
|
133
|
-
} : {
|
|
134
|
-
context: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
|
|
135
|
-
});
|
|
136
|
-
/**
|
|
137
|
-
* Create Server-side client from a procedure.
|
|
138
|
-
*
|
|
139
|
-
* @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
|
|
140
|
-
*/
|
|
141
|
-
declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TMeta>>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TMeta, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap>;
|
|
142
|
-
|
|
143
96
|
/**
|
|
144
97
|
* Represents a router, which defines a hierarchical structure of procedures.
|
|
145
98
|
*
|
|
146
99
|
* @info A procedure is a router too.
|
|
147
100
|
* @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#contract-router Contract Router Docs}
|
|
148
101
|
*/
|
|
149
|
-
type Router<T extends AnyContractRouter, TInitialContext extends Context> = T extends ContractProcedure<infer
|
|
102
|
+
type Router<T extends AnyContractRouter, TInitialContext extends Context> = T extends ContractProcedure<infer USchemas, infer UErrorMap, infer UMeta> ? Procedure<TInitialContext, any, USchemas, UErrorMap, UMeta> : {
|
|
150
103
|
[K in keyof T]: T[K] extends AnyContractRouter ? Lazyable<Router<T[K], TInitialContext>> : never;
|
|
151
104
|
};
|
|
152
105
|
type AnyRouter = Router<any, any>;
|
|
@@ -157,7 +110,7 @@ type InferRouterInitialContext<T extends AnyRouter> = T extends Router<any, infe
|
|
|
157
110
|
* @info A procedure is a router too.
|
|
158
111
|
* @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
|
|
159
112
|
*/
|
|
160
|
-
type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any
|
|
113
|
+
type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any> ? UInitialContext : {
|
|
161
114
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never;
|
|
162
115
|
};
|
|
163
116
|
/**
|
|
@@ -166,7 +119,7 @@ type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer
|
|
|
166
119
|
* @info A procedure is a router too.
|
|
167
120
|
* @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
|
|
168
121
|
*/
|
|
169
|
-
type InferRouterCurrentContexts<T extends AnyRouter> = T extends Procedure<any, infer UCurrentContext, any, any, any
|
|
122
|
+
type InferRouterCurrentContexts<T extends AnyRouter> = T extends Procedure<any, infer UCurrentContext, any, any, any> ? UCurrentContext : {
|
|
170
123
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterCurrentContexts<U> : never;
|
|
171
124
|
};
|
|
172
125
|
/**
|
|
@@ -175,7 +128,7 @@ type InferRouterCurrentContexts<T extends AnyRouter> = T extends Procedure<any,
|
|
|
175
128
|
* @info A procedure is a router too.
|
|
176
129
|
* @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
|
|
177
130
|
*/
|
|
178
|
-
type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer
|
|
131
|
+
type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer USchemas, any, any> ? InferProcedureClientInputs<USchemas> : {
|
|
179
132
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never;
|
|
180
133
|
};
|
|
181
134
|
/**
|
|
@@ -184,9 +137,111 @@ type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infe
|
|
|
184
137
|
* @info A procedure is a router too.
|
|
185
138
|
* @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
|
|
186
139
|
*/
|
|
187
|
-
type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any,
|
|
140
|
+
type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, infer USchemas, any, any> ? InferSchemaOutput<USchemas['outputSchema']> : {
|
|
188
141
|
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
|
|
189
142
|
};
|
|
190
143
|
|
|
191
|
-
|
|
192
|
-
|
|
144
|
+
declare function getRouter<T extends Lazyable<AnyRouter | undefined>>(router: T, path: readonly string[]): T extends Lazy<any> ? Lazy<AnyRouter | undefined> : Lazyable<AnyRouter | undefined>;
|
|
145
|
+
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> & {
|
|
146
|
+
[K in keyof T]: T[K] extends Lazyable<AnyRouter> ? AccessibleLazyRouter<T[K]> : never;
|
|
147
|
+
};
|
|
148
|
+
declare function createAccessibleLazyRouter<T extends Lazy<AnyRouter | undefined>>(lazied: T): AccessibleLazyRouter<T>;
|
|
149
|
+
type EnhancedRouter<T extends Lazyable<AnyRouter>, TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap> = T extends Lazy<infer U extends AnyRouter> ? AccessibleLazyRouter<EnhancedRouter<U, TInitialContext, TCurrentContext, TErrorMap>> : T extends (Procedure<infer UInitialContext, infer UCurrentContext, infer USchemas, infer UErrorMap, infer UMeta>) ? Procedure<MergedInitialContext<TInitialContext, UInitialContext, TCurrentContext>, UCurrentContext, USchemas, MergedErrorMap<TErrorMap, UErrorMap>, UMeta> : {
|
|
150
|
+
[K in keyof T]: T[K] extends Lazyable<AnyRouter> ? EnhancedRouter<T[K], TInitialContext, TCurrentContext, TErrorMap> : never;
|
|
151
|
+
};
|
|
152
|
+
interface EnhanceRouterOptions<TErrorMap extends ErrorMap> extends EnhanceRouteOptions {
|
|
153
|
+
middlewares: readonly AnyMiddleware[];
|
|
154
|
+
errorMap: TErrorMap;
|
|
155
|
+
dedupeLeadingMiddlewares: boolean;
|
|
156
|
+
}
|
|
157
|
+
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>;
|
|
158
|
+
interface TraverseContractProceduresOptions {
|
|
159
|
+
router: AnyContractRouter | AnyRouter;
|
|
160
|
+
path: readonly string[];
|
|
161
|
+
}
|
|
162
|
+
interface TraverseContractProcedureCallbackOptions {
|
|
163
|
+
contract: AnyContractProcedure | AnyProcedure;
|
|
164
|
+
path: readonly string[];
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* @deprecated Use `TraverseContractProcedureCallbackOptions` instead.
|
|
168
|
+
*/
|
|
169
|
+
type ContractProcedureCallbackOptions = TraverseContractProcedureCallbackOptions;
|
|
170
|
+
interface LazyTraverseContractProceduresOptions {
|
|
171
|
+
router: Lazy<AnyRouter>;
|
|
172
|
+
path: readonly string[];
|
|
173
|
+
}
|
|
174
|
+
declare function traverseContractProcedures(options: TraverseContractProceduresOptions, callback: (options: TraverseContractProcedureCallbackOptions) => void, lazyOptions?: LazyTraverseContractProceduresOptions[]): LazyTraverseContractProceduresOptions[];
|
|
175
|
+
declare function resolveContractProcedures(options: TraverseContractProceduresOptions, callback: (options: TraverseContractProcedureCallbackOptions) => void): Promise<void>;
|
|
176
|
+
type UnlaziedRouter<T extends AnyRouter> = T extends AnyProcedure ? T : {
|
|
177
|
+
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? UnlaziedRouter<U> : never;
|
|
178
|
+
};
|
|
179
|
+
declare function unlazyRouter<T extends AnyRouter>(router: T): Promise<UnlaziedRouter<T>>;
|
|
180
|
+
|
|
181
|
+
declare const LAZY_SYMBOL: unique symbol;
|
|
182
|
+
interface LazyMeta {
|
|
183
|
+
prefix?: HTTPPath;
|
|
184
|
+
}
|
|
185
|
+
interface Lazy<T> {
|
|
186
|
+
[LAZY_SYMBOL]: {
|
|
187
|
+
loader: () => Promise<{
|
|
188
|
+
default: T;
|
|
189
|
+
}>;
|
|
190
|
+
meta: LazyMeta;
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
type Lazyable<T> = T | Lazy<T>;
|
|
194
|
+
/**
|
|
195
|
+
* @internal
|
|
196
|
+
*/
|
|
197
|
+
declare function lazyInternal<T>(loader: () => Promise<{
|
|
198
|
+
default: T;
|
|
199
|
+
}>, meta?: LazyMeta): Lazy<T>;
|
|
200
|
+
/**
|
|
201
|
+
* Creates a lazy-loaded item.
|
|
202
|
+
*
|
|
203
|
+
* @warning The `prefix` in `meta` only holds metadata and does not apply the prefix to the lazy router, use `os.prefix(...).lazyRoute(...)` instead.
|
|
204
|
+
*/
|
|
205
|
+
declare function lazy<T extends Router<ContractRouter<{}>, any>>(prefix: HTTPPath, loader: () => Promise<{
|
|
206
|
+
default: T;
|
|
207
|
+
}>): EnhancedRouter<Lazy<T>, {}, {}, {}>;
|
|
208
|
+
declare function isLazy(item: unknown): item is Lazy<any>;
|
|
209
|
+
declare function getLazyMeta(lazied: Lazy<any>): LazyMeta;
|
|
210
|
+
declare function unlazy<T extends Lazyable<any>>(lazied: T): Promise<{
|
|
211
|
+
default: T extends Lazy<infer U> ? U : T;
|
|
212
|
+
}>;
|
|
213
|
+
|
|
214
|
+
type ProcedureClient<TClientContext extends ClientContext, TSchemas extends Schemas, TErrorMap extends ErrorMap> = Client<TClientContext, InferProcedureClientInputs<TSchemas>, InferSchemaOutput<TSchemas['outputSchema']>, ErrorFromErrorMap<TErrorMap>>;
|
|
215
|
+
interface ProcedureClientInterceptorOptions<TInitialContext extends Context, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
|
216
|
+
context: TInitialContext;
|
|
217
|
+
input: {
|
|
218
|
+
path: unknown;
|
|
219
|
+
query: unknown;
|
|
220
|
+
body: unknown;
|
|
221
|
+
};
|
|
222
|
+
errors: ORPCErrorConstructorMap<TErrorMap>;
|
|
223
|
+
path: readonly string[];
|
|
224
|
+
procedure: Procedure<Context, Context, Schemas, ErrorMap, TMeta>;
|
|
225
|
+
signal?: AbortSignal;
|
|
226
|
+
lastEventId: string | undefined;
|
|
227
|
+
}
|
|
228
|
+
type CreateProcedureClientOptions<TInitialContext extends Context, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext> = {
|
|
229
|
+
/**
|
|
230
|
+
* This is helpful for logging and analytics.
|
|
231
|
+
*/
|
|
232
|
+
path?: readonly string[];
|
|
233
|
+
interceptors?: Interceptor<ProcedureClientInterceptorOptions<TInitialContext, TErrorMap, TMeta>, PromiseWithError<InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>>[];
|
|
234
|
+
} & (Record<never, never> extends TInitialContext ? {
|
|
235
|
+
context?: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
|
|
236
|
+
} : {
|
|
237
|
+
context: Value<Promisable<TInitialContext>, [clientContext: TClientContext]>;
|
|
238
|
+
});
|
|
239
|
+
/**
|
|
240
|
+
* Create Server-side client from a procedure.
|
|
241
|
+
*
|
|
242
|
+
* @see {@link https://orpc.unnoq.com/docs/client/server-side Server-side Client Docs}
|
|
243
|
+
*/
|
|
244
|
+
declare function createProcedureClient<TInitialContext extends Context, TSchemas extends Schemas, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TSchemas, TErrorMap, TMeta>>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TSchemas['outputSchema'], TErrorMap, TMeta, TClientContext>>): ProcedureClient<TClientContext, TSchemas, TErrorMap>;
|
|
245
|
+
|
|
246
|
+
export { traverseContractProcedures as $, middlewareOutputFn as B, isProcedure as G, createProcedureClient as J, Procedure as P, getRouter as T, createAccessibleLazyRouter as V, enhanceRouter as W, resolveContractProcedures as a0, unlazyRouter as a2, mergeCurrentContext as m, createORPCErrorConstructorMap as n, LAZY_SYMBOL as o, lazyInternal as q, lazy as r, isLazy as s, getLazyMeta as t, unlazy as u };
|
|
247
|
+
export type { AnyMiddleware as A, Context as C, ProcedureHandlerOptions as D, EnhanceRouterOptions as E, ProcedureDef as F, ProcedureClientInterceptorOptions as H, InferRouterInitialContext as I, InferRouterInitialContexts as K, Lazy as L, Middleware as M, InferRouterCurrentContexts as N, ORPCErrorConstructorMap as O, InferRouterInputs as Q, Router as R, InferRouterOutputs as S, AccessibleLazyRouter as U, TraverseContractProceduresOptions as X, TraverseContractProcedureCallbackOptions as Y, ContractProcedureCallbackOptions as Z, LazyTraverseContractProceduresOptions as _, CreateProcedureClientOptions as a, UnlaziedRouter as a1, ProcedureClient as b, MergedInitialContext as c, MergedCurrentContext as d, ProcedureHandler as e, EnhancedRouter as f, MapInputMiddleware as g, AnyProcedure as h, Lazyable as i, AnyRouter as j, ORPCErrorConstructorMapItemOptions as k, ORPCErrorConstructorMapItem as l, LazyMeta as p, MiddlewareResult as v, MiddlewareNextFnOptions as w, MiddlewareNextFn as x, MiddlewareOutputFn as y, MiddlewareOptions as z };
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { stringifyJSON, isObject, isORPCErrorStatus, tryDecodeURIComponent, toHttpPath, toArray, intercept, runWithSpan, ORPC_NAME, isAsyncIteratorObject, asyncIteratorWithSpan, setSpanError, ORPCError, toORPCError } from '@temporary-name/shared';
|
|
2
|
+
import { flattenHeader } from '@temporary-name/standard-server';
|
|
3
|
+
import { c as createProcedureClient } from './server.DlRH_uit.mjs';
|
|
4
|
+
import { fallbackContractConfig } from '@temporary-name/contract';
|
|
5
|
+
import { d as deserialize, b as bracketNotationDeserialize, s as serialize, a as standardizeHTTPPath } from './server.Kxw442A9.mjs';
|
|
6
|
+
import { traverseContractProcedures, isProcedure, getLazyMeta, unlazy, getRouter, createContractedProcedure } from '@temporary-name/server';
|
|
7
|
+
import { createRouter, addRoute, findRoute } from 'rou3';
|
|
8
|
+
|
|
9
|
+
async function decode(request, pathParams) {
|
|
10
|
+
return {
|
|
11
|
+
path: pathParams ?? {},
|
|
12
|
+
query: bracketNotationDeserialize(Array.from(request.url.searchParams.entries())),
|
|
13
|
+
headers: request.headers,
|
|
14
|
+
body: deserialize(await request.body()) ?? {}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function encode(output, procedure) {
|
|
18
|
+
const successStatus = fallbackContractConfig(
|
|
19
|
+
"defaultSuccessStatus",
|
|
20
|
+
procedure["~orpc"].route.successStatus
|
|
21
|
+
);
|
|
22
|
+
const outputStructure = fallbackContractConfig(
|
|
23
|
+
"defaultOutputStructure",
|
|
24
|
+
procedure["~orpc"].route.outputStructure
|
|
25
|
+
);
|
|
26
|
+
if (outputStructure === "compact") {
|
|
27
|
+
return {
|
|
28
|
+
status: successStatus,
|
|
29
|
+
headers: {},
|
|
30
|
+
body: serialize(output)
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
if (!isDetailedOutput(output)) {
|
|
34
|
+
throw new Error(`
|
|
35
|
+
Invalid "detailed" output structure:
|
|
36
|
+
\u2022 Expected an object with optional properties:
|
|
37
|
+
- status (number 200-399)
|
|
38
|
+
- headers (Record<string, string | string[]>)
|
|
39
|
+
- body (any)
|
|
40
|
+
\u2022 No extra keys allowed.
|
|
41
|
+
|
|
42
|
+
Actual value:
|
|
43
|
+
${stringifyJSON(output)}
|
|
44
|
+
`);
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
status: output.status ?? successStatus,
|
|
48
|
+
headers: output.headers ?? {},
|
|
49
|
+
body: serialize(output.body)
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function encodeError(error) {
|
|
53
|
+
return {
|
|
54
|
+
status: error.status,
|
|
55
|
+
headers: {},
|
|
56
|
+
body: serialize(error.toJSON(), { outputFormat: "plain" })
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function isDetailedOutput(output) {
|
|
60
|
+
if (!isObject(output)) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
if (output.headers && !isObject(output.headers)) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
if (output.status !== void 0 && (typeof output.status !== "number" || !Number.isInteger(output.status) || isORPCErrorStatus(output.status))) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function resolveFriendlyStandardHandleOptions(options) {
|
|
73
|
+
return {
|
|
74
|
+
...options,
|
|
75
|
+
context: options.context ?? {}
|
|
76
|
+
// Context only optional if all fields are optional
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function toRou3Pattern(path) {
|
|
80
|
+
return standardizeHTTPPath(path).replace(/\/\{\+([^}]+)\}/g, "/**:$1").replace(/\/\{([^}]+)\}/g, "/:$1");
|
|
81
|
+
}
|
|
82
|
+
function decodeParams(params) {
|
|
83
|
+
return Object.fromEntries(
|
|
84
|
+
Object.entries(params).map(([key, value]) => [key, tryDecodeURIComponent(value)])
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
class StandardOpenAPIMatcher {
|
|
89
|
+
tree = createRouter();
|
|
90
|
+
pendingRouters = [];
|
|
91
|
+
init(router, path = []) {
|
|
92
|
+
const laziedOptions = traverseContractProcedures({ router, path }, (traverseOptions) => {
|
|
93
|
+
const { path: path2, contract } = traverseOptions;
|
|
94
|
+
const method = fallbackContractConfig("defaultMethod", contract["~orpc"].route.method);
|
|
95
|
+
const httpPath = toRou3Pattern(contract["~orpc"].route.path ?? toHttpPath(path2));
|
|
96
|
+
if (isProcedure(contract)) {
|
|
97
|
+
addRoute(this.tree, method, httpPath, {
|
|
98
|
+
path: path2,
|
|
99
|
+
contract,
|
|
100
|
+
procedure: contract,
|
|
101
|
+
// this mean dev not used contract-first so we can used contract as procedure directly
|
|
102
|
+
router
|
|
103
|
+
});
|
|
104
|
+
} else {
|
|
105
|
+
addRoute(this.tree, method, httpPath, {
|
|
106
|
+
path: path2,
|
|
107
|
+
contract,
|
|
108
|
+
procedure: void 0,
|
|
109
|
+
router
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
this.pendingRouters.push(
|
|
114
|
+
...laziedOptions.map((option) => ({
|
|
115
|
+
...option,
|
|
116
|
+
httpPathPrefix: toHttpPath(option.path),
|
|
117
|
+
laziedPrefix: getLazyMeta(option.router).prefix
|
|
118
|
+
}))
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
async match(method, pathname) {
|
|
122
|
+
if (this.pendingRouters.length) {
|
|
123
|
+
const newPendingRouters = [];
|
|
124
|
+
for (const pendingRouter of this.pendingRouters) {
|
|
125
|
+
if (!pendingRouter.laziedPrefix || pathname.startsWith(pendingRouter.laziedPrefix) || pathname.startsWith(pendingRouter.httpPathPrefix)) {
|
|
126
|
+
const { default: router } = await unlazy(pendingRouter.router);
|
|
127
|
+
this.init(router, pendingRouter.path);
|
|
128
|
+
} else {
|
|
129
|
+
newPendingRouters.push(pendingRouter);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
this.pendingRouters = newPendingRouters;
|
|
133
|
+
}
|
|
134
|
+
const match = findRoute(this.tree, method, pathname);
|
|
135
|
+
if (!match) {
|
|
136
|
+
return void 0;
|
|
137
|
+
}
|
|
138
|
+
if (!match.data.procedure) {
|
|
139
|
+
const { default: maybeProcedure } = await unlazy(getRouter(match.data.router, match.data.path));
|
|
140
|
+
if (!isProcedure(maybeProcedure)) {
|
|
141
|
+
throw new Error(`
|
|
142
|
+
[Contract-First] Missing or invalid implementation for procedure at path: ${toHttpPath(match.data.path)}.
|
|
143
|
+
Ensure that the procedure is correctly defined and matches the expected contract.
|
|
144
|
+
`);
|
|
145
|
+
}
|
|
146
|
+
match.data.procedure = createContractedProcedure(maybeProcedure, match.data.contract);
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
path: match.data.path,
|
|
150
|
+
procedure: match.data.procedure,
|
|
151
|
+
params: match.params ? decodeParams(match.params) : void 0
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
class CompositeStandardHandlerPlugin {
|
|
157
|
+
plugins;
|
|
158
|
+
constructor(plugins = []) {
|
|
159
|
+
this.plugins = [...plugins].sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
|
160
|
+
}
|
|
161
|
+
init(options, router) {
|
|
162
|
+
for (const plugin of this.plugins) {
|
|
163
|
+
plugin.init?.(options, router);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
class StandardHandler {
|
|
169
|
+
interceptors;
|
|
170
|
+
clientInterceptors;
|
|
171
|
+
rootInterceptors;
|
|
172
|
+
matcher;
|
|
173
|
+
constructor(router, options) {
|
|
174
|
+
this.matcher = new StandardOpenAPIMatcher();
|
|
175
|
+
const plugins = new CompositeStandardHandlerPlugin(options.plugins);
|
|
176
|
+
plugins.init(options, router);
|
|
177
|
+
this.interceptors = toArray(options.interceptors);
|
|
178
|
+
this.clientInterceptors = toArray(options.clientInterceptors);
|
|
179
|
+
this.rootInterceptors = toArray(options.rootInterceptors);
|
|
180
|
+
this.matcher.init(router);
|
|
181
|
+
}
|
|
182
|
+
async handle(request, options) {
|
|
183
|
+
const prefix = options.prefix?.replace(/\/$/, "") || void 0;
|
|
184
|
+
if (prefix && !request.url.pathname.startsWith(`${prefix}/`) && request.url.pathname !== prefix) {
|
|
185
|
+
return { matched: false, response: void 0 };
|
|
186
|
+
}
|
|
187
|
+
return intercept(this.rootInterceptors, { ...options, request, prefix }, async (interceptorOptions) => {
|
|
188
|
+
return runWithSpan({ name: `${request.method} ${request.url.pathname}` }, async (span) => {
|
|
189
|
+
let step;
|
|
190
|
+
try {
|
|
191
|
+
return await intercept(
|
|
192
|
+
this.interceptors,
|
|
193
|
+
interceptorOptions,
|
|
194
|
+
async ({ request: request2, context, prefix: prefix2 }) => {
|
|
195
|
+
const method = request2.method;
|
|
196
|
+
const url = request2.url;
|
|
197
|
+
const pathname = prefix2 ? url.pathname.replace(prefix2, "") : url.pathname;
|
|
198
|
+
const match = await runWithSpan(
|
|
199
|
+
{ name: "find_procedure" },
|
|
200
|
+
() => this.matcher.match(method, `/${pathname.replace(/^\/|\/$/g, "")}`)
|
|
201
|
+
);
|
|
202
|
+
if (!match) {
|
|
203
|
+
return { matched: false, response: void 0 };
|
|
204
|
+
}
|
|
205
|
+
span?.updateName(`${ORPC_NAME}.${match.path.join("/")}`);
|
|
206
|
+
span?.setAttribute("rpc.system", ORPC_NAME);
|
|
207
|
+
span?.setAttribute("rpc.method", match.path.join("."));
|
|
208
|
+
step = "decode_input";
|
|
209
|
+
const input = await runWithSpan({ name: "decode_input" }, () => decode(request2, match.params));
|
|
210
|
+
step = void 0;
|
|
211
|
+
if (isAsyncIteratorObject(input.body)) {
|
|
212
|
+
input.body = asyncIteratorWithSpan(
|
|
213
|
+
{ name: "consume_event_iterator_input", signal: request2.signal },
|
|
214
|
+
input.body
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
const client = createProcedureClient(match.procedure, {
|
|
218
|
+
context,
|
|
219
|
+
path: match.path,
|
|
220
|
+
interceptors: this.clientInterceptors
|
|
221
|
+
});
|
|
222
|
+
step = "call_procedure";
|
|
223
|
+
const output = await client(input, {
|
|
224
|
+
signal: request2.signal,
|
|
225
|
+
lastEventId: flattenHeader(request2.headers["last-event-id"])
|
|
226
|
+
});
|
|
227
|
+
step = void 0;
|
|
228
|
+
const response = encode(output, match.procedure);
|
|
229
|
+
return {
|
|
230
|
+
matched: true,
|
|
231
|
+
response
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
);
|
|
235
|
+
} catch (e) {
|
|
236
|
+
if (step !== "call_procedure") {
|
|
237
|
+
setSpanError(span, e);
|
|
238
|
+
}
|
|
239
|
+
const error = step === "decode_input" && !(e instanceof ORPCError) ? new ORPCError("BAD_REQUEST", {
|
|
240
|
+
message: `Malformed request. Ensure the request body is properly formatted and the 'Content-Type' header is set correctly.`,
|
|
241
|
+
cause: e
|
|
242
|
+
}) : toORPCError(e);
|
|
243
|
+
const response = encodeError(error);
|
|
244
|
+
return {
|
|
245
|
+
matched: true,
|
|
246
|
+
response
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export { CompositeStandardHandlerPlugin as C, StandardHandler as S, encodeError as a, StandardOpenAPIMatcher as b, decodeParams as c, decode as d, encode as e, resolveFriendlyStandardHandleOptions as r, toRou3Pattern as t };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@temporary-name/server",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.9.3-alpha.
|
|
4
|
+
"version": "1.9.3-alpha.32780b2c7ad58cf8dcbc93a40f13494185223e6e",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://www.stainless.com/",
|
|
7
7
|
"repository": {
|
|
@@ -47,6 +47,11 @@
|
|
|
47
47
|
"types": "./dist/adapters/aws-lambda/index.d.mts",
|
|
48
48
|
"import": "./dist/adapters/aws-lambda/index.mjs",
|
|
49
49
|
"default": "./dist/adapters/aws-lambda/index.mjs"
|
|
50
|
+
},
|
|
51
|
+
"./openapi": {
|
|
52
|
+
"types": "./dist/openapi/index.d.mts",
|
|
53
|
+
"import": "./dist/openapi/index.mjs",
|
|
54
|
+
"default": "./dist/openapi/index.mjs"
|
|
50
55
|
}
|
|
51
56
|
},
|
|
52
57
|
"files": [
|
|
@@ -66,18 +71,20 @@
|
|
|
66
71
|
},
|
|
67
72
|
"dependencies": {
|
|
68
73
|
"cookie": "^1.0.2",
|
|
69
|
-
"
|
|
74
|
+
"rou3": "^0.7.7",
|
|
70
75
|
"zod": "^4.1.12",
|
|
71
|
-
"@temporary-name/interop": "1.9.3-alpha.
|
|
72
|
-
"@temporary-name/contract": "1.9.3-alpha.
|
|
73
|
-
"@temporary-name/
|
|
74
|
-
"@temporary-name/standard-server": "1.9.3-alpha.
|
|
75
|
-
"@temporary-name/standard-server-
|
|
76
|
-
"@temporary-name/
|
|
77
|
-
"@temporary-name/
|
|
78
|
-
"@temporary-name/
|
|
76
|
+
"@temporary-name/interop": "1.9.3-alpha.32780b2c7ad58cf8dcbc93a40f13494185223e6e",
|
|
77
|
+
"@temporary-name/contract": "1.9.3-alpha.32780b2c7ad58cf8dcbc93a40f13494185223e6e",
|
|
78
|
+
"@temporary-name/standard-server": "1.9.3-alpha.32780b2c7ad58cf8dcbc93a40f13494185223e6e",
|
|
79
|
+
"@temporary-name/standard-server-fetch": "1.9.3-alpha.32780b2c7ad58cf8dcbc93a40f13494185223e6e",
|
|
80
|
+
"@temporary-name/standard-server-node": "1.9.3-alpha.32780b2c7ad58cf8dcbc93a40f13494185223e6e",
|
|
81
|
+
"@temporary-name/zod": "1.9.3-alpha.32780b2c7ad58cf8dcbc93a40f13494185223e6e",
|
|
82
|
+
"@temporary-name/shared": "1.9.3-alpha.32780b2c7ad58cf8dcbc93a40f13494185223e6e",
|
|
83
|
+
"@temporary-name/json-schema": "1.9.3-alpha.32780b2c7ad58cf8dcbc93a40f13494185223e6e",
|
|
84
|
+
"@temporary-name/standard-server-aws-lambda": "1.9.3-alpha.32780b2c7ad58cf8dcbc93a40f13494185223e6e"
|
|
79
85
|
},
|
|
80
86
|
"devDependencies": {
|
|
87
|
+
"@types/supertest": "^6.0.3",
|
|
81
88
|
"@types/ws": "^8.18.1",
|
|
82
89
|
"supertest": "^7.1.4"
|
|
83
90
|
},
|