alepha 0.8.1 → 0.9.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.
- package/README.md +47 -17
- package/batch.d.ts +83 -117
- package/bucket.cjs +8 -0
- package/bucket.d.ts +194 -0
- package/bucket.js +1 -0
- package/cache/redis.d.ts +14 -14
- package/cache.d.ts +101 -238
- package/command.d.ts +66 -71
- package/core.d.ts +1003 -851
- package/datetime.d.ts +90 -116
- package/file.d.ts +23 -13
- package/lock/redis.d.ts +11 -11
- package/lock.d.ts +121 -111
- package/package.json +54 -40
- package/postgres.d.ts +218 -393
- package/queue/redis.d.ts +13 -13
- package/queue.d.ts +84 -198
- package/react/auth.d.ts +47 -53
- package/react/head.d.ts +4 -7
- package/react.d.ts +47 -183
- package/redis.d.ts +31 -16
- package/retry.d.ts +70 -59
- package/router.d.ts +9 -9
- package/scheduler.d.ts +54 -93
- package/security.d.ts +95 -276
- package/server/cache.d.ts +22 -28
- package/server/compress.d.ts +16 -7
- package/server/cookies.d.ts +65 -233
- package/server/cors.d.ts +15 -13
- package/server/health.d.ts +23 -23
- package/server/helmet.d.ts +17 -18
- package/server/links.d.ts +108 -88
- package/server/metrics.d.ts +25 -21
- package/server/multipart.d.ts +12 -14
- package/server/proxy.d.ts +22 -17
- package/server/security.cjs +8 -0
- package/server/security.d.ts +90 -0
- package/server/security.js +1 -0
- package/server/static.d.ts +63 -67
- package/server/swagger.d.ts +73 -62
- package/server.d.ts +250 -446
- package/topic/redis.d.ts +25 -24
- package/topic.d.ts +68 -115
package/server.d.ts
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
import * as _alepha_core1 from "alepha";
|
|
2
|
-
import * as
|
|
3
|
-
import * as
|
|
4
|
-
import * as
|
|
2
|
+
import * as _alepha_core0$1 from "alepha";
|
|
3
|
+
import * as _alepha_core5 from "alepha";
|
|
4
|
+
import * as _alepha_core13 from "alepha";
|
|
5
5
|
import * as _alepha_core12 from "alepha";
|
|
6
|
-
import * as
|
|
7
|
-
import * as
|
|
8
|
-
import { Alepha, Async, FileLike, KIND,
|
|
9
|
-
import { JwtProvider, Permission, SecurityProvider, ServiceAccountDescriptor, UserAccountToken } from "alepha/security";
|
|
10
|
-
import * as _alepha_cache2 from "alepha/cache";
|
|
6
|
+
import * as _alepha_core2 from "alepha";
|
|
7
|
+
import * as _alepha_core0 from "alepha";
|
|
8
|
+
import { Alepha, Async, Descriptor, FileLike, KIND, Static, StreamLike, TObject, TSchema } from "alepha";
|
|
11
9
|
import { Readable } from "node:stream";
|
|
12
10
|
import { ReadableStream } from "node:stream/web";
|
|
13
11
|
import { Route, RouterProvider } from "alepha/router";
|
|
12
|
+
import * as _alepha_cache0 from "alepha/cache";
|
|
14
13
|
import { IncomingMessage, ServerResponse as ServerResponse$1 } from "node:http";
|
|
15
14
|
import { DurationLike } from "alepha/datetime";
|
|
16
|
-
import * as
|
|
17
|
-
import * as
|
|
18
|
-
import * as
|
|
19
|
-
import * as
|
|
15
|
+
import * as _sinclair_typebox7 from "@sinclair/typebox";
|
|
16
|
+
import * as _sinclair_typebox33 from "@sinclair/typebox";
|
|
17
|
+
import * as _sinclair_typebox0 from "@sinclair/typebox";
|
|
18
|
+
import * as http0 from "http";
|
|
20
19
|
|
|
21
20
|
//#region src/constants/routeMethods.d.ts
|
|
22
21
|
declare const routeMethods: readonly ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS", "CONNECT", "TRACE"];
|
|
@@ -36,7 +35,7 @@ declare class ServerReply {
|
|
|
36
35
|
}
|
|
37
36
|
//# sourceMappingURL=ServerReply.d.ts.map
|
|
38
37
|
//#endregion
|
|
39
|
-
//#region src/interfaces/
|
|
38
|
+
//#region src/interfaces/ServerRequest.d.ts
|
|
40
39
|
interface RequestConfigSchema {
|
|
41
40
|
body?: TSchema;
|
|
42
41
|
params?: TObject;
|
|
@@ -62,20 +61,15 @@ interface ServerRequest<TConfig extends RequestConfigSchema = RequestConfigSchem
|
|
|
62
61
|
res: ServerResponse$1;
|
|
63
62
|
};
|
|
64
63
|
};
|
|
65
|
-
user: UserAccountToken;
|
|
66
64
|
}
|
|
67
65
|
interface ServerRoute<TConfig extends RequestConfigSchema = RequestConfigSchema> extends Route {
|
|
68
|
-
method?: RouteMethod;
|
|
69
66
|
handler: ServerHandler<TConfig>;
|
|
67
|
+
method?: RouteMethod;
|
|
70
68
|
schema?: TConfig;
|
|
71
69
|
/**
|
|
72
70
|
* @see ServerLoggerProvider
|
|
73
71
|
*/
|
|
74
72
|
silent?: boolean;
|
|
75
|
-
/**
|
|
76
|
-
* @see ServerSecurityProvider
|
|
77
|
-
*/
|
|
78
|
-
secure?: ServerRouteSecure;
|
|
79
73
|
}
|
|
80
74
|
type ServerResponseBody<TConfig extends RequestConfigSchema = RequestConfigSchema> = TConfig["response"] extends TSchema ? Static<TConfig["response"]> : ResponseBodyType;
|
|
81
75
|
type ResponseKind = "json" | "text" | "void" | "file" | "any";
|
|
@@ -87,7 +81,7 @@ interface ServerResponse {
|
|
|
87
81
|
headers: Record<string, string>;
|
|
88
82
|
status: number;
|
|
89
83
|
}
|
|
90
|
-
interface
|
|
84
|
+
interface ServerRouteMatcher extends Route {
|
|
91
85
|
handler: (request: ServerRawRequest) => Promise<ServerResponse>;
|
|
92
86
|
}
|
|
93
87
|
interface ServerRawRequest {
|
|
@@ -103,39 +97,53 @@ interface ServerRawRequest {
|
|
|
103
97
|
};
|
|
104
98
|
};
|
|
105
99
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
100
|
+
//# sourceMappingURL=ServerRequest.d.ts.map
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region src/providers/ServerProvider.d.ts
|
|
103
|
+
declare abstract class ServerProvider {
|
|
104
|
+
protected readonly alepha: Alepha;
|
|
105
|
+
abstract get hostname(): string;
|
|
106
|
+
protected isViteNotFound(url?: string, route?: Route, params?: Record<string, string>): boolean;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=ServerProvider.d.ts.map
|
|
109
|
+
|
|
113
110
|
//#endregion
|
|
114
|
-
//#region src/
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
111
|
+
//#region src/providers/ServerRouterProvider.d.ts
|
|
112
|
+
/**
|
|
113
|
+
* Main router for all routes on the server side.
|
|
114
|
+
*
|
|
115
|
+
* - $route => generic route
|
|
116
|
+
* - $action => action route (for API calls)
|
|
117
|
+
* - $page => React route (for SSR)
|
|
118
|
+
*/
|
|
119
|
+
declare class ServerRouterProvider extends RouterProvider<ServerRouteMatcher> {
|
|
120
|
+
protected readonly alepha: Alepha;
|
|
121
|
+
protected readonly routes: ServerRoute[];
|
|
122
|
+
getRoutes(): ServerRoute[];
|
|
123
|
+
createRoute<TConfig extends RequestConfigSchema = RequestConfigSchema>(route: ServerRoute<TConfig>): void;
|
|
124
|
+
onRequest(route: ServerRoute, rawRequest: ServerRawRequest, responseKind: ResponseKind): Promise<ServerResponse>;
|
|
125
|
+
protected processRequest(request: ServerRequest, route: ServerRoute, responseKind: ResponseKind): Promise<{
|
|
126
|
+
status: number;
|
|
127
|
+
headers: Record<string, string> & {
|
|
128
|
+
"set-cookie"?: string[];
|
|
129
|
+
};
|
|
130
|
+
body: any;
|
|
131
|
+
}>;
|
|
132
|
+
protected runRouteHandler(route: ServerRoute, request: ServerRequest, responseKind: ResponseKind): Promise<void>;
|
|
133
|
+
protected getResponseType(schema?: RequestConfigSchema): ResponseKind;
|
|
134
|
+
protected errorHandler(route: ServerRoute, request: ServerRequest, error: Error): Promise<void>;
|
|
135
|
+
validateRequest(route: {
|
|
125
136
|
schema?: RequestConfigSchema;
|
|
126
|
-
}):
|
|
127
|
-
|
|
128
|
-
protected short(name: string): string;
|
|
129
|
-
fetchLinks(_url: string): void;
|
|
137
|
+
}, request: ServerRequestConfig): void;
|
|
138
|
+
serializeResponse(route: ServerRoute, reply: ServerReply, responseKind: ResponseKind): void;
|
|
130
139
|
}
|
|
131
|
-
//# sourceMappingURL=
|
|
140
|
+
//# sourceMappingURL=ServerRouterProvider.d.ts.map
|
|
132
141
|
//#endregion
|
|
133
142
|
//#region src/services/HttpClient.d.ts
|
|
134
143
|
declare class HttpClient {
|
|
135
144
|
protected readonly log: _alepha_core1.Logger;
|
|
136
145
|
protected readonly alepha: Alepha;
|
|
137
|
-
|
|
138
|
-
readonly cache: _alepha_cache2.CacheDescriptor<HttpClientCache, any[]>;
|
|
146
|
+
readonly cache: _alepha_cache0.CacheDescriptorFn<HttpClientCache, any[]>;
|
|
139
147
|
protected readonly pendingRequests: HttpClientPendingRequests;
|
|
140
148
|
clear(): Promise<void>;
|
|
141
149
|
fetchAction(args: FetchActionArgs): Promise<FetchResponse>;
|
|
@@ -204,43 +212,69 @@ interface HttpAction {
|
|
|
204
212
|
}
|
|
205
213
|
//#endregion
|
|
206
214
|
//#region src/descriptors/$action.d.ts
|
|
207
|
-
|
|
215
|
+
/**
|
|
216
|
+
* Create an action endpoint.
|
|
217
|
+
*
|
|
218
|
+
* By default, all actions are prefixed by `/api`.
|
|
219
|
+
* If `name` is not provided, the action will be named after the property key.
|
|
220
|
+
* If `path` is not provided, the action will be named after the function name.
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* ```ts
|
|
224
|
+
* class MyController {
|
|
225
|
+
* hello = $action({
|
|
226
|
+
* handler: () => "Hello World",
|
|
227
|
+
* })
|
|
228
|
+
* }
|
|
229
|
+
* // GET /api/hello -> "Hello World"
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
208
232
|
declare const $action: {
|
|
209
233
|
<TConfig extends RequestConfigSchema>(options: ActionDescriptorOptions<TConfig>): ActionDescriptor<TConfig>;
|
|
210
|
-
[KIND]:
|
|
234
|
+
[KIND]: typeof ActionDescriptor;
|
|
211
235
|
};
|
|
212
|
-
interface ActionDescriptorOptions<TConfig extends RequestConfigSchema
|
|
236
|
+
interface ActionDescriptorOptions<TConfig extends RequestConfigSchema> extends Omit<ServerRoute, "handler" | "path" | "schema" | "mapParams"> {
|
|
213
237
|
/**
|
|
214
|
-
* Name the
|
|
238
|
+
* Name of the action.
|
|
239
|
+
*
|
|
240
|
+
* - It will be used to generate the route path if `path` is not provided.
|
|
241
|
+
* - It will be used to generate the permission name if `security` is enabled.
|
|
215
242
|
*/
|
|
216
243
|
name?: string;
|
|
217
244
|
/**
|
|
218
|
-
*
|
|
245
|
+
* Group actions together.
|
|
219
246
|
*
|
|
220
|
-
*
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
*
|
|
247
|
+
* - If not provided, the service name containing the route will be used.
|
|
248
|
+
* - It will be used as Tag for documentation purposes.
|
|
249
|
+
* - It will be used for permission name generation if `security` is enabled.
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* ```ts
|
|
253
|
+
* // group = "MyController"
|
|
254
|
+
* class MyController {
|
|
255
|
+
* hello = $action({ handler: () => "Hello World" });
|
|
256
|
+
* }
|
|
225
257
|
*
|
|
226
|
-
*
|
|
227
|
-
*
|
|
258
|
+
* // group = "users"
|
|
259
|
+
* class MyOtherController {
|
|
260
|
+
* group = "users";
|
|
261
|
+
* a1 = $action({ handler: () => "Action 1", group: this.group });
|
|
262
|
+
* a2 = $action({ handler: () => "Action 2", group: this.group });
|
|
263
|
+
* }
|
|
264
|
+
* ```
|
|
228
265
|
*/
|
|
229
|
-
|
|
266
|
+
group?: string;
|
|
230
267
|
/**
|
|
231
|
-
* Pathname of the route.
|
|
268
|
+
* Pathname of the route. If not provided, property key is used.
|
|
232
269
|
*/
|
|
233
270
|
path?: string;
|
|
234
|
-
/**
|
|
235
|
-
* Inherit options from another route.
|
|
236
|
-
*/
|
|
237
|
-
use?: {
|
|
238
|
-
[OPTIONS]: ActionDescriptorOptions<TConfig>;
|
|
239
|
-
};
|
|
240
271
|
/**
|
|
241
272
|
* The route method.
|
|
242
273
|
*
|
|
243
|
-
*
|
|
274
|
+
* - If not provided, it will be set to "GET" by default.
|
|
275
|
+
* - If not provider and a body is provided, it will be set to "POST".
|
|
276
|
+
*
|
|
277
|
+
* Wildcard methods are not supported for now. (e.g. "ALL", "ANY", etc.)
|
|
244
278
|
*/
|
|
245
279
|
method?: RouteMethod;
|
|
246
280
|
/**
|
|
@@ -252,66 +286,87 @@ interface ActionDescriptorOptions<TConfig extends RequestConfigSchema = RequestC
|
|
|
252
286
|
*/
|
|
253
287
|
schema?: TConfig;
|
|
254
288
|
/**
|
|
255
|
-
*
|
|
256
|
-
*/
|
|
257
|
-
summary?: string;
|
|
258
|
-
/**
|
|
259
|
-
* Long description of the route.
|
|
289
|
+
* A short description of the action. Used for documentation purposes.
|
|
260
290
|
*/
|
|
261
291
|
description?: string;
|
|
262
292
|
/**
|
|
263
293
|
* Disable the route. Useful with env variables do disable one specific route.
|
|
294
|
+
* Route won't be available in the API but can still be called locally!
|
|
264
295
|
*/
|
|
265
296
|
disabled?: boolean;
|
|
266
|
-
/**
|
|
267
|
-
* Mark the route as private.
|
|
268
|
-
* - It won't be exposed in the API documentation.
|
|
269
|
-
* - It won't be exposed in _links.
|
|
270
|
-
*/
|
|
271
|
-
internal?: boolean;
|
|
272
297
|
/**
|
|
273
298
|
* Main route handler. This is where the route logic is implemented.
|
|
274
299
|
*/
|
|
275
|
-
handler
|
|
300
|
+
handler: ServerActionHandler<TConfig>;
|
|
276
301
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
302
|
+
declare class ActionDescriptor<TConfig extends RequestConfigSchema> extends Descriptor<ActionDescriptorOptions<TConfig>> {
|
|
303
|
+
protected readonly log: _alepha_core0$1.Logger;
|
|
304
|
+
protected readonly env: {
|
|
305
|
+
SERVER_API_PREFIX: string;
|
|
306
|
+
};
|
|
307
|
+
protected readonly httpClient: HttpClient;
|
|
308
|
+
protected readonly serverProvider: ServerProvider;
|
|
309
|
+
protected readonly serverRouterProvider: ServerRouterProvider;
|
|
310
|
+
protected onInit(): void;
|
|
311
|
+
get prefix(): string;
|
|
312
|
+
get route(): ServerRoute;
|
|
313
|
+
/**
|
|
314
|
+
* Returns the name of the action.
|
|
315
|
+
*/
|
|
316
|
+
get name(): string;
|
|
280
317
|
/**
|
|
281
|
-
*
|
|
318
|
+
* Returns the group of the action. (e.g. "orders", "admin", etc.)
|
|
282
319
|
*/
|
|
283
|
-
(
|
|
320
|
+
get group(): string;
|
|
284
321
|
/**
|
|
285
|
-
*
|
|
322
|
+
* Returns the HTTP method of the action.
|
|
323
|
+
*/
|
|
324
|
+
get method(): RouteMethod;
|
|
325
|
+
/**
|
|
326
|
+
* Returns the path of the action.
|
|
327
|
+
*
|
|
328
|
+
* Path is prefixed by `/api` by default.
|
|
286
329
|
*/
|
|
287
|
-
|
|
330
|
+
get path(): string;
|
|
331
|
+
get schema(): TConfig | undefined;
|
|
332
|
+
getBodyContentType(): string | undefined;
|
|
288
333
|
/**
|
|
289
|
-
*
|
|
334
|
+
* Call the action handler directly.
|
|
335
|
+
* There is no HTTP layer involved.
|
|
290
336
|
*/
|
|
291
|
-
|
|
337
|
+
run(config: ClientRequestEntry<TConfig>, options?: ClientRequestOptions): Promise<ClientRequestResponse<TConfig>>;
|
|
338
|
+
/**
|
|
339
|
+
* Works like `run`, but always fetches (http request) the route.
|
|
340
|
+
*/
|
|
341
|
+
fetch(config?: ClientRequestEntry<TConfig>, options?: ClientRequestOptions): Promise<FetchResponse<ClientRequestResponse<TConfig>>>;
|
|
292
342
|
}
|
|
293
|
-
type ClientRequestEntry<TConfig extends RequestConfigSchema
|
|
294
|
-
type ClientRequestEntryContainer<TConfig extends RequestConfigSchema
|
|
343
|
+
type ClientRequestEntry<TConfig extends RequestConfigSchema, T = ClientRequestEntryContainer<TConfig>> = { [K in keyof T as T[K] extends undefined ? never : K]: T[K] };
|
|
344
|
+
type ClientRequestEntryContainer<TConfig extends RequestConfigSchema> = {
|
|
295
345
|
body: TConfig["body"] extends TSchema ? Static<TConfig["body"]> : undefined;
|
|
296
346
|
params: TConfig["params"] extends TSchema ? Static<TConfig["params"]> : undefined;
|
|
297
347
|
headers?: TConfig["headers"] extends TSchema ? Static<TConfig["headers"]> : undefined;
|
|
298
348
|
query?: TConfig["query"] extends TSchema ? Partial<Static<TConfig["query"]>> : undefined;
|
|
299
349
|
};
|
|
300
350
|
interface ClientRequestOptions extends FetchOptions {
|
|
301
|
-
/**
|
|
302
|
-
* Forward user from the previous request.
|
|
303
|
-
* If "system", use system user. @see {ServerSecurityProvider.localSystemUser}
|
|
304
|
-
* If "context", use the user from the current context (e.g. request).
|
|
305
|
-
*
|
|
306
|
-
* @default "system" is provided, else "context" is used.
|
|
307
|
-
*/
|
|
308
|
-
user?: UserAccountToken | "system" | "context";
|
|
309
351
|
/**
|
|
310
352
|
* Standard request fetch options.
|
|
311
353
|
*/
|
|
312
354
|
request?: RequestInit;
|
|
313
355
|
}
|
|
314
356
|
type ClientRequestResponse<TConfig extends RequestConfigSchema> = TConfig["response"] extends TSchema ? Static<TConfig["response"]> : any;
|
|
357
|
+
/**
|
|
358
|
+
* Specific handler for server actions.
|
|
359
|
+
*/
|
|
360
|
+
type ServerActionHandler<TConfig extends RequestConfigSchema = RequestConfigSchema> = (request: ServerActionRequest<TConfig>) => Async<ServerResponseBody<TConfig>>;
|
|
361
|
+
/**
|
|
362
|
+
* Server Action Request Interface
|
|
363
|
+
*
|
|
364
|
+
* Can be extended with module augmentation to add custom properties (like `user` in Server Security).
|
|
365
|
+
*
|
|
366
|
+
* This is NOT Server Request, but a specific type for actions.
|
|
367
|
+
*/
|
|
368
|
+
interface ServerActionRequest<TConfig extends RequestConfigSchema> extends ServerRequest<TConfig> {}
|
|
369
|
+
//# sourceMappingURL=$action.d.ts.map
|
|
315
370
|
//#endregion
|
|
316
371
|
//#region src/errors/HttpError.d.ts
|
|
317
372
|
declare class HttpError extends Error {
|
|
@@ -353,16 +408,24 @@ interface HttpErrorLike extends Error {
|
|
|
353
408
|
//# sourceMappingURL=HttpError.d.ts.map
|
|
354
409
|
//#endregion
|
|
355
410
|
//#region src/descriptors/$route.d.ts
|
|
356
|
-
|
|
411
|
+
/**
|
|
412
|
+
* Create a basic endpoint.
|
|
413
|
+
*
|
|
414
|
+
* It's a low level descriptor. You probably want to use `$action` instead.
|
|
415
|
+
*
|
|
416
|
+
* @see {@link $action}
|
|
417
|
+
* @see {@link $page}
|
|
418
|
+
*/
|
|
357
419
|
declare const $route: {
|
|
358
|
-
<TConfig extends RequestConfigSchema
|
|
359
|
-
[KIND]:
|
|
420
|
+
<TConfig extends RequestConfigSchema>(options: RouteDescriptorOptions<TConfig>): RouteDescriptor<TConfig>;
|
|
421
|
+
[KIND]: typeof RouteDescriptor;
|
|
360
422
|
};
|
|
361
423
|
interface RouteDescriptorOptions<TConfig extends RequestConfigSchema = RequestConfigSchema> extends ServerRoute<TConfig> {}
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
}
|
|
424
|
+
declare class RouteDescriptor<TConfig extends RequestConfigSchema> extends Descriptor<RouteDescriptorOptions<TConfig>> {
|
|
425
|
+
protected readonly serverRouterProvider: ServerRouterProvider;
|
|
426
|
+
protected onInit(): void;
|
|
427
|
+
}
|
|
428
|
+
//# sourceMappingURL=$route.d.ts.map
|
|
366
429
|
//#endregion
|
|
367
430
|
//#region src/errors/BadRequestError.d.ts
|
|
368
431
|
declare class BadRequestError extends HttpError {
|
|
@@ -400,24 +463,30 @@ declare class ValidationError extends HttpError {
|
|
|
400
463
|
}
|
|
401
464
|
//# sourceMappingURL=ValidationError.d.ts.map
|
|
402
465
|
//#endregion
|
|
466
|
+
//#region src/helpers/isMultipart.d.ts
|
|
467
|
+
declare const isMultipart: (options: {
|
|
468
|
+
schema?: RequestConfigSchema;
|
|
469
|
+
}) => boolean;
|
|
470
|
+
//# sourceMappingURL=isMultipart.d.ts.map
|
|
471
|
+
//#endregion
|
|
403
472
|
//#region src/schemas/apiLinksResponseSchema.d.ts
|
|
404
|
-
declare const apiLinkSchema:
|
|
405
|
-
name:
|
|
406
|
-
path:
|
|
407
|
-
method:
|
|
408
|
-
group:
|
|
409
|
-
requestBodyType:
|
|
410
|
-
service:
|
|
473
|
+
declare const apiLinkSchema: _sinclair_typebox7.TObject<{
|
|
474
|
+
name: _sinclair_typebox7.TString;
|
|
475
|
+
path: _sinclair_typebox7.TString;
|
|
476
|
+
method: _sinclair_typebox7.TOptional<_sinclair_typebox7.TString>;
|
|
477
|
+
group: _sinclair_typebox7.TOptional<_sinclair_typebox7.TString>;
|
|
478
|
+
requestBodyType: _sinclair_typebox7.TOptional<_sinclair_typebox7.TString>;
|
|
479
|
+
service: _sinclair_typebox7.TOptional<_sinclair_typebox7.TString>;
|
|
411
480
|
}>;
|
|
412
|
-
declare const apiLinksResponseSchema:
|
|
413
|
-
prefix:
|
|
414
|
-
links:
|
|
415
|
-
name:
|
|
416
|
-
path:
|
|
417
|
-
method:
|
|
418
|
-
group:
|
|
419
|
-
requestBodyType:
|
|
420
|
-
service:
|
|
481
|
+
declare const apiLinksResponseSchema: _sinclair_typebox7.TObject<{
|
|
482
|
+
prefix: _sinclair_typebox7.TOptional<_sinclair_typebox7.TString>;
|
|
483
|
+
links: _sinclair_typebox7.TArray<_sinclair_typebox7.TObject<{
|
|
484
|
+
name: _sinclair_typebox7.TString;
|
|
485
|
+
path: _sinclair_typebox7.TString;
|
|
486
|
+
method: _sinclair_typebox7.TOptional<_sinclair_typebox7.TString>;
|
|
487
|
+
group: _sinclair_typebox7.TOptional<_sinclair_typebox7.TString>;
|
|
488
|
+
requestBodyType: _sinclair_typebox7.TOptional<_sinclair_typebox7.TString>;
|
|
489
|
+
service: _sinclair_typebox7.TOptional<_sinclair_typebox7.TString>;
|
|
421
490
|
}>>;
|
|
422
491
|
}>;
|
|
423
492
|
type ApiLinksResponse = Static<typeof apiLinksResponseSchema>;
|
|
@@ -425,38 +494,66 @@ type ApiLink = Static<typeof apiLinkSchema>;
|
|
|
425
494
|
//# sourceMappingURL=apiLinksResponseSchema.d.ts.map
|
|
426
495
|
//#endregion
|
|
427
496
|
//#region src/schemas/errorSchema.d.ts
|
|
428
|
-
declare const errorSchema:
|
|
429
|
-
error:
|
|
430
|
-
status:
|
|
431
|
-
message:
|
|
432
|
-
details:
|
|
433
|
-
cause:
|
|
434
|
-
name:
|
|
435
|
-
message:
|
|
497
|
+
declare const errorSchema: _sinclair_typebox33.TObject<{
|
|
498
|
+
error: _sinclair_typebox33.TString;
|
|
499
|
+
status: _sinclair_typebox33.TNumber;
|
|
500
|
+
message: _sinclair_typebox33.TString;
|
|
501
|
+
details: _sinclair_typebox33.TOptional<_sinclair_typebox33.TString>;
|
|
502
|
+
cause: _sinclair_typebox33.TOptional<_sinclair_typebox33.TObject<{
|
|
503
|
+
name: _sinclair_typebox33.TString;
|
|
504
|
+
message: _sinclair_typebox33.TString;
|
|
436
505
|
}>>;
|
|
437
506
|
}>;
|
|
438
507
|
//# sourceMappingURL=errorSchema.d.ts.map
|
|
439
508
|
//#endregion
|
|
440
509
|
//#region src/schemas/okSchema.d.ts
|
|
441
|
-
declare const okSchema:
|
|
442
|
-
ok:
|
|
443
|
-
id:
|
|
444
|
-
count:
|
|
510
|
+
declare const okSchema: _sinclair_typebox0.TObject<{
|
|
511
|
+
ok: _sinclair_typebox0.TBoolean;
|
|
512
|
+
id: _sinclair_typebox0.TOptional<_sinclair_typebox0.TUnion<[_sinclair_typebox0.TString, _sinclair_typebox0.TInteger]>>;
|
|
513
|
+
count: _sinclair_typebox0.TOptional<_sinclair_typebox0.TNumber>;
|
|
445
514
|
}>;
|
|
446
515
|
type Ok = Static<typeof okSchema>;
|
|
447
516
|
//# sourceMappingURL=okSchema.d.ts.map
|
|
448
517
|
//#endregion
|
|
449
|
-
//#region src/providers/
|
|
518
|
+
//#region src/providers/NodeHttpServerProvider.d.ts
|
|
519
|
+
declare const envSchema: _alepha_core5.TObject<{
|
|
520
|
+
SERVER_PORT: _alepha_core5.TNumber;
|
|
521
|
+
SERVER_HOST: _alepha_core5.TString;
|
|
522
|
+
}>;
|
|
523
|
+
declare module "alepha" {
|
|
524
|
+
interface Env extends Partial<Static<typeof envSchema>> {}
|
|
525
|
+
}
|
|
526
|
+
declare class NodeHttpServerProvider extends ServerProvider {
|
|
527
|
+
protected readonly alepha: Alepha;
|
|
528
|
+
protected readonly log: _alepha_core5.Logger;
|
|
529
|
+
protected readonly env: {
|
|
530
|
+
SERVER_PORT: number;
|
|
531
|
+
SERVER_HOST: string;
|
|
532
|
+
};
|
|
533
|
+
protected readonly router: ServerRouterProvider;
|
|
534
|
+
protected readonly server: http0.Server<typeof IncomingMessage, typeof ServerResponse$1>;
|
|
535
|
+
protected readonly onNodeRequest: _alepha_core5.HookDescriptor<"node:request">;
|
|
536
|
+
handle(req: IncomingMessage, res: ServerResponse$1): Promise<void>;
|
|
537
|
+
createRouterRequest(req: IncomingMessage, res: ServerResponse$1, params?: Record<string, string>): ServerRawRequest;
|
|
538
|
+
getProtocol(req: IncomingMessage): "http" | "https";
|
|
539
|
+
get hostname(): string;
|
|
540
|
+
readonly start: _alepha_core5.HookDescriptor<"start">;
|
|
541
|
+
protected readonly stop: _alepha_core5.HookDescriptor<"stop">;
|
|
542
|
+
protected listen(): Promise<void>;
|
|
543
|
+
protected close(): Promise<void>;
|
|
544
|
+
}
|
|
545
|
+
//#endregion
|
|
546
|
+
//#region src/providers/ServerLoggerProvider.d.ts
|
|
450
547
|
declare class ServerLoggerProvider {
|
|
451
|
-
protected readonly log:
|
|
548
|
+
protected readonly log: _alepha_core13.Logger;
|
|
452
549
|
protected readonly alepha: Alepha;
|
|
453
|
-
readonly onRequest:
|
|
454
|
-
readonly onError:
|
|
455
|
-
readonly onResponse:
|
|
550
|
+
readonly onRequest: _alepha_core13.HookDescriptor<"server:onRequest">;
|
|
551
|
+
readonly onError: _alepha_core13.HookDescriptor<"server:onError">;
|
|
552
|
+
readonly onResponse: _alepha_core13.HookDescriptor<"server:onResponse">;
|
|
456
553
|
}
|
|
457
554
|
//# sourceMappingURL=ServerLoggerProvider.d.ts.map
|
|
458
555
|
//#endregion
|
|
459
|
-
//#region src/providers/
|
|
556
|
+
//#region src/providers/ServerNotReadyProvider.d.ts
|
|
460
557
|
/**
|
|
461
558
|
* On every request, this provider checks if the server is ready.
|
|
462
559
|
*
|
|
@@ -466,182 +563,30 @@ declare class ServerLoggerProvider {
|
|
|
466
563
|
*/
|
|
467
564
|
declare class ServerNotReadyProvider {
|
|
468
565
|
protected readonly alepha: Alepha;
|
|
469
|
-
readonly onRequest:
|
|
566
|
+
readonly onRequest: _alepha_core12.HookDescriptor<"server:onRequest">;
|
|
470
567
|
}
|
|
471
568
|
//# sourceMappingURL=ServerNotReadyProvider.d.ts.map
|
|
472
569
|
//#endregion
|
|
473
|
-
//#region src/providers/
|
|
474
|
-
declare class ServerSecurityProvider {
|
|
475
|
-
protected readonly log: _alepha_core8.Logger;
|
|
476
|
-
protected readonly securityProvider: SecurityProvider;
|
|
477
|
-
protected readonly jwtProvider: JwtProvider;
|
|
478
|
-
protected readonly alepha: Alepha;
|
|
479
|
-
readonly onClientRequest: _alepha_core8.HookDescriptor<"client:onRequest">;
|
|
480
|
-
protected readonly onRequest: _alepha_core8.HookDescriptor<"server:onRequest">;
|
|
481
|
-
protected readonly onRoute: _alepha_core8.HookDescriptor<"server:onRoute">;
|
|
482
|
-
}
|
|
483
|
-
//# sourceMappingURL=ServerSecurityProvider.d.ts.map
|
|
484
|
-
//#endregion
|
|
485
|
-
//#region src/providers/features/ServerTimingProvider.d.ts
|
|
570
|
+
//#region src/providers/ServerTimingProvider.d.ts
|
|
486
571
|
type TimingMap = Record<string, [number, number]>;
|
|
487
572
|
declare class ServerTimingProvider {
|
|
488
|
-
protected readonly log:
|
|
573
|
+
protected readonly log: _alepha_core2.Logger;
|
|
489
574
|
protected readonly alepha: Alepha;
|
|
490
|
-
readonly onRequest:
|
|
491
|
-
readonly onResponse:
|
|
575
|
+
readonly onRequest: _alepha_core2.HookDescriptor<"server:onRequest">;
|
|
576
|
+
readonly onResponse: _alepha_core2.HookDescriptor<"server:onResponse">;
|
|
492
577
|
protected get handlerName(): string;
|
|
493
578
|
beginTiming(name: string): void;
|
|
494
579
|
endTiming(name: string): void;
|
|
495
580
|
protected setDuration(name: string, timing: TimingMap): void;
|
|
496
581
|
}
|
|
497
582
|
//#endregion
|
|
498
|
-
//#region src/providers/ServerRouterProvider.d.ts
|
|
499
|
-
/**
|
|
500
|
-
* Main router for all routes on the server side.
|
|
501
|
-
*
|
|
502
|
-
* - $route => generic route
|
|
503
|
-
* - $action => action route (for API calls)
|
|
504
|
-
* - $page => React route (for SSR)
|
|
505
|
-
*/
|
|
506
|
-
declare class ServerRouterProvider extends RouterProvider<ServerRouteWithHandler> {
|
|
507
|
-
protected readonly alepha: Alepha;
|
|
508
|
-
route<TConfig extends RequestConfigSchema = RequestConfigSchema>(route: ServerRoute<TConfig>): Promise<void>;
|
|
509
|
-
onRequest(route: ServerRoute, rawRequest: ServerRawRequest, responseKind: ResponseKind): Promise<ServerResponse>;
|
|
510
|
-
protected processRequest(request: ServerRequest, route: ServerRoute, responseKind: ResponseKind): Promise<{
|
|
511
|
-
status: number;
|
|
512
|
-
headers: Record<string, string> & {
|
|
513
|
-
"set-cookie"?: string[];
|
|
514
|
-
};
|
|
515
|
-
body: any;
|
|
516
|
-
}>;
|
|
517
|
-
protected runRouteHandler(route: ServerRoute, request: ServerRequest, responseKind: ResponseKind): Promise<void>;
|
|
518
|
-
protected getResponseType(schema?: RequestConfigSchema): ResponseKind;
|
|
519
|
-
protected errorHandler(route: ServerRoute, request: ServerRequest, error: Error): Promise<void>;
|
|
520
|
-
validateRequest(route: {
|
|
521
|
-
schema?: RequestConfigSchema;
|
|
522
|
-
}, request: ServerRequestConfig): void;
|
|
523
|
-
serializeResponse(route: ServerRoute, reply: ServerReply, responseKind: ResponseKind): void;
|
|
524
|
-
}
|
|
525
|
-
//# sourceMappingURL=ServerRouterProvider.d.ts.map
|
|
526
|
-
//#endregion
|
|
527
|
-
//#region src/providers/platforms/ServerProvider.d.ts
|
|
528
|
-
declare abstract class ServerProvider {
|
|
529
|
-
protected readonly alepha: Alepha;
|
|
530
|
-
abstract get hostname(): string;
|
|
531
|
-
protected isViteNotFound(url?: string, route?: Route, params?: Record<string, string>): boolean;
|
|
532
|
-
}
|
|
533
|
-
//# sourceMappingURL=ServerProvider.d.ts.map
|
|
534
|
-
//#endregion
|
|
535
|
-
//#region src/providers/platforms/NodeHttpServerProvider.d.ts
|
|
536
|
-
declare const envSchema$1: _alepha_core15.TObject<{
|
|
537
|
-
SERVER_PORT: _alepha_core15.TNumber;
|
|
538
|
-
SERVER_HOST: _alepha_core15.TString;
|
|
539
|
-
}>;
|
|
540
|
-
declare module "alepha" {
|
|
541
|
-
interface Env extends Partial<Static<typeof envSchema$1>> {}
|
|
542
|
-
}
|
|
543
|
-
declare class NodeHttpServerProvider extends ServerProvider {
|
|
544
|
-
protected readonly alepha: Alepha;
|
|
545
|
-
protected readonly log: _alepha_core15.Logger;
|
|
546
|
-
protected readonly env: {
|
|
547
|
-
SERVER_PORT: number;
|
|
548
|
-
SERVER_HOST: string;
|
|
549
|
-
};
|
|
550
|
-
protected readonly router: ServerRouterProvider;
|
|
551
|
-
protected readonly server: http20.Server<typeof IncomingMessage, typeof ServerResponse$1>;
|
|
552
|
-
protected readonly onNodeRequest: _alepha_core15.HookDescriptor<"node:request">;
|
|
553
|
-
handle(req: IncomingMessage, res: ServerResponse$1): Promise<void>;
|
|
554
|
-
createRouterRequest(req: IncomingMessage, res: ServerResponse$1, params?: Record<string, string>): ServerRawRequest;
|
|
555
|
-
getProtocol(req: IncomingMessage): "http" | "https";
|
|
556
|
-
get hostname(): string;
|
|
557
|
-
readonly start: _alepha_core15.HookDescriptor<"start">;
|
|
558
|
-
protected readonly stop: _alepha_core15.HookDescriptor<"stop">;
|
|
559
|
-
protected listen(): Promise<void>;
|
|
560
|
-
protected close(): Promise<void>;
|
|
561
|
-
}
|
|
562
|
-
//#endregion
|
|
563
|
-
//#region src/providers/ServerActionDescriptorProvider.d.ts
|
|
564
|
-
declare const envSchema: _alepha_core24.TObject<{
|
|
565
|
-
SERVER_API_PREFIX: _alepha_core24.TString;
|
|
566
|
-
SERVER_SECURITY_ENABLED: _alepha_core24.TBoolean;
|
|
567
|
-
}>;
|
|
568
|
-
declare module "alepha" {
|
|
569
|
-
interface Env extends Partial<Static<typeof envSchema>> {}
|
|
570
|
-
interface State {
|
|
571
|
-
/**
|
|
572
|
-
* Real (or fake) user account, used for internal actions.
|
|
573
|
-
* If you define this, you assume that all actions are executed by this user by default.
|
|
574
|
-
* And to force a different user, you need to pass it explicitly in the options.
|
|
575
|
-
*/
|
|
576
|
-
"ServerSecurityProvider.localSystemUser"?: UserAccountToken;
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
declare class ServerActionDescriptorProvider {
|
|
580
|
-
protected readonly log: _alepha_core24.Logger;
|
|
581
|
-
protected readonly alepha: Alepha;
|
|
582
|
-
protected readonly env: {
|
|
583
|
-
SERVER_API_PREFIX: string;
|
|
584
|
-
SERVER_SECURITY_ENABLED: boolean;
|
|
585
|
-
};
|
|
586
|
-
protected readonly client: HttpClient;
|
|
587
|
-
protected readonly serverProvider: ServerProvider;
|
|
588
|
-
protected readonly helper: ActionDescriptorHelper;
|
|
589
|
-
protected readonly routerProvider: ServerRouterProvider;
|
|
590
|
-
protected readonly actions: ServerRouteAction[];
|
|
591
|
-
getActions(): ServerRouteAction<RequestConfigSchema>[];
|
|
592
|
-
getPrefix(): string;
|
|
593
|
-
readonly configure: _alepha_core24.HookDescriptor<"configure">;
|
|
594
|
-
registerAction(value: ActionDescriptor, key: string, instance: any, prefix?: string): Promise<void>;
|
|
595
|
-
/**
|
|
596
|
-
* Check a mock function for the specified route.
|
|
597
|
-
*
|
|
598
|
-
* This is mostly used for testing purposes.
|
|
599
|
-
*/
|
|
600
|
-
protected createLocalHandler(action: ActionDescriptorOptions, permission: Permission): (config?: ServerRequestConfigEntry, options?: ClientRequestOptions) => Promise<any>;
|
|
601
|
-
/**
|
|
602
|
-
* Get the user account token for a local action call.
|
|
603
|
-
* It will check the options, context, and system user.
|
|
604
|
-
*/
|
|
605
|
-
protected getUserFromLocalFunctionContext(options: {
|
|
606
|
-
user?: UserAccountToken | "system" | "context";
|
|
607
|
-
}, permission: Permission, isRouteSecure: boolean): UserAccountToken | undefined;
|
|
608
|
-
}
|
|
609
|
-
declare const isServerAction: (value: any) => value is ServerRouteAction;
|
|
610
|
-
interface ServerRemote {
|
|
611
|
-
url: string;
|
|
612
|
-
name: string;
|
|
613
|
-
proxy: boolean;
|
|
614
|
-
internal: boolean;
|
|
615
|
-
links: (args: {
|
|
616
|
-
authorization?: string;
|
|
617
|
-
}) => Promise<ApiLinksResponse>;
|
|
618
|
-
schema: (args: {
|
|
619
|
-
name: string;
|
|
620
|
-
authorization?: string;
|
|
621
|
-
}) => Promise<any>;
|
|
622
|
-
serviceAccount?: ServiceAccountDescriptor;
|
|
623
|
-
prefix: string;
|
|
624
|
-
}
|
|
625
|
-
interface ServerRouteAction<TConfig extends RequestConfigSchema = RequestConfigSchema> extends ServerRoute<TConfig> {
|
|
626
|
-
prefix: string;
|
|
627
|
-
method: RouteMethod;
|
|
628
|
-
name: string;
|
|
629
|
-
group: string;
|
|
630
|
-
permission: Permission;
|
|
631
|
-
options: ActionDescriptorOptions;
|
|
632
|
-
localHandler: LocalHandler;
|
|
633
|
-
}
|
|
634
|
-
type LocalHandler<TConfig extends RequestConfigSchema = RequestConfigSchema> = (config?: ServerRequestConfigEntry<TConfig>, options?: ClientRequestOptions) => Promise<any>;
|
|
635
|
-
//#endregion
|
|
636
583
|
//#region src/index.d.ts
|
|
637
584
|
declare module "alepha" {
|
|
638
585
|
interface Hooks {
|
|
639
|
-
"
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
"server:onRoute": {
|
|
644
|
-
route: ServerRoute;
|
|
586
|
+
"action:onRequest": {
|
|
587
|
+
action: ActionDescriptor<RequestConfigSchema>;
|
|
588
|
+
request: ServerRequest;
|
|
589
|
+
options: ClientRequestOptions;
|
|
645
590
|
};
|
|
646
591
|
"server:onRequest": {
|
|
647
592
|
route: ServerRoute;
|
|
@@ -677,6 +622,10 @@ declare module "alepha" {
|
|
|
677
622
|
route?: HttpAction;
|
|
678
623
|
error: HttpError;
|
|
679
624
|
};
|
|
625
|
+
"node:request": {
|
|
626
|
+
req: IncomingMessage;
|
|
627
|
+
res: ServerResponse$1;
|
|
628
|
+
};
|
|
680
629
|
}
|
|
681
630
|
}
|
|
682
631
|
/**
|
|
@@ -686,158 +635,13 @@ declare module "alepha" {
|
|
|
686
635
|
* on class properties. It provides automatic request/response handling, schema validation, middleware support,
|
|
687
636
|
* and seamless integration with other Alepha modules for a complete backend solution.
|
|
688
637
|
*
|
|
689
|
-
* **Key Features:**
|
|
690
|
-
* - Declarative route definition with `$route` descriptor
|
|
691
|
-
* - API action handlers with `$action` descriptor
|
|
692
|
-
* - Schema validation for requests and responses
|
|
693
|
-
* - Automatic body parsing and response formatting
|
|
694
|
-
* - Built-in middleware system and error handling
|
|
695
|
-
* - Type-safe request parameters and response data
|
|
696
|
-
* - Integration with authentication and security modules
|
|
697
|
-
*
|
|
698
|
-
* **Basic Routing:**
|
|
699
|
-
* ```ts
|
|
700
|
-
* import { Alepha, run, t } from "alepha";
|
|
701
|
-
* import { AlephaServer, $route } from "alepha/server";
|
|
702
|
-
*
|
|
703
|
-
* class ApiRoutes {
|
|
704
|
-
* // Simple GET route
|
|
705
|
-
* getUsers = $route({
|
|
706
|
-
* path: "/api/users",
|
|
707
|
-
* method: "GET",
|
|
708
|
-
* handler: async () => {
|
|
709
|
-
* const users = await getAllUsers();
|
|
710
|
-
* return Response.json(users);
|
|
711
|
-
* },
|
|
712
|
-
* });
|
|
713
|
-
*
|
|
714
|
-
* // POST route with body validation
|
|
715
|
-
* createUser = $route({
|
|
716
|
-
* path: "/api/users",
|
|
717
|
-
* method: "POST",
|
|
718
|
-
* schema: {
|
|
719
|
-
* body: t.object({
|
|
720
|
-
* name: t.string(),
|
|
721
|
-
* email: t.string(),
|
|
722
|
-
* }),
|
|
723
|
-
* },
|
|
724
|
-
* handler: async ({ body }) => {
|
|
725
|
-
* const user = await createUser(body);
|
|
726
|
-
* return Response.json(user, { status: 201 });
|
|
727
|
-
* },
|
|
728
|
-
* });
|
|
729
|
-
*
|
|
730
|
-
* // Dynamic route with parameters
|
|
731
|
-
* getUserById = $route({
|
|
732
|
-
* path: "/api/users/:id",
|
|
733
|
-
* method: "GET",
|
|
734
|
-
* schema: {
|
|
735
|
-
* params: t.object({
|
|
736
|
-
* id: t.string(),
|
|
737
|
-
* }),
|
|
738
|
-
* },
|
|
739
|
-
* handler: async ({ params }) => {
|
|
740
|
-
* const user = await findUserById(params.id);
|
|
741
|
-
* if (!user) {
|
|
742
|
-
* return new Response("User not found", { status: 404 });
|
|
743
|
-
* }
|
|
744
|
-
* return Response.json(user);
|
|
745
|
-
* },
|
|
746
|
-
* });
|
|
747
|
-
* }
|
|
748
|
-
*
|
|
749
|
-
* const alepha = Alepha.create()
|
|
750
|
-
* .with(AlephaServer)
|
|
751
|
-
* .with(ApiRoutes);
|
|
752
|
-
*
|
|
753
|
-
* run(alepha);
|
|
754
|
-
* ```
|
|
755
|
-
*
|
|
756
|
-
* **Action Descriptors:**
|
|
757
|
-
* ```ts
|
|
758
|
-
* import { $action } from "alepha/server";
|
|
759
|
-
*
|
|
760
|
-
* class UserController {
|
|
761
|
-
* // Reusable business logic action
|
|
762
|
-
* getUserProfile = $action({
|
|
763
|
-
* schema: {
|
|
764
|
-
* params: t.object({
|
|
765
|
-
* userId: t.string(),
|
|
766
|
-
* }),
|
|
767
|
-
* response: t.object({
|
|
768
|
-
* id: t.string(),
|
|
769
|
-
* name: t.string(),
|
|
770
|
-
* email: t.string(),
|
|
771
|
-
* }),
|
|
772
|
-
* },
|
|
773
|
-
* handler: async ({ params }) => {
|
|
774
|
-
* const user = await getUserById(params.userId);
|
|
775
|
-
* return {
|
|
776
|
-
* id: user.id,
|
|
777
|
-
* name: user.name,
|
|
778
|
-
* email: user.email,
|
|
779
|
-
* };
|
|
780
|
-
* },
|
|
781
|
-
* });
|
|
782
|
-
*
|
|
783
|
-
* // Route that uses the action
|
|
784
|
-
* profileRoute = $route({
|
|
785
|
-
* path: "/api/profile/:userId",
|
|
786
|
-
* method: "GET",
|
|
787
|
-
* handler: async ({ params }) => {
|
|
788
|
-
* const profile = await this.getUserProfile({ params });
|
|
789
|
-
* return Response.json(profile);
|
|
790
|
-
* },
|
|
791
|
-
* });
|
|
792
|
-
* }
|
|
793
|
-
* ```
|
|
794
|
-
*
|
|
795
|
-
* **Middleware and Error Handling:**
|
|
796
|
-
* ```ts
|
|
797
|
-
* class AppServer {
|
|
798
|
-
* // Global middleware
|
|
799
|
-
* middleware = $route({
|
|
800
|
-
* path: "*",
|
|
801
|
-
* method: "*",
|
|
802
|
-
* handler: async ({ request, next }) => {
|
|
803
|
-
* console.log(`${request.method} ${request.url}`);
|
|
804
|
-
* try {
|
|
805
|
-
* return await next();
|
|
806
|
-
* } catch (error) {
|
|
807
|
-
* console.error("Request failed:", error);
|
|
808
|
-
* return Response.json({ error: "Internal Server Error" }, { status: 500 });
|
|
809
|
-
* }
|
|
810
|
-
* },
|
|
811
|
-
* });
|
|
812
|
-
*
|
|
813
|
-
* // CORS preflight handling
|
|
814
|
-
* corsPrelight = $route({
|
|
815
|
-
* path: "*",
|
|
816
|
-
* method: "OPTIONS",
|
|
817
|
-
* handler: async () => {
|
|
818
|
-
* return new Response(null, {
|
|
819
|
-
* status: 200,
|
|
820
|
-
* headers: {
|
|
821
|
-
* "Access-Control-Allow-Origin": "*",
|
|
822
|
-
* "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE",
|
|
823
|
-
* "Access-Control-Allow-Headers": "Content-Type, Authorization",
|
|
824
|
-
* },
|
|
825
|
-
* });
|
|
826
|
-
* },
|
|
827
|
-
* });
|
|
828
|
-
* }
|
|
829
|
-
* ```
|
|
830
|
-
*
|
|
831
638
|
* @see {@link $route}
|
|
832
639
|
* @see {@link $action}
|
|
833
640
|
* @module alepha.server
|
|
834
641
|
*/
|
|
835
|
-
declare
|
|
836
|
-
readonly name = "alepha.server";
|
|
837
|
-
readonly $services: (alepha: Alepha) => void;
|
|
838
|
-
}
|
|
642
|
+
declare const AlephaServer: _alepha_core0.ModuleDescriptor;
|
|
839
643
|
//# sourceMappingURL=index.d.ts.map
|
|
840
644
|
|
|
841
645
|
//#endregion
|
|
842
|
-
export { $action, $route, ActionDescriptor,
|
|
646
|
+
export { $action, $route, ActionDescriptor, ActionDescriptorOptions, AlephaServer, ApiLink, ApiLinksResponse, BadRequestError, ClientRequestEntry, ClientRequestEntryContainer, ClientRequestOptions, ClientRequestResponse, ConflictError, FetchActionArgs, FetchOptions, FetchResponse, ForbiddenError, HttpAction, HttpClient, HttpClientPendingRequests, HttpError, HttpErrorLike, NodeHttpServerProvider, NotFoundError, Ok, RequestConfigSchema, ResponseBodyType, ResponseKind, RouteDescriptor, RouteDescriptorOptions, RouteMethod, ServerActionHandler, ServerActionRequest, ServerHandler, ServerLoggerProvider, ServerMiddlewareHandler, ServerNotReadyProvider, ServerProvider, ServerRawRequest, ServerReply, ServerRequest, ServerRequestConfig, ServerRequestConfigEntry, ServerResponse, ServerResponseBody, ServerRoute, ServerRouteMatcher, ServerRouterProvider, ServerTimingProvider, UnauthorizedError, ValidationError, apiLinkSchema, apiLinksResponseSchema, errorNameByStatus, errorSchema, isHttpError, isMultipart, okSchema, routeMethods };
|
|
843
647
|
//# sourceMappingURL=index.d.ts.map
|