@statezero/core 0.1.45 → 0.1.47
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.
|
@@ -25,6 +25,7 @@ export class FileObject {
|
|
|
25
25
|
get status(): "failed" | "uploading" | "uploaded" | "pending";
|
|
26
26
|
get filePath(): any;
|
|
27
27
|
get fileUrl(): any;
|
|
28
|
+
serialize(): any;
|
|
28
29
|
_initializeAndStartUpload(file: any, options: any): any;
|
|
29
30
|
/**
|
|
30
31
|
* Fast upload using S3 presigned URLs with multipart support
|
|
@@ -82,6 +82,25 @@ export class FileObject {
|
|
|
82
82
|
}
|
|
83
83
|
return configInstance.buildFileUrl(this.uploadResult.file_url, this.constructor.configKey);
|
|
84
84
|
}
|
|
85
|
+
serialize() {
|
|
86
|
+
const status = this.status;
|
|
87
|
+
if (status === "uploaded" && this.filePath) {
|
|
88
|
+
return this.filePath;
|
|
89
|
+
}
|
|
90
|
+
else if (status === "failed") {
|
|
91
|
+
// Fix: use "failed" instead of "error"
|
|
92
|
+
throw new Error(`Cannot use FileObject in query - upload failed: ${this.uploadError}`);
|
|
93
|
+
}
|
|
94
|
+
else if (status === "uploading") {
|
|
95
|
+
throw new Error(`Cannot use FileObject in query - file is still uploading. Wait for upload to complete before executing the query.`);
|
|
96
|
+
}
|
|
97
|
+
else if (status === "pending") {
|
|
98
|
+
throw new Error(`Cannot use FileObject in query - file upload has not started yet.`);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
throw new Error(`Cannot use FileObject in query - unexpected status: ${status}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
85
104
|
async _initializeAndStartUpload(file, options) {
|
|
86
105
|
const config = configInstance.getConfig();
|
|
87
106
|
const backend = config.backendConfigs?.[this.constructor.configKey];
|
|
@@ -13,6 +13,7 @@ import { FileObject } from './files.js';
|
|
|
13
13
|
import { configInstance } from "../../config.js";
|
|
14
14
|
import { parseStateZeroError, MultipleObjectsReturned, DoesNotExist, } from "./errors.js";
|
|
15
15
|
import axios from "axios";
|
|
16
|
+
import { typeOf } from "mathjs";
|
|
16
17
|
/**
|
|
17
18
|
* A constructor for a Model.
|
|
18
19
|
*
|
|
@@ -192,28 +193,15 @@ export class Model {
|
|
|
192
193
|
*/
|
|
193
194
|
serializeField(field) {
|
|
194
195
|
const ModelClass = this.constructor;
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
if (
|
|
203
|
-
|
|
204
|
-
}
|
|
205
|
-
else if (status === "error") {
|
|
206
|
-
throw new Error(`Cannot serialize FileObject for field '${field}' - upload failed: ${value.uploadError}`);
|
|
207
|
-
}
|
|
208
|
-
else if (status === "uploading") {
|
|
209
|
-
throw new Error(`Cannot serialize FileObject for field '${field}' - file is still uploading`);
|
|
210
|
-
}
|
|
211
|
-
else if (status === "pending") {
|
|
212
|
-
throw new Error(`Cannot serialize FileObject for field '${field}' - file upload has not started`);
|
|
213
|
-
}
|
|
214
|
-
else {
|
|
215
|
-
throw new Error(`Cannot serialize FileObject for field '${field}' - unexpected status: ${status}`);
|
|
216
|
-
}
|
|
196
|
+
if (ModelClass.primaryKeyField === field)
|
|
197
|
+
return this._pk;
|
|
198
|
+
// check local overrides
|
|
199
|
+
let value = this._data[field];
|
|
200
|
+
// if it's not been overridden, get it from the store
|
|
201
|
+
if (value === undefined && !isNil(this._pk)) {
|
|
202
|
+
let storedValue = modelStoreRegistry.getEntity(ModelClass, this._pk);
|
|
203
|
+
if (storedValue)
|
|
204
|
+
value = storedValue[field];
|
|
217
205
|
}
|
|
218
206
|
// Date/DateTime fields need special handling - convert Date objects to strings for API
|
|
219
207
|
const dateFormats = ["date", "date-time"];
|
|
@@ -223,6 +211,12 @@ export class Model {
|
|
|
223
211
|
// Let DateParsingHelpers.serializeDate throw if it fails
|
|
224
212
|
return DateParsingHelpers.serializeDate(value, field, ModelClass.schema);
|
|
225
213
|
}
|
|
214
|
+
const fileFormats = ["file-field", "image-field"];
|
|
215
|
+
if (ModelClass.schema &&
|
|
216
|
+
fileFormats.includes(ModelClass.schema.properties[field]?.format)) {
|
|
217
|
+
value = this.getField(field);
|
|
218
|
+
return value ? value.serialize() : null;
|
|
219
|
+
}
|
|
226
220
|
return value;
|
|
227
221
|
}
|
|
228
222
|
/**
|
package/package.json
CHANGED