@openinc/parse-server-opendash 4.7.0 → 4.8.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/features/schema/helper/migrationMode.js +2 -0
- package/dist/hooks/Service_Schedule.js +7 -0
- package/dist/hooks/Service_Schedule_Execution.js +10 -4
- package/dist/hooks/Service_Schedule_Template.js +5 -0
- package/dist/scripts/migration/lib/cadence.d.ts +75 -0
- package/dist/scripts/migration/lib/cadence.js +246 -0
- package/dist/scripts/migration/lib/env.d.ts +5 -0
- package/dist/scripts/migration/lib/env.js +23 -0
- package/dist/scripts/migration/lib/schedule.d.ts +306 -0
- package/dist/scripts/migration/lib/schedule.js +613 -0
- package/dist/scripts/migration/passes/03-equipment.js +11 -4
- package/dist/scripts/migration/passes/13-schedule-templates.d.ts +15 -0
- package/dist/scripts/migration/passes/13-schedule-templates.js +163 -0
- package/dist/scripts/migration/passes/14-schedules.d.ts +30 -0
- package/dist/scripts/migration/passes/14-schedules.js +239 -0
- package/dist/scripts/migration/passes/15-executions.d.ts +34 -0
- package/dist/scripts/migration/passes/15-executions.js +244 -0
- package/dist/scripts/migration/passes/16-schedule-meta.d.ts +23 -0
- package/dist/scripts/migration/passes/16-schedule-meta.js +308 -0
- package/dist/scripts/migration/passes/17-schedule-assets.d.ts +30 -0
- package/dist/scripts/migration/passes/17-schedule-assets.js +240 -0
- package/dist/scripts/migration/passes/18-calendar-links.d.ts +25 -0
- package/dist/scripts/migration/passes/18-calendar-links.js +132 -0
- package/dist/scripts/migration/passes/19-schedule-history.d.ts +18 -0
- package/dist/scripts/migration/passes/19-schedule-history.js +186 -0
- package/dist/scripts/migration/run.js +20 -9
- package/dist/scripts/migration/verify.js +294 -11
- package/dist/scripts/seed-v1-testdata.d.ts +2 -0
- package/dist/scripts/seed-v1-testdata.js +392 -6
- package/dist/types/Service_Schedule.d.ts +3 -0
- package/dist/types/Service_Schedule.js +6 -0
- package/dist/types/Service_Schedule_Execution.d.ts +1 -1
- package/package.json +1 -1
- package/schema/Service_Schedule.json +4 -0
|
@@ -39,6 +39,8 @@ function isMigrationMode() {
|
|
|
39
39
|
" defaults are applied — the writer must set them itself)",
|
|
40
40
|
" · assignment / watcher notifications are suppressed",
|
|
41
41
|
" · tag closure reconciliation is suppressed",
|
|
42
|
+
" · maintenance plan / template ACL sync and the Outlook push are",
|
|
43
|
+
" suppressed",
|
|
42
44
|
" This must NOT be set during normal operation.",
|
|
43
45
|
"!".repeat(80),
|
|
44
46
|
"",
|
|
@@ -35,6 +35,13 @@ async function init() {
|
|
|
35
35
|
});
|
|
36
36
|
(0, index_js_1.afterSaveHook)(index_js_4.Service_Schedule, async (request) => {
|
|
37
37
|
const { object, original, context } = request;
|
|
38
|
+
// The v1 → v2 migration writes the ACL this hook would derive itself, and
|
|
39
|
+
// must not reach Outlook: every migrated plan would be pushed as a *new*
|
|
40
|
+
// event before its v1 event link is carried over, doubling the customer's
|
|
41
|
+
// calendar. The ACL sync would also re-save the plan under the master key
|
|
42
|
+
// without `skipChangelog`. See helper/migrationMode.ts.
|
|
43
|
+
if ((0, index_js_1.isMigrationMode)())
|
|
44
|
+
return;
|
|
38
45
|
// Our own ACL write — the assignments already match, nothing to redo.
|
|
39
46
|
if (context?.[assignmentAcl_js_1.ASSIGNMENT_ACL_CONTEXT_FLAG])
|
|
40
47
|
return;
|
|
@@ -62,11 +62,17 @@ async function init() {
|
|
|
62
62
|
// gates the button in the UI now gates the write as well. Until this,
|
|
63
63
|
// `can-perform-execution` only hid a button: anyone who could reach the
|
|
64
64
|
// Parse class could sign a protocol.
|
|
65
|
+
//
|
|
66
|
+
// Takes the session token from `request`, not from `request.user`, and that
|
|
67
|
+
// is not a style choice: `defaultHandler` above does
|
|
68
|
+
// `request.user.fetch({ useMasterKey: true })`, which refetches the *same*
|
|
69
|
+
// `Parse.User` instance in place. `_User` has no `sessionToken` column — it
|
|
70
|
+
// lives in `_Session` — so the fetch leaves the object without one, and
|
|
71
|
+
// every later `user.getSessionToken()` returns undefined. `beforeSaveHook`
|
|
72
|
+
// captures the token at trigger entry, before any of this runs, which is
|
|
73
|
+
// why every other call site passes `request` and works.
|
|
65
74
|
if (object.isNew()) {
|
|
66
|
-
await (0, index_js_2.requirePermission)(
|
|
67
|
-
sessionToken: user?.getSessionToken(),
|
|
68
|
-
master: request.master,
|
|
69
|
-
}, Permissions_js_1.Permissions.SERVICE.execution_perform, "perform a maintenance execution");
|
|
75
|
+
await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.execution_perform, "perform a maintenance execution");
|
|
70
76
|
}
|
|
71
77
|
// Who performed it is established by the server from the session, not
|
|
72
78
|
// accepted from the client. A protocol that names somebody else is worth
|
|
@@ -23,6 +23,11 @@ async function init() {
|
|
|
23
23
|
});
|
|
24
24
|
(0, index_js_1.afterSaveHook)(index_js_2.Service_Schedule_Template, async (request) => {
|
|
25
25
|
const { object, context } = request;
|
|
26
|
+
// The v1 → v2 migration writes the ACL this hook would derive itself; the
|
|
27
|
+
// sync would re-save the template under the master key without
|
|
28
|
+
// `skipChangelog`. See helper/migrationMode.ts.
|
|
29
|
+
if ((0, index_js_1.isMigrationMode)())
|
|
30
|
+
return;
|
|
26
31
|
// Our own ACL write — the assignments already match.
|
|
27
32
|
if (context?.[assignmentAcl_js_1.ASSIGNMENT_ACL_CONTEXT_FLAG])
|
|
28
33
|
return;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v1 schedule timing (`cron`) → v2 cadence (`OD3_Service_Schedule.cadence`).
|
|
3
|
+
*
|
|
4
|
+
* v1 stores `{ schedule_type: "timestamp", timestamp: { startDate, endDate,
|
|
5
|
+
* number, unit, onlyWeeks } }` and computes occurrences with dayjs as
|
|
6
|
+
* `startDate + k·number unit` (`ScheduleIterator` in `@opendash/schedule`). v2
|
|
7
|
+
* stores an RFC 5545 rule. This is a format translation — no occurrence is
|
|
8
|
+
* computed here.
|
|
9
|
+
*
|
|
10
|
+
* Why a translation lives here and not in `@opendash/schedule`, where schedule
|
|
11
|
+
* maths belongs: that package ships ESM only, and this server compiles to
|
|
12
|
+
* CommonJS, so it cannot import it. The equivalence of the two is proven
|
|
13
|
+
* against the real package instead — see the README, "Schedules".
|
|
14
|
+
*/
|
|
15
|
+
/** A v2 cadence, as far as the migration writes one. */
|
|
16
|
+
export type MigratedCadence = {
|
|
17
|
+
kind: "rrule";
|
|
18
|
+
/** Bare rule, no `RRULE:` prefix — the plan editor cannot read one. */
|
|
19
|
+
rrule: string;
|
|
20
|
+
dtstart: string;
|
|
21
|
+
until?: string;
|
|
22
|
+
timezone: string;
|
|
23
|
+
} | {
|
|
24
|
+
kind: "manual";
|
|
25
|
+
};
|
|
26
|
+
export interface CadenceConversion {
|
|
27
|
+
cadence: MigratedCadence;
|
|
28
|
+
/** The result is not what v1 did — each one is reported per plan. */
|
|
29
|
+
warnings: string[];
|
|
30
|
+
/**
|
|
31
|
+
* The result is what v1 did, but spelled in a way worth knowing about —
|
|
32
|
+
* counted, not listed.
|
|
33
|
+
*/
|
|
34
|
+
notes: CadenceNote[];
|
|
35
|
+
}
|
|
36
|
+
export type CadenceNote =
|
|
37
|
+
/** No v1 interval at all → manual, as v1 never scheduled it either. */
|
|
38
|
+
"no-interval"
|
|
39
|
+
/** `number: 0` → a single appointment on the start date. */
|
|
40
|
+
| "one-off"
|
|
41
|
+
/** Month-end / leap-day start, spelled with BYSETPOS (see `monthEndRule`). */
|
|
42
|
+
| "month-end";
|
|
43
|
+
/**
|
|
44
|
+
* A date as v1 left it in a JSON column.
|
|
45
|
+
*
|
|
46
|
+
* Three encodings occur in the same field: a `Date` (decoded by the SDK), a
|
|
47
|
+
* `{ __type: "Date", iso }` wire object, and a bare ISO string — v1's
|
|
48
|
+
* `shiftScheduleInterval` clones the interval with `JSON.parse(JSON.stringify())`
|
|
49
|
+
* and only restores `startDate`, so every shifted plan carries `endDate` as a
|
|
50
|
+
* string.
|
|
51
|
+
*/
|
|
52
|
+
export declare function asDate(value: unknown): Date | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* A plan's interval laid over its template's.
|
|
55
|
+
*
|
|
56
|
+
* **A copy of `mergeScheduleInterval` from `@opendash/schedule`** (see the file
|
|
57
|
+
* comment for why it cannot be imported), which both the v1 frontend and the
|
|
58
|
+
* scheduler use to decide when a v1 plan is due. Keep the two identical — the
|
|
59
|
+
* migration has to arrive at the interval v1 actually fired on, not a
|
|
60
|
+
* plausible one. `undefined` / `null` in the plan do not erase the template's
|
|
61
|
+
* value; `Date`s and arrays are values, not structures.
|
|
62
|
+
*/
|
|
63
|
+
export declare function mergeScheduleInterval(base: unknown, override: unknown): unknown;
|
|
64
|
+
/**
|
|
65
|
+
* Translate an effective v1 interval (already merged over its template) into a
|
|
66
|
+
* cadence.
|
|
67
|
+
*
|
|
68
|
+
* `fallbackStart` anchors an interval that has no start date: v1 used "now" at
|
|
69
|
+
* every evaluation there, which never pins a date down. The caller passes the
|
|
70
|
+
* plan's `createdAt`.
|
|
71
|
+
*/
|
|
72
|
+
export declare function toCadence(interval: unknown, options: {
|
|
73
|
+
timezone: string;
|
|
74
|
+
fallbackStart?: Date;
|
|
75
|
+
}): CadenceConversion;
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* v1 schedule timing (`cron`) → v2 cadence (`OD3_Service_Schedule.cadence`).
|
|
4
|
+
*
|
|
5
|
+
* v1 stores `{ schedule_type: "timestamp", timestamp: { startDate, endDate,
|
|
6
|
+
* number, unit, onlyWeeks } }` and computes occurrences with dayjs as
|
|
7
|
+
* `startDate + k·number unit` (`ScheduleIterator` in `@opendash/schedule`). v2
|
|
8
|
+
* stores an RFC 5545 rule. This is a format translation — no occurrence is
|
|
9
|
+
* computed here.
|
|
10
|
+
*
|
|
11
|
+
* Why a translation lives here and not in `@opendash/schedule`, where schedule
|
|
12
|
+
* maths belongs: that package ships ESM only, and this server compiles to
|
|
13
|
+
* CommonJS, so it cannot import it. The equivalence of the two is proven
|
|
14
|
+
* against the real package instead — see the README, "Schedules".
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.asDate = asDate;
|
|
18
|
+
exports.mergeScheduleInterval = mergeScheduleInterval;
|
|
19
|
+
exports.toCadence = toCadence;
|
|
20
|
+
const UNITS = ["days", "weeks", "months", "years"];
|
|
21
|
+
const FREQ = {
|
|
22
|
+
days: "DAILY",
|
|
23
|
+
weeks: "WEEKLY",
|
|
24
|
+
months: "MONTHLY",
|
|
25
|
+
years: "YEARLY",
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* A date as v1 left it in a JSON column.
|
|
29
|
+
*
|
|
30
|
+
* Three encodings occur in the same field: a `Date` (decoded by the SDK), a
|
|
31
|
+
* `{ __type: "Date", iso }` wire object, and a bare ISO string — v1's
|
|
32
|
+
* `shiftScheduleInterval` clones the interval with `JSON.parse(JSON.stringify())`
|
|
33
|
+
* and only restores `startDate`, so every shifted plan carries `endDate` as a
|
|
34
|
+
* string.
|
|
35
|
+
*/
|
|
36
|
+
function asDate(value) {
|
|
37
|
+
if (value instanceof Date) {
|
|
38
|
+
return Number.isNaN(value.getTime()) ? undefined : value;
|
|
39
|
+
}
|
|
40
|
+
if (typeof value === "string" && value) {
|
|
41
|
+
const parsed = new Date(value);
|
|
42
|
+
return Number.isNaN(parsed.getTime()) ? undefined : parsed;
|
|
43
|
+
}
|
|
44
|
+
if (value && typeof value === "object") {
|
|
45
|
+
return asDate(value.iso);
|
|
46
|
+
}
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
const isPlainObject = (value) => Object.prototype.toString.call(value) === "[object Object]";
|
|
50
|
+
/**
|
|
51
|
+
* A plan's interval laid over its template's.
|
|
52
|
+
*
|
|
53
|
+
* **A copy of `mergeScheduleInterval` from `@opendash/schedule`** (see the file
|
|
54
|
+
* comment for why it cannot be imported), which both the v1 frontend and the
|
|
55
|
+
* scheduler use to decide when a v1 plan is due. Keep the two identical — the
|
|
56
|
+
* migration has to arrive at the interval v1 actually fired on, not a
|
|
57
|
+
* plausible one. `undefined` / `null` in the plan do not erase the template's
|
|
58
|
+
* value; `Date`s and arrays are values, not structures.
|
|
59
|
+
*/
|
|
60
|
+
function mergeScheduleInterval(base, override) {
|
|
61
|
+
if (!base)
|
|
62
|
+
return override;
|
|
63
|
+
if (!override)
|
|
64
|
+
return base;
|
|
65
|
+
return deepMergeOverride(base, override);
|
|
66
|
+
}
|
|
67
|
+
function deepMergeOverride(base, override) {
|
|
68
|
+
if (override === null || override === undefined)
|
|
69
|
+
return base;
|
|
70
|
+
if (base === null || base === undefined)
|
|
71
|
+
return override;
|
|
72
|
+
if (!isPlainObject(base) || !isPlainObject(override))
|
|
73
|
+
return override;
|
|
74
|
+
const result = { ...base };
|
|
75
|
+
const keys = new Set([...Object.keys(base), ...Object.keys(override)]);
|
|
76
|
+
for (const key of keys) {
|
|
77
|
+
const baseValue = base[key];
|
|
78
|
+
const overrideValue = override[key];
|
|
79
|
+
if (overrideValue === undefined || overrideValue === null) {
|
|
80
|
+
result[key] = baseValue;
|
|
81
|
+
}
|
|
82
|
+
else if (isPlainObject(baseValue) && isPlainObject(overrideValue)) {
|
|
83
|
+
result[key] = deepMergeOverride(baseValue, overrideValue);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
result[key] = overrideValue;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
/** Month (1–12) and day of an instant, on the wall clock of `timeZone`. */
|
|
92
|
+
function localDay(date, timeZone) {
|
|
93
|
+
const parts = new Intl.DateTimeFormat("en-US", {
|
|
94
|
+
timeZone,
|
|
95
|
+
month: "numeric",
|
|
96
|
+
day: "numeric",
|
|
97
|
+
}).formatToParts(date);
|
|
98
|
+
const get = (type) => Number(parts.find((part) => part.type === type)?.value);
|
|
99
|
+
return { month: get("month"), day: get("day") };
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* The extra rule parts a month-end start needs.
|
|
103
|
+
*
|
|
104
|
+
* dayjs *clamps*: 31 January + 1 month is 28 February, + 2 months is 31 March
|
|
105
|
+
* (the arithmetic is always from the start, so it does not drift). RFC 5545
|
|
106
|
+
* *skips* instead — `BYMONTHDAY=31` has no February, April, June, September or
|
|
107
|
+
* November, and a plain monthly rule from the 31st loses five maintenances a
|
|
108
|
+
* year without a word. "The latest of the 28th … 31st that exists" is how
|
|
109
|
+
* RRULE spells dayjs' clamp. The same holds for 29 February on a yearly plan.
|
|
110
|
+
*
|
|
111
|
+
* The plan editor does not know `BYSETPOS`; it computes and displays these
|
|
112
|
+
* correctly, but re-editing the series in the browser simplifies it.
|
|
113
|
+
*/
|
|
114
|
+
function monthEndRule(unit, start, timeZone) {
|
|
115
|
+
const { month, day } = localDay(start, timeZone);
|
|
116
|
+
if (unit === "months" && day > 28) {
|
|
117
|
+
const days = Array.from({ length: day - 27 }, (_, i) => 28 + i);
|
|
118
|
+
return [`BYMONTHDAY=${days.join(",")}`, "BYSETPOS=-1"];
|
|
119
|
+
}
|
|
120
|
+
if (unit === "years" && month === 2 && day === 29) {
|
|
121
|
+
return ["BYMONTH=2", "BYMONTHDAY=28,29", "BYSETPOS=-1"];
|
|
122
|
+
}
|
|
123
|
+
return [];
|
|
124
|
+
}
|
|
125
|
+
/** A compact rendering of a v1 value for a report line. */
|
|
126
|
+
function show(value) {
|
|
127
|
+
try {
|
|
128
|
+
const json = JSON.stringify(value);
|
|
129
|
+
return json.length > 160 ? `${json.slice(0, 160)}…` : json;
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
return String(value);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Translate an effective v1 interval (already merged over its template) into a
|
|
137
|
+
* cadence.
|
|
138
|
+
*
|
|
139
|
+
* `fallbackStart` anchors an interval that has no start date: v1 used "now" at
|
|
140
|
+
* every evaluation there, which never pins a date down. The caller passes the
|
|
141
|
+
* plan's `createdAt`.
|
|
142
|
+
*/
|
|
143
|
+
function toCadence(interval, options) {
|
|
144
|
+
const manual = (warning, note) => ({
|
|
145
|
+
cadence: { kind: "manual" },
|
|
146
|
+
warnings: warning ? [warning] : [],
|
|
147
|
+
notes: note ? [note] : [],
|
|
148
|
+
});
|
|
149
|
+
if (interval === undefined || interval === null) {
|
|
150
|
+
return manual(undefined, "no-interval");
|
|
151
|
+
}
|
|
152
|
+
if (!isPlainObject(interval)) {
|
|
153
|
+
return manual(`unreadable interval ${show(interval)} — became manual`);
|
|
154
|
+
}
|
|
155
|
+
if (interval.schedule_type !== "timestamp") {
|
|
156
|
+
// Templates last saved before July 2025 still carry the editor's old
|
|
157
|
+
// `{ scheduletype, run_cron, run_startdate, … }` form. v1's own iterator
|
|
158
|
+
// has returned `undefined` for it ever since, so it has not been firing.
|
|
159
|
+
const legacy = "run_cron" in interval || "scheduletype" in interval;
|
|
160
|
+
return manual(legacy
|
|
161
|
+
? `pre-2025-07 interval ${show(interval)}, which v1 no longer ` +
|
|
162
|
+
`evaluated — became manual`
|
|
163
|
+
: `interval of unknown type ${show(interval)} — became manual`);
|
|
164
|
+
}
|
|
165
|
+
const timestamp = interval.timestamp;
|
|
166
|
+
if (!isPlainObject(timestamp)) {
|
|
167
|
+
return manual(`interval without a timestamp ${show(interval)} — became manual`);
|
|
168
|
+
}
|
|
169
|
+
const unit = timestamp.unit;
|
|
170
|
+
if (!unit || !UNITS.includes(unit)) {
|
|
171
|
+
return manual(`interval unit ${show(timestamp.unit)} is not one v1 could compute — ` +
|
|
172
|
+
`became manual`);
|
|
173
|
+
}
|
|
174
|
+
const warnings = [];
|
|
175
|
+
const notes = [];
|
|
176
|
+
// `ScheduleIterator` reads a missing number as 1 (`number || 1`).
|
|
177
|
+
let every = 1;
|
|
178
|
+
let oneOff = false;
|
|
179
|
+
if (typeof timestamp.number === "number") {
|
|
180
|
+
if (!Number.isFinite(timestamp.number) || timestamp.number < 0) {
|
|
181
|
+
return manual(`interval number ${show(timestamp.number)} is one v1 rejected — ` +
|
|
182
|
+
`became manual`);
|
|
183
|
+
}
|
|
184
|
+
if (timestamp.number === 0) {
|
|
185
|
+
// The editor explains 0 as "not repeated, only scheduled for the start
|
|
186
|
+
// date" (`timestamp.info.zero`), and the Outlook sync treats it that way.
|
|
187
|
+
// The iterator reads it as 1 — a daily plan in the calendar — which is a
|
|
188
|
+
// bug nobody asked for, so the intent wins.
|
|
189
|
+
oneOff = true;
|
|
190
|
+
notes.push("one-off");
|
|
191
|
+
}
|
|
192
|
+
else if (!Number.isInteger(timestamp.number)) {
|
|
193
|
+
every = Math.max(1, Math.round(timestamp.number));
|
|
194
|
+
warnings.push(`interval number ${timestamp.number} is fractional — rounded to ${every}`);
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
every = timestamp.number;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
let start = asDate(timestamp.startDate);
|
|
201
|
+
if (!start) {
|
|
202
|
+
if (!options.fallbackStart) {
|
|
203
|
+
return manual("interval has no start date — became manual");
|
|
204
|
+
}
|
|
205
|
+
start = options.fallbackStart;
|
|
206
|
+
warnings.push(`interval has no start date (v1 anchored it to "now" on every ` +
|
|
207
|
+
`evaluation) — anchored at ${start.toISOString()}`);
|
|
208
|
+
}
|
|
209
|
+
const end = asDate(timestamp.endDate);
|
|
210
|
+
if (end && end.getTime() < start.getTime()) {
|
|
211
|
+
return manual(`interval ends (${end.toISOString()}) before it starts ` +
|
|
212
|
+
`(${start.toISOString()}), which v1 rejected — became manual`);
|
|
213
|
+
}
|
|
214
|
+
if (oneOff) {
|
|
215
|
+
return {
|
|
216
|
+
cadence: {
|
|
217
|
+
kind: "rrule",
|
|
218
|
+
rrule: "FREQ=DAILY;COUNT=1",
|
|
219
|
+
dtstart: start.toISOString(),
|
|
220
|
+
timezone: options.timezone,
|
|
221
|
+
},
|
|
222
|
+
warnings,
|
|
223
|
+
notes,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
const parts = [`FREQ=${FREQ[unit]}`];
|
|
227
|
+
// The plan editor leaves out INTERVAL=1; both spellings compute the same.
|
|
228
|
+
if (every > 1)
|
|
229
|
+
parts.push(`INTERVAL=${every}`);
|
|
230
|
+
const clamp = monthEndRule(unit, start, options.timezone);
|
|
231
|
+
if (clamp.length) {
|
|
232
|
+
parts.push(...clamp);
|
|
233
|
+
notes.push("month-end");
|
|
234
|
+
}
|
|
235
|
+
return {
|
|
236
|
+
cadence: {
|
|
237
|
+
kind: "rrule",
|
|
238
|
+
rrule: parts.join(";"),
|
|
239
|
+
dtstart: start.toISOString(),
|
|
240
|
+
...(end ? { until: end.toISOString() } : {}),
|
|
241
|
+
timezone: options.timezone,
|
|
242
|
+
},
|
|
243
|
+
warnings,
|
|
244
|
+
notes,
|
|
245
|
+
};
|
|
246
|
+
}
|
|
@@ -18,6 +18,11 @@ export interface MigrationConfig {
|
|
|
18
18
|
runId: string;
|
|
19
19
|
/** Rows fetched per query page. */
|
|
20
20
|
batchSize: number;
|
|
21
|
+
/**
|
|
22
|
+
* IANA zone the v1 schedule intervals were meant in. Written onto every
|
|
23
|
+
* migrated cadence — see `lib/cadence.ts`.
|
|
24
|
+
*/
|
|
25
|
+
timezone: string;
|
|
21
26
|
}
|
|
22
27
|
export declare class MigrationConfigError extends Error {
|
|
23
28
|
}
|
|
@@ -53,8 +53,31 @@ function readConfig(argv) {
|
|
|
53
53
|
dryRun: has("dry-run"),
|
|
54
54
|
runId: flag("resume") ?? `run-${new Date().toISOString()}`,
|
|
55
55
|
batchSize: readBatchSize(flag("batch")),
|
|
56
|
+
timezone: readTimezone(flag("timezone")),
|
|
56
57
|
};
|
|
57
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* The zone migrated schedules keep their wall-clock time in.
|
|
61
|
+
*
|
|
62
|
+
* v1 did its interval arithmetic with dayjs in the *local* zone of whoever
|
|
63
|
+
* computed it — the browser — so "every month at 08:00" stayed at 08:00
|
|
64
|
+
* across the clock change. A v2 cadence only does that when it names a zone;
|
|
65
|
+
* without one it runs in absolute time and every summer occurrence moves by an
|
|
66
|
+
* hour. `Europe/Berlin` is what the plan editor falls back to as well.
|
|
67
|
+
*
|
|
68
|
+
* Validated up front: an unknown zone would otherwise surface as a
|
|
69
|
+
* `RangeError` on the first plan, halfway through a pass.
|
|
70
|
+
*/
|
|
71
|
+
function readTimezone(raw) {
|
|
72
|
+
const zone = raw ?? "Europe/Berlin";
|
|
73
|
+
try {
|
|
74
|
+
new Intl.DateTimeFormat("en-US", { timeZone: zone });
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
throw new MigrationConfigError(`--timezone must be an IANA zone such as Europe/Berlin (got "${zone}").`);
|
|
78
|
+
}
|
|
79
|
+
return zone;
|
|
80
|
+
}
|
|
58
81
|
/**
|
|
59
82
|
* Page size, validated rather than trusted.
|
|
60
83
|
*
|