@onehat/data 1.5.1 → 1.5.2

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.
@@ -511,6 +511,12 @@ describe('Repository Base', function() {
511
511
  expect(didFireAdd).to.be.true;
512
512
  });
513
513
 
514
+ it('createStandaloneEntity', async function() {
515
+ const entity = await this.repository.createStandaloneEntity({ key: 6, value: 'six' });
516
+ expect(entity.id).to.be.eq(6);
517
+ expect(_.size(this.repository.entities)).to.be.eq(5);
518
+ });
519
+
514
520
  it('addMultiple', async function() {
515
521
  await this.repository.addMultiple([
516
522
  { key: 6, value: 'six' },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onehat/data",
3
- "version": "1.5.1",
3
+ "version": "1.5.2",
4
4
  "description": "JS data modeling package with adapters for many storage mediums.",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -878,6 +878,27 @@ export default class Repository extends EventEmitter {
878
878
  return entity;
879
879
  }
880
880
 
881
+ /**
882
+ * Creates a new static Entity that does NOT persist in storage medium.
883
+ * @param {object} data - Either raw data object or Entity. If raw data, keys are Property names, Values are Property values.
884
+ * @param {boolean} isPersisted - Whether the new entity should be marked as already being persisted in storage medium.
885
+ * @param {boolean} originalIsMapped - Has data already been mapped according to schema?
886
+ * @return {object} entity - new Entity object
887
+ */
888
+ createStandaloneEntity = async (data, isPersisted = false, originalIsMapped = false) => {
889
+ if (this.isDestroyed) {
890
+ throw Error('this.createStandaloneEntity is no longer valid. Repository has been destroyed.');
891
+ }
892
+
893
+ const entity = Repository._createEntity(this.schema, data, this, isPersisted, originalIsMapped);
894
+
895
+ if (entity.isPhantom) {
896
+ entity.createId(); // either a UUID or a temp id
897
+ }
898
+
899
+ return entity;
900
+ }
901
+
881
902
  /**
882
903
  * Convenience function to add entity with mapped data.
883
904
  */