@jsb188/mday 1.1.8 → 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.
- package/package.json +105 -35
- package/src/constants/agentDoc.ts +12 -0
- package/src/constants/agentMemory.ts +154 -0
- package/src/constants/aiChat.ts +5 -0
- package/src/constants/campaign.ts +127 -0
- package/src/constants/dataTable.ts +48 -0
- package/src/constants/dataTableFieldTypes.generated.ts +63 -0
- package/src/constants/docAccess.ts +32 -0
- package/src/constants/email.ts +44 -0
- package/src/constants/fieldDoc.ts +34 -0
- package/src/constants/graphqlReactivity.ts +113 -0
- package/src/constants/inboundContact.ts +8 -0
- package/src/constants/integration.ts +13 -0
- package/src/constants/log.ts +7 -366
- package/src/constants/logActivityGroupColors.generated.ts +19 -0
- package/src/constants/logTaxonomy.generated.ts +1103 -0
- package/src/constants/noteDoc.ts +77 -0
- package/src/constants/organization.ts +18 -11
- package/src/constants/pageRoute.ts +23 -0
- package/src/constants/schedule.ts +220 -0
- package/src/constants/scheduleRuleTemplateSeed.ts +138 -0
- package/src/constants/scheduleRuleTemplates.generated.ts +145 -0
- package/src/constants/sheet.ts +168 -0
- package/src/constants/sheetRegionSources.generated.ts +578 -0
- package/src/constants/square.ts +16 -0
- package/src/constants/storage.ts +61 -0
- package/src/constants/usage.ts +79 -0
- package/src/schemas/editLogEntry.ts +1017 -738
- package/src/schemas/fieldDocsQuery.ts +12 -0
- package/src/schemas/inboundContact.ts +77 -0
- package/src/schemas/logsQuery.ts +57 -316
- package/src/schemas/organization.ts +53 -213
- package/src/types/account.d.ts +81 -0
- package/src/types/agentDoc.d.ts +64 -0
- package/src/types/agentMemory.d.ts +74 -0
- package/src/types/campaign.d.ts +683 -0
- package/src/types/dataTable.d.ts +366 -0
- package/src/types/docAccess.d.ts +96 -0
- package/src/types/email.d.ts +142 -0
- package/src/types/fieldDoc.d.ts +273 -0
- package/src/types/inboundContact.d.ts +57 -0
- package/src/types/integration.d.ts +42 -0
- package/src/types/log.d.ts +169 -190
- package/src/types/noteDoc.d.ts +86 -0
- package/src/types/organization.d.ts +175 -76
- package/src/types/pageRoute.d.ts +48 -0
- package/src/types/schedule.d.ts +391 -0
- package/src/types/sheet.d.ts +1130 -0
- package/src/types/storage.d.ts +242 -0
- package/src/types/usage.d.ts +106 -0
- package/src/types/workflow.d.ts +305 -0
- package/src/utils/agentDoc.ts +109 -0
- package/src/utils/aiChat.ts +26 -0
- package/src/utils/campaign.ts +741 -0
- package/src/utils/campaignFormEditor.ts +871 -0
- package/src/utils/dataTable.ts +849 -0
- package/src/utils/dataTableFieldTypeRegistry.ts +105 -0
- package/src/utils/dataTableRealtimeAuthority.ts +209 -0
- package/src/utils/dataTableRealtimeSelection.ts +134 -0
- package/src/utils/dataTableRowDocument.ts +508 -0
- package/src/utils/dataTableSource.ts +230 -0
- package/src/utils/docAccess.ts +383 -0
- package/src/utils/documentName.ts +53 -0
- package/src/utils/email.ts +172 -0
- package/src/utils/fieldDoc.ts +113 -0
- package/src/utils/log.ts +173 -778
- package/src/utils/logRegistryValue.ts +90 -0
- package/src/utils/logStoreRead.ts +266 -0
- package/src/utils/logTaxonomy.ts +76 -0
- package/src/utils/logTaxonomyDisplay.ts +439 -0
- package/src/utils/noteDoc.ts +827 -0
- package/src/utils/organization.ts +683 -81
- package/src/utils/pageRoute.ts +71 -0
- package/src/utils/schedule.ts +799 -0
- package/src/utils/scheduleEvaluation.ts +1994 -0
- package/src/utils/scheduleICS.ts +246 -0
- package/src/utils/scheduleRuleTemplates.ts +188 -0
- package/src/utils/sheet.ts +4973 -0
- package/src/utils/sheetAxisMove.ts +830 -0
- package/src/utils/sheetBootstrap.ts +1769 -0
- package/src/utils/sheetCommand.ts +423 -0
- package/src/utils/sheetExport.ts +238 -0
- package/src/utils/sheetFormulaEvaluation.ts +914 -0
- package/src/utils/sheetFormulaEvaluator.ts +852 -0
- package/src/utils/sheetJournal.ts +78 -0
- package/src/utils/sheetNumberFormat.ts +1211 -0
- package/src/utils/sheetRegion.ts +374 -0
- package/src/utils/sheetRegionFilter.ts +1259 -0
- package/src/utils/sheetRegionSourceRegistry.ts +594 -0
- package/src/utils/sheetSequence.ts +148 -0
- package/src/utils/sheetSnapshot.ts +992 -0
- package/src/utils/sheetStructureEdit.ts +1284 -0
- package/src/utils/square.ts +32 -0
- package/src/utils/storage.ts +152 -0
- package/src/utils/table-route.ts +262 -0
- package/src/utils/workflow.ts +380 -0
- package/tests/dataTableFieldTypeRegistry.test.ts +110 -0
- package/tests/docAccess.test.ts +525 -0
- package/tests/editLogEntry.test.ts +112 -0
- package/tests/noteDoc.test.ts +669 -0
- package/tests/schedule.test.ts +693 -0
- package/tests/scheduleEvaluation.test.ts +1970 -0
- package/tests/scheduleICS.test.ts +208 -0
- package/tests/scheduleRuleTemplates.test.ts +176 -0
- package/tests/scheduleSweepInvariants.test.ts +428 -0
- package/tests/sheetAxisMove.test.ts +343 -0
- package/tests/sheetFormulaEvaluator.test.ts +575 -0
- package/tests/sheetRegionFilter.test.ts +1135 -0
- package/tests/sheetSequence.test.ts +41 -0
- package/tests/sheetStructureEdit.test.ts +82 -0
- package/tsconfig.json +12 -0
- package/vitest.config.ts +8 -0
- package/src/constants/log-activityTexts.ts +0 -209
- package/src/constants/product.ts +0 -66
- package/src/constants/report.ts +0 -25
- package/src/schemas/childOrganizationsQuery.ts +0 -44
- package/src/schemas/productsQuery.ts +0 -145
- package/src/schemas/reportsQuery.ts +0 -107
- package/src/types/action.d.ts +0 -42
- package/src/types/product.d.ts +0 -173
- package/src/types/report.d.ts +0 -203
- package/src/utils/product-calEvent.ts +0 -508
- package/src/utils/route-helpers.ts +0 -583
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Note document ("noteDoc") constants, shared by the Deno server sanitizer
|
|
3
|
+
* and the web note editor. A note's content is one ProseMirror-shaped JSON
|
|
4
|
+
* tree restricted to the closed node/mark vocabulary declared here; anything
|
|
5
|
+
* outside this vocabulary is removed by sanitizeNoteDoc on every write.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { COLORS } from '@jsb188/app/constants/app.ts';
|
|
9
|
+
|
|
10
|
+
// Stamped on every sanitized document; bump only with a migration path
|
|
11
|
+
export const NOTE_DOC_VERSION = 1;
|
|
12
|
+
|
|
13
|
+
// Every block-level node type a note document may contain
|
|
14
|
+
export const NOTE_BLOCK_TYPES = [
|
|
15
|
+
'paragraph',
|
|
16
|
+
'heading',
|
|
17
|
+
'bulletList',
|
|
18
|
+
'orderedList',
|
|
19
|
+
'listItem',
|
|
20
|
+
'blockquote',
|
|
21
|
+
'divider',
|
|
22
|
+
'image',
|
|
23
|
+
] as const;
|
|
24
|
+
|
|
25
|
+
// Every inline node type a text-bearing block may contain
|
|
26
|
+
export const NOTE_INLINE_TYPES = ['text', 'hardBreak'] as const;
|
|
27
|
+
|
|
28
|
+
// Every inline mark type a text run may carry
|
|
29
|
+
export const NOTE_MARK_TYPES = [
|
|
30
|
+
'bold',
|
|
31
|
+
'italic',
|
|
32
|
+
'underline',
|
|
33
|
+
'strike',
|
|
34
|
+
'code',
|
|
35
|
+
'color',
|
|
36
|
+
'highlight',
|
|
37
|
+
'link',
|
|
38
|
+
] as const;
|
|
39
|
+
|
|
40
|
+
// Block types that contain other blocks; every other block type is either
|
|
41
|
+
// an inline-content leaf (paragraph, heading) or a void leaf (divider, image)
|
|
42
|
+
export const NOTE_CONTAINER_BLOCK_TYPES = [
|
|
43
|
+
'bulletList',
|
|
44
|
+
'orderedList',
|
|
45
|
+
'listItem',
|
|
46
|
+
'blockquote',
|
|
47
|
+
] as const;
|
|
48
|
+
|
|
49
|
+
// Which block types each container allows as direct children; the sanitizer
|
|
50
|
+
// unwraps/converts/wraps anything else (it never keeps illegal nesting)
|
|
51
|
+
export const NOTE_NESTING_RULES: Record<string, readonly string[]> = {
|
|
52
|
+
doc: [
|
|
53
|
+
'paragraph',
|
|
54
|
+
'heading',
|
|
55
|
+
'bulletList',
|
|
56
|
+
'orderedList',
|
|
57
|
+
'blockquote',
|
|
58
|
+
'divider',
|
|
59
|
+
'image',
|
|
60
|
+
],
|
|
61
|
+
bulletList: ['listItem'],
|
|
62
|
+
orderedList: ['listItem'],
|
|
63
|
+
listItem: ['paragraph', 'bulletList', 'orderedList'],
|
|
64
|
+
blockquote: ['paragraph'],
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// Valid tokens for color/highlight marks: the shared 21-color app palette
|
|
68
|
+
export const NOTE_COLOR_TOKENS: readonly string[] = COLORS;
|
|
69
|
+
|
|
70
|
+
// Sanitizer caps against oversized/hostile documents; the sanitizer
|
|
71
|
+
// truncates the tail once a cap is reached
|
|
72
|
+
export const NOTE_MAX_DEPTH = 6;
|
|
73
|
+
export const NOTE_MAX_BLOCKS = 2000;
|
|
74
|
+
export const NOTE_MAX_TEXT_CHARS = 200000;
|
|
75
|
+
|
|
76
|
+
// link mark hrefs must match this (kills javascript:/data:/etc URLs)
|
|
77
|
+
export const NOTE_LINK_HREF_REGEX = /^(https?:|mailto:)/i;
|
|
@@ -4,24 +4,27 @@
|
|
|
4
4
|
export const OPERATION_ENUMS = [
|
|
5
5
|
// Farms
|
|
6
6
|
'ARABLE',
|
|
7
|
-
'LIVESTOCK',
|
|
8
7
|
|
|
9
8
|
// Umbrella orgs
|
|
10
9
|
'FARMERS_MARKET',
|
|
11
10
|
'GROWER_NETWORK',
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
// External orgs
|
|
13
|
+
'RESTAURANT',
|
|
14
|
+
'VENDOR',
|
|
15
|
+
'WHOLESALE_FOOD',
|
|
16
|
+
'UNKNOWN',
|
|
15
17
|
];
|
|
16
18
|
|
|
17
|
-
export const PARENT_ORG_OPERATIONS = [
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
];
|
|
19
|
+
export const PARENT_ORG_OPERATIONS = ['FARMERS_MARKET', 'GROWER_NETWORK'];
|
|
20
|
+
|
|
21
|
+
export const AUDITOR_ORG_OPERATIONS = ['GROWER_NETWORK'];
|
|
21
22
|
|
|
22
|
-
//
|
|
23
|
+
// Membership roles
|
|
24
|
+
// Order of roles matter (for visualization)
|
|
25
|
+
// second item is default value
|
|
23
26
|
|
|
24
|
-
export const ROLE_ENUMS = ['MEMBER', 'MANAGER', 'ADMIN', 'OWNER'
|
|
27
|
+
export const ROLE_ENUMS = ['GUEST', 'MEMBER', 'MANAGER', 'ADMIN', 'OWNER'];
|
|
25
28
|
|
|
26
29
|
// Role categories (used for reminders)
|
|
27
30
|
|
|
@@ -49,6 +52,10 @@ export const COMPLIANCE_DOCUMENT_TYPE_MAP = {
|
|
|
49
52
|
'Nursery License': 'NURSERY_LICENSE',
|
|
50
53
|
};
|
|
51
54
|
|
|
52
|
-
export const COMPLIANCE_DOCUMENT_TYPE_ENUMS = Object.values(
|
|
55
|
+
export const COMPLIANCE_DOCUMENT_TYPE_ENUMS = Object.values(
|
|
56
|
+
COMPLIANCE_DOCUMENT_TYPE_MAP,
|
|
57
|
+
);
|
|
53
58
|
|
|
54
|
-
export const COMPLIANCE_DOCUMENT_TYPE_LABELS = Object.keys(
|
|
59
|
+
export const COMPLIANCE_DOCUMENT_TYPE_LABELS = Object.keys(
|
|
60
|
+
COMPLIANCE_DOCUMENT_TYPE_MAP,
|
|
61
|
+
);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Custom organization page route constants
|
|
2
|
+
|
|
3
|
+
// Queries that a custom page route can use as its data source
|
|
4
|
+
export const PAGE_ROUTE_QUERY_ENUMS = ['LOG_ENTRIES', 'CHILD_ORGANIZATIONS'];
|
|
5
|
+
|
|
6
|
+
// Slugs that can never be used for custom page routes (single-character slugs are always rejected)
|
|
7
|
+
export const PAGE_ROUTE_RESERVED_SLUGS = [
|
|
8
|
+
'workspaces',
|
|
9
|
+
'workspace',
|
|
10
|
+
'grids',
|
|
11
|
+
'grid',
|
|
12
|
+
'tables',
|
|
13
|
+
'table',
|
|
14
|
+
'workflows',
|
|
15
|
+
'workflow',
|
|
16
|
+
'billing',
|
|
17
|
+
'inbox',
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
export const PAGE_ROUTE_SLUG_MIN_LENGTH = 2;
|
|
21
|
+
export const PAGE_ROUTE_SLUG_MAX_LENGTH = 40;
|
|
22
|
+
export const PAGE_ROUTE_MAX_COLUMNS = 30;
|
|
23
|
+
export const PAGE_ROUTE_ICON_NAME_MAX_LENGTH = 80;
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scheduling and calendar constants, shared by the Deno server models, the
|
|
3
|
+
* GraphQL type definitions, and the Marketday calendar UI.
|
|
4
|
+
*
|
|
5
|
+
* Every enum value below is written into a Postgres VARCHAR column guarded by
|
|
6
|
+
* a CHECK constraint in server/src/schemas/schedule.sql. Values must stay
|
|
7
|
+
* SCREAMING_SNAKE and must never be renamed or reordered destructively —
|
|
8
|
+
* retire a value by leaving it in place and no longer offering it.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
// What a calendar is for. COVERAGE calendars run the constraint engine
|
|
12
|
+
// (staffing requirements, ratios, overtime); EVENTS calendars do not.
|
|
13
|
+
export const SCHEDULE_CALENDAR_KIND_ENUMS = ['COVERAGE', 'EVENTS'] as const;
|
|
14
|
+
|
|
15
|
+
// What one scheduled entry represents. SHIFT carries staffing requirements,
|
|
16
|
+
// EVENT is a plain calendar entry, BLOCK marks time a resource is unavailable
|
|
17
|
+
// (closure, maintenance, cleaning turnover).
|
|
18
|
+
export const SCHEDULE_OCCURRENCE_KIND_ENUMS = [
|
|
19
|
+
'SHIFT',
|
|
20
|
+
'EVENT',
|
|
21
|
+
'BLOCK',
|
|
22
|
+
] as const;
|
|
23
|
+
|
|
24
|
+
// Lifecycle of one occurrence. Only PUBLISHED rows are visible to workers and
|
|
25
|
+
// exported to calendar feeds.
|
|
26
|
+
export const SCHEDULE_OCCURRENCE_STATUS_ENUMS = [
|
|
27
|
+
'DRAFT',
|
|
28
|
+
'PUBLISHED',
|
|
29
|
+
'CANCELED',
|
|
30
|
+
] as const;
|
|
31
|
+
|
|
32
|
+
// Who an assignment attaches to: a platform account, a partner organization
|
|
33
|
+
// attending a network event, or a person with no login.
|
|
34
|
+
export const SCHEDULE_ACTOR_TYPE_ENUMS = [
|
|
35
|
+
'ACCOUNT',
|
|
36
|
+
'ORGANIZATION',
|
|
37
|
+
'CONTACT',
|
|
38
|
+
] as const;
|
|
39
|
+
|
|
40
|
+
// Assignment lifecycle. INVITED/ACCEPTED/DECLINED belong to the event-flavored
|
|
41
|
+
// RSVP flow and are reserved; no current code path writes them.
|
|
42
|
+
export const SCHEDULE_ASSIGNMENT_STATUS_ENUMS = [
|
|
43
|
+
'ASSIGNED',
|
|
44
|
+
'RELEASED',
|
|
45
|
+
'INVITED',
|
|
46
|
+
'ACCEPTED',
|
|
47
|
+
'DECLINED',
|
|
48
|
+
] as const;
|
|
49
|
+
|
|
50
|
+
// Where a demand quantity came from
|
|
51
|
+
export const SCHEDULE_DEMAND_SOURCE_ENUMS = ['MANUAL', 'IMPORTED'] as const;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The seven constraint rule kinds. Each maps to exactly one evaluator, so
|
|
55
|
+
* adding a rule kind is one evaluator plus one value here and in the DDL
|
|
56
|
+
* CHECK constraint — never a schema reshape.
|
|
57
|
+
*
|
|
58
|
+
* REQUIRED_COUNT a slot needs N assignees matching its predicate
|
|
59
|
+
* DERIVED_COUNT N is computed from a demand quantity (ratios)
|
|
60
|
+
* RESOURCE_CAPACITY a resource holds at most C concurrent occurrences
|
|
61
|
+
* ACTOR_WINDOW_AGGREGATE per-actor rolling-window limits (overtime, rest)
|
|
62
|
+
* ELIGIBILITY_AT_TIME the actor holds an attribute valid at that instant
|
|
63
|
+
* EXCLUSION_WINDOW after event T on a resource, block U for a duration
|
|
64
|
+
* CONTINUOUS_COVERAGE no uncovered instant inside an operating window
|
|
65
|
+
*/
|
|
66
|
+
export const SCHEDULE_RULE_KIND_ENUMS = [
|
|
67
|
+
'REQUIRED_COUNT',
|
|
68
|
+
'DERIVED_COUNT',
|
|
69
|
+
'RESOURCE_CAPACITY',
|
|
70
|
+
'ACTOR_WINDOW_AGGREGATE',
|
|
71
|
+
'ELIGIBILITY_AT_TIME',
|
|
72
|
+
'EXCLUSION_WINDOW',
|
|
73
|
+
'CONTINUOUS_COVERAGE',
|
|
74
|
+
] as const;
|
|
75
|
+
|
|
76
|
+
// BLOCK prevents publishing the window; WARN records the breach and lets the
|
|
77
|
+
// publisher acknowledge it
|
|
78
|
+
export const SCHEDULE_RULE_SEVERITY_ENUMS = ['BLOCK', 'WARN'] as const;
|
|
79
|
+
|
|
80
|
+
export const SCHEDULE_EVALUATION_STATUS_ENUMS = [
|
|
81
|
+
'RUNNING',
|
|
82
|
+
'COMPLETE',
|
|
83
|
+
'FAILED',
|
|
84
|
+
] as const;
|
|
85
|
+
|
|
86
|
+
// Worker-initiated changes; every one is a request, never a direct write
|
|
87
|
+
export const SCHEDULE_REQUEST_KIND_ENUMS = [
|
|
88
|
+
'RELEASE',
|
|
89
|
+
'SWAP',
|
|
90
|
+
'CLAIM',
|
|
91
|
+
'TIME_OFF',
|
|
92
|
+
] as const;
|
|
93
|
+
|
|
94
|
+
// PENDING_APPROVAL is deliberately absent. It was declared here and in the
|
|
95
|
+
// DDL, and no code path ever wrote it: a claimed request awaiting a decision is
|
|
96
|
+
// already named unambiguously by CLAIMED with a null "decidedAt". Adding a
|
|
97
|
+
// separate state would have meant a third transaction after the auto-approval
|
|
98
|
+
// decline — one more crash window — to say something two existing columns
|
|
99
|
+
// already say. The database CHECK still permits the value until the migration
|
|
100
|
+
// in schedule_rearchitecture_runbook.md is run; nothing writes it either way.
|
|
101
|
+
export const SCHEDULE_REQUEST_STATUS_ENUMS = [
|
|
102
|
+
'OPEN',
|
|
103
|
+
'CLAIMED',
|
|
104
|
+
'APPROVED',
|
|
105
|
+
'DENIED',
|
|
106
|
+
'WITHDRAWN',
|
|
107
|
+
'EXPIRED',
|
|
108
|
+
] as const;
|
|
109
|
+
|
|
110
|
+
// MINE exports only the subscriber's own assignments; CALENDAR exports every
|
|
111
|
+
// occurrence on one calendar
|
|
112
|
+
export const SCHEDULE_FEED_SCOPE_ENUMS = ['MINE', 'CALENDAR'] as const;
|
|
113
|
+
|
|
114
|
+
export const SCHEDULE_NOTIFICATION_EVENT_KIND_ENUMS = [
|
|
115
|
+
'SCHEDULE_PUBLISHED',
|
|
116
|
+
'OCCURRENCE_CHANGED',
|
|
117
|
+
'ASSIGNMENT_CHANGED',
|
|
118
|
+
'REQUEST_OPENED',
|
|
119
|
+
'REQUEST_DECIDED',
|
|
120
|
+
'VIOLATION_RAISED',
|
|
121
|
+
] as const;
|
|
122
|
+
|
|
123
|
+
export const SCHEDULE_NOTIFICATION_CHANNEL_ENUMS = ['EMAIL', 'SMS'] as const;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Recurrence
|
|
127
|
+
*
|
|
128
|
+
* The stored recurrence spec is a closed structured object rather than an
|
|
129
|
+
* RFC 5545 RRULE string: it is validated on write, expanded deterministically,
|
|
130
|
+
* and rendered to an RRULE line only when an ICS feed is generated. Weekdays
|
|
131
|
+
* use the JavaScript convention (0 = Sunday ... 6 = Saturday).
|
|
132
|
+
*/
|
|
133
|
+
export const SCHEDULE_RECURRENCE_FREQ_ENUMS = [
|
|
134
|
+
'DAILY',
|
|
135
|
+
'WEEKLY',
|
|
136
|
+
'MONTHLY',
|
|
137
|
+
'YEARLY',
|
|
138
|
+
] as const;
|
|
139
|
+
|
|
140
|
+
// Largest repeat interval accepted ("every N weeks"); guards the expander
|
|
141
|
+
// against a rule that would walk forever producing nothing
|
|
142
|
+
export const SCHEDULE_RECURRENCE_MAX_INTERVAL = 52;
|
|
143
|
+
|
|
144
|
+
// Hard ceiling on expander iterations for one call, independent of the
|
|
145
|
+
// requested window. Weekly recurrence over ten years is ~520 steps, so this
|
|
146
|
+
// only trips on a malformed rule.
|
|
147
|
+
export const SCHEDULE_RECURRENCE_MAX_ITERATIONS = 20_000;
|
|
148
|
+
|
|
149
|
+
// A byMonthDay of -1 means "the last day of the month"
|
|
150
|
+
export const SCHEDULE_RECURRENCE_LAST_DAY_OF_MONTH = -1;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Materialization
|
|
154
|
+
*/
|
|
155
|
+
|
|
156
|
+
// How far ahead the horizon job keeps concrete occurrence rows.
|
|
157
|
+
//
|
|
158
|
+
// Shortened from a year because every one of those rows is real, permanent
|
|
159
|
+
// storage that nothing ever purges, and almost none of it is ever read: a
|
|
160
|
+
// calendar grid asks for a month. Four months covers the planning horizon
|
|
161
|
+
// anybody actually schedules against, and a read that reaches past it tops the
|
|
162
|
+
// missing span up on demand (see the top-up in the calendar window read), so
|
|
163
|
+
// the shorter horizon costs a longer read once rather than a year of rows for
|
|
164
|
+
// every series forever.
|
|
165
|
+
export const SCHEDULE_MATERIALIZATION_HORIZON_DAYS = 120;
|
|
166
|
+
|
|
167
|
+
// How far into the PAST a first materialization pass may reach.
|
|
168
|
+
//
|
|
169
|
+
// A series carries the instant its rule began, which can be years back — an
|
|
170
|
+
// organization onboarding an existing schedule enters it as it really is. With
|
|
171
|
+
// no floor, creating that series materializes its entire history on the first
|
|
172
|
+
// pass, and nothing ever deletes those rows. Recent history is worth having
|
|
173
|
+
// (a calendar shows the weeks just gone); older history was never ours to
|
|
174
|
+
// invent.
|
|
175
|
+
export const SCHEDULE_MATERIALIZATION_MAX_BACKFILL_DAYS = 30;
|
|
176
|
+
|
|
177
|
+
// Occurrences one series may create in a single materialization pass; a
|
|
178
|
+
// series that needs more is picked up again on the next poll
|
|
179
|
+
export const SCHEDULE_MATERIALIZATION_MAX_PER_PASS = 500;
|
|
180
|
+
|
|
181
|
+
// Series scanned per poller tick
|
|
182
|
+
export const SCHEDULE_MATERIALIZATION_SERIES_PER_TICK = 50;
|
|
183
|
+
|
|
184
|
+
// Passes one on-demand top-up may run before it gives up and leaves the rest
|
|
185
|
+
// to the poller. A pass is capped, so a window far past the horizon needs
|
|
186
|
+
// several; a read is not the place to run an unbounded loop, so it stops.
|
|
187
|
+
export const SCHEDULE_MATERIALIZATION_TOP_UP_MAX_PASSES = 5;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Query limits
|
|
191
|
+
*/
|
|
192
|
+
|
|
193
|
+
// Longest calendar window one query may request. Deliberately longer than the
|
|
194
|
+
// materialization horizon: the past half of a long window is durable data that
|
|
195
|
+
// nothing purges (a year-end report is a real read), and the future half is
|
|
196
|
+
// filled on demand by the top-up. An over-long request is refused rather than
|
|
197
|
+
// quietly shortened, so a caller never mistakes a clipped answer for the whole
|
|
198
|
+
// range.
|
|
199
|
+
export const SCHEDULE_QUERY_MAX_WINDOW_DAYS = 400;
|
|
200
|
+
|
|
201
|
+
// Occurrences returned by one calendar query. Hitting this ceiling is an
|
|
202
|
+
// error, not a silent truncation — a calendar missing shifts nobody was told
|
|
203
|
+
// about is how somebody fails to show up for one.
|
|
204
|
+
export const SCHEDULE_QUERY_MAX_OCCURRENCES = 2_000;
|
|
205
|
+
|
|
206
|
+
// Longest single occurrence (one leap year, in minutes)
|
|
207
|
+
export const SCHEDULE_OCCURRENCE_MAX_DURATION_MINUTES = 527_040;
|
|
208
|
+
|
|
209
|
+
export const SCHEDULE_TITLE_MAX_LENGTH = 255;
|
|
210
|
+
// Must match the schedule_slots column widths; validation rejects rather than
|
|
211
|
+
// truncates, so an over-length value can never reach a write
|
|
212
|
+
export const SCHEDULE_SLOT_KEY_MAX_LENGTH = 80;
|
|
213
|
+
export const SCHEDULE_SLOT_LABEL_MAX_LENGTH = 150;
|
|
214
|
+
export const SCHEDULE_CALENDAR_NAME_MAX_LENGTH = 100;
|
|
215
|
+
export const SCHEDULE_RESOURCE_KEY_MAX_LENGTH = 80;
|
|
216
|
+
|
|
217
|
+
// access_grants."entityType" value for schedule calendars; must stay in
|
|
218
|
+
// DOC_ACCESS_ENTITY_TYPE_ENUMS and in the access_grants CHECK constraint
|
|
219
|
+
export const SCHEDULE_CALENDAR_ACCESS_ENTITY_TYPE =
|
|
220
|
+
'SCHEDULE_CALENDAR' as const;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ScheduleRuleKindEnum,
|
|
3
|
+
ScheduleRuleSeverityEnum,
|
|
4
|
+
} from '../types/schedule.d.ts';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The platform-default constraint rule templates.
|
|
8
|
+
*
|
|
9
|
+
* A rule kind is an evaluator; a template is what an organization actually
|
|
10
|
+
* recognizes. "REQUIRED_COUNT breached, shortfall 1" is a true statement no
|
|
11
|
+
* director wants to read — "Infant room is 1 teacher short (needs 2)" is the
|
|
12
|
+
* same fact in the language of the place it happened.
|
|
13
|
+
*
|
|
14
|
+
* Templates therefore carry the wording, the default configuration, and the
|
|
15
|
+
* default severity, and they resolve most-specific-first:
|
|
16
|
+
*
|
|
17
|
+
* organization row -> operation-type row -> platform default (this file)
|
|
18
|
+
*
|
|
19
|
+
* That layering is why the seed below is deliberately generic. A childcare
|
|
20
|
+
* customer overrides these with ratio language, a market overrides them with
|
|
21
|
+
* stall language, and neither has to wait for a schema change or a deploy.
|
|
22
|
+
*
|
|
23
|
+
* This file is the source of truth for the SEED only. Once seeded, the
|
|
24
|
+
* database registry is authoritative and the committed generated module is
|
|
25
|
+
* refreshed from it (deno task generate:schedule-rule-templates), exactly as
|
|
26
|
+
* the log taxonomy works.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
export interface ScheduleRuleTemplateSeedObj {
|
|
30
|
+
kind: ScheduleRuleKindEnum;
|
|
31
|
+
key: string;
|
|
32
|
+
label: string;
|
|
33
|
+
description: string;
|
|
34
|
+
// "{token}" placeholders are filled from the violation's detail object;
|
|
35
|
+
// an unknown token renders as an em dash rather than leaking the token
|
|
36
|
+
messageTemplate: string;
|
|
37
|
+
defaultConfig: Record<string, unknown>;
|
|
38
|
+
defaultSeverity: ScheduleRuleSeverityEnum;
|
|
39
|
+
ordinal: number;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const SCHEDULE_RULE_TEMPLATE_SEED: ScheduleRuleTemplateSeedObj[] = [
|
|
43
|
+
{
|
|
44
|
+
kind: 'REQUIRED_COUNT',
|
|
45
|
+
key: 'STAFF_MINIMUM',
|
|
46
|
+
label: 'Minimum staff on a slot',
|
|
47
|
+
description:
|
|
48
|
+
'A named slot must be filled by at least this many people for its whole duration.',
|
|
49
|
+
messageTemplate:
|
|
50
|
+
'{slotKey} is {shortfall} short — {actual} of {required} assigned.',
|
|
51
|
+
defaultConfig: { slotKey: '', required: 1 },
|
|
52
|
+
defaultSeverity: 'BLOCK',
|
|
53
|
+
ordinal: 10,
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
kind: 'DERIVED_COUNT',
|
|
57
|
+
key: 'RATIO_TO_DEMAND',
|
|
58
|
+
label: 'Staff-to-attendance ratio',
|
|
59
|
+
description:
|
|
60
|
+
'The number of people required is computed from an expected quantity, such as one adult per N children.',
|
|
61
|
+
messageTemplate:
|
|
62
|
+
'Ratio breach for {category}: {actual} of {required} needed for {quantity} (1 per {divisor}).',
|
|
63
|
+
defaultConfig: { category: '', divisor: 1 },
|
|
64
|
+
defaultSeverity: 'BLOCK',
|
|
65
|
+
ordinal: 20,
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
kind: 'RESOURCE_CAPACITY',
|
|
69
|
+
key: 'ROOM_CAPACITY',
|
|
70
|
+
label: 'Resource capacity',
|
|
71
|
+
description:
|
|
72
|
+
'A room, vehicle, or station can hold only so many bookings at the same time.',
|
|
73
|
+
messageTemplate:
|
|
74
|
+
'Over capacity: {actual} booked at once, limit is {capacity}.',
|
|
75
|
+
defaultConfig: { capacity: 1 },
|
|
76
|
+
defaultSeverity: 'BLOCK',
|
|
77
|
+
ordinal: 30,
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
kind: 'ELIGIBILITY_AT_TIME',
|
|
81
|
+
key: 'CERTIFICATION_REQUIRED',
|
|
82
|
+
label: 'Required certification',
|
|
83
|
+
description:
|
|
84
|
+
'Whoever works this must hold a valid credential at the moment the shift runs, not merely today.',
|
|
85
|
+
messageTemplate:
|
|
86
|
+
'Assigned worker does not hold a valid {qualification} for this time.',
|
|
87
|
+
defaultConfig: { qualification: '' },
|
|
88
|
+
defaultSeverity: 'BLOCK',
|
|
89
|
+
ordinal: 40,
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
kind: 'CONTINUOUS_COVERAGE',
|
|
93
|
+
key: 'OPERATING_HOURS_COVERAGE',
|
|
94
|
+
label: 'Uninterrupted coverage',
|
|
95
|
+
description:
|
|
96
|
+
'No gap is allowed anywhere inside the operating window — including the minutes between two shifts.',
|
|
97
|
+
messageTemplate: 'Nobody is scheduled between {opensAt} and {closesAt}.',
|
|
98
|
+
defaultConfig: { opensAt: '08:00', closesAt: '18:00' },
|
|
99
|
+
defaultSeverity: 'BLOCK',
|
|
100
|
+
ordinal: 50,
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
kind: 'ACTOR_WINDOW_AGGREGATE',
|
|
104
|
+
key: 'MAX_HOURS_PER_WEEK',
|
|
105
|
+
label: 'Maximum hours in a rolling week',
|
|
106
|
+
description:
|
|
107
|
+
'Caps how much one person can be scheduled across any rolling window, counting shifts outside this view.',
|
|
108
|
+
messageTemplate:
|
|
109
|
+
'{over} over the {max} {metric} limit in a rolling {windowHours}h window ({total} total).',
|
|
110
|
+
defaultConfig: { metric: 'HOURS', windowHours: 168, max: 40 },
|
|
111
|
+
defaultSeverity: 'WARN',
|
|
112
|
+
ordinal: 60,
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
kind: 'ACTOR_WINDOW_AGGREGATE',
|
|
116
|
+
key: 'MIN_REST_BETWEEN_SHIFTS',
|
|
117
|
+
label: 'Minimum rest between shifts',
|
|
118
|
+
description:
|
|
119
|
+
'Caps shifts inside a short rolling window so nobody closes and then opens.',
|
|
120
|
+
messageTemplate:
|
|
121
|
+
'{over} over the {max} {metric} limit in a rolling {windowHours}h window ({total} total).',
|
|
122
|
+
defaultConfig: { metric: 'SHIFTS', windowHours: 24, max: 1 },
|
|
123
|
+
defaultSeverity: 'WARN',
|
|
124
|
+
ordinal: 70,
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
kind: 'EXCLUSION_WINDOW',
|
|
128
|
+
key: 'TURNAROUND_AFTER_EVENT',
|
|
129
|
+
label: 'Turnaround after an event',
|
|
130
|
+
description:
|
|
131
|
+
'Blocks a resource for a period after a particular kind of booking, such as cleaning or a maintenance hold.',
|
|
132
|
+
messageTemplate:
|
|
133
|
+
'Only {gapMinutes} min after a {afterKind}; {blockMinutes} min are required.',
|
|
134
|
+
defaultConfig: { afterKind: 'BLOCK', blockMinutes: 60 },
|
|
135
|
+
defaultSeverity: 'BLOCK',
|
|
136
|
+
ordinal: 80,
|
|
137
|
+
},
|
|
138
|
+
];
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
// GENERATED FILE — DO NOT EDIT BY HAND.
|
|
2
|
+
// Regenerate with: deno task generate:schedule-rule-templates
|
|
3
|
+
// (reads the schedule_rule_templates registry).
|
|
4
|
+
|
|
5
|
+
import type { ScheduleRuleTemplateObj } from '../types/schedule.d.ts';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Operation-agnostic templates, keyed by "KIND:KEY". Every key an
|
|
9
|
+
* operation overrides also appears here, so resolution always terminates.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export const SCHEDULE_RULE_TEMPLATE_DEFAULTS: Record<
|
|
13
|
+
string,
|
|
14
|
+
ScheduleRuleTemplateObj
|
|
15
|
+
> = {
|
|
16
|
+
'REQUIRED_COUNT:STAFF_MINIMUM': {
|
|
17
|
+
kind: 'REQUIRED_COUNT',
|
|
18
|
+
key: 'STAFF_MINIMUM',
|
|
19
|
+
label: 'Minimum staff on a slot',
|
|
20
|
+
description:
|
|
21
|
+
'A named slot must be filled by at least this many people for its whole duration.',
|
|
22
|
+
messageTemplate:
|
|
23
|
+
'{slotKey} is {shortfall} short — {actual} of {required} assigned.',
|
|
24
|
+
defaultConfig: {
|
|
25
|
+
slotKey: '',
|
|
26
|
+
required: 1,
|
|
27
|
+
},
|
|
28
|
+
defaultSeverity: 'BLOCK',
|
|
29
|
+
ordinal: 10,
|
|
30
|
+
},
|
|
31
|
+
'DERIVED_COUNT:RATIO_TO_DEMAND': {
|
|
32
|
+
kind: 'DERIVED_COUNT',
|
|
33
|
+
key: 'RATIO_TO_DEMAND',
|
|
34
|
+
label: 'Staff-to-attendance ratio',
|
|
35
|
+
description:
|
|
36
|
+
'The number of people required is computed from an expected quantity, such as one adult per N children.',
|
|
37
|
+
messageTemplate:
|
|
38
|
+
'Ratio breach for {category}: {actual} of {required} needed for {quantity} (1 per {divisor}).',
|
|
39
|
+
defaultConfig: {
|
|
40
|
+
divisor: 1,
|
|
41
|
+
category: '',
|
|
42
|
+
},
|
|
43
|
+
defaultSeverity: 'BLOCK',
|
|
44
|
+
ordinal: 20,
|
|
45
|
+
},
|
|
46
|
+
'RESOURCE_CAPACITY:ROOM_CAPACITY': {
|
|
47
|
+
kind: 'RESOURCE_CAPACITY',
|
|
48
|
+
key: 'ROOM_CAPACITY',
|
|
49
|
+
label: 'Resource capacity',
|
|
50
|
+
description:
|
|
51
|
+
'A room, vehicle, or station can hold only so many bookings at the same time.',
|
|
52
|
+
messageTemplate:
|
|
53
|
+
'Over capacity: {actual} booked at once, limit is {capacity}.',
|
|
54
|
+
defaultConfig: {
|
|
55
|
+
capacity: 1,
|
|
56
|
+
},
|
|
57
|
+
defaultSeverity: 'BLOCK',
|
|
58
|
+
ordinal: 30,
|
|
59
|
+
},
|
|
60
|
+
'ELIGIBILITY_AT_TIME:CERTIFICATION_REQUIRED': {
|
|
61
|
+
kind: 'ELIGIBILITY_AT_TIME',
|
|
62
|
+
key: 'CERTIFICATION_REQUIRED',
|
|
63
|
+
label: 'Required certification',
|
|
64
|
+
description:
|
|
65
|
+
'Whoever works this must hold a valid credential at the moment the shift runs, not merely today.',
|
|
66
|
+
messageTemplate:
|
|
67
|
+
'Assigned worker does not hold a valid {qualification} for this time.',
|
|
68
|
+
defaultConfig: {
|
|
69
|
+
qualification: '',
|
|
70
|
+
},
|
|
71
|
+
defaultSeverity: 'BLOCK',
|
|
72
|
+
ordinal: 40,
|
|
73
|
+
},
|
|
74
|
+
'CONTINUOUS_COVERAGE:OPERATING_HOURS_COVERAGE': {
|
|
75
|
+
kind: 'CONTINUOUS_COVERAGE',
|
|
76
|
+
key: 'OPERATING_HOURS_COVERAGE',
|
|
77
|
+
label: 'Uninterrupted coverage',
|
|
78
|
+
description:
|
|
79
|
+
'No gap is allowed anywhere inside the operating window — including the minutes between two shifts.',
|
|
80
|
+
messageTemplate: 'Nobody is scheduled between {opensAt} and {closesAt}.',
|
|
81
|
+
defaultConfig: {
|
|
82
|
+
opensAt: '08:00',
|
|
83
|
+
closesAt: '18:00',
|
|
84
|
+
},
|
|
85
|
+
defaultSeverity: 'BLOCK',
|
|
86
|
+
ordinal: 50,
|
|
87
|
+
},
|
|
88
|
+
'ACTOR_WINDOW_AGGREGATE:MAX_HOURS_PER_WEEK': {
|
|
89
|
+
kind: 'ACTOR_WINDOW_AGGREGATE',
|
|
90
|
+
key: 'MAX_HOURS_PER_WEEK',
|
|
91
|
+
label: 'Maximum hours in a rolling week',
|
|
92
|
+
description:
|
|
93
|
+
'Caps how much one person can be scheduled across any rolling window, counting shifts outside this view.',
|
|
94
|
+
messageTemplate:
|
|
95
|
+
'{over} over the {max} {metric} limit in a rolling {windowHours}h window ({total} total).',
|
|
96
|
+
defaultConfig: {
|
|
97
|
+
max: 40,
|
|
98
|
+
metric: 'HOURS',
|
|
99
|
+
windowHours: 168,
|
|
100
|
+
},
|
|
101
|
+
defaultSeverity: 'WARN',
|
|
102
|
+
ordinal: 60,
|
|
103
|
+
},
|
|
104
|
+
'ACTOR_WINDOW_AGGREGATE:MIN_REST_BETWEEN_SHIFTS': {
|
|
105
|
+
kind: 'ACTOR_WINDOW_AGGREGATE',
|
|
106
|
+
key: 'MIN_REST_BETWEEN_SHIFTS',
|
|
107
|
+
label: 'Minimum rest between shifts',
|
|
108
|
+
description:
|
|
109
|
+
'Caps shifts inside a short rolling window so nobody closes and then opens.',
|
|
110
|
+
messageTemplate:
|
|
111
|
+
'{over} over the {max} {metric} limit in a rolling {windowHours}h window ({total} total).',
|
|
112
|
+
defaultConfig: {
|
|
113
|
+
max: 1,
|
|
114
|
+
metric: 'SHIFTS',
|
|
115
|
+
windowHours: 24,
|
|
116
|
+
},
|
|
117
|
+
defaultSeverity: 'WARN',
|
|
118
|
+
ordinal: 70,
|
|
119
|
+
},
|
|
120
|
+
'EXCLUSION_WINDOW:TURNAROUND_AFTER_EVENT': {
|
|
121
|
+
kind: 'EXCLUSION_WINDOW',
|
|
122
|
+
key: 'TURNAROUND_AFTER_EVENT',
|
|
123
|
+
label: 'Turnaround after an event',
|
|
124
|
+
description:
|
|
125
|
+
'Blocks a resource for a period after a particular kind of booking, such as cleaning or a maintenance hold.',
|
|
126
|
+
messageTemplate:
|
|
127
|
+
'Only {gapMinutes} min after a {afterKind}; {blockMinutes} min are required.',
|
|
128
|
+
defaultConfig: {
|
|
129
|
+
afterKind: 'BLOCK',
|
|
130
|
+
blockMinutes: 60,
|
|
131
|
+
},
|
|
132
|
+
defaultSeverity: 'BLOCK',
|
|
133
|
+
ordinal: 80,
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Per-operation overrides, keyed by operation then by "KIND:KEY". An
|
|
139
|
+
* operation absent from this map simply uses the defaults above.
|
|
140
|
+
*/
|
|
141
|
+
|
|
142
|
+
export const SCHEDULE_RULE_TEMPLATES_BY_OPERATION: Record<
|
|
143
|
+
string,
|
|
144
|
+
Record<string, ScheduleRuleTemplateObj>
|
|
145
|
+
> = {};
|