@statezero/core 0.2.11 → 0.2.13

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.
@@ -636,7 +636,8 @@ async function main() {
636
636
  console.log("Fetching action schemas from backends...");
637
637
  const fetchPromises = Object.values(backendConfigs).map(async (backend) => {
638
638
  try {
639
- const response = await axios.get(`${backend.API_URL}/actions-schema/`);
639
+ const headers = backend.SYNC_TOKEN ? { "X-Sync-Token": backend.SYNC_TOKEN } : {};
640
+ const response = await axios.get(`${backend.API_URL}/actions-schema/`, { headers });
640
641
  return { backend, actions: response.data.actions || {} };
641
642
  }
642
643
  catch (error) {
@@ -508,7 +508,8 @@ const dtsTemplate = Handlebars.compile(TS_DECLARATION_TEMPLATE);
508
508
  */
509
509
  async function generateSchemaForModel(backend, model) {
510
510
  const schemaUrl = `${backend.API_URL}/${model}/get-schema/`;
511
- const schemaResponse = await axios.get(schemaUrl);
511
+ const headers = backend.SYNC_TOKEN ? { "X-Sync-Token": backend.SYNC_TOKEN } : {};
512
+ const schemaResponse = await axios.get(schemaUrl, { headers });
512
513
  /** @type {SchemaDefinition} */
513
514
  let schema;
514
515
  if (schemaResponse.data.components?.schemas?.[model]) {
@@ -1038,7 +1039,8 @@ async function main() {
1038
1039
  const backend = backendConfigs[key];
1039
1040
  backend.NAME = key;
1040
1041
  try {
1041
- const response = await axios.get(`${backend.API_URL}/models/`);
1042
+ const headers = backend.SYNC_TOKEN ? { "X-Sync-Token": backend.SYNC_TOKEN } : {};
1043
+ const response = await axios.get(`${backend.API_URL}/models/`, { headers });
1042
1044
  return { backend, models: response.data };
1043
1045
  }
1044
1046
  catch (error) {
package/dist/config.js CHANGED
@@ -50,6 +50,7 @@ const backendSchema = z.object({
50
50
  }),
51
51
  GENERATED_ACTIONS_DIR: z.string().optional(),
52
52
  BACKEND_TZ: z.string().optional(),
53
+ SYNC_TOKEN: z.string().optional(),
53
54
  fileRootURL: z.string().url("fileRootURL must be a valid URL").optional(),
54
55
  fileUploadMode: z.enum(["server", "s3"]).default("server"),
55
56
  getAuthHeaders: z
@@ -283,16 +283,17 @@ function createOperatorFromLookup(field, lookup, value, isRelationship, ModelCla
283
283
  return { field, operator: { $in: value } };
284
284
  }
285
285
  else if (lookup === 'gt') {
286
- return { field, operator: { $gt: value } };
286
+ // Exclude null/undefined to match Django (NULL comparisons return no results)
287
+ return { field, operator: { $nin: [null, undefined], $gt: value } };
287
288
  }
288
289
  else if (lookup === 'gte') {
289
- return { field, operator: { $gte: value } };
290
+ return { field, operator: { $nin: [null, undefined], $gte: value } };
290
291
  }
291
292
  else if (lookup === 'lt') {
292
- return { field, operator: { $lt: value } };
293
+ return { field, operator: { $nin: [null, undefined], $lt: value } };
293
294
  }
294
295
  else if (lookup === 'lte') {
295
- return { field, operator: { $lte: value } };
296
+ return { field, operator: { $nin: [null, undefined], $lte: value } };
296
297
  }
297
298
  else {
298
299
  // Default to direct equality if lookup not recognized
@@ -220,7 +220,30 @@ export class ModelSerializer {
220
220
  ...context,
221
221
  });
222
222
  }
223
- // Fallback to default serialization
223
+ // Django-style type coercion for basic types (mimics get_prep_value)
224
+ if (value !== null && value !== undefined) {
225
+ if (fieldType === 'integer') {
226
+ const num = Number(value);
227
+ return Number.isNaN(num) ? value : Math.trunc(num);
228
+ }
229
+ if (fieldType === 'number') {
230
+ const num = Number(value);
231
+ return Number.isNaN(num) ? value : num;
232
+ }
233
+ if (fieldType === 'boolean') {
234
+ if (typeof value === 'string') {
235
+ const lower = value.toLowerCase();
236
+ if (['true', '1', 't', 'yes'].includes(lower))
237
+ return true;
238
+ if (['false', '0', 'f', 'no', ''].includes(lower))
239
+ return false;
240
+ }
241
+ return Boolean(value);
242
+ }
243
+ if (fieldType === 'string' && typeof value !== 'string') {
244
+ return String(value);
245
+ }
246
+ }
224
247
  return value;
225
248
  }
226
249
  toLive(data) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@statezero/core",
3
- "version": "0.2.11",
3
+ "version": "0.2.13",
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",