@statezero/core 0.1.95 → 0.1.97

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 data array.
123
+ * Creates multiple model instances using the provided model instances.
124
124
  *
125
- * @param {Array<Object>} dataList - Array of data objects to create model instances.
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(dataList: Array<Object>): Promise<Array<any>>;
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 data array.
156
+ * Creates multiple model instances using the provided model instances.
157
157
  *
158
- * @param {Array<Object>} dataList - Array of data objects to create model instances.
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(dataList) {
162
- return this.newQuerySet().bulkCreate(dataList);
161
+ async bulkCreate(modelInstances) {
162
+ return this.newQuerySet().bulkCreate(modelInstances);
163
163
  }
164
164
  /**
165
165
  * Fetches all records using the current QuerySet.
@@ -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 data array.
198
+ * Creates multiple model instances using the provided model instances.
199
199
  *
200
- * @param {Array<Object>} dataList - Array of data objects to create model instances.
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(dataList: Array<Object>): Promise<Array<any>>;
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 data array.
429
+ * Creates multiple model instances using the provided model instances.
430
430
  *
431
- * @param {Array<Object>} dataList - Array of data objects to create model instances.
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(dataList) {
434
+ async bulkCreate(modelInstances) {
435
435
  this.ensureNotMaterialized();
436
- if (!Array.isArray(dataList)) {
437
- throw new Error("bulkCreate expects an array of data objects");
436
+ if (!Array.isArray(modelInstances)) {
437
+ throw new Error("bulkCreate expects an array of model instances");
438
438
  }
439
- // Serialize each data object before sending to backend
440
- const serializedDataList = dataList.map(data => this._serializer.toInternal(data));
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(),
@@ -202,9 +202,9 @@ export class QuerysetStore {
202
202
  typeof this.getRootStore === "function" &&
203
203
  !this.isTemp) {
204
204
  const { isRoot, rootStore } = this.getRootStore(this.queryset);
205
- // If we're not in root mode and have a root store, ALWAYS render from it
206
- // since operations are only routed to root stores now
207
- if (!isRoot && rootStore) {
205
+ // Only render from root if the root has been synced at least once
206
+ // This prevents child stores from getting empty data on first render
207
+ if (!isRoot && rootStore && rootStore.lastSync !== null) {
208
208
  pks = this.renderFromRoot(optimistic, rootStore);
209
209
  }
210
210
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@statezero/core",
3
- "version": "0.1.95",
3
+ "version": "0.1.97",
4
4
  "type": "module",
5
5
  "module": "ESNext",
6
6
  "description": "The type-safe frontend client for StateZero - connect directly to your backend models with zero boilerplate",