@statezero/core 0.1.11 → 0.1.13

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.
@@ -68,12 +68,6 @@ export class Model {
68
68
  this.instanceCache.set(key, instance);
69
69
  }
70
70
  const cachedInstance = this.instanceCache.get(key);
71
- // If cached instance is dirty, return a fresh instance instead
72
- if (cachedInstance._isDirty) {
73
- const freshInstance = new this();
74
- freshInstance.pk = pk;
75
- return freshInstance;
76
- }
77
71
  return cachedInstance;
78
72
  }
79
73
  /**
@@ -68,7 +68,7 @@ export class QuerysetStore {
68
68
  }
69
69
  async addOperation(operation) {
70
70
  this.operationsMap.set(operation.operationId, operation);
71
- if (this.operationsMap.size > this.pruneThreshold) {
71
+ if (this.operationsMap.size > this.pruneThreshold && !this.isSyncing) {
72
72
  this.prune();
73
73
  }
74
74
  this._emitRenderEvent();
@@ -116,6 +116,10 @@ export class QuerysetStore {
116
116
  operation.status != Status.REJECTED);
117
117
  }
118
118
  prune() {
119
+ if (this.isSyncing) {
120
+ console.log(`[ModelStore ${this.modelClass.modelName}] Skipping prune - sync in progress`);
121
+ return;
122
+ }
119
123
  const renderedPks = this.render(false);
120
124
  this.setGroundTruth(renderedPks);
121
125
  this.setOperations(this.getInflightOperations());
@@ -182,8 +186,16 @@ export class QuerysetStore {
182
186
  ast: this.queryset.build(),
183
187
  modelClass: this.modelClass
184
188
  });
189
+ if (!response || typeof response !== "object") {
190
+ throw new Error(`Invalid response structure from fetchFn`);
191
+ }
185
192
  const { data, included } = response;
186
193
  console.log(`[${id}] Sync fetch completed. Received: ${JSON.stringify(data)}.`);
194
+ if (!Array.isArray(data)) {
195
+ console.warn(`[${id}] fetchFn returned non-array data:`, typeof data);
196
+ // Don't update ground truth with invalid data
197
+ return;
198
+ }
187
199
  // Persists all the instances (including nested instances) to the model store
188
200
  processIncludedEntities(modelStoreRegistry, included, this.modelClass);
189
201
  this.setGroundTruth(data);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@statezero/core",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "type": "module",
5
5
  "module": "ESNext",
6
6
  "description": "The type-safe frontend client for StateZero - connect directly to your backend models with zero boilerplate",