@object-ui/core 17.6.0 → 17.7.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.
Files changed (134) hide show
  1. package/CHANGELOG.md +6610 -0
  2. package/README.md +101 -14
  3. package/dist/actions/ActionEngine.d.ts +4 -2
  4. package/dist/actions/ActionEngine.js +13 -8
  5. package/dist/actions/ActionRunner.d.ts +288 -27
  6. package/dist/actions/ActionRunner.js +443 -63
  7. package/dist/actions/TransactionManager.d.ts +7 -2
  8. package/dist/actions/actionKeys.d.ts +9 -7
  9. package/dist/actions/actionKeys.js +57 -14
  10. package/dist/actions/actionResponse.js +2 -2
  11. package/dist/actions/index.d.ts +1 -0
  12. package/dist/actions/index.js +1 -0
  13. package/dist/actions/recordDelete.d.ts +118 -0
  14. package/dist/actions/recordDelete.js +112 -0
  15. package/dist/adapters/ValueDataSource.d.ts +6 -1
  16. package/dist/adapters/ValueDataSource.js +1090 -98
  17. package/dist/adapters/batchTransaction.d.ts +1 -1
  18. package/dist/adapters/batchTransaction.js +1 -1
  19. package/dist/builder/schema-builder.d.ts +38 -81
  20. package/dist/builder/schema-builder.js +33 -152
  21. package/dist/data-scope/ViewDataProvider.d.ts +1 -1
  22. package/dist/data-scope/ViewDataProvider.js +21 -1
  23. package/dist/data-scope/element-data-source.d.ts +261 -7
  24. package/dist/data-scope/element-data-source.js +342 -52
  25. package/dist/data-scope/index.d.ts +9 -4
  26. package/dist/data-scope/index.js +9 -4
  27. package/dist/evaluator/ExpressionEvaluator.d.ts +86 -0
  28. package/dist/evaluator/ExpressionEvaluator.js +184 -12
  29. package/dist/evaluator/FormulaFunctions.d.ts +0 -10
  30. package/dist/evaluator/FormulaFunctions.js +166 -27
  31. package/dist/evaluator/declaredPredicate.d.ts +93 -9
  32. package/dist/evaluator/declaredPredicate.js +117 -16
  33. package/dist/evaluator/fieldRules.d.ts +88 -4
  34. package/dist/evaluator/fieldRules.js +203 -31
  35. package/dist/evaluator/index.d.ts +1 -0
  36. package/dist/evaluator/index.js +1 -0
  37. package/dist/evaluator/listConditional.d.ts +103 -34
  38. package/dist/evaluator/listConditional.js +127 -50
  39. package/dist/evaluator/optionRules.d.ts +77 -6
  40. package/dist/evaluator/optionRules.js +87 -10
  41. package/dist/evaluator/predicateInput.d.ts +15 -4
  42. package/dist/evaluator/predicateInput.js +35 -2
  43. package/dist/evaluator/rowPredicateCanon.d.ts +7 -18
  44. package/dist/evaluator/rowPredicateCanon.js +65 -115
  45. package/dist/evaluator/subjectPermissions.d.ts +76 -0
  46. package/dist/evaluator/subjectPermissions.js +44 -0
  47. package/dist/evaluator/unevaluablePredicate.d.ts +57 -0
  48. package/dist/evaluator/unevaluablePredicate.js +70 -0
  49. package/dist/index.d.ts +14 -0
  50. package/dist/index.js +80 -2
  51. package/dist/protocols/index.d.ts +0 -1
  52. package/dist/protocols/index.js +9 -1
  53. package/dist/registry/Registry.d.ts +358 -31
  54. package/dist/registry/Registry.js +263 -11
  55. package/dist/registry/WidgetRegistry.js +7 -3
  56. package/dist/registry/html-tier-intrinsics.d.ts +90 -0
  57. package/dist/registry/html-tier-intrinsics.js +110 -0
  58. package/dist/registry/public-blocks.d.ts +8 -0
  59. package/dist/registry/public-blocks.js +57 -0
  60. package/dist/theme/ThemeEngine.js +1 -1
  61. package/dist/utils/chart-category-key.d.ts +82 -0
  62. package/dist/utils/chart-category-key.js +84 -0
  63. package/dist/utils/chart-measure-key.d.ts +64 -0
  64. package/dist/utils/chart-measure-key.js +65 -0
  65. package/dist/utils/chart-presentation.d.ts +95 -112
  66. package/dist/utils/chart-presentation.js +169 -104
  67. package/dist/utils/chart-series.d.ts +131 -5
  68. package/dist/utils/chart-series.js +98 -16
  69. package/dist/utils/column-sortability.d.ts +157 -0
  70. package/dist/utils/column-sortability.js +217 -0
  71. package/dist/utils/dashboard-filters.d.ts +38 -6
  72. package/dist/utils/dashboard-filters.js +107 -61
  73. package/dist/utils/dataset-format.d.ts +211 -30
  74. package/dist/utils/dataset-format.js +389 -46
  75. package/dist/utils/date-display.d.ts +354 -0
  76. package/dist/utils/date-display.js +463 -0
  77. package/dist/utils/date-macros.js +7 -0
  78. package/dist/utils/drill-down.d.ts +78 -0
  79. package/dist/utils/drill-down.js +93 -0
  80. package/dist/utils/emptiness.d.ts +96 -0
  81. package/dist/utils/emptiness.js +101 -0
  82. package/dist/utils/expand-fields.d.ts +76 -6
  83. package/dist/utils/expand-fields.js +76 -6
  84. package/dist/utils/extract-records.d.ts +65 -5
  85. package/dist/utils/extract-records.js +65 -8
  86. package/dist/utils/filter-converter.d.ts +152 -4
  87. package/dist/utils/filter-converter.js +1092 -22
  88. package/dist/utils/filter-tokens.d.ts +49 -5
  89. package/dist/utils/filter-tokens.js +105 -33
  90. package/dist/utils/grouping-fields.d.ts +61 -0
  91. package/dist/utils/grouping-fields.js +84 -0
  92. package/dist/utils/managedBy.d.ts +3 -3
  93. package/dist/utils/managedBy.js +5 -5
  94. package/dist/utils/native-date-value.d.ts +48 -0
  95. package/dist/utils/native-date-value.js +167 -0
  96. package/dist/utils/non-grid-row-ceiling.d.ts +143 -0
  97. package/dist/utils/non-grid-row-ceiling.js +141 -0
  98. package/dist/utils/normalize-list-view.d.ts +121 -1
  99. package/dist/utils/normalize-list-view.js +186 -6
  100. package/dist/utils/number-display.d.ts +63 -14
  101. package/dist/utils/number-display.js +34 -12
  102. package/dist/utils/object-aggregate-query.d.ts +113 -0
  103. package/dist/utils/object-aggregate-query.js +50 -0
  104. package/dist/utils/parent-scope.d.ts +123 -0
  105. package/dist/utils/parent-scope.js +140 -0
  106. package/dist/utils/predicate-fields.d.ts +45 -12
  107. package/dist/utils/predicate-fields.js +137 -12
  108. package/dist/utils/record-color.d.ts +75 -0
  109. package/dist/utils/record-color.js +65 -0
  110. package/dist/utils/record-source.d.ts +298 -0
  111. package/dist/utils/record-source.js +331 -0
  112. package/dist/utils/record-title.d.ts +148 -8
  113. package/dist/utils/record-title.js +220 -26
  114. package/dist/utils/reference-keys.d.ts +21 -22
  115. package/dist/utils/reference-keys.js +532 -29
  116. package/dist/utils/sort-query.d.ts +115 -15
  117. package/dist/utils/sort-query.js +240 -13
  118. package/dist/utils/text-comparand.d.ts +92 -0
  119. package/dist/utils/text-comparand.js +99 -0
  120. package/dist/utils/without-denied-fields.d.ts +49 -0
  121. package/dist/utils/without-denied-fields.js +52 -0
  122. package/dist/validation/index.d.ts +8 -4
  123. package/dist/validation/index.js +8 -4
  124. package/dist/validation/schema-validator.d.ts +1 -1
  125. package/dist/validation/schema-validator.js +200 -82
  126. package/dist/validation/validators/object-validation-engine.d.ts +1 -1
  127. package/dist/validation/validators/object-validation-engine.js +14 -3
  128. package/package.json +8 -9
  129. package/dist/data-scope/DataScopeManager.d.ts +0 -127
  130. package/dist/data-scope/DataScopeManager.js +0 -229
  131. package/dist/protocols/ResponsiveProtocol.d.ts +0 -73
  132. package/dist/protocols/ResponsiveProtocol.js +0 -158
  133. package/dist/validation/validation-engine.d.ts +0 -88
  134. package/dist/validation/validation-engine.js +0 -434
@@ -1,434 +0,0 @@
1
- /**
2
- * ObjectUI
3
- * Copyright (c) 2024-present ObjectStack Inc.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
- /**
9
- * Validation Engine - Executes validation rules
10
- */
11
- export class ValidationEngine {
12
- constructor() {
13
- Object.defineProperty(this, "customValidators", {
14
- enumerable: true,
15
- configurable: true,
16
- writable: true,
17
- value: new Map()
18
- });
19
- Object.defineProperty(this, "customAsyncValidators", {
20
- enumerable: true,
21
- configurable: true,
22
- writable: true,
23
- value: new Map()
24
- });
25
- }
26
- /**
27
- * Register a custom synchronous validator by name
28
- */
29
- registerValidator(name, fn) {
30
- this.customValidators.set(name, fn);
31
- }
32
- /**
33
- * Register a custom asynchronous validator by name
34
- */
35
- registerAsyncValidator(name, fn) {
36
- this.customAsyncValidators.set(name, fn);
37
- }
38
- /**
39
- * Check if a custom validator is registered
40
- */
41
- hasValidator(name) {
42
- return this.customValidators.has(name) || this.customAsyncValidators.has(name);
43
- }
44
- /**
45
- * Get all registered custom validator names
46
- */
47
- getValidatorNames() {
48
- return [
49
- ...Array.from(this.customValidators.keys()),
50
- ...Array.from(this.customAsyncValidators.keys()),
51
- ];
52
- }
53
- /**
54
- * Validate a value against validation schema
55
- */
56
- async validate(value, schema, context) {
57
- const errors = [];
58
- const warnings = [];
59
- for (const rule of schema.rules) {
60
- const result = await this.validateRule(value, rule, context);
61
- if (result) {
62
- const error = {
63
- field: schema.field || 'unknown',
64
- message: result,
65
- code: rule.type,
66
- rule: rule.type,
67
- severity: rule.severity || 'error',
68
- };
69
- if (rule.severity === 'warning' || rule.severity === 'info') {
70
- warnings.push(error);
71
- }
72
- else {
73
- errors.push(error);
74
- }
75
- }
76
- }
77
- return {
78
- valid: errors.length === 0,
79
- errors,
80
- warnings,
81
- };
82
- }
83
- /**
84
- * Validate a single rule
85
- */
86
- async validateRule(value, rule, context) {
87
- // Custom async validator (inline)
88
- if (rule.async_validator) {
89
- const result = await rule.async_validator(value, context);
90
- if (result === false) {
91
- return rule.message || 'Async validation failed';
92
- }
93
- if (typeof result === 'string') {
94
- return result;
95
- }
96
- return null;
97
- }
98
- // Custom sync validator (inline)
99
- if (rule.validator) {
100
- const result = rule.validator(value, context);
101
- if (result === false) {
102
- return rule.message || 'Validation failed';
103
- }
104
- if (typeof result === 'string') {
105
- return result;
106
- }
107
- return null;
108
- }
109
- // Registered custom async validator (by name)
110
- const registeredAsync = this.customAsyncValidators.get(rule.type);
111
- if (registeredAsync) {
112
- const result = await registeredAsync(value, context);
113
- if (result === false) {
114
- return rule.message || 'Async validation failed';
115
- }
116
- if (typeof result === 'string') {
117
- return result;
118
- }
119
- return null;
120
- }
121
- // Registered custom sync validator (by name)
122
- const registeredSync = this.customValidators.get(rule.type);
123
- if (registeredSync) {
124
- const result = registeredSync(value, context);
125
- if (result === false) {
126
- return rule.message || 'Validation failed';
127
- }
128
- if (typeof result === 'string') {
129
- return result;
130
- }
131
- return null;
132
- }
133
- // Built-in validators
134
- return this.validateBuiltInRule(value, rule, context);
135
- }
136
- /**
137
- * Validate built-in rules
138
- */
139
- async validateBuiltInRule(value, rule, context) {
140
- const { type, params, message } = rule;
141
- switch (type) {
142
- case 'required':
143
- if (value === null || value === undefined || value === '') {
144
- return message || 'This field is required';
145
- }
146
- break;
147
- case 'min_length':
148
- if (typeof value === 'string' && value.length < params) {
149
- return message || `Minimum length is ${params} characters`;
150
- }
151
- break;
152
- case 'max_length':
153
- if (typeof value === 'string' && value.length > params) {
154
- return message || `Maximum length is ${params} characters`;
155
- }
156
- break;
157
- case 'pattern':
158
- if (typeof value === 'string') {
159
- try {
160
- const regex = typeof params === 'string' ? new RegExp(params) : params;
161
- if (!regex.test(value)) {
162
- return message || 'Invalid format';
163
- }
164
- }
165
- catch (error) {
166
- return message || 'Invalid pattern configuration';
167
- }
168
- }
169
- break;
170
- case 'email':
171
- if (typeof value === 'string') {
172
- const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
173
- if (!emailRegex.test(value)) {
174
- return message || 'Invalid email address';
175
- }
176
- }
177
- break;
178
- case 'url':
179
- if (typeof value === 'string') {
180
- try {
181
- new URL(value);
182
- }
183
- catch {
184
- return message || 'Invalid URL';
185
- }
186
- }
187
- break;
188
- case 'phone':
189
- if (typeof value === 'string') {
190
- const phoneRegex = /^[\d\s\-+()]+$/;
191
- if (!phoneRegex.test(value)) {
192
- return message || 'Invalid phone number';
193
- }
194
- }
195
- break;
196
- case 'min':
197
- if (typeof value === 'number' && value < params) {
198
- return message || `Minimum value is ${params}`;
199
- }
200
- break;
201
- case 'max':
202
- if (typeof value === 'number' && value > params) {
203
- return message || `Maximum value is ${params}`;
204
- }
205
- break;
206
- case 'integer':
207
- if (typeof value === 'number' && !Number.isInteger(value)) {
208
- return message || 'Value must be an integer';
209
- }
210
- break;
211
- case 'positive':
212
- if (typeof value === 'number' && value <= 0) {
213
- return message || 'Value must be positive';
214
- }
215
- break;
216
- case 'negative':
217
- if (typeof value === 'number' && value >= 0) {
218
- return message || 'Value must be negative';
219
- }
220
- break;
221
- case 'date_min':
222
- if (value instanceof Date || typeof value === 'string') {
223
- const date = value instanceof Date ? value : new Date(value);
224
- const minDate = params instanceof Date ? params : new Date(params);
225
- if (date < minDate) {
226
- return message || `Date must be after ${minDate.toLocaleDateString()}`;
227
- }
228
- }
229
- break;
230
- case 'date_max':
231
- if (value instanceof Date || typeof value === 'string') {
232
- const date = value instanceof Date ? value : new Date(value);
233
- const maxDate = params instanceof Date ? params : new Date(params);
234
- if (date > maxDate) {
235
- return message || `Date must be before ${maxDate.toLocaleDateString()}`;
236
- }
237
- }
238
- break;
239
- case 'date_future':
240
- if (value instanceof Date || typeof value === 'string') {
241
- const date = value instanceof Date ? value : new Date(value);
242
- if (date <= new Date()) {
243
- return message || 'Date must be in the future';
244
- }
245
- }
246
- break;
247
- case 'date_past':
248
- if (value instanceof Date || typeof value === 'string') {
249
- const date = value instanceof Date ? value : new Date(value);
250
- if (date >= new Date()) {
251
- return message || 'Date must be in the past';
252
- }
253
- }
254
- break;
255
- case 'min_items':
256
- if (Array.isArray(value) && value.length < params) {
257
- return message || `Minimum ${params} items required`;
258
- }
259
- break;
260
- case 'max_items':
261
- if (Array.isArray(value) && value.length > params) {
262
- return message || `Maximum ${params} items allowed`;
263
- }
264
- break;
265
- case 'unique_items':
266
- if (Array.isArray(value)) {
267
- const unique = new Set(value);
268
- if (unique.size !== value.length) {
269
- return message || 'All items must be unique';
270
- }
271
- }
272
- break;
273
- case 'field_match':
274
- if (context?.values && params) {
275
- const otherValue = context.values[params];
276
- if (value !== otherValue) {
277
- return message || `Value must match ${params}`;
278
- }
279
- }
280
- break;
281
- case 'field_compare':
282
- if (context?.values && params) {
283
- const { field: otherField, operator } = params;
284
- const otherValue = context.values[otherField];
285
- switch (operator) {
286
- case '>':
287
- if (value <= otherValue) {
288
- return message || `Value must be greater than ${otherField}`;
289
- }
290
- break;
291
- case '<':
292
- if (value >= otherValue) {
293
- return message || `Value must be less than ${otherField}`;
294
- }
295
- break;
296
- case '>=':
297
- if (value < otherValue) {
298
- return message || `Value must be greater than or equal to ${otherField}`;
299
- }
300
- break;
301
- case '<=':
302
- if (value > otherValue) {
303
- return message || `Value must be less than or equal to ${otherField}`;
304
- }
305
- break;
306
- }
307
- }
308
- break;
309
- case 'conditional':
310
- if (context?.values && params) {
311
- const { condition, rules } = params;
312
- if (!Array.isArray(rules) || rules.length === 0) {
313
- break;
314
- }
315
- const conditionMet = this.evaluateCondition(condition, context.values);
316
- if (conditionMet) {
317
- for (const conditionalRule of rules) {
318
- const result = await this.validateRule(value, conditionalRule, context);
319
- if (result) {
320
- return result;
321
- }
322
- }
323
- }
324
- }
325
- break;
326
- default:
327
- // Unhandled validation rule type
328
- console.warn(`Unsupported validation rule type: ${type}`);
329
- return null;
330
- }
331
- return null;
332
- }
333
- /**
334
- * Evaluate a condition
335
- * Note: Conditions must be declarative objects, not functions, for security.
336
- */
337
- evaluateCondition(condition, values) {
338
- if (typeof condition === 'function') {
339
- console.warn('Function-based conditions are deprecated and will be removed. Use declarative conditions instead.\n\n' +
340
- ' Migration:\n' +
341
- ' // Before (deprecated):\n' +
342
- ' { condition: (values) => values.age > 18 }\n\n' +
343
- ' // After:\n' +
344
- ' { condition: { field: "age", operator: ">", value: 18 } }\n\n' +
345
- ' See: https://github.com/objectstack-ai/objectui/blob/main/MIGRATION_GUIDE.md');
346
- return false; // Security: reject function-based conditions
347
- }
348
- if (typeof condition === 'object' && condition.field) {
349
- const fieldValue = values[condition.field];
350
- const { operator = '=', value } = condition;
351
- switch (operator) {
352
- case '=':
353
- return fieldValue === value;
354
- case '!=':
355
- return fieldValue !== value;
356
- case '>':
357
- return fieldValue > value;
358
- case '<':
359
- return fieldValue < value;
360
- case '>=':
361
- return fieldValue >= value;
362
- case '<=':
363
- return fieldValue <= value;
364
- case 'in':
365
- return Array.isArray(value) && value.includes(fieldValue);
366
- default:
367
- return false;
368
- }
369
- }
370
- return false;
371
- }
372
- /**
373
- * Validate multiple fields
374
- */
375
- async validateFields(values, schemas) {
376
- const results = {};
377
- const context = {
378
- values,
379
- };
380
- for (const [field, schema] of Object.entries(schemas)) {
381
- const value = values[field];
382
- const schemaWithField = {
383
- ...schema,
384
- field: schema.field ?? field,
385
- };
386
- results[field] = await this.validate(value, schemaWithField, context);
387
- }
388
- return results;
389
- }
390
- /**
391
- * Check if all fields are valid
392
- */
393
- isValid(results) {
394
- return Object.values(results).every(result => result.valid);
395
- }
396
- /**
397
- * Get all errors from validation results
398
- */
399
- getAllErrors(results) {
400
- const errors = [];
401
- for (const result of Object.values(results)) {
402
- errors.push(...result.errors);
403
- }
404
- return errors;
405
- }
406
- /**
407
- * Get all warnings from validation results
408
- */
409
- getAllWarnings(results) {
410
- const warnings = [];
411
- for (const result of Object.values(results)) {
412
- if (result.warnings) {
413
- warnings.push(...result.warnings);
414
- }
415
- }
416
- return warnings;
417
- }
418
- }
419
- /**
420
- * Default validation engine instance
421
- */
422
- export const defaultValidationEngine = new ValidationEngine();
423
- /**
424
- * Convenience function to validate a value
425
- */
426
- export async function validate(value, schema, context) {
427
- return defaultValidationEngine.validate(value, schema, context);
428
- }
429
- /**
430
- * Convenience function to validate multiple fields
431
- */
432
- export async function validateFields(values, schemas) {
433
- return defaultValidationEngine.validateFields(values, schemas);
434
- }