@statezero/core 0.1.49 → 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 =
|
|
33
|
+
this.uploadPromise = null;
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
36
36
|
// Handle File objects (for upload) - existing code
|
|
@@ -59,13 +59,6 @@ export class FileObject {
|
|
|
59
59
|
`Provided: ${this.chunkSize / (1024 * 1024)}MB`);
|
|
60
60
|
}
|
|
61
61
|
this.maxConcurrency = options.maxConcurrency || 3;
|
|
62
|
-
// This is to make the fileObject serializable by IDB in the cache
|
|
63
|
-
Object.defineProperty(this, "uploadPromise", {
|
|
64
|
-
value: Promise.resolve(this.uploadResult),
|
|
65
|
-
writable: true,
|
|
66
|
-
enumerable: false,
|
|
67
|
-
configurable: true
|
|
68
|
-
});
|
|
69
62
|
this.uploadPromise = this._initializeAndStartUpload(file, options);
|
|
70
63
|
}
|
|
71
64
|
get isStoredFile() {
|
|
@@ -374,7 +367,23 @@ export class FileObject {
|
|
|
374
367
|
return new Blob([this.fileData], { type: this.type });
|
|
375
368
|
}
|
|
376
369
|
async waitForUpload() {
|
|
377
|
-
|
|
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);
|
|
378
387
|
}
|
|
379
388
|
toJSON() {
|
|
380
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