alepha 0.6.9 → 0.7.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/cache.d.ts CHANGED
@@ -92,6 +92,7 @@ interface TSchema extends TKind, SchemaOptions {
92
92
  }
93
93
 
94
94
  declare class CacheProvider {
95
+ constructor();
95
96
  /**
96
97
  * Get the value of a key.
97
98
  *
package/core.d.ts CHANGED
@@ -17,6 +17,13 @@ import { Readable } from 'node:stream';
17
17
  */
18
18
  declare const KIND: unique symbol;
19
19
 
20
+ /**
21
+ * Used for identifying descriptors.
22
+ *
23
+ * @internal
24
+ */
25
+ declare const OPTIONS: unique symbol;
26
+
20
27
  /**
21
28
  * Represents a value that can be either a value or a promise.
22
29
  */
@@ -84,42 +91,7 @@ interface ClassProvider<T extends object = any> {
84
91
  parents: Array<Class | null>;
85
92
  }
86
93
 
87
- /**
88
- * Used for identifying descriptors.
89
- *
90
- * @internal
91
- */
92
- declare const OPTIONS: unique symbol;
93
-
94
94
  declare const KEY = "HOOK";
95
- interface Hooks {
96
- /**
97
- * Triggered during the configuration phase. Before the start phase.
98
- *
99
- * - Configuration should technically be called many times without any side effects.
100
- * - Spamming Alepha#configure() should not cause any issues.
101
- */
102
- configure: Alepha;
103
- /**
104
- * Triggered during the start phase. When `Alepha#start()` is called.
105
- *
106
- * - Start is called only once. It should not be called multiple times.
107
- */
108
- start: Alepha;
109
- /**
110
- * Triggered during the ready phase. After the start phase.
111
- *
112
- * - Ready is called only once. It should not be called multiple times.
113
- */
114
- ready: Alepha;
115
- /**
116
- * Triggered during the stop phase.
117
- *
118
- * - Stop is called only once. It should not be called multiple times.
119
- * - Stop should be called after a SIGINT or SIGTERM signal in order to gracefully shutdown the application.
120
- */
121
- stop: Alepha;
122
- }
123
95
  interface HookOptions<T extends keyof Hooks> {
124
96
  /**
125
97
  * The name of the hook. "configure", "start", "ready", "stop", ...
@@ -442,6 +414,35 @@ interface State {
442
414
  afterEach?: (run: any) => any;
443
415
  onTestFinished?: (run: any) => any;
444
416
  }
417
+ interface Hooks {
418
+ echo: any;
419
+ /**
420
+ * Triggered during the configuration phase. Before the start phase.
421
+ *
422
+ * - Configuration should technically be called many times without any side effects.
423
+ * - Spamming Alepha#configure() should not cause any issues.
424
+ */
425
+ configure: Alepha;
426
+ /**
427
+ * Triggered during the start phase. When `Alepha#start()` is called.
428
+ *
429
+ * - Start is called only once. It should not be called multiple times.
430
+ */
431
+ start: Alepha;
432
+ /**
433
+ * Triggered during the ready phase. After the start phase.
434
+ *
435
+ * - Ready is called only once. It should not be called multiple times.
436
+ */
437
+ ready: Alepha;
438
+ /**
439
+ * Triggered during the stop phase.
440
+ *
441
+ * - Stop is called only once. It should not be called multiple times.
442
+ * - Stop should be called after a SIGINT or SIGTERM signal in order to gracefully shutdown the application.
443
+ */
444
+ stop: Alepha;
445
+ }
445
446
  /**
446
447
  *
447
448
  *
@@ -623,10 +624,11 @@ declare class Alepha {
623
624
  skipRegistration?: boolean;
624
625
  args?: any[];
625
626
  }): T;
626
- on<T extends keyof Hooks>(event: T, hook: Hook<T>): () => void;
627
+ on<T extends keyof Hooks>(event: T, hookOrFunc: Hook<T> | ((payload: Hooks[T]) => Async<void>)): () => void;
627
628
  emit<T extends keyof Hooks>(func: keyof Hooks, payload: Hooks[T], options?: {
628
629
  reverse?: boolean;
629
630
  log?: boolean;
631
+ catch?: boolean;
630
632
  }): Promise<void>;
631
633
  /**
632
634
  * Casts the given value to the specified schema.
@@ -708,6 +710,10 @@ declare class Alepha {
708
710
  */
709
711
  declare const PROVIDER: unique symbol;
710
712
 
713
+ declare const $module: (opts: {
714
+ services: Array<Class>;
715
+ }) => {};
716
+
711
717
  /**
712
718
  * Get the instance of the specified type from the context.
713
719
  *
@@ -734,11 +740,15 @@ declare const $logger: (name?: string) => Logger;
734
740
  */
735
741
  interface RetryDescriptorOptions<T extends (...args: any[]) => any> {
736
742
  /**
743
+ * Maximum number of attempts.
737
744
  *
745
+ * @default 3
738
746
  */
739
747
  max?: number;
740
748
  /**
749
+ * Delay in milliseconds.
741
750
  *
751
+ * @default 0
742
752
  */
743
753
  delay?: number;
744
754
  /**
@@ -749,14 +759,23 @@ interface RetryDescriptorOptions<T extends (...args: any[]) => any> {
749
759
  *
750
760
  */
751
761
  handler: T;
762
+ /**
763
+ * Optional error handler.
764
+ *
765
+ * This will be called when an error occurs.
766
+ *
767
+ * @default undefined
768
+ */
769
+ onError?: (error: Error, attempt: number, ...parameters: Parameters<T>) => void;
752
770
  }
771
+ type MaybePromise<T> = T extends Promise<any> ? T : Promise<T>;
753
772
  /**
754
773
  * Retry descriptor.
755
774
  *
756
775
  * @param opts - Retry descriptor options.
757
776
  * @returns A function that will retry the handler.
758
777
  */
759
- declare const $retry: <T extends (...args: any[]) => any>(opts: RetryDescriptorOptions<T>) => ((...parameters: Parameters<T>) => Promise<ReturnType<T>>);
778
+ declare const $retry: <T extends (...args: any[]) => any>(opts: RetryDescriptorOptions<T>) => ((...parameters: Parameters<T>) => MaybePromise<ReturnType<T>>);
760
779
 
761
780
  declare class AppNotStartedError extends Error {
762
781
  constructor();
@@ -779,26 +798,6 @@ declare class TypeBoxError extends Error {
779
798
  constructor(value: ValueError);
780
799
  }
781
800
 
782
- interface EventEmitterItem<T extends object> {
783
- name: keyof T;
784
- handler: (arg: any) => Async<void>;
785
- }
786
- declare class EventEmitter<T extends object> {
787
- protected events: EventEmitterItem<T>[];
788
- /**
789
- *
790
- * @param name
791
- * @param handler
792
- */
793
- on<Key extends keyof T>(name: Key, handler: (arg: T[Key]) => void): () => void;
794
- /**
795
- *
796
- * @param name
797
- * @param data
798
- */
799
- emit<Key extends keyof T>(name: Key, data: T[Key]): Promise<void>;
800
- }
801
-
802
801
  declare class TypeProvider {
803
802
  static DEFAULT_STRING_MAX_LENGTH: number;
804
803
  static DEFAULT_LONG_STRING_MAX_LENGTH: number;
@@ -995,4 +994,4 @@ declare const run: (arg: Alepha | Class | ((env?: Env) => Alepha), opts?: {
995
994
  ready?: (alepha: Alepha) => Async<void>;
996
995
  }) => Alepha;
997
996
 
998
- export { $cursor, $hook, $inject, $logger, $retry, Alepha, type AlephaStringOptions, AppNotStartedError, type Async, type AsyncFn, type AsyncLocalStorageData, AsyncLocalStorageProvider, COLORS, CircularDependencyError, type Class, type ClassEntry, type ClassProvider, type ClassSwap, ContainerLockedError, type CursorDescriptor, type Descriptor, type DescriptorIdentifier, type DescriptorItem, type Env, EventEmitter, type EventEmitterItem, EventEmitterLike, type FileLike, type Hook, type HookDescriptor, type HookOptions, type Hooks, KIND, LEVEL_COLORS, type LogLevel, Logger, type LoggerEnv, type LoggerOptions, MockLogger, type MockLoggerStore, NotImplementedError, OPTIONS, PROVIDER, type PromiseFn, type RetryDescriptorOptions, type State, type StreamLike, type TFile, type TStream, type TextLength, TypeBoxError, TypeProvider, __alephaRef, __bind, __descriptor, descriptorEvents, isDescriptorValue, isFileLike, isTypeFile, isTypeStream, isUUID, run, t };
997
+ export { $cursor, $hook, $inject, $logger, $module, $retry, Alepha, type AlephaStringOptions, AppNotStartedError, type Async, type AsyncFn, type AsyncLocalStorageData, AsyncLocalStorageProvider, COLORS, CircularDependencyError, type Class, type ClassEntry, type ClassProvider, type ClassSwap, ContainerLockedError, type CursorDescriptor, type Descriptor, type DescriptorIdentifier, type DescriptorItem, type Env, EventEmitterLike, type FileLike, type Hook, type HookDescriptor, type HookOptions, type Hooks, KIND, LEVEL_COLORS, type LogLevel, Logger, type LoggerEnv, type LoggerOptions, type MaybePromise, MockLogger, type MockLoggerStore, NotImplementedError, OPTIONS, PROVIDER, type PromiseFn, type RetryDescriptorOptions, type State, type StreamLike, type TFile, type TStream, type TextLength, TypeBoxError, TypeProvider, __alephaRef, __bind, __descriptor, descriptorEvents, isDescriptorValue, isFileLike, isTypeFile, isTypeStream, isUUID, run, t };
package/lock.d.ts CHANGED
@@ -123,6 +123,7 @@ declare const $lock: {
123
123
  * Store Provider Interface
124
124
  */
125
125
  declare class LockProvider {
126
+ constructor();
126
127
  /**
127
128
  * Set the string value of a key.
128
129
  *
@@ -238,7 +239,7 @@ declare class MemoryLockProvider implements LockProvider {
238
239
  /**
239
240
  * A store provider that uses Redis.
240
241
  */
241
- declare class RedisLockProvider extends LockProvider {
242
+ declare class RedisLockProvider implements LockProvider {
242
243
  protected readonly log: _alepha_core.Logger;
243
244
  protected readonly redisProvider: RedisProvider;
244
245
  /**
package/package.json CHANGED
@@ -1,31 +1,37 @@
1
1
  {
2
2
  "name": "alepha",
3
- "version": "0.6.9",
3
+ "version": "0.7.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
+ "description": "TypeScript framework for building full-stack apps with strict conventions, custom schemas, and React-based SPA or SSR without filesystem-based routing.",
7
+ "homepage": "https://github.com/feunard/alepha",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/feunard/alepha.git"
11
+ },
6
12
  "main": "./core.js",
7
13
  "types": "./core.d.ts",
8
14
  "dependencies": {
9
- "@alepha/cache": "0.6.9",
10
- "@alepha/core": "0.6.9",
11
- "@alepha/datetime": "0.6.9",
12
- "@alepha/lock": "0.6.9",
13
- "@alepha/postgres": "0.6.9",
14
- "@alepha/queue": "0.6.9",
15
- "@alepha/react": "0.6.9",
16
- "@alepha/react-auth": "0.6.9",
17
- "@alepha/redis": "0.6.9",
18
- "@alepha/scheduler": "0.6.9",
19
- "@alepha/security": "0.6.9",
20
- "@alepha/server": "0.6.9",
21
- "@alepha/server-cookies": "0.6.9",
22
- "@alepha/server-metrics": "0.6.9",
23
- "@alepha/server-proxy": "0.6.9",
24
- "@alepha/server-static": "0.6.9",
25
- "@alepha/server-swagger": "0.6.9",
26
- "@alepha/testing": "0.6.9",
27
- "@alepha/topic": "0.6.9",
28
- "@alepha/vite": "0.6.9"
15
+ "@alepha/cache": "0.7.0",
16
+ "@alepha/core": "0.7.0",
17
+ "@alepha/datetime": "0.7.0",
18
+ "@alepha/lock": "0.7.0",
19
+ "@alepha/postgres": "0.7.0",
20
+ "@alepha/queue": "0.7.0",
21
+ "@alepha/react": "0.7.0",
22
+ "@alepha/react-auth": "0.7.0",
23
+ "@alepha/redis": "0.7.0",
24
+ "@alepha/scheduler": "0.7.0",
25
+ "@alepha/security": "0.7.0",
26
+ "@alepha/server": "0.7.0",
27
+ "@alepha/server-cookies": "0.7.0",
28
+ "@alepha/server-metrics": "0.7.0",
29
+ "@alepha/server-proxy": "0.6.10",
30
+ "@alepha/server-static": "0.7.0",
31
+ "@alepha/server-swagger": "0.7.0",
32
+ "@alepha/testing": "0.7.0",
33
+ "@alepha/topic": "0.7.0",
34
+ "@alepha/vite": "0.7.0"
29
35
  },
30
36
  "peerDependencies": {
31
37
  "@types/react": "^19",