@acodeninja/persist 3.0.0-next.19 → 3.0.0-next.20

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/Connection.js +12 -12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acodeninja/persist",
3
- "version": "3.0.0-next.19",
3
+ "version": "3.0.0-next.20",
4
4
  "description": "A JSON based data modelling and persistence module with alternate storage mechanisms.",
5
5
  "type": "module",
6
6
  "scripts": {
package/src/Connection.js CHANGED
@@ -185,13 +185,13 @@ export default class Connection {
185
185
  modelToProcess.validate();
186
186
  const currentModel = await this.get(modelToProcess.id).catch(() => null);
187
187
 
188
- const modelToProcessHasChanged = JSON.stringify(currentModel?.toData() || {}) !== JSON.stringify(modelToProcess.toData());
188
+ const modelToProcessHasChanged = !_.isEqual(currentModel?.toData() || {}, modelToProcess.toData());
189
189
 
190
190
  if (modelToProcessHasChanged) modelsToPut.push(modelToProcess);
191
191
 
192
192
  if (
193
193
  Boolean(modelToProcess.constructor.indexedProperties().length) &&
194
- (!currentModel || JSON.stringify(currentModel.toIndexData()) !== JSON.stringify(modelToProcess.toIndexData()))
194
+ (!currentModel || !_.isEqual(currentModel.toIndexData(), modelToProcess.toIndexData()))
195
195
  ) {
196
196
  const modelToProcessConstructor = this.#getModelConstructorFromId(modelToProcess.id);
197
197
  modelsToReindex[modelToProcessConstructor] = modelsToReindex[modelToProcessConstructor] || [];
@@ -200,7 +200,7 @@ export default class Connection {
200
200
 
201
201
  if (
202
202
  Boolean(modelToProcess.constructor.searchProperties().length) &&
203
- (!currentModel || JSON.stringify(currentModel.toSearchData()) !== JSON.stringify(modelToProcess.toSearchData()))
203
+ (!currentModel || !_.isEqual(currentModel.toSearchData(), modelToProcess.toSearchData()))
204
204
  ) {
205
205
  const modelToProcessConstructor = this.#getModelConstructorFromId(modelToProcess.id);
206
206
  modelsToReindexSearch[modelToProcessConstructor] = modelsToReindexSearch[modelToProcessConstructor] || [];
@@ -343,15 +343,15 @@ export default class Connection {
343
343
  await Promise.all([
344
344
  Promise.all(Object.entries(indexActions).map(async ([constructorName, actions]) => {
345
345
  const modelConstructor = this.#models[constructorName];
346
- indexCache[modelConstructor] = indexCache[modelConstructor] ?? await this.#storage.getIndex(modelConstructor);
346
+ indexCache[constructorName] = indexCache[constructorName] ?? await this.#storage.getIndex(modelConstructor);
347
347
 
348
348
  actions.forEach(([action, actionModel]) => {
349
349
  if (action === 'delete') {
350
- indexCache[modelConstructor] = _.omit(indexCache[modelConstructor], [actionModel.id]);
350
+ indexCache[constructorName] = _.omit(indexCache[constructorName], [actionModel.id]);
351
351
  }
352
352
  if (action === 'reindex') {
353
- indexCache[modelConstructor] = {
354
- ...indexCache[modelConstructor],
353
+ indexCache[constructorName] = {
354
+ ...indexCache[constructorName],
355
355
  [actionModel.id]: actionModel.toIndexData(),
356
356
  };
357
357
  }
@@ -359,15 +359,15 @@ export default class Connection {
359
359
  })),
360
360
  Promise.all(Object.entries(searchIndexActions).map(async ([constructorName, actions]) => {
361
361
  const modelConstructor = this.#models[constructorName];
362
- searchIndexCache[modelConstructor] = searchIndexCache[modelConstructor] ?? await this.#storage.getSearchIndex(modelConstructor);
362
+ searchIndexCache[constructorName] = searchIndexCache[constructorName] ?? await this.#storage.getSearchIndex(modelConstructor);
363
363
 
364
364
  actions.forEach(([action, actionModel]) => {
365
365
  if (action === 'delete') {
366
- searchIndexCache[modelConstructor] = _.omit(searchIndexCache[modelConstructor], [actionModel.id]);
366
+ searchIndexCache[constructorName] = _.omit(searchIndexCache[constructorName], [actionModel.id]);
367
367
  }
368
368
  if (action === 'reindex') {
369
- searchIndexCache[modelConstructor] = {
370
- ...searchIndexCache[modelConstructor],
369
+ searchIndexCache[constructorName] = {
370
+ ...searchIndexCache[constructorName],
371
371
  [actionModel.id]: actionModel.toSearchData(),
372
372
  };
373
373
  }
@@ -377,7 +377,7 @@ export default class Connection {
377
377
 
378
378
  await Promise.all([
379
379
  Promise.all(modelsToDelete.map(m => this.#storage.deleteModel(m))),
380
- Promise.all(modelsToPut.map(m => this.#storage.putModel(m))),
380
+ Promise.all(modelsToPut.map(m => this.#storage.putModel(m.toData()))),
381
381
  Promise.all(
382
382
  Object.entries(indexCache)
383
383
  .map(([constructorName, index]) => this.#storage.putIndex(this.#models[constructorName], index)),