@statezero/core 0.2.38 → 0.2.39

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 +322 -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 +46 -0
  287. package/dist/syncEngine/sync.js +389 -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,284 @@
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
+ };
6
+ var _a, _MetricStrategyFactory_customStrategies, _MetricStrategyFactory_defaultStrategies, _MetricStrategyFactory_generateStrategyKey;
7
+ import { Status, Type } from '../stores/operation.js';
8
+ import { isNil } from 'lodash-es';
9
+ /**
10
+ * Base class for metric calculation strategies with operations
11
+ */
12
+ export class MetricCalculationStrategy {
13
+ /**
14
+ * Calculate metric based on ground truth and operations
15
+ */
16
+ calculateWithOperations(baseValue, operations, field, ModelClass) {
17
+ // Initialize the current value based on the metric type
18
+ let currentValue = baseValue === null ? this.getInitialValue() : baseValue;
19
+ // Process operations sequentially
20
+ for (const op of operations) {
21
+ // Skip rejected operations
22
+ if (op.status === Status.REJECTED)
23
+ continue;
24
+ // Process each instance in the operation
25
+ op.frozenInstances.forEach((originalData, index) => {
26
+ let pk = originalData[ModelClass.primaryKeyField];
27
+ // Get the updated data for this instance (for UPDATE operations)
28
+ const updatedData = op.instances[index] || null;
29
+ // Create operation data object for the reducer
30
+ const singleOp = {
31
+ originalData, // Pre-operation state
32
+ updatedData, // Post-operation state (for updates)
33
+ type: op.type,
34
+ status: op.status
35
+ };
36
+ // Apply this single operation using the strategy-specific reducer
37
+ currentValue = this.reduceOperation(currentValue, singleOp, field);
38
+ });
39
+ }
40
+ return currentValue;
41
+ }
42
+ /**
43
+ * Get initial value for the metric type
44
+ * Override in subclasses if needed
45
+ */
46
+ getInitialValue() {
47
+ return 0; // Default for count and sum
48
+ }
49
+ /**
50
+ * Process a single operation - implement in subclasses
51
+ */
52
+ reduceOperation(currentValue, operation, field) {
53
+ throw new Error('reduceOperation must be implemented by subclass');
54
+ }
55
+ /**
56
+ * Safely get a numeric value from an object
57
+ */
58
+ safeGetValue(obj, field) {
59
+ if (!obj || !field)
60
+ return 0;
61
+ const value = obj[field];
62
+ if (isNil(value))
63
+ return 0;
64
+ const numValue = parseFloat(value);
65
+ return isNaN(numValue) ? 0 : numValue;
66
+ }
67
+ }
68
+ /**
69
+ * Count strategy implementation
70
+ */
71
+ export class CountStrategy extends MetricCalculationStrategy {
72
+ reduceOperation(currentCount, operation, field) {
73
+ // Skip rejected operations
74
+ if (operation.status === Status.REJECTED) {
75
+ return currentCount;
76
+ }
77
+ const { type } = operation;
78
+ // Handle operation types
79
+ if (type === Type.CREATE) {
80
+ return currentCount + 1;
81
+ }
82
+ else if ([Type.DELETE, Type.DELETE_INSTANCE].includes(type)) {
83
+ return Math.max(0, currentCount - 1);
84
+ }
85
+ // Other operation types don't affect the count
86
+ return currentCount;
87
+ }
88
+ }
89
+ /**
90
+ * Sum strategy implementation
91
+ */
92
+ export class SumStrategy extends MetricCalculationStrategy {
93
+ reduceOperation(currentSum, operation, field) {
94
+ // Skip rejected operations
95
+ if (operation.status === Status.REJECTED) {
96
+ return currentSum;
97
+ }
98
+ if (!field) {
99
+ throw new Error('SumStrategy requires a field parameter');
100
+ }
101
+ const { type, originalData, updatedData } = operation;
102
+ switch (type) {
103
+ case Type.CREATE:
104
+ // For CREATE, add the value to the sum
105
+ return currentSum + this.safeGetValue(originalData, field);
106
+ case Type.CHECKPOINT:
107
+ case Type.UPDATE:
108
+ // For UPDATE, subtract old value and add new value
109
+ if (updatedData) {
110
+ const oldValue = this.safeGetValue(originalData, field);
111
+ const newValue = this.safeGetValue(updatedData, field);
112
+ return currentSum - oldValue + newValue;
113
+ }
114
+ return currentSum;
115
+ case Type.DELETE:
116
+ case Type.DELETE_INSTANCE:
117
+ // For DELETE, subtract the value from the sum
118
+ return currentSum - this.safeGetValue(originalData, field);
119
+ default:
120
+ return currentSum;
121
+ }
122
+ }
123
+ }
124
+ /**
125
+ * Min strategy implementation
126
+ */
127
+ export class MinStrategy extends MetricCalculationStrategy {
128
+ getInitialValue() {
129
+ return Infinity;
130
+ }
131
+ reduceOperation(currentMin, operation, field) {
132
+ // Skip rejected operations
133
+ if (operation.status === Status.REJECTED) {
134
+ return currentMin;
135
+ }
136
+ if (!field) {
137
+ throw new Error('MinStrategy requires a field parameter');
138
+ }
139
+ const { type, originalData, updatedData } = operation;
140
+ if (type === Type.CREATE) {
141
+ // For CREATE, check if the new value is smaller than current min
142
+ const value = this.safeGetValue(originalData, field);
143
+ return Math.min(currentMin, value);
144
+ }
145
+ else if ((type === Type.UPDATE || type.CHECKPOINT) && updatedData) {
146
+ // For UPDATE, first check if we're updating the minimum value
147
+ const oldValue = this.safeGetValue(originalData, field);
148
+ const newValue = this.safeGetValue(updatedData, field);
149
+ if (oldValue === currentMin) {
150
+ // We're updating the current minimum, need to find the new minimum
151
+ if (newValue <= oldValue) {
152
+ // Simple case: new value is still the minimum
153
+ return newValue;
154
+ }
155
+ else {
156
+ // Harder case: need to recalculate minimum
157
+ // For now, conservatively use the new value
158
+ return newValue;
159
+ }
160
+ }
161
+ else if (newValue < currentMin) {
162
+ // The updated value is a new minimum
163
+ return newValue;
164
+ }
165
+ }
166
+ // For other cases, maintain current min
167
+ return currentMin;
168
+ }
169
+ }
170
+ /**
171
+ * Max strategy implementation
172
+ */
173
+ export class MaxStrategy extends MetricCalculationStrategy {
174
+ getInitialValue() {
175
+ return -Infinity;
176
+ }
177
+ reduceOperation(currentMax, operation, field) {
178
+ // Skip rejected operations
179
+ if (operation.status === Status.REJECTED) {
180
+ return currentMax;
181
+ }
182
+ if (!field) {
183
+ throw new Error('MaxStrategy requires a field parameter');
184
+ }
185
+ const { type, originalData, updatedData } = operation;
186
+ if (type === Type.CREATE) {
187
+ // For CREATE, check if the new value is larger than current max
188
+ const value = this.safeGetValue(originalData, field);
189
+ return Math.max(currentMax, value);
190
+ }
191
+ else if ((type === Type.UPDATE || type === Type.CHECKPOINT) && updatedData) {
192
+ // For UPDATE, first check if we're updating the maximum value
193
+ const oldValue = this.safeGetValue(originalData, field);
194
+ const newValue = this.safeGetValue(updatedData, field);
195
+ if (oldValue === currentMax) {
196
+ // We're updating the current maximum, need to find the new maximum
197
+ if (newValue >= oldValue) {
198
+ // Simple case: new value is still the maximum
199
+ return newValue;
200
+ }
201
+ else {
202
+ // Harder case: need to recalculate maximum
203
+ // For now, conservatively use the new value
204
+ return newValue;
205
+ }
206
+ }
207
+ else if (newValue > currentMax) {
208
+ // The updated value is a new maximum
209
+ return newValue;
210
+ }
211
+ }
212
+ // For other cases, maintain current max
213
+ return currentMax;
214
+ }
215
+ }
216
+ /**
217
+ * Factory class for creating the appropriate strategy
218
+ */
219
+ export class MetricStrategyFactory {
220
+ /**
221
+ * Clear all custom strategy overrides
222
+ */
223
+ static clearCustomStrategies() {
224
+ __classPrivateFieldGet(this, _a, "f", _MetricStrategyFactory_customStrategies).clear();
225
+ }
226
+ /**
227
+ * Override a strategy for a specific metric type and model class
228
+ * @param {string} metricType - The type of metric (count, sum, min, max)
229
+ * @param {Function|null} ModelClass - The model class or null for a generic override
230
+ * @param {MetricCalculationStrategy} strategy - The strategy to use
231
+ */
232
+ static overrideStrategy(metricType, ModelClass, strategy) {
233
+ if (!metricType || !strategy) {
234
+ throw new Error('overrideStrategy requires metricType and strategy');
235
+ }
236
+ if (!(strategy instanceof MetricCalculationStrategy)) {
237
+ throw new Error('strategy must be an instance of MetricCalculationStrategy');
238
+ }
239
+ let key;
240
+ if (ModelClass) {
241
+ // Model-specific override
242
+ key = __classPrivateFieldGet(this, _a, "m", _MetricStrategyFactory_generateStrategyKey).call(this, metricType, ModelClass);
243
+ }
244
+ else {
245
+ // Generic override for all models
246
+ key = `${metricType}::*::*`;
247
+ }
248
+ __classPrivateFieldGet(this, _a, "f", _MetricStrategyFactory_customStrategies).set(key, strategy);
249
+ }
250
+ /**
251
+ * Get the appropriate strategy for a model class and metric type
252
+ * @param {string} metricType - The type of metric (count, sum, min, max)
253
+ * @param {Function} ModelClass - The model class
254
+ * @returns {MetricCalculationStrategy} The appropriate strategy
255
+ */
256
+ static getStrategy(metricType, ModelClass) {
257
+ const normalizedMetricType = metricType.toLowerCase();
258
+ // Check for model-specific override first
259
+ const specificKey = __classPrivateFieldGet(this, _a, "m", _MetricStrategyFactory_generateStrategyKey).call(this, normalizedMetricType, ModelClass);
260
+ if (__classPrivateFieldGet(this, _a, "f", _MetricStrategyFactory_customStrategies).has(specificKey)) {
261
+ return __classPrivateFieldGet(this, _a, "f", _MetricStrategyFactory_customStrategies).get(specificKey);
262
+ }
263
+ // Check for metric-only override (works across all models)
264
+ const genericKey = `${normalizedMetricType}::*::*`;
265
+ if (__classPrivateFieldGet(this, _a, "f", _MetricStrategyFactory_customStrategies).has(genericKey)) {
266
+ return __classPrivateFieldGet(this, _a, "f", _MetricStrategyFactory_customStrategies).get(genericKey);
267
+ }
268
+ // Otherwise, return the default strategy based on the metric type
269
+ const strategyCreator = __classPrivateFieldGet(this, _a, "f", _MetricStrategyFactory_defaultStrategies).get(normalizedMetricType) || __classPrivateFieldGet(this, _a, "f", _MetricStrategyFactory_defaultStrategies).get('count');
270
+ return strategyCreator();
271
+ }
272
+ }
273
+ _a = MetricStrategyFactory, _MetricStrategyFactory_generateStrategyKey = function _MetricStrategyFactory_generateStrategyKey(metricType, ModelClass) {
274
+ return `${metricType}::${ModelClass.configKey}::${ModelClass.modelName}`;
275
+ };
276
+ // Collection of custom strategy overrides
277
+ _MetricStrategyFactory_customStrategies = { value: new Map() };
278
+ // Default strategy map
279
+ _MetricStrategyFactory_defaultStrategies = { value: new Map([
280
+ ['count', () => new CountStrategy()],
281
+ ['sum', () => new SumStrategy()],
282
+ ['min', () => new MinStrategy()],
283
+ ['max', () => new MaxStrategy()]
284
+ ]) };
@@ -0,0 +1,58 @@
1
+ /**
2
+ * LiveMetric, a simple wrapper that always returns the latest metric value
3
+ * using a getter for the value property
4
+ */
5
+ export class LiveMetric {
6
+ constructor(queryset: any, metricType: any, field?: null);
7
+ queryset: any;
8
+ metricType: any;
9
+ field: any;
10
+ get lqs(): import("./querysetStoreRegistry.js").LiveQueryset;
11
+ /**
12
+ * Refresh the metric data from the database
13
+ * Delegates to the underlying store's sync method
14
+ */
15
+ refreshFromDb(): any;
16
+ /**
17
+ * Getter that always returns the current value from the store
18
+ */
19
+ get value(): any;
20
+ }
21
+ /**
22
+ * Registry to manage metric stores
23
+ */
24
+ export class MetricRegistry {
25
+ _stores: Map<any, any>;
26
+ syncManager: any;
27
+ clear(): void;
28
+ setSyncManager(syncManager: any): void;
29
+ /**
30
+ * Get all metric stores that match a specific queryset
31
+ * @param {Queryset} queryset - The queryset to match
32
+ * @returns {Array} Array of metric stores
33
+ */
34
+ getAllStoresForQueryset(queryset: Queryset): any[];
35
+ _makeKey(metricType: any, queryset: any, field?: null): string;
36
+ /**
37
+ * Get a metric store for a specific queryset and metric type
38
+ */
39
+ getStore(metricType: any, queryset: any, field?: null): any;
40
+ /**
41
+ * Get a metric value for a specific queryset
42
+ */
43
+ getEntity(metricType: any, queryset: any, field?: null): Object | null;
44
+ /**
45
+ * Set metric ground truth value
46
+ */
47
+ setEntity(metricType: any, queryset: any, field: any, value: any): any;
48
+ /**
49
+ * Sync a specific metric with the server
50
+ */
51
+ syncMetric(metricType: any, queryset: any, field?: null): any;
52
+ /**
53
+ * Get the queryset for a specific key
54
+ * Useful for debugging or auditing
55
+ */
56
+ getQuerysetForKey(key: any): any;
57
+ }
58
+ export const metricRegistry: MetricRegistry;
@@ -0,0 +1,171 @@
1
+ import { MetricStore } from '../stores/metricStore.js';
2
+ import { isNil, isEmpty } from 'lodash-es';
3
+ import { querysetStoreRegistry } from './querysetStoreRegistry.js';
4
+ import { QueryExecutor } from '../../flavours/django/queryExecutor.js';
5
+ import { wrapReactiveMetric } from '../../reactiveAdaptor.js';
6
+ import hash from 'object-hash';
7
+ /**
8
+ * LiveMetric, a simple wrapper that always returns the latest metric value
9
+ * using a getter for the value property
10
+ */
11
+ export class LiveMetric {
12
+ constructor(queryset, metricType, field = null) {
13
+ this.queryset = queryset;
14
+ this.metricType = metricType;
15
+ this.field = field;
16
+ }
17
+ get lqs() {
18
+ return querysetStoreRegistry.getEntity(this.queryset);
19
+ }
20
+ /**
21
+ * Refresh the metric data from the database
22
+ * Delegates to the underlying store's sync method
23
+ */
24
+ refreshFromDb() {
25
+ const store = metricRegistry.getStore(this.metricType, this.queryset, this.field);
26
+ return store.sync(true);
27
+ }
28
+ /**
29
+ * Getter that always returns the current value from the store
30
+ */
31
+ get value() {
32
+ // Get the latest store from the registry
33
+ const store = metricRegistry.getStore(this.metricType, this.queryset, this.field);
34
+ if (!store) {
35
+ return null;
36
+ }
37
+ // Render the current value
38
+ return store.render();
39
+ }
40
+ }
41
+ /**
42
+ * Registry to manage metric stores
43
+ */
44
+ export class MetricRegistry {
45
+ constructor() {
46
+ // Store both the store and a reference to the queryset as a tuple
47
+ this._stores = new Map();
48
+ this.syncManager = null;
49
+ }
50
+ clear() {
51
+ for (const entry of this._stores.values()) {
52
+ this.syncManager.unfollowModel(this, entry.store.modelClass);
53
+ }
54
+ this._stores = new Map();
55
+ }
56
+ setSyncManager(syncManager) {
57
+ this.syncManager = syncManager;
58
+ }
59
+ /**
60
+ * Get all metric stores that match a specific queryset
61
+ * @param {Queryset} queryset - The queryset to match
62
+ * @returns {Array} Array of metric stores
63
+ */
64
+ getAllStoresForQueryset(queryset) {
65
+ if (isNil(queryset) || isNil(queryset.ModelClass)) {
66
+ return [];
67
+ }
68
+ const stores = [];
69
+ const modelClass = queryset.ModelClass;
70
+ for (const [key, entry] of this._stores.entries()) {
71
+ const store = entry.store;
72
+ // First check if model class matches
73
+ if (store.modelClass !== modelClass) {
74
+ continue;
75
+ }
76
+ if (store.queryset.semanticKey != queryset.semanticKey) {
77
+ continue;
78
+ }
79
+ stores.push(store);
80
+ }
81
+ return stores;
82
+ }
83
+ _makeKey(metricType, queryset, field = null) {
84
+ const modelClass = queryset.ModelClass;
85
+ const ast = queryset.build();
86
+ return `${metricType}::${modelClass.configKey}::${modelClass.modelName}::${field || 'null'}::${hash(ast)}`;
87
+ }
88
+ /**
89
+ * Get a metric store for a specific queryset and metric type
90
+ */
91
+ getStore(metricType, queryset, field = null) {
92
+ if (isNil(metricType) || isNil(queryset) || isNil(queryset.ModelClass)) {
93
+ return null;
94
+ }
95
+ const modelClass = queryset.ModelClass;
96
+ const ast = queryset.build();
97
+ const key = this._makeKey(metricType, queryset, field);
98
+ if (!this._stores.has(key)) {
99
+ // Create fetch function for this metric
100
+ const fetchMetricFn = async ({ metricType, modelClass, field, ast }) => {
101
+ const qs = queryset.clone();
102
+ return await QueryExecutor.executeAgg(qs, metricType, { field });
103
+ };
104
+ // Create new store
105
+ const store = new MetricStore(metricType, modelClass, queryset, field, ast, fetchMetricFn);
106
+ // Store both the store and a reference to the queryset
107
+ this._stores.set(key, {
108
+ store,
109
+ queryset // This keeps the queryset alive
110
+ });
111
+ this.syncManager.followModel(this, store.modelClass);
112
+ }
113
+ return this._stores.get(key).store;
114
+ }
115
+ /**
116
+ * Get a metric value for a specific queryset
117
+ */
118
+ getEntity(metricType, queryset, field = null) {
119
+ // defensive checks
120
+ if (isNil(metricType) || isNil(queryset) || isNil(queryset.ModelClass)) {
121
+ return null;
122
+ }
123
+ // Get the store (creates if doesn't exist)
124
+ const store = this.getStore(metricType, queryset, field);
125
+ // Create a LiveMetric that will always get the latest store and value
126
+ const liveMetric = new LiveMetric(queryset, metricType, field);
127
+ // If we're in a reactive environment, wrap the metric
128
+ return wrapReactiveMetric(liveMetric);
129
+ }
130
+ /**
131
+ * Set metric ground truth value
132
+ */
133
+ setEntity(metricType, queryset, field, value) {
134
+ // defensive checks
135
+ if (isNil(metricType) || isNil(queryset) || isNil(queryset.ModelClass)) {
136
+ return null;
137
+ }
138
+ const store = this.getStore(metricType, queryset, field);
139
+ if (!store) {
140
+ return null;
141
+ }
142
+ // check if the store already has a ground truth or operations
143
+ if (!isNil(store.groundTruthValue) || !isEmpty(store.operations)) {
144
+ store.reset();
145
+ }
146
+ store.setGroundTruth(value);
147
+ return value;
148
+ }
149
+ /**
150
+ * Sync a specific metric with the server
151
+ */
152
+ syncMetric(metricType, queryset, field = null) {
153
+ const store = this.getStore(metricType, queryset, field);
154
+ if (store) {
155
+ return store.sync();
156
+ }
157
+ return null;
158
+ }
159
+ /**
160
+ * Get the queryset for a specific key
161
+ * Useful for debugging or auditing
162
+ */
163
+ getQuerysetForKey(key) {
164
+ if (this._stores.has(key)) {
165
+ return this._stores.get(key).queryset;
166
+ }
167
+ return null;
168
+ }
169
+ }
170
+ // Export singleton instance
171
+ export const metricRegistry = new MetricRegistry();
@@ -0,0 +1,11 @@
1
+ export class ModelStoreRegistry {
2
+ _stores: Map<any, any>;
3
+ syncManager: () => void;
4
+ clear(): void;
5
+ setSyncManager(syncManager: any): void;
6
+ getStore(modelClass: any): any;
7
+ getEntity(modelClass: any, pk: any): any;
8
+ setEntity(modelClass: any, pk: any, data: any): any;
9
+ setEntities(modelClass: any, entities: any): void;
10
+ }
11
+ export const modelStoreRegistry: ModelStoreRegistry;
@@ -0,0 +1,63 @@
1
+ import { ModelStore } from '../stores/modelStore.js';
2
+ import { isNil } from 'lodash-es';
3
+ export class ModelStoreRegistry {
4
+ constructor() {
5
+ this._stores = new Map();
6
+ this.syncManager = () => { console.warn("SyncManager not set for ModelStoreRegistry"); };
7
+ }
8
+ clear() {
9
+ for (const modelClass of this._stores.keys()) {
10
+ this.syncManager.unfollowModel(this, modelClass);
11
+ }
12
+ this._stores = new Map();
13
+ }
14
+ setSyncManager(syncManager) {
15
+ this.syncManager = syncManager;
16
+ }
17
+ getStore(modelClass) {
18
+ if (!this._stores.has(modelClass)) {
19
+ // Create a new ModelStore on demand
20
+ const fetchModels = async ({ pks, modelClass }) => {
21
+ return await modelClass.objects.filter({
22
+ [`${modelClass.primaryKeyField}__in`]: pks
23
+ }).fetch().serialize();
24
+ };
25
+ this._stores.set(modelClass, new ModelStore(modelClass, fetchModels, null, null));
26
+ this.syncManager.followModel(this, modelClass);
27
+ }
28
+ return this._stores.get(modelClass);
29
+ }
30
+ // Get a single entity from the store
31
+ getEntity(modelClass, pk) {
32
+ // defensive checks for this nested func
33
+ if (isNil(modelClass) || isNil(pk))
34
+ return;
35
+ if (pk[modelClass.primaryKeyField])
36
+ throw new Error("getEntity should be called with a pk not an object");
37
+ // logic
38
+ const store = this.getStore(modelClass);
39
+ const renderedData = store.render([pk]);
40
+ return renderedData[0] || null;
41
+ }
42
+ // Add or update an entity ground truth in the store, not for operations!
43
+ setEntity(modelClass, pk, data) {
44
+ // defensive checks for this nested func
45
+ if (isNil(modelClass) || isNil(pk))
46
+ return;
47
+ if (pk[modelClass.primaryKeyField])
48
+ throw new Error("getEntity should be called with a pk not an object");
49
+ // logic
50
+ const store = this.getStore(modelClass);
51
+ store.addToGroundTruth([data]);
52
+ return data;
53
+ }
54
+ // Batch add or update entities in the store ground truth
55
+ setEntities(modelClass, entities) {
56
+ if (isNil(modelClass) || !entities?.length)
57
+ return;
58
+ const store = this.getStore(modelClass);
59
+ store.addToGroundTruth(entities);
60
+ }
61
+ }
62
+ // Export singleton instance
63
+ export const modelStoreRegistry = new ModelStoreRegistry();
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Simple graph for tracking queryset store ancestry
3
+ */
4
+ export class QuerysetStoreGraph {
5
+ graph: any;
6
+ processedQuerysets: Set<any>;
7
+ /**
8
+ * Add a queryset and its parent relationship to the graph
9
+ */
10
+ addQueryset(queryset: any): void;
11
+ /**
12
+ * Find the root (topmost ancestor) of a queryset chain within a subset.
13
+ * Traverses up the graph but only considers nodes that are in the subset.
14
+ * Uses the graph to "jump" through nodes not in subset to find connections.
15
+ *
16
+ * @param {Object} queryset - The queryset to analyze
17
+ * @param {Set|null} subset - Set of semanticKeys to consider. If null, considers all nodes in graph.
18
+ * @returns {Object} { isRoot: boolean, root: semanticKey|null }
19
+ */
20
+ findRoot(queryset: Object, subset?: Set<any> | null): Object;
21
+ /**
22
+ * Check if parent queryset is a valid data source for creating an edge.
23
+ * Parent must have data that is a superset of what child needs.
24
+ * Child with offset must sync independently (can't derive window from parent).
25
+ *
26
+ * @param {Object} parentOpts - Parent's serializerOptions
27
+ * @param {Object} childOpts - Child's serializerOptions
28
+ * @param {Array|undefined} parentOrderBy - Parent's ordering
29
+ * @param {Array|undefined} childOrderBy - Child's ordering
30
+ * @returns {boolean} - True if parent is valid for edge creation
31
+ */
32
+ _isValidParentForEdge(parentOpts: Object | undefined, childOpts: Object | undefined, parentOrderBy: any[] | undefined, childOrderBy: any[] | undefined): boolean;
33
+ /**
34
+ * Check if two orderings are equivalent.
35
+ * @param {Array|undefined} orderBy1
36
+ * @param {Array|undefined} orderBy2
37
+ * @returns {boolean}
38
+ */
39
+ _orderingsMatch(orderBy1: any[] | undefined, orderBy2: any[] | undefined): boolean;
40
+ clear(): void;
41
+ }