@onehat/data 1.8.5 → 1.8.8
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 +1 -1
- package/src/Entity.js +4 -2
- package/src/OneHatData.js +34 -0
- package/src/Repository/OneBuild.js +2 -2
package/package.json
CHANGED
package/src/Entity.js
CHANGED
|
@@ -152,9 +152,11 @@ class Entity extends EventEmitter {
|
|
|
152
152
|
},
|
|
153
153
|
set (target, name, value, receiver) {
|
|
154
154
|
if (!Reflect.has(target, name)) {
|
|
155
|
-
|
|
155
|
+
target.setValue(name, value);
|
|
156
|
+
} else {
|
|
157
|
+
Reflect.set(target, name, value, receiver);
|
|
156
158
|
}
|
|
157
|
-
return
|
|
159
|
+
return true; // Return true, or else we sometimes get a proxy trap type error. https://developer.mozilla.org/en-US/docs/web/javascript/reference/global_objects/proxy/proxy/set
|
|
158
160
|
},
|
|
159
161
|
});
|
|
160
162
|
|
package/src/OneHatData.js
CHANGED
|
@@ -50,6 +50,12 @@ export class OneHatData extends EventEmitter {
|
|
|
50
50
|
* @private
|
|
51
51
|
*/
|
|
52
52
|
this.repositories = {};
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @member {Object} uniqueRepositoriesMap - Object map of all unique Repositories, with signature of { mapName: id }
|
|
56
|
+
* @private
|
|
57
|
+
*/
|
|
58
|
+
this.uniqueRepositoriesMap = {};
|
|
53
59
|
|
|
54
60
|
/**
|
|
55
61
|
* @member {boolean} isDestroyed - Whether this object has been destroyed
|
|
@@ -442,6 +448,34 @@ export class OneHatData extends EventEmitter {
|
|
|
442
448
|
return schema.getBoundRepository();
|
|
443
449
|
}
|
|
444
450
|
|
|
451
|
+
/**
|
|
452
|
+
* Gets or creates a unique repository with the supplied schemaName and name
|
|
453
|
+
* @param {string} schemaName - Name of Schema
|
|
454
|
+
* @param {string} mapName - Name of unique repository (will be internally mapped to an id)
|
|
455
|
+
* @return {Repository} repository
|
|
456
|
+
*/
|
|
457
|
+
getOrCreateUniqueRepository = async (mapName, schemaName) => {
|
|
458
|
+
if (this.isDestroyed) {
|
|
459
|
+
throw new Error('this.getUniqueRepository is no longer valid. OneHatData has been destroyed.');
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
// Try to get it
|
|
463
|
+
const id = this.uniqueRepositoriesMap[mapName];
|
|
464
|
+
if (id) {
|
|
465
|
+
return this.getRepositoryById(id);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
// Try to create it
|
|
469
|
+
const schema = this.getSchema(schemaName);
|
|
470
|
+
if (!schema) {
|
|
471
|
+
return null;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
const repository = await this.createRepository(schemaName);
|
|
475
|
+
this.uniqueRepositoriesMap[mapName] = repository.id;
|
|
476
|
+
return repository;
|
|
477
|
+
}
|
|
478
|
+
|
|
445
479
|
/**
|
|
446
480
|
* Checks whether the requested bound Repository exists.
|
|
447
481
|
* @param {string} name - Name of Schema
|
|
@@ -163,7 +163,7 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
163
163
|
}
|
|
164
164
|
});
|
|
165
165
|
|
|
166
|
-
if (this.isLoaded) {
|
|
166
|
+
if (this.isLoaded && this.autoLoad) {
|
|
167
167
|
return this.reload();
|
|
168
168
|
}
|
|
169
169
|
}
|
|
@@ -183,7 +183,7 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
183
183
|
this.setBaseParam('order', sorterStrings.join(','));
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
-
if (this.isLoaded) {
|
|
186
|
+
if (this.isLoaded && this.autoLoad) {
|
|
187
187
|
return this.reload();
|
|
188
188
|
}
|
|
189
189
|
}
|