alepha 0.8.1 → 0.9.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.
- package/README.md +47 -17
- package/batch.d.ts +83 -117
- package/bucket.cjs +8 -0
- package/bucket.d.ts +194 -0
- package/bucket.js +1 -0
- package/cache/redis.d.ts +14 -14
- package/cache.d.ts +101 -238
- package/command.d.ts +79 -70
- package/core.d.ts +1012 -855
- package/datetime.d.ts +90 -116
- package/file.d.ts +23 -13
- package/lock/redis.d.ts +11 -11
- package/lock.d.ts +121 -111
- package/package.json +54 -40
- package/postgres.d.ts +218 -393
- package/queue/redis.d.ts +13 -13
- package/queue.d.ts +84 -198
- package/react/auth.d.ts +47 -53
- package/react/head.d.ts +4 -7
- package/react.d.ts +48 -183
- package/redis.d.ts +31 -16
- package/retry.d.ts +70 -59
- package/router.d.ts +9 -9
- package/scheduler.d.ts +54 -93
- package/security.d.ts +95 -276
- package/server/cache.d.ts +22 -28
- package/server/compress.d.ts +16 -7
- package/server/cookies.d.ts +65 -233
- package/server/cors.d.ts +15 -13
- package/server/health.d.ts +23 -23
- package/server/helmet.d.ts +17 -18
- package/server/links.d.ts +108 -88
- package/server/metrics.d.ts +25 -21
- package/server/multipart.d.ts +12 -14
- package/server/proxy.d.ts +22 -17
- package/server/security.cjs +8 -0
- package/server/security.d.ts +92 -0
- package/server/security.js +1 -0
- package/server/static.d.ts +63 -67
- package/server/swagger.d.ts +73 -62
- package/server.d.ts +253 -448
- package/topic/redis.d.ts +25 -24
- package/topic.d.ts +68 -115
package/datetime.d.ts
CHANGED
|
@@ -1,167 +1,141 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as _alepha_core0$1 from "alepha";
|
|
2
|
+
import * as _alepha_core0 from "alepha";
|
|
3
|
+
import { Alepha, Descriptor, KIND } from "alepha";
|
|
2
4
|
import dayjs, { Dayjs, ManipulateType } from "dayjs";
|
|
3
5
|
import dayjsDuration from "dayjs/plugin/duration.js";
|
|
4
6
|
|
|
5
|
-
//#region src/helpers/Interval.d.ts
|
|
6
|
-
declare class Interval {
|
|
7
|
-
private timer;
|
|
8
|
-
private readonly run;
|
|
9
|
-
private duration;
|
|
10
|
-
private options;
|
|
11
|
-
constructor(duration: number, options: IntervalDescriptorOptions);
|
|
12
|
-
/**
|
|
13
|
-
* Start the interval.
|
|
14
|
-
*/
|
|
15
|
-
start(): Promise<void>;
|
|
16
|
-
/**
|
|
17
|
-
* Add time to the interval.
|
|
18
|
-
*
|
|
19
|
-
* @param amountMs
|
|
20
|
-
*/
|
|
21
|
-
add(amountMs: number): Promise<void>;
|
|
22
|
-
/**
|
|
23
|
-
* Clear the interval.
|
|
24
|
-
*/
|
|
25
|
-
clear(): void;
|
|
26
|
-
}
|
|
27
|
-
//#endregion
|
|
28
|
-
//#region src/helpers/Timeout.d.ts
|
|
29
|
-
declare class Timeout {
|
|
30
|
-
private timer;
|
|
31
|
-
private duration;
|
|
32
|
-
private readonly now;
|
|
33
|
-
private readonly callback;
|
|
34
|
-
constructor(now: number, duration: number, callback: () => void);
|
|
35
|
-
/**
|
|
36
|
-
* Add time to the timeout.
|
|
37
|
-
*/
|
|
38
|
-
add(amountMs: number): void;
|
|
39
|
-
/**
|
|
40
|
-
* Clear the timeout.
|
|
41
|
-
*/
|
|
42
|
-
clear(): void;
|
|
43
|
-
/**
|
|
44
|
-
* Start the timeout.
|
|
45
|
-
*
|
|
46
|
-
* @private
|
|
47
|
-
*/
|
|
48
|
-
private start;
|
|
49
|
-
}
|
|
50
|
-
//#endregion
|
|
51
7
|
//#region src/providers/DateTimeProvider.d.ts
|
|
8
|
+
type DateTimeApi = typeof dayjs;
|
|
52
9
|
type DateTime = dayjs.Dayjs;
|
|
53
10
|
type Duration = dayjsDuration.Duration;
|
|
54
11
|
type DurationLike = number | dayjsDuration.Duration | [number, ManipulateType];
|
|
55
12
|
declare class DateTimeProvider {
|
|
56
|
-
protected
|
|
13
|
+
protected alepha: Alepha;
|
|
14
|
+
protected log: _alepha_core0$1.Logger;
|
|
57
15
|
protected ref: DateTime | null;
|
|
58
16
|
protected readonly timeouts: Timeout[];
|
|
59
17
|
protected readonly intervals: Interval[];
|
|
60
18
|
constructor();
|
|
61
|
-
protected readonly start: HookDescriptor<"start">;
|
|
62
|
-
protected readonly stop: HookDescriptor<"stop">;
|
|
63
19
|
/**
|
|
64
|
-
|
|
65
|
-
|
|
20
|
+
* Load Day.js plugins.
|
|
21
|
+
*
|
|
22
|
+
* You can override this method to add custom plugins.
|
|
23
|
+
*/
|
|
24
|
+
protected plugins(api: DateTimeApi): void;
|
|
25
|
+
protected readonly start: _alepha_core0$1.HookDescriptor<"start">;
|
|
26
|
+
protected readonly stop: _alepha_core0$1.HookDescriptor<"stop">;
|
|
27
|
+
/**
|
|
28
|
+
* Create a new DateTime instance.
|
|
29
|
+
*/
|
|
66
30
|
of(date: string | number | Date | Dayjs | null | undefined): DateTime;
|
|
67
31
|
/**
|
|
68
|
-
|
|
69
|
-
|
|
32
|
+
* Get the current date.
|
|
33
|
+
*/
|
|
70
34
|
now(): DateTime;
|
|
71
35
|
/**
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
36
|
+
* Get the current date as a string.
|
|
37
|
+
*
|
|
38
|
+
* @param date
|
|
39
|
+
*/
|
|
76
40
|
toISOString(date?: Date | string | DateTime): string;
|
|
77
41
|
/**
|
|
78
|
-
|
|
79
|
-
|
|
42
|
+
* Get the current date as a string.
|
|
43
|
+
*/
|
|
80
44
|
nowISOString(): string;
|
|
81
45
|
/**
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
46
|
+
* Get the current date as a string.
|
|
47
|
+
*
|
|
48
|
+
* @protected
|
|
49
|
+
*/
|
|
86
50
|
protected getCurrentDate(): DateTime;
|
|
87
51
|
/**
|
|
88
|
-
|
|
89
|
-
|
|
52
|
+
* Create a new Duration instance.
|
|
53
|
+
*/
|
|
90
54
|
duration: (duration: DurationLike, unit?: ManipulateType) => Duration;
|
|
91
55
|
isDurationLike(value: unknown): value is DurationLike;
|
|
92
56
|
/**
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
57
|
+
* Return a promise that resolves after the next tick.
|
|
58
|
+
* It uses `setTimeout` with 0 ms delay.
|
|
59
|
+
*/
|
|
96
60
|
tick(): Promise<void>;
|
|
97
61
|
/**
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
62
|
+
* Wait for a certain duration.
|
|
63
|
+
*
|
|
64
|
+
* You can clear the timeout by using the `AbortSignal` API.
|
|
65
|
+
* Aborted signal will resolve the promise immediately, it does not reject it.
|
|
66
|
+
*/
|
|
103
67
|
wait(duration: DurationLike, options?: {
|
|
104
68
|
signal?: AbortSignal;
|
|
105
69
|
now?: number;
|
|
106
70
|
}): Promise<void>;
|
|
71
|
+
createInterval(run: () => unknown, distance: DurationLike): Interval;
|
|
107
72
|
/**
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
* Create an interval.
|
|
113
|
-
*
|
|
114
|
-
* @param args
|
|
115
|
-
*/
|
|
116
|
-
interval(args: IntervalDescriptorOptions): Interval;
|
|
73
|
+
* Run a callback after a certain duration.
|
|
74
|
+
*/
|
|
75
|
+
createTimeout(callback: () => void, duration: DurationLike, now?: number): Timeout;
|
|
76
|
+
clearTimeout(timeout: Timeout): void;
|
|
117
77
|
/**
|
|
118
|
-
|
|
119
|
-
|
|
78
|
+
* Run a function with a deadline.
|
|
79
|
+
*/
|
|
120
80
|
deadline<T>(fn: (signal: AbortSignal) => Promise<T>, duration: DurationLike): Promise<T>;
|
|
121
|
-
// Testing
|
|
122
81
|
/**
|
|
123
|
-
|
|
124
|
-
|
|
82
|
+
* Add time to the current date.
|
|
83
|
+
*/
|
|
125
84
|
travel(duration: DurationLike, unit?: ManipulateType): Promise<void>;
|
|
126
85
|
/**
|
|
127
|
-
|
|
128
|
-
|
|
86
|
+
* Stop the time.
|
|
87
|
+
*/
|
|
129
88
|
pause(): DateTime;
|
|
130
89
|
/**
|
|
131
|
-
|
|
132
|
-
|
|
90
|
+
* Reset the reference date.
|
|
91
|
+
*/
|
|
133
92
|
reset(): void;
|
|
134
93
|
}
|
|
94
|
+
interface Interval {
|
|
95
|
+
timer?: any;
|
|
96
|
+
duration: number;
|
|
97
|
+
run: () => unknown;
|
|
98
|
+
}
|
|
99
|
+
interface Timeout {
|
|
100
|
+
now: number;
|
|
101
|
+
timer?: any;
|
|
102
|
+
duration: number;
|
|
103
|
+
callback: () => void;
|
|
104
|
+
clear: () => void;
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=DateTimeProvider.d.ts.map
|
|
135
107
|
//#endregion
|
|
136
108
|
//#region src/descriptors/$interval.d.ts
|
|
137
109
|
/**
|
|
138
|
-
*
|
|
139
|
-
|
|
140
|
-
|
|
110
|
+
* Run a function periodically.
|
|
111
|
+
* It uses the `setInterval` internally.
|
|
112
|
+
* It starts by default when the context starts and stops when the context stops.
|
|
113
|
+
*/
|
|
114
|
+
declare const $interval: {
|
|
115
|
+
(options: IntervalDescriptorOptions): IntervalDescriptor;
|
|
116
|
+
[KIND]: typeof IntervalDescriptor;
|
|
117
|
+
};
|
|
141
118
|
interface IntervalDescriptorOptions {
|
|
142
119
|
/**
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
* Whether to attach the interval to the context.
|
|
150
|
-
*
|
|
151
|
-
* Attached intervals are automatically started when the context starts and stopped when the context stops.
|
|
152
|
-
*
|
|
153
|
-
* @default true
|
|
154
|
-
*/
|
|
155
|
-
attach?: boolean;
|
|
156
|
-
/**
|
|
157
|
-
* The interval handler.
|
|
158
|
-
*/
|
|
159
|
-
handler: () => Async<void>;
|
|
160
|
-
/**
|
|
161
|
-
* The interval duration.
|
|
162
|
-
*/
|
|
120
|
+
* The interval handler.
|
|
121
|
+
*/
|
|
122
|
+
handler: () => unknown;
|
|
123
|
+
/**
|
|
124
|
+
* The interval duration.
|
|
125
|
+
*/
|
|
163
126
|
duration: DurationLike;
|
|
164
127
|
}
|
|
128
|
+
declare class IntervalDescriptor extends Descriptor<IntervalDescriptorOptions> {
|
|
129
|
+
protected readonly dateTimeProvider: DateTimeProvider;
|
|
130
|
+
called: number;
|
|
131
|
+
protected onInit(): void;
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=$interval.d.ts.map
|
|
134
|
+
//#endregion
|
|
135
|
+
//#region src/index.d.ts
|
|
136
|
+
declare const AlephaDateTime: _alepha_core0.ModuleDescriptor;
|
|
137
|
+
//# sourceMappingURL=index.d.ts.map
|
|
138
|
+
|
|
165
139
|
//#endregion
|
|
166
|
-
export { $interval, DateTime, DateTimeProvider, Duration, DurationLike, Interval, IntervalDescriptorOptions, Timeout };
|
|
140
|
+
export { $interval, AlephaDateTime, DateTime, DateTimeApi, DateTimeProvider, Duration, DurationLike, Interval, IntervalDescriptor, IntervalDescriptorOptions, Timeout };
|
|
167
141
|
//# sourceMappingURL=index.d.ts.map
|
package/file.d.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { FileLike, StreamLike } from "alepha";
|
|
2
2
|
|
|
3
3
|
//#region src/helpers/createFile.d.ts
|
|
4
|
-
declare const createFile: (source: string | Buffer | ArrayBuffer | StreamLike, options?: {
|
|
4
|
+
declare const createFile: (source: string | Buffer | ArrayBuffer | StreamLike | File, options?: {
|
|
5
5
|
type?: string;
|
|
6
6
|
name?: string;
|
|
7
|
+
size?: number;
|
|
8
|
+
}) => FileLike;
|
|
9
|
+
declare const createFileFromWebFile: (source: File, options?: {
|
|
10
|
+
type?: string;
|
|
11
|
+
name?: string;
|
|
12
|
+
size?: number;
|
|
7
13
|
}) => FileLike;
|
|
8
14
|
declare const createFileFromBuffer: (source: Buffer, options?: {
|
|
9
15
|
type?: string;
|
|
@@ -12,6 +18,7 @@ declare const createFileFromBuffer: (source: Buffer, options?: {
|
|
|
12
18
|
declare const createFileFromStream: (source: StreamLike, options?: {
|
|
13
19
|
type?: string;
|
|
14
20
|
name?: string;
|
|
21
|
+
size?: number;
|
|
15
22
|
}) => FileLike & {
|
|
16
23
|
_buffer: null | Buffer;
|
|
17
24
|
};
|
|
@@ -20,27 +27,30 @@ declare const createFileFromUrl: (url: string, options?: {
|
|
|
20
27
|
name?: string;
|
|
21
28
|
}) => FileLike;
|
|
22
29
|
/**
|
|
23
|
-
* Converts a stream-like object to a Buffer.
|
|
24
|
-
*/
|
|
30
|
+
* Converts a stream-like object to a Buffer.
|
|
31
|
+
*/
|
|
25
32
|
declare const streamToBuffer: (streamLike: StreamLike) => Promise<Buffer>;
|
|
26
33
|
/**
|
|
27
|
-
* Converts a Node.js Buffer to an ArrayBuffer.
|
|
28
|
-
*/
|
|
34
|
+
* Converts a Node.js Buffer to an ArrayBuffer.
|
|
35
|
+
*/
|
|
29
36
|
declare const bufferToArrayBuffer: (buffer: Buffer) => ArrayBuffer;
|
|
30
37
|
declare const isReadableStream: (obj: unknown) => obj is NodeJS.ReadableStream;
|
|
38
|
+
//# sourceMappingURL=createFile.d.ts.map
|
|
31
39
|
//#endregion
|
|
32
40
|
//#region src/helpers/getContentType.d.ts
|
|
33
41
|
/**
|
|
34
|
-
* Can be used to get the content type of file based on its extension.
|
|
35
|
-
*
|
|
36
|
-
* Feel free to add more mime types in your project!
|
|
37
|
-
*/
|
|
42
|
+
* Can be used to get the content type of file based on its extension.
|
|
43
|
+
*
|
|
44
|
+
* Feel free to add more mime types in your project!
|
|
45
|
+
*/
|
|
38
46
|
declare const mimeMap: Record<string, string>;
|
|
39
47
|
/**
|
|
40
|
-
* Returns the content type of file based on its filename.
|
|
41
|
-
* @see {mimeMap}
|
|
42
|
-
*/
|
|
48
|
+
* Returns the content type of file based on its filename.
|
|
49
|
+
* @see {mimeMap}
|
|
50
|
+
*/
|
|
43
51
|
declare const getContentType: (filename: string) => string;
|
|
52
|
+
//# sourceMappingURL=getContentType.d.ts.map
|
|
53
|
+
|
|
44
54
|
//#endregion
|
|
45
|
-
export { bufferToArrayBuffer, createFile, createFileFromBuffer, createFileFromStream, createFileFromUrl, getContentType, isReadableStream, mimeMap, streamToBuffer };
|
|
55
|
+
export { bufferToArrayBuffer, createFile, createFileFromBuffer, createFileFromStream, createFileFromUrl, createFileFromWebFile, getContentType, isReadableStream, mimeMap, streamToBuffer };
|
|
46
56
|
//# sourceMappingURL=index.d.ts.map
|
package/lock/redis.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import * as _alepha_core0 from "alepha";
|
|
2
|
+
import { Logger } from "alepha";
|
|
1
3
|
import { LockProvider } from "alepha/lock";
|
|
2
|
-
import { Alepha, Logger } from "alepha";
|
|
3
4
|
import { RedisProvider } from "alepha/redis";
|
|
4
5
|
|
|
5
6
|
//#region src/providers/RedisLockProvider.d.ts
|
|
@@ -9,19 +10,18 @@ declare class RedisLockProvider implements LockProvider {
|
|
|
9
10
|
set(key: string, value: string, nx?: boolean, px?: number): Promise<string>;
|
|
10
11
|
del(...keys: string[]): Promise<void>;
|
|
11
12
|
}
|
|
13
|
+
//# sourceMappingURL=RedisLockProvider.d.ts.map
|
|
12
14
|
//#endregion
|
|
13
15
|
//#region src/index.d.ts
|
|
14
|
-
// ---------------------------------------------------------------------------------------------------------------------
|
|
15
16
|
/**
|
|
16
|
-
* Plugin for Alepha that provides a locking mechanism.
|
|
17
|
-
*
|
|
18
|
-
* @see {@link RedisLockProvider}
|
|
19
|
-
* @module alepha.lock.redis
|
|
20
|
-
*/
|
|
21
|
-
declare
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
17
|
+
* Plugin for Alepha that provides a locking mechanism.
|
|
18
|
+
*
|
|
19
|
+
* @see {@link RedisLockProvider}
|
|
20
|
+
* @module alepha.lock.redis
|
|
21
|
+
*/
|
|
22
|
+
declare const AlephaLockRedis: _alepha_core0.ModuleDescriptor;
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
24
|
+
|
|
25
25
|
//#endregion
|
|
26
26
|
export { AlephaLockRedis, RedisLockProvider };
|
|
27
27
|
//# sourceMappingURL=index.d.ts.map
|
package/lock.d.ts
CHANGED
|
@@ -1,160 +1,170 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import * as _alepha_core1 from "alepha";
|
|
2
|
+
import * as _alepha_core0$1 from "alepha";
|
|
3
|
+
import * as _alepha_core0 from "alepha";
|
|
4
|
+
import { AsyncFn, Descriptor, KIND, Static } from "alepha";
|
|
5
|
+
import * as _alepha_topic0 from "alepha/topic";
|
|
6
|
+
import { TopicProvider } from "alepha/topic";
|
|
3
7
|
import { DateTime, DateTimeProvider, DurationLike, Timeout } from "alepha/datetime";
|
|
8
|
+
import * as dayjs_plugin_duration0 from "dayjs/plugin/duration";
|
|
4
9
|
|
|
10
|
+
//#region src/providers/LockProvider.d.ts
|
|
11
|
+
/**
|
|
12
|
+
* Store Provider Interface
|
|
13
|
+
*/
|
|
14
|
+
declare abstract class LockProvider {
|
|
15
|
+
/**
|
|
16
|
+
* Set the string value of a key.
|
|
17
|
+
*
|
|
18
|
+
* @param key The key of the value to set.
|
|
19
|
+
* @param value The value to set.
|
|
20
|
+
* @param nx If set to true, the key will only be set if it does not already exist.
|
|
21
|
+
* @param px Set the specified expire time, in milliseconds.
|
|
22
|
+
*/
|
|
23
|
+
abstract set(key: string, value: string, nx?: boolean, px?: number): Promise<string>;
|
|
24
|
+
/**
|
|
25
|
+
* Remove the specified keys.
|
|
26
|
+
*
|
|
27
|
+
* @param keys The keys to delete.
|
|
28
|
+
*/
|
|
29
|
+
abstract del(...keys: string[]): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=LockProvider.d.ts.map
|
|
32
|
+
//#endregion
|
|
5
33
|
//#region src/descriptors/$lock.d.ts
|
|
6
|
-
declare const KEY = "LOCK";
|
|
7
34
|
/**
|
|
8
|
-
* Lock descriptor
|
|
9
|
-
*
|
|
10
|
-
* Make sure that only one instance of the handler is running at a time.
|
|
11
|
-
*
|
|
12
|
-
* When connected to a remote store, the lock is shared across all processes.
|
|
13
|
-
*
|
|
14
|
-
* @param options
|
|
15
|
-
*/
|
|
35
|
+
* Lock descriptor
|
|
36
|
+
*
|
|
37
|
+
* Make sure that only one instance of the handler is running at a time.
|
|
38
|
+
*
|
|
39
|
+
* When connected to a remote store, the lock is shared across all processes.
|
|
40
|
+
*
|
|
41
|
+
* @param options
|
|
42
|
+
*/
|
|
16
43
|
declare const $lock: {
|
|
17
44
|
<TFunc extends AsyncFn>(options: LockDescriptorOptions<TFunc>): LockDescriptor<TFunc>;
|
|
18
|
-
[KIND]:
|
|
45
|
+
[KIND]: typeof LockDescriptor;
|
|
19
46
|
};
|
|
20
47
|
interface LockDescriptorOptions<TFunc extends AsyncFn> {
|
|
21
48
|
/**
|
|
22
|
-
|
|
23
|
-
|
|
49
|
+
* Function executed when the lock is acquired.
|
|
50
|
+
*/
|
|
24
51
|
handler: TFunc;
|
|
25
52
|
/**
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
53
|
+
* If true, the handler will wait for the lock to be released.
|
|
54
|
+
*
|
|
55
|
+
* To understand:
|
|
56
|
+
*
|
|
57
|
+
* ### wait = false
|
|
58
|
+
* You have 3 servers running scheduled tasks, you want to ensure that only one of them runs the task at a time.
|
|
59
|
+
* But you don't want the other servers to wait for the lock to be released before they run the task.
|
|
60
|
+
*
|
|
61
|
+
* Problem with not waiting:
|
|
62
|
+
* If the lock is released before a new late trigger, handler will be executed multiple times.
|
|
63
|
+
* Aka, if you have 3 servers but not clock synchronized.
|
|
64
|
+
*
|
|
65
|
+
* ### wait = true
|
|
66
|
+
* You have 3 servers running a migration script on startup, migration script must be run only once.
|
|
67
|
+
* You want to wait the end of migration for each server as they all require the migration to be completed.
|
|
68
|
+
*
|
|
69
|
+
*
|
|
70
|
+
* @default false
|
|
71
|
+
*/
|
|
30
72
|
wait?: boolean;
|
|
31
|
-
key?: string | ((...args: Parameters<TFunc>) => string);
|
|
32
|
-
maxDuration?: DurationLike;
|
|
33
|
-
gracePeriod?: (...args: Parameters<TFunc>) => DurationLike | undefined;
|
|
34
|
-
}
|
|
35
|
-
interface LockDescriptor<TFunc extends AsyncFn> {
|
|
36
|
-
[KIND]: typeof KEY;
|
|
37
|
-
[OPTIONS]: LockDescriptorOptions<TFunc>;
|
|
38
73
|
/**
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
*/
|
|
43
|
-
(...args: Parameters<TFunc>): Promise<void>;
|
|
44
|
-
}
|
|
45
|
-
//#endregion
|
|
46
|
-
//#region src/providers/LockProvider.d.ts
|
|
47
|
-
/**
|
|
48
|
-
* Store Provider Interface
|
|
49
|
-
*/
|
|
50
|
-
declare abstract class LockProvider {
|
|
74
|
+
* Create you own unique key for the lock.
|
|
75
|
+
*/
|
|
76
|
+
name?: string | ((...args: Parameters<TFunc>) => string);
|
|
51
77
|
/**
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
* @param px Set the specified expire time, in milliseconds.
|
|
58
|
-
*/
|
|
59
|
-
abstract set(key: string, value: string, nx?: boolean, px?: number): Promise<string>;
|
|
78
|
+
* Lock timeout.
|
|
79
|
+
*
|
|
80
|
+
* @default 5 minutes
|
|
81
|
+
*/
|
|
82
|
+
maxDuration?: DurationLike;
|
|
60
83
|
/**
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
84
|
+
* Additional lifetime of the lock after the handler has finished executing.
|
|
85
|
+
*
|
|
86
|
+
* This is useful to ensure that the lock is not released too early
|
|
87
|
+
*
|
|
88
|
+
* @default null
|
|
89
|
+
*/
|
|
90
|
+
gracePeriod?: ((...args: Parameters<TFunc>) => DurationLike | undefined) | DurationLike;
|
|
66
91
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
declare class LockTopicProvider extends TopicProvider {}
|
|
70
|
-
//#endregion
|
|
71
|
-
//#region src/providers/LockDescriptorProvider.d.ts
|
|
72
|
-
declare const envSchema: TObject<{
|
|
73
|
-
LOCK_PREFIX_KEY: TString;
|
|
92
|
+
declare const envSchema: _alepha_core1.TObject<{
|
|
93
|
+
LOCK_PREFIX_KEY: _alepha_core1.TString;
|
|
74
94
|
}>;
|
|
75
95
|
declare module "alepha" {
|
|
76
96
|
interface Env extends Partial<Static<typeof envSchema>> {}
|
|
77
97
|
}
|
|
78
|
-
declare class
|
|
79
|
-
protected readonly
|
|
98
|
+
declare class LockDescriptor<TFunc extends AsyncFn> extends Descriptor<LockDescriptorOptions<TFunc>> {
|
|
99
|
+
protected readonly log: _alepha_core1.Logger;
|
|
100
|
+
protected readonly provider: LockProvider;
|
|
101
|
+
protected readonly env: {
|
|
102
|
+
LOCK_PREFIX_KEY: string;
|
|
103
|
+
};
|
|
80
104
|
protected readonly dateTimeProvider: DateTimeProvider;
|
|
81
|
-
protected readonly
|
|
82
|
-
|
|
83
|
-
protected readonly
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
protected readonly locks: Map<string, LockDescriptorValue>;
|
|
87
|
-
protected readonly configure: HookDescriptor<"configure">;
|
|
88
|
-
protected readonly topicLockEnd: TopicDescriptor<{
|
|
89
|
-
payload: TObject<{
|
|
90
|
-
name: TString;
|
|
105
|
+
protected readonly id: `${string}-${string}-${string}-${string}-${string}`;
|
|
106
|
+
readonly maxDuration: dayjs_plugin_duration0.Duration;
|
|
107
|
+
protected readonly topicLockEnd: _alepha_topic0.TopicDescriptor<{
|
|
108
|
+
payload: _alepha_core1.TObject<{
|
|
109
|
+
name: _alepha_core1.TString;
|
|
91
110
|
}>;
|
|
92
111
|
}>;
|
|
93
|
-
|
|
112
|
+
run(...args: Parameters<TFunc>): Promise<void>;
|
|
94
113
|
/**
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
*/
|
|
100
|
-
protected run(value: LockDescriptorValue, ...args: any[]): Promise<void>;
|
|
114
|
+
* Set the lock for the given key.
|
|
115
|
+
*/
|
|
116
|
+
protected lock(key: string): Promise<LockResult>;
|
|
117
|
+
protected setGracePeriod(key: string, lock: LockResult, ...args: Parameters<TFunc>): Promise<void>;
|
|
101
118
|
protected wait(key: string, maxDuration: DurationLike): Promise<void>;
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
*
|
|
105
|
-
* @param key - The key to lock.
|
|
106
|
-
* @param item - The lock descriptor value.
|
|
107
|
-
*/
|
|
108
|
-
protected lock(key: string, item: LockDescriptorValue): Promise<LockObject>;
|
|
109
|
-
protected parse(value: string): LockObject;
|
|
110
|
-
}
|
|
111
|
-
interface LockDescriptorValue {
|
|
112
|
-
options: LockDescriptorOptions<AsyncFn>;
|
|
113
|
-
key: (...args: any[]) => string;
|
|
114
|
-
maxDuration: DurationLike;
|
|
119
|
+
protected key(...args: Parameters<TFunc>): string;
|
|
120
|
+
protected parse(value: string): LockResult;
|
|
115
121
|
}
|
|
116
|
-
interface
|
|
122
|
+
interface LockResult {
|
|
117
123
|
id: string;
|
|
118
124
|
createdAt: DateTime;
|
|
119
125
|
endedAt?: DateTime;
|
|
120
126
|
response?: string;
|
|
121
127
|
}
|
|
128
|
+
//#endregion
|
|
129
|
+
//#region src/providers/LockTopicProvider.d.ts
|
|
130
|
+
declare abstract class LockTopicProvider extends TopicProvider {}
|
|
131
|
+
//# sourceMappingURL=LockTopicProvider.d.ts.map
|
|
132
|
+
|
|
122
133
|
//#endregion
|
|
123
134
|
//#region src/providers/MemoryLockProvider.d.ts
|
|
124
135
|
/**
|
|
125
|
-
* A simple in-memory store provider.
|
|
126
|
-
*/
|
|
136
|
+
* A simple in-memory store provider.
|
|
137
|
+
*/
|
|
127
138
|
declare class MemoryLockProvider implements LockProvider {
|
|
128
139
|
protected readonly dateTimeProvider: DateTimeProvider;
|
|
129
|
-
protected readonly log: Logger;
|
|
140
|
+
protected readonly log: _alepha_core0$1.Logger;
|
|
130
141
|
/**
|
|
131
|
-
|
|
132
|
-
|
|
142
|
+
* The in-memory store.
|
|
143
|
+
*/
|
|
133
144
|
protected store: Record<string, string>;
|
|
134
145
|
/**
|
|
135
|
-
|
|
136
|
-
|
|
146
|
+
* Timeouts used to expire keys.
|
|
147
|
+
*/
|
|
137
148
|
protected storeTimeout: Record<string, Timeout>;
|
|
138
149
|
set(key: string, value: string, nx?: boolean, px?: number): Promise<string>;
|
|
139
150
|
del(...keys: string[]): Promise<void>;
|
|
140
151
|
private ttl;
|
|
141
152
|
}
|
|
153
|
+
//# sourceMappingURL=MemoryLockProvider.d.ts.map
|
|
142
154
|
//#endregion
|
|
143
155
|
//#region src/index.d.ts
|
|
144
|
-
// ---------------------------------------------------------------------------------------------------------------------
|
|
145
156
|
/**
|
|
146
|
-
* Lock a resource for a certain period of time.
|
|
147
|
-
*
|
|
148
|
-
* This module provides a memory implementation of the lock provider.
|
|
149
|
-
* You probably want to use an implementation like RedisLockProvider for distributed systems.
|
|
150
|
-
*
|
|
151
|
-
* @see {@link $lock}
|
|
152
|
-
* @module alepha.lock
|
|
153
|
-
*/
|
|
154
|
-
declare
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}
|
|
157
|
+
* Lock a resource for a certain period of time.
|
|
158
|
+
*
|
|
159
|
+
* This module provides a memory implementation of the lock provider.
|
|
160
|
+
* You probably want to use an implementation like RedisLockProvider for distributed systems.
|
|
161
|
+
*
|
|
162
|
+
* @see {@link $lock}
|
|
163
|
+
* @module alepha.lock
|
|
164
|
+
*/
|
|
165
|
+
declare const AlephaLock: _alepha_core0.ModuleDescriptor;
|
|
166
|
+
//# sourceMappingURL=index.d.ts.map
|
|
167
|
+
|
|
158
168
|
//#endregion
|
|
159
|
-
export { $lock, AlephaLock, LockDescriptor, LockDescriptorOptions,
|
|
169
|
+
export { $lock, AlephaLock, LockDescriptor, LockDescriptorOptions, LockProvider, LockResult, LockTopicProvider, MemoryLockProvider };
|
|
160
170
|
//# sourceMappingURL=index.d.ts.map
|