@temporary-name/server 1.9.3-alpha.8dcf0da5d97e7b89ab5ce50c8d1733c158e629a8 → 1.9.3-alpha.907c7c78d0193d34752279de92d699e50d6bc3a1
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 +4 -6
- package/dist/adapters/aws-lambda/index.d.ts +4 -6
- package/dist/adapters/aws-lambda/index.mjs +4 -4
- package/dist/adapters/fetch/index.d.mts +8 -86
- package/dist/adapters/fetch/index.d.ts +8 -86
- package/dist/adapters/fetch/index.mjs +16 -155
- package/dist/adapters/node/index.d.mts +8 -63
- package/dist/adapters/node/index.d.ts +8 -63
- package/dist/adapters/node/index.mjs +14 -120
- package/dist/adapters/standard/index.d.mts +5 -7
- package/dist/adapters/standard/index.d.ts +5 -7
- package/dist/adapters/standard/index.mjs +4 -4
- package/dist/helpers/index.mjs +3 -29
- package/dist/index.d.mts +104 -182
- package/dist/index.d.ts +104 -182
- package/dist/index.mjs +126 -104
- package/dist/openapi/index.d.mts +11 -27
- package/dist/openapi/index.d.ts +11 -27
- package/dist/openapi/index.mjs +8 -75
- package/dist/shared/server.Bj_UpI5O.d.mts +372 -0
- package/dist/shared/server.Bj_UpI5O.d.ts +372 -0
- package/dist/shared/server.C1RJffw4.mjs +30 -0
- package/dist/shared/server.C6VnFy4S.d.mts +41 -0
- package/dist/shared/server.CQIFwyhc.mjs +40 -0
- package/dist/shared/server.ChOv1yG3.mjs +319 -0
- package/dist/shared/server.CnzXkSjj.d.ts +41 -0
- package/dist/shared/server.DXzEGRE2.mjs +403 -0
- package/dist/shared/server.DgzAlPjF.mjs +160 -0
- package/dist/shared/server.YUvuxHty.mjs +48 -0
- package/package.json +10 -27
- package/dist/plugins/index.d.mts +0 -160
- package/dist/plugins/index.d.ts +0 -160
- package/dist/plugins/index.mjs +0 -288
- package/dist/shared/server.BSJugGGA.d.mts +0 -56
- package/dist/shared/server.Bs8EZATl.d.ts +0 -23
- package/dist/shared/server.CHV9AQHl.mjs +0 -412
- package/dist/shared/server.CWWP8ypC.d.mts +0 -239
- package/dist/shared/server.CWWP8ypC.d.ts +0 -239
- package/dist/shared/server.Cn7WsRHl.mjs +0 -254
- package/dist/shared/server.DrMgIiBr.d.mts +0 -23
- package/dist/shared/server.EKwDe0d2.d.ts +0 -56
- package/dist/shared/server.JtIZ8YG7.mjs +0 -237
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
import { Promisable, HTTPMethod, HTTPPath, OutputStructure, OpenAPI, IsEqual, StandardLazyRequest } from '@temporary-name/shared';
|
|
2
|
+
import * as z from '@temporary-name/zod';
|
|
3
|
+
|
|
4
|
+
type Context = Record<PropertyKey, any>;
|
|
5
|
+
type MergedInitialContext<TInitial extends Context, TAdditional extends Context, TCurrent extends Context> = TInitial & Omit<TAdditional, keyof TCurrent>;
|
|
6
|
+
type MergedCurrentContext<T extends Context, U extends Context> = Omit<T, keyof U> & U;
|
|
7
|
+
type BuildContextWithAuth<TContext extends Context, TAuthContext> = MergedCurrentContext<TContext, {
|
|
8
|
+
auth: TAuthContext | ('auth' extends keyof TContext ? TContext['auth'] : never);
|
|
9
|
+
}>;
|
|
10
|
+
declare function mergeCurrentContext<T extends Context, U extends Context>(context: T, other: U): MergedCurrentContext<T, U>;
|
|
11
|
+
|
|
12
|
+
type Meta = Record<string, any>;
|
|
13
|
+
declare function mergeMeta<T extends Meta>(meta1: T, meta2: T): T;
|
|
14
|
+
|
|
15
|
+
type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
|
|
16
|
+
output: TOutput;
|
|
17
|
+
context: TOutContext;
|
|
18
|
+
}>;
|
|
19
|
+
interface MiddlewareNextFn<TOutput> {
|
|
20
|
+
<U extends Context = {}>(options?: {
|
|
21
|
+
context?: U;
|
|
22
|
+
}): MiddlewareResult<U, TOutput>;
|
|
23
|
+
}
|
|
24
|
+
interface MiddlewareOutputFn<TOutput> {
|
|
25
|
+
(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
|
|
26
|
+
}
|
|
27
|
+
interface MiddlewareOptions<TInContext extends Context, TOutput, TMeta extends Meta> extends ProcedureHandlerOptions<TInContext, TMeta> {
|
|
28
|
+
next: MiddlewareNextFn<TOutput>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* A function that represents a middleware.
|
|
32
|
+
*
|
|
33
|
+
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
34
|
+
*/
|
|
35
|
+
interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TMeta extends Meta> {
|
|
36
|
+
(options: MiddlewareOptions<TInContext, TOutput, TMeta>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
|
|
37
|
+
}
|
|
38
|
+
type AnyMiddleware = Middleware<any, any, any, any, any>;
|
|
39
|
+
interface MapInputMiddleware<TInput, TMappedInput> {
|
|
40
|
+
(input: TInput): TMappedInput;
|
|
41
|
+
}
|
|
42
|
+
declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<Record<never, never>, 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
|
+
};
|
|
186
|
+
|
|
187
|
+
type DefaultProcedureHandlerOptions = ProcedureHandlerOptions<Context, Meta>;
|
|
188
|
+
interface ProcedureHandlerOptions<TCurrentContext extends Context, TMeta extends Meta> {
|
|
189
|
+
context: TCurrentContext;
|
|
190
|
+
path: readonly string[];
|
|
191
|
+
procedure: Procedure<Context, Context, Schemas, TMeta>;
|
|
192
|
+
signal?: AbortSignal;
|
|
193
|
+
request?: StandardLazyRequest;
|
|
194
|
+
lastEventId: string | undefined;
|
|
195
|
+
}
|
|
196
|
+
interface ProcedureHandler<TCurrentContext extends Context, TInput extends {
|
|
197
|
+
path: any;
|
|
198
|
+
query: any;
|
|
199
|
+
body: any;
|
|
200
|
+
}, THandlerOutput, TMeta extends Meta> {
|
|
201
|
+
(input: TInput, opt: ProcedureHandlerOptions<TCurrentContext, TMeta>): Promisable<THandlerOutput>;
|
|
202
|
+
}
|
|
203
|
+
interface ContractDef<TInitialContext extends Context, TSchemas extends Schemas, TMeta extends Meta> {
|
|
204
|
+
meta: TMeta;
|
|
205
|
+
route: Route;
|
|
206
|
+
schemas: TSchemas;
|
|
207
|
+
middlewares: readonly Middleware<TInitialContext, any, any, any, any>[];
|
|
208
|
+
authConfigs: TypedAuthConfig[];
|
|
209
|
+
inputValidationIndex: number;
|
|
210
|
+
outputValidationIndex: number;
|
|
211
|
+
}
|
|
212
|
+
type AnyContractDef = ContractDef<Context, Schemas, Meta>;
|
|
213
|
+
declare class Contract<TDef extends AnyContractDef = AnyContractDef> {
|
|
214
|
+
/**
|
|
215
|
+
* This property holds the defined options.
|
|
216
|
+
*/
|
|
217
|
+
'~orpc': TDef;
|
|
218
|
+
constructor(def: TDef);
|
|
219
|
+
}
|
|
220
|
+
interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TMeta extends Meta> extends ContractDef<TInitialContext, TSchemas, TMeta> {
|
|
221
|
+
handler: ProcedureHandler<TCurrentContext, any, any, any>;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* This class represents a procedure.
|
|
225
|
+
*
|
|
226
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
|
|
227
|
+
*/
|
|
228
|
+
declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TMeta extends Meta> extends Contract<ProcedureDef<TInitialContext, TCurrentContext, TSchemas, TMeta>> {
|
|
229
|
+
}
|
|
230
|
+
type AnyProcedure = Procedure<any, any, Schemas, any>;
|
|
231
|
+
declare function isProcedure(item: unknown): item is AnyProcedure;
|
|
232
|
+
|
|
233
|
+
type ValidatedAuthContext = {};
|
|
234
|
+
interface BasicAuthConfig<TAuthContext extends ValidatedAuthContext, TCurrentContext extends Context, TMeta extends Meta> {
|
|
235
|
+
tokenPrefix?: string;
|
|
236
|
+
validate: (username: string, password: string, options: ProcedureHandlerOptions<TCurrentContext, TMeta>) => Promisable<TAuthContext>;
|
|
237
|
+
}
|
|
238
|
+
interface TokenAuthConfig<TAuthContext extends ValidatedAuthContext, TCurrentContext extends Context, TMeta extends Meta> {
|
|
239
|
+
tokenPrefix?: string;
|
|
240
|
+
validate: (token: string, options: ProcedureHandlerOptions<TCurrentContext, TMeta>) => Promisable<TAuthContext>;
|
|
241
|
+
}
|
|
242
|
+
interface NamedTokenAuthConfig<TAuthContext extends ValidatedAuthContext, TCurrentContext extends Context, TMeta extends Meta> extends TokenAuthConfig<TAuthContext, TCurrentContext, TMeta> {
|
|
243
|
+
name: string;
|
|
244
|
+
}
|
|
245
|
+
type AuthType = 'header' | 'query' | 'cookie' | 'bearer' | 'basic' | 'none';
|
|
246
|
+
type AuthConfig<TAuthType extends AuthType, TAuthContext extends ValidatedAuthContext = ValidatedAuthContext, TCurrentContext extends Context = Context, TMeta extends Meta = Meta> = TAuthType extends 'basic' ? BasicAuthConfig<TAuthContext, TCurrentContext, TMeta> : TAuthType extends 'bearer' ? TokenAuthConfig<TAuthContext, TCurrentContext, TMeta> : TAuthType extends 'header' ? NamedTokenAuthConfig<TAuthContext, TCurrentContext, TMeta> : TAuthType extends 'query' ? NamedTokenAuthConfig<TAuthContext, TCurrentContext, TMeta> : TAuthType extends 'cookie' ? NamedTokenAuthConfig<TAuthContext, TCurrentContext, TMeta> : TAuthType extends 'none' ? {} : never;
|
|
247
|
+
type TypedAuthConfig<TAuthType extends AuthType = AuthType> = {
|
|
248
|
+
type: TAuthType;
|
|
249
|
+
} & AuthConfig<TAuthType, object>;
|
|
250
|
+
|
|
251
|
+
type ContractRouter = Contract | {
|
|
252
|
+
[k: string]: ContractRouter;
|
|
253
|
+
};
|
|
254
|
+
/**
|
|
255
|
+
* Represents a router, which defines a hierarchical structure of procedures.
|
|
256
|
+
*
|
|
257
|
+
* @info A procedure is a router too.
|
|
258
|
+
* @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#contract-router Contract Router Docs}
|
|
259
|
+
*/
|
|
260
|
+
type Router<TInitialContext extends Context> = Procedure<TInitialContext, any, any, any> | {
|
|
261
|
+
[k: string]: Lazyable<Router<TInitialContext>>;
|
|
262
|
+
};
|
|
263
|
+
type AnyRouter = Router<any>;
|
|
264
|
+
type InferRouterInitialContext<T extends AnyRouter> = T extends Router<infer UInitialContext> ? UInitialContext : never;
|
|
265
|
+
/**
|
|
266
|
+
* Infer all initial context of the router.
|
|
267
|
+
*
|
|
268
|
+
* @info A procedure is a router too.
|
|
269
|
+
* @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
|
|
270
|
+
*/
|
|
271
|
+
type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any> ? UInitialContext : {
|
|
272
|
+
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never;
|
|
273
|
+
};
|
|
274
|
+
/**
|
|
275
|
+
* Infer all current context of the router.
|
|
276
|
+
*
|
|
277
|
+
* @info A procedure is a router too.
|
|
278
|
+
* @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
|
|
279
|
+
*/
|
|
280
|
+
type InferRouterCurrentContexts<T extends AnyRouter> = T extends Procedure<any, infer UCurrentContext, any, any> ? UCurrentContext : {
|
|
281
|
+
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterCurrentContexts<U> : never;
|
|
282
|
+
};
|
|
283
|
+
/**
|
|
284
|
+
* Infer all router inputs
|
|
285
|
+
*
|
|
286
|
+
* @info A procedure is a router too.
|
|
287
|
+
* @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
|
|
288
|
+
*/
|
|
289
|
+
type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer USchemas, any> ? InferProcedureClientInputs<USchemas> : {
|
|
290
|
+
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never;
|
|
291
|
+
};
|
|
292
|
+
/**
|
|
293
|
+
* Infer all router outputs
|
|
294
|
+
*
|
|
295
|
+
* @info A procedure is a router too.
|
|
296
|
+
* @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
|
|
297
|
+
*/
|
|
298
|
+
type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, infer USchemas, any> ? InferSchemaOutput<USchemas['outputSchema']> : {
|
|
299
|
+
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
declare function getRouter<T extends Lazyable<AnyRouter | undefined>>(router: T, path: readonly string[]): T extends Lazy<any> ? Lazy<AnyRouter | undefined> : Lazyable<AnyRouter | undefined>;
|
|
303
|
+
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> & {
|
|
304
|
+
[K in keyof T]: T[K] extends Lazyable<AnyRouter> ? AccessibleLazyRouter<T[K]> : never;
|
|
305
|
+
};
|
|
306
|
+
declare function createAccessibleLazyRouter<T extends Lazy<AnyRouter | undefined>>(lazied: T): AccessibleLazyRouter<T>;
|
|
307
|
+
type EnhancedRouter<T extends Lazyable<AnyRouter>, TInitialContext extends Context, TCurrentContext extends Context> = T extends Lazy<infer U extends AnyRouter> ? AccessibleLazyRouter<EnhancedRouter<U, TInitialContext, TCurrentContext>> : T extends Procedure<infer UInitialContext, infer UCurrentContext, infer USchemas, infer UMeta> ? Procedure<MergedInitialContext<TInitialContext, UInitialContext, TCurrentContext>, UCurrentContext, USchemas, UMeta> : {
|
|
308
|
+
[K in keyof T]: T[K] extends Lazyable<AnyRouter> ? EnhancedRouter<T[K], TInitialContext, TCurrentContext> : never;
|
|
309
|
+
};
|
|
310
|
+
interface EnhanceRouterOptions extends EnhanceRouteOptions {
|
|
311
|
+
middlewares: readonly AnyMiddleware[];
|
|
312
|
+
dedupeLeadingMiddlewares: boolean;
|
|
313
|
+
}
|
|
314
|
+
declare function enhanceRouter<T extends Lazyable<AnyRouter>, TInitialContext extends Context, TCurrentContext extends Context>(router: T, options: EnhanceRouterOptions): EnhancedRouter<T, TInitialContext, TCurrentContext>;
|
|
315
|
+
interface TraverseContractProceduresOptions {
|
|
316
|
+
router: ContractRouter | AnyRouter;
|
|
317
|
+
path: readonly string[];
|
|
318
|
+
}
|
|
319
|
+
interface TraverseContractProcedureCallbackOptions {
|
|
320
|
+
contract: Contract;
|
|
321
|
+
path: readonly string[];
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* @deprecated Use `TraverseContractProcedureCallbackOptions` instead.
|
|
325
|
+
*/
|
|
326
|
+
type ContractProcedureCallbackOptions = TraverseContractProcedureCallbackOptions;
|
|
327
|
+
interface LazyTraverseContractProceduresOptions {
|
|
328
|
+
router: Lazy<AnyRouter>;
|
|
329
|
+
path: readonly string[];
|
|
330
|
+
}
|
|
331
|
+
declare function traverseContractProcedures(options: TraverseContractProceduresOptions, callback: (options: TraverseContractProcedureCallbackOptions) => void, lazyOptions?: LazyTraverseContractProceduresOptions[]): LazyTraverseContractProceduresOptions[];
|
|
332
|
+
declare function resolveContractProcedures(options: TraverseContractProceduresOptions, callback: (options: TraverseContractProcedureCallbackOptions) => void): Promise<void>;
|
|
333
|
+
type UnlaziedRouter<T extends AnyRouter> = T extends AnyProcedure ? T : {
|
|
334
|
+
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? UnlaziedRouter<U> : never;
|
|
335
|
+
};
|
|
336
|
+
declare function unlazyRouter<T extends AnyRouter>(router: T): Promise<UnlaziedRouter<T>>;
|
|
337
|
+
|
|
338
|
+
declare const LAZY_SYMBOL: unique symbol;
|
|
339
|
+
interface LazyMeta {
|
|
340
|
+
prefix?: HTTPPath;
|
|
341
|
+
}
|
|
342
|
+
interface Lazy<T> {
|
|
343
|
+
[LAZY_SYMBOL]: {
|
|
344
|
+
loader: () => Promise<{
|
|
345
|
+
default: T;
|
|
346
|
+
}>;
|
|
347
|
+
meta: LazyMeta;
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
type Lazyable<T> = T | Lazy<T>;
|
|
351
|
+
/**
|
|
352
|
+
* @internal
|
|
353
|
+
*/
|
|
354
|
+
declare function lazyInternal<T>(loader: () => Promise<{
|
|
355
|
+
default: T;
|
|
356
|
+
}>, meta?: LazyMeta): Lazy<T>;
|
|
357
|
+
/**
|
|
358
|
+
* Creates a lazy-loaded item.
|
|
359
|
+
*
|
|
360
|
+
* @warning The `prefix` in `meta` only holds metadata and does not apply the prefix to the lazy router, use `os.prefix(...).lazyRoute(...)` instead.
|
|
361
|
+
*/
|
|
362
|
+
declare function lazy<T extends Router<any>>(prefix: HTTPPath, loader: () => Promise<{
|
|
363
|
+
default: T;
|
|
364
|
+
}>): EnhancedRouter<Lazy<T>, {}, {}>;
|
|
365
|
+
declare function isLazy(item: unknown): item is Lazy<any>;
|
|
366
|
+
declare function getLazyMeta(lazied: Lazy<any>): LazyMeta;
|
|
367
|
+
declare function unlazy<T extends Lazyable<any>>(lazied: T): Promise<{
|
|
368
|
+
default: T extends Lazy<infer U> ? U : T;
|
|
369
|
+
}>;
|
|
370
|
+
|
|
371
|
+
export { lazyInternal as F, lazy as G, isLazy as H, getLazyMeta as J, unlazy as K, mergeMeta as N, Procedure as P, middlewareOutputFn as Y, isProcedure as a1, getRouter as a7, createAccessibleLazyRouter as a9, enhanceRouter as aa, traverseContractProcedures as af, resolveContractProcedures as ag, unlazyRouter as ai, initialSchemas as ak, Contract as b, mergeCurrentContext as y, LAZY_SYMBOL as z };
|
|
372
|
+
export type { AnyContractDef as $, AnyShape as A, BuildContextWithAuth as B, Context as C, LazyMeta as D, EnhanceRouterOptions as E, InferProcedureClientInputs as I, Lazyable as L, Meta as M, MiddlewareResult as O, MiddlewareNextFn as Q, Route as R, Schemas as S, MiddlewareOutputFn as T, UnionToIntersection as U, ValidatedAuthContext as V, WrapShape as W, MiddlewareOptions as X, DefaultProcedureHandlerOptions as Z, ProcedureHandlerOptions as _, InferSchemaOutput as a, ProcedureDef as a0, ContractRouter as a2, InferRouterInitialContexts as a3, InferRouterCurrentContexts as a4, InferRouterInputs as a5, InferRouterOutputs as a6, AccessibleLazyRouter as a8, TraverseContractProceduresOptions as ab, TraverseContractProcedureCallbackOptions as ac, ContractProcedureCallbackOptions as ad, LazyTraverseContractProceduresOptions as ae, UnlaziedRouter as ah, TypeRest as aj, MergedSchemas as c, AnySchema as d, Middleware as e, MergedInitialContext as f, MergedCurrentContext as g, AuthType as h, AuthConfig as i, ProcedureHandler as j, InferHandlerInputs as k, InferSchemaInput as l, Router as m, EnhancedRouter as n, MapInputMiddleware as o, ContractDef as p, InitialSchemas as q, SchemaIssue as r, Schema as s, AnyMiddleware as t, Lazy as u, AnyProcedure as v, AnyRouter as w, InferRouterInitialContext as x };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { parse, serialize } from 'cookie';
|
|
2
|
+
|
|
3
|
+
function setCookie(headers, name, value, options = {}) {
|
|
4
|
+
if (headers === void 0) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
const cookieString = serialize(name, value, {
|
|
8
|
+
path: "/",
|
|
9
|
+
...options
|
|
10
|
+
});
|
|
11
|
+
headers.append("Set-Cookie", cookieString);
|
|
12
|
+
}
|
|
13
|
+
function getCookie(headers, name, options = {}) {
|
|
14
|
+
if (headers === void 0) {
|
|
15
|
+
return void 0;
|
|
16
|
+
}
|
|
17
|
+
const cookieHeader = headers.get("cookie");
|
|
18
|
+
if (cookieHeader === null) {
|
|
19
|
+
return void 0;
|
|
20
|
+
}
|
|
21
|
+
return parse(cookieHeader, options)[name];
|
|
22
|
+
}
|
|
23
|
+
function deleteCookie(headers, name, options = {}) {
|
|
24
|
+
return setCookie(headers, name, "", {
|
|
25
|
+
...options,
|
|
26
|
+
maxAge: 0
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { deleteCookie as d, getCookie as g, setCookie as s };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { HTTPPath, StandardResponse, StandardLazyRequest } from '@temporary-name/shared';
|
|
2
|
+
import { C as Context, m as Router } from './server.Bj_UpI5O.mjs';
|
|
3
|
+
|
|
4
|
+
interface StandardHandleOptions<T extends Context> {
|
|
5
|
+
prefix?: HTTPPath;
|
|
6
|
+
context: T;
|
|
7
|
+
}
|
|
8
|
+
type StandardHandleResult = {
|
|
9
|
+
matched: true;
|
|
10
|
+
response: StandardResponse;
|
|
11
|
+
} | {
|
|
12
|
+
matched: false;
|
|
13
|
+
response: undefined;
|
|
14
|
+
};
|
|
15
|
+
interface StandardHandlerOptions<TContext extends Context> {
|
|
16
|
+
}
|
|
17
|
+
declare class StandardHandler<T extends Context> {
|
|
18
|
+
private readonly matcher;
|
|
19
|
+
constructor(router: Router<T>, _options: NoInfer<StandardHandlerOptions<T>>);
|
|
20
|
+
handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
|
24
|
+
context?: T;
|
|
25
|
+
} : {
|
|
26
|
+
context: T;
|
|
27
|
+
});
|
|
28
|
+
declare function resolveFriendlyStandardHandleOptions<T extends Context>(options: FriendlyStandardHandleOptions<T>): StandardHandleOptions<T>;
|
|
29
|
+
/**
|
|
30
|
+
* {@link https://github.com/unjs/rou3}
|
|
31
|
+
*
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
declare function toRou3Pattern(path: HTTPPath): string;
|
|
35
|
+
/**
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
declare function decodeParams(params: Record<string, string>): Record<string, string>;
|
|
39
|
+
|
|
40
|
+
export { StandardHandler as c, decodeParams as d, resolveFriendlyStandardHandleOptions as r, toRou3Pattern as t };
|
|
41
|
+
export type { FriendlyStandardHandleOptions as F, StandardHandleOptions as S, StandardHandleResult as a, StandardHandlerOptions as b };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { isObject } from '@temporary-name/shared';
|
|
2
|
+
|
|
3
|
+
function jsonSerialize(data, hasBlobRef = { value: false }) {
|
|
4
|
+
if (data instanceof Blob) {
|
|
5
|
+
hasBlobRef.value = true;
|
|
6
|
+
return [data, hasBlobRef.value];
|
|
7
|
+
}
|
|
8
|
+
if (data instanceof Set) {
|
|
9
|
+
return jsonSerialize(Array.from(data), hasBlobRef);
|
|
10
|
+
}
|
|
11
|
+
if (data instanceof Map) {
|
|
12
|
+
return jsonSerialize(Array.from(data.entries()), hasBlobRef);
|
|
13
|
+
}
|
|
14
|
+
if (Array.isArray(data)) {
|
|
15
|
+
const json = data.map((v) => v === void 0 ? null : jsonSerialize(v, hasBlobRef)[0]);
|
|
16
|
+
return [json, hasBlobRef.value];
|
|
17
|
+
}
|
|
18
|
+
if (isObject(data)) {
|
|
19
|
+
const json = {};
|
|
20
|
+
for (const k in data) {
|
|
21
|
+
if (k === "toJSON" && typeof data[k] === "function") {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
json[k] = jsonSerialize(data[k], hasBlobRef)[0];
|
|
25
|
+
}
|
|
26
|
+
return [json, hasBlobRef.value];
|
|
27
|
+
}
|
|
28
|
+
if (typeof data === "bigint" || data instanceof RegExp || data instanceof URL) {
|
|
29
|
+
return [data.toString(), hasBlobRef.value];
|
|
30
|
+
}
|
|
31
|
+
if (data instanceof Date) {
|
|
32
|
+
return [Number.isNaN(data.getTime()) ? null : data.toISOString(), hasBlobRef.value];
|
|
33
|
+
}
|
|
34
|
+
if (Number.isNaN(data)) {
|
|
35
|
+
return [null, hasBlobRef.value];
|
|
36
|
+
}
|
|
37
|
+
return [data, hasBlobRef.value];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { jsonSerialize as j };
|