semola 0.6.0 → 0.6.2

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.
Files changed (51) hide show
  1. package/README.md +19 -5
  2. package/dist/index-DISN0WKZ.d.mts +78 -0
  3. package/dist/lib/api/index.cjs +1 -537
  4. package/dist/lib/api/index.d.cts +1 -271
  5. package/dist/lib/api/index.d.mts +100 -164
  6. package/dist/lib/api/index.mjs +1 -535
  7. package/dist/lib/cache/index.cjs +1 -99
  8. package/dist/lib/cache/index.d.cts +1 -27
  9. package/dist/lib/cache/index.mjs +1 -98
  10. package/dist/lib/cli/index.cjs +3 -0
  11. package/dist/lib/cli/index.d.cts +1 -0
  12. package/dist/lib/cli/index.d.mts +90 -0
  13. package/dist/lib/cli/index.mjs +3 -0
  14. package/dist/lib/cron/index.cjs +1 -735
  15. package/dist/lib/cron/index.d.cts +1 -146
  16. package/dist/lib/cron/index.d.mts +99 -36
  17. package/dist/lib/cron/index.mjs +1 -726
  18. package/dist/lib/errors/index.cjs +1 -30
  19. package/dist/lib/errors/index.d.cts +1 -13
  20. package/dist/lib/errors/index.mjs +1 -26
  21. package/dist/lib/i18n/index.cjs +1 -42
  22. package/dist/lib/i18n/index.d.cts +1 -28
  23. package/dist/lib/i18n/index.d.mts +2 -2
  24. package/dist/lib/i18n/index.mjs +1 -41
  25. package/dist/lib/logging/index.cjs +1 -388
  26. package/dist/lib/logging/index.d.cts +1 -108
  27. package/dist/lib/logging/index.mjs +1 -374
  28. package/dist/lib/orm/index.cjs +1 -1642
  29. package/dist/lib/orm/index.d.cts +1 -402
  30. package/dist/lib/orm/index.d.mts +27 -25
  31. package/dist/lib/orm/index.mjs +1 -1630
  32. package/dist/lib/policy/index.cjs +1 -285
  33. package/dist/lib/policy/index.d.cts +1 -77
  34. package/dist/lib/policy/index.d.mts +1 -1
  35. package/dist/lib/policy/index.mjs +1 -265
  36. package/dist/lib/prompts/index.cjs +6 -769
  37. package/dist/lib/prompts/index.d.cts +1 -75
  38. package/dist/lib/prompts/index.mjs +6 -762
  39. package/dist/lib/pubsub/index.cjs +1 -141
  40. package/dist/lib/pubsub/index.d.cts +1 -26
  41. package/dist/lib/pubsub/index.mjs +1 -140
  42. package/dist/lib/queue/index.cjs +1 -212
  43. package/dist/lib/queue/index.d.cts +1 -81
  44. package/dist/lib/queue/index.mjs +1 -209
  45. package/dist/lib/workflow/index.cjs +1 -537
  46. package/dist/lib/workflow/index.d.cts +1 -150
  47. package/dist/lib/workflow/index.d.mts +0 -1
  48. package/dist/lib/workflow/index.mjs +1 -527
  49. package/dist/rolldown-runtime-CMqjfN_6.cjs +1 -0
  50. package/package.json +17 -5
  51. package/dist/chunk-CKQMccvm.cjs +0 -28
@@ -1,271 +1 @@
1
- //#region src/lib/api/openapi/types.d.ts
2
- type OpenApiSpec = {
3
- openapi: string;
4
- info: {
5
- title: string;
6
- description?: string;
7
- version: string;
8
- };
9
- servers?: Array<{
10
- url: string;
11
- description?: string;
12
- }>;
13
- paths: Record<string, OpenApiPath>;
14
- components?: {
15
- schemas?: Record<string, unknown>;
16
- responses?: Record<string, unknown>;
17
- parameters?: Record<string, unknown>;
18
- requestBodies?: Record<string, unknown>;
19
- securitySchemes?: Record<string, unknown>;
20
- };
21
- };
22
- type OpenApiPath = {
23
- [method: string]: OpenApiOperation;
24
- };
25
- type OpenApiOperation = {
26
- summary?: string;
27
- description?: string;
28
- operationId?: string;
29
- tags?: string[];
30
- parameters?: OpenApiParameter[];
31
- requestBody?: OpenApiRequestBody;
32
- responses: Record<string, OpenApiResponse>;
33
- security?: Array<Record<string, string[]>>;
34
- };
35
- type OpenApiParameter = {
36
- name: string;
37
- in: "path" | "query" | "header" | "cookie";
38
- required?: boolean;
39
- schema: unknown;
40
- description?: string;
41
- };
42
- type OpenApiRequestBody = {
43
- required?: boolean;
44
- content: {
45
- [mediaType: string]: {
46
- schema: unknown;
47
- };
48
- };
49
- };
50
- type OpenApiResponse = {
51
- description: string;
52
- content?: {
53
- [mediaType: string]: {
54
- schema: unknown;
55
- };
56
- };
57
- };
58
- //#endregion
59
- //#region node_modules/@standard-schema/spec/dist/index.d.ts
60
- /** The Standard Typed interface. This is a base type extended by other specs. */
61
- interface StandardTypedV1<Input = unknown, Output = Input> {
62
- /** The Standard properties. */
63
- readonly "~standard": StandardTypedV1.Props<Input, Output>;
64
- }
65
- declare namespace StandardTypedV1 {
66
- /** The Standard Typed properties interface. */
67
- interface Props<Input = unknown, Output = Input> {
68
- /** The version number of the standard. */
69
- readonly version: 1;
70
- /** The vendor name of the schema library. */
71
- readonly vendor: string;
72
- /** Inferred types associated with the schema. */
73
- readonly types?: Types<Input, Output> | undefined;
74
- }
75
- /** The Standard Typed types interface. */
76
- interface Types<Input = unknown, Output = Input> {
77
- /** The input type of the schema. */
78
- readonly input: Input;
79
- /** The output type of the schema. */
80
- readonly output: Output;
81
- }
82
- /** Infers the input type of a Standard Typed. */
83
- type InferInput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["input"];
84
- /** Infers the output type of a Standard Typed. */
85
- type InferOutput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["output"];
86
- }
87
- /** The Standard Schema interface. */
88
- interface StandardSchemaV1<Input = unknown, Output = Input> {
89
- /** The Standard Schema properties. */
90
- readonly "~standard": StandardSchemaV1.Props<Input, Output>;
91
- }
92
- declare namespace StandardSchemaV1 {
93
- /** The Standard Schema properties interface. */
94
- interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
95
- /** Validates unknown input values. */
96
- readonly validate: (value: unknown, options?: StandardSchemaV1.Options | undefined) => Result<Output> | Promise<Result<Output>>;
97
- }
98
- /** The result interface of the validate function. */
99
- type Result<Output> = SuccessResult<Output> | FailureResult;
100
- /** The result interface if validation succeeds. */
101
- interface SuccessResult<Output> {
102
- /** The typed output value. */
103
- readonly value: Output;
104
- /** A falsy value for `issues` indicates success. */
105
- readonly issues?: undefined;
106
- }
107
- interface Options {
108
- /** Explicit support for additional vendor-specific parameters, if needed. */
109
- readonly libraryOptions?: Record<string, unknown> | undefined;
110
- }
111
- /** The result interface if validation fails. */
112
- interface FailureResult {
113
- /** The issues of failed validation. */
114
- readonly issues: ReadonlyArray<Issue>;
115
- }
116
- /** The issue interface of the failure output. */
117
- interface Issue {
118
- /** The error message of the issue. */
119
- readonly message: string;
120
- /** The path of the issue, if any. */
121
- readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
122
- }
123
- /** The path segment interface of the issue. */
124
- interface PathSegment {
125
- /** The key representing a path segment. */
126
- readonly key: PropertyKey;
127
- }
128
- /** The Standard types interface. */
129
- interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {}
130
- /** Infers the input type of a Standard. */
131
- type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
132
- /** Infers the output type of a Standard. */
133
- type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
134
- }
135
- /** The Standard JSON Schema interface. */
136
- //#endregion
137
- //#region src/lib/api/middleware/types.d.ts
138
- type MiddlewareHandler<TReq extends RequestSchema = RequestSchema, TRes extends ResponseSchema | undefined = undefined, TExt extends Record<string, unknown> = Record<never, never>> = (c: Context<TReq, TRes>) => Response | TExt | undefined | Promise<Response | TExt | undefined> | Promise<void> | void;
139
- type MiddlewareOptions<TReq extends RequestSchema = RequestSchema, TRes extends ResponseSchema | undefined = undefined, TExt extends Record<string, unknown> = Record<string, unknown>> = {
140
- request?: TReq;
141
- response?: TRes;
142
- handler: MiddlewareHandler<TReq, TRes, TExt>;
143
- };
144
- type InferMiddlewareExtension<T> = T extends {
145
- options: MiddlewareOptions<infer _TReq, infer _TRes, infer E>;
146
- } ? E : never;
147
- type MergeMiddlewareExtensions<T extends readonly unknown[]> = T extends readonly [infer First, ...infer Rest] ? InferMiddlewareExtension<First> & MergeMiddlewareExtensions<Rest> : {};
148
- //#endregion
149
- //#region src/lib/api/core/types.d.ts
150
- type ResponseSchema = {
151
- [status: number]: StandardSchemaV1;
152
- };
153
- type RequestSchema = {
154
- params?: StandardSchemaV1;
155
- body?: StandardSchemaV1;
156
- query?: StandardSchemaV1;
157
- headers?: StandardSchemaV1;
158
- cookies?: StandardSchemaV1;
159
- };
160
- type SafeTypeAccess<T, K extends "input" | "output"> = T extends StandardSchemaV1 ? T["~standard"] extends {
161
- types?: infer U;
162
- } ? U extends Record<K, infer V> ? V : never : never : undefined;
163
- type InferOutput<T extends StandardSchemaV1 | undefined> = SafeTypeAccess<T, "output">;
164
- type InferInput<T extends StandardSchemaV1 | undefined> = SafeTypeAccess<T, "input">;
165
- type ExtractStatusCodes<T extends ResponseSchema> = keyof T & number;
166
- type ExtractStatusCodesOrAny<T extends ResponseSchema | undefined> = T extends ResponseSchema ? ExtractStatusCodes<T> : number;
167
- type ValidationOptions = boolean | {
168
- input?: boolean;
169
- output?: boolean;
170
- };
171
- type ApiOptions<TMiddlewares extends readonly Middleware[] = readonly []> = {
172
- prefix?: string;
173
- openapi?: OpenApiOptions;
174
- middlewares?: TMiddlewares;
175
- validation?: ValidationOptions;
176
- };
177
- type SecuritySchemeApiKey = {
178
- type: "apiKey";
179
- name: string;
180
- in: "query" | "header" | "cookie";
181
- description?: string;
182
- };
183
- type SecuritySchemeHttp = {
184
- type: "http";
185
- scheme: string;
186
- bearerFormat?: string;
187
- description?: string;
188
- };
189
- type SecuritySchemeOAuth2Flow = {
190
- authorizationUrl?: string;
191
- tokenUrl?: string;
192
- refreshUrl?: string;
193
- scopes: Record<string, string>;
194
- };
195
- type SecuritySchemeOAuth2 = {
196
- type: "oauth2";
197
- flows: {
198
- implicit?: SecuritySchemeOAuth2Flow;
199
- password?: SecuritySchemeOAuth2Flow;
200
- clientCredentials?: SecuritySchemeOAuth2Flow;
201
- authorizationCode?: SecuritySchemeOAuth2Flow;
202
- };
203
- description?: string;
204
- };
205
- type SecuritySchemeOpenIdConnect = {
206
- type: "openIdConnect";
207
- openIdConnectUrl: string;
208
- description?: string;
209
- };
210
- type SecurityScheme = SecuritySchemeApiKey | SecuritySchemeHttp | SecuritySchemeOAuth2 | SecuritySchemeOpenIdConnect;
211
- type OpenApiOptions = {
212
- version: string;
213
- title: string;
214
- description?: string;
215
- servers?: Array<{
216
- url: string;
217
- description?: string;
218
- }>;
219
- securitySchemes?: Record<string, SecurityScheme>;
220
- };
221
- type Context<TReq extends RequestSchema = RequestSchema, TRes extends ResponseSchema | undefined = undefined, TExt extends Record<string, unknown> = Record<string, unknown>> = {
222
- raw: Request;
223
- req: {
224
- body: InferOutput<TReq["body"]>;
225
- query: InferOutput<TReq["query"]>;
226
- headers: InferOutput<TReq["headers"]>;
227
- cookies: InferOutput<TReq["cookies"]>;
228
- params: InferOutput<TReq["params"]>;
229
- };
230
- json: <S extends ExtractStatusCodesOrAny<TRes>>(status: S, data: TRes extends ResponseSchema ? InferOutput<TRes[S]> : unknown) => Response;
231
- text: (status: number, text: string) => Response;
232
- html: (status: number, html: string) => Response;
233
- redirect: (status: number, url: string) => Response;
234
- get: <K extends keyof TExt>(key: K) => TExt[K];
235
- };
236
- type RouteHandler<TReq extends RequestSchema = RequestSchema, TRes extends ResponseSchema | undefined = undefined, TExt extends Record<string, unknown> = Record<string, unknown>> = (c: Context<TReq, TRes, TExt>) => Response | Promise<Response>;
237
- type RouteConfig<TReq extends RequestSchema = RequestSchema, TRes extends ResponseSchema | undefined = undefined, TGlobalMiddlewares extends readonly Middleware[] = readonly [], TRouteMiddlewares extends readonly Middleware[] = readonly []> = {
238
- path: string;
239
- method: Bun.Serve.HTTPMethod;
240
- request?: TReq;
241
- response?: TRes;
242
- middlewares?: TRouteMiddlewares;
243
- handler: RouteHandler<TReq, TRes, MergeMiddlewareExtensions<TGlobalMiddlewares> & MergeMiddlewareExtensions<TRouteMiddlewares>>;
244
- summary?: string;
245
- description?: string;
246
- operationId?: string;
247
- tags?: string[];
248
- };
249
- //#endregion
250
- //#region src/lib/api/middleware/index.d.ts
251
- declare class Middleware<TRequest extends RequestSchema = RequestSchema, TResponse extends ResponseSchema = ResponseSchema, TExtension extends Record<string, unknown> = Record<string, unknown>> {
252
- options: MiddlewareOptions<TRequest, TResponse, TExtension>;
253
- constructor(options: MiddlewareOptions<TRequest, TResponse, TExtension>);
254
- }
255
- //#endregion
256
- //#region src/lib/api/core/index.d.ts
257
- declare class Api<TMiddlewares extends readonly Middleware[] = readonly []> {
258
- private options;
259
- private routes;
260
- constructor(options?: ApiOptions<TMiddlewares>);
261
- private getFullPath;
262
- private validateRequestSchema;
263
- private createContext;
264
- private validateResponseBody;
265
- private buildBunRoutes;
266
- defineRoute<TReq extends RequestSchema = RequestSchema, TRes extends ResponseSchema = ResponseSchema, TRouteMiddlewares extends readonly Middleware[] = readonly []>(config: RouteConfig<TReq, TRes, TMiddlewares, TRouteMiddlewares>): void;
267
- getOpenApiSpec(): Promise<OpenApiSpec>;
268
- serve(port: number, callback?: (server: Bun.Server<unknown>) => void): void;
269
- }
270
- //#endregion
271
- export { Api, type ApiOptions, type Context, type ExtractStatusCodes, type InferInput, type InferMiddlewareExtension, type InferOutput, type MergeMiddlewareExtensions, Middleware, type MiddlewareHandler, type MiddlewareOptions, type OpenApiOptions, type RequestSchema, type ResponseSchema, type RouteConfig, type RouteHandler, type SecurityScheme, type SecuritySchemeApiKey, type SecuritySchemeHttp, type SecuritySchemeOAuth2, type SecuritySchemeOAuth2Flow, type SecuritySchemeOpenIdConnect };
1
+ export type * from './index.d.mts'
@@ -1,152 +1,13 @@
1
- //#region src/lib/api/openapi/types.d.ts
2
- type OpenApiSpec = {
3
- openapi: string;
4
- info: {
5
- title: string;
6
- description?: string;
7
- version: string;
8
- };
9
- servers?: Array<{
10
- url: string;
11
- description?: string;
12
- }>;
13
- paths: Record<string, OpenApiPath>;
14
- components?: {
15
- schemas?: Record<string, unknown>;
16
- responses?: Record<string, unknown>;
17
- parameters?: Record<string, unknown>;
18
- requestBodies?: Record<string, unknown>;
19
- securitySchemes?: Record<string, unknown>;
20
- };
21
- };
22
- type OpenApiPath = {
23
- [method: string]: OpenApiOperation;
24
- };
25
- type OpenApiOperation = {
26
- summary?: string;
27
- description?: string;
28
- operationId?: string;
29
- tags?: string[];
30
- parameters?: OpenApiParameter[];
31
- requestBody?: OpenApiRequestBody;
32
- responses: Record<string, OpenApiResponse>;
33
- security?: Array<Record<string, string[]>>;
34
- };
35
- type OpenApiParameter = {
36
- name: string;
37
- in: "path" | "query" | "header" | "cookie";
38
- required?: boolean;
39
- schema: unknown;
40
- description?: string;
41
- };
42
- type OpenApiRequestBody = {
43
- required?: boolean;
44
- content: {
45
- [mediaType: string]: {
46
- schema: unknown;
47
- };
48
- };
49
- };
50
- type OpenApiResponse = {
51
- description: string;
52
- content?: {
53
- [mediaType: string]: {
54
- schema: unknown;
55
- };
56
- };
57
- };
58
- //#endregion
59
- //#region node_modules/@standard-schema/spec/dist/index.d.ts
60
- /** The Standard Typed interface. This is a base type extended by other specs. */
61
- interface StandardTypedV1<Input = unknown, Output = Input> {
62
- /** The Standard properties. */
63
- readonly "~standard": StandardTypedV1.Props<Input, Output>;
64
- }
65
- declare namespace StandardTypedV1 {
66
- /** The Standard Typed properties interface. */
67
- interface Props<Input = unknown, Output = Input> {
68
- /** The version number of the standard. */
69
- readonly version: 1;
70
- /** The vendor name of the schema library. */
71
- readonly vendor: string;
72
- /** Inferred types associated with the schema. */
73
- readonly types?: Types<Input, Output> | undefined;
74
- }
75
- /** The Standard Typed types interface. */
76
- interface Types<Input = unknown, Output = Input> {
77
- /** The input type of the schema. */
78
- readonly input: Input;
79
- /** The output type of the schema. */
80
- readonly output: Output;
81
- }
82
- /** Infers the input type of a Standard Typed. */
83
- type InferInput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["input"];
84
- /** Infers the output type of a Standard Typed. */
85
- type InferOutput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["output"];
86
- }
87
- /** The Standard Schema interface. */
88
- interface StandardSchemaV1<Input = unknown, Output = Input> {
89
- /** The Standard Schema properties. */
90
- readonly "~standard": StandardSchemaV1.Props<Input, Output>;
91
- }
92
- declare namespace StandardSchemaV1 {
93
- /** The Standard Schema properties interface. */
94
- interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
95
- /** Validates unknown input values. */
96
- readonly validate: (value: unknown, options?: StandardSchemaV1.Options | undefined) => Result<Output> | Promise<Result<Output>>;
97
- }
98
- /** The result interface of the validate function. */
99
- type Result<Output> = SuccessResult<Output> | FailureResult;
100
- /** The result interface if validation succeeds. */
101
- interface SuccessResult<Output> {
102
- /** The typed output value. */
103
- readonly value: Output;
104
- /** A falsy value for `issues` indicates success. */
105
- readonly issues?: undefined;
106
- }
107
- interface Options {
108
- /** Explicit support for additional vendor-specific parameters, if needed. */
109
- readonly libraryOptions?: Record<string, unknown> | undefined;
110
- }
111
- /** The result interface if validation fails. */
112
- interface FailureResult {
113
- /** The issues of failed validation. */
114
- readonly issues: ReadonlyArray<Issue>;
115
- }
116
- /** The issue interface of the failure output. */
117
- interface Issue {
118
- /** The error message of the issue. */
119
- readonly message: string;
120
- /** The path of the issue, if any. */
121
- readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
122
- }
123
- /** The path segment interface of the issue. */
124
- interface PathSegment {
125
- /** The key representing a path segment. */
126
- readonly key: PropertyKey;
127
- }
128
- /** The Standard types interface. */
129
- interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {}
130
- /** Infers the input type of a Standard. */
131
- type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
132
- /** Infers the output type of a Standard. */
133
- type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
1
+ import { t as StandardSchemaV1 } from "../../index-DISN0WKZ.mjs";
2
+ //#region src/lib/api/middleware.d.ts
3
+ declare class Middleware<TRequest extends RequestSchema = RequestSchema, TResponse extends ResponseSchema = ResponseSchema, TExtension extends Record<string, unknown> = Record<string, unknown>> {
4
+ options: MiddlewareOptions<TRequest, TResponse, TExtension>;
5
+ constructor(options: MiddlewareOptions<TRequest, TResponse, TExtension>);
134
6
  }
135
- /** The Standard JSON Schema interface. */
136
- //#endregion
137
- //#region src/lib/api/middleware/types.d.ts
138
- type MiddlewareHandler<TReq extends RequestSchema = RequestSchema, TRes extends ResponseSchema | undefined = undefined, TExt extends Record<string, unknown> = Record<never, never>> = (c: Context<TReq, TRes>) => Response | TExt | undefined | Promise<Response | TExt | undefined> | Promise<void> | void;
139
- type MiddlewareOptions<TReq extends RequestSchema = RequestSchema, TRes extends ResponseSchema | undefined = undefined, TExt extends Record<string, unknown> = Record<string, unknown>> = {
140
- request?: TReq;
141
- response?: TRes;
142
- handler: MiddlewareHandler<TReq, TRes, TExt>;
143
- };
144
- type InferMiddlewareExtension<T> = T extends {
145
- options: MiddlewareOptions<infer _TReq, infer _TRes, infer E>;
146
- } ? E : never;
147
- type MergeMiddlewareExtensions<T extends readonly unknown[]> = T extends readonly [infer First, ...infer Rest] ? InferMiddlewareExtension<First> & MergeMiddlewareExtensions<Rest> : {};
148
7
  //#endregion
149
- //#region src/lib/api/core/types.d.ts
8
+ //#region src/lib/api/types.d.ts
9
+ type HTTPMethod = Bun.Serve.HTTPMethod;
10
+ type BunHandler = Bun.Serve.Handler<Bun.BunRequest, Bun.Server<unknown>, Response>;
150
11
  type ResponseSchema = {
151
12
  [status: number]: StandardSchemaV1;
152
13
  };
@@ -174,6 +35,10 @@ type ApiOptions<TMiddlewares extends readonly Middleware[] = readonly []> = {
174
35
  middlewares?: TMiddlewares;
175
36
  validation?: ValidationOptions;
176
37
  };
38
+ type GroupOptions<TMiddlewares extends readonly Middleware[] = readonly []> = {
39
+ prefix?: string;
40
+ middlewares?: TMiddlewares;
41
+ };
177
42
  type SecuritySchemeApiKey = {
178
43
  type: "apiKey";
179
44
  name: string;
@@ -233,39 +98,110 @@ type Context<TReq extends RequestSchema = RequestSchema, TRes extends ResponseSc
233
98
  redirect: (status: number, url: string) => Response;
234
99
  get: <K extends keyof TExt>(key: K) => TExt[K];
235
100
  };
101
+ type RouteReturn = Response | string | number | boolean | null | Record<string, unknown> | unknown[];
236
102
  type RouteHandler<TReq extends RequestSchema = RequestSchema, TRes extends ResponseSchema | undefined = undefined, TExt extends Record<string, unknown> = Record<string, unknown>> = (c: Context<TReq, TRes, TExt>) => Response | Promise<Response>;
103
+ type BareRouteHandler = () => RouteReturn | Promise<RouteReturn>;
104
+ type MethodRoutes = Record<string, Partial<Record<HTTPMethod, BunHandler>>>;
237
105
  type RouteConfig<TReq extends RequestSchema = RequestSchema, TRes extends ResponseSchema | undefined = undefined, TGlobalMiddlewares extends readonly Middleware[] = readonly [], TRouteMiddlewares extends readonly Middleware[] = readonly []> = {
238
106
  path: string;
239
107
  method: Bun.Serve.HTTPMethod;
240
108
  request?: TReq;
241
109
  response?: TRes;
242
110
  middlewares?: TRouteMiddlewares;
243
- handler: RouteHandler<TReq, TRes, MergeMiddlewareExtensions<TGlobalMiddlewares> & MergeMiddlewareExtensions<TRouteMiddlewares>>;
111
+ handler: RouteHandler<TReq, TRes, MergeMiddlewareExtensions<TGlobalMiddlewares> & MergeMiddlewareExtensions<TRouteMiddlewares>> | BareRouteHandler;
244
112
  summary?: string;
245
113
  description?: string;
246
114
  operationId?: string;
247
115
  tags?: string[];
248
116
  };
117
+ type MiddlewareHandler<TReq extends RequestSchema = RequestSchema, TRes extends ResponseSchema | undefined = undefined, TExt extends Record<string, unknown> = Record<never, never>> = (c: Context<TReq, TRes>) => Response | TExt | undefined | Promise<Response | TExt | undefined> | Promise<void> | void;
118
+ type MiddlewareOptions<TReq extends RequestSchema = RequestSchema, TRes extends ResponseSchema | undefined = undefined, TExt extends Record<string, unknown> = Record<string, unknown>> = {
119
+ request?: TReq;
120
+ response?: TRes;
121
+ handler: MiddlewareHandler<TReq, TRes, TExt>;
122
+ };
123
+ type InferMiddlewareExtension<T> = T extends {
124
+ options: MiddlewareOptions<infer _TReq, infer _TRes, infer E>;
125
+ } ? E : never;
126
+ type MergeMiddlewareExtensions<T extends readonly unknown[]> = T extends readonly [infer First, ...infer Rest] ? InferMiddlewareExtension<First> & MergeMiddlewareExtensions<Rest> : {};
127
+ type OpenApiSpec = {
128
+ openapi: string;
129
+ info: {
130
+ title: string;
131
+ description?: string;
132
+ version: string;
133
+ };
134
+ servers?: Array<{
135
+ url: string;
136
+ description?: string;
137
+ }>;
138
+ paths: Record<string, OpenApiPath>;
139
+ components?: {
140
+ schemas?: Record<string, unknown>;
141
+ securitySchemes?: Record<string, unknown>;
142
+ };
143
+ };
144
+ type OpenApiPath = {
145
+ [method: string]: OpenApiOperation;
146
+ };
147
+ type OpenApiOperation = {
148
+ summary?: string;
149
+ description?: string;
150
+ operationId?: string;
151
+ tags?: string[];
152
+ parameters?: OpenApiParameter[];
153
+ requestBody?: OpenApiRequestBody;
154
+ responses: Record<string, OpenApiResponse>;
155
+ };
156
+ type OpenApiParameter = {
157
+ name: string;
158
+ in: "path" | "query" | "header" | "cookie";
159
+ required?: boolean;
160
+ schema: unknown;
161
+ };
162
+ type OpenApiRequestBody = {
163
+ required?: boolean;
164
+ content: {
165
+ [mediaType: string]: {
166
+ schema: unknown;
167
+ };
168
+ };
169
+ };
170
+ type OpenApiResponse = {
171
+ description: string;
172
+ content?: {
173
+ [mediaType: string]: {
174
+ schema: unknown;
175
+ };
176
+ };
177
+ };
249
178
  //#endregion
250
- //#region src/lib/api/middleware/index.d.ts
251
- declare class Middleware<TRequest extends RequestSchema = RequestSchema, TResponse extends ResponseSchema = ResponseSchema, TExtension extends Record<string, unknown> = Record<string, unknown>> {
252
- options: MiddlewareOptions<TRequest, TResponse, TExtension>;
253
- constructor(options: MiddlewareOptions<TRequest, TResponse, TExtension>);
179
+ //#region src/lib/api/group.d.ts
180
+ type InternalRouteConfig = RouteConfig<RequestSchema, ResponseSchema, readonly Middleware[], readonly Middleware[]>;
181
+ declare class Group<TMiddlewares extends readonly Middleware[] = readonly []> {
182
+ protected options: GroupOptions<TMiddlewares>;
183
+ protected routes: InternalRouteConfig[];
184
+ protected groups: Group<readonly Middleware[]>[];
185
+ private parent?;
186
+ constructor(options?: GroupOptions<TMiddlewares>);
187
+ defineRoute<TReq extends RequestSchema = RequestSchema, TRes extends ResponseSchema = ResponseSchema, TRouteMiddlewares extends readonly Middleware[] = readonly []>(config: RouteConfig<TReq, TRes, TMiddlewares, TRouteMiddlewares>): void;
188
+ mount(group: Group<readonly Middleware[]>): void;
189
+ protected onRoutesChanged(): void;
190
+ protected collectRoutes(prefix?: string | undefined, inheritedMiddlewares?: readonly Middleware[]): InternalRouteConfig[];
254
191
  }
255
192
  //#endregion
256
- //#region src/lib/api/core/index.d.ts
257
- declare class Api<TMiddlewares extends readonly Middleware[] = readonly []> {
258
- private options;
259
- private routes;
193
+ //#region src/lib/api/api.d.ts
194
+ declare class Api<TMiddlewares extends readonly Middleware[] = readonly []> extends Group<TMiddlewares> {
195
+ protected options: ApiOptions<TMiddlewares>;
196
+ private compiled?;
197
+ private needsRecompile;
260
198
  constructor(options?: ApiOptions<TMiddlewares>);
261
- private getFullPath;
262
- private validateRequestSchema;
263
- private createContext;
264
- private validateResponseBody;
265
- private buildBunRoutes;
266
- defineRoute<TReq extends RequestSchema = RequestSchema, TRes extends ResponseSchema = ResponseSchema, TRouteMiddlewares extends readonly Middleware[] = readonly []>(config: RouteConfig<TReq, TRes, TMiddlewares, TRouteMiddlewares>): void;
267
- getOpenApiSpec(): Promise<OpenApiSpec>;
199
+ protected onRoutesChanged(): void;
200
+ fetch: (req: Request) => Promise<Response> | Response;
201
+ getRouteHandlers(): MethodRoutes;
202
+ getOpenApiSpec(): OpenApiSpec;
268
203
  serve(port: number, callback?: (server: Bun.Server<unknown>) => void): void;
204
+ private ensureCompiled;
269
205
  }
270
206
  //#endregion
271
- export { Api, type ApiOptions, type Context, type ExtractStatusCodes, type InferInput, type InferMiddlewareExtension, type InferOutput, type MergeMiddlewareExtensions, Middleware, type MiddlewareHandler, type MiddlewareOptions, type OpenApiOptions, type RequestSchema, type ResponseSchema, type RouteConfig, type RouteHandler, type SecurityScheme, type SecuritySchemeApiKey, type SecuritySchemeHttp, type SecuritySchemeOAuth2, type SecuritySchemeOAuth2Flow, type SecuritySchemeOpenIdConnect };
207
+ export { Api, type ApiOptions, type Context, type ExtractStatusCodes, Group, type GroupOptions, type InferInput, type InferMiddlewareExtension, type InferOutput, type MergeMiddlewareExtensions, Middleware, type MiddlewareHandler, type MiddlewareOptions, type OpenApiOptions, type RequestSchema, type ResponseSchema, type RouteConfig, type RouteHandler, type SecurityScheme, type SecuritySchemeApiKey, type SecuritySchemeHttp, type SecuritySchemeOAuth2, type SecuritySchemeOAuth2Flow, type SecuritySchemeOpenIdConnect };