pinia-orm-edge 1.9.0-28580088.76eb4a5 → 1.9.0-28580847.34348a5
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/casts.cjs +7 -1
- package/dist/casts.d.cts +1 -1
- package/dist/casts.d.mts +1 -1
- package/dist/casts.d.ts +1 -1
- package/dist/casts.mjs +7 -1
- package/dist/helpers.cjs +1 -1
- package/dist/helpers.mjs +1 -1
- package/dist/index.cjs +37 -13
- package/dist/index.mjs +37 -13
- package/dist/shared/{pinia-orm.9bb2aea1.cjs → pinia-orm.a88d8365.cjs} +9 -1
- package/dist/shared/{pinia-orm.07af123e.mjs → pinia-orm.f3905af9.mjs} +9 -2
- package/package.json +2 -2
package/dist/casts.cjs
CHANGED
@@ -113,7 +113,13 @@ class DateCast extends CastAttribute.CastAttribute {
|
|
113
113
|
if (value === null) {
|
114
114
|
return null;
|
115
115
|
}
|
116
|
-
|
116
|
+
if (typeof value === "number") {
|
117
|
+
return new Date(value).toISOString();
|
118
|
+
}
|
119
|
+
if (typeof value === "string") {
|
120
|
+
return new Date(Date.parse(value)).toISOString();
|
121
|
+
}
|
122
|
+
return value.toISOString();
|
117
123
|
}
|
118
124
|
}
|
119
125
|
|
package/dist/casts.d.cts
CHANGED
@@ -60,7 +60,7 @@ declare class DateCast extends CastAttribute {
|
|
60
60
|
/**
|
61
61
|
* Make the value for the attribute.
|
62
62
|
*/
|
63
|
-
set(value: string | Date | null): string | null;
|
63
|
+
set(value: string | number | Date | null): string | null;
|
64
64
|
}
|
65
65
|
|
66
66
|
export { ArrayCast, BooleanCast, DateCast, NumberCast, StringCast };
|
package/dist/casts.d.mts
CHANGED
@@ -60,7 +60,7 @@ declare class DateCast extends CastAttribute {
|
|
60
60
|
/**
|
61
61
|
* Make the value for the attribute.
|
62
62
|
*/
|
63
|
-
set(value: string | Date | null): string | null;
|
63
|
+
set(value: string | number | Date | null): string | null;
|
64
64
|
}
|
65
65
|
|
66
66
|
export { ArrayCast, BooleanCast, DateCast, NumberCast, StringCast };
|
package/dist/casts.d.ts
CHANGED
@@ -60,7 +60,7 @@ declare class DateCast extends CastAttribute {
|
|
60
60
|
/**
|
61
61
|
* Make the value for the attribute.
|
62
62
|
*/
|
63
|
-
set(value: string | Date | null): string | null;
|
63
|
+
set(value: string | number | Date | null): string | null;
|
64
64
|
}
|
65
65
|
|
66
66
|
export { ArrayCast, BooleanCast, DateCast, NumberCast, StringCast };
|
package/dist/casts.mjs
CHANGED
@@ -111,7 +111,13 @@ class DateCast extends CastAttribute {
|
|
111
111
|
if (value === null) {
|
112
112
|
return null;
|
113
113
|
}
|
114
|
-
|
114
|
+
if (typeof value === "number") {
|
115
|
+
return new Date(value).toISOString();
|
116
|
+
}
|
117
|
+
if (typeof value === "string") {
|
118
|
+
return new Date(Date.parse(value)).toISOString();
|
119
|
+
}
|
120
|
+
return value.toISOString();
|
115
121
|
}
|
116
122
|
}
|
117
123
|
|
package/dist/helpers.cjs
CHANGED
package/dist/helpers.mjs
CHANGED
package/dist/index.cjs
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
const Utils = require('./shared/pinia-orm.
|
3
|
+
const Utils = require('./shared/pinia-orm.a88d8365.cjs');
|
4
4
|
const pinia = require('pinia');
|
5
5
|
const normalizr = require('@pinia-orm/normalizr');
|
6
6
|
const CastAttribute = require('./shared/pinia-orm.a7e3e0f3.cjs');
|
@@ -1484,7 +1484,7 @@ 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 });
|
@@ -2023,7 +2023,7 @@ let String$1 = class String extends Type {
|
|
2023
2023
|
}
|
2024
2024
|
};
|
2025
2025
|
|
2026
|
-
|
2026
|
+
class Number extends Type {
|
2027
2027
|
/**
|
2028
2028
|
* Create a new Number attribute instance.
|
2029
2029
|
*/
|
@@ -2036,7 +2036,7 @@ let Number$1 = class Number extends Type {
|
|
2036
2036
|
make(value) {
|
2037
2037
|
return this.makeReturn("number", value);
|
2038
2038
|
}
|
2039
|
-
}
|
2039
|
+
}
|
2040
2040
|
|
2041
2041
|
class Boolean extends Type {
|
2042
2042
|
/**
|
@@ -2915,7 +2915,7 @@ class Model {
|
|
2915
2915
|
* Create a new Number attribute instance.
|
2916
2916
|
*/
|
2917
2917
|
static number(value) {
|
2918
|
-
return new Number
|
2918
|
+
return new Number(this.newRawInstance(), value);
|
2919
2919
|
}
|
2920
2920
|
/**
|
2921
2921
|
* Create a new Boolean attribute instance.
|
@@ -3184,18 +3184,12 @@ class Model {
|
|
3184
3184
|
continue;
|
3185
3185
|
}
|
3186
3186
|
const attr = fields[key];
|
3187
|
-
|
3187
|
+
const value = attributes[key];
|
3188
3188
|
if (attr instanceof Relation && !fillRelation) {
|
3189
3189
|
continue;
|
3190
3190
|
}
|
3191
3191
|
const mutator = mutators?.[key];
|
3192
3192
|
const cast = this.$casts()[key]?.newRawInstance(fields);
|
3193
|
-
if (mutator && operation === "get") {
|
3194
|
-
value = typeof mutator === "function" ? mutator(value) : typeof mutator.get === "function" ? mutator.get(value) : value;
|
3195
|
-
}
|
3196
|
-
if (cast && operation === "get") {
|
3197
|
-
value = cast.get(value);
|
3198
|
-
}
|
3199
3193
|
let keyValue = this.$fillField(key, attr, value);
|
3200
3194
|
if (mutator && typeof mutator !== "function" && operation === "set" && mutator.set) {
|
3201
3195
|
keyValue = mutator.set(keyValue);
|
@@ -3203,6 +3197,36 @@ class Model {
|
|
3203
3197
|
if (cast && operation === "set") {
|
3204
3198
|
keyValue = cast.set(keyValue);
|
3205
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
|
+
}
|
3206
3230
|
this[key] = this[key] ?? keyValue;
|
3207
3231
|
}
|
3208
3232
|
operation === "set" && (this.$self().original[this.$getKey(this, true)] = this.$getAttributes());
|
@@ -3421,7 +3445,7 @@ class Model {
|
|
3421
3445
|
return this.serializeArray(value);
|
3422
3446
|
}
|
3423
3447
|
if (typeof value === "object") {
|
3424
|
-
if (
|
3448
|
+
if (Utils.isDate(value)) {
|
3425
3449
|
return value.toISOString();
|
3426
3450
|
} else {
|
3427
3451
|
return this.serializeObject(value);
|
package/dist/index.mjs
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { i as isArray, t as throwError, a as assert, g as generateId, b as isNullish, c as compareWithOperator, d as generateKey, e as isEmpty, f as isFunction, h as groupBy, o as orderBy, j as equals } from './shared/pinia-orm.
|
1
|
+
import { i as isArray, t as throwError, a as assert, g as generateId, b as isNullish, c as compareWithOperator, d as generateKey, e as isEmpty, f as isFunction, h as groupBy, o as orderBy, j as equals, k as isDate } from './shared/pinia-orm.f3905af9.mjs';
|
2
2
|
import { defineStore, acceptHMRUpdate } from 'pinia';
|
3
3
|
import { schema, normalize } from '@pinia-orm/normalizr';
|
4
4
|
export { C as CastAttribute } from './shared/pinia-orm.4ff2e12f.mjs';
|
@@ -1482,7 +1482,7 @@ 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 });
|
@@ -2021,7 +2021,7 @@ let String$1 = class String extends Type {
|
|
2021
2021
|
}
|
2022
2022
|
};
|
2023
2023
|
|
2024
|
-
|
2024
|
+
class Number extends Type {
|
2025
2025
|
/**
|
2026
2026
|
* Create a new Number attribute instance.
|
2027
2027
|
*/
|
@@ -2034,7 +2034,7 @@ let Number$1 = class Number extends Type {
|
|
2034
2034
|
make(value) {
|
2035
2035
|
return this.makeReturn("number", value);
|
2036
2036
|
}
|
2037
|
-
}
|
2037
|
+
}
|
2038
2038
|
|
2039
2039
|
class Boolean extends Type {
|
2040
2040
|
/**
|
@@ -2913,7 +2913,7 @@ class Model {
|
|
2913
2913
|
* Create a new Number attribute instance.
|
2914
2914
|
*/
|
2915
2915
|
static number(value) {
|
2916
|
-
return new Number
|
2916
|
+
return new Number(this.newRawInstance(), value);
|
2917
2917
|
}
|
2918
2918
|
/**
|
2919
2919
|
* Create a new Boolean attribute instance.
|
@@ -3182,18 +3182,12 @@ class Model {
|
|
3182
3182
|
continue;
|
3183
3183
|
}
|
3184
3184
|
const attr = fields[key];
|
3185
|
-
|
3185
|
+
const value = attributes[key];
|
3186
3186
|
if (attr instanceof Relation && !fillRelation) {
|
3187
3187
|
continue;
|
3188
3188
|
}
|
3189
3189
|
const mutator = mutators?.[key];
|
3190
3190
|
const cast = this.$casts()[key]?.newRawInstance(fields);
|
3191
|
-
if (mutator && operation === "get") {
|
3192
|
-
value = typeof mutator === "function" ? mutator(value) : typeof mutator.get === "function" ? mutator.get(value) : value;
|
3193
|
-
}
|
3194
|
-
if (cast && operation === "get") {
|
3195
|
-
value = cast.get(value);
|
3196
|
-
}
|
3197
3191
|
let keyValue = this.$fillField(key, attr, value);
|
3198
3192
|
if (mutator && typeof mutator !== "function" && operation === "set" && mutator.set) {
|
3199
3193
|
keyValue = mutator.set(keyValue);
|
@@ -3201,6 +3195,36 @@ class Model {
|
|
3201
3195
|
if (cast && operation === "set") {
|
3202
3196
|
keyValue = cast.set(keyValue);
|
3203
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
|
+
}
|
3204
3228
|
this[key] = this[key] ?? keyValue;
|
3205
3229
|
}
|
3206
3230
|
operation === "set" && (this.$self().original[this.$getKey(this, true)] = this.$getAttributes());
|
@@ -3419,7 +3443,7 @@ class Model {
|
|
3419
3443
|
return this.serializeArray(value);
|
3420
3444
|
}
|
3421
3445
|
if (typeof value === "object") {
|
3422
|
-
if (
|
3446
|
+
if (isDate(value)) {
|
3423
3447
|
return value.toISOString();
|
3424
3448
|
} else {
|
3425
3449
|
return this.serializeObject(value);
|
@@ -21,6 +21,9 @@ function compareWithOperator(leftValue, rightValue, operator) {
|
|
21
21
|
function isNullish(value) {
|
22
22
|
return value === void 0 || value === null;
|
23
23
|
}
|
24
|
+
function isDate(value) {
|
25
|
+
return value instanceof Date && !Number.isNaN(value.getTime()) && typeof value.toISOString === "function";
|
26
|
+
}
|
24
27
|
function isArray(value) {
|
25
28
|
return Array.isArray(value);
|
26
29
|
}
|
@@ -37,7 +40,11 @@ function orderBy(collection, iteratees, directions, flags = "SORT_REGULAR") {
|
|
37
40
|
let index = -1;
|
38
41
|
const result = collection.map((value) => {
|
39
42
|
const criteria = iteratees.map((iteratee) => {
|
40
|
-
|
43
|
+
if (typeof iteratee === "function") {
|
44
|
+
return iteratee(value);
|
45
|
+
}
|
46
|
+
const newValue = getValue(value, iteratee, false);
|
47
|
+
return isDate(newValue) ? new Date(newValue).getTime() : newValue;
|
41
48
|
});
|
42
49
|
return { criteria, index: ++index, value };
|
43
50
|
});
|
@@ -160,6 +167,7 @@ exports.generateKey = generateKey;
|
|
160
167
|
exports.getValue = getValue;
|
161
168
|
exports.groupBy = groupBy;
|
162
169
|
exports.isArray = isArray;
|
170
|
+
exports.isDate = isDate;
|
163
171
|
exports.isEmpty = isEmpty;
|
164
172
|
exports.isFunction = isFunction;
|
165
173
|
exports.isNullish = isNullish;
|
@@ -19,6 +19,9 @@ function compareWithOperator(leftValue, rightValue, operator) {
|
|
19
19
|
function isNullish(value) {
|
20
20
|
return value === void 0 || value === null;
|
21
21
|
}
|
22
|
+
function isDate(value) {
|
23
|
+
return value instanceof Date && !Number.isNaN(value.getTime()) && typeof value.toISOString === "function";
|
24
|
+
}
|
22
25
|
function isArray(value) {
|
23
26
|
return Array.isArray(value);
|
24
27
|
}
|
@@ -35,7 +38,11 @@ function orderBy(collection, iteratees, directions, flags = "SORT_REGULAR") {
|
|
35
38
|
let index = -1;
|
36
39
|
const result = collection.map((value) => {
|
37
40
|
const criteria = iteratees.map((iteratee) => {
|
38
|
-
|
41
|
+
if (typeof iteratee === "function") {
|
42
|
+
return iteratee(value);
|
43
|
+
}
|
44
|
+
const newValue = getValue(value, iteratee, false);
|
45
|
+
return isDate(newValue) ? new Date(newValue).getTime() : newValue;
|
39
46
|
});
|
40
47
|
return { criteria, index: ++index, value };
|
41
48
|
});
|
@@ -150,4 +157,4 @@ function equals(a, b) {
|
|
150
157
|
return keys.every((k) => equals(a[k], b[k]));
|
151
158
|
}
|
152
159
|
|
153
|
-
export { assert as a, isNullish as b, compareWithOperator as c, generateKey as d, isEmpty as e, isFunction as f, generateId as g, groupBy as h, isArray as i, equals as j,
|
160
|
+
export { assert as a, isNullish as b, compareWithOperator as c, generateKey as d, isEmpty as e, isFunction as f, generateId as g, groupBy as h, isArray as i, equals as j, isDate as k, getValue as l, orderBy as o, throwError as t };
|
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-28580847.34348a5",
|
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-28580847.34348a5"
|
50
50
|
},
|
51
51
|
"devDependencies": {
|
52
52
|
"@nuxt/eslint-config": "^0.3.10",
|