@onehat/data 1.22.16 → 1.22.18

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.16",
3
+ "version": "1.22.18",
4
4
  "description": "JS data modeling package with adapters for many storage mediums.",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -115,16 +115,6 @@ class Entity extends EventEmitter {
115
115
  */
116
116
  this.isTree = schema.repository.type === 'tree' || false;
117
117
 
118
- if (this.isTree && !schema.model.parentIdProperty) {
119
- throw new Error('parentIdProperty cannot be empty for a TreeNode');
120
- }
121
- if (this.isTree && this.repository?.isClosureTable && !schema.model.depthProperty) {
122
- throw new Error('depthProperty cannot be empty for a Closure Table TreeNode');
123
- }
124
- if (this.isTree && !schema.model.hasChildrenProperty) {
125
- throw new Error('hasChildrenProperty cannot be empty for a TreeNode');
126
- }
127
-
128
118
  /**
129
119
  * @member {TreeNode} parent - The parent TreeNode for this TreeNode
130
120
  * @public
@@ -346,7 +336,16 @@ class Entity extends EventEmitter {
346
336
  if (this.isDestroyed) {
347
337
  throw Error('this._createProperties is no longer valid. Entity has been destroyed.');
348
338
  }
349
- const propertyDefinitions = this.schema.model.properties;
339
+ let propertyDefinitions = this.schema.model.properties;
340
+ if (this.isTree) {
341
+ const treePropertyDefinitions = [
342
+ // defaults
343
+ { name: 'parentId', mapping: 'parentId', type: 'int', isEditingDisabled: true, isFilteringDisabled: true, },
344
+ { name: 'hasChildren', mapping: 'hasChildren', type: 'bool', isEditingDisabled: true, isFilteringDisabled: true, },
345
+ { name: 'depth', mapping: 'depth', type: 'int', isEditingDisabled: true, isFilteringDisabled: true, },
346
+ ];
347
+ propertyDefinitions = _.unionBy(propertyDefinitions, treePropertyDefinitions, 'name'); // propertyDefinitions will override treePropertyDefinitions
348
+ }
350
349
  let properties = {};
351
350
  _.each(propertyDefinitions, (definition) => {
352
351
  if (!definition.name) {
@@ -75,19 +75,19 @@ export default class Schema extends EventEmitter {
75
75
  * @member {string} parentIdProperty - name of parent_id Property (e.g. 'categories__parent_id' for Adjacency Lists, and parent_id for Closure Tables)
76
76
  * For trees only
77
77
  */
78
- parentIdProperty: null,
78
+ parentIdProperty: 'parentId',
79
79
 
80
80
  /**
81
81
  * @member {string} depthIdProperty - name of depth Property (e.g. 'categories__depth' for Adjacency Lists, and depth for Closure Tables)
82
82
  * For trees only
83
83
  */
84
- depthProperty: null,
84
+ depthProperty: 'depth',
85
85
 
86
86
  /**
87
87
  * @member {string} hasChildrenProperty - name of hasChildren Property (e.g. 'categories__has_children' for Adjacency Lists, and has_children for Closure Tables)
88
88
  * For trees only
89
89
  */
90
- hasChildrenProperty: null,
90
+ hasChildrenProperty: 'hasChildren',
91
91
 
92
92
  /**
93
93
  * @member {boolean} isAdjacencyList - Whether this tree is an Adjacency List