@simpleplatform/ui-kit 0.2.1 → 0.3.0
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/README.md +267 -37
- package/dist/contracts/index.d.ts +2 -0
- package/dist/contracts/index.d.ts.map +1 -1
- package/dist/contracts/index.js +1 -0
- package/dist/contracts/views.d.ts +181 -0
- package/dist/contracts/views.d.ts.map +1 -0
- package/dist/contracts/views.js +813 -0
- package/dist/react/index.d.ts +2 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +1 -0
- package/dist/react/record-bridge.d.ts +9 -0
- package/dist/react/record-bridge.d.ts.map +1 -1
- package/dist/react/record-bridge.js +8 -0
- package/dist/react/record-form.d.ts.map +1 -1
- package/dist/react/record-form.js +3 -0
- package/dist/react/record-view.d.ts +6 -0
- package/dist/react/record-view.d.ts.map +1 -0
- package/dist/react/record-view.js +190 -0
- package/dist/runtime.d.ts +2 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +7 -1
- package/package.json +2 -2
|
@@ -0,0 +1,813 @@
|
|
|
1
|
+
export const FILTER_OPERATORS_V1 = [
|
|
2
|
+
'between',
|
|
3
|
+
'contained_in',
|
|
4
|
+
'contains',
|
|
5
|
+
'ends_with',
|
|
6
|
+
'eq',
|
|
7
|
+
'future',
|
|
8
|
+
'gt',
|
|
9
|
+
'gte',
|
|
10
|
+
'has_key',
|
|
11
|
+
'has_keys_all',
|
|
12
|
+
'has_keys_any',
|
|
13
|
+
'in',
|
|
14
|
+
'is_empty',
|
|
15
|
+
'is_false',
|
|
16
|
+
'is_not_empty',
|
|
17
|
+
'is_not_null',
|
|
18
|
+
'is_null',
|
|
19
|
+
'is_true',
|
|
20
|
+
'last_month',
|
|
21
|
+
'last_n_days',
|
|
22
|
+
'last_week',
|
|
23
|
+
'last_year',
|
|
24
|
+
'lt',
|
|
25
|
+
'lte',
|
|
26
|
+
'neq',
|
|
27
|
+
'next_n_days',
|
|
28
|
+
'nin',
|
|
29
|
+
'past',
|
|
30
|
+
'path_exists',
|
|
31
|
+
'regex',
|
|
32
|
+
'starts_with',
|
|
33
|
+
'this_month',
|
|
34
|
+
'this_week',
|
|
35
|
+
'this_year',
|
|
36
|
+
'today',
|
|
37
|
+
'yesterday',
|
|
38
|
+
];
|
|
39
|
+
export const RECORD_VIEW_ICON_IDS_V1 = [
|
|
40
|
+
'lucide:circle-alert',
|
|
41
|
+
'lucide:arrow-up-right',
|
|
42
|
+
'lucide:columns-3',
|
|
43
|
+
'lucide:box',
|
|
44
|
+
'lucide:calendar-days',
|
|
45
|
+
'lucide:check',
|
|
46
|
+
'lucide:clock-3',
|
|
47
|
+
'lucide:file',
|
|
48
|
+
'lucide:circle-question-mark',
|
|
49
|
+
'lucide:inbox',
|
|
50
|
+
'lucide:layout-grid',
|
|
51
|
+
'lucide:list',
|
|
52
|
+
'lucide:mail',
|
|
53
|
+
'lucide:settings',
|
|
54
|
+
'lucide:star',
|
|
55
|
+
'lucide:table',
|
|
56
|
+
'lucide:tag',
|
|
57
|
+
'lucide:user-round',
|
|
58
|
+
'lucide:video',
|
|
59
|
+
];
|
|
60
|
+
export const RECORD_TILE_PRESENTATIONS_V1 = [
|
|
61
|
+
'editorial',
|
|
62
|
+
'email',
|
|
63
|
+
'media',
|
|
64
|
+
'person',
|
|
65
|
+
'row',
|
|
66
|
+
'spotlight',
|
|
67
|
+
'status',
|
|
68
|
+
];
|
|
69
|
+
export const RECORD_VIEW_KINDS_V1 = ['board', 'inbox', 'list', 'table'];
|
|
70
|
+
export class RecordViewContractError extends Error {
|
|
71
|
+
constructor(message) {
|
|
72
|
+
super(message);
|
|
73
|
+
this.name = 'RecordViewContractError';
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function isPlainObject(value) {
|
|
77
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
78
|
+
return false;
|
|
79
|
+
const proto = Object.getPrototypeOf(value);
|
|
80
|
+
return proto === Object.prototype || proto === null;
|
|
81
|
+
}
|
|
82
|
+
function isNonEmptyString(value) {
|
|
83
|
+
return typeof value === 'string' && value.trim().length > 0 && value.trim() === value;
|
|
84
|
+
}
|
|
85
|
+
function assertOnlyKeys(value, allowed, label) {
|
|
86
|
+
const allowedKeys = new Set(allowed);
|
|
87
|
+
const unexpected = Object.keys(value).find(key => !allowedKeys.has(key));
|
|
88
|
+
if (unexpected)
|
|
89
|
+
throw new RecordViewContractError(`${label} contains an unsupported property: ${unexpected}.`);
|
|
90
|
+
}
|
|
91
|
+
export function validateTableRecordSourceV1(value) {
|
|
92
|
+
if (!isPlainObject(value))
|
|
93
|
+
throw new RecordViewContractError('Record source must be an object.');
|
|
94
|
+
if (value.kind !== 'table')
|
|
95
|
+
throw new RecordViewContractError('Record source kind must be \'table\'.');
|
|
96
|
+
assertOnlyKeys(value, ['kind', 'appId', 'tableId'], 'Table source');
|
|
97
|
+
if (!isNonEmptyString(value.appId))
|
|
98
|
+
throw new RecordViewContractError('Table source appId must be a non-empty string without whitespace padding.');
|
|
99
|
+
if (!isNonEmptyString(value.tableId))
|
|
100
|
+
throw new RecordViewContractError('Table source tableId must be a non-empty string without whitespace padding.');
|
|
101
|
+
return { appId: value.appId, kind: 'table', tableId: value.tableId };
|
|
102
|
+
}
|
|
103
|
+
export function validateRecordSourceV1(value) {
|
|
104
|
+
return validateTableRecordSourceV1(value);
|
|
105
|
+
}
|
|
106
|
+
export function isRecordSourceV1(value) {
|
|
107
|
+
try {
|
|
108
|
+
validateRecordSourceV1(value);
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
export function validateRecordReferenceV1(value) {
|
|
116
|
+
if (!isPlainObject(value)) {
|
|
117
|
+
throw new RecordViewContractError('Record reference must be an object.');
|
|
118
|
+
}
|
|
119
|
+
if (!isNonEmptyString(value.appId)) {
|
|
120
|
+
throw new RecordViewContractError('Record reference appId must be a non-empty string.');
|
|
121
|
+
}
|
|
122
|
+
if (!isNonEmptyString(value.tableName)) {
|
|
123
|
+
throw new RecordViewContractError('Record reference tableName must be a non-empty string.');
|
|
124
|
+
}
|
|
125
|
+
if (!isNonEmptyString(value.recordId)) {
|
|
126
|
+
throw new RecordViewContractError('Record reference recordId must be a non-empty string.');
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
appId: value.appId,
|
|
130
|
+
recordId: value.recordId,
|
|
131
|
+
tableName: value.tableName,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
export function isRecordReferenceV1(value) {
|
|
135
|
+
try {
|
|
136
|
+
validateRecordReferenceV1(value);
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
export function validateViewItemReferenceV1(value) {
|
|
144
|
+
if (!isPlainObject(value)) {
|
|
145
|
+
throw new RecordViewContractError('View item reference must be an object.');
|
|
146
|
+
}
|
|
147
|
+
if (value.kind !== 'record')
|
|
148
|
+
throw new RecordViewContractError(`View item reference kind must be 'record', got '${String(value.kind)}'.`);
|
|
149
|
+
assertOnlyKeys(value, ['appId', 'kind', 'recordId', 'tableName'], 'Record view item reference');
|
|
150
|
+
return { ...validateRecordReferenceV1(value), kind: 'record' };
|
|
151
|
+
}
|
|
152
|
+
export function isViewItemReferenceV1(value) {
|
|
153
|
+
try {
|
|
154
|
+
validateViewItemReferenceV1(value);
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const MAX_FILTER_DEPTH = 8;
|
|
162
|
+
const MAX_FILTER_NODES = 100;
|
|
163
|
+
const MAX_GROUP_CHILDREN = 50;
|
|
164
|
+
const MAX_OPERAND_DEPTH = 4;
|
|
165
|
+
const MAX_OPERAND_ITEMS = 100;
|
|
166
|
+
const MAX_STRING_LENGTH = 4096;
|
|
167
|
+
const MAX_PRESETS = 20;
|
|
168
|
+
const MAX_VIEW_FIELDS = 40;
|
|
169
|
+
const MAX_SORT_FIELDS = 5;
|
|
170
|
+
const MAX_LANES = 20;
|
|
171
|
+
const MAX_LANE_PAGE_SIZE = 50;
|
|
172
|
+
const SAFE_TILE_ICON_IDS = new Set(RECORD_VIEW_ICON_IDS_V1);
|
|
173
|
+
const isSafeTileIconId = (value) => typeof value === 'string' && SAFE_TILE_ICON_IDS.has(value);
|
|
174
|
+
const FILTER_OPERATORS_WITHOUT_VALUES = new Set([
|
|
175
|
+
'future',
|
|
176
|
+
'is_empty',
|
|
177
|
+
'is_false',
|
|
178
|
+
'is_not_empty',
|
|
179
|
+
'is_not_null',
|
|
180
|
+
'is_null',
|
|
181
|
+
'is_true',
|
|
182
|
+
'last_month',
|
|
183
|
+
'last_week',
|
|
184
|
+
'last_year',
|
|
185
|
+
'past',
|
|
186
|
+
'this_month',
|
|
187
|
+
'this_week',
|
|
188
|
+
'this_year',
|
|
189
|
+
'today',
|
|
190
|
+
'yesterday',
|
|
191
|
+
]);
|
|
192
|
+
function validateJsonValue(value, depth = 0, seen = new Set()) {
|
|
193
|
+
if (depth > MAX_OPERAND_DEPTH) {
|
|
194
|
+
throw new RecordViewContractError('Filter operand is nested too deeply.');
|
|
195
|
+
}
|
|
196
|
+
if (value === null || typeof value === 'boolean')
|
|
197
|
+
return value;
|
|
198
|
+
if (typeof value === 'number' && Number.isFinite(value))
|
|
199
|
+
return value;
|
|
200
|
+
if (typeof value === 'string') {
|
|
201
|
+
if (value.length > MAX_STRING_LENGTH)
|
|
202
|
+
throw new RecordViewContractError('Filter operand string is too long.');
|
|
203
|
+
return value;
|
|
204
|
+
}
|
|
205
|
+
if (typeof value !== 'object')
|
|
206
|
+
throw new RecordViewContractError('Filter operands must be JSON values.');
|
|
207
|
+
if (seen.has(value))
|
|
208
|
+
throw new RecordViewContractError('Filter operands cannot contain cycles.');
|
|
209
|
+
seen.add(value);
|
|
210
|
+
try {
|
|
211
|
+
if (Array.isArray(value)) {
|
|
212
|
+
if (value.length > MAX_OPERAND_ITEMS)
|
|
213
|
+
throw new RecordViewContractError('Filter operand contains too many items.');
|
|
214
|
+
return value.map(item => validateJsonValue(item, depth + 1, seen));
|
|
215
|
+
}
|
|
216
|
+
if (!isPlainObject(value))
|
|
217
|
+
throw new RecordViewContractError('Filter operands must be plain JSON objects.');
|
|
218
|
+
const entries = Object.entries(value);
|
|
219
|
+
if (entries.length > MAX_OPERAND_ITEMS)
|
|
220
|
+
throw new RecordViewContractError('Filter operand contains too many properties.');
|
|
221
|
+
return Object.fromEntries(entries.map(([key, item]) => {
|
|
222
|
+
if (!key || key.length > 128 || key === '__proto__' || key === 'constructor' || key === 'prototype')
|
|
223
|
+
throw new RecordViewContractError('Filter operand contains an invalid key.');
|
|
224
|
+
return [key, validateJsonValue(item, depth + 1, seen)];
|
|
225
|
+
}));
|
|
226
|
+
}
|
|
227
|
+
finally {
|
|
228
|
+
seen.delete(value);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
function validateFilterNode(node, depth, state) {
|
|
232
|
+
if (depth > MAX_FILTER_DEPTH || ++state.count > MAX_FILTER_NODES)
|
|
233
|
+
throw new RecordViewContractError('Filter expression is nested too deeply or has too many nodes.');
|
|
234
|
+
if (!isPlainObject(node)) {
|
|
235
|
+
throw new RecordViewContractError('Filter node must be an object.');
|
|
236
|
+
}
|
|
237
|
+
if (node.kind === 'group') {
|
|
238
|
+
assertOnlyKeys(node, ['children', 'kind', 'operator'], 'Filter group');
|
|
239
|
+
if (node.operator !== 'and' && node.operator !== 'or') {
|
|
240
|
+
throw new RecordViewContractError(`Filter group operator must be 'and' or 'or', got ${String(node.operator)}.`);
|
|
241
|
+
}
|
|
242
|
+
if (!Array.isArray(node.children) || node.children.length === 0 || node.children.length > MAX_GROUP_CHILDREN) {
|
|
243
|
+
throw new RecordViewContractError('Filter group children must contain between 1 and 50 nodes.');
|
|
244
|
+
}
|
|
245
|
+
return {
|
|
246
|
+
children: node.children.map(child => validateFilterNode(child, depth + 1, state)),
|
|
247
|
+
kind: 'group',
|
|
248
|
+
operator: node.operator,
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
if (node.kind === 'predicate') {
|
|
252
|
+
if (!isNonEmptyString(node.fieldName)) {
|
|
253
|
+
throw new RecordViewContractError('Filter predicate fieldName must be a non-empty string.');
|
|
254
|
+
}
|
|
255
|
+
if (node.fieldName.length > 200)
|
|
256
|
+
throw new RecordViewContractError('Filter predicate fieldName must be at most 200 characters.');
|
|
257
|
+
assertOnlyKeys(node, ['fieldName', 'kind', 'operator', 'value', 'value2'], 'Filter predicate');
|
|
258
|
+
if (!FILTER_OPERATORS_V1.includes(node.operator)) {
|
|
259
|
+
throw new RecordViewContractError(`Unknown filter operator: ${String(node.operator)}.`);
|
|
260
|
+
}
|
|
261
|
+
const operator = node.operator;
|
|
262
|
+
const hasValue = Object.prototype.hasOwnProperty.call(node, 'value');
|
|
263
|
+
const hasValue2 = Object.prototype.hasOwnProperty.call(node, 'value2');
|
|
264
|
+
if (FILTER_OPERATORS_WITHOUT_VALUES.has(operator)) {
|
|
265
|
+
if (hasValue || hasValue2)
|
|
266
|
+
throw new RecordViewContractError(`Filter operator ${operator} does not accept a value.`);
|
|
267
|
+
}
|
|
268
|
+
else if (!hasValue) {
|
|
269
|
+
throw new RecordViewContractError(`Filter operator ${operator} requires a value.`);
|
|
270
|
+
}
|
|
271
|
+
if (operator === 'between' && !hasValue2)
|
|
272
|
+
throw new RecordViewContractError('Filter operator between requires two values.');
|
|
273
|
+
if (operator !== 'between' && hasValue2)
|
|
274
|
+
throw new RecordViewContractError(`Filter operator ${operator} does not accept a second value.`);
|
|
275
|
+
if ((operator === 'last_n_days' || operator === 'next_n_days') && typeof node.value !== 'number')
|
|
276
|
+
throw new RecordViewContractError(`Filter operator ${operator} requires a number.`);
|
|
277
|
+
const value = hasValue ? validateJsonValue(node.value) : undefined;
|
|
278
|
+
const value2 = hasValue2 ? validateJsonValue(node.value2) : undefined;
|
|
279
|
+
if (operator === 'between' && ((typeof value === 'object' && value !== null) || (typeof value2 === 'object' && value2 !== null)))
|
|
280
|
+
throw new RecordViewContractError('The between filter requires scalar bounds.');
|
|
281
|
+
if (value !== undefined && Array.isArray(value) && value.length > MAX_OPERAND_ITEMS)
|
|
282
|
+
throw new RecordViewContractError('Filter operand contains too many items.');
|
|
283
|
+
return {
|
|
284
|
+
fieldName: node.fieldName,
|
|
285
|
+
kind: 'predicate',
|
|
286
|
+
operator: node.operator,
|
|
287
|
+
...(value !== undefined ? { value } : {}),
|
|
288
|
+
...(value2 !== undefined ? { value2 } : {}),
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
throw new RecordViewContractError(`Unknown filter node kind: ${String(node.kind)}.`);
|
|
292
|
+
}
|
|
293
|
+
export function validateFilterExpressionV1(value) {
|
|
294
|
+
if (!isPlainObject(value)) {
|
|
295
|
+
throw new RecordViewContractError('Filter expression must be an object.');
|
|
296
|
+
}
|
|
297
|
+
if (value.version !== 1) {
|
|
298
|
+
throw new RecordViewContractError(`Filter expression version must be 1, got ${String(value.version)}.`);
|
|
299
|
+
}
|
|
300
|
+
assertOnlyKeys(value, ['root', 'version'], 'Filter expression');
|
|
301
|
+
const root = validateFilterNode(value.root, 1, { count: 0 });
|
|
302
|
+
return {
|
|
303
|
+
root,
|
|
304
|
+
version: 1,
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
/** Validates filter shape for the authorized record source. */
|
|
308
|
+
export function validateSourceFilterExpressionV1(source, value) {
|
|
309
|
+
validateRecordSourceV1(source);
|
|
310
|
+
const validatedFilter = validateFilterExpressionV1(value);
|
|
311
|
+
return validatedFilter;
|
|
312
|
+
}
|
|
313
|
+
export function isFilterExpressionV1(value) {
|
|
314
|
+
try {
|
|
315
|
+
validateFilterExpressionV1(value);
|
|
316
|
+
return true;
|
|
317
|
+
}
|
|
318
|
+
catch {
|
|
319
|
+
return false;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
export function validateRecordSortV1(value) {
|
|
323
|
+
if (!isPlainObject(value)) {
|
|
324
|
+
throw new RecordViewContractError('Record sort must be an object.');
|
|
325
|
+
}
|
|
326
|
+
if (!isNonEmptyString(value.fieldName)) {
|
|
327
|
+
throw new RecordViewContractError('Record sort fieldName must be a non-empty string.');
|
|
328
|
+
}
|
|
329
|
+
assertOnlyKeys(value, ['direction', 'fieldName'], 'Record sort');
|
|
330
|
+
if (value.fieldName.length > 200)
|
|
331
|
+
throw new RecordViewContractError('Record sort fieldName must be at most 200 characters.');
|
|
332
|
+
if (value.direction !== 'asc' && value.direction !== 'desc') {
|
|
333
|
+
throw new RecordViewContractError(`Record sort direction must be 'asc' or 'desc', got ${String(value.direction)}.`);
|
|
334
|
+
}
|
|
335
|
+
return {
|
|
336
|
+
direction: value.direction,
|
|
337
|
+
fieldName: value.fieldName,
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
export function isRecordSortV1(value) {
|
|
341
|
+
try {
|
|
342
|
+
validateRecordSortV1(value);
|
|
343
|
+
return true;
|
|
344
|
+
}
|
|
345
|
+
catch {
|
|
346
|
+
return false;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
export function validateRecordTileLayoutV1(value) {
|
|
350
|
+
if (!isPlainObject(value)) {
|
|
351
|
+
throw new RecordViewContractError('Record tile layout must be an object.');
|
|
352
|
+
}
|
|
353
|
+
if (value.version !== 1) {
|
|
354
|
+
throw new RecordViewContractError(`Record tile layout version must be 1, got ${String(value.version)}.`);
|
|
355
|
+
}
|
|
356
|
+
if (!RECORD_TILE_PRESENTATIONS_V1.includes(value.presentation)) {
|
|
357
|
+
throw new RecordViewContractError(`Invalid tile presentation: ${String(value.presentation)}.`);
|
|
358
|
+
}
|
|
359
|
+
if (!isNonEmptyString(value.titleFieldName)) {
|
|
360
|
+
throw new RecordViewContractError('Record tile layout titleFieldName must be a non-empty string.');
|
|
361
|
+
}
|
|
362
|
+
if (value.presentation === 'email') {
|
|
363
|
+
if (!isNonEmptyString(value.eyebrowFieldName) || !isNonEmptyString(value.subtitleFieldName) || !isNonEmptyString(value.trailingFieldName)) {
|
|
364
|
+
throw new RecordViewContractError('Email tiles require sender, preview, and received-at fields.');
|
|
365
|
+
}
|
|
366
|
+
if (value.badgeFieldNames !== undefined || value.detailFieldNames !== undefined || value.visual !== undefined) {
|
|
367
|
+
throw new RecordViewContractError('Email tiles do not support badges, details, or visuals.');
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
assertOnlyKeys(value, ['badgeFieldNames', 'detailFieldNames', 'eyebrowFieldName', 'presentation', 'subtitleFieldName', 'titleFieldName', 'trailingFieldName', 'version', 'visual'], 'Record tile layout');
|
|
371
|
+
for (const name of ['titleFieldName', 'eyebrowFieldName', 'subtitleFieldName', 'trailingFieldName']) {
|
|
372
|
+
const fieldName = value[name];
|
|
373
|
+
if (fieldName !== undefined && (typeof fieldName !== 'string' || fieldName.length > 200))
|
|
374
|
+
throw new RecordViewContractError(`Record tile layout ${name} must be at most 200 characters.`);
|
|
375
|
+
}
|
|
376
|
+
let visual;
|
|
377
|
+
if (value.visual !== undefined) {
|
|
378
|
+
if (!isPlainObject(value.visual)) {
|
|
379
|
+
throw new RecordViewContractError('Tile visual must be an object.');
|
|
380
|
+
}
|
|
381
|
+
if (value.visual.kind === 'image') {
|
|
382
|
+
if (!isNonEmptyString(value.visual.fieldName)) {
|
|
383
|
+
throw new RecordViewContractError('Tile image visual requires fieldName.');
|
|
384
|
+
}
|
|
385
|
+
if (value.visual.altFieldName !== undefined && !isNonEmptyString(value.visual.altFieldName)) {
|
|
386
|
+
throw new RecordViewContractError('Tile image visual altFieldName must be a non-empty string.');
|
|
387
|
+
}
|
|
388
|
+
if (value.visual.fieldName.length > 200 || (typeof value.visual.altFieldName === 'string' && value.visual.altFieldName.length > 200))
|
|
389
|
+
throw new RecordViewContractError('Tile image visual field names must be at most 200 characters.');
|
|
390
|
+
if (value.visual.fit !== undefined && value.visual.fit !== 'cover' && value.visual.fit !== 'contain') {
|
|
391
|
+
throw new RecordViewContractError(`Tile image visual fit must be 'cover' or 'contain', got ${String(value.visual.fit)}.`);
|
|
392
|
+
}
|
|
393
|
+
assertOnlyKeys(value.visual, ['altFieldName', 'fieldName', 'fit', 'kind'], 'Tile image visual');
|
|
394
|
+
visual = {
|
|
395
|
+
...(value.visual.altFieldName ? { altFieldName: value.visual.altFieldName } : {}),
|
|
396
|
+
fieldName: value.visual.fieldName,
|
|
397
|
+
...(value.visual.fit ? { fit: value.visual.fit } : {}),
|
|
398
|
+
kind: 'image',
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
else if (value.visual.kind === 'icon') {
|
|
402
|
+
if (!isNonEmptyString(value.visual.iconId)) {
|
|
403
|
+
throw new RecordViewContractError('Tile icon visual requires iconId.');
|
|
404
|
+
}
|
|
405
|
+
if (!isSafeTileIconId(value.visual.iconId))
|
|
406
|
+
throw new RecordViewContractError(`Tile icon is not in the platform icon catalogue: ${value.visual.iconId}.`);
|
|
407
|
+
assertOnlyKeys(value.visual, ['iconId', 'kind'], 'Tile icon visual');
|
|
408
|
+
visual = { iconId: value.visual.iconId, kind: 'icon' };
|
|
409
|
+
}
|
|
410
|
+
else if (value.visual.kind === 'enum-icon') {
|
|
411
|
+
if (!isNonEmptyString(value.visual.fieldName)) {
|
|
412
|
+
throw new RecordViewContractError('Tile enum-icon visual requires fieldName.');
|
|
413
|
+
}
|
|
414
|
+
if (!isPlainObject(value.visual.iconsByValue)) {
|
|
415
|
+
throw new RecordViewContractError('Tile enum-icon visual requires iconsByValue map.');
|
|
416
|
+
}
|
|
417
|
+
const iconValues = Object.keys(value.visual.iconsByValue);
|
|
418
|
+
if (iconValues.length > 100 || iconValues.some(key => !isNonEmptyString(key) || key.length > 200))
|
|
419
|
+
throw new RecordViewContractError('Tile enum-icon map must contain at most 100 unpadded, non-empty values of at most 200 characters.');
|
|
420
|
+
if (!isNonEmptyString(value.visual.fallbackIconId)) {
|
|
421
|
+
throw new RecordViewContractError('Tile enum-icon visual requires fallbackIconId.');
|
|
422
|
+
}
|
|
423
|
+
if (value.visual.fieldName.length > 200)
|
|
424
|
+
throw new RecordViewContractError('Tile enum-icon fieldName must be at most 200 characters.');
|
|
425
|
+
for (const iconId of [value.visual.fallbackIconId, ...Object.values(value.visual.iconsByValue)]) {
|
|
426
|
+
if (!isSafeTileIconId(iconId))
|
|
427
|
+
throw new RecordViewContractError(`Tile icon is not in the platform icon catalogue: ${String(iconId)}.`);
|
|
428
|
+
}
|
|
429
|
+
assertOnlyKeys(value.visual, ['fallbackIconId', 'fieldName', 'iconsByValue', 'kind'], 'Tile enum icon visual');
|
|
430
|
+
visual = {
|
|
431
|
+
fallbackIconId: value.visual.fallbackIconId,
|
|
432
|
+
fieldName: value.visual.fieldName,
|
|
433
|
+
iconsByValue: Object.fromEntries(Object.entries(value.visual.iconsByValue).map(([key, iconId]) => [key, iconId])),
|
|
434
|
+
kind: 'enum-icon',
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
else {
|
|
438
|
+
throw new RecordViewContractError(`Invalid tile visual kind: ${String(value.visual.kind)}.`);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
const checkOptionalStringArray = (arr, name) => {
|
|
442
|
+
if (arr === undefined)
|
|
443
|
+
return undefined;
|
|
444
|
+
if (!Array.isArray(arr) || arr.length > MAX_VIEW_FIELDS || !arr.every(item => isNonEmptyString(item) && item.length <= 200)) {
|
|
445
|
+
throw new RecordViewContractError(`Tile layout ${name} must be an array of non-empty strings.`);
|
|
446
|
+
}
|
|
447
|
+
if (new Set(arr).size !== arr.length)
|
|
448
|
+
throw new RecordViewContractError(`Tile layout ${name} cannot contain duplicate fields.`);
|
|
449
|
+
return arr;
|
|
450
|
+
};
|
|
451
|
+
if (value.eyebrowFieldName !== undefined && !isNonEmptyString(value.eyebrowFieldName)) {
|
|
452
|
+
throw new RecordViewContractError('Tile layout eyebrowFieldName must be a non-empty string.');
|
|
453
|
+
}
|
|
454
|
+
if (value.subtitleFieldName !== undefined && !isNonEmptyString(value.subtitleFieldName)) {
|
|
455
|
+
throw new RecordViewContractError('Tile layout subtitleFieldName must be a non-empty string.');
|
|
456
|
+
}
|
|
457
|
+
if (value.trailingFieldName !== undefined && !isNonEmptyString(value.trailingFieldName)) {
|
|
458
|
+
throw new RecordViewContractError('Tile layout trailingFieldName must be a non-empty string.');
|
|
459
|
+
}
|
|
460
|
+
return {
|
|
461
|
+
...(value.badgeFieldNames !== undefined ? { badgeFieldNames: checkOptionalStringArray(value.badgeFieldNames, 'badgeFieldNames') } : {}),
|
|
462
|
+
...(value.detailFieldNames !== undefined ? { detailFieldNames: checkOptionalStringArray(value.detailFieldNames, 'detailFieldNames') } : {}),
|
|
463
|
+
...(isNonEmptyString(value.eyebrowFieldName) ? { eyebrowFieldName: value.eyebrowFieldName } : {}),
|
|
464
|
+
presentation: value.presentation,
|
|
465
|
+
...(isNonEmptyString(value.subtitleFieldName) ? { subtitleFieldName: value.subtitleFieldName } : {}),
|
|
466
|
+
titleFieldName: value.titleFieldName,
|
|
467
|
+
...(isNonEmptyString(value.trailingFieldName) ? { trailingFieldName: value.trailingFieldName } : {}),
|
|
468
|
+
version: 1,
|
|
469
|
+
...(visual ? { visual } : {}),
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
export function isRecordTileLayoutV1(value) {
|
|
473
|
+
try {
|
|
474
|
+
validateRecordTileLayoutV1(value);
|
|
475
|
+
return true;
|
|
476
|
+
}
|
|
477
|
+
catch {
|
|
478
|
+
return false;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
function validatePresetBase(value) {
|
|
482
|
+
if (!isPlainObject(value)) {
|
|
483
|
+
throw new RecordViewContractError('Preset must be an object.');
|
|
484
|
+
}
|
|
485
|
+
if (!isNonEmptyString(value.id)) {
|
|
486
|
+
throw new RecordViewContractError('Preset id must be a non-empty string.');
|
|
487
|
+
}
|
|
488
|
+
if (!isNonEmptyString(value.title)) {
|
|
489
|
+
throw new RecordViewContractError('Preset title must be a non-empty string.');
|
|
490
|
+
}
|
|
491
|
+
assertOnlyKeys(value, ['config', 'filter', 'id', 'kind', 'orderBy', 'title'], 'Preset');
|
|
492
|
+
if (value.id.length > 80 || value.title.length > 120)
|
|
493
|
+
throw new RecordViewContractError('Preset id must be at most 80 characters and title at most 120 characters.');
|
|
494
|
+
const filter = value.filter !== undefined ? validateFilterExpressionV1(value.filter) : undefined;
|
|
495
|
+
const orderBy = validateOrderBy(value.orderBy);
|
|
496
|
+
return {
|
|
497
|
+
...(filter ? { filter } : {}),
|
|
498
|
+
id: value.id,
|
|
499
|
+
...(orderBy ? { orderBy } : {}),
|
|
500
|
+
title: value.title,
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
function validateOrderBy(orderBy) {
|
|
504
|
+
if (orderBy === undefined)
|
|
505
|
+
return undefined;
|
|
506
|
+
if (!Array.isArray(orderBy) || orderBy.length > MAX_SORT_FIELDS) {
|
|
507
|
+
throw new RecordViewContractError(`Preset orderBy must contain at most ${MAX_SORT_FIELDS} sort fields.`);
|
|
508
|
+
}
|
|
509
|
+
const sorts = orderBy.map(validateRecordSortV1);
|
|
510
|
+
if (new Set(sorts.map(sort => sort.fieldName)).size !== sorts.length)
|
|
511
|
+
throw new RecordViewContractError('Preset orderBy cannot contain duplicate fields.');
|
|
512
|
+
return sorts;
|
|
513
|
+
}
|
|
514
|
+
export function validateListPresetV1(value) {
|
|
515
|
+
const base = validatePresetBase(value);
|
|
516
|
+
const obj = value;
|
|
517
|
+
if (obj.kind !== 'list') {
|
|
518
|
+
throw new RecordViewContractError(`List preset kind must be 'list', got ${String(obj.kind)}.`);
|
|
519
|
+
}
|
|
520
|
+
if (!isPlainObject(obj.config)) {
|
|
521
|
+
throw new RecordViewContractError('List preset config must be an object.');
|
|
522
|
+
}
|
|
523
|
+
const tile = validateRecordTileLayoutV1(obj.config.tile);
|
|
524
|
+
assertOnlyKeys(obj.config, ['tile'], 'List preset config');
|
|
525
|
+
return {
|
|
526
|
+
...base,
|
|
527
|
+
config: {
|
|
528
|
+
tile,
|
|
529
|
+
},
|
|
530
|
+
kind: 'list',
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
export function isListPresetV1(value) {
|
|
534
|
+
try {
|
|
535
|
+
validateListPresetV1(value);
|
|
536
|
+
return true;
|
|
537
|
+
}
|
|
538
|
+
catch {
|
|
539
|
+
return false;
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
export function validateDataGridPresetV1(value) {
|
|
543
|
+
const base = validatePresetBase(value);
|
|
544
|
+
const obj = value;
|
|
545
|
+
if (obj.kind !== 'table') {
|
|
546
|
+
throw new RecordViewContractError(`DataGrid preset kind must be 'table', got ${String(obj.kind)}.`);
|
|
547
|
+
}
|
|
548
|
+
if (!isPlainObject(obj.config)) {
|
|
549
|
+
throw new RecordViewContractError('DataGrid preset config must be an object.');
|
|
550
|
+
}
|
|
551
|
+
assertOnlyKeys(obj.config, ['columns', 'tile'], 'DataGrid preset config');
|
|
552
|
+
if (!Array.isArray(obj.config.columns) || obj.config.columns.length === 0 || obj.config.columns.length > MAX_VIEW_FIELDS) {
|
|
553
|
+
throw new RecordViewContractError(`DataGrid preset columns must contain 1 to ${MAX_VIEW_FIELDS} columns.`);
|
|
554
|
+
}
|
|
555
|
+
const columns = obj.config.columns.map((col) => {
|
|
556
|
+
if (!isPlainObject(col) || !isNonEmptyString(col.fieldName)) {
|
|
557
|
+
throw new RecordViewContractError('Column definition must include non-empty fieldName.');
|
|
558
|
+
}
|
|
559
|
+
assertOnlyKeys(col, ['fieldName', 'width'], 'DataGrid column');
|
|
560
|
+
if (col.fieldName.length > 200) {
|
|
561
|
+
throw new RecordViewContractError('DataGrid fieldName must be at most 200 characters.');
|
|
562
|
+
}
|
|
563
|
+
if (col.width !== undefined && (typeof col.width !== 'number' || !Number.isFinite(col.width) || col.width < 80 || col.width > 800)) {
|
|
564
|
+
throw new RecordViewContractError('Column width must be between 80 and 800 pixels.');
|
|
565
|
+
}
|
|
566
|
+
return {
|
|
567
|
+
fieldName: col.fieldName,
|
|
568
|
+
...(col.width !== undefined ? { width: col.width } : {}),
|
|
569
|
+
};
|
|
570
|
+
});
|
|
571
|
+
if (new Set(columns.map(column => column.fieldName)).size !== columns.length)
|
|
572
|
+
throw new RecordViewContractError('DataGrid columns cannot contain duplicate fields.');
|
|
573
|
+
const tile = obj.config.tile !== undefined ? validateRecordTileLayoutV1(obj.config.tile) : undefined;
|
|
574
|
+
return {
|
|
575
|
+
...base,
|
|
576
|
+
config: {
|
|
577
|
+
columns,
|
|
578
|
+
...(tile ? { tile } : {}),
|
|
579
|
+
},
|
|
580
|
+
kind: 'table',
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
export function isDataGridPresetV1(value) {
|
|
584
|
+
try {
|
|
585
|
+
validateDataGridPresetV1(value);
|
|
586
|
+
return true;
|
|
587
|
+
}
|
|
588
|
+
catch {
|
|
589
|
+
return false;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
export function validateBoardPresetV1(value) {
|
|
593
|
+
const base = validatePresetBase(value);
|
|
594
|
+
const obj = value;
|
|
595
|
+
if (obj.kind !== 'board') {
|
|
596
|
+
throw new RecordViewContractError(`Board preset kind must be 'board', got ${String(obj.kind)}.`);
|
|
597
|
+
}
|
|
598
|
+
if (!isPlainObject(obj.config)) {
|
|
599
|
+
throw new RecordViewContractError('Board preset config must be an object.');
|
|
600
|
+
}
|
|
601
|
+
if (!isNonEmptyString(obj.config.laneFieldName)) {
|
|
602
|
+
throw new RecordViewContractError('Board preset laneFieldName must be a non-empty string.');
|
|
603
|
+
}
|
|
604
|
+
if (obj.config.laneFieldName.length > 200)
|
|
605
|
+
throw new RecordViewContractError('Board preset laneFieldName must be at most 200 characters.');
|
|
606
|
+
assertOnlyKeys(obj.config, ['laneFieldName', 'laneOrder', 'lanePageSize', 'summaries', 'tile'], 'Board preset config');
|
|
607
|
+
const tile = validateRecordTileLayoutV1(obj.config.tile);
|
|
608
|
+
if (obj.config.laneOrder !== undefined && (!Array.isArray(obj.config.laneOrder) || obj.config.laneOrder.length === 0 || obj.config.laneOrder.length > MAX_LANES || !obj.config.laneOrder.every(isNonEmptyString))) {
|
|
609
|
+
throw new RecordViewContractError(`Board preset laneOrder must contain 1 to ${MAX_LANES} non-empty strings.`);
|
|
610
|
+
}
|
|
611
|
+
if (Array.isArray(obj.config.laneOrder) && new Set(obj.config.laneOrder).size !== obj.config.laneOrder.length) {
|
|
612
|
+
throw new RecordViewContractError('Board preset laneOrder cannot contain duplicate values.');
|
|
613
|
+
}
|
|
614
|
+
if (obj.config.lanePageSize !== undefined && (!Number.isInteger(obj.config.lanePageSize) || obj.config.lanePageSize < 1 || obj.config.lanePageSize > MAX_LANE_PAGE_SIZE))
|
|
615
|
+
throw new RecordViewContractError(`Board preset lanePageSize must be between 1 and ${MAX_LANE_PAGE_SIZE}.`);
|
|
616
|
+
const summaries = validateRecordViewSummariesV1(obj.config.summaries);
|
|
617
|
+
return {
|
|
618
|
+
...base,
|
|
619
|
+
config: {
|
|
620
|
+
laneFieldName: obj.config.laneFieldName,
|
|
621
|
+
...(obj.config.laneOrder ? { laneOrder: obj.config.laneOrder } : {}),
|
|
622
|
+
...(obj.config.lanePageSize !== undefined ? { lanePageSize: obj.config.lanePageSize } : {}),
|
|
623
|
+
...(summaries ? { summaries } : {}),
|
|
624
|
+
tile,
|
|
625
|
+
},
|
|
626
|
+
kind: 'board',
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
function validateRecordViewSummariesV1(value) {
|
|
630
|
+
if (value === undefined)
|
|
631
|
+
return undefined;
|
|
632
|
+
if (!Array.isArray(value) || value.length > 3)
|
|
633
|
+
throw new RecordViewContractError('Board summaries must contain at most 3 numeric summaries.');
|
|
634
|
+
const summaries = value.map((entry) => {
|
|
635
|
+
if (!isPlainObject(entry))
|
|
636
|
+
throw new RecordViewContractError('Board summary must be an object.');
|
|
637
|
+
assertOnlyKeys(entry, ['fieldName', 'operation'], 'Board summary');
|
|
638
|
+
if (!isNonEmptyString(entry.fieldName) || entry.fieldName.length > 200)
|
|
639
|
+
throw new RecordViewContractError('Board summary fieldName must be a non-empty string of at most 200 characters.');
|
|
640
|
+
if (entry.operation !== 'average' && entry.operation !== 'max' && entry.operation !== 'min' && entry.operation !== 'sum')
|
|
641
|
+
throw new RecordViewContractError('Board summary operation must be average, max, min, or sum.');
|
|
642
|
+
return { fieldName: entry.fieldName, operation: entry.operation };
|
|
643
|
+
});
|
|
644
|
+
if (new Set(summaries.map(summary => `${summary.operation}:${summary.fieldName}`)).size !== summaries.length)
|
|
645
|
+
throw new RecordViewContractError('Board summaries cannot contain duplicates.');
|
|
646
|
+
return summaries;
|
|
647
|
+
}
|
|
648
|
+
export function isBoardPresetV1(value) {
|
|
649
|
+
if (!isPlainObject(value) || value.kind !== 'board')
|
|
650
|
+
return false;
|
|
651
|
+
try {
|
|
652
|
+
validateBoardPresetV1(value);
|
|
653
|
+
return true;
|
|
654
|
+
}
|
|
655
|
+
catch {
|
|
656
|
+
return false;
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
export function validateInboxPresetV1(value) {
|
|
660
|
+
const base = validatePresetBase(value);
|
|
661
|
+
const obj = value;
|
|
662
|
+
if (obj.kind !== 'inbox') {
|
|
663
|
+
throw new RecordViewContractError(`Inbox preset kind must be 'inbox', got ${String(obj.kind)}.`);
|
|
664
|
+
}
|
|
665
|
+
if (!isPlainObject(obj.config)) {
|
|
666
|
+
throw new RecordViewContractError('Inbox preset config must be an object.');
|
|
667
|
+
}
|
|
668
|
+
const listTile = validateRecordTileLayoutV1(obj.config.listTile);
|
|
669
|
+
if (obj.config.detail !== undefined && obj.config.detail !== 'fields' && obj.config.detail !== 'record')
|
|
670
|
+
throw new RecordViewContractError('Inbox detail must be fields or record.');
|
|
671
|
+
if (obj.config.detail === 'record' && obj.config.detailFieldNames !== undefined) {
|
|
672
|
+
throw new RecordViewContractError('Inbox detailFieldNames are only valid when detail is fields.');
|
|
673
|
+
}
|
|
674
|
+
const detailFieldNames = obj.config.detail === 'record' ? undefined : obj.config.detailFieldNames;
|
|
675
|
+
if (detailFieldNames !== undefined && (!Array.isArray(detailFieldNames) || detailFieldNames.length === 0 || detailFieldNames.length > MAX_VIEW_FIELDS || !detailFieldNames.every(name => isNonEmptyString(name) && name.length <= 200))) {
|
|
676
|
+
throw new RecordViewContractError(`Inbox preset detailFieldNames must contain 1 to ${MAX_VIEW_FIELDS} non-empty field names.`);
|
|
677
|
+
}
|
|
678
|
+
if (detailFieldNames === undefined && obj.config.detail !== 'record') {
|
|
679
|
+
throw new RecordViewContractError(`Inbox preset detailFieldNames must contain 1 to ${MAX_VIEW_FIELDS} non-empty field names.`);
|
|
680
|
+
}
|
|
681
|
+
if (Array.isArray(detailFieldNames) && new Set(detailFieldNames).size !== detailFieldNames.length)
|
|
682
|
+
throw new RecordViewContractError('Inbox preset detailFieldNames cannot contain duplicates.');
|
|
683
|
+
assertOnlyKeys(obj.config, ['detail', 'detailFieldNames', 'listTile'], 'Inbox preset config');
|
|
684
|
+
const detailConfig = obj.config.detail === 'record'
|
|
685
|
+
? { detail: 'record' }
|
|
686
|
+
: {
|
|
687
|
+
...(obj.config.detail === 'fields' ? { detail: 'fields' } : {}),
|
|
688
|
+
detailFieldNames: detailFieldNames,
|
|
689
|
+
};
|
|
690
|
+
return {
|
|
691
|
+
...base,
|
|
692
|
+
config: {
|
|
693
|
+
...detailConfig,
|
|
694
|
+
listTile,
|
|
695
|
+
},
|
|
696
|
+
kind: 'inbox',
|
|
697
|
+
};
|
|
698
|
+
}
|
|
699
|
+
export function isInboxPresetV1(value) {
|
|
700
|
+
try {
|
|
701
|
+
validateInboxPresetV1(value);
|
|
702
|
+
return true;
|
|
703
|
+
}
|
|
704
|
+
catch {
|
|
705
|
+
return false;
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
export function validateRecordViewPresetV1(value) {
|
|
709
|
+
if (!isPlainObject(value)) {
|
|
710
|
+
throw new RecordViewContractError('Preset must be an object.');
|
|
711
|
+
}
|
|
712
|
+
switch (value.kind) {
|
|
713
|
+
case 'list':
|
|
714
|
+
return validateListPresetV1(value);
|
|
715
|
+
case 'table':
|
|
716
|
+
return validateDataGridPresetV1(value);
|
|
717
|
+
case 'board':
|
|
718
|
+
return validateBoardPresetV1(value);
|
|
719
|
+
case 'inbox':
|
|
720
|
+
return validateInboxPresetV1(value);
|
|
721
|
+
default:
|
|
722
|
+
throw new RecordViewContractError(`Unknown record view preset kind: ${String(value.kind)}.`);
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
export function isRecordViewPresetV1(value) {
|
|
726
|
+
try {
|
|
727
|
+
validateRecordViewPresetV1(value);
|
|
728
|
+
return true;
|
|
729
|
+
}
|
|
730
|
+
catch {
|
|
731
|
+
return false;
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
export function validateViewPresetSetV1(value) {
|
|
735
|
+
if (!isPlainObject(value)) {
|
|
736
|
+
throw new RecordViewContractError('ViewPresetSet must be an object.');
|
|
737
|
+
}
|
|
738
|
+
assertOnlyKeys(value, ['defaultPresetId', 'presets', 'version'], 'ViewPresetSet');
|
|
739
|
+
if (value.version !== 1) {
|
|
740
|
+
throw new RecordViewContractError(`ViewPresetSet version must be 1, got ${String(value.version)}.`);
|
|
741
|
+
}
|
|
742
|
+
if (!isNonEmptyString(value.defaultPresetId)) {
|
|
743
|
+
throw new RecordViewContractError('ViewPresetSet defaultPresetId must be a non-empty string.');
|
|
744
|
+
}
|
|
745
|
+
if (value.defaultPresetId.length > 80)
|
|
746
|
+
throw new RecordViewContractError('ViewPresetSet defaultPresetId must be at most 80 characters.');
|
|
747
|
+
if (!Array.isArray(value.presets) || value.presets.length === 0 || value.presets.length > MAX_PRESETS) {
|
|
748
|
+
throw new RecordViewContractError(`ViewPresetSet presets must contain 1 to ${MAX_PRESETS} presets.`);
|
|
749
|
+
}
|
|
750
|
+
const presets = value.presets.map(validateRecordViewPresetV1);
|
|
751
|
+
const ids = new Set();
|
|
752
|
+
for (const preset of presets) {
|
|
753
|
+
if (ids.has(preset.id)) {
|
|
754
|
+
throw new RecordViewContractError(`Duplicate preset id found: ${preset.id}.`);
|
|
755
|
+
}
|
|
756
|
+
ids.add(preset.id);
|
|
757
|
+
}
|
|
758
|
+
if (!ids.has(value.defaultPresetId)) {
|
|
759
|
+
throw new RecordViewContractError(`defaultPresetId '${value.defaultPresetId}' not found in presets.`);
|
|
760
|
+
}
|
|
761
|
+
return {
|
|
762
|
+
defaultPresetId: value.defaultPresetId,
|
|
763
|
+
presets,
|
|
764
|
+
version: 1,
|
|
765
|
+
};
|
|
766
|
+
}
|
|
767
|
+
export function isViewPresetSetV1(value) {
|
|
768
|
+
try {
|
|
769
|
+
validateViewPresetSetV1(value);
|
|
770
|
+
return true;
|
|
771
|
+
}
|
|
772
|
+
catch {
|
|
773
|
+
return false;
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
export function validateControlledFilterPropsV1(props) {
|
|
777
|
+
if (!isPlainObject(props)) {
|
|
778
|
+
throw new RecordViewContractError('Props must be an object.');
|
|
779
|
+
}
|
|
780
|
+
const hasFilter = 'filter' in props;
|
|
781
|
+
const hasOnFilterChange = 'onFilterChange' in props;
|
|
782
|
+
if (!hasFilter && !hasOnFilterChange) {
|
|
783
|
+
return {};
|
|
784
|
+
}
|
|
785
|
+
if (hasFilter && props.filter === undefined && !hasOnFilterChange) {
|
|
786
|
+
return {};
|
|
787
|
+
}
|
|
788
|
+
if (hasFilter && !hasOnFilterChange) {
|
|
789
|
+
throw new RecordViewContractError('Controlled filter requires onFilterChange callback.');
|
|
790
|
+
}
|
|
791
|
+
if (!hasFilter && hasOnFilterChange) {
|
|
792
|
+
throw new RecordViewContractError('Controlled onFilterChange requires filter expression prop.');
|
|
793
|
+
}
|
|
794
|
+
if (typeof props.onFilterChange !== 'function') {
|
|
795
|
+
throw new RecordViewContractError('onFilterChange must be a function.');
|
|
796
|
+
}
|
|
797
|
+
if (props.filter !== undefined) {
|
|
798
|
+
validateFilterExpressionV1(props.filter);
|
|
799
|
+
}
|
|
800
|
+
return {
|
|
801
|
+
filter: props.filter,
|
|
802
|
+
onFilterChange: props.onFilterChange,
|
|
803
|
+
};
|
|
804
|
+
}
|
|
805
|
+
export function isControlledFilterPropsV1(props) {
|
|
806
|
+
try {
|
|
807
|
+
validateControlledFilterPropsV1(props);
|
|
808
|
+
return true;
|
|
809
|
+
}
|
|
810
|
+
catch {
|
|
811
|
+
return false;
|
|
812
|
+
}
|
|
813
|
+
}
|