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/datetime.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Async } from "@alepha/core";
|
|
1
|
+
import { Async, HookDescriptor, Logger } from "alepha";
|
|
3
2
|
import dayjs, { Dayjs, ManipulateType } from "dayjs";
|
|
4
3
|
import dayjsDuration from "dayjs/plugin/duration.js";
|
|
5
4
|
|
|
@@ -11,18 +10,18 @@ declare class Interval {
|
|
|
11
10
|
private options;
|
|
12
11
|
constructor(duration: number, options: IntervalDescriptorOptions);
|
|
13
12
|
/**
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
* Start the interval.
|
|
14
|
+
*/
|
|
16
15
|
start(): Promise<void>;
|
|
17
16
|
/**
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
* Add time to the interval.
|
|
18
|
+
*
|
|
19
|
+
* @param amountMs
|
|
20
|
+
*/
|
|
22
21
|
add(amountMs: number): Promise<void>;
|
|
23
22
|
/**
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
* Clear the interval.
|
|
24
|
+
*/
|
|
26
25
|
clear(): void;
|
|
27
26
|
}
|
|
28
27
|
//#endregion
|
|
@@ -34,18 +33,18 @@ declare class Timeout {
|
|
|
34
33
|
private readonly callback;
|
|
35
34
|
constructor(now: number, duration: number, callback: () => void);
|
|
36
35
|
/**
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
* Add time to the timeout.
|
|
37
|
+
*/
|
|
39
38
|
add(amountMs: number): void;
|
|
40
39
|
/**
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
* Clear the timeout.
|
|
41
|
+
*/
|
|
43
42
|
clear(): void;
|
|
44
43
|
/**
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
* Start the timeout.
|
|
45
|
+
*
|
|
46
|
+
* @private
|
|
47
|
+
*/
|
|
49
48
|
private start;
|
|
50
49
|
}
|
|
51
50
|
//#endregion
|
|
@@ -54,113 +53,114 @@ type DateTime = dayjs.Dayjs;
|
|
|
54
53
|
type Duration = dayjsDuration.Duration;
|
|
55
54
|
type DurationLike = number | dayjsDuration.Duration | [number, ManipulateType];
|
|
56
55
|
declare class DateTimeProvider {
|
|
57
|
-
protected log:
|
|
56
|
+
protected log: Logger;
|
|
58
57
|
protected ref: DateTime | null;
|
|
59
58
|
protected readonly timeouts: Timeout[];
|
|
60
59
|
protected readonly intervals: Interval[];
|
|
61
60
|
constructor();
|
|
62
|
-
protected readonly start:
|
|
63
|
-
protected readonly stop:
|
|
61
|
+
protected readonly start: HookDescriptor<"start">;
|
|
62
|
+
protected readonly stop: HookDescriptor<"stop">;
|
|
64
63
|
/**
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
* Create a new DateTime instance.
|
|
65
|
+
*/
|
|
67
66
|
of(date: string | number | Date | Dayjs | null | undefined): DateTime;
|
|
68
67
|
/**
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
* Get the current date.
|
|
69
|
+
*/
|
|
71
70
|
now(): DateTime;
|
|
72
71
|
/**
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
* Get the current date as a string.
|
|
73
|
+
*
|
|
74
|
+
* @param date
|
|
75
|
+
*/
|
|
77
76
|
toISOString(date?: Date | string | DateTime): string;
|
|
78
77
|
/**
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
* Get the current date as a string.
|
|
79
|
+
*/
|
|
81
80
|
nowISOString(): string;
|
|
82
81
|
/**
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
82
|
+
* Get the current date as a string.
|
|
83
|
+
*
|
|
84
|
+
* @protected
|
|
85
|
+
*/
|
|
87
86
|
protected getCurrentDate(): DateTime;
|
|
88
87
|
/**
|
|
89
|
-
|
|
90
|
-
|
|
88
|
+
* Create a new Duration instance.
|
|
89
|
+
*/
|
|
91
90
|
duration: (duration: DurationLike, unit?: ManipulateType) => Duration;
|
|
92
91
|
isDurationLike(value: unknown): value is DurationLike;
|
|
93
92
|
/**
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
93
|
+
* Return a promise that resolves after a next tick.
|
|
94
|
+
* It uses `setTimeout` with 0ms delay.
|
|
95
|
+
*/
|
|
97
96
|
tick(): Promise<void>;
|
|
98
97
|
/**
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
98
|
+
* Wait for a certain duration.
|
|
99
|
+
*
|
|
100
|
+
* You can clear the timeout by using the `AbortSignal` API.
|
|
101
|
+
* Aborted signal will resolve the promise immediately, it does not reject it.
|
|
102
|
+
*/
|
|
104
103
|
wait(duration: DurationLike, options?: {
|
|
105
104
|
signal?: AbortSignal;
|
|
106
105
|
now?: number;
|
|
107
106
|
}): Promise<void>;
|
|
108
107
|
/**
|
|
109
|
-
|
|
110
|
-
|
|
108
|
+
* Run a callback after a certain duration.
|
|
109
|
+
*/
|
|
111
110
|
timeout(callback: () => void, duration: DurationLike, now?: number): Timeout;
|
|
112
111
|
/**
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
112
|
+
* Create an interval.
|
|
113
|
+
*
|
|
114
|
+
* @param args
|
|
115
|
+
*/
|
|
117
116
|
interval(args: IntervalDescriptorOptions): Interval;
|
|
118
117
|
/**
|
|
119
|
-
|
|
120
|
-
|
|
118
|
+
* Run a function with a deadline.
|
|
119
|
+
*/
|
|
121
120
|
deadline<T>(fn: (signal: AbortSignal) => Promise<T>, duration: DurationLike): Promise<T>;
|
|
121
|
+
// Testing
|
|
122
122
|
/**
|
|
123
|
-
|
|
124
|
-
|
|
123
|
+
* Add time to the current date.
|
|
124
|
+
*/
|
|
125
125
|
travel(duration: DurationLike, unit?: ManipulateType): Promise<void>;
|
|
126
126
|
/**
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
pause():
|
|
127
|
+
* Stop the time.
|
|
128
|
+
*/
|
|
129
|
+
pause(): DateTime;
|
|
130
130
|
/**
|
|
131
|
-
|
|
132
|
-
|
|
131
|
+
* Reset the reference date.
|
|
132
|
+
*/
|
|
133
133
|
reset(): void;
|
|
134
134
|
}
|
|
135
135
|
//#endregion
|
|
136
136
|
//#region src/descriptors/$interval.d.ts
|
|
137
137
|
interface IntervalDescriptorOptions {
|
|
138
138
|
/**
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
139
|
+
* Whether to start the interval immediately.
|
|
140
|
+
*
|
|
141
|
+
* @default false
|
|
142
|
+
*/
|
|
143
143
|
run?: boolean;
|
|
144
144
|
/**
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
145
|
+
* Whether to attach the interval to the context.
|
|
146
|
+
*
|
|
147
|
+
* Attached intervals are automatically started when the context starts and stopped when the context stops.
|
|
148
|
+
*
|
|
149
|
+
* @default true
|
|
150
|
+
*/
|
|
151
151
|
attach?: boolean;
|
|
152
152
|
/**
|
|
153
|
-
|
|
154
|
-
|
|
153
|
+
* The interval handler.
|
|
154
|
+
*/
|
|
155
155
|
handler: () => Async<void>;
|
|
156
156
|
/**
|
|
157
|
-
|
|
158
|
-
|
|
157
|
+
* The interval duration.
|
|
158
|
+
*/
|
|
159
159
|
duration: DurationLike;
|
|
160
160
|
}
|
|
161
161
|
/**
|
|
162
|
-
|
|
163
|
-
|
|
162
|
+
* Registers a new interval.
|
|
163
|
+
*/
|
|
164
164
|
declare const $interval: (options: IntervalDescriptorOptions) => Interval;
|
|
165
165
|
//#endregion
|
|
166
166
|
export { $interval, DateTime, DateTimeProvider, Duration, DurationLike, Interval, IntervalDescriptorOptions, Timeout };
|
package/lock/redis.d.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { LockProvider } from "
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import { RedisProvider } from "@alepha/redis";
|
|
1
|
+
import { LockProvider } from "alepha/lock";
|
|
2
|
+
import { Alepha, Logger } from "alepha";
|
|
3
|
+
import { RedisProvider } from "alepha/redis";
|
|
5
4
|
|
|
6
5
|
//#region src/providers/RedisLockProvider.d.ts
|
|
7
6
|
declare class RedisLockProvider implements LockProvider {
|
|
8
|
-
protected readonly log:
|
|
7
|
+
protected readonly log: Logger;
|
|
9
8
|
protected readonly redisProvider: RedisProvider;
|
|
10
9
|
set(key: string, value: string, nx?: boolean, px?: number): Promise<string>;
|
|
11
10
|
del(...keys: string[]): Promise<void>;
|
|
12
11
|
}
|
|
13
12
|
//#endregion
|
|
14
13
|
//#region src/index.d.ts
|
|
14
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
15
15
|
/**
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
* Alepha Lock Redis Module
|
|
17
|
+
*
|
|
18
|
+
* Plugin for Alepha that provides a locking mechanism.
|
|
19
|
+
*
|
|
20
|
+
* @see {@link RedisLockProvider}
|
|
21
|
+
* @module alepha.lock.redis
|
|
22
|
+
*/
|
|
23
23
|
declare class AlephaLockRedis {
|
|
24
24
|
readonly name = "alepha.lock.redis";
|
|
25
25
|
readonly $services: (alepha: Alepha) => Alepha;
|
package/lock.d.ts
CHANGED
|
@@ -1,23 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import * as _alepha_topic8 from "@alepha/topic";
|
|
5
|
-
import { TopicProvider } from "@alepha/topic";
|
|
6
|
-
import { DateTime, DateTimeProvider, DurationLike, Timeout } from "@alepha/datetime";
|
|
7
|
-
import * as _sinclair_typebox1 from "@sinclair/typebox";
|
|
1
|
+
import { Alepha, AsyncFn, HookDescriptor, KIND, Logger, OPTIONS, Static, TObject, TString } from "alepha";
|
|
2
|
+
import { TopicDescriptor, TopicProvider } from "alepha/topic";
|
|
3
|
+
import { DateTime, DateTimeProvider, DurationLike, Timeout } from "alepha/datetime";
|
|
8
4
|
|
|
9
5
|
//#region src/descriptors/$lock.d.ts
|
|
10
6
|
declare const KEY = "LOCK";
|
|
11
7
|
interface LockDescriptorOptions<TFunc extends AsyncFn> {
|
|
12
8
|
/**
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
* Function executed when the lock is acquired.
|
|
10
|
+
*/
|
|
15
11
|
handler: TFunc;
|
|
16
12
|
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
* If true, the handler will wait for the lock to be released.
|
|
14
|
+
*
|
|
15
|
+
* @default false
|
|
16
|
+
*/
|
|
21
17
|
wait?: boolean;
|
|
22
18
|
key?: string | ((...args: Parameters<TFunc>) => string);
|
|
23
19
|
maxDuration?: DurationLike;
|
|
@@ -27,21 +23,21 @@ interface LockDescriptor<TFunc extends AsyncFn> {
|
|
|
27
23
|
[KIND]: typeof KEY;
|
|
28
24
|
[OPTIONS]: LockDescriptorOptions<TFunc>;
|
|
29
25
|
/**
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
* Apply the lock.
|
|
27
|
+
*
|
|
28
|
+
* @param args
|
|
29
|
+
*/
|
|
34
30
|
(...args: Parameters<TFunc>): Promise<void>;
|
|
35
31
|
}
|
|
36
32
|
/**
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
33
|
+
* Lock descriptor
|
|
34
|
+
*
|
|
35
|
+
* Make sure that only one instance of the handler is running at a time.
|
|
36
|
+
*
|
|
37
|
+
* When connected to a remote store, the lock is shared across all processes.
|
|
38
|
+
*
|
|
39
|
+
* @param options
|
|
40
|
+
*/
|
|
45
41
|
declare const $lock: {
|
|
46
42
|
<TFunc extends AsyncFn>(options: LockDescriptorOptions<TFunc>): LockDescriptor<TFunc>;
|
|
47
43
|
[KIND]: string;
|
|
@@ -49,23 +45,23 @@ declare const $lock: {
|
|
|
49
45
|
//#endregion
|
|
50
46
|
//#region src/providers/LockProvider.d.ts
|
|
51
47
|
/**
|
|
52
|
-
|
|
53
|
-
|
|
48
|
+
* Store Provider Interface
|
|
49
|
+
*/
|
|
54
50
|
declare abstract class LockProvider {
|
|
55
51
|
/**
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
52
|
+
* Set the string value of a key.
|
|
53
|
+
*
|
|
54
|
+
* @param key The key of the value to set.
|
|
55
|
+
* @param value The value to set.
|
|
56
|
+
* @param nx If set to true, the key will only be set if it does not already exist.
|
|
57
|
+
* @param px Set the specified expire time, in milliseconds.
|
|
58
|
+
*/
|
|
63
59
|
abstract set(key: string, value: string, nx?: boolean, px?: number): Promise<string>;
|
|
64
60
|
/**
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
61
|
+
* Remove the specified keys.
|
|
62
|
+
*
|
|
63
|
+
* @param keys The keys to delete.
|
|
64
|
+
*/
|
|
69
65
|
abstract del(...keys: string[]): Promise<void>;
|
|
70
66
|
}
|
|
71
67
|
//#endregion
|
|
@@ -73,8 +69,8 @@ declare abstract class LockProvider {
|
|
|
73
69
|
declare class LockTopicProvider extends TopicProvider {}
|
|
74
70
|
//#endregion
|
|
75
71
|
//#region src/providers/LockDescriptorProvider.d.ts
|
|
76
|
-
declare const envSchema:
|
|
77
|
-
LOCK_PREFIX_KEY:
|
|
72
|
+
declare const envSchema: TObject<{
|
|
73
|
+
LOCK_PREFIX_KEY: TString;
|
|
78
74
|
}>;
|
|
79
75
|
declare module "alepha" {
|
|
80
76
|
interface Env extends Partial<Static<typeof envSchema>> {}
|
|
@@ -84,33 +80,31 @@ declare class LockDescriptorProvider {
|
|
|
84
80
|
protected readonly dateTimeProvider: DateTimeProvider;
|
|
85
81
|
protected readonly lockProvider: LockProvider;
|
|
86
82
|
protected readonly lockTopicProvider: LockTopicProvider;
|
|
87
|
-
protected readonly log:
|
|
88
|
-
protected readonly env:
|
|
89
|
-
LOCK_PREFIX_KEY: string;
|
|
90
|
-
};
|
|
83
|
+
protected readonly log: Logger;
|
|
84
|
+
protected readonly env: Static<typeof envSchema>;
|
|
91
85
|
protected readonly id: string;
|
|
92
86
|
protected readonly locks: Map<string, LockDescriptorValue>;
|
|
93
|
-
protected readonly configure:
|
|
94
|
-
protected readonly topicLockEnd:
|
|
95
|
-
payload:
|
|
96
|
-
name:
|
|
87
|
+
protected readonly configure: HookDescriptor<"configure">;
|
|
88
|
+
protected readonly topicLockEnd: TopicDescriptor<{
|
|
89
|
+
payload: TObject<{
|
|
90
|
+
name: TString;
|
|
97
91
|
}>;
|
|
98
92
|
}>;
|
|
99
93
|
protected prefixKey(key: string): string;
|
|
100
94
|
/**
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
95
|
+
* Run the lock handler.
|
|
96
|
+
*
|
|
97
|
+
* @param value
|
|
98
|
+
* @param args
|
|
99
|
+
*/
|
|
106
100
|
protected run(value: LockDescriptorValue, ...args: any[]): Promise<void>;
|
|
107
101
|
protected wait(key: string, maxDuration: DurationLike): Promise<void>;
|
|
108
102
|
/**
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
103
|
+
* Lock the key.
|
|
104
|
+
*
|
|
105
|
+
* @param key - The key to lock.
|
|
106
|
+
* @param item - The lock descriptor value.
|
|
107
|
+
*/
|
|
114
108
|
protected lock(key: string, item: LockDescriptorValue): Promise<LockObject>;
|
|
115
109
|
protected parse(value: string): LockObject;
|
|
116
110
|
}
|
|
@@ -128,18 +122,18 @@ interface LockObject {
|
|
|
128
122
|
//#endregion
|
|
129
123
|
//#region src/providers/MemoryLockProvider.d.ts
|
|
130
124
|
/**
|
|
131
|
-
|
|
132
|
-
|
|
125
|
+
* A simple in-memory store provider.
|
|
126
|
+
*/
|
|
133
127
|
declare class MemoryLockProvider implements LockProvider {
|
|
134
128
|
protected readonly dateTimeProvider: DateTimeProvider;
|
|
135
|
-
protected readonly log:
|
|
129
|
+
protected readonly log: Logger;
|
|
136
130
|
/**
|
|
137
|
-
|
|
138
|
-
|
|
131
|
+
* The in-memory store.
|
|
132
|
+
*/
|
|
139
133
|
protected store: Record<string, string>;
|
|
140
134
|
/**
|
|
141
|
-
|
|
142
|
-
|
|
135
|
+
* Timeouts used to expire keys.
|
|
136
|
+
*/
|
|
143
137
|
protected storeTimeout: Record<string, Timeout>;
|
|
144
138
|
set(key: string, value: string, nx?: boolean, px?: number): Promise<string>;
|
|
145
139
|
del(...keys: string[]): Promise<void>;
|
|
@@ -147,17 +141,18 @@ declare class MemoryLockProvider implements LockProvider {
|
|
|
147
141
|
}
|
|
148
142
|
//#endregion
|
|
149
143
|
//#region src/index.d.ts
|
|
144
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
150
145
|
/**
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
146
|
+
* Alepha Lock Module
|
|
147
|
+
*
|
|
148
|
+
* Lock a resource for a certain period of time.
|
|
149
|
+
*
|
|
150
|
+
* This module provides a memory implementation of the lock provider.
|
|
151
|
+
* You probably want to use an implementation like RedisLockProvider for distributed systems.
|
|
152
|
+
*
|
|
153
|
+
* @see {@link $lock}
|
|
154
|
+
* @module alepha.lock
|
|
155
|
+
*/
|
|
161
156
|
declare class AlephaLock {
|
|
162
157
|
readonly name = "alepha.lock";
|
|
163
158
|
readonly $services: (alepha: Alepha) => Alepha;
|