pinia-orm-edge 1.9.0-28580847.34348a5 → 1.9.0-28580959.70a2cd0

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/dist/index.cjs CHANGED
@@ -1307,16 +1307,16 @@ class Query {
1307
1307
  const record = elements[id];
1308
1308
  const existing = currentData[id];
1309
1309
  let model = existing ? this.hydrate({ ...existing, ...record }, { operation: "set", action: "update" }) : this.hydrate(record, { operation: "set", action: "save" });
1310
- const isSaving = model.$self().saving(model, record);
1311
- const isUpdatingOrCreating = existing ? model.$self().updating(model, record) : model.$self().creating(model, record);
1310
+ const isSaving = model.$self().saving(model, existing ?? {});
1311
+ const isUpdatingOrCreating = existing ? model.$self().updating(model, existing ?? {}) : model.$self().creating(model, existing ?? {});
1312
1312
  if (isSaving === false || isUpdatingOrCreating === false) {
1313
1313
  continue;
1314
1314
  }
1315
1315
  if (model.$isDirty()) {
1316
1316
  model = this.hydrate(model.$getAttributes(), { operation: "set", action: existing ? "update" : "save" });
1317
1317
  }
1318
- afterSavingHooks.push(() => model.$self().saved(model, record));
1319
- afterSavingHooks.push(() => existing ? model.$self().updated(model, record) : model.$self().created(model, record));
1318
+ afterSavingHooks.push(() => model.$self().saved(model, existing ?? {}));
1319
+ afterSavingHooks.push(() => existing ? model.$self().updated(model, existing ?? {}) : model.$self().created(model, existing ?? {}));
1320
1320
  newData[id] = model.$getAttributes();
1321
1321
  if (Object.values(model.$types()).length > 0 && !newData[id][model.$typeKey()]) {
1322
1322
  newData[id][model.$typeKey()] = record[model.$typeKey()];
@@ -1482,16 +1482,19 @@ class Query {
1482
1482
  */
1483
1483
  getHydratedModel(record, options) {
1484
1484
  const id = this.model.$getKey(record, true);
1485
- const savedHydratedModel = id && this.hydratedDataCache.get(this.model.$entity() + id);
1485
+ const savedHydratedModel = id && options?.operation !== "set" && this.hydratedDataCache.get(this.model.$entity() + id);
1486
1486
  if (!this.getNewHydrated && options?.operation !== "set" && savedHydratedModel) {
1487
- return savedHydratedModel.$fill(record, options);
1487
+ return savedHydratedModel;
1488
1488
  }
1489
1489
  const modelByType = this.model.$types()[record[this.model.$typeKey()]];
1490
1490
  const getNewInsance = (newOptions) => (modelByType ? modelByType.newRawInstance() : this.model).$newInstance(record, { relations: false, ...options || {}, ...newOptions });
1491
1491
  const hydratedModel = getNewInsance();
1492
- if (id && (!this.getNewHydrated && options?.operation !== "set" || options?.action === "update")) {
1492
+ if (id && !this.getNewHydrated && options?.operation !== "set") {
1493
1493
  this.hydratedDataCache.set(this.model.$entity() + id, hydratedModel);
1494
1494
  }
1495
+ if (id && options?.action === "update") {
1496
+ this.hydratedDataCache.set(this.model.$entity() + id, getNewInsance({ operation: "get" }));
1497
+ }
1495
1498
  return hydratedModel;
1496
1499
  }
1497
1500
  }
package/dist/index.mjs CHANGED
@@ -1305,16 +1305,16 @@ class Query {
1305
1305
  const record = elements[id];
1306
1306
  const existing = currentData[id];
1307
1307
  let model = existing ? this.hydrate({ ...existing, ...record }, { operation: "set", action: "update" }) : this.hydrate(record, { operation: "set", action: "save" });
1308
- const isSaving = model.$self().saving(model, record);
1309
- const isUpdatingOrCreating = existing ? model.$self().updating(model, record) : model.$self().creating(model, record);
1308
+ const isSaving = model.$self().saving(model, existing ?? {});
1309
+ const isUpdatingOrCreating = existing ? model.$self().updating(model, existing ?? {}) : model.$self().creating(model, existing ?? {});
1310
1310
  if (isSaving === false || isUpdatingOrCreating === false) {
1311
1311
  continue;
1312
1312
  }
1313
1313
  if (model.$isDirty()) {
1314
1314
  model = this.hydrate(model.$getAttributes(), { operation: "set", action: existing ? "update" : "save" });
1315
1315
  }
1316
- afterSavingHooks.push(() => model.$self().saved(model, record));
1317
- afterSavingHooks.push(() => existing ? model.$self().updated(model, record) : model.$self().created(model, record));
1316
+ afterSavingHooks.push(() => model.$self().saved(model, existing ?? {}));
1317
+ afterSavingHooks.push(() => existing ? model.$self().updated(model, existing ?? {}) : model.$self().created(model, existing ?? {}));
1318
1318
  newData[id] = model.$getAttributes();
1319
1319
  if (Object.values(model.$types()).length > 0 && !newData[id][model.$typeKey()]) {
1320
1320
  newData[id][model.$typeKey()] = record[model.$typeKey()];
@@ -1480,16 +1480,19 @@ class Query {
1480
1480
  */
1481
1481
  getHydratedModel(record, options) {
1482
1482
  const id = this.model.$getKey(record, true);
1483
- const savedHydratedModel = id && this.hydratedDataCache.get(this.model.$entity() + id);
1483
+ const savedHydratedModel = id && options?.operation !== "set" && this.hydratedDataCache.get(this.model.$entity() + id);
1484
1484
  if (!this.getNewHydrated && options?.operation !== "set" && savedHydratedModel) {
1485
- return savedHydratedModel.$fill(record, options);
1485
+ return savedHydratedModel;
1486
1486
  }
1487
1487
  const modelByType = this.model.$types()[record[this.model.$typeKey()]];
1488
1488
  const getNewInsance = (newOptions) => (modelByType ? modelByType.newRawInstance() : this.model).$newInstance(record, { relations: false, ...options || {}, ...newOptions });
1489
1489
  const hydratedModel = getNewInsance();
1490
- if (id && (!this.getNewHydrated && options?.operation !== "set" || options?.action === "update")) {
1490
+ if (id && !this.getNewHydrated && options?.operation !== "set") {
1491
1491
  this.hydratedDataCache.set(this.model.$entity() + id, hydratedModel);
1492
1492
  }
1493
+ if (id && options?.action === "update") {
1494
+ this.hydratedDataCache.set(this.model.$entity() + id, getNewInsance({ operation: "get" }));
1495
+ }
1493
1496
  return hydratedModel;
1494
1497
  }
1495
1498
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinia-orm-edge",
3
- "version": "1.9.0-28580847.34348a5",
3
+ "version": "1.9.0-28580959.70a2cd0",
4
4
  "description": "The Pinia plugin to enable Object-Relational Mapping access to the Pinia Store.",
5
5
  "keywords": [
6
6
  "vue",
@@ -46,7 +46,7 @@
46
46
  "pinia": "^2.1.7"
47
47
  },
48
48
  "dependencies": {
49
- "@pinia-orm/normalizr": "npm:@pinia-orm/normalizr-edge@1.9.0-28580847.34348a5"
49
+ "@pinia-orm/normalizr": "npm:@pinia-orm/normalizr-edge@1.9.0-28580959.70a2cd0"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@nuxt/eslint-config": "^0.3.10",