akanjs 2.2.4-rc.4 → 2.2.4-rc.5
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/package.json
CHANGED
|
@@ -300,6 +300,13 @@ const jsonPath = (path: string) =>
|
|
|
300
300
|
.map((part) => part.replaceAll('"', '\\"'))
|
|
301
301
|
.join(".")}`;
|
|
302
302
|
const encodeSqlValue = (value: unknown) => encodeDocumentValue(value);
|
|
303
|
+
|
|
304
|
+
const decodeDateValue = (value: unknown) => {
|
|
305
|
+
if (value === null || value === undefined) return value;
|
|
306
|
+
if (typeof value === "number") return dayjs(value);
|
|
307
|
+
const epoch = Number(value);
|
|
308
|
+
return Number.isNaN(epoch) ? dayjs(value as never) : dayjs(epoch);
|
|
309
|
+
};
|
|
303
310
|
const QUERY_OPERATOR_KEYS = new Set([
|
|
304
311
|
"eq",
|
|
305
312
|
"ne",
|
|
@@ -773,8 +780,8 @@ export class SqliteDocumentStore {
|
|
|
773
780
|
} else {
|
|
774
781
|
doc[key] = value;
|
|
775
782
|
}
|
|
776
|
-
if (
|
|
777
|
-
doc[key] = this.
|
|
783
|
+
if (doc[key] !== undefined && doc[key] !== null) {
|
|
784
|
+
doc[key] = this.normalizeWriteValue(doc[key], props);
|
|
778
785
|
}
|
|
779
786
|
if (props.enum && doc[key] !== undefined && doc[key] !== null) {
|
|
780
787
|
const values = Array.isArray(doc[key]) ? doc[key] : [doc[key]];
|
|
@@ -992,8 +999,8 @@ export class SqliteDocumentStore {
|
|
|
992
999
|
return new Map(entries.map(([key, item]) => [key, this.decodeMapValue(item, props)]));
|
|
993
1000
|
}
|
|
994
1001
|
if (props.modelRef === Date) {
|
|
995
|
-
if (Array.isArray(value)) return value.map((item) => (item === null ? item :
|
|
996
|
-
return
|
|
1002
|
+
if (Array.isArray(value)) return value.map((item) => (item === null ? item : decodeDateValue(item)));
|
|
1003
|
+
return decodeDateValue(value);
|
|
997
1004
|
}
|
|
998
1005
|
if (Array.isArray(value)) return value.map((item) => this.decodeNestedValue(item, props));
|
|
999
1006
|
return this.decodeNestedValue(value, props);
|
|
@@ -1001,7 +1008,7 @@ export class SqliteDocumentStore {
|
|
|
1001
1008
|
|
|
1002
1009
|
private decodeMapValue(value: unknown, props: Record<string, unknown>) {
|
|
1003
1010
|
if (value === undefined || value === null) return value;
|
|
1004
|
-
if (props.of === Date) return
|
|
1011
|
+
if (props.of === Date) return decodeDateValue(value);
|
|
1005
1012
|
return value;
|
|
1006
1013
|
}
|
|
1007
1014
|
|
|
@@ -1024,8 +1031,13 @@ export class SqliteDocumentStore {
|
|
|
1024
1031
|
return result;
|
|
1025
1032
|
}
|
|
1026
1033
|
|
|
1027
|
-
private
|
|
1034
|
+
private normalizeWriteValue(value: unknown, props: Record<string, unknown>): unknown {
|
|
1028
1035
|
if (value === undefined || value === null) return value;
|
|
1036
|
+
if (props.modelRef === Date) {
|
|
1037
|
+
if (Array.isArray(value))
|
|
1038
|
+
return value.map((item) => (item === null || item === undefined ? item : dayjs(item as never)));
|
|
1039
|
+
return dayjs(value as never);
|
|
1040
|
+
}
|
|
1029
1041
|
if (!props.isClass || !props.isScalar) return value;
|
|
1030
1042
|
if (Array.isArray(value)) return value.map((item) => this.fillScalarDefaults(item, props));
|
|
1031
1043
|
return this.fillScalarDefaults(value, props);
|
|
@@ -1040,7 +1052,7 @@ export class SqliteDocumentStore {
|
|
|
1040
1052
|
for (const [key, fieldMeta] of Object.entries(scalarFields)) {
|
|
1041
1053
|
const nestedProps = fieldMeta.getProps();
|
|
1042
1054
|
if (result[key] === undefined) result[key] = defaults[key];
|
|
1043
|
-
else result[key] = this.
|
|
1055
|
+
else result[key] = this.normalizeWriteValue(result[key], nestedProps);
|
|
1044
1056
|
}
|
|
1045
1057
|
return result;
|
|
1046
1058
|
}
|
|
@@ -256,7 +256,7 @@ export declare class SqliteDocumentStore {
|
|
|
256
256
|
private decodeFieldValue;
|
|
257
257
|
private decodeMapValue;
|
|
258
258
|
private decodeNestedValue;
|
|
259
|
-
private
|
|
259
|
+
private normalizeWriteValue;
|
|
260
260
|
private fillScalarDefaults;
|
|
261
261
|
hydrate(data: DocumentRecord, originalData?: DocumentRecord): any;
|
|
262
262
|
private runHooks;
|