@statezero/core 0.2.8 → 0.2.9

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.
@@ -44,6 +44,12 @@ export class QuerysetStore {
44
44
  private _getValidatedAndFilteredPks;
45
45
  render(optimistic?: boolean, fromCache?: boolean): any[];
46
46
  renderFromRoot(optimistic: boolean | undefined, rootStore: any): any[];
47
+ /**
48
+ * Render by getting ALL instances from the model store and applying
49
+ * the queryset's filters locally. Used for temp stores (e.g., optimistic
50
+ * chained filters) that don't have their own ground truth.
51
+ */
52
+ renderFromModelStore(optimistic?: boolean): any[];
47
53
  renderFromData(optimistic?: boolean): any[];
48
54
  applyOperation(operation: any, currentPks: any): any;
49
55
  sync(forceFromDb?: boolean): Promise<void>;
@@ -211,6 +211,11 @@ export class QuerysetStore {
211
211
  pks = this.renderFromRoot(optimistic, rootStore);
212
212
  }
213
213
  }
214
+ // For temp stores with no ground truth (e.g., chained optimistic filters),
215
+ // render from the model store instead of empty ground truth
216
+ if (isNil(pks) && this.isTemp && this.groundTruthPks.length === 0) {
217
+ pks = this.renderFromModelStore(optimistic);
218
+ }
214
219
  if (isNil(pks)) {
215
220
  pks = this.renderFromData(optimistic);
216
221
  }
@@ -231,6 +236,24 @@ export class QuerysetStore {
231
236
  let result = filter(renderedData, ast, this.modelClass, false);
232
237
  return result;
233
238
  }
239
+ /**
240
+ * Render by getting ALL instances from the model store and applying
241
+ * the queryset's filters locally. Used for temp stores (e.g., optimistic
242
+ * chained filters) that don't have their own ground truth.
243
+ */
244
+ renderFromModelStore(optimistic = true) {
245
+ const modelStore = modelStoreRegistry.getStore(this.modelClass);
246
+ // Get all PKs from the model store
247
+ const allPks = modelStore.groundTruthPks;
248
+ // Convert to model instances (like renderFromRoot does)
249
+ const allInstances = allPks.map((pk) => {
250
+ return this.modelClass.fromPk(pk, this.queryset);
251
+ });
252
+ // Apply the queryset's AST filters locally
253
+ const ast = this.queryset.build();
254
+ const result = filter(allInstances, ast, this.modelClass, false);
255
+ return result;
256
+ }
234
257
  renderFromData(optimistic = true) {
235
258
  const renderedPks = this.groundTruthSet;
236
259
  for (const op of this.operations) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@statezero/core",
3
- "version": "0.2.8",
3
+ "version": "0.2.9",
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",