@openinc/parse-server-opendash 4.6.0 → 4.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/dist/features/schema/helper/migrationMode.js +2 -0
- package/dist/hooks/Service_Schedule.js +7 -0
- package/dist/hooks/Service_Schedule_Template.js +5 -0
- package/dist/scripts/migration/lib/articleMeta.d.ts +34 -10
- package/dist/scripts/migration/lib/articleMeta.js +58 -11
- 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/equipmentMeta.d.ts +65 -0
- package/dist/scripts/migration/lib/equipmentMeta.js +155 -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 +181 -4
- package/dist/scripts/migration/passes/05-articles.d.ts +12 -15
- package/dist/scripts/migration/passes/05-articles.js +83 -33
- 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 +450 -12
- package/dist/scripts/seed-v1-testdata.d.ts +2 -0
- package/dist/scripts/seed-v1-testdata.js +449 -10
- 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;
|
|
@@ -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;
|
|
@@ -2,21 +2,29 @@ import { Meta_Entry } from "../../../types/index.js";
|
|
|
2
2
|
import type { MetaFieldConfig } from "../../../types/custom/MetaField.js";
|
|
3
3
|
import type { MigrationConfig } from "./env.js";
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Article data that has **no column of its own**, kept as plugin-meta.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
7
|
+
* **Narrowed on 2026-09-25.** This used to carry v1's whole stock-keeping set,
|
|
8
|
+
* because `OD3_BDE_Article` was a lean catalogue shared with BDE and its ABAS
|
|
9
|
+
* sync and widening it was not ours to do. That changed on 2026-09-18: the class
|
|
10
|
+
* gained `stock`, `minimumStock`, `storageLocation`, `supplier`, `orderNumber`,
|
|
11
|
+
* `price`, `priceCurrency` and `packageSize` as real columns, and both article
|
|
12
|
+
* admin views edit them there.
|
|
13
|
+
*
|
|
14
|
+
* Pass 05 therefore writes those to the columns now, and only what still has no
|
|
15
|
+
* home stays here: v1's `category` — deliberately never given a column, since
|
|
16
|
+
* tags and `type` already classify and a third such field goes stale — v1's
|
|
17
|
+
* `description` (the label column is taken by v1's `name`), and the `Source`
|
|
18
|
+
* links behind `Item.sources`.
|
|
11
19
|
*
|
|
12
20
|
* ⚠️ The ABAS sync still owns the columns it writes and replaces them on every
|
|
13
21
|
* run. It does not touch the stock-keeping ones today — if that changes, they
|
|
14
22
|
* are the collision to watch.
|
|
15
23
|
*
|
|
16
|
-
*
|
|
24
|
+
* What remains lands in a `Meta_Entry` under the same
|
|
17
25
|
* `["service", <entity>, "meta"]` context every other core master-data entity
|
|
18
|
-
* uses (`constants.metaContext`)
|
|
19
|
-
*
|
|
26
|
+
* uses (`constants.metaContext`), editable through the article admin view in
|
|
27
|
+
* `openservice-core` with no extra machinery.
|
|
20
28
|
*
|
|
21
29
|
* **Deliberately not `["bde","article","custom"]`.** That context belongs to the
|
|
22
30
|
* ABAS sync (`node-stack-scheduler`, `syncArticle.ts`), which replaces `config`
|
|
@@ -26,6 +34,15 @@ import type { MigrationConfig } from "./env.js";
|
|
|
26
34
|
* would have its values clobbered on the next sync.
|
|
27
35
|
*/
|
|
28
36
|
export declare const ARTICLE_META_CONTEXT: string[];
|
|
37
|
+
/**
|
|
38
|
+
* Keys this context used to hold that are **now columns** on `OD3_BDE_Article`.
|
|
39
|
+
*
|
|
40
|
+
* Pass 05 strips them from any entry it finds, so an installation migrated
|
|
41
|
+
* before 2026-09-25 heals on the next run instead of showing every value twice —
|
|
42
|
+
* once in the article form, once under *Kopfdaten*. Listed here rather than in
|
|
43
|
+
* the pass because it is a statement about this context's history.
|
|
44
|
+
*/
|
|
45
|
+
export declare const META_KEYS_NOW_COLUMNS: readonly ["price", "stock", "stockAlarmAt", "stockUnit", "storageLocation", "supplier", "orderNumber"];
|
|
29
46
|
/**
|
|
30
47
|
* The field definitions written to the shared `Meta_Config`.
|
|
31
48
|
*
|
|
@@ -33,8 +50,6 @@ export declare const ARTICLE_META_CONTEXT: string[];
|
|
|
33
50
|
* stock, reorder level, storage location, supplier and order number. Leaving
|
|
34
51
|
* them here would have shown every article twice — once as an empty meta field,
|
|
35
52
|
* once as the column that actually holds the value.
|
|
36
|
-
*
|
|
37
|
-
* What remains is what has no column: the category, and the equipment links.
|
|
38
53
|
*/
|
|
39
54
|
export declare const ARTICLE_META_FIELDS: MetaFieldConfig[];
|
|
40
55
|
/**
|
|
@@ -45,6 +60,15 @@ export declare const ARTICLE_META_FIELDS: MetaFieldConfig[];
|
|
|
45
60
|
* later as "the migration ate our prices".
|
|
46
61
|
*/
|
|
47
62
|
export declare function parsePrice(raw: unknown): number | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* The currency of a v1 price string, where it states one.
|
|
65
|
+
*
|
|
66
|
+
* v1 has no currency column — it stored free text like `"12,50 €"`. Returns
|
|
67
|
+
* `undefined` rather than assuming EUR: the instances are German, but stamping a
|
|
68
|
+
* currency onto a bare `"12,50"` would be asserting something the source never
|
|
69
|
+
* said, and `priceCurrency` is nullable precisely so it can stay unknown.
|
|
70
|
+
*/
|
|
71
|
+
export declare function parsePriceCurrency(raw: unknown): string | undefined;
|
|
48
72
|
/**
|
|
49
73
|
* Ensure the shared `Meta_Config` exists for a tenant, returning its id.
|
|
50
74
|
*
|
|
@@ -3,8 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ARTICLE_META_FIELDS = exports.ARTICLE_META_CONTEXT = void 0;
|
|
6
|
+
exports.ARTICLE_META_FIELDS = exports.META_KEYS_NOW_COLUMNS = exports.ARTICLE_META_CONTEXT = void 0;
|
|
7
7
|
exports.parsePrice = parsePrice;
|
|
8
|
+
exports.parsePriceCurrency = parsePriceCurrency;
|
|
8
9
|
exports.ensureArticleMetaConfig = ensureArticleMetaConfig;
|
|
9
10
|
exports.loadArticleMetaEntries = loadArticleMetaEntries;
|
|
10
11
|
exports.loadArticleMetaConfigs = loadArticleMetaConfigs;
|
|
@@ -14,21 +15,29 @@ const acl_js_1 = require("./acl.js");
|
|
|
14
15
|
const ptr_js_1 = require("./ptr.js");
|
|
15
16
|
const pass_js_1 = require("./pass.js");
|
|
16
17
|
/**
|
|
17
|
-
*
|
|
18
|
+
* Article data that has **no column of its own**, kept as plugin-meta.
|
|
18
19
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
20
|
+
* **Narrowed on 2026-09-25.** This used to carry v1's whole stock-keeping set,
|
|
21
|
+
* because `OD3_BDE_Article` was a lean catalogue shared with BDE and its ABAS
|
|
22
|
+
* sync and widening it was not ours to do. That changed on 2026-09-18: the class
|
|
23
|
+
* gained `stock`, `minimumStock`, `storageLocation`, `supplier`, `orderNumber`,
|
|
24
|
+
* `price`, `priceCurrency` and `packageSize` as real columns, and both article
|
|
25
|
+
* admin views edit them there.
|
|
26
|
+
*
|
|
27
|
+
* Pass 05 therefore writes those to the columns now, and only what still has no
|
|
28
|
+
* home stays here: v1's `category` — deliberately never given a column, since
|
|
29
|
+
* tags and `type` already classify and a third such field goes stale — v1's
|
|
30
|
+
* `description` (the label column is taken by v1's `name`), and the `Source`
|
|
31
|
+
* links behind `Item.sources`.
|
|
23
32
|
*
|
|
24
33
|
* ⚠️ The ABAS sync still owns the columns it writes and replaces them on every
|
|
25
34
|
* run. It does not touch the stock-keeping ones today — if that changes, they
|
|
26
35
|
* are the collision to watch.
|
|
27
36
|
*
|
|
28
|
-
*
|
|
37
|
+
* What remains lands in a `Meta_Entry` under the same
|
|
29
38
|
* `["service", <entity>, "meta"]` context every other core master-data entity
|
|
30
|
-
* uses (`constants.metaContext`)
|
|
31
|
-
*
|
|
39
|
+
* uses (`constants.metaContext`), editable through the article admin view in
|
|
40
|
+
* `openservice-core` with no extra machinery.
|
|
32
41
|
*
|
|
33
42
|
* **Deliberately not `["bde","article","custom"]`.** That context belongs to the
|
|
34
43
|
* ABAS sync (`node-stack-scheduler`, `syncArticle.ts`), which replaces `config`
|
|
@@ -38,6 +47,23 @@ const pass_js_1 = require("./pass.js");
|
|
|
38
47
|
* would have its values clobbered on the next sync.
|
|
39
48
|
*/
|
|
40
49
|
exports.ARTICLE_META_CONTEXT = ["service", "article", "meta"];
|
|
50
|
+
/**
|
|
51
|
+
* Keys this context used to hold that are **now columns** on `OD3_BDE_Article`.
|
|
52
|
+
*
|
|
53
|
+
* Pass 05 strips them from any entry it finds, so an installation migrated
|
|
54
|
+
* before 2026-09-25 heals on the next run instead of showing every value twice —
|
|
55
|
+
* once in the article form, once under *Kopfdaten*. Listed here rather than in
|
|
56
|
+
* the pass because it is a statement about this context's history.
|
|
57
|
+
*/
|
|
58
|
+
exports.META_KEYS_NOW_COLUMNS = [
|
|
59
|
+
"price",
|
|
60
|
+
"stock",
|
|
61
|
+
"stockAlarmAt",
|
|
62
|
+
"stockUnit",
|
|
63
|
+
"storageLocation",
|
|
64
|
+
"supplier",
|
|
65
|
+
"orderNumber",
|
|
66
|
+
];
|
|
41
67
|
/**
|
|
42
68
|
* The field definitions written to the shared `Meta_Config`.
|
|
43
69
|
*
|
|
@@ -45,11 +71,10 @@ exports.ARTICLE_META_CONTEXT = ["service", "article", "meta"];
|
|
|
45
71
|
* stock, reorder level, storage location, supplier and order number. Leaving
|
|
46
72
|
* them here would have shown every article twice — once as an empty meta field,
|
|
47
73
|
* once as the column that actually holds the value.
|
|
48
|
-
*
|
|
49
|
-
* What remains is what has no column: the category, and the equipment links.
|
|
50
74
|
*/
|
|
51
75
|
exports.ARTICLE_META_FIELDS = [
|
|
52
76
|
{ type: "string", name: "category", label: "Kategorie" },
|
|
77
|
+
{ type: "string", name: "notes", label: "Beschreibung (v1)" },
|
|
53
78
|
{
|
|
54
79
|
type: "select_parse",
|
|
55
80
|
name: "equipment",
|
|
@@ -78,6 +103,28 @@ function parsePrice(raw) {
|
|
|
78
103
|
const value = Number(cleaned);
|
|
79
104
|
return Number.isFinite(value) ? value : undefined;
|
|
80
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* The currency of a v1 price string, where it states one.
|
|
108
|
+
*
|
|
109
|
+
* v1 has no currency column — it stored free text like `"12,50 €"`. Returns
|
|
110
|
+
* `undefined` rather than assuming EUR: the instances are German, but stamping a
|
|
111
|
+
* currency onto a bare `"12,50"` would be asserting something the source never
|
|
112
|
+
* said, and `priceCurrency` is nullable precisely so it can stay unknown.
|
|
113
|
+
*/
|
|
114
|
+
function parsePriceCurrency(raw) {
|
|
115
|
+
if (raw === undefined || raw === null)
|
|
116
|
+
return undefined;
|
|
117
|
+
const text = String(raw).toUpperCase();
|
|
118
|
+
if (text.includes("€") || text.includes("EUR"))
|
|
119
|
+
return "EUR";
|
|
120
|
+
if (text.includes("$") || text.includes("USD"))
|
|
121
|
+
return "USD";
|
|
122
|
+
if (text.includes("£") || text.includes("GBP"))
|
|
123
|
+
return "GBP";
|
|
124
|
+
if (text.includes("CHF"))
|
|
125
|
+
return "CHF";
|
|
126
|
+
return undefined;
|
|
127
|
+
}
|
|
81
128
|
/**
|
|
82
129
|
* Ensure the shared `Meta_Config` exists for a tenant, returning its id.
|
|
83
130
|
*
|
|
@@ -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
|
*
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Meta_Entry } from "../../../types/index.js";
|
|
2
|
+
import type { MigrationConfig } from "./env.js";
|
|
3
|
+
/**
|
|
4
|
+
* Equipment header data, migrated from `OD3_SourceMeta`.
|
|
5
|
+
*
|
|
6
|
+
* v1 hangs a single `OD3_SourceMeta` off each `OD3_Source` (`Source.meta`) and
|
|
7
|
+
* lets clients put whatever they like in its `data` Object — a flat
|
|
8
|
+
* `{ field: value | value[] }` map with no schema anywhere. v2 has no column for
|
|
9
|
+
* any of it, so it lands in plugin-meta under the context the equipment admin
|
|
10
|
+
* view already reads: `metaContext("equipment")` in `openservice-core`, i.e.
|
|
11
|
+
* `["service","equipment","meta"]`. Nothing new had to be invented — the meta
|
|
12
|
+
* editor is already wired up on that view.
|
|
13
|
+
*
|
|
14
|
+
* **D2 was reversed on 2026-09-25.** The plan originally dropped `SourceMeta`
|
|
15
|
+
* and called surfacing it on Equipment a v2 feature. Clients are using it, so it
|
|
16
|
+
* migrates.
|
|
17
|
+
*
|
|
18
|
+
* The four `SourceMeta` columns that are not `data` — `name`, `description`,
|
|
19
|
+
* `location`, `file` — have no column on Equipment either, so they join the same
|
|
20
|
+
* entry. A `data` key of the same name wins, and the column value moves aside
|
|
21
|
+
* (see {@link reservedFallback}) rather than being overwritten.
|
|
22
|
+
*/
|
|
23
|
+
export declare const EQUIPMENT_META_CONTEXT: string[];
|
|
24
|
+
/** A plugin-meta field config, as inferred from a v1 value. */
|
|
25
|
+
export interface InferredMetaField {
|
|
26
|
+
name: string;
|
|
27
|
+
label: string;
|
|
28
|
+
type: "string" | "number" | "boolean";
|
|
29
|
+
multiple?: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Infer a field config from a value, because v1 has no definitions to convert.
|
|
33
|
+
*
|
|
34
|
+
* Unlike ticket meta (pass 07), which migrates real v1 field definitions,
|
|
35
|
+
* `SourceMeta.data` is raw key/value with no schema. The type is therefore read
|
|
36
|
+
* off the value itself; an array becomes the scalar type plus `multiple`, which
|
|
37
|
+
* is what `getSourceMetaMap` already assumed v1 values could be.
|
|
38
|
+
*/
|
|
39
|
+
export declare function inferMetaField(name: string, value: unknown): InferredMetaField | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Storable form of a v1 value.
|
|
42
|
+
*
|
|
43
|
+
* Plugin-meta has no geo or file field type, so a `GeoPoint` becomes
|
|
44
|
+
* `"lat,lng"` and a `File` becomes its URL. Both are reported by the pass rather
|
|
45
|
+
* than dropped — a string keeps the value readable and recoverable, which is the
|
|
46
|
+
* point.
|
|
47
|
+
*/
|
|
48
|
+
export declare function metaValue(value: unknown): unknown;
|
|
49
|
+
/** Where a `SourceMeta` column goes when `data` already claimed its name. */
|
|
50
|
+
export declare function reservedFallback(name: string): string;
|
|
51
|
+
/**
|
|
52
|
+
* Ensure the shared `Meta_Config` for a tenant, returning its id.
|
|
53
|
+
*
|
|
54
|
+
* Tenant-scoped for the same reason as the article config: the migration reads
|
|
55
|
+
* with the maintenance key, which bypasses ACL, so an unscoped `.first()` would
|
|
56
|
+
* find another tenant's config and overwrite it.
|
|
57
|
+
*
|
|
58
|
+
* Fields are merged into whatever the config already has rather than replacing
|
|
59
|
+
* it, so a config a human has already extended by hand survives a re-run.
|
|
60
|
+
*/
|
|
61
|
+
export declare function ensureEquipmentMetaConfig(config: MigrationConfig, tenantId: string, fields: InferredMetaField[]): Promise<string | undefined>;
|
|
62
|
+
/** Existing equipment meta entries, keyed by the equipment they belong to. */
|
|
63
|
+
export declare function loadEquipmentMetaEntries(config: MigrationConfig): Promise<Map<string, Meta_Entry>>;
|
|
64
|
+
/** The `Meta_Config` ids already present for this context, keyed by tenant. */
|
|
65
|
+
export declare function loadEquipmentMetaConfigs(config: MigrationConfig): Promise<Map<string, string>>;
|