@statezero/core 0.1.25 → 0.1.27
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.
|
@@ -23,7 +23,7 @@ export class DateParsingHelpers {
|
|
|
23
23
|
// Get field-specific format from schema
|
|
24
24
|
const formatStrings = {
|
|
25
25
|
'date': schema.date_format,
|
|
26
|
-
'
|
|
26
|
+
'date-time': schema.datetime_format
|
|
27
27
|
};
|
|
28
28
|
const dateFormat = formatStrings[fieldFormat];
|
|
29
29
|
// Check if format is supported
|
|
@@ -56,13 +56,13 @@ export class DateParsingHelpers {
|
|
|
56
56
|
return date;
|
|
57
57
|
}
|
|
58
58
|
const fieldFormat = schema.properties[fieldName].format;
|
|
59
|
-
if (!["date", "
|
|
59
|
+
if (!["date", "date-time"].includes(fieldFormat)) {
|
|
60
60
|
throw new Error(`Only date and date-time fields can be processed to JS date objects. ${fieldName} has format ${fieldFormat}`);
|
|
61
61
|
}
|
|
62
62
|
// Get field-specific format from schema
|
|
63
63
|
const formatStrings = {
|
|
64
64
|
'date': schema.date_format,
|
|
65
|
-
'
|
|
65
|
+
'date-time': schema.datetime_format
|
|
66
66
|
};
|
|
67
67
|
const dateFormat = formatStrings[fieldFormat];
|
|
68
68
|
// Check if format is supported
|
|
@@ -89,6 +89,14 @@ export class Model {
|
|
|
89
89
|
if (storedValue)
|
|
90
90
|
value = storedValue[field]; // if stops null -> undefined
|
|
91
91
|
}
|
|
92
|
+
// Date/DateTime fields need special handling - convert to Date objects
|
|
93
|
+
const dateFormats = ["date", "datetime", "date-time"];
|
|
94
|
+
if (ModelClass.schema &&
|
|
95
|
+
dateFormats.includes(ModelClass.schema.properties[field]?.format) &&
|
|
96
|
+
value) {
|
|
97
|
+
// Let DateParsingHelpers.parseDate throw if it fails
|
|
98
|
+
return DateParsingHelpers.parseDate(value, field, ModelClass.schema);
|
|
99
|
+
}
|
|
92
100
|
// File/Image fields need special handling - wrap as FileObject
|
|
93
101
|
const fileFormats = ["file-path", "image-path"];
|
|
94
102
|
if (ModelClass.schema &&
|
|
@@ -191,6 +199,14 @@ export class Model {
|
|
|
191
199
|
if (storedValue)
|
|
192
200
|
value = storedValue[field];
|
|
193
201
|
}
|
|
202
|
+
// Date/DateTime fields need special handling - convert Date objects to strings for API
|
|
203
|
+
const dateFormats = ["date", "date-time"];
|
|
204
|
+
if (ModelClass.schema &&
|
|
205
|
+
dateFormats.includes(ModelClass.schema.properties[field]?.format) &&
|
|
206
|
+
value instanceof Date) {
|
|
207
|
+
// Let DateParsingHelpers.serializeDate throw if it fails
|
|
208
|
+
return DateParsingHelpers.serializeDate(value, field, ModelClass.schema);
|
|
209
|
+
}
|
|
194
210
|
return value;
|
|
195
211
|
}
|
|
196
212
|
/**
|
|
@@ -29,7 +29,9 @@ export class QuerysetStoreGraph {
|
|
|
29
29
|
if (current.__parent) {
|
|
30
30
|
const parentKey = current.__parent.semanticKey;
|
|
31
31
|
this.graph.setNode(parentKey);
|
|
32
|
-
|
|
32
|
+
if (currentKey !== parentKey) {
|
|
33
|
+
this.graph.setEdge(currentKey, parentKey);
|
|
34
|
+
}
|
|
33
35
|
current = current.__parent;
|
|
34
36
|
}
|
|
35
37
|
else {
|
|
@@ -13,6 +13,9 @@ export class QuerysetStore {
|
|
|
13
13
|
getRootStore: any;
|
|
14
14
|
qsCache: Cache;
|
|
15
15
|
_lastRenderedPks: any[] | null;
|
|
16
|
+
renderCallbacks: Set<any>;
|
|
17
|
+
_rootUnregister: any;
|
|
18
|
+
_currentRootStore: any;
|
|
16
19
|
get cacheKey(): any;
|
|
17
20
|
onHydrated(hydratedData: any): void;
|
|
18
21
|
setCache(result: any): void;
|
|
@@ -30,6 +33,8 @@ export class QuerysetStore {
|
|
|
30
33
|
getTrimmedOperations(): any[];
|
|
31
34
|
getInflightOperations(): any[];
|
|
32
35
|
prune(): void;
|
|
36
|
+
registerRenderCallback(callback: any): () => boolean;
|
|
37
|
+
_ensureRootRegistration(): void;
|
|
33
38
|
render(optimistic?: boolean, fromCache?: boolean): any[];
|
|
34
39
|
renderFromRoot(optimistic: boolean | undefined, rootStore: any): any[];
|
|
35
40
|
renderFromData(optimistic?: boolean): any[];
|
|
@@ -30,6 +30,10 @@ export class QuerysetStore {
|
|
|
30
30
|
}
|
|
31
31
|
this.qsCache = new Cache("queryset-cache", {}, this.onHydrated.bind(this));
|
|
32
32
|
this._lastRenderedPks = null;
|
|
33
|
+
this.renderCallbacks = new Set();
|
|
34
|
+
this._rootUnregister = null;
|
|
35
|
+
this._currentRootStore = null;
|
|
36
|
+
this._ensureRootRegistration();
|
|
33
37
|
}
|
|
34
38
|
// Caching
|
|
35
39
|
get cacheKey() {
|
|
@@ -76,6 +80,14 @@ export class QuerysetStore {
|
|
|
76
80
|
if (!isEqual(newPks, this._lastRenderedPks)) {
|
|
77
81
|
this._lastRenderedPks = newPks; // Update the cache with the new state
|
|
78
82
|
querysetEventEmitter.emit(`${this.modelClass.configKey}::${this.modelClass.modelName}::queryset::render`, { ast: this.queryset.build(), ModelClass: this.modelClass });
|
|
83
|
+
this.renderCallbacks.forEach((callback) => {
|
|
84
|
+
try {
|
|
85
|
+
callback();
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
console.warn("Error in render callback:", error);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
79
91
|
}
|
|
80
92
|
}
|
|
81
93
|
async addOperation(operation) {
|
|
@@ -130,7 +142,34 @@ export class QuerysetStore {
|
|
|
130
142
|
this.setGroundTruth(renderedPks);
|
|
131
143
|
this.setOperations(this.getInflightOperations());
|
|
132
144
|
}
|
|
145
|
+
registerRenderCallback(callback) {
|
|
146
|
+
this.renderCallbacks.add(callback);
|
|
147
|
+
return () => this.renderCallbacks.delete(callback);
|
|
148
|
+
}
|
|
149
|
+
_ensureRootRegistration() {
|
|
150
|
+
if (this.isTemp)
|
|
151
|
+
return;
|
|
152
|
+
const { isRoot, rootStore } = this.getRootStore(this.queryset);
|
|
153
|
+
// If the root store hasn't changed, nothing to do
|
|
154
|
+
if (this._currentRootStore === rootStore) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
// Root store changed - clean up old registration if it exists
|
|
158
|
+
if (this._rootUnregister) {
|
|
159
|
+
this._rootUnregister();
|
|
160
|
+
this._rootUnregister = null;
|
|
161
|
+
}
|
|
162
|
+
// Set up new registration if we're derived and have a root store
|
|
163
|
+
if (!isRoot && rootStore) {
|
|
164
|
+
this._rootUnregister = rootStore.registerRenderCallback(() => {
|
|
165
|
+
this._emitRenderEvent();
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
// Update current root store reference (could be null now)
|
|
169
|
+
this._currentRootStore = rootStore;
|
|
170
|
+
}
|
|
133
171
|
render(optimistic = true, fromCache = false) {
|
|
172
|
+
this._ensureRootRegistration();
|
|
134
173
|
if (fromCache) {
|
|
135
174
|
const cachedResult = this.qsCache.get(this.cacheKey);
|
|
136
175
|
if (Array.isArray(cachedResult)) {
|
package/package.json
CHANGED