pinia-orm-edge 1.9.0-28579698.2e55b90 → 1.9.0-28580767.64b3b57
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 +33 -12
- package/dist/index.mjs +33 -12
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
@@ -1484,17 +1484,14 @@ class Query {
|
|
1484
1484
|
const id = this.model.$getKey(record, true);
|
1485
1485
|
const savedHydratedModel = id && this.hydratedDataCache.get(this.model.$entity() + id);
|
1486
1486
|
if (!this.getNewHydrated && options?.operation !== "set" && savedHydratedModel) {
|
1487
|
-
return savedHydratedModel;
|
1487
|
+
return savedHydratedModel.$fill(record, options);
|
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") {
|
1492
|
+
if (id && (!this.getNewHydrated && options?.operation !== "set" || options?.action === "update")) {
|
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
|
-
}
|
1498
1495
|
return hydratedModel;
|
1499
1496
|
}
|
1500
1497
|
}
|
@@ -3187,18 +3184,12 @@ class Model {
|
|
3187
3184
|
continue;
|
3188
3185
|
}
|
3189
3186
|
const attr = fields[key];
|
3190
|
-
|
3187
|
+
const value = attributes[key];
|
3191
3188
|
if (attr instanceof Relation && !fillRelation) {
|
3192
3189
|
continue;
|
3193
3190
|
}
|
3194
3191
|
const mutator = mutators?.[key];
|
3195
3192
|
const cast = this.$casts()[key]?.newRawInstance(fields);
|
3196
|
-
if (mutator && operation === "get") {
|
3197
|
-
value = typeof mutator === "function" ? mutator(value) : typeof mutator.get === "function" ? mutator.get(value) : value;
|
3198
|
-
}
|
3199
|
-
if (cast && operation === "get") {
|
3200
|
-
value = cast.get(value);
|
3201
|
-
}
|
3202
3193
|
let keyValue = this.$fillField(key, attr, value);
|
3203
3194
|
if (mutator && typeof mutator !== "function" && operation === "set" && mutator.set) {
|
3204
3195
|
keyValue = mutator.set(keyValue);
|
@@ -3206,6 +3197,36 @@ class Model {
|
|
3206
3197
|
if (cast && operation === "set") {
|
3207
3198
|
keyValue = cast.set(keyValue);
|
3208
3199
|
}
|
3200
|
+
if (cast || mutator) {
|
3201
|
+
Object.defineProperty(this, "_" + key, {
|
3202
|
+
configurable: true,
|
3203
|
+
writable: true,
|
3204
|
+
enumerable: false
|
3205
|
+
});
|
3206
|
+
Object.defineProperty(this, key, {
|
3207
|
+
configurable: true,
|
3208
|
+
enumerable: true,
|
3209
|
+
get() {
|
3210
|
+
let scopeValue = this["_" + key];
|
3211
|
+
if (scopeValue === void 0) {
|
3212
|
+
return keyValue;
|
3213
|
+
}
|
3214
|
+
if (operation === "set") {
|
3215
|
+
return scopeValue;
|
3216
|
+
}
|
3217
|
+
if (mutator) {
|
3218
|
+
scopeValue = typeof mutator === "function" ? mutator(scopeValue) : typeof mutator.get === "function" ? mutator.get(scopeValue) : scopeValue;
|
3219
|
+
}
|
3220
|
+
if (cast) {
|
3221
|
+
scopeValue = cast.get(scopeValue);
|
3222
|
+
}
|
3223
|
+
return scopeValue;
|
3224
|
+
},
|
3225
|
+
set(value2) {
|
3226
|
+
this["_" + key] = value2;
|
3227
|
+
}
|
3228
|
+
});
|
3229
|
+
}
|
3209
3230
|
this[key] = this[key] ?? keyValue;
|
3210
3231
|
}
|
3211
3232
|
operation === "set" && (this.$self().original[this.$getKey(this, true)] = this.$getAttributes());
|
package/dist/index.mjs
CHANGED
@@ -1482,17 +1482,14 @@ class Query {
|
|
1482
1482
|
const id = this.model.$getKey(record, true);
|
1483
1483
|
const savedHydratedModel = id && this.hydratedDataCache.get(this.model.$entity() + id);
|
1484
1484
|
if (!this.getNewHydrated && options?.operation !== "set" && savedHydratedModel) {
|
1485
|
-
return savedHydratedModel;
|
1485
|
+
return savedHydratedModel.$fill(record, options);
|
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") {
|
1490
|
+
if (id && (!this.getNewHydrated && options?.operation !== "set" || options?.action === "update")) {
|
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
|
-
}
|
1496
1493
|
return hydratedModel;
|
1497
1494
|
}
|
1498
1495
|
}
|
@@ -3185,18 +3182,12 @@ class Model {
|
|
3185
3182
|
continue;
|
3186
3183
|
}
|
3187
3184
|
const attr = fields[key];
|
3188
|
-
|
3185
|
+
const value = attributes[key];
|
3189
3186
|
if (attr instanceof Relation && !fillRelation) {
|
3190
3187
|
continue;
|
3191
3188
|
}
|
3192
3189
|
const mutator = mutators?.[key];
|
3193
3190
|
const cast = this.$casts()[key]?.newRawInstance(fields);
|
3194
|
-
if (mutator && operation === "get") {
|
3195
|
-
value = typeof mutator === "function" ? mutator(value) : typeof mutator.get === "function" ? mutator.get(value) : value;
|
3196
|
-
}
|
3197
|
-
if (cast && operation === "get") {
|
3198
|
-
value = cast.get(value);
|
3199
|
-
}
|
3200
3191
|
let keyValue = this.$fillField(key, attr, value);
|
3201
3192
|
if (mutator && typeof mutator !== "function" && operation === "set" && mutator.set) {
|
3202
3193
|
keyValue = mutator.set(keyValue);
|
@@ -3204,6 +3195,36 @@ class Model {
|
|
3204
3195
|
if (cast && operation === "set") {
|
3205
3196
|
keyValue = cast.set(keyValue);
|
3206
3197
|
}
|
3198
|
+
if (cast || mutator) {
|
3199
|
+
Object.defineProperty(this, "_" + key, {
|
3200
|
+
configurable: true,
|
3201
|
+
writable: true,
|
3202
|
+
enumerable: false
|
3203
|
+
});
|
3204
|
+
Object.defineProperty(this, key, {
|
3205
|
+
configurable: true,
|
3206
|
+
enumerable: true,
|
3207
|
+
get() {
|
3208
|
+
let scopeValue = this["_" + key];
|
3209
|
+
if (scopeValue === void 0) {
|
3210
|
+
return keyValue;
|
3211
|
+
}
|
3212
|
+
if (operation === "set") {
|
3213
|
+
return scopeValue;
|
3214
|
+
}
|
3215
|
+
if (mutator) {
|
3216
|
+
scopeValue = typeof mutator === "function" ? mutator(scopeValue) : typeof mutator.get === "function" ? mutator.get(scopeValue) : scopeValue;
|
3217
|
+
}
|
3218
|
+
if (cast) {
|
3219
|
+
scopeValue = cast.get(scopeValue);
|
3220
|
+
}
|
3221
|
+
return scopeValue;
|
3222
|
+
},
|
3223
|
+
set(value2) {
|
3224
|
+
this["_" + key] = value2;
|
3225
|
+
}
|
3226
|
+
});
|
3227
|
+
}
|
3207
3228
|
this[key] = this[key] ?? keyValue;
|
3208
3229
|
}
|
3209
3230
|
operation === "set" && (this.$self().original[this.$getKey(this, true)] = this.$getAttributes());
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "pinia-orm-edge",
|
3
|
-
"version": "1.9.0-
|
3
|
+
"version": "1.9.0-28580767.64b3b57",
|
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-
|
49
|
+
"@pinia-orm/normalizr": "npm:@pinia-orm/normalizr-edge@1.9.0-28580767.64b3b57"
|
50
50
|
},
|
51
51
|
"devDependencies": {
|
52
52
|
"@nuxt/eslint-config": "^0.3.10",
|