@onehat/data 1.22.29 → 1.22.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onehat/data",
3
- "version": "1.22.29",
3
+ "version": "1.22.30",
4
4
  "description": "JS data modeling package with adapters for many storage mediums.",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -21,7 +21,7 @@ import _ from 'lodash';
21
21
  * Class represents a Property that can store values of multiple types.
22
22
  * The actual type is determined dynamically based on the value being set.
23
23
  *
24
- * Usage: { name: 'date', title: 'Date', types: ['date', 'string'], },
24
+ * Usage: { name: 'date', title: 'Date', type: 'mixed', types: ['date', 'string'], },
25
25
  * This is primarily used to allow a field that's normally one PropertyType
26
26
  * to also accept string values (e.g. values like '2025-01-01' or 'N/A').
27
27
  *
@@ -402,6 +402,56 @@ export default class MixedProperty extends EventEmitter {
402
402
  this.internalProperties.forEach((property) => property.destroy());
403
403
  this.internalProperties.clear();
404
404
  }
405
+
406
+ /**
407
+ * Returns the default configuration for this PropertyType.
408
+ * For MixedProperty, this delegates to the first configured type's defaults.
409
+ * @param {Object} defaults - The default configuration to merge with (should include 'types' array)
410
+ * @returns {Object} The default configuration
411
+ */
412
+ static getStaticDefaults(defaults = {}) {
413
+ const mixedPropertyDefaults = {
414
+ name: null,
415
+ allowNull: true,
416
+ depends: null,
417
+ mapping: null,
418
+ submitAsString: false,
419
+ isSortable: true,
420
+ isTempId: false,
421
+ isVirtual: false,
422
+ title: null,
423
+ tooltip: null,
424
+ fieldGroup: null,
425
+ isForeignModel: false,
426
+ filterType: null,
427
+ isFilteringDisabled: false,
428
+ viewerType: null,
429
+ editorType: null,
430
+ isEditingDisabled: false,
431
+ defaultValue: null,
432
+ formatter: null,
433
+ };
434
+
435
+ // If types are configured, use the first type's default value
436
+ if (defaults.types && Array.isArray(defaults.types) && defaults.types.length > 0) {
437
+ const
438
+ firstTypeConfig = defaults.types[0],
439
+ firstTypeName = typeof firstTypeConfig === 'string' ? firstTypeConfig : firstTypeConfig.type;
440
+ if (firstTypeName) {
441
+ try {
442
+ const PropertyClass = MixedProperty.prototype._getPropertyClass(firstTypeName);
443
+ const typeDefaults = PropertyClass.getStaticDefaults ? PropertyClass.getStaticDefaults() : {};
444
+ if (typeDefaults.defaultValue !== undefined) {
445
+ mixedPropertyDefaults.defaultValue = typeDefaults.defaultValue;
446
+ }
447
+ } catch (e) {
448
+ // If we can't get the property class, just use null default
449
+ }
450
+ }
451
+ }
452
+
453
+ return _.merge({}, mixedPropertyDefaults, defaults);
454
+ }
405
455
  }
406
456
 
407
457
  MixedProperty.className = 'Mixed';
@@ -286,7 +286,9 @@ export default class Schema extends EventEmitter {
286
286
  if (!propertyType) {
287
287
  propertyType = PropertyTypes['string'];
288
288
  }
289
- const staticDefaults = propertyType.getStaticDefaults();
289
+ // Pass the property definition to getStaticDefaults for types like 'mixed'
290
+ // that need access to the configuration (e.g., the types array)
291
+ const staticDefaults = propertyType.getStaticDefaults(property);
290
292
  defaultValue = staticDefaults.defaultValue;
291
293
  }
292
294
  if (_.isFunction(defaultValue)) {