alepha 0.7.7 → 0.8.1

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.
Files changed (55) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +7 -34
  3. package/batch.cjs +8 -0
  4. package/batch.d.ts +147 -0
  5. package/batch.js +1 -0
  6. package/cache/redis.d.ts +13 -18
  7. package/cache.d.ts +183 -119
  8. package/command.cjs +8 -0
  9. package/command.d.ts +152 -0
  10. package/command.js +1 -0
  11. package/core.d.ts +846 -838
  12. package/datetime.d.ts +78 -78
  13. package/file.cjs +8 -0
  14. package/file.d.ts +46 -0
  15. package/file.js +1 -0
  16. package/lock/redis.d.ts +10 -12
  17. package/lock.d.ts +73 -80
  18. package/package.json +86 -34
  19. package/postgres.d.ts +348 -170
  20. package/queue/redis.d.ts +13 -13
  21. package/queue.d.ts +107 -18
  22. package/react/auth.d.ts +22 -16
  23. package/react/head.d.ts +10 -4
  24. package/react.d.ts +206 -49
  25. package/redis.d.ts +23 -27
  26. package/retry.d.ts +75 -54
  27. package/router.cjs +8 -0
  28. package/router.d.ts +45 -0
  29. package/router.js +1 -0
  30. package/scheduler.d.ts +15 -16
  31. package/security.d.ts +229 -40
  32. package/server/cache.d.ts +7 -8
  33. package/server/compress.cjs +8 -0
  34. package/server/compress.d.ts +26 -0
  35. package/server/compress.js +1 -0
  36. package/server/cookies.d.ts +249 -18
  37. package/server/cors.d.ts +7 -3
  38. package/server/health.d.ts +21 -24
  39. package/server/helmet.cjs +8 -0
  40. package/server/helmet.d.ts +70 -0
  41. package/server/helmet.js +1 -0
  42. package/server/links.d.ts +87 -93
  43. package/server/metrics.cjs +8 -0
  44. package/server/metrics.d.ts +35 -0
  45. package/server/metrics.js +1 -0
  46. package/server/multipart.cjs +8 -0
  47. package/server/multipart.d.ts +46 -0
  48. package/server/multipart.js +1 -0
  49. package/server/proxy.d.ts +11 -11
  50. package/server/static.d.ts +70 -55
  51. package/server/swagger.d.ts +55 -54
  52. package/server.d.ts +273 -123
  53. package/topic/redis.d.ts +22 -23
  54. package/topic.d.ts +26 -19
  55. package/vite.d.ts +59 -36
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Feunard
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Feunard
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,44 +1,17 @@
1
- <div align="center">
1
+ # Alepha Alepha
2
2
 
3
- <h1 >
4
- <img
5
- src="https://raw.githubusercontent.com/feunard/alepha/main/assets/logo.png"
6
- width="128"
7
- height="128"
8
- alt="Logo"
9
- valign="middle"
10
- />
11
- Alepha
12
- </h1>
13
- <p style="max-width: 512px">
14
- 🚧
15
- </p>
16
- <a href="https://www.npmjs.com/package/alepha"><img src="https://img.shields.io/npm/v/alepha.svg" alt="npm"/></a>
17
- <a href="https://www.npmjs.com/package/alepha"><img src="https://img.shields.io/npm/l/alepha.svg" alt="npm"/></a>
18
- <a href="https://codecov.io/gh/feunard/alepha"><img src="https://codecov.io/gh/feunard/alepha/graph/badge.svg?token=ZDLWI514CP" alt="npm"/></a>
19
- <a href="https://www.npmjs.com/package/alepha"><img src="https://img.shields.io/npm/dt/alepha.svg" alt="npm"/></a>
20
- <a href="https://github.com/feunard/alepha"><img src="https://img.shields.io/github/stars/feunard/alepha.svg?style=social" alt="GitHub stars"/></a>
21
- </div>
3
+ TypeScript framework for building full-stack apps with strict conventions, and React-based SPA or SSR without filesystem-based routing.
22
4
 
23
5
  ## Installation
24
6
 
7
+ This package is part of the Alepha framework and can be installed via the all-in-one package:
8
+
25
9
  ```bash
26
10
  npm install alepha
27
11
  ```
28
12
 
29
- ## Usage
30
-
31
- Minimalist http server with a single endpoint.
32
-
33
- ```ts
34
- import { run } from "alepha";
35
- import { $action } from "alepha/server";
13
+ Alternatively, you can install it individually:
36
14
 
37
- class App {
38
- hello = $action({
39
- handler: () => "Hello world!",
40
- })
41
- }
42
-
43
- run(App);
15
+ ```bash
16
+ npm install @alepha/core alepha
44
17
  ```
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,147 @@
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
+ /**
8
+ * Creates a batch processor. This is useful for grouping multiple operations
9
+ * (like API calls or database writes) into a single one to improve performance.
10
+ */
11
+ declare const $batch: {
12
+ <TItem extends TSchema, TResponse>(options: BatchDescriptorOptions<TItem, TResponse>): BatchDescriptor<TItem, TResponse>;
13
+ [KIND]: string;
14
+ };
15
+ // ---------------------------------------------------------------------------------------------------------------------
16
+ interface BatchDescriptorOptions<TItem extends TSchema, TResponse = any> {
17
+ /**
18
+ * A TypeBox schema to validate each item pushed to the batch.
19
+ */
20
+ schema: TItem;
21
+ /**
22
+ * The handler function that processes a batch of items.
23
+ */
24
+ handler: (items: Static<TItem>[]) => TResponse;
25
+ /**
26
+ * The maximum number of items in a batch. When this size is reached,
27
+ * the batch is flushed automatically.
28
+ * @default 10
29
+ */
30
+ maxSize?: number;
31
+ /**
32
+ * The maximum duration to wait before flushing a batch, even if it's not full.
33
+ * Starts from the moment the first item is added to a partition.
34
+ * @default [1, "second"]
35
+ */
36
+ maxDuration?: DurationLike;
37
+ /**
38
+ * A function to determine the partition key for an item. Items with the
39
+ * same key are batched together. If not provided, all items are placed in a single, default partition.
40
+ */
41
+ partitionBy?: (item: Static<TItem>) => string;
42
+ /**
43
+ * The maximum number of concurrent `handler` executions.
44
+ * @default 1
45
+ */
46
+ concurrency?: number;
47
+ /**
48
+ * Retry options for the batch handler if it fails.
49
+ * Leverages the `@alepha/retry` module.
50
+ */
51
+ retry?: Omit<RetryDescriptorOptions<() => Array<Static<TItem>>>, "handler">;
52
+ }
53
+ interface BatchDescriptor<TItem extends TSchema, TResponse = any> {
54
+ [KIND]: typeof KEY;
55
+ [OPTIONS]: BatchDescriptorOptions<TItem, TResponse>;
56
+ /**
57
+ * Pushes an item into the batch. The item will be processed
58
+ * asynchronously with other items when the batch is flushed.
59
+ */
60
+ push: (item: Static<TItem>) => Promise<TResponse>;
61
+ /**
62
+ * Manually triggers a flush for one or all partitions.
63
+ * @param partitionKey Optional. If provided, only flushes the specified partition. Otherwise, all partitions are flushed.
64
+ */
65
+ flush: (partitionKey?: string) => Promise<TResponse>;
66
+ }
67
+ //#endregion
68
+ //#region src/providers/BatchDescriptorProvider.d.ts
69
+ interface PartitionState<TItem extends TSchema> {
70
+ items: Static<TItem>[];
71
+ timeout?: Timeout;
72
+ // Promises to resolve/reject when the batch is processed
73
+ resolvers: Array<{
74
+ resolve: (result?: any) => void;
75
+ reject: (reason?: any) => void;
76
+ }>;
77
+ }
78
+ interface BatchInstance<TItem extends TSchema> {
79
+ id: string;
80
+ options: BatchDescriptorOptions<TItem>;
81
+ partitions: Map<string, PartitionState<TItem>>;
82
+ activeHandlers: PromiseWithResolvers<void>[];
83
+ handler: (items: Static<TItem>[]) => Promise<void>;
84
+ }
85
+ /**
86
+ * Process every $batch.
87
+ */
88
+ declare class BatchDescriptorProvider {
89
+ protected readonly alepha: Alepha;
90
+ protected readonly log: Logger;
91
+ protected readonly dateTimeProvider: DateTimeProvider;
92
+ protected readonly instances: Map<string, BatchInstance<any>>;
93
+ protected readonly configure: HookDescriptor<"configure">;
94
+ // On application stop, flush all pending batches gracefully.
95
+ protected readonly onStop: HookDescriptor<"stop">;
96
+ protected push<TItem>(id: string, item: TItem): Promise<void>;
97
+ protected flush(id: string, partitionKey?: string): Promise<void>;
98
+ protected flushPartition<TItem extends TSchema>(instance: BatchInstance<TItem>, partitionKey: string): Promise<void>;
99
+ }
100
+ //#endregion
101
+ //#region src/index.d.ts
102
+ // ---------------------------------------------------------------------------------------------------------------------
103
+ /**
104
+ * This module allows you to group multiple asynchronous operations into a single "batch," which is then processed together.
105
+ * This is an essential pattern for improving performance, reducing I/O, and interacting efficiently with rate-limited APIs or databases.
106
+ *
107
+ * ### Basic Example: A Simple Event Logger
108
+ *
109
+ * Let's create a batch processor that collects log messages and prints them to the console every 5 seconds or whenever 10 messages have been collected.
110
+ *
111
+ * ```ts
112
+ * import { Alepha, $hook, run, t } from "alepha";
113
+ * import { $batch } from "alepha/batch";
114
+ *
115
+ * class LoggingService {
116
+ * // define the batch processor
117
+ * logBatch = $batch({
118
+ * schema: t.string(),
119
+ * maxSize: 10,
120
+ * maxDuration: [5, "seconds"],
121
+ * handler: async (items) => {
122
+ * console.log(`[BATCH LOG] Processing ${items.length} events:`, items);
123
+ * },
124
+ * });
125
+ *
126
+ * // example of how to use it
127
+ * onReady = $hook({
128
+ * on: "ready",
129
+ * handler: async () => {
130
+ * this.logBatch.push("Application started.");
131
+ * this.logBatch.push("User authenticated.");
132
+ * // ... more events pushed from elsewhere in the app
133
+ * },
134
+ * });
135
+ * }
136
+ * ```
137
+ *
138
+ * @see {@link $batch}
139
+ * @module alepha.batch
140
+ */
141
+ declare class AlephaBatch implements Module {
142
+ readonly name = "alepha.batch";
143
+ readonly $services: (alepha: Alepha) => Alepha;
144
+ }
145
+ //#endregion
146
+ export { $batch, AlephaBatch, BatchDescriptor, BatchDescriptorOptions, BatchDescriptorProvider };
147
+ //# 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,13 @@ 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
+ * Plugin for Alepha Cache that provides Redis caching capabilities.
29
+ *
30
+ * @see {@link RedisCacheProvider}
31
+ * @module alepha.cache.redis
32
+ */
38
33
  declare class AlephaCacheRedis implements Module {
39
34
  readonly name = "alepha.cache.redis";
40
35
  readonly $services: (alepha: Alepha) => Alepha;