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