@statezero/core 0.1.42 → 0.1.44

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.
@@ -37,51 +37,6 @@ export function processIncludedEntities(modelStoreRegistry, included, ModelClass
37
37
  throw new Error(`Failed to process included entities: ${error.message}`);
38
38
  }
39
39
  }
40
- /**
41
- * Recursively processes an object to replace FileObject instances with their file paths.
42
- * Throws an error if any FileObject is not yet uploaded.
43
- *
44
- * @param {any} obj - The object to process
45
- * @returns {any} The processed object with FileObjects replaced by paths
46
- */
47
- function processFileObjects(obj) {
48
- if (obj === null || obj === undefined) {
49
- return obj;
50
- }
51
- // Handle FileObject instances
52
- if (obj instanceof FileObject) {
53
- const status = obj.status;
54
- if (status === 'uploaded' && obj.filePath) {
55
- return obj.filePath;
56
- }
57
- else if (status === 'error') {
58
- throw new Error(`Cannot use FileObject in query - upload failed: ${obj.uploadError}`);
59
- }
60
- else if (status === 'uploading') {
61
- throw new Error(`Cannot use FileObject in query - file is still uploading. Wait for upload to complete before executing the query.`);
62
- }
63
- else if (status === 'pending') {
64
- throw new Error(`Cannot use FileObject in query - file upload has not started yet.`);
65
- }
66
- else {
67
- throw new Error(`Cannot use FileObject in query - unexpected status: ${status}`);
68
- }
69
- }
70
- // Handle arrays
71
- if (Array.isArray(obj)) {
72
- return obj.map(item => processFileObjects(item));
73
- }
74
- // Handle plain objects
75
- if (typeof obj === 'object' && obj.constructor === Object) {
76
- const processedObj = {};
77
- for (const [key, value] of Object.entries(obj)) {
78
- processedObj[key] = processFileObjects(value);
79
- }
80
- return processedObj;
81
- }
82
- // Return primitive values as-is
83
- return obj;
84
- }
85
40
  /**
86
41
  * Makes an API call to the backend with the given QuerySet.
87
42
  * Automatically handles FileObject replacement with file paths for write operations.
@@ -129,15 +84,6 @@ export async function makeApiCall(querySet, operationType, args = {}, operationI
129
84
  "get_or_create", "update_or_create"
130
85
  ];
131
86
  const isWriteOperation = writeOperations.includes(operationType);
132
- // Process FileObjects for write operations
133
- if (isWriteOperation) {
134
- try {
135
- payload = processFileObjects(payload);
136
- }
137
- catch (error) {
138
- throw new Error(`Failed to process file uploads: ${error.message}`);
139
- }
140
- }
141
87
  const baseUrl = backend.API_URL.replace(/\/+$/, "");
142
88
  const finalUrl = `${baseUrl}/${ModelClass.modelName}/`;
143
89
  const headers = backend.getAuthHeaders ? backend.getAuthHeaders() : {};
@@ -202,6 +202,28 @@ export class Model {
202
202
  if (storedValue)
203
203
  value = storedValue[field];
204
204
  }
205
+ // File/Image fields need special handling - extract file_path from FileObject
206
+ const fileFormats = ["file-path", "image-path"];
207
+ if (ModelClass.schema &&
208
+ fileFormats.includes(ModelClass.schema.properties[field]?.format) &&
209
+ value instanceof FileObject) {
210
+ const status = value.status;
211
+ if (status === "uploaded" && value.filePath) {
212
+ return value.filePath;
213
+ }
214
+ else if (status === "error") {
215
+ throw new Error(`Cannot serialize FileObject for field '${field}' - upload failed: ${value.uploadError}`);
216
+ }
217
+ else if (status === "uploading") {
218
+ throw new Error(`Cannot serialize FileObject for field '${field}' - file is still uploading`);
219
+ }
220
+ else if (status === "pending") {
221
+ throw new Error(`Cannot serialize FileObject for field '${field}' - file upload has not started`);
222
+ }
223
+ else {
224
+ throw new Error(`Cannot serialize FileObject for field '${field}' - unexpected status: ${status}`);
225
+ }
226
+ }
205
227
  // Date/DateTime fields need special handling - convert Date objects to strings for API
206
228
  const dateFormats = ["date", "date-time"];
207
229
  if (ModelClass.schema &&
@@ -67,14 +67,15 @@ export class MetricRegistry {
67
67
  }
68
68
  const stores = [];
69
69
  const modelClass = queryset.ModelClass;
70
- const operationAst = queryset.build();
71
70
  for (const [key, entry] of this._stores.entries()) {
72
71
  const store = entry.store;
73
72
  // First check if model class matches
74
73
  if (store.modelClass !== modelClass) {
75
74
  continue;
76
75
  }
77
- // #TODO match queryset based on ast
76
+ if (store.queryset.semanticKey != queryset.semanticKey) {
77
+ continue;
78
+ }
78
79
  stores.push(store);
79
80
  }
80
81
  return stores;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@statezero/core",
3
- "version": "0.1.42",
3
+ "version": "0.1.44",
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",