@alepha/bucket-vercel 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/dist/index.d.ts CHANGED
@@ -1,11 +1,1958 @@
1
- import * as alepha1 from "alepha";
2
- import { Alepha, FileLike, Static } from "alepha";
3
- import { FileMetadataService, FileStorageProvider } from "alepha/bucket";
4
- import { DateTimeProvider } from "alepha/datetime";
5
- import { FileSystemProvider } from "alepha/file";
6
- import * as alepha_logger0 from "alepha/logger";
7
1
  import { del, head, put } from "@vercel/blob";
2
+ import * as typebox0 from "typebox";
3
+ import { Static, StaticDecode as Static$1, StaticEncode, TAny, TArray, TArray as TArray$1, TBoolean, TInteger, TNumber, TObject, TObject as TObject$1, TOptional, TOptionalAdd, TRecord, TSchema, TSchema as TSchema$1, TString, TUnsafe } from "typebox";
4
+ import { AsyncLocalStorage } from "node:async_hooks";
5
+ import { Readable } from "node:stream";
6
+ import { ReadableStream as ReadableStream$1 } from "node:stream/web";
7
+ import { Validator } from "typebox/compile";
8
+ import dayjsDuration from "dayjs/plugin/duration.js";
9
+ import DayjsApi, { Dayjs, ManipulateType, PluginFunc } from "dayjs";
10
+ import "node:fs";
8
11
 
12
+ //#region ../alepha/src/core/constants/KIND.d.ts
13
+ /**
14
+ * Used for identifying descriptors.
15
+ *
16
+ * @internal
17
+ */
18
+ declare const KIND: unique symbol;
19
+ //#endregion
20
+ //#region ../alepha/src/core/interfaces/Service.d.ts
21
+ /**
22
+ * In Alepha, a service is a class that can be instantiated or an abstract class. Nothing more, nothing less...
23
+ */
24
+ type Service<T extends object = any> = InstantiableClass<T> | AbstractClass<T> | RunFunction<T>;
25
+ type RunFunction<T extends object = any> = (...args: any[]) => T | void;
26
+ type InstantiableClass<T extends object = any> = new (...args: any[]) => T;
27
+ /**
28
+ * Abstract class is a class that cannot be instantiated directly!
29
+ * It widely used for defining interfaces.
30
+ */
31
+ type AbstractClass<T extends object = any> = abstract new (...args: any[]) => T;
32
+ /**
33
+ * Service substitution allows you to register a class as a different class.
34
+ * Providing class A, but using class B instead.
35
+ * This is useful for testing, mocking, or providing a different implementation of a service.
36
+ *
37
+ * class A is mostly an AbstractClass, while class B is an InstantiableClass.
38
+ */
39
+ interface ServiceSubstitution<T extends object = any> {
40
+ /**
41
+ * Every time someone asks for this class, it will be provided with the 'use' class.
42
+ */
43
+ provide: Service<T>;
44
+ /**
45
+ * Service to use instead of the 'provide' service.
46
+ *
47
+ * Syntax is inspired by Angular's DI system.
48
+ */
49
+ use: Service<T>;
50
+ /**
51
+ * If true, if the service already exists -> just ignore the substitution and do not throw an error.
52
+ * Mostly used for plugins to enforce a substitution without throwing an error.
53
+ */
54
+ optional?: boolean;
55
+ }
56
+ /**
57
+ * Every time you register a service, you can use this type to define it.
58
+ *
59
+ * alepha.with( ServiceEntry )
60
+ * or
61
+ * alepha.with( provide: ServiceEntry, use: MyOwnServiceEntry )
62
+ *
63
+ * And yes, you declare the *type* of the service, not the *instance*.
64
+ */
65
+ type ServiceEntry<T extends object = any> = Service<T> | ServiceSubstitution<T>;
66
+ //#endregion
67
+ //#region ../alepha/src/core/helpers/descriptor.d.ts
68
+ interface DescriptorArgs<T extends object = {}> {
69
+ options: T;
70
+ alepha: Alepha;
71
+ service: InstantiableClass<Service>;
72
+ module?: Service;
73
+ }
74
+ interface DescriptorConfig {
75
+ propertyKey: string;
76
+ service: InstantiableClass<Service>;
77
+ module?: Service;
78
+ }
79
+ declare abstract class Descriptor<T extends object = {}> {
80
+ protected readonly alepha: Alepha;
81
+ readonly options: T;
82
+ readonly config: DescriptorConfig;
83
+ constructor(args: DescriptorArgs<T>);
84
+ /**
85
+ * Called automatically by Alepha after the descriptor is created.
86
+ */
87
+ protected onInit(): void;
88
+ }
89
+ type DescriptorFactoryLike<T extends object = any> = {
90
+ (options: T): any;
91
+ [KIND]: any;
92
+ };
93
+ //#endregion
94
+ //#region ../alepha/src/core/descriptors/$inject.d.ts
95
+ interface InjectOptions<T extends object = any> {
96
+ /**
97
+ * - 'transient' → Always a new instance on every inject. Zero caching.
98
+ * - 'singleton' → One instance per Alepha runtime (per-thread). Never disposed until Alepha shuts down. (default)
99
+ * - 'scoped' → One instance per AsyncLocalStorage context.
100
+ * - A new scope is created when Alepha handles a request, a scheduled job, a queue worker task...
101
+ * - You can also start a manual scope via alepha.context.run(() => { ... }).
102
+ * - When the scope ends, the scoped registry is discarded.
103
+ *
104
+ * @default "singleton"
105
+ */
106
+ lifetime?: "transient" | "singleton" | "scoped";
107
+ /**
108
+ * Constructor arguments to pass when creating a new instance.
109
+ */
110
+ args?: ConstructorParameters<InstantiableClass<T>>;
111
+ /**
112
+ * Parent that requested the instance.
113
+ *
114
+ * @internal
115
+ */
116
+ parent?: Service | null;
117
+ }
118
+ //#endregion
119
+ //#region ../alepha/src/core/descriptors/$module.d.ts
120
+ interface ModuleDescriptorOptions {
121
+ /**
122
+ * Name of the module.
123
+ *
124
+ * It should be in the format of `project.module.submodule`.
125
+ */
126
+ name: string;
127
+ /**
128
+ * List all services related to this module.
129
+ *
130
+ * If you don't declare 'register' function, all services will be registered automatically.
131
+ * If you declare 'register' function, you must handle the registration of ALL services manually.
132
+ */
133
+ services?: Array<Service>;
134
+ /**
135
+ * List of $descriptors to register in the module.
136
+ */
137
+ descriptors?: Array<DescriptorFactoryLike>;
138
+ /**
139
+ * By default, module will register ALL services.
140
+ * You can override this behavior by providing a register function.
141
+ * It's useful when you want to register services conditionally or in a specific order.
142
+ *
143
+ * Again, if you declare 'register', you must handle the registration of ALL services manually.
144
+ */
145
+ register?: (alepha: Alepha) => void;
146
+ }
147
+ /**
148
+ * Base class for all modules.
149
+ */
150
+ declare abstract class Module {
151
+ abstract readonly options: ModuleDescriptorOptions;
152
+ abstract register(alepha: Alepha): void;
153
+ static NAME_REGEX: RegExp;
154
+ /**
155
+ * Check if a Service is a Module.
156
+ */
157
+ static is(ctor: Service): boolean;
158
+ /**
159
+ * Get the Module of a Service.
160
+ *
161
+ * Returns undefined if the Service is not part of a Module.
162
+ */
163
+ static of(ctor: Service): Service<Module> | undefined;
164
+ }
165
+ //#endregion
166
+ //#region ../alepha/src/core/interfaces/Async.d.ts
167
+ /**
168
+ * Represents a value that can be either a value or a promise of value.
169
+ */
170
+ type Async<T> = T | Promise<T>;
171
+ //#endregion
172
+ //#region ../alepha/src/core/interfaces/LoggerInterface.d.ts
173
+ type LogLevel = "ERROR" | "WARN" | "INFO" | "DEBUG" | "TRACE" | "SILENT";
174
+ interface LoggerInterface {
175
+ trace(message: string, data?: unknown): void;
176
+ debug(message: string, data?: unknown): void;
177
+ info(message: string, data?: unknown): void;
178
+ warn(message: string, data?: unknown): void;
179
+ error(message: string, data?: unknown): void;
180
+ }
181
+ //#endregion
182
+ //#region ../alepha/src/core/providers/AlsProvider.d.ts
183
+ type AsyncLocalStorageData = any;
184
+ declare class AlsProvider {
185
+ static create: () => AsyncLocalStorage<AsyncLocalStorageData> | undefined;
186
+ als?: AsyncLocalStorage<AsyncLocalStorageData>;
187
+ constructor();
188
+ createContextId(): string;
189
+ run<R>(callback: () => R, data?: Record<string, any>): R;
190
+ exists(): boolean;
191
+ get<T>(key: string): T | undefined;
192
+ set<T>(key: string, value: T): void;
193
+ }
194
+ //#endregion
195
+ //#region ../alepha/src/core/providers/Json.d.ts
196
+ /**
197
+ * Mimics the JSON global object with stringify and parse methods.
198
+ *
199
+ * Used across the codebase via dependency injection.
200
+ */
201
+ declare class Json {
202
+ stringify(value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string;
203
+ parse(text: string, reviver?: (this: any, key: string, value: any) => any): any;
204
+ }
205
+ //#endregion
206
+ //#region ../alepha/src/core/helpers/FileLike.d.ts
207
+ interface FileLike {
208
+ /**
209
+ * Filename.
210
+ * @default "file"
211
+ */
212
+ name: string;
213
+ /**
214
+ * Mandatory MIME type of the file.
215
+ * @default "application/octet-stream"
216
+ */
217
+ type: string;
218
+ /**
219
+ * Size of the file in bytes.
220
+ *
221
+ * Always 0 for streams, as the size is not known until the stream is fully read.
222
+ *
223
+ * @default 0
224
+ */
225
+ size: number;
226
+ /**
227
+ * Last modified timestamp in milliseconds since epoch.
228
+ *
229
+ * Always the current timestamp for streams, as the last modified time is not known.
230
+ * We use this field to ensure compatibility with File API.
231
+ *
232
+ * @default Date.now()
233
+ */
234
+ lastModified: number;
235
+ /**
236
+ * Returns a ReadableStream or Node.js Readable stream of the file content.
237
+ *
238
+ * For streams, this is the original stream.
239
+ */
240
+ stream(): StreamLike;
241
+ /**
242
+ * Returns the file content as an ArrayBuffer.
243
+ *
244
+ * For streams, this reads the entire stream into memory.
245
+ */
246
+ arrayBuffer(): Promise<ArrayBuffer>;
247
+ /**
248
+ * Returns the file content as a string.
249
+ *
250
+ * For streams, this reads the entire stream into memory and converts it to a string.
251
+ */
252
+ text(): Promise<string>;
253
+ /**
254
+ * Optional file path, if the file is stored on disk.
255
+ *
256
+ * This is not from the File API, but rather a custom field to indicate where the file is stored.
257
+ */
258
+ filepath?: string;
259
+ }
260
+ type StreamLike = ReadableStream | ReadableStream$1 | Readable | NodeJS.ReadableStream;
261
+ //#endregion
262
+ //#region ../alepha/src/core/providers/TypeProvider.d.ts
263
+ declare module "typebox" {
264
+ interface TString {
265
+ format?: string;
266
+ minLength?: number;
267
+ maxLength?: number;
268
+ }
269
+ interface TNumber {
270
+ format?: "int64";
271
+ }
272
+ }
273
+ //#endregion
274
+ //#region ../alepha/src/core/providers/SchemaCodec.d.ts
275
+ declare abstract class SchemaCodec {
276
+ /**
277
+ * Encode the value to a string format.
278
+ */
279
+ abstract encodeToString<T extends TSchema$1>(schema: T, value: Static$1<T>): string;
280
+ /**
281
+ * Encode the value to a binary format.
282
+ */
283
+ abstract encodeToBinary<T extends TSchema$1>(schema: T, value: Static$1<T>): Uint8Array;
284
+ /**
285
+ * Decode string, binary, or other formats to the schema type.
286
+ */
287
+ abstract decode<T>(schema: TSchema$1, value: unknown): T;
288
+ }
289
+ //#endregion
290
+ //#region ../alepha/src/core/providers/JsonSchemaCodec.d.ts
291
+ declare class JsonSchemaCodec extends SchemaCodec {
292
+ protected readonly json: Json;
293
+ protected readonly encoder: TextEncoder;
294
+ protected readonly decoder: TextDecoder;
295
+ encodeToString<T extends TSchema>(schema: T, value: Static$1<T>): string;
296
+ encodeToBinary<T extends TSchema>(schema: T, value: Static$1<T>): Uint8Array;
297
+ decode<T>(schema: TSchema, value: unknown): T;
298
+ }
299
+ //#endregion
300
+ //#region ../alepha/src/core/providers/SchemaValidator.d.ts
301
+ declare class SchemaValidator {
302
+ protected cache: Map<TSchema, Validator<typebox0.TProperties, TSchema, unknown, unknown>>;
303
+ /**
304
+ * Validate the value against the provided schema.
305
+ *
306
+ * Validation create a new value by applying some preprocessing. (e.g., trimming text)
307
+ */
308
+ validate<T extends TSchema>(schema: T, value: unknown, options?: ValidateOptions): Static$1<T>;
309
+ protected getValidator<T extends TSchema>(schema: T): Validator<{}, T>;
310
+ /**
311
+ * Preprocess the value based on the schema before validation.
312
+ *
313
+ * - If the value is `null` and the schema does not allow `null`, it converts it to `undefined`.
314
+ * - If the value is a string and the schema has a `~options.trim` flag, it trims whitespace from the string.
315
+ */
316
+ beforeParse(schema: any, value: any, options: ValidateOptions): any;
317
+ /**
318
+ * Used by `beforeParse` to determine if a schema allows null values.
319
+ */
320
+ protected isSchemaNullable: (schema: any) => boolean;
321
+ }
322
+ interface ValidateOptions {
323
+ trim?: boolean;
324
+ nullToUndefined?: boolean;
325
+ deleteUndefined?: boolean;
326
+ }
327
+ //#endregion
328
+ //#region ../alepha/src/core/providers/CodecManager.d.ts
329
+ type Encoding = "object" | "string" | "binary";
330
+ interface EncodeOptions<T extends Encoding = Encoding> {
331
+ /**
332
+ * The output encoding format:
333
+ * - 'string': Returns JSON string
334
+ * - 'binary': Returns Uint8Array (for protobuf, msgpack, etc.)
335
+ *
336
+ * @default "string"
337
+ */
338
+ as?: T;
339
+ /**
340
+ * The encoder to use (e.g., 'json', 'protobuf', 'msgpack')
341
+ *
342
+ * @default "json"
343
+ */
344
+ encoder?: string;
345
+ /**
346
+ * Validation options to apply before encoding.
347
+ */
348
+ validation?: ValidateOptions | false;
349
+ }
350
+ type EncodeResult<T extends TSchema, E extends Encoding> = E extends "string" ? string : E extends "binary" ? Uint8Array : StaticEncode<T>;
351
+ interface DecodeOptions {
352
+ /**
353
+ * The encoder to use (e.g., 'json', 'protobuf', 'msgpack')
354
+ *
355
+ * @default "json"
356
+ */
357
+ encoder?: string;
358
+ /**
359
+ * Validation options to apply before encoding.
360
+ */
361
+ validation?: ValidateOptions | false;
362
+ }
363
+ /**
364
+ * CodecManager manages multiple codec formats and provides a unified interface
365
+ * for encoding and decoding data with different formats.
366
+ */
367
+ declare class CodecManager {
368
+ protected readonly codecs: Map<string, SchemaCodec>;
369
+ protected readonly jsonCodec: JsonSchemaCodec;
370
+ protected readonly schemaValidator: SchemaValidator;
371
+ default: string;
372
+ constructor();
373
+ /**
374
+ * Register a new codec format.
375
+ *
376
+ * @param name - The name of the codec (e.g., 'json', 'protobuf')
377
+ * @param codec - The codec implementation
378
+ */
379
+ register(name: string, codec: SchemaCodec): void;
380
+ /**
381
+ * Get a specific codec by name.
382
+ *
383
+ * @param name - The name of the codec
384
+ * @returns The codec instance
385
+ * @throws {AlephaError} If the codec is not found
386
+ */
387
+ getCodec(name: string): SchemaCodec;
388
+ /**
389
+ * Encode data using the specified codec and output format.
390
+ */
391
+ encode<T extends TSchema, E extends Encoding = "object">(schema: T, value: unknown, options?: EncodeOptions<E>): EncodeResult<T, E>;
392
+ /**
393
+ * Decode data using the specified codec.
394
+ */
395
+ decode<T extends TSchema>(schema: T, data: any, options?: DecodeOptions): Static$1<T>;
396
+ /**
397
+ * Validate decoded data against the schema.
398
+ *
399
+ * This is automatically called before encoding or after decoding.
400
+ */
401
+ validate<T extends TSchema>(schema: T, value: unknown, options?: ValidateOptions): Static$1<T>;
402
+ }
403
+ //#endregion
404
+ //#region ../alepha/src/core/providers/EventManager.d.ts
405
+ declare class EventManager {
406
+ protected logFn?: () => LoggerInterface | undefined;
407
+ /**
408
+ * List of events that can be triggered. Powered by $hook().
409
+ */
410
+ protected events: Record<string, Array<Hook>>;
411
+ constructor(logFn?: () => LoggerInterface | undefined);
412
+ protected get log(): LoggerInterface | undefined;
413
+ /**
414
+ * Registers a hook for the specified event.
415
+ */
416
+ on<T extends keyof Hooks>(event: T, hookOrFunc: Hook<T> | ((payload: Hooks[T]) => Async<void>)): () => void;
417
+ /**
418
+ * Emits the specified event with the given payload.
419
+ */
420
+ emit<T extends keyof Hooks>(func: T, payload: Hooks[T], options?: {
421
+ /**
422
+ * If true, the hooks will be executed in reverse order.
423
+ * This is useful for "stop" hooks that should be executed in reverse order.
424
+ *
425
+ * @default false
426
+ */
427
+ reverse?: boolean;
428
+ /**
429
+ * If true, the hooks will be logged with their execution time.
430
+ *
431
+ * @default false
432
+ */
433
+ log?: boolean;
434
+ /**
435
+ * If true, errors will be caught and logged instead of throwing.
436
+ *
437
+ * @default false
438
+ */
439
+ catch?: boolean;
440
+ }): Promise<void>;
441
+ }
442
+ //#endregion
443
+ //#region ../alepha/src/core/descriptors/$atom.d.ts
444
+ type AtomOptions<T extends TAtomObject, N extends string> = {
445
+ name: N;
446
+ schema: T;
447
+ description?: string;
448
+ } & (T extends TOptionalAdd<T> ? {
449
+ default?: Static$1<T>;
450
+ } : {
451
+ default: Static$1<T>;
452
+ });
453
+ declare class Atom<T extends TAtomObject = TObject$1, N extends string = string> {
454
+ readonly options: AtomOptions<T, N>;
455
+ get schema(): T;
456
+ get key(): N;
457
+ constructor(options: AtomOptions<T, N>);
458
+ }
459
+ type TAtomObject = TObject$1<any> | TArray;
460
+ type AtomStatic<T extends TAtomObject> = T extends TOptionalAdd<T> ? Static$1<T> | undefined : Static$1<T>;
461
+ //#endregion
462
+ //#region ../alepha/src/core/providers/StateManager.d.ts
463
+ interface AtomWithValue {
464
+ atom: Atom;
465
+ value: unknown;
466
+ }
467
+ declare class StateManager<State$1 extends object = State> {
468
+ protected readonly als: AlsProvider;
469
+ protected readonly events: EventManager;
470
+ protected readonly codec: JsonSchemaCodec;
471
+ protected readonly atoms: Map<keyof State$1, Atom<TObject<typebox0.TProperties>, string>>;
472
+ protected store: Partial<State$1>;
473
+ constructor(store?: Partial<State$1>);
474
+ getAtoms(context?: boolean): Array<AtomWithValue>;
475
+ register(atom: Atom<any>): this;
476
+ /**
477
+ * Get a value from the state with proper typing
478
+ */
479
+ get<T extends TAtomObject>(target: Atom<T>): Static$1<T>;
480
+ get<Key extends keyof State$1>(target: Key): State$1[Key] | undefined;
481
+ /**
482
+ * Set a value in the state
483
+ */
484
+ set<T extends TAtomObject>(target: Atom<T>, value: AtomStatic<T>): this;
485
+ set<Key extends keyof State$1>(target: Key, value: State$1[Key] | undefined): this;
486
+ /**
487
+ * Mutate a value in the state.
488
+ */
489
+ mut<T extends TObject>(target: Atom<T>, mutator: (current: Static$1<T>) => Static$1<T>): this;
490
+ mut<Key extends keyof State$1>(target: Key, mutator: (current: State$1[Key] | undefined) => State$1[Key] | undefined): this;
491
+ /**
492
+ * Check if a key exists in the state
493
+ */
494
+ has<Key extends keyof State$1>(key: Key): boolean;
495
+ /**
496
+ * Delete a key from the state (set to undefined)
497
+ */
498
+ del<Key extends keyof State$1>(key: Key): this;
499
+ /**
500
+ * Push a value to an array in the state
501
+ */
502
+ push<Key extends keyof OnlyArray<State$1>>(key: Key, value: NonNullable<State$1[Key]> extends Array<infer U> ? U : never): this;
503
+ /**
504
+ * Clear all state
505
+ */
506
+ clear(): this;
507
+ /**
508
+ * Get all keys that exist in the state
509
+ */
510
+ keys(): (keyof State$1)[];
511
+ }
512
+ type OnlyArray<T extends object> = { [K in keyof T]: NonNullable<T[K]> extends Array<any> ? K : never };
513
+ //#endregion
514
+ //#region ../alepha/src/core/Alepha.d.ts
515
+ /**
516
+ * Core container of the Alepha framework.
517
+ *
518
+ * It is responsible for managing the lifecycle of services,
519
+ * handling dependency injection,
520
+ * and providing a unified interface for the application.
521
+ *
522
+ * @example
523
+ * ```ts
524
+ * import { Alepha, run } from "alepha";
525
+ *
526
+ * class MyService {
527
+ * // business logic here
528
+ * }
529
+ *
530
+ * const alepha = Alepha.create({
531
+ * // state, env, and other properties
532
+ * })
533
+ *
534
+ * alepha.with(MyService);
535
+ *
536
+ * run(alepha); // trigger .start (and .stop) automatically
537
+ * ```
538
+ *
539
+ * ### Alepha Factory
540
+ *
541
+ * Alepha.create() is an enhanced version of new Alepha().
542
+ * - It merges `process.env` with the provided state.env when available.
543
+ * - It populates the test hooks for Vitest or Jest environments when available.
544
+ *
545
+ * new Alepha() is fine if you don't need these helpers.
546
+ *
547
+ * ### Platforms & Environments
548
+ *
549
+ * Alepha is designed to work in various environments:
550
+ * - **Browser**: Runs in the browser, using the global `window` object.
551
+ * - **Serverless**: Runs in serverless environments like Vercel or Vite.
552
+ * - **Test**: Runs in test environments like Jest or Vitest.
553
+ * - **Production**: Runs in production environments, typically with NODE_ENV set to "production".
554
+ * * You can check the current environment using the following methods:
555
+ *
556
+ * - `isBrowser()`: Returns true if the App is running in a browser environment.
557
+ * - `isServerless()`: Returns true if the App is running in a serverless environment.
558
+ * - `isTest()`: Returns true if the App is running in a test environment.
559
+ * - `isProduction()`: Returns true if the App is running in a production environment.
560
+ *
561
+ * ### State & Environment
562
+ *
563
+ * The state of the Alepha container is stored in the `store` property.
564
+ * Most important property is `store.env`, which contains the environment variables.
565
+ *
566
+ * ```ts
567
+ * const alepha = Alepha.create({ env: { MY_VAR: "value" } });
568
+ *
569
+ * // You can access the environment variables using alepha.env
570
+ * console.log(alepha.env.MY_VAR); // "value"
571
+ *
572
+ * // But you should use $env() descriptor to get typed values from the environment.
573
+ * class App {
574
+ * env = $env(
575
+ * t.object({
576
+ * MY_VAR: t.text(),
577
+ * })
578
+ * );
579
+ * }
580
+ * ```
581
+ *
582
+ * ### Modules
583
+ *
584
+ * Modules are a way to group services together.
585
+ * You can register a module using the `$module` descriptor.
586
+ *
587
+ * ```ts
588
+ * import { $module } from "alepha";
589
+ *
590
+ * class MyLib {}
591
+ *
592
+ * const myModule = $module({
593
+ * name: "my.project.module",
594
+ * services: [MyLib],
595
+ * });
596
+ * ```
597
+ *
598
+ * Do not use modules for small applications.
599
+ *
600
+ * ### Hooks
601
+ *
602
+ * Hooks are a way to run async functions from all registered providers/services.
603
+ * You can register a hook using the `$hook` descriptor.
604
+ *
605
+ * ```ts
606
+ * import { $hook } from "alepha";
607
+ *
608
+ * class App {
609
+ * log = $logger();
610
+ * onCustomerHook = $hook({
611
+ * on: "my:custom:hook",
612
+ * handler: () => {
613
+ * this.log?.info("App is being configured");
614
+ * },
615
+ * });
616
+ * }
617
+ *
618
+ * Alepha.create()
619
+ * .with(App)
620
+ * .start()
621
+ * .then(alepha => alepha.events.emit("my:custom:hook"));
622
+ * ```
623
+ *
624
+ * Hooks are fully typed. You can create your own hooks by using module augmentation:
625
+ *
626
+ * ```ts
627
+ * declare module "alepha" {
628
+ * interface Hooks {
629
+ * "my:custom:hook": {
630
+ * arg1: string;
631
+ * }
632
+ * }
633
+ * }
634
+ * ```
635
+ *
636
+ * @module alepha
637
+ */
638
+ declare class Alepha {
639
+ /**
640
+ * Creates a new instance of the Alepha container with some helpers:
641
+ *
642
+ * - merges `process.env` with the provided state.env when available.
643
+ * - populates the test hooks for Vitest or Jest environments when available.
644
+ *
645
+ * If you are not interested about these helpers, you can use the constructor directly.
646
+ */
647
+ static create(state?: Partial<State>): Alepha;
648
+ /**
649
+ * Flag indicating whether the App won't accept any further changes.
650
+ * Pass to true when #start() is called.
651
+ */
652
+ protected locked: boolean;
653
+ /**
654
+ * True if the App has been configured.
655
+ */
656
+ protected configured: boolean;
657
+ /**
658
+ * True if the App has started.
659
+ */
660
+ protected started: boolean;
661
+ /**
662
+ * True if the App is ready.
663
+ */
664
+ protected ready: boolean;
665
+ /**
666
+ * A promise that resolves when the App has started.
667
+ */
668
+ protected starting?: PromiseWithResolvers<this>;
669
+ /**
670
+ * Initial state of the container.
671
+ *
672
+ * > Used to initialize the StateManager.
673
+ */
674
+ protected init: Partial<State>;
675
+ /**
676
+ * During the instantiation process, we keep a list of pending instantiations.
677
+ * > It allows us to detect circular dependencies.
678
+ */
679
+ protected pendingInstantiations: Service[];
680
+ /**
681
+ * Cache for environment variables.
682
+ * > It allows us to avoid parsing the same schema multiple times.
683
+ */
684
+ protected cacheEnv: Map<TSchema$1, any>;
685
+ /**
686
+ * List of modules that are registered in the container.
687
+ *
688
+ * Modules are used to group services and provide a way to register them in the container.
689
+ */
690
+ protected modules: Array<Module>;
691
+ /**
692
+ * List of service substitutions.
693
+ *
694
+ * Services registered here will be replaced by the specified service when injected.
695
+ */
696
+ protected substitutions: Map<Service, {
697
+ use: Service;
698
+ }>;
699
+ /**
700
+ * Registry of descriptors.
701
+ */
702
+ protected descriptorRegistry: Map<Service<Descriptor<{}>>, Descriptor<{}>[]>;
703
+ /**
704
+ * List of all services + how they are provided.
705
+ */
706
+ protected registry: Map<Service, ServiceDefinition>;
707
+ /**
708
+ * Node.js feature that allows to store context across asynchronous calls.
709
+ *
710
+ * This is used for logging, tracing, and other context-related features.
711
+ *
712
+ * Mocked for browser environments.
713
+ */
714
+ get context(): AlsProvider;
715
+ /**
716
+ * Event manager to handle lifecycle events and custom events.
717
+ */
718
+ get events(): EventManager;
719
+ /**
720
+ * State manager to store arbitrary values.
721
+ */
722
+ get state(): StateManager<State>;
723
+ /**
724
+ * Codec manager for encoding and decoding data with different formats.
725
+ *
726
+ * Supports multiple codec formats (JSON, Protobuf, etc.) with a unified interface.
727
+ */
728
+ get codec(): CodecManager;
729
+ /**
730
+ * Get logger instance.
731
+ */
732
+ get log(): LoggerInterface | undefined;
733
+ /**
734
+ * The environment variables for the App.
735
+ */
736
+ get env(): Readonly<Env>;
737
+ constructor(init?: Partial<State>);
738
+ /**
739
+ * True when start() is called.
740
+ *
741
+ * -> No more services can be added, it's over, bye!
742
+ */
743
+ isLocked(): boolean;
744
+ /**
745
+ * Returns whether the App is configured.
746
+ *
747
+ * It means that Alepha#configure() has been called.
748
+ *
749
+ * > By default, configure() is called automatically when start() is called, but you can also call it manually.
750
+ */
751
+ isConfigured(): boolean;
752
+ /**
753
+ * Returns whether the App has started.
754
+ *
755
+ * It means that #start() has been called but maybe not all services are ready.
756
+ */
757
+ isStarted(): boolean;
758
+ /**
759
+ * True if the App is ready. It means that Alepha is started AND ready() hook has beed called.
760
+ */
761
+ isReady(): boolean;
762
+ /**
763
+ * True if the App is running in a Continuous Integration environment.
764
+ */
765
+ isCI(): boolean;
766
+ /**
767
+ * True if the App is running in a browser environment.
768
+ */
769
+ isBrowser(): boolean;
770
+ /**
771
+ * Returns whether the App is running in Vite dev mode.
772
+ */
773
+ isViteDev(): boolean;
774
+ isBun(): boolean;
775
+ /**
776
+ * Returns whether the App is running in a serverless environment.
777
+ */
778
+ isServerless(): boolean;
779
+ /**
780
+ * Returns whether the App is in test mode. (Running in a test environment)
781
+ *
782
+ * > This is automatically set when running tests with Jest or Vitest.
783
+ */
784
+ isTest(): boolean;
785
+ /**
786
+ * Returns whether the App is in production mode. (Running in a production environment)
787
+ *
788
+ * > This is automatically set by Vite or Vercel. However, you have to set it manually when running Docker apps.
789
+ */
790
+ isProduction(): boolean;
791
+ /**
792
+ * Starts the App.
793
+ *
794
+ * - Lock any further changes to the container.
795
+ * - Run "configure" hook for all services. Descriptors will be processed.
796
+ * - Run "start" hook for all services. Providers will connect/listen/...
797
+ * - Run "ready" hook for all services. This is the point where the App is ready to serve requests.
798
+ *
799
+ * @return A promise that resolves when the App has started.
800
+ */
801
+ start(): Promise<this>;
802
+ /**
803
+ * Stops the App.
804
+ *
805
+ * - Run "stop" hook for all services.
806
+ *
807
+ * Stop will NOT reset the container.
808
+ * Stop will NOT unlock the container.
809
+ *
810
+ * > Stop is used to gracefully shut down the application, nothing more. There is no "restart".
811
+ *
812
+ * @return A promise that resolves when the App has stopped.
813
+ */
814
+ stop(): Promise<void>;
815
+ /**
816
+ * Check if entry is registered in the container.
817
+ */
818
+ has(entry: ServiceEntry, opts?: {
819
+ /**
820
+ * Check if the entry is registered in the pending instantiation stack.
821
+ *
822
+ * @default true
823
+ */
824
+ inStack?: boolean;
825
+ /**
826
+ * Check if the entry is registered in the container registry.
827
+ *
828
+ * @default true
829
+ */
830
+ inRegistry?: boolean;
831
+ /**
832
+ * Check if the entry is registered in the substitutions.
833
+ *
834
+ * @default true
835
+ */
836
+ inSubstitutions?: boolean;
837
+ /**
838
+ * Where to look for registered services.
839
+ *
840
+ * @default this.registry
841
+ */
842
+ registry?: Map<Service, ServiceDefinition>;
843
+ }): boolean;
844
+ /**
845
+ * Registers the specified service in the container.
846
+ *
847
+ * - If the service is ALREADY registered, the method does nothing.
848
+ * - If the service is NOT registered, a new instance is created and registered.
849
+ *
850
+ * Method is chainable, so you can register multiple services in a single call.
851
+ *
852
+ * > ServiceEntry allows to provide a service **substitution** feature.
853
+ *
854
+ * @example
855
+ * ```ts
856
+ * class A { value = "a"; }
857
+ * class B { value = "b"; }
858
+ * class M { a = $inject(A); }
859
+ *
860
+ * Alepha.create().with({ provide: A, use: B }).get(M).a.value; // "b"
861
+ * ```
862
+ *
863
+ * > **Substitution** is an advanced feature that allows you to replace a service with another service.
864
+ * > It's useful for testing or for providing different implementations of a service.
865
+ * > If you are interested in configuring a service, use Alepha#configure() instead.
866
+ *
867
+ * @param serviceEntry - The service to register in the container.
868
+ * @return Current instance of Alepha.
869
+ */
870
+ with<T extends object>(serviceEntry: ServiceEntry<T> | {
871
+ default: ServiceEntry<T>;
872
+ }): this;
873
+ /**
874
+ * Get an instance of the specified service from the container.
875
+ *
876
+ * @see {@link InjectOptions} for the available options.
877
+ */
878
+ inject<T extends object>(service: Service<T> | string, opts?: InjectOptions<T>): T;
879
+ /**
880
+ * Applies environment variables to the provided schema and state object.
881
+ *
882
+ * It replaces also all templated $ENV inside string values.
883
+ *
884
+ * @param schema - The schema object to apply environment variables to.
885
+ * @return The schema object with environment variables applied.
886
+ */
887
+ parseEnv<T extends TObject>(schema: T): Static<T>;
888
+ /**
889
+ * Dump the current dependency graph of the App.
890
+ *
891
+ * This method returns a record where the keys are the names of the services.
892
+ */
893
+ graph(): Record<string, {
894
+ from: string[];
895
+ as?: string[];
896
+ module?: string;
897
+ }>;
898
+ services<T extends object>(base: Service<T>): Array<T>;
899
+ /**
900
+ * Get all descriptors of the specified type.
901
+ */
902
+ descriptors<TDescriptor extends Descriptor>(factory: {
903
+ [KIND]: InstantiableClass<TDescriptor>;
904
+ } | string): Array<TDescriptor>;
905
+ protected new<T extends object>(service: Service<T>, args?: any[]): T;
906
+ protected processDescriptor(value: Descriptor, propertyKey?: string): void;
907
+ }
908
+ interface Hook<T extends keyof Hooks = any> {
909
+ caller?: Service;
910
+ priority?: "first" | "last";
911
+ callback: (payload: Hooks[T]) => Async<void>;
912
+ }
913
+ /**
914
+ * This is how we store services in the Alepha container.
915
+ */
916
+ interface ServiceDefinition<T extends object = any> {
917
+ /**
918
+ * The instance of the class or type definition.
919
+ * Mostly used for caching / singleton but can be used for other purposes like forcing the instance.
920
+ */
921
+ instance: T;
922
+ /**
923
+ * List of classes which use this class.
924
+ */
925
+ parents: Array<Service | null>;
926
+ }
927
+ interface Env {
928
+ [key: string]: string | boolean | number | undefined;
929
+ /**
930
+ * Optional environment variable that indicates the current environment.
931
+ */
932
+ NODE_ENV?: "dev" | "test" | "production";
933
+ /**
934
+ * Optional name of the application.
935
+ */
936
+ APP_NAME?: string;
937
+ /**
938
+ * Optional root module name.
939
+ */
940
+ MODULE_NAME?: string;
941
+ }
942
+ interface State {
943
+ /**
944
+ * Environment variables for the application.
945
+ */
946
+ env?: Readonly<Env>;
947
+ /**
948
+ * Logger instance to be used by the Alepha container.
949
+ *
950
+ * @internal
951
+ */
952
+ "alepha.logger"?: LoggerInterface;
953
+ /**
954
+ * If defined, the Alepha container will only register this service and its dependencies.
955
+ */
956
+ "alepha.target"?: Service;
957
+ /**
958
+ * Bind to Vitest 'beforeAll' hook.
959
+ * Used for testing purposes.
960
+ * This is automatically attached if Alepha#create() detects a test environment and global 'beforeAll' is available.
961
+ */
962
+ "alepha.test.beforeAll"?: (run: any) => any;
963
+ /**
964
+ * Bind to Vitest 'afterAll' hook.
965
+ * Used for testing purposes.
966
+ * This is automatically attached if Alepha#create() detects a test environment and global 'afterAll' is available.
967
+ */
968
+ "alepha.test.afterAll"?: (run: any) => any;
969
+ /**
970
+ * Bind to Vitest 'afterEach' hook.
971
+ * Used for testing purposes.
972
+ * This is automatically attached if Alepha#create() detects a test environment and global 'afterEach' is available.
973
+ */
974
+ "alepha.test.afterEach"?: (run: any) => any;
975
+ /**
976
+ * Bind to Vitest 'onTestFinished' hook.
977
+ * Used for testing purposes.
978
+ * This is automatically attached if Alepha#create() detects a test environment and global 'onTestFinished' is available.
979
+ */
980
+ "alepha.test.onTestFinished"?: (run: any) => any;
981
+ /**
982
+ * List of static assets to be copied to the output directory during the build process.
983
+ *
984
+ * Used for Alepha-based applications that require static assets.
985
+ *
986
+ * See alepha/vite for more details.
987
+ */
988
+ "alepha.build.assets"?: Array<string>;
989
+ }
990
+ interface Hooks {
991
+ /**
992
+ * Used for testing purposes.
993
+ */
994
+ echo: unknown;
995
+ /**
996
+ * Triggered during the configuration phase. Before the start phase.
997
+ */
998
+ configure: Alepha;
999
+ /**
1000
+ * Triggered during the start phase. When `Alepha#start()` is called.
1001
+ */
1002
+ start: Alepha;
1003
+ /**
1004
+ * Triggered during the ready phase. After the start phase.
1005
+ */
1006
+ ready: Alepha;
1007
+ /**
1008
+ * Triggered during the stop phase.
1009
+ *
1010
+ * - Stop should be called after a SIGINT or SIGTERM signal in order to gracefully shutdown the application. (@see `run()` method)
1011
+ *
1012
+ */
1013
+ stop: Alepha;
1014
+ /**
1015
+ * Triggered when a state value is mutated.
1016
+ */
1017
+ "state:mutate": {
1018
+ /**
1019
+ * The key of the state that was mutated.
1020
+ */
1021
+ key: keyof State;
1022
+ /**
1023
+ * The new value of the state.
1024
+ */
1025
+ value: any;
1026
+ /**
1027
+ * The previous value of the state.
1028
+ */
1029
+ prevValue: any;
1030
+ };
1031
+ }
1032
+ //#endregion
1033
+ //#region ../alepha/src/core/descriptors/$hook.d.ts
1034
+ interface HookOptions<T extends keyof Hooks> {
1035
+ /**
1036
+ * The name of the hook. "configure", "start", "ready", "stop", ...
1037
+ */
1038
+ on: T;
1039
+ /**
1040
+ * The handler to run when the hook is triggered.
1041
+ */
1042
+ handler: (args: Hooks[T]) => Async<any>;
1043
+ /**
1044
+ * Force the hook to run first or last on the list of hooks.
1045
+ */
1046
+ priority?: "first" | "last";
1047
+ /**
1048
+ * Empty placeholder, not implemented yet. :-)
1049
+ */
1050
+ before?: object | Array<object>;
1051
+ /**
1052
+ * Empty placeholder, not implemented yet. :-)
1053
+ */
1054
+ after?: object | Array<object>;
1055
+ }
1056
+ declare class HookDescriptor<T extends keyof Hooks> extends Descriptor<HookOptions<T>> {
1057
+ called: number;
1058
+ protected onInit(): void;
1059
+ }
1060
+ //#endregion
1061
+ //#region ../alepha/src/core/schemas/pageSchema.d.ts
1062
+ declare const pageMetadataSchema: TObject$1<{
1063
+ number: TInteger;
1064
+ size: TInteger;
1065
+ offset: TInteger;
1066
+ numberOfElements: TInteger;
1067
+ totalElements: TOptional<TInteger>;
1068
+ totalPages: TOptional<TInteger>;
1069
+ isEmpty: TBoolean;
1070
+ isFirst: TBoolean;
1071
+ isLast: TBoolean;
1072
+ sort: TOptional<TObject$1<{
1073
+ sorted: TBoolean;
1074
+ fields: TArray$1<TObject$1<{
1075
+ field: TString;
1076
+ direction: TUnsafe<"asc" | "desc">;
1077
+ }>>;
1078
+ }>>;
1079
+ }>;
1080
+ type TPage<T extends TObject$1 | TRecord> = TObject$1<{
1081
+ content: TArray$1<T>;
1082
+ page: typeof pageMetadataSchema;
1083
+ }>;
1084
+ declare module "alepha" {
1085
+ interface TypeProvider {
1086
+ /**
1087
+ * Create a schema for a paginated response.
1088
+ */
1089
+ page<T extends TObject$1 | TRecord>(itemSchema: T): TPage<T>;
1090
+ }
1091
+ }
1092
+ //#endregion
1093
+ //#region ../alepha/src/logger/schemas/logEntrySchema.d.ts
1094
+ declare const logEntrySchema: TObject$1<{
1095
+ level: TUnsafe<"SILENT" | "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR">;
1096
+ message: TString;
1097
+ service: TString;
1098
+ module: TString;
1099
+ context: TOptional<TString>;
1100
+ app: TOptional<TString>;
1101
+ data: TOptional<TAny>;
1102
+ timestamp: TNumber;
1103
+ }>;
1104
+ type LogEntry = Static$1<typeof logEntrySchema>;
1105
+ //#endregion
1106
+ //#region ../alepha/src/datetime/providers/DateTimeProvider.d.ts
1107
+ type DateTime = DayjsApi.Dayjs;
1108
+ type Duration = dayjsDuration.Duration;
1109
+ type DurationLike = number | dayjsDuration.Duration | [number, ManipulateType];
1110
+ declare class DateTimeProvider {
1111
+ static PLUGINS: Array<PluginFunc<any>>;
1112
+ protected alepha: Alepha;
1113
+ protected ref: DateTime | null;
1114
+ protected readonly timeouts: Timeout[];
1115
+ protected readonly intervals: Interval[];
1116
+ constructor();
1117
+ protected readonly onStart: HookDescriptor<"start">;
1118
+ protected readonly onStop: HookDescriptor<"stop">;
1119
+ setLocale(locale: string): void;
1120
+ isDateTime(value: unknown): value is DateTime;
1121
+ /**
1122
+ * Create a new UTC DateTime instance.
1123
+ */
1124
+ utc(date: string | number | Date | Dayjs | null | undefined): DateTime;
1125
+ /**
1126
+ * Create a new DateTime instance.
1127
+ */
1128
+ of(date: string | number | Date | Dayjs | null | undefined): DateTime;
1129
+ /**
1130
+ * Get the current date as a string.
1131
+ */
1132
+ toISOString(date?: Date | string | DateTime): string;
1133
+ /**
1134
+ * Get the current date.
1135
+ */
1136
+ now(): DateTime;
1137
+ /**
1138
+ * Get the current date as a string.
1139
+ *
1140
+ * This is much faster than `DateTimeProvider.now().toISOString()` as it avoids creating a DateTime instance.
1141
+ */
1142
+ nowISOString(): string;
1143
+ /**
1144
+ * Get the current date as milliseconds since epoch.
1145
+ *
1146
+ * This is much faster than `DateTimeProvider.now().valueOf()` as it avoids creating a DateTime instance.
1147
+ */
1148
+ nowMillis(): number;
1149
+ /**
1150
+ * Get the current date as a string.
1151
+ *
1152
+ * @protected
1153
+ */
1154
+ protected getCurrentDate(): DateTime;
1155
+ /**
1156
+ * Create a new Duration instance.
1157
+ */
1158
+ duration: (duration: DurationLike, unit?: ManipulateType) => Duration;
1159
+ isDurationLike(value: unknown): value is DurationLike;
1160
+ /**
1161
+ * Return a promise that resolves after the next tick.
1162
+ * It uses `setTimeout` with 0 ms delay.
1163
+ */
1164
+ tick(): Promise<void>;
1165
+ /**
1166
+ * Wait for a certain duration.
1167
+ *
1168
+ * You can clear the timeout by using the `AbortSignal` API.
1169
+ * Aborted signal will resolve the promise immediately, it does not reject it.
1170
+ */
1171
+ wait(duration: DurationLike, options?: {
1172
+ signal?: AbortSignal;
1173
+ now?: number;
1174
+ }): Promise<void>;
1175
+ createInterval(run: () => unknown, duration: DurationLike, start?: boolean): Interval;
1176
+ /**
1177
+ * Run a callback after a certain duration.
1178
+ */
1179
+ createTimeout(callback: () => void, duration: DurationLike, now?: number): Timeout;
1180
+ clearTimeout(timeout: Timeout): void;
1181
+ clearInterval(interval: Interval): void;
1182
+ /**
1183
+ * Run a function with a deadline.
1184
+ */
1185
+ deadline<T>(fn: (signal: AbortSignal) => Promise<T>, duration: DurationLike): Promise<T>;
1186
+ /**
1187
+ * Add time to the current date.
1188
+ */
1189
+ travel(duration: DurationLike, unit?: ManipulateType): Promise<void>;
1190
+ /**
1191
+ * Stop the time.
1192
+ */
1193
+ pause(): DateTime;
1194
+ /**
1195
+ * Reset the reference date.
1196
+ */
1197
+ reset(): void;
1198
+ }
1199
+ interface Interval {
1200
+ timer?: any;
1201
+ duration: number;
1202
+ run: () => unknown;
1203
+ }
1204
+ interface Timeout {
1205
+ now: number;
1206
+ timer?: any;
1207
+ duration: number;
1208
+ callback: () => void;
1209
+ clear: () => void;
1210
+ }
1211
+ //#endregion
1212
+ //#region ../alepha/src/logger/providers/LogDestinationProvider.d.ts
1213
+ declare abstract class LogDestinationProvider {
1214
+ abstract write(message: string, entry: LogEntry): void;
1215
+ }
1216
+ //#endregion
1217
+ //#region ../alepha/src/logger/providers/LogFormatterProvider.d.ts
1218
+ declare abstract class LogFormatterProvider {
1219
+ abstract format(entry: LogEntry): string;
1220
+ }
1221
+ //#endregion
1222
+ //#region ../alepha/src/logger/services/Logger.d.ts
1223
+ declare class Logger implements LoggerInterface {
1224
+ protected readonly alepha: Alepha;
1225
+ protected readonly formatter: LogFormatterProvider;
1226
+ protected readonly destination: LogDestinationProvider;
1227
+ protected readonly dateTimeProvider: DateTimeProvider;
1228
+ protected readonly levels: Record<string, number>;
1229
+ protected readonly service: string;
1230
+ protected readonly module: string;
1231
+ protected readonly app?: string;
1232
+ protected appLogLevel: string;
1233
+ protected logLevel: LogLevel;
1234
+ constructor(service: string, module: string);
1235
+ get context(): string | undefined;
1236
+ get level(): string;
1237
+ parseLevel(level: string, app: string): LogLevel;
1238
+ private matchesPattern;
1239
+ asLogLevel(something: string): LogLevel;
1240
+ error(message: string, data?: unknown): void;
1241
+ warn(message: string, data?: unknown): void;
1242
+ info(message: string, data?: unknown): void;
1243
+ debug(message: string, data?: unknown): void;
1244
+ trace(message: string, data?: unknown): void;
1245
+ protected log(level: LogLevel, message: string, data?: unknown): void;
1246
+ protected emit(entry: LogEntry, message?: string): void;
1247
+ }
1248
+ //#endregion
1249
+ //#region ../alepha/src/logger/index.d.ts
1250
+ declare const envSchema$1: TObject$1<{
1251
+ /**
1252
+ * Default log level for the application.
1253
+ *
1254
+ * Default by environment:
1255
+ * - dev = info
1256
+ * - prod = info
1257
+ * - test = error
1258
+ *
1259
+ * Levels are: "trace" | "debug" | "info" | "warn" | "error" | "silent"
1260
+ *
1261
+ * Level can be set for a specific module:
1262
+ *
1263
+ * @example
1264
+ * LOG_LEVEL=my.module.name:debug,info # Set debug level for my.module.name and info for all other modules
1265
+ * LOG_LEVEL=alepha:trace, info # Set trace level for all alepha modules and info for all other modules
1266
+ */
1267
+ LOG_LEVEL: TOptional<TString>;
1268
+ /**
1269
+ * Built-in log formats.
1270
+ * - "json" - JSON format, useful for structured logging and log aggregation. {@link JsonFormatterProvider}
1271
+ * - "pretty" - Simple text format, human-readable, with colors. {@link SimpleFormatterProvider}
1272
+ * - "raw" - Raw format, no formatting, just the message. {@link RawFormatterProvider}
1273
+ */
1274
+ LOG_FORMAT: TOptional<TUnsafe<"json" | "pretty" | "raw">>;
1275
+ }>;
1276
+ declare module "alepha" {
1277
+ interface Env extends Partial<Static$1<typeof envSchema$1>> {}
1278
+ interface State {
1279
+ /**
1280
+ * Current log level for the application or specific modules.
1281
+ */
1282
+ "alepha.logger.level"?: string;
1283
+ }
1284
+ interface Hooks {
1285
+ log: {
1286
+ message?: string;
1287
+ entry: LogEntry;
1288
+ };
1289
+ }
1290
+ }
1291
+ //#endregion
1292
+ //#region ../alepha/src/bucket/providers/FileStorageProvider.d.ts
1293
+ declare abstract class FileStorageProvider {
1294
+ /**
1295
+ * Uploads a file to the storage.
1296
+ *
1297
+ * @param bucketName - Container name
1298
+ * @param file - File to upload
1299
+ * @param fileId - Optional file identifier. If not provided, a unique ID will be generated.
1300
+ * @return The identifier of the uploaded file.
1301
+ */
1302
+ abstract upload(bucketName: string, file: FileLike, fileId?: string): Promise<string>;
1303
+ /**
1304
+ * Downloads a file from the storage.
1305
+ *
1306
+ * @param bucketName - Container name
1307
+ * @param fileId - Identifier of the file to download
1308
+ * @return The downloaded file as a FileLike object.
1309
+ */
1310
+ abstract download(bucketName: string, fileId: string): Promise<FileLike>;
1311
+ /**
1312
+ * Check if fileId exists in the storage bucket.
1313
+ *
1314
+ * @param bucketName - Container name
1315
+ * @param fileId - Identifier of the file to stream
1316
+ * @return True is the file exists, false otherwise.
1317
+ */
1318
+ abstract exists(bucketName: string, fileId: string): Promise<boolean>;
1319
+ /**
1320
+ * Delete permanently a file from the storage.
1321
+ *
1322
+ * @param bucketName - Container name
1323
+ * @param fileId - Identifier of the file to delete
1324
+ */
1325
+ abstract delete(bucketName: string, fileId: string): Promise<void>;
1326
+ }
1327
+ //#endregion
1328
+ //#region ../alepha/src/file/providers/FileSystemProvider.d.ts
1329
+ /**
1330
+ * Options for creating a file from a URL
1331
+ */
1332
+ interface CreateFileFromUrlOptions {
1333
+ /**
1334
+ * The URL to load the file from (file://, http://, or https://)
1335
+ */
1336
+ url: string;
1337
+ /**
1338
+ * The MIME type of the file (optional, will be detected from filename if not provided)
1339
+ */
1340
+ type?: string;
1341
+ /**
1342
+ * The name of the file (optional, will be extracted from URL if not provided)
1343
+ */
1344
+ name?: string;
1345
+ }
1346
+ /**
1347
+ * Options for creating a file from a path (URL with file:// scheme)
1348
+ */
1349
+ interface CreateFileFromPathOptions {
1350
+ /**
1351
+ * The path to the file on the local filesystem
1352
+ */
1353
+ path: string;
1354
+ /**
1355
+ * The MIME type of the file (optional, will be detected from filename if not provided)
1356
+ */
1357
+ type?: string;
1358
+ /**
1359
+ * The name of the file (optional, will be extracted from URL if not provided)
1360
+ */
1361
+ name?: string;
1362
+ }
1363
+ /**
1364
+ * Options for creating a file from a Buffer
1365
+ */
1366
+ interface CreateFileFromBufferOptions {
1367
+ /**
1368
+ * The Buffer containing the file data
1369
+ */
1370
+ buffer: Buffer;
1371
+ /**
1372
+ * The MIME type of the file (optional, will be detected from name if not provided)
1373
+ */
1374
+ type?: string;
1375
+ /**
1376
+ * The name of the file (required for proper content type detection)
1377
+ */
1378
+ name?: string;
1379
+ }
1380
+ /**
1381
+ * Options for creating a file from a stream
1382
+ */
1383
+ interface CreateFileFromStreamOptions {
1384
+ /**
1385
+ * The readable stream containing the file data
1386
+ */
1387
+ stream: StreamLike;
1388
+ /**
1389
+ * The MIME type of the file (optional, will be detected from name if not provided)
1390
+ */
1391
+ type?: string;
1392
+ /**
1393
+ * The name of the file (required for proper content type detection)
1394
+ */
1395
+ name?: string;
1396
+ /**
1397
+ * The size of the file in bytes (optional)
1398
+ */
1399
+ size?: number;
1400
+ }
1401
+ /**
1402
+ * Options for creating a file from text content
1403
+ */
1404
+ interface CreateFileFromTextOptions {
1405
+ /**
1406
+ * The text content to create the file from
1407
+ */
1408
+ text: string;
1409
+ /**
1410
+ * The MIME type of the file (default: text/plain)
1411
+ */
1412
+ type?: string;
1413
+ /**
1414
+ * The name of the file (default: "file.txt")
1415
+ */
1416
+ name?: string;
1417
+ }
1418
+ interface CreateFileFromResponseOptions {
1419
+ /**
1420
+ * The Response object containing the file data
1421
+ */
1422
+ response: Response;
1423
+ /**
1424
+ * Override the name (optional, uses filename from Content-Disposition header if not provided)
1425
+ */
1426
+ name?: string;
1427
+ /**
1428
+ * Override the MIME type (optional, uses file.type if not provided)
1429
+ */
1430
+ type?: string;
1431
+ }
1432
+ /**
1433
+ * Options for creating a file from a Web File object
1434
+ */
1435
+ interface CreateFileFromWebFileOptions {
1436
+ /**
1437
+ * The Web File object
1438
+ */
1439
+ file: File;
1440
+ /**
1441
+ * Override the MIME type (optional, uses file.type if not provided)
1442
+ */
1443
+ type?: string;
1444
+ /**
1445
+ * Override the name (optional, uses file.name if not provided)
1446
+ */
1447
+ name?: string;
1448
+ /**
1449
+ * Override the size (optional, uses file.size if not provided)
1450
+ */
1451
+ size?: number;
1452
+ }
1453
+ /**
1454
+ * Options for creating a file from an ArrayBuffer
1455
+ */
1456
+ interface CreateFileFromArrayBufferOptions {
1457
+ /**
1458
+ * The ArrayBuffer containing the file data
1459
+ */
1460
+ arrayBuffer: ArrayBuffer;
1461
+ /**
1462
+ * The MIME type of the file (optional, will be detected from name if not provided)
1463
+ */
1464
+ type?: string;
1465
+ /**
1466
+ * The name of the file (required for proper content type detection)
1467
+ */
1468
+ name?: string;
1469
+ }
1470
+ /**
1471
+ * Union type for all createFile options
1472
+ */
1473
+ type CreateFileOptions = CreateFileFromUrlOptions | CreateFileFromPathOptions | CreateFileFromBufferOptions | CreateFileFromStreamOptions | CreateFileFromTextOptions | CreateFileFromWebFileOptions | CreateFileFromResponseOptions | CreateFileFromArrayBufferOptions;
1474
+ /**
1475
+ * Options for rm (remove) operation
1476
+ */
1477
+ interface RmOptions {
1478
+ /**
1479
+ * If true, removes directories and their contents recursively
1480
+ */
1481
+ recursive?: boolean;
1482
+ /**
1483
+ * If true, no error will be thrown if the path does not exist
1484
+ */
1485
+ force?: boolean;
1486
+ }
1487
+ /**
1488
+ * Options for cp (copy) operation
1489
+ */
1490
+ interface CpOptions {
1491
+ /**
1492
+ * If true, copy directories recursively
1493
+ */
1494
+ recursive?: boolean;
1495
+ /**
1496
+ * If true, overwrite existing destination
1497
+ */
1498
+ force?: boolean;
1499
+ }
1500
+ /**
1501
+ * Options for mkdir operation
1502
+ */
1503
+ interface MkdirOptions {
1504
+ /**
1505
+ * If true, creates parent directories as needed
1506
+ */
1507
+ recursive?: boolean;
1508
+ /**
1509
+ * File mode (permission and sticky bits)
1510
+ */
1511
+ mode?: number;
1512
+ }
1513
+ /**
1514
+ * Options for ls (list) operation
1515
+ */
1516
+ interface LsOptions {
1517
+ /**
1518
+ * If true, list contents of directories recursively
1519
+ */
1520
+ recursive?: boolean;
1521
+ /**
1522
+ * If true, include hidden files (starting with .)
1523
+ */
1524
+ hidden?: boolean;
1525
+ }
1526
+ /**
1527
+ * FileSystem interface providing utilities for working with files.
1528
+ */
1529
+ declare abstract class FileSystemProvider {
1530
+ /**
1531
+ * Creates a FileLike object from various sources.
1532
+ *
1533
+ * @param options - Options for creating the file
1534
+ * @returns A FileLike object
1535
+ */
1536
+ abstract createFile(options: CreateFileOptions): FileLike;
1537
+ /**
1538
+ * Removes a file or directory.
1539
+ *
1540
+ * @param path - The path to remove
1541
+ * @param options - Remove options
1542
+ */
1543
+ abstract rm(path: string, options?: RmOptions): Promise<void>;
1544
+ /**
1545
+ * Copies a file or directory.
1546
+ *
1547
+ * @param src - Source path
1548
+ * @param dest - Destination path
1549
+ * @param options - Copy options
1550
+ */
1551
+ abstract cp(src: string, dest: string, options?: CpOptions): Promise<void>;
1552
+ /**
1553
+ * Moves/renames a file or directory.
1554
+ *
1555
+ * @param src - Source path
1556
+ * @param dest - Destination path
1557
+ */
1558
+ abstract mv(src: string, dest: string): Promise<void>;
1559
+ /**
1560
+ * Creates a directory.
1561
+ *
1562
+ * @param path - The directory path to create
1563
+ * @param options - Mkdir options
1564
+ */
1565
+ abstract mkdir(path: string, options?: MkdirOptions): Promise<void>;
1566
+ /**
1567
+ * Lists files in a directory.
1568
+ *
1569
+ * @param path - The directory path to list
1570
+ * @param options - List options
1571
+ * @returns Array of filenames
1572
+ */
1573
+ abstract ls(path: string, options?: LsOptions): Promise<string[]>;
1574
+ /**
1575
+ * Checks if a file or directory exists.
1576
+ *
1577
+ * @param path - The path to check
1578
+ * @returns True if the path exists, false otherwise
1579
+ */
1580
+ abstract exists(path: string): Promise<boolean>;
1581
+ /**
1582
+ * Reads the content of a file.
1583
+ *
1584
+ * @param path - The file path to read
1585
+ * @returns The file content as a Buffer
1586
+ */
1587
+ abstract readFile(path: string): Promise<Buffer>;
1588
+ /**
1589
+ * Writes data to a file.
1590
+ *
1591
+ * @param path - The file path to write to
1592
+ * @param data - The data to write (Buffer or string)
1593
+ */
1594
+ abstract writeFile(path: string, data: Uint8Array | Buffer | string | FileLike): Promise<void>;
1595
+ }
1596
+ //#endregion
1597
+ //#region ../alepha/src/file/services/FileDetector.d.ts
1598
+ interface FileTypeResult {
1599
+ /**
1600
+ * The detected MIME type
1601
+ */
1602
+ mimeType: string;
1603
+ /**
1604
+ * The detected file extension
1605
+ */
1606
+ extension: string;
1607
+ /**
1608
+ * Whether the file type was verified by magic bytes
1609
+ */
1610
+ verified: boolean;
1611
+ /**
1612
+ * The stream (potentially wrapped to allow re-reading)
1613
+ */
1614
+ stream: Readable;
1615
+ }
1616
+ /**
1617
+ * Service for detecting file types and getting content types.
1618
+ *
1619
+ * @example
1620
+ * ```typescript
1621
+ * const detector = alepha.inject(FileDetector);
1622
+ *
1623
+ * // Get content type from filename
1624
+ * const mimeType = detector.getContentType("image.png"); // "image/png"
1625
+ *
1626
+ * // Detect file type by magic bytes
1627
+ * const stream = createReadStream('image.png');
1628
+ * const result = await detector.detectFileType(stream, 'image.png');
1629
+ * console.log(result.mimeType); // 'image/png'
1630
+ * console.log(result.verified); // true if magic bytes match
1631
+ * ```
1632
+ */
1633
+ declare class FileDetector {
1634
+ /**
1635
+ * Magic byte signatures for common file formats.
1636
+ * Each signature is represented as an array of bytes or null (wildcard).
1637
+ */
1638
+ protected static readonly MAGIC_BYTES: Record<string, {
1639
+ signature: (number | null)[];
1640
+ mimeType: string;
1641
+ }[]>;
1642
+ /**
1643
+ * All possible format signatures for checking against actual file content
1644
+ */
1645
+ protected static readonly ALL_SIGNATURES: {
1646
+ signature: (number | null)[];
1647
+ mimeType: string;
1648
+ ext: string;
1649
+ }[];
1650
+ /**
1651
+ * MIME type map for file extensions.
1652
+ *
1653
+ * Can be used to get the content type of file based on its extension.
1654
+ * Feel free to add more mime types in your project!
1655
+ */
1656
+ static readonly mimeMap: Record<string, string>;
1657
+ /**
1658
+ * Reverse MIME type map for looking up extensions from MIME types.
1659
+ * Prefers shorter, more common extensions when multiple exist.
1660
+ */
1661
+ protected static readonly reverseMimeMap: Record<string, string>;
1662
+ /**
1663
+ * Returns the file extension for a given MIME type.
1664
+ *
1665
+ * @param mimeType - The MIME type to look up
1666
+ * @returns The file extension (without dot), or "bin" if not found
1667
+ *
1668
+ * @example
1669
+ * ```typescript
1670
+ * const detector = alepha.inject(FileDetector);
1671
+ * const ext = detector.getExtensionFromMimeType("image/png"); // "png"
1672
+ * const ext2 = detector.getExtensionFromMimeType("application/octet-stream"); // "bin"
1673
+ * ```
1674
+ */
1675
+ getExtensionFromMimeType(mimeType: string): string;
1676
+ /**
1677
+ * Returns the content type of file based on its filename.
1678
+ *
1679
+ * @param filename - The filename to check
1680
+ * @returns The MIME type
1681
+ *
1682
+ * @example
1683
+ * ```typescript
1684
+ * const detector = alepha.inject(FileDetector);
1685
+ * const mimeType = detector.getContentType("image.png"); // "image/png"
1686
+ * ```
1687
+ */
1688
+ getContentType(filename: string): string;
1689
+ /**
1690
+ * Detects the file type by checking magic bytes against the stream content.
1691
+ *
1692
+ * @param stream - The readable stream to check
1693
+ * @param filename - The filename (used to get the extension)
1694
+ * @returns File type information including MIME type, extension, and verification status
1695
+ *
1696
+ * @example
1697
+ * ```typescript
1698
+ * const detector = alepha.inject(FileDetector);
1699
+ * const stream = createReadStream('image.png');
1700
+ * const result = await detector.detectFileType(stream, 'image.png');
1701
+ * console.log(result.mimeType); // 'image/png'
1702
+ * console.log(result.verified); // true if magic bytes match
1703
+ * ```
1704
+ */
1705
+ detectFileType(stream: Readable, filename: string): Promise<FileTypeResult>;
1706
+ /**
1707
+ * Reads all bytes from a stream and returns the first N bytes along with a new stream containing all data.
1708
+ * This approach reads the entire stream upfront to avoid complex async handling issues.
1709
+ *
1710
+ * @protected
1711
+ */
1712
+ protected peekBytes(stream: Readable, numBytes: number): Promise<{
1713
+ buffer: Buffer;
1714
+ stream: Readable;
1715
+ }>;
1716
+ /**
1717
+ * Checks if a buffer matches a magic byte signature.
1718
+ *
1719
+ * @protected
1720
+ */
1721
+ protected matchesSignature(buffer: Buffer, signature: (number | null)[]): boolean;
1722
+ }
1723
+ //#endregion
1724
+ //#region ../alepha/src/bucket/providers/MemoryFileStorageProvider.d.ts
1725
+ declare class MemoryFileStorageProvider implements FileStorageProvider {
1726
+ readonly files: Record<string, FileLike>;
1727
+ protected readonly fileSystem: FileSystemProvider;
1728
+ protected readonly fileDetector: FileDetector;
1729
+ upload(bucketName: string, file: FileLike, fileId?: string): Promise<string>;
1730
+ download(bucketName: string, fileId: string): Promise<FileLike>;
1731
+ exists(bucketName: string, fileId: string): Promise<boolean>;
1732
+ delete(bucketName: string, fileId: string): Promise<void>;
1733
+ protected createId(): string;
1734
+ }
1735
+ //#endregion
1736
+ //#region ../alepha/src/bucket/descriptors/$bucket.d.ts
1737
+ interface BucketDescriptorOptions extends BucketFileOptions {
1738
+ /**
1739
+ * File storage provider configuration for the bucket.
1740
+ *
1741
+ * Options:
1742
+ * - **"memory"**: In-memory storage (default for development, lost on restart)
1743
+ * - **Service<FileStorageProvider>**: Custom provider class (e.g., S3FileStorageProvider, AzureBlobProvider)
1744
+ * - **undefined**: Uses the default file storage provider from dependency injection
1745
+ *
1746
+ * **Provider Selection Guidelines**:
1747
+ * - **Development**: Use "memory" for fast, simple testing without external dependencies
1748
+ * - **Production**: Use cloud providers (S3, Azure Blob, Google Cloud Storage) for scalability
1749
+ * - **Local deployment**: Use filesystem providers for on-premise installations
1750
+ * - **Hybrid**: Use different providers for different bucket types (temp files vs permanent storage)
1751
+ *
1752
+ * **Provider Capabilities**:
1753
+ * - File persistence and durability guarantees
1754
+ * - Scalability and performance characteristics
1755
+ * - Geographic distribution and CDN integration
1756
+ * - Cost implications for storage and bandwidth
1757
+ * - Backup and disaster recovery features
1758
+ *
1759
+ * @default Uses injected FileStorageProvider
1760
+ * @example "memory"
1761
+ * @example S3FileStorageProvider
1762
+ * @example AzureBlobStorageProvider
1763
+ */
1764
+ provider?: Service<FileStorageProvider> | "memory";
1765
+ /**
1766
+ * Unique name identifier for the bucket.
1767
+ *
1768
+ * This name is used for:
1769
+ * - Storage backend organization and partitioning
1770
+ * - File path generation and URL construction
1771
+ * - Logging, monitoring, and debugging
1772
+ * - Access control and permissions management
1773
+ * - Backup and replication configuration
1774
+ *
1775
+ * **Naming Conventions**:
1776
+ * - Use lowercase with hyphens for consistency
1777
+ * - Include purpose or content type in the name
1778
+ * - Avoid spaces and special characters
1779
+ * - Consider environment prefixes for deployment isolation
1780
+ *
1781
+ * If not provided, defaults to the property key where the bucket is declared.
1782
+ *
1783
+ * @example "user-avatars"
1784
+ * @example "product-images"
1785
+ * @example "legal-documents"
1786
+ * @example "temp-processing-files"
1787
+ */
1788
+ name?: string;
1789
+ }
1790
+ interface BucketFileOptions {
1791
+ /**
1792
+ * Human-readable description of the bucket's purpose and contents.
1793
+ *
1794
+ * Used for:
1795
+ * - Documentation generation and API references
1796
+ * - Developer onboarding and system understanding
1797
+ * - Monitoring dashboards and admin interfaces
1798
+ * - Compliance and audit documentation
1799
+ *
1800
+ * **Description Best Practices**:
1801
+ * - Explain what types of files this bucket stores
1802
+ * - Mention any special handling or processing requirements
1803
+ * - Include information about retention policies if applicable
1804
+ * - Note any compliance or security considerations
1805
+ *
1806
+ * @example "User profile pictures and avatar images"
1807
+ * @example "Product catalog images with automated thumbnail generation"
1808
+ * @example "Legal documents requiring long-term retention"
1809
+ * @example "Temporary files for data processing workflows"
1810
+ */
1811
+ description?: string;
1812
+ /**
1813
+ * Array of allowed MIME types for files uploaded to this bucket.
1814
+ *
1815
+ * When specified, only files with these exact MIME types will be accepted.
1816
+ * Files with disallowed MIME types will be rejected with an InvalidFileError.
1817
+ *
1818
+ * **MIME Type Categories**:
1819
+ * - Images: "image/jpeg", "image/png", "image/gif", "image/webp", "image/svg+xml"
1820
+ * - Documents: "application/pdf", "text/plain", "text/csv"
1821
+ * - Office: "application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
1822
+ * - Archives: "application/zip", "application/x-tar", "application/gzip"
1823
+ * - Media: "video/mp4", "audio/mpeg", "audio/wav"
1824
+ *
1825
+ * **Security Considerations**:
1826
+ * - Always validate MIME types for user uploads
1827
+ * - Be cautious with executable file types
1828
+ * - Consider using allow-lists rather than deny-lists
1829
+ * - Remember that MIME types can be spoofed by malicious users
1830
+ *
1831
+ * If not specified, all MIME types are allowed (not recommended for user uploads).
1832
+ *
1833
+ * @example ["image/jpeg", "image/png"] // Only JPEG and PNG images
1834
+ * @example ["application/pdf", "text/plain"] // Documents only
1835
+ * @example ["video/mp4", "video/webm"] // Video files
1836
+ */
1837
+ mimeTypes?: string[];
1838
+ /**
1839
+ * Maximum file size allowed in megabytes (MB).
1840
+ *
1841
+ * Files larger than this limit will be rejected with an InvalidFileError.
1842
+ * This helps prevent:
1843
+ * - Storage quota exhaustion
1844
+ * - Memory issues during file processing
1845
+ * - Long upload times and timeouts
1846
+ * - Abuse of storage resources
1847
+ *
1848
+ * **Size Guidelines by File Type**:
1849
+ * - Profile images: 1-5 MB
1850
+ * - Product photos: 5-10 MB
1851
+ * - Documents: 10-50 MB
1852
+ * - Video files: 50-500 MB
1853
+ * - Data files: 100-1000 MB
1854
+ *
1855
+ * **Considerations**:
1856
+ * - Consider your storage costs and limits
1857
+ * - Factor in network upload speeds for users
1858
+ * - Account for processing requirements (thumbnails, compression)
1859
+ * - Set reasonable limits based on actual use cases
1860
+ *
1861
+ * @default 10 MB
1862
+ *
1863
+ * @example 1 // 1MB for small images
1864
+ * @example 25 // 25MB for documents
1865
+ * @example 100 // 100MB for media files
1866
+ */
1867
+ maxSize?: number;
1868
+ }
1869
+ declare class BucketDescriptor extends Descriptor<BucketDescriptorOptions> {
1870
+ readonly provider: FileStorageProvider | MemoryFileStorageProvider;
1871
+ private readonly fileSystem;
1872
+ get name(): string;
1873
+ /**
1874
+ * Uploads a file to the bucket.
1875
+ */
1876
+ upload(file: FileLike, options?: BucketFileOptions): Promise<string>;
1877
+ /**
1878
+ * Delete permanently a file from the bucket.
1879
+ */
1880
+ delete(fileId: string, skipHook?: boolean): Promise<void>;
1881
+ /**
1882
+ * Checks if a file exists in the bucket.
1883
+ */
1884
+ exists(fileId: string): Promise<boolean>;
1885
+ /**
1886
+ * Downloads a file from the bucket.
1887
+ */
1888
+ download(fileId: string): Promise<FileLike>;
1889
+ protected $provider(): FileStorageProvider | MemoryFileStorageProvider;
1890
+ }
1891
+ interface BucketFileOptions {
1892
+ /**
1893
+ * Optional description of the bucket.
1894
+ */
1895
+ description?: string;
1896
+ /**
1897
+ * Allowed MIME types.
1898
+ */
1899
+ mimeTypes?: string[];
1900
+ /**
1901
+ * Maximum size of the files in the bucket.
1902
+ *
1903
+ * @default 10
1904
+ */
1905
+ maxSize?: number;
1906
+ }
1907
+ //#endregion
1908
+ //#region ../alepha/src/bucket/providers/LocalFileStorageProvider.d.ts
1909
+ /**
1910
+ * Local file storage configuration atom
1911
+ */
1912
+ declare const localFileStorageOptions: Atom<TObject$1<{
1913
+ storagePath: TString;
1914
+ }>, "alepha.bucket.local.options">;
1915
+ type LocalFileStorageProviderOptions = Static$1<typeof localFileStorageOptions.schema>;
1916
+ declare module "alepha" {
1917
+ interface State {
1918
+ [localFileStorageOptions.key]: LocalFileStorageProviderOptions;
1919
+ }
1920
+ }
1921
+ //#endregion
1922
+ //#region ../alepha/src/bucket/index.d.ts
1923
+ declare module "alepha" {
1924
+ interface Hooks {
1925
+ /**
1926
+ * Triggered when a file is uploaded to a bucket.
1927
+ * Can be used to perform actions after a file is uploaded, like creating a database record!
1928
+ */
1929
+ "bucket:file:uploaded": {
1930
+ id: string;
1931
+ file: FileLike;
1932
+ bucket: BucketDescriptor;
1933
+ options: BucketFileOptions;
1934
+ };
1935
+ /**
1936
+ * Triggered when a file is deleted from a bucket.
1937
+ */
1938
+ "bucket:file:deleted": {
1939
+ id: string;
1940
+ bucket: BucketDescriptor;
1941
+ };
1942
+ }
1943
+ }
1944
+ /**
1945
+ * Provides file storage capabilities through declarative bucket descriptors with support for multiple storage backends.
1946
+ *
1947
+ * The bucket module enables unified file operations across different storage systems using the `$bucket` descriptor
1948
+ * on class properties. It abstracts storage provider differences, offering consistent APIs for local filesystem,
1949
+ * cloud storage, or in-memory storage for testing environments.
1950
+ *
1951
+ * @see {@link $bucket}
1952
+ * @see {@link FileStorageProvider}
1953
+ * @module alepha.bucket
1954
+ */
1955
+ //#endregion
9
1956
  //#region src/providers/VercelBlobProvider.d.ts
10
1957
  declare class VercelBlobApi {
11
1958
  put: typeof put;
@@ -14,29 +1961,29 @@ declare class VercelBlobApi {
14
1961
  }
15
1962
  //#endregion
16
1963
  //#region src/providers/VercelFileStorageProvider.d.ts
17
- declare const envSchema: alepha1.TObject<{
18
- BLOB_READ_WRITE_TOKEN: alepha1.TString;
1964
+ declare const envSchema: TObject$1<{
1965
+ BLOB_READ_WRITE_TOKEN: TString;
19
1966
  }>;
20
1967
  declare module "alepha" {
21
- interface Env extends Partial<Static<typeof envSchema>> {}
1968
+ interface Env extends Partial<Static$1<typeof envSchema>> {}
22
1969
  }
23
1970
  /**
24
1971
  * Vercel Blob Storage implementation of File Storage Provider.
25
1972
  */
26
1973
  declare class VercelFileStorageProvider implements FileStorageProvider {
27
- protected readonly log: alepha_logger0.Logger;
1974
+ protected readonly log: Logger;
28
1975
  protected readonly env: {
29
1976
  BLOB_READ_WRITE_TOKEN: string;
30
1977
  };
31
1978
  protected readonly alepha: Alepha;
32
1979
  protected readonly time: DateTimeProvider;
33
1980
  protected readonly fileSystem: FileSystemProvider;
1981
+ protected readonly fileDetector: FileDetector;
34
1982
  protected readonly stores: Set<string>;
35
1983
  protected readonly vercelBlobApi: VercelBlobApi;
36
- protected readonly metadataService: FileMetadataService;
37
- protected readonly onStart: alepha1.HookDescriptor<"start">;
1984
+ protected readonly onStart: HookDescriptor<"start">;
38
1985
  convertName(name: string): string;
39
- protected createId(): string;
1986
+ protected createId(mimeType: string): string;
40
1987
  upload(bucketName: string, file: FileLike, fileId?: string): Promise<string>;
41
1988
  download(bucketName: string, fileId: string): Promise<FileLike>;
42
1989
  exists(bucketName: string, fileId: string): Promise<boolean>;
@@ -50,7 +1997,7 @@ declare class VercelFileStorageProvider implements FileStorageProvider {
50
1997
  * @see {@link VercelFileStorageProvider}
51
1998
  * @module alepha.bucket.vercel
52
1999
  */
53
- declare const AlephaBucketVercel: alepha1.Service<alepha1.Module>;
2000
+ declare const AlephaBucketVercel: Service<Module>;
54
2001
  //#endregion
55
2002
  export { AlephaBucketVercel, VercelFileStorageProvider };
56
2003
  //# sourceMappingURL=index.d.ts.map