alepha 0.7.3 → 0.7.5
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 +32 -9
- package/cache/redis.cjs +12 -0
- package/cache/redis.d.ts +105 -0
- package/cache/redis.js +1 -0
- package/cache.d.ts +151 -217
- package/core.d.ts +128 -129
- package/datetime.d.ts +10 -4
- package/lock/redis.cjs +50 -0
- package/lock/redis.d.ts +26 -0
- package/lock/redis.js +47 -0
- package/lock.d.ts +58 -108
- package/package.json +36 -39
- package/postgres.d.ts +23 -36
- package/queue.d.ts +109 -162
- package/react/auth.d.ts +16 -5
- package/react.d.ts +82 -118
- package/redis.d.ts +11 -5
- package/retry.d.ts +30 -30
- package/scheduler.d.ts +58 -26
- package/security.d.ts +4 -4
- package/server/cache.d.ts +38 -7
- package/server/swagger.d.ts +17 -2
- package/server.d.ts +5 -10
- package/src/cache/redis.ts +1 -0
- package/src/lock/redis.ts +1 -0
- package/src/queue/redis.ts +1 -0
- package/src/topic/redis.ts +1 -0
- package/topic.d.ts +18 -84
- package/vite.d.ts +2 -2
- package/assets/logo.png +0 -0
package/README.md
CHANGED
|
@@ -1,21 +1,44 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
|
|
3
|
-
<
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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>
|
|
7
13
|
<p style="max-width: 512px">
|
|
8
14
|
🚧
|
|
9
15
|
</p>
|
|
10
|
-
|
|
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>
|
|
11
21
|
</div>
|
|
12
22
|
|
|
13
|
-
[](https://www.npmjs.com/package/alepha)
|
|
14
|
-
[](https://www.npmjs.com/package/alepha)
|
|
15
|
-
[](https://www.npmjs.com/package/alepha)
|
|
16
|
-
|
|
17
23
|
## Installation
|
|
18
24
|
|
|
19
25
|
```bash
|
|
20
26
|
npm install alepha
|
|
21
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/cache/redis.cjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var cacheRedis = require('@alepha/cache-redis');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
Object.keys(cacheRedis).forEach(function (k) {
|
|
8
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () { return cacheRedis[k]; }
|
|
11
|
+
});
|
|
12
|
+
});
|
package/cache/redis.d.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import * as _alepha_core from '@alepha/core';
|
|
2
|
+
import { Static, Alepha, Module } from '@alepha/core';
|
|
3
|
+
import { CacheProvider } from '@alepha/cache';
|
|
4
|
+
import { RedisProvider } from '@alepha/redis';
|
|
5
|
+
|
|
6
|
+
/** Symbol key applied to readonly types */
|
|
7
|
+
declare const ReadonlyKind: unique symbol;
|
|
8
|
+
/** Symbol key applied to optional types */
|
|
9
|
+
declare const OptionalKind: unique symbol;
|
|
10
|
+
/** Symbol key applied to types */
|
|
11
|
+
declare const Hint: unique symbol;
|
|
12
|
+
/** Symbol key applied to types */
|
|
13
|
+
declare const Kind: unique symbol;
|
|
14
|
+
|
|
15
|
+
type StringFormatOption = 'date-time' | 'time' | 'date' | 'email' | 'idn-email' | 'hostname' | 'idn-hostname' | 'ipv4' | 'ipv6' | 'uri' | 'uri-reference' | 'iri' | 'uuid' | 'iri-reference' | 'uri-template' | 'json-pointer' | 'relative-json-pointer' | 'regex' | ({} & string);
|
|
16
|
+
type StringContentEncodingOption = '7bit' | '8bit' | 'binary' | 'quoted-printable' | 'base64' | ({} & string);
|
|
17
|
+
interface StringOptions extends SchemaOptions {
|
|
18
|
+
/** The maximum string length */
|
|
19
|
+
maxLength?: number;
|
|
20
|
+
/** The minimum string length */
|
|
21
|
+
minLength?: number;
|
|
22
|
+
/** A regular expression pattern this string should match */
|
|
23
|
+
pattern?: string;
|
|
24
|
+
/** A format this string should match */
|
|
25
|
+
format?: StringFormatOption;
|
|
26
|
+
/** The content encoding for this string */
|
|
27
|
+
contentEncoding?: StringContentEncodingOption;
|
|
28
|
+
/** The content media type for this string */
|
|
29
|
+
contentMediaType?: string;
|
|
30
|
+
}
|
|
31
|
+
interface TString extends TSchema, StringOptions {
|
|
32
|
+
[Kind]: 'String';
|
|
33
|
+
static: string;
|
|
34
|
+
type: 'string';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
type TOptional<T extends TSchema> = T & {
|
|
38
|
+
[OptionalKind]: 'Optional';
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
interface SchemaOptions {
|
|
42
|
+
$schema?: string;
|
|
43
|
+
/** Id for this schema */
|
|
44
|
+
$id?: string;
|
|
45
|
+
/** Title of this schema */
|
|
46
|
+
title?: string;
|
|
47
|
+
/** Description of this schema */
|
|
48
|
+
description?: string;
|
|
49
|
+
/** Default value for this schema */
|
|
50
|
+
default?: any;
|
|
51
|
+
/** Example values matching this schema */
|
|
52
|
+
examples?: any;
|
|
53
|
+
/** Optional annotation for readOnly */
|
|
54
|
+
readOnly?: boolean;
|
|
55
|
+
/** Optional annotation for writeOnly */
|
|
56
|
+
writeOnly?: boolean;
|
|
57
|
+
[prop: string]: any;
|
|
58
|
+
}
|
|
59
|
+
interface TKind {
|
|
60
|
+
[Kind]: string;
|
|
61
|
+
}
|
|
62
|
+
interface TSchema extends TKind, SchemaOptions {
|
|
63
|
+
[ReadonlyKind]?: string;
|
|
64
|
+
[OptionalKind]?: string;
|
|
65
|
+
[Hint]?: string;
|
|
66
|
+
params: unknown[];
|
|
67
|
+
static: unknown;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
declare const envSchema: _alepha_core.TObject<{
|
|
71
|
+
REDIS_CACHE_PREFIX: TOptional<TString>;
|
|
72
|
+
}>;
|
|
73
|
+
declare module "alepha" {
|
|
74
|
+
interface Env extends Partial<Static<typeof envSchema>> {
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
declare class RedisCacheProvider implements CacheProvider {
|
|
78
|
+
protected readonly log: _alepha_core.Logger;
|
|
79
|
+
protected readonly redisProvider: RedisProvider;
|
|
80
|
+
protected readonly env: {
|
|
81
|
+
REDIS_CACHE_PREFIX?: string | undefined;
|
|
82
|
+
};
|
|
83
|
+
protected readonly alepha: Alepha;
|
|
84
|
+
get(name: string, key: string): Promise<Uint8Array | undefined>;
|
|
85
|
+
set(name: string, key: string, value: Uint8Array | string, ttl?: number): Promise<Uint8Array>;
|
|
86
|
+
del(name: string, ...keys: string[]): Promise<void>;
|
|
87
|
+
has(name: string, key: string): Promise<boolean>;
|
|
88
|
+
keys(name: string): Promise<string[]>;
|
|
89
|
+
protected prefix(...path: string[]): string;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Alepha Cache Redis Module
|
|
94
|
+
*
|
|
95
|
+
* Plugin for Alepha Cache that provides Redis caching capabilities.
|
|
96
|
+
*
|
|
97
|
+
* @see {@link RedisCacheProvider}
|
|
98
|
+
* @module alepha.cache.redis
|
|
99
|
+
*/
|
|
100
|
+
declare class AlephaCacheRedis implements Module {
|
|
101
|
+
readonly name = "alepha.cache.redis";
|
|
102
|
+
readonly $services: (alepha: Alepha) => Alepha;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export { AlephaCacheRedis, RedisCacheProvider };
|
package/cache/redis.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@alepha/cache-redis';
|
package/cache.d.ts
CHANGED
|
@@ -1,7 +1,119 @@
|
|
|
1
1
|
import * as _alepha_core from '@alepha/core';
|
|
2
|
-
import { KIND, OPTIONS, Static, Alepha } from '@alepha/core';
|
|
2
|
+
import { KIND, OPTIONS, Static, Alepha, Module } from '@alepha/core';
|
|
3
3
|
import { DurationLike, DateTimeProvider, Timeout } from '@alepha/datetime';
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Cache provider interface.
|
|
7
|
+
*
|
|
8
|
+
* All methods are asynchronous and return promises.
|
|
9
|
+
* Values are stored as Uint8Array.
|
|
10
|
+
*/
|
|
11
|
+
declare abstract class CacheProvider {
|
|
12
|
+
/**
|
|
13
|
+
* Get the value of a key.
|
|
14
|
+
*
|
|
15
|
+
* @param name Cache name, used to group keys. Should be Redis-like "some:group:name" format.
|
|
16
|
+
* @param key The key of the value to get.
|
|
17
|
+
*
|
|
18
|
+
* @return The value of the key, or undefined if the key does not exist.
|
|
19
|
+
*/
|
|
20
|
+
abstract get(name: string, key: string): Promise<Uint8Array | undefined>;
|
|
21
|
+
/**
|
|
22
|
+
* Set the string value of a key.
|
|
23
|
+
*
|
|
24
|
+
* @param name Cache name, used to group keys. Should be Redis-like "some:group:name" format.
|
|
25
|
+
* @param key The key of the value to set.
|
|
26
|
+
* @param value The value to set.
|
|
27
|
+
* @param ttl The time-to-live of the key, in milliseconds.
|
|
28
|
+
*
|
|
29
|
+
* @return The value of the key.
|
|
30
|
+
*/
|
|
31
|
+
abstract set(name: string, key: string, value: Uint8Array, ttl?: number): Promise<Uint8Array>;
|
|
32
|
+
/**
|
|
33
|
+
* Remove the specified keys.
|
|
34
|
+
*
|
|
35
|
+
* @param name Cache name, used to group keys. Should be Redis-like "some:group:name" format.
|
|
36
|
+
* @param keys The keys to delete.
|
|
37
|
+
*/
|
|
38
|
+
abstract del(name: string, ...keys: string[]): Promise<void>;
|
|
39
|
+
abstract has(name: string, key: string): Promise<boolean>;
|
|
40
|
+
abstract keys(name: string): Promise<string[]>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
declare const KEY = "CACHE";
|
|
44
|
+
/**
|
|
45
|
+
* Cache Descriptor
|
|
46
|
+
*/
|
|
47
|
+
declare const $cache: {
|
|
48
|
+
<TReturn = string, TParameter extends any[] = any[]>(options?: CacheDescriptorOptions<TReturn, TParameter>): CacheDescriptor<TReturn, TParameter>;
|
|
49
|
+
[KIND]: string;
|
|
50
|
+
};
|
|
51
|
+
interface CacheDescriptorOptions<TReturn, TParameter extends any[] = any[]> {
|
|
52
|
+
/**
|
|
53
|
+
* The cache name. This is useful for invalidating multiple caches at once.
|
|
54
|
+
*
|
|
55
|
+
* Store key as `cache:$name:$key`.
|
|
56
|
+
*
|
|
57
|
+
* @default ClassName:methodName
|
|
58
|
+
*/
|
|
59
|
+
name?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Function which returns cached data.
|
|
62
|
+
* @param args Arguments for handler.
|
|
63
|
+
*/
|
|
64
|
+
handler?: (...args: TParameter) => TReturn;
|
|
65
|
+
/**
|
|
66
|
+
* The key generator for the cache.
|
|
67
|
+
* If not provided, the arguments will be json.stringify().
|
|
68
|
+
*/
|
|
69
|
+
key?: (...args: TParameter) => string;
|
|
70
|
+
/**
|
|
71
|
+
* The store provider for the cache.
|
|
72
|
+
* If not provided, the default store provider will be used.
|
|
73
|
+
*/
|
|
74
|
+
provider?: CacheProvider | (() => CacheProvider) | "memory";
|
|
75
|
+
/**
|
|
76
|
+
* The time-to-live for the cache in seconds.
|
|
77
|
+
* Set 0 to skip expiration.
|
|
78
|
+
*
|
|
79
|
+
* @default 300 (5 minutes).
|
|
80
|
+
*/
|
|
81
|
+
ttl?: DurationLike;
|
|
82
|
+
/**
|
|
83
|
+
* If the cache is disabled.
|
|
84
|
+
*/
|
|
85
|
+
disabled?: boolean;
|
|
86
|
+
}
|
|
87
|
+
interface CacheDescriptor<TReturn = any, TParameter extends any[] = any[]> {
|
|
88
|
+
[KIND]: typeof KEY;
|
|
89
|
+
[OPTIONS]: CacheDescriptorOptions<TReturn, TParameter>;
|
|
90
|
+
/**
|
|
91
|
+
* Cache handler.
|
|
92
|
+
*/
|
|
93
|
+
(...args: TParameter): Promise<TReturn>;
|
|
94
|
+
/**
|
|
95
|
+
* Cache key generator.
|
|
96
|
+
*/
|
|
97
|
+
key: (...args: TParameter) => string;
|
|
98
|
+
/**
|
|
99
|
+
* Invalidate cache by keys.
|
|
100
|
+
*/
|
|
101
|
+
invalidate: (...keys: string[]) => Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Set cache with key, value and ttl.
|
|
104
|
+
*
|
|
105
|
+
* @param key
|
|
106
|
+
* @param value
|
|
107
|
+
* @param ttl
|
|
108
|
+
*/
|
|
109
|
+
set: (key: string, value: TReturn, ttl?: DurationLike) => Promise<void>;
|
|
110
|
+
/**
|
|
111
|
+
* Get cache by key.
|
|
112
|
+
*
|
|
113
|
+
* @param key
|
|
114
|
+
*/
|
|
115
|
+
get: (key: string) => Promise<TReturn | undefined>;
|
|
116
|
+
}
|
|
5
117
|
|
|
6
118
|
/** Symbol key applied to readonly types */
|
|
7
119
|
declare const ReadonlyKind: unique symbol;
|
|
@@ -12,11 +124,6 @@ declare const Hint: unique symbol;
|
|
|
12
124
|
/** Symbol key applied to types */
|
|
13
125
|
declare const Kind: unique symbol;
|
|
14
126
|
|
|
15
|
-
interface TUnsafe<T> extends TSchema {
|
|
16
|
-
[Kind]: string;
|
|
17
|
-
static: T;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
127
|
type StringFormatOption = 'date-time' | 'time' | 'date' | 'email' | 'idn-email' | 'hostname' | 'idn-hostname' | 'ipv4' | 'ipv6' | 'uri' | 'uri-reference' | 'iri' | 'uuid' | 'iri-reference' | 'uri-template' | 'json-pointer' | 'relative-json-pointer' | 'regex' | ({} & string);
|
|
21
128
|
type StringContentEncodingOption = '7bit' | '8bit' | 'binary' | 'quoted-printable' | 'base64' | ({} & string);
|
|
22
129
|
interface StringOptions extends SchemaOptions {
|
|
@@ -91,169 +198,35 @@ interface TSchema extends TKind, SchemaOptions {
|
|
|
91
198
|
static: unknown;
|
|
92
199
|
}
|
|
93
200
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
* @param key The key of the value to get.
|
|
100
|
-
*/
|
|
101
|
-
get(group: string, key: string): Promise<string | undefined>;
|
|
102
|
-
/**
|
|
103
|
-
* Set the string value of a key.
|
|
104
|
-
*
|
|
105
|
-
* @param group The group of the value to get.
|
|
106
|
-
* @param key The key of the value to set.
|
|
107
|
-
* @param value The value to set.
|
|
108
|
-
* @param ttl The time-to-live of the key, in milliseconds.
|
|
109
|
-
*/
|
|
110
|
-
set(group: string, key: string, value: string, ttl?: number): Promise<string>;
|
|
111
|
-
/**
|
|
112
|
-
* Remove the specified keys.
|
|
113
|
-
*
|
|
114
|
-
* @param group The group of the value to get.
|
|
115
|
-
* @param keys The keys to delete.
|
|
116
|
-
*/
|
|
117
|
-
del(group: string, ...keys: string[]): Promise<void>;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
declare class DefaultCacheProvider implements CacheProvider {
|
|
121
|
-
constructor();
|
|
122
|
-
get(): Promise<string | undefined>;
|
|
123
|
-
set(): Promise<string>;
|
|
124
|
-
del(): Promise<void>;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
declare const KEY = "CACHE";
|
|
128
|
-
interface CacheDescriptorOptions<TReturn, TParameter extends any[] = any[]> {
|
|
129
|
-
/**
|
|
130
|
-
* Function which returns cached data.
|
|
131
|
-
* @param args Arguments for handler.
|
|
132
|
-
*/
|
|
133
|
-
handler?: (...args: TParameter) => TReturn;
|
|
134
|
-
/**
|
|
135
|
-
* The key generator for the cache.
|
|
136
|
-
* If not provided, the arguments will be json.stringify().
|
|
137
|
-
*/
|
|
138
|
-
key?: (...args: TParameter) => string;
|
|
139
|
-
/**
|
|
140
|
-
* The store provider for the cache.
|
|
141
|
-
* If not provided, the default store provider will be used.
|
|
142
|
-
*/
|
|
143
|
-
provider?: (() => DefaultCacheProvider) | "memory";
|
|
144
|
-
/**
|
|
145
|
-
* The cache group. This is useful for invalidating multiple caches at once.
|
|
146
|
-
* Key is used as the group if not provided.
|
|
147
|
-
*
|
|
148
|
-
* Store key as `cache:$group:$key`.
|
|
149
|
-
*
|
|
150
|
-
* @default ClassName:methodName
|
|
151
|
-
*/
|
|
152
|
-
group?: string;
|
|
153
|
-
/**
|
|
154
|
-
* The time-to-live for the cache in seconds.
|
|
155
|
-
* Set 0 to skip expiration.
|
|
156
|
-
*
|
|
157
|
-
* @default 300 (5 minutes).
|
|
158
|
-
*/
|
|
159
|
-
ttl?: DurationLike;
|
|
160
|
-
/**
|
|
161
|
-
* If the cache is disabled.
|
|
162
|
-
*/
|
|
163
|
-
disabled?: boolean;
|
|
164
|
-
}
|
|
165
|
-
interface CacheDescriptor<TReturn = any, TParameter extends any[] = any[]> {
|
|
166
|
-
[KIND]: typeof KEY;
|
|
167
|
-
[OPTIONS]: CacheDescriptorOptions<TReturn, TParameter>;
|
|
168
|
-
/**
|
|
169
|
-
* Cache handler.
|
|
170
|
-
*/
|
|
171
|
-
(...args: TParameter): Promise<TReturn>;
|
|
172
|
-
/**
|
|
173
|
-
* Cache key generator.
|
|
174
|
-
*/
|
|
175
|
-
key: (...args: TParameter) => string;
|
|
176
|
-
/**
|
|
177
|
-
* Invalidate cache by keys.
|
|
178
|
-
*/
|
|
179
|
-
invalidate: (...keys: string[]) => Promise<void>;
|
|
180
|
-
/**
|
|
181
|
-
* Set cache with key, value and ttl.
|
|
182
|
-
*
|
|
183
|
-
* @param key
|
|
184
|
-
* @param value
|
|
185
|
-
* @param ttl
|
|
186
|
-
*/
|
|
187
|
-
set: (key: string, value: TReturn, ttl?: DurationLike) => Promise<void>;
|
|
188
|
-
/**
|
|
189
|
-
* Get cache by key.
|
|
190
|
-
*
|
|
191
|
-
* @param key
|
|
192
|
-
*/
|
|
193
|
-
get: (key: string) => Promise<TReturn | undefined>;
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Cache Descriptor
|
|
197
|
-
*
|
|
198
|
-
* @param options
|
|
199
|
-
*/
|
|
200
|
-
declare const $cache: {
|
|
201
|
-
<TReturn = string, TParameter extends any[] = any[]>(options?: CacheDescriptorOptions<TReturn, TParameter>): CacheDescriptor<TReturn, TParameter>;
|
|
202
|
-
[KIND]: string;
|
|
201
|
+
type CacheName = string;
|
|
202
|
+
type CacheKey = string;
|
|
203
|
+
type CacheValue = {
|
|
204
|
+
data?: Uint8Array;
|
|
205
|
+
timeout?: Timeout;
|
|
203
206
|
};
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* A simple in-memory store provider.
|
|
207
|
-
*/
|
|
208
207
|
declare class MemoryCacheProvider implements CacheProvider {
|
|
209
208
|
protected readonly dateTimeProvider: DateTimeProvider;
|
|
210
209
|
protected readonly log: _alepha_core.Logger;
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
*/
|
|
218
|
-
protected storeTimeout: Record<string, Record<string, Timeout>>;
|
|
219
|
-
/**
|
|
220
|
-
* Get the value of a key.
|
|
221
|
-
*
|
|
222
|
-
* @param group The group of the value to get.
|
|
223
|
-
* @param key The key of the value to get.
|
|
224
|
-
*/
|
|
225
|
-
get(group: string, key: string): Promise<string | undefined>;
|
|
226
|
-
/**
|
|
227
|
-
* Set the string value of a key.
|
|
228
|
-
*
|
|
229
|
-
* @param group The group of the value to get.
|
|
230
|
-
* @param key The key of the value to set.
|
|
231
|
-
* @param value The value to set.
|
|
232
|
-
* @param ttl The time-to-live of the key, in milliseconds.
|
|
233
|
-
*/
|
|
234
|
-
set(group: string, key: string, value: string, ttl?: number): Promise<string>;
|
|
235
|
-
/**
|
|
236
|
-
* Remove the specified keys.
|
|
237
|
-
*
|
|
238
|
-
* @param group The group of the value to get.
|
|
239
|
-
* @param keys The keys to delete.
|
|
240
|
-
*/
|
|
241
|
-
del(group: string, ...keys: string[]): Promise<void>;
|
|
242
|
-
private ttl;
|
|
210
|
+
protected store: Record<CacheName, Record<CacheKey, CacheValue>>;
|
|
211
|
+
get(name: string, key: string): Promise<Uint8Array | undefined>;
|
|
212
|
+
set(name: string, key: string, value: Uint8Array, ttl?: number): Promise<Uint8Array>;
|
|
213
|
+
del(name: string, ...keys: string[]): Promise<void>;
|
|
214
|
+
has(name: string, key: string): Promise<boolean>;
|
|
215
|
+
keys(name: string): Promise<string[]>;
|
|
243
216
|
}
|
|
244
217
|
|
|
245
|
-
declare const envSchema
|
|
218
|
+
declare const envSchema: _alepha_core.TObject<{
|
|
246
219
|
CACHE_DEFAULT_TTL: TNumber;
|
|
247
220
|
CACHE_PREFIX: TOptional<TString>;
|
|
248
221
|
CACHE_ENABLED: TBoolean;
|
|
249
222
|
}>;
|
|
250
223
|
declare module "alepha" {
|
|
251
|
-
interface Env extends Partial<Static<typeof envSchema
|
|
224
|
+
interface Env extends Partial<Static<typeof envSchema>> {
|
|
252
225
|
}
|
|
253
226
|
}
|
|
254
227
|
declare class CacheDescriptorProvider {
|
|
255
228
|
protected readonly alepha: Alepha;
|
|
256
|
-
protected readonly cacheProvider:
|
|
229
|
+
protected readonly cacheProvider: CacheProvider;
|
|
257
230
|
protected readonly memoryCacheProvider: MemoryCacheProvider;
|
|
258
231
|
protected readonly dateTimeProvider: DateTimeProvider;
|
|
259
232
|
protected readonly env: {
|
|
@@ -300,72 +273,33 @@ declare class CacheDescriptorProvider {
|
|
|
300
273
|
* @param ttl Override cache.ttl option.
|
|
301
274
|
*/
|
|
302
275
|
set<TReturn>(cache: Cache<TReturn>, key: string, value: TReturn, ttl?: DurationLike): Promise<void>;
|
|
303
|
-
protected
|
|
304
|
-
protected
|
|
276
|
+
protected encoder: TextEncoder;
|
|
277
|
+
protected decoder: TextDecoder;
|
|
278
|
+
protected codes: {
|
|
279
|
+
BINARY: number;
|
|
280
|
+
JSON: number;
|
|
281
|
+
STRING: number;
|
|
282
|
+
};
|
|
283
|
+
protected serialize<TReturn>(value: TReturn): Uint8Array;
|
|
284
|
+
protected deserialize<TReturn>(uint8Array: Uint8Array): Promise<TReturn>;
|
|
305
285
|
}
|
|
306
286
|
interface Cache<TReturn = any, TParameter extends any[] = any[]> {
|
|
307
|
-
|
|
287
|
+
name: string;
|
|
308
288
|
options: CacheDescriptorOptions<TReturn, TParameter>;
|
|
309
289
|
}
|
|
310
290
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
};
|
|
324
|
-
get publisher(): RedisClient;
|
|
325
|
-
/**
|
|
326
|
-
* Get the value of a key.
|
|
327
|
-
*
|
|
328
|
-
* @param group - The group of the value to get.
|
|
329
|
-
* @param key - The key of the value to get.
|
|
330
|
-
*/
|
|
331
|
-
get(group: string, key: string): Promise<string | undefined>;
|
|
332
|
-
/**
|
|
333
|
-
* Set the string value of a key.
|
|
334
|
-
*
|
|
335
|
-
* @param group - The group of the value to get.
|
|
336
|
-
* @param key - The key of the value to set.
|
|
337
|
-
* @param value - The value to set.
|
|
338
|
-
* @param ttl - The time-to-live of the key, in milliseconds.
|
|
339
|
-
*/
|
|
340
|
-
set(group: string, key: string, value: string, ttl?: number): Promise<string>;
|
|
341
|
-
/**
|
|
342
|
-
* Remove the specified keys.
|
|
343
|
-
*
|
|
344
|
-
* @param group - The group of the value to get.
|
|
345
|
-
* @param keys - The keys to delete.
|
|
346
|
-
*/
|
|
347
|
-
del(group: string, ...keys: string[]): Promise<void>;
|
|
348
|
-
/**
|
|
349
|
-
* Prefix the cache key.
|
|
350
|
-
*
|
|
351
|
-
* @param path - The path to prefix.
|
|
352
|
-
*/
|
|
353
|
-
protected prefix(...path: string[]): string;
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
declare const envSchema: _alepha_core.TObject<{
|
|
357
|
-
CACHE_PROVIDER: TUnsafe<"memory" | "redis">;
|
|
358
|
-
}>;
|
|
359
|
-
declare module "@alepha/core" {
|
|
360
|
-
interface Env extends Partial<Static<typeof envSchema>> {
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
declare class CacheModule {
|
|
364
|
-
protected readonly alepha: Alepha;
|
|
365
|
-
protected readonly env: {
|
|
366
|
-
CACHE_PROVIDER: "memory" | "redis";
|
|
367
|
-
};
|
|
368
|
-
constructor();
|
|
291
|
+
/**
|
|
292
|
+
* Alepha Cache Module
|
|
293
|
+
*
|
|
294
|
+
* This module provides a caching mechanism for Alepha applications.
|
|
295
|
+
*
|
|
296
|
+
* @see {@link $cache}
|
|
297
|
+
* @see {@link CacheProvider}
|
|
298
|
+
* @module alepha.cache
|
|
299
|
+
*/
|
|
300
|
+
declare class AlephaCache implements Module {
|
|
301
|
+
readonly name = "alepha.cache";
|
|
302
|
+
readonly $services: (alepha: Alepha) => Alepha;
|
|
369
303
|
}
|
|
370
304
|
|
|
371
|
-
export { $cache, type Cache, type CacheDescriptor, type CacheDescriptorOptions, CacheDescriptorProvider,
|
|
305
|
+
export { $cache, AlephaCache, type Cache, type CacheDescriptor, type CacheDescriptorOptions, CacheDescriptorProvider, CacheProvider, MemoryCacheProvider };
|