alepha 0.7.7 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/batch.cjs +8 -0
- package/batch.d.ts +114 -0
- package/batch.js +1 -0
- package/cache/redis.d.ts +15 -18
- package/cache.d.ts +115 -119
- package/command.cjs +8 -0
- package/command.d.ts +154 -0
- package/command.js +1 -0
- package/core.d.ts +798 -794
- package/datetime.d.ts +76 -76
- package/lock/redis.d.ts +12 -12
- package/lock.d.ts +70 -75
- package/package.json +72 -34
- package/postgres.d.ts +202 -156
- package/queue/redis.d.ts +15 -13
- package/queue.d.ts +16 -13
- package/react/auth.d.ts +15 -10
- package/react/head.d.ts +9 -3
- package/react.d.ts +59 -36
- package/redis.d.ts +20 -27
- package/retry.d.ts +74 -54
- package/scheduler.d.ts +14 -12
- package/security.d.ts +38 -28
- package/server/cache.d.ts +7 -5
- package/server/compress.cjs +8 -0
- package/server/compress.d.ts +26 -0
- package/server/compress.js +1 -0
- package/server/cookies.d.ts +68 -14
- package/server/cors.d.ts +7 -3
- package/server/health.d.ts +24 -24
- package/server/helmet.cjs +8 -0
- package/server/helmet.d.ts +72 -0
- package/server/helmet.js +1 -0
- package/server/links.d.ts +79 -88
- package/server/metrics.cjs +8 -0
- package/server/metrics.d.ts +37 -0
- package/server/metrics.js +1 -0
- package/server/multipart.cjs +8 -0
- package/server/multipart.d.ts +48 -0
- package/server/multipart.js +1 -0
- package/server/proxy.d.ts +7 -7
- package/server/static.d.ts +63 -51
- package/server/swagger.d.ts +50 -50
- package/server.d.ts +114 -117
- package/topic/redis.d.ts +24 -23
- package/topic.d.ts +9 -3
- package/vite.d.ts +8 -1
package/core.d.ts
CHANGED
|
@@ -2,102 +2,109 @@ 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";
|
|
81
88
|
interface HookOptions<T extends keyof Hooks> {
|
|
82
89
|
/**
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
90
|
+
* The name of the hook. "configure", "start", "ready", "stop", ...
|
|
91
|
+
*/
|
|
92
|
+
on: T;
|
|
86
93
|
/**
|
|
87
|
-
|
|
88
|
-
|
|
94
|
+
* The handler to run when the hook is triggered.
|
|
95
|
+
*/
|
|
89
96
|
handler: (app: Hooks[T]) => Async<any>;
|
|
90
97
|
/**
|
|
91
|
-
|
|
92
|
-
|
|
98
|
+
* Force the hook to run first or last on the list of hooks.
|
|
99
|
+
*/
|
|
93
100
|
priority?: "first" | "last";
|
|
94
101
|
/**
|
|
95
|
-
|
|
96
|
-
|
|
102
|
+
* Empty placeholder, not working yet. :-)
|
|
103
|
+
*/
|
|
97
104
|
before?: object | Array<object>;
|
|
98
105
|
/**
|
|
99
|
-
|
|
100
|
-
|
|
106
|
+
* Empty placeholder, not working yet. :-)
|
|
107
|
+
*/
|
|
101
108
|
after?: object | Array<object>;
|
|
102
109
|
}
|
|
103
110
|
interface Hook<T extends keyof Hooks = any> {
|
|
@@ -111,44 +118,44 @@ interface HookDescriptor<T extends keyof Hooks> {
|
|
|
111
118
|
(app: Hooks[T]): Async<any>;
|
|
112
119
|
}
|
|
113
120
|
/**
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
121
|
+
* Registers a new hook.
|
|
122
|
+
*
|
|
123
|
+
* ```ts
|
|
124
|
+
* import { $hook } from "alepha";
|
|
125
|
+
*
|
|
126
|
+
* class MyProvider {
|
|
127
|
+
* onStart = $hook({
|
|
128
|
+
* name: "start", // or "configure", "ready", "stop", ...
|
|
129
|
+
* handler: async (app) => {
|
|
130
|
+
* // await db.connect(); ...
|
|
131
|
+
* }
|
|
132
|
+
* });
|
|
133
|
+
* }
|
|
134
|
+
* ```
|
|
135
|
+
*
|
|
136
|
+
* Hooks are used to run async functions from all registered providers/services.
|
|
137
|
+
*
|
|
138
|
+
* You can't register a hook after the App has started.
|
|
139
|
+
*
|
|
140
|
+
* It's used under the hood by the `configure`, `start`, and `stop` methods.
|
|
141
|
+
* Some modules also use hooks to run their own logic. (e.g. `@alepha/server`).
|
|
142
|
+
*
|
|
143
|
+
* You can create your own hooks by using module augmentation:
|
|
144
|
+
*
|
|
145
|
+
* ```ts
|
|
146
|
+
* declare module "alepha" {
|
|
147
|
+
*
|
|
148
|
+
* interface Hooks {
|
|
149
|
+
* "my:custom:hook": {
|
|
150
|
+
* arg1: string;
|
|
151
|
+
* }
|
|
152
|
+
* }
|
|
153
|
+
* }
|
|
154
|
+
*
|
|
155
|
+
* await alepha.emit("my:custom:hook", { arg1: "value" });
|
|
156
|
+
* ```
|
|
157
|
+
*
|
|
158
|
+
*/
|
|
152
159
|
declare const $hook: {
|
|
153
160
|
<T extends keyof Hooks>(options: HookOptions<T>): HookDescriptor<T>;
|
|
154
161
|
[KIND]: string;
|
|
@@ -162,17 +169,19 @@ 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
|
|
177
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
169
178
|
/**
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
179
|
+
* /!\ Global variable /!\
|
|
180
|
+
*
|
|
181
|
+
* Store the current context and definition during injection phase.
|
|
182
|
+
*
|
|
183
|
+
* @internal
|
|
184
|
+
*/
|
|
176
185
|
declare const __alephaRef: {
|
|
177
186
|
context?: Alepha;
|
|
178
187
|
definition?: Service;
|
|
@@ -182,42 +191,44 @@ declare const __alephaRef: {
|
|
|
182
191
|
parent: Service;
|
|
183
192
|
};
|
|
184
193
|
};
|
|
194
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
185
195
|
/**
|
|
186
|
-
|
|
187
|
-
|
|
196
|
+
* Cursor descriptor.
|
|
197
|
+
*/
|
|
188
198
|
interface CursorDescriptor {
|
|
189
199
|
context: Alepha;
|
|
190
200
|
definition?: Service;
|
|
191
201
|
module?: ModuleDefinition;
|
|
192
202
|
}
|
|
193
203
|
/**
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
204
|
+
* Get Alepha instance and Class definition from the current context.
|
|
205
|
+
* This should be used inside a descriptor only.
|
|
206
|
+
*
|
|
207
|
+
* ```ts
|
|
208
|
+
* import { $cursor } from "alepha";
|
|
209
|
+
*
|
|
210
|
+
* const $ = () => {
|
|
211
|
+
*
|
|
212
|
+
* const { context, definition } = $cursor();
|
|
213
|
+
*
|
|
214
|
+
* // context - alepha instance
|
|
215
|
+
* // definition - class which is creating this descriptor
|
|
216
|
+
*
|
|
217
|
+
* return {};
|
|
218
|
+
* }
|
|
219
|
+
*
|
|
220
|
+
* ```
|
|
221
|
+
*
|
|
222
|
+
* @internal
|
|
223
|
+
*/
|
|
214
224
|
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,605 @@ 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
|
|
464
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
447
465
|
interface Env extends LoggerEnv {
|
|
448
466
|
[key: string]: string | boolean | number | undefined;
|
|
449
467
|
/**
|
|
450
|
-
|
|
451
|
-
|
|
468
|
+
* Optional environment variable that indicates the current environment.
|
|
469
|
+
*/
|
|
452
470
|
NODE_ENV?: "dev" | "test" | "production";
|
|
453
471
|
/**
|
|
454
|
-
|
|
455
|
-
|
|
472
|
+
* Optional name of the application.
|
|
473
|
+
*/
|
|
456
474
|
APP_NAME?: string;
|
|
457
475
|
/**
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
476
|
+
* Optional root module name.
|
|
477
|
+
*/
|
|
478
|
+
MODULE_NAME?: string;
|
|
479
|
+
/**
|
|
480
|
+
* If true, the container will not automatically register the default providers based on the descriptors.
|
|
481
|
+
*
|
|
482
|
+
* It means that you have to alepha.with(ServiceModule) manually. No magic.
|
|
483
|
+
*
|
|
484
|
+
* @default false
|
|
485
|
+
*/
|
|
464
486
|
EXPLICIT_PROVIDERS?: boolean;
|
|
465
487
|
}
|
|
488
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
466
489
|
interface State {
|
|
467
490
|
log: Logger;
|
|
468
491
|
env?: Readonly<Env>;
|
|
492
|
+
// test hooks
|
|
469
493
|
beforeAll?: (run: any) => any;
|
|
470
494
|
afterAll?: (run: any) => any;
|
|
471
495
|
afterEach?: (run: any) => any;
|
|
472
496
|
onTestFinished?: (run: any) => any;
|
|
473
497
|
}
|
|
498
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
474
499
|
interface Hooks {
|
|
475
500
|
echo: any;
|
|
476
501
|
/**
|
|
477
|
-
|
|
478
|
-
|
|
502
|
+
* Triggered during the configuration phase. Before the start phase.
|
|
503
|
+
*/
|
|
479
504
|
configure: Alepha;
|
|
480
505
|
/**
|
|
481
|
-
|
|
482
|
-
|
|
506
|
+
* Triggered during the start phase. When `Alepha#start()` is called.
|
|
507
|
+
*/
|
|
483
508
|
start: Alepha;
|
|
484
509
|
/**
|
|
485
|
-
|
|
486
|
-
|
|
510
|
+
* Triggered during the ready phase. After the start phase.
|
|
511
|
+
*/
|
|
487
512
|
ready: Alepha;
|
|
488
513
|
/**
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
514
|
+
* Triggered during the stop phase.
|
|
515
|
+
*
|
|
516
|
+
* - Stop should be called after a SIGINT or SIGTERM signal in order to gracefully shutdown the application. (@see `run()` method)
|
|
517
|
+
*
|
|
518
|
+
*/
|
|
494
519
|
stop: Alepha;
|
|
495
520
|
/**
|
|
496
|
-
|
|
497
|
-
|
|
521
|
+
* Triggered when a state value is mutated.
|
|
522
|
+
*/
|
|
498
523
|
"state:mutate": {
|
|
499
524
|
/**
|
|
500
|
-
|
|
501
|
-
|
|
525
|
+
* The key of the state that was mutated.
|
|
526
|
+
*/
|
|
502
527
|
key: keyof State;
|
|
503
528
|
/**
|
|
504
|
-
|
|
505
|
-
|
|
529
|
+
* The new value of the state.
|
|
530
|
+
*/
|
|
506
531
|
value: any;
|
|
507
532
|
/**
|
|
508
|
-
|
|
509
|
-
|
|
533
|
+
* The previous value of the state.
|
|
534
|
+
*/
|
|
510
535
|
prevValue: any;
|
|
511
536
|
};
|
|
512
537
|
}
|
|
538
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
513
539
|
/**
|
|
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
|
-
|
|
540
|
+
* Core container of the Alepha framework.
|
|
541
|
+
*
|
|
542
|
+
* It is responsible for managing the lifecycle of services,
|
|
543
|
+
* handling dependency injection,
|
|
544
|
+
* and providing a unified interface for the application.
|
|
545
|
+
*
|
|
546
|
+
* @example
|
|
547
|
+
* ```ts
|
|
548
|
+
* import { Alepha, run } from "alepha";
|
|
549
|
+
*
|
|
550
|
+
* class MyService {
|
|
551
|
+
* // business logic here
|
|
552
|
+
* }
|
|
553
|
+
*
|
|
554
|
+
* const alepha = Alepha.create({
|
|
555
|
+
* // state, env, and other properties
|
|
556
|
+
* })
|
|
557
|
+
*
|
|
558
|
+
* alepha.with(MyService);
|
|
559
|
+
*
|
|
560
|
+
* run(alepha); // trigger .start (and .stop) automatically
|
|
561
|
+
* ```
|
|
562
|
+
*
|
|
563
|
+
* > Some alepha methods are not intended to be used directly, use descriptors instead.
|
|
564
|
+
*
|
|
565
|
+
* - $hook -> alepha.on()
|
|
566
|
+
* - $inject -> alepha.get(), alepha.parseEnv()
|
|
567
|
+
*/
|
|
542
568
|
declare class Alepha {
|
|
543
569
|
/**
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
570
|
+
* Creates a new instance of the Alepha container with some helpers:
|
|
571
|
+
*
|
|
572
|
+
* - merges `process.env` with the provided state.env when available.
|
|
573
|
+
* - populates the test hooks for Vitest or Jest environments when available.
|
|
574
|
+
*
|
|
575
|
+
* If you are not interested about these helpers, you can use the constructor directly.
|
|
576
|
+
*/
|
|
551
577
|
static create(state?: Partial<State>): Alepha;
|
|
552
578
|
/**
|
|
553
|
-
|
|
554
|
-
|
|
579
|
+
* List of all services + how they are provided.
|
|
580
|
+
*/
|
|
555
581
|
protected registry: Map<Service, ServiceDefinition>;
|
|
556
582
|
/**
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
583
|
+
* Flag indicating whether the App won't accept any further changes.
|
|
584
|
+
* Pass to true when #start() is called.
|
|
585
|
+
*/
|
|
560
586
|
protected locked: boolean;
|
|
561
587
|
/**
|
|
562
|
-
|
|
563
|
-
|
|
588
|
+
* True if the App has been configured.
|
|
589
|
+
*/
|
|
564
590
|
protected configured: boolean;
|
|
565
591
|
/**
|
|
566
|
-
|
|
567
|
-
|
|
592
|
+
* True if the App has started.
|
|
593
|
+
*/
|
|
568
594
|
protected started: boolean;
|
|
569
595
|
/**
|
|
570
|
-
|
|
571
|
-
|
|
596
|
+
* True if the App is ready.
|
|
597
|
+
*/
|
|
572
598
|
protected ready: boolean;
|
|
573
599
|
/**
|
|
574
|
-
|
|
575
|
-
|
|
600
|
+
* A promise that resolves when the App has started.
|
|
601
|
+
*/
|
|
576
602
|
protected starting?: PromiseWithResolvers<this>;
|
|
577
603
|
/**
|
|
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
|
-
|
|
604
|
+
* The current state of the App.
|
|
605
|
+
*
|
|
606
|
+
* It contains the environment variables, logger, and other state-related properties.
|
|
607
|
+
*
|
|
608
|
+
* You can declare your own state properties by extending the `State` interface.
|
|
609
|
+
*
|
|
610
|
+
* ```ts
|
|
611
|
+
* declare module "alepha" {
|
|
612
|
+
* interface State {
|
|
613
|
+
* myCustomValue: string;
|
|
614
|
+
* }
|
|
615
|
+
* }
|
|
616
|
+
* ```
|
|
617
|
+
*
|
|
618
|
+
* Same story for the `Env` interface.
|
|
619
|
+
* ```ts
|
|
620
|
+
* declare module "alepha" {
|
|
621
|
+
* interface Env {
|
|
622
|
+
* readonly myCustomValue: string;
|
|
623
|
+
* }
|
|
624
|
+
* }
|
|
625
|
+
* ```
|
|
626
|
+
*
|
|
627
|
+
* State values can be function or primitive values.
|
|
628
|
+
* However, all .env variables must serializable to JSON.
|
|
629
|
+
*/
|
|
604
630
|
protected store: State;
|
|
605
631
|
/**
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
632
|
+
* During the instantiation process, we keep a list of pending instantiations.
|
|
633
|
+
* > It allows us to detect circular dependencies.
|
|
634
|
+
*/
|
|
609
635
|
protected pendingInstantiations: Service[];
|
|
610
636
|
/**
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
637
|
+
* Cache for environment variables.
|
|
638
|
+
* > It allows us to avoid parsing the same schema multiple times.
|
|
639
|
+
*/
|
|
614
640
|
protected cacheEnv: Map<TSchema$1, any>;
|
|
615
641
|
/**
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
642
|
+
* Cache for TypeBox type checks.
|
|
643
|
+
* > It allows us to avoid compiling the same schema multiple times.
|
|
644
|
+
*/
|
|
619
645
|
protected cacheTypeCheck: Map<TSchema$1, TypeCheck<TSchema$1>>;
|
|
620
646
|
/**
|
|
621
|
-
|
|
622
|
-
|
|
647
|
+
* List of events that can be triggered. Powered by $hook().
|
|
648
|
+
*/
|
|
623
649
|
protected events: Record<string, Array<Hook>>;
|
|
624
650
|
/**
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
651
|
+
* List of modules that are registered in the container.
|
|
652
|
+
*
|
|
653
|
+
* Modules are used to group services and provide a way to register them in the container.
|
|
654
|
+
*/
|
|
629
655
|
protected modules: Array<ModuleDefinition>;
|
|
630
656
|
/**
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
readonly context:
|
|
657
|
+
* Node.js feature that allows to store context across asynchronous calls.
|
|
658
|
+
*
|
|
659
|
+
* This is used for logging, tracing, and other context-related features.
|
|
660
|
+
*
|
|
661
|
+
* Mocked for browser environments.
|
|
662
|
+
*/
|
|
663
|
+
readonly context: AlsProvider;
|
|
638
664
|
/**
|
|
639
|
-
|
|
640
|
-
|
|
665
|
+
* Get logger instance.
|
|
666
|
+
*/
|
|
641
667
|
get log(): Logger;
|
|
642
668
|
/**
|
|
643
|
-
|
|
644
|
-
|
|
669
|
+
* The environment variables for the App.
|
|
670
|
+
*/
|
|
645
671
|
get env(): Readonly<Env>;
|
|
646
672
|
constructor(state?: Partial<State>);
|
|
647
673
|
/**
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
*/
|
|
651
|
-
handle?: (req: any, res: any) => Promise<any>;
|
|
652
|
-
/**
|
|
653
|
-
* State accessor and mutator.
|
|
654
|
-
*/
|
|
674
|
+
* State accessor and mutator.
|
|
675
|
+
*/
|
|
655
676
|
state<Key extends keyof State>(key: Key, value?: State[Key]): State[Key];
|
|
677
|
+
// -------------------------------------------------------------------------------------------------------------------
|
|
656
678
|
/**
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
679
|
+
* True when start() is called.
|
|
680
|
+
*
|
|
681
|
+
* -> No more services can be added, it's over, bye!
|
|
682
|
+
*/
|
|
661
683
|
isLocked(): boolean;
|
|
662
684
|
/**
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
685
|
+
* Returns whether the App is configured.
|
|
686
|
+
*
|
|
687
|
+
* It means that Alepha#configure() has been called.
|
|
688
|
+
*
|
|
689
|
+
* > By default, configure() is called automatically when start() is called, but you can also call it manually.
|
|
690
|
+
*/
|
|
669
691
|
isConfigured(): boolean;
|
|
670
692
|
/**
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
693
|
+
* Returns whether the App has started.
|
|
694
|
+
*
|
|
695
|
+
* It means that #start() has been called but maybe not all services are ready.
|
|
696
|
+
*/
|
|
675
697
|
isStarted(): boolean;
|
|
676
698
|
/**
|
|
677
|
-
|
|
678
|
-
|
|
699
|
+
* True if the App is ready. It means that Alepha is started AND ready() hook has beed called.
|
|
700
|
+
*/
|
|
679
701
|
isReady(): boolean;
|
|
680
702
|
/**
|
|
681
|
-
|
|
682
|
-
|
|
703
|
+
* True if the App is running in a browser environment.
|
|
704
|
+
*/
|
|
683
705
|
isBrowser(): boolean;
|
|
684
706
|
/**
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
707
|
+
* Returns whether the App is running in a serverless environment.
|
|
708
|
+
*
|
|
709
|
+
* > Vite developer mode is also considered serverless.
|
|
710
|
+
*/
|
|
689
711
|
isServerless(): boolean | "vite" | "vercel";
|
|
690
712
|
/**
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
713
|
+
* Returns whether the App is in test mode. (Running in a test environment)
|
|
714
|
+
*
|
|
715
|
+
* > This is automatically set when running tests with Jest or Vitest.
|
|
716
|
+
*/
|
|
695
717
|
isTest(): boolean;
|
|
696
718
|
/**
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
719
|
+
* Returns whether the App is in production mode. (Running in a production environment)
|
|
720
|
+
*
|
|
721
|
+
* > This is automatically set by Vite or Vercel. However, you have to set it manually when running Docker apps.
|
|
722
|
+
*/
|
|
701
723
|
isProduction(): boolean;
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
724
|
+
// -------------------------------------------------------------------------------------------------------------------
|
|
725
|
+
/**
|
|
726
|
+
* Starts the App.
|
|
727
|
+
*
|
|
728
|
+
* - Lock any further changes to the container.
|
|
729
|
+
* - Run "configure" hook for all services. Descriptors will be processed.
|
|
730
|
+
* - Run "start" hook for all services. Providers will connect/listen/...
|
|
731
|
+
* - Run "ready" hook for all services. This is the point where the App is ready to serve requests.
|
|
732
|
+
*
|
|
733
|
+
* @return A promise that resolves when the App has started.
|
|
734
|
+
*/
|
|
712
735
|
start(): Promise<this>;
|
|
713
736
|
/**
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
737
|
+
* Stops the App.
|
|
738
|
+
*
|
|
739
|
+
* - Run "stop" hook for all services.
|
|
740
|
+
*
|
|
741
|
+
* Stop will NOT reset the container.
|
|
742
|
+
* Stop will NOT unlock the container.
|
|
743
|
+
*
|
|
744
|
+
* > Stop is used to gracefully shut down the application, nothing more. There is no "restart".
|
|
745
|
+
*
|
|
746
|
+
* @return A promise that resolves when the App has stopped.
|
|
747
|
+
*/
|
|
725
748
|
stop(): Promise<void>;
|
|
749
|
+
// -------------------------------------------------------------------------------------------------------------------
|
|
726
750
|
/**
|
|
727
|
-
|
|
728
|
-
|
|
751
|
+
* Check if entry is registered in the container.
|
|
752
|
+
*/
|
|
729
753
|
has(entry: ServiceEntry, opts?: {
|
|
730
754
|
/**
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
755
|
+
* Check if the entry is registered in the pending instantiation stack.
|
|
756
|
+
*
|
|
757
|
+
* Default: true
|
|
758
|
+
*/
|
|
735
759
|
inStack?: boolean;
|
|
736
760
|
/**
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
761
|
+
* Check if the entry is registered in the container registry.
|
|
762
|
+
*
|
|
763
|
+
* Default: true
|
|
764
|
+
*/
|
|
741
765
|
inRegistry?: boolean;
|
|
742
766
|
}): boolean;
|
|
743
767
|
/**
|
|
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
|
-
|
|
768
|
+
* Registers the specified service in the container.
|
|
769
|
+
*
|
|
770
|
+
* - If the service is ALREADY registered, the method does nothing.
|
|
771
|
+
* - If the service is NOT registered, a new instance is created and registered.
|
|
772
|
+
*
|
|
773
|
+
* Method is chainable, so you can register multiple services in a single call.
|
|
774
|
+
*
|
|
775
|
+
* > ServiceEntry allows to provide a service **substitution** feature.
|
|
776
|
+
*
|
|
777
|
+
* @example
|
|
778
|
+
* ```ts
|
|
779
|
+
* class A { value = "a"; }
|
|
780
|
+
* class B { value = "b"; }
|
|
781
|
+
* class M { a = $inject(A); }
|
|
782
|
+
*
|
|
783
|
+
* Alepha.create().with({ provide: A, use: B }).get(M).a.value; // "b"
|
|
784
|
+
* ```
|
|
785
|
+
*
|
|
786
|
+
* > **Substitution** is an advanced feature that allows you to replace a service with another service.
|
|
787
|
+
* > It's useful for testing or for providing different implementations of a service.
|
|
788
|
+
* > If you are interested in configuring a service, use Alepha#configure() instead.
|
|
789
|
+
*
|
|
790
|
+
* @param entry - The service to register in the container.
|
|
791
|
+
* @return Current instance of Alepha.
|
|
792
|
+
*/
|
|
769
793
|
with<T extends object>(entry: ServiceEntry<T>): this;
|
|
770
794
|
/**
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
795
|
+
* Get the instance of the specified service and apply some changes, depending on the options.
|
|
796
|
+
* - If the service is already registered, it will return the existing instance. (except if `skipCache` is true)
|
|
797
|
+
* - If the service is not registered, it will create a new instance and register it. (except if `skipRegistration` is true)
|
|
798
|
+
* - New instance can be created with custom constructor arguments. (`args` option)
|
|
799
|
+
*
|
|
800
|
+
* > This method is used by $inject() under the hood.
|
|
801
|
+
*
|
|
802
|
+
* @return The instance of the specified class or type.
|
|
803
|
+
*/
|
|
780
804
|
get<T extends object>(serviceEntry: ServiceEntry<T>, opts?: {
|
|
781
805
|
/**
|
|
782
|
-
|
|
783
|
-
|
|
806
|
+
* Ignore current existing instance.
|
|
807
|
+
*/
|
|
784
808
|
skipCache?: boolean;
|
|
785
809
|
/**
|
|
786
|
-
|
|
787
|
-
|
|
810
|
+
* Don't store the instance in the registry.
|
|
811
|
+
*/
|
|
788
812
|
skipRegistration?: boolean;
|
|
789
813
|
/**
|
|
790
|
-
|
|
791
|
-
|
|
814
|
+
* Constructor arguments to pass when creating a new instance.
|
|
815
|
+
*/
|
|
792
816
|
args?: ConstructorParameters<InstantiableService<T>>;
|
|
793
817
|
/**
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
818
|
+
* Parent service that requested the instance.
|
|
819
|
+
* @internal
|
|
820
|
+
*/
|
|
797
821
|
parent?: Service | null;
|
|
798
822
|
/**
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
823
|
+
* If the service is provided by a module, the module definition.
|
|
824
|
+
* @internal
|
|
825
|
+
*/
|
|
802
826
|
module?: ModuleDefinition;
|
|
803
827
|
}): T;
|
|
804
828
|
/**
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
configure<T extends
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
829
|
+
* Configures the specified service with the provided state.
|
|
830
|
+
* If service is not registered, it will do nothing.
|
|
831
|
+
*
|
|
832
|
+
* It's recommended to use this method on the `configure` hook.
|
|
833
|
+
* @example
|
|
834
|
+
* ```ts
|
|
835
|
+
* class AppConfig {
|
|
836
|
+
* configure = $hook({
|
|
837
|
+
* name: "configure",
|
|
838
|
+
* handler: (a) => {
|
|
839
|
+
* a.configure(MyProvider, { some: "data" });
|
|
840
|
+
* }
|
|
841
|
+
* })
|
|
842
|
+
* }
|
|
843
|
+
* ```
|
|
844
|
+
*/
|
|
845
|
+
configure<T extends {
|
|
846
|
+
options: object;
|
|
847
|
+
}>(service: Service<T>, state: Partial<T["options"]>): this;
|
|
848
|
+
// -------------------------------------------------------------------------------------------------------------------
|
|
849
|
+
/**
|
|
850
|
+
* Registers a hook for the specified event.
|
|
851
|
+
*/
|
|
825
852
|
on<T extends keyof Hooks>(event: T, hookOrFunc: Hook<T> | ((payload: Hooks[T]) => Async<void>)): () => void;
|
|
826
853
|
/**
|
|
827
|
-
|
|
828
|
-
|
|
854
|
+
* Emits the specified event with the given payload.
|
|
855
|
+
*/
|
|
829
856
|
emit<T extends keyof Hooks>(func: keyof Hooks, payload: Hooks[T], options?: {
|
|
830
857
|
/**
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
858
|
+
* If true, the hooks will be executed in reverse order.
|
|
859
|
+
* This is useful for "stop" hooks that should be executed in reverse order.
|
|
860
|
+
*
|
|
861
|
+
* @default false
|
|
862
|
+
*/
|
|
836
863
|
reverse?: boolean;
|
|
837
864
|
/**
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
865
|
+
* If true, the hooks will be logged with their execution time.
|
|
866
|
+
*
|
|
867
|
+
* @default false
|
|
868
|
+
*/
|
|
842
869
|
log?: boolean;
|
|
843
870
|
/**
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
871
|
+
* If true, errors will be caught and logged instead of throwing.
|
|
872
|
+
*
|
|
873
|
+
* @default false
|
|
874
|
+
*/
|
|
848
875
|
catch?: boolean;
|
|
849
876
|
}): Promise<void>;
|
|
877
|
+
// -------------------------------------------------------------------------------------------------------------------
|
|
850
878
|
/**
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
879
|
+
* Casts the given value to the specified schema.
|
|
880
|
+
*
|
|
881
|
+
* It uses the TypeBox library to validate the value against the schema.
|
|
882
|
+
*/
|
|
855
883
|
parse<T extends TSchema$1>(schema: T, value?: any, opts?: {
|
|
856
884
|
/**
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
885
|
+
* Clone the value before parsing.
|
|
886
|
+
* @default true
|
|
887
|
+
*/
|
|
860
888
|
clone?: boolean;
|
|
861
889
|
/**
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
890
|
+
* Apply default values defined in the schema.
|
|
891
|
+
* @default true
|
|
892
|
+
*/
|
|
865
893
|
default?: boolean;
|
|
866
894
|
/**
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
895
|
+
* Remove all values not defined in the schema.
|
|
896
|
+
* @default true
|
|
897
|
+
*/
|
|
870
898
|
clean?: boolean;
|
|
871
899
|
/**
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
900
|
+
* Try to cast/convert some data based on the schema.
|
|
901
|
+
* @default true
|
|
902
|
+
*/
|
|
875
903
|
convert?: boolean;
|
|
876
904
|
/**
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
905
|
+
* Prepare value after being deserialized.
|
|
906
|
+
* @default true
|
|
907
|
+
*/
|
|
880
908
|
check?: boolean;
|
|
881
909
|
}): Static$1<T>;
|
|
882
910
|
/**
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
911
|
+
* Applies environment variables to the provided schema and state object.
|
|
912
|
+
*
|
|
913
|
+
* It replaces also all templated $ENV inside string values.
|
|
914
|
+
*
|
|
915
|
+
* @param schema - The schema object to apply environment variables to.
|
|
916
|
+
* @return The schema object with environment variables applied.
|
|
917
|
+
*/
|
|
890
918
|
parseEnv<T extends TObject$1>(schema: T): Static$1<T>;
|
|
919
|
+
// -------------------------------------------------------------------------------------------------------------------
|
|
891
920
|
/**
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
921
|
+
* Dump the current dependency graph of the App.
|
|
922
|
+
*
|
|
923
|
+
* This method returns a record where the keys are the names of the services.
|
|
924
|
+
*/
|
|
896
925
|
graph(): Record<string, {
|
|
897
926
|
from: string[];
|
|
898
927
|
as?: string;
|
|
899
928
|
module?: string;
|
|
900
929
|
}>;
|
|
930
|
+
// -------------------------------------------------------------------------------------------------------------------
|
|
901
931
|
/**
|
|
902
|
-
|
|
903
|
-
|
|
932
|
+
* @internal
|
|
933
|
+
*/
|
|
904
934
|
getDescriptorValues<T extends Descriptor>(descriptor: T): Array<DescriptorItem<T>>;
|
|
905
935
|
/**
|
|
906
|
-
|
|
907
|
-
|
|
936
|
+
* @internal
|
|
937
|
+
*/
|
|
908
938
|
protected new<T extends object>(definition: Service<T>, args?: any[], module?: ModuleDefinition): T;
|
|
909
939
|
/**
|
|
910
|
-
|
|
911
|
-
|
|
940
|
+
* @internal
|
|
941
|
+
*/
|
|
912
942
|
protected createLogger(env: Env): Logger;
|
|
913
|
-
/**
|
|
914
|
-
* @internal
|
|
915
|
-
*/
|
|
916
943
|
getModuleOf(service: Service): Module | undefined;
|
|
917
944
|
}
|
|
945
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
918
946
|
/**
|
|
919
|
-
|
|
920
|
-
|
|
947
|
+
* This is how we store services in the Alepha container.
|
|
948
|
+
*/
|
|
921
949
|
interface ServiceDefinition<T extends object = any> {
|
|
922
950
|
/**
|
|
923
|
-
|
|
924
|
-
|
|
951
|
+
* The class or type definition to provide.
|
|
952
|
+
*/
|
|
925
953
|
provide: Service<T>;
|
|
926
954
|
/**
|
|
927
|
-
|
|
928
|
-
|
|
955
|
+
* The class or type definition to use. This will override the 'provide' property.
|
|
956
|
+
*/
|
|
929
957
|
use?: Service<T>;
|
|
930
958
|
/**
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
959
|
+
* The instance of the class or type definition.
|
|
960
|
+
* Mostly used for caching / singleton but can be used for other purposes like forcing the instance.
|
|
961
|
+
*/
|
|
934
962
|
instance: T;
|
|
935
963
|
/**
|
|
936
|
-
|
|
937
|
-
|
|
964
|
+
* List of classes which use this class.
|
|
965
|
+
*/
|
|
938
966
|
parents: Array<Service | null>;
|
|
939
967
|
/**
|
|
940
|
-
|
|
941
|
-
|
|
968
|
+
* If the service is provided by a module, the module definition.
|
|
969
|
+
*/
|
|
942
970
|
module?: ModuleDefinition;
|
|
943
971
|
}
|
|
944
972
|
//#endregion
|
|
945
973
|
//#region src/interfaces/Run.d.ts
|
|
946
974
|
interface RunOptions {
|
|
947
975
|
/**
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
976
|
+
* Environment variables to be used by the application.
|
|
977
|
+
* If not provided, it will use the current process environment.
|
|
978
|
+
*/
|
|
951
979
|
env?: Env;
|
|
952
980
|
/**
|
|
953
|
-
|
|
954
|
-
|
|
981
|
+
* A callback that will be executed before the application starts.
|
|
982
|
+
*/
|
|
955
983
|
configure?: (alepha: Alepha) => Async<void>;
|
|
956
984
|
/**
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
985
|
+
* A callback that will be executed once the application is ready.
|
|
986
|
+
* This is useful for initializing resources or starting background tasks.
|
|
987
|
+
*/
|
|
960
988
|
ready?: (alepha: Alepha) => Async<void>;
|
|
961
989
|
/**
|
|
962
|
-
|
|
963
|
-
|
|
990
|
+
* If true, the application will stop after the ready callback is executed.
|
|
991
|
+
*/
|
|
964
992
|
once?: boolean;
|
|
965
993
|
}
|
|
966
994
|
//#endregion
|
|
967
995
|
//#region src/descriptors/$inject.d.ts
|
|
968
996
|
/**
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
997
|
+
* Get the instance of the specified type from the context.
|
|
998
|
+
*
|
|
999
|
+
* - If the type is a class, it will be resolved from the context.
|
|
1000
|
+
* - If the type is a schema, it will be parsed from the environment.
|
|
1001
|
+
*
|
|
1002
|
+
* ```ts
|
|
1003
|
+
* class A { }
|
|
1004
|
+
* class B {
|
|
1005
|
+
* a = $inject(A);
|
|
1006
|
+
* }
|
|
1007
|
+
* ```
|
|
1008
|
+
*
|
|
1009
|
+
* @param type - Type (or TypeBox schema) to resolve
|
|
1010
|
+
* @returns Instance of the specified type
|
|
1011
|
+
*/
|
|
984
1012
|
declare function $inject<T extends TObject$1>(type: T): Static$1<T>;
|
|
985
1013
|
declare function $inject<T extends object>(type: Service<T>): T;
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
1014
|
+
declare class InjectResolverRegistry {
|
|
1015
|
+
resolvers: Array<(it: any) => any>;
|
|
1016
|
+
register(fn: (it: any) => any): void;
|
|
1017
|
+
resolve(it: any): any;
|
|
1018
|
+
}
|
|
1019
|
+
declare const $injectResolverRegistry: InjectResolverRegistry;
|
|
990
1020
|
//#endregion
|
|
991
1021
|
//#region src/descriptors/$logger.d.ts
|
|
1022
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
992
1023
|
/**
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1024
|
+
* Create a logger.
|
|
1025
|
+
*
|
|
1026
|
+
* `name` is optional, by default it will use the name of the service.
|
|
1027
|
+
*
|
|
1028
|
+
* @example
|
|
1029
|
+
* ```ts
|
|
1030
|
+
* import { $logger } from "alepha";
|
|
1031
|
+
*
|
|
1032
|
+
* class MyService {
|
|
1033
|
+
* log = $logger();
|
|
1034
|
+
*
|
|
1035
|
+
* constructor() {
|
|
1036
|
+
* // print something like 'date - [MyService] Service initialized'
|
|
1037
|
+
* this.log.info("Service initialized");
|
|
1038
|
+
* }
|
|
1039
|
+
* }
|
|
1040
|
+
* ```
|
|
1041
|
+
*/
|
|
1011
1042
|
declare const $logger: (name?: string) => Logger;
|
|
1012
1043
|
//#endregion
|
|
1013
1044
|
//#region src/errors/AlephaError.d.ts
|
|
1045
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
1014
1046
|
/**
|
|
1015
|
-
|
|
1016
|
-
|
|
1047
|
+
* Default error class for Alepha.
|
|
1048
|
+
*/
|
|
1017
1049
|
declare class AlephaError extends Error {}
|
|
1018
1050
|
//#endregion
|
|
1019
1051
|
//#region src/errors/AppNotStartedError.d.ts
|
|
@@ -1043,245 +1075,217 @@ declare class TypeBoxError extends Error {
|
|
|
1043
1075
|
}
|
|
1044
1076
|
//#endregion
|
|
1045
1077
|
//#region src/providers/TypeProvider.d.ts
|
|
1078
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
1046
1079
|
declare class TypeProvider {
|
|
1047
1080
|
static DEFAULT_STRING_MAX_LENGTH: number;
|
|
1048
1081
|
static DEFAULT_LONG_STRING_MAX_LENGTH: number;
|
|
1049
1082
|
static DEFAULT_RICH_STRING_MAX_LENGTH: number;
|
|
1050
1083
|
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: {
|
|
1084
|
+
static FormatRegistry: typeof FormatRegistry;
|
|
1085
|
+
raw: typeof Type;
|
|
1086
|
+
any(options?: SchemaOptions): TAny$1;
|
|
1087
|
+
void(options?: SchemaOptions): TVoid;
|
|
1088
|
+
undefined(options?: SchemaOptions): TUndefined;
|
|
1089
|
+
record<Key extends TSchema$1, Value extends TSchema$1>(key: Key, value: Value, options?: ObjectOptions): TRecordOrObject<Key, Value>;
|
|
1090
|
+
omit<Type extends TSchema$1, Key extends TSchema$1>(type: Type, key: Key, options?: SchemaOptions): TOmit<Type, Key>;
|
|
1091
|
+
partial<MappedResult extends TMappedResult>(type: MappedResult, options?: SchemaOptions): TPartialFromMappedResult<MappedResult>;
|
|
1092
|
+
union<Types extends TSchema$1[]>(types: [...Types], options?: SchemaOptions): Union<Types>;
|
|
1093
|
+
composite<T extends TSchema$1[]>(schemas: [...T], options?: ObjectOptions): TComposite<T>;
|
|
1094
|
+
pick<Type extends TSchema$1, Key extends PropertyKey[]>(type: Type, key: readonly [...Key], options?: SchemaOptions): TPick<Type, Key>;
|
|
1095
|
+
/**
|
|
1096
|
+
* Create a schema for an object.
|
|
1097
|
+
*
|
|
1098
|
+
* @param properties The properties of the object.
|
|
1099
|
+
* @param options The options for the object.
|
|
1100
|
+
*/
|
|
1101
|
+
object<T extends TProperties$1>(properties: T, options?: ObjectOptions): TObject$1<T>;
|
|
1102
|
+
/**
|
|
1103
|
+
* Create a schema for an array.
|
|
1104
|
+
*
|
|
1105
|
+
* @param schema
|
|
1106
|
+
* @param options
|
|
1107
|
+
*/
|
|
1108
|
+
array<T extends TSchema$1>(schema: T, options?: ArrayOptions): TArray$1<T>;
|
|
1109
|
+
/**
|
|
1110
|
+
* Create a schema for a string.
|
|
1111
|
+
*
|
|
1112
|
+
* @param options
|
|
1113
|
+
*/
|
|
1114
|
+
string(options?: AlephaStringOptions): TString$1;
|
|
1115
|
+
/**
|
|
1116
|
+
* Create a schema for a JSON object.
|
|
1117
|
+
*
|
|
1118
|
+
* @param options
|
|
1119
|
+
*/
|
|
1120
|
+
json(options?: SchemaOptions): TRecord$1<TString$1, TAny$1>;
|
|
1121
|
+
/**
|
|
1122
|
+
* Create a schema for a boolean.
|
|
1123
|
+
*
|
|
1124
|
+
* @param options
|
|
1125
|
+
*/
|
|
1126
|
+
boolean(options?: SchemaOptions): TBoolean$1;
|
|
1127
|
+
/**
|
|
1128
|
+
* Create a schema for a number.
|
|
1129
|
+
*
|
|
1130
|
+
* @param options
|
|
1131
|
+
*/
|
|
1132
|
+
number(options?: NumberOptions): TNumber$1;
|
|
1133
|
+
/**
|
|
1134
|
+
* Create a schema for an unsigned 8-bit integer.
|
|
1135
|
+
*
|
|
1136
|
+
* @param options
|
|
1137
|
+
*/
|
|
1138
|
+
uchar(options?: IntegerOptions): TInteger;
|
|
1139
|
+
/**
|
|
1140
|
+
* Create a schema for an unsigned 32-bit integer.
|
|
1141
|
+
*/
|
|
1142
|
+
uint(options?: IntegerOptions): TNumber$1;
|
|
1143
|
+
/**
|
|
1144
|
+
* Create a schema for a signed 32-bit integer.
|
|
1145
|
+
*/
|
|
1146
|
+
int(options?: IntegerOptions): TInteger;
|
|
1147
|
+
/**
|
|
1148
|
+
* Create a schema for a signed 32-bit integer.
|
|
1149
|
+
*/
|
|
1150
|
+
integer(options?: IntegerOptions): TInteger;
|
|
1151
|
+
/**
|
|
1152
|
+
* Create a schema for a bigint. Bigint is a 64-bit integer.
|
|
1153
|
+
* This is a workaround for TypeBox, which does not support bigint natively.
|
|
1154
|
+
*/
|
|
1155
|
+
bigint(options?: IntegerOptions): TNumber$1;
|
|
1156
|
+
/**
|
|
1157
|
+
* Make a schema optional.
|
|
1158
|
+
*
|
|
1159
|
+
* @param schema The schema to make optional.
|
|
1160
|
+
*/
|
|
1161
|
+
optional<T extends TSchema$1>(schema: T): TOptionalWithFlag<T, true>;
|
|
1162
|
+
/**
|
|
1163
|
+
* Make a schema nullable.
|
|
1164
|
+
*
|
|
1165
|
+
* @param schema The schema to make nullable.
|
|
1166
|
+
* @param options The options for the schema.
|
|
1167
|
+
*/
|
|
1168
|
+
nullable<T extends TSchema$1>(schema: T, options?: ObjectOptions): TUnion<[TNull, T]>;
|
|
1169
|
+
/**
|
|
1170
|
+
* Map a schema to another schema.
|
|
1171
|
+
*
|
|
1172
|
+
* @param schema The schema to map.
|
|
1173
|
+
* @param operations The operations to perform on the schema.
|
|
1174
|
+
* @param options The options for the schema.
|
|
1175
|
+
* @returns The mapped schema.
|
|
1176
|
+
*/
|
|
1177
|
+
map<T extends TObject$1 | TIntersect, Omit extends (keyof T["properties"])[], Optional extends (keyof T["properties"])[]>(schema: T, operations: {
|
|
1158
1178
|
omit: readonly [...Omit];
|
|
1159
1179
|
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?: {
|
|
1180
|
+
}, options?: ObjectOptions): TComposite<[TOmit<T, [...Omit, ...Optional]>, TPartial<TPick<T, Optional>>]>;
|
|
1181
|
+
/**
|
|
1182
|
+
* Create a schema for a string enum.
|
|
1183
|
+
*
|
|
1184
|
+
* @param values
|
|
1185
|
+
* @param options
|
|
1186
|
+
*/
|
|
1187
|
+
enum<T extends string[]>(values: [...T], options?: StringOptions): TUnsafe<T[number]>;
|
|
1188
|
+
/**
|
|
1189
|
+
* Create a schema for a datetime.
|
|
1190
|
+
*
|
|
1191
|
+
* @param options The options for the date.
|
|
1192
|
+
*/
|
|
1193
|
+
datetime(options?: StringOptions): TString$1;
|
|
1194
|
+
/**
|
|
1195
|
+
* Create a schema for a date.
|
|
1196
|
+
*
|
|
1197
|
+
* @param options
|
|
1198
|
+
*/
|
|
1199
|
+
date(options?: StringOptions): TString$1;
|
|
1200
|
+
/**
|
|
1201
|
+
* Create a schema for uuid.
|
|
1202
|
+
*
|
|
1203
|
+
* @param options The options for the duration.
|
|
1204
|
+
*/
|
|
1205
|
+
uuid(options?: StringOptions): TString$1;
|
|
1206
|
+
unsafe<T>(kind: string, options?: UnsafeOptions): TUnsafe<T>;
|
|
1207
|
+
file(options?: {
|
|
1210
1208
|
max?: number;
|
|
1211
|
-
})
|
|
1212
|
-
stream
|
|
1209
|
+
}): TFile;
|
|
1210
|
+
stream(): TStream;
|
|
1213
1211
|
}
|
|
1212
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
1214
1213
|
interface FileLike {
|
|
1215
1214
|
/**
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1215
|
+
* Filename.
|
|
1216
|
+
* @default "file"
|
|
1217
|
+
*/
|
|
1219
1218
|
name: string;
|
|
1220
1219
|
/**
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1220
|
+
* Mandatory MIME type of the file.
|
|
1221
|
+
* @default "application/octet-stream"
|
|
1222
|
+
*/
|
|
1224
1223
|
type: string;
|
|
1225
1224
|
/**
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1225
|
+
* Size of the file in bytes.
|
|
1226
|
+
*
|
|
1227
|
+
* Always 0 for streams, as the size is not known until the stream is fully read.
|
|
1228
|
+
*
|
|
1229
|
+
* @default 0
|
|
1230
|
+
*/
|
|
1232
1231
|
size: number;
|
|
1233
1232
|
/**
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1233
|
+
* Last modified timestamp in milliseconds since epoch.
|
|
1234
|
+
*
|
|
1235
|
+
* Always the current timestamp for streams, as the last modified time is not known.
|
|
1236
|
+
* We use this field to ensure compatibility with File API.
|
|
1237
|
+
*
|
|
1238
|
+
* @default Date.now()
|
|
1239
|
+
*/
|
|
1241
1240
|
lastModified: number;
|
|
1242
1241
|
/**
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1242
|
+
* Returns a ReadableStream or Node.js Readable stream of the file content.
|
|
1243
|
+
*
|
|
1244
|
+
* For streams, this is the original stream.
|
|
1245
|
+
*/
|
|
1247
1246
|
stream(): StreamLike;
|
|
1248
1247
|
/**
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1248
|
+
* Returns the file content as an ArrayBuffer.
|
|
1249
|
+
*
|
|
1250
|
+
* For streams, this reads the entire stream into memory.
|
|
1251
|
+
*/
|
|
1253
1252
|
arrayBuffer(): Promise<ArrayBuffer>;
|
|
1254
1253
|
/**
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1254
|
+
* Returns the file content as a string.
|
|
1255
|
+
*
|
|
1256
|
+
* For streams, this reads the entire stream into memory and converts it to a string.
|
|
1257
|
+
*/
|
|
1259
1258
|
text(): Promise<string>;
|
|
1259
|
+
// -- node specific fields --
|
|
1260
1260
|
/**
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1261
|
+
* Optional file path, if the file is stored on disk.
|
|
1262
|
+
*
|
|
1263
|
+
* This is not from the File API, but rather a custom field to indicate where the file is stored.
|
|
1264
|
+
*/
|
|
1265
1265
|
filepath?: string;
|
|
1266
1266
|
}
|
|
1267
1267
|
/**
|
|
1268
|
-
|
|
1269
|
-
|
|
1268
|
+
* TypeBox view of FileLike.
|
|
1269
|
+
*/
|
|
1270
1270
|
type TFile = TUnsafe<FileLike>;
|
|
1271
1271
|
declare const isTypeFile: (value: TSchema$1) => value is TFile;
|
|
1272
1272
|
declare const isFileLike: (value: any) => value is FileLike;
|
|
1273
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
1273
1274
|
type StreamLike = ReadableStream | ReadableStream$1 | Readable | NodeJS.ReadableStream;
|
|
1274
1275
|
type TStream = TUnsafe<StreamLike>;
|
|
1275
1276
|
declare const isTypeStream: (value: TSchema$1) => value is TStream;
|
|
1277
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
1276
1278
|
type TextLength = "short" | "long" | "rich";
|
|
1277
1279
|
interface AlephaStringOptions extends StringOptions {
|
|
1278
1280
|
size?: TextLength;
|
|
1279
1281
|
}
|
|
1282
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
1280
1283
|
declare const t: TypeProvider;
|
|
1284
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
1281
1285
|
declare const isUUID: (value: string) => boolean;
|
|
1282
1286
|
//#endregion
|
|
1283
1287
|
//#region src/index.d.ts
|
|
1284
1288
|
declare const run: (entry: Alepha | Service | Array<Service>, opts?: RunOptions) => Alepha;
|
|
1285
1289
|
//#endregion
|
|
1286
|
-
export { $cursor, $
|
|
1290
|
+
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
1291
|
//# sourceMappingURL=index.d.ts.map
|