@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,736 @@
1
+ import { MultipleObjectsReturned, DoesNotExist, parseStateZeroError, } from "./errors.js";
2
+ import { Model } from "./model.js";
3
+ import { ModelSerializer, relationshipFieldSerializer, dateFieldSerializer } from "./serializers.js";
4
+ import axios from "axios";
5
+ import { QueryExecutor } from "./queryExecutor.js";
6
+ import { v7 } from "uuid";
7
+ import hash from "object-hash";
8
+ import rfdc from "rfdc";
9
+ const clone = rfdc();
10
+ /**
11
+ * A QuerySet provides a fluent API for constructing and executing queries.
12
+ *
13
+ * @template T
14
+ */
15
+ export class QuerySet {
16
+ /**
17
+ * Creates a new QuerySet.
18
+ *
19
+ * @param {ModelConstructor} ModelClass - The model constructor.
20
+ * @param {Object} [config={}] - The configuration for the QuerySet.
21
+ * @param {QueryNode[]} [config.nodes] - Array of query nodes.
22
+ * @param {Array<{ field: string, direction: 'asc'|'desc' }>} [config.orderBy] - Ordering configuration.
23
+ * @param {Set<string>} [config.fields] - Set of fields to retrieve.
24
+ * @param {Aggregation[]} [config.aggregations] - Aggregation operations.
25
+ * @param {string} [config.initialQueryset] - The initial queryset identifier.
26
+ * @param {SerializerOptions} [config.serializerOptions] - Serializer options.
27
+ * @param {boolean} [config.materialized] - Whether the queryset is materialized.
28
+ */
29
+ constructor(ModelClass, config = {}, parent = null) {
30
+ this.ModelClass = ModelClass;
31
+ this.nodes = config.nodes || [];
32
+ this._orderBy = config.orderBy;
33
+ this._fields = config.fields || new Set();
34
+ this._aggregations = config.aggregations || [];
35
+ this._initialQueryset = config.initialQueryset;
36
+ this._serializerOptions = config.serializerOptions || {};
37
+ this._materialized = config.materialized || false;
38
+ this._optimisticOnly = config.optimisticOnly || false;
39
+ this._remoteOnly = config.remoteOnly || false;
40
+ this.__uuid = v7();
41
+ this.__parent = parent;
42
+ this.__reactivityId = parent?.__reactivityId;
43
+ // Initialize the serializer for this model
44
+ this._serializer = new ModelSerializer(this.ModelClass);
45
+ }
46
+ /**
47
+ * Clones this QuerySet, creating a new instance with the same configuration.
48
+ *
49
+ * @returns {QuerySet} A new QuerySet instance.
50
+ */
51
+ clone() {
52
+ return new QuerySet(this.ModelClass, {
53
+ nodes: [...this.nodes],
54
+ orderBy: this._orderBy ? [...this._orderBy] : undefined,
55
+ fields: new Set(this._fields),
56
+ aggregations: [...this._aggregations],
57
+ initialQueryset: this._initialQueryset,
58
+ serializerOptions: { ...this._serializerOptions },
59
+ materialized: this._materialized,
60
+ optimisticOnly: this._optimisticOnly,
61
+ remoteOnly: this._remoteOnly,
62
+ }, this);
63
+ }
64
+ get semanticKey() {
65
+ return JSON.stringify({
66
+ ModelClass: {
67
+ configKey: this.ModelClass.configKey,
68
+ modelName: this.ModelClass.modelName,
69
+ },
70
+ ast: this.build(),
71
+ });
72
+ }
73
+ get key() {
74
+ return this.__uuid;
75
+ }
76
+ /**
77
+ * Ensures the QuerySet is still lazy (not materialized).
78
+ *
79
+ * @private
80
+ * @throws {Error} If the QuerySet is already materialized.
81
+ */
82
+ ensureNotMaterialized() {
83
+ if (this._materialized) {
84
+ throw new Error("Cannot chain further operations on a materialized QuerySet.");
85
+ }
86
+ }
87
+ /**
88
+ * Returns the model constructor for this QuerySet.
89
+ *
90
+ * @returns {ModelConstructor} The model constructor.
91
+ */
92
+ get modelClass() {
93
+ return this.ModelClass;
94
+ }
95
+ /**
96
+ * Sets serializer options for the QuerySet.
97
+ *
98
+ * @param {SerializerOptions} options - The serializer options to set.
99
+ * @returns {QuerySet} This QuerySet instance for chaining.
100
+ */
101
+ setSerializerOptions(options) {
102
+ this._serializerOptions = { ...this._serializerOptions, ...options };
103
+ return this;
104
+ }
105
+ /**
106
+ * Serializes filter conditions using the model serializer.
107
+ *
108
+ * @private
109
+ * @param {Object} conditions - The filter conditions to serialize.
110
+ * @returns {Object} The serialized conditions.
111
+ */
112
+ _serializeConditions(conditions) {
113
+ if (!conditions || typeof conditions !== "object") {
114
+ return conditions;
115
+ }
116
+ const serializedConditions = {};
117
+ for (const [fieldPath, value] of Object.entries(conditions)) {
118
+ serializedConditions[fieldPath] = this._serializeValue(value);
119
+ }
120
+ return serializedConditions;
121
+ }
122
+ /**
123
+ * Serializes a value based on its type (handles arrays, Model instances, Dates, primitives)
124
+ *
125
+ * @private
126
+ * @param {any} value - The value to serialize
127
+ * @returns {any} The serialized value
128
+ */
129
+ _serializeValue(value) {
130
+ // Handle arrays (for __in lookups)
131
+ if (Array.isArray(value)) {
132
+ return value.map(item => this._serializeValue(item));
133
+ }
134
+ // Handle Model instances (objects with pk, serialize method, and constructor with configKey/modelName)
135
+ // Note: Model instances are objects, not classes (typeof instance === 'object')
136
+ if (value &&
137
+ typeof value === 'object' &&
138
+ !(value instanceof Date) && // Exclude Date objects
139
+ 'pk' in value &&
140
+ 'serialize' in value &&
141
+ typeof value.serialize === 'function' &&
142
+ value.constructor &&
143
+ 'configKey' in value.constructor &&
144
+ 'modelName' in value.constructor) {
145
+ return relationshipFieldSerializer.toInternal(value);
146
+ }
147
+ // Handle Date objects
148
+ // Without field context, we default to datetime format (ISO string with time)
149
+ // Unless it's exactly midnight in UTC, which likely indicates a date-only field
150
+ if (value instanceof Date) {
151
+ // Check if it's midnight UTC (likely a date-only value)
152
+ const hours = value.getUTCHours();
153
+ const minutes = value.getUTCMinutes();
154
+ const seconds = value.getUTCSeconds();
155
+ const milliseconds = value.getUTCMilliseconds();
156
+ if (hours === 0 && minutes === 0 && seconds === 0 && milliseconds === 0) {
157
+ // It's midnight UTC - serialize as date-only (YYYY-MM-DD)
158
+ return value.toISOString().split('T')[0];
159
+ }
160
+ else {
161
+ // Has time component - serialize as full datetime
162
+ return value.toISOString();
163
+ }
164
+ }
165
+ // Everything else (strings, numbers, booleans, null) - return as-is
166
+ return value;
167
+ }
168
+ /**
169
+ * Filters the QuerySet with the provided conditions.
170
+ *
171
+ * @param {Object} conditions - The filter conditions.
172
+ * @returns {QuerySet} A new QuerySet with the filter applied.
173
+ */
174
+ filter(conditions) {
175
+ this.ensureNotMaterialized();
176
+ const { Q: qConditions, ...filters } = conditions;
177
+ const newNodes = [...this.nodes];
178
+ if (Object.keys(filters).length > 0) {
179
+ // Serialize the filter conditions before adding to the node
180
+ const serializedFilters = this._serializeConditions(filters);
181
+ newNodes.push({
182
+ type: "filter",
183
+ conditions: serializedFilters,
184
+ });
185
+ }
186
+ if (qConditions && qConditions.length) {
187
+ newNodes.push({
188
+ type: "and",
189
+ children: qConditions.map((q) => this.processQObject(q)),
190
+ });
191
+ }
192
+ return new QuerySet(this.ModelClass, {
193
+ ...this._getConfig(),
194
+ nodes: newNodes,
195
+ }, this);
196
+ }
197
+ /**
198
+ * Excludes the specified conditions from the QuerySet.
199
+ *
200
+ * @param {Object} conditions - The conditions to exclude.
201
+ * @returns {QuerySet} A new QuerySet with the exclusion applied.
202
+ */
203
+ exclude(conditions) {
204
+ this.ensureNotMaterialized();
205
+ const { Q: qConditions, ...filters } = conditions;
206
+ const newNodes = [...this.nodes];
207
+ let childNode = null;
208
+ if (Object.keys(filters).length > 0 && qConditions && qConditions.length) {
209
+ // Serialize the filter conditions
210
+ const serializedFilters = this._serializeConditions(filters);
211
+ childNode = {
212
+ type: "and",
213
+ children: [
214
+ { type: "filter", conditions: serializedFilters },
215
+ {
216
+ type: "and",
217
+ children: qConditions.map((q) => this.processQObject(q)),
218
+ },
219
+ ],
220
+ };
221
+ }
222
+ else if (Object.keys(filters).length > 0) {
223
+ // Serialize the filter conditions
224
+ const serializedFilters = this._serializeConditions(filters);
225
+ childNode = {
226
+ type: "filter",
227
+ conditions: serializedFilters,
228
+ };
229
+ }
230
+ else if (qConditions && qConditions.length) {
231
+ childNode = {
232
+ type: "and",
233
+ children: qConditions.map((q) => this.processQObject(q)),
234
+ };
235
+ }
236
+ const excludeNode = {
237
+ type: "exclude",
238
+ child: childNode,
239
+ };
240
+ newNodes.push(excludeNode);
241
+ return new QuerySet(this.ModelClass, {
242
+ ...this._getConfig(),
243
+ nodes: newNodes,
244
+ }, this);
245
+ }
246
+ /**
247
+ * Orders the QuerySet by the specified fields.
248
+ *
249
+ * @param {...string} fields - Fields to order by.
250
+ * @returns {QuerySet} A new QuerySet with ordering applied.
251
+ */
252
+ orderBy(...fields) {
253
+ this.ensureNotMaterialized();
254
+ return new QuerySet(this.ModelClass, {
255
+ ...this._getConfig(),
256
+ orderBy: fields,
257
+ }, this);
258
+ }
259
+ /**
260
+ * Applies a search to the QuerySet using the specified search query and fields.
261
+ *
262
+ * @param {string} searchQuery - The search query.
263
+ * @param {string[]} [searchFields] - The fields to search.
264
+ * @returns {QuerySet} A new QuerySet with the search applied.
265
+ */
266
+ search(searchQuery, searchFields) {
267
+ this.ensureNotMaterialized();
268
+ const newNodes = [...this.nodes];
269
+ newNodes.push({
270
+ type: "search",
271
+ searchQuery,
272
+ searchFields: searchFields,
273
+ });
274
+ return new QuerySet(this.ModelClass, {
275
+ ...this._getConfig(),
276
+ nodes: newNodes,
277
+ }, this);
278
+ }
279
+ /**
280
+ * Processes a Q object or condition into a QueryNode.
281
+ *
282
+ * @private
283
+ * @param {QObject|QCondition} q - The query object or condition.
284
+ * @returns {QueryNode} The processed QueryNode.
285
+ */
286
+ processQObject(q) {
287
+ if ("operator" in q && "conditions" in q) {
288
+ return {
289
+ type: q.operator === "AND" ? "and" : "or",
290
+ children: Array.isArray(q.conditions)
291
+ ? q.conditions.map((c) => this.processQObject(c))
292
+ : [],
293
+ };
294
+ }
295
+ else {
296
+ // Serialize the conditions in Q objects as well
297
+ const serializedConditions = this._serializeConditions(q);
298
+ return {
299
+ type: "filter",
300
+ conditions: serializedConditions,
301
+ };
302
+ }
303
+ }
304
+ /**
305
+ * Aggregates the QuerySet using the specified function.
306
+ *
307
+ * @param {AggregateFunction} fn - The aggregation function.
308
+ * @param {string} field - The field to aggregate.
309
+ * @param {string} [alias] - An optional alias for the aggregated field.
310
+ * @returns {QuerySet} A new QuerySet with the aggregation applied.
311
+ */
312
+ aggregate(fn, field, alias) {
313
+ this.ensureNotMaterialized();
314
+ return new QuerySet(this.ModelClass, {
315
+ ...this._getConfig(),
316
+ aggregations: [
317
+ ...this._aggregations,
318
+ {
319
+ function: fn,
320
+ field: field,
321
+ alias,
322
+ },
323
+ ],
324
+ }, this);
325
+ }
326
+ /**
327
+ * Executes a count query on the QuerySet.
328
+ *
329
+ * @param {string} [field] - The field to count.
330
+ * @returns {Promise<number>} A promise that resolves to the count.
331
+ */
332
+ count(field) {
333
+ this.ensureNotMaterialized();
334
+ const newQs = new QuerySet(this.ModelClass, {
335
+ ...this._getConfig(),
336
+ materialized: true,
337
+ }, this);
338
+ return QueryExecutor.execute(newQs, "count", {
339
+ field: field || this.ModelClass.primaryKeyField,
340
+ });
341
+ }
342
+ /**
343
+ * Executes a sum aggregation on the QuerySet.
344
+ *
345
+ * @param {string} field - The field to sum.
346
+ * @returns {Promise<number>} A promise that resolves to the sum.
347
+ */
348
+ sum(field) {
349
+ this.ensureNotMaterialized();
350
+ const newQs = new QuerySet(this.ModelClass, {
351
+ ...this._getConfig(),
352
+ materialized: true,
353
+ }, this);
354
+ return QueryExecutor.execute(newQs, "sum", { field });
355
+ }
356
+ /**
357
+ * Executes an average aggregation on the QuerySet.
358
+ *
359
+ * @param {string} field - The field to average.
360
+ * @returns {Promise<number>} A promise that resolves to the average.
361
+ */
362
+ avg(field) {
363
+ this.ensureNotMaterialized();
364
+ const newQs = new QuerySet(this.ModelClass, {
365
+ ...this._getConfig(),
366
+ materialized: true,
367
+ }, this);
368
+ return QueryExecutor.execute(newQs, "avg", { field });
369
+ }
370
+ /**
371
+ * Executes a min aggregation on the QuerySet.
372
+ *
373
+ * @param {string} field - The field to find the minimum value for.
374
+ * @returns {Promise<any>} A promise that resolves to the minimum value.
375
+ */
376
+ min(field) {
377
+ this.ensureNotMaterialized();
378
+ const newQs = new QuerySet(this.ModelClass, {
379
+ ...this._getConfig(),
380
+ materialized: true,
381
+ }, this);
382
+ return QueryExecutor.execute(newQs, "min", { field });
383
+ }
384
+ /**
385
+ * Executes a max aggregation on the QuerySet.
386
+ *
387
+ * @param {string} field - The field to find the maximum value for.
388
+ * @returns {Promise<any>} A promise that resolves to the maximum value.
389
+ */
390
+ max(field) {
391
+ this.ensureNotMaterialized();
392
+ const newQs = new QuerySet(this.ModelClass, {
393
+ ...this._getConfig(),
394
+ materialized: true,
395
+ }, this);
396
+ return QueryExecutor.execute(newQs, "max", { field });
397
+ }
398
+ /**
399
+ * Retrieves the first record of the QuerySet.
400
+ *
401
+ * @param {SerializerOptions} [serializerOptions] - Optional serializer options.
402
+ * @returns {Promise<T|null>} A promise that resolves to the first record or null.
403
+ */
404
+ first(serializerOptions) {
405
+ this.ensureNotMaterialized();
406
+ const newQs = new QuerySet(this.ModelClass, {
407
+ ...this._getConfig(),
408
+ serializerOptions: serializerOptions
409
+ ? { ...this._serializerOptions, ...serializerOptions }
410
+ : this._serializerOptions,
411
+ materialized: true,
412
+ }, this);
413
+ return QueryExecutor.execute(newQs, "first");
414
+ }
415
+ /**
416
+ * Retrieves the last record of the QuerySet.
417
+ *
418
+ * @param {SerializerOptions} [serializerOptions] - Optional serializer options.
419
+ * @returns {Promise<T|null>} A promise that resolves to the last record or null.
420
+ */
421
+ last(serializerOptions) {
422
+ this.ensureNotMaterialized();
423
+ const newQs = new QuerySet(this.ModelClass, {
424
+ ...this._getConfig(),
425
+ serializerOptions: serializerOptions
426
+ ? { ...this._serializerOptions, ...serializerOptions }
427
+ : this._serializerOptions,
428
+ materialized: true,
429
+ }, this);
430
+ return QueryExecutor.execute(newQs, "last");
431
+ }
432
+ /**
433
+ * Checks if any records exist in the QuerySet.
434
+ *
435
+ * @returns {Promise<boolean>} A promise that resolves to true if records exist, otherwise false.
436
+ */
437
+ exists() {
438
+ this.ensureNotMaterialized();
439
+ const newQs = new QuerySet(this.ModelClass, {
440
+ ...this._getConfig(),
441
+ materialized: true,
442
+ }, this);
443
+ return QueryExecutor.execute(newQs, "exists");
444
+ }
445
+ /**
446
+ * Applies serializer options to the QuerySet.
447
+ *
448
+ * @param {SerializerOptions} [serializerOptions] - Optional serializer options.
449
+ * @returns {QuerySet} A new QuerySet with the serializer options applied.
450
+ */
451
+ all(serializerOptions) {
452
+ this.ensureNotMaterialized();
453
+ if (serializerOptions) {
454
+ return new QuerySet(this.ModelClass, {
455
+ ...this._getConfig(),
456
+ serializerOptions: {
457
+ ...this._serializerOptions,
458
+ ...serializerOptions,
459
+ },
460
+ }, this);
461
+ }
462
+ return this;
463
+ }
464
+ /**
465
+ * Internal method to create an optimistic-only QuerySet.
466
+ * @private
467
+ * @returns {QuerySet} A new QuerySet with optimistic-only mode enabled.
468
+ */
469
+ _optimistic() {
470
+ this.ensureNotMaterialized();
471
+ return new QuerySet(this.ModelClass, {
472
+ ...this._getConfig(),
473
+ optimisticOnly: true,
474
+ }, this);
475
+ }
476
+ /**
477
+ * Returns a QuerySet marked as optimistic-only, meaning operations will only
478
+ * update local state without making backend API calls.
479
+ *
480
+ * @returns {QuerySet} A new QuerySet with optimistic-only mode enabled.
481
+ */
482
+ get optimistic() {
483
+ return this._optimistic();
484
+ }
485
+ /**
486
+ * Returns a QuerySet marked as remote-only, meaning operations will
487
+ * hit the backend but skip local store updates and live thenables.
488
+ *
489
+ * @returns {QuerySet} A new QuerySet with remote-only mode enabled.
490
+ */
491
+ remote() {
492
+ return new QuerySet(this.ModelClass, {
493
+ ...this._getConfig(),
494
+ remoteOnly: true,
495
+ }, this);
496
+ }
497
+ /**
498
+ * Creates a new record in the QuerySet.
499
+ * @param {Object} data - The fields and values for the new record.
500
+ * @returns {Promise<any>} The created model instance.
501
+ */
502
+ async create(data) {
503
+ this.ensureNotMaterialized();
504
+ // Serialize the data before sending to backend
505
+ const serializedData = this._serializer.toInternal(data);
506
+ // Materialize for create
507
+ const newQs = new QuerySet(this.ModelClass, {
508
+ ...this._getConfig(),
509
+ materialized: true,
510
+ }, this);
511
+ return QueryExecutor.execute(newQs, "create", { data: serializedData });
512
+ }
513
+ /**
514
+ * Creates multiple model instances using the provided model instances.
515
+ *
516
+ * @param {Array<Model>} modelInstances - Array of unsaved model instances to create.
517
+ * @returns {Promise<Array<any>>} A promise that resolves to an array of newly created model instances.
518
+ */
519
+ async bulkCreate(modelInstances) {
520
+ this.ensureNotMaterialized();
521
+ if (!Array.isArray(modelInstances)) {
522
+ throw new Error("bulkCreate expects an array of model instances");
523
+ }
524
+ // Serialize each model instance using model.serialize()
525
+ const serializedDataList = modelInstances.map(instance => {
526
+ if (!instance || typeof instance.serialize !== 'function') {
527
+ throw new Error("bulkCreate requires model instances. Did you pass a plain object instead?");
528
+ }
529
+ return instance.serialize();
530
+ });
531
+ // Materialize for bulk create
532
+ const newQs = new QuerySet(this.ModelClass, {
533
+ ...this._getConfig(),
534
+ materialized: true,
535
+ }, this);
536
+ return QueryExecutor.execute(newQs, "bulk_create", { data: serializedDataList });
537
+ }
538
+ /**
539
+ * Updates records in the QuerySet.
540
+ *
541
+ * @param {Object} updates - The fields to update.
542
+ * @returns {Promise<[number, Object]>} A promise that resolves to a tuple with the number of updated records and a mapping of model names to counts.
543
+ */
544
+ update(updates) {
545
+ if (arguments.length > 1) {
546
+ throw new Error("Update accepts only accepts an object of the updates to apply. Use filter() before calling update() to select elements.");
547
+ }
548
+ this.ensureNotMaterialized();
549
+ // Serialize the updates before sending to backend
550
+ const serializedUpdates = this._serializer.toInternal(updates);
551
+ const newQs = new QuerySet(this.ModelClass, {
552
+ ...this._getConfig(),
553
+ materialized: true,
554
+ });
555
+ return QueryExecutor.execute(newQs, "update", { data: serializedUpdates });
556
+ }
557
+ /**
558
+ * Deletes records in the QuerySet.
559
+ *
560
+ * @returns {Promise<[number, Object]>} A promise that resolves to a tuple with the number of deleted records and a mapping of model names to counts.
561
+ */
562
+ delete() {
563
+ if (arguments.length > 0) {
564
+ throw new Error("delete() does not accept arguments and will delete the entire queryset. Use filter() before calling delete() to select elements.");
565
+ }
566
+ this.ensureNotMaterialized();
567
+ const newQs = new QuerySet(this.ModelClass, {
568
+ ...this._getConfig(),
569
+ materialized: true,
570
+ }, this);
571
+ return QueryExecutor.execute(newQs, "delete");
572
+ }
573
+ /**
574
+ * Retrieves a single record from the QuerySet.
575
+ *
576
+ * @param {Object} [filters] - Optional filters to apply.
577
+ * @param {SerializerOptions} [serializerOptions] - Optional serializer options.
578
+ * @returns {Promise<T>} A promise that resolves to the retrieved record.
579
+ * @throws {MultipleObjectsReturned} If more than one record is found.
580
+ * @throws {DoesNotExist} If no records are found.
581
+ */
582
+ get(filters, serializerOptions) {
583
+ this.ensureNotMaterialized();
584
+ let newQs = this;
585
+ if (filters) {
586
+ newQs = this.filter(filters);
587
+ }
588
+ if (serializerOptions) {
589
+ newQs = new QuerySet(this.ModelClass, {
590
+ ...newQs._getConfig(),
591
+ serializerOptions: {
592
+ ...newQs._serializerOptions,
593
+ ...serializerOptions,
594
+ },
595
+ }, this);
596
+ }
597
+ const materializedQs = new QuerySet(this.ModelClass, {
598
+ ...newQs._getConfig(),
599
+ materialized: true,
600
+ }, this);
601
+ const result = QueryExecutor.execute(materializedQs, "get");
602
+ if (result === null) {
603
+ throw new DoesNotExist();
604
+ }
605
+ return result;
606
+ }
607
+ /**
608
+ * Gets or creates a record based on the provided lookup parameters.
609
+ *
610
+ * @param {Object} lookupParams - The lookup parameters to find the record.
611
+ * @param {Object} [defaults={}] - Default values to use when creating a new record.
612
+ * @returns {Promise<[T, boolean]>} A promise that resolves to a tuple of [instance, created].
613
+ */
614
+ async getOrCreate(lookupParams, defaults = {}) {
615
+ this.ensureNotMaterialized();
616
+ // Serialize both lookup params and defaults
617
+ const serializedLookup = this._serializer.toInternal(lookupParams);
618
+ const serializedDefaults = this._serializer.toInternal(defaults);
619
+ const newQs = new QuerySet(this.ModelClass, {
620
+ ...this._getConfig(),
621
+ materialized: true,
622
+ }, this);
623
+ return QueryExecutor.execute(newQs, "get_or_create", {
624
+ lookup: serializedLookup,
625
+ defaults: serializedDefaults,
626
+ });
627
+ }
628
+ /**
629
+ * Updates or creates a record based on the provided lookup parameters.
630
+ *
631
+ * @param {Object} lookupParams - The lookup parameters to find the record.
632
+ * @param {Object} [defaults={}] - Default values to use when creating or updating.
633
+ * @returns {Promise<[T, boolean]>} A promise that resolves to a tuple of [instance, created].
634
+ */
635
+ async updateOrCreate(lookupParams, defaults = {}) {
636
+ this.ensureNotMaterialized();
637
+ // Serialize both lookup params and defaults
638
+ const serializedLookup = this._serializer.toInternal(lookupParams);
639
+ const serializedDefaults = this._serializer.toInternal(defaults);
640
+ const newQs = new QuerySet(this.ModelClass, {
641
+ ...this._getConfig(),
642
+ materialized: true,
643
+ }, this);
644
+ return QueryExecutor.execute(newQs, "update_or_create", {
645
+ lookup: serializedLookup,
646
+ defaults: serializedDefaults,
647
+ });
648
+ }
649
+ /**
650
+ * Builds the final query object to be sent to the backend (simple jsonable object format).
651
+ *
652
+ * @returns {Object} The final query object.
653
+ */
654
+ build() {
655
+ let searchData = null;
656
+ const nonSearchNodes = [];
657
+ for (const node of this.nodes) {
658
+ if (node.type === "search") {
659
+ searchData = {
660
+ searchQuery: node.searchQuery || "",
661
+ searchFields: node.searchFields || this.ModelClass.schema.searchable_fields
662
+ };
663
+ }
664
+ else {
665
+ nonSearchNodes.push(node);
666
+ }
667
+ }
668
+ const filterNode = nonSearchNodes.length === 0
669
+ ? null
670
+ : nonSearchNodes.length === 1
671
+ ? nonSearchNodes[0]
672
+ : {
673
+ type: "and",
674
+ children: nonSearchNodes,
675
+ };
676
+ return clone({
677
+ filter: filterNode,
678
+ search: searchData,
679
+ aggregations: this._aggregations,
680
+ orderBy: this._orderBy,
681
+ serializerOptions: this._serializerOptions,
682
+ });
683
+ }
684
+ /**
685
+ * Returns the current configuration of the QuerySet.
686
+ *
687
+ * @private
688
+ * @returns {Object} The current QuerySet configuration.
689
+ */
690
+ _getConfig() {
691
+ return {
692
+ nodes: this.nodes,
693
+ orderBy: this._orderBy,
694
+ fields: this._fields,
695
+ aggregations: this._aggregations,
696
+ initialQueryset: this._initialQueryset,
697
+ serializerOptions: this._serializerOptions,
698
+ optimisticOnly: this._optimisticOnly,
699
+ remoteOnly: this._remoteOnly,
700
+ };
701
+ }
702
+ /**
703
+ * Materializes the QuerySet into an array of model instances.
704
+ *
705
+ * @param {SerializerOptions} [serializerOptions] - Optional serializer options.
706
+ * @returns {Promise<T[]>} A promise that resolves to an array of model instances.
707
+ */
708
+ fetch(serializerOptions) {
709
+ let querySet = this;
710
+ if (serializerOptions) {
711
+ querySet = new QuerySet(this.ModelClass, {
712
+ ...this._getConfig(),
713
+ serializerOptions: {
714
+ ...this._serializerOptions,
715
+ ...serializerOptions,
716
+ },
717
+ }, this);
718
+ }
719
+ const materializedQs = new QuerySet(this.ModelClass, {
720
+ ...querySet._getConfig(),
721
+ materialized: true,
722
+ }, this);
723
+ return QueryExecutor.execute(materializedQs, "list");
724
+ }
725
+ /**
726
+ * Implements the async iterator protocol so that you can iterate over the QuerySet.
727
+ *
728
+ * @returns {AsyncIterator<T>} An async iterator over the model instances.
729
+ */
730
+ async *[Symbol.asyncIterator]() {
731
+ const items = await this.fetch();
732
+ for (const item of items) {
733
+ yield item;
734
+ }
735
+ }
736
+ }