alepha 0.7.7 → 0.8.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/LICENSE +21 -21
- package/README.md +7 -34
- package/batch.cjs +8 -0
- package/batch.d.ts +147 -0
- package/batch.js +1 -0
- package/cache/redis.d.ts +13 -18
- package/cache.d.ts +183 -119
- package/command.cjs +8 -0
- package/command.d.ts +152 -0
- package/command.js +1 -0
- package/core.d.ts +846 -838
- package/datetime.d.ts +78 -78
- package/file.cjs +8 -0
- package/file.d.ts +46 -0
- package/file.js +1 -0
- package/lock/redis.d.ts +10 -12
- package/lock.d.ts +73 -80
- package/package.json +86 -34
- package/postgres.d.ts +348 -170
- package/queue/redis.d.ts +13 -13
- package/queue.d.ts +107 -18
- package/react/auth.d.ts +22 -16
- package/react/head.d.ts +10 -4
- package/react.d.ts +206 -49
- package/redis.d.ts +23 -27
- package/retry.d.ts +75 -54
- package/router.cjs +8 -0
- package/router.d.ts +45 -0
- package/router.js +1 -0
- package/scheduler.d.ts +15 -16
- package/security.d.ts +229 -40
- package/server/cache.d.ts +7 -8
- package/server/compress.cjs +8 -0
- package/server/compress.d.ts +26 -0
- package/server/compress.js +1 -0
- package/server/cookies.d.ts +249 -18
- package/server/cors.d.ts +7 -3
- package/server/health.d.ts +21 -24
- package/server/helmet.cjs +8 -0
- package/server/helmet.d.ts +70 -0
- package/server/helmet.js +1 -0
- package/server/links.d.ts +87 -93
- package/server/metrics.cjs +8 -0
- package/server/metrics.d.ts +35 -0
- package/server/metrics.js +1 -0
- package/server/multipart.cjs +8 -0
- package/server/multipart.d.ts +46 -0
- package/server/multipart.js +1 -0
- package/server/proxy.d.ts +11 -11
- package/server/static.d.ts +70 -55
- package/server/swagger.d.ts +55 -54
- package/server.d.ts +273 -123
- package/topic/redis.d.ts +22 -23
- package/topic.d.ts +26 -19
- package/vite.d.ts +59 -36
package/core.d.ts
CHANGED
|
@@ -2,102 +2,152 @@ import { AsyncLocalStorage } from "node:async_hooks";
|
|
|
2
2
|
import { TypeCheck } from "@sinclair/typebox/compiler";
|
|
3
3
|
import * as TypeBoxValue from "@sinclair/typebox/value";
|
|
4
4
|
import * as TypeBox from "@sinclair/typebox";
|
|
5
|
-
import { ArrayOptions, IntegerOptions, NumberOptions, ObjectOptions, SchemaOptions, Static, Static as Static$1, StaticDecode, StaticEncode, StringOptions, TArray, TBoolean, TInteger, TIntersect, TNull, TNumber, TObject, TObject as TObject$1, TOptionalWithFlag, TProperties, TSchema, TSchema as TSchema$1, TString, TUnsafe, TypeGuard, Union, UnsafeOptions } from "@sinclair/typebox";
|
|
5
|
+
import { ArrayOptions, FormatRegistry, IntegerOptions, NumberOptions, ObjectOptions, SchemaOptions, Static, Static as Static$1, StaticDecode, StaticEncode, StringOptions, TAny, TAny as TAny$1, TArray, TArray as TArray$1, TBoolean, TBoolean as TBoolean$1, TComposite, TInteger, TIntersect, TMappedResult, TNull, TNumber, TNumber as TNumber$1, TObject, TObject as TObject$1, TOmit, TOptional, TOptionalWithFlag, TPartial, TPartialFromMappedResult, TPick, TProperties, TProperties as TProperties$1, TRecord, TRecord as TRecord$1, TRecordOrObject, TSchema, TSchema as TSchema$1, TString, TString as TString$1, TUndefined, TUnion, TUnsafe, TVoid, Type, TypeGuard, Union, UnsafeOptions } from "@sinclair/typebox";
|
|
6
6
|
import { ValueError } from "@sinclair/typebox/errors";
|
|
7
|
-
import { ReadableStream as ReadableStream$1 } from "node:stream/web";
|
|
8
7
|
import { Readable } from "node:stream";
|
|
8
|
+
import { ReadableStream as ReadableStream$1 } from "node:stream/web";
|
|
9
9
|
|
|
10
10
|
//#region src/constants/KIND.d.ts
|
|
11
11
|
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
* Used for identifying descriptors.
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
16
|
declare const KIND: unique symbol;
|
|
17
17
|
//#endregion
|
|
18
18
|
//#region src/constants/OPTIONS.d.ts
|
|
19
19
|
/**
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
* Used for descriptors options.
|
|
21
|
+
*
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
24
|
declare const OPTIONS: unique symbol;
|
|
25
25
|
//#endregion
|
|
26
26
|
//#region src/interfaces/Async.d.ts
|
|
27
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
27
28
|
/**
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
* Represents a value that can be either a value or a promise.
|
|
30
|
+
*/
|
|
30
31
|
type Async<T> = T | Promise<T>;
|
|
32
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
31
33
|
/**
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
* Represents a function that returns a promise.
|
|
35
|
+
*/
|
|
34
36
|
type PromiseFn = (...args: any[]) => Promise<any>;
|
|
37
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
35
38
|
/**
|
|
36
|
-
|
|
37
|
-
|
|
39
|
+
* Represents a function that returns an async value.
|
|
40
|
+
*/
|
|
38
41
|
type AsyncFn = (...args: any[]) => Async<any>;
|
|
42
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
39
43
|
type MaybePromise<T> = T extends Promise<any> ? T : Promise<T>;
|
|
40
44
|
//#endregion
|
|
41
45
|
//#region src/interfaces/Service.d.ts
|
|
46
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
42
47
|
/**
|
|
43
|
-
|
|
44
|
-
|
|
48
|
+
* In Alepha, a service is a class that can be instantiated. Nothing more, nothing less.
|
|
49
|
+
*/
|
|
45
50
|
type Service<T extends object = any> = InstantiableService<T> | AbstractService<T>;
|
|
46
51
|
type InstantiableService<T extends object = any> = new (...args: any[]) => T;
|
|
47
52
|
type AbstractService<T extends object = any> = abstract new (...args: any[]) => T;
|
|
53
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
48
54
|
/**
|
|
49
|
-
|
|
50
|
-
|
|
55
|
+
* Service substitution allows you to register a class as a different class.
|
|
56
|
+
*/
|
|
51
57
|
interface ServiceSubstitution<T extends object = any> {
|
|
52
58
|
/**
|
|
53
|
-
|
|
54
|
-
|
|
59
|
+
* Every time someone asks for this service, it will be provided with the 'use' service.
|
|
60
|
+
*/
|
|
55
61
|
provide: Service<T>;
|
|
56
62
|
/**
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
63
|
+
* Service to use instead of the 'provide' service.
|
|
64
|
+
*
|
|
65
|
+
* Note: Syntax is based on Angular's DI system.
|
|
66
|
+
*/
|
|
61
67
|
use: Service<T>;
|
|
62
68
|
/**
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
69
|
+
* If true and the service already exists, just ignore the substitution and do not throw an error.
|
|
70
|
+
* Mostly used for plugins to enforce a substitution without throwing an error.
|
|
71
|
+
*/
|
|
66
72
|
optional?: boolean;
|
|
67
73
|
}
|
|
74
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
68
75
|
/**
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
76
|
+
* Every time you register a service, you can use this type to define it.
|
|
77
|
+
*
|
|
78
|
+
* alepha.with( ServiceEntry )
|
|
79
|
+
* or
|
|
80
|
+
* alepha.with( provide: ServiceEntry, use: MyOwnServiceEntry )
|
|
81
|
+
*
|
|
82
|
+
* And yes, you declare the *type* of the service, not the *instance*.
|
|
83
|
+
*/
|
|
77
84
|
type ServiceEntry<T extends object = any> = Service<T> | ServiceSubstitution<T>;
|
|
78
85
|
//#endregion
|
|
79
86
|
//#region src/descriptors/$hook.d.ts
|
|
80
87
|
declare const KEY = "HOOK";
|
|
88
|
+
/**
|
|
89
|
+
* Registers a new hook.
|
|
90
|
+
*
|
|
91
|
+
* ```ts
|
|
92
|
+
* import { $hook } from "alepha";
|
|
93
|
+
*
|
|
94
|
+
* class MyProvider {
|
|
95
|
+
* onStart = $hook({
|
|
96
|
+
* name: "start", // or "configure", "ready", "stop", ...
|
|
97
|
+
* handler: async (app) => {
|
|
98
|
+
* // await db.connect(); ...
|
|
99
|
+
* }
|
|
100
|
+
* });
|
|
101
|
+
* }
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* Hooks are used to run async functions from all registered providers/services.
|
|
105
|
+
*
|
|
106
|
+
* You can't register a hook after the App has started.
|
|
107
|
+
*
|
|
108
|
+
* It's used under the hood by the `configure`, `start`, and `stop` methods.
|
|
109
|
+
* Some modules also use hooks to run their own logic. (e.g. `@alepha/server`).
|
|
110
|
+
*
|
|
111
|
+
* You can create your own hooks by using module augmentation:
|
|
112
|
+
*
|
|
113
|
+
* ```ts
|
|
114
|
+
* declare module "alepha" {
|
|
115
|
+
*
|
|
116
|
+
* interface Hooks {
|
|
117
|
+
* "my:custom:hook": {
|
|
118
|
+
* arg1: string;
|
|
119
|
+
* }
|
|
120
|
+
* }
|
|
121
|
+
* }
|
|
122
|
+
*
|
|
123
|
+
* await alepha.emit("my:custom:hook", { arg1: "value" });
|
|
124
|
+
* ```
|
|
125
|
+
*
|
|
126
|
+
*/
|
|
127
|
+
declare const $hook: {
|
|
128
|
+
<T extends keyof Hooks>(options: HookOptions<T>): HookDescriptor<T>;
|
|
129
|
+
[KIND]: string;
|
|
130
|
+
};
|
|
81
131
|
interface HookOptions<T extends keyof Hooks> {
|
|
82
132
|
/**
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
133
|
+
* The name of the hook. "configure", "start", "ready", "stop", ...
|
|
134
|
+
*/
|
|
135
|
+
on: T;
|
|
86
136
|
/**
|
|
87
|
-
|
|
88
|
-
|
|
137
|
+
* The handler to run when the hook is triggered.
|
|
138
|
+
*/
|
|
89
139
|
handler: (app: Hooks[T]) => Async<any>;
|
|
90
140
|
/**
|
|
91
|
-
|
|
92
|
-
|
|
141
|
+
* Force the hook to run first or last on the list of hooks.
|
|
142
|
+
*/
|
|
93
143
|
priority?: "first" | "last";
|
|
94
144
|
/**
|
|
95
|
-
|
|
96
|
-
|
|
145
|
+
* Empty placeholder, not working yet. :-)
|
|
146
|
+
*/
|
|
97
147
|
before?: object | Array<object>;
|
|
98
148
|
/**
|
|
99
|
-
|
|
100
|
-
|
|
149
|
+
* Empty placeholder, not working yet. :-)
|
|
150
|
+
*/
|
|
101
151
|
after?: object | Array<object>;
|
|
102
152
|
}
|
|
103
153
|
interface Hook<T extends keyof Hooks = any> {
|
|
@@ -110,49 +160,6 @@ interface HookDescriptor<T extends keyof Hooks> {
|
|
|
110
160
|
[OPTIONS]: HookOptions<T>;
|
|
111
161
|
(app: Hooks[T]): Async<any>;
|
|
112
162
|
}
|
|
113
|
-
/**
|
|
114
|
-
* Registers a new hook.
|
|
115
|
-
*
|
|
116
|
-
* ```ts
|
|
117
|
-
* import { $hook } from "alepha";
|
|
118
|
-
*
|
|
119
|
-
* class MyProvider {
|
|
120
|
-
* onStart = $hook({
|
|
121
|
-
* name: "start", // or "configure", "ready", "stop", ...
|
|
122
|
-
* handler: async (app) => {
|
|
123
|
-
* // await db.connect(); ...
|
|
124
|
-
* }
|
|
125
|
-
* });
|
|
126
|
-
* }
|
|
127
|
-
* ```
|
|
128
|
-
*
|
|
129
|
-
* Hooks are used to run async functions from all registered providers/services.
|
|
130
|
-
*
|
|
131
|
-
* You can't register a hook after the App has started.
|
|
132
|
-
*
|
|
133
|
-
* It's used under the hood by the `configure`, `start`, and `stop` methods.
|
|
134
|
-
* Some modules also use hooks to run their own logic. (e.g. `@alepha/server`).
|
|
135
|
-
*
|
|
136
|
-
* You can create your own hooks by using module augmentation:
|
|
137
|
-
*
|
|
138
|
-
* ```ts
|
|
139
|
-
* declare module "alepha" {
|
|
140
|
-
*
|
|
141
|
-
* interface Hooks {
|
|
142
|
-
* "my:custom:hook": {
|
|
143
|
-
* arg1: string;
|
|
144
|
-
* }
|
|
145
|
-
* }
|
|
146
|
-
* }
|
|
147
|
-
*
|
|
148
|
-
* await alepha.emit("my:custom:hook", { arg1: "value" });
|
|
149
|
-
* ```
|
|
150
|
-
*
|
|
151
|
-
*/
|
|
152
|
-
declare const $hook: {
|
|
153
|
-
<T extends keyof Hooks>(options: HookOptions<T>): HookDescriptor<T>;
|
|
154
|
-
[KIND]: string;
|
|
155
|
-
};
|
|
156
163
|
//#endregion
|
|
157
164
|
//#region src/helpers/Module.d.ts
|
|
158
165
|
interface Module {
|
|
@@ -162,17 +169,41 @@ interface Module {
|
|
|
162
169
|
interface ModuleDefinition extends Module {
|
|
163
170
|
services: Array<Service>;
|
|
164
171
|
}
|
|
172
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
165
173
|
declare const isModule: (value: unknown) => value is Module;
|
|
166
174
|
declare const toModuleName: (name: string) => string;
|
|
167
175
|
//#endregion
|
|
168
176
|
//#region src/descriptors/$cursor.d.ts
|
|
169
177
|
/**
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
178
|
+
* Get Alepha instance and Class definition from the current context.
|
|
179
|
+
* This should be used inside a descriptor only.
|
|
180
|
+
*
|
|
181
|
+
* ```ts
|
|
182
|
+
* import { $cursor } from "alepha";
|
|
183
|
+
*
|
|
184
|
+
* const $ = () => {
|
|
185
|
+
*
|
|
186
|
+
* const { context, definition } = $cursor();
|
|
187
|
+
*
|
|
188
|
+
* // context - alepha instance
|
|
189
|
+
* // definition - class which is creating this descriptor
|
|
190
|
+
*
|
|
191
|
+
* return {};
|
|
192
|
+
* }
|
|
193
|
+
*
|
|
194
|
+
* ```
|
|
195
|
+
*
|
|
196
|
+
* @internal
|
|
197
|
+
*/
|
|
198
|
+
declare const $cursor: () => CursorDescriptor;
|
|
199
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
200
|
+
/**
|
|
201
|
+
* /!\ Global variable /!\
|
|
202
|
+
*
|
|
203
|
+
* Store the current context and definition during injection phase.
|
|
204
|
+
*
|
|
205
|
+
* @internal
|
|
206
|
+
*/
|
|
176
207
|
declare const __alephaRef: {
|
|
177
208
|
context?: Alepha;
|
|
178
209
|
definition?: Service;
|
|
@@ -182,42 +213,22 @@ declare const __alephaRef: {
|
|
|
182
213
|
parent: Service;
|
|
183
214
|
};
|
|
184
215
|
};
|
|
216
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
185
217
|
/**
|
|
186
|
-
|
|
187
|
-
|
|
218
|
+
* Cursor descriptor.
|
|
219
|
+
*/
|
|
188
220
|
interface CursorDescriptor {
|
|
189
221
|
context: Alepha;
|
|
190
222
|
definition?: Service;
|
|
191
223
|
module?: ModuleDefinition;
|
|
192
224
|
}
|
|
193
|
-
/**
|
|
194
|
-
* Get Alepha instance and Class definition from the current context.
|
|
195
|
-
* This should be used inside a descriptor only.
|
|
196
|
-
*
|
|
197
|
-
* ```ts
|
|
198
|
-
* import { $cursor } from "@alepha/core";
|
|
199
|
-
*
|
|
200
|
-
* const $ = () => {
|
|
201
|
-
*
|
|
202
|
-
* const { context, definition } = $cursor();
|
|
203
|
-
*
|
|
204
|
-
* // context - alepha instance
|
|
205
|
-
* // definition - class which is creating this descriptor
|
|
206
|
-
*
|
|
207
|
-
* return {};
|
|
208
|
-
* }
|
|
209
|
-
*
|
|
210
|
-
* ```
|
|
211
|
-
*
|
|
212
|
-
* @internal
|
|
213
|
-
*/
|
|
214
|
-
declare const $cursor: () => CursorDescriptor;
|
|
215
225
|
//#endregion
|
|
216
226
|
//#region src/helpers/EventEmitterLike.d.ts
|
|
227
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
217
228
|
/**
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
229
|
+
* Low-cost event emitter like for internal use.
|
|
230
|
+
* Used only for descriptor implicit registration.
|
|
231
|
+
*/
|
|
221
232
|
declare class EventEmitterLike<TEvents extends {
|
|
222
233
|
[key: string]: any;
|
|
223
234
|
}> {
|
|
@@ -227,69 +238,76 @@ declare class EventEmitterLike<TEvents extends {
|
|
|
227
238
|
}
|
|
228
239
|
//#endregion
|
|
229
240
|
//#region src/helpers/descriptor.d.ts
|
|
241
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
230
242
|
/**
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
243
|
+
* Descriptor events.
|
|
244
|
+
*
|
|
245
|
+
* - `create` - Emitted when a descriptor is created.
|
|
246
|
+
*/
|
|
235
247
|
declare const descriptorEvents: EventEmitterLike<{
|
|
236
248
|
create: CursorDescriptor & {
|
|
237
249
|
[KIND]: string;
|
|
238
250
|
};
|
|
239
251
|
}>;
|
|
252
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
240
253
|
/**
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
254
|
+
* Register a descriptor.
|
|
255
|
+
*
|
|
256
|
+
* This is used to run the event "create" and allow auto-registration of descriptors.
|
|
257
|
+
*
|
|
258
|
+
* @internal
|
|
259
|
+
* @param kind
|
|
260
|
+
*/
|
|
248
261
|
declare const __descriptor: (kind: string) => void;
|
|
262
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
249
263
|
/**
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
264
|
+
* Auto-inject a class/module when a descriptor is created.
|
|
265
|
+
*
|
|
266
|
+
* Like, you auto-inject the ServerModule when a `$route` descriptor is used.
|
|
267
|
+
*
|
|
268
|
+
* @param descriptor
|
|
269
|
+
* @param to
|
|
270
|
+
*/
|
|
257
271
|
declare const __bind: (descriptor: {
|
|
258
272
|
[KIND]: string;
|
|
259
273
|
}, ...to: Service[]) => void;
|
|
274
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
260
275
|
/**
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
276
|
+
* Check if the value is a descriptor value.
|
|
277
|
+
*
|
|
278
|
+
* @param value - Value to check.
|
|
279
|
+
* @returns Is the value a descriptor value.
|
|
280
|
+
*/
|
|
266
281
|
declare const isDescriptorValue: (value: any) => value is DescriptorIdentifier;
|
|
282
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
267
283
|
/**
|
|
268
|
-
|
|
269
|
-
|
|
284
|
+
* The "$descriptor" function.
|
|
285
|
+
*/
|
|
270
286
|
interface Descriptor<T extends object = any> {
|
|
271
287
|
[KIND]: string;
|
|
272
288
|
(options: T): DescriptorIdentifier<T>;
|
|
273
289
|
}
|
|
290
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
274
291
|
/**
|
|
275
|
-
|
|
276
|
-
|
|
292
|
+
* Class member descriptor.
|
|
293
|
+
*/
|
|
277
294
|
interface DescriptorIdentifier<T = object> {
|
|
278
295
|
[KIND]: string;
|
|
279
296
|
[OPTIONS]: T;
|
|
280
297
|
}
|
|
298
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
281
299
|
/**
|
|
282
|
-
|
|
283
|
-
|
|
300
|
+
* Descriptor identifier + his instance + his key.
|
|
301
|
+
*/
|
|
284
302
|
interface DescriptorItem<T extends Descriptor> {
|
|
285
303
|
value: ReturnType<T>;
|
|
286
304
|
key: string;
|
|
287
305
|
instance: Record<string, any>;
|
|
288
306
|
}
|
|
289
307
|
//#endregion
|
|
290
|
-
//#region src/providers/
|
|
308
|
+
//#region src/providers/AlsProvider.d.ts
|
|
291
309
|
type AsyncLocalStorageData = any;
|
|
292
|
-
declare class
|
|
310
|
+
declare class AlsProvider {
|
|
293
311
|
static create: () => AsyncLocalStorage<AsyncLocalStorageData> | undefined;
|
|
294
312
|
protected als?: AsyncLocalStorage<AsyncLocalStorageData>;
|
|
295
313
|
constructor();
|
|
@@ -300,61 +318,68 @@ declare class AsyncLocalStorageProvider {
|
|
|
300
318
|
}
|
|
301
319
|
//#endregion
|
|
302
320
|
//#region src/services/Logger.d.ts
|
|
321
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
303
322
|
type LogLevel = "error" | "warn" | "info" | "debug" | "trace" | "silent";
|
|
323
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
304
324
|
interface LoggerEnv {
|
|
305
325
|
/**
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
326
|
+
* Default log level for the application.
|
|
327
|
+
* Default by environment:
|
|
328
|
+
* - dev = "debug"
|
|
329
|
+
* - test = "error"
|
|
330
|
+
* - prod = "info"
|
|
331
|
+
*
|
|
332
|
+
* "trace" | "debug" | "info" | "warn" | "error" | "silent"
|
|
333
|
+
*/
|
|
334
|
+
LOG_LEVEL?: string;
|
|
335
|
+
/**
|
|
336
|
+
* Disable colors in the console output.
|
|
337
|
+
*/
|
|
316
338
|
NO_COLOR?: string;
|
|
317
339
|
/**
|
|
318
|
-
|
|
319
|
-
|
|
340
|
+
* Force color output for the application.
|
|
341
|
+
*/
|
|
320
342
|
FORCE_COLOR?: string;
|
|
321
343
|
/**
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
LOG_FORMAT?: "json" | "text";
|
|
344
|
+
* Log format.
|
|
345
|
+
*
|
|
346
|
+
* @default "text"
|
|
347
|
+
*/
|
|
348
|
+
LOG_FORMAT?: "json" | "text" | "cli" | "raw";
|
|
327
349
|
}
|
|
350
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
328
351
|
interface LoggerOptions {
|
|
329
352
|
/**
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
level?:
|
|
353
|
+
* The logging level. Can be one of "error", "warn", "info", "debug", or "trace".
|
|
354
|
+
*/
|
|
355
|
+
level?: string;
|
|
356
|
+
app?: string;
|
|
333
357
|
/**
|
|
334
|
-
|
|
335
|
-
|
|
358
|
+
* The name of the logger. Like a module name or a service name.
|
|
359
|
+
*/
|
|
336
360
|
name?: string;
|
|
337
361
|
/**
|
|
338
|
-
|
|
339
|
-
|
|
362
|
+
* An optional context to include in the log output. Like a request ID or a correlation ID.
|
|
363
|
+
*/
|
|
340
364
|
context?: string;
|
|
341
365
|
/**
|
|
342
|
-
|
|
343
|
-
|
|
366
|
+
* An optional tag to include in the log output. Like a class name or a module name.
|
|
367
|
+
*/
|
|
344
368
|
caller?: string;
|
|
345
369
|
/**
|
|
346
|
-
|
|
347
|
-
|
|
370
|
+
* Whether to use colors in the log output. Defaults to true.
|
|
371
|
+
*/
|
|
348
372
|
color?: boolean;
|
|
349
373
|
/**
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
374
|
+
* Log output format. Can be "json", "text", or "cli".
|
|
375
|
+
*/
|
|
376
|
+
format?: string;
|
|
353
377
|
/**
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
als?:
|
|
378
|
+
* An optional async local storage provider to use for storing context information.
|
|
379
|
+
*/
|
|
380
|
+
als?: AlsProvider;
|
|
357
381
|
}
|
|
382
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
358
383
|
declare const COLORS: {
|
|
359
384
|
reset: string;
|
|
360
385
|
grey: string;
|
|
@@ -366,17 +391,22 @@ declare const COLORS: {
|
|
|
366
391
|
cyan: string;
|
|
367
392
|
darkGrey: string;
|
|
368
393
|
};
|
|
369
|
-
declare const LEVEL_COLORS: Record<
|
|
394
|
+
declare const LEVEL_COLORS: Record<string, string>;
|
|
395
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
370
396
|
declare class Logger {
|
|
371
|
-
protected levelOrder: Record<
|
|
372
|
-
readonly level:
|
|
397
|
+
protected levelOrder: Record<string, number>;
|
|
398
|
+
readonly level: string;
|
|
399
|
+
readonly rawLevel: string;
|
|
373
400
|
readonly name: string;
|
|
374
401
|
protected caller: string;
|
|
375
402
|
protected context: string;
|
|
403
|
+
protected app: string;
|
|
376
404
|
protected color: boolean;
|
|
377
|
-
protected
|
|
378
|
-
protected als?:
|
|
405
|
+
protected format: string;
|
|
406
|
+
protected als?: AlsProvider;
|
|
379
407
|
constructor(options?: LoggerOptions);
|
|
408
|
+
parseLevel(level: string, app: string): LogLevel;
|
|
409
|
+
asLogLevel(something: string): LogLevel;
|
|
380
410
|
child(options: LoggerOptions): Logger;
|
|
381
411
|
error(message: unknown, data?: object | Error | string | unknown): void;
|
|
382
412
|
warn(message: unknown, data?: object | Error | string): void;
|
|
@@ -384,49 +414,32 @@ declare class Logger {
|
|
|
384
414
|
debug(message: unknown, data?: object | Error | string): void;
|
|
385
415
|
trace(message: unknown, data?: object | Error | string): void;
|
|
386
416
|
/**
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
* @param level
|
|
390
|
-
* @param message
|
|
391
|
-
* @param data
|
|
392
|
-
* @protected
|
|
393
|
-
*/
|
|
417
|
+
* Log a message to the console.
|
|
418
|
+
*/
|
|
394
419
|
protected log(level: LogLevel, message: unknown, data?: object | Error | string): void;
|
|
395
420
|
/**
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
* @param formatted
|
|
399
|
-
* @protected
|
|
400
|
-
*/
|
|
421
|
+
* Print a log message to the console.
|
|
422
|
+
*/
|
|
401
423
|
protected print(formatted: string): void;
|
|
402
424
|
/**
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
* @param level
|
|
406
|
-
* @param message
|
|
407
|
-
* @param data
|
|
408
|
-
* @protected
|
|
409
|
-
*/
|
|
425
|
+
* Format a log message to JSON.
|
|
426
|
+
*/
|
|
410
427
|
protected formatJson(level: LogLevel, message: unknown, data?: object | Error | string): string;
|
|
411
428
|
protected formatJsonError(error: Error): object;
|
|
412
429
|
/**
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
* @param level
|
|
416
|
-
* @param message
|
|
417
|
-
* @param data
|
|
418
|
-
* @protected
|
|
419
|
-
*/
|
|
430
|
+
* Format a log message to a string.
|
|
431
|
+
*/
|
|
420
432
|
protected formatLog(level: LogLevel, message: string, data?: object | Error): string;
|
|
421
433
|
protected colorize(color: string, text: string, reset?: string): string;
|
|
422
434
|
/**
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
435
|
+
* Format an error to a string.
|
|
436
|
+
*
|
|
437
|
+
* @param error
|
|
438
|
+
* @protected
|
|
439
|
+
*/
|
|
428
440
|
protected formatError(error: Error): string;
|
|
429
441
|
}
|
|
442
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
430
443
|
declare class MockLogger extends Logger {
|
|
431
444
|
store: MockLoggerStore;
|
|
432
445
|
constructor(options?: LoggerOptions & {
|
|
@@ -434,586 +447,606 @@ declare class MockLogger extends Logger {
|
|
|
434
447
|
});
|
|
435
448
|
print(msg: string): void;
|
|
436
449
|
child(options: LoggerOptions): MockLogger;
|
|
450
|
+
reset(): void;
|
|
437
451
|
}
|
|
452
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
438
453
|
interface MockLoggerStore {
|
|
439
454
|
stack: Array<{
|
|
440
455
|
date: string;
|
|
441
456
|
level: string;
|
|
442
457
|
message: string;
|
|
458
|
+
context?: string;
|
|
459
|
+
app?: string;
|
|
443
460
|
} & Record<string, any>>;
|
|
444
461
|
}
|
|
445
462
|
//#endregion
|
|
446
463
|
//#region src/Alepha.d.ts
|
|
447
|
-
interface Env extends LoggerEnv {
|
|
448
|
-
[key: string]: string | boolean | number | undefined;
|
|
449
|
-
/**
|
|
450
|
-
* Optional environment variable that indicates the current environment.
|
|
451
|
-
*/
|
|
452
|
-
NODE_ENV?: "dev" | "test" | "production";
|
|
453
|
-
/**
|
|
454
|
-
* Optional name of the application.
|
|
455
|
-
*/
|
|
456
|
-
APP_NAME?: string;
|
|
457
|
-
/**
|
|
458
|
-
* If true, the container will not automatically register the default providers based on the descriptors.
|
|
459
|
-
*
|
|
460
|
-
* It means that you have to alepha.with(ServiceModule) manually. No magic.
|
|
461
|
-
*
|
|
462
|
-
* @default false
|
|
463
|
-
*/
|
|
464
|
-
EXPLICIT_PROVIDERS?: boolean;
|
|
465
|
-
}
|
|
466
|
-
interface State {
|
|
467
|
-
log: Logger;
|
|
468
|
-
env?: Readonly<Env>;
|
|
469
|
-
beforeAll?: (run: any) => any;
|
|
470
|
-
afterAll?: (run: any) => any;
|
|
471
|
-
afterEach?: (run: any) => any;
|
|
472
|
-
onTestFinished?: (run: any) => any;
|
|
473
|
-
}
|
|
474
|
-
interface Hooks {
|
|
475
|
-
echo: any;
|
|
476
|
-
/**
|
|
477
|
-
* Triggered during the configuration phase. Before the start phase.
|
|
478
|
-
*/
|
|
479
|
-
configure: Alepha;
|
|
480
|
-
/**
|
|
481
|
-
* Triggered during the start phase. When `Alepha#start()` is called.
|
|
482
|
-
*/
|
|
483
|
-
start: Alepha;
|
|
484
|
-
/**
|
|
485
|
-
* Triggered during the ready phase. After the start phase.
|
|
486
|
-
*/
|
|
487
|
-
ready: Alepha;
|
|
488
|
-
/**
|
|
489
|
-
* Triggered during the stop phase.
|
|
490
|
-
*
|
|
491
|
-
* - Stop should be called after a SIGINT or SIGTERM signal in order to gracefully shutdown the application. (@see `run()` method)
|
|
492
|
-
*
|
|
493
|
-
*/
|
|
494
|
-
stop: Alepha;
|
|
495
|
-
/**
|
|
496
|
-
* Triggered when a state value is mutated.
|
|
497
|
-
*/
|
|
498
|
-
"state:mutate": {
|
|
499
|
-
/**
|
|
500
|
-
* The key of the state that was mutated.
|
|
501
|
-
*/
|
|
502
|
-
key: keyof State;
|
|
503
|
-
/**
|
|
504
|
-
* The new value of the state.
|
|
505
|
-
*/
|
|
506
|
-
value: any;
|
|
507
|
-
/**
|
|
508
|
-
* The previous value of the state.
|
|
509
|
-
*/
|
|
510
|
-
prevValue: any;
|
|
511
|
-
};
|
|
512
|
-
}
|
|
513
464
|
/**
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
465
|
+
* Core container of the Alepha framework.
|
|
466
|
+
*
|
|
467
|
+
* It is responsible for managing the lifecycle of services,
|
|
468
|
+
* handling dependency injection,
|
|
469
|
+
* and providing a unified interface for the application.
|
|
470
|
+
*
|
|
471
|
+
* @example
|
|
472
|
+
* ```ts
|
|
473
|
+
* import { Alepha, run } from "alepha";
|
|
474
|
+
*
|
|
475
|
+
* class MyService {
|
|
476
|
+
* // business logic here
|
|
477
|
+
* }
|
|
478
|
+
*
|
|
479
|
+
* const alepha = Alepha.create({
|
|
480
|
+
* // state, env, and other properties
|
|
481
|
+
* })
|
|
482
|
+
*
|
|
483
|
+
* alepha.with(MyService);
|
|
484
|
+
*
|
|
485
|
+
* run(alepha); // trigger .start (and .stop) automatically
|
|
486
|
+
* ```
|
|
487
|
+
*
|
|
488
|
+
* > Some alepha methods are not intended to be used directly, use descriptors instead.
|
|
489
|
+
* >
|
|
490
|
+
* > - $hook -> alepha.on()
|
|
491
|
+
* > - $inject -> alepha.get(), alepha.parseEnv()
|
|
492
|
+
*/
|
|
542
493
|
declare class Alepha {
|
|
543
494
|
/**
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
495
|
+
* Creates a new instance of the Alepha container with some helpers:
|
|
496
|
+
*
|
|
497
|
+
* - merges `process.env` with the provided state.env when available.
|
|
498
|
+
* - populates the test hooks for Vitest or Jest environments when available.
|
|
499
|
+
*
|
|
500
|
+
* If you are not interested about these helpers, you can use the constructor directly.
|
|
501
|
+
*/
|
|
551
502
|
static create(state?: Partial<State>): Alepha;
|
|
552
503
|
/**
|
|
553
|
-
|
|
554
|
-
|
|
504
|
+
* List of all services + how they are provided.
|
|
505
|
+
*/
|
|
555
506
|
protected registry: Map<Service, ServiceDefinition>;
|
|
556
507
|
/**
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
508
|
+
* Flag indicating whether the App won't accept any further changes.
|
|
509
|
+
* Pass to true when #start() is called.
|
|
510
|
+
*/
|
|
560
511
|
protected locked: boolean;
|
|
561
512
|
/**
|
|
562
|
-
|
|
563
|
-
|
|
513
|
+
* True if the App has been configured.
|
|
514
|
+
*/
|
|
564
515
|
protected configured: boolean;
|
|
565
516
|
/**
|
|
566
|
-
|
|
567
|
-
|
|
517
|
+
* True if the App has started.
|
|
518
|
+
*/
|
|
568
519
|
protected started: boolean;
|
|
569
520
|
/**
|
|
570
|
-
|
|
571
|
-
|
|
521
|
+
* True if the App is ready.
|
|
522
|
+
*/
|
|
572
523
|
protected ready: boolean;
|
|
573
524
|
/**
|
|
574
|
-
|
|
575
|
-
|
|
525
|
+
* A promise that resolves when the App has started.
|
|
526
|
+
*/
|
|
576
527
|
protected starting?: PromiseWithResolvers<this>;
|
|
577
528
|
/**
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
529
|
+
* The current state of the App.
|
|
530
|
+
*
|
|
531
|
+
* It contains the environment variables, logger, and other state-related properties.
|
|
532
|
+
*
|
|
533
|
+
* You can declare your own state properties by extending the `State` interface.
|
|
534
|
+
*
|
|
535
|
+
* ```ts
|
|
536
|
+
* declare module "alepha" {
|
|
537
|
+
* interface State {
|
|
538
|
+
* myCustomValue: string;
|
|
539
|
+
* }
|
|
540
|
+
* }
|
|
541
|
+
* ```
|
|
542
|
+
*
|
|
543
|
+
* Same story for the `Env` interface.
|
|
544
|
+
* ```ts
|
|
545
|
+
* declare module "alepha" {
|
|
546
|
+
* interface Env {
|
|
547
|
+
* readonly myCustomValue: string;
|
|
548
|
+
* }
|
|
549
|
+
* }
|
|
550
|
+
* ```
|
|
551
|
+
*
|
|
552
|
+
* State values can be function or primitive values.
|
|
553
|
+
* However, all .env variables must serializable to JSON.
|
|
554
|
+
*/
|
|
604
555
|
protected store: State;
|
|
605
556
|
/**
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
557
|
+
* During the instantiation process, we keep a list of pending instantiations.
|
|
558
|
+
* > It allows us to detect circular dependencies.
|
|
559
|
+
*/
|
|
609
560
|
protected pendingInstantiations: Service[];
|
|
610
561
|
/**
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
562
|
+
* Cache for environment variables.
|
|
563
|
+
* > It allows us to avoid parsing the same schema multiple times.
|
|
564
|
+
*/
|
|
614
565
|
protected cacheEnv: Map<TSchema$1, any>;
|
|
615
566
|
/**
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
567
|
+
* Cache for TypeBox type checks.
|
|
568
|
+
* > It allows us to avoid compiling the same schema multiple times.
|
|
569
|
+
*/
|
|
619
570
|
protected cacheTypeCheck: Map<TSchema$1, TypeCheck<TSchema$1>>;
|
|
620
571
|
/**
|
|
621
|
-
|
|
622
|
-
|
|
572
|
+
* List of events that can be triggered. Powered by $hook().
|
|
573
|
+
*/
|
|
623
574
|
protected events: Record<string, Array<Hook>>;
|
|
624
575
|
/**
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
576
|
+
* List of modules that are registered in the container.
|
|
577
|
+
*
|
|
578
|
+
* Modules are used to group services and provide a way to register them in the container.
|
|
579
|
+
*/
|
|
629
580
|
protected modules: Array<ModuleDefinition>;
|
|
630
581
|
/**
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
readonly context:
|
|
582
|
+
* Node.js feature that allows to store context across asynchronous calls.
|
|
583
|
+
*
|
|
584
|
+
* This is used for logging, tracing, and other context-related features.
|
|
585
|
+
*
|
|
586
|
+
* Mocked for browser environments.
|
|
587
|
+
*/
|
|
588
|
+
readonly context: AlsProvider;
|
|
638
589
|
/**
|
|
639
|
-
|
|
640
|
-
|
|
590
|
+
* Get logger instance.
|
|
591
|
+
*/
|
|
641
592
|
get log(): Logger;
|
|
642
593
|
/**
|
|
643
|
-
|
|
644
|
-
|
|
594
|
+
* The environment variables for the App.
|
|
595
|
+
*/
|
|
645
596
|
get env(): Readonly<Env>;
|
|
646
597
|
constructor(state?: Partial<State>);
|
|
647
598
|
/**
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
*/
|
|
651
|
-
handle?: (req: any, res: any) => Promise<any>;
|
|
652
|
-
/**
|
|
653
|
-
* State accessor and mutator.
|
|
654
|
-
*/
|
|
599
|
+
* State accessor and mutator.
|
|
600
|
+
*/
|
|
655
601
|
state<Key extends keyof State>(key: Key, value?: State[Key]): State[Key];
|
|
602
|
+
// -------------------------------------------------------------------------------------------------------------------
|
|
656
603
|
/**
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
604
|
+
* True when start() is called.
|
|
605
|
+
*
|
|
606
|
+
* -> No more services can be added, it's over, bye!
|
|
607
|
+
*/
|
|
661
608
|
isLocked(): boolean;
|
|
662
609
|
/**
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
610
|
+
* Returns whether the App is configured.
|
|
611
|
+
*
|
|
612
|
+
* It means that Alepha#configure() has been called.
|
|
613
|
+
*
|
|
614
|
+
* > By default, configure() is called automatically when start() is called, but you can also call it manually.
|
|
615
|
+
*/
|
|
669
616
|
isConfigured(): boolean;
|
|
670
617
|
/**
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
618
|
+
* Returns whether the App has started.
|
|
619
|
+
*
|
|
620
|
+
* It means that #start() has been called but maybe not all services are ready.
|
|
621
|
+
*/
|
|
675
622
|
isStarted(): boolean;
|
|
676
623
|
/**
|
|
677
|
-
|
|
678
|
-
|
|
624
|
+
* True if the App is ready. It means that Alepha is started AND ready() hook has beed called.
|
|
625
|
+
*/
|
|
679
626
|
isReady(): boolean;
|
|
680
627
|
/**
|
|
681
|
-
|
|
682
|
-
|
|
628
|
+
* True if the App is running in a browser environment.
|
|
629
|
+
*/
|
|
683
630
|
isBrowser(): boolean;
|
|
684
631
|
/**
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
632
|
+
* Returns whether the App is running in a serverless environment.
|
|
633
|
+
*
|
|
634
|
+
* > Vite developer mode is also considered serverless.
|
|
635
|
+
*/
|
|
689
636
|
isServerless(): boolean | "vite" | "vercel";
|
|
690
637
|
/**
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
638
|
+
* Returns whether the App is in test mode. (Running in a test environment)
|
|
639
|
+
*
|
|
640
|
+
* > This is automatically set when running tests with Jest or Vitest.
|
|
641
|
+
*/
|
|
695
642
|
isTest(): boolean;
|
|
696
643
|
/**
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
644
|
+
* Returns whether the App is in production mode. (Running in a production environment)
|
|
645
|
+
*
|
|
646
|
+
* > This is automatically set by Vite or Vercel. However, you have to set it manually when running Docker apps.
|
|
647
|
+
*/
|
|
701
648
|
isProduction(): boolean;
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
649
|
+
// -------------------------------------------------------------------------------------------------------------------
|
|
650
|
+
/**
|
|
651
|
+
* Starts the App.
|
|
652
|
+
*
|
|
653
|
+
* - Lock any further changes to the container.
|
|
654
|
+
* - Run "configure" hook for all services. Descriptors will be processed.
|
|
655
|
+
* - Run "start" hook for all services. Providers will connect/listen/...
|
|
656
|
+
* - Run "ready" hook for all services. This is the point where the App is ready to serve requests.
|
|
657
|
+
*
|
|
658
|
+
* @return A promise that resolves when the App has started.
|
|
659
|
+
*/
|
|
712
660
|
start(): Promise<this>;
|
|
713
661
|
/**
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
662
|
+
* Stops the App.
|
|
663
|
+
*
|
|
664
|
+
* - Run "stop" hook for all services.
|
|
665
|
+
*
|
|
666
|
+
* Stop will NOT reset the container.
|
|
667
|
+
* Stop will NOT unlock the container.
|
|
668
|
+
*
|
|
669
|
+
* > Stop is used to gracefully shut down the application, nothing more. There is no "restart".
|
|
670
|
+
*
|
|
671
|
+
* @return A promise that resolves when the App has stopped.
|
|
672
|
+
*/
|
|
725
673
|
stop(): Promise<void>;
|
|
674
|
+
// -------------------------------------------------------------------------------------------------------------------
|
|
726
675
|
/**
|
|
727
|
-
|
|
728
|
-
|
|
676
|
+
* Check if entry is registered in the container.
|
|
677
|
+
*/
|
|
729
678
|
has(entry: ServiceEntry, opts?: {
|
|
730
679
|
/**
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
680
|
+
* Check if the entry is registered in the pending instantiation stack.
|
|
681
|
+
*
|
|
682
|
+
* Default: true
|
|
683
|
+
*/
|
|
735
684
|
inStack?: boolean;
|
|
736
685
|
/**
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
686
|
+
* Check if the entry is registered in the container registry.
|
|
687
|
+
*
|
|
688
|
+
* Default: true
|
|
689
|
+
*/
|
|
741
690
|
inRegistry?: boolean;
|
|
742
691
|
}): boolean;
|
|
743
692
|
/**
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
693
|
+
* Registers the specified service in the container.
|
|
694
|
+
*
|
|
695
|
+
* - If the service is ALREADY registered, the method does nothing.
|
|
696
|
+
* - If the service is NOT registered, a new instance is created and registered.
|
|
697
|
+
*
|
|
698
|
+
* Method is chainable, so you can register multiple services in a single call.
|
|
699
|
+
*
|
|
700
|
+
* > ServiceEntry allows to provide a service **substitution** feature.
|
|
701
|
+
*
|
|
702
|
+
* @example
|
|
703
|
+
* ```ts
|
|
704
|
+
* class A { value = "a"; }
|
|
705
|
+
* class B { value = "b"; }
|
|
706
|
+
* class M { a = $inject(A); }
|
|
707
|
+
*
|
|
708
|
+
* Alepha.create().with({ provide: A, use: B }).get(M).a.value; // "b"
|
|
709
|
+
* ```
|
|
710
|
+
*
|
|
711
|
+
* > **Substitution** is an advanced feature that allows you to replace a service with another service.
|
|
712
|
+
* > It's useful for testing or for providing different implementations of a service.
|
|
713
|
+
* > If you are interested in configuring a service, use Alepha#configure() instead.
|
|
714
|
+
*
|
|
715
|
+
* @param entry - The service to register in the container.
|
|
716
|
+
* @return Current instance of Alepha.
|
|
717
|
+
*/
|
|
769
718
|
with<T extends object>(entry: ServiceEntry<T>): this;
|
|
770
719
|
/**
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
720
|
+
* Get the instance of the specified service and apply some changes, depending on the options.
|
|
721
|
+
* - If the service is already registered, it will return the existing instance. (except if `skipCache` is true)
|
|
722
|
+
* - If the service is not registered, it will create a new instance and register it. (except if `skipRegistration` is true)
|
|
723
|
+
* - New instance can be created with custom constructor arguments. (`args` option)
|
|
724
|
+
*
|
|
725
|
+
* > This method is used by $inject() under the hood.
|
|
726
|
+
*
|
|
727
|
+
* @return The instance of the specified class or type.
|
|
728
|
+
*/
|
|
780
729
|
get<T extends object>(serviceEntry: ServiceEntry<T>, opts?: {
|
|
781
730
|
/**
|
|
782
|
-
|
|
783
|
-
|
|
731
|
+
* Ignore current existing instance.
|
|
732
|
+
*/
|
|
784
733
|
skipCache?: boolean;
|
|
785
734
|
/**
|
|
786
|
-
|
|
787
|
-
|
|
735
|
+
* Don't store the instance in the registry.
|
|
736
|
+
*/
|
|
788
737
|
skipRegistration?: boolean;
|
|
789
738
|
/**
|
|
790
|
-
|
|
791
|
-
|
|
739
|
+
* Constructor arguments to pass when creating a new instance.
|
|
740
|
+
*/
|
|
792
741
|
args?: ConstructorParameters<InstantiableService<T>>;
|
|
793
742
|
/**
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
743
|
+
* Parent service that requested the instance.
|
|
744
|
+
* @internal
|
|
745
|
+
*/
|
|
797
746
|
parent?: Service | null;
|
|
798
747
|
/**
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
748
|
+
* If the service is provided by a module, the module definition.
|
|
749
|
+
* @internal
|
|
750
|
+
*/
|
|
802
751
|
module?: ModuleDefinition;
|
|
803
752
|
}): T;
|
|
804
753
|
/**
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
configure<T extends
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
754
|
+
* Configures the specified service with the provided state.
|
|
755
|
+
* If service is not registered, it will do nothing.
|
|
756
|
+
*
|
|
757
|
+
* It's recommended to use this method on the `configure` hook.
|
|
758
|
+
* @example
|
|
759
|
+
* ```ts
|
|
760
|
+
* class AppConfig {
|
|
761
|
+
* configure = $hook({
|
|
762
|
+
* name: "configure",
|
|
763
|
+
* handler: (a) => {
|
|
764
|
+
* a.configure(MyProvider, { some: "data" });
|
|
765
|
+
* }
|
|
766
|
+
* })
|
|
767
|
+
* }
|
|
768
|
+
* ```
|
|
769
|
+
*/
|
|
770
|
+
configure<T extends {
|
|
771
|
+
options: object;
|
|
772
|
+
}>(service: Service<T>, state: Partial<T["options"]>): this;
|
|
773
|
+
// -------------------------------------------------------------------------------------------------------------------
|
|
774
|
+
protected useCounter: number;
|
|
775
|
+
use<T extends Descriptor>(descriptor: T, options: Parameters<T>[0]): ReturnType<T>;
|
|
776
|
+
// -------------------------------------------------------------------------------------------------------------------
|
|
777
|
+
/**
|
|
778
|
+
* Registers a hook for the specified event.
|
|
779
|
+
*/
|
|
825
780
|
on<T extends keyof Hooks>(event: T, hookOrFunc: Hook<T> | ((payload: Hooks[T]) => Async<void>)): () => void;
|
|
826
781
|
/**
|
|
827
|
-
|
|
828
|
-
|
|
782
|
+
* Emits the specified event with the given payload.
|
|
783
|
+
*/
|
|
829
784
|
emit<T extends keyof Hooks>(func: keyof Hooks, payload: Hooks[T], options?: {
|
|
830
785
|
/**
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
786
|
+
* If true, the hooks will be executed in reverse order.
|
|
787
|
+
* This is useful for "stop" hooks that should be executed in reverse order.
|
|
788
|
+
*
|
|
789
|
+
* @default false
|
|
790
|
+
*/
|
|
836
791
|
reverse?: boolean;
|
|
837
792
|
/**
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
793
|
+
* If true, the hooks will be logged with their execution time.
|
|
794
|
+
*
|
|
795
|
+
* @default false
|
|
796
|
+
*/
|
|
842
797
|
log?: boolean;
|
|
843
798
|
/**
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
799
|
+
* If true, errors will be caught and logged instead of throwing.
|
|
800
|
+
*
|
|
801
|
+
* @default false
|
|
802
|
+
*/
|
|
848
803
|
catch?: boolean;
|
|
849
804
|
}): Promise<void>;
|
|
805
|
+
// -------------------------------------------------------------------------------------------------------------------
|
|
850
806
|
/**
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
807
|
+
* Casts the given value to the specified schema.
|
|
808
|
+
*
|
|
809
|
+
* It uses the TypeBox library to validate the value against the schema.
|
|
810
|
+
*/
|
|
855
811
|
parse<T extends TSchema$1>(schema: T, value?: any, opts?: {
|
|
856
812
|
/**
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
813
|
+
* Clone the value before parsing.
|
|
814
|
+
* @default true
|
|
815
|
+
*/
|
|
860
816
|
clone?: boolean;
|
|
861
817
|
/**
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
818
|
+
* Apply default values defined in the schema.
|
|
819
|
+
* @default true
|
|
820
|
+
*/
|
|
865
821
|
default?: boolean;
|
|
866
822
|
/**
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
823
|
+
* Remove all values not defined in the schema.
|
|
824
|
+
* @default true
|
|
825
|
+
*/
|
|
870
826
|
clean?: boolean;
|
|
871
827
|
/**
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
828
|
+
* Try to cast/convert some data based on the schema.
|
|
829
|
+
* @default true
|
|
830
|
+
*/
|
|
875
831
|
convert?: boolean;
|
|
876
832
|
/**
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
833
|
+
* Prepare value after being deserialized.
|
|
834
|
+
* @default true
|
|
835
|
+
*/
|
|
880
836
|
check?: boolean;
|
|
881
837
|
}): Static$1<T>;
|
|
882
838
|
/**
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
839
|
+
* Applies environment variables to the provided schema and state object.
|
|
840
|
+
*
|
|
841
|
+
* It replaces also all templated $ENV inside string values.
|
|
842
|
+
*
|
|
843
|
+
* @param schema - The schema object to apply environment variables to.
|
|
844
|
+
* @return The schema object with environment variables applied.
|
|
845
|
+
*/
|
|
890
846
|
parseEnv<T extends TObject$1>(schema: T): Static$1<T>;
|
|
847
|
+
// -------------------------------------------------------------------------------------------------------------------
|
|
891
848
|
/**
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
849
|
+
* Dump the current dependency graph of the App.
|
|
850
|
+
*
|
|
851
|
+
* This method returns a record where the keys are the names of the services.
|
|
852
|
+
*/
|
|
896
853
|
graph(): Record<string, {
|
|
897
854
|
from: string[];
|
|
898
855
|
as?: string;
|
|
899
856
|
module?: string;
|
|
900
857
|
}>;
|
|
858
|
+
// -------------------------------------------------------------------------------------------------------------------
|
|
901
859
|
/**
|
|
902
|
-
|
|
903
|
-
|
|
860
|
+
* @internal
|
|
861
|
+
*/
|
|
904
862
|
getDescriptorValues<T extends Descriptor>(descriptor: T): Array<DescriptorItem<T>>;
|
|
905
863
|
/**
|
|
906
|
-
|
|
907
|
-
|
|
864
|
+
* @internal
|
|
865
|
+
*/
|
|
908
866
|
protected new<T extends object>(definition: Service<T>, args?: any[], module?: ModuleDefinition): T;
|
|
909
867
|
/**
|
|
910
|
-
|
|
911
|
-
|
|
868
|
+
* @internal
|
|
869
|
+
*/
|
|
912
870
|
protected createLogger(env: Env): Logger;
|
|
913
|
-
/**
|
|
914
|
-
* @internal
|
|
915
|
-
*/
|
|
916
871
|
getModuleOf(service: Service): Module | undefined;
|
|
917
872
|
}
|
|
873
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
918
874
|
/**
|
|
919
|
-
|
|
920
|
-
|
|
875
|
+
* This is how we store services in the Alepha container.
|
|
876
|
+
*/
|
|
921
877
|
interface ServiceDefinition<T extends object = any> {
|
|
922
878
|
/**
|
|
923
|
-
|
|
924
|
-
|
|
879
|
+
* The class or type definition to provide.
|
|
880
|
+
*/
|
|
925
881
|
provide: Service<T>;
|
|
926
882
|
/**
|
|
927
|
-
|
|
928
|
-
|
|
883
|
+
* The class or type definition to use. This will override the 'provide' property.
|
|
884
|
+
*/
|
|
929
885
|
use?: Service<T>;
|
|
930
886
|
/**
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
887
|
+
* The instance of the class or type definition.
|
|
888
|
+
* Mostly used for caching / singleton but can be used for other purposes like forcing the instance.
|
|
889
|
+
*/
|
|
934
890
|
instance: T;
|
|
935
891
|
/**
|
|
936
|
-
|
|
937
|
-
|
|
892
|
+
* List of classes which use this class.
|
|
893
|
+
*/
|
|
938
894
|
parents: Array<Service | null>;
|
|
939
895
|
/**
|
|
940
|
-
|
|
941
|
-
|
|
896
|
+
* If the service is provided by a module, the module definition.
|
|
897
|
+
*/
|
|
942
898
|
module?: ModuleDefinition;
|
|
943
899
|
}
|
|
900
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
901
|
+
interface Env extends LoggerEnv {
|
|
902
|
+
[key: string]: string | boolean | number | undefined;
|
|
903
|
+
/**
|
|
904
|
+
* Optional environment variable that indicates the current environment.
|
|
905
|
+
*/
|
|
906
|
+
NODE_ENV?: "dev" | "test" | "production";
|
|
907
|
+
/**
|
|
908
|
+
* Optional name of the application.
|
|
909
|
+
*/
|
|
910
|
+
APP_NAME?: string;
|
|
911
|
+
/**
|
|
912
|
+
* Optional root module name.
|
|
913
|
+
*/
|
|
914
|
+
MODULE_NAME?: string;
|
|
915
|
+
/**
|
|
916
|
+
* If true, the container will not automatically register the default providers based on the descriptors.
|
|
917
|
+
*
|
|
918
|
+
* It means that you have to alepha.with(ServiceModule) manually. No magic.
|
|
919
|
+
*
|
|
920
|
+
* @default false
|
|
921
|
+
*/
|
|
922
|
+
EXPLICIT_PROVIDERS?: boolean;
|
|
923
|
+
}
|
|
924
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
925
|
+
interface State {
|
|
926
|
+
log: Logger;
|
|
927
|
+
env?: Readonly<Env>;
|
|
928
|
+
// test hooks
|
|
929
|
+
beforeAll?: (run: any) => any;
|
|
930
|
+
afterAll?: (run: any) => any;
|
|
931
|
+
afterEach?: (run: any) => any;
|
|
932
|
+
onTestFinished?: (run: any) => any;
|
|
933
|
+
}
|
|
934
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
935
|
+
interface Hooks {
|
|
936
|
+
echo: any;
|
|
937
|
+
/**
|
|
938
|
+
* Triggered during the configuration phase. Before the start phase.
|
|
939
|
+
*/
|
|
940
|
+
configure: Alepha;
|
|
941
|
+
/**
|
|
942
|
+
* Triggered during the start phase. When `Alepha#start()` is called.
|
|
943
|
+
*/
|
|
944
|
+
start: Alepha;
|
|
945
|
+
/**
|
|
946
|
+
* Triggered during the ready phase. After the start phase.
|
|
947
|
+
*/
|
|
948
|
+
ready: Alepha;
|
|
949
|
+
/**
|
|
950
|
+
* Triggered during the stop phase.
|
|
951
|
+
*
|
|
952
|
+
* - Stop should be called after a SIGINT or SIGTERM signal in order to gracefully shutdown the application. (@see `run()` method)
|
|
953
|
+
*
|
|
954
|
+
*/
|
|
955
|
+
stop: Alepha;
|
|
956
|
+
/**
|
|
957
|
+
* Triggered when a state value is mutated.
|
|
958
|
+
*/
|
|
959
|
+
"state:mutate": {
|
|
960
|
+
/**
|
|
961
|
+
* The key of the state that was mutated.
|
|
962
|
+
*/
|
|
963
|
+
key: keyof State;
|
|
964
|
+
/**
|
|
965
|
+
* The new value of the state.
|
|
966
|
+
*/
|
|
967
|
+
value: any;
|
|
968
|
+
/**
|
|
969
|
+
* The previous value of the state.
|
|
970
|
+
*/
|
|
971
|
+
prevValue: any;
|
|
972
|
+
};
|
|
973
|
+
}
|
|
944
974
|
//#endregion
|
|
945
975
|
//#region src/interfaces/Run.d.ts
|
|
946
976
|
interface RunOptions {
|
|
947
977
|
/**
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
978
|
+
* Environment variables to be used by the application.
|
|
979
|
+
* If not provided, it will use the current process environment.
|
|
980
|
+
*/
|
|
951
981
|
env?: Env;
|
|
952
982
|
/**
|
|
953
|
-
|
|
954
|
-
|
|
983
|
+
* A callback that will be executed before the application starts.
|
|
984
|
+
*/
|
|
955
985
|
configure?: (alepha: Alepha) => Async<void>;
|
|
956
986
|
/**
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
987
|
+
* A callback that will be executed once the application is ready.
|
|
988
|
+
* This is useful for initializing resources or starting background tasks.
|
|
989
|
+
*/
|
|
960
990
|
ready?: (alepha: Alepha) => Async<void>;
|
|
961
991
|
/**
|
|
962
|
-
|
|
963
|
-
|
|
992
|
+
* If true, the application will stop after the ready callback is executed.
|
|
993
|
+
*/
|
|
964
994
|
once?: boolean;
|
|
965
995
|
}
|
|
966
996
|
//#endregion
|
|
967
997
|
//#region src/descriptors/$inject.d.ts
|
|
968
998
|
/**
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
999
|
+
* Get the instance of the specified type from the context.
|
|
1000
|
+
*
|
|
1001
|
+
* - If the type is a class, it will be resolved from the context.
|
|
1002
|
+
* - If the type is a schema, it will be parsed from the environment.
|
|
1003
|
+
*
|
|
1004
|
+
* ```ts
|
|
1005
|
+
* class A { }
|
|
1006
|
+
* class B {
|
|
1007
|
+
* a = $inject(A);
|
|
1008
|
+
* }
|
|
1009
|
+
* ```
|
|
1010
|
+
*
|
|
1011
|
+
* @param type - Type (or TypeBox schema) to resolve
|
|
1012
|
+
* @returns Instance of the specified type
|
|
1013
|
+
*/
|
|
984
1014
|
declare function $inject<T extends TObject$1>(type: T): Static$1<T>;
|
|
985
1015
|
declare function $inject<T extends object>(type: Service<T>): T;
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
1016
|
+
declare class InjectResolverRegistry {
|
|
1017
|
+
resolvers: Array<(it: any) => any>;
|
|
1018
|
+
register(fn: (it: any) => any): void;
|
|
1019
|
+
resolve(it: any): any;
|
|
1020
|
+
}
|
|
1021
|
+
declare const $injectResolverRegistry: InjectResolverRegistry;
|
|
990
1022
|
//#endregion
|
|
991
1023
|
//#region src/descriptors/$logger.d.ts
|
|
992
1024
|
/**
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1025
|
+
* Create a logger.
|
|
1026
|
+
*
|
|
1027
|
+
* `name` is optional, by default it will use the name of the service.
|
|
1028
|
+
*
|
|
1029
|
+
* @example
|
|
1030
|
+
* ```ts
|
|
1031
|
+
* import { $logger } from "alepha";
|
|
1032
|
+
*
|
|
1033
|
+
* class MyService {
|
|
1034
|
+
* log = $logger();
|
|
1035
|
+
*
|
|
1036
|
+
* constructor() {
|
|
1037
|
+
* // print something like 'date - [MyService] Service initialized'
|
|
1038
|
+
* this.log.info("Service initialized");
|
|
1039
|
+
* }
|
|
1040
|
+
* }
|
|
1041
|
+
* ```
|
|
1042
|
+
*/
|
|
1011
1043
|
declare const $logger: (name?: string) => Logger;
|
|
1012
1044
|
//#endregion
|
|
1013
1045
|
//#region src/errors/AlephaError.d.ts
|
|
1046
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
1014
1047
|
/**
|
|
1015
|
-
|
|
1016
|
-
|
|
1048
|
+
* Default error class for Alepha.
|
|
1049
|
+
*/
|
|
1017
1050
|
declare class AlephaError extends Error {}
|
|
1018
1051
|
//#endregion
|
|
1019
1052
|
//#region src/errors/AppNotStartedError.d.ts
|
|
@@ -1043,245 +1076,220 @@ declare class TypeBoxError extends Error {
|
|
|
1043
1076
|
}
|
|
1044
1077
|
//#endregion
|
|
1045
1078
|
//#region src/providers/TypeProvider.d.ts
|
|
1079
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
1046
1080
|
declare class TypeProvider {
|
|
1047
1081
|
static DEFAULT_STRING_MAX_LENGTH: number;
|
|
1048
1082
|
static DEFAULT_LONG_STRING_MAX_LENGTH: number;
|
|
1049
1083
|
static DEFAULT_RICH_STRING_MAX_LENGTH: number;
|
|
1050
1084
|
static DEFAULT_ARRAY_MAX_ITEMS: number;
|
|
1051
|
-
static FormatRegistry: typeof
|
|
1052
|
-
|
|
1053
|
-
any
|
|
1054
|
-
void
|
|
1055
|
-
undefined
|
|
1056
|
-
record
|
|
1057
|
-
omit:
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
/**
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
/**
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
* @param schema The schema to make nullable.
|
|
1146
|
-
* @param options The options for the schema.
|
|
1147
|
-
*/
|
|
1148
|
-
nullable: <T extends TSchema$1>(schema: T, options?: ObjectOptions) => Union<[TNull, T]>;
|
|
1149
|
-
/**
|
|
1150
|
-
* Map a schema to another schema.
|
|
1151
|
-
*
|
|
1152
|
-
* @param schema The schema to map.
|
|
1153
|
-
* @param operations The operations to perform on the schema.
|
|
1154
|
-
* @param options The options for the schema.
|
|
1155
|
-
* @returns The mapped schema.
|
|
1156
|
-
*/
|
|
1157
|
-
map: <T extends TObject$1 | TIntersect, Omit extends (keyof T["properties"])[], Optional extends (keyof T["properties"])[]>(schema: T, operations: {
|
|
1085
|
+
static FormatRegistry: typeof FormatRegistry;
|
|
1086
|
+
raw: typeof Type;
|
|
1087
|
+
any(options?: SchemaOptions): TAny$1;
|
|
1088
|
+
void(options?: SchemaOptions): TVoid;
|
|
1089
|
+
undefined(options?: SchemaOptions): TUndefined;
|
|
1090
|
+
record<Key extends TSchema$1, Value extends TSchema$1>(key: Key, value: Value, options?: ObjectOptions): TRecordOrObject<Key, Value>;
|
|
1091
|
+
omit<Type extends TSchema$1, Key extends TSchema$1>(type: Type, key: Key, options?: SchemaOptions): TOmit<Type, Key>;
|
|
1092
|
+
partial<MappedResult extends TMappedResult>(type: MappedResult, options?: SchemaOptions): TPartialFromMappedResult<MappedResult>;
|
|
1093
|
+
union<Types extends TSchema$1[]>(types: [...Types], options?: SchemaOptions): Union<Types>;
|
|
1094
|
+
composite<T extends TSchema$1[]>(schemas: [...T], options?: ObjectOptions): TComposite<T>;
|
|
1095
|
+
pick<Type extends TSchema$1, Key extends PropertyKey[]>(type: Type, key: readonly [...Key], options?: SchemaOptions): TPick<Type, Key>;
|
|
1096
|
+
/**
|
|
1097
|
+
* Create a schema for an object.
|
|
1098
|
+
*
|
|
1099
|
+
* @param properties The properties of the object.
|
|
1100
|
+
* @param options The options for the object.
|
|
1101
|
+
*/
|
|
1102
|
+
object<T extends TProperties$1>(properties: T, options?: ObjectOptions): TObject$1<T>;
|
|
1103
|
+
/**
|
|
1104
|
+
* Create a schema for an array.
|
|
1105
|
+
*
|
|
1106
|
+
* @param schema
|
|
1107
|
+
* @param options
|
|
1108
|
+
*/
|
|
1109
|
+
array<T extends TSchema$1>(schema: T, options?: ArrayOptions): TArray$1<T>;
|
|
1110
|
+
/**
|
|
1111
|
+
* Create a schema for a string.
|
|
1112
|
+
*
|
|
1113
|
+
* @param options
|
|
1114
|
+
*/
|
|
1115
|
+
string(options?: AlephaStringOptions): TString$1;
|
|
1116
|
+
/**
|
|
1117
|
+
* Create a schema for a JSON object.
|
|
1118
|
+
*
|
|
1119
|
+
* @param options
|
|
1120
|
+
*/
|
|
1121
|
+
json(options?: SchemaOptions): TRecord$1<TString$1, TAny$1>;
|
|
1122
|
+
/**
|
|
1123
|
+
* Create a schema for a boolean.
|
|
1124
|
+
*
|
|
1125
|
+
* @param options
|
|
1126
|
+
*/
|
|
1127
|
+
boolean(options?: SchemaOptions): TBoolean$1;
|
|
1128
|
+
/**
|
|
1129
|
+
* Create a schema for a number.
|
|
1130
|
+
*
|
|
1131
|
+
* @param options
|
|
1132
|
+
*/
|
|
1133
|
+
number(options?: NumberOptions): TNumber$1;
|
|
1134
|
+
/**
|
|
1135
|
+
* Create a schema for an unsigned 8-bit integer.
|
|
1136
|
+
*
|
|
1137
|
+
* @param options
|
|
1138
|
+
*/
|
|
1139
|
+
uchar(options?: IntegerOptions): TInteger;
|
|
1140
|
+
/**
|
|
1141
|
+
* Create a schema for an unsigned 32-bit integer.
|
|
1142
|
+
*/
|
|
1143
|
+
uint(options?: IntegerOptions): TNumber$1;
|
|
1144
|
+
/**
|
|
1145
|
+
* Create a schema for a signed 32-bit integer.
|
|
1146
|
+
*/
|
|
1147
|
+
int(options?: IntegerOptions): TInteger;
|
|
1148
|
+
/**
|
|
1149
|
+
* Create a schema for a signed 32-bit integer.
|
|
1150
|
+
*/
|
|
1151
|
+
integer(options?: IntegerOptions): TInteger;
|
|
1152
|
+
/**
|
|
1153
|
+
* Create a schema for a bigint. Bigint is a 64-bit integer.
|
|
1154
|
+
* This is a workaround for TypeBox, which does not support bigint natively.
|
|
1155
|
+
*/
|
|
1156
|
+
bigint(options?: IntegerOptions): TNumber$1;
|
|
1157
|
+
/**
|
|
1158
|
+
* Make a schema optional.
|
|
1159
|
+
*
|
|
1160
|
+
* @param schema The schema to make optional.
|
|
1161
|
+
*/
|
|
1162
|
+
optional<T extends TSchema$1>(schema: T): TOptionalWithFlag<T, true>;
|
|
1163
|
+
/**
|
|
1164
|
+
* Make a schema nullable.
|
|
1165
|
+
*
|
|
1166
|
+
* @param schema The schema to make nullable.
|
|
1167
|
+
* @param options The options for the schema.
|
|
1168
|
+
*/
|
|
1169
|
+
nullable<T extends TSchema$1>(schema: T, options?: ObjectOptions): TUnion<[TNull, T]>;
|
|
1170
|
+
/**
|
|
1171
|
+
* Map a schema to another schema.
|
|
1172
|
+
*
|
|
1173
|
+
* @param schema The schema to map.
|
|
1174
|
+
* @param operations The operations to perform on the schema.
|
|
1175
|
+
* @param options The options for the schema.
|
|
1176
|
+
* @returns The mapped schema.
|
|
1177
|
+
*/
|
|
1178
|
+
map<T extends TObject$1 | TIntersect, Omit extends (keyof T["properties"])[], Optional extends (keyof T["properties"])[]>(schema: T, operations: {
|
|
1158
1179
|
omit: readonly [...Omit];
|
|
1159
1180
|
optional: [...Optional];
|
|
1160
|
-
}, options?: ObjectOptions) => TObject$1<TypeBox.Evaluate<TypeBox.TSetDistinct<[...TypeBox.TKeyOfPropertyKeys<TypeBox.TOmit<T, [...Omit, ...Optional], T extends TypeBox.TRef<string> ? true : false, [...Omit, ...Optional] extends infer T_1 ? T_1 extends [...Omit, ...Optional] ? T_1 extends TypeBox.TRef<string> ? true : false : never : never>>, ...TypeBox.TKeyOfPropertyKeys<TypeBox.TPartial<TypeBox.TPick<T, Optional, T extends TypeBox.TRef<string> ? true : false, Optional extends TypeBox.TRef<string> ? true : false>>>], []> extends infer T_2 ? T_2 extends TypeBox.TSetDistinct<[...TypeBox.TKeyOfPropertyKeys<TypeBox.TOmit<T, [...Omit, ...Optional], T extends TypeBox.TRef<string> ? true : false, [...Omit, ...Optional] extends infer T_53 ? T_53 extends [...Omit, ...Optional] ? T_53 extends TypeBox.TRef<string> ? true : false : never : never>>, ...TypeBox.TKeyOfPropertyKeys<TypeBox.TPartial<TypeBox.TPick<T, Optional, T extends TypeBox.TRef<string> ? true : false, Optional extends TypeBox.TRef<string> ? true : false>>>], []> ? T_2 extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? R extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? R extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? R extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? R extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? R extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? R extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? R extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? R extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? R extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? R extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? /*elided*/any : { [_ in L]: TypeBox.TIntersectEvaluated<TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TOmit<T, [...Omit, ...Optional], T extends TypeBox.TRef<string> ? true : false, [...Omit, ...Optional] extends infer T_3 ? T_3 extends [...Omit, ...Optional] ? T_3 extends TypeBox.TRef<string> ? true : false : never : never>, L>, TSchema$1> extends infer T_4 ? T_4 extends TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TOmit<T, [...Omit, ...Optional], T extends TypeBox.TRef<string> ? true : false, [...Omit, ...Optional] extends infer T_7 ? T_7 extends [...Omit, ...Optional] ? T_7 extends TypeBox.TRef<string> ? true : false : never : never>, L>, TSchema$1> ? T_4 extends TypeBox.TNever ? TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TPartial<TypeBox.TPick<T, Optional, T extends TypeBox.TRef<string> ? true : false, Optional extends TypeBox.TRef<string> ? true : false>>, L>, TSchema$1> extends infer T_5 ? T_5 extends TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TPartial<TypeBox.TPick<T, Optional, T extends TypeBox.TRef<string> ? true : false, Optional extends TypeBox.TRef<string> ? true : false>>, L>, TSchema$1> ? T_5 extends TypeBox.TNever ? [] : [T_5] : never : never : TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TPartial<TypeBox.TPick<T, Optional, T extends TypeBox.TRef<string> ? true : false, Optional extends TypeBox.TRef<string> ? true : false>>, L>, TSchema$1> extends infer T_6 ? T_6 extends TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TPartial<TypeBox.TPick<T, Optional, T extends TypeBox.TRef<string> ? true : false, Optional extends TypeBox.TRef<string> ? true : false>>, L>, TSchema$1> ? T_6 extends TypeBox.TNever ? [T_4] : [T_4, T_6] : never : never : never : never> } : { [_ in L]: TypeBox.TIntersectEvaluated<TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TOmit<T, [...Omit, ...Optional], T extends TypeBox.TRef<string> ? true : false, [...Omit, ...Optional] extends infer T_8 ? T_8 extends [...Omit, ...Optional] ? T_8 extends TypeBox.TRef<string> ? true : false : never : never>, L>, TSchema$1> extends infer T_9 ? T_9 extends TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TOmit<T, [...Omit, ...Optional], T extends TypeBox.TRef<string> ? true : false, [...Omit, ...Optional] extends infer T_12 ? T_12 extends [...Omit, ...Optional] ? T_12 extends TypeBox.TRef<string> ? true : false : never : never>, L>, TSchema$1> ? T_9 extends TypeBox.TNever ? TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TPartial<TypeBox.TPick<T, Optional, T extends TypeBox.TRef<string> ? true : false, Optional extends TypeBox.TRef<string> ? true : false>>, L>, TSchema$1> extends infer T_10 ? T_10 extends TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TPartial<TypeBox.TPick<T, Optional, T extends TypeBox.TRef<string> ? true : false, Optional extends TypeBox.TRef<string> ? true : false>>, L>, TSchema$1> ? T_10 extends TypeBox.TNever ? [] : [T_10] : never : never : TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TPartial<TypeBox.TPick<T, Optional, T extends TypeBox.TRef<string> ? true : false, Optional extends TypeBox.TRef<string> ? true : false>>, L>, TSchema$1> extends infer T_11 ? T_11 extends TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TPartial<TypeBox.TPick<T, Optional, T extends TypeBox.TRef<string> ? true : false, Optional extends TypeBox.TRef<string> ? true : false>>, L>, TSchema$1> ? T_11 extends TypeBox.TNever ? [T_9] : [T_9, T_11] : never : never : never : never> } : { [_ in L]: TypeBox.TIntersectEvaluated<TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TOmit<T, [...Omit, ...Optional], T extends TypeBox.TRef<string> ? true : false, [...Omit, ...Optional] extends infer T_13 ? T_13 extends [...Omit, ...Optional] ? T_13 extends TypeBox.TRef<string> ? true : false : never : never>, L>, TSchema$1> extends infer T_14 ? T_14 extends TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TOmit<T, [...Omit, ...Optional], T extends TypeBox.TRef<string> ? true : false, [...Omit, ...Optional] extends infer T_17 ? T_17 extends [...Omit, ...Optional] ? T_17 extends TypeBox.TRef<string> ? true : false : never : never>, L>, TSchema$1> ? T_14 extends TypeBox.TNever ? TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TPartial<TypeBox.TPick<T, Optional, T extends TypeBox.TRef<string> ? true : false, Optional extends TypeBox.TRef<string> ? true : false>>, L>, TSchema$1> extends infer T_15 ? T_15 extends TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TPartial<TypeBox.TPick<T, Optional, T extends TypeBox.TRef<string> ? true : false, Optional extends TypeBox.TRef<string> ? true : false>>, L>, TSchema$1> ? T_15 extends TypeBox.TNever ? [] : [T_15] : never : never : TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TPartial<TypeBox.TPick<T, Optional, T extends TypeBox.TRef<string> ? true : false, Optional extends TypeBox.TRef<string> ? true : false>>, L>, TSchema$1> extends infer T_16 ? T_16 extends TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TPartial<TypeBox.TPick<T, Optional, T extends TypeBox.TRef<string> ? true : false, Optional extends TypeBox.TRef<string> ? true : false>>, L>, TSchema$1> ? T_16 extends TypeBox.TNever ? [T_14] : [T_14, T_16] : never : never : never : never> } : { [_ in L]: TypeBox.TIntersectEvaluated<TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TOmit<T, [...Omit, ...Optional], T extends TypeBox.TRef<string> ? true : false, [...Omit, ...Optional] extends infer T_18 ? T_18 extends [...Omit, ...Optional] ? T_18 extends TypeBox.TRef<string> ? true : false : never : never>, L>, TSchema$1> extends infer T_19 ? T_19 extends TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TOmit<T, [...Omit, ...Optional], T extends TypeBox.TRef<string> ? true : false, [...Omit, ...Optional] extends infer T_22 ? T_22 extends [...Omit, ...Optional] ? T_22 extends TypeBox.TRef<string> ? true : false : never : never>, L>, TSchema$1> ? T_19 extends TypeBox.TNever ? TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TPartial<TypeBox.TPick<T, Optional, T extends TypeBox.TRef<string> ? true : false, Optional extends TypeBox.TRef<string> ? true : false>>, L>, TSchema$1> extends infer T_20 ? T_20 extends TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TPartial<TypeBox.TPick<T, Optional, T extends TypeBox.TRef<string> ? true : false, Optional extends TypeBox.TRef<string> ? true : false>>, L>, TSchema$1> ? T_20 extends TypeBox.TNever ? [] : [T_20] : never : never : TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TPartial<TypeBox.TPick<T, Optional, T extends TypeBox.TRef<string> ? true : false, Optional extends TypeBox.TRef<string> ? true : false>>, L>, TSchema$1> extends infer T_21 ? T_21 extends TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TPartial<TypeBox.TPick<T, Optional, T extends TypeBox.TRef<string> ? true : false, Optional extends TypeBox.TRef<string> ? true : false>>, L>, TSchema$1> ? T_21 extends TypeBox.TNever ? [T_19] : [T_19, T_21] : never : never : never : never> } : { [_ in L]: TypeBox.TIntersectEvaluated<TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TOmit<T, [...Omit, ...Optional], T extends TypeBox.TRef<string> ? true : false, [...Omit, ...Optional] extends infer T_23 ? T_23 extends [...Omit, ...Optional] ? T_23 extends TypeBox.TRef<string> ? true : false : never : never>, L>, TSchema$1> extends infer T_24 ? T_24 extends TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TOmit<T, [...Omit, ...Optional], T extends TypeBox.TRef<string> ? true : false, [...Omit, ...Optional] extends infer T_27 ? T_27 extends [...Omit, ...Optional] ? T_27 extends TypeBox.TRef<string> ? true : false : never : never>, L>, TSchema$1> ? T_24 extends TypeBox.TNever ? TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TPartial<TypeBox.TPick<T, Optional, T extends TypeBox.TRef<string> ? true : false, Optional extends TypeBox.TRef<string> ? true : false>>, L>, TSchema$1> extends infer T_25 ? T_25 extends TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TPartial<TypeBox.TPick<T, Optional, T extends TypeBox.TRef<string> ? true : false, Optional extends TypeBox.TRef<string> ? true : false>>, L>, TSchema$1> ? T_25 extends TypeBox.TNever ? [] : [T_25] : never : never : TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TPartial<TypeBox.TPick<T, Optional, T extends TypeBox.TRef<string> ? true : false, Optional extends TypeBox.TRef<string> ? true : false>>, L>, TSchema$1> extends infer T_26 ? T_26 extends TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TPartial<TypeBox.TPick<T, Optional, T extends TypeBox.TRef<string> ? true : false, Optional extends TypeBox.TRef<string> ? true : false>>, L>, TSchema$1> ? T_26 extends TypeBox.TNever ? [T_24] : [T_24, T_26] : never : never : never : never> } : { [_ in L]: TypeBox.TIntersectEvaluated<TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TOmit<T, [...Omit, ...Optional], T extends TypeBox.TRef<string> ? true : false, [...Omit, ...Optional] extends infer T_28 ? T_28 extends [...Omit, ...Optional] ? T_28 extends TypeBox.TRef<string> ? true : false : never : never>, L>, TSchema$1> extends infer T_29 ? T_29 extends TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TOmit<T, [...Omit, ...Optional], T extends TypeBox.TRef<string> ? true : false, [...Omit, ...Optional] extends infer T_32 ? T_32 extends [...Omit, ...Optional] ? T_32 extends TypeBox.TRef<string> ? true : false : never : never>, L>, TSchema$1> ? T_29 extends TypeBox.TNever ? TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TPartial<TypeBox.TPick<T, Optional, T extends TypeBox.TRef<string> ? true : false, Optional extends TypeBox.TRef<string> ? true : false>>, L>, TSchema$1> extends infer T_30 ? T_30 extends TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TPartial<TypeBox.TPick<T, Optional, T extends TypeBox.TRef<string> ? true : false, Optional extends TypeBox.TRef<string> ? true : false>>, L>, TSchema$1> ? T_30 extends TypeBox.TNever ? [] : [T_30] : never : never : TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TPartial<TypeBox.TPick<T, Optional, T extends TypeBox.TRef<string> ? true : false, Optional extends TypeBox.TRef<string> ? true : false>>, L>, TSchema$1> extends infer T_31 ? T_31 extends TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TPartial<TypeBox.TPick<T, Optional, T extends TypeBox.TRef<string> ? true : false, Optional extends TypeBox.TRef<string> ? true : false>>, L>, TSchema$1> ? T_31 extends TypeBox.TNever ? [T_29] : [T_29, T_31] : never : never : never : never> } : { [_ in L]: TypeBox.TIntersectEvaluated<TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TOmit<T, [...Omit, ...Optional], T extends TypeBox.TRef<string> ? true : false, [...Omit, ...Optional] extends infer T_33 ? T_33 extends [...Omit, ...Optional] ? T_33 extends TypeBox.TRef<string> ? true : false : never : never>, L>, TSchema$1> extends infer T_34 ? T_34 extends TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TOmit<T, [...Omit, ...Optional], T extends TypeBox.TRef<string> ? true : false, [...Omit, ...Optional] extends infer T_37 ? T_37 extends [...Omit, ...Optional] ? T_37 extends TypeBox.TRef<string> ? true : false : never : never>, L>, TSchema$1> ? T_34 extends TypeBox.TNever ? TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TPartial<TypeBox.TPick<T, Optional, T extends TypeBox.TRef<string> ? true : false, Optional extends TypeBox.TRef<string> ? true : false>>, L>, TSchema$1> extends infer T_35 ? T_35 extends TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TPartial<TypeBox.TPick<T, Optional, T extends TypeBox.TRef<string> ? true : false, Optional extends TypeBox.TRef<string> ? true : false>>, L>, TSchema$1> ? T_35 extends TypeBox.TNever ? [] : [T_35] : never : never : TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TPartial<TypeBox.TPick<T, Optional, T extends TypeBox.TRef<string> ? true : false, Optional extends TypeBox.TRef<string> ? true : false>>, L>, TSchema$1> extends infer T_36 ? T_36 extends TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TPartial<TypeBox.TPick<T, Optional, T extends TypeBox.TRef<string> ? true : false, Optional extends TypeBox.TRef<string> ? true : false>>, L>, TSchema$1> ? T_36 extends TypeBox.TNever ? [T_34] : [T_34, T_36] : never : never : never : never> } : { [_ in L]: TypeBox.TIntersectEvaluated<TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TOmit<T, [...Omit, ...Optional], T extends TypeBox.TRef<string> ? true : false, [...Omit, ...Optional] extends infer T_38 ? T_38 extends [...Omit, ...Optional] ? T_38 extends TypeBox.TRef<string> ? true : false : never : never>, L>, TSchema$1> extends infer T_39 ? T_39 extends TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TOmit<T, [...Omit, ...Optional], T extends TypeBox.TRef<string> ? true : false, [...Omit, ...Optional] extends infer T_42 ? T_42 extends [...Omit, ...Optional] ? T_42 extends TypeBox.TRef<string> ? true : false : never : never>, L>, TSchema$1> ? T_39 extends TypeBox.TNever ? TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TPartial<TypeBox.TPick<T, Optional, T extends TypeBox.TRef<string> ? true : false, Optional extends TypeBox.TRef<string> ? true : false>>, L>, TSchema$1> extends infer T_40 ? T_40 extends TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TPartial<TypeBox.TPick<T, Optional, T extends TypeBox.TRef<string> ? true : false, Optional extends TypeBox.TRef<string> ? true : false>>, L>, TSchema$1> ? T_40 extends TypeBox.TNever ? [] : [T_40] : never : never : TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TPartial<TypeBox.TPick<T, Optional, T extends TypeBox.TRef<string> ? true : false, Optional extends TypeBox.TRef<string> ? true : false>>, L>, TSchema$1> extends infer T_41 ? T_41 extends TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TPartial<TypeBox.TPick<T, Optional, T extends TypeBox.TRef<string> ? true : false, Optional extends TypeBox.TRef<string> ? true : false>>, L>, TSchema$1> ? T_41 extends TypeBox.TNever ? [T_39] : [T_39, T_41] : never : never : never : never> } : { [_ in L]: TypeBox.TIntersectEvaluated<TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TOmit<T, [...Omit, ...Optional], T extends TypeBox.TRef<string> ? true : false, [...Omit, ...Optional] extends infer T_43 ? T_43 extends [...Omit, ...Optional] ? T_43 extends TypeBox.TRef<string> ? true : false : never : never>, L>, TSchema$1> extends infer T_44 ? T_44 extends TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TOmit<T, [...Omit, ...Optional], T extends TypeBox.TRef<string> ? true : false, [...Omit, ...Optional] extends infer T_47 ? T_47 extends [...Omit, ...Optional] ? T_47 extends TypeBox.TRef<string> ? true : false : never : never>, L>, TSchema$1> ? T_44 extends TypeBox.TNever ? TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TPartial<TypeBox.TPick<T, Optional, T extends TypeBox.TRef<string> ? true : false, Optional extends TypeBox.TRef<string> ? true : false>>, L>, TSchema$1> extends infer T_45 ? T_45 extends TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TPartial<TypeBox.TPick<T, Optional, T extends TypeBox.TRef<string> ? true : false, Optional extends TypeBox.TRef<string> ? true : false>>, L>, TSchema$1> ? T_45 extends TypeBox.TNever ? [] : [T_45] : never : never : TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TPartial<TypeBox.TPick<T, Optional, T extends TypeBox.TRef<string> ? true : false, Optional extends TypeBox.TRef<string> ? true : false>>, L>, TSchema$1> extends infer T_46 ? T_46 extends TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TPartial<TypeBox.TPick<T, Optional, T extends TypeBox.TRef<string> ? true : false, Optional extends TypeBox.TRef<string> ? true : false>>, L>, TSchema$1> ? T_46 extends TypeBox.TNever ? [T_44] : [T_44, T_46] : never : never : never : never> } : { [_ in L]: TypeBox.TIntersectEvaluated<TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TOmit<T, [...Omit, ...Optional], T extends TypeBox.TRef<string> ? true : false, [...Omit, ...Optional] extends infer T_48 ? T_48 extends [...Omit, ...Optional] ? T_48 extends TypeBox.TRef<string> ? true : false : never : never>, L>, TSchema$1> extends infer T_49 ? T_49 extends TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TOmit<T, [...Omit, ...Optional], T extends TypeBox.TRef<string> ? true : false, [...Omit, ...Optional] extends infer T_52 ? T_52 extends [...Omit, ...Optional] ? T_52 extends TypeBox.TRef<string> ? true : false : never : never>, L>, TSchema$1> ? T_49 extends TypeBox.TNever ? TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TPartial<TypeBox.TPick<T, Optional, T extends TypeBox.TRef<string> ? true : false, Optional extends TypeBox.TRef<string> ? true : false>>, L>, TSchema$1> extends infer T_50 ? T_50 extends TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TPartial<TypeBox.TPick<T, Optional, T extends TypeBox.TRef<string> ? true : false, Optional extends TypeBox.TRef<string> ? true : false>>, L>, TSchema$1> ? T_50 extends TypeBox.TNever ? [] : [T_50] : never : never : TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TPartial<TypeBox.TPick<T, Optional, T extends TypeBox.TRef<string> ? true : false, Optional extends TypeBox.TRef<string> ? true : false>>, L>, TSchema$1> extends infer T_51 ? T_51 extends TypeBox.Assert<TypeBox.TIndexFromPropertyKey<TypeBox.TPartial<TypeBox.TPick<T, Optional, T extends TypeBox.TRef<string> ? true : false, Optional extends TypeBox.TRef<string> ? true : false>>, L>, TSchema$1> ? T_51 extends TypeBox.TNever ? [T_49] : [T_49, T_51] : never : never : never : never> } : {} : never : never>>;
|
|
1161
|
-
/**
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
enum
|
|
1168
|
-
/**
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
/**
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
*/
|
|
1189
|
-
datetime: (options?: StringOptions) => TString;
|
|
1190
|
-
/**
|
|
1191
|
-
* Create a schema for a date.
|
|
1192
|
-
*
|
|
1193
|
-
* @param options
|
|
1194
|
-
*/
|
|
1195
|
-
date: (options?: StringOptions) => TString;
|
|
1196
|
-
/**
|
|
1197
|
-
* Create a schema for uuid.
|
|
1198
|
-
*
|
|
1199
|
-
* @param options The options for the duration.
|
|
1200
|
-
*/
|
|
1201
|
-
uuid: (options?: StringOptions) => TString;
|
|
1202
|
-
/**
|
|
1203
|
-
*
|
|
1204
|
-
*
|
|
1205
|
-
* @param kind
|
|
1206
|
-
* @param options
|
|
1207
|
-
*/
|
|
1208
|
-
unsafe: <T>(kind: string, options?: UnsafeOptions) => TUnsafe<T>;
|
|
1209
|
-
file: (options?: {
|
|
1181
|
+
}, options?: ObjectOptions): TComposite<[TOmit<T, [...Omit, ...Optional]>, TPartial<TPick<T, Optional>>]>;
|
|
1182
|
+
/**
|
|
1183
|
+
* Create a schema for a string enum.
|
|
1184
|
+
*
|
|
1185
|
+
* @param values
|
|
1186
|
+
* @param options
|
|
1187
|
+
*/
|
|
1188
|
+
enum<T extends string[]>(values: [...T], options?: StringOptions): TUnsafe<T[number]>;
|
|
1189
|
+
/**
|
|
1190
|
+
* Create a schema for a datetime.
|
|
1191
|
+
*
|
|
1192
|
+
* @param options The options for the date.
|
|
1193
|
+
*/
|
|
1194
|
+
datetime(options?: StringOptions): TString$1;
|
|
1195
|
+
/**
|
|
1196
|
+
* Create a schema for a date.
|
|
1197
|
+
*
|
|
1198
|
+
* @param options
|
|
1199
|
+
*/
|
|
1200
|
+
date(options?: StringOptions): TString$1;
|
|
1201
|
+
/**
|
|
1202
|
+
* Create a schema for uuid.
|
|
1203
|
+
*
|
|
1204
|
+
* @param options The options for the duration.
|
|
1205
|
+
*/
|
|
1206
|
+
uuid(options?: StringOptions): TString$1;
|
|
1207
|
+
unsafe<T>(kind: string, options?: UnsafeOptions): TUnsafe<T>;
|
|
1208
|
+
file(options?: {
|
|
1210
1209
|
max?: number;
|
|
1211
|
-
})
|
|
1212
|
-
stream
|
|
1210
|
+
}): TFile;
|
|
1211
|
+
stream(): TStream;
|
|
1213
1212
|
}
|
|
1213
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
1214
1214
|
interface FileLike {
|
|
1215
1215
|
/**
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1216
|
+
* Filename.
|
|
1217
|
+
* @default "file"
|
|
1218
|
+
*/
|
|
1219
1219
|
name: string;
|
|
1220
1220
|
/**
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1221
|
+
* Mandatory MIME type of the file.
|
|
1222
|
+
* @default "application/octet-stream"
|
|
1223
|
+
*/
|
|
1224
1224
|
type: string;
|
|
1225
1225
|
/**
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1226
|
+
* Size of the file in bytes.
|
|
1227
|
+
*
|
|
1228
|
+
* Always 0 for streams, as the size is not known until the stream is fully read.
|
|
1229
|
+
*
|
|
1230
|
+
* @default 0
|
|
1231
|
+
*/
|
|
1232
1232
|
size: number;
|
|
1233
1233
|
/**
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1234
|
+
* Last modified timestamp in milliseconds since epoch.
|
|
1235
|
+
*
|
|
1236
|
+
* Always the current timestamp for streams, as the last modified time is not known.
|
|
1237
|
+
* We use this field to ensure compatibility with File API.
|
|
1238
|
+
*
|
|
1239
|
+
* @default Date.now()
|
|
1240
|
+
*/
|
|
1241
1241
|
lastModified: number;
|
|
1242
1242
|
/**
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1243
|
+
* Returns a ReadableStream or Node.js Readable stream of the file content.
|
|
1244
|
+
*
|
|
1245
|
+
* For streams, this is the original stream.
|
|
1246
|
+
*/
|
|
1247
1247
|
stream(): StreamLike;
|
|
1248
1248
|
/**
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1249
|
+
* Returns the file content as an ArrayBuffer.
|
|
1250
|
+
*
|
|
1251
|
+
* For streams, this reads the entire stream into memory.
|
|
1252
|
+
*/
|
|
1253
1253
|
arrayBuffer(): Promise<ArrayBuffer>;
|
|
1254
1254
|
/**
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1255
|
+
* Returns the file content as a string.
|
|
1256
|
+
*
|
|
1257
|
+
* For streams, this reads the entire stream into memory and converts it to a string.
|
|
1258
|
+
*/
|
|
1259
1259
|
text(): Promise<string>;
|
|
1260
|
+
// -- node specific fields --
|
|
1260
1261
|
/**
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1262
|
+
* Optional file path, if the file is stored on disk.
|
|
1263
|
+
*
|
|
1264
|
+
* This is not from the File API, but rather a custom field to indicate where the file is stored.
|
|
1265
|
+
*/
|
|
1265
1266
|
filepath?: string;
|
|
1266
1267
|
}
|
|
1267
1268
|
/**
|
|
1268
|
-
|
|
1269
|
-
|
|
1269
|
+
* TypeBox view of FileLike.
|
|
1270
|
+
*/
|
|
1270
1271
|
type TFile = TUnsafe<FileLike>;
|
|
1271
1272
|
declare const isTypeFile: (value: TSchema$1) => value is TFile;
|
|
1272
1273
|
declare const isFileLike: (value: any) => value is FileLike;
|
|
1274
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
1273
1275
|
type StreamLike = ReadableStream | ReadableStream$1 | Readable | NodeJS.ReadableStream;
|
|
1274
1276
|
type TStream = TUnsafe<StreamLike>;
|
|
1275
1277
|
declare const isTypeStream: (value: TSchema$1) => value is TStream;
|
|
1278
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
1276
1279
|
type TextLength = "short" | "long" | "rich";
|
|
1277
1280
|
interface AlephaStringOptions extends StringOptions {
|
|
1278
1281
|
size?: TextLength;
|
|
1279
1282
|
}
|
|
1283
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
1280
1284
|
declare const t: TypeProvider;
|
|
1285
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
1281
1286
|
declare const isUUID: (value: string) => boolean;
|
|
1282
1287
|
//#endregion
|
|
1283
1288
|
//#region src/index.d.ts
|
|
1289
|
+
/**
|
|
1290
|
+
*
|
|
1291
|
+
*/
|
|
1284
1292
|
declare const run: (entry: Alepha | Service | Array<Service>, opts?: RunOptions) => Alepha;
|
|
1285
1293
|
//#endregion
|
|
1286
|
-
export { $cursor, $
|
|
1294
|
+
export { $cursor, $hook, $inject, $injectResolverRegistry, $logger, AbstractService, Alepha, AlephaError, AlephaStringOptions, AlsProvider, AppNotStartedError, Async, AsyncFn, AsyncLocalStorageData, COLORS, CircularDependencyError, ContainerLockedError, CursorDescriptor, Descriptor, DescriptorIdentifier, DescriptorItem, Env, FileLike, Hook, HookDescriptor, HookOptions, Hooks, InstantiableService, KIND, LEVEL_COLORS, LogLevel, Logger, LoggerEnv, LoggerOptions, MaybePromise, MockLogger, MockLoggerStore, Module, ModuleDefinition, NotImplementedError, OPTIONS, PromiseFn, Service, ServiceEntry, ServiceSubstitution, State, Static, StaticDecode, StaticEncode, StreamLike, TAny, TArray, TBoolean, TFile, TNumber, TObject, TOptional, TProperties, TRecord, TSchema, TStream, TString, TextLength, TypeBox, TypeBoxError, TypeBoxValue, TypeGuard, TypeProvider, __alephaRef, __bind, __descriptor, descriptorEvents, isDescriptorValue, isFileLike, isModule, isTypeFile, isTypeStream, isUUID, run, t, toModuleName };
|
|
1287
1295
|
//# sourceMappingURL=index.d.ts.map
|