@critical-path/core 0.36.0 → 0.36.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. package/package.json +5 -1
  2. package/CHANGELOG.md +0 -593
  3. package/dist/deliverables.test.d.ts +0 -2
  4. package/dist/deliverables.test.d.ts.map +0 -1
  5. package/dist/deliverables.test.js +0 -232
  6. package/dist/deliverables.test.js.map +0 -1
  7. package/dist/domain/calendar.test.d.ts +0 -2
  8. package/dist/domain/calendar.test.d.ts.map +0 -1
  9. package/dist/domain/calendar.test.js +0 -181
  10. package/dist/domain/calendar.test.js.map +0 -1
  11. package/dist/domain/cpm.test.d.ts +0 -2
  12. package/dist/domain/cpm.test.d.ts.map +0 -1
  13. package/dist/domain/cpm.test.js +0 -166
  14. package/dist/domain/cpm.test.js.map +0 -1
  15. package/dist/domain/ddd.test.d.ts +0 -2
  16. package/dist/domain/ddd.test.d.ts.map +0 -1
  17. package/dist/domain/ddd.test.js +0 -349
  18. package/dist/domain/ddd.test.js.map +0 -1
  19. package/dist/domain/ladder.test.d.ts +0 -2
  20. package/dist/domain/ladder.test.d.ts.map +0 -1
  21. package/dist/domain/ladder.test.js +0 -213
  22. package/dist/domain/ladder.test.js.map +0 -1
  23. package/dist/domain/metrics.test.d.ts +0 -2
  24. package/dist/domain/metrics.test.d.ts.map +0 -1
  25. package/dist/domain/metrics.test.js +0 -252
  26. package/dist/domain/metrics.test.js.map +0 -1
  27. package/dist/domain/task-duration.test.d.ts +0 -2
  28. package/dist/domain/task-duration.test.d.ts.map +0 -1
  29. package/dist/domain/task-duration.test.js +0 -307
  30. package/dist/domain/task-duration.test.js.map +0 -1
  31. package/dist/domain/workload.test.d.ts +0 -2
  32. package/dist/domain/workload.test.d.ts.map +0 -1
  33. package/dist/domain/workload.test.js +0 -261
  34. package/dist/domain/workload.test.js.map +0 -1
  35. package/dist/engine/actor.test.d.ts +0 -2
  36. package/dist/engine/actor.test.d.ts.map +0 -1
  37. package/dist/engine/actor.test.js +0 -54
  38. package/dist/engine/actor.test.js.map +0 -1
  39. package/dist/engine/authorization.test.d.ts +0 -2
  40. package/dist/engine/authorization.test.d.ts.map +0 -1
  41. package/dist/engine/authorization.test.js +0 -154
  42. package/dist/engine/authorization.test.js.map +0 -1
  43. package/dist/engine/cascade.test.d.ts +0 -2
  44. package/dist/engine/cascade.test.d.ts.map +0 -1
  45. package/dist/engine/cascade.test.js +0 -99
  46. package/dist/engine/cascade.test.js.map +0 -1
  47. package/dist/engine/config.test.d.ts +0 -2
  48. package/dist/engine/config.test.d.ts.map +0 -1
  49. package/dist/engine/config.test.js +0 -46
  50. package/dist/engine/config.test.js.map +0 -1
  51. package/dist/engine/entity-events.test.d.ts +0 -2
  52. package/dist/engine/entity-events.test.d.ts.map +0 -1
  53. package/dist/engine/entity-events.test.js +0 -61
  54. package/dist/engine/entity-events.test.js.map +0 -1
  55. package/dist/index.test.d.ts +0 -2
  56. package/dist/index.test.d.ts.map +0 -1
  57. package/dist/index.test.js +0 -429
  58. package/dist/index.test.js.map +0 -1
  59. package/dist/plugins/plugins.test.d.ts +0 -2
  60. package/dist/plugins/plugins.test.d.ts.map +0 -1
  61. package/dist/plugins/plugins.test.js +0 -137
  62. package/dist/plugins/plugins.test.js.map +0 -1
  63. package/dist/schemas/schemas.test.d.ts +0 -2
  64. package/dist/schemas/schemas.test.d.ts.map +0 -1
  65. package/dist/schemas/schemas.test.js +0 -58
  66. package/dist/schemas/schemas.test.js.map +0 -1
  67. package/dist/status.test.d.ts +0 -2
  68. package/dist/status.test.d.ts.map +0 -1
  69. package/dist/status.test.js +0 -295
  70. package/dist/status.test.js.map +0 -1
  71. package/dist/storage/storage.test.d.ts +0 -2
  72. package/dist/storage/storage.test.d.ts.map +0 -1
  73. package/dist/storage/storage.test.js +0 -236
  74. package/dist/storage/storage.test.js.map +0 -1
  75. package/dist/storage/upload-limits.test.d.ts +0 -2
  76. package/dist/storage/upload-limits.test.d.ts.map +0 -1
  77. package/dist/storage/upload-limits.test.js +0 -31
  78. package/dist/storage/upload-limits.test.js.map +0 -1
  79. package/dist/store/conformance.test.d.ts +0 -2
  80. package/dist/store/conformance.test.d.ts.map +0 -1
  81. package/dist/store/conformance.test.js +0 -15
  82. package/dist/store/conformance.test.js.map +0 -1
  83. package/dist/store/firebase.test.d.ts +0 -2
  84. package/dist/store/firebase.test.d.ts.map +0 -1
  85. package/dist/store/firebase.test.js +0 -103
  86. package/dist/store/firebase.test.js.map +0 -1
  87. package/dist/store/query.test.d.ts +0 -2
  88. package/dist/store/query.test.d.ts.map +0 -1
  89. package/dist/store/query.test.js +0 -89
  90. package/dist/store/query.test.js.map +0 -1
  91. package/dist/store/sqlite.test.d.ts +0 -2
  92. package/dist/store/sqlite.test.d.ts.map +0 -1
  93. package/dist/store/sqlite.test.js +0 -177
  94. package/dist/store/sqlite.test.js.map +0 -1
  95. package/dist/task-state.test.d.ts +0 -2
  96. package/dist/task-state.test.d.ts.map +0 -1
  97. package/dist/task-state.test.js +0 -423
  98. package/dist/task-state.test.js.map +0 -1
  99. package/dist/use-case-validation.test.d.ts +0 -2
  100. package/dist/use-case-validation.test.d.ts.map +0 -1
  101. package/dist/use-case-validation.test.js +0 -281
  102. package/dist/use-case-validation.test.js.map +0 -1
  103. package/dist/utils/fractional-index.test.d.ts +0 -2
  104. package/dist/utils/fractional-index.test.d.ts.map +0 -1
  105. package/dist/utils/fractional-index.test.js +0 -182
  106. package/dist/utils/fractional-index.test.js.map +0 -1
  107. package/dist/utils/key.test.d.ts +0 -2
  108. package/dist/utils/key.test.d.ts.map +0 -1
  109. package/dist/utils/key.test.js +0 -65
  110. package/dist/utils/key.test.js.map +0 -1
  111. package/dist/utils/mentions.test.d.ts +0 -2
  112. package/dist/utils/mentions.test.d.ts.map +0 -1
  113. package/dist/utils/mentions.test.js +0 -114
  114. package/dist/utils/mentions.test.js.map +0 -1
  115. package/dist/webhooks/webhooks.test.d.ts +0 -2
  116. package/dist/webhooks/webhooks.test.d.ts.map +0 -1
  117. package/dist/webhooks/webhooks.test.js +0 -154
  118. package/dist/webhooks/webhooks.test.js.map +0 -1
  119. package/src/deliverables.test.ts +0 -284
  120. package/src/domain/authorization.ts +0 -82
  121. package/src/domain/calendar.test.ts +0 -216
  122. package/src/domain/calendar.ts +0 -502
  123. package/src/domain/cpm.test.ts +0 -189
  124. package/src/domain/cpm.ts +0 -258
  125. package/src/domain/custom-fields.ts +0 -172
  126. package/src/domain/ddd.test.ts +0 -442
  127. package/src/domain/entities.ts +0 -798
  128. package/src/domain/errors.ts +0 -38
  129. package/src/domain/events.ts +0 -369
  130. package/src/domain/graph.ts +0 -70
  131. package/src/domain/index.ts +0 -12
  132. package/src/domain/ladder.test.ts +0 -251
  133. package/src/domain/ladder.ts +0 -474
  134. package/src/domain/metrics.test.ts +0 -288
  135. package/src/domain/metrics.ts +0 -497
  136. package/src/domain/task-duration.test.ts +0 -354
  137. package/src/domain/workload.test.ts +0 -311
  138. package/src/domain/workload.ts +0 -457
  139. package/src/engine/actor.test.ts +0 -63
  140. package/src/engine/authorization.test.ts +0 -199
  141. package/src/engine/cascade.test.ts +0 -121
  142. package/src/engine/config.test.ts +0 -51
  143. package/src/engine/entity-events.test.ts +0 -67
  144. package/src/engine/index.ts +0 -2495
  145. package/src/index.test.ts +0 -514
  146. package/src/index.ts +0 -9
  147. package/src/plugins/index.ts +0 -103
  148. package/src/plugins/plugins.test.ts +0 -161
  149. package/src/schemas/index.ts +0 -402
  150. package/src/schemas/schemas.test.ts +0 -116
  151. package/src/status.test.ts +0 -354
  152. package/src/storage/file-storage.ts +0 -200
  153. package/src/storage/firebase-storage.ts +0 -209
  154. package/src/storage/index.ts +0 -3
  155. package/src/storage/s3.ts +0 -151
  156. package/src/storage/storage.test.ts +0 -274
  157. package/src/storage/upload-limits.test.ts +0 -41
  158. package/src/store/conformance.test.ts +0 -15
  159. package/src/store/firebase.test.ts +0 -131
  160. package/src/store/firebase.ts +0 -658
  161. package/src/store/index.ts +0 -623
  162. package/src/store/query.test.ts +0 -110
  163. package/src/store/query.ts +0 -113
  164. package/src/store/sqlite.test.ts +0 -218
  165. package/src/store/sqlite.ts +0 -1480
  166. package/src/task-state.test.ts +0 -506
  167. package/src/testing/conformance.ts +0 -319
  168. package/src/testing/index.ts +0 -1
  169. package/src/types/index.ts +0 -871
  170. package/src/use-case-validation.test.ts +0 -324
  171. package/src/utils/fractional-index.test.ts +0 -228
  172. package/src/utils/fractional-index.ts +0 -254
  173. package/src/utils/index.ts +0 -7
  174. package/src/utils/key.test.ts +0 -76
  175. package/src/utils/key.ts +0 -62
  176. package/src/utils/mentions.test.ts +0 -132
  177. package/src/utils/mentions.ts +0 -131
  178. package/src/utils/status.ts +0 -419
  179. package/src/utils/workflow.ts +0 -306
  180. package/src/webhooks/dispatcher.ts +0 -190
  181. package/src/webhooks/index.ts +0 -2
  182. package/src/webhooks/signature.ts +0 -57
  183. package/src/webhooks/webhooks.test.ts +0 -201
  184. package/tsconfig.json +0 -8
  185. package/tsconfig.tsbuildinfo +0 -1
package/src/domain/cpm.ts DELETED
@@ -1,258 +0,0 @@
1
- import type {
2
- Task,
3
- TaskDependency,
4
- TaskCriticalPathSchedule,
5
- CriticalPathAnalysis,
6
- WorkSchedule
7
- } from '../types/index.js';
8
- import { DEFAULT_WORK_SCHEDULE, addWorkingHours, parseDate } from './calendar.js';
9
-
10
- export function getTaskDurationHours(task: Task): number {
11
- if (typeof task.estimatedHours === 'number' && task.estimatedHours >= 0) {
12
- return task.estimatedHours;
13
- }
14
- if (typeof task.estimatedDurationMinutes === 'number' && task.estimatedDurationMinutes >= 0) {
15
- return task.estimatedDurationMinutes / 60;
16
- }
17
- if (typeof task.actualHours === 'number' && task.actualHours > 0) {
18
- return task.actualHours;
19
- }
20
- // Default to 1 hour for non-empty tasks without explicit estimate
21
- return 1;
22
- }
23
-
24
- export interface CPMOptions {
25
- projectStartDate?: string | Date;
26
- schedule?: WorkSchedule;
27
- }
28
-
29
- /**
30
- * Calculates the Critical Path Method (CPM) schedule for a set of tasks and their dependencies.
31
- * - Forward Pass: computes earlyStart and earlyFinish (in working hours and calendar dates)
32
- * - Backward Pass: computes lateStart, lateFinish, and totalSlack
33
- * - Respects working days, working hours, and holidays via WorkSchedule
34
- * - Identifies critical tasks (totalSlack === 0) that dictate the minimum project duration.
35
- */
36
- export function calculateCPM(
37
- projectId: string,
38
- tasks: Task[],
39
- dependencies: TaskDependency[],
40
- options: CPMOptions = {}
41
- ): CriticalPathAnalysis {
42
- const calculatedAt = new Date().toISOString();
43
- const schedule = options.schedule || DEFAULT_WORK_SCHEDULE;
44
- const projectStartDate = options.projectStartDate ? parseDate(options.projectStartDate) : undefined;
45
-
46
- if (tasks.length === 0) {
47
- return {
48
- projectId,
49
- calculatedAt,
50
- totalDurationHours: 0,
51
- totalWorkingHours: 0,
52
- projectStartDate: projectStartDate ? projectStartDate.toISOString() : undefined,
53
- projectEndDate: projectStartDate ? projectStartDate.toISOString() : undefined,
54
- criticalTaskIds: [],
55
- tasks: []
56
- };
57
- }
58
-
59
- const taskMap = new Map<string, Task>(tasks.map((t) => [t.id, t]));
60
- const taskIds = Array.from(taskMap.keys());
61
-
62
- // Build adjacency graph:
63
- // prerequisites[v] = tasks that v depends on (must finish before v starts)
64
- // successors[u] = tasks that depend on u (can only start after u finishes)
65
- const prerequisites = new Map<string, Set<string>>();
66
- const successors = new Map<string, Set<string>>();
67
-
68
- for (const id of taskIds) {
69
- prerequisites.set(id, new Set<string>());
70
- successors.set(id, new Set<string>());
71
- }
72
-
73
- for (const dep of dependencies) {
74
- let sourceId: string | null = null;
75
- let targetId: string | null = null;
76
-
77
- if (dep.type === 'blocking') {
78
- // taskId depends on dependsOnTaskId (dependsOnTaskId -> taskId)
79
- sourceId = dep.dependsOnTaskId;
80
- targetId = dep.taskId;
81
- } else if (dep.type === 'blocked_by') {
82
- // dependsOnTaskId is blocked by taskId (taskId -> dependsOnTaskId)
83
- sourceId = dep.taskId;
84
- targetId = dep.dependsOnTaskId;
85
- }
86
-
87
- if (sourceId && targetId && taskMap.has(sourceId) && taskMap.has(targetId) && sourceId !== targetId) {
88
- prerequisites.get(targetId)!.add(sourceId);
89
- successors.get(sourceId)!.add(targetId);
90
- }
91
- }
92
-
93
- // Topological sorting via Kahn's algorithm
94
- const inDegree = new Map<string, number>();
95
- for (const id of taskIds) {
96
- inDegree.set(id, prerequisites.get(id)!.size);
97
- }
98
-
99
- const queue: string[] = [];
100
- for (const [id, deg] of inDegree.entries()) {
101
- if (deg === 0) {
102
- queue.push(id);
103
- }
104
- }
105
-
106
- const topoOrder: string[] = [];
107
- while (queue.length > 0) {
108
- const current = queue.shift()!;
109
- topoOrder.push(current);
110
-
111
- for (const next of successors.get(current)!) {
112
- const updatedDeg = inDegree.get(next)! - 1;
113
- inDegree.set(next, updatedDeg);
114
- if (updatedDeg === 0) {
115
- queue.push(next);
116
- }
117
- }
118
- }
119
-
120
- // If there's a cycle or disconnected nodes not processed in topoOrder, append them
121
- if (topoOrder.length < taskIds.length) {
122
- for (const id of taskIds) {
123
- if (!topoOrder.includes(id)) {
124
- topoOrder.push(id);
125
- }
126
- }
127
- }
128
-
129
- // --- FORWARD PASS ---
130
- const earlyStart = new Map<string, number>();
131
- const earlyFinish = new Map<string, number>();
132
-
133
- for (const id of topoOrder) {
134
- const task = taskMap.get(id)!;
135
- const duration = getTaskDurationHours(task);
136
- const prereqs = prerequisites.get(id) || new Set();
137
-
138
- let maxPrereqFinish = 0;
139
- for (const p of prereqs) {
140
- const pFinish = earlyFinish.get(p) ?? 0;
141
- if (pFinish > maxPrereqFinish) {
142
- maxPrereqFinish = pFinish;
143
- }
144
- }
145
-
146
- const es = maxPrereqFinish;
147
- const ef = es + duration;
148
-
149
- earlyStart.set(id, es);
150
- earlyFinish.set(id, ef);
151
- }
152
-
153
- // Total project duration
154
- let totalDurationHours = 0;
155
- for (const ef of earlyFinish.values()) {
156
- if (ef > totalDurationHours) {
157
- totalDurationHours = ef;
158
- }
159
- }
160
-
161
- // --- BACKWARD PASS ---
162
- const lateStart = new Map<string, number>();
163
- const lateFinish = new Map<string, number>();
164
-
165
- // Process in reverse topological order
166
- for (let i = topoOrder.length - 1; i >= 0; i--) {
167
- const id = topoOrder[i];
168
- const task = taskMap.get(id)!;
169
- const duration = getTaskDurationHours(task);
170
- const succs = successors.get(id) || new Set();
171
-
172
- let minSuccLateStart = totalDurationHours;
173
- if (succs.size > 0) {
174
- minSuccLateStart = Infinity;
175
- for (const s of succs) {
176
- const sLateStart = lateStart.get(s);
177
- if (sLateStart !== undefined && sLateStart < minSuccLateStart) {
178
- minSuccLateStart = sLateStart;
179
- }
180
- }
181
- if (!Number.isFinite(minSuccLateStart)) {
182
- minSuccLateStart = totalDurationHours;
183
- }
184
- }
185
-
186
- const lf = minSuccLateStart;
187
- const ls = lf - duration;
188
-
189
- lateFinish.set(id, lf);
190
- lateStart.set(id, ls);
191
- }
192
-
193
- // --- SLACK & CRITICAL PATH ---
194
- const schedules: TaskCriticalPathSchedule[] = [];
195
- const criticalTaskIds: string[] = [];
196
-
197
- for (const id of taskIds) {
198
- const es = earlyStart.get(id) ?? 0;
199
- const ef = earlyFinish.get(id) ?? 0;
200
- const ls = lateStart.get(id) ?? 0;
201
- const lf = lateFinish.get(id) ?? 0;
202
-
203
- const rawSlack = lf - ef;
204
- const totalSlack = Math.round(rawSlack * 100) / 100;
205
- const isCritical = totalSlack <= 0.001;
206
-
207
- if (isCritical) {
208
- criticalTaskIds.push(id);
209
- }
210
-
211
- const task = taskMap.get(id)!;
212
- const duration = getTaskDurationHours(task);
213
-
214
- const earlyStartDate = projectStartDate
215
- ? addWorkingHours(projectStartDate, es, schedule).toISOString()
216
- : undefined;
217
- const earlyFinishDate = projectStartDate
218
- ? addWorkingHours(projectStartDate, ef, schedule).toISOString()
219
- : undefined;
220
- const lateStartDate = projectStartDate
221
- ? addWorkingHours(projectStartDate, ls, schedule).toISOString()
222
- : undefined;
223
- const lateFinishDate = projectStartDate
224
- ? addWorkingHours(projectStartDate, lf, schedule).toISOString()
225
- : undefined;
226
-
227
- schedules.push({
228
- taskId: id,
229
- earlyStart: Math.round(es * 100) / 100,
230
- earlyFinish: Math.round(ef * 100) / 100,
231
- lateStart: Math.round(ls * 100) / 100,
232
- lateFinish: Math.round(lf * 100) / 100,
233
- totalSlack,
234
- isCritical,
235
- durationHours: duration,
236
- slackWorkingHours: totalSlack,
237
- earlyStartDate,
238
- earlyFinishDate,
239
- lateStartDate,
240
- lateFinishDate
241
- });
242
- }
243
-
244
- const projectEndDate = projectStartDate
245
- ? addWorkingHours(projectStartDate, totalDurationHours, schedule).toISOString()
246
- : undefined;
247
-
248
- return {
249
- projectId,
250
- calculatedAt,
251
- totalDurationHours: Math.round(totalDurationHours * 100) / 100,
252
- totalWorkingHours: Math.round(totalDurationHours * 100) / 100,
253
- projectStartDate: projectStartDate ? projectStartDate.toISOString() : undefined,
254
- projectEndDate,
255
- criticalTaskIds,
256
- tasks: schedules
257
- };
258
- }
@@ -1,172 +0,0 @@
1
- import type { CustomFieldDefinition, CustomFieldType } from '../types/index.js';
2
- import { BUILT_IN_CUSTOM_FIELD_TYPES } from '../plugins/index.js';
3
-
4
- export class CustomFieldValidationError extends Error {
5
- public readonly fieldKey: string;
6
- public readonly expectedType?: string;
7
- public readonly receivedValue?: unknown;
8
-
9
- constructor(message: string, fieldKey: string, expectedType?: string, receivedValue?: unknown) {
10
- super(message);
11
- this.name = 'CustomFieldValidationError';
12
- this.fieldKey = fieldKey;
13
- this.expectedType = expectedType;
14
- this.receivedValue = receivedValue;
15
- }
16
- }
17
-
18
- export function validateCustomFieldValues(
19
- definitions: CustomFieldDefinition[] | undefined,
20
- values: Record<string, unknown> | undefined,
21
- customTypes?: ReadonlyMap<string, CustomFieldType>
22
- ): void {
23
- if (!definitions || definitions.length === 0) return;
24
- const customValues = values || {};
25
-
26
- for (const def of definitions) {
27
- const value = customValues[def.key];
28
-
29
- // Check required invariant
30
- if (def.required && (value === undefined || value === null || value === '')) {
31
- throw new CustomFieldValidationError(
32
- `Custom field "${def.label || def.key}" (${def.key}) is required.`,
33
- def.key,
34
- def.type,
35
- value
36
- );
37
- }
38
-
39
- if (value === undefined || value === null) {
40
- continue;
41
- }
42
-
43
- // Type and schema validation
44
- switch (def.type) {
45
- case 'number':
46
- if (typeof value !== 'number' || isNaN(value)) {
47
- throw new CustomFieldValidationError(
48
- `Custom field "${def.label || def.key}" must be a valid number. Received: ${typeof value}`,
49
- def.key,
50
- 'number',
51
- value
52
- );
53
- }
54
- break;
55
-
56
- case 'text':
57
- case 'user':
58
- if (typeof value !== 'string') {
59
- throw new CustomFieldValidationError(
60
- `Custom field "${def.label || def.key}" must be a string. Received: ${typeof value}`,
61
- def.key,
62
- def.type,
63
- value
64
- );
65
- }
66
- break;
67
-
68
- case 'boolean':
69
- if (typeof value !== 'boolean') {
70
- throw new CustomFieldValidationError(
71
- `Custom field "${def.label || def.key}" must be a boolean. Received: ${typeof value}`,
72
- def.key,
73
- 'boolean',
74
- value
75
- );
76
- }
77
- break;
78
-
79
- case 'date':
80
- if (typeof value !== 'string' || isNaN(new Date(value).getTime())) {
81
- throw new CustomFieldValidationError(
82
- `Custom field "${def.label || def.key}" must be a valid ISO date string. Received: ${JSON.stringify(value)}`,
83
- def.key,
84
- 'date',
85
- value
86
- );
87
- }
88
- break;
89
-
90
- case 'single_select':
91
- if (typeof value !== 'string') {
92
- throw new CustomFieldValidationError(
93
- `Custom field "${def.label || def.key}" must be a string option. Received: ${typeof value}`,
94
- def.key,
95
- 'single_select',
96
- value
97
- );
98
- }
99
- if (def.options && def.options.length > 0 && !def.options.includes(value)) {
100
- throw new CustomFieldValidationError(
101
- `Custom field "${def.label || def.key}" value "${value}" is not an allowed option [${def.options.join(', ')}].`,
102
- def.key,
103
- 'single_select',
104
- value
105
- );
106
- }
107
- break;
108
-
109
- case 'multi_select':
110
- if (!Array.isArray(value)) {
111
- throw new CustomFieldValidationError(
112
- `Custom field "${def.label || def.key}" must be an array of string options. Received: ${typeof value}`,
113
- def.key,
114
- 'multi_select',
115
- value
116
- );
117
- }
118
- if (def.options && def.options.length > 0) {
119
- for (const item of value) {
120
- if (typeof item !== 'string' || !def.options.includes(item)) {
121
- throw new CustomFieldValidationError(
122
- `Custom field "${def.label || def.key}" option "${item}" is not allowed in [${def.options.join(', ')}].`,
123
- def.key,
124
- 'multi_select',
125
- item
126
- );
127
- }
128
- }
129
- }
130
- break;
131
- default: {
132
- const custom = customTypes?.get(def.type);
133
- if (!custom) {
134
- throw new CustomFieldValidationError(
135
- `Custom field "${def.label || def.key}" has unknown type "${def.type}". Register it with a plugin's customFieldTypes.`,
136
- def.key,
137
- def.type,
138
- value
139
- );
140
- }
141
- const problem = custom.validate(value, def);
142
- if (problem) {
143
- throw new CustomFieldValidationError(
144
- `Custom field "${def.label || def.key}" ${problem}`,
145
- def.key,
146
- def.type,
147
- value
148
- );
149
- }
150
- }
151
- }
152
- }
153
- }
154
-
155
- /**
156
- * Checks that every definition uses a built-in type or one registered by a plugin, so projects
157
- * cannot be configured with fields that would reject every value.
158
- */
159
- export function validateCustomFieldDefinitions(
160
- definitions: CustomFieldDefinition[] | undefined,
161
- customTypes?: ReadonlyMap<string, CustomFieldType>
162
- ): void {
163
- for (const def of definitions ?? []) {
164
- if (!(BUILT_IN_CUSTOM_FIELD_TYPES as readonly string[]).includes(def.type) && !customTypes?.has(def.type)) {
165
- throw new CustomFieldValidationError(
166
- `Custom field "${def.label || def.key}" has unknown type "${def.type}". Register it with a plugin's customFieldTypes.`,
167
- def.key,
168
- def.type
169
- );
170
- }
171
- }
172
- }