@stonyx/orm 0.3.2-alpha.19 → 0.3.2-alpha.20

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/store.js CHANGED
@@ -264,12 +264,30 @@ export default class Store {
264
264
  const pendingMap = getPendingRegistry().get(modelName);
265
265
  if (pendingMap)
266
266
  pendingMap.delete(recordId);
267
+ // Clean pendingBelongsTo entries in both directions
267
268
  const pendingBelongsToMap = getPendingBelongsToRegistry();
268
269
  if (pendingBelongsToMap) {
269
- // Clean entries where this model is the TARGET of a pending belongsTo
270
+ // Direction 1: evicted record was the TARGET others were waiting for
270
271
  const targetEntries = pendingBelongsToMap.get(modelName);
271
272
  if (targetEntries)
272
273
  targetEntries.delete(recordId);
274
+ // Direction 2: evicted record was the SOURCE with unresolved forward-references
275
+ for (const [, targetIdMap] of pendingBelongsToMap) {
276
+ for (const [targetId, entries] of targetIdMap) {
277
+ if (!Array.isArray(entries))
278
+ continue;
279
+ const filtered = entries.filter((e) => {
280
+ const entry = e;
281
+ return !(entry.sourceModelName === modelName && entry.relationshipId === recordId);
282
+ });
283
+ if (filtered.length === 0) {
284
+ targetIdMap.delete(targetId);
285
+ }
286
+ else if (filtered.length < entries.length) {
287
+ targetIdMap.set(targetId, filtered);
288
+ }
289
+ }
290
+ }
273
291
  }
274
292
  }
275
293
  /**
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "stonyx-async",
5
5
  "stonyx-module"
6
6
  ],
7
- "version": "0.3.2-alpha.19",
7
+ "version": "0.3.2-alpha.20",
8
8
  "description": "",
9
9
  "main": "dist/index.js",
10
10
  "type": "module",
package/src/store.ts CHANGED
@@ -347,11 +347,28 @@ export default class Store {
347
347
  const pendingMap = getPendingRegistry().get(modelName);
348
348
  if (pendingMap) pendingMap.delete(recordId);
349
349
 
350
+ // Clean pendingBelongsTo entries in both directions
350
351
  const pendingBelongsToMap = getPendingBelongsToRegistry();
351
352
  if (pendingBelongsToMap) {
352
- // Clean entries where this model is the TARGET of a pending belongsTo
353
+ // Direction 1: evicted record was the TARGET others were waiting for
353
354
  const targetEntries = pendingBelongsToMap.get(modelName);
354
355
  if (targetEntries) targetEntries.delete(recordId);
356
+
357
+ // Direction 2: evicted record was the SOURCE with unresolved forward-references
358
+ for (const [, targetIdMap] of pendingBelongsToMap) {
359
+ for (const [targetId, entries] of targetIdMap) {
360
+ if (!Array.isArray(entries)) continue;
361
+ const filtered = entries.filter((e: unknown) => {
362
+ const entry = e as { sourceModelName?: string; relationshipId?: unknown };
363
+ return !(entry.sourceModelName === modelName && entry.relationshipId === recordId);
364
+ });
365
+ if (filtered.length === 0) {
366
+ targetIdMap.delete(targetId);
367
+ } else if (filtered.length < entries.length) {
368
+ targetIdMap.set(targetId, filtered);
369
+ }
370
+ }
371
+ }
355
372
  }
356
373
  }
357
374