@stonyx/orm 0.3.2-beta.76 → 0.3.2-beta.77
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/manage-record.js +1 -3
- package/dist/store.d.ts +6 -0
- package/dist/store.js +20 -0
- package/package.json +1 -1
- package/src/manage-record.ts +1 -2
- package/src/store.ts +21 -0
package/dist/manage-record.js
CHANGED
|
@@ -117,9 +117,7 @@ export function createRecord(modelName, rawData = {}, userOptions = {}) {
|
|
|
117
117
|
.finally(() => {
|
|
118
118
|
// Evict non-memory records after persist to prevent unbounded heap growth (stonyx#81)
|
|
119
119
|
if (store._memoryResolver && !store._memoryResolver(modelName)) {
|
|
120
|
-
|
|
121
|
-
if (ms)
|
|
122
|
-
ms.delete(record.id);
|
|
120
|
+
store.evictRecord(modelName, record.id);
|
|
123
121
|
}
|
|
124
122
|
});
|
|
125
123
|
}
|
package/dist/store.d.ts
CHANGED
|
@@ -46,6 +46,12 @@ export default class Store {
|
|
|
46
46
|
private _isMemoryModel;
|
|
47
47
|
set(key: string, value: Map<number | string, unknown>): void;
|
|
48
48
|
remove(key: string, id?: number | string): void;
|
|
49
|
+
/**
|
|
50
|
+
* Evict a record from the store with full relationship registry cleanup,
|
|
51
|
+
* WITHOUT calling record.clean(). This preserves the caller's reference
|
|
52
|
+
* to the returned record (used by memory:false post-persist eviction).
|
|
53
|
+
*/
|
|
54
|
+
evictRecord(modelName: string, id: unknown): void;
|
|
49
55
|
unloadRecord(model: string, id: unknown, options?: UnloadOptions): void;
|
|
50
56
|
unloadAllRecords(model: string, options?: UnloadOptions): void;
|
|
51
57
|
private _removeFromHasManyArrays;
|
package/dist/store.js
CHANGED
|
@@ -127,6 +127,26 @@ export default class Store {
|
|
|
127
127
|
return this.unloadRecord(key, id);
|
|
128
128
|
this.unloadAllRecords(key);
|
|
129
129
|
}
|
|
130
|
+
/**
|
|
131
|
+
* Evict a record from the store with full relationship registry cleanup,
|
|
132
|
+
* WITHOUT calling record.clean(). This preserves the caller's reference
|
|
133
|
+
* to the returned record (used by memory:false post-persist eviction).
|
|
134
|
+
*/
|
|
135
|
+
evictRecord(modelName, id) {
|
|
136
|
+
const modelStore = this.data.get(modelName);
|
|
137
|
+
if (!modelStore)
|
|
138
|
+
return;
|
|
139
|
+
if (typeof id !== 'string' && typeof id !== 'number')
|
|
140
|
+
return;
|
|
141
|
+
const raw = modelStore.get(id);
|
|
142
|
+
if (!raw || !isStoreRecord(raw))
|
|
143
|
+
return;
|
|
144
|
+
const visited = new Set([`${modelName}:${id}`]);
|
|
145
|
+
this._removeFromHasManyArrays(modelName, id, visited);
|
|
146
|
+
this._nullifyBelongsToReferences(modelName, id, visited);
|
|
147
|
+
this._cleanupRelationshipRegistries(modelName, id);
|
|
148
|
+
modelStore.delete(id);
|
|
149
|
+
}
|
|
130
150
|
unloadRecord(model, id, options = {}) {
|
|
131
151
|
const modelStore = this.data.get(model);
|
|
132
152
|
if (!modelStore) {
|
package/package.json
CHANGED
package/src/manage-record.ts
CHANGED
|
@@ -152,8 +152,7 @@ export function createRecord(modelName: string, rawData: { [key: string]: unknow
|
|
|
152
152
|
.finally(() => {
|
|
153
153
|
// Evict non-memory records after persist to prevent unbounded heap growth (stonyx#81)
|
|
154
154
|
if (store._memoryResolver && !store._memoryResolver(modelName)) {
|
|
155
|
-
|
|
156
|
-
if (ms) ms.delete(record.id as number | string);
|
|
155
|
+
store.evictRecord(modelName, record.id);
|
|
157
156
|
}
|
|
158
157
|
});
|
|
159
158
|
}
|
package/src/store.ts
CHANGED
|
@@ -193,6 +193,27 @@ export default class Store {
|
|
|
193
193
|
this.unloadAllRecords(key);
|
|
194
194
|
}
|
|
195
195
|
|
|
196
|
+
/**
|
|
197
|
+
* Evict a record from the store with full relationship registry cleanup,
|
|
198
|
+
* WITHOUT calling record.clean(). This preserves the caller's reference
|
|
199
|
+
* to the returned record (used by memory:false post-persist eviction).
|
|
200
|
+
*/
|
|
201
|
+
evictRecord(modelName: string, id: unknown): void {
|
|
202
|
+
const modelStore = this.data.get(modelName);
|
|
203
|
+
if (!modelStore) return;
|
|
204
|
+
|
|
205
|
+
if (typeof id !== 'string' && typeof id !== 'number') return;
|
|
206
|
+
const raw = modelStore.get(id);
|
|
207
|
+
if (!raw || !isStoreRecord(raw)) return;
|
|
208
|
+
|
|
209
|
+
const visited = new Set([`${modelName}:${id}`]);
|
|
210
|
+
this._removeFromHasManyArrays(modelName, id, visited);
|
|
211
|
+
this._nullifyBelongsToReferences(modelName, id, visited);
|
|
212
|
+
this._cleanupRelationshipRegistries(modelName, id);
|
|
213
|
+
|
|
214
|
+
modelStore.delete(id);
|
|
215
|
+
}
|
|
216
|
+
|
|
196
217
|
unloadRecord(model: string, id: unknown, options: UnloadOptions = {}): void {
|
|
197
218
|
const modelStore = this.data.get(model);
|
|
198
219
|
|