alepha 0.7.6 → 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/LICENSE +21 -21
- package/README.md +44 -44
- 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 +800 -795
- package/datetime.d.ts +76 -76
- package/lock/redis.d.ts +12 -12
- package/lock.d.ts +70 -75
- package/package.json +102 -29
- package/postgres.d.ts +385 -278
- package/queue/redis.d.ts +15 -13
- package/queue.d.ts +16 -13
- package/react/auth.d.ts +16 -16
- package/react/head.cjs +8 -0
- package/react/head.d.ts +92 -0
- package/react/head.js +1 -0
- package/react.d.ts +90 -116
- package/redis.d.ts +20 -27
- package/retry.d.ts +74 -54
- package/scheduler.d.ts +14 -13
- package/security.d.ts +38 -41
- package/server/cache.d.ts +9 -7
- package/server/compress.cjs +8 -0
- package/server/compress.d.ts +26 -0
- package/server/compress.js +1 -0
- package/server/cookies.d.ts +71 -14
- package/server/cors.cjs +8 -0
- package/server/cors.d.ts +29 -0
- package/server/cors.js +1 -0
- package/server/health.cjs +8 -0
- package/server/health.d.ts +42 -0
- package/server/health.js +1 -0
- package/server/helmet.cjs +8 -0
- package/server/helmet.d.ts +72 -0
- package/server/helmet.js +1 -0
- package/server/links.cjs +8 -0
- package/server/links.d.ts +179 -0
- package/server/links.js +1 -0
- 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.cjs +8 -0
- package/server/proxy.d.ts +41 -0
- package/server/proxy.js +1 -0
- package/server/static.d.ts +63 -51
- package/server/swagger.d.ts +50 -50
- package/server.d.ts +220 -437
- package/topic/redis.d.ts +24 -23
- package/topic.d.ts +9 -19
- 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,133 +238,148 @@ 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();
|
|
296
|
-
|
|
314
|
+
createContextId(): string;
|
|
315
|
+
run<R>(callback: () => R, data?: Record<string, any>): R;
|
|
297
316
|
get<T>(key: string): T | undefined;
|
|
298
317
|
set<T>(key: string, value: T): void;
|
|
299
318
|
}
|
|
300
319
|
//#endregion
|
|
301
320
|
//#region src/services/Logger.d.ts
|
|
321
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
302
322
|
type LogLevel = "error" | "warn" | "info" | "debug" | "trace" | "silent";
|
|
323
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
303
324
|
interface LoggerEnv {
|
|
304
325
|
/**
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
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
|
+
*/
|
|
315
338
|
NO_COLOR?: string;
|
|
316
339
|
/**
|
|
317
|
-
|
|
318
|
-
|
|
340
|
+
* Force color output for the application.
|
|
341
|
+
*/
|
|
319
342
|
FORCE_COLOR?: string;
|
|
320
343
|
/**
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
LOG_FORMAT?: "json" | "text";
|
|
344
|
+
* Log format.
|
|
345
|
+
*
|
|
346
|
+
* @default "text"
|
|
347
|
+
*/
|
|
348
|
+
LOG_FORMAT?: "json" | "text" | "cli" | "raw";
|
|
326
349
|
}
|
|
350
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
327
351
|
interface LoggerOptions {
|
|
328
352
|
/**
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
level?:
|
|
353
|
+
* The logging level. Can be one of "error", "warn", "info", "debug", or "trace".
|
|
354
|
+
*/
|
|
355
|
+
level?: string;
|
|
356
|
+
app?: string;
|
|
332
357
|
/**
|
|
333
|
-
|
|
334
|
-
|
|
358
|
+
* The name of the logger. Like a module name or a service name.
|
|
359
|
+
*/
|
|
335
360
|
name?: string;
|
|
336
361
|
/**
|
|
337
|
-
|
|
338
|
-
|
|
362
|
+
* An optional context to include in the log output. Like a request ID or a correlation ID.
|
|
363
|
+
*/
|
|
339
364
|
context?: string;
|
|
340
365
|
/**
|
|
341
|
-
|
|
342
|
-
|
|
366
|
+
* An optional tag to include in the log output. Like a class name or a module name.
|
|
367
|
+
*/
|
|
343
368
|
caller?: string;
|
|
344
369
|
/**
|
|
345
|
-
|
|
346
|
-
|
|
370
|
+
* Whether to use colors in the log output. Defaults to true.
|
|
371
|
+
*/
|
|
347
372
|
color?: boolean;
|
|
348
373
|
/**
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
374
|
+
* Log output format. Can be "json", "text", or "cli".
|
|
375
|
+
*/
|
|
376
|
+
format?: string;
|
|
352
377
|
/**
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
als?:
|
|
378
|
+
* An optional async local storage provider to use for storing context information.
|
|
379
|
+
*/
|
|
380
|
+
als?: AlsProvider;
|
|
356
381
|
}
|
|
382
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
357
383
|
declare const COLORS: {
|
|
358
384
|
reset: string;
|
|
359
385
|
grey: string;
|
|
@@ -365,17 +391,22 @@ declare const COLORS: {
|
|
|
365
391
|
cyan: string;
|
|
366
392
|
darkGrey: string;
|
|
367
393
|
};
|
|
368
|
-
declare const LEVEL_COLORS: Record<
|
|
394
|
+
declare const LEVEL_COLORS: Record<string, string>;
|
|
395
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
369
396
|
declare class Logger {
|
|
370
|
-
protected levelOrder: Record<
|
|
371
|
-
readonly level:
|
|
397
|
+
protected levelOrder: Record<string, number>;
|
|
398
|
+
readonly level: string;
|
|
399
|
+
readonly rawLevel: string;
|
|
372
400
|
readonly name: string;
|
|
373
401
|
protected caller: string;
|
|
374
402
|
protected context: string;
|
|
403
|
+
protected app: string;
|
|
375
404
|
protected color: boolean;
|
|
376
|
-
protected
|
|
377
|
-
protected als?:
|
|
405
|
+
protected format: string;
|
|
406
|
+
protected als?: AlsProvider;
|
|
378
407
|
constructor(options?: LoggerOptions);
|
|
408
|
+
parseLevel(level: string, app: string): LogLevel;
|
|
409
|
+
asLogLevel(something: string): LogLevel;
|
|
379
410
|
child(options: LoggerOptions): Logger;
|
|
380
411
|
error(message: unknown, data?: object | Error | string | unknown): void;
|
|
381
412
|
warn(message: unknown, data?: object | Error | string): void;
|
|
@@ -383,49 +414,32 @@ declare class Logger {
|
|
|
383
414
|
debug(message: unknown, data?: object | Error | string): void;
|
|
384
415
|
trace(message: unknown, data?: object | Error | string): void;
|
|
385
416
|
/**
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
* @param level
|
|
389
|
-
* @param message
|
|
390
|
-
* @param data
|
|
391
|
-
* @protected
|
|
392
|
-
*/
|
|
417
|
+
* Log a message to the console.
|
|
418
|
+
*/
|
|
393
419
|
protected log(level: LogLevel, message: unknown, data?: object | Error | string): void;
|
|
394
420
|
/**
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
* @param formatted
|
|
398
|
-
* @protected
|
|
399
|
-
*/
|
|
421
|
+
* Print a log message to the console.
|
|
422
|
+
*/
|
|
400
423
|
protected print(formatted: string): void;
|
|
401
424
|
/**
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
* @param level
|
|
405
|
-
* @param message
|
|
406
|
-
* @param data
|
|
407
|
-
* @protected
|
|
408
|
-
*/
|
|
425
|
+
* Format a log message to JSON.
|
|
426
|
+
*/
|
|
409
427
|
protected formatJson(level: LogLevel, message: unknown, data?: object | Error | string): string;
|
|
410
428
|
protected formatJsonError(error: Error): object;
|
|
411
429
|
/**
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
* @param level
|
|
415
|
-
* @param message
|
|
416
|
-
* @param data
|
|
417
|
-
* @protected
|
|
418
|
-
*/
|
|
430
|
+
* Format a log message to a string.
|
|
431
|
+
*/
|
|
419
432
|
protected formatLog(level: LogLevel, message: string, data?: object | Error): string;
|
|
420
433
|
protected colorize(color: string, text: string, reset?: string): string;
|
|
421
434
|
/**
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
435
|
+
* Format an error to a string.
|
|
436
|
+
*
|
|
437
|
+
* @param error
|
|
438
|
+
* @protected
|
|
439
|
+
*/
|
|
427
440
|
protected formatError(error: Error): string;
|
|
428
441
|
}
|
|
442
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
429
443
|
declare class MockLogger extends Logger {
|
|
430
444
|
store: MockLoggerStore;
|
|
431
445
|
constructor(options?: LoggerOptions & {
|
|
@@ -433,586 +447,605 @@ declare class MockLogger extends Logger {
|
|
|
433
447
|
});
|
|
434
448
|
print(msg: string): void;
|
|
435
449
|
child(options: LoggerOptions): MockLogger;
|
|
450
|
+
reset(): void;
|
|
436
451
|
}
|
|
452
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
437
453
|
interface MockLoggerStore {
|
|
438
454
|
stack: Array<{
|
|
439
455
|
date: string;
|
|
440
456
|
level: string;
|
|
441
457
|
message: string;
|
|
458
|
+
context?: string;
|
|
459
|
+
app?: string;
|
|
442
460
|
} & Record<string, any>>;
|
|
443
461
|
}
|
|
444
462
|
//#endregion
|
|
445
463
|
//#region src/Alepha.d.ts
|
|
464
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
446
465
|
interface Env extends LoggerEnv {
|
|
447
466
|
[key: string]: string | boolean | number | undefined;
|
|
448
467
|
/**
|
|
449
|
-
|
|
450
|
-
|
|
468
|
+
* Optional environment variable that indicates the current environment.
|
|
469
|
+
*/
|
|
451
470
|
NODE_ENV?: "dev" | "test" | "production";
|
|
452
471
|
/**
|
|
453
|
-
|
|
454
|
-
|
|
472
|
+
* Optional name of the application.
|
|
473
|
+
*/
|
|
455
474
|
APP_NAME?: string;
|
|
456
475
|
/**
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
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
|
+
*/
|
|
463
486
|
EXPLICIT_PROVIDERS?: boolean;
|
|
464
487
|
}
|
|
488
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
465
489
|
interface State {
|
|
466
490
|
log: Logger;
|
|
467
491
|
env?: Readonly<Env>;
|
|
492
|
+
// test hooks
|
|
468
493
|
beforeAll?: (run: any) => any;
|
|
469
494
|
afterAll?: (run: any) => any;
|
|
470
495
|
afterEach?: (run: any) => any;
|
|
471
496
|
onTestFinished?: (run: any) => any;
|
|
472
497
|
}
|
|
498
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
473
499
|
interface Hooks {
|
|
474
500
|
echo: any;
|
|
475
501
|
/**
|
|
476
|
-
|
|
477
|
-
|
|
502
|
+
* Triggered during the configuration phase. Before the start phase.
|
|
503
|
+
*/
|
|
478
504
|
configure: Alepha;
|
|
479
505
|
/**
|
|
480
|
-
|
|
481
|
-
|
|
506
|
+
* Triggered during the start phase. When `Alepha#start()` is called.
|
|
507
|
+
*/
|
|
482
508
|
start: Alepha;
|
|
483
509
|
/**
|
|
484
|
-
|
|
485
|
-
|
|
510
|
+
* Triggered during the ready phase. After the start phase.
|
|
511
|
+
*/
|
|
486
512
|
ready: Alepha;
|
|
487
513
|
/**
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
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
|
+
*/
|
|
493
519
|
stop: Alepha;
|
|
494
520
|
/**
|
|
495
|
-
|
|
496
|
-
|
|
521
|
+
* Triggered when a state value is mutated.
|
|
522
|
+
*/
|
|
497
523
|
"state:mutate": {
|
|
498
524
|
/**
|
|
499
|
-
|
|
500
|
-
|
|
525
|
+
* The key of the state that was mutated.
|
|
526
|
+
*/
|
|
501
527
|
key: keyof State;
|
|
502
528
|
/**
|
|
503
|
-
|
|
504
|
-
|
|
529
|
+
* The new value of the state.
|
|
530
|
+
*/
|
|
505
531
|
value: any;
|
|
506
532
|
/**
|
|
507
|
-
|
|
508
|
-
|
|
533
|
+
* The previous value of the state.
|
|
534
|
+
*/
|
|
509
535
|
prevValue: any;
|
|
510
536
|
};
|
|
511
537
|
}
|
|
538
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
512
539
|
/**
|
|
513
|
-
|
|
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
|
-
|
|
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
|
+
*/
|
|
541
568
|
declare class Alepha {
|
|
542
569
|
/**
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
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
|
+
*/
|
|
550
577
|
static create(state?: Partial<State>): Alepha;
|
|
551
578
|
/**
|
|
552
|
-
|
|
553
|
-
|
|
579
|
+
* List of all services + how they are provided.
|
|
580
|
+
*/
|
|
554
581
|
protected registry: Map<Service, ServiceDefinition>;
|
|
555
582
|
/**
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
583
|
+
* Flag indicating whether the App won't accept any further changes.
|
|
584
|
+
* Pass to true when #start() is called.
|
|
585
|
+
*/
|
|
559
586
|
protected locked: boolean;
|
|
560
587
|
/**
|
|
561
|
-
|
|
562
|
-
|
|
588
|
+
* True if the App has been configured.
|
|
589
|
+
*/
|
|
563
590
|
protected configured: boolean;
|
|
564
591
|
/**
|
|
565
|
-
|
|
566
|
-
|
|
592
|
+
* True if the App has started.
|
|
593
|
+
*/
|
|
567
594
|
protected started: boolean;
|
|
568
595
|
/**
|
|
569
|
-
|
|
570
|
-
|
|
596
|
+
* True if the App is ready.
|
|
597
|
+
*/
|
|
571
598
|
protected ready: boolean;
|
|
572
599
|
/**
|
|
573
|
-
|
|
574
|
-
|
|
600
|
+
* A promise that resolves when the App has started.
|
|
601
|
+
*/
|
|
575
602
|
protected starting?: PromiseWithResolvers<this>;
|
|
576
603
|
/**
|
|
577
|
-
|
|
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
|
-
|
|
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
|
+
*/
|
|
603
630
|
protected store: State;
|
|
604
631
|
/**
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
632
|
+
* During the instantiation process, we keep a list of pending instantiations.
|
|
633
|
+
* > It allows us to detect circular dependencies.
|
|
634
|
+
*/
|
|
608
635
|
protected pendingInstantiations: Service[];
|
|
609
636
|
/**
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
637
|
+
* Cache for environment variables.
|
|
638
|
+
* > It allows us to avoid parsing the same schema multiple times.
|
|
639
|
+
*/
|
|
613
640
|
protected cacheEnv: Map<TSchema$1, any>;
|
|
614
641
|
/**
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
642
|
+
* Cache for TypeBox type checks.
|
|
643
|
+
* > It allows us to avoid compiling the same schema multiple times.
|
|
644
|
+
*/
|
|
618
645
|
protected cacheTypeCheck: Map<TSchema$1, TypeCheck<TSchema$1>>;
|
|
619
646
|
/**
|
|
620
|
-
|
|
621
|
-
|
|
647
|
+
* List of events that can be triggered. Powered by $hook().
|
|
648
|
+
*/
|
|
622
649
|
protected events: Record<string, Array<Hook>>;
|
|
623
650
|
/**
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
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
|
+
*/
|
|
628
655
|
protected modules: Array<ModuleDefinition>;
|
|
629
656
|
/**
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
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;
|
|
637
664
|
/**
|
|
638
|
-
|
|
639
|
-
|
|
665
|
+
* Get logger instance.
|
|
666
|
+
*/
|
|
640
667
|
get log(): Logger;
|
|
641
668
|
/**
|
|
642
|
-
|
|
643
|
-
|
|
669
|
+
* The environment variables for the App.
|
|
670
|
+
*/
|
|
644
671
|
get env(): Readonly<Env>;
|
|
645
672
|
constructor(state?: Partial<State>);
|
|
646
673
|
/**
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
*/
|
|
650
|
-
handle?: (req: any, res: any) => Promise<any>;
|
|
651
|
-
/**
|
|
652
|
-
* State accessor and mutator.
|
|
653
|
-
*/
|
|
674
|
+
* State accessor and mutator.
|
|
675
|
+
*/
|
|
654
676
|
state<Key extends keyof State>(key: Key, value?: State[Key]): State[Key];
|
|
677
|
+
// -------------------------------------------------------------------------------------------------------------------
|
|
655
678
|
/**
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
679
|
+
* True when start() is called.
|
|
680
|
+
*
|
|
681
|
+
* -> No more services can be added, it's over, bye!
|
|
682
|
+
*/
|
|
660
683
|
isLocked(): boolean;
|
|
661
684
|
/**
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
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
|
+
*/
|
|
668
691
|
isConfigured(): boolean;
|
|
669
692
|
/**
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
693
|
+
* Returns whether the App has started.
|
|
694
|
+
*
|
|
695
|
+
* It means that #start() has been called but maybe not all services are ready.
|
|
696
|
+
*/
|
|
674
697
|
isStarted(): boolean;
|
|
675
698
|
/**
|
|
676
|
-
|
|
677
|
-
|
|
699
|
+
* True if the App is ready. It means that Alepha is started AND ready() hook has beed called.
|
|
700
|
+
*/
|
|
678
701
|
isReady(): boolean;
|
|
679
702
|
/**
|
|
680
|
-
|
|
681
|
-
|
|
703
|
+
* True if the App is running in a browser environment.
|
|
704
|
+
*/
|
|
682
705
|
isBrowser(): boolean;
|
|
683
706
|
/**
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
707
|
+
* Returns whether the App is running in a serverless environment.
|
|
708
|
+
*
|
|
709
|
+
* > Vite developer mode is also considered serverless.
|
|
710
|
+
*/
|
|
688
711
|
isServerless(): boolean | "vite" | "vercel";
|
|
689
712
|
/**
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
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
|
+
*/
|
|
694
717
|
isTest(): boolean;
|
|
695
718
|
/**
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
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
|
+
*/
|
|
700
723
|
isProduction(): boolean;
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
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
|
+
*/
|
|
711
735
|
start(): Promise<this>;
|
|
712
736
|
/**
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
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
|
+
*/
|
|
724
748
|
stop(): Promise<void>;
|
|
749
|
+
// -------------------------------------------------------------------------------------------------------------------
|
|
725
750
|
/**
|
|
726
|
-
|
|
727
|
-
|
|
751
|
+
* Check if entry is registered in the container.
|
|
752
|
+
*/
|
|
728
753
|
has(entry: ServiceEntry, opts?: {
|
|
729
754
|
/**
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
755
|
+
* Check if the entry is registered in the pending instantiation stack.
|
|
756
|
+
*
|
|
757
|
+
* Default: true
|
|
758
|
+
*/
|
|
734
759
|
inStack?: boolean;
|
|
735
760
|
/**
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
761
|
+
* Check if the entry is registered in the container registry.
|
|
762
|
+
*
|
|
763
|
+
* Default: true
|
|
764
|
+
*/
|
|
740
765
|
inRegistry?: boolean;
|
|
741
766
|
}): boolean;
|
|
742
767
|
/**
|
|
743
|
-
|
|
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
|
+
* 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
|
+
*/
|
|
768
793
|
with<T extends object>(entry: ServiceEntry<T>): this;
|
|
769
794
|
/**
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
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
|
+
*/
|
|
779
804
|
get<T extends object>(serviceEntry: ServiceEntry<T>, opts?: {
|
|
780
805
|
/**
|
|
781
|
-
|
|
782
|
-
|
|
806
|
+
* Ignore current existing instance.
|
|
807
|
+
*/
|
|
783
808
|
skipCache?: boolean;
|
|
784
809
|
/**
|
|
785
|
-
|
|
786
|
-
|
|
810
|
+
* Don't store the instance in the registry.
|
|
811
|
+
*/
|
|
787
812
|
skipRegistration?: boolean;
|
|
788
813
|
/**
|
|
789
|
-
|
|
790
|
-
|
|
814
|
+
* Constructor arguments to pass when creating a new instance.
|
|
815
|
+
*/
|
|
791
816
|
args?: ConstructorParameters<InstantiableService<T>>;
|
|
792
817
|
/**
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
818
|
+
* Parent service that requested the instance.
|
|
819
|
+
* @internal
|
|
820
|
+
*/
|
|
796
821
|
parent?: Service | null;
|
|
797
822
|
/**
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
823
|
+
* If the service is provided by a module, the module definition.
|
|
824
|
+
* @internal
|
|
825
|
+
*/
|
|
801
826
|
module?: ModuleDefinition;
|
|
802
827
|
}): T;
|
|
803
828
|
/**
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
configure<T extends
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
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
|
+
*/
|
|
824
852
|
on<T extends keyof Hooks>(event: T, hookOrFunc: Hook<T> | ((payload: Hooks[T]) => Async<void>)): () => void;
|
|
825
853
|
/**
|
|
826
|
-
|
|
827
|
-
|
|
854
|
+
* Emits the specified event with the given payload.
|
|
855
|
+
*/
|
|
828
856
|
emit<T extends keyof Hooks>(func: keyof Hooks, payload: Hooks[T], options?: {
|
|
829
857
|
/**
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
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
|
+
*/
|
|
835
863
|
reverse?: boolean;
|
|
836
864
|
/**
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
865
|
+
* If true, the hooks will be logged with their execution time.
|
|
866
|
+
*
|
|
867
|
+
* @default false
|
|
868
|
+
*/
|
|
841
869
|
log?: boolean;
|
|
842
870
|
/**
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
871
|
+
* If true, errors will be caught and logged instead of throwing.
|
|
872
|
+
*
|
|
873
|
+
* @default false
|
|
874
|
+
*/
|
|
847
875
|
catch?: boolean;
|
|
848
876
|
}): Promise<void>;
|
|
877
|
+
// -------------------------------------------------------------------------------------------------------------------
|
|
849
878
|
/**
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
879
|
+
* Casts the given value to the specified schema.
|
|
880
|
+
*
|
|
881
|
+
* It uses the TypeBox library to validate the value against the schema.
|
|
882
|
+
*/
|
|
854
883
|
parse<T extends TSchema$1>(schema: T, value?: any, opts?: {
|
|
855
884
|
/**
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
885
|
+
* Clone the value before parsing.
|
|
886
|
+
* @default true
|
|
887
|
+
*/
|
|
859
888
|
clone?: boolean;
|
|
860
889
|
/**
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
890
|
+
* Apply default values defined in the schema.
|
|
891
|
+
* @default true
|
|
892
|
+
*/
|
|
864
893
|
default?: boolean;
|
|
865
894
|
/**
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
895
|
+
* Remove all values not defined in the schema.
|
|
896
|
+
* @default true
|
|
897
|
+
*/
|
|
869
898
|
clean?: boolean;
|
|
870
899
|
/**
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
900
|
+
* Try to cast/convert some data based on the schema.
|
|
901
|
+
* @default true
|
|
902
|
+
*/
|
|
874
903
|
convert?: boolean;
|
|
875
904
|
/**
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
905
|
+
* Prepare value after being deserialized.
|
|
906
|
+
* @default true
|
|
907
|
+
*/
|
|
879
908
|
check?: boolean;
|
|
880
909
|
}): Static$1<T>;
|
|
881
910
|
/**
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
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
|
+
*/
|
|
889
918
|
parseEnv<T extends TObject$1>(schema: T): Static$1<T>;
|
|
919
|
+
// -------------------------------------------------------------------------------------------------------------------
|
|
890
920
|
/**
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
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
|
+
*/
|
|
895
925
|
graph(): Record<string, {
|
|
896
926
|
from: string[];
|
|
897
927
|
as?: string;
|
|
898
928
|
module?: string;
|
|
899
929
|
}>;
|
|
930
|
+
// -------------------------------------------------------------------------------------------------------------------
|
|
900
931
|
/**
|
|
901
|
-
|
|
902
|
-
|
|
932
|
+
* @internal
|
|
933
|
+
*/
|
|
903
934
|
getDescriptorValues<T extends Descriptor>(descriptor: T): Array<DescriptorItem<T>>;
|
|
904
935
|
/**
|
|
905
|
-
|
|
906
|
-
|
|
936
|
+
* @internal
|
|
937
|
+
*/
|
|
907
938
|
protected new<T extends object>(definition: Service<T>, args?: any[], module?: ModuleDefinition): T;
|
|
908
939
|
/**
|
|
909
|
-
|
|
910
|
-
|
|
940
|
+
* @internal
|
|
941
|
+
*/
|
|
911
942
|
protected createLogger(env: Env): Logger;
|
|
912
|
-
/**
|
|
913
|
-
* @internal
|
|
914
|
-
*/
|
|
915
943
|
getModuleOf(service: Service): Module | undefined;
|
|
916
944
|
}
|
|
945
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
917
946
|
/**
|
|
918
|
-
|
|
919
|
-
|
|
947
|
+
* This is how we store services in the Alepha container.
|
|
948
|
+
*/
|
|
920
949
|
interface ServiceDefinition<T extends object = any> {
|
|
921
950
|
/**
|
|
922
|
-
|
|
923
|
-
|
|
951
|
+
* The class or type definition to provide.
|
|
952
|
+
*/
|
|
924
953
|
provide: Service<T>;
|
|
925
954
|
/**
|
|
926
|
-
|
|
927
|
-
|
|
955
|
+
* The class or type definition to use. This will override the 'provide' property.
|
|
956
|
+
*/
|
|
928
957
|
use?: Service<T>;
|
|
929
958
|
/**
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
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
|
+
*/
|
|
933
962
|
instance: T;
|
|
934
963
|
/**
|
|
935
|
-
|
|
936
|
-
|
|
964
|
+
* List of classes which use this class.
|
|
965
|
+
*/
|
|
937
966
|
parents: Array<Service | null>;
|
|
938
967
|
/**
|
|
939
|
-
|
|
940
|
-
|
|
968
|
+
* If the service is provided by a module, the module definition.
|
|
969
|
+
*/
|
|
941
970
|
module?: ModuleDefinition;
|
|
942
971
|
}
|
|
943
972
|
//#endregion
|
|
944
973
|
//#region src/interfaces/Run.d.ts
|
|
945
974
|
interface RunOptions {
|
|
946
975
|
/**
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
976
|
+
* Environment variables to be used by the application.
|
|
977
|
+
* If not provided, it will use the current process environment.
|
|
978
|
+
*/
|
|
950
979
|
env?: Env;
|
|
951
980
|
/**
|
|
952
|
-
|
|
953
|
-
|
|
981
|
+
* A callback that will be executed before the application starts.
|
|
982
|
+
*/
|
|
954
983
|
configure?: (alepha: Alepha) => Async<void>;
|
|
955
984
|
/**
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
985
|
+
* A callback that will be executed once the application is ready.
|
|
986
|
+
* This is useful for initializing resources or starting background tasks.
|
|
987
|
+
*/
|
|
959
988
|
ready?: (alepha: Alepha) => Async<void>;
|
|
960
989
|
/**
|
|
961
|
-
|
|
962
|
-
|
|
990
|
+
* If true, the application will stop after the ready callback is executed.
|
|
991
|
+
*/
|
|
963
992
|
once?: boolean;
|
|
964
993
|
}
|
|
965
994
|
//#endregion
|
|
966
995
|
//#region src/descriptors/$inject.d.ts
|
|
967
996
|
/**
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
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
|
+
*/
|
|
983
1012
|
declare function $inject<T extends TObject$1>(type: T): Static$1<T>;
|
|
984
1013
|
declare function $inject<T extends object>(type: Service<T>): T;
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
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;
|
|
989
1020
|
//#endregion
|
|
990
1021
|
//#region src/descriptors/$logger.d.ts
|
|
1022
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
991
1023
|
/**
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
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
|
+
*/
|
|
1010
1042
|
declare const $logger: (name?: string) => Logger;
|
|
1011
1043
|
//#endregion
|
|
1012
1044
|
//#region src/errors/AlephaError.d.ts
|
|
1045
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
1013
1046
|
/**
|
|
1014
|
-
|
|
1015
|
-
|
|
1047
|
+
* Default error class for Alepha.
|
|
1048
|
+
*/
|
|
1016
1049
|
declare class AlephaError extends Error {}
|
|
1017
1050
|
//#endregion
|
|
1018
1051
|
//#region src/errors/AppNotStartedError.d.ts
|
|
@@ -1042,245 +1075,217 @@ declare class TypeBoxError extends Error {
|
|
|
1042
1075
|
}
|
|
1043
1076
|
//#endregion
|
|
1044
1077
|
//#region src/providers/TypeProvider.d.ts
|
|
1078
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
1045
1079
|
declare class TypeProvider {
|
|
1046
1080
|
static DEFAULT_STRING_MAX_LENGTH: number;
|
|
1047
1081
|
static DEFAULT_LONG_STRING_MAX_LENGTH: number;
|
|
1048
1082
|
static DEFAULT_RICH_STRING_MAX_LENGTH: number;
|
|
1049
1083
|
static DEFAULT_ARRAY_MAX_ITEMS: number;
|
|
1050
|
-
static FormatRegistry: typeof
|
|
1051
|
-
|
|
1052
|
-
any
|
|
1053
|
-
void
|
|
1054
|
-
undefined
|
|
1055
|
-
record
|
|
1056
|
-
omit:
|
|
1057
|
-
|
|
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
|
-
* @param schema The schema to make nullable.
|
|
1145
|
-
* @param options The options for the schema.
|
|
1146
|
-
*/
|
|
1147
|
-
nullable: <T extends TSchema$1>(schema: T, options?: ObjectOptions) => Union<[TNull, T]>;
|
|
1148
|
-
/**
|
|
1149
|
-
* Map a schema to another schema.
|
|
1150
|
-
*
|
|
1151
|
-
* @param schema The schema to map.
|
|
1152
|
-
* @param operations The operations to perform on the schema.
|
|
1153
|
-
* @param options The options for the schema.
|
|
1154
|
-
* @returns The mapped schema.
|
|
1155
|
-
*/
|
|
1156
|
-
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: {
|
|
1157
1178
|
omit: readonly [...Omit];
|
|
1158
1179
|
optional: [...Optional];
|
|
1159
|
-
}, 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>>;
|
|
1160
|
-
/**
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
enum
|
|
1167
|
-
/**
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
/**
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
*/
|
|
1188
|
-
datetime: (options?: StringOptions) => TString;
|
|
1189
|
-
/**
|
|
1190
|
-
* Create a schema for a date.
|
|
1191
|
-
*
|
|
1192
|
-
* @param options
|
|
1193
|
-
*/
|
|
1194
|
-
date: (options?: StringOptions) => TString;
|
|
1195
|
-
/**
|
|
1196
|
-
* Create a schema for uuid.
|
|
1197
|
-
*
|
|
1198
|
-
* @param options The options for the duration.
|
|
1199
|
-
*/
|
|
1200
|
-
uuid: (options?: StringOptions) => TString;
|
|
1201
|
-
/**
|
|
1202
|
-
*
|
|
1203
|
-
*
|
|
1204
|
-
* @param kind
|
|
1205
|
-
* @param options
|
|
1206
|
-
*/
|
|
1207
|
-
unsafe: <T>(kind: string, options?: UnsafeOptions) => TUnsafe<T>;
|
|
1208
|
-
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?: {
|
|
1209
1208
|
max?: number;
|
|
1210
|
-
})
|
|
1211
|
-
stream
|
|
1209
|
+
}): TFile;
|
|
1210
|
+
stream(): TStream;
|
|
1212
1211
|
}
|
|
1212
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
1213
1213
|
interface FileLike {
|
|
1214
1214
|
/**
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1215
|
+
* Filename.
|
|
1216
|
+
* @default "file"
|
|
1217
|
+
*/
|
|
1218
1218
|
name: string;
|
|
1219
1219
|
/**
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1220
|
+
* Mandatory MIME type of the file.
|
|
1221
|
+
* @default "application/octet-stream"
|
|
1222
|
+
*/
|
|
1223
1223
|
type: string;
|
|
1224
1224
|
/**
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
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
|
+
*/
|
|
1231
1231
|
size: number;
|
|
1232
1232
|
/**
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
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
|
+
*/
|
|
1240
1240
|
lastModified: number;
|
|
1241
1241
|
/**
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1242
|
+
* Returns a ReadableStream or Node.js Readable stream of the file content.
|
|
1243
|
+
*
|
|
1244
|
+
* For streams, this is the original stream.
|
|
1245
|
+
*/
|
|
1246
1246
|
stream(): StreamLike;
|
|
1247
1247
|
/**
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1248
|
+
* Returns the file content as an ArrayBuffer.
|
|
1249
|
+
*
|
|
1250
|
+
* For streams, this reads the entire stream into memory.
|
|
1251
|
+
*/
|
|
1252
1252
|
arrayBuffer(): Promise<ArrayBuffer>;
|
|
1253
1253
|
/**
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
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
|
+
*/
|
|
1258
1258
|
text(): Promise<string>;
|
|
1259
|
+
// -- node specific fields --
|
|
1259
1260
|
/**
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
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
|
+
*/
|
|
1264
1265
|
filepath?: string;
|
|
1265
1266
|
}
|
|
1266
1267
|
/**
|
|
1267
|
-
|
|
1268
|
-
|
|
1268
|
+
* TypeBox view of FileLike.
|
|
1269
|
+
*/
|
|
1269
1270
|
type TFile = TUnsafe<FileLike>;
|
|
1270
1271
|
declare const isTypeFile: (value: TSchema$1) => value is TFile;
|
|
1271
1272
|
declare const isFileLike: (value: any) => value is FileLike;
|
|
1273
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
1272
1274
|
type StreamLike = ReadableStream | ReadableStream$1 | Readable | NodeJS.ReadableStream;
|
|
1273
1275
|
type TStream = TUnsafe<StreamLike>;
|
|
1274
1276
|
declare const isTypeStream: (value: TSchema$1) => value is TStream;
|
|
1277
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
1275
1278
|
type TextLength = "short" | "long" | "rich";
|
|
1276
1279
|
interface AlephaStringOptions extends StringOptions {
|
|
1277
1280
|
size?: TextLength;
|
|
1278
1281
|
}
|
|
1282
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
1279
1283
|
declare const t: TypeProvider;
|
|
1284
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
1280
1285
|
declare const isUUID: (value: string) => boolean;
|
|
1281
1286
|
//#endregion
|
|
1282
1287
|
//#region src/index.d.ts
|
|
1283
1288
|
declare const run: (entry: Alepha | Service | Array<Service>, opts?: RunOptions) => Alepha;
|
|
1284
1289
|
//#endregion
|
|
1285
|
-
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 };
|
|
1286
1291
|
//# sourceMappingURL=index.d.ts.map
|