@jsb188/mday 1.1.11 → 1.1.12

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 (210) hide show
  1. package/package.json +58 -23
  2. package/src/constants/agentMemory.ts +14 -45
  3. package/src/constants/agentNote.ts +212 -0
  4. package/src/constants/aiChat.ts +5 -0
  5. package/src/constants/billing.ts +126 -0
  6. package/src/constants/campaign.ts +156 -47
  7. package/src/constants/contact.ts +72 -0
  8. package/src/constants/csvExport.ts +133 -0
  9. package/src/constants/dataTable.ts +12 -38
  10. package/src/constants/dataTableFieldTypes.generated.ts +3 -7
  11. package/src/constants/docAccess.ts +3 -2
  12. package/src/constants/dt.ts +234 -0
  13. package/src/constants/email.ts +114 -12
  14. package/src/constants/fieldDoc.ts +74 -4
  15. package/src/constants/graphqlReactivity.ts +108 -25
  16. package/src/constants/log.ts +9 -0
  17. package/src/constants/logDisplay/README.md +88 -0
  18. package/src/constants/logDisplay/defaults.ts +39 -0
  19. package/src/constants/logDisplay/index.ts +27 -0
  20. package/src/constants/logDisplay/operations/arable.ts +16 -0
  21. package/src/constants/logDisplay/operations/farmersMarket.ts +10 -0
  22. package/src/constants/logDisplay/operations/foodManufacturing.ts +13 -0
  23. package/src/constants/logDisplay/shared/accounting.ts +13 -0
  24. package/src/constants/logDisplay/shared/interactions.ts +13 -0
  25. package/src/constants/logDisplay/shared/rackTemperatures.ts +42 -0
  26. package/src/constants/logTaxonomy.generated.ts +1834 -730
  27. package/src/constants/organization.ts +13 -14
  28. package/src/constants/qrCode.ts +30 -0
  29. package/src/constants/sheet.ts +65 -101
  30. package/src/constants/sms.ts +18 -0
  31. package/src/constants/storage.ts +33 -9
  32. package/src/constants/usage.ts +3 -0
  33. package/src/constants/workflowSteps.ts +60 -0
  34. package/src/schemas/editLogEntry.ts +106 -283
  35. package/src/schemas/inboundContact.ts +5 -5
  36. package/src/types/agentMemory.d.ts +38 -14
  37. package/src/types/agentNote.d.ts +443 -0
  38. package/src/types/billing.d.ts +537 -0
  39. package/src/types/campaign.d.ts +1043 -193
  40. package/src/types/contact.d.ts +15 -0
  41. package/src/types/csvExport.d.ts +213 -0
  42. package/src/types/dataAnalysis.d.ts +44 -0
  43. package/src/types/dataTable.d.ts +102 -309
  44. package/src/types/definitionElement.d.ts +35 -0
  45. package/src/types/dt.d.ts +257 -0
  46. package/src/types/email.d.ts +144 -55
  47. package/src/types/emailReplyReport.d.ts +76 -0
  48. package/src/types/fieldDoc.d.ts +579 -150
  49. package/src/types/fieldDocContract.d.ts +90 -0
  50. package/src/types/inboundContact.d.ts +8 -0
  51. package/src/types/log.d.ts +94 -3
  52. package/src/types/logDisplay.types.ts +85 -0
  53. package/src/types/organization.d.ts +8 -3
  54. package/src/types/qrCode.d.ts +96 -0
  55. package/src/types/richText.d.ts +81 -0
  56. package/src/types/sheet.d.ts +180 -463
  57. package/src/types/sms.d.ts +38 -0
  58. package/src/types/storage.d.ts +266 -27
  59. package/src/types/workflow.d.ts +196 -66
  60. package/src/utils/agentMemory.ts +15 -0
  61. package/src/utils/agentNote.ts +850 -0
  62. package/src/utils/aiChat.ts +31 -14
  63. package/src/utils/aiChatWork.ts +64 -0
  64. package/src/utils/billing.ts +37 -0
  65. package/src/utils/campaign.ts +642 -209
  66. package/src/utils/campaignAI.ts +72 -0
  67. package/src/utils/campaignAccess.ts +239 -0
  68. package/src/utils/campaignEmail.ts +601 -0
  69. package/src/utils/campaignEmailCompiler.ts +372 -0
  70. package/src/utils/campaignEmailImages.ts +60 -0
  71. package/src/utils/campaignEmailStyles.ts +544 -0
  72. package/src/utils/campaignLifecycle.ts +104 -0
  73. package/src/utils/campaignPreview.ts +285 -0
  74. package/src/utils/contact.ts +50 -0
  75. package/src/utils/csvExport.ts +19 -0
  76. package/src/utils/dataTable.ts +18 -556
  77. package/src/utils/dataTableFieldTypeRegistry.ts +1 -0
  78. package/src/utils/dataTableRelativeDate.ts +447 -0
  79. package/src/utils/definitionElement.ts +84 -0
  80. package/src/utils/email.ts +208 -1
  81. package/src/utils/emailReplyReport.test.ts +187 -0
  82. package/src/utils/emailReplyReport.ts +143 -0
  83. package/src/utils/fieldDoc.ts +81 -37
  84. package/src/utils/fieldDocAnswers.ts +128 -0
  85. package/src/utils/fieldDocDefaults.ts +36 -0
  86. package/src/utils/fieldDocProgram.ts +36 -0
  87. package/src/utils/fieldDocSummary.ts +30 -0
  88. package/src/utils/log.ts +232 -141
  89. package/src/utils/logDisplay.helpers.ts +177 -0
  90. package/src/utils/logDisplay.ts +87 -0
  91. package/src/utils/logStoreRead.ts +9 -13
  92. package/src/utils/logTaxonomy.helpers.ts +17 -0
  93. package/src/utils/logTaxonomyDisplay.ts +80 -124
  94. package/src/utils/noteDoc.ts +66 -284
  95. package/src/utils/organization.ts +117 -283
  96. package/src/utils/qrCode.helpers.ts +189 -0
  97. package/src/utils/qrCode.test.ts +519 -0
  98. package/src/utils/qrCode.ts +273 -0
  99. package/src/utils/richTextHTML.ts +385 -0
  100. package/src/utils/sheet.ts +123 -4834
  101. package/src/utils/sheetAxisMove.ts +77 -291
  102. package/src/utils/sheetBootstrap.ts +771 -1138
  103. package/src/utils/sheetCellLiteral.ts +101 -0
  104. package/src/utils/sheetCommand.ts +23 -88
  105. package/src/utils/sheetDesign.ts +705 -0
  106. package/src/utils/sheetExport.ts +17 -69
  107. package/src/utils/sheetFeatureReference.ts +183 -0
  108. package/src/utils/sheetFormulaArgs.ts +168 -0
  109. package/src/utils/sheetFormulaCompile.ts +475 -0
  110. package/src/utils/sheetFormulaConditionalAggregate.ts +254 -0
  111. package/src/utils/sheetFormulaCriteria.ts +656 -0
  112. package/src/utils/sheetFormulaDate.ts +444 -0
  113. package/src/utils/sheetFormulaEvaluation.ts +388 -403
  114. package/src/utils/sheetFormulaEvaluator.ts +589 -444
  115. package/src/utils/sheetFormulaFunctionHandlers.ts +403 -0
  116. package/src/utils/sheetFormulaLogical.ts +116 -0
  117. package/src/utils/sheetFormulaLookup.ts +488 -0
  118. package/src/utils/sheetFormulaMath.ts +48 -0
  119. package/src/utils/sheetFormulaParser.ts +729 -0
  120. package/src/utils/sheetFormulaRange.ts +330 -0
  121. package/src/utils/sheetFormulaReference.ts +703 -0
  122. package/src/utils/sheetFormulaReferenceAggregates.ts +313 -0
  123. package/src/utils/sheetFormulaReferenceDates.ts +237 -0
  124. package/src/utils/sheetFormulaReferenceLogical.ts +330 -0
  125. package/src/utils/sheetFormulaReferenceLookup.ts +341 -0
  126. package/src/utils/sheetFormulaReferenceMath.ts +95 -0
  127. package/src/utils/sheetFormulaReferenceRewrite.ts +220 -0
  128. package/src/utils/sheetFormulaReferenceText.ts +462 -0
  129. package/src/utils/sheetFormulaSyntax.ts +1027 -0
  130. package/src/utils/sheetFormulaText.ts +430 -0
  131. package/src/utils/sheetJournal.ts +140 -18
  132. package/src/utils/sheetNumberFormat.ts +68 -267
  133. package/src/utils/sheetPreview.ts +68 -0
  134. package/src/utils/sheetSequence.ts +13 -43
  135. package/src/utils/sheetSnapshot.ts +176 -429
  136. package/src/utils/sheetStructureEdit.ts +537 -907
  137. package/src/utils/sheetStructureReferences.ts +389 -0
  138. package/src/utils/storage.ts +49 -3
  139. package/src/utils/time.ts +12 -0
  140. package/src/utils/workflow.ts +199 -73
  141. package/src/utils/workflowLogFingerprint.ts +302 -0
  142. package/src/utils/workflowLogRevisionSnapshot.ts +424 -0
  143. package/src/utils/workflowProgress.ts +280 -0
  144. package/src/utils/workflowTriggers.ts +61 -0
  145. package/tests/agentNote.test.ts +395 -0
  146. package/tests/campaignAI.test.ts +119 -0
  147. package/tests/campaignAccess.test.ts +239 -0
  148. package/tests/campaignEmail.test.ts +441 -0
  149. package/tests/campaignLifecycle.test.ts +134 -0
  150. package/tests/campaignPublication.test.ts +309 -0
  151. package/tests/dataTableFieldTypeRegistry.test.ts +2 -1
  152. package/tests/dataTableRelativeDate.test.ts +412 -0
  153. package/tests/email.test.ts +39 -0
  154. package/tests/fieldDocProgram.test.ts +114 -0
  155. package/tests/logDisplay.fixtures.ts +67 -0
  156. package/tests/logDisplay.test.ts +227 -0
  157. package/tests/noteDoc.test.ts +37 -192
  158. package/tests/richTextHTML.test.ts +185 -0
  159. package/tests/sheetAxisMove.test.ts +49 -40
  160. package/tests/sheetBootstrap.test.ts +1967 -0
  161. package/tests/sheetFeatureReference.test.ts +22 -0
  162. package/tests/sheetFormulaCriteria.test.ts +269 -0
  163. package/tests/sheetFormulaEvaluator.test.ts +93 -200
  164. package/tests/sheetFormulaFunctions.test.ts +538 -0
  165. package/tests/sheetFormulaLanguage.test.ts +361 -0
  166. package/tests/sheetFormulaParity.fixtures.ts +872 -0
  167. package/tests/sheetFormulaParity.test.ts +188 -0
  168. package/tests/sheetFormulaRange.test.ts +167 -0
  169. package/tests/sheetFormulaReference.test.ts +78 -0
  170. package/tests/sheetFormulaReferenceRewrite.test.ts +117 -0
  171. package/tests/sheetFormulaTextDate.test.ts +512 -0
  172. package/tests/sheetSequence.test.ts +4 -23
  173. package/tests/sheetSnapshot.test.ts +134 -0
  174. package/tests/sheetStructureEdit.test.ts +492 -37
  175. package/tests/sheetStructureReferences.test.ts +589 -0
  176. package/tests/workflowLifecycleStatus.test.ts +60 -0
  177. package/tests/workflowLogFingerprint.test.ts +203 -0
  178. package/tests/workflowLogRevisionSnapshot.test.ts +96 -0
  179. package/tests/workflowProgress.test.ts +180 -0
  180. package/tests/workflowTriggers.test.ts +29 -0
  181. package/src/constants/agentDoc.ts +0 -12
  182. package/src/constants/logActivityGroupColors.generated.ts +0 -19
  183. package/src/constants/schedule.ts +0 -220
  184. package/src/constants/scheduleRuleTemplateSeed.ts +0 -138
  185. package/src/constants/scheduleRuleTemplates.generated.ts +0 -145
  186. package/src/constants/sheetRegionSources.generated.ts +0 -578
  187. package/src/schemas/fieldDocsQuery.ts +0 -12
  188. package/src/schemas/organization.ts +0 -68
  189. package/src/types/agentDoc.d.ts +0 -64
  190. package/src/types/noteDoc.d.ts +0 -86
  191. package/src/types/schedule.d.ts +0 -391
  192. package/src/utils/agentDoc.ts +0 -109
  193. package/src/utils/campaignFormEditor.ts +0 -871
  194. package/src/utils/dataTableRealtimeAuthority.ts +0 -209
  195. package/src/utils/dataTableRealtimeSelection.ts +0 -134
  196. package/src/utils/dataTableRowDocument.ts +0 -508
  197. package/src/utils/dataTableSource.ts +0 -230
  198. package/src/utils/schedule.ts +0 -799
  199. package/src/utils/scheduleEvaluation.ts +0 -1994
  200. package/src/utils/scheduleICS.ts +0 -246
  201. package/src/utils/scheduleRuleTemplates.ts +0 -188
  202. package/src/utils/sheetRegion.ts +0 -374
  203. package/src/utils/sheetRegionFilter.ts +0 -1259
  204. package/src/utils/sheetRegionSourceRegistry.ts +0 -594
  205. package/tests/schedule.test.ts +0 -693
  206. package/tests/scheduleEvaluation.test.ts +0 -1970
  207. package/tests/scheduleICS.test.ts +0 -208
  208. package/tests/scheduleRuleTemplates.test.ts +0 -176
  209. package/tests/scheduleSweepInvariants.test.ts +0 -428
  210. package/tests/sheetRegionFilter.test.ts +0 -1135
@@ -1,220 +0,0 @@
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;
@@ -1,138 +0,0 @@
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
- ];
@@ -1,145 +0,0 @@
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
- > = {};