@statezero/core 0.1.7 → 0.1.8
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.
|
@@ -5,10 +5,10 @@ export class FileObject {
|
|
|
5
5
|
static configKey: string;
|
|
6
6
|
static MIN_CHUNK_SIZE: number;
|
|
7
7
|
constructor(file: any, options?: {});
|
|
8
|
-
name:
|
|
9
|
-
size:
|
|
10
|
-
type:
|
|
11
|
-
lastModified: number;
|
|
8
|
+
name: any;
|
|
9
|
+
size: any;
|
|
10
|
+
type: any;
|
|
11
|
+
lastModified: number | null;
|
|
12
12
|
uploaded: boolean;
|
|
13
13
|
uploading: boolean;
|
|
14
14
|
uploadResult: any;
|
|
@@ -21,6 +21,7 @@ export class FileObject {
|
|
|
21
21
|
chunkSize: any;
|
|
22
22
|
maxConcurrency: any;
|
|
23
23
|
uploadPromise: any;
|
|
24
|
+
get isStoredFile(): any;
|
|
24
25
|
get status(): "failed" | "uploading" | "uploaded" | "pending";
|
|
25
26
|
get filePath(): any;
|
|
26
27
|
get fileUrl(): any;
|
|
@@ -59,9 +60,9 @@ export class FileObject {
|
|
|
59
60
|
getBlob(): Blob;
|
|
60
61
|
waitForUpload(): Promise<any>;
|
|
61
62
|
toJSON(): {
|
|
62
|
-
name:
|
|
63
|
-
size:
|
|
64
|
-
type:
|
|
63
|
+
name: any;
|
|
64
|
+
size: any;
|
|
65
|
+
type: any;
|
|
65
66
|
status: string;
|
|
66
67
|
uploaded: boolean;
|
|
67
68
|
filePath: any;
|
|
@@ -5,9 +5,37 @@ import PQueue from "p-queue";
|
|
|
5
5
|
* FileObject - A file wrapper that handles uploads to StateZero backend
|
|
6
6
|
*/
|
|
7
7
|
export class FileObject {
|
|
8
|
+
// Simple changes to FileObject constructor
|
|
8
9
|
constructor(file, options = {}) {
|
|
10
|
+
// Handle stored file data (from API)
|
|
11
|
+
if (file &&
|
|
12
|
+
typeof file === "object" &&
|
|
13
|
+
file.file_path &&
|
|
14
|
+
!(file instanceof File)) {
|
|
15
|
+
// This is stored file data from the backend
|
|
16
|
+
this.name = file.file_name;
|
|
17
|
+
this.size = file.size;
|
|
18
|
+
this.type = file.mime_type; // Now coming from backend
|
|
19
|
+
this.lastModified = null;
|
|
20
|
+
// Mark as already uploaded
|
|
21
|
+
this.uploaded = true;
|
|
22
|
+
this.uploading = false;
|
|
23
|
+
this.uploadResult = file; // Store the entire response
|
|
24
|
+
this.uploadError = null;
|
|
25
|
+
this.fileData = null;
|
|
26
|
+
// No upload properties needed
|
|
27
|
+
this.uploadType = null;
|
|
28
|
+
this.uploadId = null;
|
|
29
|
+
this.totalChunks = 0;
|
|
30
|
+
this.completedChunks = 0;
|
|
31
|
+
this.chunkSize = null;
|
|
32
|
+
this.maxConcurrency = null;
|
|
33
|
+
this.uploadPromise = Promise.resolve(this.uploadResult);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
// Handle File objects (for upload) - existing code
|
|
9
37
|
if (!file || !(file instanceof File)) {
|
|
10
|
-
throw new Error("FileObject requires a File object");
|
|
38
|
+
throw new Error("FileObject requires a File object or stored file data");
|
|
11
39
|
}
|
|
12
40
|
// Store file metadata directly
|
|
13
41
|
this.name = file.name;
|
|
@@ -33,6 +61,9 @@ export class FileObject {
|
|
|
33
61
|
this.maxConcurrency = options.maxConcurrency || 3;
|
|
34
62
|
this.uploadPromise = this._initializeAndStartUpload(file, options);
|
|
35
63
|
}
|
|
64
|
+
get isStoredFile() {
|
|
65
|
+
return this.uploaded && !this.fileData && this.uploadResult?.file_path;
|
|
66
|
+
}
|
|
36
67
|
get status() {
|
|
37
68
|
if (this.uploadError)
|
|
38
69
|
return "failed";
|
|
@@ -83,6 +83,17 @@ export class Model {
|
|
|
83
83
|
if (storedValue)
|
|
84
84
|
value = storedValue[field]; // if stops null -> undefined
|
|
85
85
|
}
|
|
86
|
+
// File fields need special handling - wrap as FileObject
|
|
87
|
+
if (ModelClass.fileFields && ModelClass.fileFields.has(field) && value) {
|
|
88
|
+
// Check if it's already a FileObject
|
|
89
|
+
if (value instanceof FileObject) {
|
|
90
|
+
return value;
|
|
91
|
+
}
|
|
92
|
+
// If it's stored file data from API, wrap it as FileObject
|
|
93
|
+
if (typeof value === "object" && value.file_path) {
|
|
94
|
+
return new FileObject(value);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
86
97
|
// relationship fields need special handling
|
|
87
98
|
if (ModelClass.relationshipFields.has(field) && value) {
|
|
88
99
|
// fetch the stored value
|
|
@@ -48,8 +48,8 @@ export class MaxStrategy extends MetricCalculationStrategy {
|
|
|
48
48
|
* Factory class for creating the appropriate strategy
|
|
49
49
|
*/
|
|
50
50
|
export class MetricStrategyFactory {
|
|
51
|
-
static "__#
|
|
52
|
-
static "__#
|
|
51
|
+
static "__#5@#customStrategies": Map<any, any>;
|
|
52
|
+
static "__#5@#defaultStrategies": Map<string, () => CountStrategy>;
|
|
53
53
|
/**
|
|
54
54
|
* Clear all custom strategy overrides
|
|
55
55
|
*/
|
|
@@ -61,7 +61,7 @@ export class MetricStrategyFactory {
|
|
|
61
61
|
* @param {Function} ModelClass - The model class
|
|
62
62
|
* @returns {string} A unique key
|
|
63
63
|
*/
|
|
64
|
-
private static "__#
|
|
64
|
+
private static "__#5@#generateStrategyKey";
|
|
65
65
|
/**
|
|
66
66
|
* Override a strategy for a specific metric type and model class
|
|
67
67
|
* @param {string} metricType - The type of metric (count, sum, min, max)
|
package/package.json
CHANGED