@stonyx/orm 0.3.2-beta.90 → 0.3.2-beta.92

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/record.js CHANGED
@@ -40,11 +40,13 @@ export default class Record {
40
40
  const records = {};
41
41
  for (const [key, childRecord] of Object.entries(this.__relationships)) {
42
42
  if (Array.isArray(childRecord)) {
43
+ // Filter out cleaned records (those with no __model)
44
+ const live = childRecord.filter((r) => r?.__model);
43
45
  // Deduplicate by record ID — keep last occurrence (latest data wins)
44
46
  const seen = new Set();
45
47
  const unique = [];
46
- for (let i = childRecord.length - 1; i >= 0; i--) {
47
- const r = childRecord[i];
48
+ for (let i = live.length - 1; i >= 0; i--) {
49
+ const r = live[i];
48
50
  if (!seen.has(r.id)) {
49
51
  seen.add(r.id);
50
52
  unique.push(r);
@@ -54,7 +56,7 @@ export default class Record {
54
56
  records[key] = unique.map((r) => r.serialize());
55
57
  }
56
58
  else {
57
- records[key] = childRecord?.serialize() ?? null;
59
+ records[key] = childRecord?.__model ? childRecord.serialize() : null;
58
60
  }
59
61
  }
60
62
  return { ...data, ...records };
@@ -86,8 +88,8 @@ export default class Record {
86
88
  if (fields && !fields.has(key))
87
89
  continue;
88
90
  const relationshipData = Array.isArray(childRecord)
89
- ? childRecord.map((r) => ({ type: r.__model.__name, id: r.id }))
90
- : childRecord ? { type: childRecord.__model.__name, id: childRecord.id } : null;
91
+ ? childRecord.filter((r) => r?.__model).map((r) => ({ type: r.__model.__name, id: r.id }))
92
+ : (childRecord && childRecord.__model) ? { type: childRecord.__model.__name, id: childRecord.id } : null;
91
93
  // Dasherize the key for URL paths (e.g., accessLinks -> access-links)
92
94
  const dasherizedKey = camelCaseToKebabCase(key);
93
95
  relationships[dasherizedKey] = { data: relationshipData };
package/dist/store.js CHANGED
@@ -22,7 +22,7 @@ export default class Store {
22
22
  this.data = new Map();
23
23
  }
24
24
  get(key, id) {
25
- if (!id)
25
+ if (id === undefined)
26
26
  return this.data.get(key);
27
27
  return this.data.get(key)?.get(id);
28
28
  }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "stonyx-async",
5
5
  "stonyx-module"
6
6
  ],
7
- "version": "0.3.2-beta.90",
7
+ "version": "0.3.2-beta.92",
8
8
  "description": "",
9
9
  "main": "dist/index.js",
10
10
  "type": "module",
package/src/record.ts CHANGED
@@ -87,12 +87,15 @@ export default class Record {
87
87
 
88
88
  for (const [key, childRecord] of Object.entries(this.__relationships)) {
89
89
  if (Array.isArray(childRecord)) {
90
+ // Filter out cleaned records (those with no __model)
91
+ const live = childRecord.filter((r: Record) => r?.__model);
92
+
90
93
  // Deduplicate by record ID — keep last occurrence (latest data wins)
91
94
  const seen = new Set<unknown>();
92
95
  const unique: Record[] = [];
93
96
 
94
- for (let i = childRecord.length - 1; i >= 0; i--) {
95
- const r = childRecord[i] as Record;
97
+ for (let i = live.length - 1; i >= 0; i--) {
98
+ const r = live[i] as Record;
96
99
  if (!seen.has(r.id)) {
97
100
  seen.add(r.id);
98
101
  unique.push(r);
@@ -102,7 +105,7 @@ export default class Record {
102
105
  unique.reverse();
103
106
  records[key] = unique.map((r: Record) => r.serialize());
104
107
  } else {
105
- records[key] = (childRecord as Record)?.serialize() ?? null;
108
+ records[key] = (childRecord as Record)?.__model ? (childRecord as Record).serialize() : null;
106
109
  }
107
110
  }
108
111
 
@@ -136,8 +139,8 @@ export default class Record {
136
139
  if (fields && !fields.has(key)) continue;
137
140
 
138
141
  const relationshipData = Array.isArray(childRecord)
139
- ? childRecord.map((r: Record) => ({ type: r.__model.__name, id: r.id }))
140
- : childRecord ? { type: (childRecord as Record).__model.__name, id: (childRecord as Record).id } : null;
142
+ ? childRecord.filter((r: Record) => r?.__model).map((r: Record) => ({ type: r.__model.__name, id: r.id }))
143
+ : (childRecord && (childRecord as Record).__model) ? { type: (childRecord as Record).__model.__name, id: (childRecord as Record).id } : null;
141
144
 
142
145
  // Dasherize the key for URL paths (e.g., accessLinks -> access-links)
143
146
  const dasherizedKey = camelCaseToKebabCase(key);
package/src/store.ts CHANGED
@@ -64,7 +64,7 @@ export default class Store {
64
64
  get(key: string): Map<number | string, unknown> | undefined;
65
65
  get(key: string, id: number | string): unknown;
66
66
  get(key: string, id?: number | string): Map<number | string, unknown> | unknown | undefined {
67
- if (!id) return this.data.get(key);
67
+ if (id === undefined) return this.data.get(key);
68
68
 
69
69
  return this.data.get(key)?.get(id);
70
70
  }