@alepha/protobuf 0.12.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/chunk-MC1wKe0N.js +27 -0
- package/dist/index.cjs +10 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1014 -16
- package/dist/index.d.ts +1015 -17
- package/package.json +7 -5
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.ts.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,11 +1,1009 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import {
|
|
1
|
+
import * as typebox0 from "typebox";
|
|
2
|
+
import { Static, StaticDecode as Static$1, StaticEncode, TArray, TArray as TArray$1, TBoolean, TInteger, TObject, TObject as TObject$1, TOptional, TOptionalAdd, TRecord, TSchema, TSchema as TSchema$1, TString, TUnsafe } from "typebox";
|
|
3
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
4
|
+
import { Validator } from "typebox/compile";
|
|
3
5
|
import protobufjs, { Type } from "protobufjs";
|
|
4
6
|
|
|
7
|
+
//#region ../alepha/src/core/constants/KIND.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* Used for identifying descriptors.
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
declare const KIND: unique symbol;
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region ../alepha/src/core/interfaces/Service.d.ts
|
|
16
|
+
/**
|
|
17
|
+
* In Alepha, a service is a class that can be instantiated or an abstract class. Nothing more, nothing less...
|
|
18
|
+
*/
|
|
19
|
+
type Service<T extends object = any> = InstantiableClass<T> | AbstractClass<T> | RunFunction<T>;
|
|
20
|
+
type RunFunction<T extends object = any> = (...args: any[]) => T | void;
|
|
21
|
+
type InstantiableClass<T extends object = any> = new (...args: any[]) => T;
|
|
22
|
+
/**
|
|
23
|
+
* Abstract class is a class that cannot be instantiated directly!
|
|
24
|
+
* It widely used for defining interfaces.
|
|
25
|
+
*/
|
|
26
|
+
type AbstractClass<T extends object = any> = abstract new (...args: any[]) => T;
|
|
27
|
+
/**
|
|
28
|
+
* Service substitution allows you to register a class as a different class.
|
|
29
|
+
* Providing class A, but using class B instead.
|
|
30
|
+
* This is useful for testing, mocking, or providing a different implementation of a service.
|
|
31
|
+
*
|
|
32
|
+
* class A is mostly an AbstractClass, while class B is an InstantiableClass.
|
|
33
|
+
*/
|
|
34
|
+
interface ServiceSubstitution<T extends object = any> {
|
|
35
|
+
/**
|
|
36
|
+
* Every time someone asks for this class, it will be provided with the 'use' class.
|
|
37
|
+
*/
|
|
38
|
+
provide: Service<T>;
|
|
39
|
+
/**
|
|
40
|
+
* Service to use instead of the 'provide' service.
|
|
41
|
+
*
|
|
42
|
+
* Syntax is inspired by Angular's DI system.
|
|
43
|
+
*/
|
|
44
|
+
use: Service<T>;
|
|
45
|
+
/**
|
|
46
|
+
* If true, if the service already exists -> just ignore the substitution and do not throw an error.
|
|
47
|
+
* Mostly used for plugins to enforce a substitution without throwing an error.
|
|
48
|
+
*/
|
|
49
|
+
optional?: boolean;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Every time you register a service, you can use this type to define it.
|
|
53
|
+
*
|
|
54
|
+
* alepha.with( ServiceEntry )
|
|
55
|
+
* or
|
|
56
|
+
* alepha.with( provide: ServiceEntry, use: MyOwnServiceEntry )
|
|
57
|
+
*
|
|
58
|
+
* And yes, you declare the *type* of the service, not the *instance*.
|
|
59
|
+
*/
|
|
60
|
+
type ServiceEntry<T extends object = any> = Service<T> | ServiceSubstitution<T>;
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region ../alepha/src/core/helpers/descriptor.d.ts
|
|
63
|
+
interface DescriptorArgs<T extends object = {}> {
|
|
64
|
+
options: T;
|
|
65
|
+
alepha: Alepha;
|
|
66
|
+
service: InstantiableClass<Service>;
|
|
67
|
+
module?: Service;
|
|
68
|
+
}
|
|
69
|
+
interface DescriptorConfig {
|
|
70
|
+
propertyKey: string;
|
|
71
|
+
service: InstantiableClass<Service>;
|
|
72
|
+
module?: Service;
|
|
73
|
+
}
|
|
74
|
+
declare abstract class Descriptor<T extends object = {}> {
|
|
75
|
+
protected readonly alepha: Alepha;
|
|
76
|
+
readonly options: T;
|
|
77
|
+
readonly config: DescriptorConfig;
|
|
78
|
+
constructor(args: DescriptorArgs<T>);
|
|
79
|
+
/**
|
|
80
|
+
* Called automatically by Alepha after the descriptor is created.
|
|
81
|
+
*/
|
|
82
|
+
protected onInit(): void;
|
|
83
|
+
}
|
|
84
|
+
type DescriptorFactoryLike<T extends object = any> = {
|
|
85
|
+
(options: T): any;
|
|
86
|
+
[KIND]: any;
|
|
87
|
+
};
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region ../alepha/src/core/descriptors/$inject.d.ts
|
|
90
|
+
interface InjectOptions<T extends object = any> {
|
|
91
|
+
/**
|
|
92
|
+
* - 'transient' → Always a new instance on every inject. Zero caching.
|
|
93
|
+
* - 'singleton' → One instance per Alepha runtime (per-thread). Never disposed until Alepha shuts down. (default)
|
|
94
|
+
* - 'scoped' → One instance per AsyncLocalStorage context.
|
|
95
|
+
* - A new scope is created when Alepha handles a request, a scheduled job, a queue worker task...
|
|
96
|
+
* - You can also start a manual scope via alepha.context.run(() => { ... }).
|
|
97
|
+
* - When the scope ends, the scoped registry is discarded.
|
|
98
|
+
*
|
|
99
|
+
* @default "singleton"
|
|
100
|
+
*/
|
|
101
|
+
lifetime?: "transient" | "singleton" | "scoped";
|
|
102
|
+
/**
|
|
103
|
+
* Constructor arguments to pass when creating a new instance.
|
|
104
|
+
*/
|
|
105
|
+
args?: ConstructorParameters<InstantiableClass<T>>;
|
|
106
|
+
/**
|
|
107
|
+
* Parent that requested the instance.
|
|
108
|
+
*
|
|
109
|
+
* @internal
|
|
110
|
+
*/
|
|
111
|
+
parent?: Service | null;
|
|
112
|
+
}
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region ../alepha/src/core/descriptors/$module.d.ts
|
|
115
|
+
interface ModuleDescriptorOptions {
|
|
116
|
+
/**
|
|
117
|
+
* Name of the module.
|
|
118
|
+
*
|
|
119
|
+
* It should be in the format of `project.module.submodule`.
|
|
120
|
+
*/
|
|
121
|
+
name: string;
|
|
122
|
+
/**
|
|
123
|
+
* List all services related to this module.
|
|
124
|
+
*
|
|
125
|
+
* If you don't declare 'register' function, all services will be registered automatically.
|
|
126
|
+
* If you declare 'register' function, you must handle the registration of ALL services manually.
|
|
127
|
+
*/
|
|
128
|
+
services?: Array<Service>;
|
|
129
|
+
/**
|
|
130
|
+
* List of $descriptors to register in the module.
|
|
131
|
+
*/
|
|
132
|
+
descriptors?: Array<DescriptorFactoryLike>;
|
|
133
|
+
/**
|
|
134
|
+
* By default, module will register ALL services.
|
|
135
|
+
* You can override this behavior by providing a register function.
|
|
136
|
+
* It's useful when you want to register services conditionally or in a specific order.
|
|
137
|
+
*
|
|
138
|
+
* Again, if you declare 'register', you must handle the registration of ALL services manually.
|
|
139
|
+
*/
|
|
140
|
+
register?: (alepha: Alepha) => void;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Base class for all modules.
|
|
144
|
+
*/
|
|
145
|
+
declare abstract class Module {
|
|
146
|
+
abstract readonly options: ModuleDescriptorOptions;
|
|
147
|
+
abstract register(alepha: Alepha): void;
|
|
148
|
+
static NAME_REGEX: RegExp;
|
|
149
|
+
/**
|
|
150
|
+
* Check if a Service is a Module.
|
|
151
|
+
*/
|
|
152
|
+
static is(ctor: Service): boolean;
|
|
153
|
+
/**
|
|
154
|
+
* Get the Module of a Service.
|
|
155
|
+
*
|
|
156
|
+
* Returns undefined if the Service is not part of a Module.
|
|
157
|
+
*/
|
|
158
|
+
static of(ctor: Service): Service<Module> | undefined;
|
|
159
|
+
}
|
|
160
|
+
//#endregion
|
|
161
|
+
//#region ../alepha/src/core/interfaces/Async.d.ts
|
|
162
|
+
/**
|
|
163
|
+
* Represents a value that can be either a value or a promise of value.
|
|
164
|
+
*/
|
|
165
|
+
type Async<T> = T | Promise<T>;
|
|
166
|
+
//#endregion
|
|
167
|
+
//#region ../alepha/src/core/interfaces/LoggerInterface.d.ts
|
|
168
|
+
interface LoggerInterface {
|
|
169
|
+
trace(message: string, data?: unknown): void;
|
|
170
|
+
debug(message: string, data?: unknown): void;
|
|
171
|
+
info(message: string, data?: unknown): void;
|
|
172
|
+
warn(message: string, data?: unknown): void;
|
|
173
|
+
error(message: string, data?: unknown): void;
|
|
174
|
+
}
|
|
175
|
+
//#endregion
|
|
176
|
+
//#region ../alepha/src/core/providers/AlsProvider.d.ts
|
|
177
|
+
type AsyncLocalStorageData = any;
|
|
178
|
+
declare class AlsProvider {
|
|
179
|
+
static create: () => AsyncLocalStorage<AsyncLocalStorageData> | undefined;
|
|
180
|
+
als?: AsyncLocalStorage<AsyncLocalStorageData>;
|
|
181
|
+
constructor();
|
|
182
|
+
createContextId(): string;
|
|
183
|
+
run<R>(callback: () => R, data?: Record<string, any>): R;
|
|
184
|
+
exists(): boolean;
|
|
185
|
+
get<T>(key: string): T | undefined;
|
|
186
|
+
set<T>(key: string, value: T): void;
|
|
187
|
+
}
|
|
188
|
+
//#endregion
|
|
189
|
+
//#region ../alepha/src/core/providers/Json.d.ts
|
|
190
|
+
/**
|
|
191
|
+
* Mimics the JSON global object with stringify and parse methods.
|
|
192
|
+
*
|
|
193
|
+
* Used across the codebase via dependency injection.
|
|
194
|
+
*/
|
|
195
|
+
declare class Json {
|
|
196
|
+
stringify(value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string;
|
|
197
|
+
parse(text: string, reviver?: (this: any, key: string, value: any) => any): any;
|
|
198
|
+
}
|
|
199
|
+
//#endregion
|
|
200
|
+
//#region ../alepha/src/core/providers/TypeProvider.d.ts
|
|
201
|
+
declare module "typebox" {
|
|
202
|
+
interface TString {
|
|
203
|
+
format?: string;
|
|
204
|
+
minLength?: number;
|
|
205
|
+
maxLength?: number;
|
|
206
|
+
}
|
|
207
|
+
interface TNumber {
|
|
208
|
+
format?: "int64";
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
//#endregion
|
|
212
|
+
//#region ../alepha/src/core/providers/SchemaCodec.d.ts
|
|
213
|
+
declare abstract class SchemaCodec {
|
|
214
|
+
/**
|
|
215
|
+
* Encode the value to a string format.
|
|
216
|
+
*/
|
|
217
|
+
abstract encodeToString<T extends TSchema$1>(schema: T, value: Static$1<T>): string;
|
|
218
|
+
/**
|
|
219
|
+
* Encode the value to a binary format.
|
|
220
|
+
*/
|
|
221
|
+
abstract encodeToBinary<T extends TSchema$1>(schema: T, value: Static$1<T>): Uint8Array;
|
|
222
|
+
/**
|
|
223
|
+
* Decode string, binary, or other formats to the schema type.
|
|
224
|
+
*/
|
|
225
|
+
abstract decode<T>(schema: TSchema$1, value: unknown): T;
|
|
226
|
+
}
|
|
227
|
+
//#endregion
|
|
228
|
+
//#region ../alepha/src/core/providers/JsonSchemaCodec.d.ts
|
|
229
|
+
declare class JsonSchemaCodec extends SchemaCodec {
|
|
230
|
+
protected readonly json: Json;
|
|
231
|
+
protected readonly encoder: TextEncoder;
|
|
232
|
+
protected readonly decoder: TextDecoder;
|
|
233
|
+
encodeToString<T extends TSchema>(schema: T, value: Static$1<T>): string;
|
|
234
|
+
encodeToBinary<T extends TSchema>(schema: T, value: Static$1<T>): Uint8Array;
|
|
235
|
+
decode<T>(schema: TSchema, value: unknown): T;
|
|
236
|
+
}
|
|
237
|
+
//#endregion
|
|
238
|
+
//#region ../alepha/src/core/providers/SchemaValidator.d.ts
|
|
239
|
+
declare class SchemaValidator {
|
|
240
|
+
protected cache: Map<TSchema, Validator<typebox0.TProperties, TSchema, unknown, unknown>>;
|
|
241
|
+
/**
|
|
242
|
+
* Validate the value against the provided schema.
|
|
243
|
+
*
|
|
244
|
+
* Validation create a new value by applying some preprocessing. (e.g., trimming text)
|
|
245
|
+
*/
|
|
246
|
+
validate<T extends TSchema>(schema: T, value: unknown, options?: ValidateOptions): Static$1<T>;
|
|
247
|
+
protected getValidator<T extends TSchema>(schema: T): Validator<{}, T>;
|
|
248
|
+
/**
|
|
249
|
+
* Preprocess the value based on the schema before validation.
|
|
250
|
+
*
|
|
251
|
+
* - If the value is `null` and the schema does not allow `null`, it converts it to `undefined`.
|
|
252
|
+
* - If the value is a string and the schema has a `~options.trim` flag, it trims whitespace from the string.
|
|
253
|
+
*/
|
|
254
|
+
beforeParse(schema: any, value: any, options: ValidateOptions): any;
|
|
255
|
+
/**
|
|
256
|
+
* Used by `beforeParse` to determine if a schema allows null values.
|
|
257
|
+
*/
|
|
258
|
+
protected isSchemaNullable: (schema: any) => boolean;
|
|
259
|
+
}
|
|
260
|
+
interface ValidateOptions {
|
|
261
|
+
trim?: boolean;
|
|
262
|
+
nullToUndefined?: boolean;
|
|
263
|
+
deleteUndefined?: boolean;
|
|
264
|
+
}
|
|
265
|
+
//#endregion
|
|
266
|
+
//#region ../alepha/src/core/providers/CodecManager.d.ts
|
|
267
|
+
type Encoding = "object" | "string" | "binary";
|
|
268
|
+
interface EncodeOptions<T extends Encoding = Encoding> {
|
|
269
|
+
/**
|
|
270
|
+
* The output encoding format:
|
|
271
|
+
* - 'string': Returns JSON string
|
|
272
|
+
* - 'binary': Returns Uint8Array (for protobuf, msgpack, etc.)
|
|
273
|
+
*
|
|
274
|
+
* @default "string"
|
|
275
|
+
*/
|
|
276
|
+
as?: T;
|
|
277
|
+
/**
|
|
278
|
+
* The encoder to use (e.g., 'json', 'protobuf', 'msgpack')
|
|
279
|
+
*
|
|
280
|
+
* @default "json"
|
|
281
|
+
*/
|
|
282
|
+
encoder?: string;
|
|
283
|
+
/**
|
|
284
|
+
* Validation options to apply before encoding.
|
|
285
|
+
*/
|
|
286
|
+
validation?: ValidateOptions | false;
|
|
287
|
+
}
|
|
288
|
+
type EncodeResult<T extends TSchema, E extends Encoding> = E extends "string" ? string : E extends "binary" ? Uint8Array : StaticEncode<T>;
|
|
289
|
+
interface DecodeOptions {
|
|
290
|
+
/**
|
|
291
|
+
* The encoder to use (e.g., 'json', 'protobuf', 'msgpack')
|
|
292
|
+
*
|
|
293
|
+
* @default "json"
|
|
294
|
+
*/
|
|
295
|
+
encoder?: string;
|
|
296
|
+
/**
|
|
297
|
+
* Validation options to apply before encoding.
|
|
298
|
+
*/
|
|
299
|
+
validation?: ValidateOptions | false;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* CodecManager manages multiple codec formats and provides a unified interface
|
|
303
|
+
* for encoding and decoding data with different formats.
|
|
304
|
+
*/
|
|
305
|
+
declare class CodecManager {
|
|
306
|
+
protected readonly codecs: Map<string, SchemaCodec>;
|
|
307
|
+
protected readonly jsonCodec: JsonSchemaCodec;
|
|
308
|
+
protected readonly schemaValidator: SchemaValidator;
|
|
309
|
+
default: string;
|
|
310
|
+
constructor();
|
|
311
|
+
/**
|
|
312
|
+
* Register a new codec format.
|
|
313
|
+
*
|
|
314
|
+
* @param name - The name of the codec (e.g., 'json', 'protobuf')
|
|
315
|
+
* @param codec - The codec implementation
|
|
316
|
+
*/
|
|
317
|
+
register(name: string, codec: SchemaCodec): void;
|
|
318
|
+
/**
|
|
319
|
+
* Get a specific codec by name.
|
|
320
|
+
*
|
|
321
|
+
* @param name - The name of the codec
|
|
322
|
+
* @returns The codec instance
|
|
323
|
+
* @throws {AlephaError} If the codec is not found
|
|
324
|
+
*/
|
|
325
|
+
getCodec(name: string): SchemaCodec;
|
|
326
|
+
/**
|
|
327
|
+
* Encode data using the specified codec and output format.
|
|
328
|
+
*/
|
|
329
|
+
encode<T extends TSchema, E extends Encoding = "object">(schema: T, value: unknown, options?: EncodeOptions<E>): EncodeResult<T, E>;
|
|
330
|
+
/**
|
|
331
|
+
* Decode data using the specified codec.
|
|
332
|
+
*/
|
|
333
|
+
decode<T extends TSchema>(schema: T, data: any, options?: DecodeOptions): Static$1<T>;
|
|
334
|
+
/**
|
|
335
|
+
* Validate decoded data against the schema.
|
|
336
|
+
*
|
|
337
|
+
* This is automatically called before encoding or after decoding.
|
|
338
|
+
*/
|
|
339
|
+
validate<T extends TSchema>(schema: T, value: unknown, options?: ValidateOptions): Static$1<T>;
|
|
340
|
+
}
|
|
341
|
+
//#endregion
|
|
342
|
+
//#region ../alepha/src/core/providers/EventManager.d.ts
|
|
343
|
+
declare class EventManager {
|
|
344
|
+
protected logFn?: () => LoggerInterface | undefined;
|
|
345
|
+
/**
|
|
346
|
+
* List of events that can be triggered. Powered by $hook().
|
|
347
|
+
*/
|
|
348
|
+
protected events: Record<string, Array<Hook>>;
|
|
349
|
+
constructor(logFn?: () => LoggerInterface | undefined);
|
|
350
|
+
protected get log(): LoggerInterface | undefined;
|
|
351
|
+
/**
|
|
352
|
+
* Registers a hook for the specified event.
|
|
353
|
+
*/
|
|
354
|
+
on<T extends keyof Hooks>(event: T, hookOrFunc: Hook<T> | ((payload: Hooks[T]) => Async<void>)): () => void;
|
|
355
|
+
/**
|
|
356
|
+
* Emits the specified event with the given payload.
|
|
357
|
+
*/
|
|
358
|
+
emit<T extends keyof Hooks>(func: T, payload: Hooks[T], options?: {
|
|
359
|
+
/**
|
|
360
|
+
* If true, the hooks will be executed in reverse order.
|
|
361
|
+
* This is useful for "stop" hooks that should be executed in reverse order.
|
|
362
|
+
*
|
|
363
|
+
* @default false
|
|
364
|
+
*/
|
|
365
|
+
reverse?: boolean;
|
|
366
|
+
/**
|
|
367
|
+
* If true, the hooks will be logged with their execution time.
|
|
368
|
+
*
|
|
369
|
+
* @default false
|
|
370
|
+
*/
|
|
371
|
+
log?: boolean;
|
|
372
|
+
/**
|
|
373
|
+
* If true, errors will be caught and logged instead of throwing.
|
|
374
|
+
*
|
|
375
|
+
* @default false
|
|
376
|
+
*/
|
|
377
|
+
catch?: boolean;
|
|
378
|
+
}): Promise<void>;
|
|
379
|
+
}
|
|
380
|
+
//#endregion
|
|
381
|
+
//#region ../alepha/src/core/descriptors/$atom.d.ts
|
|
382
|
+
type AtomOptions<T extends TAtomObject, N extends string> = {
|
|
383
|
+
name: N;
|
|
384
|
+
schema: T;
|
|
385
|
+
description?: string;
|
|
386
|
+
} & (T extends TOptionalAdd<T> ? {
|
|
387
|
+
default?: Static$1<T>;
|
|
388
|
+
} : {
|
|
389
|
+
default: Static$1<T>;
|
|
390
|
+
});
|
|
391
|
+
declare class Atom<T extends TAtomObject = TObject$1, N extends string = string> {
|
|
392
|
+
readonly options: AtomOptions<T, N>;
|
|
393
|
+
get schema(): T;
|
|
394
|
+
get key(): N;
|
|
395
|
+
constructor(options: AtomOptions<T, N>);
|
|
396
|
+
}
|
|
397
|
+
type TAtomObject = TObject$1<any> | TArray;
|
|
398
|
+
type AtomStatic<T extends TAtomObject> = T extends TOptionalAdd<T> ? Static$1<T> | undefined : Static$1<T>;
|
|
399
|
+
//#endregion
|
|
400
|
+
//#region ../alepha/src/core/providers/StateManager.d.ts
|
|
401
|
+
interface AtomWithValue {
|
|
402
|
+
atom: Atom;
|
|
403
|
+
value: unknown;
|
|
404
|
+
}
|
|
405
|
+
declare class StateManager<State$1 extends object = State> {
|
|
406
|
+
protected readonly als: AlsProvider;
|
|
407
|
+
protected readonly events: EventManager;
|
|
408
|
+
protected readonly codec: JsonSchemaCodec;
|
|
409
|
+
protected readonly atoms: Map<keyof State$1, Atom<TObject<typebox0.TProperties>, string>>;
|
|
410
|
+
protected store: Partial<State$1>;
|
|
411
|
+
constructor(store?: Partial<State$1>);
|
|
412
|
+
getAtoms(context?: boolean): Array<AtomWithValue>;
|
|
413
|
+
register(atom: Atom<any>): this;
|
|
414
|
+
/**
|
|
415
|
+
* Get a value from the state with proper typing
|
|
416
|
+
*/
|
|
417
|
+
get<T extends TAtomObject>(target: Atom<T>): Static$1<T>;
|
|
418
|
+
get<Key extends keyof State$1>(target: Key): State$1[Key] | undefined;
|
|
419
|
+
/**
|
|
420
|
+
* Set a value in the state
|
|
421
|
+
*/
|
|
422
|
+
set<T extends TAtomObject>(target: Atom<T>, value: AtomStatic<T>): this;
|
|
423
|
+
set<Key extends keyof State$1>(target: Key, value: State$1[Key] | undefined): this;
|
|
424
|
+
/**
|
|
425
|
+
* Mutate a value in the state.
|
|
426
|
+
*/
|
|
427
|
+
mut<T extends TObject>(target: Atom<T>, mutator: (current: Static$1<T>) => Static$1<T>): this;
|
|
428
|
+
mut<Key extends keyof State$1>(target: Key, mutator: (current: State$1[Key] | undefined) => State$1[Key] | undefined): this;
|
|
429
|
+
/**
|
|
430
|
+
* Check if a key exists in the state
|
|
431
|
+
*/
|
|
432
|
+
has<Key extends keyof State$1>(key: Key): boolean;
|
|
433
|
+
/**
|
|
434
|
+
* Delete a key from the state (set to undefined)
|
|
435
|
+
*/
|
|
436
|
+
del<Key extends keyof State$1>(key: Key): this;
|
|
437
|
+
/**
|
|
438
|
+
* Push a value to an array in the state
|
|
439
|
+
*/
|
|
440
|
+
push<Key extends keyof OnlyArray<State$1>>(key: Key, value: NonNullable<State$1[Key]> extends Array<infer U> ? U : never): this;
|
|
441
|
+
/**
|
|
442
|
+
* Clear all state
|
|
443
|
+
*/
|
|
444
|
+
clear(): this;
|
|
445
|
+
/**
|
|
446
|
+
* Get all keys that exist in the state
|
|
447
|
+
*/
|
|
448
|
+
keys(): (keyof State$1)[];
|
|
449
|
+
}
|
|
450
|
+
type OnlyArray<T extends object> = { [K in keyof T]: NonNullable<T[K]> extends Array<any> ? K : never };
|
|
451
|
+
//#endregion
|
|
452
|
+
//#region ../alepha/src/core/Alepha.d.ts
|
|
453
|
+
/**
|
|
454
|
+
* Core container of the Alepha framework.
|
|
455
|
+
*
|
|
456
|
+
* It is responsible for managing the lifecycle of services,
|
|
457
|
+
* handling dependency injection,
|
|
458
|
+
* and providing a unified interface for the application.
|
|
459
|
+
*
|
|
460
|
+
* @example
|
|
461
|
+
* ```ts
|
|
462
|
+
* import { Alepha, run } from "alepha";
|
|
463
|
+
*
|
|
464
|
+
* class MyService {
|
|
465
|
+
* // business logic here
|
|
466
|
+
* }
|
|
467
|
+
*
|
|
468
|
+
* const alepha = Alepha.create({
|
|
469
|
+
* // state, env, and other properties
|
|
470
|
+
* })
|
|
471
|
+
*
|
|
472
|
+
* alepha.with(MyService);
|
|
473
|
+
*
|
|
474
|
+
* run(alepha); // trigger .start (and .stop) automatically
|
|
475
|
+
* ```
|
|
476
|
+
*
|
|
477
|
+
* ### Alepha Factory
|
|
478
|
+
*
|
|
479
|
+
* Alepha.create() is an enhanced version of new Alepha().
|
|
480
|
+
* - It merges `process.env` with the provided state.env when available.
|
|
481
|
+
* - It populates the test hooks for Vitest or Jest environments when available.
|
|
482
|
+
*
|
|
483
|
+
* new Alepha() is fine if you don't need these helpers.
|
|
484
|
+
*
|
|
485
|
+
* ### Platforms & Environments
|
|
486
|
+
*
|
|
487
|
+
* Alepha is designed to work in various environments:
|
|
488
|
+
* - **Browser**: Runs in the browser, using the global `window` object.
|
|
489
|
+
* - **Serverless**: Runs in serverless environments like Vercel or Vite.
|
|
490
|
+
* - **Test**: Runs in test environments like Jest or Vitest.
|
|
491
|
+
* - **Production**: Runs in production environments, typically with NODE_ENV set to "production".
|
|
492
|
+
* * You can check the current environment using the following methods:
|
|
493
|
+
*
|
|
494
|
+
* - `isBrowser()`: Returns true if the App is running in a browser environment.
|
|
495
|
+
* - `isServerless()`: Returns true if the App is running in a serverless environment.
|
|
496
|
+
* - `isTest()`: Returns true if the App is running in a test environment.
|
|
497
|
+
* - `isProduction()`: Returns true if the App is running in a production environment.
|
|
498
|
+
*
|
|
499
|
+
* ### State & Environment
|
|
500
|
+
*
|
|
501
|
+
* The state of the Alepha container is stored in the `store` property.
|
|
502
|
+
* Most important property is `store.env`, which contains the environment variables.
|
|
503
|
+
*
|
|
504
|
+
* ```ts
|
|
505
|
+
* const alepha = Alepha.create({ env: { MY_VAR: "value" } });
|
|
506
|
+
*
|
|
507
|
+
* // You can access the environment variables using alepha.env
|
|
508
|
+
* console.log(alepha.env.MY_VAR); // "value"
|
|
509
|
+
*
|
|
510
|
+
* // But you should use $env() descriptor to get typed values from the environment.
|
|
511
|
+
* class App {
|
|
512
|
+
* env = $env(
|
|
513
|
+
* t.object({
|
|
514
|
+
* MY_VAR: t.text(),
|
|
515
|
+
* })
|
|
516
|
+
* );
|
|
517
|
+
* }
|
|
518
|
+
* ```
|
|
519
|
+
*
|
|
520
|
+
* ### Modules
|
|
521
|
+
*
|
|
522
|
+
* Modules are a way to group services together.
|
|
523
|
+
* You can register a module using the `$module` descriptor.
|
|
524
|
+
*
|
|
525
|
+
* ```ts
|
|
526
|
+
* import { $module } from "alepha";
|
|
527
|
+
*
|
|
528
|
+
* class MyLib {}
|
|
529
|
+
*
|
|
530
|
+
* const myModule = $module({
|
|
531
|
+
* name: "my.project.module",
|
|
532
|
+
* services: [MyLib],
|
|
533
|
+
* });
|
|
534
|
+
* ```
|
|
535
|
+
*
|
|
536
|
+
* Do not use modules for small applications.
|
|
537
|
+
*
|
|
538
|
+
* ### Hooks
|
|
539
|
+
*
|
|
540
|
+
* Hooks are a way to run async functions from all registered providers/services.
|
|
541
|
+
* You can register a hook using the `$hook` descriptor.
|
|
542
|
+
*
|
|
543
|
+
* ```ts
|
|
544
|
+
* import { $hook } from "alepha";
|
|
545
|
+
*
|
|
546
|
+
* class App {
|
|
547
|
+
* log = $logger();
|
|
548
|
+
* onCustomerHook = $hook({
|
|
549
|
+
* on: "my:custom:hook",
|
|
550
|
+
* handler: () => {
|
|
551
|
+
* this.log?.info("App is being configured");
|
|
552
|
+
* },
|
|
553
|
+
* });
|
|
554
|
+
* }
|
|
555
|
+
*
|
|
556
|
+
* Alepha.create()
|
|
557
|
+
* .with(App)
|
|
558
|
+
* .start()
|
|
559
|
+
* .then(alepha => alepha.events.emit("my:custom:hook"));
|
|
560
|
+
* ```
|
|
561
|
+
*
|
|
562
|
+
* Hooks are fully typed. You can create your own hooks by using module augmentation:
|
|
563
|
+
*
|
|
564
|
+
* ```ts
|
|
565
|
+
* declare module "alepha" {
|
|
566
|
+
* interface Hooks {
|
|
567
|
+
* "my:custom:hook": {
|
|
568
|
+
* arg1: string;
|
|
569
|
+
* }
|
|
570
|
+
* }
|
|
571
|
+
* }
|
|
572
|
+
* ```
|
|
573
|
+
*
|
|
574
|
+
* @module alepha
|
|
575
|
+
*/
|
|
576
|
+
declare class Alepha {
|
|
577
|
+
/**
|
|
578
|
+
* Creates a new instance of the Alepha container with some helpers:
|
|
579
|
+
*
|
|
580
|
+
* - merges `process.env` with the provided state.env when available.
|
|
581
|
+
* - populates the test hooks for Vitest or Jest environments when available.
|
|
582
|
+
*
|
|
583
|
+
* If you are not interested about these helpers, you can use the constructor directly.
|
|
584
|
+
*/
|
|
585
|
+
static create(state?: Partial<State>): Alepha;
|
|
586
|
+
/**
|
|
587
|
+
* Flag indicating whether the App won't accept any further changes.
|
|
588
|
+
* Pass to true when #start() is called.
|
|
589
|
+
*/
|
|
590
|
+
protected locked: boolean;
|
|
591
|
+
/**
|
|
592
|
+
* True if the App has been configured.
|
|
593
|
+
*/
|
|
594
|
+
protected configured: boolean;
|
|
595
|
+
/**
|
|
596
|
+
* True if the App has started.
|
|
597
|
+
*/
|
|
598
|
+
protected started: boolean;
|
|
599
|
+
/**
|
|
600
|
+
* True if the App is ready.
|
|
601
|
+
*/
|
|
602
|
+
protected ready: boolean;
|
|
603
|
+
/**
|
|
604
|
+
* A promise that resolves when the App has started.
|
|
605
|
+
*/
|
|
606
|
+
protected starting?: PromiseWithResolvers<this>;
|
|
607
|
+
/**
|
|
608
|
+
* Initial state of the container.
|
|
609
|
+
*
|
|
610
|
+
* > Used to initialize the StateManager.
|
|
611
|
+
*/
|
|
612
|
+
protected init: Partial<State>;
|
|
613
|
+
/**
|
|
614
|
+
* During the instantiation process, we keep a list of pending instantiations.
|
|
615
|
+
* > It allows us to detect circular dependencies.
|
|
616
|
+
*/
|
|
617
|
+
protected pendingInstantiations: Service[];
|
|
618
|
+
/**
|
|
619
|
+
* Cache for environment variables.
|
|
620
|
+
* > It allows us to avoid parsing the same schema multiple times.
|
|
621
|
+
*/
|
|
622
|
+
protected cacheEnv: Map<TSchema$1, any>;
|
|
623
|
+
/**
|
|
624
|
+
* List of modules that are registered in the container.
|
|
625
|
+
*
|
|
626
|
+
* Modules are used to group services and provide a way to register them in the container.
|
|
627
|
+
*/
|
|
628
|
+
protected modules: Array<Module>;
|
|
629
|
+
/**
|
|
630
|
+
* List of service substitutions.
|
|
631
|
+
*
|
|
632
|
+
* Services registered here will be replaced by the specified service when injected.
|
|
633
|
+
*/
|
|
634
|
+
protected substitutions: Map<Service, {
|
|
635
|
+
use: Service;
|
|
636
|
+
}>;
|
|
637
|
+
/**
|
|
638
|
+
* Registry of descriptors.
|
|
639
|
+
*/
|
|
640
|
+
protected descriptorRegistry: Map<Service<Descriptor<{}>>, Descriptor<{}>[]>;
|
|
641
|
+
/**
|
|
642
|
+
* List of all services + how they are provided.
|
|
643
|
+
*/
|
|
644
|
+
protected registry: Map<Service, ServiceDefinition>;
|
|
645
|
+
/**
|
|
646
|
+
* Node.js feature that allows to store context across asynchronous calls.
|
|
647
|
+
*
|
|
648
|
+
* This is used for logging, tracing, and other context-related features.
|
|
649
|
+
*
|
|
650
|
+
* Mocked for browser environments.
|
|
651
|
+
*/
|
|
652
|
+
get context(): AlsProvider;
|
|
653
|
+
/**
|
|
654
|
+
* Event manager to handle lifecycle events and custom events.
|
|
655
|
+
*/
|
|
656
|
+
get events(): EventManager;
|
|
657
|
+
/**
|
|
658
|
+
* State manager to store arbitrary values.
|
|
659
|
+
*/
|
|
660
|
+
get state(): StateManager<State>;
|
|
661
|
+
/**
|
|
662
|
+
* Codec manager for encoding and decoding data with different formats.
|
|
663
|
+
*
|
|
664
|
+
* Supports multiple codec formats (JSON, Protobuf, etc.) with a unified interface.
|
|
665
|
+
*/
|
|
666
|
+
get codec(): CodecManager;
|
|
667
|
+
/**
|
|
668
|
+
* Get logger instance.
|
|
669
|
+
*/
|
|
670
|
+
get log(): LoggerInterface | undefined;
|
|
671
|
+
/**
|
|
672
|
+
* The environment variables for the App.
|
|
673
|
+
*/
|
|
674
|
+
get env(): Readonly<Env>;
|
|
675
|
+
constructor(init?: Partial<State>);
|
|
676
|
+
/**
|
|
677
|
+
* True when start() is called.
|
|
678
|
+
*
|
|
679
|
+
* -> No more services can be added, it's over, bye!
|
|
680
|
+
*/
|
|
681
|
+
isLocked(): boolean;
|
|
682
|
+
/**
|
|
683
|
+
* Returns whether the App is configured.
|
|
684
|
+
*
|
|
685
|
+
* It means that Alepha#configure() has been called.
|
|
686
|
+
*
|
|
687
|
+
* > By default, configure() is called automatically when start() is called, but you can also call it manually.
|
|
688
|
+
*/
|
|
689
|
+
isConfigured(): boolean;
|
|
690
|
+
/**
|
|
691
|
+
* Returns whether the App has started.
|
|
692
|
+
*
|
|
693
|
+
* It means that #start() has been called but maybe not all services are ready.
|
|
694
|
+
*/
|
|
695
|
+
isStarted(): boolean;
|
|
696
|
+
/**
|
|
697
|
+
* True if the App is ready. It means that Alepha is started AND ready() hook has beed called.
|
|
698
|
+
*/
|
|
699
|
+
isReady(): boolean;
|
|
700
|
+
/**
|
|
701
|
+
* True if the App is running in a Continuous Integration environment.
|
|
702
|
+
*/
|
|
703
|
+
isCI(): boolean;
|
|
704
|
+
/**
|
|
705
|
+
* True if the App is running in a browser environment.
|
|
706
|
+
*/
|
|
707
|
+
isBrowser(): boolean;
|
|
708
|
+
/**
|
|
709
|
+
* Returns whether the App is running in Vite dev mode.
|
|
710
|
+
*/
|
|
711
|
+
isViteDev(): boolean;
|
|
712
|
+
isBun(): boolean;
|
|
713
|
+
/**
|
|
714
|
+
* Returns whether the App is running in a serverless environment.
|
|
715
|
+
*/
|
|
716
|
+
isServerless(): boolean;
|
|
717
|
+
/**
|
|
718
|
+
* Returns whether the App is in test mode. (Running in a test environment)
|
|
719
|
+
*
|
|
720
|
+
* > This is automatically set when running tests with Jest or Vitest.
|
|
721
|
+
*/
|
|
722
|
+
isTest(): boolean;
|
|
723
|
+
/**
|
|
724
|
+
* Returns whether the App is in production mode. (Running in a production environment)
|
|
725
|
+
*
|
|
726
|
+
* > This is automatically set by Vite or Vercel. However, you have to set it manually when running Docker apps.
|
|
727
|
+
*/
|
|
728
|
+
isProduction(): boolean;
|
|
729
|
+
/**
|
|
730
|
+
* Starts the App.
|
|
731
|
+
*
|
|
732
|
+
* - Lock any further changes to the container.
|
|
733
|
+
* - Run "configure" hook for all services. Descriptors will be processed.
|
|
734
|
+
* - Run "start" hook for all services. Providers will connect/listen/...
|
|
735
|
+
* - Run "ready" hook for all services. This is the point where the App is ready to serve requests.
|
|
736
|
+
*
|
|
737
|
+
* @return A promise that resolves when the App has started.
|
|
738
|
+
*/
|
|
739
|
+
start(): Promise<this>;
|
|
740
|
+
/**
|
|
741
|
+
* Stops the App.
|
|
742
|
+
*
|
|
743
|
+
* - Run "stop" hook for all services.
|
|
744
|
+
*
|
|
745
|
+
* Stop will NOT reset the container.
|
|
746
|
+
* Stop will NOT unlock the container.
|
|
747
|
+
*
|
|
748
|
+
* > Stop is used to gracefully shut down the application, nothing more. There is no "restart".
|
|
749
|
+
*
|
|
750
|
+
* @return A promise that resolves when the App has stopped.
|
|
751
|
+
*/
|
|
752
|
+
stop(): Promise<void>;
|
|
753
|
+
/**
|
|
754
|
+
* Check if entry is registered in the container.
|
|
755
|
+
*/
|
|
756
|
+
has(entry: ServiceEntry, opts?: {
|
|
757
|
+
/**
|
|
758
|
+
* Check if the entry is registered in the pending instantiation stack.
|
|
759
|
+
*
|
|
760
|
+
* @default true
|
|
761
|
+
*/
|
|
762
|
+
inStack?: boolean;
|
|
763
|
+
/**
|
|
764
|
+
* Check if the entry is registered in the container registry.
|
|
765
|
+
*
|
|
766
|
+
* @default true
|
|
767
|
+
*/
|
|
768
|
+
inRegistry?: boolean;
|
|
769
|
+
/**
|
|
770
|
+
* Check if the entry is registered in the substitutions.
|
|
771
|
+
*
|
|
772
|
+
* @default true
|
|
773
|
+
*/
|
|
774
|
+
inSubstitutions?: boolean;
|
|
775
|
+
/**
|
|
776
|
+
* Where to look for registered services.
|
|
777
|
+
*
|
|
778
|
+
* @default this.registry
|
|
779
|
+
*/
|
|
780
|
+
registry?: Map<Service, ServiceDefinition>;
|
|
781
|
+
}): boolean;
|
|
782
|
+
/**
|
|
783
|
+
* Registers the specified service in the container.
|
|
784
|
+
*
|
|
785
|
+
* - If the service is ALREADY registered, the method does nothing.
|
|
786
|
+
* - If the service is NOT registered, a new instance is created and registered.
|
|
787
|
+
*
|
|
788
|
+
* Method is chainable, so you can register multiple services in a single call.
|
|
789
|
+
*
|
|
790
|
+
* > ServiceEntry allows to provide a service **substitution** feature.
|
|
791
|
+
*
|
|
792
|
+
* @example
|
|
793
|
+
* ```ts
|
|
794
|
+
* class A { value = "a"; }
|
|
795
|
+
* class B { value = "b"; }
|
|
796
|
+
* class M { a = $inject(A); }
|
|
797
|
+
*
|
|
798
|
+
* Alepha.create().with({ provide: A, use: B }).get(M).a.value; // "b"
|
|
799
|
+
* ```
|
|
800
|
+
*
|
|
801
|
+
* > **Substitution** is an advanced feature that allows you to replace a service with another service.
|
|
802
|
+
* > It's useful for testing or for providing different implementations of a service.
|
|
803
|
+
* > If you are interested in configuring a service, use Alepha#configure() instead.
|
|
804
|
+
*
|
|
805
|
+
* @param serviceEntry - The service to register in the container.
|
|
806
|
+
* @return Current instance of Alepha.
|
|
807
|
+
*/
|
|
808
|
+
with<T extends object>(serviceEntry: ServiceEntry<T> | {
|
|
809
|
+
default: ServiceEntry<T>;
|
|
810
|
+
}): this;
|
|
811
|
+
/**
|
|
812
|
+
* Get an instance of the specified service from the container.
|
|
813
|
+
*
|
|
814
|
+
* @see {@link InjectOptions} for the available options.
|
|
815
|
+
*/
|
|
816
|
+
inject<T extends object>(service: Service<T> | string, opts?: InjectOptions<T>): T;
|
|
817
|
+
/**
|
|
818
|
+
* Applies environment variables to the provided schema and state object.
|
|
819
|
+
*
|
|
820
|
+
* It replaces also all templated $ENV inside string values.
|
|
821
|
+
*
|
|
822
|
+
* @param schema - The schema object to apply environment variables to.
|
|
823
|
+
* @return The schema object with environment variables applied.
|
|
824
|
+
*/
|
|
825
|
+
parseEnv<T extends TObject>(schema: T): Static<T>;
|
|
826
|
+
/**
|
|
827
|
+
* Dump the current dependency graph of the App.
|
|
828
|
+
*
|
|
829
|
+
* This method returns a record where the keys are the names of the services.
|
|
830
|
+
*/
|
|
831
|
+
graph(): Record<string, {
|
|
832
|
+
from: string[];
|
|
833
|
+
as?: string[];
|
|
834
|
+
module?: string;
|
|
835
|
+
}>;
|
|
836
|
+
services<T extends object>(base: Service<T>): Array<T>;
|
|
837
|
+
/**
|
|
838
|
+
* Get all descriptors of the specified type.
|
|
839
|
+
*/
|
|
840
|
+
descriptors<TDescriptor extends Descriptor>(factory: {
|
|
841
|
+
[KIND]: InstantiableClass<TDescriptor>;
|
|
842
|
+
} | string): Array<TDescriptor>;
|
|
843
|
+
protected new<T extends object>(service: Service<T>, args?: any[]): T;
|
|
844
|
+
protected processDescriptor(value: Descriptor, propertyKey?: string): void;
|
|
845
|
+
}
|
|
846
|
+
interface Hook<T extends keyof Hooks = any> {
|
|
847
|
+
caller?: Service;
|
|
848
|
+
priority?: "first" | "last";
|
|
849
|
+
callback: (payload: Hooks[T]) => Async<void>;
|
|
850
|
+
}
|
|
851
|
+
/**
|
|
852
|
+
* This is how we store services in the Alepha container.
|
|
853
|
+
*/
|
|
854
|
+
interface ServiceDefinition<T extends object = any> {
|
|
855
|
+
/**
|
|
856
|
+
* The instance of the class or type definition.
|
|
857
|
+
* Mostly used for caching / singleton but can be used for other purposes like forcing the instance.
|
|
858
|
+
*/
|
|
859
|
+
instance: T;
|
|
860
|
+
/**
|
|
861
|
+
* List of classes which use this class.
|
|
862
|
+
*/
|
|
863
|
+
parents: Array<Service | null>;
|
|
864
|
+
}
|
|
865
|
+
interface Env {
|
|
866
|
+
[key: string]: string | boolean | number | undefined;
|
|
867
|
+
/**
|
|
868
|
+
* Optional environment variable that indicates the current environment.
|
|
869
|
+
*/
|
|
870
|
+
NODE_ENV?: "dev" | "test" | "production";
|
|
871
|
+
/**
|
|
872
|
+
* Optional name of the application.
|
|
873
|
+
*/
|
|
874
|
+
APP_NAME?: string;
|
|
875
|
+
/**
|
|
876
|
+
* Optional root module name.
|
|
877
|
+
*/
|
|
878
|
+
MODULE_NAME?: string;
|
|
879
|
+
}
|
|
880
|
+
interface State {
|
|
881
|
+
/**
|
|
882
|
+
* Environment variables for the application.
|
|
883
|
+
*/
|
|
884
|
+
env?: Readonly<Env>;
|
|
885
|
+
/**
|
|
886
|
+
* Logger instance to be used by the Alepha container.
|
|
887
|
+
*
|
|
888
|
+
* @internal
|
|
889
|
+
*/
|
|
890
|
+
"alepha.logger"?: LoggerInterface;
|
|
891
|
+
/**
|
|
892
|
+
* If defined, the Alepha container will only register this service and its dependencies.
|
|
893
|
+
*/
|
|
894
|
+
"alepha.target"?: Service;
|
|
895
|
+
/**
|
|
896
|
+
* Bind to Vitest 'beforeAll' hook.
|
|
897
|
+
* Used for testing purposes.
|
|
898
|
+
* This is automatically attached if Alepha#create() detects a test environment and global 'beforeAll' is available.
|
|
899
|
+
*/
|
|
900
|
+
"alepha.test.beforeAll"?: (run: any) => any;
|
|
901
|
+
/**
|
|
902
|
+
* Bind to Vitest 'afterAll' hook.
|
|
903
|
+
* Used for testing purposes.
|
|
904
|
+
* This is automatically attached if Alepha#create() detects a test environment and global 'afterAll' is available.
|
|
905
|
+
*/
|
|
906
|
+
"alepha.test.afterAll"?: (run: any) => any;
|
|
907
|
+
/**
|
|
908
|
+
* Bind to Vitest 'afterEach' hook.
|
|
909
|
+
* Used for testing purposes.
|
|
910
|
+
* This is automatically attached if Alepha#create() detects a test environment and global 'afterEach' is available.
|
|
911
|
+
*/
|
|
912
|
+
"alepha.test.afterEach"?: (run: any) => any;
|
|
913
|
+
/**
|
|
914
|
+
* Bind to Vitest 'onTestFinished' hook.
|
|
915
|
+
* Used for testing purposes.
|
|
916
|
+
* This is automatically attached if Alepha#create() detects a test environment and global 'onTestFinished' is available.
|
|
917
|
+
*/
|
|
918
|
+
"alepha.test.onTestFinished"?: (run: any) => any;
|
|
919
|
+
/**
|
|
920
|
+
* List of static assets to be copied to the output directory during the build process.
|
|
921
|
+
*
|
|
922
|
+
* Used for Alepha-based applications that require static assets.
|
|
923
|
+
*
|
|
924
|
+
* See alepha/vite for more details.
|
|
925
|
+
*/
|
|
926
|
+
"alepha.build.assets"?: Array<string>;
|
|
927
|
+
}
|
|
928
|
+
interface Hooks {
|
|
929
|
+
/**
|
|
930
|
+
* Used for testing purposes.
|
|
931
|
+
*/
|
|
932
|
+
echo: unknown;
|
|
933
|
+
/**
|
|
934
|
+
* Triggered during the configuration phase. Before the start phase.
|
|
935
|
+
*/
|
|
936
|
+
configure: Alepha;
|
|
937
|
+
/**
|
|
938
|
+
* Triggered during the start phase. When `Alepha#start()` is called.
|
|
939
|
+
*/
|
|
940
|
+
start: Alepha;
|
|
941
|
+
/**
|
|
942
|
+
* Triggered during the ready phase. After the start phase.
|
|
943
|
+
*/
|
|
944
|
+
ready: Alepha;
|
|
945
|
+
/**
|
|
946
|
+
* Triggered during the stop phase.
|
|
947
|
+
*
|
|
948
|
+
* - Stop should be called after a SIGINT or SIGTERM signal in order to gracefully shutdown the application. (@see `run()` method)
|
|
949
|
+
*
|
|
950
|
+
*/
|
|
951
|
+
stop: Alepha;
|
|
952
|
+
/**
|
|
953
|
+
* Triggered when a state value is mutated.
|
|
954
|
+
*/
|
|
955
|
+
"state:mutate": {
|
|
956
|
+
/**
|
|
957
|
+
* The key of the state that was mutated.
|
|
958
|
+
*/
|
|
959
|
+
key: keyof State;
|
|
960
|
+
/**
|
|
961
|
+
* The new value of the state.
|
|
962
|
+
*/
|
|
963
|
+
value: any;
|
|
964
|
+
/**
|
|
965
|
+
* The previous value of the state.
|
|
966
|
+
*/
|
|
967
|
+
prevValue: any;
|
|
968
|
+
};
|
|
969
|
+
}
|
|
970
|
+
//#endregion
|
|
971
|
+
//#region ../alepha/src/core/schemas/pageSchema.d.ts
|
|
972
|
+
declare const pageMetadataSchema: TObject$1<{
|
|
973
|
+
number: TInteger;
|
|
974
|
+
size: TInteger;
|
|
975
|
+
offset: TInteger;
|
|
976
|
+
numberOfElements: TInteger;
|
|
977
|
+
totalElements: TOptional<TInteger>;
|
|
978
|
+
totalPages: TOptional<TInteger>;
|
|
979
|
+
isEmpty: TBoolean;
|
|
980
|
+
isFirst: TBoolean;
|
|
981
|
+
isLast: TBoolean;
|
|
982
|
+
sort: TOptional<TObject$1<{
|
|
983
|
+
sorted: TBoolean;
|
|
984
|
+
fields: TArray$1<TObject$1<{
|
|
985
|
+
field: TString;
|
|
986
|
+
direction: TUnsafe<"asc" | "desc">;
|
|
987
|
+
}>>;
|
|
988
|
+
}>>;
|
|
989
|
+
}>;
|
|
990
|
+
type TPage<T extends TObject$1 | TRecord> = TObject$1<{
|
|
991
|
+
content: TArray$1<T>;
|
|
992
|
+
page: typeof pageMetadataSchema;
|
|
993
|
+
}>;
|
|
994
|
+
declare module "alepha" {
|
|
995
|
+
interface TypeProvider {
|
|
996
|
+
/**
|
|
997
|
+
* Create a schema for a paginated response.
|
|
998
|
+
*/
|
|
999
|
+
page<T extends TObject$1 | TRecord>(itemSchema: T): TPage<T>;
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
//#endregion
|
|
5
1003
|
//#region src/providers/ProtobufProvider.d.ts
|
|
6
1004
|
declare class ProtobufProvider {
|
|
7
1005
|
protected readonly alepha: Alepha;
|
|
8
|
-
protected readonly schemas: Map<string | TObject, Type>;
|
|
1006
|
+
protected readonly schemas: Map<string | TObject$1, Type>;
|
|
9
1007
|
protected readonly protobuf: typeof protobufjs;
|
|
10
1008
|
protected readonly enumDefinitions: Map<string, string[]>;
|
|
11
1009
|
/**
|
|
@@ -23,27 +1021,27 @@ declare class ProtobufProvider {
|
|
|
23
1021
|
/**
|
|
24
1022
|
* Convert a TypeBox schema to a Protobuf schema as a string.
|
|
25
1023
|
*/
|
|
26
|
-
createProtobufSchema(schema: TSchema, options?: CreateProtobufSchemaOptions): string;
|
|
1024
|
+
createProtobufSchema(schema: TSchema$1, options?: CreateProtobufSchemaOptions): string;
|
|
27
1025
|
/**
|
|
28
1026
|
* Parse an object schema with dependencies (sub-messages).
|
|
29
1027
|
*/
|
|
30
|
-
protected parseObjectWithDependencies(obj: TSchema, parentName: string): {
|
|
1028
|
+
protected parseObjectWithDependencies(obj: TSchema$1, parentName: string): {
|
|
31
1029
|
message: string;
|
|
32
1030
|
subMessages: string[];
|
|
33
1031
|
};
|
|
34
1032
|
/**
|
|
35
1033
|
* Convert a primitive TypeBox schema type to a Protobuf spec type.
|
|
36
1034
|
*/
|
|
37
|
-
protected convertType(schema: TSchema): string;
|
|
1035
|
+
protected convertType(schema: TSchema$1): string;
|
|
38
1036
|
/**
|
|
39
1037
|
* Check if a schema is an enum type.
|
|
40
1038
|
* TypeBox enums have an "enum" property with an array of values.
|
|
41
1039
|
*/
|
|
42
|
-
protected isEnum(schema: TSchema): boolean;
|
|
1040
|
+
protected isEnum(schema: TSchema$1): boolean;
|
|
43
1041
|
/**
|
|
44
1042
|
* Extract enum values from a TypeBox enum schema.
|
|
45
1043
|
*/
|
|
46
|
-
protected getEnumValues(schema: TSchema): string[];
|
|
1044
|
+
protected getEnumValues(schema: TSchema$1): string[];
|
|
47
1045
|
/**
|
|
48
1046
|
* Register an enum and return its type name.
|
|
49
1047
|
* Generates a PascalCase name from the field name.
|
|
@@ -73,31 +1071,31 @@ interface CreateProtobufSchemaOptions {
|
|
|
73
1071
|
declare class ProtobufSchemaCodec extends SchemaCodec {
|
|
74
1072
|
protected protobufProvider: ProtobufProvider;
|
|
75
1073
|
protected decoder: TextDecoder;
|
|
76
|
-
encodeToString<T extends TSchema>(schema: T, value: Static<T>): string;
|
|
77
|
-
encodeToBinary<T extends TSchema>(schema: T, value: Static<T>): Uint8Array;
|
|
78
|
-
decode<T>(schema: TSchema, value: unknown): T;
|
|
1074
|
+
encodeToString<T extends TSchema$1>(schema: T, value: Static$1<T>): string;
|
|
1075
|
+
encodeToBinary<T extends TSchema$1>(schema: T, value: Static$1<T>): Uint8Array;
|
|
1076
|
+
decode<T>(schema: TSchema$1, value: unknown): T;
|
|
79
1077
|
/**
|
|
80
1078
|
* Apply proto3 default values for fields that were omitted during encoding.
|
|
81
1079
|
* Proto3 omits fields with default values, so we need to restore them.
|
|
82
1080
|
* Also converts enum integers back to their string values.
|
|
83
1081
|
*/
|
|
84
|
-
protected applyProto3Defaults(schema: TSchema, value: any): any;
|
|
1082
|
+
protected applyProto3Defaults(schema: TSchema$1, value: any): any;
|
|
85
1083
|
/**
|
|
86
1084
|
* Check if a schema is an enum type.
|
|
87
1085
|
*/
|
|
88
|
-
protected isEnum(schema: TSchema): boolean;
|
|
1086
|
+
protected isEnum(schema: TSchema$1): boolean;
|
|
89
1087
|
/**
|
|
90
1088
|
* Convert an enum value from protobuf integer to TypeBox string.
|
|
91
1089
|
*/
|
|
92
|
-
protected convertEnumValue(schema: TSchema, value: any): any;
|
|
1090
|
+
protected convertEnumValue(schema: TSchema$1, value: any): any;
|
|
93
1091
|
/**
|
|
94
1092
|
* Get the proto3 default value for a schema type.
|
|
95
1093
|
*/
|
|
96
|
-
protected getProto3Default(schema: TSchema): any;
|
|
1094
|
+
protected getProto3Default(schema: TSchema$1): any;
|
|
97
1095
|
}
|
|
98
1096
|
//#endregion
|
|
99
1097
|
//#region src/index.d.ts
|
|
100
|
-
declare const AlephaProtobuf:
|
|
1098
|
+
declare const AlephaProtobuf: Service<Module>;
|
|
101
1099
|
//#endregion
|
|
102
1100
|
export { AlephaProtobuf, CreateProtobufSchemaOptions, ProtobufProvider, ProtobufSchema, ProtobufSchemaCodec };
|
|
103
1101
|
//# sourceMappingURL=index.d.cts.map
|