@statezero/core 0.1.8 → 0.1.10
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.
- package/dist/config.d.ts +5 -0
- package/dist/config.js +23 -1
- package/dist/flavours/django/files.js +4 -1
- package/dist/flavours/django/model.js +18 -3
- package/package.json +1 -1
package/dist/config.d.ts
CHANGED
|
@@ -29,6 +29,10 @@ export function initializeAllEventReceivers(): Object;
|
|
|
29
29
|
* @param {Function} getterFn - The getModelClass function imported from model-registry.js
|
|
30
30
|
*/
|
|
31
31
|
export function registerModelGetter(getterFn: Function): void;
|
|
32
|
+
/**
|
|
33
|
+
* Helper function to build file URLs
|
|
34
|
+
*/
|
|
35
|
+
export function buildFileUrl(fileUrl: any, backendKey?: string): any;
|
|
32
36
|
/**
|
|
33
37
|
* Get a model class by name using the registered getter.
|
|
34
38
|
*
|
|
@@ -47,6 +51,7 @@ export namespace configInstance {
|
|
|
47
51
|
export { initializeEventReceiver };
|
|
48
52
|
export { registerModelGetter };
|
|
49
53
|
export { getModelClass };
|
|
54
|
+
export { buildFileUrl };
|
|
50
55
|
}
|
|
51
56
|
export default configInstance;
|
|
52
57
|
import { PusherEventReceiver } from './core/eventReceivers.js';
|
package/dist/config.js
CHANGED
|
@@ -47,6 +47,7 @@ const backendSchema = z.object({
|
|
|
47
47
|
API_URL: z.string().url('API_URL must be a valid URL'),
|
|
48
48
|
GENERATED_TYPES_DIR: z.string({ required_error: 'GENERATED_TYPES_DIR is required' }),
|
|
49
49
|
BACKEND_TZ: z.string().optional(),
|
|
50
|
+
fileRootURL: z.string().url('fileRootURL must be a valid URL').optional(),
|
|
50
51
|
fileUploadMode: z.enum(['server', 's3']).default('server'),
|
|
51
52
|
getAuthHeaders: z.function().optional()
|
|
52
53
|
.refine((fn) => fn === undefined || typeof fn === 'function', 'getAuthHeaders must be a function if provided'),
|
|
@@ -212,6 +213,26 @@ export function registerModelGetter(getterFn) {
|
|
|
212
213
|
}
|
|
213
214
|
modelGetter = getterFn;
|
|
214
215
|
}
|
|
216
|
+
/**
|
|
217
|
+
* Helper function to build file URLs
|
|
218
|
+
*/
|
|
219
|
+
export function buildFileUrl(fileUrl, backendKey = 'default') {
|
|
220
|
+
// If URL is already absolute (cloud storage), use it as-is
|
|
221
|
+
if (fileUrl && fileUrl.startsWith('http')) {
|
|
222
|
+
return fileUrl;
|
|
223
|
+
}
|
|
224
|
+
const cfg = getConfig();
|
|
225
|
+
const backend = cfg.backendConfigs[backendKey];
|
|
226
|
+
if (!backend) {
|
|
227
|
+
throw new ConfigError(`Backend "${backendKey}" not found in configuration.`);
|
|
228
|
+
}
|
|
229
|
+
// If no fileRootURL provided, return relative URL as-is
|
|
230
|
+
if (!backend.fileRootURL) {
|
|
231
|
+
return fileUrl;
|
|
232
|
+
}
|
|
233
|
+
// Construct full URL
|
|
234
|
+
return backend.fileRootURL.replace(/\/$/, '') + fileUrl;
|
|
235
|
+
}
|
|
215
236
|
/**
|
|
216
237
|
* Get a model class by name using the registered getter.
|
|
217
238
|
*
|
|
@@ -237,6 +258,7 @@ export const configInstance = {
|
|
|
237
258
|
setBackendConfig,
|
|
238
259
|
initializeEventReceiver,
|
|
239
260
|
registerModelGetter,
|
|
240
|
-
getModelClass
|
|
261
|
+
getModelClass,
|
|
262
|
+
buildFileUrl
|
|
241
263
|
};
|
|
242
264
|
export default configInstance;
|
|
@@ -77,7 +77,10 @@ export class FileObject {
|
|
|
77
77
|
return this.uploadResult?.file_path;
|
|
78
78
|
}
|
|
79
79
|
get fileUrl() {
|
|
80
|
-
|
|
80
|
+
if (!this.uploadResult?.file_url) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
return configInstance.buildFileUrl(this.uploadResult.file_url, this.constructor.configKey);
|
|
81
84
|
}
|
|
82
85
|
async _initializeAndStartUpload(file, options) {
|
|
83
86
|
const config = configInstance.getConfig();
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
|
|
2
|
+
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
|
|
3
|
+
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
|
4
|
+
};
|
|
1
5
|
import { Manager } from "./manager.js";
|
|
2
6
|
import { ValidationError } from "./errors.js";
|
|
3
7
|
import { modelStoreRegistry } from "../../syncEngine/registries/modelStoreRegistry.js";
|
|
@@ -5,6 +9,7 @@ import { isNil } from "lodash-es";
|
|
|
5
9
|
import { QueryExecutor } from "./queryExecutor";
|
|
6
10
|
import { wrapReactiveModel } from "../../reactiveAdaptor.js";
|
|
7
11
|
import { DateParsingHelpers } from "./dates.js";
|
|
12
|
+
import { FileObject } from './files.js';
|
|
8
13
|
/**
|
|
9
14
|
* A constructor for a Model.
|
|
10
15
|
*
|
|
@@ -70,6 +75,7 @@ export class Model {
|
|
|
70
75
|
* @returns {any} The field value
|
|
71
76
|
*/
|
|
72
77
|
getField(field) {
|
|
78
|
+
var _a;
|
|
73
79
|
// Access the reactive __version property to establish dependency for vue integration
|
|
74
80
|
const trackVersion = this.__version;
|
|
75
81
|
const ModelClass = this.constructor;
|
|
@@ -83,15 +89,24 @@ export class Model {
|
|
|
83
89
|
if (storedValue)
|
|
84
90
|
value = storedValue[field]; // if stops null -> undefined
|
|
85
91
|
}
|
|
86
|
-
// File fields need special handling - wrap as FileObject
|
|
87
|
-
|
|
92
|
+
// File/Image fields need special handling - wrap as FileObject
|
|
93
|
+
const fileFormats = ["file-path", "image-path"];
|
|
94
|
+
if (ModelClass.schema &&
|
|
95
|
+
fileFormats.includes(ModelClass.schema.properties[field]?.format) &&
|
|
96
|
+
value) {
|
|
88
97
|
// Check if it's already a FileObject
|
|
89
98
|
if (value instanceof FileObject) {
|
|
90
99
|
return value;
|
|
91
100
|
}
|
|
92
101
|
// If it's stored file data from API, wrap it as FileObject
|
|
93
102
|
if (typeof value === "object" && value.file_path) {
|
|
94
|
-
|
|
103
|
+
// Create anonymous subclass with correct configKey
|
|
104
|
+
const BackendFileObject = (_a = class extends FileObject {
|
|
105
|
+
},
|
|
106
|
+
__setFunctionName(_a, "BackendFileObject"),
|
|
107
|
+
_a.configKey = ModelClass.configKey,
|
|
108
|
+
_a);
|
|
109
|
+
return new BackendFileObject(value);
|
|
95
110
|
}
|
|
96
111
|
}
|
|
97
112
|
// relationship fields need special handling
|
package/package.json
CHANGED