@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.
Files changed (34) hide show
  1. package/dist/features/schema/helper/migrationMode.js +2 -0
  2. package/dist/hooks/Service_Schedule.js +7 -0
  3. package/dist/hooks/Service_Schedule_Execution.js +10 -4
  4. package/dist/hooks/Service_Schedule_Template.js +5 -0
  5. package/dist/scripts/migration/lib/cadence.d.ts +75 -0
  6. package/dist/scripts/migration/lib/cadence.js +246 -0
  7. package/dist/scripts/migration/lib/env.d.ts +5 -0
  8. package/dist/scripts/migration/lib/env.js +23 -0
  9. package/dist/scripts/migration/lib/schedule.d.ts +306 -0
  10. package/dist/scripts/migration/lib/schedule.js +613 -0
  11. package/dist/scripts/migration/passes/03-equipment.js +11 -4
  12. package/dist/scripts/migration/passes/13-schedule-templates.d.ts +15 -0
  13. package/dist/scripts/migration/passes/13-schedule-templates.js +163 -0
  14. package/dist/scripts/migration/passes/14-schedules.d.ts +30 -0
  15. package/dist/scripts/migration/passes/14-schedules.js +239 -0
  16. package/dist/scripts/migration/passes/15-executions.d.ts +34 -0
  17. package/dist/scripts/migration/passes/15-executions.js +244 -0
  18. package/dist/scripts/migration/passes/16-schedule-meta.d.ts +23 -0
  19. package/dist/scripts/migration/passes/16-schedule-meta.js +308 -0
  20. package/dist/scripts/migration/passes/17-schedule-assets.d.ts +30 -0
  21. package/dist/scripts/migration/passes/17-schedule-assets.js +240 -0
  22. package/dist/scripts/migration/passes/18-calendar-links.d.ts +25 -0
  23. package/dist/scripts/migration/passes/18-calendar-links.js +132 -0
  24. package/dist/scripts/migration/passes/19-schedule-history.d.ts +18 -0
  25. package/dist/scripts/migration/passes/19-schedule-history.js +186 -0
  26. package/dist/scripts/migration/run.js +20 -9
  27. package/dist/scripts/migration/verify.js +294 -11
  28. package/dist/scripts/seed-v1-testdata.d.ts +2 -0
  29. package/dist/scripts/seed-v1-testdata.js +392 -6
  30. package/dist/types/Service_Schedule.d.ts +3 -0
  31. package/dist/types/Service_Schedule.js +6 -0
  32. package/dist/types/Service_Schedule_Execution.d.ts +1 -1
  33. package/package.json +1 -1
  34. package/schema/Service_Schedule.json +4 -0
@@ -0,0 +1,306 @@
1
+ import type { ServiceNotificationRule } from "../../../features/openservice/serviceSchedules/calendarSync/ServiceSyncTypes.js";
2
+ import { Maintenance_Schedule, Maintenance_Schedule_Execution, Maintenance_Schedule_Execution_Step, Maintenance_Schedule_Step } from "../../../types/index.js";
3
+ import type { TicketMaterial } from "../../../types/custom/TicketMaterial.js";
4
+ import type { MigrationConfig } from "./env.js";
5
+ /**
6
+ * What the schedule passes (13–19) share.
7
+ *
8
+ * Several passes have to agree on the same derived facts — which v2 step id a
9
+ * v1 step became, which plan a v1 execution belongs to, whether a v1 run
10
+ * counts as done. Each of those is decided **here, once**, the way
11
+ * `lib/material.ts` is shared by the ticket fold and replay: two passes that
12
+ * derived a step id differently would write captured values nobody can find.
13
+ */
14
+ /**
15
+ * Where a step's capture fields (`OD3_Meta_Config`) and captured values
16
+ * (`OD3_Meta_Entry`) live. Mirrors `stepMetaContext` in openservice-core
17
+ * (`models/embedded/ScheduleStep.ts`).
18
+ */
19
+ export declare const stepMetaContext: (stepId: string) => string[];
20
+ /** v1's own step meta context (written since 2026-02), keyed by v1 step id. */
21
+ export declare const legacyStepMetaContext: (v1StepId: string) => string[];
22
+ export declare const STEP_META_PREFIX: string;
23
+ export declare const LEGACY_STEP_META_PREFIX: string;
24
+ /** The step id inside a stringified step meta context, v1 or v2. */
25
+ export declare function stepIdOfContext(context: string): string | undefined;
26
+ /**
27
+ * Photos and files of one execution. Mirrors `executionMediaContext` in
28
+ * openservice-schedule (`features/schedules/utils/documents.ts`) — a plain
29
+ * string, not a stringified array like the ticket context.
30
+ */
31
+ export declare const executionMediaContext: (executionId: string) => string;
32
+ /**
33
+ * Machine documents: shared by every plan of one equipment, per plan when it
34
+ * has none. Mirrors `machineDocsContext` in the same file.
35
+ */
36
+ export declare function machineDocsContext(options: {
37
+ equipmentId?: string;
38
+ scheduleId: string;
39
+ }): string;
40
+ /**
41
+ * A deterministic, UUID-shaped id.
42
+ *
43
+ * v2 step ids are opaque UUIDs, and several things hang off one: the step's
44
+ * `Meta_Config`, every execution's step result, every captured `Meta_Entry`.
45
+ * A random id would make a re-run mint a second set and orphan the first, so
46
+ * the id is a hash of what the step *is* — which is also what lets pass 15
47
+ * and pass 16 arrive at the same id without talking to each other.
48
+ */
49
+ export declare function mintId(...parts: string[]): string;
50
+ /**
51
+ * The id a v1 step gets inside one v2 plan.
52
+ *
53
+ * Minted **per plan**, not per v1 step: v1 step rows are shared — a template's
54
+ * steps are added to every plan created from it — while a v2 step belongs to
55
+ * one plan, and its capture fields are keyed by its id. Two plans sharing one
56
+ * id would share one `Meta_Config`, and editing the fields of one would edit
57
+ * the other.
58
+ */
59
+ export declare const planStepId: (v1PlanId: string, v1StepId: string) => string;
60
+ /** The same for a template's steps. */
61
+ export declare const templateStepId: (v1TemplateId: string, v1StepId: string) => string;
62
+ /** The synthetic step an execution's material hangs off — see pass 15. */
63
+ export declare const materialStepId: (v1ExecutionId: string) => string;
64
+ /**
65
+ * The v2 step id of each step of one v1 execution, keyed by execution-step id.
66
+ *
67
+ * A step that points at its plan step (`step`, written since 2026-02) takes
68
+ * that plan step's id, so the protocol, the plan and the captured values all
69
+ * agree on it. Older rows have no such pointer and get an id of their own —
70
+ * matching them to a plan step by title would be a guess, and a wrong guess
71
+ * files a measurement under the wrong step.
72
+ */
73
+ export declare function executionStepIds(steps: Maintenance_Schedule_Execution_Step[], v1PlanId: string | undefined): Map<string, string>;
74
+ /** A v2 step, as `OD3_Service_Schedule.steps` / `Execution.steps` store it. */
75
+ export interface V2Step {
76
+ id: string;
77
+ order: number;
78
+ title: string;
79
+ description?: string;
80
+ required?: boolean;
81
+ material?: TicketMaterial[];
82
+ }
83
+ /**
84
+ * v1 order: by `order`, then by age.
85
+ *
86
+ * `order` is global across the whole v1 class rather than per plan, and rows
87
+ * from before 2025-08 all carry 0 — so it sorts, but only the position in the
88
+ * result means anything. v2 renumbers from 0.
89
+ */
90
+ export declare function byV1Order<T extends Parse.Object>(rows: T[]): T[];
91
+ /**
92
+ * The step rows of v1 plans and templates, read once per owner.
93
+ *
94
+ * A relation cannot be batch-loaded, so every owner costs a query — and the
95
+ * same template's steps are asked for once per plan made from it.
96
+ */
97
+ export declare class StepSource {
98
+ private readonly batchSize;
99
+ private readonly cache;
100
+ constructor(batchSize: number);
101
+ /** The rows in an owner's `steps` relation, in v1 order. */
102
+ of(owner: Parse.Object): Promise<Maintenance_Schedule_Step[]>;
103
+ /**
104
+ * The steps a v1 execution of this plan was built from: the plan's own, or
105
+ * — when it has none — its template's
106
+ * (`hooks/Maintenance_Schedule_Execution.ts`). That is what the plan meant
107
+ * to a technician, so it is what the v2 plan carries.
108
+ */
109
+ ofPlan(plan: Maintenance_Schedule): Promise<{
110
+ rows: Maintenance_Schedule_Step[];
111
+ inherited: boolean;
112
+ }>;
113
+ }
114
+ /**
115
+ * Whether a v1 step field is an era-A *static* field.
116
+ *
117
+ * `Schedule_Step.fields` meant three things over time:
118
+ * - **A** (≈ 2024-12 – 2025-08): `{ metafield: {label, …}, value }` — a value an
119
+ * admin set on the step, shown to the technician, never captured.
120
+ * - **B** (2025-08 – 2026-02): a meta field *config* (`{ name, type, … }`) whose
121
+ * values were captured per execution into `Execution_Step.meta`.
122
+ * - **C** (since 2026-02): not written; the config is an `OD3_Meta_Config`.
123
+ */
124
+ export declare function isStaticField(field: unknown): boolean;
125
+ /**
126
+ * A step description with its era-A static fields appended.
127
+ *
128
+ * v2 has no per-step properties an admin fills in — only capture fields, which
129
+ * are the technician's. What an era-A field said ("PSA: Handschuhe") is an
130
+ * instruction, and the description is where v2 keeps instructions, so it moves
131
+ * there rather than being dropped.
132
+ */
133
+ export declare function withStaticFields(description: unknown, fields: unknown): string | undefined;
134
+ /** A v1 step (or execution step) as a v2 step. */
135
+ export declare function toV2Step(row: Parse.Object, id: string, order: number, required: boolean): V2Step;
136
+ /** Who could see a v1 plan or template, read back from its ACL. */
137
+ export interface V1Access {
138
+ /**
139
+ * The creator. v1 plans have no `user` column — their afterSave granted the
140
+ * creating user read+write and nobody else a write, so the (first) user
141
+ * with write access *is* the creator.
142
+ */
143
+ creatorId?: string;
144
+ /** Further users with read access — they become assignees. */
145
+ readerUserIds: string[];
146
+ /** Roles with read access, minus the admin roles every plan carries. */
147
+ readerRoleNames: string[];
148
+ /** Users besides the creator who could write; v2 assignees only read. */
149
+ demotedWriterIds: string[];
150
+ /**
151
+ * Readable by everybody: no ACL at all, or public read. v1's afterSave only
152
+ * *saves* the ACL it builds when the write was not master — so every plan
153
+ * the v1 Outlook poller imported has none. v2 plans are never public; the
154
+ * nearest is an assignment to the tenant's user role.
155
+ */
156
+ unrestricted: boolean;
157
+ }
158
+ export declare function readV1Access(object: Parse.Object, tenantId: string | undefined): V1Access;
159
+ /**
160
+ * The roles a migrated plan or template is assigned to: the ones its ACL
161
+ * named, plus the tenant's user role when everybody could read it.
162
+ */
163
+ export declare function assignedRoleNames(access: V1Access, tenantId: string): string[];
164
+ /**
165
+ * The ACL of a private v2 plan or template.
166
+ *
167
+ * Mirrors `syncAssignmentAcl` (`features/openservice/serviceSchedules/
168
+ * assignmentAcl.ts`) exactly: administrators, the creator read+write, the
169
+ * assigned roles and users read. That hook derives the ACL from the
170
+ * assignments on every save — so an ACL written here that the assignments do
171
+ * not explain would be silently narrowed by the first edit in v2. Anything
172
+ * v1 granted therefore has to arrive as an *assignment*, and this is the ACL
173
+ * those assignments imply. Tenant users get no read: plans are private.
174
+ */
175
+ export declare function privateAcl(options: {
176
+ tenantId: string;
177
+ creatorId?: string;
178
+ roleNames: string[];
179
+ userIds: string[];
180
+ }): Parse.ACL;
181
+ /**
182
+ * Write the assignment relations of a plan or template that already exists.
183
+ *
184
+ * Relations cannot be part of a create body — Parse rejects an array where
185
+ * the schema says Relation — so they follow as an update. In migration mode
186
+ * the afterSave that would re-derive the ACL from them is off, which is why
187
+ * the create already carried the ACL they imply ({@link privateAcl}).
188
+ */
189
+ export declare function addAssignments(className: string, objectId: string, assignments: {
190
+ roleIds: string[];
191
+ userIds?: string[];
192
+ }): Promise<void>;
193
+ /**
194
+ * v1 plan contacts as v2 service providers.
195
+ *
196
+ * `notify: false` on purpose: v1 only *listed* contacts on a plan and never
197
+ * mailed them — the scheduler notified users. Sending external service
198
+ * providers mail from the first v2 tick onwards would be new behaviour
199
+ * nobody switched on; the flag is the provider's consent, and the plan editor
200
+ * turns it on per provider. `notifyOffsetDays` is the editor's default.
201
+ */
202
+ export declare function serviceProviders(contactIds: string[]): Array<{
203
+ contactId: string;
204
+ notify: boolean;
205
+ notifyOffsetDays: number;
206
+ }>;
207
+ /**
208
+ * Role names → ids for the roles a v1 ACL named.
209
+ *
210
+ * ACLs grant by name, assignment relations by id. A name with no role behind
211
+ * it any more is returned separately: it cannot become an assignment, and a
212
+ * grant without one would not survive the first save in v2.
213
+ */
214
+ export declare function resolveRoles(names: string[], roleIdByName: Map<string, string>): {
215
+ ids: string[];
216
+ names: string[];
217
+ unknown: string[];
218
+ };
219
+ /**
220
+ * The plan's `notifyBeforeDue`, or its template's.
221
+ *
222
+ * `||`, not `??`, because that is what the v1 scheduler did: any object —
223
+ * including the `{ value: 0, unit: "milliseconds" }` the admin form writes on
224
+ * mount — hides the template's value.
225
+ */
226
+ export declare function effectiveNotifyBeforeDue(plan: Parse.Object, template: Parse.Object | undefined): unknown;
227
+ /** v1's lead time in milliseconds, or undefined for "no reminder". */
228
+ export declare function leadTimeMs(notifyBeforeDue: unknown): number | undefined;
229
+ export interface RuleConversion {
230
+ rules: ServiceNotificationRule[];
231
+ /** Set when the v1 reminder could not be carried over exactly. */
232
+ deviation?: string;
233
+ }
234
+ /**
235
+ * Who v1 notified about a plan, in v2 terms.
236
+ *
237
+ * v1 notified exactly the users the plan's ACL let read it, directly or
238
+ * through a role (`getRecipientsFromACL` in the scheduler) — and nobody for a
239
+ * plan without an ACL. The users go into `userIds`. The roles are the plan's
240
+ * assignments now, so the rules notify its assigned roles — except on an
241
+ * unrestricted plan, whose tenant-user assignment is there for visibility
242
+ * only: notifying it would mail the whole tenant about a plan v1 mailed
243
+ * nobody about. Its explicit roles, if any, are named instead.
244
+ *
245
+ * Members of `od-admin` read every plan and were therefore notified of every
246
+ * plan; that is deliberately not carried over.
247
+ */
248
+ export declare function v1Recipients(access: V1Access, explicitRoleIds: string[]): Pick<ServiceNotificationRule, "assignedRoles" | "userIds" | "roleIds">;
249
+ /**
250
+ * v1's notifications as v2 rules.
251
+ *
252
+ * v1 notified at every occurrence (the scheduler's `on` job, for every enabled
253
+ * plan) and, with a `notifyBeforeDue`, once more ahead of it. Both become a
254
+ * rule, with the recipients of {@link v1Recipients}.
255
+ *
256
+ * Ids are minted, not random: they are the dedup key of a sent message.
257
+ */
258
+ export declare function notificationRules(key: string, notifyBeforeDue: unknown, who: Pick<ServiceNotificationRule, "assignedRoles" | "userIds" | "roleIds">): RuleConversion;
259
+ export type ExecutionFate = {
260
+ fate: "completed";
261
+ completedAt: Date;
262
+ } | {
263
+ fate: "open";
264
+ } | {
265
+ fate: "abandoned";
266
+ reason: string;
267
+ };
268
+ /**
269
+ * Whether a v1 execution is a protocol, a run still in progress, or a run
270
+ * somebody gave up on.
271
+ *
272
+ * v2 has no status column — `completedAt` is the whole state. An abandoned
273
+ * run therefore has no faithful v2 form: without `completedAt` it would come
274
+ * back as a resumable run ("Durchführung starten" picks up any open one), and
275
+ * with it, it would claim maintenance nobody did. It is not migrated.
276
+ *
277
+ * `status` alone cannot tell, because v1 rewrites it at every server start:
278
+ * every execution with a `finishedAt` becomes `completed`, including the
279
+ * `terminated` ones a re-run closed. For a plan's execution the runner only
280
+ * ever completed one with all steps done, so a finished plan run with an open
281
+ * step is one of those terminated runs. A direct maintenance may legitimately
282
+ * finish with skipped steps, so the inference is not made there.
283
+ */
284
+ export declare function classifyExecution(execution: Maintenance_Schedule_Execution, steps: Maintenance_Schedule_Execution_Step[], forPlan: boolean): ExecutionFate;
285
+ /** What reading v1 needs of the config — `verify.ts` has no more than this. */
286
+ type ReadScope = Pick<MigrationConfig, "tenantId" | "batchSize">;
287
+ /** The execution-step rows of every execution, in v1 order. */
288
+ export declare function executionStepsByExecution(config: ReadScope): Promise<Map<string, Maintenance_Schedule_Execution_Step[]>>;
289
+ /**
290
+ * Which v1 plan an execution belongs to.
291
+ *
292
+ * Executions from before 2025-08 name their template and source but no plan;
293
+ * v1 links them at every boot to the plan with that template and source
294
+ * (`features/openservice/schedules/reassignScheduleExecutions.ts`). The
295
+ * migration applies the same rule rather than turning them into direct
296
+ * maintenances.
297
+ */
298
+ export declare class PlanIndex {
299
+ private readonly byTemplateAndSource;
300
+ private readonly plans;
301
+ static load(config: ReadScope): Promise<PlanIndex>;
302
+ plan(v1PlanId: string): Maintenance_Schedule | undefined;
303
+ /** The v1 plan id an execution belongs to, if any. */
304
+ resolve(execution: Maintenance_Schedule_Execution): string | undefined;
305
+ }
306
+ export {};