alepha 0.6.9 → 0.6.10

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.
@@ -734,11 +736,15 @@ declare const $logger: (name?: string) => Logger;
734
736
  */
735
737
  interface RetryDescriptorOptions<T extends (...args: any[]) => any> {
736
738
  /**
739
+ * Maximum number of attempts.
737
740
  *
741
+ * @default 3
738
742
  */
739
743
  max?: number;
740
744
  /**
745
+ * Delay in milliseconds.
741
746
  *
747
+ * @default 0
742
748
  */
743
749
  delay?: number;
744
750
  /**
@@ -779,26 +785,6 @@ declare class TypeBoxError extends Error {
779
785
  constructor(value: ValueError);
780
786
  }
781
787
 
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
788
  declare class TypeProvider {
803
789
  static DEFAULT_STRING_MAX_LENGTH: number;
804
790
  static DEFAULT_LONG_STRING_MAX_LENGTH: number;
@@ -995,4 +981,4 @@ declare const run: (arg: Alepha | Class | ((env?: Env) => Alepha), opts?: {
995
981
  ready?: (alepha: Alepha) => Async<void>;
996
982
  }) => Alepha;
997
983
 
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 };
984
+ 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, 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 };
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.6.10",
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.6.10",
16
+ "@alepha/core": "0.6.10",
17
+ "@alepha/datetime": "0.6.10",
18
+ "@alepha/lock": "0.6.10",
19
+ "@alepha/postgres": "0.6.10",
20
+ "@alepha/queue": "0.6.10",
21
+ "@alepha/react": "0.6.10",
22
+ "@alepha/react-auth": "0.6.10",
23
+ "@alepha/redis": "0.6.10",
24
+ "@alepha/scheduler": "0.6.10",
25
+ "@alepha/security": "0.6.10",
26
+ "@alepha/server": "0.6.10",
27
+ "@alepha/server-cookies": "0.6.10",
28
+ "@alepha/server-metrics": "0.6.10",
29
+ "@alepha/server-proxy": "0.6.10",
30
+ "@alepha/server-static": "0.6.10",
31
+ "@alepha/server-swagger": "0.6.10",
32
+ "@alepha/testing": "0.6.10",
33
+ "@alepha/topic": "0.6.10",
34
+ "@alepha/vite": "0.6.10"
29
35
  },
30
36
  "peerDependencies": {
31
37
  "@types/react": "^19",
package/postgres.d.ts CHANGED
@@ -114,6 +114,7 @@ type PgTableWithColumnsAndSchema<T extends TableConfig, R extends TObject$1> = P
114
114
 
115
115
  type SQLLike = SQLWrapper | string;
116
116
  declare class PostgresProvider {
117
+ constructor();
117
118
  /**
118
119
  * Get the database instance
119
120
  */
package/queue.d.ts CHANGED
@@ -60,6 +60,7 @@ interface TSchema extends TKind, SchemaOptions {
60
60
  }
61
61
 
62
62
  declare class QueueProvider {
63
+ constructor();
63
64
  /**
64
65
  * Push a message to the queue.
65
66
  *
package/redis.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as _alepha_core from '@alepha/core';
2
2
  import { Static, Alepha } from '@alepha/core';
3
3
  import * as Redis from 'ioredis';
4
- import Redis__default from 'ioredis';
4
+ import Redis__default, { RedisOptions } from 'ioredis';
5
5
 
6
6
  /** Symbol key applied to readonly types */
7
7
  declare const ReadonlyKind: unique symbol;
@@ -110,6 +110,7 @@ declare class RedisProvider {
110
110
  * Close the connection to the Redis server.
111
111
  */
112
112
  close(): Promise<void>;
113
+ duplicate(options?: Partial<RedisOptions>): RedisClient;
113
114
  /**
114
115
  * Redis subscriber client factory method.
115
116
  */
package/server/proxy.d.ts CHANGED
@@ -5,9 +5,10 @@ import { ServerRequest, ServerRouterProvider } from '@alepha/server';
5
5
  type ProxyDescriptorOptions = {
6
6
  path: string;
7
7
  target: string;
8
+ disabled?: boolean;
8
9
  beforeRequest?: (request: ServerRequest, proxyRequest: RequestInit) => Async<void>;
9
10
  afterResponse?: (request: ServerRequest, proxyResponse: Response) => Async<void>;
10
- disabled?: boolean;
11
+ rewrite?: (url: URL) => void;
11
12
  };
12
13
  interface ProxyDescriptor {
13
14
  [KIND]: "PROXY";
package/server.d.ts CHANGED
@@ -499,9 +499,14 @@ declare class HttpClient {
499
499
  * @protected
500
500
  */
501
501
  protected response(response: Response, options: FetchRunOptions): Promise<Response | any>;
502
+ protected isMaybeFile(response: Response): boolean;
502
503
  protected getFileLike(response: Response, defaultFileName?: string): FileLike;
503
504
  protected pathVariables(url: string, action: HttpClientLink, args?: ServerRequestConfigEntry): string;
504
- protected queryParams(url: string, action: HttpClientLink, args?: ServerRequestConfigEntry): string;
505
+ queryParams(url: string, action: {
506
+ schema?: {
507
+ query?: TObject$1;
508
+ };
509
+ }, args?: ServerRequestConfigEntry): string;
505
510
  of<T extends object>(options?: {
506
511
  group?: string;
507
512
  host?: string | (() => string);
@@ -535,6 +540,8 @@ interface HttpClientLink {
535
540
  protected?: boolean;
536
541
  schema?: RequestConfigSchema;
537
542
  handler?: ServerHandler;
543
+ host?: string;
544
+ proxy?: boolean;
538
545
  }
539
546
  type HttpVirtualClient<T> = {
540
547
  [K in keyof T as T[K] extends RouteDescriptor ? K : never]: T[K] & {
@@ -548,11 +555,23 @@ interface RemoteDescriptorOptions {
548
555
  * The URL of the remote service.
549
556
  */
550
557
  url: string | (() => string);
558
+ /**
559
+ * @default "/api/_links"
560
+ */
561
+ linkPath?: string;
562
+ /**
563
+ * If true, all methods of the remote service will be exposed as actions.
564
+ */
565
+ proxy?: boolean | {
566
+ beforeRequest?: (request: ServerRequest, proxyRequest: RequestInit) => Async<void>;
567
+ afterResponse?: (request: ServerRequest, proxyResponse: Response) => Async<void>;
568
+ rewrite?: (url: URL) => void;
569
+ };
551
570
  /**
552
571
  * One or many instance of classes to be registered as remote services.
553
572
  * Services must contain some $action() descriptors.
554
573
  */
555
- services: object | Array<object>;
574
+ services?: object | Array<object>;
556
575
  /**
557
576
  * The name of the remote service.
558
577
  *
@@ -570,6 +589,7 @@ declare const $remote: {
570
589
  };
571
590
 
572
591
  declare class ServerProvider {
592
+ constructor();
573
593
  get hostname(): string;
574
594
  }
575
595
 
@@ -596,7 +616,14 @@ declare class ServerActionDescriptorProvider {
596
616
  protected readonly actions: ServerRouteAction[];
597
617
  getActions(): ServerRouteAction<RequestConfigSchema>[];
598
618
  readonly configure: _alepha_core.HookDescriptor<"configure">;
599
- registerRemote(value: RemoteDescriptor, key: string): void;
619
+ registerRemote(value: RemoteDescriptor, key: string): Promise<void>;
620
+ loadRemoteLinks: (options: RemoteDescriptorOptions) => Promise<Promise<void>>;
621
+ proxy(url: string, link: HttpClientLink, options: {
622
+ beforeRequest?: (request: ServerRequest, proxyRequest: RequestInit) => Async<void>;
623
+ afterResponse?: (request: ServerRequest, proxyResponse: Response) => Async<void>;
624
+ rewrite?: (url: URL) => void;
625
+ }): Promise<void>;
626
+ private getRawRequestBody;
600
627
  registerAction(value: RouteDescriptor, key: string, instance: any, prefix?: string): Promise<void>;
601
628
  /**
602
629
  * When your action has no handler, it's considered as an 'API'.
@@ -654,6 +681,7 @@ interface ServerRemote {
654
681
  url: string;
655
682
  services: object[];
656
683
  name: string;
684
+ proxy: boolean;
657
685
  }
658
686
  interface ServerRouteAction<TConfig extends RequestConfigSchema = RequestConfigSchema> extends ServerRoute<TConfig> {
659
687
  method: RouteMethod;
@@ -720,7 +748,7 @@ declare class ServerMultipartProvider {
720
748
  protected readonly helper: RouteDescriptorHelper;
721
749
  protected readonly alepha: Alepha;
722
750
  readonly onRequest: _alepha_core.HookDescriptor<"server:onRequest">;
723
- readonly onSend: _alepha_core.HookDescriptor<"server:onSend">;
751
+ readonly onSend: _alepha_core.HookDescriptor<"server:onResponse">;
724
752
  handleMultipartBodyFromNode(route: ServerRoute, stream: IncomingMessage): Promise<{
725
753
  body: Record<string, any>;
726
754
  cleanup: () => Promise<void>;
package/topic.d.ts CHANGED
@@ -47,6 +47,7 @@ interface TSchema extends TKind, SchemaOptions {
47
47
  }
48
48
 
49
49
  declare class TopicProvider {
50
+ constructor();
50
51
  /**
51
52
  * Publish a message to a topic.
52
53
  *