@statezero/core 0.1.56 → 0.1.57
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/flavours/django/files.d.ts +0 -1
- package/dist/flavours/django/files.js +0 -2
- package/dist/flavours/django/model.d.ts +1 -14
- package/dist/flavours/django/model.js +24 -65
- package/dist/syncEngine/stores/modelStore.d.ts +0 -5
- package/dist/syncEngine/stores/modelStore.js +1 -14
- package/package.json +1 -1
|
@@ -44,7 +44,7 @@ export class Model {
|
|
|
44
44
|
*/
|
|
45
45
|
static validate(data: Object, validateType?: string, partial?: boolean): Promise<boolean>;
|
|
46
46
|
constructor(data?: {});
|
|
47
|
-
_data:
|
|
47
|
+
_data: {};
|
|
48
48
|
_pk: any;
|
|
49
49
|
__version: number;
|
|
50
50
|
touch(): void;
|
|
@@ -60,11 +60,6 @@ export class Model {
|
|
|
60
60
|
* @returns {number|undefined} The primary key.
|
|
61
61
|
*/
|
|
62
62
|
get pk(): number | undefined;
|
|
63
|
-
/**
|
|
64
|
-
* STANDARDIZATION: Convert rich objects to plain JS data for internal storage
|
|
65
|
-
*/
|
|
66
|
-
_standardizeIncomingData(data: any): any;
|
|
67
|
-
_standardizeFieldValue(field: any, value: any): any;
|
|
68
63
|
/**
|
|
69
64
|
* Gets a field value from the internal data store
|
|
70
65
|
*
|
|
@@ -72,14 +67,6 @@ export class Model {
|
|
|
72
67
|
* @returns {any} The field value
|
|
73
68
|
*/
|
|
74
69
|
getField(field: string): any;
|
|
75
|
-
/**
|
|
76
|
-
* HYDRATION: Convert plain stored data back to rich objects
|
|
77
|
-
*
|
|
78
|
-
* @param {string} field - The field name
|
|
79
|
-
* @param {any} value - The plain stored value
|
|
80
|
-
* @returns {any} The hydrated rich object
|
|
81
|
-
*/
|
|
82
|
-
_hydrateFieldValue(field: string, value: any): any;
|
|
83
70
|
/**
|
|
84
71
|
* Sets a field value in the internal data store
|
|
85
72
|
*
|
|
@@ -9,7 +9,7 @@ import { isNil } from "lodash-es";
|
|
|
9
9
|
import { QueryExecutor } from "./queryExecutor";
|
|
10
10
|
import { wrapReactiveModel } from "../../reactiveAdaptor.js";
|
|
11
11
|
import { DateParsingHelpers } from "./dates.js";
|
|
12
|
-
import { FileObject } from
|
|
12
|
+
import { FileObject } from './files.js';
|
|
13
13
|
import { configInstance } from "../../config.js";
|
|
14
14
|
import { parseStateZeroError, MultipleObjectsReturned, DoesNotExist, } from "./errors.js";
|
|
15
15
|
import axios from "axios";
|
|
@@ -32,8 +32,8 @@ import axios from "axios";
|
|
|
32
32
|
*/
|
|
33
33
|
export class Model {
|
|
34
34
|
constructor(data = {}) {
|
|
35
|
-
// Initialize internal data store
|
|
36
|
-
this._data =
|
|
35
|
+
// Initialize internal data store
|
|
36
|
+
this._data = data;
|
|
37
37
|
this._pk = data[this.constructor.primaryKeyField] || undefined;
|
|
38
38
|
this.__version = 0;
|
|
39
39
|
return wrapReactiveModel(this);
|
|
@@ -71,48 +71,6 @@ export class Model {
|
|
|
71
71
|
}
|
|
72
72
|
return this.instanceCache.get(key);
|
|
73
73
|
}
|
|
74
|
-
/**
|
|
75
|
-
* STANDARDIZATION: Convert rich objects to plain JS data for internal storage
|
|
76
|
-
*/
|
|
77
|
-
_standardizeIncomingData(data) {
|
|
78
|
-
if (!data || typeof data !== "object")
|
|
79
|
-
return data;
|
|
80
|
-
const standardized = {};
|
|
81
|
-
for (const [field, value] of Object.entries(data)) {
|
|
82
|
-
standardized[field] = this._standardizeFieldValue(field, value);
|
|
83
|
-
}
|
|
84
|
-
return standardized;
|
|
85
|
-
}
|
|
86
|
-
_standardizeFieldValue(field, value) {
|
|
87
|
-
if (isNil(value))
|
|
88
|
-
return value;
|
|
89
|
-
const ModelClass = this.constructor;
|
|
90
|
-
// Handle Date objects -> formatted strings
|
|
91
|
-
if (value instanceof Date) {
|
|
92
|
-
return DateParsingHelpers.serializeDate(value, field, ModelClass.schema);
|
|
93
|
-
}
|
|
94
|
-
// Handle FileObject -> simple file path/data
|
|
95
|
-
const fileFormats = ["file-path", "image-path"];
|
|
96
|
-
if (ModelClass.schema?.properties[field]?.format &&
|
|
97
|
-
fileFormats.includes(ModelClass.schema.properties[field].format) &&
|
|
98
|
-
value &&
|
|
99
|
-
typeof value.toJSON === "function") {
|
|
100
|
-
// Return a serializable JSON representation of the FileObject.
|
|
101
|
-
return value.toJSON();
|
|
102
|
-
}
|
|
103
|
-
// Handle Model instances -> primary keys
|
|
104
|
-
if (value &&
|
|
105
|
-
typeof value === "object" &&
|
|
106
|
-
value.constructor &&
|
|
107
|
-
value.constructor.primaryKeyField) {
|
|
108
|
-
return value.pk;
|
|
109
|
-
}
|
|
110
|
-
// Handle arrays (for many-to-many relationships)
|
|
111
|
-
if (Array.isArray(value)) {
|
|
112
|
-
return value.map((item) => this._standardizeFieldValue(field, item));
|
|
113
|
-
}
|
|
114
|
-
return value;
|
|
115
|
-
}
|
|
116
74
|
/**
|
|
117
75
|
* Gets a field value from the internal data store
|
|
118
76
|
*
|
|
@@ -120,6 +78,7 @@ export class Model {
|
|
|
120
78
|
* @returns {any} The field value
|
|
121
79
|
*/
|
|
122
80
|
getField(field) {
|
|
81
|
+
var _a;
|
|
123
82
|
// Access the reactive __version property to establish dependency for vue integration
|
|
124
83
|
const trackVersion = this.__version;
|
|
125
84
|
const ModelClass = this.constructor;
|
|
@@ -133,21 +92,6 @@ export class Model {
|
|
|
133
92
|
if (storedValue)
|
|
134
93
|
value = storedValue[field]; // if stops null -> undefined
|
|
135
94
|
}
|
|
136
|
-
// Convert plain stored data back to rich objects
|
|
137
|
-
return this._hydrateFieldValue(field, value);
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* HYDRATION: Convert plain stored data back to rich objects
|
|
141
|
-
*
|
|
142
|
-
* @param {string} field - The field name
|
|
143
|
-
* @param {any} value - The plain stored value
|
|
144
|
-
* @returns {any} The hydrated rich object
|
|
145
|
-
*/
|
|
146
|
-
_hydrateFieldValue(field, value) {
|
|
147
|
-
var _a;
|
|
148
|
-
if (isNil(value))
|
|
149
|
-
return value;
|
|
150
|
-
const ModelClass = this.constructor;
|
|
151
95
|
// Date/DateTime fields need special handling - convert to Date objects
|
|
152
96
|
const dateFormats = ["date", "datetime", "date-time"];
|
|
153
97
|
if (ModelClass.schema &&
|
|
@@ -161,6 +105,10 @@ export class Model {
|
|
|
161
105
|
if (ModelClass.schema &&
|
|
162
106
|
fileFormats.includes(ModelClass.schema.properties[field]?.format) &&
|
|
163
107
|
value) {
|
|
108
|
+
// Check if it's already a FileObject
|
|
109
|
+
if (value instanceof FileObject) {
|
|
110
|
+
return value;
|
|
111
|
+
}
|
|
164
112
|
// If it's stored file data from API, wrap it as FileObject
|
|
165
113
|
if (typeof value === "object" && value.file_path) {
|
|
166
114
|
// Create anonymous subclass with correct configKey
|
|
@@ -204,13 +152,11 @@ export class Model {
|
|
|
204
152
|
*/
|
|
205
153
|
setField(field, value) {
|
|
206
154
|
const ModelClass = this.constructor;
|
|
207
|
-
// Standardize the value before storing
|
|
208
|
-
const standardizedValue = this._standardizeFieldValue(field, value);
|
|
209
155
|
if (ModelClass.primaryKeyField === field) {
|
|
210
|
-
this._pk =
|
|
156
|
+
this._pk = value;
|
|
211
157
|
}
|
|
212
158
|
else {
|
|
213
|
-
this._data[field] =
|
|
159
|
+
this._data[field] = value;
|
|
214
160
|
}
|
|
215
161
|
}
|
|
216
162
|
/**
|
|
@@ -256,7 +202,20 @@ export class Model {
|
|
|
256
202
|
if (storedValue)
|
|
257
203
|
value = storedValue[field];
|
|
258
204
|
}
|
|
259
|
-
//
|
|
205
|
+
// Date/DateTime fields need special handling - convert Date objects to strings for API
|
|
206
|
+
const dateFormats = ["date", "date-time"];
|
|
207
|
+
if (ModelClass.schema &&
|
|
208
|
+
dateFormats.includes(ModelClass.schema.properties[field]?.format) &&
|
|
209
|
+
value instanceof Date) {
|
|
210
|
+
// Let DateParsingHelpers.serializeDate throw if it fails
|
|
211
|
+
return DateParsingHelpers.serializeDate(value, field, ModelClass.schema);
|
|
212
|
+
}
|
|
213
|
+
const fileFormats = ["file-path", "image-path"];
|
|
214
|
+
if (ModelClass.schema &&
|
|
215
|
+
fileFormats.includes(ModelClass.schema.properties[field]?.format) &&
|
|
216
|
+
value) {
|
|
217
|
+
return value.filePath || value.file_path || value;
|
|
218
|
+
}
|
|
260
219
|
return value;
|
|
261
220
|
}
|
|
262
221
|
/**
|
|
@@ -17,11 +17,6 @@ export class ModelStore {
|
|
|
17
17
|
_loadOperations(operationsData: any): void;
|
|
18
18
|
get cacheKey(): string;
|
|
19
19
|
onHydrated(): void;
|
|
20
|
-
/**
|
|
21
|
-
* Convert raw data objects to standardized format for caching
|
|
22
|
-
* Creates temporary model instances to leverage the standardization logic
|
|
23
|
-
*/
|
|
24
|
-
_standardizeForCache(items: any): any;
|
|
25
20
|
setCache(result: any): void;
|
|
26
21
|
clearCache(): void;
|
|
27
22
|
updateCache(items: any, requestedPks: any): void;
|
|
@@ -117,18 +117,6 @@ export class ModelStore {
|
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
|
-
/**
|
|
121
|
-
* Convert raw data objects to standardized format for caching
|
|
122
|
-
* Creates temporary model instances to leverage the standardization logic
|
|
123
|
-
*/
|
|
124
|
-
_standardizeForCache(items) {
|
|
125
|
-
return items.map((item) => {
|
|
126
|
-
// Create a temporary model instance with the raw data
|
|
127
|
-
const tempInstance = new this.modelClass(item);
|
|
128
|
-
// Use the serialize method to get standardized data
|
|
129
|
-
return tempInstance.serialize();
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
120
|
setCache(result) {
|
|
133
121
|
const pkField = this.pkField;
|
|
134
122
|
let nonTempPkItems = [];
|
|
@@ -143,8 +131,7 @@ export class ModelStore {
|
|
|
143
131
|
item[pkField] = pk;
|
|
144
132
|
nonTempPkItems.push(item);
|
|
145
133
|
});
|
|
146
|
-
|
|
147
|
-
this.modelCache.set(this.cacheKey, standardizedItems);
|
|
134
|
+
this.modelCache.set(this.cacheKey, nonTempPkItems);
|
|
148
135
|
}
|
|
149
136
|
clearCache() {
|
|
150
137
|
this.modelCache.delete(this.cacheKey);
|
package/package.json
CHANGED