alepha 0.13.0 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api-jobs/index.d.ts +26 -26
- package/dist/api-users/index.d.ts +1 -1
- package/dist/cli/{dist-Sz2EXvQX.cjs → dist-Dl9Vl7Ur.js} +17 -13
- package/dist/cli/{dist-BBPjuQ56.js.map → dist-Dl9Vl7Ur.js.map} +1 -1
- package/dist/cli/index.d.ts +3 -11
- package/dist/cli/index.js +106 -74
- package/dist/cli/index.js.map +1 -1
- package/dist/email/index.js +71 -73
- package/dist/email/index.js.map +1 -1
- package/dist/orm/index.d.ts +1 -1
- package/dist/orm/index.js.map +1 -1
- package/dist/queue/index.d.ts +4 -4
- package/dist/retry/index.d.ts +1 -1
- package/dist/retry/index.js +2 -2
- package/dist/retry/index.js.map +1 -1
- package/dist/scheduler/index.d.ts +6 -6
- package/dist/security/index.d.ts +28 -28
- package/dist/server/index.js +1 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server-health/index.d.ts +17 -17
- package/dist/server-metrics/index.js +170 -174
- package/dist/server-metrics/index.js.map +1 -1
- package/dist/server-security/index.d.ts +9 -9
- package/dist/vite/index.js +4 -5
- package/dist/vite/index.js.map +1 -1
- package/dist/websocket/index.d.ts +7 -7
- package/package.json +52 -103
- package/src/cli/apps/AlephaPackageBuilderCli.ts +7 -2
- package/src/cli/assets/appRouterTs.ts +9 -0
- package/src/cli/assets/indexHtml.ts +2 -1
- package/src/cli/assets/mainBrowserTs.ts +10 -0
- package/src/cli/commands/CoreCommands.ts +6 -5
- package/src/cli/commands/DrizzleCommands.ts +65 -57
- package/src/cli/commands/VerifyCommands.ts +1 -1
- package/src/cli/services/ProjectUtils.ts +44 -38
- package/src/orm/providers/DrizzleKitProvider.ts +1 -1
- package/src/retry/descriptors/$retry.ts +5 -3
- package/src/server/providers/NodeHttpServerProvider.ts +1 -1
- package/src/vite/helpers/boot.ts +3 -3
- package/dist/api-files/index.cjs +0 -1293
- package/dist/api-files/index.cjs.map +0 -1
- package/dist/api-files/index.d.cts +0 -829
- package/dist/api-jobs/index.cjs +0 -274
- package/dist/api-jobs/index.cjs.map +0 -1
- package/dist/api-jobs/index.d.cts +0 -654
- package/dist/api-notifications/index.cjs +0 -380
- package/dist/api-notifications/index.cjs.map +0 -1
- package/dist/api-notifications/index.d.cts +0 -289
- package/dist/api-parameters/index.cjs +0 -66
- package/dist/api-parameters/index.cjs.map +0 -1
- package/dist/api-parameters/index.d.cts +0 -84
- package/dist/api-users/index.cjs +0 -6009
- package/dist/api-users/index.cjs.map +0 -1
- package/dist/api-users/index.d.cts +0 -4740
- package/dist/api-verifications/index.cjs +0 -407
- package/dist/api-verifications/index.cjs.map +0 -1
- package/dist/api-verifications/index.d.cts +0 -207
- package/dist/batch/index.cjs +0 -408
- package/dist/batch/index.cjs.map +0 -1
- package/dist/batch/index.d.cts +0 -330
- package/dist/bin/index.cjs +0 -17
- package/dist/bin/index.cjs.map +0 -1
- package/dist/bin/index.d.cts +0 -1
- package/dist/bucket/index.cjs +0 -303
- package/dist/bucket/index.cjs.map +0 -1
- package/dist/bucket/index.d.cts +0 -355
- package/dist/cache/index.cjs +0 -241
- package/dist/cache/index.cjs.map +0 -1
- package/dist/cache/index.d.cts +0 -202
- package/dist/cache-redis/index.cjs +0 -84
- package/dist/cache-redis/index.cjs.map +0 -1
- package/dist/cache-redis/index.d.cts +0 -40
- package/dist/cli/chunk-DSlc6foC.cjs +0 -43
- package/dist/cli/dist-BBPjuQ56.js +0 -2778
- package/dist/cli/dist-Sz2EXvQX.cjs.map +0 -1
- package/dist/cli/index.cjs +0 -1241
- package/dist/cli/index.cjs.map +0 -1
- package/dist/cli/index.d.cts +0 -422
- package/dist/command/index.cjs +0 -693
- package/dist/command/index.cjs.map +0 -1
- package/dist/command/index.d.cts +0 -340
- package/dist/core/index.cjs +0 -2264
- package/dist/core/index.cjs.map +0 -1
- package/dist/core/index.d.cts +0 -1927
- package/dist/datetime/index.cjs +0 -318
- package/dist/datetime/index.cjs.map +0 -1
- package/dist/datetime/index.d.cts +0 -145
- package/dist/email/index.cjs +0 -10874
- package/dist/email/index.cjs.map +0 -1
- package/dist/email/index.d.cts +0 -186
- package/dist/fake/index.cjs +0 -34641
- package/dist/fake/index.cjs.map +0 -1
- package/dist/fake/index.d.cts +0 -74
- package/dist/file/index.cjs +0 -1212
- package/dist/file/index.cjs.map +0 -1
- package/dist/file/index.d.cts +0 -698
- package/dist/lock/index.cjs +0 -226
- package/dist/lock/index.cjs.map +0 -1
- package/dist/lock/index.d.cts +0 -361
- package/dist/lock-redis/index.cjs +0 -113
- package/dist/lock-redis/index.cjs.map +0 -1
- package/dist/lock-redis/index.d.cts +0 -24
- package/dist/logger/index.cjs +0 -521
- package/dist/logger/index.cjs.map +0 -1
- package/dist/logger/index.d.cts +0 -281
- package/dist/orm/index.cjs +0 -2986
- package/dist/orm/index.cjs.map +0 -1
- package/dist/orm/index.d.cts +0 -2213
- package/dist/queue/index.cjs +0 -1044
- package/dist/queue/index.cjs.map +0 -1
- package/dist/queue/index.d.cts +0 -1265
- package/dist/queue-redis/index.cjs +0 -873
- package/dist/queue-redis/index.cjs.map +0 -1
- package/dist/queue-redis/index.d.cts +0 -82
- package/dist/redis/index.cjs +0 -153
- package/dist/redis/index.cjs.map +0 -1
- package/dist/redis/index.d.cts +0 -82
- package/dist/retry/index.cjs +0 -146
- package/dist/retry/index.cjs.map +0 -1
- package/dist/retry/index.d.cts +0 -172
- package/dist/router/index.cjs +0 -111
- package/dist/router/index.cjs.map +0 -1
- package/dist/router/index.d.cts +0 -46
- package/dist/scheduler/index.cjs +0 -576
- package/dist/scheduler/index.cjs.map +0 -1
- package/dist/scheduler/index.d.cts +0 -145
- package/dist/security/index.cjs +0 -2402
- package/dist/security/index.cjs.map +0 -1
- package/dist/security/index.d.cts +0 -598
- package/dist/server/index.cjs +0 -1680
- package/dist/server/index.cjs.map +0 -1
- package/dist/server/index.d.cts +0 -810
- package/dist/server-auth/index.cjs +0 -3146
- package/dist/server-auth/index.cjs.map +0 -1
- package/dist/server-auth/index.d.cts +0 -1164
- package/dist/server-cache/index.cjs +0 -252
- package/dist/server-cache/index.cjs.map +0 -1
- package/dist/server-cache/index.d.cts +0 -164
- package/dist/server-compress/index.cjs +0 -141
- package/dist/server-compress/index.cjs.map +0 -1
- package/dist/server-compress/index.d.cts +0 -38
- package/dist/server-cookies/index.cjs +0 -234
- package/dist/server-cookies/index.cjs.map +0 -1
- package/dist/server-cookies/index.d.cts +0 -144
- package/dist/server-cors/index.cjs +0 -201
- package/dist/server-cors/index.cjs.map +0 -1
- package/dist/server-cors/index.d.cts +0 -140
- package/dist/server-health/index.cjs +0 -62
- package/dist/server-health/index.cjs.map +0 -1
- package/dist/server-health/index.d.cts +0 -58
- package/dist/server-helmet/index.cjs +0 -131
- package/dist/server-helmet/index.cjs.map +0 -1
- package/dist/server-helmet/index.d.cts +0 -97
- package/dist/server-links/index.cjs +0 -992
- package/dist/server-links/index.cjs.map +0 -1
- package/dist/server-links/index.d.cts +0 -513
- package/dist/server-metrics/index.cjs +0 -4535
- package/dist/server-metrics/index.cjs.map +0 -1
- package/dist/server-metrics/index.d.cts +0 -35
- package/dist/server-multipart/index.cjs +0 -237
- package/dist/server-multipart/index.cjs.map +0 -1
- package/dist/server-multipart/index.d.cts +0 -50
- package/dist/server-proxy/index.cjs +0 -186
- package/dist/server-proxy/index.cjs.map +0 -1
- package/dist/server-proxy/index.d.cts +0 -234
- package/dist/server-rate-limit/index.cjs +0 -241
- package/dist/server-rate-limit/index.cjs.map +0 -1
- package/dist/server-rate-limit/index.d.cts +0 -183
- package/dist/server-security/index.cjs +0 -316
- package/dist/server-security/index.cjs.map +0 -1
- package/dist/server-security/index.d.cts +0 -173
- package/dist/server-static/index.cjs +0 -170
- package/dist/server-static/index.cjs.map +0 -1
- package/dist/server-static/index.d.cts +0 -121
- package/dist/server-swagger/index.cjs +0 -1021
- package/dist/server-swagger/index.cjs.map +0 -1
- package/dist/server-swagger/index.d.cts +0 -382
- package/dist/sms/index.cjs +0 -221
- package/dist/sms/index.cjs.map +0 -1
- package/dist/sms/index.d.cts +0 -130
- package/dist/thread/index.cjs +0 -350
- package/dist/thread/index.cjs.map +0 -1
- package/dist/thread/index.d.cts +0 -260
- package/dist/topic/index.cjs +0 -282
- package/dist/topic/index.cjs.map +0 -1
- package/dist/topic/index.d.cts +0 -523
- package/dist/topic-redis/index.cjs +0 -71
- package/dist/topic-redis/index.cjs.map +0 -1
- package/dist/topic-redis/index.d.cts +0 -42
- package/dist/vite/index.cjs +0 -1077
- package/dist/vite/index.cjs.map +0 -1
- package/dist/vite/index.d.cts +0 -542
- package/dist/websocket/index.cjs +0 -1117
- package/dist/websocket/index.cjs.map +0 -1
- package/dist/websocket/index.d.cts +0 -861
package/dist/core/index.d.cts
DELETED
|
@@ -1,1927 +0,0 @@
|
|
|
1
|
-
import * as TypeBox from "typebox";
|
|
2
|
-
import { Static as Static$1, StaticDecode, StaticDecode as Static, StaticEncode, StaticEncode as StaticEncode$1, TAny, TAny as TAny$1, TArray, TArray as TArray$1, TArrayOptions, TBigInt, TBoolean, TBoolean as TBoolean$1, TInteger, TInteger as TInteger$1, TInterface, TKeysToIndexer, TKeysToIndexer as TKeysToIndexer$1, TNull, TNull as TNull$1, TNumber, TNumber as TNumber$1, TNumberOptions, TNumberOptions as TNumberOptions$1, TObject, TObject as TObject$1, TObjectOptions, TObjectOptions as TObjectOptions$1, TOmit, TOptional, TOptionalAdd, TOptionalAdd as TOptionalAdd$1, TPartial, TPick, TPick as TPick$1, TProperties, TProperties as TProperties$1, TRecord, TRecord as TRecord$1, TSchema, TSchema as TSchema$1, TSchemaOptions, TString, TString as TString$1, TStringOptions, TStringOptions as TStringOptions$1, TTuple, TUnion, TUnion as TUnion$1, TUnsafe, TUnsafe as TUnsafe$1, TVoid } from "typebox";
|
|
3
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
4
|
-
import TypeBoxFormat from "typebox/format";
|
|
5
|
-
import * as TypeBoxValue from "typebox/value";
|
|
6
|
-
import { TLocalizedValidationError } from "typebox/error";
|
|
7
|
-
import { Readable } from "node:stream";
|
|
8
|
-
import { ReadableStream as ReadableStream$1 } from "node:stream/web";
|
|
9
|
-
import { Validator } from "typebox/compile";
|
|
10
|
-
|
|
11
|
-
//#region src/core/constants/KIND.d.ts
|
|
12
|
-
/**
|
|
13
|
-
* Used for identifying descriptors.
|
|
14
|
-
*
|
|
15
|
-
* @internal
|
|
16
|
-
*/
|
|
17
|
-
declare const KIND: unique symbol;
|
|
18
|
-
//#endregion
|
|
19
|
-
//#region src/core/constants/MODULE.d.ts
|
|
20
|
-
/**
|
|
21
|
-
* Used for identifying modules.
|
|
22
|
-
*
|
|
23
|
-
* @internal
|
|
24
|
-
*/
|
|
25
|
-
declare const MODULE: unique symbol;
|
|
26
|
-
//#endregion
|
|
27
|
-
//#region src/core/interfaces/Service.d.ts
|
|
28
|
-
/**
|
|
29
|
-
* In Alepha, a service is a class that can be instantiated or an abstract class. Nothing more, nothing less...
|
|
30
|
-
*/
|
|
31
|
-
type Service<T extends object = any> = InstantiableClass<T> | AbstractClass<T> | RunFunction<T>;
|
|
32
|
-
type RunFunction<T extends object = any> = (...args: any[]) => T | void;
|
|
33
|
-
type InstantiableClass<T extends object = any> = new (...args: any[]) => T;
|
|
34
|
-
/**
|
|
35
|
-
* Abstract class is a class that cannot be instantiated directly!
|
|
36
|
-
* It widely used for defining interfaces.
|
|
37
|
-
*/
|
|
38
|
-
type AbstractClass<T extends object = any> = abstract new (...args: any[]) => T;
|
|
39
|
-
/**
|
|
40
|
-
* Service substitution allows you to register a class as a different class.
|
|
41
|
-
* Providing class A, but using class B instead.
|
|
42
|
-
* This is useful for testing, mocking, or providing a different implementation of a service.
|
|
43
|
-
*
|
|
44
|
-
* class A is mostly an AbstractClass, while class B is an InstantiableClass.
|
|
45
|
-
*/
|
|
46
|
-
interface ServiceSubstitution<T extends object = any> {
|
|
47
|
-
/**
|
|
48
|
-
* Every time someone asks for this class, it will be provided with the 'use' class.
|
|
49
|
-
*/
|
|
50
|
-
provide: Service<T>;
|
|
51
|
-
/**
|
|
52
|
-
* Service to use instead of the 'provide' service.
|
|
53
|
-
*
|
|
54
|
-
* Syntax is inspired by Angular's DI system.
|
|
55
|
-
*/
|
|
56
|
-
use: Service<T>;
|
|
57
|
-
/**
|
|
58
|
-
* If true, if the service already exists -> just ignore the substitution and do not throw an error.
|
|
59
|
-
* Mostly used for plugins to enforce a substitution without throwing an error.
|
|
60
|
-
*/
|
|
61
|
-
optional?: boolean;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Every time you register a service, you can use this type to define it.
|
|
65
|
-
*
|
|
66
|
-
* alepha.with( ServiceEntry )
|
|
67
|
-
* or
|
|
68
|
-
* alepha.with( provide: ServiceEntry, use: MyOwnServiceEntry )
|
|
69
|
-
*
|
|
70
|
-
* And yes, you declare the *type* of the service, not the *instance*.
|
|
71
|
-
*/
|
|
72
|
-
type ServiceEntry<T extends object = any> = Service<T> | ServiceSubstitution<T>;
|
|
73
|
-
declare function isClass(func: any): func is InstantiableClass;
|
|
74
|
-
//#endregion
|
|
75
|
-
//#region src/core/helpers/descriptor.d.ts
|
|
76
|
-
interface DescriptorArgs<T extends object = {}> {
|
|
77
|
-
options: T;
|
|
78
|
-
alepha: Alepha;
|
|
79
|
-
service: InstantiableClass<Service>;
|
|
80
|
-
module?: Service;
|
|
81
|
-
}
|
|
82
|
-
interface DescriptorConfig {
|
|
83
|
-
propertyKey: string;
|
|
84
|
-
service: InstantiableClass<Service>;
|
|
85
|
-
module?: Service;
|
|
86
|
-
}
|
|
87
|
-
declare abstract class Descriptor<T extends object = {}> {
|
|
88
|
-
protected readonly alepha: Alepha;
|
|
89
|
-
readonly options: T;
|
|
90
|
-
readonly config: DescriptorConfig;
|
|
91
|
-
constructor(args: DescriptorArgs<T>);
|
|
92
|
-
/**
|
|
93
|
-
* Called automatically by Alepha after the descriptor is created.
|
|
94
|
-
*/
|
|
95
|
-
protected onInit(): void;
|
|
96
|
-
}
|
|
97
|
-
type DescriptorFactory<TDescriptor extends Descriptor = Descriptor> = {
|
|
98
|
-
(options: TDescriptor["options"]): TDescriptor;
|
|
99
|
-
[KIND]: InstantiableClass<TDescriptor>;
|
|
100
|
-
};
|
|
101
|
-
type DescriptorFactoryLike<T extends object = any> = {
|
|
102
|
-
(options: T): any;
|
|
103
|
-
[KIND]: any;
|
|
104
|
-
};
|
|
105
|
-
declare const createDescriptor: <TDescriptor extends Descriptor>(descriptor: InstantiableClass<TDescriptor> & {
|
|
106
|
-
[MODULE]?: Service;
|
|
107
|
-
}, options: TDescriptor["options"]) => TDescriptor;
|
|
108
|
-
//#endregion
|
|
109
|
-
//#region src/core/descriptors/$inject.d.ts
|
|
110
|
-
/**
|
|
111
|
-
* Get the instance of the specified type from the context.
|
|
112
|
-
*
|
|
113
|
-
* ```ts
|
|
114
|
-
* class A { }
|
|
115
|
-
* class B {
|
|
116
|
-
* a = $inject(A);
|
|
117
|
-
* }
|
|
118
|
-
* ```
|
|
119
|
-
*/
|
|
120
|
-
declare const $inject: <T extends object>(type: Service<T>, opts?: InjectOptions<T>) => T;
|
|
121
|
-
declare class InjectDescriptor extends Descriptor {}
|
|
122
|
-
interface InjectOptions<T extends object = any> {
|
|
123
|
-
/**
|
|
124
|
-
* - 'transient' → Always a new instance on every inject. Zero caching.
|
|
125
|
-
* - 'singleton' → One instance per Alepha runtime (per-thread). Never disposed until Alepha shuts down. (default)
|
|
126
|
-
* - 'scoped' → One instance per AsyncLocalStorage context.
|
|
127
|
-
* - A new scope is created when Alepha handles a request, a scheduled job, a queue worker task...
|
|
128
|
-
* - You can also start a manual scope via alepha.context.run(() => { ... }).
|
|
129
|
-
* - When the scope ends, the scoped registry is discarded.
|
|
130
|
-
*
|
|
131
|
-
* @default "singleton"
|
|
132
|
-
*/
|
|
133
|
-
lifetime?: "transient" | "singleton" | "scoped";
|
|
134
|
-
/**
|
|
135
|
-
* Constructor arguments to pass when creating a new instance.
|
|
136
|
-
*/
|
|
137
|
-
args?: ConstructorParameters<InstantiableClass<T>>;
|
|
138
|
-
/**
|
|
139
|
-
* Parent that requested the instance.
|
|
140
|
-
*
|
|
141
|
-
* @internal
|
|
142
|
-
*/
|
|
143
|
-
parent?: Service | null;
|
|
144
|
-
}
|
|
145
|
-
//#endregion
|
|
146
|
-
//#region src/core/descriptors/$module.d.ts
|
|
147
|
-
/**
|
|
148
|
-
* Wrap Services and Descriptors into a Module.
|
|
149
|
-
*
|
|
150
|
-
* - A module is just a Service with some extra {@link Module}.
|
|
151
|
-
* - You must attach a `name` to it.
|
|
152
|
-
* - Name must follow the pattern: `project.module.submodule`. (e.g. `myapp.users.auth`).
|
|
153
|
-
*
|
|
154
|
-
* @example
|
|
155
|
-
* ```ts
|
|
156
|
-
* import { $module } from "alepha";
|
|
157
|
-
* import { MyService } from "./MyService.ts";
|
|
158
|
-
*
|
|
159
|
-
* // export MyService, so it can be used everywhere (optional)
|
|
160
|
-
* export * from "./MyService.ts";
|
|
161
|
-
*
|
|
162
|
-
* export default $module({
|
|
163
|
-
* name: "my.project.module",
|
|
164
|
-
* // MyService will have a module context "my.project.module"
|
|
165
|
-
* services: [MyService],
|
|
166
|
-
* });
|
|
167
|
-
* ```
|
|
168
|
-
*
|
|
169
|
-
* ### Why Modules?
|
|
170
|
-
*
|
|
171
|
-
* #### Logging
|
|
172
|
-
*
|
|
173
|
-
* By default, AlephaLogger will log the module name in the logs.
|
|
174
|
-
* This helps to identify where the logs are coming from.
|
|
175
|
-
*
|
|
176
|
-
* You can also set different log levels for different modules.
|
|
177
|
-
* It means you can set 'some.very.specific.module' to 'debug' and keep the rest of the application to 'info'.
|
|
178
|
-
*
|
|
179
|
-
* #### Modulith
|
|
180
|
-
*
|
|
181
|
-
* Force to structure your application in modules, even if it's a single deployable unit.
|
|
182
|
-
* It helps to keep a clean architecture and avoid monolithic applications.
|
|
183
|
-
*
|
|
184
|
-
* A strict mode flag will probably come to enforce module boundaries.
|
|
185
|
-
* -> Throwing errors when a service from another module is injected.
|
|
186
|
-
* But it's not implemented yet.
|
|
187
|
-
*
|
|
188
|
-
* ### When not to use Modules?
|
|
189
|
-
*
|
|
190
|
-
* Small applications does not need modules. It's better to keep it simple.
|
|
191
|
-
* Modules are more useful when the application grows and needs to be structured.
|
|
192
|
-
* If we speak with number of `$actions`, a module should be used when you have more than 30 actions in a single module.
|
|
193
|
-
* Meaning that if you have 100 actions, you should have at least 3 modules.
|
|
194
|
-
*/
|
|
195
|
-
declare const $module: <T extends object = {}>(options: ModuleDescriptorOptions) => Service<Module>;
|
|
196
|
-
interface ModuleDescriptorOptions {
|
|
197
|
-
/**
|
|
198
|
-
* Name of the module.
|
|
199
|
-
*
|
|
200
|
-
* It should be in the format of `project.module.submodule`.
|
|
201
|
-
*/
|
|
202
|
-
name: string;
|
|
203
|
-
/**
|
|
204
|
-
* List all services related to this module.
|
|
205
|
-
*
|
|
206
|
-
* If you don't declare 'register' function, all services will be registered automatically.
|
|
207
|
-
* If you declare 'register' function, you must handle the registration of ALL services manually.
|
|
208
|
-
*/
|
|
209
|
-
services?: Array<Service>;
|
|
210
|
-
/**
|
|
211
|
-
* List of $descriptors to register in the module.
|
|
212
|
-
*/
|
|
213
|
-
descriptors?: Array<DescriptorFactoryLike>;
|
|
214
|
-
/**
|
|
215
|
-
* By default, module will register ALL services.
|
|
216
|
-
* You can override this behavior by providing a register function.
|
|
217
|
-
* It's useful when you want to register services conditionally or in a specific order.
|
|
218
|
-
*
|
|
219
|
-
* Again, if you declare 'register', you must handle the registration of ALL services manually.
|
|
220
|
-
*/
|
|
221
|
-
register?: (alepha: Alepha) => void;
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Base class for all modules.
|
|
225
|
-
*/
|
|
226
|
-
declare abstract class Module {
|
|
227
|
-
abstract readonly options: ModuleDescriptorOptions;
|
|
228
|
-
abstract register(alepha: Alepha): void;
|
|
229
|
-
static NAME_REGEX: RegExp;
|
|
230
|
-
/**
|
|
231
|
-
* Check if a Service is a Module.
|
|
232
|
-
*/
|
|
233
|
-
static is(ctor: Service): boolean;
|
|
234
|
-
/**
|
|
235
|
-
* Get the Module of a Service.
|
|
236
|
-
*
|
|
237
|
-
* Returns undefined if the Service is not part of a Module.
|
|
238
|
-
*/
|
|
239
|
-
static of(ctor: Service): Service<Module> | undefined;
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* Helper type to add Module metadata to a Service.
|
|
243
|
-
*/
|
|
244
|
-
type WithModule<T extends object = any> = T & {
|
|
245
|
-
[MODULE]?: Service;
|
|
246
|
-
};
|
|
247
|
-
//#endregion
|
|
248
|
-
//#region src/core/interfaces/Async.d.ts
|
|
249
|
-
/**
|
|
250
|
-
* Represents a value that can be either a value or a promise of value.
|
|
251
|
-
*/
|
|
252
|
-
type Async<T> = T | Promise<T>;
|
|
253
|
-
/**
|
|
254
|
-
* Represents a function that returns an async value.
|
|
255
|
-
*/
|
|
256
|
-
type AsyncFn = (...args: any[]) => Async<any>;
|
|
257
|
-
/**
|
|
258
|
-
* Transforms a type T into a promise if it is not already a promise.
|
|
259
|
-
*/
|
|
260
|
-
type MaybePromise<T> = T extends Promise<any> ? T : Promise<T>;
|
|
261
|
-
//#endregion
|
|
262
|
-
//#region src/core/interfaces/LoggerInterface.d.ts
|
|
263
|
-
type LogLevel = "ERROR" | "WARN" | "INFO" | "DEBUG" | "TRACE" | "SILENT";
|
|
264
|
-
interface LoggerInterface {
|
|
265
|
-
trace(message: string, data?: unknown): void;
|
|
266
|
-
debug(message: string, data?: unknown): void;
|
|
267
|
-
info(message: string, data?: unknown): void;
|
|
268
|
-
warn(message: string, data?: unknown): void;
|
|
269
|
-
error(message: string, data?: unknown): void;
|
|
270
|
-
}
|
|
271
|
-
//#endregion
|
|
272
|
-
//#region src/core/providers/AlsProvider.d.ts
|
|
273
|
-
type AsyncLocalStorageData = any;
|
|
274
|
-
declare class AlsProvider {
|
|
275
|
-
static create: () => AsyncLocalStorage<AsyncLocalStorageData> | undefined;
|
|
276
|
-
als?: AsyncLocalStorage<AsyncLocalStorageData>;
|
|
277
|
-
constructor();
|
|
278
|
-
createContextId(): string;
|
|
279
|
-
run<R>(callback: () => R, data?: Record<string, any>): R;
|
|
280
|
-
exists(): boolean;
|
|
281
|
-
get<T>(key: string): T | undefined;
|
|
282
|
-
set<T>(key: string, value: T): void;
|
|
283
|
-
}
|
|
284
|
-
//#endregion
|
|
285
|
-
//#region src/core/providers/Json.d.ts
|
|
286
|
-
/**
|
|
287
|
-
* Mimics the JSON global object with stringify and parse methods.
|
|
288
|
-
*
|
|
289
|
-
* Used across the codebase via dependency injection.
|
|
290
|
-
*/
|
|
291
|
-
declare class Json {
|
|
292
|
-
stringify(value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string;
|
|
293
|
-
parse(text: string, reviver?: (this: any, key: string, value: any) => any): any;
|
|
294
|
-
}
|
|
295
|
-
//#endregion
|
|
296
|
-
//#region src/core/errors/AlephaError.d.ts
|
|
297
|
-
/**
|
|
298
|
-
* Default error class for Alepha.
|
|
299
|
-
*/
|
|
300
|
-
declare class AlephaError extends Error {
|
|
301
|
-
name: string;
|
|
302
|
-
}
|
|
303
|
-
//#endregion
|
|
304
|
-
//#region src/core/errors/TypeBoxError.d.ts
|
|
305
|
-
declare class TypeBoxError extends AlephaError {
|
|
306
|
-
name: string;
|
|
307
|
-
readonly cause: TLocalizedValidationError;
|
|
308
|
-
readonly value: {
|
|
309
|
-
path: string;
|
|
310
|
-
message: string;
|
|
311
|
-
};
|
|
312
|
-
constructor(error: TLocalizedValidationError);
|
|
313
|
-
}
|
|
314
|
-
interface TypeBoxErrorParams {
|
|
315
|
-
requiredProperties?: string[];
|
|
316
|
-
}
|
|
317
|
-
//#endregion
|
|
318
|
-
//#region src/core/helpers/FileLike.d.ts
|
|
319
|
-
interface FileLike {
|
|
320
|
-
/**
|
|
321
|
-
* Filename.
|
|
322
|
-
* @default "file"
|
|
323
|
-
*/
|
|
324
|
-
name: string;
|
|
325
|
-
/**
|
|
326
|
-
* Mandatory MIME type of the file.
|
|
327
|
-
* @default "application/octet-stream"
|
|
328
|
-
*/
|
|
329
|
-
type: string;
|
|
330
|
-
/**
|
|
331
|
-
* Size of the file in bytes.
|
|
332
|
-
*
|
|
333
|
-
* Always 0 for streams, as the size is not known until the stream is fully read.
|
|
334
|
-
*
|
|
335
|
-
* @default 0
|
|
336
|
-
*/
|
|
337
|
-
size: number;
|
|
338
|
-
/**
|
|
339
|
-
* Last modified timestamp in milliseconds since epoch.
|
|
340
|
-
*
|
|
341
|
-
* Always the current timestamp for streams, as the last modified time is not known.
|
|
342
|
-
* We use this field to ensure compatibility with File API.
|
|
343
|
-
*
|
|
344
|
-
* @default Date.now()
|
|
345
|
-
*/
|
|
346
|
-
lastModified: number;
|
|
347
|
-
/**
|
|
348
|
-
* Returns a ReadableStream or Node.js Readable stream of the file content.
|
|
349
|
-
*
|
|
350
|
-
* For streams, this is the original stream.
|
|
351
|
-
*/
|
|
352
|
-
stream(): StreamLike;
|
|
353
|
-
/**
|
|
354
|
-
* Returns the file content as an ArrayBuffer.
|
|
355
|
-
*
|
|
356
|
-
* For streams, this reads the entire stream into memory.
|
|
357
|
-
*/
|
|
358
|
-
arrayBuffer(): Promise<ArrayBuffer>;
|
|
359
|
-
/**
|
|
360
|
-
* Returns the file content as a string.
|
|
361
|
-
*
|
|
362
|
-
* For streams, this reads the entire stream into memory and converts it to a string.
|
|
363
|
-
*/
|
|
364
|
-
text(): Promise<string>;
|
|
365
|
-
/**
|
|
366
|
-
* Optional file path, if the file is stored on disk.
|
|
367
|
-
*
|
|
368
|
-
* This is not from the File API, but rather a custom field to indicate where the file is stored.
|
|
369
|
-
*/
|
|
370
|
-
filepath?: string;
|
|
371
|
-
}
|
|
372
|
-
/**
|
|
373
|
-
* TypeBox view of FileLike.
|
|
374
|
-
*/
|
|
375
|
-
type TFile = TUnsafe$1<FileLike>;
|
|
376
|
-
declare const isTypeFile: (value: TSchema$1) => value is TFile;
|
|
377
|
-
declare const isFileLike: (value: any) => value is FileLike;
|
|
378
|
-
type StreamLike = ReadableStream | ReadableStream$1 | Readable | NodeJS.ReadableStream;
|
|
379
|
-
type TStream = TUnsafe$1<StreamLike>;
|
|
380
|
-
//#endregion
|
|
381
|
-
//#region src/core/providers/TypeProvider.d.ts
|
|
382
|
-
declare const isUUID: typeof TypeBoxFormat.IsUuid;
|
|
383
|
-
declare const isEmail: typeof TypeBoxFormat.IsEmail;
|
|
384
|
-
declare const isURL: typeof TypeBoxFormat.IsUrl;
|
|
385
|
-
declare const isDateTime: typeof TypeBoxFormat.IsDateTime;
|
|
386
|
-
declare const isDate: typeof TypeBoxFormat.IsDate;
|
|
387
|
-
declare const isTime: typeof TypeBoxFormat.IsTime;
|
|
388
|
-
declare const isDuration: typeof TypeBoxFormat.IsDuration;
|
|
389
|
-
declare class TypeGuard {
|
|
390
|
-
isBigInt: (value: TSchema$1) => value is TString$1;
|
|
391
|
-
isUUID: (value: TSchema$1) => value is TString$1;
|
|
392
|
-
isObject: typeof TypeBox.IsObject;
|
|
393
|
-
isNumber: typeof TypeBox.IsNumber;
|
|
394
|
-
isString: typeof TypeBox.IsString;
|
|
395
|
-
isBoolean: typeof TypeBox.IsBoolean;
|
|
396
|
-
isAny: typeof TypeBox.IsAny;
|
|
397
|
-
isArray: typeof TypeBox.IsArray;
|
|
398
|
-
isOptional: typeof TypeBox.IsOptional;
|
|
399
|
-
isUnion: typeof TypeBox.IsUnion;
|
|
400
|
-
isInteger: typeof TypeBox.IsInteger;
|
|
401
|
-
isNull: typeof TypeBox.IsNull;
|
|
402
|
-
isUndefined: typeof TypeBox.IsUndefined;
|
|
403
|
-
isUnsafe: typeof TypeBox.IsUnsafe;
|
|
404
|
-
isRecord: typeof TypeBox.IsRecord;
|
|
405
|
-
isTuple: typeof TypeBox.IsTuple;
|
|
406
|
-
isVoid: typeof TypeBox.IsVoid;
|
|
407
|
-
isLiteral: typeof TypeBox.IsLiteral;
|
|
408
|
-
isSchema: typeof TypeBox.IsSchema;
|
|
409
|
-
isFile: (value: TSchema$1) => value is TFile;
|
|
410
|
-
isDateTime: (schema: unknown) => boolean;
|
|
411
|
-
isDate: (schema: unknown) => boolean;
|
|
412
|
-
isTime: (schema: unknown) => boolean;
|
|
413
|
-
isDuration: (schema: unknown) => boolean;
|
|
414
|
-
}
|
|
415
|
-
declare module "typebox" {
|
|
416
|
-
interface TString {
|
|
417
|
-
format?: string;
|
|
418
|
-
minLength?: number;
|
|
419
|
-
maxLength?: number;
|
|
420
|
-
}
|
|
421
|
-
interface TNumber {
|
|
422
|
-
format?: "int64";
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
declare class TypeProvider {
|
|
426
|
-
static format: typeof TypeBoxFormat;
|
|
427
|
-
static translateError(error: TypeBoxError, locale?: string): string;
|
|
428
|
-
static setLocale(locale: string): void;
|
|
429
|
-
static isValidBigInt(value: string | number): boolean;
|
|
430
|
-
/**
|
|
431
|
-
* Default maximum length for strings.
|
|
432
|
-
*
|
|
433
|
-
* It can be set to a larger value:
|
|
434
|
-
* ```ts
|
|
435
|
-
* TypeProvider.DEFAULT_STRING_MAX_LENGTH = 1000000;
|
|
436
|
-
* TypeProvider.DEFAULT_STRING_MAX_LENGTH = undefined; // no limit (not recommended)
|
|
437
|
-
* ```
|
|
438
|
-
*/
|
|
439
|
-
static DEFAULT_STRING_MAX_LENGTH: number | undefined;
|
|
440
|
-
/**
|
|
441
|
-
* Maximum length for short strings, such as names or titles.
|
|
442
|
-
*/
|
|
443
|
-
static DEFAULT_SHORT_STRING_MAX_LENGTH: number | undefined;
|
|
444
|
-
/**
|
|
445
|
-
* Maximum length for long strings, such as descriptions or comments.
|
|
446
|
-
* It can be overridden in the string options.
|
|
447
|
-
*
|
|
448
|
-
* It can be set to a larger value:
|
|
449
|
-
* ```ts
|
|
450
|
-
* TypeProvider.DEFAULT_LONG_STRING_MAX_LENGTH = 2048;
|
|
451
|
-
* ```
|
|
452
|
-
*/
|
|
453
|
-
static DEFAULT_LONG_STRING_MAX_LENGTH: number | undefined;
|
|
454
|
-
/**
|
|
455
|
-
* Maximum length for rich strings, such as HTML or Markdown.
|
|
456
|
-
* This is a large value to accommodate rich text content.
|
|
457
|
-
* > It's also the maximum length of PG's TEXT type.
|
|
458
|
-
*
|
|
459
|
-
* It can be overridden in the string options.
|
|
460
|
-
*
|
|
461
|
-
* It can be set to a larger value:
|
|
462
|
-
* ```ts
|
|
463
|
-
* TypeProvider.DEFAULT_RICH_STRING_MAX_LENGTH = 1000000;
|
|
464
|
-
* ```
|
|
465
|
-
*/
|
|
466
|
-
static DEFAULT_RICH_STRING_MAX_LENGTH: number | undefined;
|
|
467
|
-
/**
|
|
468
|
-
* Maximum number of items in an array.
|
|
469
|
-
* This is a default value to prevent excessive memory usage.
|
|
470
|
-
* It can be overridden in the array options.
|
|
471
|
-
*/
|
|
472
|
-
static DEFAULT_ARRAY_MAX_ITEMS: number;
|
|
473
|
-
raw: typeof TypeBox.Type;
|
|
474
|
-
any: typeof TypeBox.Any;
|
|
475
|
-
void: typeof TypeBox.Void;
|
|
476
|
-
undefined: typeof TypeBox.Undefined;
|
|
477
|
-
record: typeof TypeBox.Record;
|
|
478
|
-
union: typeof TypeBox.Union;
|
|
479
|
-
tuple: typeof TypeBox.Tuple;
|
|
480
|
-
null: typeof TypeBox.Null;
|
|
481
|
-
const: typeof TypeBox.Literal;
|
|
482
|
-
options: typeof TypeBox.Options;
|
|
483
|
-
/**
|
|
484
|
-
* Type guards to check the type of schema.
|
|
485
|
-
* This is not a runtime type check, but a compile-time type guard.
|
|
486
|
-
*
|
|
487
|
-
* @example
|
|
488
|
-
* ```ts
|
|
489
|
-
* if (t.schema.isString(schema)) {
|
|
490
|
-
* // schema is TString
|
|
491
|
-
* }
|
|
492
|
-
* ```
|
|
493
|
-
*/
|
|
494
|
-
readonly schema: TypeGuard;
|
|
495
|
-
extend<T extends TSchema$1[], U$1 extends TProperties$1>(schema: [...T], properties: U$1, options?: TSchemaOptions): TInterface<T, U$1>;
|
|
496
|
-
extend<T extends TObject$1, U$1 extends TProperties$1>(schema: T, properties: U$1, options?: TSchemaOptions): TInterface<[T], U$1>;
|
|
497
|
-
pick<T extends TObject$1, Indexer extends PropertyKey[]>(schema: T, keys: [...Indexer], options?: TObjectOptions$1): TPick$1<T, TKeysToIndexer$1<Indexer>>;
|
|
498
|
-
omit<T extends TObject$1, Indexer extends PropertyKey[]>(schema: T, keys: [...Indexer], options?: TObjectOptions$1): TOmit<T, TKeysToIndexer$1<Indexer>>;
|
|
499
|
-
partial<T extends TSchema$1>(schema: T, options?: TSchemaOptions): TPartial<T>;
|
|
500
|
-
/**
|
|
501
|
-
* Create a schema for an object.
|
|
502
|
-
* By default, additional properties are not allowed.
|
|
503
|
-
*
|
|
504
|
-
* @example
|
|
505
|
-
* ```ts
|
|
506
|
-
* const userSchema = t.object({
|
|
507
|
-
* id: t.integer(),
|
|
508
|
-
* name: t.string(),
|
|
509
|
-
* });
|
|
510
|
-
* ```
|
|
511
|
-
*/
|
|
512
|
-
object<T extends TProperties$1>(properties: T, options?: TObjectOptions$1): TObject$1<T>;
|
|
513
|
-
/**
|
|
514
|
-
* Create a schema for an array.
|
|
515
|
-
* By default, the maximum number of items is limited to prevent excessive memory usage.
|
|
516
|
-
*
|
|
517
|
-
* @see TypeProvider.DEFAULT_ARRAY_MAX_ITEMS
|
|
518
|
-
*/
|
|
519
|
-
array<T extends TSchema$1>(schema: T, options?: TArrayOptions): TArray$1<T>;
|
|
520
|
-
/**
|
|
521
|
-
* Create a schema for a string.
|
|
522
|
-
* For db or input fields, consider using `t.text()` instead, which has length limits.
|
|
523
|
-
*
|
|
524
|
-
* If you need a string with specific format (e.g. email, uuid), consider using the corresponding method (e.g. `t.email()`, `t.uuid()`).
|
|
525
|
-
*/
|
|
526
|
-
string(options?: TStringOptions$1): TString$1;
|
|
527
|
-
/**
|
|
528
|
-
* Create a schema for a string with length limits.
|
|
529
|
-
* For internal strings without length limits, consider using `t.string()` instead.
|
|
530
|
-
*
|
|
531
|
-
* Default size is "regular", which has a max length of 255 characters.
|
|
532
|
-
*/
|
|
533
|
-
text(options?: TTextOptions): TString$1;
|
|
534
|
-
/**
|
|
535
|
-
* Create a schema for a JSON object.
|
|
536
|
-
* This is a record with string keys and any values.
|
|
537
|
-
*/
|
|
538
|
-
json(options?: TSchemaOptions): TRecord$1<string, TAny$1>;
|
|
539
|
-
/**
|
|
540
|
-
* Create a schema for a boolean.
|
|
541
|
-
*/
|
|
542
|
-
boolean(options?: TSchemaOptions): TBoolean$1;
|
|
543
|
-
/**
|
|
544
|
-
* Create a schema for a number.
|
|
545
|
-
*/
|
|
546
|
-
number(options?: TNumberOptions$1): TNumber$1;
|
|
547
|
-
/**
|
|
548
|
-
* Create a schema for an integer.
|
|
549
|
-
*/
|
|
550
|
-
integer(options?: TNumberOptions$1): TInteger$1;
|
|
551
|
-
int32(options?: TNumberOptions$1): TInteger$1;
|
|
552
|
-
/**
|
|
553
|
-
* Mimic a signed 64-bit integer.
|
|
554
|
-
*
|
|
555
|
-
* This is NOT a true int64, as JavaScript cannot represent all int64 values.
|
|
556
|
-
* It is a number that is an integer and between -9007199254740991 and 9007199254740991.
|
|
557
|
-
* Use `t.bigint()` for true int64 values represented as strings.
|
|
558
|
-
*/
|
|
559
|
-
int64(options?: TNumberOptions$1): TNumber$1;
|
|
560
|
-
/**
|
|
561
|
-
* Make a schema optional.
|
|
562
|
-
*/
|
|
563
|
-
optional<T extends TSchema$1>(schema: T): TOptionalAdd$1<T>;
|
|
564
|
-
/**
|
|
565
|
-
* Make a schema nullable.
|
|
566
|
-
*/
|
|
567
|
-
nullable<T extends TSchema$1>(schema: T, options?: TObjectOptions$1): TUnion$1<[TNull$1, T]>;
|
|
568
|
-
/**
|
|
569
|
-
* Create a schema that maps all properties of an object schema to nullable.
|
|
570
|
-
*/
|
|
571
|
-
nullify: <T extends TSchema$1>(schema: T, options?: TObjectOptions$1) => TypeBox.TMappedInstantiate<{}, {
|
|
572
|
-
callstack: [];
|
|
573
|
-
}, TypeBox.TIdentifier<"K">, TypeBox.TKeyOfInstantiate<{}, {
|
|
574
|
-
callstack: [];
|
|
575
|
-
}, T>, TypeBox.TRef<"K">, TUnion$1<[TypeBox.TIndexInstantiate<{}, {
|
|
576
|
-
callstack: [];
|
|
577
|
-
}, T, TypeBox.TRef<"K">>, TNull$1]>>;
|
|
578
|
-
/**
|
|
579
|
-
* Create a schema for a string enum.
|
|
580
|
-
*/
|
|
581
|
-
enum<T extends string[]>(values: [...T], options?: TTextOptions): TUnsafe$1<T[number]>;
|
|
582
|
-
/**
|
|
583
|
-
* Create a schema for a bigint represented as a string.
|
|
584
|
-
* This is a string that validates bigint format (e.g. "123456789").
|
|
585
|
-
*/
|
|
586
|
-
bigint(options?: TStringOptions$1): TString$1;
|
|
587
|
-
/**
|
|
588
|
-
* Create a schema for a URL represented as a string.
|
|
589
|
-
*/
|
|
590
|
-
url(options?: TStringOptions$1): TString$1;
|
|
591
|
-
/**
|
|
592
|
-
* Create a schema for binary data represented as a base64 string.
|
|
593
|
-
*/
|
|
594
|
-
binary(options: TStringOptions$1): TString$1;
|
|
595
|
-
/**
|
|
596
|
-
* Create a schema for uuid.
|
|
597
|
-
*/
|
|
598
|
-
uuid(options?: TStringOptions$1): TString$1;
|
|
599
|
-
/**
|
|
600
|
-
* Create a schema for a file-like object.
|
|
601
|
-
*
|
|
602
|
-
* File like mimics the File API in browsers, but is adapted to work in Node.js as well.
|
|
603
|
-
*
|
|
604
|
-
* Implementation of file-like objects is handled by "alepha/file" package.
|
|
605
|
-
*/
|
|
606
|
-
file(options?: {
|
|
607
|
-
maxSize?: number;
|
|
608
|
-
}): TFile;
|
|
609
|
-
/**
|
|
610
|
-
* @experimental
|
|
611
|
-
*/
|
|
612
|
-
stream(): TStream;
|
|
613
|
-
email(options?: TStringOptions$1): TString$1;
|
|
614
|
-
e164(options?: TStringOptions$1): TString$1;
|
|
615
|
-
bcp47(options?: TStringOptions$1): TString$1;
|
|
616
|
-
/**
|
|
617
|
-
* Create a schema for short text, such as names or titles.
|
|
618
|
-
* Default max length is 64 characters.
|
|
619
|
-
*/
|
|
620
|
-
shortText(options?: TStringOptions$1): TString$1;
|
|
621
|
-
/**
|
|
622
|
-
* Create a schema for long text, such as descriptions or comments.
|
|
623
|
-
* Default max length is 1024 characters.
|
|
624
|
-
*/
|
|
625
|
-
longText(options?: TStringOptions$1): TString$1;
|
|
626
|
-
/**
|
|
627
|
-
* Create a schema for rich text, such as HTML or Markdown.
|
|
628
|
-
* Default max length is 65535 characters.
|
|
629
|
-
*/
|
|
630
|
-
richText(options?: TStringOptions$1): TString$1;
|
|
631
|
-
/**
|
|
632
|
-
* Create a schema for a string enum e.g. LIKE_THIS.
|
|
633
|
-
*/
|
|
634
|
-
snakeCase: (options?: TStringOptions$1) => TString$1;
|
|
635
|
-
/**
|
|
636
|
-
* Create a schema for an object with a value and label.
|
|
637
|
-
*/
|
|
638
|
-
valueLabel: (options?: TObjectOptions$1) => TObject$1<{
|
|
639
|
-
value: TString$1;
|
|
640
|
-
label: TString$1;
|
|
641
|
-
description: TypeBox.TOptional<TString$1>;
|
|
642
|
-
}>;
|
|
643
|
-
datetime: (options?: TStringOptions$1) => TString$1;
|
|
644
|
-
date: (options?: TStringOptions$1) => TString$1;
|
|
645
|
-
time: (options?: TStringOptions$1) => TString$1;
|
|
646
|
-
duration: (options?: TStringOptions$1) => TString$1;
|
|
647
|
-
}
|
|
648
|
-
type TextLength = "short" | "regular" | "long" | "rich";
|
|
649
|
-
interface TTextOptions extends TStringOptions$1 {
|
|
650
|
-
/**
|
|
651
|
-
* Predefined size of the text.
|
|
652
|
-
*
|
|
653
|
-
* - `short` - short text, such as names or titles. Default max length is 64 characters.
|
|
654
|
-
* - `regular` - regular text, such as single-line input. Default max length is 255 characters.
|
|
655
|
-
* - `long` - long text, such as descriptions or comments. Default max length is 1024 characters.
|
|
656
|
-
* - `rich` - rich text, such as HTML or Markdown. Default max length is 65535 characters.
|
|
657
|
-
*
|
|
658
|
-
* You can override the default max length by specifying `maxLength` in the options.
|
|
659
|
-
*
|
|
660
|
-
* @default "regular"
|
|
661
|
-
*/
|
|
662
|
-
size?: TextLength;
|
|
663
|
-
/**
|
|
664
|
-
* Trim whitespace from both ends of the string.
|
|
665
|
-
*
|
|
666
|
-
* @default true
|
|
667
|
-
*/
|
|
668
|
-
trim?: boolean;
|
|
669
|
-
/**
|
|
670
|
-
* Convert the string to lowercase.
|
|
671
|
-
*
|
|
672
|
-
* @default false
|
|
673
|
-
*/
|
|
674
|
-
lowercase?: boolean;
|
|
675
|
-
}
|
|
676
|
-
declare const t: TypeProvider;
|
|
677
|
-
//#endregion
|
|
678
|
-
//#region src/core/providers/SchemaCodec.d.ts
|
|
679
|
-
declare abstract class SchemaCodec {
|
|
680
|
-
/**
|
|
681
|
-
* Encode the value to a string format.
|
|
682
|
-
*/
|
|
683
|
-
abstract encodeToString<T extends TSchema>(schema: T, value: Static<T>): string;
|
|
684
|
-
/**
|
|
685
|
-
* Encode the value to a binary format.
|
|
686
|
-
*/
|
|
687
|
-
abstract encodeToBinary<T extends TSchema>(schema: T, value: Static<T>): Uint8Array;
|
|
688
|
-
/**
|
|
689
|
-
* Decode string, binary, or other formats to the schema type.
|
|
690
|
-
*/
|
|
691
|
-
abstract decode<T>(schema: TSchema, value: unknown): T;
|
|
692
|
-
}
|
|
693
|
-
//#endregion
|
|
694
|
-
//#region src/core/providers/JsonSchemaCodec.d.ts
|
|
695
|
-
declare class JsonSchemaCodec extends SchemaCodec {
|
|
696
|
-
protected readonly json: Json;
|
|
697
|
-
protected readonly encoder: TextEncoder;
|
|
698
|
-
protected readonly decoder: TextDecoder;
|
|
699
|
-
encodeToString<T extends TSchema$1>(schema: T, value: Static<T>): string;
|
|
700
|
-
encodeToBinary<T extends TSchema$1>(schema: T, value: Static<T>): Uint8Array;
|
|
701
|
-
decode<T>(schema: TSchema$1, value: unknown): T;
|
|
702
|
-
}
|
|
703
|
-
//#endregion
|
|
704
|
-
//#region src/core/providers/SchemaValidator.d.ts
|
|
705
|
-
declare class SchemaValidator {
|
|
706
|
-
protected cache: Map<TSchema$1, Validator<TypeBox.TProperties, TSchema$1, unknown, unknown>>;
|
|
707
|
-
/**
|
|
708
|
-
* Validate the value against the provided schema.
|
|
709
|
-
*
|
|
710
|
-
* Validation create a new value by applying some preprocessing. (e.g., trimming text)
|
|
711
|
-
*/
|
|
712
|
-
validate<T extends TSchema$1>(schema: T, value: unknown, options?: ValidateOptions): Static<T>;
|
|
713
|
-
protected getValidator<T extends TSchema$1>(schema: T): Validator<{}, T>;
|
|
714
|
-
/**
|
|
715
|
-
* Preprocess the value based on the schema before validation.
|
|
716
|
-
*
|
|
717
|
-
* - If the value is `null` and the schema does not allow `null`, it converts it to `undefined`.
|
|
718
|
-
* - If the value is a string and the schema has a `~options.trim` flag, it trims whitespace from the string.
|
|
719
|
-
*/
|
|
720
|
-
beforeParse(schema: any, value: any, options: ValidateOptions): any;
|
|
721
|
-
/**
|
|
722
|
-
* Used by `beforeParse` to determine if a schema allows null values.
|
|
723
|
-
*/
|
|
724
|
-
protected isSchemaNullable: (schema: any) => boolean;
|
|
725
|
-
}
|
|
726
|
-
interface ValidateOptions {
|
|
727
|
-
trim?: boolean;
|
|
728
|
-
nullToUndefined?: boolean;
|
|
729
|
-
deleteUndefined?: boolean;
|
|
730
|
-
}
|
|
731
|
-
//#endregion
|
|
732
|
-
//#region src/core/providers/CodecManager.d.ts
|
|
733
|
-
type Encoding = "object" | "string" | "binary";
|
|
734
|
-
interface EncodeOptions<T extends Encoding = Encoding> {
|
|
735
|
-
/**
|
|
736
|
-
* The output encoding format:
|
|
737
|
-
* - 'string': Returns JSON string
|
|
738
|
-
* - 'binary': Returns Uint8Array (for protobuf, msgpack, etc.)
|
|
739
|
-
*
|
|
740
|
-
* @default "string"
|
|
741
|
-
*/
|
|
742
|
-
as?: T;
|
|
743
|
-
/**
|
|
744
|
-
* The encoder to use (e.g., 'json', 'protobuf', 'msgpack')
|
|
745
|
-
*
|
|
746
|
-
* @default "json"
|
|
747
|
-
*/
|
|
748
|
-
encoder?: string;
|
|
749
|
-
/**
|
|
750
|
-
* Validation options to apply before encoding.
|
|
751
|
-
*/
|
|
752
|
-
validation?: ValidateOptions | false;
|
|
753
|
-
}
|
|
754
|
-
type EncodeResult<T extends TSchema$1, E extends Encoding> = E extends "string" ? string : E extends "binary" ? Uint8Array : StaticEncode$1<T>;
|
|
755
|
-
interface DecodeOptions {
|
|
756
|
-
/**
|
|
757
|
-
* The encoder to use (e.g., 'json', 'protobuf', 'msgpack')
|
|
758
|
-
*
|
|
759
|
-
* @default "json"
|
|
760
|
-
*/
|
|
761
|
-
encoder?: string;
|
|
762
|
-
/**
|
|
763
|
-
* Validation options to apply before encoding.
|
|
764
|
-
*/
|
|
765
|
-
validation?: ValidateOptions | false;
|
|
766
|
-
}
|
|
767
|
-
/**
|
|
768
|
-
* CodecManager manages multiple codec formats and provides a unified interface
|
|
769
|
-
* for encoding and decoding data with different formats.
|
|
770
|
-
*/
|
|
771
|
-
declare class CodecManager {
|
|
772
|
-
protected readonly codecs: Map<string, SchemaCodec>;
|
|
773
|
-
protected readonly jsonCodec: JsonSchemaCodec;
|
|
774
|
-
protected readonly schemaValidator: SchemaValidator;
|
|
775
|
-
default: string;
|
|
776
|
-
constructor();
|
|
777
|
-
/**
|
|
778
|
-
* Register a new codec format.
|
|
779
|
-
*
|
|
780
|
-
* @param name - The name of the codec (e.g., 'json', 'protobuf')
|
|
781
|
-
* @param codec - The codec implementation
|
|
782
|
-
*/
|
|
783
|
-
register(name: string, codec: SchemaCodec): void;
|
|
784
|
-
/**
|
|
785
|
-
* Get a specific codec by name.
|
|
786
|
-
*
|
|
787
|
-
* @param name - The name of the codec
|
|
788
|
-
* @returns The codec instance
|
|
789
|
-
* @throws {AlephaError} If the codec is not found
|
|
790
|
-
*/
|
|
791
|
-
getCodec(name: string): SchemaCodec;
|
|
792
|
-
/**
|
|
793
|
-
* Encode data using the specified codec and output format.
|
|
794
|
-
*/
|
|
795
|
-
encode<T extends TSchema$1, E extends Encoding = "object">(schema: T, value: unknown, options?: EncodeOptions<E>): EncodeResult<T, E>;
|
|
796
|
-
/**
|
|
797
|
-
* Decode data using the specified codec.
|
|
798
|
-
*/
|
|
799
|
-
decode<T extends TSchema$1>(schema: T, data: any, options?: DecodeOptions): Static<T>;
|
|
800
|
-
/**
|
|
801
|
-
* Validate decoded data against the schema.
|
|
802
|
-
*
|
|
803
|
-
* This is automatically called before encoding or after decoding.
|
|
804
|
-
*/
|
|
805
|
-
validate<T extends TSchema$1>(schema: T, value: unknown, options?: ValidateOptions): Static<T>;
|
|
806
|
-
}
|
|
807
|
-
//#endregion
|
|
808
|
-
//#region src/core/providers/EventManager.d.ts
|
|
809
|
-
declare class EventManager {
|
|
810
|
-
protected logFn?: () => LoggerInterface | undefined;
|
|
811
|
-
/**
|
|
812
|
-
* List of events that can be triggered. Powered by $hook().
|
|
813
|
-
*/
|
|
814
|
-
protected events: Record<string, Array<Hook>>;
|
|
815
|
-
constructor(logFn?: () => LoggerInterface | undefined);
|
|
816
|
-
protected get log(): LoggerInterface | undefined;
|
|
817
|
-
/**
|
|
818
|
-
* Registers a hook for the specified event.
|
|
819
|
-
*/
|
|
820
|
-
on<T extends keyof Hooks>(event: T, hookOrFunc: Hook<T> | ((payload: Hooks[T]) => Async<void>)): () => void;
|
|
821
|
-
/**
|
|
822
|
-
* Emits the specified event with the given payload.
|
|
823
|
-
*/
|
|
824
|
-
emit<T extends keyof Hooks>(func: T, payload: Hooks[T], options?: {
|
|
825
|
-
/**
|
|
826
|
-
* If true, the hooks will be executed in reverse order.
|
|
827
|
-
* This is useful for "stop" hooks that should be executed in reverse order.
|
|
828
|
-
*
|
|
829
|
-
* @default false
|
|
830
|
-
*/
|
|
831
|
-
reverse?: boolean;
|
|
832
|
-
/**
|
|
833
|
-
* If true, the hooks will be logged with their execution time.
|
|
834
|
-
*
|
|
835
|
-
* @default false
|
|
836
|
-
*/
|
|
837
|
-
log?: boolean;
|
|
838
|
-
/**
|
|
839
|
-
* If true, errors will be caught and logged instead of throwing.
|
|
840
|
-
*
|
|
841
|
-
* @default false
|
|
842
|
-
*/
|
|
843
|
-
catch?: boolean;
|
|
844
|
-
}): Promise<void>;
|
|
845
|
-
}
|
|
846
|
-
//#endregion
|
|
847
|
-
//#region src/core/descriptors/$atom.d.ts
|
|
848
|
-
/**
|
|
849
|
-
* Define an atom for state management.
|
|
850
|
-
*
|
|
851
|
-
* Atom lets you define a piece of state with a name, schema, and default value.
|
|
852
|
-
*
|
|
853
|
-
* By default, Alepha state is just a simple key-value store.
|
|
854
|
-
* Using atoms allows you to have type safety, validation, and default values for your state.
|
|
855
|
-
*
|
|
856
|
-
* You control how state is structured and validated.
|
|
857
|
-
*
|
|
858
|
-
* Features:
|
|
859
|
-
* - Set a schema for validation
|
|
860
|
-
* - Set a default value for initial state
|
|
861
|
-
* - Rules, like read-only, custom validation, etc.
|
|
862
|
-
* - Automatic getter access in services with {@link $use}
|
|
863
|
-
* - SSR support (server state automatically serialized and hydrated on client)
|
|
864
|
-
* - React integration (useAtom hook for automatic component re-renders)
|
|
865
|
-
* - Middleware
|
|
866
|
-
* - Persistence adapters (localStorage, Redis, database, file system, cookie, etc.)
|
|
867
|
-
* - State migrations (version upgrades when schema changes)
|
|
868
|
-
* - Documentation generation & devtools integration
|
|
869
|
-
*
|
|
870
|
-
* Common use cases:
|
|
871
|
-
* - user preferences
|
|
872
|
-
* - feature flags
|
|
873
|
-
* - configuration options
|
|
874
|
-
* - session data
|
|
875
|
-
*
|
|
876
|
-
* Atom must contain only serializable data.
|
|
877
|
-
* Avoid storing complex objects like class instances, functions, or DOM elements.
|
|
878
|
-
* If you need to store complex data, consider using identifiers or references instead.
|
|
879
|
-
*/
|
|
880
|
-
declare const $atom: {
|
|
881
|
-
<T extends TObject<TProperties$2> | TArray$1, N extends string>(options: AtomOptions<T, N>): Atom<T, N>;
|
|
882
|
-
[KIND]: string;
|
|
883
|
-
};
|
|
884
|
-
type AtomOptions<T extends TAtomObject, N extends string> = {
|
|
885
|
-
name: N;
|
|
886
|
-
schema: T;
|
|
887
|
-
description?: string;
|
|
888
|
-
} & (T extends TOptionalAdd<T> ? {
|
|
889
|
-
default?: Static<T>;
|
|
890
|
-
} : {
|
|
891
|
-
default: Static<T>;
|
|
892
|
-
});
|
|
893
|
-
declare class Atom<T extends TAtomObject = TObject, N extends string = string> {
|
|
894
|
-
readonly options: AtomOptions<T, N>;
|
|
895
|
-
get schema(): T;
|
|
896
|
-
get key(): N;
|
|
897
|
-
constructor(options: AtomOptions<T, N>);
|
|
898
|
-
}
|
|
899
|
-
type TProperties$2 = any;
|
|
900
|
-
type TAtomObject = TObject<any> | TArray$1;
|
|
901
|
-
type AtomStatic<T extends TAtomObject> = T extends TOptionalAdd<T> ? Static<T> | undefined : Static<T>;
|
|
902
|
-
//#endregion
|
|
903
|
-
//#region src/core/providers/StateManager.d.ts
|
|
904
|
-
interface AtomWithValue {
|
|
905
|
-
atom: Atom;
|
|
906
|
-
value: unknown;
|
|
907
|
-
}
|
|
908
|
-
declare class StateManager<State$1 extends object = State> {
|
|
909
|
-
protected readonly als: AlsProvider;
|
|
910
|
-
protected readonly events: EventManager;
|
|
911
|
-
protected readonly codec: JsonSchemaCodec;
|
|
912
|
-
protected readonly atoms: Map<keyof State$1, Atom<TObject$1<TypeBox.TProperties>, string>>;
|
|
913
|
-
protected store: Partial<State$1>;
|
|
914
|
-
constructor(store?: Partial<State$1>);
|
|
915
|
-
getAtoms(context?: boolean): Array<AtomWithValue>;
|
|
916
|
-
register(atom: Atom<any>): this;
|
|
917
|
-
/**
|
|
918
|
-
* Get a value from the state with proper typing
|
|
919
|
-
*/
|
|
920
|
-
get<T extends TAtomObject>(target: Atom<T>): Static<T>;
|
|
921
|
-
get<Key extends keyof State$1>(target: Key): State$1[Key] | undefined;
|
|
922
|
-
/**
|
|
923
|
-
* Set a value in the state
|
|
924
|
-
*/
|
|
925
|
-
set<T extends TAtomObject>(target: Atom<T>, value: AtomStatic<T>): this;
|
|
926
|
-
set<Key extends keyof State$1>(target: Key, value: State$1[Key] | undefined): this;
|
|
927
|
-
/**
|
|
928
|
-
* Mutate a value in the state.
|
|
929
|
-
*/
|
|
930
|
-
mut<T extends TObject$1>(target: Atom<T>, mutator: (current: Static<T>) => Static<T>): this;
|
|
931
|
-
mut<Key extends keyof State$1>(target: Key, mutator: (current: State$1[Key] | undefined) => State$1[Key] | undefined): this;
|
|
932
|
-
/**
|
|
933
|
-
* Check if a key exists in the state
|
|
934
|
-
*/
|
|
935
|
-
has<Key extends keyof State$1>(key: Key): boolean;
|
|
936
|
-
/**
|
|
937
|
-
* Delete a key from the state (set to undefined)
|
|
938
|
-
*/
|
|
939
|
-
del<Key extends keyof State$1>(key: Key): this;
|
|
940
|
-
/**
|
|
941
|
-
* Push a value to an array in the state
|
|
942
|
-
*/
|
|
943
|
-
push<Key extends keyof OnlyArray<State$1>>(key: Key, value: NonNullable<State$1[Key]> extends Array<infer U> ? U : never): this;
|
|
944
|
-
/**
|
|
945
|
-
* Clear all state
|
|
946
|
-
*/
|
|
947
|
-
clear(): this;
|
|
948
|
-
/**
|
|
949
|
-
* Get all keys that exist in the state
|
|
950
|
-
*/
|
|
951
|
-
keys(): (keyof State$1)[];
|
|
952
|
-
}
|
|
953
|
-
type OnlyArray<T extends object> = { [K in keyof T]: NonNullable<T[K]> extends Array<any> ? K : never };
|
|
954
|
-
//#endregion
|
|
955
|
-
//#region src/core/Alepha.d.ts
|
|
956
|
-
/**
|
|
957
|
-
* Core container of the Alepha framework.
|
|
958
|
-
*
|
|
959
|
-
* It is responsible for managing the lifecycle of services,
|
|
960
|
-
* handling dependency injection,
|
|
961
|
-
* and providing a unified interface for the application.
|
|
962
|
-
*
|
|
963
|
-
* @example
|
|
964
|
-
* ```ts
|
|
965
|
-
* import { Alepha, run } from "alepha";
|
|
966
|
-
*
|
|
967
|
-
* class MyService {
|
|
968
|
-
* // business logic here
|
|
969
|
-
* }
|
|
970
|
-
*
|
|
971
|
-
* const alepha = Alepha.create({
|
|
972
|
-
* // state, env, and other properties
|
|
973
|
-
* })
|
|
974
|
-
*
|
|
975
|
-
* alepha.with(MyService);
|
|
976
|
-
*
|
|
977
|
-
* run(alepha); // trigger .start (and .stop) automatically
|
|
978
|
-
* ```
|
|
979
|
-
*
|
|
980
|
-
* ### Alepha Factory
|
|
981
|
-
*
|
|
982
|
-
* Alepha.create() is an enhanced version of new Alepha().
|
|
983
|
-
* - It merges `process.env` with the provided state.env when available.
|
|
984
|
-
* - It populates the test hooks for Vitest or Jest environments when available.
|
|
985
|
-
*
|
|
986
|
-
* new Alepha() is fine if you don't need these helpers.
|
|
987
|
-
*
|
|
988
|
-
* ### Platforms & Environments
|
|
989
|
-
*
|
|
990
|
-
* Alepha is designed to work in various environments:
|
|
991
|
-
* - **Browser**: Runs in the browser, using the global `window` object.
|
|
992
|
-
* - **Serverless**: Runs in serverless environments like Vercel or Vite.
|
|
993
|
-
* - **Test**: Runs in test environments like Jest or Vitest.
|
|
994
|
-
* - **Production**: Runs in production environments, typically with NODE_ENV set to "production".
|
|
995
|
-
* * You can check the current environment using the following methods:
|
|
996
|
-
*
|
|
997
|
-
* - `isBrowser()`: Returns true if the App is running in a browser environment.
|
|
998
|
-
* - `isServerless()`: Returns true if the App is running in a serverless environment.
|
|
999
|
-
* - `isTest()`: Returns true if the App is running in a test environment.
|
|
1000
|
-
* - `isProduction()`: Returns true if the App is running in a production environment.
|
|
1001
|
-
*
|
|
1002
|
-
* ### State & Environment
|
|
1003
|
-
*
|
|
1004
|
-
* The state of the Alepha container is stored in the `store` property.
|
|
1005
|
-
* Most important property is `store.env`, which contains the environment variables.
|
|
1006
|
-
*
|
|
1007
|
-
* ```ts
|
|
1008
|
-
* const alepha = Alepha.create({ env: { MY_VAR: "value" } });
|
|
1009
|
-
*
|
|
1010
|
-
* // You can access the environment variables using alepha.env
|
|
1011
|
-
* console.log(alepha.env.MY_VAR); // "value"
|
|
1012
|
-
*
|
|
1013
|
-
* // But you should use $env() descriptor to get typed values from the environment.
|
|
1014
|
-
* class App {
|
|
1015
|
-
* env = $env(
|
|
1016
|
-
* t.object({
|
|
1017
|
-
* MY_VAR: t.text(),
|
|
1018
|
-
* })
|
|
1019
|
-
* );
|
|
1020
|
-
* }
|
|
1021
|
-
* ```
|
|
1022
|
-
*
|
|
1023
|
-
* ### Modules
|
|
1024
|
-
*
|
|
1025
|
-
* Modules are a way to group services together.
|
|
1026
|
-
* You can register a module using the `$module` descriptor.
|
|
1027
|
-
*
|
|
1028
|
-
* ```ts
|
|
1029
|
-
* import { $module } from "alepha";
|
|
1030
|
-
*
|
|
1031
|
-
* class MyLib {}
|
|
1032
|
-
*
|
|
1033
|
-
* const myModule = $module({
|
|
1034
|
-
* name: "my.project.module",
|
|
1035
|
-
* services: [MyLib],
|
|
1036
|
-
* });
|
|
1037
|
-
* ```
|
|
1038
|
-
*
|
|
1039
|
-
* Do not use modules for small applications.
|
|
1040
|
-
*
|
|
1041
|
-
* ### Hooks
|
|
1042
|
-
*
|
|
1043
|
-
* Hooks are a way to run async functions from all registered providers/services.
|
|
1044
|
-
* You can register a hook using the `$hook` descriptor.
|
|
1045
|
-
*
|
|
1046
|
-
* ```ts
|
|
1047
|
-
* import { $hook } from "alepha";
|
|
1048
|
-
*
|
|
1049
|
-
* class App {
|
|
1050
|
-
* log = $logger();
|
|
1051
|
-
* onCustomerHook = $hook({
|
|
1052
|
-
* on: "my:custom:hook",
|
|
1053
|
-
* handler: () => {
|
|
1054
|
-
* this.log?.info("App is being configured");
|
|
1055
|
-
* },
|
|
1056
|
-
* });
|
|
1057
|
-
* }
|
|
1058
|
-
*
|
|
1059
|
-
* Alepha.create()
|
|
1060
|
-
* .with(App)
|
|
1061
|
-
* .start()
|
|
1062
|
-
* .then(alepha => alepha.events.emit("my:custom:hook"));
|
|
1063
|
-
* ```
|
|
1064
|
-
*
|
|
1065
|
-
* Hooks are fully typed. You can create your own hooks by using module augmentation:
|
|
1066
|
-
*
|
|
1067
|
-
* ```ts
|
|
1068
|
-
* declare module "alepha" {
|
|
1069
|
-
* interface Hooks {
|
|
1070
|
-
* "my:custom:hook": {
|
|
1071
|
-
* arg1: string;
|
|
1072
|
-
* }
|
|
1073
|
-
* }
|
|
1074
|
-
* }
|
|
1075
|
-
* ```
|
|
1076
|
-
*
|
|
1077
|
-
* @module alepha
|
|
1078
|
-
*/
|
|
1079
|
-
declare class Alepha {
|
|
1080
|
-
/**
|
|
1081
|
-
* Creates a new instance of the Alepha container with some helpers:
|
|
1082
|
-
*
|
|
1083
|
-
* - merges `process.env` with the provided state.env when available.
|
|
1084
|
-
* - populates the test hooks for Vitest or Jest environments when available.
|
|
1085
|
-
*
|
|
1086
|
-
* If you are not interested about these helpers, you can use the constructor directly.
|
|
1087
|
-
*/
|
|
1088
|
-
static create(state?: Partial<State>): Alepha;
|
|
1089
|
-
/**
|
|
1090
|
-
* Flag indicating whether the App won't accept any further changes.
|
|
1091
|
-
* Pass to true when #start() is called.
|
|
1092
|
-
*/
|
|
1093
|
-
protected locked: boolean;
|
|
1094
|
-
/**
|
|
1095
|
-
* True if the App has been configured.
|
|
1096
|
-
*/
|
|
1097
|
-
protected configured: boolean;
|
|
1098
|
-
/**
|
|
1099
|
-
* True if the App has started.
|
|
1100
|
-
*/
|
|
1101
|
-
protected started: boolean;
|
|
1102
|
-
/**
|
|
1103
|
-
* True if the App is ready.
|
|
1104
|
-
*/
|
|
1105
|
-
protected ready: boolean;
|
|
1106
|
-
/**
|
|
1107
|
-
* A promise that resolves when the App has started.
|
|
1108
|
-
*/
|
|
1109
|
-
protected starting?: PromiseWithResolvers<this>;
|
|
1110
|
-
/**
|
|
1111
|
-
* Initial state of the container.
|
|
1112
|
-
*
|
|
1113
|
-
* > Used to initialize the StateManager.
|
|
1114
|
-
*/
|
|
1115
|
-
protected init: Partial<State>;
|
|
1116
|
-
/**
|
|
1117
|
-
* During the instantiation process, we keep a list of pending instantiations.
|
|
1118
|
-
* > It allows us to detect circular dependencies.
|
|
1119
|
-
*/
|
|
1120
|
-
protected pendingInstantiations: Service[];
|
|
1121
|
-
/**
|
|
1122
|
-
* Cache for environment variables.
|
|
1123
|
-
* > It allows us to avoid parsing the same schema multiple times.
|
|
1124
|
-
*/
|
|
1125
|
-
protected cacheEnv: Map<TSchema, any>;
|
|
1126
|
-
/**
|
|
1127
|
-
* List of modules that are registered in the container.
|
|
1128
|
-
*
|
|
1129
|
-
* Modules are used to group services and provide a way to register them in the container.
|
|
1130
|
-
*/
|
|
1131
|
-
protected modules: Array<Module>;
|
|
1132
|
-
/**
|
|
1133
|
-
* List of service substitutions.
|
|
1134
|
-
*
|
|
1135
|
-
* Services registered here will be replaced by the specified service when injected.
|
|
1136
|
-
*/
|
|
1137
|
-
protected substitutions: Map<Service, {
|
|
1138
|
-
use: Service;
|
|
1139
|
-
}>;
|
|
1140
|
-
/**
|
|
1141
|
-
* Registry of descriptors.
|
|
1142
|
-
*/
|
|
1143
|
-
protected descriptorRegistry: Map<Service<Descriptor<{}>>, Descriptor<{}>[]>;
|
|
1144
|
-
/**
|
|
1145
|
-
* List of all services + how they are provided.
|
|
1146
|
-
*/
|
|
1147
|
-
protected registry: Map<Service, ServiceDefinition>;
|
|
1148
|
-
/**
|
|
1149
|
-
* Node.js feature that allows to store context across asynchronous calls.
|
|
1150
|
-
*
|
|
1151
|
-
* This is used for logging, tracing, and other context-related features.
|
|
1152
|
-
*
|
|
1153
|
-
* Mocked for browser environments.
|
|
1154
|
-
*/
|
|
1155
|
-
get context(): AlsProvider;
|
|
1156
|
-
/**
|
|
1157
|
-
* Event manager to handle lifecycle events and custom events.
|
|
1158
|
-
*/
|
|
1159
|
-
get events(): EventManager;
|
|
1160
|
-
/**
|
|
1161
|
-
* State manager to store arbitrary values.
|
|
1162
|
-
*/
|
|
1163
|
-
get state(): StateManager<State>;
|
|
1164
|
-
/**
|
|
1165
|
-
* Codec manager for encoding and decoding data with different formats.
|
|
1166
|
-
*
|
|
1167
|
-
* Supports multiple codec formats (JSON, Protobuf, etc.) with a unified interface.
|
|
1168
|
-
*/
|
|
1169
|
-
get codec(): CodecManager;
|
|
1170
|
-
/**
|
|
1171
|
-
* Get logger instance.
|
|
1172
|
-
*/
|
|
1173
|
-
get log(): LoggerInterface | undefined;
|
|
1174
|
-
/**
|
|
1175
|
-
* The environment variables for the App.
|
|
1176
|
-
*/
|
|
1177
|
-
get env(): Readonly<Env>;
|
|
1178
|
-
constructor(init?: Partial<State>);
|
|
1179
|
-
/**
|
|
1180
|
-
* True when start() is called.
|
|
1181
|
-
*
|
|
1182
|
-
* -> No more services can be added, it's over, bye!
|
|
1183
|
-
*/
|
|
1184
|
-
isLocked(): boolean;
|
|
1185
|
-
/**
|
|
1186
|
-
* Returns whether the App is configured.
|
|
1187
|
-
*
|
|
1188
|
-
* It means that Alepha#configure() has been called.
|
|
1189
|
-
*
|
|
1190
|
-
* > By default, configure() is called automatically when start() is called, but you can also call it manually.
|
|
1191
|
-
*/
|
|
1192
|
-
isConfigured(): boolean;
|
|
1193
|
-
/**
|
|
1194
|
-
* Returns whether the App has started.
|
|
1195
|
-
*
|
|
1196
|
-
* It means that #start() has been called but maybe not all services are ready.
|
|
1197
|
-
*/
|
|
1198
|
-
isStarted(): boolean;
|
|
1199
|
-
/**
|
|
1200
|
-
* True if the App is ready. It means that Alepha is started AND ready() hook has beed called.
|
|
1201
|
-
*/
|
|
1202
|
-
isReady(): boolean;
|
|
1203
|
-
/**
|
|
1204
|
-
* True if the App is running in a Continuous Integration environment.
|
|
1205
|
-
*/
|
|
1206
|
-
isCI(): boolean;
|
|
1207
|
-
/**
|
|
1208
|
-
* True if the App is running in a browser environment.
|
|
1209
|
-
*/
|
|
1210
|
-
isBrowser(): boolean;
|
|
1211
|
-
/**
|
|
1212
|
-
* Returns whether the App is running in Vite dev mode.
|
|
1213
|
-
*/
|
|
1214
|
-
isViteDev(): boolean;
|
|
1215
|
-
isBun(): boolean;
|
|
1216
|
-
/**
|
|
1217
|
-
* Returns whether the App is running in a serverless environment.
|
|
1218
|
-
*/
|
|
1219
|
-
isServerless(): boolean;
|
|
1220
|
-
/**
|
|
1221
|
-
* Returns whether the App is in test mode. (Running in a test environment)
|
|
1222
|
-
*
|
|
1223
|
-
* > This is automatically set when running tests with Jest or Vitest.
|
|
1224
|
-
*/
|
|
1225
|
-
isTest(): boolean;
|
|
1226
|
-
/**
|
|
1227
|
-
* Returns whether the App is in production mode. (Running in a production environment)
|
|
1228
|
-
*
|
|
1229
|
-
* > This is automatically set by Vite or Vercel. However, you have to set it manually when running Docker apps.
|
|
1230
|
-
*/
|
|
1231
|
-
isProduction(): boolean;
|
|
1232
|
-
/**
|
|
1233
|
-
* Starts the App.
|
|
1234
|
-
*
|
|
1235
|
-
* - Lock any further changes to the container.
|
|
1236
|
-
* - Run "configure" hook for all services. Descriptors will be processed.
|
|
1237
|
-
* - Run "start" hook for all services. Providers will connect/listen/...
|
|
1238
|
-
* - Run "ready" hook for all services. This is the point where the App is ready to serve requests.
|
|
1239
|
-
*
|
|
1240
|
-
* @return A promise that resolves when the App has started.
|
|
1241
|
-
*/
|
|
1242
|
-
start(): Promise<this>;
|
|
1243
|
-
/**
|
|
1244
|
-
* Stops the App.
|
|
1245
|
-
*
|
|
1246
|
-
* - Run "stop" hook for all services.
|
|
1247
|
-
*
|
|
1248
|
-
* Stop will NOT reset the container.
|
|
1249
|
-
* Stop will NOT unlock the container.
|
|
1250
|
-
*
|
|
1251
|
-
* > Stop is used to gracefully shut down the application, nothing more. There is no "restart".
|
|
1252
|
-
*
|
|
1253
|
-
* @return A promise that resolves when the App has stopped.
|
|
1254
|
-
*/
|
|
1255
|
-
stop(): Promise<void>;
|
|
1256
|
-
/**
|
|
1257
|
-
* Check if entry is registered in the container.
|
|
1258
|
-
*/
|
|
1259
|
-
has(entry: ServiceEntry, opts?: {
|
|
1260
|
-
/**
|
|
1261
|
-
* Check if the entry is registered in the pending instantiation stack.
|
|
1262
|
-
*
|
|
1263
|
-
* @default true
|
|
1264
|
-
*/
|
|
1265
|
-
inStack?: boolean;
|
|
1266
|
-
/**
|
|
1267
|
-
* Check if the entry is registered in the container registry.
|
|
1268
|
-
*
|
|
1269
|
-
* @default true
|
|
1270
|
-
*/
|
|
1271
|
-
inRegistry?: boolean;
|
|
1272
|
-
/**
|
|
1273
|
-
* Check if the entry is registered in the substitutions.
|
|
1274
|
-
*
|
|
1275
|
-
* @default true
|
|
1276
|
-
*/
|
|
1277
|
-
inSubstitutions?: boolean;
|
|
1278
|
-
/**
|
|
1279
|
-
* Where to look for registered services.
|
|
1280
|
-
*
|
|
1281
|
-
* @default this.registry
|
|
1282
|
-
*/
|
|
1283
|
-
registry?: Map<Service, ServiceDefinition>;
|
|
1284
|
-
}): boolean;
|
|
1285
|
-
/**
|
|
1286
|
-
* Registers the specified service in the container.
|
|
1287
|
-
*
|
|
1288
|
-
* - If the service is ALREADY registered, the method does nothing.
|
|
1289
|
-
* - If the service is NOT registered, a new instance is created and registered.
|
|
1290
|
-
*
|
|
1291
|
-
* Method is chainable, so you can register multiple services in a single call.
|
|
1292
|
-
*
|
|
1293
|
-
* > ServiceEntry allows to provide a service **substitution** feature.
|
|
1294
|
-
*
|
|
1295
|
-
* @example
|
|
1296
|
-
* ```ts
|
|
1297
|
-
* class A { value = "a"; }
|
|
1298
|
-
* class B { value = "b"; }
|
|
1299
|
-
* class M { a = $inject(A); }
|
|
1300
|
-
*
|
|
1301
|
-
* Alepha.create().with({ provide: A, use: B }).get(M).a.value; // "b"
|
|
1302
|
-
* ```
|
|
1303
|
-
*
|
|
1304
|
-
* > **Substitution** is an advanced feature that allows you to replace a service with another service.
|
|
1305
|
-
* > It's useful for testing or for providing different implementations of a service.
|
|
1306
|
-
* > If you are interested in configuring a service, use Alepha#configure() instead.
|
|
1307
|
-
*
|
|
1308
|
-
* @param serviceEntry - The service to register in the container.
|
|
1309
|
-
* @return Current instance of Alepha.
|
|
1310
|
-
*/
|
|
1311
|
-
with<T extends object>(serviceEntry: ServiceEntry<T> | {
|
|
1312
|
-
default: ServiceEntry<T>;
|
|
1313
|
-
}): this;
|
|
1314
|
-
/**
|
|
1315
|
-
* Get an instance of the specified service from the container.
|
|
1316
|
-
*
|
|
1317
|
-
* @see {@link InjectOptions} for the available options.
|
|
1318
|
-
*/
|
|
1319
|
-
inject<T extends object>(service: Service<T> | string, opts?: InjectOptions<T>): T;
|
|
1320
|
-
/**
|
|
1321
|
-
* Applies environment variables to the provided schema and state object.
|
|
1322
|
-
*
|
|
1323
|
-
* It replaces also all templated $ENV inside string values.
|
|
1324
|
-
*
|
|
1325
|
-
* @param schema - The schema object to apply environment variables to.
|
|
1326
|
-
* @return The schema object with environment variables applied.
|
|
1327
|
-
*/
|
|
1328
|
-
parseEnv<T extends TObject$1>(schema: T): Static$1<T>;
|
|
1329
|
-
/**
|
|
1330
|
-
* Dump the current dependency graph of the App.
|
|
1331
|
-
*
|
|
1332
|
-
* This method returns a record where the keys are the names of the services.
|
|
1333
|
-
*/
|
|
1334
|
-
graph(): Record<string, {
|
|
1335
|
-
from: string[];
|
|
1336
|
-
as?: string[];
|
|
1337
|
-
module?: string;
|
|
1338
|
-
}>;
|
|
1339
|
-
services<T extends object>(base: Service<T>): Array<T>;
|
|
1340
|
-
/**
|
|
1341
|
-
* Get all descriptors of the specified type.
|
|
1342
|
-
*/
|
|
1343
|
-
descriptors<TDescriptor extends Descriptor>(factory: {
|
|
1344
|
-
[KIND]: InstantiableClass<TDescriptor>;
|
|
1345
|
-
} | string): Array<TDescriptor>;
|
|
1346
|
-
protected new<T extends object>(service: Service<T>, args?: any[]): T;
|
|
1347
|
-
protected processDescriptor(value: Descriptor, propertyKey?: string): void;
|
|
1348
|
-
}
|
|
1349
|
-
interface Hook<T extends keyof Hooks = any> {
|
|
1350
|
-
caller?: Service;
|
|
1351
|
-
priority?: "first" | "last";
|
|
1352
|
-
callback: (payload: Hooks[T]) => Async<void>;
|
|
1353
|
-
}
|
|
1354
|
-
/**
|
|
1355
|
-
* This is how we store services in the Alepha container.
|
|
1356
|
-
*/
|
|
1357
|
-
interface ServiceDefinition<T extends object = any> {
|
|
1358
|
-
/**
|
|
1359
|
-
* The instance of the class or type definition.
|
|
1360
|
-
* Mostly used for caching / singleton but can be used for other purposes like forcing the instance.
|
|
1361
|
-
*/
|
|
1362
|
-
instance: T;
|
|
1363
|
-
/**
|
|
1364
|
-
* List of classes which use this class.
|
|
1365
|
-
*/
|
|
1366
|
-
parents: Array<Service | null>;
|
|
1367
|
-
}
|
|
1368
|
-
interface Env {
|
|
1369
|
-
[key: string]: string | boolean | number | undefined;
|
|
1370
|
-
/**
|
|
1371
|
-
* Optional environment variable that indicates the current environment.
|
|
1372
|
-
*/
|
|
1373
|
-
NODE_ENV?: "dev" | "test" | "production";
|
|
1374
|
-
/**
|
|
1375
|
-
* Optional name of the application.
|
|
1376
|
-
*/
|
|
1377
|
-
APP_NAME?: string;
|
|
1378
|
-
/**
|
|
1379
|
-
* Optional root module name.
|
|
1380
|
-
*/
|
|
1381
|
-
MODULE_NAME?: string;
|
|
1382
|
-
}
|
|
1383
|
-
interface State {
|
|
1384
|
-
/**
|
|
1385
|
-
* Environment variables for the application.
|
|
1386
|
-
*/
|
|
1387
|
-
env?: Readonly<Env>;
|
|
1388
|
-
/**
|
|
1389
|
-
* Logger instance to be used by the Alepha container.
|
|
1390
|
-
*
|
|
1391
|
-
* @internal
|
|
1392
|
-
*/
|
|
1393
|
-
"alepha.logger"?: LoggerInterface;
|
|
1394
|
-
/**
|
|
1395
|
-
* If defined, the Alepha container will only register this service and its dependencies.
|
|
1396
|
-
*/
|
|
1397
|
-
"alepha.target"?: Service;
|
|
1398
|
-
/**
|
|
1399
|
-
* Bind to Vitest 'beforeAll' hook.
|
|
1400
|
-
* Used for testing purposes.
|
|
1401
|
-
* This is automatically attached if Alepha#create() detects a test environment and global 'beforeAll' is available.
|
|
1402
|
-
*/
|
|
1403
|
-
"alepha.test.beforeAll"?: (run: any) => any;
|
|
1404
|
-
/**
|
|
1405
|
-
* Bind to Vitest 'afterAll' hook.
|
|
1406
|
-
* Used for testing purposes.
|
|
1407
|
-
* This is automatically attached if Alepha#create() detects a test environment and global 'afterAll' is available.
|
|
1408
|
-
*/
|
|
1409
|
-
"alepha.test.afterAll"?: (run: any) => any;
|
|
1410
|
-
/**
|
|
1411
|
-
* Bind to Vitest 'afterEach' hook.
|
|
1412
|
-
* Used for testing purposes.
|
|
1413
|
-
* This is automatically attached if Alepha#create() detects a test environment and global 'afterEach' is available.
|
|
1414
|
-
*/
|
|
1415
|
-
"alepha.test.afterEach"?: (run: any) => any;
|
|
1416
|
-
/**
|
|
1417
|
-
* Bind to Vitest 'onTestFinished' hook.
|
|
1418
|
-
* Used for testing purposes.
|
|
1419
|
-
* This is automatically attached if Alepha#create() detects a test environment and global 'onTestFinished' is available.
|
|
1420
|
-
*/
|
|
1421
|
-
"alepha.test.onTestFinished"?: (run: any) => any;
|
|
1422
|
-
/**
|
|
1423
|
-
* List of static assets to be copied to the output directory during the build process.
|
|
1424
|
-
*
|
|
1425
|
-
* Used for Alepha-based applications that require static assets.
|
|
1426
|
-
*
|
|
1427
|
-
* See alepha/vite for more details.
|
|
1428
|
-
*/
|
|
1429
|
-
"alepha.build.assets"?: Array<string>;
|
|
1430
|
-
}
|
|
1431
|
-
interface Hooks {
|
|
1432
|
-
/**
|
|
1433
|
-
* Used for testing purposes.
|
|
1434
|
-
*/
|
|
1435
|
-
echo: unknown;
|
|
1436
|
-
/**
|
|
1437
|
-
* Triggered during the configuration phase. Before the start phase.
|
|
1438
|
-
*/
|
|
1439
|
-
configure: Alepha;
|
|
1440
|
-
/**
|
|
1441
|
-
* Triggered during the start phase. When `Alepha#start()` is called.
|
|
1442
|
-
*/
|
|
1443
|
-
start: Alepha;
|
|
1444
|
-
/**
|
|
1445
|
-
* Triggered during the ready phase. After the start phase.
|
|
1446
|
-
*/
|
|
1447
|
-
ready: Alepha;
|
|
1448
|
-
/**
|
|
1449
|
-
* Triggered during the stop phase.
|
|
1450
|
-
*
|
|
1451
|
-
* - Stop should be called after a SIGINT or SIGTERM signal in order to gracefully shutdown the application. (@see `run()` method)
|
|
1452
|
-
*
|
|
1453
|
-
*/
|
|
1454
|
-
stop: Alepha;
|
|
1455
|
-
/**
|
|
1456
|
-
* Triggered when a state value is mutated.
|
|
1457
|
-
*/
|
|
1458
|
-
"state:mutate": {
|
|
1459
|
-
/**
|
|
1460
|
-
* The key of the state that was mutated.
|
|
1461
|
-
*/
|
|
1462
|
-
key: keyof State;
|
|
1463
|
-
/**
|
|
1464
|
-
* The new value of the state.
|
|
1465
|
-
*/
|
|
1466
|
-
value: any;
|
|
1467
|
-
/**
|
|
1468
|
-
* The previous value of the state.
|
|
1469
|
-
*/
|
|
1470
|
-
prevValue: any;
|
|
1471
|
-
};
|
|
1472
|
-
}
|
|
1473
|
-
//#endregion
|
|
1474
|
-
//#region src/core/interfaces/Run.d.ts
|
|
1475
|
-
interface RunOptions {
|
|
1476
|
-
/**
|
|
1477
|
-
* Environment variables to be used by the application.
|
|
1478
|
-
* It will be merged with the current process environment.
|
|
1479
|
-
*/
|
|
1480
|
-
env?: Env;
|
|
1481
|
-
/**
|
|
1482
|
-
* A callback that will be executed before the application starts.
|
|
1483
|
-
*/
|
|
1484
|
-
configure?: (alepha: Alepha) => Async<void>;
|
|
1485
|
-
/**
|
|
1486
|
-
* A callback that will be executed once the application is ready.
|
|
1487
|
-
* This is useful for initializing resources or starting background tasks.
|
|
1488
|
-
*/
|
|
1489
|
-
ready?: (alepha: Alepha) => Async<void>;
|
|
1490
|
-
/**
|
|
1491
|
-
* If true, the application will .stop() after the ready callback is executed.
|
|
1492
|
-
* Useful for one-time tasks!
|
|
1493
|
-
*/
|
|
1494
|
-
once?: boolean;
|
|
1495
|
-
/**
|
|
1496
|
-
* If true, the application will run in cluster mode.
|
|
1497
|
-
*/
|
|
1498
|
-
cluster?: boolean;
|
|
1499
|
-
}
|
|
1500
|
-
//#endregion
|
|
1501
|
-
//#region src/core/constants/OPTIONS.d.ts
|
|
1502
|
-
/**
|
|
1503
|
-
* Used for descriptors options.
|
|
1504
|
-
*
|
|
1505
|
-
* @internal
|
|
1506
|
-
*/
|
|
1507
|
-
declare const OPTIONS: unique symbol;
|
|
1508
|
-
//#endregion
|
|
1509
|
-
//#region src/core/descriptors/$context.d.ts
|
|
1510
|
-
/**
|
|
1511
|
-
* Get Alepha instance and current service from the current context.
|
|
1512
|
-
*
|
|
1513
|
-
* It can only be used inside $descriptor functions.
|
|
1514
|
-
*
|
|
1515
|
-
* ```ts
|
|
1516
|
-
* import { $context } from "alepha";
|
|
1517
|
-
*
|
|
1518
|
-
* const $hello = () => {
|
|
1519
|
-
* const { alepha, service, module } = $context();
|
|
1520
|
-
*
|
|
1521
|
-
* // alepha - alepha instance
|
|
1522
|
-
* // service - class which is creating this descriptor, this is NOT the instance but the service definition
|
|
1523
|
-
* // module - module definition, if any
|
|
1524
|
-
*
|
|
1525
|
-
* return {};
|
|
1526
|
-
* }
|
|
1527
|
-
*
|
|
1528
|
-
* class MyService {
|
|
1529
|
-
* hello = $hello();
|
|
1530
|
-
* }
|
|
1531
|
-
*
|
|
1532
|
-
* const alepha = new Alepha().with(MyService);
|
|
1533
|
-
* ```
|
|
1534
|
-
*
|
|
1535
|
-
* @internal
|
|
1536
|
-
*/
|
|
1537
|
-
declare const $context: () => ContextDescriptor;
|
|
1538
|
-
interface ContextDescriptor {
|
|
1539
|
-
/**
|
|
1540
|
-
* Alepha instance.
|
|
1541
|
-
*/
|
|
1542
|
-
alepha: Alepha;
|
|
1543
|
-
/**
|
|
1544
|
-
* Service definition which is creating this descriptor.
|
|
1545
|
-
* This is NOT the instance but the service definition.
|
|
1546
|
-
*/
|
|
1547
|
-
service?: Service;
|
|
1548
|
-
/**
|
|
1549
|
-
* Module definition, if any.
|
|
1550
|
-
*/
|
|
1551
|
-
module?: Service;
|
|
1552
|
-
}
|
|
1553
|
-
//#endregion
|
|
1554
|
-
//#region src/core/descriptors/$env.d.ts
|
|
1555
|
-
/**
|
|
1556
|
-
* Get typed values from environment variables.
|
|
1557
|
-
*
|
|
1558
|
-
* @example
|
|
1559
|
-
* ```ts
|
|
1560
|
-
* const alepha = Alepha.create({
|
|
1561
|
-
* env: {
|
|
1562
|
-
* // Alepha.create() will also use process.env when running on Node.js
|
|
1563
|
-
* HELLO: "world",
|
|
1564
|
-
* }
|
|
1565
|
-
* });
|
|
1566
|
-
*
|
|
1567
|
-
* class App {
|
|
1568
|
-
* log = $logger();
|
|
1569
|
-
*
|
|
1570
|
-
* // program expect a var env "HELLO" as string to works
|
|
1571
|
-
* env = $env(t.object({
|
|
1572
|
-
* HELLO: t.text()
|
|
1573
|
-
* }));
|
|
1574
|
-
*
|
|
1575
|
-
* sayHello = () => this.log.info("Hello ${this.env.HELLO}")
|
|
1576
|
-
* }
|
|
1577
|
-
*
|
|
1578
|
-
* run(alepha.with(App));
|
|
1579
|
-
* ```
|
|
1580
|
-
*/
|
|
1581
|
-
declare const $env: <T extends TObject$1>(type: T) => Static$1<T>;
|
|
1582
|
-
//#endregion
|
|
1583
|
-
//#region src/core/descriptors/$hook.d.ts
|
|
1584
|
-
/**
|
|
1585
|
-
* Registers a new hook.
|
|
1586
|
-
*
|
|
1587
|
-
* ```ts
|
|
1588
|
-
* import { $hook } from "alepha";
|
|
1589
|
-
*
|
|
1590
|
-
* class MyProvider {
|
|
1591
|
-
* onStart = $hook({
|
|
1592
|
-
* name: "start", // or "configure", "ready", "stop", ...
|
|
1593
|
-
* handler: async (app) => {
|
|
1594
|
-
* // await db.connect(); ...
|
|
1595
|
-
* }
|
|
1596
|
-
* });
|
|
1597
|
-
* }
|
|
1598
|
-
* ```
|
|
1599
|
-
*
|
|
1600
|
-
* Hooks are used to run async functions from all registered providers/services.
|
|
1601
|
-
*
|
|
1602
|
-
* You can't register a hook after the App has started.
|
|
1603
|
-
*
|
|
1604
|
-
* It's used under the hood by the `configure`, `start`, and `stop` methods.
|
|
1605
|
-
* Some modules also use hooks to run their own logic. (e.g. `alepha/server`).
|
|
1606
|
-
*
|
|
1607
|
-
* You can create your own hooks by using module augmentation:
|
|
1608
|
-
*
|
|
1609
|
-
* ```ts
|
|
1610
|
-
* declare module "alepha" {
|
|
1611
|
-
*
|
|
1612
|
-
* interface Hooks {
|
|
1613
|
-
* "my:custom:hook": {
|
|
1614
|
-
* arg1: string;
|
|
1615
|
-
* }
|
|
1616
|
-
* }
|
|
1617
|
-
* }
|
|
1618
|
-
*
|
|
1619
|
-
* await alepha.events.emit("my:custom:hook", { arg1: "value" });
|
|
1620
|
-
* ```
|
|
1621
|
-
*
|
|
1622
|
-
*/
|
|
1623
|
-
declare const $hook: {
|
|
1624
|
-
<T extends keyof Hooks>(options: HookOptions<T>): HookDescriptor<T>;
|
|
1625
|
-
[KIND]: typeof HookDescriptor;
|
|
1626
|
-
};
|
|
1627
|
-
interface HookOptions<T extends keyof Hooks> {
|
|
1628
|
-
/**
|
|
1629
|
-
* The name of the hook. "configure", "start", "ready", "stop", ...
|
|
1630
|
-
*/
|
|
1631
|
-
on: T;
|
|
1632
|
-
/**
|
|
1633
|
-
* The handler to run when the hook is triggered.
|
|
1634
|
-
*/
|
|
1635
|
-
handler: (args: Hooks[T]) => Async<any>;
|
|
1636
|
-
/**
|
|
1637
|
-
* Force the hook to run first or last on the list of hooks.
|
|
1638
|
-
*/
|
|
1639
|
-
priority?: "first" | "last";
|
|
1640
|
-
/**
|
|
1641
|
-
* Empty placeholder, not implemented yet. :-)
|
|
1642
|
-
*/
|
|
1643
|
-
before?: object | Array<object>;
|
|
1644
|
-
/**
|
|
1645
|
-
* Empty placeholder, not implemented yet. :-)
|
|
1646
|
-
*/
|
|
1647
|
-
after?: object | Array<object>;
|
|
1648
|
-
}
|
|
1649
|
-
declare class HookDescriptor<T extends keyof Hooks> extends Descriptor<HookOptions<T>> {
|
|
1650
|
-
called: number;
|
|
1651
|
-
protected onInit(): void;
|
|
1652
|
-
}
|
|
1653
|
-
//#endregion
|
|
1654
|
-
//#region src/core/descriptors/$use.d.ts
|
|
1655
|
-
/**
|
|
1656
|
-
* Subscribes to an atom's state and returns its current value for use in components.
|
|
1657
|
-
*
|
|
1658
|
-
* Creates a reactive connection between an atom and a component, automatically registering
|
|
1659
|
-
* the atom in the application state if not already registered. The returned value is reactive
|
|
1660
|
-
* and will update when the atom's state changes.
|
|
1661
|
-
*
|
|
1662
|
-
* **Use Cases**: Accessing global state, sharing data between components, reactive UI updates
|
|
1663
|
-
*
|
|
1664
|
-
* @example
|
|
1665
|
-
* ```ts
|
|
1666
|
-
* const userState = $atom({ schema: t.object({ name: t.text(), role: t.text() }) });
|
|
1667
|
-
*
|
|
1668
|
-
* class UserComponent {
|
|
1669
|
-
* user = $use(userState); // Reactive reference to atom state
|
|
1670
|
-
*
|
|
1671
|
-
* render() {
|
|
1672
|
-
* return <div>Hello {this.user.name}!</div>;
|
|
1673
|
-
* }
|
|
1674
|
-
* }
|
|
1675
|
-
* ```
|
|
1676
|
-
*/
|
|
1677
|
-
declare const $use: <T extends TObject, N extends string>(atom: Atom<T, N>) => Readonly<Static<T>>;
|
|
1678
|
-
//#endregion
|
|
1679
|
-
//#region src/core/errors/AppNotStartedError.d.ts
|
|
1680
|
-
declare class AppNotStartedError extends AlephaError {
|
|
1681
|
-
readonly name = "AppNotStartedError";
|
|
1682
|
-
constructor();
|
|
1683
|
-
}
|
|
1684
|
-
//#endregion
|
|
1685
|
-
//#region src/core/errors/CircularDependencyError.d.ts
|
|
1686
|
-
declare class CircularDependencyError extends AlephaError {
|
|
1687
|
-
readonly name = "CircularDependencyError";
|
|
1688
|
-
constructor(provider: string, parents?: string[]);
|
|
1689
|
-
}
|
|
1690
|
-
//#endregion
|
|
1691
|
-
//#region src/core/errors/ContainerLockedError.d.ts
|
|
1692
|
-
declare class ContainerLockedError extends AlephaError {
|
|
1693
|
-
readonly name = "ContainerLockedError";
|
|
1694
|
-
constructor(message?: string);
|
|
1695
|
-
}
|
|
1696
|
-
//#endregion
|
|
1697
|
-
//#region src/core/errors/TooLateSubstitutionError.d.ts
|
|
1698
|
-
declare class TooLateSubstitutionError extends AlephaError {
|
|
1699
|
-
readonly name = "TooLateSubstitutionError";
|
|
1700
|
-
constructor(original: string, substitution: string);
|
|
1701
|
-
}
|
|
1702
|
-
//#endregion
|
|
1703
|
-
//#region src/core/schemas/pageSchema.d.ts
|
|
1704
|
-
declare const pageMetadataSchema: TObject<{
|
|
1705
|
-
number: TInteger;
|
|
1706
|
-
size: TInteger;
|
|
1707
|
-
offset: TInteger;
|
|
1708
|
-
numberOfElements: TInteger;
|
|
1709
|
-
totalElements: TOptional<TInteger>;
|
|
1710
|
-
totalPages: TOptional<TInteger>;
|
|
1711
|
-
isEmpty: TBoolean;
|
|
1712
|
-
isFirst: TBoolean;
|
|
1713
|
-
isLast: TBoolean;
|
|
1714
|
-
sort: TOptional<TObject<{
|
|
1715
|
-
sorted: TBoolean;
|
|
1716
|
-
fields: TArray<TObject<{
|
|
1717
|
-
field: TString;
|
|
1718
|
-
direction: TUnsafe<"asc" | "desc">;
|
|
1719
|
-
}>>;
|
|
1720
|
-
}>>;
|
|
1721
|
-
}>;
|
|
1722
|
-
/**
|
|
1723
|
-
* Create a pagination schema for the given object schema.
|
|
1724
|
-
*
|
|
1725
|
-
* Provides a standardized pagination response format compatible with Spring Data's Page interface.
|
|
1726
|
-
* This schema can be used across any data source (databases, APIs, caches, etc.).
|
|
1727
|
-
*
|
|
1728
|
-
* @example
|
|
1729
|
-
* ```ts
|
|
1730
|
-
* const userSchema = t.object({ id: t.integer(), name: t.text() });
|
|
1731
|
-
* const userPageSchema = pageSchema(userSchema);
|
|
1732
|
-
* ```
|
|
1733
|
-
*
|
|
1734
|
-
* @example In an API endpoint
|
|
1735
|
-
* ```ts
|
|
1736
|
-
* $action({
|
|
1737
|
-
* output: pageSchema(UserSchema),
|
|
1738
|
-
* handler: async () => {
|
|
1739
|
-
* return await userRepo.paginate();
|
|
1740
|
-
* }
|
|
1741
|
-
* })
|
|
1742
|
-
* ```
|
|
1743
|
-
*/
|
|
1744
|
-
declare const pageSchema: <T extends TObject | TRecord>(objectSchema: T, options?: TObjectOptions) => TPage<T>;
|
|
1745
|
-
type TPage<T extends TObject | TRecord> = TObject<{
|
|
1746
|
-
content: TArray<T>;
|
|
1747
|
-
page: typeof pageMetadataSchema;
|
|
1748
|
-
}>;
|
|
1749
|
-
/**
|
|
1750
|
-
* Opinionated type definition for a paginated response.
|
|
1751
|
-
*
|
|
1752
|
-
* Inspired by Spring Data's Page interface with all essential pagination metadata.
|
|
1753
|
-
* This generic type can be used with any data source.
|
|
1754
|
-
*
|
|
1755
|
-
* @example
|
|
1756
|
-
* ```ts
|
|
1757
|
-
* const page: Page<User> = {
|
|
1758
|
-
* content: [user1, user2, ...],
|
|
1759
|
-
* page: {
|
|
1760
|
-
* number: 0,
|
|
1761
|
-
* size: 10,
|
|
1762
|
-
* offset: 0,
|
|
1763
|
-
* numberOfElements: 10,
|
|
1764
|
-
* totalElements: 1200,
|
|
1765
|
-
* totalPages: 120,
|
|
1766
|
-
* isEmpty: false,
|
|
1767
|
-
* isFirst: true,
|
|
1768
|
-
* isLast: false,
|
|
1769
|
-
* sort: {
|
|
1770
|
-
* sorted: true,
|
|
1771
|
-
* fields: [
|
|
1772
|
-
* { field: "name", direction: "asc" }
|
|
1773
|
-
* ]
|
|
1774
|
-
* }
|
|
1775
|
-
* }
|
|
1776
|
-
* }
|
|
1777
|
-
* ```
|
|
1778
|
-
*/
|
|
1779
|
-
type Page<T> = {
|
|
1780
|
-
/**
|
|
1781
|
-
* Array of items on the current page.
|
|
1782
|
-
*/
|
|
1783
|
-
content: T[];
|
|
1784
|
-
page: Static<typeof pageMetadataSchema>;
|
|
1785
|
-
};
|
|
1786
|
-
type PageMetadata = Static<typeof pageMetadataSchema>;
|
|
1787
|
-
declare module "alepha" {
|
|
1788
|
-
interface TypeProvider {
|
|
1789
|
-
/**
|
|
1790
|
-
* Create a schema for a paginated response.
|
|
1791
|
-
*/
|
|
1792
|
-
page<T extends TObject | TRecord>(itemSchema: T): TPage<T>;
|
|
1793
|
-
}
|
|
1794
|
-
}
|
|
1795
|
-
//#endregion
|
|
1796
|
-
//#region src/core/helpers/createPagination.d.ts
|
|
1797
|
-
/**
|
|
1798
|
-
* Create a pagination object from an array of entities.
|
|
1799
|
-
*
|
|
1800
|
-
* This is a pure function that works with any data source (databases, APIs, caches, arrays, etc.).
|
|
1801
|
-
* It handles the core pagination logic including:
|
|
1802
|
-
* - Slicing the content to the requested page size
|
|
1803
|
-
* - Calculating pagination metadata (offset, page number, etc.)
|
|
1804
|
-
* - Determining navigation state (isFirst, isLast)
|
|
1805
|
-
* - Including sort metadata when provided
|
|
1806
|
-
*
|
|
1807
|
-
* @param entities - The entities to paginate (should include one extra item to detect if there's a next page)
|
|
1808
|
-
* @param limit - The limit of the pagination (page size)
|
|
1809
|
-
* @param offset - The offset of the pagination (starting position)
|
|
1810
|
-
* @param sort - Optional sort metadata to include in response
|
|
1811
|
-
* @returns A complete Page object with content and metadata
|
|
1812
|
-
*
|
|
1813
|
-
* @example Basic pagination
|
|
1814
|
-
* ```ts
|
|
1815
|
-
* const users = await fetchUsers({ limit: 11, offset: 0 }); // Fetch limit + 1
|
|
1816
|
-
* const page = createPagination(users, 10, 0);
|
|
1817
|
-
* // page.content has max 10 items
|
|
1818
|
-
* // page.page.isLast tells us if there are more pages
|
|
1819
|
-
* ```
|
|
1820
|
-
*
|
|
1821
|
-
* @example With sorting
|
|
1822
|
-
* ```ts
|
|
1823
|
-
* const page = createPagination(
|
|
1824
|
-
* entities,
|
|
1825
|
-
* 10,
|
|
1826
|
-
* 0,
|
|
1827
|
-
* [{ column: "name", direction: "asc" }]
|
|
1828
|
-
* );
|
|
1829
|
-
* ```
|
|
1830
|
-
*
|
|
1831
|
-
* @example In a custom service
|
|
1832
|
-
* ```ts
|
|
1833
|
-
* class MyService {
|
|
1834
|
-
* async listItems(page: number, size: number) {
|
|
1835
|
-
* const items = await this.fetchItems({ limit: size + 1, offset: page * size });
|
|
1836
|
-
* return createPagination(items, size, page * size);
|
|
1837
|
-
* }
|
|
1838
|
-
* }
|
|
1839
|
-
* ```
|
|
1840
|
-
*/
|
|
1841
|
-
declare function createPagination<T>(entities: T[], limit?: number, offset?: number, sort?: Array<{
|
|
1842
|
-
column: string;
|
|
1843
|
-
direction: "asc" | "desc";
|
|
1844
|
-
}>): Page<T>;
|
|
1845
|
-
//#endregion
|
|
1846
|
-
//#region src/core/interfaces/Pagination.d.ts
|
|
1847
|
-
/**
|
|
1848
|
-
* Generic pagination request parameters.
|
|
1849
|
-
*
|
|
1850
|
-
* This interface defines the common structure for pagination queries
|
|
1851
|
-
* across all data sources. Individual packages can extend or adapt this
|
|
1852
|
-
* interface for their specific needs.
|
|
1853
|
-
*
|
|
1854
|
-
* @example Basic usage
|
|
1855
|
-
* ```ts
|
|
1856
|
-
* const query: PageRequest = {
|
|
1857
|
-
* page: 0,
|
|
1858
|
-
* size: 20
|
|
1859
|
-
* };
|
|
1860
|
-
* ```
|
|
1861
|
-
*
|
|
1862
|
-
* @example With all parameters
|
|
1863
|
-
* ```ts
|
|
1864
|
-
* const query: PageRequest = {
|
|
1865
|
-
* page: 2,
|
|
1866
|
-
* size: 50
|
|
1867
|
-
* };
|
|
1868
|
-
* ```
|
|
1869
|
-
*/
|
|
1870
|
-
interface PageRequest {
|
|
1871
|
-
/**
|
|
1872
|
-
* The page number to retrieve (0-indexed).
|
|
1873
|
-
* @default 0
|
|
1874
|
-
*/
|
|
1875
|
-
page?: number;
|
|
1876
|
-
/**
|
|
1877
|
-
* The number of items per page.
|
|
1878
|
-
* @default 10
|
|
1879
|
-
*/
|
|
1880
|
-
size?: number;
|
|
1881
|
-
}
|
|
1882
|
-
/**
|
|
1883
|
-
* Sort direction for ordering results.
|
|
1884
|
-
*/
|
|
1885
|
-
type SortDirection = "asc" | "desc";
|
|
1886
|
-
/**
|
|
1887
|
-
* Sort field specification.
|
|
1888
|
-
*/
|
|
1889
|
-
interface SortField {
|
|
1890
|
-
/**
|
|
1891
|
-
* The field/column name to sort by.
|
|
1892
|
-
*/
|
|
1893
|
-
field: string;
|
|
1894
|
-
/**
|
|
1895
|
-
* The sort direction.
|
|
1896
|
-
* @default "asc"
|
|
1897
|
-
*/
|
|
1898
|
-
direction: SortDirection;
|
|
1899
|
-
}
|
|
1900
|
-
//#endregion
|
|
1901
|
-
//#region src/core/schemas/pageQuerySchema.d.ts
|
|
1902
|
-
declare const pageQuerySchema: TObject<{
|
|
1903
|
-
page: TOptional<TInteger>;
|
|
1904
|
-
size: TOptional<TInteger>;
|
|
1905
|
-
sort: TOptional<TString>;
|
|
1906
|
-
}>;
|
|
1907
|
-
type PageQuery = Static<typeof pageQuerySchema>;
|
|
1908
|
-
//#endregion
|
|
1909
|
-
//#region src/core/index.d.ts
|
|
1910
|
-
/**
|
|
1911
|
-
* Run Alepha application, trigger start lifecycle.
|
|
1912
|
-
*
|
|
1913
|
-
* ```ts
|
|
1914
|
-
* import { Alepha, run } from "alepha";
|
|
1915
|
-
* import { MyService } from "./services/MyService.ts";
|
|
1916
|
-
*
|
|
1917
|
-
* const alepha = new Alepha({ env: { APP_NAME: "MyAlephaApp" } });
|
|
1918
|
-
*
|
|
1919
|
-
* alepha.with(MyService);
|
|
1920
|
-
*
|
|
1921
|
-
* export default run(alepha);
|
|
1922
|
-
* ```
|
|
1923
|
-
*/
|
|
1924
|
-
declare const run: (entry: Alepha | Service | Array<Service>, opts?: RunOptions) => Alepha;
|
|
1925
|
-
//#endregion
|
|
1926
|
-
export { $atom, $context, $env, $hook, $inject, $module, $use, AbstractClass, Alepha, AlephaError, AlsProvider, AppNotStartedError, Async, AsyncFn, AsyncLocalStorageData, Atom, AtomOptions, AtomStatic, AtomWithValue, CircularDependencyError, CodecManager, ContainerLockedError, ContextDescriptor, DecodeOptions, Descriptor, DescriptorArgs, DescriptorConfig, DescriptorFactory, DescriptorFactoryLike, EncodeOptions, EncodeResult, Encoding, Env, EventManager, FileLike, Hook, HookDescriptor, HookOptions, Hooks, InjectDescriptor, InjectOptions, InstantiableClass, JsonSchemaCodec, KIND, LogLevel, LoggerInterface, MaybePromise, Module, ModuleDescriptorOptions, OPTIONS, Page, PageMetadata, PageQuery, PageRequest, RunFunction, SchemaCodec, Service, ServiceEntry, ServiceSubstitution, SortDirection, SortField, State, StateManager, type Static, type StaticDecode, type StaticEncode, StreamLike, type TAny, type TArray, TAtomObject, type TBigInt, type TBoolean, TFile, type TInteger, type TKeysToIndexer, type TNull, type TNumber, type TNumberOptions, type TObject, type TObjectOptions, type TOptional, type TOptionalAdd, TPage, type TPick, type TProperties, type TRecord, type TSchema, TStream, type TString, type TStringOptions, TTextOptions, type TTuple, type TUnion, type TUnsafe, type TVoid, TextLength, TooLateSubstitutionError, TypeBox, TypeBoxError, TypeBoxErrorParams, TypeBoxFormat, TypeBoxValue, TypeGuard, TypeProvider, WithModule, createDescriptor, createPagination, isClass, isDate, isDateTime, isDuration, isEmail, isFileLike, isTime, isTypeFile, isURL, isUUID, pageMetadataSchema, pageQuerySchema, pageSchema, run, t };
|
|
1927
|
-
//# sourceMappingURL=index.d.cts.map
|