@statezero/core 0.1.96 → 0.1.98
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.
|
@@ -120,12 +120,12 @@ export class Manager {
|
|
|
120
120
|
*/
|
|
121
121
|
create(data: any): Promise<any>;
|
|
122
122
|
/**
|
|
123
|
-
* Creates multiple model instances using the provided
|
|
123
|
+
* Creates multiple model instances using the provided model instances.
|
|
124
124
|
*
|
|
125
|
-
* @param {Array<
|
|
125
|
+
* @param {Array<Model>} modelInstances - Array of unsaved model instances to create.
|
|
126
126
|
* @returns {Promise<Array<*>>} A promise that resolves to an array of newly created model instances.
|
|
127
127
|
*/
|
|
128
|
-
bulkCreate(
|
|
128
|
+
bulkCreate(modelInstances: Array<Model>): Promise<Array<any>>;
|
|
129
129
|
/**
|
|
130
130
|
* Fetches all records using the current QuerySet.
|
|
131
131
|
*
|
|
@@ -153,13 +153,13 @@ export class Manager {
|
|
|
153
153
|
return this.newQuerySet().create(data);
|
|
154
154
|
}
|
|
155
155
|
/**
|
|
156
|
-
* Creates multiple model instances using the provided
|
|
156
|
+
* Creates multiple model instances using the provided model instances.
|
|
157
157
|
*
|
|
158
|
-
* @param {Array<
|
|
158
|
+
* @param {Array<Model>} modelInstances - Array of unsaved model instances to create.
|
|
159
159
|
* @returns {Promise<Array<*>>} A promise that resolves to an array of newly created model instances.
|
|
160
160
|
*/
|
|
161
|
-
async bulkCreate(
|
|
162
|
-
return this.newQuerySet().bulkCreate(
|
|
161
|
+
async bulkCreate(modelInstances) {
|
|
162
|
+
return this.newQuerySet().bulkCreate(modelInstances);
|
|
163
163
|
}
|
|
164
164
|
/**
|
|
165
165
|
* Fetches all records using the current QuerySet.
|
|
@@ -223,7 +223,7 @@ export class QueryExecutor {
|
|
|
223
223
|
};
|
|
224
224
|
const operation = OperationFactory.createUpdateOperation(querySet, apiCallArgs.data, querySet.build().filter);
|
|
225
225
|
const estimatedCount = operation.instances.length;
|
|
226
|
-
let liveResult = [estimatedCount, { [modelName]: estimatedCount }];
|
|
226
|
+
let liveResult = [estimatedCount, { [modelName]: estimatedCount }, []];
|
|
227
227
|
const promise = makeApiCall(querySet, operationType, apiCallArgs, operation.operationId)
|
|
228
228
|
.then((response) => {
|
|
229
229
|
const { data, included } = response.data || {};
|
|
@@ -233,7 +233,7 @@ export class QueryExecutor {
|
|
|
233
233
|
: [];
|
|
234
234
|
operation.updateStatus(Status.CONFIRMED, updatedObjects);
|
|
235
235
|
const updatedCount = response.metadata?.updated_count ?? 0;
|
|
236
|
-
liveResult = [updatedCount, { [modelName]: updatedCount }];
|
|
236
|
+
liveResult = [updatedCount, { [modelName]: updatedCount }, updatedObjects];
|
|
237
237
|
breakThenable(liveResult);
|
|
238
238
|
return liveResult;
|
|
239
239
|
})
|
|
@@ -258,13 +258,13 @@ export class QueryExecutor {
|
|
|
258
258
|
const operation = OperationFactory.createDeleteOperation(querySet);
|
|
259
259
|
// live placeholder: assume we delete all existing pks
|
|
260
260
|
const estimatedCount = operation.instances.length;
|
|
261
|
-
let liveResult = [estimatedCount, { [modelName]: estimatedCount }];
|
|
261
|
+
let liveResult = [estimatedCount, { [modelName]: estimatedCount }, []];
|
|
262
262
|
const promise = makeApiCall(querySet, operationType, {}, operation.operationId)
|
|
263
263
|
.then((response) => {
|
|
264
264
|
const deletedCount = response.metadata.deleted_count;
|
|
265
265
|
const deletedInstances = response.metadata.rows_deleted;
|
|
266
266
|
operation.updateStatus(Status.CONFIRMED, deletedInstances);
|
|
267
|
-
liveResult = [deletedCount, { [modelName]: deletedCount }];
|
|
267
|
+
liveResult = [deletedCount, { [modelName]: deletedCount }, deletedInstances || []];
|
|
268
268
|
breakThenable(liveResult);
|
|
269
269
|
return liveResult;
|
|
270
270
|
})
|
|
@@ -468,7 +468,7 @@ export class QueryExecutor {
|
|
|
468
468
|
// Use factory to create operation
|
|
469
469
|
const operation = OperationFactory.createDeleteInstanceOperation(querySet, args);
|
|
470
470
|
// 1) placeholder result
|
|
471
|
-
let liveResult = [1, { [modelName]: 1 }];
|
|
471
|
+
let liveResult = [1, { [modelName]: 1 }, []];
|
|
472
472
|
// 2) async call
|
|
473
473
|
const promise = makeApiCall(querySet, operationType, args, operation.operationId)
|
|
474
474
|
.then((response) => {
|
|
@@ -477,10 +477,12 @@ export class QueryExecutor {
|
|
|
477
477
|
if (typeof response.data === "number") {
|
|
478
478
|
deletedCount = response.data;
|
|
479
479
|
}
|
|
480
|
+
// Get deleted instances from metadata if available
|
|
481
|
+
const deletedInstances = response.metadata?.rows_deleted || [args];
|
|
480
482
|
// Confirm operation
|
|
481
483
|
operation.updateStatus(Status.CONFIRMED, [args]);
|
|
482
484
|
// Swap in real result and freeze
|
|
483
|
-
liveResult = [deletedCount, { [modelName]: deletedCount }];
|
|
485
|
+
liveResult = [deletedCount, { [modelName]: deletedCount }, deletedInstances];
|
|
484
486
|
breakThenable(liveResult);
|
|
485
487
|
return liveResult;
|
|
486
488
|
})
|
|
@@ -195,12 +195,12 @@ export class QuerySet<T> {
|
|
|
195
195
|
*/
|
|
196
196
|
create(data: Object): Promise<any>;
|
|
197
197
|
/**
|
|
198
|
-
* Creates multiple model instances using the provided
|
|
198
|
+
* Creates multiple model instances using the provided model instances.
|
|
199
199
|
*
|
|
200
|
-
* @param {Array<
|
|
200
|
+
* @param {Array<Model>} modelInstances - Array of unsaved model instances to create.
|
|
201
201
|
* @returns {Promise<Array<any>>} A promise that resolves to an array of newly created model instances.
|
|
202
202
|
*/
|
|
203
|
-
bulkCreate(
|
|
203
|
+
bulkCreate(modelInstances: Array<Model>): Promise<Array<any>>;
|
|
204
204
|
/**
|
|
205
205
|
* Updates records in the QuerySet.
|
|
206
206
|
*
|
|
@@ -268,3 +268,4 @@ export class QuerySet<T> {
|
|
|
268
268
|
[Symbol.asyncIterator](): AsyncIterator<T>;
|
|
269
269
|
}
|
|
270
270
|
import { ModelSerializer } from "./serializers.js";
|
|
271
|
+
import { Model } from "./model.js";
|
|
@@ -426,18 +426,23 @@ export class QuerySet {
|
|
|
426
426
|
return QueryExecutor.execute(newQs, "create", { data: serializedData });
|
|
427
427
|
}
|
|
428
428
|
/**
|
|
429
|
-
* Creates multiple model instances using the provided
|
|
429
|
+
* Creates multiple model instances using the provided model instances.
|
|
430
430
|
*
|
|
431
|
-
* @param {Array<
|
|
431
|
+
* @param {Array<Model>} modelInstances - Array of unsaved model instances to create.
|
|
432
432
|
* @returns {Promise<Array<any>>} A promise that resolves to an array of newly created model instances.
|
|
433
433
|
*/
|
|
434
|
-
async bulkCreate(
|
|
434
|
+
async bulkCreate(modelInstances) {
|
|
435
435
|
this.ensureNotMaterialized();
|
|
436
|
-
if (!Array.isArray(
|
|
437
|
-
throw new Error("bulkCreate expects an array of
|
|
436
|
+
if (!Array.isArray(modelInstances)) {
|
|
437
|
+
throw new Error("bulkCreate expects an array of model instances");
|
|
438
438
|
}
|
|
439
|
-
// Serialize each
|
|
440
|
-
const serializedDataList =
|
|
439
|
+
// Serialize each model instance using model.serialize()
|
|
440
|
+
const serializedDataList = modelInstances.map(instance => {
|
|
441
|
+
if (!instance || typeof instance.serialize !== 'function') {
|
|
442
|
+
throw new Error("bulkCreate requires model instances. Did you pass a plain object instead?");
|
|
443
|
+
}
|
|
444
|
+
return instance.serialize();
|
|
445
|
+
});
|
|
441
446
|
// Materialize for bulk create
|
|
442
447
|
const newQs = new QuerySet(this.ModelClass, {
|
|
443
448
|
...this._getConfig(),
|
package/package.json
CHANGED