alepha 0.7.7 → 0.8.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/batch.cjs ADDED
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+ var m = require('@alepha/batch');
3
+ Object.keys(m).forEach(function (k) {
4
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
5
+ enumerable: true,
6
+ get: function () { return m[k]; }
7
+ });
8
+ });
package/batch.d.ts ADDED
@@ -0,0 +1,114 @@
1
+ import { Alepha, HookDescriptor, KIND, Logger, Module, OPTIONS, Static, TSchema } from "alepha";
2
+ import { DateTimeProvider, DurationLike, Timeout } from "alepha/datetime";
3
+ import { RetryDescriptorOptions } from "alepha/retry";
4
+
5
+ //#region src/descriptors/$batch.d.ts
6
+ declare const KEY = "BATCH";
7
+ interface BatchDescriptorOptions<TItem extends TSchema, TResponse = any> {
8
+ /**
9
+ * A TypeBox schema to validate each item pushed to the batch.
10
+ */
11
+ schema: TItem;
12
+ /**
13
+ * The handler function that processes a batch of items.
14
+ */
15
+ handler: (items: Static<TItem>[]) => TResponse;
16
+ /**
17
+ * The maximum number of items in a batch. When this size is reached,
18
+ * the batch is flushed automatically.
19
+ * @default 10
20
+ */
21
+ maxSize?: number;
22
+ /**
23
+ * The maximum duration to wait before flushing a batch, even if it's not full.
24
+ * Starts from the moment the first item is added to a partition.
25
+ * @default [1, "second"]
26
+ */
27
+ maxDuration?: DurationLike;
28
+ /**
29
+ * A function to determine the partition key for an item. Items with the
30
+ * same key are batched together. If not provided, all items are placed in a single, default partition.
31
+ */
32
+ partitionBy?: (item: Static<TItem>) => string;
33
+ /**
34
+ * The maximum number of concurrent `handler` executions.
35
+ * @default 1
36
+ */
37
+ concurrency?: number;
38
+ /**
39
+ * Retry options for the batch handler if it fails.
40
+ * Leverages the `@alepha/retry` module.
41
+ */
42
+ retry?: Omit<RetryDescriptorOptions<() => Array<Static<TItem>>>, "handler">;
43
+ }
44
+ interface BatchDescriptor<TItem extends TSchema, TResponse = any> {
45
+ [KIND]: typeof KEY;
46
+ [OPTIONS]: BatchDescriptorOptions<TItem, TResponse>;
47
+ /**
48
+ * Pushes an item into the batch. The item will be processed
49
+ * asynchronously with other items when the batch is flushed.
50
+ */
51
+ push: (item: Static<TItem>) => Promise<TResponse>;
52
+ /**
53
+ * Manually triggers a flush for one or all partitions.
54
+ * @param partitionKey Optional. If provided, only flushes the specified partition. Otherwise, all partitions are flushed.
55
+ */
56
+ flush: (partitionKey?: string) => Promise<TResponse>;
57
+ }
58
+ /**
59
+ * Creates a batch processor. This is useful for grouping multiple operations
60
+ * (like API calls or database writes) into a single one to improve performance.
61
+ */
62
+ declare const $batch: {
63
+ <TItem extends TSchema, TResponse>(options: BatchDescriptorOptions<TItem, TResponse>): BatchDescriptor<TItem, TResponse>;
64
+ [KIND]: string;
65
+ };
66
+ //#endregion
67
+ //#region src/providers/BatchDescriptorProvider.d.ts
68
+ interface PartitionState<TItem extends TSchema> {
69
+ items: Static<TItem>[];
70
+ timeout?: Timeout;
71
+ // Promises to resolve/reject when the batch is processed
72
+ resolvers: Array<{
73
+ resolve: (result?: any) => void;
74
+ reject: (reason?: any) => void;
75
+ }>;
76
+ }
77
+ interface BatchInstance<TItem extends TSchema> {
78
+ id: string;
79
+ options: BatchDescriptorOptions<TItem>;
80
+ partitions: Map<string, PartitionState<TItem>>;
81
+ activeHandlers: PromiseWithResolvers<void>[];
82
+ handler: (items: Static<TItem>[]) => Promise<void>;
83
+ }
84
+ declare class BatchDescriptorProvider {
85
+ protected readonly alepha: Alepha;
86
+ protected readonly log: Logger;
87
+ protected readonly dateTimeProvider: DateTimeProvider;
88
+ protected readonly instances: Map<string, BatchInstance<any>>;
89
+ protected readonly configure: HookDescriptor<"configure">;
90
+ // On application stop, flush all pending batches gracefully.
91
+ protected readonly onStop: HookDescriptor<"stop">;
92
+ protected push<TItem>(id: string, item: TItem): Promise<void>;
93
+ protected flush(id: string, partitionKey?: string): Promise<void>;
94
+ protected flushPartition<TItem extends TSchema>(instance: BatchInstance<TItem>, partitionKey: string): Promise<void>;
95
+ }
96
+ //#endregion
97
+ //#region src/index.d.ts
98
+ // ---------------------------------------------------------------------------------------------------------------------
99
+ /**
100
+ * Alepha Batch Module
101
+ *
102
+ * This module provides a powerful batch processing utility that can group
103
+ * multiple operations into a single one based on size, time, or partitions.
104
+ *
105
+ * @see {@link $batch}
106
+ * @module alepha.batch
107
+ */
108
+ declare class AlephaBatch implements Module {
109
+ readonly name = "alepha.batch";
110
+ readonly $services: (alepha: Alepha) => Alepha;
111
+ }
112
+ //#endregion
113
+ export { $batch, AlephaBatch, BatchDescriptor, BatchDescriptorOptions, BatchDescriptorProvider };
114
+ //# sourceMappingURL=index.d.ts.map
package/batch.js ADDED
@@ -0,0 +1 @@
1
+ export * from '@alepha/batch'
package/cache/redis.d.ts CHANGED
@@ -1,22 +1,18 @@
1
- import { CacheProvider } from "@alepha/cache";
2
- import * as _alepha_core2 from "@alepha/core";
3
- import { Alepha, Module, Static } from "@alepha/core";
4
- import { RedisProvider } from "@alepha/redis";
5
- import * as _sinclair_typebox0 from "@sinclair/typebox";
1
+ import { CacheProvider } from "alepha/cache";
2
+ import { Alepha, Logger, Module, Static, TObject, TOptional, TString } from "alepha";
3
+ import { RedisProvider } from "alepha/redis";
6
4
 
7
5
  //#region src/providers/RedisCacheProvider.d.ts
8
- declare const envSchema: _alepha_core2.TObject<{
9
- REDIS_CACHE_PREFIX: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
6
+ declare const envSchema: TObject<{
7
+ REDIS_CACHE_PREFIX: TOptional<TString>;
10
8
  }>;
11
9
  declare module "alepha" {
12
10
  interface Env extends Partial<Static<typeof envSchema>> {}
13
11
  }
14
12
  declare class RedisCacheProvider implements CacheProvider {
15
- protected readonly log: _alepha_core2.Logger;
13
+ protected readonly log: Logger;
16
14
  protected readonly redisProvider: RedisProvider;
17
- protected readonly env: {
18
- REDIS_CACHE_PREFIX?: string | undefined;
19
- };
15
+ protected readonly env: Static<typeof envSchema>;
20
16
  protected readonly alepha: Alepha;
21
17
  get(name: string, key: string): Promise<Uint8Array | undefined>;
22
18
  set(name: string, key: string, value: Uint8Array | string, ttl?: number): Promise<Uint8Array>;
@@ -27,14 +23,15 @@ declare class RedisCacheProvider implements CacheProvider {
27
23
  }
28
24
  //#endregion
29
25
  //#region src/index.d.ts
26
+ // ---------------------------------------------------------------------------------------------------------------------
30
27
  /**
31
- * Alepha Cache Redis Module
32
- *
33
- * Plugin for Alepha Cache that provides Redis caching capabilities.
34
- *
35
- * @see {@link RedisCacheProvider}
36
- * @module alepha.cache.redis
37
- */
28
+ * Alepha Cache Redis Module
29
+ *
30
+ * Plugin for Alepha Cache that provides Redis caching capabilities.
31
+ *
32
+ * @see {@link RedisCacheProvider}
33
+ * @module alepha.cache.redis
34
+ */
38
35
  declare class AlephaCacheRedis implements Module {
39
36
  readonly name = "alepha.cache.redis";
40
37
  readonly $services: (alepha: Alepha) => Alepha;
package/cache.d.ts CHANGED
@@ -1,43 +1,41 @@
1
- import * as _alepha_core0 from "@alepha/core";
2
- import * as _alepha_core5 from "@alepha/core";
3
- import { Alepha, KIND, Module, OPTIONS, Static } from "@alepha/core";
4
- import { DateTimeProvider, DurationLike, Timeout } from "@alepha/datetime";
5
- import * as _sinclair_typebox1 from "@sinclair/typebox";
1
+ import { Alepha, HookDescriptor, KIND, Logger, Module, OPTIONS, Static, TBoolean, TNumber, TObject, TOptional, TString } from "alepha";
2
+ import { DateTimeProvider, DurationLike, Timeout } from "alepha/datetime";
6
3
 
7
4
  //#region src/providers/CacheProvider.d.ts
5
+
8
6
  /**
9
- * Cache provider interface.
10
- *
11
- * All methods are asynchronous and return promises.
12
- * Values are stored as Uint8Array.
13
- */
7
+ * Cache provider interface.
8
+ *
9
+ * All methods are asynchronous and return promises.
10
+ * Values are stored as Uint8Array.
11
+ */
14
12
  declare abstract class CacheProvider {
15
13
  /**
16
- * Get the value of a key.
17
- *
18
- * @param name Cache name, used to group keys. Should be Redis-like "some:group:name" format.
19
- * @param key The key of the value to get.
20
- *
21
- * @return The value of the key, or undefined if the key does not exist.
22
- */
14
+ * Get the value of a key.
15
+ *
16
+ * @param name Cache name, used to group keys. Should be Redis-like "some:group:name" format.
17
+ * @param key The key of the value to get.
18
+ *
19
+ * @return The value of the key, or undefined if the key does not exist.
20
+ */
23
21
  abstract get(name: string, key: string): Promise<Uint8Array | undefined>;
24
22
  /**
25
- * Set the string value of a key.
26
- *
27
- * @param name Cache name, used to group keys. Should be Redis-like "some:group:name" format.
28
- * @param key The key of the value to set.
29
- * @param value The value to set.
30
- * @param ttl The time-to-live of the key, in milliseconds.
31
- *
32
- * @return The value of the key.
33
- */
23
+ * Set the string value of a key.
24
+ *
25
+ * @param name Cache name, used to group keys. Should be Redis-like "some:group:name" format.
26
+ * @param key The key of the value to set.
27
+ * @param value The value to set.
28
+ * @param ttl The time-to-live of the key, in milliseconds.
29
+ *
30
+ * @return The value of the key.
31
+ */
34
32
  abstract set(name: string, key: string, value: Uint8Array, ttl?: number): Promise<Uint8Array>;
35
33
  /**
36
- * Remove the specified keys.
37
- *
38
- * @param name Cache name, used to group keys. Should be Redis-like "some:group:name" format.
39
- * @param keys The keys to delete.
40
- */
34
+ * Remove the specified keys.
35
+ *
36
+ * @param name Cache name, used to group keys. Should be Redis-like "some:group:name" format.
37
+ * @param keys The keys to delete.
38
+ */
41
39
  abstract del(name: string, ...keys: string[]): Promise<void>;
42
40
  abstract has(name: string, key: string): Promise<boolean>;
43
41
  abstract keys(name: string): Promise<string[]>;
@@ -46,76 +44,77 @@ declare abstract class CacheProvider {
46
44
  //#region src/descriptors/$cache.d.ts
47
45
  declare const KEY = "CACHE";
48
46
  /**
49
- * Cache Descriptor
50
- */
47
+ * Cache Descriptor
48
+ */
51
49
  declare const $cache: {
52
50
  <TReturn = string, TParameter extends any[] = any[]>(options?: CacheDescriptorOptions<TReturn, TParameter>): CacheDescriptor<TReturn, TParameter>;
53
51
  [KIND]: string;
54
52
  };
53
+ // ---------------------------------------------------------------------------------------------------------------------
55
54
  interface CacheDescriptorOptions<TReturn, TParameter extends any[] = any[]> {
56
55
  /**
57
- * The cache name. This is useful for invalidating multiple caches at once.
58
- *
59
- * Store key as `cache:$name:$key`.
60
- *
61
- * @default ClassName:methodName
62
- */
56
+ * The cache name. This is useful for invalidating multiple caches at once.
57
+ *
58
+ * Store key as `cache:$name:$key`.
59
+ *
60
+ * @default ClassName:methodName
61
+ */
63
62
  name?: string;
64
63
  /**
65
- * Function which returns cached data.
66
- * @param args Arguments for handler.
67
- */
64
+ * Function which returns cached data.
65
+ * @param args Arguments for handler.
66
+ */
68
67
  handler?: (...args: TParameter) => TReturn;
69
68
  /**
70
- * The key generator for the cache.
71
- * If not provided, the arguments will be json.stringify().
72
- */
69
+ * The key generator for the cache.
70
+ * If not provided, the arguments will be json.stringify().
71
+ */
73
72
  key?: (...args: TParameter) => string;
74
73
  /**
75
- * The store provider for the cache.
76
- * If not provided, the default store provider will be used.
77
- */
74
+ * The store provider for the cache.
75
+ * If not provided, the default store provider will be used.
76
+ */
78
77
  provider?: CacheProvider | (() => CacheProvider) | "memory";
79
78
  /**
80
- * The time-to-live for the cache in seconds.
81
- * Set 0 to skip expiration.
82
- *
83
- * @default 300 (5 minutes).
84
- */
79
+ * The time-to-live for the cache in seconds.
80
+ * Set 0 to skip expiration.
81
+ *
82
+ * @default 300 (5 minutes).
83
+ */
85
84
  ttl?: DurationLike;
86
85
  /**
87
- * If the cache is disabled.
88
- */
86
+ * If the cache is disabled.
87
+ */
89
88
  disabled?: boolean;
90
89
  }
91
90
  interface CacheDescriptor<TReturn = any, TParameter extends any[] = any[]> {
92
91
  [KIND]: typeof KEY;
93
92
  [OPTIONS]: CacheDescriptorOptions<TReturn, TParameter>;
94
93
  /**
95
- * Cache handler.
96
- */
94
+ * Cache handler.
95
+ */
97
96
  (...args: TParameter): Promise<TReturn>;
98
97
  /**
99
- * Cache key generator.
100
- */
98
+ * Cache key generator.
99
+ */
101
100
  key: (...args: TParameter) => string;
102
101
  /**
103
- * Invalidate cache by keys.
104
- */
102
+ * Invalidate cache by keys.
103
+ */
105
104
  invalidate: (...keys: string[]) => Promise<void>;
106
105
  /**
107
- * Set cache with key, value and ttl.
108
- *
109
- * @param key
110
- * @param value
111
- * @param ttl
112
- */
106
+ * Set cache with key, value and ttl.
107
+ *
108
+ * @param key
109
+ * @param value
110
+ * @param ttl
111
+ */
113
112
  set: (key: string, value: TReturn, ttl?: DurationLike) => Promise<void>;
114
113
  /**
115
- * Get cache by key.
116
- *
117
- * @param key
118
- */
114
+ * Get cache by key.
115
+ *
116
+ * @param key
117
+ */
119
118
  get: (key: string) => Promise<TReturn | undefined>;
120
119
  }
121
120
  //#endregion
@@ -128,7 +127,7 @@ type CacheValue = {
128
127
  };
129
128
  declare class MemoryCacheProvider implements CacheProvider {
130
129
  protected readonly dateTimeProvider: DateTimeProvider;
131
- protected readonly log: _alepha_core0.Logger;
130
+ protected readonly log: Logger;
132
131
  protected store: Record<CacheName, Record<CacheKey, CacheValue>>;
133
132
  get(name: string, key: string): Promise<Uint8Array | undefined>;
134
133
  set(name: string, key: string, value: Uint8Array, ttl?: number): Promise<Uint8Array>;
@@ -138,10 +137,10 @@ declare class MemoryCacheProvider implements CacheProvider {
138
137
  }
139
138
  //#endregion
140
139
  //#region src/providers/CacheDescriptorProvider.d.ts
141
- declare const envSchema: _alepha_core5.TObject<{
142
- CACHE_DEFAULT_TTL: _sinclair_typebox1.TNumber;
143
- CACHE_PREFIX: _sinclair_typebox1.TOptional<_sinclair_typebox1.TString>;
144
- CACHE_ENABLED: _sinclair_typebox1.TBoolean;
140
+ declare const envSchema: TObject<{
141
+ CACHE_DEFAULT_TTL: TNumber;
142
+ CACHE_PREFIX: TOptional<TString>;
143
+ CACHE_ENABLED: TBoolean;
145
144
  }>;
146
145
  declare module "alepha" {
147
146
  interface Env extends Partial<Static<typeof envSchema>> {}
@@ -151,57 +150,53 @@ declare class CacheDescriptorProvider {
151
150
  protected readonly cacheProvider: CacheProvider;
152
151
  protected readonly memoryCacheProvider: MemoryCacheProvider;
153
152
  protected readonly dateTimeProvider: DateTimeProvider;
154
- protected readonly env: {
155
- CACHE_PREFIX?: string | undefined;
156
- CACHE_DEFAULT_TTL: number;
157
- CACHE_ENABLED: boolean;
158
- };
153
+ protected readonly env: Static<typeof envSchema>;
159
154
  protected readonly caches: Cache[];
160
- protected readonly configure: _alepha_core5.HookDescriptor<"configure">;
161
- register(cache: Cache): Cache<any, any[]>;
155
+ protected encoder: TextEncoder;
156
+ protected decoder: TextDecoder;
157
+ protected codes: {
158
+ BINARY: number;
159
+ JSON: number;
160
+ STRING: number;
161
+ };
162
+ protected readonly configure: HookDescriptor<"configure">;
163
+ register(cache: Cache): Cache;
162
164
  processDescriptors(): void;
163
165
  getCaches(): Cache[];
164
166
  /**
165
- * Clear all cache entries.
166
- */
167
+ * Clear all cache entries.
168
+ */
167
169
  clear(): Promise<void>;
168
170
  /**
169
- * Get the store provider for the given cache options.
170
- *
171
- * @param options
172
- */
171
+ * Get the store provider for the given cache options.
172
+ *
173
+ * @param options
174
+ */
173
175
  provider(options: Pick<CacheDescriptorOptions<any[], any>, "provider">): CacheProvider;
174
176
  /**
175
- * Get the cache key for the given state and arguments.
176
- */
177
+ * Get the cache key for the given state and arguments.
178
+ */
177
179
  key(cache: Cache, ...args: any[]): string;
178
180
  /**
179
- * Invalidate the cache for the given state and arguments.
180
- */
181
+ * Invalidate the cache for the given state and arguments.
182
+ */
181
183
  invalidate(cache: Cache, ...keys: string[]): Promise<void>;
182
184
  /**
183
- * Run the cache handler with the given state and arguments.
184
- * You must run on a $cache with a handler defined.
185
- */
185
+ * Run the cache handler with the given state and arguments.
186
+ * You must run on a $cache with a handler defined.
187
+ */
186
188
  run<TReturn, TParameter extends any[]>(cache: Cache<TReturn, TParameter>, ...args: TParameter): Promise<TReturn>;
187
189
  get<TReturn>(cache: Cache<TReturn>, key: string): Promise<TReturn | undefined>;
188
190
  /**
189
- * Manually set a value in the cache.
190
- * It's used by .run() method, but you will need it when you don't have cache handler defined.
191
- *
192
- * @param cache Cache object with all configuration and options (even TTL).
193
- * @param key Cache key, build with .key() method or manually.
194
- * @param value Value to store in cache.
195
- * @param ttl Override cache.ttl option.
196
- */
191
+ * Manually set a value in the cache.
192
+ * It's used by .run() method, but you will need it when you don't have cache handler defined.
193
+ *
194
+ * @param cache Cache object with all configuration and options (even TTL).
195
+ * @param key Cache key, build with .key() method or manually.
196
+ * @param value Value to store in cache.
197
+ * @param ttl Override cache.ttl option.
198
+ */
197
199
  set<TReturn>(cache: Cache<TReturn>, key: string, value: TReturn, ttl?: DurationLike): Promise<void>;
198
- protected encoder: TextEncoder;
199
- protected decoder: TextDecoder;
200
- protected codes: {
201
- BINARY: number;
202
- JSON: number;
203
- STRING: number;
204
- };
205
200
  protected serialize<TReturn>(value: TReturn): Uint8Array;
206
201
  protected deserialize<TReturn>(uint8Array: Uint8Array): Promise<TReturn>;
207
202
  }
@@ -211,15 +206,16 @@ interface Cache<TReturn = any, TParameter extends any[] = any[]> {
211
206
  }
212
207
  //#endregion
213
208
  //#region src/index.d.ts
209
+ // ---------------------------------------------------------------------------------------------------------------------
214
210
  /**
215
- * Alepha Cache Module
216
- *
217
- * This module provides a caching mechanism for Alepha applications.
218
- *
219
- * @see {@link $cache}
220
- * @see {@link CacheProvider}
221
- * @module alepha.cache
222
- */
211
+ * Alepha Cache Module
212
+ *
213
+ * This module provides a caching mechanism for Alepha applications.
214
+ *
215
+ * @see {@link $cache}
216
+ * @see {@link CacheProvider}
217
+ * @module alepha.cache
218
+ */
223
219
  declare class AlephaCache implements Module {
224
220
  readonly name = "alepha.cache";
225
221
  readonly $services: (alepha: Alepha) => Alepha;
package/command.cjs ADDED
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+ var m = require('@alepha/command');
3
+ Object.keys(m).forEach(function (k) {
4
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
5
+ enumerable: true,
6
+ get: function () { return m[k]; }
7
+ });
8
+ });
package/command.d.ts ADDED
@@ -0,0 +1,154 @@
1
+ import { Alepha, AlephaError, Async, HookDescriptor, KIND, Logger, Module, OPTIONS, Static, TObject, TProperties, TSchema, TString } from "alepha";
2
+ import * as fs from "node:fs/promises";
3
+ import { glob } from "node:fs/promises";
4
+
5
+ //#region src/helpers/Runner.d.ts
6
+ type Task = {
7
+ name: string;
8
+ handler: () => any;
9
+ };
10
+ interface Timer {
11
+ name: string;
12
+ duration: string;
13
+ }
14
+ interface RunnerMethod {
15
+ (cmd: string | Array<string | Task>, fn?: () => any): Promise<string>;
16
+ rm: (glob: string | string[]) => Promise<string>;
17
+ }
18
+ declare class Runner {
19
+ protected readonly log: Logger;
20
+ protected readonly timers: Timer[];
21
+ protected readonly startTime: number;
22
+ readonly run: RunnerMethod;
23
+ constructor(log: Logger);
24
+ protected exec(cmd: string): Promise<string>;
25
+ /**
26
+ * Executes one or more tasks.
27
+ *
28
+ * @param task - A single task or an array of tasks to run in parallel.
29
+ */
30
+ protected execute(task: Task | Task[]): Promise<string>;
31
+ /**
32
+ * Prints a summary of all executed tasks and their durations.
33
+ */
34
+ summary(): void;
35
+ protected executeTask(task: Task): Promise<string>;
36
+ protected renderTable(data: string[][]): void;
37
+ }
38
+ //#endregion
39
+ //#region src/descriptors/$command.d.ts
40
+ declare const KEY = "COMMAND";
41
+ interface CommandDescriptorOptions<T extends TObject> {
42
+ /**
43
+ * The handler function to execute when the command is matched.
44
+ */
45
+ handler: (args: {
46
+ flags: Static<T>;
47
+ run: RunnerMethod;
48
+ glob: typeof glob;
49
+ fs: typeof fs;
50
+ }) => Async<void>;
51
+ /**
52
+ * The name of the command. If omitted, the property key is used.
53
+ *
54
+ * An empty string "" denotes the root command.
55
+ */
56
+ name?: string;
57
+ /**
58
+ * A short description of the command, shown in the help message.
59
+ */
60
+ description?: string;
61
+ /**
62
+ * An array of alternative names for the command.
63
+ */
64
+ aliases?: string[];
65
+ /**
66
+ * A TypeBox object schema defining the flags for the command.
67
+ */
68
+ flags?: T;
69
+ }
70
+ interface CommandDescriptor<T extends TObject> {
71
+ [KIND]: typeof KEY;
72
+ [OPTIONS]: CommandDescriptorOptions<T>;
73
+ /**
74
+ * Executes the command. This is a placeholder and will be replaced by the provider.
75
+ */
76
+ (flags: Static<T>): Promise<void>;
77
+ }
78
+ /**
79
+ * Declares a CLI command.
80
+ *
81
+ * This descriptor allows you to define a command, its flags, and its handler
82
+ * within your Alepha application structure.
83
+ */
84
+ declare const $command: {
85
+ <T extends TObject>(options: CommandDescriptorOptions<T>): CommandDescriptor<T>;
86
+ [KIND]: string;
87
+ };
88
+ //#endregion
89
+ //#region src/errors/CommandError.d.ts
90
+ declare class CommandError extends AlephaError {}
91
+ //#endregion
92
+ //#region src/providers/CommandDescriptorProvider.d.ts
93
+ interface Command {
94
+ key: string;
95
+ name: string;
96
+ description?: string;
97
+ aliases: string[];
98
+ flags: TObject<TProperties>;
99
+ handler: (flags: any) => Promise<void>;
100
+ }
101
+ declare const envSchema: TObject<{
102
+ CLI_NAME: TString;
103
+ CLI_DESCRIPTION: TString;
104
+ }>;
105
+ declare module "alepha" {
106
+ interface Env extends Partial<Static<typeof envSchema>> {}
107
+ }
108
+ declare class CommandDescriptorProvider {
109
+ protected readonly env: Static<typeof envSchema>;
110
+ protected readonly alepha: Alepha;
111
+ protected readonly log: Logger;
112
+ protected commands: Command[];
113
+ options: {
114
+ name: string;
115
+ description: string;
116
+ argv: string[];
117
+ };
118
+ protected readonly globalFlags: Record<string, {
119
+ aliases: string[];
120
+ description: string;
121
+ schema: TSchema;
122
+ }>;
123
+ protected readonly onConfigure: HookDescriptor<"configure">;
124
+ protected readonly onReady: HookDescriptor<"ready">;
125
+ private findCommand;
126
+ protected parseCommandFlags(argv: string[], schema: TObject): Record<string, any>;
127
+ protected parseFlags(argv: string[], flagDefs: {
128
+ key: string;
129
+ aliases: string[];
130
+ schema: TSchema;
131
+ }[]): Record<string, any>;
132
+ private printHelp;
133
+ private getMaxCmdLength;
134
+ private getMaxFlagLength;
135
+ }
136
+ //#endregion
137
+ //#region src/index.d.ts
138
+ // ---------------------------------------------------------------------------------------------------------------------
139
+ /**
140
+ * Alepha Command Module
141
+ *
142
+ * This module provides a powerful way to build command-line interfaces
143
+ * directly within your Alepha application, using declarative descriptors.
144
+ *
145
+ * @see {@link $command}
146
+ * @module alepha.command
147
+ */
148
+ declare class AlephaCommand implements Module {
149
+ readonly name = "alepha.command";
150
+ readonly $services: (alepha: Alepha) => Alepha;
151
+ }
152
+ //#endregion
153
+ export { $command, AlephaCommand, CommandDescriptor, CommandDescriptorOptions, CommandDescriptorProvider, CommandError, Runner, RunnerMethod, Task };
154
+ //# sourceMappingURL=index.d.ts.map
package/command.js ADDED
@@ -0,0 +1 @@
1
+ export * from '@alepha/command'