alepha 0.7.6 → 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/LICENSE +21 -21
- package/README.md +44 -44
- package/batch.cjs +8 -0
- package/batch.d.ts +114 -0
- package/batch.js +1 -0
- package/cache/redis.d.ts +15 -18
- package/cache.d.ts +115 -119
- package/command.cjs +8 -0
- package/command.d.ts +154 -0
- package/command.js +1 -0
- package/core.d.ts +800 -795
- package/datetime.d.ts +76 -76
- package/lock/redis.d.ts +12 -12
- package/lock.d.ts +70 -75
- package/package.json +102 -29
- package/postgres.d.ts +385 -278
- package/queue/redis.d.ts +15 -13
- package/queue.d.ts +16 -13
- package/react/auth.d.ts +16 -16
- package/react/head.cjs +8 -0
- package/react/head.d.ts +92 -0
- package/react/head.js +1 -0
- package/react.d.ts +90 -116
- package/redis.d.ts +20 -27
- package/retry.d.ts +74 -54
- package/scheduler.d.ts +14 -13
- package/security.d.ts +38 -41
- package/server/cache.d.ts +9 -7
- package/server/compress.cjs +8 -0
- package/server/compress.d.ts +26 -0
- package/server/compress.js +1 -0
- package/server/cookies.d.ts +71 -14
- package/server/cors.cjs +8 -0
- package/server/cors.d.ts +29 -0
- package/server/cors.js +1 -0
- package/server/health.cjs +8 -0
- package/server/health.d.ts +42 -0
- package/server/health.js +1 -0
- package/server/helmet.cjs +8 -0
- package/server/helmet.d.ts +72 -0
- package/server/helmet.js +1 -0
- package/server/links.cjs +8 -0
- package/server/links.d.ts +179 -0
- package/server/links.js +1 -0
- package/server/metrics.cjs +8 -0
- package/server/metrics.d.ts +37 -0
- package/server/metrics.js +1 -0
- package/server/multipart.cjs +8 -0
- package/server/multipart.d.ts +48 -0
- package/server/multipart.js +1 -0
- package/server/proxy.cjs +8 -0
- package/server/proxy.d.ts +41 -0
- package/server/proxy.js +1 -0
- package/server/static.d.ts +63 -51
- package/server/swagger.d.ts +50 -50
- package/server.d.ts +220 -437
- package/topic/redis.d.ts +24 -23
- package/topic.d.ts +9 -19
- package/vite.d.ts +8 -1
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,44 @@
|
|
|
1
|
-
<div align="center">
|
|
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>
|
|
22
|
-
|
|
23
|
-
## Installation
|
|
24
|
-
|
|
25
|
-
```bash
|
|
26
|
-
npm install alepha
|
|
27
|
-
```
|
|
28
|
-
|
|
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";
|
|
36
|
-
|
|
37
|
-
class App {
|
|
38
|
-
hello = $action({
|
|
39
|
-
handler: () => "Hello world!",
|
|
40
|
-
})
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
run(App);
|
|
44
|
-
```
|
|
1
|
+
<div align="center">
|
|
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>
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install alepha
|
|
27
|
+
```
|
|
28
|
+
|
|
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";
|
|
36
|
+
|
|
37
|
+
class App {
|
|
38
|
+
hello = $action({
|
|
39
|
+
handler: () => "Hello world!",
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
run(App);
|
|
44
|
+
```
|
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 "
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
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:
|
|
9
|
-
REDIS_CACHE_PREFIX:
|
|
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:
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
|
2
|
-
import
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
* Function which returns cached data.
|
|
65
|
+
* @param args Arguments for handler.
|
|
66
|
+
*/
|
|
68
67
|
handler?: (...args: TParameter) => TReturn;
|
|
69
68
|
/**
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
|
|
76
|
-
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
|
|
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
|
-
|
|
96
|
-
|
|
94
|
+
* Cache handler.
|
|
95
|
+
*/
|
|
97
96
|
(...args: TParameter): Promise<TReturn>;
|
|
98
97
|
/**
|
|
99
|
-
|
|
100
|
-
|
|
98
|
+
* Cache key generator.
|
|
99
|
+
*/
|
|
101
100
|
key: (...args: TParameter) => string;
|
|
102
101
|
/**
|
|
103
|
-
|
|
104
|
-
|
|
102
|
+
* Invalidate cache by keys.
|
|
103
|
+
*/
|
|
105
104
|
invalidate: (...keys: string[]) => Promise<void>;
|
|
106
105
|
/**
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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:
|
|
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:
|
|
142
|
-
CACHE_DEFAULT_TTL:
|
|
143
|
-
CACHE_PREFIX:
|
|
144
|
-
CACHE_ENABLED:
|
|
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
|
|
161
|
-
|
|
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
|
-
|
|
166
|
-
|
|
167
|
+
* Clear all cache entries.
|
|
168
|
+
*/
|
|
167
169
|
clear(): Promise<void>;
|
|
168
170
|
/**
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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
|
-
|
|
176
|
-
|
|
177
|
+
* Get the cache key for the given state and arguments.
|
|
178
|
+
*/
|
|
177
179
|
key(cache: Cache, ...args: any[]): string;
|
|
178
180
|
/**
|
|
179
|
-
|
|
180
|
-
|
|
181
|
+
* Invalidate the cache for the given state and arguments.
|
|
182
|
+
*/
|
|
181
183
|
invalidate(cache: Cache, ...keys: string[]): Promise<void>;
|
|
182
184
|
/**
|
|
183
|
-
|
|
184
|
-
|
|
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
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
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
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
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
|
+
});
|