@tachybase/module-auth 0.23.8

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.
Files changed (95) hide show
  1. package/.turbo/turbo-build.log +14 -0
  2. package/README.md +117 -0
  3. package/client.d.ts +2 -0
  4. package/client.js +65 -0
  5. package/dist/client/AuthProvider.d.ts +2 -0
  6. package/dist/client/authenticator.d.ts +12 -0
  7. package/dist/client/basic/Options.d.ts +2 -0
  8. package/dist/client/basic/SignInForm.d.ts +9 -0
  9. package/dist/client/basic/SignUpForm.d.ts +13 -0
  10. package/dist/client/basic/index.d.ts +3 -0
  11. package/dist/client/bind/AuthenticatorBind.d.ts +2 -0
  12. package/dist/client/bind/BindForm.d.ts +5 -0
  13. package/dist/client/bind/schemas/authenticators.d.ts +2 -0
  14. package/dist/client/index.d.ts +30 -0
  15. package/dist/client/index.js +22 -0
  16. package/dist/client/locale/index.d.ts +2 -0
  17. package/dist/client/pages/AuthLayout.d.ts +2 -0
  18. package/dist/client/pages/SignInPage.d.ts +13 -0
  19. package/dist/client/pages/SignUpPage.d.ts +20 -0
  20. package/dist/client/pages/index.d.ts +3 -0
  21. package/dist/client/settings/Authenticator.d.ts +2 -0
  22. package/dist/client/settings/Options.d.ts +4 -0
  23. package/dist/client/settings/authType.d.ts +15 -0
  24. package/dist/client/settings/schemas/authenticators.d.ts +3 -0
  25. package/dist/externalVersion.js +16 -0
  26. package/dist/index.d.ts +1 -0
  27. package/dist/index.js +40 -0
  28. package/dist/locale/en-US.json +31 -0
  29. package/dist/locale/ko_KR.json +26 -0
  30. package/dist/locale/zh-CN.json +31 -0
  31. package/dist/node_modules/cron/LICENSE +8 -0
  32. package/dist/node_modules/cron/dist/constants.d.ts +74 -0
  33. package/dist/node_modules/cron/dist/constants.js +78 -0
  34. package/dist/node_modules/cron/dist/errors.d.ts +5 -0
  35. package/dist/node_modules/cron/dist/errors.js +13 -0
  36. package/dist/node_modules/cron/dist/index.d.ts +6 -0
  37. package/dist/node_modules/cron/dist/index.js +1 -0
  38. package/dist/node_modules/cron/dist/job.d.ts +30 -0
  39. package/dist/node_modules/cron/dist/job.js +222 -0
  40. package/dist/node_modules/cron/dist/time.d.ts +33 -0
  41. package/dist/node_modules/cron/dist/time.js +444 -0
  42. package/dist/node_modules/cron/dist/types/cron.types.d.ts +50 -0
  43. package/dist/node_modules/cron/dist/types/cron.types.js +3 -0
  44. package/dist/node_modules/cron/dist/types/utils.d.ts +3 -0
  45. package/dist/node_modules/cron/dist/types/utils.js +3 -0
  46. package/dist/node_modules/cron/dist/utils.d.ts +2 -0
  47. package/dist/node_modules/cron/dist/utils.js +8 -0
  48. package/dist/node_modules/cron/package.json +1 -0
  49. package/dist/preset.d.ts +3 -0
  50. package/dist/preset.js +34 -0
  51. package/dist/server/actions/auth.d.ts +8 -0
  52. package/dist/server/actions/auth.js +40 -0
  53. package/dist/server/actions/authenticators.d.ts +10 -0
  54. package/dist/server/actions/authenticators.js +153 -0
  55. package/dist/server/basic-auth.d.ts +10 -0
  56. package/dist/server/basic-auth.js +176 -0
  57. package/dist/server/collections/authenticators.d.ts +5 -0
  58. package/dist/server/collections/authenticators.js +117 -0
  59. package/dist/server/collections/token-blacklist.d.ts +2 -0
  60. package/dist/server/collections/token-blacklist.js +42 -0
  61. package/dist/server/collections/users-authenticators.d.ts +6 -0
  62. package/dist/server/collections/users-authenticators.js +85 -0
  63. package/dist/server/index.d.ts +3 -0
  64. package/dist/server/index.js +42 -0
  65. package/dist/server/locale/en-US.d.ts +9 -0
  66. package/dist/server/locale/en-US.js +30 -0
  67. package/dist/server/locale/fr-FR.d.ts +9 -0
  68. package/dist/server/locale/fr-FR.js +30 -0
  69. package/dist/server/locale/index.d.ts +3 -0
  70. package/dist/server/locale/index.js +43 -0
  71. package/dist/server/locale/ja-JP.d.ts +5 -0
  72. package/dist/server/locale/ja-JP.js +26 -0
  73. package/dist/server/locale/pt-BR.d.ts +9 -0
  74. package/dist/server/locale/pt-BR.js +30 -0
  75. package/dist/server/locale/zh-CN.d.ts +11 -0
  76. package/dist/server/locale/zh-CN.js +32 -0
  77. package/dist/server/migrations/20230506152253-basic-authenticator.d.ts +6 -0
  78. package/dist/server/migrations/20230506152253-basic-authenticator.js +44 -0
  79. package/dist/server/migrations/20230607174500-update-basic.d.ts +6 -0
  80. package/dist/server/migrations/20230607174500-update-basic.js +47 -0
  81. package/dist/server/migrations/20231218132032-fix-allow-signup.d.ts +6 -0
  82. package/dist/server/migrations/20231218132032-fix-allow-signup.js +55 -0
  83. package/dist/server/model/authenticator.d.ts +10 -0
  84. package/dist/server/model/authenticator.js +81 -0
  85. package/dist/server/plugin.d.ts +11 -0
  86. package/dist/server/plugin.js +132 -0
  87. package/dist/server/storer.d.ts +16 -0
  88. package/dist/server/storer.js +69 -0
  89. package/dist/server/token-blacklist.d.ts +17 -0
  90. package/dist/server/token-blacklist.js +86 -0
  91. package/dist/swagger/index.d.ts +754 -0
  92. package/dist/swagger/index.js +787 -0
  93. package/package.json +34 -0
  94. package/server.d.ts +2 -0
  95. package/server.js +65 -0
@@ -0,0 +1,222 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.CronJob = void 0;
13
+ const child_process_1 = require("child_process");
14
+ const errors_1 = require("./errors");
15
+ const time_1 = require("./time");
16
+ class CronJob {
17
+ get isCallbackRunning() {
18
+ return this._isCallbackRunning;
19
+ }
20
+ constructor(cronTime, onTick, onComplete, start, timeZone, context, runOnInit, utcOffset, unrefTimeout, waitForCompletion) {
21
+ this.running = false;
22
+ this.unrefTimeout = false;
23
+ this.lastExecution = null;
24
+ this.runOnce = false;
25
+ this.waitForCompletion = false;
26
+ this._isCallbackRunning = false;
27
+ this._callbacks = [];
28
+ this.context = (context !== null && context !== void 0 ? context : this);
29
+ this.waitForCompletion = Boolean(waitForCompletion);
30
+ if (timeZone != null && utcOffset != null) {
31
+ throw new errors_1.ExclusiveParametersError('timeZone', 'utcOffset');
32
+ }
33
+ if (timeZone != null) {
34
+ this.cronTime = new time_1.CronTime(cronTime, timeZone, null);
35
+ }
36
+ else if (utcOffset != null) {
37
+ this.cronTime = new time_1.CronTime(cronTime, null, utcOffset);
38
+ }
39
+ else {
40
+ this.cronTime = new time_1.CronTime(cronTime, timeZone, utcOffset);
41
+ }
42
+ if (unrefTimeout != null) {
43
+ this.unrefTimeout = unrefTimeout;
44
+ }
45
+ if (onComplete != null) {
46
+ this.onComplete = this._fnWrap(onComplete);
47
+ }
48
+ if (this.cronTime.realDate) {
49
+ this.runOnce = true;
50
+ }
51
+ this.addCallback(this._fnWrap(onTick));
52
+ if (runOnInit) {
53
+ this.lastExecution = new Date();
54
+ void this.fireOnTick();
55
+ }
56
+ if (start)
57
+ this.start();
58
+ }
59
+ static from(params) {
60
+ if (params.timeZone != null && params.utcOffset != null) {
61
+ throw new errors_1.ExclusiveParametersError('timeZone', 'utcOffset');
62
+ }
63
+ if (params.timeZone != null) {
64
+ return new CronJob(params.cronTime, params.onTick, params.onComplete, params.start, params.timeZone, params.context, params.runOnInit, params.utcOffset, params.unrefTimeout, params.waitForCompletion);
65
+ }
66
+ else if (params.utcOffset != null) {
67
+ return new CronJob(params.cronTime, params.onTick, params.onComplete, params.start, null, params.context, params.runOnInit, params.utcOffset, params.unrefTimeout, params.waitForCompletion);
68
+ }
69
+ else {
70
+ return new CronJob(params.cronTime, params.onTick, params.onComplete, params.start, params.timeZone, params.context, params.runOnInit, params.utcOffset, params.unrefTimeout, params.waitForCompletion);
71
+ }
72
+ }
73
+ _fnWrap(cmd) {
74
+ var _a, _b;
75
+ switch (typeof cmd) {
76
+ case 'function': {
77
+ return cmd;
78
+ }
79
+ case 'string': {
80
+ const [command, ...args] = cmd.split(' ');
81
+ return child_process_1.spawn.bind(undefined, command !== null && command !== void 0 ? command : cmd, args, {});
82
+ }
83
+ case 'object': {
84
+ return child_process_1.spawn.bind(undefined, cmd.command, (_a = cmd.args) !== null && _a !== void 0 ? _a : [], (_b = cmd.options) !== null && _b !== void 0 ? _b : {});
85
+ }
86
+ }
87
+ }
88
+ addCallback(callback) {
89
+ if (typeof callback === 'function') {
90
+ this._callbacks.push(callback);
91
+ }
92
+ }
93
+ setTime(time) {
94
+ if (!(time instanceof time_1.CronTime)) {
95
+ throw new errors_1.CronError('time must be an instance of CronTime.');
96
+ }
97
+ const wasRunning = this.running;
98
+ this.stop();
99
+ this.cronTime = time;
100
+ if (time.realDate)
101
+ this.runOnce = true;
102
+ if (wasRunning)
103
+ this.start();
104
+ }
105
+ nextDate() {
106
+ return this.cronTime.sendAt();
107
+ }
108
+ fireOnTick() {
109
+ return __awaiter(this, void 0, void 0, function* () {
110
+ if (this.waitForCompletion && this._isCallbackRunning)
111
+ return;
112
+ this._isCallbackRunning = true;
113
+ try {
114
+ for (const callback of this._callbacks) {
115
+ const result = callback.call(this.context, this.onComplete);
116
+ if (this.waitForCompletion)
117
+ yield result;
118
+ }
119
+ }
120
+ catch (error) {
121
+ console.error('[Cron] error in callback', error);
122
+ }
123
+ finally {
124
+ this._isCallbackRunning = false;
125
+ }
126
+ });
127
+ }
128
+ nextDates(i) {
129
+ return this.cronTime.sendAt(i !== null && i !== void 0 ? i : 0);
130
+ }
131
+ start() {
132
+ if (this.running)
133
+ return;
134
+ const MAXDELAY = 2147483647;
135
+ let timeout = this.cronTime.getTimeout();
136
+ let remaining = 0;
137
+ let startTime;
138
+ const setCronTimeout = (t) => {
139
+ startTime = Date.now();
140
+ this._timeout = setTimeout(callbackWrapper, t);
141
+ if (this.unrefTimeout && typeof this._timeout.unref === 'function') {
142
+ this._timeout.unref();
143
+ }
144
+ };
145
+ const callbackWrapper = () => {
146
+ const diff = startTime + timeout - Date.now();
147
+ if (diff > 0) {
148
+ let newTimeout = this.cronTime.getTimeout();
149
+ if (newTimeout > diff) {
150
+ newTimeout = diff;
151
+ }
152
+ remaining += newTimeout;
153
+ }
154
+ if (remaining) {
155
+ if (remaining > MAXDELAY) {
156
+ remaining -= MAXDELAY;
157
+ timeout = MAXDELAY;
158
+ }
159
+ else {
160
+ timeout = remaining;
161
+ remaining = 0;
162
+ }
163
+ setCronTimeout(timeout);
164
+ }
165
+ else {
166
+ this.lastExecution = new Date();
167
+ this.running = false;
168
+ if (!this.runOnce)
169
+ this.start();
170
+ void this.fireOnTick();
171
+ }
172
+ };
173
+ if (timeout >= 0) {
174
+ this.running = true;
175
+ if (timeout > MAXDELAY) {
176
+ remaining = timeout - MAXDELAY;
177
+ timeout = MAXDELAY;
178
+ }
179
+ setCronTimeout(timeout);
180
+ }
181
+ else {
182
+ this.stop();
183
+ }
184
+ }
185
+ lastDate() {
186
+ return this.lastExecution;
187
+ }
188
+ _executeOnComplete() {
189
+ return __awaiter(this, void 0, void 0, function* () {
190
+ if (typeof this.onComplete !== 'function')
191
+ return;
192
+ try {
193
+ yield this.onComplete.call(this.context);
194
+ }
195
+ catch (error) {
196
+ console.error('[Cron] error in onComplete callback:', error);
197
+ }
198
+ });
199
+ }
200
+ _waitForJobCompletion() {
201
+ return __awaiter(this, void 0, void 0, function* () {
202
+ while (this._isCallbackRunning) {
203
+ yield new Promise(resolve => setTimeout(resolve, 100));
204
+ }
205
+ });
206
+ }
207
+ stop() {
208
+ if (this._timeout)
209
+ clearTimeout(this._timeout);
210
+ this.running = false;
211
+ if (!this.waitForCompletion) {
212
+ void this._executeOnComplete();
213
+ return;
214
+ }
215
+ void Promise.resolve().then(() => __awaiter(this, void 0, void 0, function* () {
216
+ yield this._waitForJobCompletion();
217
+ yield this._executeOnComplete();
218
+ }));
219
+ }
220
+ }
221
+ exports.CronJob = CronJob;
222
+ //# sourceMappingURL=job.js.map
@@ -0,0 +1,33 @@
1
+ import { DateTime, Zone } from 'luxon';
2
+ import { CronJobParams } from './types/cron.types';
3
+ export declare class CronTime {
4
+ source: string | DateTime;
5
+ timeZone?: string;
6
+ utcOffset?: number;
7
+ realDate: boolean;
8
+ private second;
9
+ private minute;
10
+ private hour;
11
+ private dayOfMonth;
12
+ private month;
13
+ private dayOfWeek;
14
+ constructor(source: CronJobParams['cronTime'], timeZone?: CronJobParams['timeZone'], utcOffset?: null);
15
+ constructor(source: CronJobParams['cronTime'], timeZone?: null, utcOffset?: CronJobParams['utcOffset']);
16
+ private _getWeekDay;
17
+ private _verifyParse;
18
+ sendAt(): DateTime;
19
+ sendAt(i: number): DateTime[];
20
+ getTimeout(): number;
21
+ toString(): string;
22
+ toJSON(): string[];
23
+ getNextDateFrom(start: Date | DateTime, timeZone?: string | Zone): DateTime<boolean>;
24
+ private _findPreviousDSTJump;
25
+ private _checkTimeInSkippedRange;
26
+ private _checkTimeInSkippedRangeSingleHour;
27
+ private _checkTimeInSkippedRangeMultiHour;
28
+ private _forwardDSTJump;
29
+ private _wcOrAll;
30
+ private _hasAll;
31
+ private _parse;
32
+ private _parseField;
33
+ }
@@ -0,0 +1,444 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CronTime = void 0;
4
+ const luxon_1 = require("luxon");
5
+ const constants_1 = require("./constants");
6
+ const errors_1 = require("./errors");
7
+ const utils_1 = require("./utils");
8
+ class CronTime {
9
+ constructor(source, timeZone, utcOffset) {
10
+ this.realDate = false;
11
+ this.second = {};
12
+ this.minute = {};
13
+ this.hour = {};
14
+ this.dayOfMonth = {};
15
+ this.month = {};
16
+ this.dayOfWeek = {};
17
+ if (timeZone != null && utcOffset != null) {
18
+ throw new errors_1.ExclusiveParametersError('timeZone', 'utcOffset');
19
+ }
20
+ if (timeZone) {
21
+ const dt = luxon_1.DateTime.fromObject({}, { zone: timeZone });
22
+ if (!dt.isValid) {
23
+ throw new errors_1.CronError('Invalid timezone.');
24
+ }
25
+ this.timeZone = timeZone;
26
+ }
27
+ if (utcOffset != null) {
28
+ this.utcOffset = utcOffset;
29
+ }
30
+ if (source instanceof Date || source instanceof luxon_1.DateTime) {
31
+ this.source =
32
+ source instanceof Date ? luxon_1.DateTime.fromJSDate(source) : source;
33
+ this.realDate = true;
34
+ }
35
+ else {
36
+ this.source = source;
37
+ this._parse(this.source);
38
+ this._verifyParse();
39
+ }
40
+ }
41
+ _getWeekDay(date) {
42
+ return date.weekday === 7 ? 0 : date.weekday;
43
+ }
44
+ _verifyParse() {
45
+ const months = (0, utils_1.getRecordKeys)(this.month);
46
+ const daysOfMonth = (0, utils_1.getRecordKeys)(this.dayOfMonth);
47
+ let isOk = false;
48
+ let lastWrongMonth = null;
49
+ for (const m of months) {
50
+ const con = constants_1.MONTH_CONSTRAINTS[m];
51
+ for (const day of daysOfMonth) {
52
+ if (day <= con) {
53
+ isOk = true;
54
+ }
55
+ }
56
+ if (!isOk) {
57
+ lastWrongMonth = m;
58
+ console.warn(`Month '${m}' is limited to '${con}' days.`);
59
+ }
60
+ }
61
+ if (!isOk && lastWrongMonth !== null) {
62
+ const notOkCon = constants_1.MONTH_CONSTRAINTS[lastWrongMonth];
63
+ for (const notOkDay of daysOfMonth) {
64
+ if (notOkDay > notOkCon) {
65
+ delete this.dayOfMonth[notOkDay];
66
+ const fixedDay = (notOkDay % notOkCon);
67
+ this.dayOfMonth[fixedDay] = true;
68
+ }
69
+ }
70
+ }
71
+ }
72
+ sendAt(i) {
73
+ let date = this.realDate && this.source instanceof luxon_1.DateTime
74
+ ? this.source
75
+ : luxon_1.DateTime.local();
76
+ if (this.timeZone) {
77
+ date = date.setZone(this.timeZone);
78
+ }
79
+ if (this.utcOffset !== undefined) {
80
+ const sign = this.utcOffset < 0 ? '-' : '+';
81
+ const offsetHours = Math.trunc(this.utcOffset / 60);
82
+ const offsetHoursStr = String(Math.abs(offsetHours)).padStart(2, '0');
83
+ const offsetMins = Math.abs(this.utcOffset - offsetHours * 60);
84
+ const offsetMinsStr = String(offsetMins).padStart(2, '0');
85
+ const utcZone = `UTC${sign}${offsetHoursStr}:${offsetMinsStr}`;
86
+ date = date.setZone(utcZone);
87
+ if (!date.isValid) {
88
+ throw new errors_1.CronError('ERROR: You specified an invalid UTC offset.');
89
+ }
90
+ }
91
+ if (this.realDate) {
92
+ if (luxon_1.DateTime.local() > date) {
93
+ throw new errors_1.CronError('WARNING: Date in past. Will never be fired.');
94
+ }
95
+ return date;
96
+ }
97
+ if (i === undefined || isNaN(i) || i < 0) {
98
+ return this.getNextDateFrom(date);
99
+ }
100
+ else {
101
+ const dates = [];
102
+ for (; i > 0; i--) {
103
+ date = this.getNextDateFrom(date);
104
+ dates.push(date);
105
+ }
106
+ return dates;
107
+ }
108
+ }
109
+ getTimeout() {
110
+ return Math.max(-1, this.sendAt().toMillis() - luxon_1.DateTime.local().toMillis());
111
+ }
112
+ toString() {
113
+ return this.toJSON().join(' ');
114
+ }
115
+ toJSON() {
116
+ return constants_1.TIME_UNITS.map(unit => {
117
+ return this._wcOrAll(unit);
118
+ });
119
+ }
120
+ getNextDateFrom(start, timeZone) {
121
+ var _a;
122
+ if (start instanceof Date) {
123
+ start = luxon_1.DateTime.fromJSDate(start);
124
+ }
125
+ let date = start;
126
+ const firstDate = start.toMillis();
127
+ if (timeZone) {
128
+ date = date.setZone(timeZone);
129
+ }
130
+ if (!this.realDate) {
131
+ if (date.millisecond > 0) {
132
+ date = date.set({ millisecond: 0, second: date.second + 1 });
133
+ }
134
+ }
135
+ if (!date.isValid) {
136
+ throw new errors_1.CronError('ERROR: You specified an invalid date.');
137
+ }
138
+ const maxMatch = luxon_1.DateTime.now().plus({ years: 8 });
139
+ while (true) {
140
+ const diff = date.toMillis() - start.toMillis();
141
+ if (date > maxMatch) {
142
+ throw new errors_1.CronError(`Something went wrong. No execution date was found in the next 8 years.
143
+ Please provide the following string if you would like to help debug:
144
+ Time Zone: ${(_a = timeZone === null || timeZone === void 0 ? void 0 : timeZone.toString()) !== null && _a !== void 0 ? _a : '""'} - Cron String: ${this.source.toString()} - UTC offset: ${date.offset} - current Date: ${luxon_1.DateTime.local().toString()}`);
145
+ }
146
+ if (!(date.month in this.month) &&
147
+ Object.keys(this.month).length !== 12) {
148
+ date = date.plus({ months: 1 });
149
+ date = date.set({ day: 1, hour: 0, minute: 0, second: 0 });
150
+ if (this._forwardDSTJump(0, 0, date)) {
151
+ const [isDone, newDate] = this._findPreviousDSTJump(date);
152
+ date = newDate;
153
+ if (isDone)
154
+ break;
155
+ }
156
+ continue;
157
+ }
158
+ if (!(date.day in this.dayOfMonth) &&
159
+ Object.keys(this.dayOfMonth).length !== 31 &&
160
+ !(this._getWeekDay(date) in this.dayOfWeek &&
161
+ Object.keys(this.dayOfWeek).length !== 7)) {
162
+ date = date.plus({ days: 1 });
163
+ date = date.set({ hour: 0, minute: 0, second: 0 });
164
+ if (this._forwardDSTJump(0, 0, date)) {
165
+ const [isDone, newDate] = this._findPreviousDSTJump(date);
166
+ date = newDate;
167
+ if (isDone)
168
+ break;
169
+ }
170
+ continue;
171
+ }
172
+ if (!(this._getWeekDay(date) in this.dayOfWeek) &&
173
+ Object.keys(this.dayOfWeek).length !== 7 &&
174
+ !(date.day in this.dayOfMonth &&
175
+ Object.keys(this.dayOfMonth).length !== 31)) {
176
+ date = date.plus({ days: 1 });
177
+ date = date.set({ hour: 0, minute: 0, second: 0 });
178
+ if (this._forwardDSTJump(0, 0, date)) {
179
+ const [isDone, newDate] = this._findPreviousDSTJump(date);
180
+ date = newDate;
181
+ if (isDone)
182
+ break;
183
+ }
184
+ continue;
185
+ }
186
+ if (!(date.hour in this.hour) && Object.keys(this.hour).length !== 24) {
187
+ const expectedHour = date.hour === 23 && diff > 86400000 ? 0 : date.hour + 1;
188
+ const expectedMinute = date.minute;
189
+ date = date.set({ hour: expectedHour });
190
+ date = date.set({ minute: 0, second: 0 });
191
+ if (this._forwardDSTJump(expectedHour, expectedMinute, date)) {
192
+ const [isDone, newDate] = this._findPreviousDSTJump(date);
193
+ date = newDate;
194
+ if (isDone)
195
+ break;
196
+ }
197
+ continue;
198
+ }
199
+ if (!(date.minute in this.minute) &&
200
+ Object.keys(this.minute).length !== 60) {
201
+ const expectedMinute = date.minute === 59 && diff > 3600000 ? 0 : date.minute + 1;
202
+ const expectedHour = date.hour + (expectedMinute === 60 ? 1 : 0);
203
+ date = date.set({ minute: expectedMinute });
204
+ date = date.set({ second: 0 });
205
+ if (this._forwardDSTJump(expectedHour, expectedMinute, date)) {
206
+ const [isDone, newDate] = this._findPreviousDSTJump(date);
207
+ date = newDate;
208
+ if (isDone)
209
+ break;
210
+ }
211
+ continue;
212
+ }
213
+ if (!(date.second in this.second) &&
214
+ Object.keys(this.second).length !== 60) {
215
+ const expectedSecond = date.second === 59 && diff > 60000 ? 0 : date.second + 1;
216
+ const expectedMinute = date.minute + (expectedSecond === 60 ? 1 : 0);
217
+ const expectedHour = date.hour + (expectedMinute === 60 ? 1 : 0);
218
+ date = date.set({ second: expectedSecond });
219
+ if (this._forwardDSTJump(expectedHour, expectedMinute, date)) {
220
+ const [isDone, newDate] = this._findPreviousDSTJump(date);
221
+ date = newDate;
222
+ if (isDone)
223
+ break;
224
+ }
225
+ continue;
226
+ }
227
+ if (date.toMillis() === firstDate) {
228
+ const expectedSecond = date.second + 1;
229
+ const expectedMinute = date.minute + (expectedSecond === 60 ? 1 : 0);
230
+ const expectedHour = date.hour + (expectedMinute === 60 ? 1 : 0);
231
+ date = date.set({ second: expectedSecond });
232
+ if (this._forwardDSTJump(expectedHour, expectedMinute, date)) {
233
+ const [isDone, newDate] = this._findPreviousDSTJump(date);
234
+ date = newDate;
235
+ if (isDone)
236
+ break;
237
+ }
238
+ continue;
239
+ }
240
+ break;
241
+ }
242
+ return date;
243
+ }
244
+ _findPreviousDSTJump(date) {
245
+ var _a;
246
+ let expectedMinute, expectedHour, actualMinute, actualHour;
247
+ let maybeJumpingPoint = date;
248
+ const iterationLimit = 60 * 24;
249
+ let iteration = 0;
250
+ do {
251
+ if (++iteration > iterationLimit) {
252
+ throw new errors_1.CronError(`ERROR: This DST checking related function assumes the input DateTime (${(_a = date.toISO()) !== null && _a !== void 0 ? _a : date.toMillis()}) is within 24 hours of a DST jump.`);
253
+ }
254
+ expectedMinute = maybeJumpingPoint.minute - 1;
255
+ expectedHour = maybeJumpingPoint.hour;
256
+ if (expectedMinute < 0) {
257
+ expectedMinute += 60;
258
+ expectedHour = (expectedHour + 24 - 1) % 24;
259
+ }
260
+ maybeJumpingPoint = maybeJumpingPoint.minus({ minute: 1 });
261
+ actualMinute = maybeJumpingPoint.minute;
262
+ actualHour = maybeJumpingPoint.hour;
263
+ } while (expectedMinute === actualMinute && expectedHour === actualHour);
264
+ const afterJumpingPoint = maybeJumpingPoint
265
+ .plus({ minute: 1 })
266
+ .set({ second: 0, millisecond: 0 });
267
+ const beforeJumpingPoint = afterJumpingPoint.minus({ second: 1 });
268
+ if (date.month + 1 in this.month &&
269
+ date.day in this.dayOfMonth &&
270
+ this._getWeekDay(date) in this.dayOfWeek) {
271
+ return [
272
+ this._checkTimeInSkippedRange(beforeJumpingPoint, afterJumpingPoint),
273
+ afterJumpingPoint
274
+ ];
275
+ }
276
+ return [false, afterJumpingPoint];
277
+ }
278
+ _checkTimeInSkippedRange(beforeJumpingPoint, afterJumpingPoint) {
279
+ const startingMinute = (beforeJumpingPoint.minute + 1) % 60;
280
+ const startingHour = (beforeJumpingPoint.hour + (startingMinute === 0 ? 1 : 0)) % 24;
281
+ const hourRangeSize = afterJumpingPoint.hour - startingHour + 1;
282
+ const isHourJump = startingMinute === 0 && afterJumpingPoint.minute === 0;
283
+ if (hourRangeSize === 2 && isHourJump) {
284
+ return startingHour in this.hour;
285
+ }
286
+ else if (hourRangeSize === 1) {
287
+ return (startingHour in this.hour &&
288
+ this._checkTimeInSkippedRangeSingleHour(startingMinute, afterJumpingPoint.minute));
289
+ }
290
+ else {
291
+ return this._checkTimeInSkippedRangeMultiHour(startingHour, startingMinute, afterJumpingPoint.hour, afterJumpingPoint.minute);
292
+ }
293
+ }
294
+ _checkTimeInSkippedRangeSingleHour(startMinute, endMinute) {
295
+ for (let minute = startMinute; minute < endMinute; ++minute) {
296
+ if (minute in this.minute)
297
+ return true;
298
+ }
299
+ return endMinute in this.minute && 0 in this.second;
300
+ }
301
+ _checkTimeInSkippedRangeMultiHour(startHour, startMinute, endHour, endMinute) {
302
+ if (startHour >= endHour) {
303
+ throw new errors_1.CronError(`ERROR: This DST checking related function assumes the forward jump starting hour (${startHour}) is less than the end hour (${endHour})`);
304
+ }
305
+ const firstHourMinuteRange = Array.from({ length: 60 - startMinute }, (_, k) => startMinute + k);
306
+ const lastHourMinuteRange = Array.from({ length: endMinute }, (_, k) => k);
307
+ const middleHourMinuteRange = Array.from({ length: 60 }, (_, k) => k);
308
+ const selectRange = (forHour) => {
309
+ if (forHour === startHour) {
310
+ return firstHourMinuteRange;
311
+ }
312
+ else if (forHour === endHour) {
313
+ return lastHourMinuteRange;
314
+ }
315
+ else {
316
+ return middleHourMinuteRange;
317
+ }
318
+ };
319
+ for (let hour = startHour; hour <= endHour; ++hour) {
320
+ if (!(hour in this.hour))
321
+ continue;
322
+ const usingRange = selectRange(hour);
323
+ for (const minute of usingRange) {
324
+ if (minute in this.minute)
325
+ return true;
326
+ }
327
+ }
328
+ return endHour in this.hour && endMinute in this.minute && 0 in this.second;
329
+ }
330
+ _forwardDSTJump(expectedHour, expectedMinute, actualDate) {
331
+ const actualHour = actualDate.hour;
332
+ const actualMinute = actualDate.minute;
333
+ const didHoursJumped = expectedHour % 24 < actualHour;
334
+ const didMinutesJumped = expectedMinute % 60 < actualMinute;
335
+ return didHoursJumped || didMinutesJumped;
336
+ }
337
+ _wcOrAll(unit) {
338
+ if (this._hasAll(unit)) {
339
+ return '*';
340
+ }
341
+ const all = [];
342
+ for (const time in this[unit]) {
343
+ all.push(time);
344
+ }
345
+ return all.join(',');
346
+ }
347
+ _hasAll(unit) {
348
+ const constraints = constants_1.CONSTRAINTS[unit];
349
+ const low = constraints[0];
350
+ const high = unit === constants_1.TIME_UNITS_MAP.DAY_OF_WEEK ? constraints[1] - 1 : constraints[1];
351
+ for (let i = low, n = high; i < n; i++) {
352
+ if (!(i in this[unit])) {
353
+ return false;
354
+ }
355
+ }
356
+ return true;
357
+ }
358
+ _parse(source) {
359
+ var _a;
360
+ source = source.toLowerCase();
361
+ if (Object.keys(constants_1.PRESETS).includes(source)) {
362
+ source = constants_1.PRESETS[source];
363
+ }
364
+ source = source.replace(/[a-z]{1,3}/gi, (alias) => {
365
+ if (Object.keys(constants_1.ALIASES).includes(alias)) {
366
+ return constants_1.ALIASES[alias].toString();
367
+ }
368
+ throw new errors_1.CronError(`Unknown alias: ${alias}`);
369
+ });
370
+ const units = source.trim().split(/\s+/);
371
+ if (units.length < constants_1.TIME_UNITS_LEN - 1) {
372
+ throw new errors_1.CronError('Too few fields');
373
+ }
374
+ if (units.length > constants_1.TIME_UNITS_LEN) {
375
+ throw new errors_1.CronError('Too many fields');
376
+ }
377
+ const unitsLen = units.length;
378
+ for (const unit of constants_1.TIME_UNITS) {
379
+ const i = constants_1.TIME_UNITS.indexOf(unit);
380
+ const cur = (_a = units[i - (constants_1.TIME_UNITS_LEN - unitsLen)]) !== null && _a !== void 0 ? _a : constants_1.PARSE_DEFAULTS[unit];
381
+ this._parseField(cur, unit);
382
+ }
383
+ }
384
+ _parseField(value, unit) {
385
+ const typeObj = this[unit];
386
+ let pointer;
387
+ const constraints = constants_1.CONSTRAINTS[unit];
388
+ const low = constraints[0];
389
+ const high = constraints[1];
390
+ const fields = value.split(',');
391
+ fields.forEach(field => {
392
+ const wildcardIndex = field.indexOf('*');
393
+ if (wildcardIndex !== -1 && wildcardIndex !== 0) {
394
+ throw new errors_1.CronError(`Field (${field}) has an invalid wildcard expression`);
395
+ }
396
+ });
397
+ value = value.replace(constants_1.RE_WILDCARDS, `${low}-${high}`);
398
+ const allRanges = value.split(',');
399
+ for (const range of allRanges) {
400
+ const match = [...range.matchAll(constants_1.RE_RANGE)][0];
401
+ if ((match === null || match === void 0 ? void 0 : match[1]) !== undefined) {
402
+ const [, mLower, mUpper, mStep] = match;
403
+ let lower = parseInt(mLower, 10);
404
+ let upper = mUpper !== undefined ? parseInt(mUpper, 10) : undefined;
405
+ const wasStepDefined = mStep !== undefined;
406
+ const step = parseInt(mStep !== null && mStep !== void 0 ? mStep : '1', 10);
407
+ if (step === 0) {
408
+ throw new errors_1.CronError(`Field (${unit}) has a step of zero`);
409
+ }
410
+ if (upper !== undefined && lower > upper) {
411
+ throw new errors_1.CronError(`Field (${unit}) has an invalid range`);
412
+ }
413
+ const isOutOfRange = lower < low ||
414
+ (upper !== undefined && upper > high) ||
415
+ (upper === undefined && lower > high);
416
+ if (isOutOfRange) {
417
+ throw new errors_1.CronError(`Field value (${value}) is out of range`);
418
+ }
419
+ lower = Math.min(Math.max(low, ~~Math.abs(lower)), high);
420
+ if (upper !== undefined) {
421
+ upper = Math.min(high, ~~Math.abs(upper));
422
+ }
423
+ else {
424
+ upper = wasStepDefined ? high : lower;
425
+ }
426
+ pointer = lower;
427
+ do {
428
+ typeObj[pointer] = true;
429
+ pointer += step;
430
+ } while (pointer <= upper);
431
+ if (unit === 'dayOfWeek') {
432
+ if (!typeObj[0] && !!typeObj[7])
433
+ typeObj[0] = typeObj[7];
434
+ delete typeObj[7];
435
+ }
436
+ }
437
+ else {
438
+ throw new errors_1.CronError(`Field (${unit}) cannot be parsed`);
439
+ }
440
+ }
441
+ }
442
+ }
443
+ exports.CronTime = CronTime;
444
+ //# sourceMappingURL=time.js.map