@forklaunch/core 0.15.12 → 0.16.0

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.
@@ -1,20 +1,23 @@
1
1
  import { ParsedQs } from 'qs';
2
2
  export { ParsedQs } from 'qs';
3
- import { UnionToIntersection, TypeSafeFunction, StringWithoutSlash, Prettify, MakePropertyOptionalIfChildrenOptional, SanitizePathSlashes, PrettyCamelCase, EmptyObject } from '@forklaunch/common';
4
- import { AnySchemaValidator, UnboxedObjectSchema, IdiomaticSchema, Schema } from '@forklaunch/validator';
3
+ import { Prettify, SanitizePathSlashes, PrettyCamelCase, TypeSafeFunction, UnionToIntersection, EmptyObject } from '@forklaunch/common';
4
+ import { AnySchemaValidator } from '@forklaunch/validator';
5
5
  import { ServerOptions, IncomingMessage, ServerResponse } from 'node:http';
6
- import { Counter, Gauge, Histogram, UpDownCounter, ObservableCounter, ObservableGauge, ObservableUpDownCounter, Span } from '@opentelemetry/api';
7
- import pino, { LevelWithSilentOrString, LevelWithSilent } from 'pino';
8
- export { LevelWithSilent, LevelWithSilentOrString, Logger } from 'pino';
9
- import { JWTPayload, JWK } from 'jose';
10
- import { Readable } from 'stream';
6
+ import { M as Method, P as PathParamHttpContractDetails, H as HttpContractDetails, E as ExpressLikeRouterOptions, a as SessionObject, b as ParamsObject, R as ResponsesObject, B as Body, Q as QueryObject, c as HeadersObject, V as VersionSchema, d as SchemaAuthMethods, C as ContractDetails, e as ExpressLikeSchemaHandler, f as ResolvedSessionObject, g as PathMatch, L as LiveTypeFunction, h as LiveSdkFunction, A as AuthMethodsBase, O as OpenTelemetryCollector, i as MetricsDefinition, j as ExpressLikeApplicationOptions, k as ParamsDictionary, l as VersionedRequests, m as AuthMethods, D as DecodeResource, n as BasicAuthMethods, F as ForklaunchRequest, o as MiddlewareContractDetails, p as ExpressLikeSchemaAuthMapper, q as ForklaunchResponse, r as ForklaunchResHeaders, s as ForklaunchStatusResponse, t as ForklaunchSendableData, T as TelemetryOptions, u as LoggerMeta, v as LogFn } from '../apiDefinition.types-BYizofKE.mjs';
7
+ export { ac as BodyObject, ax as DocsConfiguration, a9 as ErrorContainer, a6 as ExpressLikeAuthMapper, ay as ExpressLikeGlobalAuthOptions, U as ExpressLikeHandler, az as ExpressLikeSchemaGlobalAuthOptions, _ as ExtractBody, X as ExtractContentType, Y as ExtractResponseBody, at as ExtractedParamsObject, ai as FileBody, z as ForklaunchBaseRequest, G as ForklaunchNextFunction, a8 as ForklaunchResErrors, ar as HmacMethods, av as HttpMethod, ag as JsonBody, aq as JwtAuthMethods, a7 as LiveTypeFunctionRequestInit, W as MapParamsSchema, $ as MapReqBodySchema, a1 as MapReqHeadersSchema, a0 as MapReqQuerySchema, Z as MapResBodyMapSchema, a2 as MapResHeadersSchema, as as MapSchema, a5 as MapSessionSchema, a3 as MapVersionedReqsSchema, a4 as MapVersionedRespsSchema, aA as MetricType, aj as MultipartForm, ab as NumberOnlyObject, au as PathParamMethod, ad as RawTypedResponseBody, y as RequestContext, J as ResolvedForklaunchAuthRequest, I as ResolvedForklaunchRequest, N as ResolvedForklaunchResponse, af as ResponseBody, aw as ResponseCompiledSchema, aa as ResponseShape, al as ServerSentEventBody, S as StringOnlyObject, ah as TextBody, ap as TypedBody, ao as TypedRequestBody, ae as TypedResponseBody, am as UnknownBody, an as UnknownResponseBody, ak as UrlEncodedForm, K as VersionedResponses, w as httpRequestsTotalCounter, x as httpServerDurationHistogram } from '../apiDefinition.types-BYizofKE.mjs';
8
+ import { JWK, JWTPayload } from 'jose';
11
9
  import { FastMCP } from '@forklaunch/fastmcp-fork';
12
- import { CorsOptions } from 'cors';
13
- import { ApiReferenceConfiguration } from '@scalar/express-api-reference';
14
10
  import { ZodSchemaValidator } from '@forklaunch/validator/zod';
11
+ import http from 'http';
15
12
  import { OpenAPIObject } from 'openapi3-ts/oas31';
13
+ import pino, { LevelWithSilentOrString, LevelWithSilent } from 'pino';
14
+ export { LevelWithSilent, LevelWithSilentOrString, Logger } from 'pino';
16
15
  import { AnyValueMap } from '@opentelemetry/api-logs';
17
16
  export { ATTR_HTTP_REQUEST_METHOD, ATTR_HTTP_RESPONSE_STATUS_CODE, ATTR_HTTP_ROUTE, ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions';
17
+ import '@opentelemetry/api';
18
+ import 'stream';
19
+ import 'cors';
20
+ import '@scalar/express-api-reference';
18
21
 
19
22
  interface PathBasedHandler<RouterHandler> {
20
23
  (path: string, ...handlers: RouterHandler[]): unknown;
@@ -40,1050 +43,6 @@ interface ExpressLikeRouter<RouterHandler, Router> extends ServerOptions<typeof
40
43
  trace: PathBasedHandler<RouterHandler>;
41
44
  }
42
45
 
43
- type MetricType<T extends string> = T extends 'counter' ? Counter : T extends 'gauge' ? Gauge : T extends 'histogram' ? Histogram : T extends 'upDownCounter' ? UpDownCounter : T extends 'observableCounter' ? ObservableCounter : T extends 'observableGauge' ? ObservableGauge : T extends 'observableUpDownCounter' ? ObservableUpDownCounter : undefined;
44
- type MetricsDefinition = Record<string, 'counter' | 'gauge' | 'histogram' | 'upDownCounter' | 'observableCounter' | 'observableGauge' | 'observableUpDownCounter'>;
45
- type LoggerMeta = Record<string, unknown> & {
46
- _meta: true;
47
- };
48
- interface LogFn {
49
- <T extends object>(obj: T | LoggerMeta, msg?: string | LoggerMeta, ...args: unknown[]): void;
50
- (obj: unknown | LoggerMeta, msg?: string | LoggerMeta, ...args: unknown[]): void;
51
- (msg: string | LoggerMeta, ...args: unknown[]): void;
52
- }
53
- interface TelemetryOptions {
54
- enabled: boolean | {
55
- metrics?: boolean;
56
- tracing?: boolean;
57
- logging?: boolean;
58
- };
59
- level: LevelWithSilentOrString;
60
- }
61
-
62
- declare class OpenTelemetryCollector<AppliedMetricsDefinition extends MetricsDefinition> {
63
- #private;
64
- constructor(serviceName: string, level?: LevelWithSilentOrString, metricDefinitions?: AppliedMetricsDefinition);
65
- log(level: LevelWithSilent, ...args: (string | unknown | LoggerMeta)[]): void;
66
- info: LogFn;
67
- error: LogFn;
68
- warn: LogFn;
69
- debug: LogFn;
70
- trace: LogFn;
71
- getMetric<T extends keyof AppliedMetricsDefinition>(metricId: T): MetricType<AppliedMetricsDefinition[T]>;
72
- }
73
- declare const httpRequestsTotalCounter: Counter<{
74
- "service.name": string;
75
- "api.name": string;
76
- "http.request.method": string;
77
- "http.route": string;
78
- "http.response.status_code": number;
79
- }>;
80
- declare const httpServerDurationHistogram: Histogram<{
81
- "service.name": string;
82
- "api.name": string;
83
- "http.request.method": string;
84
- "http.route": string;
85
- "http.response.status_code": number;
86
- }>;
87
-
88
- /**
89
- * Dictionary type for URL parameters.
90
- */
91
- type ParamsDictionary = {
92
- [key: string]: string;
93
- };
94
- /**
95
- * Type representing an object with only string keys.
96
- *
97
- * @template SV - A type that extends AnySchemaValidator.
98
- */
99
- type StringOnlyObject<SV extends AnySchemaValidator> = Omit<UnboxedObjectSchema<SV>, number | symbol>;
100
- /**
101
- * Type representing an object with only number keys.
102
- *
103
- * @template SV - A type that extends AnySchemaValidator.
104
- */
105
- type NumberOnlyObject<SV extends AnySchemaValidator> = Omit<UnboxedObjectSchema<SV>, string | symbol>;
106
- /**
107
- * Type representing the body object in a request.
108
- *
109
- * @template SV - A type that extends AnySchemaValidator.
110
- */
111
- type BodyObject<SV extends AnySchemaValidator> = StringOnlyObject<SV>;
112
- /**
113
- * Type representing the parameters object in a request.
114
- *
115
- * @template SV - A type that extends AnySchemaValidator.
116
- */
117
- type ParamsObject<SV extends AnySchemaValidator> = StringOnlyObject<SV>;
118
- /**
119
- * Type representing the query object in a request.
120
- *
121
- * @template SV - A type that extends AnySchemaValidator.
122
- */
123
- type QueryObject<SV extends AnySchemaValidator> = StringOnlyObject<SV>;
124
- /**
125
- * Type representing the headers object in a request.
126
- *
127
- * @template SV - A type that extends AnySchemaValidator.
128
- */
129
- type HeadersObject<SV extends AnySchemaValidator> = StringOnlyObject<SV>;
130
- type RawTypedResponseBody<SV extends AnySchemaValidator> = TextBody<SV> | JsonBody<SV> | FileBody<SV> | ServerSentEventBody<SV> | UnknownResponseBody<SV>;
131
- type ExclusiveResponseBodyBase<SV extends AnySchemaValidator> = {
132
- [K in keyof UnionToIntersection<RawTypedResponseBody<SV>>]?: undefined;
133
- };
134
- type ExclusiveSchemaCatchall<SV extends AnySchemaValidator> = {
135
- [K in keyof SV['_SchemaCatchall'] as string extends K ? never : number extends K ? never : symbol extends K ? never : K]?: undefined;
136
- };
137
- type TypedResponseBody<SV extends AnySchemaValidator> = {
138
- [K in keyof (ExclusiveSchemaCatchall<SV> & ExclusiveResponseBodyBase<SV>)]?: K extends keyof TextBody<SV> ? TextBody<SV>[K] : undefined;
139
- } | {
140
- [K in keyof (ExclusiveSchemaCatchall<SV> & ExclusiveResponseBodyBase<SV>)]?: K extends keyof JsonBody<SV> ? JsonBody<SV>[K] : undefined;
141
- } | {
142
- [K in keyof (ExclusiveSchemaCatchall<SV> & ExclusiveResponseBodyBase<SV>)]?: K extends keyof FileBody<SV> ? FileBody<SV>[K] : undefined;
143
- } | {
144
- [K in keyof (ExclusiveSchemaCatchall<SV> & ExclusiveResponseBodyBase<SV>)]?: K extends keyof ServerSentEventBody<SV> ? ServerSentEventBody<SV>[K] : undefined;
145
- } | {
146
- [K in keyof (ExclusiveSchemaCatchall<SV> & ExclusiveResponseBodyBase<SV>)]?: K extends keyof UnknownResponseBody<SV> ? UnknownResponseBody<SV>[K] : undefined;
147
- };
148
- type ResponseBody<SV extends AnySchemaValidator> = TypedResponseBody<SV> | (ExclusiveResponseBodyBase<SV> & SV['_ValidSchemaObject']) | (ExclusiveResponseBodyBase<SV> & UnboxedObjectSchema<SV>) | (ExclusiveResponseBodyBase<SV> & SV['string']) | (ExclusiveResponseBodyBase<SV> & SV['number']) | (ExclusiveResponseBodyBase<SV> & SV['boolean']) | (ExclusiveResponseBodyBase<SV> & SV['date']) | (ExclusiveResponseBodyBase<SV> & SV['array']) | (ExclusiveResponseBodyBase<SV> & SV['file']);
149
- /**
150
- * Type representing the responses object in a request.
151
- *
152
- * @template SV - A type that extends AnySchemaValidator.
153
- */
154
- type ResponsesObject<SV extends AnySchemaValidator> = {
155
- [K: number]: ResponseBody<SV>;
156
- };
157
- type JsonBody<SV extends AnySchemaValidator> = {
158
- contentType?: 'application/json' | string;
159
- json: BodyObject<SV> | SV['_ValidSchemaObject'] | SV['_SchemaCatchall'];
160
- };
161
- /**
162
- * Type representing the body in a request.
163
- *
164
- * @template SV - A type that extends AnySchemaValidator.
165
- */
166
- type TextBody<SV extends AnySchemaValidator> = {
167
- contentType?: 'application/xml' | 'text/plain' | 'text/html' | 'text/css' | 'text/javascript' | 'text/csv' | 'text/markdown' | 'text/xml' | 'text/rtf' | 'text/x-yaml' | 'text/yaml' | string;
168
- text: SV['string'];
169
- };
170
- type FileBody<SV extends AnySchemaValidator> = {
171
- contentType?: 'application/octet-stream' | 'application/pdf' | 'application/vnd.ms-excel' | 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' | 'application/msword' | 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' | 'application/zip' | 'image/jpeg' | 'image/png' | 'image/gif' | 'audio/mpeg' | 'audio/wav' | 'video/mp4' | string;
172
- file: SV['file'];
173
- };
174
- /**
175
- * Type representing the body in a request.
176
- *
177
- * @template SV - A type that extends AnySchemaValidator.
178
- */
179
- type MultipartForm<SV extends AnySchemaValidator> = {
180
- contentType?: 'multipart/form-data' | 'multipart/mixed' | 'multipart/alternative' | 'multipart/related' | 'multipart/signed' | 'multipart/encrypted' | string;
181
- multipartForm: BodyObject<SV>;
182
- };
183
- /**
184
- * Type representing the body in a request.
185
- *
186
- * @template SV - A type that extends AnySchemaValidator.
187
- */
188
- type UrlEncodedForm<SV extends AnySchemaValidator> = {
189
- contentType?: 'application/x-www-form-urlencoded' | 'application/x-url-encoded' | 'application/x-www-url-encoded' | 'application/x-urlencode' | string;
190
- urlEncodedForm: BodyObject<SV>;
191
- };
192
- type ServerSentEventBody<SV extends AnySchemaValidator> = {
193
- contentType?: 'text/event-stream' | string;
194
- event: {
195
- id: SV['string'];
196
- data: SV['string'] | BodyObject<SV>;
197
- };
198
- };
199
- type UnknownBody<SV extends AnySchemaValidator> = {
200
- contentType?: string;
201
- schema: BodyObject<SV> | SV['_ValidSchemaObject'] | SV['_SchemaCatchall'];
202
- };
203
- type UnknownResponseBody<SV extends AnySchemaValidator> = {
204
- contentType?: string;
205
- schema: BodyObject<SV> | SV['_ValidSchemaObject'] | SV['_SchemaCatchall'];
206
- };
207
- type ExclusiveRequestBodyBase<SV extends AnySchemaValidator> = {
208
- [K in keyof UnionToIntersection<TypedBody<SV>>]?: undefined;
209
- };
210
- type TypedRequestBody<SV extends AnySchemaValidator> = {
211
- [K in keyof (ExclusiveSchemaCatchall<SV> & ExclusiveRequestBodyBase<SV>)]?: K extends keyof TextBody<SV> ? TextBody<SV>[K] : undefined;
212
- } | {
213
- [K in keyof (ExclusiveSchemaCatchall<SV> & ExclusiveRequestBodyBase<SV>)]?: K extends keyof JsonBody<SV> ? JsonBody<SV>[K] : undefined;
214
- } | {
215
- [K in keyof (ExclusiveSchemaCatchall<SV> & ExclusiveRequestBodyBase<SV>)]?: K extends keyof FileBody<SV> ? FileBody<SV>[K] : undefined;
216
- } | {
217
- [K in keyof (ExclusiveSchemaCatchall<SV> & ExclusiveRequestBodyBase<SV>)]?: K extends keyof MultipartForm<SV> ? MultipartForm<SV>[K] : undefined;
218
- } | {
219
- [K in keyof (ExclusiveSchemaCatchall<SV> & ExclusiveRequestBodyBase<SV>)]?: K extends keyof UrlEncodedForm<SV> ? UrlEncodedForm<SV>[K] : undefined;
220
- } | {
221
- [K in keyof (ExclusiveSchemaCatchall<SV> & ExclusiveRequestBodyBase<SV>)]?: K extends keyof UnknownBody<SV> ? UnknownBody<SV>[K] : undefined;
222
- };
223
- type TypedBody<SV extends AnySchemaValidator> = JsonBody<SV> | TextBody<SV> | FileBody<SV> | MultipartForm<SV> | UrlEncodedForm<SV> | UnknownBody<SV>;
224
- type Body<SV extends AnySchemaValidator> = TypedRequestBody<SV> | (ExclusiveRequestBodyBase<SV> & SV['_ValidSchemaObject']) | (ExclusiveRequestBodyBase<SV> & UnboxedObjectSchema<SV>) | (ExclusiveRequestBodyBase<SV> & SV['string']) | (ExclusiveRequestBodyBase<SV> & SV['number']) | (ExclusiveRequestBodyBase<SV> & SV['boolean']) | (ExclusiveRequestBodyBase<SV> & SV['date']) | (ExclusiveRequestBodyBase<SV> & SV['array']) | (ExclusiveRequestBodyBase<SV> & SV['file']) | (ExclusiveRequestBodyBase<SV> & SV['any']) | (ExclusiveRequestBodyBase<SV> & SV['unknown']) | (ExclusiveRequestBodyBase<SV> & SV['binary']) | (ExclusiveRequestBodyBase<SV> & (SV['type'] extends TypeSafeFunction ? ReturnType<SV['type']> : never));
225
- type SessionObject<SV extends AnySchemaValidator> = StringOnlyObject<SV>;
226
- type BasicAuthMethods = {
227
- readonly basic: {
228
- readonly login: (username: string, password: string) => boolean;
229
- };
230
- readonly jwt?: never;
231
- readonly hmac?: never;
232
- };
233
- type JwtAuthMethods = {
234
- jwt: {
235
- readonly jwksPublicKey: JWK;
236
- } | {
237
- readonly jwksPublicKeyUrl: string;
238
- } | {
239
- readonly signatureKey: string;
240
- };
241
- readonly basic?: never;
242
- readonly hmac?: never;
243
- };
244
- type HmacMethods = {
245
- readonly hmac: {
246
- readonly secretKeys: Record<string, string>;
247
- };
248
- readonly sessionSchema?: never;
249
- readonly basic?: never;
250
- readonly jwt?: never;
251
- };
252
- type TokenOptions = {
253
- readonly tokenPrefix?: string;
254
- readonly headerName?: string;
255
- };
256
- type DecodeResource = (token: string) => JWTPayload | Promise<JWTPayload>;
257
- type AuthMethodsBase = TokenOptions & (HmacMethods | ({
258
- readonly decodeResource?: DecodeResource;
259
- } & (PermissionSet | RoleSet) & (BasicAuthMethods | JwtAuthMethods)));
260
- type PermissionSet = {
261
- readonly allowedPermissions: Set<string>;
262
- } | {
263
- readonly forbiddenPermissions: Set<string>;
264
- };
265
- type RoleSet = {
266
- readonly allowedRoles: Set<string>;
267
- } | {
268
- readonly forbiddenRoles: Set<string>;
269
- };
270
- /**
271
- * Type representing the authentication methods.
272
- */
273
- type SchemaAuthMethods<SV extends AnySchemaValidator, ParamsSchema extends ParamsObject<SV>, ReqBody extends Body<SV>, QuerySchema extends QueryObject<SV>, ReqHeaders extends HeadersObject<SV>, VersionedApi extends VersionSchema<SV, Method>, BaseRequest> = AuthMethodsBase & {
274
- readonly sessionSchema?: SessionObject<SV>;
275
- readonly requiredScope?: string;
276
- readonly scopeHeirarchy?: string[];
277
- readonly surfaceScopes?: ExpressLikeSchemaAuthMapper<SV, ParamsSchema, ReqBody, QuerySchema, ReqHeaders, VersionedApi, SessionObject<SV>, BaseRequest>;
278
- } & ({
279
- readonly surfacePermissions?: ExpressLikeSchemaAuthMapper<SV, ParamsSchema, ReqBody, QuerySchema, ReqHeaders, VersionedApi, SessionObject<SV>, BaseRequest>;
280
- } | {
281
- readonly surfaceRoles?: ExpressLikeSchemaAuthMapper<SV, ParamsSchema, ReqBody, QuerySchema, ReqHeaders, VersionedApi, SessionObject<SV>, BaseRequest>;
282
- });
283
- type AuthMethods<SV extends AnySchemaValidator, P extends ParamsDictionary, ReqBody extends Record<string, unknown>, ReqQuery extends Record<string, unknown>, ReqHeaders extends Record<string, string>, VersionedReqs extends VersionedRequests, BaseRequest> = AuthMethodsBase & {
284
- readonly sessionSchema?: SessionObject<SV>;
285
- readonly requiredScope?: string;
286
- readonly scopeHeirarchy?: string[];
287
- readonly surfaceScopes?: ExpressLikeAuthMapper<SV, P, ReqBody, ReqQuery, ReqHeaders, VersionedReqs, SessionObject<SV>, BaseRequest>;
288
- } & (({
289
- readonly surfacePermissions?: ExpressLikeAuthMapper<SV, P, ReqBody, ReqQuery, ReqHeaders, VersionedReqs, SessionObject<SV>, BaseRequest>;
290
- } & PermissionSet) | ({
291
- readonly surfaceRoles?: ExpressLikeAuthMapper<SV, P, ReqBody, ReqQuery, ReqHeaders, VersionedReqs, SessionObject<SV>, BaseRequest>;
292
- } & RoleSet));
293
- /**
294
- * Type representing a mapped schema.
295
- *s ParamsDictionary,
296
- // ReqBody extends Record<string, unknown>,
297
- //
298
- * @template SV - A type that extends AnySchemaValidator.
299
- * @template T - A type that extends IdiomaticSchema or a valid schema object.
300
- */
301
- type MapSchema<SV extends AnySchemaValidator, T extends IdiomaticSchema<SV> | SV['_ValidSchemaObject']> = Schema<T, SV> extends infer U ? (T extends U ? unknown : U) : never;
302
- /**
303
- * Type representing the parameters in a request.
304
- */
305
- type ExtractParams<Path extends `/${string}`> = Path extends `${string}/:${infer Param}/${infer Rest}` ? Param | ExtractParams<`/${Rest}`> : Path extends `${string}/:${infer Param}` ? Param : never;
306
- /**
307
- * Type representing the parameters in a request.
308
- */
309
- type ExtractedParamsObject<Path extends `/${string}`> = Record<ExtractParams<Path>, unknown>;
310
- /**
311
- * Represents the path parameter methods.
312
- */
313
- type PathParamMethod = 'get' | 'delete' | 'options' | 'head' | 'trace';
314
- /**
315
- * Represents the body parameter methods.
316
- */
317
- type HttpMethod = 'post' | 'patch' | 'put';
318
- /**
319
- * Represents all supported typed methods.
320
- */
321
- type Method = PathParamMethod | HttpMethod | 'middleware';
322
- /**
323
- * Interface representing a compiled schema for a response.
324
- */
325
- type ResponseCompiledSchema = {
326
- headers?: unknown;
327
- responses: Record<number, unknown>;
328
- };
329
- type BasePathParamHttpContractDetailsIO<SV extends AnySchemaValidator, BodySchema extends Body<SV> | undefined = Body<SV>, ResponseSchemas extends ResponsesObject<SV> = ResponsesObject<SV>, QuerySchema extends QueryObject<SV> | undefined = QueryObject<SV>, ReqHeaders extends HeadersObject<SV> | undefined = HeadersObject<SV>, ResHeaders extends HeadersObject<SV> | undefined = HeadersObject<SV>> = {
330
- /** Optional body for the contract */
331
- readonly body?: BodySchema;
332
- /** Response schemas for the contract */
333
- readonly responses: ResponseSchemas;
334
- /** Optional request headers for the contract */
335
- readonly requestHeaders?: ReqHeaders;
336
- /** Optional response headers for the contract */
337
- readonly responseHeaders?: ResHeaders;
338
- /** Optional query schemas for the contract */
339
- readonly query?: QuerySchema;
340
- };
341
- type VersionedBasePathParamHttpContractDetailsIO<SV extends AnySchemaValidator, VersionedApi extends VersionSchema<SV, PathParamMethod>> = {
342
- readonly versions: VersionedApi;
343
- };
344
- type BasePathParamHttpContractDetails<SV extends AnySchemaValidator, Name extends string = string, Path extends `/${string}` = `/${string}`, ParamsSchema extends ParamsObject<SV> = ParamsObject<SV>> = {
345
- /** Name of the contract */
346
- readonly name: StringWithoutSlash<Name>;
347
- /** Summary of the contract */
348
- readonly summary: string;
349
- /** Options for the contract */
350
- readonly options?: {
351
- /** Optional request validation for the contract */
352
- readonly requestValidation?: 'error' | 'warning' | 'none';
353
- /** Optional response validation for the contract */
354
- readonly responseValidation?: 'error' | 'warning' | 'none';
355
- /** Optional MCP details for the contract */
356
- readonly mcp?: boolean;
357
- /** Optional OpenAPI details for the contract */
358
- readonly openapi?: boolean;
359
- };
360
- } & (string | number | symbol extends ExtractedParamsObject<Path> ? {
361
- /** Optional parameters for the contract */
362
- readonly params?: ParamsSchema;
363
- } : {
364
- /** Required parameters for the contract */
365
- readonly params: {
366
- [K in keyof ExtractedParamsObject<Path>]: ParamsSchema[K];
367
- };
368
- });
369
- /**
370
- * Interface representing HTTP contract details for path parameters.
371
- *
372
- * @template SV - A type that extends AnySchemaValidator.
373
- * @template ParamsSchema - A type for parameter schemas, defaulting to ParamsObject.
374
- * @template ResponseSchemas - A type for response schemas, defaulting to ResponsesObject.
375
- * @template QuerySchema - A type for query schemas, defaulting to QueryObject.
376
- */
377
- type PathParamHttpContractDetails<SV extends AnySchemaValidator, Name extends string = string, Path extends `/${string}` = `/${string}`, ParamsSchema extends ParamsObject<SV> = ParamsObject<SV>, ResponseSchemas extends ResponsesObject<SV> = ResponsesObject<SV>, BodySchema extends Body<SV> = Body<SV>, QuerySchema extends QueryObject<SV> = QueryObject<SV>, ReqHeaders extends HeadersObject<SV> = HeadersObject<SV>, ResHeaders extends HeadersObject<SV> = HeadersObject<SV>, VersionedApi extends VersionSchema<SV, Method> = VersionSchema<SV, PathParamMethod>, BaseRequest = unknown, Auth extends SchemaAuthMethods<SV, ParamsSchema, BodySchema, QuerySchema, ReqHeaders, VersionedApi, BaseRequest> = SchemaAuthMethods<SV, ParamsSchema, BodySchema, QuerySchema, ReqHeaders, VersionedApi, BaseRequest>> = BasePathParamHttpContractDetails<SV, Name, Path, ParamsSchema> & ((BasePathParamHttpContractDetailsIO<SV, never, ResponseSchemas, QuerySchema, ReqHeaders, ResHeaders> & {
378
- readonly versions?: never;
379
- }) | (VersionedBasePathParamHttpContractDetailsIO<SV, VersionedApi> & {
380
- readonly query?: never;
381
- readonly requestHeaders?: never;
382
- readonly responseHeaders?: never;
383
- readonly responses?: never;
384
- })) & {
385
- /** Optional authentication details for the contract */
386
- readonly auth?: Auth;
387
- };
388
- type VersionedHttpContractDetailsIO<SV extends AnySchemaValidator, VersionedApi extends VersionSchema<SV, HttpMethod>> = {
389
- readonly versions: VersionedApi;
390
- };
391
- /**
392
- * Interface representing HTTP contract details.
393
- *
394
- * @template SV - A type that extends AnySchemaValidator.
395
- * @template ParamsSchema - A type for parameter schemas, defaulting to ParamsObject.
396
- * @template ResponseSchemas - A type for response schemas, defaulting to ResponsesObject.
397
- * @template BodySchema - A type for the body schema, defaulting to Body.
398
- * @template QuerySchema - A type for query schemas, defaulting to QueryObject.
399
- */
400
- type HttpContractDetails<SV extends AnySchemaValidator, Name extends string = string, Path extends `/${string}` = `/${string}`, ParamsSchema extends ParamsObject<SV> = ParamsObject<SV>, ResponseSchemas extends ResponsesObject<SV> = ResponsesObject<SV>, BodySchema extends Body<SV> = Body<SV>, QuerySchema extends QueryObject<SV> = QueryObject<SV>, ReqHeaders extends HeadersObject<SV> = HeadersObject<SV>, ResHeaders extends HeadersObject<SV> = HeadersObject<SV>, VersionedApi extends VersionSchema<SV, Method> = VersionSchema<SV, HttpMethod>, BaseRequest = unknown, Auth extends SchemaAuthMethods<SV, ParamsSchema, BodySchema, QuerySchema, ReqHeaders, VersionedApi, BaseRequest> = SchemaAuthMethods<SV, ParamsSchema, BodySchema, QuerySchema, ReqHeaders, VersionedApi, BaseRequest>> = BasePathParamHttpContractDetails<SV, Name, Path, ParamsSchema> & ((BasePathParamHttpContractDetailsIO<SV, BodySchema, ResponseSchemas, QuerySchema, ReqHeaders, ResHeaders> & {
401
- readonly versions?: never;
402
- }) | (VersionedHttpContractDetailsIO<SV, VersionedApi> & {
403
- readonly query?: never;
404
- readonly requestHeaders?: never;
405
- readonly responseHeaders?: never;
406
- readonly body?: never;
407
- readonly responses?: never;
408
- })) & {
409
- readonly auth?: Auth;
410
- };
411
- /**
412
- * Interface representing HTTP contract details for middleware.
413
- *
414
- * @template SV - A type that extends AnySchemaValidator.
415
- * @template ParamsSchema - A type for parameter schemas, defaulting to ParamsObject.
416
- * @template ResponseSchemas - A type for response schemas, defaulting to ResponsesObject.
417
- * @template QuerySchema - A type for query schemas, defaulting to QueryObject.
418
- * @template ReqHeaders - A type for request headers, defaulting to HeadersObject.
419
- * @template ResHeaders - A type for response headers, defaulting to HeadersObject.
420
- */
421
- type MiddlewareContractDetails<SV extends AnySchemaValidator, Name extends string = string, Path extends `/${string}` = `/${string}`, ParamsSchema extends ParamsObject<SV> = ParamsObject<SV>, ResponseSchemas extends ResponsesObject<SV> = ResponsesObject<SV>, BodySchema extends Body<SV> = Body<SV>, QuerySchema extends QueryObject<SV> = QueryObject<SV>, ReqHeaders extends HeadersObject<SV> = HeadersObject<SV>, ResHeaders extends HeadersObject<SV> = HeadersObject<SV>, VersionedApi extends VersionSchema<SV, Method> = VersionSchema<SV, 'middleware'>, BaseRequest = unknown, Auth extends SchemaAuthMethods<SV, ParamsSchema, BodySchema, QuerySchema, ReqHeaders, VersionedApi, BaseRequest> = SchemaAuthMethods<SV, ParamsSchema, BodySchema, QuerySchema, ReqHeaders, VersionedApi, BaseRequest>> = Omit<Partial<HttpContractDetails<SV, Name, Path, ParamsSchema, ResponseSchemas, BodySchema, QuerySchema, ReqHeaders, ResHeaders, VersionedApi, BaseRequest, Auth>>, 'responses'>;
422
- type VersionSchema<SV extends AnySchemaValidator, ContractMethod extends Method> = Record<string, BasePathParamHttpContractDetailsIO<SV, ContractMethod extends PathParamMethod ? never : Body<SV>, ResponsesObject<SV>, QueryObject<SV>, HeadersObject<SV>, HeadersObject<SV>>>;
423
- /**
424
- * Utility for different Contract Detail types
425
- */
426
- type ContractDetails<SV extends AnySchemaValidator, Name extends string, ContractMethod extends Method, Path extends `/${string}`, ParamsSchema extends ParamsObject<SV>, ResponseSchemas extends ResponsesObject<SV>, BodySchema extends Body<SV>, QuerySchema extends QueryObject<SV>, ReqHeaders extends HeadersObject<SV>, ResHeaders extends HeadersObject<SV>, VersionedApi extends VersionSchema<SV, ContractMethod>, BaseRequest, Auth extends SchemaAuthMethods<SV, ParamsSchema, BodySchema, QuerySchema, ReqHeaders, VersionedApi, BaseRequest>> = ContractMethod extends PathParamMethod ? PathParamHttpContractDetails<SV, Name, Path, ParamsSchema, ResponseSchemas, BodySchema, QuerySchema, ReqHeaders, ResHeaders, VersionedApi, BaseRequest, Auth> : ContractMethod extends HttpMethod ? HttpContractDetails<SV, Name, Path, ParamsSchema, ResponseSchemas, BodySchema, QuerySchema, ReqHeaders, ResHeaders, VersionedApi, BaseRequest, Auth> : ContractMethod extends 'middleware' ? MiddlewareContractDetails<SV, Name, Path, ParamsSchema, ResponseSchemas, BodySchema, QuerySchema, ReqHeaders, ResHeaders, VersionedApi, BaseRequest, Auth> : never;
427
- /**
428
- * Resolves the session object type to use for authentication.
429
- *
430
- * If `AuthSession` is provided and extends `SessionObject<SV>`, it is used as the session type.
431
- * Otherwise, the `FallbackSession` type is used.
432
- *
433
- * @template SV - The schema validator type.
434
- * @template AuthSession - The session object type provided by the authentication method, or undefined.
435
- * @template FallbackSession - The fallback session object type to use if `AuthSession` is not provided.
436
- */
437
- type ResolvedSessionObject<SV extends AnySchemaValidator, AuthSession extends SessionObject<SV> | undefined, FallbackSession extends SessionObject<SV>> = AuthSession extends {
438
- readonly sessionSchema?: infer ResolvedSessionSchema | undefined;
439
- } | undefined ? ResolvedSessionSchema extends SessionObject<SV> ? ResolvedSessionSchema : FallbackSession : FallbackSession;
440
-
441
- type DocsConfiguration = ({
442
- type: 'scalar';
443
- } & Partial<Omit<ApiReferenceConfiguration, 'spec'>>) | {
444
- type: 'swagger';
445
- };
446
-
447
- /**
448
- * Options for global authentication in Express-like applications.
449
- *
450
- * @template SV - The schema validator type.
451
- * @template SessionSchema - The session schema type.
452
- *
453
- * Can be `false` to disable authentication, or an object specifying session schema and
454
- * functions to surface scopes, permissions, and roles from the JWT/session.
455
- */
456
- type ExpressLikeGlobalAuthOptions<SV extends AnySchemaValidator, SessionSchema extends Record<string, unknown>> = false | {
457
- /**
458
- * Optional session schema for the authentication context.
459
- */
460
- sessionSchema?: SessionSchema;
461
- /**
462
- * Optional array describing the scope hierarchy for authorization.
463
- */
464
- scopeHeirarchy?: string[];
465
- /**
466
- * Function to extract a set of scopes from the JWT payload and request.
467
- */
468
- surfaceScopes?: (payload: JWTPayload & SessionSchema, req?: ForklaunchRequest<SV, Record<string, string>, Record<string, unknown>, Record<string, unknown>, Record<string, unknown>, string, SessionSchema>) => Set<string> | Promise<Set<string>>;
469
- /**
470
- * Function to extract a set of permissions from the JWT payload and request.
471
- */
472
- surfacePermissions?: (payload: JWTPayload & SessionSchema, req?: ForklaunchRequest<SV, Record<string, string>, Record<string, unknown>, Record<string, unknown>, Record<string, unknown>, string, SessionSchema>) => Set<string> | Promise<Set<string>>;
473
- /**
474
- * Function to extract a set of roles from the JWT payload and request.
475
- */
476
- surfaceRoles?: (payload: JWTPayload & SessionSchema, req?: ForklaunchRequest<SV, Record<string, string>, Record<string, unknown>, Record<string, unknown>, Record<string, unknown>, string, SessionSchema>) => Set<string> | Promise<Set<string>>;
477
- };
478
- /**
479
- * Schema-aware version of ExpressLikeGlobalAuthOptions.
480
- *
481
- * @template SV - The schema validator type.
482
- * @template SessionSchema - The session object type.
483
- */
484
- type ExpressLikeSchemaGlobalAuthOptions<SV extends AnySchemaValidator, SessionSchema extends SessionObject<SV>> = ExpressLikeGlobalAuthOptions<SV, MapSessionSchema<SV, SessionSchema>>;
485
- /**
486
- * Options for configuring an Express-like router.
487
- *
488
- * @template SV - The schema validator type.
489
- * @template SessionSchema - The session object type.
490
- */
491
- type ExpressLikeRouterOptions<SV extends AnySchemaValidator, SessionSchema extends SessionObject<SV>> = {
492
- /**
493
- * Authentication options for the router.
494
- */
495
- auth?: ExpressLikeSchemaGlobalAuthOptions<SV, SessionSchema>;
496
- /**
497
- * Validation options for request and response.
498
- * Can be `false` to disable validation, or an object to configure request/response validation levels.
499
- */
500
- validation?: false | {
501
- /**
502
- * Request validation mode: 'none', 'warning', or 'error'.
503
- */
504
- request?: 'none' | 'warning' | 'error';
505
- /**
506
- * Response validation mode: 'none', 'warning', or 'error'.
507
- */
508
- response?: 'none' | 'warning' | 'error';
509
- };
510
- /**
511
- * OpenAPI documentation options.
512
- */
513
- openapi?: boolean;
514
- /**
515
- * MCP options.
516
- */
517
- mcp?: boolean;
518
- };
519
- /**
520
- * Options for configuring an Express-like application.
521
- *
522
- * @template SV - The schema validator type.
523
- * @template SessionSchema - The session object type.
524
- */
525
- type ExpressLikeApplicationOptions<SV extends AnySchemaValidator, SessionSchema extends SessionObject<SV>> = Omit<ExpressLikeRouterOptions<SV, SessionSchema>, 'openapi' | 'mcp'> & {
526
- /**
527
- * Documentation configuration.
528
- */
529
- docs?: DocsConfiguration;
530
- /**
531
- * Hosting/server options.
532
- */
533
- hosting?: {
534
- /**
535
- * SSL configuration or boolean to enable/disable SSL.
536
- */
537
- ssl?: {
538
- /**
539
- * SSL certificate as a string.
540
- */
541
- certFile: string;
542
- /**
543
- * SSL key as a string.
544
- */
545
- keyFile: string;
546
- /**
547
- * SSL CA as a string.
548
- */
549
- caFile: string;
550
- };
551
- /**
552
- * Number of worker processes to spawn.
553
- */
554
- workerCount?: number;
555
- /**
556
- * Routing strategy to use.
557
- */
558
- routingStrategy?: 'round-robin' | 'sticky' | 'random';
559
- };
560
- /**
561
- * FastMCP (management/control plane) options.
562
- * Can be `false` to disable, or an object to configure.
563
- */
564
- mcp?: false | {
565
- /**
566
- * Port for the MCP server.
567
- */
568
- port?: number;
569
- /**
570
- * Endpoint for the MCP server.
571
- */
572
- path?: `/${string}`;
573
- /**
574
- * Additional options for FastMCP.
575
- */
576
- options?: ConstructorParameters<typeof FastMCP>[0];
577
- /**
578
- * Additional tools to register with the MCP server.
579
- */
580
- additionalTools: (mcpServer: FastMCP) => void;
581
- /**
582
- * Content type mapping for the MCP server.
583
- */
584
- contentTypeMapping?: Record<string, string>;
585
- /**
586
- * Version of the MCP server.
587
- */
588
- version?: `${number}.${number}.${number}`;
589
- };
590
- /**
591
- * OpenAPI documentation options.
592
- * Can be `false` to disable, or an object to configure.
593
- */
594
- openapi?: false | {
595
- /**
596
- * Path to serve the OpenAPI docs (e.g., '/openapi').
597
- */
598
- path?: `/${string}`;
599
- /**
600
- * Title for the OpenAPI documentation.
601
- */
602
- title?: string;
603
- /**
604
- * Description for the OpenAPI documentation.
605
- */
606
- description?: string;
607
- /**
608
- * Contact information for the API.
609
- */
610
- contact?: {
611
- /**
612
- * Contact name.
613
- */
614
- name?: string;
615
- /**
616
- * Contact email.
617
- */
618
- email?: string;
619
- };
620
- /**
621
- * Whether to enable discrete versioning for OpenAPI docs.
622
- */
623
- discreteVersions?: boolean;
624
- };
625
- /**
626
- * CORS configuration options.
627
- */
628
- cors?: CorsOptions;
629
- };
630
-
631
- /**
632
- * Interface representing the context of a request.
633
- */
634
- interface RequestContext {
635
- /** Correlation ID for tracking requests */
636
- correlationId: string;
637
- /** Optional idempotency key for ensuring idempotent requests */
638
- idempotencyKey?: string;
639
- /** Active OpenTelemetry Span */
640
- span?: Span;
641
- }
642
- interface ForklaunchBaseRequest<P extends ParamsDictionary, ReqBody extends Record<string, unknown>, ReqQuery extends ParsedQs, ReqHeaders extends Record<string, string>> {
643
- /** Request parameters */
644
- params: P;
645
- /** Request headers */
646
- headers: ReqHeaders;
647
- /** Request body */
648
- body: ReqBody;
649
- /** Request query */
650
- query: ReqQuery;
651
- /** Method */
652
- method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'CONNECT' | 'TRACE';
653
- /** Request path */
654
- path: string;
655
- /** Original path */
656
- originalPath: string;
657
- /** OpenTelemetry Collector */
658
- openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>;
659
- }
660
- /**
661
- * Interface representing a Forklaunch request.
662
- *
663
- * @template SV - A type that extends AnySchemaValidator.
664
- * @template P - A type for request parameters, defaulting to ParamsDictionary.
665
- * @template ReqBody - A type for the request body, defaulting to unknown.
666
- * @template ReqQuery - A type for the request query, defaulting to ParsedQs.
667
- * @template Headers - A type for the request headers, defaulting to IncomingHttpHeaders.
668
- */
669
- interface ForklaunchRequest<SV extends AnySchemaValidator, P extends ParamsDictionary, ReqBody extends Record<string, unknown>, ReqQuery extends Record<string, unknown>, ReqHeaders extends Record<string, unknown>, Version extends string, SessionSchema extends Record<string, unknown>> {
670
- /** Context of the request */
671
- context: Prettify<RequestContext>;
672
- /** API Version of the request */
673
- version: Version;
674
- /** Request parameters */
675
- params: P;
676
- /** Request headers */
677
- headers: ReqHeaders;
678
- /** Request body */
679
- body: ReqBody;
680
- /** Request query */
681
- query: ReqQuery;
682
- /** Contract details for the request */
683
- contractDetails: PathParamHttpContractDetails<SV> | HttpContractDetails<SV>;
684
- /** Schema validator */
685
- schemaValidator: SV;
686
- /** Method */
687
- method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'CONNECT' | 'TRACE';
688
- /** Request path */
689
- path: string;
690
- /** Request schema, compiled */
691
- requestSchema: unknown | Record<string, unknown>;
692
- /** Original path */
693
- originalPath: string;
694
- /** OpenTelemetry Collector */
695
- openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>;
696
- /** Session */
697
- session: JWTPayload & SessionSchema;
698
- /** Parsed versions */
699
- _parsedVersions: string[] | number;
700
- /** Global options */
701
- _globalOptions: () => ExpressLikeRouterOptions<SV, SessionSchema> | undefined;
702
- }
703
- /**
704
- * Represents the types of data that can be sent in a response.
705
- */
706
- type ForklaunchSendableData = Record<string, unknown> | string | Buffer | ArrayBuffer | NodeJS.ReadableStream | null | undefined;
707
- /**
708
- * Interface representing a Forklaunch response status.
709
- * @template ResBody - A type for the response body.
710
- */
711
- interface ForklaunchStatusResponse<ResBody> {
712
- /**
713
- * Sends the response.
714
- * @param {ResBodyMap} [body] - The response body.
715
- * @param {boolean} [close_connection] - Whether to close the connection.
716
- * @returns {T} - The sent response.
717
- */
718
- send: {
719
- (body?: ResBody extends AsyncGenerator<unknown> ? never : ResBody extends Blob ? Blob | File | Buffer | ArrayBuffer | NodeJS.ReadableStream : ResBody | null, close_connection?: boolean): boolean;
720
- <U>(body?: ResBody extends AsyncGenerator<unknown> ? never : ResBody extends Blob ? Blob | File | Buffer | ArrayBuffer | NodeJS.ReadableStream : ResBody | null, close_connection?: boolean): U;
721
- };
722
- /**
723
- * Sends a JSON response.
724
- * @param {ResBodyMap} [body] - The response body.
725
- * @returns {boolean|T} - The JSON response.
726
- */
727
- json: {
728
- (body: ResBody extends string | AsyncGenerator<unknown> ? never : ResBody | null): boolean;
729
- <U>(body: ResBody extends string | AsyncGenerator<unknown> ? never : ResBody | null): U;
730
- };
731
- /**
732
- * Sends a JSONP response.
733
- * @param {ResBodyMap} [body] - The response body.
734
- * @returns {boolean|T} - The JSONP response.
735
- */
736
- jsonp: {
737
- (body: ResBody extends string | AsyncGenerator<unknown> ? never : ResBody | null): boolean;
738
- <U>(body: ResBody extends string | AsyncGenerator<unknown> ? never : ResBody | null): U;
739
- };
740
- /**
741
- * Sends a Server-Sent Event (SSE) response.
742
- * @param {ResBodyMap} [body] - The response body.
743
- * @param {number} interval - The interval between events.
744
- */
745
- sseEmitter: (generator: () => AsyncGenerator<ResBody extends AsyncGenerator<infer T> ? T : never, void, unknown>) => void;
746
- }
747
- type ToNumber<T extends string | number | symbol> = T extends number ? T : T extends `${infer N extends number}` ? N : never;
748
- /**
749
- * Interface representing a Forklaunch response.
750
- *
751
- * @template ResBodyMap - A type for the response body, defaulting to common status code responses.
752
- * @template StatusCode - A type for the status code, defaulting to number.
753
- */
754
- interface ForklaunchResponse<BaseResponse, ResBodyMap extends Record<number, unknown>, ResHeaders extends Record<string, unknown>, LocalsObj extends Record<string, unknown>, Version extends string> {
755
- /** Data of the response body */
756
- bodyData: unknown;
757
- /** Status code of the response */
758
- statusCode: number;
759
- /** Whether the response is finished */
760
- headersSent: boolean;
761
- /**
762
- * Gets the headers of the response.
763
- * @returns {Omit<ResHeaders, keyof ForklaunchResHeaders> & ForklaunchResHeaders} - The headers of the response.
764
- */
765
- getHeaders: () => Omit<ResHeaders, keyof ForklaunchResHeaders> & ForklaunchResHeaders;
766
- /**
767
- * Gets a header for the response.
768
- * @param {string} key - The header key.
769
- * @returns {string | string[] | undefined} The header value.
770
- */
771
- getHeader: (key: string) => string | string[] | undefined;
772
- /**
773
- * Sets a header for the response.
774
- * @param {string} key - The header key.
775
- * @param {string} value - The header value.
776
- */
777
- setHeader: {
778
- <K extends keyof (ResHeaders & ForklaunchResHeaders)>(key: K, value: K extends keyof ForklaunchResHeaders ? ForklaunchResHeaders[K] : ResHeaders[K]): void;
779
- <K extends keyof (ResHeaders & ForklaunchResHeaders)>(key: K, value: K extends keyof ForklaunchResHeaders ? ForklaunchResHeaders[K] : ResHeaders[K]): BaseResponse;
780
- };
781
- /**
782
- * Adds an event listener to the response.
783
- * @param {string} event - The event to listen for.
784
- * @param {Function} listener - The listener function.
785
- */
786
- on(event: 'close', listener: () => void): BaseResponse & this;
787
- on(event: 'drain', listener: () => void): BaseResponse & this;
788
- on(event: 'error', listener: (err: Error) => void): BaseResponse & this;
789
- on(event: 'finish', listener: () => void): BaseResponse & this;
790
- on(event: 'pipe', listener: (src: Readable) => void): BaseResponse & this;
791
- on(event: 'unpipe', listener: (src: Readable) => void): BaseResponse & this;
792
- on(event: string | symbol, listener: (...args: unknown[]) => void): BaseResponse & this;
793
- /**
794
- * Sets the status of the response.
795
- * @param {U} code - The status code.
796
- * @param {string} [message] - Optional message.
797
- * @returns {ForklaunchResponse<(ResBodyMap)[U], ResHeaders, U, LocalsObj>} - The response with the given status.
798
- */
799
- status: {
800
- <U extends ToNumber<keyof (ResBodyMap & ForklaunchResErrors)>>(code: U): Omit<BaseResponse, keyof ForklaunchStatusResponse<(Omit<ForklaunchResErrors, keyof ResBodyMap> & ResBodyMap)[U]>> & ForklaunchStatusResponse<(Omit<ForklaunchResErrors, keyof ResBodyMap> & ResBodyMap)[U]>;
801
- <U extends ToNumber<keyof (ResBodyMap & ForklaunchResErrors)>>(code: U, message?: string): Omit<BaseResponse, keyof ForklaunchStatusResponse<(Omit<ForklaunchResErrors, keyof ResBodyMap> & ResBodyMap)[U]>> & ForklaunchStatusResponse<(Omit<ForklaunchResErrors, keyof ResBodyMap> & ResBodyMap)[U]>;
802
- };
803
- /**
804
- * Ends the response.
805
- * @param {string} [data] - Optional data to send.
806
- */
807
- end: {
808
- (data?: string): void;
809
- (cb?: (() => void) | undefined): BaseResponse;
810
- };
811
- /**
812
- * Sets the content type of the response.
813
- * @param {string} type - The content type.
814
- */
815
- type: {
816
- (type: string): void;
817
- (type: string): BaseResponse;
818
- };
819
- /** Local variables */
820
- locals: LocalsObj;
821
- /** Cors */
822
- cors: boolean;
823
- /** Response schema, compiled */
824
- responseSchemas: ResponseCompiledSchema | Record<string, ResponseCompiledSchema>;
825
- /** Whether the metric has been recorded */
826
- metricRecorded: boolean;
827
- /** Whether the response has been sent */
828
- sent: boolean;
829
- /** Versioned responses */
830
- version: Version;
831
- }
832
- /**
833
- * Type representing the next function in a middleware.
834
- * @param {unknown} [err] - Optional error parameter.
835
- */
836
- type ForklaunchNextFunction = (err?: unknown) => void;
837
- type VersionedRequests = Record<string, {
838
- requestHeaders?: Record<string, unknown>;
839
- body?: Record<string, unknown>;
840
- query?: Record<string, unknown>;
841
- }>;
842
- type ResolvedForklaunchRequestBase<SV extends AnySchemaValidator, P extends ParamsDictionary, ReqBody extends Record<string, unknown>, ReqQuery extends Record<string, unknown>, ReqHeaders extends Record<string, unknown>, Version extends string, SessionSchema extends Record<string, unknown>, BaseRequest> = unknown extends BaseRequest ? ForklaunchRequest<SV, P, ReqBody, ReqQuery, ReqHeaders, Version, SessionSchema> : Omit<BaseRequest, keyof ForklaunchRequest<SV, P, ReqBody, ReqQuery, ReqHeaders, Version, SessionSchema>> & ForklaunchRequest<SV, P, ReqBody, ReqQuery, ReqHeaders, Version, SessionSchema>;
843
- /**
844
- * Type representing the resolved forklaunch request from a base request type.
845
- * @template SV - A type that extends AnySchemaValidator.
846
- * @template P - A type for request parameters, defaulting to ParamsDictionary.
847
- * @template ReqBody - A type for the request body, defaulting to Record<string, unknown>.
848
- * @template ReqQuery - A type for the request query, defaulting to ParsedQs.
849
- * @template ReqHeaders - A type for the request headers, defaulting to Record<string, unknown>.
850
- * @template BaseRequest - A type for the base request.
851
- */
852
- type ResolvedForklaunchRequest<SV extends AnySchemaValidator, P extends ParamsDictionary, ReqBody extends Record<string, unknown>, ReqQuery extends Record<string, unknown>, ReqHeaders extends Record<string, string>, VersionedReqs extends VersionedRequests, SessionSchema extends Record<string, unknown>, BaseRequest> = VersionedRequests extends VersionedReqs ? ResolvedForklaunchRequestBase<SV, P, ReqBody, ReqQuery, ReqHeaders, never, SessionSchema, BaseRequest> : {
853
- [K in keyof VersionedReqs]: ResolvedForklaunchRequestBase<SV, P, VersionedReqs[K]['body'] extends Record<string, unknown> ? VersionedReqs[K]['body'] : Record<string, unknown>, VersionedReqs[K]['query'] extends Record<string, unknown> ? VersionedReqs[K]['query'] : ParsedQs, VersionedReqs[K]['requestHeaders'] extends Record<string, unknown> ? VersionedReqs[K]['requestHeaders'] : Record<string, string>, K extends string ? K : never, SessionSchema, BaseRequest>;
854
- }[keyof VersionedReqs];
855
- type ResolvedForklaunchAuthRequest<P extends ParamsDictionary, ReqBody extends Record<string, unknown>, ReqQuery extends ParsedQs, ReqHeaders extends Record<string, string>, BaseRequest> = unknown extends BaseRequest ? ForklaunchBaseRequest<P, ReqBody, ReqQuery, ReqHeaders> : {
856
- [key in keyof BaseRequest]: key extends keyof ForklaunchBaseRequest<P, ReqBody, ReqQuery, ReqHeaders> ? ForklaunchBaseRequest<P, ReqBody, ReqQuery, ReqHeaders>[key] : key extends keyof BaseRequest ? BaseRequest[key] : never;
857
- };
858
- type VersionedResponses = Record<string, {
859
- responseHeaders?: Record<string, unknown>;
860
- responses: Record<number, unknown>;
861
- }>;
862
- type ResolvedForklaunchResponseBase<ResBodyMap extends Record<number, unknown>, ResHeaders extends Record<string, unknown>, LocalsObj extends Record<string, unknown>, Version extends string, BaseResponse> = unknown extends BaseResponse ? ForklaunchResponse<BaseResponse, ResBodyMap, ResHeaders, LocalsObj, Version> : (string extends Version ? unknown : {
863
- version?: Version;
864
- }) & {
865
- [K in keyof BaseResponse | keyof ForklaunchResponse<BaseResponse, ResBodyMap, ResHeaders, LocalsObj, Version>]: K extends keyof ForklaunchResponse<BaseResponse, ResBodyMap, ResHeaders, LocalsObj, Version> ? ForklaunchResponse<BaseResponse, ResBodyMap, ResHeaders, LocalsObj, Version>[K] : K extends keyof BaseResponse ? BaseResponse[K] : never;
866
- };
867
- type ResolvedForklaunchResponse<ResBodyMap extends Record<number, unknown>, ResHeaders extends Record<string, string>, LocalsObj extends Record<string, unknown>, VersionedResps extends VersionedResponses, BaseResponse> = VersionedResponses extends VersionedResps ? ResolvedForklaunchResponseBase<ResBodyMap, ResHeaders, LocalsObj, never, BaseResponse> : {
868
- [K in keyof VersionedResps]: ResolvedForklaunchResponseBase<VersionedResps[K]['responses'], VersionedResps[K]['responseHeaders'] extends Record<string, unknown> ? VersionedResps[K]['responseHeaders'] : Record<string, string>, LocalsObj, K extends string ? K : never, BaseResponse>;
869
- }[keyof VersionedResps];
870
- /**
871
- * Represents a middleware handler with schema validation.
872
- *
873
- * @template SV - A type that extends AnySchemaValidator.
874
- * @template P - A type for request parameters, defaulting to ParamsDictionary.
875
- * @template ResBodyMap - A type for the response body, defaulting to unknown.
876
- * @template ReqBody - A type for the request body, defaulting to unknown.
877
- * @template ReqQuery - A type for the request query, defaulting to ParsedQs.
878
- * @template LocalsObj - A type for local variables, defaulting to an empty object.
879
- * @template StatusCode - A type for the status code, defaulting to number.
880
- */
881
- interface ExpressLikeHandler<SV extends AnySchemaValidator, P extends ParamsDictionary, ResBodyMap extends Record<number, unknown>, ReqBody extends Record<string, unknown>, ReqQuery extends ParsedQs, ReqHeaders extends Record<string, string>, ResHeaders extends Record<string, string>, LocalsObj extends Record<string, unknown>, VersionedReqs extends VersionedRequests, VersionedResps extends VersionedResponses, SessionSchema extends Record<string, unknown>, BaseRequest, BaseResponse, NextFunction> {
882
- (req: ResolvedForklaunchRequest<SV, P, ReqBody, ReqQuery, ReqHeaders, VersionedReqs, SessionSchema, BaseRequest>, res: ResolvedForklaunchResponse<ResBodyMap, ResHeaders, LocalsObj, VersionedResps, BaseResponse>, next: NextFunction): unknown;
883
- }
884
- type MapParamsSchema<SV extends AnySchemaValidator, P extends ParamsObject<SV>> = MapSchema<SV, P> extends infer Params ? unknown extends Params ? ParamsDictionary : Params : ParamsDictionary;
885
- type ExtractContentType<SV extends AnySchemaValidator, T extends ResponseBody<SV> | unknown> = T extends {
886
- contentType: string;
887
- } ? T['contentType'] : T extends JsonBody<SV> ? 'application/json' : T extends TextBody<SV> ? 'text/plain' : T extends FileBody<SV> ? 'application/octet-stream' : T extends ServerSentEventBody<SV> ? 'text/event-stream' : T extends UnknownResponseBody<SV> ? 'application/json' : T extends SV['file'] ? 'application/octet-stream' : 'text/plain';
888
- type ExtractResponseBody<SV extends AnySchemaValidator, T extends ResponseBody<SV> | unknown> = T extends JsonBody<SV> ? MapSchema<SV, T['json']> : T extends TextBody<SV> ? MapSchema<SV, T['text']> : T extends FileBody<SV> ? File | Blob : T extends ServerSentEventBody<SV> ? AsyncGenerator<MapSchema<SV, T['event']>> : T extends UnknownResponseBody<SV> ? MapSchema<SV, T['schema']> : MapSchema<SV, T>;
889
- type MapResBodyMapSchema<SV extends AnySchemaValidator, ResBodyMap extends ResponsesObject<SV>> = unknown extends ResBodyMap ? ForklaunchResErrors : {
890
- [K in keyof ResBodyMap]: ExtractResponseBody<SV, ResBodyMap[K]>;
891
- };
892
- type ExtractBody<SV extends AnySchemaValidator, T extends Body<SV>> = T extends JsonBody<SV> ? T['json'] : T extends TextBody<SV> ? T['text'] : T extends FileBody<SV> ? T['file'] : T extends MultipartForm<SV> ? T['multipartForm'] : T extends UrlEncodedForm<SV> ? T['urlEncodedForm'] : T extends UnknownBody<SV> ? T['schema'] : T;
893
- type MapReqBodySchema<SV extends AnySchemaValidator, ReqBody extends Body<SV>> = MapSchema<SV, ExtractBody<SV, ReqBody>> extends infer Body ? unknown extends Body ? Record<string, unknown> : Body : Record<string, unknown>;
894
- type MapReqQuerySchema<SV extends AnySchemaValidator, ReqQuery extends QueryObject<SV>> = MapSchema<SV, ReqQuery> extends infer Query ? unknown extends Query ? ParsedQs : Query : ParsedQs;
895
- type MapReqHeadersSchema<SV extends AnySchemaValidator, ReqHeaders extends HeadersObject<SV>> = MapSchema<SV, ReqHeaders> extends infer RequestHeaders ? unknown extends RequestHeaders ? Record<string, string> : RequestHeaders : Record<string, string>;
896
- type MapResHeadersSchema<SV extends AnySchemaValidator, ResHeaders extends HeadersObject<SV>> = MapSchema<SV, ResHeaders> extends infer ResponseHeaders ? unknown extends ResponseHeaders ? ForklaunchResHeaders : ResponseHeaders : ForklaunchResHeaders;
897
- type MapVersionedReqsSchema<SV extends AnySchemaValidator, VersionedReqs extends VersionSchema<SV, Method>> = {
898
- [K in keyof VersionedReqs]: (VersionedReqs[K]['requestHeaders'] extends HeadersObject<SV> ? {
899
- requestHeaders: MapReqHeadersSchema<SV, VersionedReqs[K]['requestHeaders']>;
900
- } : unknown) & (VersionedReqs[K]['body'] extends Body<SV> ? {
901
- body: MapReqBodySchema<SV, VersionedReqs[K]['body']>;
902
- } : unknown) & (VersionedReqs[K]['query'] extends QueryObject<SV> ? {
903
- query: MapReqQuerySchema<SV, VersionedReqs[K]['query']>;
904
- } : unknown);
905
- } extends infer MappedVersionedReqs ? MappedVersionedReqs extends VersionedRequests ? MappedVersionedReqs : VersionedRequests : VersionedRequests;
906
- type MapVersionedRespsSchema<SV extends AnySchemaValidator, VersionedResps extends VersionSchema<SV, Method>> = {
907
- [K in keyof VersionedResps]: (VersionedResps[K]['responseHeaders'] extends HeadersObject<SV> ? {
908
- responseHeaders: MapResHeadersSchema<SV, VersionedResps[K]['responseHeaders']>;
909
- } : unknown) & (VersionedResps[K]['responses'] extends ResponsesObject<SV> ? {
910
- responses: MapResBodyMapSchema<SV, VersionedResps[K]['responses']>;
911
- } : unknown);
912
- } extends infer MappedVersionedResps ? MappedVersionedResps extends VersionedResponses ? MappedVersionedResps : VersionedResponses : VersionedResponses;
913
- type MapSessionSchema<SV extends AnySchemaValidator, SessionSchema extends SessionObject<SV>> = SessionSchema extends infer UnmappedSessionSchema ? UnmappedSessionSchema extends SessionObject<SV> ? MapSchema<SV, UnmappedSessionSchema> : never : never;
914
- /**
915
- * Represents a schema middleware handler with typed parameters, responses, body, and query.
916
- *
917
- * @template SV - A type that extends AnySchemaValidator.
918
- * @template P - A type for parameter schemas, defaulting to ParamsObject.
919
- * @template ResBodyMap - A type for response schemas, defaulting to ResponsesObject.
920
- * @template ReqBody - A type for the request body, defaulting to Body.
921
- * @template ReqQuery - A type for the request query, defaulting to QueryObject.
922
- * @template LocalsObj - A type for local variables, defaulting to an empty object.
923
- */
924
- type ExpressLikeSchemaHandler<SV extends AnySchemaValidator, P extends ParamsObject<SV>, ResBodyMap extends ResponsesObject<SV>, ReqBody extends Body<SV>, ReqQuery extends QueryObject<SV>, ReqHeaders extends HeadersObject<SV>, ResHeaders extends HeadersObject<SV>, LocalsObj extends Record<string, unknown>, VersionedApi extends VersionSchema<SV, Method>, SessionSchema extends Record<string, unknown>, BaseRequest, BaseResponse, NextFunction> = ExpressLikeHandler<SV, MapParamsSchema<SV, P>, MapResBodyMapSchema<SV, ResBodyMap>, MapReqBodySchema<SV, ReqBody>, MapReqQuerySchema<SV, ReqQuery>, MapReqHeadersSchema<SV, ReqHeaders>, MapResHeadersSchema<SV, ResHeaders>, LocalsObj, MapVersionedReqsSchema<SV, VersionedApi>, MapVersionedRespsSchema<SV, VersionedApi>, MapSessionSchema<SV, SessionSchema>, BaseRequest, BaseResponse, NextFunction>;
925
- /**
926
- * Represents a function that maps an authenticated request with schema validation
927
- * to a set of authorization strings, with request properties automatically inferred from the schema.
928
- *
929
- * @template SV - The type representing the schema validator.
930
- * @template P - The type representing request parameters inferred from the schema.
931
- * @template ReqBody - The type representing the request body inferred from the schema.
932
- * @template ReqQuery - The type representing the request query parameters inferred from the schema.
933
- * @template ReqHeaders - The type representing the request headers inferred from the schema.
934
- *
935
- * @param {ForklaunchRequest<SV, P, ReqBody, ReqQuery, ReqHeaders>} req - The request object with schema validation.
936
- * @returns {Set<string> | Promise<Set<string>>} - A set of authorization strings or a promise that resolves to it.
937
- */
938
- type ExpressLikeSchemaAuthMapper<SV extends AnySchemaValidator, P extends ParamsObject<SV>, ReqBody extends Body<SV>, ReqQuery extends QueryObject<SV>, ReqHeaders extends HeadersObject<SV>, VersionedReqs extends VersionSchema<SV, Method>, SessionSchema extends SessionObject<SV>, BaseRequest> = ExpressLikeAuthMapper<SV, P extends infer UnmappedParams ? UnmappedParams extends ParamsObject<SV> ? MapParamsSchema<SV, UnmappedParams> : never : never, ReqBody extends infer UnmappedReqBody ? UnmappedReqBody extends Body<SV> ? MapReqBodySchema<SV, UnmappedReqBody> : never : never, ReqQuery extends infer UnmappedReqQuery ? UnmappedReqQuery extends QueryObject<SV> ? MapReqQuerySchema<SV, UnmappedReqQuery> : never : never, ReqHeaders extends infer UnmappedReqHeaders ? UnmappedReqHeaders extends HeadersObject<SV> ? MapReqHeadersSchema<SV, UnmappedReqHeaders> : never : never, VersionedReqs extends infer UnmappedVersionedReqs ? UnmappedVersionedReqs extends VersionSchema<SV, Method> ? MapVersionedReqsSchema<SV, UnmappedVersionedReqs> : never : never, SessionSchema extends infer UnmappedSessionSchema ? UnmappedSessionSchema extends Record<string, unknown> ? MapSessionSchema<SV, UnmappedSessionSchema> : never : never, BaseRequest>;
939
- type ExpressLikeAuthMapper<SV extends AnySchemaValidator, P extends ParamsDictionary, ReqBody extends Record<string, unknown>, ReqQuery extends Record<string, unknown>, ReqHeaders extends Record<string, string>, VersionedReqs extends VersionedRequests, SessionSchema extends Record<string, unknown>, BaseRequest> = (payload: JWTPayload & SessionSchema, req?: ResolvedForklaunchRequest<SV, P, ReqBody, ReqQuery, ReqHeaders, VersionedReqs, SessionSchema, BaseRequest>) => Set<string> | Promise<Set<string>>;
940
- type TokenPrefix<Auth extends AuthMethodsBase> = undefined extends Auth['tokenPrefix'] ? Auth extends BasicAuthMethods ? 'Basic ' : Auth extends HmacMethods ? 'HMAC ' : 'Bearer ' : `${Auth['tokenPrefix']} `;
941
- type AuthHeaders<Auth extends AuthMethodsBase> = undefined extends Auth['headerName'] ? {
942
- authorization: Auth extends HmacMethods ? `${TokenPrefix<Auth>}keyId=${string} ts=${string} nonce=${string} signature=${string}` : `${TokenPrefix<Auth>}${string}`;
943
- } : {
944
- [K in NonNullable<Auth['headerName']>]: `${TokenPrefix<Auth>}${string}`;
945
- };
946
- type AuthCollapse<Auth extends AuthMethodsBase> = undefined extends Auth['jwt'] ? undefined extends Auth['basic'] ? undefined extends Auth['hmac'] ? true : false : false : false;
947
- type LiveTypeFunctionRequestInit<SV extends AnySchemaValidator, P extends ParamsObject<SV>, ReqBody extends Body<SV> | undefined, ReqQuery extends QueryObject<SV> | undefined, ReqHeaders extends HeadersObject<SV> | undefined, Auth extends AuthMethodsBase> = MakePropertyOptionalIfChildrenOptional<(Body<SV> extends ReqBody ? unknown : {
948
- body: MapSchema<SV, ReqBody>;
949
- }) & (QueryObject<SV> extends ReqQuery ? unknown : {
950
- query: MapSchema<SV, ReqQuery>;
951
- }) & (HeadersObject<SV> extends ReqHeaders ? true extends AuthCollapse<Auth> ? unknown : {
952
- headers: AuthHeaders<Auth>;
953
- } : true extends AuthCollapse<Auth> ? {
954
- headers: MapSchema<SV, ReqHeaders>;
955
- } : {
956
- headers: MapSchema<SV, ReqHeaders> & AuthHeaders<Auth>;
957
- }) & (ParamsObject<SV> extends P ? unknown : {
958
- params: MapSchema<SV, P>;
959
- })>;
960
- /**
961
- * Represents a live type function for the SDK.
962
- *
963
- * @template SV - A type that extends AnySchemaValidator.
964
- * @template Path - A type for the route path.
965
- * @template P - A type for request parameters.
966
- * @template ResBodyMap - A type for response schemas.
967
- * @template ReqBody - A type for the request body.
968
- * @template ReqQuery - A type for the request query.
969
- * @template ReqHeaders - A type for the request headers.
970
- * @template ResHeaders - A type for the response headers.
971
- *
972
- */
973
- type LiveTypeFunction<SV extends AnySchemaValidator, Route extends string, P extends ParamsObject<SV>, ResBodyMap extends ResponsesObject<SV>, ReqBody extends Body<SV>, ReqQuery extends QueryObject<SV>, ReqHeaders extends HeadersObject<SV>, ResHeaders extends HeadersObject<SV>, ContractMethod extends Method, VersionedApi extends VersionSchema<SV, ContractMethod>, Auth extends AuthMethodsBase> = string extends keyof VersionedApi ? (route: SanitizePathSlashes<Route>, ...reqInit: Prettify<Omit<RequestInit, 'method' | 'body' | 'query' | 'headers' | 'params'> & {
974
- method: Uppercase<ContractMethod>;
975
- } & LiveTypeFunctionRequestInit<SV, P, ReqBody, ReqQuery, ReqHeaders, Auth>> extends infer ReqInit ? ReqInit extends {
976
- body: unknown;
977
- } | {
978
- params: unknown;
979
- } | {
980
- query: unknown;
981
- } | {
982
- headers: unknown;
983
- } ? [reqInit: Prettify<ReqInit>] : [reqInit?: Prettify<ReqInit>] : never) => Promise<Prettify<SdkResponse<SV, ResponsesObject<SV> extends ResBodyMap ? Record<number, unknown> : ResBodyMap, ForklaunchResHeaders extends ResHeaders ? unknown : MapSchema<SV, ResHeaders>>>> : {
984
- [K in keyof VersionedApi]: (...reqInit: Prettify<Omit<RequestInit, 'method' | 'body' | 'query' | 'headers' | 'params'> & LiveTypeFunctionRequestInit<SV, P, VersionedApi[K]['body'] extends Body<SV> ? VersionedApi[K]['body'] : Body<SV>, VersionedApi[K]['query'] extends QueryObject<SV> ? VersionedApi[K]['query'] : QueryObject<SV>, VersionedApi[K]['requestHeaders'] extends HeadersObject<SV> ? VersionedApi[K]['requestHeaders'] : HeadersObject<SV>, Auth>> & {
985
- version: K;
986
- } extends infer ReqInit ? ReqInit extends {
987
- body: unknown;
988
- } | {
989
- params: unknown;
990
- } | {
991
- query: unknown;
992
- } | {
993
- headers: unknown;
994
- } ? [reqInit: Prettify<ReqInit>] : [reqInit?: Prettify<ReqInit>] : never) => Promise<Prettify<SdkResponse<SV, ResponsesObject<SV> extends VersionedApi[K]['responses'] ? Record<number, unknown> : VersionedApi[K]['responses'], ForklaunchResHeaders extends VersionedApi[K]['responseHeaders'] ? unknown : MapSchema<SV, VersionedApi[K]['responseHeaders']>>>>;
995
- };
996
- /**
997
- * Represents a live type function for the SDK.
998
- *
999
- * @template SV - A type that extends AnySchemaValidator.
1000
- * @template P - A type for request parameters.
1001
- * @template ResBodyMap - A type for response schemas.
1002
- * @template ReqBody - A type for the request body.
1003
- * @template ReqQuery - A type for the request query.
1004
- * @template ReqHeaders - A type for the request headers.
1005
- * @template ResHeaders - A type for the response headers.
1006
- *
1007
- */
1008
- type LiveSdkFunction<SV extends AnySchemaValidator, P extends ParamsObject<SV>, ResBodyMap extends ResponsesObject<SV>, ReqBody extends Body<SV>, ReqQuery extends QueryObject<SV>, ReqHeaders extends HeadersObject<SV>, ResHeaders extends HeadersObject<SV>, VersionedApi extends VersionSchema<SV, Method>, Auth extends AuthMethodsBase> = string extends keyof VersionedApi ? (...reqInit: Prettify<Omit<RequestInit, 'method' | 'body' | 'query' | 'headers' | 'params'> & LiveTypeFunctionRequestInit<SV, P, ReqBody, ReqQuery, ReqHeaders, Auth>> extends infer ReqInit ? ReqInit extends {
1009
- body: unknown;
1010
- } | {
1011
- params: unknown;
1012
- } | {
1013
- query: unknown;
1014
- } | {
1015
- headers: unknown;
1016
- } ? [reqInit: Prettify<ReqInit>] : [reqInit?: Prettify<ReqInit>] : never) => Promise<Prettify<SdkResponse<SV, ResponsesObject<SV> extends ResBodyMap ? Record<number, unknown> : ResBodyMap, ForklaunchResHeaders extends ResHeaders ? unknown : MapSchema<SV, ResHeaders>>>> : {
1017
- [K in keyof VersionedApi]: (...reqInit: Prettify<Omit<RequestInit, 'method' | 'body' | 'query' | 'headers' | 'params'> & LiveTypeFunctionRequestInit<SV, P, VersionedApi[K]['body'] extends Body<SV> ? VersionedApi[K]['body'] : Body<SV>, VersionedApi[K]['query'] extends QueryObject<SV> ? VersionedApi[K]['query'] : QueryObject<SV>, VersionedApi[K]['requestHeaders'] extends HeadersObject<SV> ? VersionedApi[K]['requestHeaders'] : HeadersObject<SV>, Auth>> extends infer ReqInit ? ReqInit extends {
1018
- body: unknown;
1019
- } | {
1020
- params: unknown;
1021
- } | {
1022
- query: unknown;
1023
- } | {
1024
- headers: unknown;
1025
- } ? [reqInit: Prettify<ReqInit>] : [reqInit?: Prettify<ReqInit>] : never) => Promise<Prettify<SdkResponse<SV, ResponsesObject<SV> extends VersionedApi[K]['responses'] ? Record<number, unknown> : VersionedApi[K]['responses'], ForklaunchResHeaders extends VersionedApi[K]['responseHeaders'] ? unknown : MapSchema<SV, VersionedApi[K]['responseHeaders']>>>>;
1026
- };
1027
- /**
1028
- * Represents a basic SDK Response object.
1029
- *
1030
- * @template ResBodyMap - A type for the response body.
1031
- * @template ResHeaders - A type for the response headers.
1032
- */
1033
- type SdkResponse<SV extends AnySchemaValidator, ResBodyMap extends Record<number, unknown>, ResHeaders extends Record<string, unknown> | unknown> = ({
1034
- [K in keyof ForklaunchResErrors]: {
1035
- code: K;
1036
- contentType: 'text/plain';
1037
- response: ForklaunchResErrors[K];
1038
- };
1039
- } & {
1040
- [K in keyof ResBodyMap]: {
1041
- code: K;
1042
- contentType: ExtractContentType<SV, ResBodyMap[K]>;
1043
- response: ExtractResponseBody<SV, ResBodyMap[K]>;
1044
- } & (unknown extends ResHeaders ? unknown : {
1045
- headers: ResHeaders;
1046
- });
1047
- })[keyof (ForklaunchResErrors & ResBodyMap)];
1048
- /**
1049
- * Represents the default error types for responses.
1050
- */
1051
- type ForklaunchResErrors<BadRequest = string, Unauthorized = string, NotFound = string, Forbidden = string, InternalServerErrorType = string> = {
1052
- 400: BadRequest;
1053
- 401: Unauthorized;
1054
- 404: NotFound;
1055
- 403: Forbidden;
1056
- 500: InternalServerErrorType;
1057
- };
1058
- /**
1059
- * Represents the default header types for responses.
1060
- */
1061
- type ForklaunchResHeaders = {
1062
- 'x-correlation-id': string;
1063
- };
1064
- /**
1065
- * Represents the default error types for responses.
1066
- */
1067
- type ErrorContainer<Code extends number> = {
1068
- /** The error code */
1069
- code: Code;
1070
- /** The error message */
1071
- error: string;
1072
- };
1073
- /**
1074
- * Represents a parsed response shape.
1075
- */
1076
- type ResponseShape<Params, Headers, Query, Body> = {
1077
- params: Params;
1078
- headers: Headers;
1079
- query: Query;
1080
- body: Body;
1081
- };
1082
- /**
1083
- * Represents a path match.
1084
- */
1085
- type PathMatch<SuppliedPath extends `/${string}`, ActualPath extends `/${string}`> = ActualPath extends SuppliedPath ? SuppliedPath extends ActualPath ? SuppliedPath : never : never;
1086
-
1087
46
  interface ConstrainedForklaunchRouter<SV extends AnySchemaValidator, RequestHandler> extends ForklaunchRouter<SV> {
1088
47
  requestHandler: RequestHandler;
1089
48
  }
@@ -1979,7 +938,7 @@ declare const getCodeForStatus: (status: string) => null | StatusCode;
1979
938
  * @param {ForklaunchRouter<SV>[]} routers - The routers to include in the server.
1980
939
  * @returns {McpServer} - The generated ModelContextProtocol server.
1981
940
  */
1982
- declare function generateMcpServer<T extends Record<string, unknown> | undefined = Record<string, unknown> | undefined>(schemaValidator: ZodSchemaValidator, protocol: 'http' | 'https', host: string, port: number, version: `${number}.${number}.${number}`, application: ForklaunchRouter<ZodSchemaValidator>, appOptions?: ExpressLikeApplicationOptions<ZodSchemaValidator, SessionObject<ZodSchemaValidator>>['mcp'], options?: ConstructorParameters<typeof FastMCP<T>>[0], contentTypeMap?: Record<string, string>): FastMCP<T>;
941
+ declare function generateMcpServer<T extends Record<string, unknown> | undefined = Record<string, unknown> | undefined>(schemaValidator: ZodSchemaValidator, protocol: 'http' | 'https', host: string, port: number, version: `${number}.${number}.${number}`, application: ForklaunchRouter<ZodSchemaValidator>, appOptions?: ExpressLikeApplicationOptions<ZodSchemaValidator, SessionObject<ZodSchemaValidator>>['mcp'], options?: ConstructorParameters<typeof FastMCP<T>>[0], contentTypeMap?: Record<string, string>, authenticate?: (request: http.IncomingMessage) => Promise<Record<string, unknown> | undefined>): FastMCP<Record<string, unknown> | undefined>;
1983
942
 
1984
943
  /**
1985
944
  * Enhances the Express-like `send` method with additional logic for response handling and validation.
@@ -2094,4 +1053,4 @@ declare function logger(level: LevelWithSilentOrString, meta?: AnyValueMap): Pin
2094
1053
 
2095
1054
  declare function recordMetric<SV extends AnySchemaValidator, P extends ParamsDictionary, ReqBody extends Record<string, unknown>, ReqQuery extends ParsedQs, ResBodyMap extends Record<string, unknown>, ReqHeaders extends Record<string, string>, ResHeaders extends Record<string, unknown>, LocalsObj extends Record<string, unknown>, VersionedReqs extends VersionedRequests, SessionSchema extends Record<string, unknown>>(req: ForklaunchRequest<SV, P, ReqBody, ReqQuery, ReqHeaders, Extract<keyof VersionedReqs, string>, SessionSchema>, res: ForklaunchResponse<unknown, ResBodyMap, ResHeaders, LocalsObj, Extract<keyof VersionedReqs, string>>): void;
2096
1055
 
2097
- export { ATTR_API_NAME, ATTR_CORRELATION_ID, type AuthMethods, type AuthMethodsBase, type BasicAuthMethods, type Body, type BodyObject, type ClusterConfig, type ConstrainedForklaunchRouter, type ContractDetails, type ContractDetailsExpressLikeSchemaHandler, type ContractDetailsOrMiddlewareOrTypedHandler, type DecodeResource, type DocsConfiguration, type ErrorContainer, type ExpressLikeApplicationOptions, type ExpressLikeAuthMapper, type ExpressLikeGlobalAuthOptions, type ExpressLikeHandler, type ExpressLikeRouter, type ExpressLikeRouterOptions, type ExpressLikeSchemaAuthMapper, type ExpressLikeSchemaGlobalAuthOptions, type ExpressLikeSchemaHandler, type ExpressLikeTypedHandler, type ExtractBody, type ExtractContentType, type ExtractLiveTypeFn, type ExtractResponseBody, type ExtractedParamsObject, type FetchFunction, type FileBody, type ForklaunchBaseRequest, ForklaunchExpressLikeApplication, ForklaunchExpressLikeRouter, type ForklaunchNextFunction, type ForklaunchRequest, type ForklaunchResErrors, type ForklaunchResHeaders, type ForklaunchResponse, type ForklaunchRoute, type ForklaunchRouter, type ForklaunchSendableData, type ForklaunchStatusResponse, HTTPStatuses, type HeadersObject, type HmacMethods, type HttpContractDetails, type HttpMethod, type JsonBody, type JwtAuthMethods, type LiveSdkFunction, type LiveTypeFunction, type LiveTypeFunctionRequestInit, type LiveTypeRouteDefinition, type LogFn, type LoggerMeta, type MapHandlerToLiveSdk, type MapParamsSchema, type MapReqBodySchema, type MapReqHeadersSchema, type MapReqQuerySchema, type MapResBodyMapSchema, type MapResHeadersSchema, type MapSchema, type MapSessionSchema, type MapToFetch, type MapToSdk, type MapVersionedReqsSchema, type MapVersionedRespsSchema, type Method, type MetricType, type MetricsDefinition, type MiddlewareContractDetails, type MiddlewareOrMiddlewareWithTypedHandler, type MultipartForm, type NestableRouterBasedHandler, type NumberOnlyObject, OPENAPI_DEFAULT_VERSION, OpenTelemetryCollector, type ParamsDictionary, type ParamsObject, type PathBasedHandler, type PathMatch, type PathOrMiddlewareBasedHandler, type PathParamHttpContractDetails, type PathParamMethod, PinoLogger, type QueryObject, type RawTypedResponseBody, type RequestContext, type ResolvedForklaunchAuthRequest, type ResolvedForklaunchRequest, type ResolvedForklaunchResponse, type ResolvedSessionObject, type ResponseBody, type ResponseCompiledSchema, type ResponseShape, type ResponsesObject, type RouterMap, type RoutingStrategy, type SchemaAuthMethods, type SdkHandler, type SdkHandlerObject, type SdkRouter, type ServerSentEventBody, type SessionObject, type StatusCode, type StringOnlyObject, type TelemetryOptions, type TextBody, type ToFetchMap, type TypedBody, type TypedHandler, type TypedMiddlewareDefinition, type TypedNestableMiddlewareDefinition, type TypedRequestBody, type TypedResponseBody, type UnknownBody, type UnknownResponseBody, type UrlEncodedForm, type VersionSchema, type VersionedRequests, type VersionedResponses, createHmacToken, delete_, discriminateAuthMethod, discriminateBody, discriminateResponseBodies, enrichExpressLikeSend, evaluateTelemetryOptions, generateMcpServer, generateOpenApiSpecs, get, getCachedJwks, getCodeForStatus, head, httpRequestsTotalCounter, httpServerDurationHistogram, isClientError, isForklaunchRequest, isForklaunchRouter, isInformational, isPortBound, isRedirection, isServerError, isSuccessful, isValidStatusCode, logger, meta, metricsDefinitions, middleware, options, patch, post, put, recordMetric, trace, typedAuthHandler, typedHandler };
1056
+ export { ATTR_API_NAME, ATTR_CORRELATION_ID, AuthMethods, AuthMethodsBase, BasicAuthMethods, Body, type ClusterConfig, type ConstrainedForklaunchRouter, ContractDetails, type ContractDetailsExpressLikeSchemaHandler, type ContractDetailsOrMiddlewareOrTypedHandler, DecodeResource, ExpressLikeApplicationOptions, type ExpressLikeRouter, ExpressLikeRouterOptions, ExpressLikeSchemaAuthMapper, ExpressLikeSchemaHandler, type ExpressLikeTypedHandler, type ExtractLiveTypeFn, type FetchFunction, ForklaunchExpressLikeApplication, ForklaunchExpressLikeRouter, ForklaunchRequest, ForklaunchResHeaders, ForklaunchResponse, type ForklaunchRoute, type ForklaunchRouter, ForklaunchSendableData, ForklaunchStatusResponse, HTTPStatuses, HeadersObject, HttpContractDetails, LiveSdkFunction, LiveTypeFunction, type LiveTypeRouteDefinition, LogFn, LoggerMeta, type MapHandlerToLiveSdk, type MapToFetch, type MapToSdk, Method, MetricsDefinition, MiddlewareContractDetails, type MiddlewareOrMiddlewareWithTypedHandler, type NestableRouterBasedHandler, OPENAPI_DEFAULT_VERSION, OpenTelemetryCollector, ParamsDictionary, ParamsObject, type PathBasedHandler, PathMatch, type PathOrMiddlewareBasedHandler, PathParamHttpContractDetails, PinoLogger, QueryObject, ResolvedSessionObject, ResponsesObject, type RouterMap, type RoutingStrategy, SchemaAuthMethods, type SdkHandler, type SdkHandlerObject, type SdkRouter, SessionObject, type StatusCode, TelemetryOptions, type ToFetchMap, type TypedHandler, type TypedMiddlewareDefinition, type TypedNestableMiddlewareDefinition, VersionSchema, VersionedRequests, createHmacToken, delete_, discriminateAuthMethod, discriminateBody, discriminateResponseBodies, enrichExpressLikeSend, evaluateTelemetryOptions, generateMcpServer, generateOpenApiSpecs, get, getCachedJwks, getCodeForStatus, head, isClientError, isForklaunchRequest, isForklaunchRouter, isInformational, isPortBound, isRedirection, isServerError, isSuccessful, isValidStatusCode, logger, meta, metricsDefinitions, middleware, options, patch, post, put, recordMetric, trace, typedAuthHandler, typedHandler };