@jsb188/schedule 1.1.12 → 1.1.13

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 (59) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +33 -14
  3. package/src/constants/schedule.ts +710 -306
  4. package/src/types/schedule.d.ts +1827 -456
  5. package/src/ui/ScheduleSettingsUI.tsx +21 -23
  6. package/src/utils/autofill.ts +469 -0
  7. package/src/utils/availability.ts +167 -0
  8. package/src/utils/candidates.ts +447 -0
  9. package/src/utils/coverage.helpers.ts +509 -554
  10. package/src/utils/coverage.ts +1121 -526
  11. package/src/utils/cpm.helpers.ts +27 -29
  12. package/src/utils/cpm.ts +53 -41
  13. package/src/utils/cpmLeveling.helpers.ts +89 -16
  14. package/src/utils/cpmLeveling.ts +28 -26
  15. package/src/utils/cycle.ts +325 -0
  16. package/src/utils/demand.ts +239 -0
  17. package/src/utils/eligibility.ts +553 -400
  18. package/src/utils/ids.ts +47 -0
  19. package/src/utils/laborRules.ts +740 -0
  20. package/src/utils/localTime.ts +312 -0
  21. package/src/utils/offer.ts +300 -0
  22. package/src/utils/planCsv.ts +73 -19
  23. package/src/utils/predicate.ts +111 -0
  24. package/src/utils/request.ts +212 -114
  25. package/src/utils/resource.ts +412 -112
  26. package/src/utils/rule.ts +697 -163
  27. package/src/utils/rulePresets.ts +116 -0
  28. package/src/utils/run.ts +0 -8
  29. package/src/utils/scheduleText.ts +4074 -0
  30. package/src/utils/shiftChange.ts +279 -0
  31. package/src/utils/standing.ts +730 -0
  32. package/src/utils/template.ts +619 -0
  33. package/src/utils/violation.ts +184 -0
  34. package/src/utils/workTime.ts +341 -120
  35. package/src/utils/defaults.ts +0 -8
  36. package/src/utils/recurrence.ts +0 -616
  37. package/src/utils/series.ts +0 -161
  38. package/src/utils/slot.ts +0 -208
  39. package/tests/coverage.fixtures.ts +0 -111
  40. package/tests/coverage.test.ts +0 -503
  41. package/tests/cpm.bench.test.ts +0 -154
  42. package/tests/cpm.test.ts +0 -354
  43. package/tests/cpmCorrectness.test.ts +0 -327
  44. package/tests/cpmLeveling.test.ts +0 -471
  45. package/tests/eligibility.test.ts +0 -320
  46. package/tests/gantt-geometry.test.ts +0 -367
  47. package/tests/gantt-histogram.test.ts +0 -78
  48. package/tests/gantt-keyboard.test.ts +0 -69
  49. package/tests/helpers/cpmFixtures.ts +0 -101
  50. package/tests/projectInputs.test.ts +0 -165
  51. package/tests/recurrence.test.ts +0 -68
  52. package/tests/request.test.ts +0 -99
  53. package/tests/resource.test.ts +0 -95
  54. package/tests/rule.test.ts +0 -98
  55. package/tests/series.test.ts +0 -120
  56. package/tests/workTime.test.ts +0 -1007
  57. package/tests/workTimeContracts.test.ts +0 -111
  58. package/tsconfig.json +0 -13
  59. package/vitest.config.ts +0 -8
@@ -1,98 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import {
3
- getEffectiveRule,
4
- getMaxActorWindowDays,
5
- resolveEffectiveScheduleRules,
6
- validateScheduleRuleConfig,
7
- } from '../src/utils/rule.ts';
8
- import { person, rule } from './coverage.fixtures.ts';
9
-
10
- describe('closed coverage rules', () => {
11
- it.each([
12
- ['REQUIRED_COUNT', { ratioDivisor: 2 }],
13
- ['ELIGIBILITY', { predicate: {} }],
14
- ['DERIVED_COUNT', { ratios: {} }],
15
- ['DERIVED_COUNT', { ratios: { INFANT: 0 } }],
16
- ['DERIVED_COUNT', { ratios: { INFANT: 51 } }],
17
- ['OPERATING_HOURS', { minAdults: 100 }],
18
- ['ACTOR_WINDOW_AGGREGATE', { windowDays: 32, maxMinutes: 10 }],
19
- ['ACTOR_WINDOW_AGGREGATE', { maxMinutes: 60 }],
20
- ['ACTOR_WINDOW_AGGREGATE', {}],
21
- ] as const)('rejects invalid %s config %j', (kind, config) => {
22
- expect(validateScheduleRuleConfig(kind, config).error).toBeTruthy();
23
- });
24
- it('normalizes ratios and rejects trimmed duplicates', () => {
25
- expect(
26
- validateScheduleRuleConfig('DERIVED_COUNT', { ratios: { ' INFANT ': 4 } })
27
- .config,
28
- ).toEqual({ ratios: { INFANT: 4 }, predicate: null });
29
- expect(
30
- validateScheduleRuleConfig('DERIVED_COUNT', {
31
- ratios: { ' INFANT': 4, INFANT: 5 },
32
- }).error,
33
- ).toBeTruthy();
34
- });
35
- it('resolves resource scope over calendar over organization, with numeric id ties', () => {
36
- const resources = new Map([['room', person('room', { kind: 'SPACE' })]]);
37
- const rules = [
38
- rule('REQUIRED_COUNT', {}, { id: '1', severity: 'WARN' }),
39
- rule('REQUIRED_COUNT', {}, { id: '2', calendarId: 'cal' }),
40
- rule('REQUIRED_COUNT', {}, { id: '10', resourceId: 'room' }),
41
- rule(
42
- 'REQUIRED_COUNT',
43
- {},
44
- { id: '9', resourceId: 'room', severity: 'WARN' },
45
- ),
46
- ];
47
- const { index } = resolveEffectiveScheduleRules(rules, 'cal', resources);
48
- expect(getEffectiveRule(index, 'REQUIRED_COUNT', 'room')?.ruleId).toBe('9');
49
- expect(getEffectiveRule(index, 'REQUIRED_COUNT', null)?.ruleId).toBe('2');
50
- });
51
- it('keeps the operating center rule independent of room rules', () => {
52
- const { index } = resolveEffectiveScheduleRules(
53
- [rule('OPERATING_HOURS', { minAdults: 2, predicate: null })],
54
- 'cal',
55
- new Map(),
56
- );
57
- expect(getEffectiveRule(index, 'OPERATING_HOURS', null)).not.toBeNull();
58
- expect(getEffectiveRule(index, 'OPERATING_HOURS', 'room')).toBeNull();
59
- });
60
- it('diagnoses wrong subjects and missing resources', () => {
61
- const result = resolveEffectiveScheduleRules(
62
- [
63
- rule('ELIGIBILITY', {}, { resourceId: 'room' }),
64
- rule(
65
- 'DERIVED_COUNT',
66
- { ratios: { X: 4 }, predicate: null },
67
- { resourceId: 'missing' },
68
- ),
69
- ],
70
- 'cal',
71
- new Map([['room', person('room', { kind: 'SPACE' })]]),
72
- );
73
- expect(result.diagnostics.map((d) => d.code).sort()).toEqual([
74
- 'RULE_SUBJECT_KIND_MISMATCH',
75
- 'UNKNOWN_RESOURCE',
76
- ]);
77
- });
78
- it('bounds history using the largest valid actor rule', () => {
79
- expect(
80
- getMaxActorWindowDays([
81
- rule('ACTOR_WINDOW_AGGREGATE', {
82
- windowDays: 31,
83
- maxMinutes: 100,
84
- minRestMinutes: null,
85
- }),
86
- ]),
87
- ).toBe(31);
88
- expect(
89
- getMaxActorWindowDays([
90
- rule('ACTOR_WINDOW_AGGREGATE', {
91
- windowDays: null,
92
- maxMinutes: null,
93
- minRestMinutes: 60,
94
- }),
95
- ]),
96
- ).toBe(1);
97
- });
98
- });
@@ -1,120 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { expandScheduleSeriesInstances } from '../src/utils/recurrence.ts';
3
- import {
4
- getLocalDateKey,
5
- planScheduleSeriesRegeneration,
6
- type SeriesExistingInstance,
7
- } from '../src/utils/series.ts';
8
-
9
- /* Build a small daily series spanning a daylight-saving boundary. */
10
- function series() {
11
- return {
12
- title: 'Morning',
13
- timeZone: 'America/New_York',
14
- recurrence: { freq: 'DAILY' as const, count: 3 },
15
- startsAt: '2026-03-07T13:00:00Z',
16
- durationMinutes: 240,
17
- active: true,
18
- slotTemplate: [],
19
- };
20
- }
21
-
22
- /* Materialize existing identities as a server loader would return them. */
23
- function existing(): SeriesExistingInstance[] {
24
- return expandScheduleSeriesInstances(series()).map((row, i) => ({
25
- ...row,
26
- id: String(i),
27
- detached: false,
28
- hasLiveAssignments: i === 2,
29
- }));
30
- }
31
-
32
- /* Plan one deterministic edit with convenient overridable inputs. */
33
- function plan(
34
- extra: Partial<Parameters<typeof planScheduleSeriesRegeneration>[0]> = {},
35
- ) {
36
- return planScheduleSeriesRegeneration({
37
- series: series(),
38
- existing: existing(),
39
- fromDate: '2026-03-07',
40
- now: new Date('2026-03-07T12:00:00Z'),
41
- horizon: new Date('2026-03-12T00:00:00Z'),
42
- labelsChanged: false,
43
- slotTemplateChanged: false,
44
- ...extra,
45
- });
46
- }
47
-
48
- describe('safe series regeneration', () => {
49
- it('keys local dates across DST independently of UTC offset', () => {
50
- const rows = expandScheduleSeriesInstances(series());
51
- expect(rows.map((row) => row.recurrenceDate)).toEqual([
52
- '2026-03-07',
53
- '2026-03-08',
54
- '2026-03-09',
55
- ]);
56
- expect(rows[1].startAt.toISOString()).toBe('2026-03-08T12:00:00.000Z');
57
- expect(getLocalDateKey(rows[1].startAt, series().timeZone)).toBe(
58
- '2026-03-08',
59
- );
60
- });
61
- it('preserves matched ids and assignments when time changes', () => {
62
- const result = plan({
63
- series: { ...series(), startsAt: '2026-03-07T12:30:00Z' },
64
- });
65
- expect(result.update.map((row) => row.id)).toEqual(['0', '1', '2']);
66
- expect(result.create).toEqual([]);
67
- expect(result.detach).toEqual([]);
68
- });
69
- it('propagates label-only edits to matched rows', () => {
70
- const result = plan({
71
- labelsChanged: true,
72
- series: { ...series(), title: 'Renamed' },
73
- });
74
- expect(result.labels?.title).toBe('Renamed');
75
- expect(result.update).toEqual([{ id: '0' }, { id: '1' }, { id: '2' }]);
76
- });
77
- it('detaches staffed removed dates and deletes unstaffed dates', () => {
78
- const result = plan({
79
- series: { ...series(), recurrence: { freq: 'DAILY', count: 1 } },
80
- });
81
- expect(result.detach).toEqual([{ id: '2', reason: 'DATE_REMOVED' }]);
82
- expect(result.delete).toEqual(['1']);
83
- });
84
- it('preserves detached dates without duplicate creation', () => {
85
- const rows = existing();
86
- rows[1].detached = true;
87
- const result = plan({ existing: rows });
88
- expect(result.skipped).toEqual([
89
- { recurrenceDate: '2026-03-08', reason: 'DETACHED_EXISTS' },
90
- ]);
91
- expect(result.create).toEqual([]);
92
- expect(result.update.map((row) => row.id)).toEqual(['0', '2']);
93
- });
94
- it('never edits, deletes or detaches an already-started instance', () => {
95
- const result = plan({
96
- now: new Date('2026-03-07T14:00:00Z'),
97
- series: { ...series(), active: false },
98
- });
99
- expect(result.skipped).toEqual([
100
- { recurrenceDate: '2026-03-07', reason: 'ALREADY_STARTED' },
101
- ]);
102
- expect(result.delete).toEqual(['1']);
103
- expect(result.detach).toEqual([{ id: '2', reason: 'SERIES_DELETED' }]);
104
- });
105
- it('freezes a date if its edited time would move into the past', () => {
106
- const result = plan({
107
- series: { ...series(), startsAt: '2026-03-07T11:00:00Z' },
108
- });
109
- expect(result.skipped).toEqual([
110
- { recurrenceDate: '2026-03-07', reason: 'ALREADY_STARTED' },
111
- ]);
112
- expect(result.delete).toEqual([]);
113
- });
114
- it('keeps count relative to the series origin for later materialization', () => {
115
- const rows = expandScheduleSeriesInstances(series(), {
116
- from: new Date('2026-03-09T00:00:00Z'),
117
- });
118
- expect(rows.map((row) => row.recurrenceDate)).toEqual(['2026-03-09']);
119
- });
120
- });