@stonyx/orm 0.3.2-alpha.13 → 0.3.2-alpha.15
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 +10 -1
- package/package.json +1 -1
- package/src/manage-record.ts +15 -7
package/dist/manage-record.js
CHANGED
|
@@ -84,13 +84,22 @@ export function createRecord(modelName, rawData = {}, userOptions = {}) {
|
|
|
84
84
|
const shouldPersist = orm?.sqlDb && !options.isDbRecord && !userOptions._relationshipKey && !options._skipAutoPersist;
|
|
85
85
|
if (shouldPersist) {
|
|
86
86
|
const response = { data: { id: record.id } };
|
|
87
|
-
orm.sqlDb.persist('create', modelName, { rawData }, response)
|
|
87
|
+
orm.sqlDb.persist('create', modelName, { rawData }, response)
|
|
88
|
+
.catch((err) => {
|
|
88
89
|
orm.emitPersistError({
|
|
89
90
|
operation: 'create',
|
|
90
91
|
modelName,
|
|
91
92
|
recordId: record.id,
|
|
92
93
|
error: err instanceof Error ? err : new Error(String(err)),
|
|
93
94
|
});
|
|
95
|
+
})
|
|
96
|
+
.finally(() => {
|
|
97
|
+
// Evict non-memory records after persist to prevent unbounded heap growth (stonyx#81)
|
|
98
|
+
if (store._memoryResolver && !store._memoryResolver(modelName)) {
|
|
99
|
+
const ms = store.get(modelName);
|
|
100
|
+
if (ms)
|
|
101
|
+
ms.delete(record.id);
|
|
102
|
+
}
|
|
94
103
|
});
|
|
95
104
|
}
|
|
96
105
|
return record;
|
package/package.json
CHANGED
package/src/manage-record.ts
CHANGED
|
@@ -118,14 +118,22 @@ export function createRecord(modelName: string, rawData: { [key: string]: unknow
|
|
|
118
118
|
const shouldPersist = orm?.sqlDb && !options.isDbRecord && !userOptions._relationshipKey && !options._skipAutoPersist;
|
|
119
119
|
if (shouldPersist) {
|
|
120
120
|
const response = { data: { id: record.id } };
|
|
121
|
-
orm!.sqlDb!.persist('create', modelName, { rawData }, response)
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
121
|
+
orm!.sqlDb!.persist('create', modelName, { rawData }, response)
|
|
122
|
+
.catch((err: unknown) => {
|
|
123
|
+
orm!.emitPersistError({
|
|
124
|
+
operation: 'create',
|
|
125
|
+
modelName,
|
|
126
|
+
recordId: record.id,
|
|
127
|
+
error: err instanceof Error ? err : new Error(String(err)),
|
|
128
|
+
});
|
|
129
|
+
})
|
|
130
|
+
.finally(() => {
|
|
131
|
+
// Evict non-memory records after persist to prevent unbounded heap growth (stonyx#81)
|
|
132
|
+
if (store._memoryResolver && !store._memoryResolver(modelName)) {
|
|
133
|
+
const ms = store.get(modelName);
|
|
134
|
+
if (ms) ms.delete(record.id as number | string);
|
|
135
|
+
}
|
|
127
136
|
});
|
|
128
|
-
});
|
|
129
137
|
}
|
|
130
138
|
|
|
131
139
|
return record;
|