@statezero/core 0.2.38 → 0.2.40

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.
Files changed (294) hide show
  1. package/dist/actions/backend1/django_app/calculate-hash.d.ts +57 -0
  2. package/dist/actions/backend1/django_app/calculate-hash.js +80 -0
  3. package/dist/actions/backend1/django_app/calculate-hash.schema.json +148 -0
  4. package/dist/actions/backend1/django_app/get-current-username.d.ts +29 -0
  5. package/dist/actions/backend1/django_app/get-current-username.js +65 -0
  6. package/dist/actions/backend1/django_app/get-current-username.schema.json +47 -0
  7. package/dist/actions/backend1/django_app/get-server-status.d.ts +38 -0
  8. package/dist/actions/backend1/django_app/get-server-status.js +68 -0
  9. package/dist/actions/backend1/django_app/get-server-status.schema.json +93 -0
  10. package/dist/actions/backend1/django_app/get-user-info.d.ts +44 -0
  11. package/dist/actions/backend1/django_app/get-user-info.js +70 -0
  12. package/dist/actions/backend1/django_app/get-user-info.schema.json +127 -0
  13. package/dist/actions/backend1/django_app/index.d.ts +1 -0
  14. package/dist/actions/backend1/django_app/index.js +6 -0
  15. package/dist/actions/backend1/django_app/process-data.d.ts +51 -0
  16. package/dist/actions/backend1/django_app/process-data.js +78 -0
  17. package/dist/actions/backend1/django_app/process-data.schema.json +117 -0
  18. package/dist/actions/backend1/django_app/send-notification.d.ts +55 -0
  19. package/dist/actions/backend1/django_app/send-notification.js +81 -0
  20. package/dist/actions/backend1/django_app/send-notification.schema.json +175 -0
  21. package/dist/actions/backend1/index.d.ts +1 -0
  22. package/dist/actions/backend1/index.js +1 -0
  23. package/dist/actions/default/django_app/calculate-hash.d.ts +57 -0
  24. package/dist/actions/default/django_app/calculate-hash.js +80 -0
  25. package/dist/actions/default/django_app/calculate-hash.schema.json +148 -0
  26. package/dist/actions/default/django_app/get-current-username.d.ts +29 -0
  27. package/dist/actions/default/django_app/get-current-username.js +65 -0
  28. package/dist/actions/default/django_app/get-current-username.schema.json +47 -0
  29. package/dist/actions/default/django_app/get-server-status.d.ts +38 -0
  30. package/dist/actions/default/django_app/get-server-status.js +68 -0
  31. package/dist/actions/default/django_app/get-server-status.schema.json +93 -0
  32. package/dist/actions/default/django_app/get-user-info.d.ts +44 -0
  33. package/dist/actions/default/django_app/get-user-info.js +70 -0
  34. package/dist/actions/default/django_app/get-user-info.schema.json +127 -0
  35. package/dist/actions/default/django_app/index.d.ts +1 -0
  36. package/dist/actions/default/django_app/index.js +6 -0
  37. package/dist/actions/default/django_app/process-data.d.ts +51 -0
  38. package/dist/actions/default/django_app/process-data.js +78 -0
  39. package/dist/actions/default/django_app/process-data.schema.json +117 -0
  40. package/dist/actions/default/django_app/send-notification.d.ts +55 -0
  41. package/dist/actions/default/django_app/send-notification.js +81 -0
  42. package/dist/actions/default/django_app/send-notification.schema.json +175 -0
  43. package/dist/actions/default/index.d.ts +1 -0
  44. package/dist/actions/default/index.js +1 -0
  45. package/dist/actions/index.d.ts +1 -0
  46. package/dist/actions/index.js +5 -0
  47. package/dist/adaptors/react/composables.d.ts +1 -0
  48. package/dist/adaptors/react/composables.js +4 -0
  49. package/dist/adaptors/react/index.d.ts +1 -0
  50. package/dist/adaptors/react/index.js +1 -0
  51. package/dist/adaptors/vue/components/LayoutRenderer.js +46 -49
  52. package/dist/adaptors/vue/components/defaults/index.d.ts +7 -0
  53. package/dist/adaptors/vue/components/defaults/index.js +31 -0
  54. package/dist/adaptors/vue/components/index.d.ts +1 -0
  55. package/dist/adaptors/vue/components/index.js +7 -0
  56. package/dist/adaptors/vue/composables.d.ts +2 -0
  57. package/dist/adaptors/vue/composables.js +44 -0
  58. package/dist/adaptors/vue/index.d.ts +3 -0
  59. package/dist/adaptors/vue/index.js +4 -0
  60. package/dist/adaptors/vue/reactivity.d.ts +18 -0
  61. package/dist/adaptors/vue/reactivity.js +132 -0
  62. package/dist/cli/commands/sync.d.ts +6 -0
  63. package/dist/cli/commands/sync.js +30 -0
  64. package/dist/cli/commands/syncActions.d.ts +46 -0
  65. package/dist/cli/commands/syncActions.js +717 -0
  66. package/dist/cli/commands/syncModels.d.ts +132 -0
  67. package/dist/cli/commands/syncModels.js +1120 -0
  68. package/dist/cli/configFileLoader.d.ts +10 -0
  69. package/dist/cli/configFileLoader.js +85 -0
  70. package/dist/cli/index.d.ts +2 -0
  71. package/dist/cli/index.js +22 -0
  72. package/dist/config.d.ts +57 -0
  73. package/dist/config.js +273 -0
  74. package/dist/core/eventReceivers.d.ts +185 -0
  75. package/dist/core/eventReceivers.js +266 -0
  76. package/dist/core/utils.d.ts +8 -0
  77. package/dist/core/utils.js +62 -0
  78. package/dist/errorHandler.d.ts +21 -0
  79. package/dist/errorHandler.js +27 -0
  80. package/dist/filtering/localFiltering.d.ts +110 -0
  81. package/dist/filtering/localFiltering.js +1080 -0
  82. package/dist/flavours/django/dates.d.ts +34 -0
  83. package/dist/flavours/django/dates.js +113 -0
  84. package/dist/flavours/django/errors.d.ts +138 -0
  85. package/dist/flavours/django/errors.js +195 -0
  86. package/dist/flavours/django/f.d.ts +6 -0
  87. package/dist/flavours/django/f.js +91 -0
  88. package/dist/flavours/django/files.d.ts +62 -0
  89. package/dist/flavours/django/files.js +355 -0
  90. package/dist/flavours/django/makeApiCall.d.ts +36 -0
  91. package/dist/flavours/django/makeApiCall.js +169 -0
  92. package/dist/flavours/django/manager.d.ts +204 -0
  93. package/dist/flavours/django/manager.js +222 -0
  94. package/dist/flavours/django/model.d.ts +137 -0
  95. package/dist/flavours/django/model.js +366 -0
  96. package/dist/flavours/django/operationFactory.d.ts +73 -0
  97. package/dist/flavours/django/operationFactory.js +248 -0
  98. package/dist/flavours/django/q.d.ts +70 -0
  99. package/dist/flavours/django/q.js +43 -0
  100. package/dist/flavours/django/queryExecutor.d.ts +149 -0
  101. package/dist/flavours/django/queryExecutor.js +590 -0
  102. package/dist/flavours/django/querySet.d.ts +301 -0
  103. package/dist/flavours/django/querySet.js +736 -0
  104. package/dist/flavours/django/serializers.d.ts +39 -0
  105. package/dist/flavours/django/serializers.js +296 -0
  106. package/dist/flavours/django/tempPk.d.ts +31 -0
  107. package/dist/flavours/django/tempPk.js +92 -0
  108. package/dist/flavours/django/utils.d.ts +19 -0
  109. package/dist/flavours/django/utils.js +29 -0
  110. package/dist/index.d.ts +46 -0
  111. package/dist/index.js +48 -0
  112. package/dist/models/backend1/django_app/comprehensivemodel.d.ts +894 -0
  113. package/dist/models/backend1/django_app/comprehensivemodel.js +71 -0
  114. package/dist/models/backend1/django_app/comprehensivemodel.schema.json +870 -0
  115. package/dist/models/backend1/django_app/custompkmodel.d.ts +92 -0
  116. package/dist/models/backend1/django_app/custompkmodel.js +69 -0
  117. package/dist/models/backend1/django_app/custompkmodel.schema.json +71 -0
  118. package/dist/models/backend1/django_app/dailyrate.d.ts +230 -0
  119. package/dist/models/backend1/django_app/dailyrate.js +71 -0
  120. package/dist/models/backend1/django_app/dailyrate.schema.json +212 -0
  121. package/dist/models/backend1/django_app/deepmodellevel1.d.ts +140 -0
  122. package/dist/models/backend1/django_app/deepmodellevel1.js +72 -0
  123. package/dist/models/backend1/django_app/deepmodellevel1.schema.json +114 -0
  124. package/dist/models/backend1/django_app/deepmodellevel2.d.ts +118 -0
  125. package/dist/models/backend1/django_app/deepmodellevel2.js +71 -0
  126. package/dist/models/backend1/django_app/deepmodellevel2.schema.json +92 -0
  127. package/dist/models/backend1/django_app/deepmodellevel3.d.ts +92 -0
  128. package/dist/models/backend1/django_app/deepmodellevel3.js +69 -0
  129. package/dist/models/backend1/django_app/deepmodellevel3.schema.json +69 -0
  130. package/dist/models/backend1/django_app/dummymodel.d.ts +134 -0
  131. package/dist/models/backend1/django_app/dummymodel.js +71 -0
  132. package/dist/models/backend1/django_app/dummymodel.schema.json +109 -0
  133. package/dist/models/backend1/django_app/dummyrelatedmodel.d.ts +92 -0
  134. package/dist/models/backend1/django_app/dummyrelatedmodel.js +69 -0
  135. package/dist/models/backend1/django_app/dummyrelatedmodel.schema.json +69 -0
  136. package/dist/models/backend1/django_app/filetest.d.ts +140 -0
  137. package/dist/models/backend1/django_app/filetest.js +69 -0
  138. package/dist/models/backend1/django_app/filetest.schema.json +111 -0
  139. package/dist/models/backend1/django_app/index.d.ts +1 -0
  140. package/dist/models/backend1/django_app/index.js +21 -0
  141. package/dist/models/backend1/django_app/m2mdepthtestlevel1.d.ts +118 -0
  142. package/dist/models/backend1/django_app/m2mdepthtestlevel1.js +71 -0
  143. package/dist/models/backend1/django_app/m2mdepthtestlevel1.schema.json +94 -0
  144. package/dist/models/backend1/django_app/m2mdepthtestlevel2.d.ts +118 -0
  145. package/dist/models/backend1/django_app/m2mdepthtestlevel2.js +71 -0
  146. package/dist/models/backend1/django_app/m2mdepthtestlevel2.schema.json +94 -0
  147. package/dist/models/backend1/django_app/m2mdepthtestlevel3.d.ts +134 -0
  148. package/dist/models/backend1/django_app/m2mdepthtestlevel3.js +71 -0
  149. package/dist/models/backend1/django_app/m2mdepthtestlevel3.schema.json +112 -0
  150. package/dist/models/backend1/django_app/modelwithcustompkrelation.d.ts +118 -0
  151. package/dist/models/backend1/django_app/modelwithcustompkrelation.js +71 -0
  152. package/dist/models/backend1/django_app/modelwithcustompkrelation.schema.json +93 -0
  153. package/dist/models/backend1/django_app/modelwithrestrictedfields.d.ts +134 -0
  154. package/dist/models/backend1/django_app/modelwithrestrictedfields.js +71 -0
  155. package/dist/models/backend1/django_app/modelwithrestrictedfields.schema.json +111 -0
  156. package/dist/models/backend1/django_app/namefiltercustompkmodel.d.ts +92 -0
  157. package/dist/models/backend1/django_app/namefiltercustompkmodel.js +69 -0
  158. package/dist/models/backend1/django_app/namefiltercustompkmodel.schema.json +71 -0
  159. package/dist/models/backend1/django_app/order.d.ts +220 -0
  160. package/dist/models/backend1/django_app/order.js +71 -0
  161. package/dist/models/backend1/django_app/order.schema.json +203 -0
  162. package/dist/models/backend1/django_app/orderitem.d.ts +172 -0
  163. package/dist/models/backend1/django_app/orderitem.js +72 -0
  164. package/dist/models/backend1/django_app/orderitem.schema.json +149 -0
  165. package/dist/models/backend1/django_app/product.d.ts +254 -0
  166. package/dist/models/backend1/django_app/product.js +71 -0
  167. package/dist/models/backend1/django_app/product.schema.json +277 -0
  168. package/dist/models/backend1/django_app/productcategory.d.ts +92 -0
  169. package/dist/models/backend1/django_app/productcategory.js +69 -0
  170. package/dist/models/backend1/django_app/productcategory.schema.json +70 -0
  171. package/dist/models/backend1/django_app/rateplan.d.ts +92 -0
  172. package/dist/models/backend1/django_app/rateplan.js +69 -0
  173. package/dist/models/backend1/django_app/rateplan.schema.json +70 -0
  174. package/dist/models/backend1/django_app/restrictedfieldrelatedmodel.d.ts +108 -0
  175. package/dist/models/backend1/django_app/restrictedfieldrelatedmodel.js +69 -0
  176. package/dist/models/backend1/django_app/restrictedfieldrelatedmodel.schema.json +87 -0
  177. package/dist/models/backend1/fileobject.d.ts +4 -0
  178. package/dist/models/backend1/fileobject.js +9 -0
  179. package/dist/models/backend1/index.d.ts +2 -0
  180. package/dist/models/backend1/index.js +2 -0
  181. package/dist/models/default/django_app/comprehensivemodel.d.ts +894 -0
  182. package/dist/models/default/django_app/comprehensivemodel.js +71 -0
  183. package/dist/models/default/django_app/comprehensivemodel.schema.json +870 -0
  184. package/dist/models/default/django_app/custompkmodel.d.ts +92 -0
  185. package/dist/models/default/django_app/custompkmodel.js +69 -0
  186. package/dist/models/default/django_app/custompkmodel.schema.json +71 -0
  187. package/dist/models/default/django_app/dailyrate.d.ts +230 -0
  188. package/dist/models/default/django_app/dailyrate.js +71 -0
  189. package/dist/models/default/django_app/dailyrate.schema.json +212 -0
  190. package/dist/models/default/django_app/deepmodellevel1.d.ts +128 -0
  191. package/dist/models/default/django_app/deepmodellevel1.js +72 -0
  192. package/dist/models/default/django_app/deepmodellevel1.schema.json +102 -0
  193. package/dist/models/default/django_app/deepmodellevel2.d.ts +106 -0
  194. package/dist/models/default/django_app/deepmodellevel2.js +71 -0
  195. package/dist/models/default/django_app/deepmodellevel2.schema.json +80 -0
  196. package/dist/models/default/django_app/deepmodellevel3.d.ts +80 -0
  197. package/dist/models/default/django_app/deepmodellevel3.js +69 -0
  198. package/dist/models/default/django_app/deepmodellevel3.schema.json +57 -0
  199. package/dist/models/default/django_app/dummymodel.d.ts +122 -0
  200. package/dist/models/default/django_app/dummymodel.js +71 -0
  201. package/dist/models/default/django_app/dummymodel.schema.json +97 -0
  202. package/dist/models/default/django_app/dummyrelatedmodel.d.ts +80 -0
  203. package/dist/models/default/django_app/dummyrelatedmodel.js +69 -0
  204. package/dist/models/default/django_app/dummyrelatedmodel.schema.json +57 -0
  205. package/dist/models/default/django_app/filetest.d.ts +128 -0
  206. package/dist/models/default/django_app/filetest.js +69 -0
  207. package/dist/models/default/django_app/filetest.schema.json +99 -0
  208. package/dist/models/default/django_app/index.d.ts +1 -0
  209. package/dist/models/default/django_app/index.js +21 -0
  210. package/dist/models/default/django_app/m2mdepthtestlevel1.d.ts +118 -0
  211. package/dist/models/default/django_app/m2mdepthtestlevel1.js +71 -0
  212. package/dist/models/default/django_app/m2mdepthtestlevel1.schema.json +94 -0
  213. package/dist/models/default/django_app/m2mdepthtestlevel2.d.ts +118 -0
  214. package/dist/models/default/django_app/m2mdepthtestlevel2.js +71 -0
  215. package/dist/models/default/django_app/m2mdepthtestlevel2.schema.json +94 -0
  216. package/dist/models/default/django_app/m2mdepthtestlevel3.d.ts +134 -0
  217. package/dist/models/default/django_app/m2mdepthtestlevel3.js +71 -0
  218. package/dist/models/default/django_app/m2mdepthtestlevel3.schema.json +112 -0
  219. package/dist/models/default/django_app/modelwithcustompkrelation.d.ts +118 -0
  220. package/dist/models/default/django_app/modelwithcustompkrelation.js +71 -0
  221. package/dist/models/default/django_app/modelwithcustompkrelation.schema.json +93 -0
  222. package/dist/models/default/django_app/modelwithrestrictedfields.d.ts +134 -0
  223. package/dist/models/default/django_app/modelwithrestrictedfields.js +71 -0
  224. package/dist/models/default/django_app/modelwithrestrictedfields.schema.json +111 -0
  225. package/dist/models/default/django_app/namefiltercustompkmodel.d.ts +92 -0
  226. package/dist/models/default/django_app/namefiltercustompkmodel.js +69 -0
  227. package/dist/models/default/django_app/namefiltercustompkmodel.schema.json +71 -0
  228. package/dist/models/default/django_app/order.d.ts +220 -0
  229. package/dist/models/default/django_app/order.js +71 -0
  230. package/dist/models/default/django_app/order.schema.json +203 -0
  231. package/dist/models/default/django_app/orderitem.d.ts +172 -0
  232. package/dist/models/default/django_app/orderitem.js +72 -0
  233. package/dist/models/default/django_app/orderitem.schema.json +149 -0
  234. package/dist/models/default/django_app/product.d.ts +254 -0
  235. package/dist/models/default/django_app/product.js +71 -0
  236. package/dist/models/default/django_app/product.schema.json +277 -0
  237. package/dist/models/default/django_app/productcategory.d.ts +92 -0
  238. package/dist/models/default/django_app/productcategory.js +69 -0
  239. package/dist/models/default/django_app/productcategory.schema.json +70 -0
  240. package/dist/models/default/django_app/rateplan.d.ts +92 -0
  241. package/dist/models/default/django_app/rateplan.js +69 -0
  242. package/dist/models/default/django_app/rateplan.schema.json +70 -0
  243. package/dist/models/default/django_app/restrictedfieldrelatedmodel.d.ts +108 -0
  244. package/dist/models/default/django_app/restrictedfieldrelatedmodel.js +69 -0
  245. package/dist/models/default/django_app/restrictedfieldrelatedmodel.schema.json +87 -0
  246. package/dist/models/default/fileobject.d.ts +4 -0
  247. package/dist/models/default/fileobject.js +9 -0
  248. package/dist/models/default/index.d.ts +2 -0
  249. package/dist/models/default/index.js +2 -0
  250. package/dist/models/index.d.ts +1 -0
  251. package/dist/models/index.js +5 -0
  252. package/dist/react-entry.d.ts +2 -0
  253. package/dist/react-entry.js +2 -0
  254. package/dist/reactiveAdaptor.d.ts +24 -0
  255. package/dist/reactiveAdaptor.js +38 -0
  256. package/dist/reset.d.ts +15 -0
  257. package/dist/reset.js +97 -0
  258. package/dist/setup.d.ts +15 -0
  259. package/dist/setup.js +33 -0
  260. package/dist/syncEngine/cache/cache.d.ts +75 -0
  261. package/dist/syncEngine/cache/cache.js +355 -0
  262. package/dist/syncEngine/metrics/metricOptCalcs.d.ts +79 -0
  263. package/dist/syncEngine/metrics/metricOptCalcs.js +284 -0
  264. package/dist/syncEngine/registries/metricRegistry.d.ts +58 -0
  265. package/dist/syncEngine/registries/metricRegistry.js +171 -0
  266. package/dist/syncEngine/registries/modelStoreRegistry.d.ts +11 -0
  267. package/dist/syncEngine/registries/modelStoreRegistry.js +63 -0
  268. package/dist/syncEngine/registries/querysetStoreGraph.d.ts +41 -0
  269. package/dist/syncEngine/registries/querysetStoreGraph.js +174 -0
  270. package/dist/syncEngine/registries/querysetStoreRegistry.d.ts +72 -0
  271. package/dist/syncEngine/registries/querysetStoreRegistry.js +335 -0
  272. package/dist/syncEngine/stores/metricStore.d.ts +55 -0
  273. package/dist/syncEngine/stores/metricStore.js +222 -0
  274. package/dist/syncEngine/stores/modelStore.d.ts +53 -0
  275. package/dist/syncEngine/stores/modelStore.js +565 -0
  276. package/dist/syncEngine/stores/operation.d.ts +139 -0
  277. package/dist/syncEngine/stores/operation.js +291 -0
  278. package/dist/syncEngine/stores/operationEventHandlers.d.ts +8 -0
  279. package/dist/syncEngine/stores/operationEventHandlers.js +348 -0
  280. package/dist/syncEngine/stores/querysetStore.d.ts +60 -0
  281. package/dist/syncEngine/stores/querysetStore.js +294 -0
  282. package/dist/syncEngine/stores/reactivity.d.ts +3 -0
  283. package/dist/syncEngine/stores/reactivity.js +4 -0
  284. package/dist/syncEngine/stores/utils.d.ts +14 -0
  285. package/dist/syncEngine/stores/utils.js +32 -0
  286. package/dist/syncEngine/sync.d.ts +51 -0
  287. package/dist/syncEngine/sync.js +419 -0
  288. package/dist/testing.d.ts +63 -0
  289. package/dist/testing.js +175 -0
  290. package/dist/vue-entry.d.ts +15 -0
  291. package/dist/vue-entry.js +7 -0
  292. package/package.json +6 -7
  293. package/dist/adaptors/vue/components/layout.tailwind.css +0 -51
  294. /package/{dist → src}/adaptors/vue/components/layout.css +0 -0
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Date parsing utilities for handling Django style date formats
3
+ */
4
+ export class DateParsingHelpers {
5
+ static SUPPORTED_FORMATS: {
6
+ 'iso-8601': null;
7
+ '%Y-%m-%d': string;
8
+ '%Y-%m-%d %H:%M:%S': string;
9
+ '%d/%m/%Y': string;
10
+ '%m/%d/%Y': string;
11
+ '%Y/%m/%d': string;
12
+ '%d-%m-%Y': string;
13
+ '%m-%d-%Y': string;
14
+ '%B %d, %Y': string;
15
+ '%d %B %Y': string;
16
+ };
17
+ /**
18
+ * Parse a date value using Django's format settings
19
+ * @param {string|Date} value - The date value to parse
20
+ * @param {string} fieldName - Name of the field (for schema lookup)
21
+ * @param {Object} schema - The model schema containing format info
22
+ * @param {string} timezone - The backend timezone (defaults to 'UTC')
23
+ * @returns {Date|null} - Parsed Date object or null if invalid
24
+ */
25
+ static parseDate(value: string | Date, fieldName: string, schema: Object, timezone?: string): Date | null;
26
+ /**
27
+ * Serialize a date using the field's configured format
28
+ * @param {Date} date - The date to serialize
29
+ * @param {string} fieldName - Name of the field (for schema lookup)
30
+ * @param {Object} schema - The model schema containing format info
31
+ * @returns {string|null} - Formatted date string or null if invalid
32
+ */
33
+ static serializeDate(date: Date, fieldName: string, schema: Object): string | null;
34
+ }
@@ -0,0 +1,113 @@
1
+ import { format, parse, parseISO } from 'date-fns';
2
+ import { DateTime } from 'luxon';
3
+ /**
4
+ * Date parsing utilities for handling Django style date formats
5
+ */
6
+ export class DateParsingHelpers {
7
+ /**
8
+ * Parse a date value using Django's format settings
9
+ * @param {string|Date} value - The date value to parse
10
+ * @param {string} fieldName - Name of the field (for schema lookup)
11
+ * @param {Object} schema - The model schema containing format info
12
+ * @param {string} timezone - The backend timezone (defaults to 'UTC')
13
+ * @returns {Date|null} - Parsed Date object or null if invalid
14
+ */
15
+ static parseDate(value, fieldName, schema, timezone = 'UTC') {
16
+ if (!value)
17
+ return null;
18
+ // If already a Date object, return as-is (it's already a specific instant in time)
19
+ if (value instanceof Date)
20
+ return value;
21
+ const fieldFormat = schema.properties[fieldName].format;
22
+ if (!["date", "date-time"].includes(fieldFormat)) {
23
+ throw new Error(`Only date and date-time fields can be processed to JS date objects. ${fieldName} has format ${fieldFormat}`);
24
+ }
25
+ // Get field-specific format from schema
26
+ const formatStrings = {
27
+ 'date': schema.date_format,
28
+ 'date-time': schema.datetime_format
29
+ };
30
+ const dateFormat = formatStrings[fieldFormat];
31
+ // Check if format is supported
32
+ if (dateFormat && !this.SUPPORTED_FORMATS.hasOwnProperty(dateFormat)) {
33
+ throw new Error(`Unsupported date format "${dateFormat}" for field ${fieldName}. Supported formats: ${Object.keys(this.SUPPORTED_FORMATS).join(', ')}`);
34
+ }
35
+ try {
36
+ // Handle ISO format (Django's default)
37
+ if (!dateFormat || dateFormat === 'iso-8601') {
38
+ // Parse the string in the server timezone using Luxon
39
+ // This ensures '2022-03-15' is interpreted as midnight in the server TZ, not browser TZ
40
+ const luxonDate = DateTime.fromISO(value, { zone: timezone });
41
+ if (!luxonDate.isValid) {
42
+ console.error(`Failed to parse ISO date "${value}":`, luxonDate.invalidReason);
43
+ return null;
44
+ }
45
+ return luxonDate.toJSDate();
46
+ }
47
+ // Handle supported Django formats
48
+ const dateFnsFormat = this.SUPPORTED_FORMATS[dateFormat];
49
+ // For non-ISO formats, use date-fns but we should still consider timezone
50
+ // For now, parse with date-fns and assume it's in the server timezone
51
+ return parse(value, dateFnsFormat, new Date());
52
+ }
53
+ catch (error) {
54
+ console.error(`Failed to parse date "${value}" with format "${dateFormat}"`, error);
55
+ return null;
56
+ }
57
+ }
58
+ /**
59
+ * Serialize a date using the field's configured format
60
+ * @param {Date} date - The date to serialize
61
+ * @param {string} fieldName - Name of the field (for schema lookup)
62
+ * @param {Object} schema - The model schema containing format info
63
+ * @returns {string|null} - Formatted date string or null if invalid
64
+ */
65
+ static serializeDate(date, fieldName, schema) {
66
+ if (!date || !(date instanceof Date) || isNaN(date.getTime())) {
67
+ return date;
68
+ }
69
+ const fieldFormat = schema.properties[fieldName].format;
70
+ if (!["date", "date-time"].includes(fieldFormat)) {
71
+ throw new Error(`Only date and date-time fields can be processed to JS date objects. ${fieldName} has format ${fieldFormat}`);
72
+ }
73
+ // Get field-specific format from schema
74
+ const formatStrings = {
75
+ 'date': schema.date_format,
76
+ 'date-time': schema.datetime_format
77
+ };
78
+ const dateFormat = formatStrings[fieldFormat];
79
+ // Check if format is supported
80
+ if (dateFormat && !this.SUPPORTED_FORMATS.hasOwnProperty(dateFormat)) {
81
+ throw new Error(`Unsupported date format "${dateFormat}" for field ${fieldName}. Supported formats: ${Object.keys(this.SUPPORTED_FORMATS).join(', ')}`);
82
+ }
83
+ try {
84
+ // Handle ISO format (Django's default)
85
+ if (!dateFormat || dateFormat === 'iso-8601') {
86
+ // For date-only fields, return just the date portion
87
+ return fieldFormat === 'date'
88
+ ? date.toISOString().slice(0, 10)
89
+ : date.toISOString();
90
+ }
91
+ // Handle supported Django formats
92
+ const dateFnsFormat = this.SUPPORTED_FORMATS[dateFormat];
93
+ return format(date, dateFnsFormat);
94
+ }
95
+ catch (error) {
96
+ console.error(`Failed to format date with format "${dateFormat}"`, error);
97
+ return date.toISOString(); // Fallback to ISO format
98
+ }
99
+ }
100
+ }
101
+ // Supported Django strftime formats and their date-fns equivalents
102
+ DateParsingHelpers.SUPPORTED_FORMATS = {
103
+ 'iso-8601': null, // Special case - use parseISO/toISOString
104
+ '%Y-%m-%d': 'yyyy-MM-dd', // 2024-12-31
105
+ '%Y-%m-%d %H:%M:%S': 'yyyy-MM-dd HH:mm:ss', // 2024-12-31 14:30:45
106
+ '%d/%m/%Y': 'dd/MM/yyyy', // 31/12/2024
107
+ '%m/%d/%Y': 'MM/dd/yyyy', // 12/31/2024
108
+ '%Y/%m/%d': 'yyyy/MM/dd', // 2024/12/31
109
+ '%d-%m-%Y': 'dd-MM-yyyy', // 31-12-2024
110
+ '%m-%d-%Y': 'MM-dd-yyyy', // 12-31-2024
111
+ '%B %d, %Y': 'MMMM dd, yyyy', // December 31, 2024
112
+ '%d %B %Y': 'dd MMMM yyyy', // 31 December 2024
113
+ };
@@ -0,0 +1,138 @@
1
+ /**
2
+ * Parses a JSON error response from the backend and returns an instance
3
+ * of the corresponding custom error.
4
+ *
5
+ * @param {IErrorResponse} errorResponse - The error response JSON.
6
+ * @returns {StateZeroError} An instance of a StateZeroError subclass.
7
+ */
8
+ export function parseStateZeroError(errorResponse: IErrorResponse): StateZeroError;
9
+ /**
10
+ * @typedef {Object} IErrorResponse
11
+ * @property {number} status - The HTTP status code.
12
+ * @property {string} type - The error type.
13
+ * @property {*} detail - The error details.
14
+ */
15
+ /**
16
+ * @typedef {Object} IErrorDetail
17
+ * @property {string} message - The error message.
18
+ * @property {string} code - The error code.
19
+ */
20
+ /**
21
+ * Base error class for StateZero errors.
22
+ */
23
+ export class StateZeroError extends Error {
24
+ /**
25
+ * Creates a new StateZeroError.
26
+ *
27
+ * @param {string} message - The error message.
28
+ * @param {string} code - The error code.
29
+ * @param {IErrorDetail|Object|string} detail - The error details.
30
+ * @param {number} status - The HTTP status code.
31
+ */
32
+ constructor(message: string, code: string, detail: IErrorDetail | Object | string, status: number);
33
+ code: string;
34
+ detail: string | Object | IErrorDetail;
35
+ status: number;
36
+ /**
37
+ * Returns a full error message including the detail.
38
+ *
39
+ * @returns {string} The full error message with details
40
+ */
41
+ getFullMessage(): string;
42
+ }
43
+ /**
44
+ * Error class for validation errors.
45
+ */
46
+ export class ValidationError extends StateZeroError {
47
+ /**
48
+ * Creates a new ValidationError.
49
+ *
50
+ * @param {IErrorDetail|Object|string} detail - The error details.
51
+ * @param {number} [status=400] - The HTTP status code.
52
+ */
53
+ constructor(detail: IErrorDetail | Object | string, status?: number);
54
+ }
55
+ /**
56
+ * Error class for "Does Not Exist" errors (renamed from NotFound).
57
+ */
58
+ export class DoesNotExist extends StateZeroError {
59
+ /**
60
+ * Creates a new DoesNotExist error.
61
+ *
62
+ * @param {IErrorDetail|Object|string} [detail="Does not exist"] - The error details.
63
+ * @param {number} [status=404] - The HTTP status code.
64
+ */
65
+ constructor(detail?: IErrorDetail | Object | string, status?: number);
66
+ }
67
+ /**
68
+ * Error class for permission denied errors.
69
+ */
70
+ export class PermissionDenied extends StateZeroError {
71
+ /**
72
+ * Creates a new PermissionDenied error.
73
+ *
74
+ * @param {IErrorDetail|Object|string} [detail="Permission denied"] - The error details.
75
+ * @param {number} [status=403] - The HTTP status code.
76
+ */
77
+ constructor(detail?: IErrorDetail | Object | string, status?: number);
78
+ }
79
+ /**
80
+ * Error class for multiple objects returned errors.
81
+ */
82
+ export class MultipleObjectsReturned extends StateZeroError {
83
+ /**
84
+ * Creates a new MultipleObjectsReturned error.
85
+ *
86
+ * @param {IErrorDetail|Object|string} [detail="Multiple objects returned"] - The error details.
87
+ * @param {number} [status=500] - The HTTP status code.
88
+ */
89
+ constructor(detail?: IErrorDetail | Object | string, status?: number);
90
+ }
91
+ /**
92
+ * Error class for AST validation errors.
93
+ */
94
+ export class ASTValidationError extends StateZeroError {
95
+ /**
96
+ * Creates a new ASTValidationError.
97
+ *
98
+ * @param {IErrorDetail|Object|string} detail - The error details.
99
+ * @param {number} [status=400] - The HTTP status code.
100
+ */
101
+ constructor(detail: IErrorDetail | Object | string, status?: number);
102
+ }
103
+ /**
104
+ * Error class for configuration errors.
105
+ */
106
+ export class ConfigError extends StateZeroError {
107
+ /**
108
+ * Creates a new ConfigError.
109
+ *
110
+ * @param {IErrorDetail|Object|string} detail - The error details.
111
+ * @param {number} [status=500] - The HTTP status code.
112
+ */
113
+ constructor(detail: IErrorDetail | Object | string, status?: number);
114
+ }
115
+ export type IErrorResponse = {
116
+ /**
117
+ * - The HTTP status code.
118
+ */
119
+ status: number;
120
+ /**
121
+ * - The error type.
122
+ */
123
+ type: string;
124
+ /**
125
+ * - The error details.
126
+ */
127
+ detail: any;
128
+ };
129
+ export type IErrorDetail = {
130
+ /**
131
+ * - The error message.
132
+ */
133
+ message: string;
134
+ /**
135
+ * - The error code.
136
+ */
137
+ code: string;
138
+ };
@@ -0,0 +1,195 @@
1
+ import { emitError } from '../../errorHandler.js';
2
+ /**
3
+ * @typedef {Object} IErrorResponse
4
+ * @property {number} status - The HTTP status code.
5
+ * @property {string} type - The error type.
6
+ * @property {*} detail - The error details.
7
+ */
8
+ /**
9
+ * @typedef {Object} IErrorDetail
10
+ * @property {string} message - The error message.
11
+ * @property {string} code - The error code.
12
+ */
13
+ /**
14
+ * Base error class for StateZero errors.
15
+ */
16
+ export class StateZeroError extends Error {
17
+ /**
18
+ * Creates a new StateZeroError.
19
+ *
20
+ * @param {string} message - The error message.
21
+ * @param {string} code - The error code.
22
+ * @param {IErrorDetail|Object|string} detail - The error details.
23
+ * @param {number} status - The HTTP status code.
24
+ */
25
+ constructor(message, code, detail, status) {
26
+ super(message);
27
+ this.name = "StateZeroError";
28
+ this.code = code;
29
+ this.detail = detail;
30
+ this.status = status;
31
+ Object.setPrototypeOf(this, new.target.prototype);
32
+ emitError(this);
33
+ }
34
+ /**
35
+ * Returns a full error message including the detail.
36
+ *
37
+ * @returns {string} The full error message with details
38
+ */
39
+ getFullMessage() {
40
+ if (typeof this.detail === 'string') {
41
+ return `${this.message}: ${this.detail}`;
42
+ }
43
+ else if (this.detail && typeof this.detail === 'object') {
44
+ if (this.detail.message) {
45
+ return `${this.message}: ${this.detail.message}`;
46
+ }
47
+ else {
48
+ try {
49
+ return `${this.message}: ${JSON.stringify(this.detail)}`;
50
+ }
51
+ catch (e) {
52
+ return `${this.message}: [Complex detail object]`;
53
+ }
54
+ }
55
+ }
56
+ return this.message;
57
+ }
58
+ }
59
+ /**
60
+ * Error class for validation errors.
61
+ */
62
+ export class ValidationError extends StateZeroError {
63
+ /**
64
+ * Creates a new ValidationError.
65
+ *
66
+ * @param {IErrorDetail|Object|string} detail - The error details.
67
+ * @param {number} [status=400] - The HTTP status code.
68
+ */
69
+ constructor(detail, status = 400) {
70
+ super("Validation error", "validation_error", detail, status);
71
+ this.name = "ValidationError";
72
+ }
73
+ }
74
+ /**
75
+ * Error class for "Does Not Exist" errors (renamed from NotFound).
76
+ */
77
+ export class DoesNotExist extends StateZeroError {
78
+ /**
79
+ * Creates a new DoesNotExist error.
80
+ *
81
+ * @param {IErrorDetail|Object|string} [detail="Does not exist"] - The error details.
82
+ * @param {number} [status=404] - The HTTP status code.
83
+ */
84
+ constructor(detail = "Does not exist", status = 404) {
85
+ super("DoesNotExist", "does_not_exist", detail, status);
86
+ this.name = "DoesNotExist";
87
+ }
88
+ }
89
+ /**
90
+ * Error class for permission denied errors.
91
+ */
92
+ export class PermissionDenied extends StateZeroError {
93
+ /**
94
+ * Creates a new PermissionDenied error.
95
+ *
96
+ * @param {IErrorDetail|Object|string} [detail="Permission denied"] - The error details.
97
+ * @param {number} [status=403] - The HTTP status code.
98
+ */
99
+ constructor(detail = "Permission denied", status = 403) {
100
+ super("Permission denied", "permission_denied", detail, status);
101
+ this.name = "PermissionDenied";
102
+ }
103
+ }
104
+ /**
105
+ * Error class for multiple objects returned errors.
106
+ */
107
+ export class MultipleObjectsReturned extends StateZeroError {
108
+ /**
109
+ * Creates a new MultipleObjectsReturned error.
110
+ *
111
+ * @param {IErrorDetail|Object|string} [detail="Multiple objects returned"] - The error details.
112
+ * @param {number} [status=500] - The HTTP status code.
113
+ */
114
+ constructor(detail = "Multiple objects returned", status = 500) {
115
+ super("Multiple objects returned", "multiple_objects_returned", detail, status);
116
+ this.name = "MultipleObjectsReturned";
117
+ }
118
+ }
119
+ /**
120
+ * Error class for AST validation errors.
121
+ */
122
+ export class ASTValidationError extends StateZeroError {
123
+ /**
124
+ * Creates a new ASTValidationError.
125
+ *
126
+ * @param {IErrorDetail|Object|string} detail - The error details.
127
+ * @param {number} [status=400] - The HTTP status code.
128
+ */
129
+ constructor(detail, status = 400) {
130
+ super("Query syntax error", "ast_validation_error", detail, status);
131
+ this.name = "ASTValidationError";
132
+ }
133
+ }
134
+ /**
135
+ * Error class for configuration errors.
136
+ */
137
+ export class ConfigError extends StateZeroError {
138
+ /**
139
+ * Creates a new ConfigError.
140
+ *
141
+ * @param {IErrorDetail|Object|string} detail - The error details.
142
+ * @param {number} [status=500] - The HTTP status code.
143
+ */
144
+ constructor(detail, status = 500) {
145
+ super("Configuration error", "config_error", detail, status);
146
+ this.name = "ConfigError";
147
+ }
148
+ }
149
+ /**
150
+ * Parses a JSON error response from the backend and returns an instance
151
+ * of the corresponding custom error.
152
+ *
153
+ * @param {IErrorResponse} errorResponse - The error response JSON.
154
+ * @returns {StateZeroError} An instance of a StateZeroError subclass.
155
+ */
156
+ export function parseStateZeroError(errorResponse) {
157
+ console.log(JSON.stringify(errorResponse));
158
+ const { status, type, detail } = errorResponse;
159
+ // Handle undefined type/status case (like in permission denied)
160
+ if (type === undefined && detail === 'Invalid token.') {
161
+ return new PermissionDenied(detail, 403);
162
+ }
163
+ switch (type) {
164
+ // Direct mappings
165
+ case "ValidationError":
166
+ return new ValidationError(detail, status);
167
+ case "NotFound":
168
+ return new DoesNotExist(detail, status);
169
+ case "MultipleObjectsReturned":
170
+ return new MultipleObjectsReturned(detail, status);
171
+ case "PermissionDenied":
172
+ return new PermissionDenied(detail, status);
173
+ case "ASTValidationError":
174
+ return new ASTValidationError(detail, status);
175
+ case "ConfigError":
176
+ return new ConfigError(detail, status);
177
+ // Django error types that map to our error classes
178
+ case "FieldError":
179
+ return new ValidationError(detail, status);
180
+ case "ValueError":
181
+ return new ValidationError(detail, status);
182
+ default:
183
+ // Fallback to status code based mapping
184
+ if (status === 400) {
185
+ return new ValidationError(detail, status);
186
+ }
187
+ else if (status === 403) {
188
+ return new PermissionDenied(detail, status);
189
+ }
190
+ else if (status === 404) {
191
+ return new DoesNotExist(detail, status);
192
+ }
193
+ return new StateZeroError("Unknown error", "unknown", detail, status);
194
+ }
195
+ }
@@ -0,0 +1,6 @@
1
+ export function F(expression: any): {
2
+ __f_expr: boolean;
3
+ original_expr: string;
4
+ ast: any;
5
+ };
6
+ export function evaluateExpression(expr: any, data: any): any;
@@ -0,0 +1,91 @@
1
+ import { ValidationError } from './errors.js';
2
+ import * as math from 'mathjs';
3
+ // Create a math instance
4
+ const mathInstance = math.create();
5
+ // Define the allowed functions that we want to keep
6
+ const allowedFunctions = ['abs', 'round', 'floor', 'ceil', 'min', 'max'];
7
+ // Define allowed operators
8
+ const ALLOWED_OPERATORS = ['+', '-', '*', '/', '%', '^'];
9
+ export function F(expression) {
10
+ if (typeof expression !== 'string' || !expression) {
11
+ throw new ValidationError('F expression requires a non-empty string');
12
+ }
13
+ try {
14
+ const node = math.parse(expression);
15
+ validateExpression(node);
16
+ return {
17
+ __f_expr: true,
18
+ original_expr: expression,
19
+ ast: node.toJSON()
20
+ };
21
+ }
22
+ catch (err) {
23
+ throw new ValidationError(`Invalid F expression: ${err.message}`);
24
+ }
25
+ }
26
+ function validateExpression(node) {
27
+ if (!node)
28
+ return;
29
+ if (node.type === 'OperatorNode') {
30
+ if (!ALLOWED_OPERATORS.includes(node.op)) {
31
+ throw new ValidationError(`Unsupported operator: ${node.op}`);
32
+ }
33
+ node.args.forEach(validateExpression);
34
+ }
35
+ else if (node.type === 'FunctionNode') {
36
+ if (!allowedFunctions.includes(node.name)) {
37
+ throw new ValidationError(`Function not allowed: ${node.name}`);
38
+ }
39
+ node.args.forEach(validateExpression);
40
+ }
41
+ else if (node.type === 'SymbolNode') {
42
+ if (!/^[a-zA-Z][a-zA-Z0-9_]*$/.test(node.name)) {
43
+ throw new ValidationError(`Invalid field name: ${node.name}`);
44
+ }
45
+ }
46
+ else if (node.type === 'ConstantNode') {
47
+ // Constants are fine
48
+ }
49
+ else if (node.type === 'ParenthesisNode') {
50
+ validateExpression(node.content);
51
+ }
52
+ else if (node.type === 'ConditionalNode') {
53
+ throw new ValidationError('Conditional expressions are not supported in F expressions');
54
+ }
55
+ else if (node.type === 'AssignmentNode') {
56
+ throw new ValidationError('Assignment expressions are not supported in F expressions');
57
+ }
58
+ else if (node.type === 'BlockNode') {
59
+ throw new ValidationError('Block expressions are not supported in F expressions');
60
+ }
61
+ else if (node.type === 'AccessorNode') {
62
+ throw new ValidationError('Accessor expressions are not supported in F expressions');
63
+ }
64
+ else if (node.type === 'IndexNode') {
65
+ throw new ValidationError('Index expressions are not supported in F expressions');
66
+ }
67
+ else if (node.type === 'RangeNode') {
68
+ throw new ValidationError('Range expressions are not supported in F expressions');
69
+ }
70
+ else if (node.type === 'ArrayNode') {
71
+ throw new ValidationError('Array expressions are not supported in F expressions');
72
+ }
73
+ else if (node.type === 'ObjectNode') {
74
+ throw new ValidationError('Object expressions are not supported in F expressions');
75
+ }
76
+ else {
77
+ throw new ValidationError(`Unsupported node type: ${node.type}`);
78
+ }
79
+ }
80
+ export function evaluateExpression(expr, data) {
81
+ if (!expr || !expr.__f_expr) {
82
+ return expr;
83
+ }
84
+ try {
85
+ return math.evaluate(expr.original_expr, data);
86
+ }
87
+ catch (err) {
88
+ console.warn(`Error evaluating F expression: ${err.message}`);
89
+ return null;
90
+ }
91
+ }
@@ -0,0 +1,62 @@
1
+ /**
2
+ * FileObject - A file wrapper that handles uploads to StateZero backend
3
+ */
4
+ export class FileObject {
5
+ static configKey: string;
6
+ static MIN_CHUNK_SIZE: number;
7
+ constructor(file: any, options?: {});
8
+ name: any;
9
+ size: any;
10
+ type: any;
11
+ lastModified: number | null;
12
+ uploaded: boolean;
13
+ uploading: boolean;
14
+ uploadResult: any;
15
+ uploadError: any;
16
+ fileData: any;
17
+ uploadType: string | null;
18
+ uploadId: any;
19
+ totalChunks: number;
20
+ completedChunks: number;
21
+ chunkSize: any;
22
+ maxConcurrency: any;
23
+ uploadPromise: any;
24
+ get isStoredFile(): any;
25
+ get status(): "failed" | "uploading" | "uploaded" | "pending";
26
+ get filePath(): any;
27
+ get fileUrl(): any;
28
+ _initializeAndStartUpload(file: any, options: any): any;
29
+ /**
30
+ * Fast upload using S3 presigned URLs with multipart support
31
+ */
32
+ _fastUpload(file: any, options?: {}): any;
33
+ /**
34
+ * Handle single file upload
35
+ */
36
+ _singleUpload(file: any, uploadData: any, options: any): Promise<any>;
37
+ /**
38
+ * Handle multipart upload with concurrency using p-queue
39
+ */
40
+ _multipartUpload(file: any, uploadData: any, options: any): Promise<any>;
41
+ /**
42
+ * Create file chunks for multipart upload
43
+ */
44
+ _createFileChunks(file: any): any[];
45
+ /**
46
+ * Complete the upload (both single and multipart)
47
+ */
48
+ _completeUpload(filePath: any, originalName: any, uploadId?: null, parts?: null): Promise<any>;
49
+ /**
50
+ * Direct upload to Django backend (original method)
51
+ */
52
+ _directUpload(options?: {}): Promise<any>;
53
+ /**
54
+ * Reads the file content into an ArrayBuffer (for direct uploads only)
55
+ */
56
+ _readFileData(file: any): Promise<void>;
57
+ /**
58
+ * Gets the file data as a Blob (for direct uploads only)
59
+ */
60
+ getBlob(): Blob;
61
+ waitForUpload(): Promise<any>;
62
+ }