@statezero/core 0.1.48 → 0.1.50

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.
@@ -60,6 +60,11 @@ export class FileObject {
60
60
  */
61
61
  getBlob(): Blob;
62
62
  waitForUpload(): Promise<any>;
63
+ /**
64
+ * Returns a static version of this FileObject that can be stored in IndexedDB
65
+ * Creates a new FileObject using the stored file constructor path
66
+ */
67
+ asStatic(): any;
63
68
  toJSON(): {
64
69
  name: any;
65
70
  size: any;
@@ -30,7 +30,7 @@ export class FileObject {
30
30
  this.completedChunks = 0;
31
31
  this.chunkSize = null;
32
32
  this.maxConcurrency = null;
33
- this.uploadPromise = Promise.resolve(this.uploadResult);
33
+ this.uploadPromise = null;
34
34
  return;
35
35
  }
36
36
  // Handle File objects (for upload) - existing code
@@ -367,7 +367,23 @@ export class FileObject {
367
367
  return new Blob([this.fileData], { type: this.type });
368
368
  }
369
369
  async waitForUpload() {
370
- return this.uploadPromise;
370
+ if (this.uploaded && this.uploadResult && !this.uploadPromise) {
371
+ return this.uploadResult;
372
+ }
373
+ if (this.uploadPromise) {
374
+ return this.uploadPromise;
375
+ }
376
+ throw new Error("No upload in progress and file not uploaded");
377
+ }
378
+ /**
379
+ * Returns a static version of this FileObject that can be stored in IndexedDB
380
+ * Creates a new FileObject using the stored file constructor path
381
+ */
382
+ asStatic() {
383
+ if (!this.uploaded || !this.uploadResult) {
384
+ throw new Error("Cannot create static version of file that hasn't been uploaded");
385
+ }
386
+ return new this.constructor(this.uploadResult);
371
387
  }
372
388
  toJSON() {
373
389
  return {
@@ -108,7 +108,7 @@ export class Model {
108
108
  value) {
109
109
  // Check if it's already a FileObject
110
110
  if (value instanceof FileObject) {
111
- return value;
111
+ return value.asStatic();
112
112
  }
113
113
  // If it's stored file data from API, wrap it as FileObject
114
114
  if (typeof value === "object" && value.file_path) {
@@ -118,7 +118,7 @@ export class Model {
118
118
  __setFunctionName(_a, "BackendFileObject"),
119
119
  _a.configKey = ModelClass.configKey,
120
120
  _a);
121
- return new BackendFileObject(value);
121
+ return new BackendFileObject(value).asStatic();
122
122
  }
123
123
  }
124
124
  // relationship fields need special handling
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@statezero/core",
3
- "version": "0.1.48",
3
+ "version": "0.1.50",
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",