alepha 0.9.5 → 0.10.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/README.md CHANGED
@@ -45,49 +45,3 @@ run(App);
45
45
  ```
46
46
 
47
47
  👉 For more information, please visit the [documentation](https://feunard.github.io/alepha/).
48
-
49
- ## Modules
50
-
51
- Alepha is modular, with a LOT of modules.
52
-
53
- ### Core & Application Layer
54
-
55
- * **Core ([@alepha/core](https://feunard.github.io/alepha/docs/alepha-core)) 📦:** The heart of the framework, providing a powerful dependency injection container, application lifecycle management, and the core descriptor system.
56
- * **Server ([@alepha/server](https://feunard.github.io/alepha/docs/alepha-server)) 🌐:** A high-performance, minimalist HTTP server for creating type-safe REST APIs using declarative `$action` descriptors.
57
- * **Database ([@alepha/postgres](https://feunard.github.io/alepha/docs/alepha-postgres)) 🗄️:** A powerful and type-safe ORM built on Drizzle. Define your schema with `$entity` and get fully-typed repositories with `$repository`.
58
- * **React ([@alepha/react](https://feunard.github.io/alepha/docs/alepha-react)) ⚛️:** Build full-stack, server-side rendered React applications with a file-based routing system (`$page`) that handles data fetching, hydration, and type-safe props.
59
-
60
- ### Backend Infrastructure & Abstractions
61
-
62
- * **Security ([@alepha/security](https://feunard.github.io/alepha/docs/alepha-security)) 🛡️:** A complete authentication and authorization system. Manage roles (`$role`), permissions (`$permission`), JWTs, and realms (`$realm`).
63
- * **Queue ([@alepha/queue](https://feunard.github.io/alepha/docs/alepha-queue)) ⏳:** A simple and robust interface for background job processing. Define workers with the `$queue` descriptor and integrate with backends like Redis.
64
- * **Cache ([@alepha/cache](https://feunard.github.io/alepha/docs/alepha-cache)) ⚡:** A flexible caching layer with support for TTL, automatic function caching (`$cache`), and multiple backends like in-memory or Redis.
65
- * **Bucket ([@alepha/bucket](https://feunard.github.io/alepha/docs/alepha-bucket)) ☁️:** A unified API for file and object storage. Abstract away the details of local, in-memory, or cloud storage providers like Azure Blob Storage.
66
- * **Scheduler ([@alepha/scheduler](https://feunard.github.io/alepha/docs/alepha-scheduler)) ⏰:** Schedule recurring tasks using cron expressions or fixed intervals with the `$scheduler` descriptor, with built-in support for distributed locking.
67
- * **Topic ([@alepha/topic](https://feunard.github.io/alepha/docs/alepha-topic)) 📢:** A publish-subscribe (pub/sub) messaging interface for building event-driven architectures with `$topic` and `$subscriber`.
68
- * **Lock ([@alepha/lock](https://feunard.github.io/alepha/docs/alepha-lock)) 🔒:** A distributed locking mechanism to ensure safe concurrent access to shared resources, using Redis or other backends.
69
-
70
- ### Server Middleware & Plugins
71
-
72
- * **Links ([@alepha/server-links](https://feunard.github.io/alepha/docs/alepha-server-links)) 🔗:** Enables end-to-end type-safe communication between your frontend and backend, or between microservices, with the `$client` descriptor.
73
- * **Swagger ([@alepha/server-swagger](https://feunard.github.io/alepha/docs/alepha-server-swagger)) 📜:** Automatically generate OpenAPI 3.0 documentation and a beautiful Swagger UI for all your `$action` API endpoints.
74
- * **Helmet ([@alepha/server-helmet](https://feunard.github.io/alepha/docs/alepha-server-helmet)) 🎩:** Enhance your application's security by automatically applying essential HTTP security headers like CSP and HSTS.
75
- * **CORS ([@alepha/server-cors](https://feunard.github.io/alepha/docs/alepha-server-cors)) ↔️:** A configurable middleware to handle Cross-Origin Resource Sharing (CORS) for your server.
76
- * **Multipart ([@alepha/server-multipart](https://feunard.github.io/alepha/docs/alepha-server-multipart)) 📎:** Seamlessly handle `multipart/form-data` requests for file uploads.
77
- * **Compress ([@alepha/server-compress](https://feunard.github.io/alepha/docs/alepha-server-compress)) 📦💨:** Automatically compress server responses with Gzip or Brotli to improve performance.
78
-
79
- And more, like **Request Logging**, **Error Handling**, and **Response Caching**, cookie parsers, and more, to enhance your server's capabilities.
80
-
81
- ### Full-Stack & React Ecosystem
82
-
83
- * **Auth ([@alepha/react-auth](https://feunard.github.io/alepha/docs/alepha-react-auth)) 🔑:** Simplifies frontend authentication flows, providing the `useAuth` hook to manage user sessions and permissions in your React components.
84
- * **Head ([@alepha/react-head](https://feunard.github.io/alepha/docs/alepha-react-head)) SEO:** Manage your document's `<head>` for SEO and metadata. Control titles, meta tags, and more, both on the server and client.
85
- * **i18n ([@alepha/react-i18n](https://feunard.github.io/alepha/docs/alepha-react-i18n)) 🌍:** A complete internationalization solution for your React applications, with support for lazy-loaded translation files and the `useI18n` hook.
86
- * **Form ([@alepha/react-form](https://feunard.github.io/alepha/docs/alepha-react-form)) 📝:** Create powerful, type-safe forms with automatic validation using the `useForm` hook, powered by your TypeBox schemas.
87
-
88
- ### Tooling & Utilities
89
-
90
- * **Vite ([@alepha/vite](https://feunard.github.io/alepha/docs/alepha-vite)) ✨:** A seamless Vite plugin that handles all the complex build and development server configurations for your full-stack Alepha applications.
91
- * **Command ([@alepha/command](https://feunard.github.io/alepha/docs/alepha-command)) ⌨️:** Build powerful, type-safe command-line interfaces and scripts directly within your application using the `$command` descriptor.
92
- * **Retry ([@alepha/retry](https://feunard.github.io/alepha/docs/alepha-retry)) 🔄:** A declarative and powerful decorator (`$retry`) for automatically retrying failed operations with exponential backoff.
93
-
package/batch.d.ts CHANGED
@@ -4,6 +4,7 @@ import { DateTimeProvider, DurationLike } from "alepha/datetime";
4
4
  import * as _alepha_logger0 from "alepha/logger";
5
5
  import * as _alepha_retry0 from "alepha/retry";
6
6
  import { RetryDescriptorOptions } from "alepha/retry";
7
+ import * as typebox0 from "typebox";
7
8
 
8
9
  //#region src/descriptors/$batch.d.ts
9
10
 
@@ -532,9 +533,7 @@ declare class BatchDescriptor<TItem extends TSchema, TResponse = any> extends De
532
533
  protected readonly dateTime: DateTimeProvider;
533
534
  protected readonly partitions: Map<any, any>;
534
535
  protected activeHandlers: PromiseWithResolvers<void>[];
535
- protected retry: _alepha_retry0.RetryDescriptorFn<(items: (TItem & {
536
- params: [];
537
- })["static"][]) => TResponse>;
536
+ protected retry: _alepha_retry0.RetryDescriptorFn<(items: typebox0.StaticType<"Encode", {}, {}, TItem>[]) => TResponse>;
538
537
  /**
539
538
  * Pushes an item into the batch. The item will be processed
540
539
  * asynchronously with other items when the batch is flushed.
package/bucket.d.ts CHANGED
@@ -2,7 +2,7 @@ import * as _alepha_core1 from "alepha";
2
2
  import { Alepha, AlephaError, Descriptor, FileLike, KIND, Service } from "alepha";
3
3
  import * as fs from "node:fs";
4
4
  import * as _alepha_logger0 from "alepha/logger";
5
- import * as _sinclair_typebox0 from "@sinclair/typebox";
5
+ import * as typebox0 from "typebox";
6
6
 
7
7
  //#region src/providers/FileStorageProvider.d.ts
8
8
  declare abstract class FileStorageProvider {
@@ -519,7 +519,7 @@ interface BucketFileOptions {
519
519
  maxSize?: number;
520
520
  }
521
521
  declare class BucketDescriptor extends Descriptor<BucketDescriptorOptions> {
522
- readonly provider: MemoryFileStorageProvider | FileStorageProvider;
522
+ readonly provider: FileStorageProvider | MemoryFileStorageProvider;
523
523
  get name(): string;
524
524
  /**
525
525
  * Uploads a file to the bucket.
@@ -537,7 +537,7 @@ declare class BucketDescriptor extends Descriptor<BucketDescriptorOptions> {
537
537
  * Downloads a file from the bucket.
538
538
  */
539
539
  download(fileId: string): Promise<FileLike>;
540
- protected $provider(): MemoryFileStorageProvider | FileStorageProvider;
540
+ protected $provider(): FileStorageProvider | MemoryFileStorageProvider;
541
541
  }
542
542
  interface BucketFileOptions {
543
543
  /**
@@ -579,10 +579,10 @@ declare class LocalFileStorageProvider implements FileStorageProvider {
579
579
  protected path(container: string, fileId?: string): string;
580
580
  protected isErrorNoEntry(error: unknown): boolean;
581
581
  }
582
- declare const fileMetadataSchema: _sinclair_typebox0.TObject<{
583
- name: _sinclair_typebox0.TString;
584
- type: _sinclair_typebox0.TString;
585
- size: _sinclair_typebox0.TNumber;
582
+ declare const fileMetadataSchema: typebox0.TObject<{
583
+ name: typebox0.TString;
584
+ type: typebox0.TString;
585
+ size: typebox0.TNumber;
586
586
  }>;
587
587
  //#endregion
588
588
  //#region src/index.d.ts
package/command.d.ts CHANGED
@@ -3,7 +3,7 @@ import { Alepha, AlephaError, Async, Descriptor, KIND, Static, TObject, TSchema
3
3
  import * as fs from "node:fs/promises";
4
4
  import { glob } from "node:fs/promises";
5
5
  import * as _alepha_logger0 from "alepha/logger";
6
- import * as _sinclair_typebox0 from "@sinclair/typebox";
6
+ import * as typebox0 from "typebox";
7
7
 
8
8
  //#region src/helpers/Runner.d.ts
9
9
  type Task = {
@@ -59,14 +59,14 @@ declare class Runner {
59
59
  * within your Alepha application structure.
60
60
  */
61
61
  declare const $command: {
62
- <T extends TObject>(options: CommandDescriptorOptions<T>): CommandDescriptor<T>;
62
+ <T extends TObject, A extends TSchema>(options: CommandDescriptorOptions<T, A>): CommandDescriptor<T, A>;
63
63
  [KIND]: typeof CommandDescriptor;
64
64
  };
65
- interface CommandDescriptorOptions<T extends TObject> {
65
+ interface CommandDescriptorOptions<T extends TObject, A extends TSchema> {
66
66
  /**
67
67
  * The handler function to execute when the command is matched.
68
68
  */
69
- handler: (args: CommandHandlerArgs<T>) => Async<void>;
69
+ handler: (args: CommandHandlerArgs<T, A>) => Async<void>;
70
70
  /**
71
71
  * The name of the command. If omitted, the property key is used.
72
72
  *
@@ -85,18 +85,36 @@ interface CommandDescriptorOptions<T extends TObject> {
85
85
  * A TypeBox object schema defining the flags for the command.
86
86
  */
87
87
  flags?: T;
88
+ /**
89
+ * An optional TypeBox schema defining the arguments for the command.
90
+ *
91
+ * @example
92
+ * args: t.string()
93
+ * my-cli command <arg1: string>
94
+ *
95
+ * args: t.optional(t.string())
96
+ * my-cli command [arg1: string]
97
+ *
98
+ * args: t.tuple([t.string(), t.number()])
99
+ * my-cli command <arg1: string> <arg2: number>
100
+ *
101
+ * args: t.tuple([t.string(), t.optional(t.number())])
102
+ * my-cli command <arg1: string> [arg2: number]
103
+ */
104
+ args?: A;
88
105
  /**
89
106
  * If false, skip summary message at the end of the command execution.
90
107
  */
91
108
  summary?: boolean;
92
109
  }
93
- declare class CommandDescriptor<T extends TObject = TObject> extends Descriptor<CommandDescriptorOptions<T>> {
110
+ declare class CommandDescriptor<T extends TObject = TObject, A extends TSchema = TSchema> extends Descriptor<CommandDescriptorOptions<T, A>> {
94
111
  readonly flags: TObject<{}>;
95
112
  readonly aliases: string[];
96
113
  get name(): string;
97
114
  }
98
- interface CommandHandlerArgs<T extends TObject> {
115
+ interface CommandHandlerArgs<T extends TObject, A extends TSchema = TSchema> {
99
116
  flags: Static<T>;
117
+ args: A extends TSchema ? Static<A> : undefined;
100
118
  run: RunnerMethod;
101
119
  glob: typeof glob;
102
120
  fs: typeof fs;
@@ -132,7 +150,7 @@ declare class CliProvider {
132
150
  help: {
133
151
  aliases: string[];
134
152
  description: string;
135
- schema: _sinclair_typebox0.TBoolean;
153
+ schema: typebox0.TBoolean;
136
154
  };
137
155
  };
138
156
  protected readonly onReady: _alepha_core1.HookDescriptor<"ready">;
@@ -144,6 +162,10 @@ declare class CliProvider {
144
162
  aliases: string[];
145
163
  schema: TSchema;
146
164
  }[]): Record<string, any>;
165
+ protected parseCommandArgs(argv: string[], schema?: TSchema): any;
166
+ protected parseArgumentValue(value: string, schema: TSchema): any;
167
+ protected generateArgsUsage(schema?: TSchema): string;
168
+ protected getTypeName(schema: TSchema): string;
147
169
  printHelp(command?: CommandDescriptor<any>): void;
148
170
  private getMaxCmdLength;
149
171
  private getMaxFlagLength;
@@ -160,7 +182,7 @@ declare class CliProvider {
160
182
  * @module alepha.command
161
183
  */
162
184
  declare const AlephaCommand: _alepha_core1.Service<_alepha_core1.Module>;
163
- declare module "@sinclair/typebox" {
185
+ declare module "typebox" {
164
186
  interface StringOptions {
165
187
  /**
166
188
  * Additional aliases for the flags.