@temporary-name/server 1.9.3-alpha.2957dbc009ec31fa21575f028b83c96651cba827 → 1.9.3-alpha.305aebe633f301e28426c6b15cdfd58ddf45641c
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 +3 -3
- package/dist/adapters/standard/index.d.ts +3 -3
- package/dist/adapters/standard/index.mjs +3 -3
- package/dist/index.d.mts +338 -34
- package/dist/index.d.ts +338 -34
- package/dist/index.mjs +424 -96
- package/dist/openapi/index.d.mts +16 -34
- package/dist/openapi/index.d.ts +16 -34
- package/dist/openapi/index.mjs +339 -298
- package/dist/shared/{server.DfUs5c4R.d.ts → server.B0LJ_wu-.d.ts} +3 -3
- package/dist/shared/{server.L8lRAYBR.d.mts → server.BQZMQrPe.d.mts} +3 -3
- package/dist/shared/{server.CpS0m3at.mjs → server.CYa9puL2.mjs} +3 -3
- package/dist/shared/server.ChOv1yG3.mjs +319 -0
- package/dist/shared/server.CjPiuQYH.d.mts +51 -0
- package/dist/shared/server.CjPiuQYH.d.ts +51 -0
- package/dist/shared/server.Cza0RB3u.mjs +160 -0
- package/dist/shared/{server.DPD7R7h_.d.mts → server.DXPMDozZ.d.mts} +182 -20
- package/dist/shared/{server.DPD7R7h_.d.ts → server.DXPMDozZ.d.ts} +182 -20
- package/dist/shared/server.Ny4yD6yY.mjs +525 -0
- package/package.json +10 -11
- package/dist/shared/server.B7tjiDal.mjs +0 -354
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Promisable,
|
|
2
|
-
import
|
|
1
|
+
import { Promisable, HTTPMethod, HTTPPath, OutputStructure, OpenAPI, IsEqual, StandardLazyRequest } from '@temporary-name/shared';
|
|
2
|
+
import * as z from '@temporary-name/zod';
|
|
3
3
|
|
|
4
|
-
type Context =
|
|
4
|
+
type Context = object;
|
|
5
5
|
type MergedInitialContext<TInitial extends Context, TAdditional extends Context, TCurrent extends Context> = TInitial & Omit<TAdditional, keyof TCurrent>;
|
|
6
6
|
type MergedCurrentContext<T extends Context, U extends Context> = Omit<T, keyof U> & U;
|
|
7
7
|
type BuildContextWithAuth<TContext extends Context, TAuthContext> = MergedCurrentContext<TContext, {
|
|
@@ -9,6 +9,9 @@ type BuildContextWithAuth<TContext extends Context, TAuthContext> = MergedCurren
|
|
|
9
9
|
}>;
|
|
10
10
|
declare function mergeCurrentContext<T extends Context, U extends Context>(context: T, other: U): MergedCurrentContext<T, U>;
|
|
11
11
|
|
|
12
|
+
type Meta = Record<string, any>;
|
|
13
|
+
declare function mergeMeta<T extends Meta>(meta1: T, meta2: T): T;
|
|
14
|
+
|
|
12
15
|
type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
|
|
13
16
|
output: TOutput;
|
|
14
17
|
context: TOutContext;
|
|
@@ -19,7 +22,7 @@ interface MiddlewareNextFn<TOutput> {
|
|
|
19
22
|
}): MiddlewareResult<U, TOutput>;
|
|
20
23
|
}
|
|
21
24
|
interface MiddlewareOutputFn<TOutput> {
|
|
22
|
-
(output: TOutput): MiddlewareResult<
|
|
25
|
+
(output: TOutput): MiddlewareResult<{}, TOutput>;
|
|
23
26
|
}
|
|
24
27
|
interface MiddlewareOptions<TInContext extends Context, TOutput, TMeta extends Meta> extends ProcedureHandlerOptions<TInContext, TMeta> {
|
|
25
28
|
next: MiddlewareNextFn<TOutput>;
|
|
@@ -36,9 +39,151 @@ type AnyMiddleware = Middleware<any, any, any, any, any>;
|
|
|
36
39
|
interface MapInputMiddleware<TInput, TMappedInput> {
|
|
37
40
|
(input: TInput): TMappedInput;
|
|
38
41
|
}
|
|
39
|
-
declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<
|
|
42
|
+
declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<{}, TOutput>;
|
|
43
|
+
|
|
44
|
+
interface Route {
|
|
45
|
+
/**
|
|
46
|
+
* The HTTP method of the procedure.
|
|
47
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
48
|
+
*
|
|
49
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
50
|
+
*/
|
|
51
|
+
method?: HTTPMethod;
|
|
52
|
+
/**
|
|
53
|
+
* The HTTP path of the procedure.
|
|
54
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
55
|
+
*
|
|
56
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
57
|
+
*/
|
|
58
|
+
path?: HTTPPath;
|
|
59
|
+
/**
|
|
60
|
+
* The operation ID of the endpoint.
|
|
61
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
62
|
+
*
|
|
63
|
+
* @default Concatenation of router segments
|
|
64
|
+
*/
|
|
65
|
+
operationId?: string;
|
|
66
|
+
/**
|
|
67
|
+
* The summary of the procedure.
|
|
68
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
69
|
+
*
|
|
70
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
71
|
+
*/
|
|
72
|
+
summary?: string;
|
|
73
|
+
/**
|
|
74
|
+
* The description of the procedure.
|
|
75
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
76
|
+
*
|
|
77
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
78
|
+
*/
|
|
79
|
+
description?: string;
|
|
80
|
+
/**
|
|
81
|
+
* Marks the procedure as deprecated.
|
|
82
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
83
|
+
*
|
|
84
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
85
|
+
*/
|
|
86
|
+
deprecated?: boolean;
|
|
87
|
+
/**
|
|
88
|
+
* The tags of the procedure.
|
|
89
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
90
|
+
*
|
|
91
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
92
|
+
*/
|
|
93
|
+
tags?: readonly string[];
|
|
94
|
+
/**
|
|
95
|
+
* The status code of the response when the procedure is successful.
|
|
96
|
+
* The status code must be in the 200-399 range.
|
|
97
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
98
|
+
*
|
|
99
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
100
|
+
* @default 200
|
|
101
|
+
*/
|
|
102
|
+
successStatus?: number;
|
|
103
|
+
/**
|
|
104
|
+
* The description of the response when the procedure is successful.
|
|
105
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
106
|
+
*
|
|
107
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
108
|
+
* @default 'OK'
|
|
109
|
+
*/
|
|
110
|
+
successDescription?: string;
|
|
111
|
+
/**
|
|
112
|
+
* Determines how the response should be structured based on the output.
|
|
113
|
+
*
|
|
114
|
+
* @option 'compact'
|
|
115
|
+
* The output data is directly returned as the response body.
|
|
116
|
+
*
|
|
117
|
+
* @option 'detailed'
|
|
118
|
+
* Return an object with optional properties:
|
|
119
|
+
* - `status`: The response status (must be in 200-399 range) if not set fallback to `successStatus`.
|
|
120
|
+
* - `headers`: Custom headers to merge with the response headers (`Record<string, string | string[] | undefined>`)
|
|
121
|
+
* - `body`: The response body.
|
|
122
|
+
*
|
|
123
|
+
* Example:
|
|
124
|
+
* ```ts
|
|
125
|
+
* const output = {
|
|
126
|
+
* status: 201,
|
|
127
|
+
* headers: { 'x-custom-header': 'value' },
|
|
128
|
+
* body: { message: 'Hello, world!' },
|
|
129
|
+
* };
|
|
130
|
+
* ```
|
|
131
|
+
*
|
|
132
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
133
|
+
* @default 'compact'
|
|
134
|
+
*/
|
|
135
|
+
outputStructure?: OutputStructure;
|
|
136
|
+
/**
|
|
137
|
+
* Override entire auto-generated OpenAPI Operation Object Specification.
|
|
138
|
+
*
|
|
139
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata Operation Metadata Docs}
|
|
140
|
+
*/
|
|
141
|
+
spec?: OpenAPI.OperationObject | ((current: OpenAPI.OperationObject) => OpenAPI.OperationObject);
|
|
142
|
+
}
|
|
143
|
+
interface EnhanceRouteOptions {
|
|
144
|
+
prefix?: HTTPPath;
|
|
145
|
+
tags?: readonly string[];
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
type Schema<TInput, TOutput> = z.core.$ZodType<TOutput, TInput>;
|
|
149
|
+
type AnySchema = z.core.$ZodType<any, any>;
|
|
150
|
+
type AnyShape = Readonly<Record<string, AnySchema>>;
|
|
151
|
+
type UnionToIntersection<T extends readonly object[]> = T extends readonly [infer First, ...infer Rest] ? First & (Rest extends readonly object[] ? UnionToIntersection<Rest> : {}) : {};
|
|
152
|
+
type WrapShape<U extends AnySchema | AnyShape> = U extends AnySchema ? U : U extends AnyShape ? z.KrustyObject<U, z.core.$strip> : never;
|
|
153
|
+
type SchemaIssue = z.core.$ZodIssue;
|
|
154
|
+
type InferSchemaInput<T extends AnySchema> = z.input<T>;
|
|
155
|
+
type InferSchemaOutput<T extends AnySchema> = z.output<T>;
|
|
156
|
+
type InferHandlerInputs<TSchemas extends Schemas> = {
|
|
157
|
+
path: InferSchemaOutput<TSchemas['pathSchema']>;
|
|
158
|
+
query: InferSchemaOutput<TSchemas['querySchema']>;
|
|
159
|
+
body: InferSchemaOutput<TSchemas['bodySchema']>;
|
|
160
|
+
};
|
|
161
|
+
type InferProcedureClientInputs<TSchemas extends Schemas> = {
|
|
162
|
+
path: InferSchemaInput<TSchemas['pathSchema']>;
|
|
163
|
+
query: InferSchemaInput<TSchemas['querySchema']>;
|
|
164
|
+
body: InferSchemaInput<TSchemas['bodySchema']>;
|
|
165
|
+
};
|
|
166
|
+
type TypeRest<TInput, TOutput> = [map: (input: TInput) => Promisable<TOutput>] | (IsEqual<TInput, TOutput> extends true ? [] : never);
|
|
167
|
+
interface Schemas {
|
|
168
|
+
pathSchema: AnySchema;
|
|
169
|
+
querySchema: AnySchema;
|
|
170
|
+
bodySchema: AnySchema;
|
|
171
|
+
outputSchema: AnySchema;
|
|
172
|
+
}
|
|
173
|
+
declare const initialSchemas: {
|
|
174
|
+
pathSchema: z.KrustyObject<{}, z.core.$strict, z.KrustyInternals<string>>;
|
|
175
|
+
querySchema: z.KrustyObject<{}, z.core.$strict, z.KrustyInternals<string>>;
|
|
176
|
+
bodySchema: z.KrustyObject<{}, z.core.$strict, z.KrustyInternals<string>>;
|
|
177
|
+
outputSchema: z.KrustyUnknown<z.KrustyInternals<string>>;
|
|
178
|
+
};
|
|
179
|
+
type InitialSchemas = typeof initialSchemas;
|
|
180
|
+
type MergedSchemas<T1 extends Schemas, T2 extends Partial<Schemas>> = {
|
|
181
|
+
pathSchema: T2['pathSchema'] extends AnySchema ? T2['pathSchema'] : T1['pathSchema'];
|
|
182
|
+
querySchema: T2['querySchema'] extends AnySchema ? T2['querySchema'] : T1['querySchema'];
|
|
183
|
+
bodySchema: T2['bodySchema'] extends AnySchema ? T2['bodySchema'] : T1['bodySchema'];
|
|
184
|
+
outputSchema: T2['outputSchema'] extends AnySchema ? T2['outputSchema'] : T1['outputSchema'];
|
|
185
|
+
};
|
|
40
186
|
|
|
41
|
-
type DefaultProcedureHandlerOptions = ProcedureHandlerOptions<Context, Meta>;
|
|
42
187
|
interface ProcedureHandlerOptions<TCurrentContext extends Context, TMeta extends Meta> {
|
|
43
188
|
context: TCurrentContext;
|
|
44
189
|
path: readonly string[];
|
|
@@ -54,16 +199,16 @@ interface ProcedureHandler<TCurrentContext extends Context, TInput extends {
|
|
|
54
199
|
}, THandlerOutput, TMeta extends Meta> {
|
|
55
200
|
(input: TInput, opt: ProcedureHandlerOptions<TCurrentContext, TMeta>): Promisable<THandlerOutput>;
|
|
56
201
|
}
|
|
57
|
-
interface ContractDef<
|
|
202
|
+
interface ContractDef<TSchemas extends Schemas, TMeta extends Meta> {
|
|
58
203
|
meta: TMeta;
|
|
59
204
|
route: Route;
|
|
60
205
|
schemas: TSchemas;
|
|
61
|
-
middlewares: readonly
|
|
62
|
-
authConfigs:
|
|
206
|
+
middlewares: readonly AnyMiddleware[];
|
|
207
|
+
authConfigs: AnyAuthConfig[];
|
|
63
208
|
inputValidationIndex: number;
|
|
64
209
|
outputValidationIndex: number;
|
|
65
210
|
}
|
|
66
|
-
type AnyContractDef = ContractDef<
|
|
211
|
+
type AnyContractDef = ContractDef<Schemas, Meta>;
|
|
67
212
|
declare class Contract<TDef extends AnyContractDef = AnyContractDef> {
|
|
68
213
|
/**
|
|
69
214
|
* This property holds the defined options.
|
|
@@ -71,8 +216,9 @@ declare class Contract<TDef extends AnyContractDef = AnyContractDef> {
|
|
|
71
216
|
'~orpc': TDef;
|
|
72
217
|
constructor(def: TDef);
|
|
73
218
|
}
|
|
74
|
-
interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TMeta extends Meta> extends ContractDef<
|
|
219
|
+
interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TMeta extends Meta> extends ContractDef<TSchemas, TMeta> {
|
|
75
220
|
handler: ProcedureHandler<TCurrentContext, any, any, any>;
|
|
221
|
+
'~~DO_NOT_USE_initialContextHack'?: (type: TInitialContext) => unknown;
|
|
76
222
|
}
|
|
77
223
|
/**
|
|
78
224
|
* This class represents a procedure.
|
|
@@ -85,22 +231,38 @@ type AnyProcedure = Procedure<any, any, Schemas, any>;
|
|
|
85
231
|
declare function isProcedure(item: unknown): item is AnyProcedure;
|
|
86
232
|
|
|
87
233
|
type ValidatedAuthContext = {};
|
|
88
|
-
interface
|
|
234
|
+
interface BaseAuthConfig {
|
|
235
|
+
oasDescription?: string;
|
|
236
|
+
oasName?: string;
|
|
237
|
+
}
|
|
238
|
+
interface BasicAuthConfig<TAuthContext extends ValidatedAuthContext, TCurrentContext extends Context, TMeta extends Meta> extends BaseAuthConfig {
|
|
89
239
|
tokenPrefix?: string;
|
|
90
240
|
validate: (username: string, password: string, options: ProcedureHandlerOptions<TCurrentContext, TMeta>) => Promisable<TAuthContext>;
|
|
91
241
|
}
|
|
92
|
-
interface
|
|
242
|
+
interface BearerAuthConfig<TAuthContext extends ValidatedAuthContext, TCurrentContext extends Context, TMeta extends Meta> extends TokenAuthConfig<TAuthContext, TCurrentContext, TMeta> {
|
|
243
|
+
oasBearerFormat?: string;
|
|
244
|
+
}
|
|
245
|
+
interface TokenAuthConfig<TAuthContext extends ValidatedAuthContext, TCurrentContext extends Context, TMeta extends Meta> extends BaseAuthConfig {
|
|
93
246
|
tokenPrefix?: string;
|
|
94
247
|
validate: (token: string, options: ProcedureHandlerOptions<TCurrentContext, TMeta>) => Promisable<TAuthContext>;
|
|
95
248
|
}
|
|
96
249
|
interface NamedTokenAuthConfig<TAuthContext extends ValidatedAuthContext, TCurrentContext extends Context, TMeta extends Meta> extends TokenAuthConfig<TAuthContext, TCurrentContext, TMeta> {
|
|
97
250
|
name: string;
|
|
98
251
|
}
|
|
99
|
-
type
|
|
100
|
-
type AuthConfig<
|
|
101
|
-
type
|
|
102
|
-
|
|
103
|
-
|
|
252
|
+
type AnyAuthConfig = AuthConfig<any, any, any>;
|
|
253
|
+
type AuthConfig<TAuthContext extends ValidatedAuthContext, TCurrentContext extends Context, TMeta extends Meta> = ({
|
|
254
|
+
type: 'basic';
|
|
255
|
+
} & BasicAuthConfig<TAuthContext, TCurrentContext, TMeta>) | ({
|
|
256
|
+
type: 'bearer';
|
|
257
|
+
} & BearerAuthConfig<TAuthContext, TCurrentContext, TMeta>) | ({
|
|
258
|
+
type: 'header';
|
|
259
|
+
} & NamedTokenAuthConfig<TAuthContext, TCurrentContext, TMeta>) | ({
|
|
260
|
+
type: 'query';
|
|
261
|
+
} & NamedTokenAuthConfig<TAuthContext, TCurrentContext, TMeta>) | ({
|
|
262
|
+
type: 'cookie';
|
|
263
|
+
} & NamedTokenAuthConfig<TAuthContext, TCurrentContext, TMeta>) | {
|
|
264
|
+
type: 'none';
|
|
265
|
+
};
|
|
104
266
|
|
|
105
267
|
type ContractRouter = Contract | {
|
|
106
268
|
[k: string]: ContractRouter;
|
|
@@ -222,5 +384,5 @@ declare function unlazy<T extends Lazyable<any>>(lazied: T): Promise<{
|
|
|
222
384
|
default: T extends Lazy<infer U> ? U : T;
|
|
223
385
|
}>;
|
|
224
386
|
|
|
225
|
-
export {
|
|
226
|
-
export type {
|
|
387
|
+
export { lazy as D, isLazy as F, getLazyMeta as G, unlazy as H, mergeMeta as J, Procedure as P, middlewareOutputFn as T, isProcedure as _, getRouter as a4, createAccessibleLazyRouter as a6, enhanceRouter as a7, traverseContractProcedures as ac, resolveContractProcedures as ad, unlazyRouter as af, initialSchemas as ah, Contract as b, mergeCurrentContext as w, LAZY_SYMBOL as x, lazyInternal as z };
|
|
388
|
+
export type { ContractRouter as $, AnyShape as A, BuildContextWithAuth as B, Context as C, EnhanceRouterOptions as E, InferProcedureClientInputs as I, MiddlewareResult as K, Lazyable as L, Meta as M, MiddlewareNextFn as N, MiddlewareOutputFn as O, MiddlewareOptions as Q, Route as R, Schemas as S, UnionToIntersection as U, ValidatedAuthContext as V, WrapShape as W, ProcedureHandlerOptions as X, AnyContractDef as Y, ProcedureDef as Z, InferSchemaOutput as a, InferRouterInitialContexts as a0, InferRouterCurrentContexts as a1, InferRouterInputs as a2, InferRouterOutputs as a3, AccessibleLazyRouter as a5, TraverseContractProceduresOptions as a8, TraverseContractProcedureCallbackOptions as a9, ContractProcedureCallbackOptions as aa, LazyTraverseContractProceduresOptions as ab, UnlaziedRouter as ae, TypeRest as ag, InitialSchemas as ai, MergedSchemas as c, AnySchema as d, Middleware as e, MergedCurrentContext as f, MergedInitialContext as g, AuthConfig as h, ProcedureHandler as i, InferHandlerInputs as j, InferSchemaInput as k, Router as l, EnhancedRouter as m, MapInputMiddleware as n, ContractDef as o, SchemaIssue as p, Schema as q, AnyMiddleware as r, Lazy as s, AnyProcedure as t, AnyRouter as u, InferRouterInitialContext as v, LazyMeta as y };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Promisable,
|
|
2
|
-
import
|
|
1
|
+
import { Promisable, HTTPMethod, HTTPPath, OutputStructure, OpenAPI, IsEqual, StandardLazyRequest } from '@temporary-name/shared';
|
|
2
|
+
import * as z from '@temporary-name/zod';
|
|
3
3
|
|
|
4
|
-
type Context =
|
|
4
|
+
type Context = object;
|
|
5
5
|
type MergedInitialContext<TInitial extends Context, TAdditional extends Context, TCurrent extends Context> = TInitial & Omit<TAdditional, keyof TCurrent>;
|
|
6
6
|
type MergedCurrentContext<T extends Context, U extends Context> = Omit<T, keyof U> & U;
|
|
7
7
|
type BuildContextWithAuth<TContext extends Context, TAuthContext> = MergedCurrentContext<TContext, {
|
|
@@ -9,6 +9,9 @@ type BuildContextWithAuth<TContext extends Context, TAuthContext> = MergedCurren
|
|
|
9
9
|
}>;
|
|
10
10
|
declare function mergeCurrentContext<T extends Context, U extends Context>(context: T, other: U): MergedCurrentContext<T, U>;
|
|
11
11
|
|
|
12
|
+
type Meta = Record<string, any>;
|
|
13
|
+
declare function mergeMeta<T extends Meta>(meta1: T, meta2: T): T;
|
|
14
|
+
|
|
12
15
|
type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
|
|
13
16
|
output: TOutput;
|
|
14
17
|
context: TOutContext;
|
|
@@ -19,7 +22,7 @@ interface MiddlewareNextFn<TOutput> {
|
|
|
19
22
|
}): MiddlewareResult<U, TOutput>;
|
|
20
23
|
}
|
|
21
24
|
interface MiddlewareOutputFn<TOutput> {
|
|
22
|
-
(output: TOutput): MiddlewareResult<
|
|
25
|
+
(output: TOutput): MiddlewareResult<{}, TOutput>;
|
|
23
26
|
}
|
|
24
27
|
interface MiddlewareOptions<TInContext extends Context, TOutput, TMeta extends Meta> extends ProcedureHandlerOptions<TInContext, TMeta> {
|
|
25
28
|
next: MiddlewareNextFn<TOutput>;
|
|
@@ -36,9 +39,151 @@ type AnyMiddleware = Middleware<any, any, any, any, any>;
|
|
|
36
39
|
interface MapInputMiddleware<TInput, TMappedInput> {
|
|
37
40
|
(input: TInput): TMappedInput;
|
|
38
41
|
}
|
|
39
|
-
declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<
|
|
42
|
+
declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<{}, TOutput>;
|
|
43
|
+
|
|
44
|
+
interface Route {
|
|
45
|
+
/**
|
|
46
|
+
* The HTTP method of the procedure.
|
|
47
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
48
|
+
*
|
|
49
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
50
|
+
*/
|
|
51
|
+
method?: HTTPMethod;
|
|
52
|
+
/**
|
|
53
|
+
* The HTTP path of the procedure.
|
|
54
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
55
|
+
*
|
|
56
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
57
|
+
*/
|
|
58
|
+
path?: HTTPPath;
|
|
59
|
+
/**
|
|
60
|
+
* The operation ID of the endpoint.
|
|
61
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
62
|
+
*
|
|
63
|
+
* @default Concatenation of router segments
|
|
64
|
+
*/
|
|
65
|
+
operationId?: string;
|
|
66
|
+
/**
|
|
67
|
+
* The summary of the procedure.
|
|
68
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
69
|
+
*
|
|
70
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
71
|
+
*/
|
|
72
|
+
summary?: string;
|
|
73
|
+
/**
|
|
74
|
+
* The description of the procedure.
|
|
75
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
76
|
+
*
|
|
77
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
78
|
+
*/
|
|
79
|
+
description?: string;
|
|
80
|
+
/**
|
|
81
|
+
* Marks the procedure as deprecated.
|
|
82
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
83
|
+
*
|
|
84
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
85
|
+
*/
|
|
86
|
+
deprecated?: boolean;
|
|
87
|
+
/**
|
|
88
|
+
* The tags of the procedure.
|
|
89
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
90
|
+
*
|
|
91
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
92
|
+
*/
|
|
93
|
+
tags?: readonly string[];
|
|
94
|
+
/**
|
|
95
|
+
* The status code of the response when the procedure is successful.
|
|
96
|
+
* The status code must be in the 200-399 range.
|
|
97
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
98
|
+
*
|
|
99
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
100
|
+
* @default 200
|
|
101
|
+
*/
|
|
102
|
+
successStatus?: number;
|
|
103
|
+
/**
|
|
104
|
+
* The description of the response when the procedure is successful.
|
|
105
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
106
|
+
*
|
|
107
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
108
|
+
* @default 'OK'
|
|
109
|
+
*/
|
|
110
|
+
successDescription?: string;
|
|
111
|
+
/**
|
|
112
|
+
* Determines how the response should be structured based on the output.
|
|
113
|
+
*
|
|
114
|
+
* @option 'compact'
|
|
115
|
+
* The output data is directly returned as the response body.
|
|
116
|
+
*
|
|
117
|
+
* @option 'detailed'
|
|
118
|
+
* Return an object with optional properties:
|
|
119
|
+
* - `status`: The response status (must be in 200-399 range) if not set fallback to `successStatus`.
|
|
120
|
+
* - `headers`: Custom headers to merge with the response headers (`Record<string, string | string[] | undefined>`)
|
|
121
|
+
* - `body`: The response body.
|
|
122
|
+
*
|
|
123
|
+
* Example:
|
|
124
|
+
* ```ts
|
|
125
|
+
* const output = {
|
|
126
|
+
* status: 201,
|
|
127
|
+
* headers: { 'x-custom-header': 'value' },
|
|
128
|
+
* body: { message: 'Hello, world!' },
|
|
129
|
+
* };
|
|
130
|
+
* ```
|
|
131
|
+
*
|
|
132
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
133
|
+
* @default 'compact'
|
|
134
|
+
*/
|
|
135
|
+
outputStructure?: OutputStructure;
|
|
136
|
+
/**
|
|
137
|
+
* Override entire auto-generated OpenAPI Operation Object Specification.
|
|
138
|
+
*
|
|
139
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata Operation Metadata Docs}
|
|
140
|
+
*/
|
|
141
|
+
spec?: OpenAPI.OperationObject | ((current: OpenAPI.OperationObject) => OpenAPI.OperationObject);
|
|
142
|
+
}
|
|
143
|
+
interface EnhanceRouteOptions {
|
|
144
|
+
prefix?: HTTPPath;
|
|
145
|
+
tags?: readonly string[];
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
type Schema<TInput, TOutput> = z.core.$ZodType<TOutput, TInput>;
|
|
149
|
+
type AnySchema = z.core.$ZodType<any, any>;
|
|
150
|
+
type AnyShape = Readonly<Record<string, AnySchema>>;
|
|
151
|
+
type UnionToIntersection<T extends readonly object[]> = T extends readonly [infer First, ...infer Rest] ? First & (Rest extends readonly object[] ? UnionToIntersection<Rest> : {}) : {};
|
|
152
|
+
type WrapShape<U extends AnySchema | AnyShape> = U extends AnySchema ? U : U extends AnyShape ? z.KrustyObject<U, z.core.$strip> : never;
|
|
153
|
+
type SchemaIssue = z.core.$ZodIssue;
|
|
154
|
+
type InferSchemaInput<T extends AnySchema> = z.input<T>;
|
|
155
|
+
type InferSchemaOutput<T extends AnySchema> = z.output<T>;
|
|
156
|
+
type InferHandlerInputs<TSchemas extends Schemas> = {
|
|
157
|
+
path: InferSchemaOutput<TSchemas['pathSchema']>;
|
|
158
|
+
query: InferSchemaOutput<TSchemas['querySchema']>;
|
|
159
|
+
body: InferSchemaOutput<TSchemas['bodySchema']>;
|
|
160
|
+
};
|
|
161
|
+
type InferProcedureClientInputs<TSchemas extends Schemas> = {
|
|
162
|
+
path: InferSchemaInput<TSchemas['pathSchema']>;
|
|
163
|
+
query: InferSchemaInput<TSchemas['querySchema']>;
|
|
164
|
+
body: InferSchemaInput<TSchemas['bodySchema']>;
|
|
165
|
+
};
|
|
166
|
+
type TypeRest<TInput, TOutput> = [map: (input: TInput) => Promisable<TOutput>] | (IsEqual<TInput, TOutput> extends true ? [] : never);
|
|
167
|
+
interface Schemas {
|
|
168
|
+
pathSchema: AnySchema;
|
|
169
|
+
querySchema: AnySchema;
|
|
170
|
+
bodySchema: AnySchema;
|
|
171
|
+
outputSchema: AnySchema;
|
|
172
|
+
}
|
|
173
|
+
declare const initialSchemas: {
|
|
174
|
+
pathSchema: z.KrustyObject<{}, z.core.$strict, z.KrustyInternals<string>>;
|
|
175
|
+
querySchema: z.KrustyObject<{}, z.core.$strict, z.KrustyInternals<string>>;
|
|
176
|
+
bodySchema: z.KrustyObject<{}, z.core.$strict, z.KrustyInternals<string>>;
|
|
177
|
+
outputSchema: z.KrustyUnknown<z.KrustyInternals<string>>;
|
|
178
|
+
};
|
|
179
|
+
type InitialSchemas = typeof initialSchemas;
|
|
180
|
+
type MergedSchemas<T1 extends Schemas, T2 extends Partial<Schemas>> = {
|
|
181
|
+
pathSchema: T2['pathSchema'] extends AnySchema ? T2['pathSchema'] : T1['pathSchema'];
|
|
182
|
+
querySchema: T2['querySchema'] extends AnySchema ? T2['querySchema'] : T1['querySchema'];
|
|
183
|
+
bodySchema: T2['bodySchema'] extends AnySchema ? T2['bodySchema'] : T1['bodySchema'];
|
|
184
|
+
outputSchema: T2['outputSchema'] extends AnySchema ? T2['outputSchema'] : T1['outputSchema'];
|
|
185
|
+
};
|
|
40
186
|
|
|
41
|
-
type DefaultProcedureHandlerOptions = ProcedureHandlerOptions<Context, Meta>;
|
|
42
187
|
interface ProcedureHandlerOptions<TCurrentContext extends Context, TMeta extends Meta> {
|
|
43
188
|
context: TCurrentContext;
|
|
44
189
|
path: readonly string[];
|
|
@@ -54,16 +199,16 @@ interface ProcedureHandler<TCurrentContext extends Context, TInput extends {
|
|
|
54
199
|
}, THandlerOutput, TMeta extends Meta> {
|
|
55
200
|
(input: TInput, opt: ProcedureHandlerOptions<TCurrentContext, TMeta>): Promisable<THandlerOutput>;
|
|
56
201
|
}
|
|
57
|
-
interface ContractDef<
|
|
202
|
+
interface ContractDef<TSchemas extends Schemas, TMeta extends Meta> {
|
|
58
203
|
meta: TMeta;
|
|
59
204
|
route: Route;
|
|
60
205
|
schemas: TSchemas;
|
|
61
|
-
middlewares: readonly
|
|
62
|
-
authConfigs:
|
|
206
|
+
middlewares: readonly AnyMiddleware[];
|
|
207
|
+
authConfigs: AnyAuthConfig[];
|
|
63
208
|
inputValidationIndex: number;
|
|
64
209
|
outputValidationIndex: number;
|
|
65
210
|
}
|
|
66
|
-
type AnyContractDef = ContractDef<
|
|
211
|
+
type AnyContractDef = ContractDef<Schemas, Meta>;
|
|
67
212
|
declare class Contract<TDef extends AnyContractDef = AnyContractDef> {
|
|
68
213
|
/**
|
|
69
214
|
* This property holds the defined options.
|
|
@@ -71,8 +216,9 @@ declare class Contract<TDef extends AnyContractDef = AnyContractDef> {
|
|
|
71
216
|
'~orpc': TDef;
|
|
72
217
|
constructor(def: TDef);
|
|
73
218
|
}
|
|
74
|
-
interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TMeta extends Meta> extends ContractDef<
|
|
219
|
+
interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TMeta extends Meta> extends ContractDef<TSchemas, TMeta> {
|
|
75
220
|
handler: ProcedureHandler<TCurrentContext, any, any, any>;
|
|
221
|
+
'~~DO_NOT_USE_initialContextHack'?: (type: TInitialContext) => unknown;
|
|
76
222
|
}
|
|
77
223
|
/**
|
|
78
224
|
* This class represents a procedure.
|
|
@@ -85,22 +231,38 @@ type AnyProcedure = Procedure<any, any, Schemas, any>;
|
|
|
85
231
|
declare function isProcedure(item: unknown): item is AnyProcedure;
|
|
86
232
|
|
|
87
233
|
type ValidatedAuthContext = {};
|
|
88
|
-
interface
|
|
234
|
+
interface BaseAuthConfig {
|
|
235
|
+
oasDescription?: string;
|
|
236
|
+
oasName?: string;
|
|
237
|
+
}
|
|
238
|
+
interface BasicAuthConfig<TAuthContext extends ValidatedAuthContext, TCurrentContext extends Context, TMeta extends Meta> extends BaseAuthConfig {
|
|
89
239
|
tokenPrefix?: string;
|
|
90
240
|
validate: (username: string, password: string, options: ProcedureHandlerOptions<TCurrentContext, TMeta>) => Promisable<TAuthContext>;
|
|
91
241
|
}
|
|
92
|
-
interface
|
|
242
|
+
interface BearerAuthConfig<TAuthContext extends ValidatedAuthContext, TCurrentContext extends Context, TMeta extends Meta> extends TokenAuthConfig<TAuthContext, TCurrentContext, TMeta> {
|
|
243
|
+
oasBearerFormat?: string;
|
|
244
|
+
}
|
|
245
|
+
interface TokenAuthConfig<TAuthContext extends ValidatedAuthContext, TCurrentContext extends Context, TMeta extends Meta> extends BaseAuthConfig {
|
|
93
246
|
tokenPrefix?: string;
|
|
94
247
|
validate: (token: string, options: ProcedureHandlerOptions<TCurrentContext, TMeta>) => Promisable<TAuthContext>;
|
|
95
248
|
}
|
|
96
249
|
interface NamedTokenAuthConfig<TAuthContext extends ValidatedAuthContext, TCurrentContext extends Context, TMeta extends Meta> extends TokenAuthConfig<TAuthContext, TCurrentContext, TMeta> {
|
|
97
250
|
name: string;
|
|
98
251
|
}
|
|
99
|
-
type
|
|
100
|
-
type AuthConfig<
|
|
101
|
-
type
|
|
102
|
-
|
|
103
|
-
|
|
252
|
+
type AnyAuthConfig = AuthConfig<any, any, any>;
|
|
253
|
+
type AuthConfig<TAuthContext extends ValidatedAuthContext, TCurrentContext extends Context, TMeta extends Meta> = ({
|
|
254
|
+
type: 'basic';
|
|
255
|
+
} & BasicAuthConfig<TAuthContext, TCurrentContext, TMeta>) | ({
|
|
256
|
+
type: 'bearer';
|
|
257
|
+
} & BearerAuthConfig<TAuthContext, TCurrentContext, TMeta>) | ({
|
|
258
|
+
type: 'header';
|
|
259
|
+
} & NamedTokenAuthConfig<TAuthContext, TCurrentContext, TMeta>) | ({
|
|
260
|
+
type: 'query';
|
|
261
|
+
} & NamedTokenAuthConfig<TAuthContext, TCurrentContext, TMeta>) | ({
|
|
262
|
+
type: 'cookie';
|
|
263
|
+
} & NamedTokenAuthConfig<TAuthContext, TCurrentContext, TMeta>) | {
|
|
264
|
+
type: 'none';
|
|
265
|
+
};
|
|
104
266
|
|
|
105
267
|
type ContractRouter = Contract | {
|
|
106
268
|
[k: string]: ContractRouter;
|
|
@@ -222,5 +384,5 @@ declare function unlazy<T extends Lazyable<any>>(lazied: T): Promise<{
|
|
|
222
384
|
default: T extends Lazy<infer U> ? U : T;
|
|
223
385
|
}>;
|
|
224
386
|
|
|
225
|
-
export {
|
|
226
|
-
export type {
|
|
387
|
+
export { lazy as D, isLazy as F, getLazyMeta as G, unlazy as H, mergeMeta as J, Procedure as P, middlewareOutputFn as T, isProcedure as _, getRouter as a4, createAccessibleLazyRouter as a6, enhanceRouter as a7, traverseContractProcedures as ac, resolveContractProcedures as ad, unlazyRouter as af, initialSchemas as ah, Contract as b, mergeCurrentContext as w, LAZY_SYMBOL as x, lazyInternal as z };
|
|
388
|
+
export type { ContractRouter as $, AnyShape as A, BuildContextWithAuth as B, Context as C, EnhanceRouterOptions as E, InferProcedureClientInputs as I, MiddlewareResult as K, Lazyable as L, Meta as M, MiddlewareNextFn as N, MiddlewareOutputFn as O, MiddlewareOptions as Q, Route as R, Schemas as S, UnionToIntersection as U, ValidatedAuthContext as V, WrapShape as W, ProcedureHandlerOptions as X, AnyContractDef as Y, ProcedureDef as Z, InferSchemaOutput as a, InferRouterInitialContexts as a0, InferRouterCurrentContexts as a1, InferRouterInputs as a2, InferRouterOutputs as a3, AccessibleLazyRouter as a5, TraverseContractProceduresOptions as a8, TraverseContractProcedureCallbackOptions as a9, ContractProcedureCallbackOptions as aa, LazyTraverseContractProceduresOptions as ab, UnlaziedRouter as ae, TypeRest as ag, InitialSchemas as ai, MergedSchemas as c, AnySchema as d, Middleware as e, MergedCurrentContext as f, MergedInitialContext as g, AuthConfig as h, ProcedureHandler as i, InferHandlerInputs as j, InferSchemaInput as k, Router as l, EnhancedRouter as m, MapInputMiddleware as n, ContractDef as o, SchemaIssue as p, Schema as q, AnyMiddleware as r, Lazy as s, AnyProcedure as t, AnyRouter as u, InferRouterInitialContext as v, LazyMeta as y };
|