alepha 0.10.6 → 0.11.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/core.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { AsyncLocalStorage } from "node:async_hooks";
2
- import { Validator } from "typebox/compile";
3
2
  import * as TypeBox from "typebox";
4
- import { Static, Static as Static$1, StaticDecode, StaticEncode, TAny, TAny as TAny$1, TArray, TArray as TArray$1, TArrayOptions, TBigInt, TBoolean, TBoolean as TBoolean$1, TInteger, TInteger as TInteger$1, TKeysToIndexer, TNull, TNull as TNull$1, TNumber, TNumber as TNumber$1, TNumberOptions, TNumberOptions as TNumberOptions$1, TObject, TObject as TObject$1, TObjectOptions, TObjectOptions as TObjectOptions$1, TOptional, TOptionalAdd, TOptionalAdd as TOptionalAdd$1, TPick, TProperties, TProperties as TProperties$1, TRecord, TRecord as TRecord$1, TSchema, TSchema as TSchema$1, TSchemaOptions, TString, TString as TString$1, TStringOptions, TStringOptions as TStringOptions$1, TTuple, TUnion, TUnion as TUnion$1, TUnsafe, TVoid } from "typebox";
3
+ import { Static as Static$1, StaticDecode, StaticDecode as Static, StaticDecode as StaticDecode$1, StaticEncode, StaticEncode as StaticEncode$1, TAny, TAny as TAny$1, TArray, TArray as TArray$1, TArrayOptions, TBigInt, TBoolean, TBoolean as TBoolean$1, TInteger, TInteger as TInteger$1, TKeysToIndexer, TKeysToIndexer as TKeysToIndexer$1, TNull, TNull as TNull$1, TNumber, TNumber as TNumber$1, TNumberOptions, TNumberOptions as TNumberOptions$1, TObject, TObject as TObject$1, TObjectOptions, TObjectOptions as TObjectOptions$1, TOmit, TOptional, TOptionalAdd, TOptionalAdd as TOptionalAdd$1, TPick, TPick as TPick$1, TProperties, TProperties as TProperties$1, TRecord, TRecord as TRecord$1, TSchema, TSchema as TSchema$1, TSchemaOptions, TString, TString as TString$1, TStringOptions, TStringOptions as TStringOptions$1, TTuple, TUnion, TUnion as TUnion$1, TUnsafe, TUnsafe as TUnsafe$1, TVoid } from "typebox";
4
+ import { Validator } from "typebox/compile";
5
5
  import TypeBoxFormat from "typebox/format";
6
6
  import * as TypeBoxValue from "typebox/value";
7
7
  import { Readable } from "node:stream";
@@ -28,7 +28,8 @@ declare const MODULE: unique symbol;
28
28
  /**
29
29
  * In Alepha, a service is a class that can be instantiated or an abstract class. Nothing more, nothing less...
30
30
  */
31
- type Service<T extends object = any> = InstantiableClass<T> | AbstractClass<T>;
31
+ type Service<T extends object = any> = InstantiableClass<T> | AbstractClass<T> | RunFunction<T>;
32
+ type RunFunction<T extends object = any> = (...args: any[]) => T | void;
32
33
  type InstantiableClass<T extends object = any> = new (...args: any[]) => T;
33
34
  /**
34
35
  * Abstract class is a class that cannot be instantiated directly!
@@ -69,6 +70,7 @@ interface ServiceSubstitution<T extends object = any> {
69
70
  * And yes, you declare the *type* of the service, not the *instance*.
70
71
  */
71
72
  type ServiceEntry<T extends object = any> = Service<T> | ServiceSubstitution<T>;
73
+ declare function isClass(func: any): func is InstantiableClass;
72
74
  //#endregion
73
75
  //#region src/helpers/descriptor.d.ts
74
76
  interface DescriptorArgs<T extends object = {}> {
@@ -257,45 +259,6 @@ interface LoggerInterface {
257
259
  error(message: string, data?: unknown): void;
258
260
  }
259
261
  //#endregion
260
- //#region src/helpers/EventManager.d.ts
261
- declare class EventManager {
262
- protected logFn?: () => LoggerInterface | undefined;
263
- /**
264
- * List of events that can be triggered. Powered by $hook().
265
- */
266
- protected events: Record<string, Array<Hook>>;
267
- constructor(logFn?: () => LoggerInterface | undefined);
268
- protected get log(): LoggerInterface | undefined;
269
- /**
270
- * Registers a hook for the specified event.
271
- */
272
- on<T extends keyof Hooks>(event: T, hookOrFunc: Hook<T> | ((payload: Hooks[T]) => Async<void>)): () => void;
273
- /**
274
- * Emits the specified event with the given payload.
275
- */
276
- emit<T extends keyof Hooks>(func: keyof Hooks, payload: Hooks[T], options?: {
277
- /**
278
- * If true, the hooks will be executed in reverse order.
279
- * This is useful for "stop" hooks that should be executed in reverse order.
280
- *
281
- * @default false
282
- */
283
- reverse?: boolean;
284
- /**
285
- * If true, the hooks will be logged with their execution time.
286
- *
287
- * @default false
288
- */
289
- log?: boolean;
290
- /**
291
- * If true, errors will be caught and logged instead of throwing.
292
- *
293
- * @default false
294
- */
295
- catch?: boolean;
296
- }): Promise<void>;
297
- }
298
- //#endregion
299
262
  //#region src/providers/AlsProvider.d.ts
300
263
  type AsyncLocalStorageData = any;
301
264
  declare class AlsProvider {
@@ -309,36 +272,15 @@ declare class AlsProvider {
309
272
  set<T>(key: string, value: T): void;
310
273
  }
311
274
  //#endregion
312
- //#region src/helpers/StateManager.d.ts
313
- declare class StateManager<S extends Record<string, any> = State> {
314
- protected store: Partial<S>;
315
- protected readonly events?: EventManager;
316
- protected readonly als?: AlsProvider;
317
- constructor(events?: EventManager, als?: AlsProvider);
318
- /**
319
- * Get a value from the state with proper typing
320
- */
321
- get<Key extends keyof S>(key: Key): S[Key] | undefined;
322
- /**
323
- * Set a value in the state
324
- */
325
- set<Key extends keyof S>(key: Key, value: S[Key] | undefined): this;
326
- /**
327
- * Check if a key exists in the state
328
- */
329
- has<Key extends keyof S>(key: Key): boolean;
330
- /**
331
- * Delete a key from the state (set to undefined)
332
- */
333
- del<Key extends keyof S>(key: Key): this;
334
- /**
335
- * Clear all state
336
- */
337
- clear(): this;
338
- /**
339
- * Get all keys that exist in the state
340
- */
341
- keys(): (keyof S)[];
275
+ //#region src/providers/Json.d.ts
276
+ /**
277
+ * Mimics the JSON global object with stringify and parse methods.
278
+ *
279
+ * Used across the codebase via dependency injection.
280
+ */
281
+ declare class Json {
282
+ stringify(value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string;
283
+ parse(text: string, reviver?: (this: any, key: string, value: any) => any): any;
342
284
  }
343
285
  //#endregion
344
286
  //#region src/helpers/FileLike.d.ts
@@ -398,20 +340,20 @@ interface FileLike {
398
340
  /**
399
341
  * TypeBox view of FileLike.
400
342
  */
401
- type TFile = TUnsafe<FileLike>;
343
+ type TFile = TUnsafe$1<FileLike>;
402
344
  declare const isTypeFile: (value: TSchema$1) => value is TFile;
403
345
  declare const isFileLike: (value: any) => value is FileLike;
404
346
  type StreamLike = ReadableStream | ReadableStream$1 | Readable | NodeJS.ReadableStream;
405
- type TStream = TUnsafe<StreamLike>;
347
+ type TStream = TUnsafe$1<StreamLike>;
406
348
  //#endregion
407
349
  //#region src/providers/TypeProvider.d.ts
408
350
  declare const isUUID: typeof TypeBoxFormat.IsUuid;
409
- declare const isDateTime: typeof TypeBoxFormat.IsDateTime;
410
- declare const isDate: typeof TypeBoxFormat.IsDate;
411
351
  declare const isEmail: typeof TypeBoxFormat.IsEmail;
412
352
  declare const isURL: typeof TypeBoxFormat.IsUrl;
413
353
  declare class TypeGuard {
414
- isSchema: typeof TypeBox.IsSchema;
354
+ isFile: (value: TSchema$1) => value is TFile;
355
+ isBigInt: (value: TSchema$1) => value is TString$1;
356
+ isUUID: (value: TSchema$1) => value is TString$1;
415
357
  isObject: typeof TypeBox.IsObject;
416
358
  isNumber: typeof TypeBox.IsNumber;
417
359
  isString: typeof TypeBox.IsString;
@@ -427,11 +369,8 @@ declare class TypeGuard {
427
369
  isRecord: typeof TypeBox.IsRecord;
428
370
  isTuple: typeof TypeBox.IsTuple;
429
371
  isVoid: typeof TypeBox.IsVoid;
430
- isFile: (value: TSchema$1) => value is TFile;
431
- isBigInt: (value: TSchema$1) => value is TString$1;
432
- isDate: (value: TSchema$1) => value is TString$1;
433
- isDatetime: (value: TSchema$1) => value is TString$1;
434
- isUUID: (value: TSchema$1) => value is TString$1;
372
+ isLiteral: typeof TypeBox.IsLiteral;
373
+ isSchema: typeof TypeBox.IsSchema;
435
374
  }
436
375
  declare module "typebox" {
437
376
  interface TString {
@@ -445,6 +384,7 @@ declare module "typebox" {
445
384
  }
446
385
  declare class TypeProvider {
447
386
  static format: typeof TypeBoxFormat;
387
+ static setLocale(locale: string): void;
448
388
  static isValidBigInt(value: string | number): boolean;
449
389
  /**
450
390
  * Default maximum length for strings.
@@ -494,12 +434,13 @@ declare class TypeProvider {
494
434
  void: typeof TypeBox.Void;
495
435
  undefined: typeof TypeBox.Undefined;
496
436
  record: typeof TypeBox.Record;
497
- omit: typeof TypeBox.Omit;
498
437
  partial: typeof TypeBox.Partial;
499
438
  union: typeof TypeBox.Union;
500
- pick: typeof TypeBox.Pick;
501
439
  tuple: typeof TypeBox.Tuple;
502
440
  interface: typeof TypeBox.Interface;
441
+ null: typeof TypeBox.Null;
442
+ const: typeof TypeBox.Literal;
443
+ codec: typeof TypeBox.Codec;
503
444
  /**
504
445
  * Type guards to check the type of schema.
505
446
  * This is not a runtime type check, but a compile-time type guard.
@@ -512,6 +453,8 @@ declare class TypeProvider {
512
453
  * ```
513
454
  */
514
455
  readonly schema: TypeGuard;
456
+ pick<T extends TObject$1, Indexer extends PropertyKey[]>(schema: T, keys: [...Indexer], options?: TObjectOptions$1): TPick$1<T, TKeysToIndexer$1<Indexer>>;
457
+ omit<T extends TObject$1, Indexer extends PropertyKey[]>(schema: T, keys: [...Indexer], options?: TObjectOptions$1): TOmit<T, TKeysToIndexer$1<Indexer>>;
515
458
  /**
516
459
  * Create a schema for an object.
517
460
  * By default, additional properties are not allowed.
@@ -536,7 +479,7 @@ declare class TypeProvider {
536
479
  * Create a schema for a string.
537
480
  * For db or input fields, consider using `t.text()` instead, which has length limits.
538
481
  *
539
- * If you need a string with specific format (e.g. email, uuid, date), consider using the corresponding method (e.g. `t.email()`, `t.uuid()`, `t.date()`).
482
+ * If you need a string with specific format (e.g. email, uuid), consider using the corresponding method (e.g. `t.email()`, `t.uuid()`).
540
483
  */
541
484
  string(options?: TStringOptions$1): TString$1;
542
485
  /**
@@ -563,6 +506,10 @@ declare class TypeProvider {
563
506
  * Create a schema for a signed 32-bit integer.
564
507
  */
565
508
  int(options?: TNumberOptions$1): TInteger$1;
509
+ /**
510
+ * @alias `t.int()`
511
+ */
512
+ integer(options?: TNumberOptions$1): TInteger$1;
566
513
  /**
567
514
  * Mimic a signed 64-bit integer.
568
515
  *
@@ -592,26 +539,20 @@ declare class TypeProvider {
592
539
  /**
593
540
  * Create a schema for a string enum.
594
541
  */
595
- enum<T extends string[]>(values: [...T], options?: TStringOptions$1): TUnsafe<T[number]>;
542
+ enum<T extends string[]>(values: [...T], options?: TStringOptions$1): TUnsafe$1<T[number]>;
596
543
  /**
597
544
  * Create a schema for a bigint.
598
545
  * This is NOT a BigInt object, but a string that represents a bigint.
599
546
  */
600
- bigint(options?: TStringOptions$1): TString$1;
601
- /**
602
- * Create a schema for a datetime.
603
- * This is NOT a Date object, but a string in ISO 8601 format.
604
- */
605
- datetime(options?: TStringOptions$1): TString$1;
547
+ bigint(options?: TStringOptions$1): TypeBox.TCodec<TString$1, bigint>;
606
548
  /**
607
- * Create a schema for a date.
608
- * This is NOT a Date object, but a string in ISO 8601 date format (YYYY-MM-DD).
549
+ * Create a schema for a url.
609
550
  */
610
- date(options?: TStringOptions$1): TString$1;
551
+ url(options?: TStringOptions$1): TypeBox.TCodec<TString$1, URL>;
611
552
  /**
612
- * Create a schema for a url.
553
+ * Create a schema for binary data represented as a string.
613
554
  */
614
- url(options?: TStringOptions$1): TString$1;
555
+ binary(options: TStringOptions$1): TypeBox.TCodec<TString$1, Uint8Array<ArrayBuffer>>;
615
556
  /**
616
557
  * Create a schema for uuid.
617
558
  */
@@ -630,10 +571,26 @@ declare class TypeProvider {
630
571
  * @experimental
631
572
  */
632
573
  stream(): TStream;
574
+ email(options?: TStringOptions$1): TString$1;
575
+ e164(options?: TStringOptions$1): TString$1;
576
+ bcp47(options?: TStringOptions$1): TString$1;
577
+ /**
578
+ * Create a schema for short text, such as names or titles.
579
+ * Default max length is 64 characters.
580
+ */
581
+ shortText(options?: TStringOptions$1): TString$1;
582
+ /**
583
+ * Create a schema for long text, such as descriptions or comments.
584
+ * Default max length is 1024 characters.
585
+ */
586
+ longText(options?: TStringOptions$1): TString$1;
587
+ /**
588
+ * Create a schema for rich text, such as HTML or Markdown.
589
+ * Default max length is 65535 characters.
590
+ */
591
+ richText(options?: TStringOptions$1): TString$1;
633
592
  /**
634
593
  * Create a schema for a string enum e.g. LIKE_THIS.
635
- *
636
- * @param options
637
594
  */
638
595
  snakeCase: (options?: TStringOptions$1) => TString$1;
639
596
  /**
@@ -669,6 +626,192 @@ interface TTextOptions extends TStringOptions$1 {
669
626
  }
670
627
  declare const t: TypeProvider;
671
628
  //#endregion
629
+ //#region src/providers/SchemaCodec.d.ts
630
+ declare abstract class SchemaCodec {
631
+ protected cache: Map<TSchema$1, Validator>;
632
+ protected guard: TypeGuard;
633
+ /**
634
+ * Encode the value to a string format.
635
+ */
636
+ abstract encodeToString(schema: TSchema$1, value: any): string;
637
+ /**
638
+ * Encode the value to a binary format.
639
+ */
640
+ abstract encodeToBinary(schema: TSchema$1, value: any): Uint8Array;
641
+ /**
642
+ * Transform a specific type for this codec.
643
+ * Return undefined to use the default schema, or return a new schema to replace it.
644
+ *
645
+ * Override this method to customize how specific types are handled in this codec.
646
+ * For example, a ProtobufCodec might keep BigInt as-is instead of converting to string.
647
+ */
648
+ protected abstract transformType(schema: TSchema$1): TSchema$1 | false | void;
649
+ encode<T extends TSchema$1>(schema: T, value: any): StaticEncode$1<T>;
650
+ decode<T extends TSchema$1>(schema: T, value: any): StaticDecode$1<T>;
651
+ protected validator<T extends TSchema$1>(schema: T): Validator<{}, T>;
652
+ /**
653
+ * Transform the schema for this codec.
654
+ * Override this method to provide custom schema transformations.
655
+ * This method should recursively transform all nested schemas.
656
+ */
657
+ protected transformSchema<T extends TSchema$1>(schema: T): TSchema$1;
658
+ /**
659
+ * Preprocess the value based on the schema before encoding.
660
+ *
661
+ * - Remove `undefined` values from objects. { a: 1, b: undefined } => { a: 1 }
662
+ */
663
+ beforeEncode: (schema: any, value: any) => any;
664
+ /**
665
+ * Preprocess the value based on the schema before validation.
666
+ *
667
+ * - If the value is `null` and the schema does not allow `null`, it converts it to `undefined`.
668
+ * - If the value is a string and the schema has a `~options.trim` flag, it trims whitespace from the string.
669
+ */
670
+ beforeDecode: (schema: any, value: any) => any;
671
+ /**
672
+ * Used by `preprocess` to determine if a schema allows null values.
673
+ */
674
+ protected isSchemaNullable: (schema: any) => boolean;
675
+ }
676
+ //#endregion
677
+ //#region src/providers/JsonSchemaCodec.d.ts
678
+ declare class JsonSchemaCodec extends SchemaCodec {
679
+ protected readonly json: Json;
680
+ protected readonly encoder: TextEncoder;
681
+ protected readonly decoder: TextDecoder;
682
+ protected transformType(schema: TSchema$1): TSchema$1 | false | void;
683
+ encodeToString(schema: TSchema$1, value: any): string;
684
+ encodeToBinary(schema: TSchema$1, value: any): Uint8Array;
685
+ decode<T extends TSchema$1>(schema: T, value: any): StaticDecode$1<T>;
686
+ }
687
+ //#endregion
688
+ //#region src/providers/CodecManager.d.ts
689
+ type Encoding = "object" | "string" | "binary";
690
+ interface EncodeOptions<T extends Encoding = Encoding> {
691
+ /**
692
+ * The output encoding format:
693
+ * - 'object': Returns native types (objects, BigInt, Date, etc.)
694
+ * - 'string': Returns JSON string
695
+ * - 'binary': Returns Uint8Array (for protobuf, msgpack, etc.)
696
+ */
697
+ as?: T;
698
+ /**
699
+ * The encoder to use (e.g., 'json', 'protobuf', 'msgpack')
700
+ * Defaults to 'json'
701
+ */
702
+ encoder?: string;
703
+ }
704
+ type EncodeResult<T extends TSchema$1, E extends Encoding> = E extends "string" ? string : E extends "binary" ? Uint8Array : StaticEncode$1<T>;
705
+ interface DecodeOptions {
706
+ /**
707
+ * The encoder to use (e.g., 'json', 'protobuf', 'msgpack')
708
+ * Defaults to 'json'
709
+ */
710
+ encoder?: string;
711
+ }
712
+ /**
713
+ * CodecManager manages multiple codec formats and provides a unified interface
714
+ * for encoding and decoding data with different formats.
715
+ */
716
+ declare class CodecManager {
717
+ protected readonly codecs: Map<string, SchemaCodec>;
718
+ protected readonly jsonCodec: JsonSchemaCodec;
719
+ default: string;
720
+ constructor();
721
+ /**
722
+ * Register a new codec format.
723
+ * @param name - The name of the codec (e.g., 'json', 'protobuf')
724
+ * @param codec - The codec implementation
725
+ */
726
+ register(name: string, codec: SchemaCodec): void;
727
+ /**
728
+ * Get a specific codec by name.
729
+ * @param name - The name of the codec
730
+ * @returns The codec instance
731
+ * @throws {AlephaError} If the codec is not found
732
+ */
733
+ get(name: string): SchemaCodec;
734
+ /**
735
+ * Encode data using the specified codec and output format.
736
+ */
737
+ encode<T extends TSchema$1, E extends Encoding = "object">(schema: T, value: any, options?: EncodeOptions<E>): EncodeResult<T, E>;
738
+ /**
739
+ * Decode data using the specified codec.
740
+ */
741
+ decode<T extends TSchema$1>(schema: T, value: any, options?: DecodeOptions): StaticDecode$1<T>;
742
+ }
743
+ //#endregion
744
+ //#region src/providers/EventManager.d.ts
745
+ declare class EventManager {
746
+ protected logFn?: () => LoggerInterface | undefined;
747
+ /**
748
+ * List of events that can be triggered. Powered by $hook().
749
+ */
750
+ protected events: Record<string, Array<Hook>>;
751
+ constructor(logFn?: () => LoggerInterface | undefined);
752
+ protected get log(): LoggerInterface | undefined;
753
+ /**
754
+ * Registers a hook for the specified event.
755
+ */
756
+ on<T extends keyof Hooks>(event: T, hookOrFunc: Hook<T> | ((payload: Hooks[T]) => Async<void>)): () => void;
757
+ /**
758
+ * Emits the specified event with the given payload.
759
+ */
760
+ emit<T extends keyof Hooks>(func: T, payload: Hooks[T], options?: {
761
+ /**
762
+ * If true, the hooks will be executed in reverse order.
763
+ * This is useful for "stop" hooks that should be executed in reverse order.
764
+ *
765
+ * @default false
766
+ */
767
+ reverse?: boolean;
768
+ /**
769
+ * If true, the hooks will be logged with their execution time.
770
+ *
771
+ * @default false
772
+ */
773
+ log?: boolean;
774
+ /**
775
+ * If true, errors will be caught and logged instead of throwing.
776
+ *
777
+ * @default false
778
+ */
779
+ catch?: boolean;
780
+ }): Promise<void>;
781
+ }
782
+ //#endregion
783
+ //#region src/providers/StateManager.d.ts
784
+ declare class StateManager<S extends Record<string, any> = State> {
785
+ protected readonly als: AlsProvider;
786
+ protected readonly events: EventManager;
787
+ protected store: Partial<S>;
788
+ constructor(store?: Partial<S>);
789
+ /**
790
+ * Get a value from the state with proper typing
791
+ */
792
+ get<Key extends keyof S>(key: Key): S[Key] | undefined;
793
+ /**
794
+ * Set a value in the state
795
+ */
796
+ set<Key extends keyof S>(key: Key, value: S[Key] | undefined): this;
797
+ /**
798
+ * Check if a key exists in the state
799
+ */
800
+ has<Key extends keyof S>(key: Key): boolean;
801
+ /**
802
+ * Delete a key from the state (set to undefined)
803
+ */
804
+ del<Key extends keyof S>(key: Key): this;
805
+ /**
806
+ * Clear all state
807
+ */
808
+ clear(): this;
809
+ /**
810
+ * Get all keys that exist in the state
811
+ */
812
+ keys(): (keyof S)[];
813
+ }
814
+ //#endregion
672
815
  //#region src/Alepha.d.ts
673
816
  /**
674
817
  * Core container of the Alepha framework.
@@ -803,10 +946,6 @@ declare class Alepha {
803
946
  * If you are not interested about these helpers, you can use the constructor directly.
804
947
  */
805
948
  static create(state?: Partial<State>): Alepha;
806
- /**
807
- * List of all services + how they are provided.
808
- */
809
- protected registry: Map<Service, ServiceDefinition>;
810
949
  /**
811
950
  * Flag indicating whether the App won't accept any further changes.
812
951
  * Pass to true when #start() is called.
@@ -829,33 +968,11 @@ declare class Alepha {
829
968
  */
830
969
  protected starting?: PromiseWithResolvers<this>;
831
970
  /**
832
- * The current state of the App.
833
- *
834
- * It contains the environment variables, logger, and other state-related properties.
835
- *
836
- * You can declare your own state properties by extending the `State` interface.
971
+ * Initial state of the container.
837
972
  *
838
- * ```ts
839
- * declare module "alepha" {
840
- * interface State {
841
- * myCustomValue: string;
842
- * }
843
- * }
844
- * ```
845
- *
846
- * Same story for the `Env` interface.
847
- * ```ts
848
- * declare module "alepha" {
849
- * interface Env {
850
- * readonly myCustomValue: string;
851
- * }
852
- * }
853
- * ```
854
- *
855
- * State values can be function or primitive values.
856
- * However, all .env variables must serializable to JSON.
973
+ * > Used to initialize the StateManager.
857
974
  */
858
- protected store: State;
975
+ protected init: State;
859
976
  /**
860
977
  * During the instantiation process, we keep a list of pending instantiations.
861
978
  * > It allows us to detect circular dependencies.
@@ -866,22 +983,34 @@ declare class Alepha {
866
983
  * > It allows us to avoid parsing the same schema multiple times.
867
984
  */
868
985
  protected cacheEnv: Map<TSchema, any>;
869
- /**
870
- * Cache for TypeBox type checks.
871
- * > It allows us to avoid compiling the same schema multiple times.
872
- */
873
- protected cacheTypeCheck: Map<TSchema, Validator>;
874
986
  /**
875
987
  * List of modules that are registered in the container.
876
988
  *
877
989
  * Modules are used to group services and provide a way to register them in the container.
878
990
  */
879
991
  protected modules: Array<Module>;
992
+ /**
993
+ * List of service substitutions.
994
+ *
995
+ * Services registered here will be replaced by the specified service when injected.
996
+ */
880
997
  protected substitutions: Map<Service, {
881
998
  use: Service;
882
999
  }>;
1000
+ /**
1001
+ * Configuration states for services.
1002
+ *
1003
+ * Used to configure services when they are instantiated.
1004
+ */
883
1005
  protected configurations: Map<Service, object>;
1006
+ /**
1007
+ * Registry of descriptors.
1008
+ */
884
1009
  protected descriptorRegistry: Map<Service<Descriptor<{}>>, Descriptor<{}>[]>;
1010
+ /**
1011
+ * List of all services + how they are provided.
1012
+ */
1013
+ protected registry: Map<Service, ServiceDefinition>;
885
1014
  /**
886
1015
  * Node.js feature that allows to store context across asynchronous calls.
887
1016
  *
@@ -889,15 +1018,21 @@ declare class Alepha {
889
1018
  *
890
1019
  * Mocked for browser environments.
891
1020
  */
892
- readonly context: AlsProvider;
1021
+ get context(): AlsProvider;
893
1022
  /**
894
1023
  * Event manager to handle lifecycle events and custom events.
895
1024
  */
896
- readonly events: EventManager;
1025
+ get events(): EventManager;
897
1026
  /**
898
1027
  * State manager to store arbitrary values.
899
1028
  */
900
- readonly state: StateManager<State>;
1029
+ get state(): StateManager<Record<string, any>>;
1030
+ /**
1031
+ * Codec manager for encoding and decoding data with different formats.
1032
+ *
1033
+ * Supports multiple codec formats (JSON, Protobuf, etc.) with a unified interface.
1034
+ */
1035
+ get codec(): CodecManager;
901
1036
  /**
902
1037
  * Get logger instance.
903
1038
  */
@@ -906,7 +1041,7 @@ declare class Alepha {
906
1041
  * The environment variables for the App.
907
1042
  */
908
1043
  get env(): Readonly<Env>;
909
- constructor(state?: Partial<State>);
1044
+ constructor(init?: Partial<State>);
910
1045
  /**
911
1046
  * True when start() is called.
912
1047
  *
@@ -935,12 +1070,14 @@ declare class Alepha {
935
1070
  * True if the App is running in a browser environment.
936
1071
  */
937
1072
  isBrowser(): boolean;
1073
+ /**
1074
+ * Returns whether the App is running in Vite dev mode.
1075
+ */
1076
+ isViteDev(): boolean;
938
1077
  /**
939
1078
  * Returns whether the App is running in a serverless environment.
940
- *
941
- * > Vite developer mode is also considered serverless.
942
1079
  */
943
- isServerless(): boolean | "vite" | "vercel";
1080
+ isServerless(): boolean;
944
1081
  /**
945
1082
  * Returns whether the App is in test mode. (Running in a test environment)
946
1083
  *
@@ -1064,43 +1201,6 @@ declare class Alepha {
1064
1201
  configure<T extends {
1065
1202
  options?: object;
1066
1203
  }>(service: Service<T>, state: Partial<T["options"]>): this;
1067
- /**
1068
- * Casts the given value to the specified schema.
1069
- *
1070
- * It uses the TypeBox library to validate the value against the schema.
1071
- */
1072
- parse<T extends TSchema>(schema: T, value?: unknown, opts?: {
1073
- /**
1074
- * Clone the value before parsing.
1075
- * @default true
1076
- */
1077
- clone?: boolean;
1078
- /**
1079
- * Apply default values defined in the schema.
1080
- * @default true
1081
- */
1082
- default?: boolean;
1083
- /**
1084
- * Remove all values not defined in the schema.
1085
- * @default true
1086
- */
1087
- clean?: boolean;
1088
- /**
1089
- * Try to cast/convert some data based on the schema.
1090
- * @default true
1091
- */
1092
- convert?: boolean;
1093
- /**
1094
- * Convert `null` to `undefined`
1095
- * @default true
1096
- */
1097
- convertNullToUndefined?: boolean;
1098
- /**
1099
- * Prepare value after being deserialized.
1100
- * @default true
1101
- */
1102
- check?: boolean;
1103
- }): Static$1<T>;
1104
1204
  /**
1105
1205
  * Applies environment variables to the provided schema and state object.
1106
1206
  *
@@ -1211,6 +1311,9 @@ interface Hooks {
1211
1311
  prevValue: any;
1212
1312
  };
1213
1313
  }
1314
+ interface Configurable<T extends object = any> {
1315
+ options: T;
1316
+ }
1214
1317
  //#endregion
1215
1318
  //#region src/interfaces/Run.d.ts
1216
1319
  interface RunOptions {
@@ -1429,23 +1532,32 @@ declare class TooLateSubstitutionError extends AlephaError {
1429
1532
  declare class TypeBoxError extends AlephaError {
1430
1533
  readonly name = "TypeBoxError";
1431
1534
  readonly cause: TLocalizedValidationError;
1432
- readonly value: any;
1433
- constructor(error: TLocalizedValidationError, value: any);
1535
+ readonly value: {
1536
+ path: string;
1537
+ message: string;
1538
+ };
1539
+ constructor(error: TLocalizedValidationError);
1540
+ }
1541
+ interface TypeBoxErrorParams {
1542
+ requiredProperties?: string[];
1434
1543
  }
1435
1544
  //#endregion
1436
1545
  //#region src/index.d.ts
1437
- declare global {
1438
- interface ImportMetaEnv {
1439
- SSR: boolean;
1440
- }
1441
- interface ImportMeta {
1442
- readonly env: ImportMetaEnv;
1443
- }
1444
- }
1445
1546
  /**
1547
+ * Run Alepha application, trigger start lifecycle.
1548
+ *
1549
+ * ```ts
1550
+ * import { Alepha, run } from "alepha";
1551
+ * import { MyService } from "./services/MyService.ts";
1446
1552
  *
1553
+ * const alepha = new Alepha({ env: { APP_NAME: "MyAlephaApp" } });
1554
+ *
1555
+ * alepha.with(MyService);
1556
+ *
1557
+ * export default run(alepha);
1558
+ * ```
1447
1559
  */
1448
- declare const run: (entry: Alepha | Service | Array<Service>, opts?: RunOptions) => void;
1560
+ declare const run: (entry: Alepha | Service | Array<Service>, opts?: RunOptions) => Alepha;
1449
1561
  //#endregion
1450
- export { $cursor, $env, $hook, $inject, $module, AbstractClass, Alepha, AlephaError, AlsProvider, AppNotStartedError, Async, AsyncFn, AsyncLocalStorageData, CircularDependencyError, ContainerLockedError, CursorDescriptor, Descriptor, DescriptorArgs, DescriptorConfig, DescriptorFactory, DescriptorFactoryLike, Env, FileLike, Hook, HookDescriptor, HookOptions, Hooks, InjectDescriptor, InjectOptions, InstantiableClass, KIND, LogLevel, LoggerInterface, MaybePromise, Module, ModuleDescriptorOptions, OPTIONS, Service, ServiceEntry, ServiceSubstitution, State, StateManager, type Static, type StaticDecode, type StaticEncode, StreamLike, type TAny, type TArray, type TBigInt, type TBoolean, TFile, type TInteger, type TKeysToIndexer, type TNull, type TNumber, type TNumberOptions, type TObject, type TObjectOptions, type TOptional, type TOptionalAdd, type TPick, type TProperties, type TRecord, type TSchema, TStream, type TString, type TStringOptions, TTextOptions, type TTuple, type TUnion, type TVoid, TextLength, TooLateSubstitutionError, TypeBox, TypeBoxError, TypeBoxFormat, TypeBoxValue, TypeGuard, TypeProvider, WithModule, __alephaRef, createDescriptor, isDate, isDateTime, isEmail, isFileLike, isTypeFile, isURL, isUUID, run, t };
1562
+ export { $cursor, $env, $hook, $inject, $module, AbstractClass, Alepha, AlephaError, AlsProvider, AppNotStartedError, Async, AsyncFn, AsyncLocalStorageData, CircularDependencyError, CodecManager, Configurable, ContainerLockedError, CursorDescriptor, DecodeOptions, Descriptor, DescriptorArgs, DescriptorConfig, DescriptorFactory, DescriptorFactoryLike, EncodeOptions, EncodeResult, Encoding, Env, FileLike, Hook, HookDescriptor, HookOptions, Hooks, InjectDescriptor, InjectOptions, InstantiableClass, JsonSchemaCodec, KIND, LogLevel, LoggerInterface, MaybePromise, Module, ModuleDescriptorOptions, OPTIONS, RunFunction, SchemaCodec, Service, ServiceEntry, ServiceSubstitution, State, StateManager, type Static, type StaticDecode, type StaticEncode, StreamLike, type TAny, type TArray, type TBigInt, type TBoolean, TFile, type TInteger, type TKeysToIndexer, type TNull, type TNumber, type TNumberOptions, type TObject, type TObjectOptions, type TOptional, type TOptionalAdd, type TPick, type TProperties, type TRecord, type TSchema, TStream, type TString, type TStringOptions, TTextOptions, type TTuple, type TUnion, type TUnsafe, type TVoid, TextLength, TooLateSubstitutionError, TypeBox, TypeBoxError, TypeBoxErrorParams, TypeBoxFormat, TypeBoxValue, TypeGuard, TypeProvider, WithModule, __alephaRef, createDescriptor, isClass, isEmail, isFileLike, isTypeFile, isURL, isUUID, run, t };
1451
1563
  //# sourceMappingURL=index.d.ts.map