@jsb188/schedule 1.1.11

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 (60) hide show
  1. package/package.json +61 -0
  2. package/src/constants/schedule.ts +549 -0
  3. package/src/css.d.ts +7 -0
  4. package/src/libs/gantt-geometry.ts +771 -0
  5. package/src/libs/gantt-histogram.ts +124 -0
  6. package/src/libs/gantt-keyboard.ts +113 -0
  7. package/src/libs/gantt-state.ts +57 -0
  8. package/src/libs/gantt-url.ts +63 -0
  9. package/src/modules/Gantt.helpers.ts +138 -0
  10. package/src/modules/Gantt.tsx +719 -0
  11. package/src/types/schedule.d.ts +1149 -0
  12. package/src/ui/ActivityFormUI.tsx +133 -0
  13. package/src/ui/GanttEditorsUI.tsx +102 -0
  14. package/src/ui/GanttHistogramUI.tsx +236 -0
  15. package/src/ui/GanttUI.tsx +792 -0
  16. package/src/ui/ProjectFormUI.tsx +273 -0
  17. package/src/ui/ProjectMobileListUI.tsx +80 -0
  18. package/src/ui/ProjectToolbarUI.tsx +54 -0
  19. package/src/ui/RelationshipListUI.tsx +176 -0
  20. package/src/ui/ScheduleRunUI.tsx +173 -0
  21. package/src/ui/ScheduleSettingsUI.tsx +420 -0
  22. package/src/utils/coverage.helpers.ts +679 -0
  23. package/src/utils/coverage.ts +630 -0
  24. package/src/utils/cpm.helpers.ts +674 -0
  25. package/src/utils/cpm.ts +907 -0
  26. package/src/utils/cpmLeveling.helpers.ts +564 -0
  27. package/src/utils/cpmLeveling.ts +367 -0
  28. package/src/utils/defaults.ts +8 -0
  29. package/src/utils/eligibility.ts +457 -0
  30. package/src/utils/planCsv.ts +344 -0
  31. package/src/utils/predecessorText.ts +96 -0
  32. package/src/utils/recurrence.ts +616 -0
  33. package/src/utils/request.ts +153 -0
  34. package/src/utils/resource.ts +182 -0
  35. package/src/utils/rule.ts +216 -0
  36. package/src/utils/run.ts +43 -0
  37. package/src/utils/series.ts +161 -0
  38. package/src/utils/slot.ts +208 -0
  39. package/src/utils/workTime.ts +1382 -0
  40. package/tests/coverage.fixtures.ts +111 -0
  41. package/tests/coverage.test.ts +503 -0
  42. package/tests/cpm.bench.test.ts +154 -0
  43. package/tests/cpm.test.ts +354 -0
  44. package/tests/cpmCorrectness.test.ts +327 -0
  45. package/tests/cpmLeveling.test.ts +471 -0
  46. package/tests/eligibility.test.ts +320 -0
  47. package/tests/gantt-geometry.test.ts +367 -0
  48. package/tests/gantt-histogram.test.ts +78 -0
  49. package/tests/gantt-keyboard.test.ts +69 -0
  50. package/tests/helpers/cpmFixtures.ts +101 -0
  51. package/tests/projectInputs.test.ts +165 -0
  52. package/tests/recurrence.test.ts +68 -0
  53. package/tests/request.test.ts +99 -0
  54. package/tests/resource.test.ts +95 -0
  55. package/tests/rule.test.ts +98 -0
  56. package/tests/series.test.ts +120 -0
  57. package/tests/workTime.test.ts +1007 -0
  58. package/tests/workTimeContracts.test.ts +111 -0
  59. package/tsconfig.json +13 -0
  60. package/vitest.config.ts +8 -0
@@ -0,0 +1,1149 @@
1
+ import type {
2
+ SCHEDULE_ASSIGNMENT_VIA_ENUMS,
3
+ SCHEDULE_ASSIGNMENT_RELEASE_REASON_ENUMS,
4
+ SCHEDULE_REQUEST_KIND_ENUMS,
5
+ SCHEDULE_REQUEST_STATUS_ENUMS,
6
+ SCHEDULE_PROJECT_RUN_KIND_ENUMS,
7
+ SCHEDULE_PROJECT_RUN_TRIGGER_ENUMS,
8
+ SCHEDULE_NOTIFICATION_STATUS_ENUMS,
9
+ SCHEDULE_NOTIFICATION_EVENT_KIND_ENUMS,
10
+ SCHEDULE_ACTIVITY_STATUS_ENUMS,
11
+ SCHEDULE_ACTIVITY_TYPE_ENUMS,
12
+ SCHEDULE_ASSIGNMENT_STATUS_ENUMS,
13
+ SCHEDULE_CONSTRAINT_TYPE_ENUMS,
14
+ SCHEDULE_DEFAULT_VIEW_ENUMS,
15
+ SCHEDULE_DIAGNOSTIC_CODE_ENUMS,
16
+ SCHEDULE_LAG_CALENDAR_ENUMS,
17
+ SCHEDULE_MODE_ENUMS,
18
+ SCHEDULE_OCCURRENCE_KIND_ENUMS,
19
+ SCHEDULE_OCCURRENCE_STATUS_ENUMS,
20
+ SCHEDULE_PROGRESS_LOGIC_ENUMS,
21
+ SCHEDULE_PROJECT_RUN_STATUS_ENUMS,
22
+ SCHEDULE_PROJECT_STATUS_ENUMS,
23
+ SCHEDULE_RECURRENCE_FREQ_ENUMS,
24
+ SCHEDULE_RELATIONSHIP_TYPE_ENUMS,
25
+ SCHEDULE_RESOURCE_KIND_ENUMS,
26
+ SCHEDULE_RULE_KIND_ENUMS,
27
+ SCHEDULE_RULE_SEVERITY_ENUMS,
28
+ SCHEDULE_SOURCE_KIND_ENUMS,
29
+ SCHEDULE_SOURCE_REVIEW_STATUS_ENUMS,
30
+ SCHEDULE_CRITICALITY_MODE_ENUMS,
31
+ SCHEDULE_LEVELING_PRIORITY_RULE_ENUMS,
32
+ SCHEDULE_DIAGNOSTIC_SEVERITY_ENUMS,
33
+ SCHEDULE_ELIGIBILITY_REASON_ENUMS,
34
+ SCHEDULE_COVERAGE_DIAGNOSTIC_CODE_ENUMS,
35
+ SCHEDULE_TIME_OFF_STATUS_ENUMS,
36
+ SCHEDULE_NOTIFY_CHANNEL_ENUMS,
37
+ SCHEDULE_ELIGIBILITY_VIOLATION_CODE_ENUMS,
38
+ SCHEDULE_ACTOR_WINDOW_VIOLATION_CODE_ENUMS,
39
+ } from '../constants/schedule.ts';
40
+
41
+ /**
42
+ * Enums
43
+ */
44
+
45
+ export type ScheduleModeEnum = (typeof SCHEDULE_MODE_ENUMS)[number];
46
+ export type ScheduleDefaultViewEnum =
47
+ (typeof SCHEDULE_DEFAULT_VIEW_ENUMS)[number];
48
+ export type ScheduleResourceKindEnum =
49
+ (typeof SCHEDULE_RESOURCE_KIND_ENUMS)[number];
50
+ export type ScheduleOccurrenceKindEnum =
51
+ (typeof SCHEDULE_OCCURRENCE_KIND_ENUMS)[number];
52
+ export type ScheduleOccurrenceStatusEnum =
53
+ (typeof SCHEDULE_OCCURRENCE_STATUS_ENUMS)[number];
54
+ export type ScheduleAssignmentStatusEnum =
55
+ (typeof SCHEDULE_ASSIGNMENT_STATUS_ENUMS)[number];
56
+ export type ScheduleRuleKindEnum = (typeof SCHEDULE_RULE_KIND_ENUMS)[number];
57
+ export type ScheduleRuleSeverityEnum =
58
+ (typeof SCHEDULE_RULE_SEVERITY_ENUMS)[number];
59
+ export type ScheduleRecurrenceFreqEnum =
60
+ (typeof SCHEDULE_RECURRENCE_FREQ_ENUMS)[number];
61
+ export type ScheduleProjectStatusEnum =
62
+ (typeof SCHEDULE_PROJECT_STATUS_ENUMS)[number];
63
+ export type ScheduleActivityTypeEnum =
64
+ (typeof SCHEDULE_ACTIVITY_TYPE_ENUMS)[number];
65
+ export type ScheduleActivityStatusEnum =
66
+ (typeof SCHEDULE_ACTIVITY_STATUS_ENUMS)[number];
67
+
68
+ export type ScheduleRelationshipTypeEnum =
69
+ (typeof SCHEDULE_RELATIONSHIP_TYPE_ENUMS)[number];
70
+ export type ScheduleConstraintTypeEnum =
71
+ (typeof SCHEDULE_CONSTRAINT_TYPE_ENUMS)[number];
72
+ export type ScheduleProgressLogicEnum =
73
+ (typeof SCHEDULE_PROGRESS_LOGIC_ENUMS)[number];
74
+ export type ScheduleLagCalendarEnum =
75
+ (typeof SCHEDULE_LAG_CALENDAR_ENUMS)[number];
76
+
77
+ export type ScheduleProjectRunStatusEnum =
78
+ (typeof SCHEDULE_PROJECT_RUN_STATUS_ENUMS)[number];
79
+ export type ScheduleDiagnosticCodeEnum =
80
+ (typeof SCHEDULE_DIAGNOSTIC_CODE_ENUMS)[number];
81
+ export type ScheduleSourceKindEnum =
82
+ (typeof SCHEDULE_SOURCE_KIND_ENUMS)[number];
83
+ export type ScheduleSourceReviewStatusEnum =
84
+ (typeof SCHEDULE_SOURCE_REVIEW_STATUS_ENUMS)[number];
85
+
86
+ /**
87
+ * Every *Data interface below models a database row, so ids are the shapes
88
+ * Postgres hands back. Client-facing ids are serialized GenericID strings and
89
+ * live on the GraphQL types instead, never on these.
90
+ */
91
+ export type ScheduleId = number | bigint;
92
+
93
+ export type ScheduleAssignmentViaEnum =
94
+ (typeof SCHEDULE_ASSIGNMENT_VIA_ENUMS)[number];
95
+ export type ScheduleAssignmentReleaseReasonEnum =
96
+ (typeof SCHEDULE_ASSIGNMENT_RELEASE_REASON_ENUMS)[number];
97
+ export type ScheduleRequestKindEnum =
98
+ (typeof SCHEDULE_REQUEST_KIND_ENUMS)[number];
99
+ export type ScheduleRequestStatusEnum =
100
+ (typeof SCHEDULE_REQUEST_STATUS_ENUMS)[number];
101
+ export type ScheduleProjectRunKindEnum =
102
+ (typeof SCHEDULE_PROJECT_RUN_KIND_ENUMS)[number];
103
+ export type ScheduleProjectRunTriggerEnum =
104
+ (typeof SCHEDULE_PROJECT_RUN_TRIGGER_ENUMS)[number];
105
+ export type ScheduleNotificationStatusEnum =
106
+ (typeof SCHEDULE_NOTIFICATION_STATUS_ENUMS)[number];
107
+ export type ScheduleNotificationEventKindEnum =
108
+ (typeof SCHEDULE_NOTIFICATION_EVENT_KIND_ENUMS)[number];
109
+
110
+ export interface ScheduleRequestPolicyObj {
111
+ autoApproveClaims: boolean;
112
+ autoApproveDrops: boolean;
113
+ requireCounterpartyConsent: boolean;
114
+ minNoticeHours: number;
115
+ requestExpiryHours: number;
116
+ }
117
+
118
+ /**
119
+ * Base access policy shared with Sheets and Notes; grants live in
120
+ * access_grants rows
121
+ */
122
+ export interface ScheduleAccessObj {
123
+ team?: string | null;
124
+ public?: string | null;
125
+ network?: string | null;
126
+ }
127
+
128
+ /**
129
+ * Working-time calendars
130
+ */
131
+
132
+ // "HH:mm" local wall-clock bounds of one working interval, end exclusive
133
+ export type ScheduleWorkInterval = [string, string];
134
+
135
+ // Working intervals per JavaScript weekday key ("0" = Sunday); a missing or
136
+ // empty key is a non-working day
137
+ export type ScheduleWeekHoursObj = Partial<
138
+ Record<'0' | '1' | '2' | '3' | '4' | '5' | '6', ScheduleWorkInterval[]>
139
+ >;
140
+
141
+ // Dated overrides keyed "YYYY-MM-DD"; an empty list is a holiday
142
+ export type ScheduleWorkExceptionsObj = Record<string, ScheduleWorkInterval[]>;
143
+
144
+ /**
145
+ * The calendar facts every engine needs; built from a work calendar row plus
146
+ * its exception rows, or from the platform standard when a project has none.
147
+ */
148
+ export interface ScheduleWorkCalendarDef {
149
+ id: string;
150
+ timeZone: string;
151
+ weekHours: ScheduleWeekHoursObj;
152
+ exceptions?: ScheduleWorkExceptionsObj | null;
153
+ // Working minutes one "day" of duration means for display and conversion
154
+ minutesPerDay?: number | null;
155
+ }
156
+
157
+ export interface ScheduleWorkCalendarData {
158
+ version: number | bigint;
159
+ id: ScheduleId;
160
+ organizationId: ScheduleId;
161
+ key: string | null;
162
+ name: string;
163
+ description: string | null;
164
+ timeZone: string;
165
+ weekHours: ScheduleWeekHoursObj;
166
+ minutesPerDay: number;
167
+ isDefault: boolean;
168
+ deletedAt: Date | string | null;
169
+ createdAt: Date | string;
170
+ updatedAt: Date | string;
171
+ }
172
+
173
+ export interface ScheduleWorkCalendarExceptionData {
174
+ id: ScheduleId;
175
+ organizationId: ScheduleId;
176
+ workCalendarId: ScheduleId;
177
+ date: Date | string;
178
+ hours: ScheduleWorkInterval[];
179
+ note: string | null;
180
+ createdAt: Date | string;
181
+ updatedAt: Date | string;
182
+ }
183
+
184
+ /**
185
+ * Resources
186
+ */
187
+
188
+ export interface ScheduleQualificationObj {
189
+ key: string; // 1..60 chars, unique per resource
190
+ expiresAt: string | null; // normalized ISO instant, or null = never expires
191
+ }
192
+
193
+ export interface ScheduleResourceConfigObj {
194
+ qualifications: ScheduleQualificationObj[]; // LABOR only, else []
195
+ roles: string[]; // LABOR only, sorted
196
+ tags: string[]; // any kind, sorted
197
+ ageGroup: string | null; // SPACE only: UI default key for new demand rows; the engine never reads it
198
+ notify: ScheduleNotifyPrefsObj | null; // LABOR only; read by schedule_notify, never by the engine
199
+ }
200
+
201
+ export interface ScheduleResourceData {
202
+ version: number | bigint;
203
+ canLevel: boolean;
204
+ id: ScheduleId;
205
+ organizationId: ScheduleId;
206
+ siteId: ScheduleId | null;
207
+ accountId: ScheduleId | null;
208
+ workCalendarId: ScheduleId | null;
209
+ kind: ScheduleResourceKindEnum;
210
+ key: string;
211
+ name: string;
212
+ // Largest units one day may hold for LABOR and EQUIPMENT (minutes)
213
+ maxUnitsPerDay: number | null;
214
+ // Concurrent occupancy for SPACE; null means unbounded
215
+ capacity: number | null;
216
+ unitOfMeasure: string | null;
217
+ config: ScheduleResourceConfigObj;
218
+ ordinal: number;
219
+ retiredAt: Date | string | null;
220
+ createdAt: Date | string;
221
+ updatedAt: Date | string;
222
+ }
223
+
224
+ export interface ScheduleResourceAvailabilityData {
225
+ id: ScheduleId;
226
+ organizationId: ScheduleId;
227
+ resourceId: ScheduleId;
228
+ startsOn: Date | string;
229
+ endsOn: Date | string | null;
230
+ maxUnitsPerDay: number;
231
+ note: string | null;
232
+ createdAt: Date | string;
233
+ updatedAt: Date | string;
234
+ }
235
+
236
+ /**
237
+ * Calendars, recurring series and coverage occurrences
238
+ */
239
+
240
+ export interface ScheduleCalendarData {
241
+ revision: number | bigint;
242
+ version: number | bigint;
243
+ id: ScheduleId;
244
+ organizationId: ScheduleId;
245
+ name: string;
246
+ description: string | null;
247
+ timeZone: string;
248
+ siteId: ScheduleId | null;
249
+ workCalendarId: ScheduleId | null;
250
+ access: ScheduleAccessObj | null;
251
+ color: string | null;
252
+ settings: Record<string, unknown>;
253
+ ordinal: number;
254
+ createdByAccountId: ScheduleId | null;
255
+ deletedAt: Date | string | null;
256
+ createdAt: Date | string;
257
+ updatedAt: Date | string;
258
+ }
259
+
260
+ /**
261
+ * One recurrence rule, stored as schedule_series."recurrence" JSONB.
262
+ *
263
+ * - byWeekday uses the JavaScript convention (0 = Sunday ... 6 = Saturday)
264
+ * and applies to WEEKLY rules
265
+ * - byMonthDay applies to MONTHLY and YEARLY rules; -1 means the last day
266
+ * - byMonth (1 = January ... 12 = December) applies to YEARLY rules
267
+ * - count and until both bound the series; whichever is reached first wins
268
+ */
269
+ export interface ScheduleRecurrenceObj {
270
+ freq: ScheduleRecurrenceFreqEnum;
271
+ interval?: number | null;
272
+ byWeekday?: number[] | null;
273
+ byMonthDay?: number[] | null;
274
+ byMonth?: number[] | null;
275
+ count?: number | null;
276
+ until?: string | null;
277
+ }
278
+
279
+ /**
280
+ * Who may fill a slot. Every listed requirement must hold; an empty predicate
281
+ * means anyone.
282
+ */
283
+ export interface ScheduleSlotPredicateObj {
284
+ roles?: string[] | null;
285
+ qualifications?: string[] | null;
286
+ tags?: string[] | null;
287
+ }
288
+
289
+ export interface ScheduleSlotTemplateObj {
290
+ key: string;
291
+ label: string | null;
292
+ requiredCount: number;
293
+ predicate: ScheduleSlotPredicateObj | null;
294
+ ordinal: number;
295
+ }
296
+
297
+ export interface ScheduleSeriesData {
298
+ finishedAt: Date | string | null;
299
+ version: number | bigint;
300
+ id: ScheduleId;
301
+ organizationId: ScheduleId;
302
+ calendarId: ScheduleId;
303
+ resourceId: ScheduleId | null;
304
+ kind: ScheduleOccurrenceKindEnum;
305
+ title: string;
306
+ note: string | null;
307
+ location: string | null;
308
+ recurrence: ScheduleRecurrenceObj;
309
+ timeZone: string;
310
+ startsAt: Date | string;
311
+ endsAt: Date | string | null;
312
+ durationMinutes: number;
313
+ allDay: boolean;
314
+ slotTemplate: ScheduleSlotTemplateObj[];
315
+ active: boolean;
316
+ materializedThrough: Date | string | null;
317
+ createdByAccountId: ScheduleId | null;
318
+ deletedAt: Date | string | null;
319
+ createdAt: Date | string;
320
+ updatedAt: Date | string;
321
+ }
322
+
323
+ export interface ScheduleOccurrenceData {
324
+ source: ScheduleSourceObj | null;
325
+ id: ScheduleId;
326
+ organizationId: ScheduleId;
327
+ calendarId: ScheduleId;
328
+ seriesId: ScheduleId | null;
329
+ recurrenceDate: Date | string | null;
330
+ resourceId: ScheduleId | null;
331
+ kind: ScheduleOccurrenceKindEnum;
332
+ title: string;
333
+ note: string | null;
334
+ location: string | null;
335
+ startAt: Date | string;
336
+ endAt: Date | string;
337
+ timeZone: string;
338
+ allDay: boolean;
339
+ status: ScheduleOccurrenceStatusEnum;
340
+ detached: boolean;
341
+ version: number | bigint;
342
+ createdByAccountId: ScheduleId | null;
343
+ publishedAt: Date | string | null;
344
+ canceledAt: Date | string | null;
345
+ deletedAt: Date | string | null;
346
+ createdAt: Date | string;
347
+ updatedAt: Date | string;
348
+ // Attached by reads that load child rows
349
+ slots?: ScheduleSlotData[];
350
+ assignments?: ScheduleAssignmentData[];
351
+ }
352
+
353
+ export interface ScheduleSlotData {
354
+ id: ScheduleId;
355
+ organizationId: ScheduleId;
356
+ occurrenceId: ScheduleId;
357
+ key: string;
358
+ label: string | null;
359
+ requiredCount: number;
360
+ predicate: ScheduleSlotPredicateObj | null;
361
+ ordinal: number;
362
+ }
363
+
364
+ export interface ScheduleAssignmentData {
365
+ releasedByAccountId: ScheduleId | null;
366
+ releasedAt: Date | string | null;
367
+ assignedVia: ScheduleAssignmentViaEnum;
368
+ releaseReason: ScheduleAssignmentReleaseReasonEnum | null;
369
+ requestId: ScheduleId | null;
370
+ id: ScheduleId;
371
+ organizationId: ScheduleId;
372
+ occurrenceId: ScheduleId;
373
+ resourceId: ScheduleId;
374
+ slotKey: string | null;
375
+ status: ScheduleAssignmentStatusEnum;
376
+ note: string | null;
377
+ assignedByAccountId: ScheduleId | null;
378
+ createdAt: Date | string;
379
+ updatedAt: Date | string;
380
+ }
381
+
382
+ export interface ScheduleDemandData {
383
+ id: ScheduleId;
384
+ organizationId: ScheduleId;
385
+ calendarId: ScheduleId;
386
+ resourceId: ScheduleId;
387
+ key: string;
388
+ quantity: number;
389
+ startAt: Date | string;
390
+ endAt: Date | string;
391
+ note: string | null;
392
+ createdAt: Date | string;
393
+ updatedAt: Date | string;
394
+ }
395
+
396
+ /**
397
+ * Coverage rules and violations
398
+ */
399
+
400
+ export type ScheduleRuleConfigObj =
401
+ | Record<string, never> // REQUIRED_COUNT, ROOM_CAPACITY, ELIGIBILITY: severity only
402
+ | ScheduleDerivedCountConfigObj
403
+ | ScheduleOperatingHoursConfigObj
404
+ | ScheduleActorWindowConfigObj;
405
+
406
+ export interface ScheduleRuleData {
407
+ id: ScheduleId;
408
+ organizationId: ScheduleId;
409
+ calendarId: ScheduleId | null;
410
+ resourceId: ScheduleId | null;
411
+ kind: ScheduleRuleKindEnum;
412
+ key: string;
413
+ label: string;
414
+ config: ScheduleRuleConfigObj;
415
+ severity: ScheduleRuleSeverityEnum;
416
+ active: boolean;
417
+ ordinal: number;
418
+ createdAt: Date | string;
419
+ updatedAt: Date | string;
420
+ }
421
+
422
+ export interface ScheduleViolationData {
423
+ acknowledgedByAccountId: ScheduleId | null;
424
+ acknowledgedAt: Date | string | null;
425
+ createdAt: Date | string;
426
+ violationKey: string;
427
+ identityKey: string;
428
+ code: ScheduleCoverageViolationCode | null;
429
+ slotKey: string | null;
430
+ degree: number;
431
+ id: ScheduleId;
432
+ organizationId: ScheduleId;
433
+ calendarId: ScheduleId;
434
+ ruleId: ScheduleId | null;
435
+ occurrenceId: ScheduleId | null;
436
+ resourceId: ScheduleId | null;
437
+ kind: ScheduleRuleKindEnum;
438
+ severity: ScheduleRuleSeverityEnum;
439
+ startAt: Date | string;
440
+ endAt: Date | string;
441
+ message: string;
442
+ detail: Record<string, unknown>;
443
+ evaluatedAt: Date | string;
444
+ }
445
+
446
+ /**
447
+ * Projects (PROJECT mode)
448
+ */
449
+
450
+ export interface ScheduleSchedulingOptionsObj {
451
+ progressLogic?: ScheduleProgressLogicEnum | null; // default RETAINED
452
+ lagCalendar?: ScheduleLagCalendarEnum | null; // default PREDECESSOR
453
+ criticalFloatThresholdMinutes?: number | null; // default 0
454
+ criticalityMode?: ScheduleCriticalityModeEnum | null; // default FLOAT
455
+ autoSchedule?: boolean | null; // decision #1; read by the server, ignored by the engine
456
+ leveling?: ScheduleLevelingOptionsObj | null;
457
+ }
458
+
459
+ /**
460
+ * Where a row came from. Written by imports and by the RFP extraction
461
+ * pipeline, so a planner can see and review machine-proposed scope.
462
+ */
463
+ export interface ScheduleSourceObj {
464
+ kind: ScheduleSourceKindEnum;
465
+ documentId?: string | null;
466
+ // Page or section reference and the quoted passage that produced the row
467
+ reference?: string | null;
468
+ quote?: string | null;
469
+ confidence?: number | null;
470
+ reviewStatus?: ScheduleSourceReviewStatusEnum | null;
471
+ reviewedByAccountId?: string | null;
472
+ reviewedAt?: string | null;
473
+ }
474
+
475
+ export interface ScheduleProjectData {
476
+ revision: number | bigint;
477
+ networkRevision: number | bigint;
478
+ runSequence: number | bigint;
479
+ latestRunId: ScheduleId | null;
480
+ id: ScheduleId;
481
+ organizationId: ScheduleId;
482
+ siteId: ScheduleId | null;
483
+ workCalendarId: ScheduleId | null;
484
+ currentBaselineId: ScheduleId | null;
485
+ code: string;
486
+ name: string;
487
+ description: string | null;
488
+ status: ScheduleProjectStatusEnum;
489
+ timeZone: string;
490
+ plannedStartAt: Date | string;
491
+ mustFinishByAt: Date | string | null;
492
+ dataDateAt: Date | string;
493
+ schedulingOptions: ScheduleSchedulingOptionsObj;
494
+ // Filled by the last successful schedule run
495
+ scheduledFinishAt: Date | string | null;
496
+ lastScheduledAt: Date | string | null;
497
+ access: ScheduleAccessObj | null;
498
+ source: ScheduleSourceObj | null;
499
+ version: number | bigint;
500
+ createdByAccountId: ScheduleId | null;
501
+ deletedAt: Date | string | null;
502
+ createdAt: Date | string;
503
+ updatedAt: Date | string;
504
+ }
505
+
506
+ export interface ScheduleWbsNodeData {
507
+ id: ScheduleId;
508
+ organizationId: ScheduleId;
509
+ projectId: ScheduleId;
510
+ parentId: ScheduleId | null;
511
+ code: string;
512
+ name: string;
513
+ // Materialized ancestry "/<rootId>/<childId>/" including the node itself
514
+ path: string;
515
+ depth: number;
516
+ ordinal: number;
517
+ deletedAt: Date | string | null;
518
+ createdAt: Date | string;
519
+ updatedAt: Date | string;
520
+ }
521
+
522
+ export interface ScheduleConstraintObj {
523
+ type: ScheduleConstraintTypeEnum;
524
+ at: Date | string | null;
525
+ }
526
+
527
+ export interface ScheduleActivityData {
528
+ startAt: Date | string | null;
529
+ finishAt: Date | string | null;
530
+ levelingDelayMinutes: number;
531
+ levelingConstrainedByResourceId: ScheduleId | null;
532
+ levelingPriority: number;
533
+ id: ScheduleId;
534
+ organizationId: ScheduleId;
535
+ projectId: ScheduleId;
536
+ wbsId: ScheduleId | null;
537
+ workCalendarId: ScheduleId | null;
538
+ code: string;
539
+ name: string;
540
+ description: string | null;
541
+ type: ScheduleActivityTypeEnum;
542
+ status: ScheduleActivityStatusEnum;
543
+ // Working minutes on the activity calendar
544
+ plannedDurationMinutes: number;
545
+ remainingDurationMinutes: number;
546
+ primaryConstraintType: ScheduleConstraintTypeEnum | null;
547
+ primaryConstraintAt: Date | string | null;
548
+ secondaryConstraintType: ScheduleConstraintTypeEnum | null;
549
+ secondaryConstraintAt: Date | string | null;
550
+ actualStartAt: Date | string | null;
551
+ actualFinishAt: Date | string | null;
552
+ // Engine outputs from the last schedule run
553
+ earlyStartAt: Date | string | null;
554
+ earlyFinishAt: Date | string | null;
555
+ lateStartAt: Date | string | null;
556
+ lateFinishAt: Date | string | null;
557
+ totalFloatMinutes: number | null;
558
+ freeFloatMinutes: number | null;
559
+ isCritical: boolean;
560
+ codes: Record<string, string>;
561
+ source: ScheduleSourceObj | null;
562
+ ordinal: number;
563
+ version: number | bigint;
564
+ createdByAccountId: ScheduleId | null;
565
+ deletedAt: Date | string | null;
566
+ createdAt: Date | string;
567
+ updatedAt: Date | string;
568
+ }
569
+
570
+ export interface ScheduleRelationshipData {
571
+ isDriving: boolean;
572
+ id: ScheduleId;
573
+ organizationId: ScheduleId;
574
+ projectId: ScheduleId;
575
+ predecessorId: ScheduleId;
576
+ successorId: ScheduleId;
577
+ type: ScheduleRelationshipTypeEnum;
578
+ lagMinutes: number;
579
+ createdByAccountId: ScheduleId | null;
580
+ createdAt: Date | string;
581
+ updatedAt: Date | string;
582
+ }
583
+
584
+ export interface ScheduleActivityAssignmentData {
585
+ id: ScheduleId;
586
+ organizationId: ScheduleId;
587
+ projectId: ScheduleId;
588
+ activityId: ScheduleId;
589
+ resourceId: ScheduleId;
590
+ // Units are working minutes for LABOR and EQUIPMENT, quantities for MATERIAL
591
+ plannedUnits: number;
592
+ unitsPerDay: number | null;
593
+ actualUnits: number;
594
+ remainingUnits: number;
595
+ createdAt: Date | string;
596
+ updatedAt: Date | string;
597
+ }
598
+
599
+ export interface ScheduleBaselineData {
600
+ runId: ScheduleId;
601
+ id: ScheduleId;
602
+ organizationId: ScheduleId;
603
+ projectId: ScheduleId;
604
+ name: string;
605
+ note: string | null;
606
+ dataDateAt: Date | string;
607
+ createdByAccountId: ScheduleId | null;
608
+ createdAt: Date | string;
609
+ }
610
+
611
+ export interface ScheduleBaselineActivityData {
612
+ projectId: ScheduleId;
613
+ id: ScheduleId;
614
+ organizationId: ScheduleId;
615
+ baselineId: ScheduleId;
616
+ activityId: ScheduleId | null;
617
+ code: string;
618
+ name: string;
619
+ plannedStartAt: Date | string | null;
620
+ plannedFinishAt: Date | string | null;
621
+ plannedDurationMinutes: number;
622
+ totalFloatMinutes: number | null;
623
+ plannedUnits: number;
624
+ percentComplete: number;
625
+ }
626
+
627
+ export interface ScheduleProjectRunStatsObj {
628
+ activityCount: number;
629
+ relationshipCount: number;
630
+ criticalCount: number;
631
+ openStartCount: number;
632
+ openFinishCount: number;
633
+ negativeFloatCount: number;
634
+ constraintOverrideCount: number;
635
+ cycleCount: number; // SCCs of size ≥ 2
636
+ longestPathCount: number; // activities on the longest path (computed in both modes)
637
+ scheduledFinishAt: string | null; // ISO of result.scheduledFinishAt
638
+ earlyFinishAt: string | null; // ISO of result.earlyFinishAt
639
+ leveled: boolean; // leveling ran
640
+ leveledCount: number; // activities with levelingDelayMinutes > 0 (milestones included)
641
+ totalLevelingDelayMinutes: number;
642
+ finishDelayMinutes: number; // wm(defaultCal, earlyFinishAt, scheduledFinishAt); 0 when not leveled
643
+ overallocatedResourceDayCount: number; // (resource, day) cells with used + external > available × (1 + tol) after leveling
644
+ levelingExceededFloatCount: number;
645
+ levelingExceededHorizonCount: number;
646
+ diagnosticCounts: Partial<Record<ScheduleDiagnosticCodeEnum, number>>;
647
+ diagnosticsTruncated: boolean;
648
+ }
649
+
650
+ export interface ScheduleDiagnosticObj {
651
+ code: ScheduleDiagnosticCodeEnum;
652
+ severity: ScheduleDiagnosticSeverityEnum;
653
+ message: string;
654
+ activityId?: string | null;
655
+ relatedActivityId?: string | null;
656
+ activityIds?: string[] | null; // CYCLE members, overallocation contributors (≤ SCHEDULE_DIAGNOSTIC_MAX_ACTIVITY_IDS)
657
+ resourceId?: string | null;
658
+ calendarId?: string | null;
659
+ fromDate?: string | null; // 'YYYY-MM-DD' local to the resource/activity calendar
660
+ toDate?: string | null;
661
+ demandUnits?: number | null;
662
+ availableUnits?: number | null;
663
+ minutes?: number | null; // delay / float / lag amount the message talks about
664
+ }
665
+
666
+ export interface ScheduleProjectRunData {
667
+ id: ScheduleId;
668
+ organizationId: ScheduleId;
669
+ projectId: ScheduleId;
670
+ sequence: number | bigint;
671
+ kind: ScheduleProjectRunKindEnum;
672
+ trigger: ScheduleProjectRunTriggerEnum;
673
+ networkRevision: number | bigint | null;
674
+ options: ScheduleSchedulingOptionsObj;
675
+ progress: ScheduleRunProgressObj;
676
+ scheduledFinishAt: Date | string | null;
677
+ jobId: ScheduleId | null;
678
+ claimToken: string | null;
679
+ cancelRequestedAt: Date | string | null;
680
+ lastError: string | null;
681
+ revision: number | bigint;
682
+ createdAt: Date | string;
683
+ updatedAt: Date | string;
684
+ status: ScheduleProjectRunStatusEnum;
685
+ dataDateAt: Date | string;
686
+ stats: ScheduleProjectRunStatsObj | null;
687
+ diagnostics: ScheduleDiagnosticObj[];
688
+ triggeredByAccountId: ScheduleId | null;
689
+ startedAt: Date | string | null;
690
+ finishedAt: Date | string | null;
691
+ }
692
+
693
+ export interface ScheduleRunProgressObj {
694
+ stage?: 'LOADING' | 'CPM' | 'LEVELING' | 'PERSISTING';
695
+ percent?: number | null;
696
+ updatedAt?: string;
697
+ }
698
+
699
+ export interface ScheduleRequestData {
700
+ autoApproved: boolean;
701
+ id: ScheduleId;
702
+ organizationId: ScheduleId;
703
+ calendarId: ScheduleId;
704
+ kind: ScheduleRequestKindEnum;
705
+ status: ScheduleRequestStatusEnum;
706
+ occurrenceId: ScheduleId;
707
+ slotKey: string | null;
708
+ sourceAssignmentId: ScheduleId | null;
709
+ targetAssignmentId: ScheduleId | null;
710
+ requesterResourceId: ScheduleId;
711
+ requesterAccountId: ScheduleId | null;
712
+ counterpartyResourceId: ScheduleId | null;
713
+ counterpartyRespondedAt: Date | string | null;
714
+ targetOccurrenceId: ScheduleId | null;
715
+ subjectStartAt: Date | string;
716
+ eligibility: Record<string, unknown>;
717
+ version: number | bigint;
718
+ reason: string | null;
719
+ decidedByAccountId: ScheduleId | null;
720
+ decidedAt: Date | string | null;
721
+ decisionNote: string | null;
722
+ expiresAt: Date | string;
723
+ closedAt: Date | string | null;
724
+ createdAt: Date | string;
725
+ updatedAt: Date | string;
726
+ }
727
+
728
+ export interface ScheduleTimeOffData {
729
+ allDay: boolean;
730
+ timeZone: string;
731
+ id: ScheduleId;
732
+ organizationId: ScheduleId;
733
+ resourceId: ScheduleId;
734
+ requesterAccountId: ScheduleId | null;
735
+ startAt: Date | string;
736
+ endAt: Date | string;
737
+ status: ScheduleTimeOffStatusEnum;
738
+ reason: string | null;
739
+ decidedByAccountId: ScheduleId | null;
740
+ decidedAt: Date | string | null;
741
+ decisionNote: string | null;
742
+ version: number | bigint;
743
+ createdAt: Date | string;
744
+ updatedAt: Date | string;
745
+ }
746
+
747
+ export interface ScheduleNotificationAudienceObj {
748
+ accountIds?: string[];
749
+ resourceIds?: string[];
750
+ calendarManagers?: { calendarId: string };
751
+ projectEditors?: { projectId: string };
752
+ assignedInWindow?: {
753
+ calendarId: string;
754
+ from: string;
755
+ to: string;
756
+ seriesId?: string;
757
+ occurrenceIds?: string[];
758
+ };
759
+ requestParticipants?: { requestId: string; includeManagers: boolean };
760
+ timeOffParticipants?: { timeOffId: string; includeManagers: boolean };
761
+ publicationId?: string;
762
+ }
763
+
764
+ export interface ScheduleNotificationData {
765
+ id: ScheduleId;
766
+ organizationId: ScheduleId;
767
+ eventKind: ScheduleNotificationEventKindEnum;
768
+ entityType: string;
769
+ entityId: ScheduleId;
770
+ calendarId: ScheduleId | null;
771
+ projectId: ScheduleId | null;
772
+ audience: ScheduleNotificationAudienceObj;
773
+ payload: { subject: string; body: string; excludeAccountId?: string | null };
774
+ link: string | null;
775
+ idempotencyKey: string;
776
+ status: ScheduleNotificationStatusEnum;
777
+ attempts: number;
778
+ recipientCount: number;
779
+ deliveredCount: number;
780
+ failedCount: number;
781
+ inAppSentAt: Date | string | null;
782
+ availableAt: Date | string;
783
+ sentAt: Date | string | null;
784
+ lastError: string | null;
785
+ jobId: ScheduleId | null;
786
+ createdAt: Date | string;
787
+ updatedAt: Date | string;
788
+ }
789
+
790
+ export interface SchedulePublicationData {
791
+ id: ScheduleId;
792
+ organizationId: ScheduleId;
793
+ calendarId: ScheduleId;
794
+ windowStart: Date | string;
795
+ windowEnd: Date | string;
796
+ occurrenceCount: number;
797
+ acknowledgedWarnings: CoverageViolationObj[];
798
+ acknowledgedWarningCount: number;
799
+ notificationId: ScheduleId | null;
800
+ publishedByAccountId: ScheduleId | null;
801
+ publishedAt: Date | string;
802
+ }
803
+
804
+ export interface ScheduleResourceUsageData {
805
+ id: ScheduleId;
806
+ organizationId: ScheduleId;
807
+ projectId: ScheduleId;
808
+ runId: ScheduleId;
809
+ resourceId: ScheduleId;
810
+ date: Date | string;
811
+ demandUnits: number;
812
+ externalUnits: number;
813
+ availableUnits: number | null;
814
+ }
815
+
816
+ export interface ScheduleCodeValueObj {
817
+ key: string;
818
+ label: string;
819
+ color?: string | null;
820
+ }
821
+
822
+ export interface ScheduleCodeTypeData {
823
+ id: ScheduleId;
824
+ organizationId: ScheduleId;
825
+ projectId: ScheduleId | null;
826
+ key: string;
827
+ name: string;
828
+ values: ScheduleCodeValueObj[];
829
+ ordinal: number;
830
+ createdAt: Date | string;
831
+ updatedAt: Date | string;
832
+ }
833
+
834
+ /**
835
+ * Critical-path engine contract (utils/cpm.ts). Ids are strings so the same
836
+ * engine runs on serialized GraphQL rows in a browser preview and on
837
+ * database rows on the server.
838
+ */
839
+
840
+ export interface CpmActivityInput {
841
+ id: string;
842
+ type: ScheduleActivityTypeEnum;
843
+ calendarId?: string | null;
844
+ wbsId?: string | null;
845
+ ordinal?: number | null; // tie-break and ORDINAL priority key; default 0
846
+ levelingPriority?: number | null; // 1 (top) .. 10 (lowest); default 5
847
+ plannedDurationMinutes: number;
848
+ remainingDurationMinutes?: number | null;
849
+ actualStartAt?: Date | string | null;
850
+ actualFinishAt?: Date | string | null;
851
+ primaryConstraint?: ScheduleConstraintObj | null;
852
+ secondaryConstraint?: ScheduleConstraintObj | null; // only START_ON_OR_AFTER | START_ON_OR_BEFORE | FINISH_ON_OR_AFTER | FINISH_ON_OR_BEFORE; others → INVALID_INPUT WARN, ignored
853
+ }
854
+
855
+ export interface CpmRelationshipInput {
856
+ predecessorId: string;
857
+ successorId: string;
858
+ type: ScheduleRelationshipTypeEnum;
859
+ lagMinutes?: number | null;
860
+ }
861
+
862
+ export interface CpmScheduleInput {
863
+ activities: CpmActivityInput[];
864
+ relationships: CpmRelationshipInput[];
865
+ calendars: Record<string, ScheduleWorkCalendarDef>; // only the calendars the project references
866
+ defaultCalendarId: string;
867
+ wbsPaths?: Record<string, string> | null; // wbsId → '/<rootId>/<childId>/'
868
+ projectStartAt: Date | string;
869
+ dataDateAt: Date | string;
870
+ mustFinishByAt?: Date | string | null;
871
+ options?: ScheduleSchedulingOptionsObj | null;
872
+ assignments?: CpmAssignmentInput[] | null; // leveling inputs; ignored unless options.leveling.enabled
873
+ resources?: CpmResourceInput[] | null;
874
+ externalUsage?: CpmExternalUsageInput[] | null;
875
+ }
876
+
877
+ export interface CpmActivityResult {
878
+ id: string;
879
+ status: ScheduleActivityStatusEnum;
880
+ earlyStartAt: Date;
881
+ earlyFinishAt: Date;
882
+ lateStartAt: Date;
883
+ lateFinishAt: Date; // analytics (decision #2)
884
+ startAt: Date;
885
+ finishAt: Date; // effective dates: early dates, or leveled dates when leveling ran
886
+ remainingDurationMinutes: number;
887
+ totalFloatMinutes: number | null; // CPM float (unleveled); null for COMPLETE
888
+ freeFloatMinutes: number | null;
889
+ isCritical: boolean; // by options.criticalityMode
890
+ drivingPredecessorIds: string[]; // binding predecessors, in predecessor input order (§5.10); the persist step derives isDriving pairs from it
891
+ levelingDelayMinutes: number; // wm(activityCal, earlyStartAt, startAt); 0 when not leveled
892
+ levelingConstrainedByResourceId: string | null;
893
+ }
894
+
895
+ export interface CpmScheduleResult {
896
+ ok: boolean;
897
+ activities: CpmActivityResult[]; // input order
898
+ scheduledFinishAt: Date | null; // max finishAt of driving activities (leveled when leveled)
899
+ earlyFinishAt: Date | null; // max EF of driving activities (analytics)
900
+ lateFinishAt: Date | null; // late-finish basis actually used (snapped on the default calendar)
901
+ resourceUsage: CpmResourceUsage[]; // [] unless leveling ran
902
+ overallocations: CpmOverallocation[]; // [] unless leveling ran
903
+ diagnostics: ScheduleDiagnosticObj[];
904
+ stats: ScheduleProjectRunStatsObj;
905
+ }
906
+
907
+ /**
908
+ * Recurrence expansion output
909
+ */
910
+
911
+ export interface ScheduleExpandedInstance {
912
+ recurrenceDate: string;
913
+ startAt: Date;
914
+ endAt: Date;
915
+ }
916
+
917
+ /**
918
+ * Coverage evaluation contract (utils/coverage.ts)
919
+ */
920
+
921
+ export interface CoverageResourceInput {
922
+ id: string;
923
+ kind: ScheduleResourceKindEnum; // every kind accepted; NOT_LABOR is a real outcome, never an UNKNOWN_RESOURCE
924
+ retiredAt: Date | string | null;
925
+ capacity: number | null; // SPACE: licensed children; null = unbounded
926
+ config: ScheduleResourceConfigObj;
927
+ }
928
+
929
+ export interface CoverageAssignmentInput {
930
+ id: string | null; // null = simulated
931
+ resourceId: string;
932
+ slotKey: string | null; // null = unslotted
933
+ }
934
+
935
+ export interface CoverageOccurrenceInput {
936
+ id: string;
937
+ kind: ScheduleOccurrenceKindEnum; // SHIFT | EVENT | BLOCK
938
+ resourceId: string | null; // SHIFT: the room (SPACE) or null = no room (a crew shift); BLOCK: the closed room, or null = the center is closed; EVENT: ignored
939
+ startAt: Date | string;
940
+ endAt: Date | string;
941
+ slots: CoverageSlotInput[]; // SHIFT only
942
+ assignments: CoverageAssignmentInput[]; // status ASSIGNED only
943
+ }
944
+
945
+ export interface CoverageDemandInput {
946
+ id: string;
947
+ resourceId: string; // the room — NOT NULL (decision #6)
948
+ key: string; // age group / demand key, open string
949
+ quantity: number; // ≥ 0, may be fractional (NUMERIC(12,2)); summed, then divided and ceil'd
950
+ startAt: Date | string;
951
+ endAt: Date | string;
952
+ }
953
+
954
+ export interface CoverageRuleInput {
955
+ id: string;
956
+ kind: ScheduleRuleKindEnum;
957
+ calendarId: string | null; // scope ladder (§4)
958
+ resourceId: string | null;
959
+ config: ScheduleRuleConfigObj;
960
+ severity: ScheduleRuleSeverityEnum;
961
+ }
962
+
963
+ export interface CoverageEvaluationInput {
964
+ calendarId: string; // the evaluated calendar: every occurrence below belongs to it
965
+ window: CoverageWindow;
966
+ timeZone: string; // calendar zone; used only to build operating intervals
967
+ operatingHours: ScheduleWorkCalendarDef | null; // schedule_calendars.workCalendarId resolved, or null
968
+ occurrences: CoverageOccurrenceInput[]; // rows of calendarId overlapping the window (SHIFT/EVENT/BLOCK, not CANCELED, not deleted)
969
+ external: CoverageExternalAssignmentInput[]; // other calendars / outside the window, for the window's people (§3.2)
970
+ resources: CoverageResourceInput[];
971
+ demand: CoverageDemandInput[];
972
+ timeOff: CoverageTimeOffInput[];
973
+ rules: CoverageRuleInput[]; // org + calendar + resource scoped, active only, unresolved
974
+ options?: {
975
+ anchorExternal?: boolean; // eligibility mode: ACTOR_WINDOW_AGGREGATE may flag external rows too (default false)
976
+ };
977
+ }
978
+
979
+ export interface CoverageViolationObj {
980
+ key: string; // identity + startAt (§7.1) — the persisted natural key
981
+ identity: string; // identity WITHOUT startAt — merge/diff basis
982
+ kind: ScheduleRuleKindEnum;
983
+ code: ScheduleCoverageViolationCode | null; // ELIGIBILITY reason, HOURS|REST for ACTOR_WINDOW_AGGREGATE, else null
984
+ ruleId: string | null;
985
+ severity: ScheduleRuleSeverityEnum;
986
+ resourceId: string | null; // the SUBJECT: room for ROOM kinds (null = center, or a room-less shift), person for PERSON kinds
987
+ occurrenceId: string | null;
988
+ slotKey: string | null;
989
+ startAt: Date;
990
+ endAt: Date; // clipped to the window
991
+ degree: number; // how bad: shortfall, excess children, minutes over, minutes short, count
992
+ detail: Record<string, unknown>; // kind-specific, JSON-stable (sorted keys), ids only — no names
993
+ }
994
+
995
+ export type ScheduleCriticalityModeEnum =
996
+ (typeof SCHEDULE_CRITICALITY_MODE_ENUMS)[number];
997
+
998
+ export type ScheduleLevelingPriorityRuleEnum =
999
+ (typeof SCHEDULE_LEVELING_PRIORITY_RULE_ENUMS)[number];
1000
+
1001
+ export type ScheduleDiagnosticSeverityEnum =
1002
+ (typeof SCHEDULE_DIAGNOSTIC_SEVERITY_ENUMS)[number];
1003
+
1004
+ export interface ScheduleLevelingOptionsObj {
1005
+ enabled?: boolean | null; // default false
1006
+ priorityRule?: ScheduleLevelingPriorityRuleEnum[] | null; // default ['TOTAL_FLOAT', 'LATE_START', 'EARLY_START', 'PRIORITY']; ORDINAL then id are always appended
1007
+ levelWithinFloat?: boolean | null; // default false
1008
+ maxOverallocationPercent?: number | null; // default 0; clamped to [0, 100]
1009
+ considerOtherProjects?: boolean | null; // default true; a SERVER load switch (the engine only sees externalUsage)
1010
+ horizonDays?: number | null; // default 730; clamped to [30, 3660]
1011
+ }
1012
+
1013
+ export interface CpmAssignmentInput {
1014
+ activityId: string;
1015
+ resourceId: string;
1016
+ remainingUnits: number; // LABOR/EQUIPMENT: working minutes still to spend; 0 with unitsPerDay null ⇒ FULL TIME (§7.4)
1017
+ unitsPerDay?: number | null; // daily rate on the activity calendar; set ⇒ that rate on every activity working day
1018
+ }
1019
+
1020
+ export interface CpmResourceInput {
1021
+ id: string;
1022
+ kind: ScheduleResourceKindEnum;
1023
+ calendarId?: string | null; // null → project default calendar
1024
+ maxUnitsPerDay: number | null; // null → unbounded (usage reported, never constrains)
1025
+ canLevel: boolean; // false → usage + overallocations reported, activities never delayed for it
1026
+ availability: Array<{
1027
+ startsOn: string;
1028
+ endsOn: string | null;
1029
+ maxUnitsPerDay: number;
1030
+ }>; // local dates ('YYYY-MM-DD') on the resource calendar; endsOn null = open
1031
+ timeOff: Array<{ startAt: Date | string; endAt: Date | string }>; // APPROVED schedule_time_off rows as instants → available 0 on every resource day they touch
1032
+ }
1033
+
1034
+ export interface CpmExternalUsageInput {
1035
+ resourceId: string;
1036
+ startAt: Date | string; // the other project's startAt
1037
+ finishAt: Date | string; // the other project's finishAt
1038
+ unitsPerDay: number; // server-computed daily rate (§8.3); spread over the resource calendar's working days inside [max(startAt, floor), finishAt)
1039
+ }
1040
+
1041
+ export interface CpmResourceUsageDay {
1042
+ dayIndex: number;
1043
+ date: string;
1044
+ demandUnits: number;
1045
+ externalUnits: number;
1046
+ availableUnits: number | null;
1047
+ }
1048
+
1049
+ export interface CpmResourceUsage {
1050
+ resourceId: string;
1051
+ calendarId: string;
1052
+ days: CpmResourceUsageDay[];
1053
+ }
1054
+
1055
+ export interface CpmOverallocation {
1056
+ resourceId: string;
1057
+ fromDate: string;
1058
+ toDate: string;
1059
+ peakDemandUnits: number;
1060
+ availableUnits: number;
1061
+ activityIds: string[];
1062
+ }
1063
+
1064
+ export type ScheduleEligibilityReasonEnum =
1065
+ (typeof SCHEDULE_ELIGIBILITY_REASON_ENUMS)[number];
1066
+
1067
+ export type ScheduleCoverageDiagnosticCodeEnum =
1068
+ (typeof SCHEDULE_COVERAGE_DIAGNOSTIC_CODE_ENUMS)[number];
1069
+
1070
+ export type ScheduleTimeOffStatusEnum =
1071
+ (typeof SCHEDULE_TIME_OFF_STATUS_ENUMS)[number];
1072
+
1073
+ export type ScheduleNotifyChannelEnum =
1074
+ (typeof SCHEDULE_NOTIFY_CHANNEL_ENUMS)[number];
1075
+
1076
+ export type ScheduleCoverageViolationCode =
1077
+ | (typeof SCHEDULE_ELIGIBILITY_VIOLATION_CODE_ENUMS)[number]
1078
+ | (typeof SCHEDULE_ACTOR_WINDOW_VIOLATION_CODE_ENUMS)[number];
1079
+
1080
+ export interface ScheduleNotifyPrefsObj {
1081
+ channels: ScheduleNotifyChannelEnum[]; // deduped; [] = opted out. The notifications design may widen this object; the validator is the only writer.
1082
+ }
1083
+
1084
+ export interface ScheduleDerivedCountConfigObj {
1085
+ ratios: Record<string, number>; // demand key → children per adult (integer 1..50); ≥ 1 entry
1086
+ predicate: ScheduleSlotPredicateObj | null; // who counts as an adult for this rule; null = any countable LABOR
1087
+ }
1088
+
1089
+ export interface ScheduleOperatingHoursConfigObj {
1090
+ minAdults: number; // integer 1..99
1091
+ predicate: ScheduleSlotPredicateObj | null;
1092
+ }
1093
+
1094
+ export interface ScheduleActorWindowConfigObj {
1095
+ windowDays: number | null; // 1..31, required together with maxMinutes
1096
+ maxMinutes: number | null; // 1..44640
1097
+ minRestMinutes: number | null; // 1..1440; at least one of the two groups present
1098
+ }
1099
+
1100
+ export interface CoverageWindow {
1101
+ from: Date | string;
1102
+ to: Date | string;
1103
+ }
1104
+
1105
+ export interface CoverageSlotInput {
1106
+ key: string;
1107
+ label: string | null;
1108
+ requiredCount: number;
1109
+ predicate: ScheduleSlotPredicateObj | null;
1110
+ ordinal: number;
1111
+ }
1112
+
1113
+ export interface CoverageExternalAssignmentInput {
1114
+ occurrenceId: string;
1115
+ calendarId: string;
1116
+ kind: 'SHIFT' | 'EVENT';
1117
+ resourceId: string; // the person
1118
+ startAt: Date | string;
1119
+ endAt: Date | string;
1120
+ }
1121
+
1122
+ export interface CoverageTimeOffInput {
1123
+ id: string;
1124
+ resourceId: string;
1125
+ startAt: Date | string;
1126
+ endAt: Date | string; // APPROVED rows only
1127
+ }
1128
+
1129
+ export interface CoverageDiagnosticObj {
1130
+ code: ScheduleCoverageDiagnosticCodeEnum;
1131
+ ruleId: string | null;
1132
+ resourceId: string | null;
1133
+ occurrenceId: string | null;
1134
+ demandId: string | null;
1135
+ detail: Record<string, unknown>; // e.g. { key } for QUALIFICATION_EXPIRY_INVALID / RATIO_NOT_CONFIGURED
1136
+ }
1137
+
1138
+ export interface CoverageEvaluationResult {
1139
+ violations: CoverageViolationObj[]; // merged, clipped, sorted
1140
+ diagnostics: CoverageDiagnosticObj[];
1141
+ stats: {
1142
+ boundaryCount: number;
1143
+ segmentCount: number;
1144
+ occurrenceCount: number;
1145
+ externalCount: number;
1146
+ operatingIntervalCount: number;
1147
+ rawViolationCount: number;
1148
+ };
1149
+ }