alepha 0.13.0 → 0.13.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/dist/api-jobs/index.d.ts +26 -26
- package/dist/api-users/index.d.ts +1 -1
- package/dist/cli/{dist-Sz2EXvQX.cjs → dist-Dl9Vl7Ur.js} +17 -13
- package/dist/cli/{dist-BBPjuQ56.js.map → dist-Dl9Vl7Ur.js.map} +1 -1
- package/dist/cli/index.d.ts +3 -11
- package/dist/cli/index.js +106 -74
- package/dist/cli/index.js.map +1 -1
- package/dist/email/index.js +71 -73
- package/dist/email/index.js.map +1 -1
- package/dist/orm/index.d.ts +1 -1
- package/dist/orm/index.js.map +1 -1
- package/dist/queue/index.d.ts +4 -4
- package/dist/retry/index.d.ts +1 -1
- package/dist/retry/index.js +2 -2
- package/dist/retry/index.js.map +1 -1
- package/dist/scheduler/index.d.ts +6 -6
- package/dist/security/index.d.ts +28 -28
- package/dist/server/index.js +1 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server-health/index.d.ts +17 -17
- package/dist/server-metrics/index.js +170 -174
- package/dist/server-metrics/index.js.map +1 -1
- package/dist/server-security/index.d.ts +9 -9
- package/dist/vite/index.js +4 -5
- package/dist/vite/index.js.map +1 -1
- package/dist/websocket/index.d.ts +7 -7
- package/package.json +52 -103
- package/src/cli/apps/AlephaPackageBuilderCli.ts +7 -2
- package/src/cli/assets/appRouterTs.ts +9 -0
- package/src/cli/assets/indexHtml.ts +2 -1
- package/src/cli/assets/mainBrowserTs.ts +10 -0
- package/src/cli/commands/CoreCommands.ts +6 -5
- package/src/cli/commands/DrizzleCommands.ts +65 -57
- package/src/cli/commands/VerifyCommands.ts +1 -1
- package/src/cli/services/ProjectUtils.ts +44 -38
- package/src/orm/providers/DrizzleKitProvider.ts +1 -1
- package/src/retry/descriptors/$retry.ts +5 -3
- package/src/server/providers/NodeHttpServerProvider.ts +1 -1
- package/src/vite/helpers/boot.ts +3 -3
- package/dist/api-files/index.cjs +0 -1293
- package/dist/api-files/index.cjs.map +0 -1
- package/dist/api-files/index.d.cts +0 -829
- package/dist/api-jobs/index.cjs +0 -274
- package/dist/api-jobs/index.cjs.map +0 -1
- package/dist/api-jobs/index.d.cts +0 -654
- package/dist/api-notifications/index.cjs +0 -380
- package/dist/api-notifications/index.cjs.map +0 -1
- package/dist/api-notifications/index.d.cts +0 -289
- package/dist/api-parameters/index.cjs +0 -66
- package/dist/api-parameters/index.cjs.map +0 -1
- package/dist/api-parameters/index.d.cts +0 -84
- package/dist/api-users/index.cjs +0 -6009
- package/dist/api-users/index.cjs.map +0 -1
- package/dist/api-users/index.d.cts +0 -4740
- package/dist/api-verifications/index.cjs +0 -407
- package/dist/api-verifications/index.cjs.map +0 -1
- package/dist/api-verifications/index.d.cts +0 -207
- package/dist/batch/index.cjs +0 -408
- package/dist/batch/index.cjs.map +0 -1
- package/dist/batch/index.d.cts +0 -330
- package/dist/bin/index.cjs +0 -17
- package/dist/bin/index.cjs.map +0 -1
- package/dist/bin/index.d.cts +0 -1
- package/dist/bucket/index.cjs +0 -303
- package/dist/bucket/index.cjs.map +0 -1
- package/dist/bucket/index.d.cts +0 -355
- package/dist/cache/index.cjs +0 -241
- package/dist/cache/index.cjs.map +0 -1
- package/dist/cache/index.d.cts +0 -202
- package/dist/cache-redis/index.cjs +0 -84
- package/dist/cache-redis/index.cjs.map +0 -1
- package/dist/cache-redis/index.d.cts +0 -40
- package/dist/cli/chunk-DSlc6foC.cjs +0 -43
- package/dist/cli/dist-BBPjuQ56.js +0 -2778
- package/dist/cli/dist-Sz2EXvQX.cjs.map +0 -1
- package/dist/cli/index.cjs +0 -1241
- package/dist/cli/index.cjs.map +0 -1
- package/dist/cli/index.d.cts +0 -422
- package/dist/command/index.cjs +0 -693
- package/dist/command/index.cjs.map +0 -1
- package/dist/command/index.d.cts +0 -340
- package/dist/core/index.cjs +0 -2264
- package/dist/core/index.cjs.map +0 -1
- package/dist/core/index.d.cts +0 -1927
- package/dist/datetime/index.cjs +0 -318
- package/dist/datetime/index.cjs.map +0 -1
- package/dist/datetime/index.d.cts +0 -145
- package/dist/email/index.cjs +0 -10874
- package/dist/email/index.cjs.map +0 -1
- package/dist/email/index.d.cts +0 -186
- package/dist/fake/index.cjs +0 -34641
- package/dist/fake/index.cjs.map +0 -1
- package/dist/fake/index.d.cts +0 -74
- package/dist/file/index.cjs +0 -1212
- package/dist/file/index.cjs.map +0 -1
- package/dist/file/index.d.cts +0 -698
- package/dist/lock/index.cjs +0 -226
- package/dist/lock/index.cjs.map +0 -1
- package/dist/lock/index.d.cts +0 -361
- package/dist/lock-redis/index.cjs +0 -113
- package/dist/lock-redis/index.cjs.map +0 -1
- package/dist/lock-redis/index.d.cts +0 -24
- package/dist/logger/index.cjs +0 -521
- package/dist/logger/index.cjs.map +0 -1
- package/dist/logger/index.d.cts +0 -281
- package/dist/orm/index.cjs +0 -2986
- package/dist/orm/index.cjs.map +0 -1
- package/dist/orm/index.d.cts +0 -2213
- package/dist/queue/index.cjs +0 -1044
- package/dist/queue/index.cjs.map +0 -1
- package/dist/queue/index.d.cts +0 -1265
- package/dist/queue-redis/index.cjs +0 -873
- package/dist/queue-redis/index.cjs.map +0 -1
- package/dist/queue-redis/index.d.cts +0 -82
- package/dist/redis/index.cjs +0 -153
- package/dist/redis/index.cjs.map +0 -1
- package/dist/redis/index.d.cts +0 -82
- package/dist/retry/index.cjs +0 -146
- package/dist/retry/index.cjs.map +0 -1
- package/dist/retry/index.d.cts +0 -172
- package/dist/router/index.cjs +0 -111
- package/dist/router/index.cjs.map +0 -1
- package/dist/router/index.d.cts +0 -46
- package/dist/scheduler/index.cjs +0 -576
- package/dist/scheduler/index.cjs.map +0 -1
- package/dist/scheduler/index.d.cts +0 -145
- package/dist/security/index.cjs +0 -2402
- package/dist/security/index.cjs.map +0 -1
- package/dist/security/index.d.cts +0 -598
- package/dist/server/index.cjs +0 -1680
- package/dist/server/index.cjs.map +0 -1
- package/dist/server/index.d.cts +0 -810
- package/dist/server-auth/index.cjs +0 -3146
- package/dist/server-auth/index.cjs.map +0 -1
- package/dist/server-auth/index.d.cts +0 -1164
- package/dist/server-cache/index.cjs +0 -252
- package/dist/server-cache/index.cjs.map +0 -1
- package/dist/server-cache/index.d.cts +0 -164
- package/dist/server-compress/index.cjs +0 -141
- package/dist/server-compress/index.cjs.map +0 -1
- package/dist/server-compress/index.d.cts +0 -38
- package/dist/server-cookies/index.cjs +0 -234
- package/dist/server-cookies/index.cjs.map +0 -1
- package/dist/server-cookies/index.d.cts +0 -144
- package/dist/server-cors/index.cjs +0 -201
- package/dist/server-cors/index.cjs.map +0 -1
- package/dist/server-cors/index.d.cts +0 -140
- package/dist/server-health/index.cjs +0 -62
- package/dist/server-health/index.cjs.map +0 -1
- package/dist/server-health/index.d.cts +0 -58
- package/dist/server-helmet/index.cjs +0 -131
- package/dist/server-helmet/index.cjs.map +0 -1
- package/dist/server-helmet/index.d.cts +0 -97
- package/dist/server-links/index.cjs +0 -992
- package/dist/server-links/index.cjs.map +0 -1
- package/dist/server-links/index.d.cts +0 -513
- package/dist/server-metrics/index.cjs +0 -4535
- package/dist/server-metrics/index.cjs.map +0 -1
- package/dist/server-metrics/index.d.cts +0 -35
- package/dist/server-multipart/index.cjs +0 -237
- package/dist/server-multipart/index.cjs.map +0 -1
- package/dist/server-multipart/index.d.cts +0 -50
- package/dist/server-proxy/index.cjs +0 -186
- package/dist/server-proxy/index.cjs.map +0 -1
- package/dist/server-proxy/index.d.cts +0 -234
- package/dist/server-rate-limit/index.cjs +0 -241
- package/dist/server-rate-limit/index.cjs.map +0 -1
- package/dist/server-rate-limit/index.d.cts +0 -183
- package/dist/server-security/index.cjs +0 -316
- package/dist/server-security/index.cjs.map +0 -1
- package/dist/server-security/index.d.cts +0 -173
- package/dist/server-static/index.cjs +0 -170
- package/dist/server-static/index.cjs.map +0 -1
- package/dist/server-static/index.d.cts +0 -121
- package/dist/server-swagger/index.cjs +0 -1021
- package/dist/server-swagger/index.cjs.map +0 -1
- package/dist/server-swagger/index.d.cts +0 -382
- package/dist/sms/index.cjs +0 -221
- package/dist/sms/index.cjs.map +0 -1
- package/dist/sms/index.d.cts +0 -130
- package/dist/thread/index.cjs +0 -350
- package/dist/thread/index.cjs.map +0 -1
- package/dist/thread/index.d.cts +0 -260
- package/dist/topic/index.cjs +0 -282
- package/dist/topic/index.cjs.map +0 -1
- package/dist/topic/index.d.cts +0 -523
- package/dist/topic-redis/index.cjs +0 -71
- package/dist/topic-redis/index.cjs.map +0 -1
- package/dist/topic-redis/index.d.cts +0 -42
- package/dist/vite/index.cjs +0 -1077
- package/dist/vite/index.cjs.map +0 -1
- package/dist/vite/index.d.cts +0 -542
- package/dist/websocket/index.cjs +0 -1117
- package/dist/websocket/index.cjs.map +0 -1
- package/dist/websocket/index.d.cts +0 -861
package/dist/datetime/index.cjs
DELETED
|
@@ -1,318 +0,0 @@
|
|
|
1
|
-
//#region rolldown:runtime
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
-
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
-
key = keys[i];
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
-
__defProp(to, key, {
|
|
14
|
-
get: ((k) => from[k]).bind(null, key),
|
|
15
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return to;
|
|
21
|
-
};
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
-
value: mod,
|
|
24
|
-
enumerable: true
|
|
25
|
-
}) : target, mod));
|
|
26
|
-
|
|
27
|
-
//#endregion
|
|
28
|
-
let alepha = require("alepha");
|
|
29
|
-
let dayjs_plugin_relativeTime_js = require("dayjs/plugin/relativeTime.js");
|
|
30
|
-
dayjs_plugin_relativeTime_js = __toESM(dayjs_plugin_relativeTime_js);
|
|
31
|
-
let dayjs_plugin_duration_js = require("dayjs/plugin/duration.js");
|
|
32
|
-
dayjs_plugin_duration_js = __toESM(dayjs_plugin_duration_js);
|
|
33
|
-
let dayjs_plugin_utc_js = require("dayjs/plugin/utc.js");
|
|
34
|
-
dayjs_plugin_utc_js = __toESM(dayjs_plugin_utc_js);
|
|
35
|
-
let dayjs_plugin_timezone_js = require("dayjs/plugin/timezone.js");
|
|
36
|
-
dayjs_plugin_timezone_js = __toESM(dayjs_plugin_timezone_js);
|
|
37
|
-
let dayjs_plugin_localizedFormat_js = require("dayjs/plugin/localizedFormat.js");
|
|
38
|
-
dayjs_plugin_localizedFormat_js = __toESM(dayjs_plugin_localizedFormat_js);
|
|
39
|
-
require("dayjs/locale/ar.js");
|
|
40
|
-
require("dayjs/locale/fr.js");
|
|
41
|
-
let dayjs = require("dayjs");
|
|
42
|
-
dayjs = __toESM(dayjs);
|
|
43
|
-
|
|
44
|
-
//#region src/datetime/providers/DateTimeProvider.ts
|
|
45
|
-
const dayjs$1 = dayjs.default;
|
|
46
|
-
const isDateTime = (value) => {
|
|
47
|
-
return dayjs$1.isDayjs(value);
|
|
48
|
-
};
|
|
49
|
-
var DateTimeProvider = class DateTimeProvider {
|
|
50
|
-
static PLUGINS = [
|
|
51
|
-
dayjs_plugin_duration_js.default,
|
|
52
|
-
dayjs_plugin_relativeTime_js.default,
|
|
53
|
-
dayjs_plugin_utc_js.default,
|
|
54
|
-
dayjs_plugin_timezone_js.default,
|
|
55
|
-
dayjs_plugin_localizedFormat_js.default
|
|
56
|
-
];
|
|
57
|
-
alepha = (0, alepha.$inject)(alepha.Alepha);
|
|
58
|
-
ref = null;
|
|
59
|
-
timeouts = [];
|
|
60
|
-
intervals = [];
|
|
61
|
-
constructor() {
|
|
62
|
-
for (const plugin of DateTimeProvider.PLUGINS) dayjs$1.extend(plugin);
|
|
63
|
-
}
|
|
64
|
-
onStart = (0, alepha.$hook)({
|
|
65
|
-
on: "start",
|
|
66
|
-
handler: async () => {
|
|
67
|
-
await Promise.all(this.intervals.map(async (interval) => {
|
|
68
|
-
if (interval.timer != null) return;
|
|
69
|
-
await interval.run();
|
|
70
|
-
interval.timer = setInterval(interval.run, interval.duration);
|
|
71
|
-
}));
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
onStop = (0, alepha.$hook)({
|
|
75
|
-
on: "stop",
|
|
76
|
-
handler: () => {
|
|
77
|
-
for (const timeout of this.timeouts) this.clearTimeout(timeout);
|
|
78
|
-
for (const interval of this.intervals) {
|
|
79
|
-
clearInterval(interval.timer);
|
|
80
|
-
interval.duration = 0;
|
|
81
|
-
interval.timer = null;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
setLocale(locale) {
|
|
86
|
-
dayjs$1.locale(locale);
|
|
87
|
-
}
|
|
88
|
-
isDateTime(value) {
|
|
89
|
-
return dayjs$1.isDayjs(value);
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Create a new UTC DateTime instance.
|
|
93
|
-
*/
|
|
94
|
-
utc(date) {
|
|
95
|
-
return dayjs$1.utc(date);
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Create a new DateTime instance.
|
|
99
|
-
*/
|
|
100
|
-
of(date) {
|
|
101
|
-
return dayjs$1(date);
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Get the current date as a string.
|
|
105
|
-
*/
|
|
106
|
-
toISOString(date = this.now()) {
|
|
107
|
-
return this.of(date).toISOString();
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Get the current date.
|
|
111
|
-
*/
|
|
112
|
-
now() {
|
|
113
|
-
return this.getCurrentDate();
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Get the current date as a string.
|
|
117
|
-
*
|
|
118
|
-
* This is much faster than `DateTimeProvider.now().toISOString()` as it avoids creating a DateTime instance.
|
|
119
|
-
*/
|
|
120
|
-
nowISOString() {
|
|
121
|
-
if (this.ref) return this.ref.toISOString();
|
|
122
|
-
return (/* @__PURE__ */ new Date()).toISOString();
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Get the current date as milliseconds since epoch.
|
|
126
|
-
*
|
|
127
|
-
* This is much faster than `DateTimeProvider.now().valueOf()` as it avoids creating a DateTime instance.
|
|
128
|
-
*/
|
|
129
|
-
nowMillis() {
|
|
130
|
-
if (this.ref) return this.ref.valueOf();
|
|
131
|
-
return Date.now();
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Get the current date as a string.
|
|
135
|
-
*
|
|
136
|
-
* @protected
|
|
137
|
-
*/
|
|
138
|
-
getCurrentDate() {
|
|
139
|
-
if (this.ref) return this.ref;
|
|
140
|
-
return dayjs$1();
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Create a new Duration instance.
|
|
144
|
-
*/
|
|
145
|
-
duration = (duration, unit) => {
|
|
146
|
-
if (Array.isArray(duration)) return dayjs$1.duration(duration[0], duration[1]);
|
|
147
|
-
if (typeof duration === "number") return dayjs$1.duration(duration, unit || "milliseconds");
|
|
148
|
-
return duration;
|
|
149
|
-
};
|
|
150
|
-
isDurationLike(value) {
|
|
151
|
-
return dayjs$1.isDuration(this.duration(value));
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Return a promise that resolves after the next tick.
|
|
155
|
-
* It uses `setTimeout` with 0 ms delay.
|
|
156
|
-
*/
|
|
157
|
-
async tick() {
|
|
158
|
-
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Wait for a certain duration.
|
|
162
|
-
*
|
|
163
|
-
* You can clear the timeout by using the `AbortSignal` API.
|
|
164
|
-
* Aborted signal will resolve the promise immediately, it does not reject it.
|
|
165
|
-
*/
|
|
166
|
-
wait(duration, options = {}) {
|
|
167
|
-
return new Promise((resolve) => {
|
|
168
|
-
let clearTimeout$1;
|
|
169
|
-
let callback;
|
|
170
|
-
const timeout = this.createTimeout(() => {
|
|
171
|
-
if (options.signal && clearTimeout$1) options.signal.removeEventListener("abort", callback);
|
|
172
|
-
resolve();
|
|
173
|
-
}, duration, options.now);
|
|
174
|
-
if (options.signal) {
|
|
175
|
-
clearTimeout$1 = () => this.clearTimeout(timeout);
|
|
176
|
-
callback = () => {
|
|
177
|
-
clearTimeout$1();
|
|
178
|
-
resolve();
|
|
179
|
-
};
|
|
180
|
-
options.signal.addEventListener("abort", callback);
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
createInterval(run, duration, start = false) {
|
|
185
|
-
const interval = {
|
|
186
|
-
run,
|
|
187
|
-
duration: this.duration(duration).asMilliseconds()
|
|
188
|
-
};
|
|
189
|
-
this.intervals.push(interval);
|
|
190
|
-
if (start) interval.timer = setInterval(interval.run, interval.duration);
|
|
191
|
-
return interval;
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Run a callback after a certain duration.
|
|
195
|
-
*/
|
|
196
|
-
createTimeout(callback, duration, now) {
|
|
197
|
-
if (this.ref && now) {
|
|
198
|
-
if (this.of(now).add(this.duration(duration)) < this.now()) callback();
|
|
199
|
-
return {
|
|
200
|
-
now,
|
|
201
|
-
duration: 0,
|
|
202
|
-
callback: () => {},
|
|
203
|
-
clear: () => {}
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
const timeout = {
|
|
207
|
-
now: now ?? this.now().valueOf(),
|
|
208
|
-
duration: this.duration(duration).asMilliseconds(),
|
|
209
|
-
callback,
|
|
210
|
-
clear: () => this.clearTimeout(timeout)
|
|
211
|
-
};
|
|
212
|
-
timeout.timer = setTimeout(() => {
|
|
213
|
-
timeout.callback();
|
|
214
|
-
}, timeout.duration);
|
|
215
|
-
this.timeouts.push(timeout);
|
|
216
|
-
return timeout;
|
|
217
|
-
}
|
|
218
|
-
clearTimeout(timeout) {
|
|
219
|
-
clearTimeout(timeout.timer);
|
|
220
|
-
timeout.duration = 0;
|
|
221
|
-
timeout.timer = null;
|
|
222
|
-
}
|
|
223
|
-
clearInterval(interval) {
|
|
224
|
-
clearInterval(interval.timer);
|
|
225
|
-
interval.duration = 0;
|
|
226
|
-
interval.timer = null;
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* Run a function with a deadline.
|
|
230
|
-
*/
|
|
231
|
-
async deadline(fn, duration) {
|
|
232
|
-
const abort = new AbortController();
|
|
233
|
-
const timeout = this.createTimeout(() => abort.abort(), duration);
|
|
234
|
-
try {
|
|
235
|
-
return await fn(abort.signal);
|
|
236
|
-
} finally {
|
|
237
|
-
this.clearTimeout(timeout);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* Add time to the current date.
|
|
242
|
-
*/
|
|
243
|
-
async travel(duration, unit) {
|
|
244
|
-
this.ref = this.ref || this.now();
|
|
245
|
-
this.ref = this.ref.add(this.duration(duration, unit));
|
|
246
|
-
const ms = this.duration(duration, unit).asMilliseconds();
|
|
247
|
-
const now = Date.now();
|
|
248
|
-
for (const timeout of this.timeouts) {
|
|
249
|
-
if (!timeout.timer) continue;
|
|
250
|
-
clearTimeout(timeout.timer);
|
|
251
|
-
timeout.timer = null;
|
|
252
|
-
const spent = now - timeout.now;
|
|
253
|
-
timeout.duration = timeout.duration - spent - ms;
|
|
254
|
-
if (timeout.duration <= 0) timeout.callback();
|
|
255
|
-
else timeout.timer = setTimeout(() => {
|
|
256
|
-
timeout.callback();
|
|
257
|
-
}, timeout.duration);
|
|
258
|
-
}
|
|
259
|
-
for (const interval of this.intervals) {
|
|
260
|
-
if (!interval.timer) continue;
|
|
261
|
-
clearInterval(interval.timer);
|
|
262
|
-
interval.timer = null;
|
|
263
|
-
const repeat = Math.floor(ms / interval.duration);
|
|
264
|
-
for (let i = 0; i < repeat; i++) await interval.run();
|
|
265
|
-
}
|
|
266
|
-
await this.tick();
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* Stop the time.
|
|
270
|
-
*/
|
|
271
|
-
pause() {
|
|
272
|
-
this.ref = this.ref || this.now();
|
|
273
|
-
return this.ref;
|
|
274
|
-
}
|
|
275
|
-
/**
|
|
276
|
-
* Reset the reference date.
|
|
277
|
-
*/
|
|
278
|
-
reset() {
|
|
279
|
-
this.ref = null;
|
|
280
|
-
}
|
|
281
|
-
};
|
|
282
|
-
|
|
283
|
-
//#endregion
|
|
284
|
-
//#region src/datetime/descriptors/$interval.ts
|
|
285
|
-
/**
|
|
286
|
-
* Run a function periodically.
|
|
287
|
-
* It uses the `setInterval` internally.
|
|
288
|
-
* It starts by default when the context starts and stops when the context stops.
|
|
289
|
-
*/
|
|
290
|
-
const $interval = (options) => (0, alepha.createDescriptor)(IntervalDescriptor, options);
|
|
291
|
-
var IntervalDescriptor = class extends alepha.Descriptor {
|
|
292
|
-
dateTimeProvider = (0, alepha.$inject)(DateTimeProvider);
|
|
293
|
-
called = 0;
|
|
294
|
-
onInit() {
|
|
295
|
-
this.dateTimeProvider.createInterval(async () => {
|
|
296
|
-
await this.options.handler();
|
|
297
|
-
this.called += 1;
|
|
298
|
-
}, this.options.duration);
|
|
299
|
-
}
|
|
300
|
-
};
|
|
301
|
-
$interval[alepha.KIND] = IntervalDescriptor;
|
|
302
|
-
|
|
303
|
-
//#endregion
|
|
304
|
-
//#region src/datetime/index.ts
|
|
305
|
-
const AlephaDateTime = (0, alepha.$module)({
|
|
306
|
-
name: "alepha.datetime",
|
|
307
|
-
descriptors: [$interval],
|
|
308
|
-
services: [DateTimeProvider]
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
//#endregion
|
|
312
|
-
exports.$interval = $interval;
|
|
313
|
-
exports.AlephaDateTime = AlephaDateTime;
|
|
314
|
-
exports.DateTimeProvider = DateTimeProvider;
|
|
315
|
-
exports.IntervalDescriptor = IntervalDescriptor;
|
|
316
|
-
exports.dayjs = dayjs$1;
|
|
317
|
-
exports.isDateTime = isDateTime;
|
|
318
|
-
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["dayjs","DayjsApi","dayjsDuration","dayjsRelativeTime","dayjsUtc","dayjsTimezone","dayjsLocalizedFormat","Alepha","clearTimeout: any","callback: any","clearTimeout","interval: Interval","timeout: Timeout","Descriptor","KIND"],"sources":["../../src/datetime/providers/DateTimeProvider.ts","../../src/datetime/descriptors/$interval.ts","../../src/datetime/index.ts"],"sourcesContent":["import \"dayjs/plugin/relativeTime.js\";\nimport \"dayjs/plugin/duration.js\";\nimport \"dayjs/plugin/utc.js\";\nimport \"dayjs/plugin/timezone.js\";\nimport \"dayjs/plugin/localizedFormat.js\";\nimport \"dayjs/locale/ar.js\";\nimport \"dayjs/locale/fr.js\";\nimport { $hook, $inject, Alepha } from \"alepha\";\nimport DayjsApi, {\n type Dayjs,\n type ManipulateType,\n type PluginFunc,\n} from \"dayjs\";\nimport dayjsDuration from \"dayjs/plugin/duration.js\";\nimport dayjsLocalizedFormat from \"dayjs/plugin/localizedFormat.js\";\nimport dayjsRelativeTime from \"dayjs/plugin/relativeTime.js\";\nimport dayjsTimezone from \"dayjs/plugin/timezone.js\";\nimport dayjsUtc from \"dayjs/plugin/utc.js\";\n\nexport type DateTime = DayjsApi.Dayjs;\nexport type Duration = dayjsDuration.Duration;\nexport type DurationLike =\n | number\n | dayjsDuration.Duration\n | [number, ManipulateType];\n\nexport const dayjs = DayjsApi;\nexport const isDateTime = (value: unknown): value is DateTime => {\n return dayjs.isDayjs(value);\n};\n\nexport class DateTimeProvider {\n public static PLUGINS: Array<PluginFunc<any>> = [\n dayjsDuration,\n dayjsRelativeTime,\n dayjsUtc,\n dayjsTimezone,\n dayjsLocalizedFormat,\n ];\n\n protected alepha = $inject(Alepha);\n protected ref: DateTime | null = null;\n protected readonly timeouts: Timeout[] = [];\n protected readonly intervals: Interval[] = [];\n\n constructor() {\n for (const plugin of DateTimeProvider.PLUGINS) {\n dayjs.extend(plugin);\n }\n }\n\n protected readonly onStart = $hook({\n on: \"start\",\n handler: async () => {\n // we start intervals now but first tick will be rejected as App is not ready yet\n await Promise.all(\n this.intervals.map(async (interval) => {\n if (interval.timer != null) {\n return;\n }\n await interval.run();\n interval.timer = setInterval(interval.run, interval.duration);\n }),\n );\n },\n });\n\n protected readonly onStop = $hook({\n on: \"stop\",\n handler: () => {\n for (const timeout of this.timeouts) {\n this.clearTimeout(timeout);\n }\n\n for (const interval of this.intervals) {\n clearInterval(interval.timer);\n interval.duration = 0;\n interval.timer = null;\n }\n },\n });\n\n public setLocale(locale: string): void {\n dayjs.locale(locale);\n }\n\n public isDateTime(value: unknown): value is DateTime {\n return dayjs.isDayjs(value);\n }\n\n /**\n * Create a new UTC DateTime instance.\n */\n public utc(\n date: string | number | Date | Dayjs | null | undefined,\n ): DateTime {\n return dayjs.utc(date);\n }\n\n /**\n * Create a new DateTime instance.\n */\n public of(date: string | number | Date | Dayjs | null | undefined): DateTime {\n return dayjs(date);\n }\n\n /**\n * Get the current date as a string.\n */\n public toISOString(date: Date | string | DateTime = this.now()): string {\n return this.of(date).toISOString();\n }\n\n /**\n * Get the current date.\n */\n public now(): DateTime {\n return this.getCurrentDate();\n }\n\n /**\n * Get the current date as a string.\n *\n * This is much faster than `DateTimeProvider.now().toISOString()` as it avoids creating a DateTime instance.\n */\n public nowISOString(): string {\n if (this.ref) {\n return this.ref.toISOString();\n }\n return new Date().toISOString();\n }\n\n /**\n * Get the current date as milliseconds since epoch.\n *\n * This is much faster than `DateTimeProvider.now().valueOf()` as it avoids creating a DateTime instance.\n */\n public nowMillis(): number {\n if (this.ref) {\n return this.ref.valueOf();\n }\n return Date.now();\n }\n\n /**\n * Get the current date as a string.\n *\n * @protected\n */\n protected getCurrentDate(): DateTime {\n if (this.ref) {\n return this.ref;\n }\n\n return dayjs();\n }\n\n /**\n * Create a new Duration instance.\n */\n public duration = (\n duration: DurationLike,\n unit?: ManipulateType,\n ): Duration => {\n if (Array.isArray(duration)) {\n return dayjs.duration(duration[0], duration[1]);\n }\n\n if (typeof duration === \"number\") {\n return dayjs.duration(duration, unit || \"milliseconds\");\n }\n\n return duration;\n };\n\n public isDurationLike(value: unknown): value is DurationLike {\n return dayjs.isDuration(this.duration(value as DurationLike));\n }\n\n // -------------------------------------------------------------------------------------------------------------------\n\n // Timer Management\n\n /**\n * Return a promise that resolves after the next tick.\n * It uses `setTimeout` with 0 ms delay.\n */\n public async tick(): Promise<void> {\n await new Promise((resolve) => setTimeout(resolve, 0));\n }\n\n /**\n * Wait for a certain duration.\n *\n * You can clear the timeout by using the `AbortSignal` API.\n * Aborted signal will resolve the promise immediately, it does not reject it.\n */\n public wait(\n duration: DurationLike,\n options: {\n signal?: AbortSignal;\n now?: number;\n } = {},\n ): Promise<void> {\n return new Promise((resolve) => {\n let clearTimeout: any;\n let callback: any;\n\n const timeout = this.createTimeout(\n () => {\n if (options.signal && clearTimeout) {\n options.signal.removeEventListener(\"abort\", callback);\n }\n resolve();\n },\n duration,\n options.now,\n );\n\n if (options.signal) {\n clearTimeout = () => this.clearTimeout(timeout);\n callback = () => {\n clearTimeout();\n resolve();\n };\n options.signal.addEventListener(\"abort\", callback);\n }\n });\n }\n\n public createInterval(\n run: () => unknown,\n duration: DurationLike,\n start = false,\n ): Interval {\n const interval: Interval = {\n run,\n duration: this.duration(duration).asMilliseconds(),\n };\n\n this.intervals.push(interval);\n\n if (start) {\n interval.timer = setInterval(interval.run, interval.duration);\n }\n\n return interval;\n }\n\n /**\n * Run a callback after a certain duration.\n */\n public createTimeout(\n callback: () => void,\n duration: DurationLike,\n now?: number,\n ): Timeout {\n if (this.ref && now) {\n const next = this.of(now).add(this.duration(duration));\n if (next < this.now()) {\n callback();\n }\n return {\n now,\n duration: 0,\n callback: () => {},\n clear: () => {},\n };\n }\n\n const timeout: Timeout = {\n now: now ?? this.now().valueOf(),\n duration: this.duration(duration).asMilliseconds(),\n callback,\n clear: () => this.clearTimeout(timeout),\n };\n\n timeout.timer = setTimeout(() => {\n timeout.callback();\n }, timeout.duration);\n\n this.timeouts.push(timeout);\n\n return timeout;\n }\n\n public clearTimeout(timeout: Timeout): void {\n clearTimeout(timeout.timer);\n timeout.duration = 0;\n timeout.timer = null;\n }\n\n public clearInterval(interval: Interval): void {\n clearInterval(interval.timer);\n interval.duration = 0;\n interval.timer = null;\n }\n\n /**\n * Run a function with a deadline.\n */\n public async deadline<T>(\n fn: (signal: AbortSignal) => Promise<T>,\n duration: DurationLike,\n ): Promise<T> {\n const abort = new AbortController();\n const timeout = this.createTimeout(() => abort.abort(), duration);\n try {\n return await fn(abort.signal);\n } finally {\n this.clearTimeout(timeout);\n }\n }\n\n // -------------------------------------------------------------------------------------------------------------------\n\n // Testing\n\n /**\n * Add time to the current date.\n */\n public async travel(\n duration: DurationLike,\n unit?: ManipulateType,\n ): Promise<void> {\n this.ref = this.ref || this.now();\n this.ref = this.ref.add(this.duration(duration, unit));\n const ms = this.duration(duration, unit).asMilliseconds();\n const now = Date.now();\n\n for (const timeout of this.timeouts) {\n if (!timeout.timer) {\n continue;\n }\n\n clearTimeout(timeout.timer);\n timeout.timer = null;\n\n const spent = now - timeout.now;\n timeout.duration = timeout.duration - spent - ms;\n\n if (timeout.duration <= 0) {\n timeout.callback();\n } else {\n timeout.timer = setTimeout(() => {\n timeout.callback();\n }, timeout.duration);\n }\n }\n\n for (const interval of this.intervals) {\n if (!interval.timer) {\n continue;\n }\n\n clearInterval(interval.timer);\n interval.timer = null;\n\n const repeat = Math.floor(ms / interval.duration);\n for (let i = 0; i < repeat; i++) {\n await interval.run();\n }\n }\n\n await this.tick();\n }\n\n /**\n * Stop the time.\n */\n public pause(): DateTime {\n this.ref = this.ref || this.now();\n return this.ref;\n }\n\n /**\n * Reset the reference date.\n */\n public reset(): void {\n this.ref = null;\n }\n}\n\nexport interface Interval {\n timer?: any;\n duration: number;\n run: () => unknown;\n}\n\nexport interface Timeout {\n now: number;\n timer?: any;\n duration: number;\n callback: () => void;\n clear: () => void;\n}\n","import { $inject, createDescriptor, Descriptor, KIND } from \"alepha\";\nimport {\n DateTimeProvider,\n type DurationLike,\n} from \"../providers/DateTimeProvider.ts\";\n\n/**\n * Run a function periodically.\n * It uses the `setInterval` internally.\n * It starts by default when the context starts and stops when the context stops.\n */\nexport const $interval = (options: IntervalDescriptorOptions) =>\n createDescriptor(IntervalDescriptor, options);\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport interface IntervalDescriptorOptions {\n /**\n * The interval handler.\n */\n handler: () => unknown;\n\n /**\n * The interval duration.\n */\n duration: DurationLike;\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport class IntervalDescriptor extends Descriptor<IntervalDescriptorOptions> {\n protected readonly dateTimeProvider = $inject(DateTimeProvider);\n\n public called = 0;\n\n protected onInit() {\n this.dateTimeProvider.createInterval(async () => {\n await this.options.handler();\n this.called += 1;\n }, this.options.duration);\n }\n}\n\n$interval[KIND] = IntervalDescriptor;\n","import { $module } from \"alepha\";\nimport { $interval } from \"./descriptors/$interval.ts\";\nimport { DateTimeProvider } from \"./providers/DateTimeProvider.ts\";\n\nexport * from \"./descriptors/$interval.ts\";\nexport * from \"./providers/DateTimeProvider.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport const AlephaDateTime = $module({\n name: \"alepha.datetime\",\n descriptors: [$interval],\n services: [DateTimeProvider],\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,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W,QAAQ;AAE9C,OAAI,QAAQ,YAAY,EACtB,SAAQ,UAAU;OAElB,SAAQ,QAAQ,iBAAiB;AAC/B,YAAQ,UAAU;MACjB,QAAQ,SAAS;;AAIxB,OAAK,MAAM,YAAY,KAAK,WAAW;AACrC,OAAI,CAAC,SAAS,MACZ;AAGF,iBAAc,SAAS,MAAM;AAC7B,YAAS,QAAQ;GAEjB,MAAM,SAAS,KAAK,MAAM,KAAK,SAAS,SAAS;AACjD,QAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,IAC1B,OAAM,SAAS,KAAK;;AAIxB,QAAM,KAAK,MAAM;;;;;CAMnB,AAAO,QAAkB;AACvB,OAAK,MAAM,KAAK,OAAO,KAAK,KAAK;AACjC,SAAO,KAAK;;;;;CAMd,AAAO,QAAc;AACnB,OAAK,MAAM;;;;;;;;;;;AChXf,MAAa,aAAa,yCACP,oBAAoB,QAAQ;AAkB/C,IAAa,qBAAb,cAAwCC,kBAAsC;CAC5E,AAAmB,uCAA2B,iBAAiB;CAE/D,AAAO,SAAS;CAEhB,AAAU,SAAS;AACjB,OAAK,iBAAiB,eAAe,YAAY;AAC/C,SAAM,KAAK,QAAQ,SAAS;AAC5B,QAAK,UAAU;KACd,KAAK,QAAQ,SAAS;;;AAI7B,UAAUC,eAAQ;;;;AClClB,MAAa,qCAAyB;CACpC,MAAM;CACN,aAAa,CAAC,UAAU;CACxB,UAAU,CAAC,iBAAiB;CAC7B,CAAC"}
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import * as alepha1 from "alepha";
|
|
2
|
-
import { Alepha, Descriptor, KIND } from "alepha";
|
|
3
|
-
import dayjsDuration from "dayjs/plugin/duration.js";
|
|
4
|
-
import DayjsApi, { Dayjs, ManipulateType, PluginFunc } from "dayjs";
|
|
5
|
-
|
|
6
|
-
//#region src/datetime/providers/DateTimeProvider.d.ts
|
|
7
|
-
|
|
8
|
-
type DateTime = DayjsApi.Dayjs;
|
|
9
|
-
type Duration = dayjsDuration.Duration;
|
|
10
|
-
type DurationLike = number | dayjsDuration.Duration | [number, ManipulateType];
|
|
11
|
-
declare const dayjs: typeof DayjsApi;
|
|
12
|
-
declare const isDateTime: (value: unknown) => value is DateTime;
|
|
13
|
-
declare class DateTimeProvider {
|
|
14
|
-
static PLUGINS: Array<PluginFunc<any>>;
|
|
15
|
-
protected alepha: Alepha;
|
|
16
|
-
protected ref: DateTime | null;
|
|
17
|
-
protected readonly timeouts: Timeout[];
|
|
18
|
-
protected readonly intervals: Interval[];
|
|
19
|
-
constructor();
|
|
20
|
-
protected readonly onStart: alepha1.HookDescriptor<"start">;
|
|
21
|
-
protected readonly onStop: alepha1.HookDescriptor<"stop">;
|
|
22
|
-
setLocale(locale: string): void;
|
|
23
|
-
isDateTime(value: unknown): value is DateTime;
|
|
24
|
-
/**
|
|
25
|
-
* Create a new UTC DateTime instance.
|
|
26
|
-
*/
|
|
27
|
-
utc(date: string | number | Date | Dayjs | null | undefined): DateTime;
|
|
28
|
-
/**
|
|
29
|
-
* Create a new DateTime instance.
|
|
30
|
-
*/
|
|
31
|
-
of(date: string | number | Date | Dayjs | null | undefined): DateTime;
|
|
32
|
-
/**
|
|
33
|
-
* Get the current date as a string.
|
|
34
|
-
*/
|
|
35
|
-
toISOString(date?: Date | string | DateTime): string;
|
|
36
|
-
/**
|
|
37
|
-
* Get the current date.
|
|
38
|
-
*/
|
|
39
|
-
now(): DateTime;
|
|
40
|
-
/**
|
|
41
|
-
* Get the current date as a string.
|
|
42
|
-
*
|
|
43
|
-
* This is much faster than `DateTimeProvider.now().toISOString()` as it avoids creating a DateTime instance.
|
|
44
|
-
*/
|
|
45
|
-
nowISOString(): string;
|
|
46
|
-
/**
|
|
47
|
-
* Get the current date as milliseconds since epoch.
|
|
48
|
-
*
|
|
49
|
-
* This is much faster than `DateTimeProvider.now().valueOf()` as it avoids creating a DateTime instance.
|
|
50
|
-
*/
|
|
51
|
-
nowMillis(): number;
|
|
52
|
-
/**
|
|
53
|
-
* Get the current date as a string.
|
|
54
|
-
*
|
|
55
|
-
* @protected
|
|
56
|
-
*/
|
|
57
|
-
protected getCurrentDate(): DateTime;
|
|
58
|
-
/**
|
|
59
|
-
* Create a new Duration instance.
|
|
60
|
-
*/
|
|
61
|
-
duration: (duration: DurationLike, unit?: ManipulateType) => Duration;
|
|
62
|
-
isDurationLike(value: unknown): value is DurationLike;
|
|
63
|
-
/**
|
|
64
|
-
* Return a promise that resolves after the next tick.
|
|
65
|
-
* It uses `setTimeout` with 0 ms delay.
|
|
66
|
-
*/
|
|
67
|
-
tick(): Promise<void>;
|
|
68
|
-
/**
|
|
69
|
-
* Wait for a certain duration.
|
|
70
|
-
*
|
|
71
|
-
* You can clear the timeout by using the `AbortSignal` API.
|
|
72
|
-
* Aborted signal will resolve the promise immediately, it does not reject it.
|
|
73
|
-
*/
|
|
74
|
-
wait(duration: DurationLike, options?: {
|
|
75
|
-
signal?: AbortSignal;
|
|
76
|
-
now?: number;
|
|
77
|
-
}): Promise<void>;
|
|
78
|
-
createInterval(run: () => unknown, duration: DurationLike, start?: boolean): Interval;
|
|
79
|
-
/**
|
|
80
|
-
* Run a callback after a certain duration.
|
|
81
|
-
*/
|
|
82
|
-
createTimeout(callback: () => void, duration: DurationLike, now?: number): Timeout;
|
|
83
|
-
clearTimeout(timeout: Timeout): void;
|
|
84
|
-
clearInterval(interval: Interval): void;
|
|
85
|
-
/**
|
|
86
|
-
* Run a function with a deadline.
|
|
87
|
-
*/
|
|
88
|
-
deadline<T>(fn: (signal: AbortSignal) => Promise<T>, duration: DurationLike): Promise<T>;
|
|
89
|
-
/**
|
|
90
|
-
* Add time to the current date.
|
|
91
|
-
*/
|
|
92
|
-
travel(duration: DurationLike, unit?: ManipulateType): Promise<void>;
|
|
93
|
-
/**
|
|
94
|
-
* Stop the time.
|
|
95
|
-
*/
|
|
96
|
-
pause(): DateTime;
|
|
97
|
-
/**
|
|
98
|
-
* Reset the reference date.
|
|
99
|
-
*/
|
|
100
|
-
reset(): void;
|
|
101
|
-
}
|
|
102
|
-
interface Interval {
|
|
103
|
-
timer?: any;
|
|
104
|
-
duration: number;
|
|
105
|
-
run: () => unknown;
|
|
106
|
-
}
|
|
107
|
-
interface Timeout {
|
|
108
|
-
now: number;
|
|
109
|
-
timer?: any;
|
|
110
|
-
duration: number;
|
|
111
|
-
callback: () => void;
|
|
112
|
-
clear: () => void;
|
|
113
|
-
}
|
|
114
|
-
//#endregion
|
|
115
|
-
//#region src/datetime/descriptors/$interval.d.ts
|
|
116
|
-
/**
|
|
117
|
-
* Run a function periodically.
|
|
118
|
-
* It uses the `setInterval` internally.
|
|
119
|
-
* It starts by default when the context starts and stops when the context stops.
|
|
120
|
-
*/
|
|
121
|
-
declare const $interval: {
|
|
122
|
-
(options: IntervalDescriptorOptions): IntervalDescriptor;
|
|
123
|
-
[KIND]: typeof IntervalDescriptor;
|
|
124
|
-
};
|
|
125
|
-
interface IntervalDescriptorOptions {
|
|
126
|
-
/**
|
|
127
|
-
* The interval handler.
|
|
128
|
-
*/
|
|
129
|
-
handler: () => unknown;
|
|
130
|
-
/**
|
|
131
|
-
* The interval duration.
|
|
132
|
-
*/
|
|
133
|
-
duration: DurationLike;
|
|
134
|
-
}
|
|
135
|
-
declare class IntervalDescriptor extends Descriptor<IntervalDescriptorOptions> {
|
|
136
|
-
protected readonly dateTimeProvider: DateTimeProvider;
|
|
137
|
-
called: number;
|
|
138
|
-
protected onInit(): void;
|
|
139
|
-
}
|
|
140
|
-
//#endregion
|
|
141
|
-
//#region src/datetime/index.d.ts
|
|
142
|
-
declare const AlephaDateTime: alepha1.Service<alepha1.Module>;
|
|
143
|
-
//#endregion
|
|
144
|
-
export { $interval, AlephaDateTime, DateTime, DateTimeProvider, Duration, DurationLike, Interval, IntervalDescriptor, IntervalDescriptorOptions, Timeout, dayjs, isDateTime };
|
|
145
|
-
//# sourceMappingURL=index.d.cts.map
|