joist-orm 1.294.0 → 2.0.0

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 (482) hide show
  1. package/build/{drivers/PostgresDriver.d.ts → PostgresDriver.d.ts} +1 -4
  2. package/build/PostgresDriver.d.ts.map +1 -0
  3. package/build/{drivers/PostgresDriver.js → PostgresDriver.js} +49 -58
  4. package/build/PostgresDriver.js.map +1 -0
  5. package/build/codegen.d.ts +2 -0
  6. package/build/codegen.d.ts.map +1 -0
  7. package/build/codegen.js +29 -0
  8. package/build/codegen.js.map +1 -0
  9. package/build/graphql-codegen-export.d.ts +2 -0
  10. package/build/graphql-codegen-export.d.ts.map +1 -0
  11. package/build/{drivers/index.js → graphql-codegen-export.js} +3 -5
  12. package/build/graphql-codegen-export.js.map +1 -0
  13. package/build/graphql-export.d.ts +2 -0
  14. package/build/graphql-export.d.ts.map +1 -0
  15. package/build/graphql-export.js +19 -0
  16. package/build/graphql-export.js.map +1 -0
  17. package/build/index.d.ts +3 -128
  18. package/build/index.d.ts.map +1 -1
  19. package/build/index.js +8 -284
  20. package/build/index.js.map +1 -1
  21. package/build/knex-export.d.ts +2 -0
  22. package/build/knex-export.d.ts.map +1 -0
  23. package/build/knex-export.js +19 -0
  24. package/build/knex-export.js.map +1 -0
  25. package/build/pg-migrate.d.ts +2 -0
  26. package/build/pg-migrate.d.ts.map +1 -0
  27. package/build/pg-migrate.js +30 -0
  28. package/build/pg-migrate.js.map +1 -0
  29. package/build/postgres-driver.d.ts +2 -0
  30. package/build/postgres-driver.d.ts.map +1 -0
  31. package/build/postgres-driver.js +7 -0
  32. package/build/postgres-driver.js.map +1 -0
  33. package/build/tests-export.d.ts +2 -0
  34. package/build/tests-export.d.ts.map +1 -0
  35. package/build/tests-export.js +19 -0
  36. package/build/tests-export.js.map +1 -0
  37. package/package.json +85 -16
  38. package/build/AliasAssigner.d.ts +0 -7
  39. package/build/AliasAssigner.d.ts.map +0 -1
  40. package/build/AliasAssigner.js +0 -30
  41. package/build/AliasAssigner.js.map +0 -1
  42. package/build/Aliases.d.ts +0 -110
  43. package/build/Aliases.d.ts.map +0 -1
  44. package/build/Aliases.js +0 -456
  45. package/build/Aliases.js.map +0 -1
  46. package/build/BaseEntity.d.ts +0 -66
  47. package/build/BaseEntity.d.ts.map +0 -1
  48. package/build/BaseEntity.js +0 -120
  49. package/build/BaseEntity.js.map +0 -1
  50. package/build/ConditionBuilder.d.ts +0 -50
  51. package/build/ConditionBuilder.d.ts.map +0 -1
  52. package/build/ConditionBuilder.js +0 -178
  53. package/build/ConditionBuilder.js.map +0 -1
  54. package/build/Entity.d.ts +0 -38
  55. package/build/Entity.d.ts.map +0 -1
  56. package/build/Entity.js +0 -8
  57. package/build/Entity.js.map +0 -1
  58. package/build/EntityFields.d.ts +0 -37
  59. package/build/EntityFields.d.ts.map +0 -1
  60. package/build/EntityFields.js +0 -3
  61. package/build/EntityFields.js.map +0 -1
  62. package/build/EntityFilter.d.ts +0 -113
  63. package/build/EntityFilter.d.ts.map +0 -1
  64. package/build/EntityFilter.js +0 -3
  65. package/build/EntityFilter.js.map +0 -1
  66. package/build/EntityGraphQLFilter.d.ts +0 -51
  67. package/build/EntityGraphQLFilter.d.ts.map +0 -1
  68. package/build/EntityGraphQLFilter.js +0 -54
  69. package/build/EntityGraphQLFilter.js.map +0 -1
  70. package/build/EntityManager.d.ts +0 -734
  71. package/build/EntityManager.d.ts.map +0 -1
  72. package/build/EntityManager.js +0 -2075
  73. package/build/EntityManager.js.map +0 -1
  74. package/build/EntityMetadata.d.ts +0 -185
  75. package/build/EntityMetadata.d.ts.map +0 -1
  76. package/build/EntityMetadata.js +0 -61
  77. package/build/EntityMetadata.js.map +0 -1
  78. package/build/EnumMetadata.d.ts +0 -15
  79. package/build/EnumMetadata.d.ts.map +0 -1
  80. package/build/EnumMetadata.js +0 -3
  81. package/build/EnumMetadata.js.map +0 -1
  82. package/build/FlushLock.d.ts +0 -26
  83. package/build/FlushLock.d.ts.map +0 -1
  84. package/build/FlushLock.js +0 -57
  85. package/build/FlushLock.js.map +0 -1
  86. package/build/HintTree.d.ts +0 -42
  87. package/build/HintTree.d.ts.map +0 -1
  88. package/build/HintTree.js +0 -64
  89. package/build/HintTree.js.map +0 -1
  90. package/build/IndexManager.d.ts +0 -30
  91. package/build/IndexManager.d.ts.map +0 -1
  92. package/build/IndexManager.js +0 -206
  93. package/build/IndexManager.js.map +0 -1
  94. package/build/InstanceData.d.ts +0 -59
  95. package/build/InstanceData.d.ts.map +0 -1
  96. package/build/InstanceData.js +0 -162
  97. package/build/InstanceData.js.map +0 -1
  98. package/build/IsLoadedCache.d.ts +0 -32
  99. package/build/IsLoadedCache.d.ts.map +0 -1
  100. package/build/IsLoadedCache.js +0 -80
  101. package/build/IsLoadedCache.js.map +0 -1
  102. package/build/JoinRows.d.ts +0 -75
  103. package/build/JoinRows.d.ts.map +0 -1
  104. package/build/JoinRows.js +0 -246
  105. package/build/JoinRows.js.map +0 -1
  106. package/build/PluginManager.d.ts +0 -90
  107. package/build/PluginManager.d.ts.map +0 -1
  108. package/build/PluginManager.js +0 -97
  109. package/build/PluginManager.js.map +0 -1
  110. package/build/QueryParser.d.ts +0 -271
  111. package/build/QueryParser.d.ts.map +0 -1
  112. package/build/QueryParser.js +0 -853
  113. package/build/QueryParser.js.map +0 -1
  114. package/build/QueryParser.pruning.d.ts +0 -5
  115. package/build/QueryParser.pruning.d.ts.map +0 -1
  116. package/build/QueryParser.pruning.js +0 -118
  117. package/build/QueryParser.pruning.js.map +0 -1
  118. package/build/QueryVisitor.d.ts +0 -19
  119. package/build/QueryVisitor.d.ts.map +0 -1
  120. package/build/QueryVisitor.js +0 -84
  121. package/build/QueryVisitor.js.map +0 -1
  122. package/build/ReactionsManager.d.ts +0 -84
  123. package/build/ReactionsManager.d.ts.map +0 -1
  124. package/build/ReactionsManager.js +0 -308
  125. package/build/ReactionsManager.js.map +0 -1
  126. package/build/Todo.d.ts +0 -31
  127. package/build/Todo.d.ts.map +0 -1
  128. package/build/Todo.js +0 -73
  129. package/build/Todo.js.map +0 -1
  130. package/build/caches.d.ts +0 -6
  131. package/build/caches.d.ts.map +0 -1
  132. package/build/caches.js +0 -42
  133. package/build/caches.js.map +0 -1
  134. package/build/changes.d.ts +0 -79
  135. package/build/changes.d.ts.map +0 -1
  136. package/build/changes.js +0 -251
  137. package/build/changes.js.map +0 -1
  138. package/build/config.d.ts +0 -237
  139. package/build/config.d.ts.map +0 -1
  140. package/build/config.js +0 -298
  141. package/build/config.js.map +0 -1
  142. package/build/config.test.d.ts +0 -2
  143. package/build/config.test.d.ts.map +0 -1
  144. package/build/config.test.js +0 -53
  145. package/build/config.test.js.map +0 -1
  146. package/build/configure.d.ts +0 -13
  147. package/build/configure.d.ts.map +0 -1
  148. package/build/configure.js +0 -329
  149. package/build/configure.js.map +0 -1
  150. package/build/dataloaders/findByUniqueDataLoader.d.ts +0 -7
  151. package/build/dataloaders/findByUniqueDataLoader.d.ts.map +0 -1
  152. package/build/dataloaders/findByUniqueDataLoader.js +0 -47
  153. package/build/dataloaders/findByUniqueDataLoader.js.map +0 -1
  154. package/build/dataloaders/findCountDataLoader.d.ts +0 -7
  155. package/build/dataloaders/findCountDataLoader.d.ts.map +0 -1
  156. package/build/dataloaders/findCountDataLoader.js +0 -74
  157. package/build/dataloaders/findCountDataLoader.js.map +0 -1
  158. package/build/dataloaders/findDataLoader.d.ts +0 -37
  159. package/build/dataloaders/findDataLoader.d.ts.map +0 -1
  160. package/build/dataloaders/findDataLoader.js +0 -337
  161. package/build/dataloaders/findDataLoader.js.map +0 -1
  162. package/build/dataloaders/findIdsDataLoader.d.ts +0 -7
  163. package/build/dataloaders/findIdsDataLoader.d.ts.map +0 -1
  164. package/build/dataloaders/findIdsDataLoader.js +0 -74
  165. package/build/dataloaders/findIdsDataLoader.js.map +0 -1
  166. package/build/dataloaders/findOrCreateDataLoader.d.ts +0 -13
  167. package/build/dataloaders/findOrCreateDataLoader.d.ts.map +0 -1
  168. package/build/dataloaders/findOrCreateDataLoader.js +0 -174
  169. package/build/dataloaders/findOrCreateDataLoader.js.map +0 -1
  170. package/build/dataloaders/lensDataLoader.d.ts +0 -12
  171. package/build/dataloaders/lensDataLoader.d.ts.map +0 -1
  172. package/build/dataloaders/lensDataLoader.js +0 -180
  173. package/build/dataloaders/lensDataLoader.js.map +0 -1
  174. package/build/dataloaders/loadDataLoader.d.ts +0 -11
  175. package/build/dataloaders/loadDataLoader.d.ts.map +0 -1
  176. package/build/dataloaders/loadDataLoader.js +0 -54
  177. package/build/dataloaders/loadDataLoader.js.map +0 -1
  178. package/build/dataloaders/manyToManyDataLoader.d.ts +0 -8
  179. package/build/dataloaders/manyToManyDataLoader.d.ts.map +0 -1
  180. package/build/dataloaders/manyToManyDataLoader.js +0 -74
  181. package/build/dataloaders/manyToManyDataLoader.js.map +0 -1
  182. package/build/dataloaders/manyToManyFindDataLoader.d.ts +0 -8
  183. package/build/dataloaders/manyToManyFindDataLoader.d.ts.map +0 -1
  184. package/build/dataloaders/manyToManyFindDataLoader.js +0 -70
  185. package/build/dataloaders/manyToManyFindDataLoader.js.map +0 -1
  186. package/build/dataloaders/oneToManyDataLoader.d.ts +0 -7
  187. package/build/dataloaders/oneToManyDataLoader.d.ts.map +0 -1
  188. package/build/dataloaders/oneToManyDataLoader.js +0 -60
  189. package/build/dataloaders/oneToManyDataLoader.js.map +0 -1
  190. package/build/dataloaders/oneToManyFindDataLoader.d.ts +0 -8
  191. package/build/dataloaders/oneToManyFindDataLoader.d.ts.map +0 -1
  192. package/build/dataloaders/oneToManyFindDataLoader.js +0 -71
  193. package/build/dataloaders/oneToManyFindDataLoader.js.map +0 -1
  194. package/build/dataloaders/oneToOneDataLoader.d.ts +0 -7
  195. package/build/dataloaders/oneToOneDataLoader.d.ts.map +0 -1
  196. package/build/dataloaders/oneToOneDataLoader.js +0 -59
  197. package/build/dataloaders/oneToOneDataLoader.js.map +0 -1
  198. package/build/dataloaders/populateDataLoader.d.ts +0 -13
  199. package/build/dataloaders/populateDataLoader.d.ts.map +0 -1
  200. package/build/dataloaders/populateDataLoader.js +0 -148
  201. package/build/dataloaders/populateDataLoader.js.map +0 -1
  202. package/build/dataloaders/recursiveChildrenDataLoader.d.ts +0 -7
  203. package/build/dataloaders/recursiveChildrenDataLoader.d.ts.map +0 -1
  204. package/build/dataloaders/recursiveChildrenDataLoader.js +0 -77
  205. package/build/dataloaders/recursiveChildrenDataLoader.js.map +0 -1
  206. package/build/dataloaders/recursiveParentsDataLoader.d.ts +0 -7
  207. package/build/dataloaders/recursiveParentsDataLoader.d.ts.map +0 -1
  208. package/build/dataloaders/recursiveParentsDataLoader.js +0 -59
  209. package/build/dataloaders/recursiveParentsDataLoader.js.map +0 -1
  210. package/build/defaults.d.ts +0 -54
  211. package/build/defaults.d.ts.map +0 -1
  212. package/build/defaults.js +0 -282
  213. package/build/defaults.js.map +0 -1
  214. package/build/driverApi.d.ts +0 -19
  215. package/build/driverApi.d.ts.map +0 -1
  216. package/build/driverApi.js +0 -17
  217. package/build/driverApi.js.map +0 -1
  218. package/build/drivers/Driver.d.ts +0 -26
  219. package/build/drivers/Driver.d.ts.map +0 -1
  220. package/build/drivers/Driver.js +0 -3
  221. package/build/drivers/Driver.js.map +0 -1
  222. package/build/drivers/EntityWriter.d.ts +0 -64
  223. package/build/drivers/EntityWriter.d.ts.map +0 -1
  224. package/build/drivers/EntityWriter.js +0 -237
  225. package/build/drivers/EntityWriter.js.map +0 -1
  226. package/build/drivers/IdAssigner.d.ts +0 -50
  227. package/build/drivers/IdAssigner.d.ts.map +0 -1
  228. package/build/drivers/IdAssigner.js +0 -133
  229. package/build/drivers/IdAssigner.js.map +0 -1
  230. package/build/drivers/PostgresDriver.d.ts.map +0 -1
  231. package/build/drivers/PostgresDriver.js.map +0 -1
  232. package/build/drivers/buildRawQuery.d.ts +0 -20
  233. package/build/drivers/buildRawQuery.d.ts.map +0 -1
  234. package/build/drivers/buildRawQuery.js +0 -148
  235. package/build/drivers/buildRawQuery.js.map +0 -1
  236. package/build/drivers/buildUtils.d.ts +0 -4
  237. package/build/drivers/buildUtils.d.ts.map +0 -1
  238. package/build/drivers/buildUtils.js +0 -79
  239. package/build/drivers/buildUtils.js.map +0 -1
  240. package/build/drivers/index.d.ts +0 -5
  241. package/build/drivers/index.d.ts.map +0 -1
  242. package/build/drivers/index.js.map +0 -1
  243. package/build/fields.d.ts +0 -24
  244. package/build/fields.d.ts.map +0 -1
  245. package/build/fields.js +0 -162
  246. package/build/fields.js.map +0 -1
  247. package/build/getProperties.d.ts +0 -28
  248. package/build/getProperties.d.ts.map +0 -1
  249. package/build/getProperties.js +0 -141
  250. package/build/getProperties.js.map +0 -1
  251. package/build/json.d.ts +0 -77
  252. package/build/json.d.ts.map +0 -1
  253. package/build/json.js +0 -116
  254. package/build/json.js.map +0 -1
  255. package/build/k.d.ts +0 -2
  256. package/build/k.d.ts.map +0 -1
  257. package/build/k.js +0 -9
  258. package/build/k.js.map +0 -1
  259. package/build/keys.d.ts +0 -49
  260. package/build/keys.d.ts.map +0 -1
  261. package/build/keys.js +0 -195
  262. package/build/keys.js.map +0 -1
  263. package/build/keywords.d.ts +0 -5
  264. package/build/keywords.d.ts.map +0 -1
  265. package/build/keywords.js +0 -124
  266. package/build/keywords.js.map +0 -1
  267. package/build/loadHints.d.ts +0 -112
  268. package/build/loadHints.d.ts.map +0 -1
  269. package/build/loadHints.js +0 -75
  270. package/build/loadHints.js.map +0 -1
  271. package/build/loadLens.d.ts +0 -66
  272. package/build/loadLens.d.ts.map +0 -1
  273. package/build/loadLens.js +0 -287
  274. package/build/loadLens.js.map +0 -1
  275. package/build/logging/FactoryLogger.d.ts +0 -24
  276. package/build/logging/FactoryLogger.d.ts.map +0 -1
  277. package/build/logging/FactoryLogger.js +0 -77
  278. package/build/logging/FactoryLogger.js.map +0 -1
  279. package/build/logging/FieldLogger.d.ts +0 -27
  280. package/build/logging/FieldLogger.d.ts.map +0 -1
  281. package/build/logging/FieldLogger.js +0 -69
  282. package/build/logging/FieldLogger.js.map +0 -1
  283. package/build/logging/ReactionLogger.d.ts +0 -23
  284. package/build/logging/ReactionLogger.d.ts.map +0 -1
  285. package/build/logging/ReactionLogger.js +0 -65
  286. package/build/logging/ReactionLogger.js.map +0 -1
  287. package/build/newEntity.d.ts +0 -45
  288. package/build/newEntity.d.ts.map +0 -1
  289. package/build/newEntity.js +0 -106
  290. package/build/newEntity.js.map +0 -1
  291. package/build/newTestInstance.d.ts +0 -193
  292. package/build/newTestInstance.d.ts.map +0 -1
  293. package/build/newTestInstance.js +0 -738
  294. package/build/newTestInstance.js.map +0 -1
  295. package/build/normalizeHints.d.ts +0 -16
  296. package/build/normalizeHints.d.ts.map +0 -1
  297. package/build/normalizeHints.js +0 -31
  298. package/build/normalizeHints.js.map +0 -1
  299. package/build/plugins/ImmutableEntitiesPlugin.d.ts +0 -9
  300. package/build/plugins/ImmutableEntitiesPlugin.d.ts.map +0 -1
  301. package/build/plugins/ImmutableEntitiesPlugin.js +0 -21
  302. package/build/plugins/ImmutableEntitiesPlugin.js.map +0 -1
  303. package/build/plugins/PreloadPlugin.d.ts +0 -69
  304. package/build/plugins/PreloadPlugin.d.ts.map +0 -1
  305. package/build/plugins/PreloadPlugin.js +0 -3
  306. package/build/plugins/PreloadPlugin.js.map +0 -1
  307. package/build/preloading/JsonAggregatePreloader.d.ts +0 -16
  308. package/build/preloading/JsonAggregatePreloader.d.ts.map +0 -1
  309. package/build/preloading/JsonAggregatePreloader.js +0 -238
  310. package/build/preloading/JsonAggregatePreloader.js.map +0 -1
  311. package/build/preloading/canPreload.d.ts +0 -3
  312. package/build/preloading/canPreload.d.ts.map +0 -1
  313. package/build/preloading/canPreload.js +0 -21
  314. package/build/preloading/canPreload.js.map +0 -1
  315. package/build/preloading/partitionHint.d.ts +0 -5
  316. package/build/preloading/partitionHint.d.ts.map +0 -1
  317. package/build/preloading/partitionHint.js +0 -56
  318. package/build/preloading/partitionHint.js.map +0 -1
  319. package/build/reactiveHints.d.ts +0 -129
  320. package/build/reactiveHints.d.ts.map +0 -1
  321. package/build/reactiveHints.js +0 -458
  322. package/build/reactiveHints.js.map +0 -1
  323. package/build/relations/AbstractPropertyImpl.d.ts +0 -8
  324. package/build/relations/AbstractPropertyImpl.d.ts.map +0 -1
  325. package/build/relations/AbstractPropertyImpl.js +0 -15
  326. package/build/relations/AbstractPropertyImpl.js.map +0 -1
  327. package/build/relations/AbstractRelationImpl.d.ts +0 -36
  328. package/build/relations/AbstractRelationImpl.d.ts.map +0 -1
  329. package/build/relations/AbstractRelationImpl.js +0 -19
  330. package/build/relations/AbstractRelationImpl.js.map +0 -1
  331. package/build/relations/Collection.d.ts +0 -28
  332. package/build/relations/Collection.d.ts.map +0 -1
  333. package/build/relations/Collection.js +0 -18
  334. package/build/relations/Collection.js.map +0 -1
  335. package/build/relations/CustomCollection.d.ts +0 -69
  336. package/build/relations/CustomCollection.d.ts.map +0 -1
  337. package/build/relations/CustomCollection.js +0 -166
  338. package/build/relations/CustomCollection.js.map +0 -1
  339. package/build/relations/CustomReference.d.ts +0 -71
  340. package/build/relations/CustomReference.d.ts.map +0 -1
  341. package/build/relations/CustomReference.js +0 -152
  342. package/build/relations/CustomReference.js.map +0 -1
  343. package/build/relations/LargeCollection.d.ts +0 -19
  344. package/build/relations/LargeCollection.d.ts.map +0 -1
  345. package/build/relations/LargeCollection.js +0 -3
  346. package/build/relations/LargeCollection.js.map +0 -1
  347. package/build/relations/ManyToManyCollection.d.ts +0 -44
  348. package/build/relations/ManyToManyCollection.d.ts.map +0 -1
  349. package/build/relations/ManyToManyCollection.js +0 -268
  350. package/build/relations/ManyToManyCollection.js.map +0 -1
  351. package/build/relations/ManyToManyLargeCollection.d.ts +0 -30
  352. package/build/relations/ManyToManyLargeCollection.d.ts.map +0 -1
  353. package/build/relations/ManyToManyLargeCollection.js +0 -119
  354. package/build/relations/ManyToManyLargeCollection.js.map +0 -1
  355. package/build/relations/ManyToOneReference.d.ts +0 -121
  356. package/build/relations/ManyToOneReference.d.ts.map +0 -1
  357. package/build/relations/ManyToOneReference.js +0 -389
  358. package/build/relations/ManyToOneReference.js.map +0 -1
  359. package/build/relations/OneToManyCollection.d.ts +0 -58
  360. package/build/relations/OneToManyCollection.d.ts.map +0 -1
  361. package/build/relations/OneToManyCollection.js +0 -347
  362. package/build/relations/OneToManyCollection.js.map +0 -1
  363. package/build/relations/OneToManyLargeCollection.d.ts +0 -26
  364. package/build/relations/OneToManyLargeCollection.d.ts.map +0 -1
  365. package/build/relations/OneToManyLargeCollection.js +0 -102
  366. package/build/relations/OneToManyLargeCollection.js.map +0 -1
  367. package/build/relations/OneToOneReference.d.ts +0 -93
  368. package/build/relations/OneToOneReference.d.ts.map +0 -1
  369. package/build/relations/OneToOneReference.js +0 -228
  370. package/build/relations/OneToOneReference.js.map +0 -1
  371. package/build/relations/PolymorphicReference.d.ts +0 -89
  372. package/build/relations/PolymorphicReference.d.ts.map +0 -1
  373. package/build/relations/PolymorphicReference.js +0 -244
  374. package/build/relations/PolymorphicReference.js.map +0 -1
  375. package/build/relations/ReactiveField.d.ts +0 -87
  376. package/build/relations/ReactiveField.d.ts.map +0 -1
  377. package/build/relations/ReactiveField.js +0 -149
  378. package/build/relations/ReactiveField.js.map +0 -1
  379. package/build/relations/ReactiveGetter.d.ts +0 -30
  380. package/build/relations/ReactiveGetter.d.ts.map +0 -1
  381. package/build/relations/ReactiveGetter.js +0 -38
  382. package/build/relations/ReactiveGetter.js.map +0 -1
  383. package/build/relations/ReactiveManyToMany.d.ts +0 -56
  384. package/build/relations/ReactiveManyToMany.d.ts.map +0 -1
  385. package/build/relations/ReactiveManyToMany.js +0 -243
  386. package/build/relations/ReactiveManyToMany.js.map +0 -1
  387. package/build/relations/ReactiveManyToManyOtherSide.d.ts +0 -47
  388. package/build/relations/ReactiveManyToManyOtherSide.d.ts.map +0 -1
  389. package/build/relations/ReactiveManyToManyOtherSide.js +0 -155
  390. package/build/relations/ReactiveManyToManyOtherSide.js.map +0 -1
  391. package/build/relations/ReactiveQueryField.d.ts +0 -41
  392. package/build/relations/ReactiveQueryField.d.ts.map +0 -1
  393. package/build/relations/ReactiveQueryField.js +0 -125
  394. package/build/relations/ReactiveQueryField.js.map +0 -1
  395. package/build/relations/ReactiveReference.d.ts +0 -119
  396. package/build/relations/ReactiveReference.d.ts.map +0 -1
  397. package/build/relations/ReactiveReference.js +0 -333
  398. package/build/relations/ReactiveReference.js.map +0 -1
  399. package/build/relations/ReadOnlyCollection.d.ts +0 -19
  400. package/build/relations/ReadOnlyCollection.d.ts.map +0 -1
  401. package/build/relations/ReadOnlyCollection.js +0 -15
  402. package/build/relations/ReadOnlyCollection.js.map +0 -1
  403. package/build/relations/RecursiveCollection.d.ts +0 -84
  404. package/build/relations/RecursiveCollection.d.ts.map +0 -1
  405. package/build/relations/RecursiveCollection.js +0 -296
  406. package/build/relations/RecursiveCollection.js.map +0 -1
  407. package/build/relations/Reference.d.ts +0 -35
  408. package/build/relations/Reference.d.ts.map +0 -1
  409. package/build/relations/Reference.js +0 -21
  410. package/build/relations/Reference.js.map +0 -1
  411. package/build/relations/Relation.d.ts +0 -14
  412. package/build/relations/Relation.d.ts.map +0 -1
  413. package/build/relations/Relation.js +0 -12
  414. package/build/relations/Relation.js.map +0 -1
  415. package/build/relations/hasAsyncMethod.d.ts +0 -27
  416. package/build/relations/hasAsyncMethod.d.ts.map +0 -1
  417. package/build/relations/hasAsyncMethod.js +0 -47
  418. package/build/relations/hasAsyncMethod.js.map +0 -1
  419. package/build/relations/hasAsyncProperty.d.ts +0 -49
  420. package/build/relations/hasAsyncProperty.d.ts.map +0 -1
  421. package/build/relations/hasAsyncProperty.js +0 -98
  422. package/build/relations/hasAsyncProperty.js.map +0 -1
  423. package/build/relations/hasManyDerived.d.ts +0 -22
  424. package/build/relations/hasManyDerived.d.ts.map +0 -1
  425. package/build/relations/hasManyDerived.js +0 -32
  426. package/build/relations/hasManyDerived.js.map +0 -1
  427. package/build/relations/hasManyThrough.d.ts +0 -10
  428. package/build/relations/hasManyThrough.d.ts.map +0 -1
  429. package/build/relations/hasManyThrough.js +0 -24
  430. package/build/relations/hasManyThrough.js.map +0 -1
  431. package/build/relations/hasOneDerived.d.ts +0 -12
  432. package/build/relations/hasOneDerived.d.ts.map +0 -1
  433. package/build/relations/hasOneDerived.js +0 -24
  434. package/build/relations/hasOneDerived.js.map +0 -1
  435. package/build/relations/hasOneThrough.d.ts +0 -10
  436. package/build/relations/hasOneThrough.d.ts.map +0 -1
  437. package/build/relations/hasOneThrough.js +0 -24
  438. package/build/relations/hasOneThrough.js.map +0 -1
  439. package/build/relations/index.d.ts +0 -28
  440. package/build/relations/index.d.ts.map +0 -1
  441. package/build/relations/index.js +0 -88
  442. package/build/relations/index.js.map +0 -1
  443. package/build/rules.d.ts +0 -123
  444. package/build/rules.d.ts.map +0 -1
  445. package/build/rules.js +0 -231
  446. package/build/rules.js.map +0 -1
  447. package/build/runtimeConfig.d.ts +0 -17
  448. package/build/runtimeConfig.d.ts.map +0 -1
  449. package/build/runtimeConfig.js +0 -18
  450. package/build/runtimeConfig.js.map +0 -1
  451. package/build/serde.d.ts +0 -277
  452. package/build/serde.d.ts.map +0 -1
  453. package/build/serde.js +0 -517
  454. package/build/serde.js.map +0 -1
  455. package/build/temporal.d.ts +0 -16
  456. package/build/temporal.d.ts.map +0 -1
  457. package/build/temporal.js +0 -48
  458. package/build/temporal.js.map +0 -1
  459. package/build/temporalMappers.d.ts +0 -25
  460. package/build/temporalMappers.d.ts.map +0 -1
  461. package/build/temporalMappers.js +0 -59
  462. package/build/temporalMappers.js.map +0 -1
  463. package/build/typeMap.d.ts +0 -68
  464. package/build/typeMap.d.ts.map +0 -1
  465. package/build/typeMap.js +0 -3
  466. package/build/typeMap.js.map +0 -1
  467. package/build/unnest.d.ts +0 -13
  468. package/build/unnest.d.ts.map +0 -1
  469. package/build/unnest.js +0 -85
  470. package/build/unnest.js.map +0 -1
  471. package/build/upsert.d.ts +0 -42
  472. package/build/upsert.d.ts.map +0 -1
  473. package/build/upsert.js +0 -265
  474. package/build/upsert.js.map +0 -1
  475. package/build/utils.d.ts +0 -58
  476. package/build/utils.d.ts.map +0 -1
  477. package/build/utils.js +0 -236
  478. package/build/utils.js.map +0 -1
  479. package/build/withLoaded.d.ts +0 -56
  480. package/build/withLoaded.d.ts.map +0 -1
  481. package/build/withLoaded.js +0 -76
  482. package/build/withLoaded.js.map +0 -1
@@ -1,853 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.skipCondition = void 0;
4
- exports.parseFindQuery = parseFindQuery;
5
- exports.parseAlias = parseAlias;
6
- exports.parseEntityFilter = parseEntityFilter;
7
- exports.parseValueFilter = parseValueFilter;
8
- exports.mapToDb = mapToDb;
9
- exports.maybeAddOrderBy = maybeAddOrderBy;
10
- exports.addTablePerClassJoinsAndClassTag = addTablePerClassJoinsAndClassTag;
11
- exports.maybeAddNotSoftDeleted = maybeAddNotSoftDeleted;
12
- exports.getTables = getTables;
13
- exports.makeLike = makeLike;
14
- const joist_utils_1 = require("joist-utils");
15
- const Aliases_1 = require("./Aliases");
16
- const Entity_1 = require("./Entity");
17
- const EntityMetadata_1 = require("./EntityMetadata");
18
- const QueryParser_pruning_1 = require("./QueryParser.pruning");
19
- const QueryVisitor_1 = require("./QueryVisitor");
20
- const configure_1 = require("./configure");
21
- const index_1 = require("./index");
22
- const keywords_1 = require("./keywords");
23
- const utils_1 = require("./utils");
24
- /** A marker condition for alias methods to indicate they should be skipped/pruned. */
25
- exports.skipCondition = {
26
- kind: "column",
27
- alias: "skip",
28
- column: "skip",
29
- dbType: "skip",
30
- cond: undefined,
31
- };
32
- /** Parses an `em.find` filter into a `ParsedFindQuery` AST for simpler execution. */
33
- function parseFindQuery(meta, filter, opts = {}) {
34
- const selects = [];
35
- const tables = [];
36
- const orderBys = [];
37
- const query = { selects, tables, orderBys };
38
- const { orderBy = undefined, conditions: optsExpression = undefined, softDeletes = "exclude", pruneJoins = true, keepAliases = [], } = opts;
39
- const cb = new index_1.ConditionBuilder();
40
- const aliases = {};
41
- function getAlias(tableName) {
42
- const abbrev = (0, utils_1.abbreviation)(tableName);
43
- const i = aliases[abbrev] || 0;
44
- aliases[abbrev] = i + 1;
45
- return i === 0 ? abbrev : `${abbrev}${i}`;
46
- }
47
- function maybeAddNotSoftDeleted(meta, alias) {
48
- if (filterSoftDeletes(meta, softDeletes)) {
49
- const column = meta.allFields[(0, EntityMetadata_1.getBaseMeta)(meta).timestampFields.deletedAt].serde?.columns[0];
50
- cb.addSimpleCondition({
51
- kind: "column",
52
- alias,
53
- column: column.columnName,
54
- dbType: column.dbType,
55
- cond: { kind: "is-null" },
56
- pruneable: true,
57
- });
58
- }
59
- }
60
- function addTable(meta, alias, join, col1, col2, filter, fieldName) {
61
- // look at filter, is it `{ book: "b2" }` or `{ book: { ... } }`
62
- const ef = parseEntityFilter(meta, filter);
63
- if (!ef && join !== "primary" && !(0, Aliases_1.isAlias)(filter)) {
64
- return;
65
- }
66
- if (join === "primary") {
67
- tables.push({ alias, table: meta.tableName, join });
68
- addTablePerClassJoinsAndClassTag(query, meta, alias, true);
69
- }
70
- else if (meta.inheritanceType === "cti" && fieldName && !(fieldName in meta.fields)) {
71
- // For cti, our meta might be a subtype while the FK is actually on the base table. This should only be the case
72
- // when the fk is on another table (e.g. o2o/o2m). In these cases, we'll be passed a field name and can verify if
73
- // its directly in our meta, if not we should assume it's in the base type and join that in first.
74
- meta.baseTypes.forEach((bt, i) => {
75
- tables.push({
76
- alias: `${alias}_b${i}`,
77
- table: bt.tableName,
78
- join: "outer",
79
- col1,
80
- col2: `${(0, keywords_1.kq)(`${alias}_b${i}`)}.${col2.split(".")[1]}`,
81
- distinct: false,
82
- });
83
- // and we still need to join in our subtype as well in case its own fields are queried against
84
- tables.push({
85
- alias: `${alias}`,
86
- table: meta.tableName,
87
- join: "outer",
88
- col1: (0, keywords_1.kqDot)(alias, "id"),
89
- col2: (0, keywords_1.kqDot)(`${alias}_b${i}`, "id"),
90
- distinct: false,
91
- });
92
- });
93
- }
94
- else if (join === "lateral" || join === "cross") {
95
- (0, utils_1.fail)("Unexpected lateral join");
96
- }
97
- else {
98
- tables.push({ alias, table: meta.tableName, join, col1, col2 });
99
- // Maybe only do this if we're the primary, or have a field that needs it?
100
- addTablePerClassJoinsAndClassTag(query, meta, alias, false);
101
- }
102
- if (needsStiDiscriminator(meta)) {
103
- addStiSubtypeFilter(cb, meta, alias);
104
- }
105
- maybeAddNotSoftDeleted(meta, alias);
106
- // The user's locally declared aliases, i.e. `const [a, b] = aliases(Author, Book)`,
107
- // aren't guaranteed to line up with the aliases we've assigned internally, like `a`
108
- // might actually be `a1` if there are two `authors` tables in the query, so push the
109
- // canonical alias value for the current clause into the Alias.
110
- if (filter && typeof filter === "object" && "as" in filter && (0, Aliases_1.isAlias)(filter.as)) {
111
- (0, Aliases_1.getAliasMgmt)(filter.as).setAlias(meta, alias);
112
- }
113
- else if ((0, Aliases_1.isAlias)(filter)) {
114
- (0, Aliases_1.getAliasMgmt)(filter).setAlias(meta, alias);
115
- }
116
- if (ef && ef.kind === "join") {
117
- // subFilter really means we're matching against the entity columns/further joins
118
- Object.keys(ef.subFilter).forEach((key) => {
119
- // Skip the `{ as: ... }` alias binding
120
- if (key === "as")
121
- return;
122
- const field = meta.allFields[key] ??
123
- meta.polyComponentFields?.[key] ??
124
- (0, utils_1.fail)(`Field '${key}' not found on ${meta.tableName}`);
125
- const fa = `${alias}${field.aliasSuffix}`;
126
- if (field.kind === "primitive" || field.kind === "primaryKey" || field.kind === "enum") {
127
- const column = field.serde.columns[0];
128
- parseValueFilter(ef.subFilter[key]).forEach((filter) => {
129
- cb.addValueFilter(fa, column, filter);
130
- });
131
- }
132
- else if (field.kind === "m2o") {
133
- const column = field.serde.columns[0];
134
- const sub = ef.subFilter[key];
135
- const joinKind = field.required && join !== "outer" ? "inner" : "outer";
136
- if ((0, Aliases_1.isAlias)(sub)) {
137
- const a = getAlias(field.otherMetadata().tableName);
138
- addTable(field.otherMetadata(), a, joinKind, (0, keywords_1.kqDot)(fa, column.columnName), (0, keywords_1.kqDot)(a, "id"), sub);
139
- }
140
- const f = parseEntityFilter(field.otherMetadata(), sub);
141
- // Probe the filter and see if it's just an id (...and not soft deleted), if so we can avoid the join
142
- if (!f) {
143
- // skip
144
- }
145
- else if (f.kind === "join" || filterSoftDeletes(field.otherMetadata(), softDeletes)) {
146
- const a = getAlias(field.otherMetadata().tableName);
147
- addTable(field.otherMetadata(), a, joinKind, (0, keywords_1.kqDot)(fa, column.columnName), (0, keywords_1.kqDot)(a, "id"), sub);
148
- }
149
- else {
150
- cb.addValueFilter(fa, column, f);
151
- }
152
- }
153
- else if (field.kind === "poly") {
154
- const f = parseEntityFilter(meta, ef.subFilter[key]);
155
- if (!f) {
156
- // skip
157
- }
158
- else if (f.kind === "join") {
159
- throw new Error("Joins through polys are not supported");
160
- }
161
- else {
162
- // We're left with basically a ValueFilter against the ids
163
- // For now only support eq/ne/in/is-null
164
- if (f.kind === "eq" || f.kind === "ne") {
165
- if (isNilIdValue(f.value))
166
- return;
167
- const comp = field.components.find((p) => {
168
- const otherMeta = p.otherMetadata();
169
- const cstr = (0, index_1.getConstructorFromTaggedId)(f.value);
170
- // tagged ids from subclasses always map to the base class, so we should compare to the base class if we don't directly match
171
- return otherMeta.cstr === cstr || otherMeta.baseType === cstr.name;
172
- });
173
- if (!comp)
174
- (0, utils_1.fail)(`Invalid tagged id passed to ${meta.type}.${key}: ${f.value}`);
175
- const column = field.serde.columns.find((c) => c.columnName === comp.columnName);
176
- cb.addValueFilter(fa, column, f);
177
- }
178
- else if (f.kind === "is-null") {
179
- // Add a condition for every component--these can be AND-d with the rest of the simple/inline conditions
180
- field.components.forEach((comp) => {
181
- const column = field.serde.columns.find((c) => c.columnName === comp.columnName);
182
- cb.addSimpleCondition({
183
- kind: "column",
184
- alias: fa,
185
- column: comp.columnName,
186
- dbType: column.dbType,
187
- cond: f,
188
- });
189
- });
190
- }
191
- else if (f.kind === "not-null") {
192
- const conditions = field.components.map((comp) => {
193
- const column = field.serde.columns.find((c) => c.columnName === comp.columnName);
194
- return {
195
- kind: "column",
196
- alias: fa,
197
- column: comp.columnName,
198
- dbType: column.dbType,
199
- cond: { kind: "not-null" },
200
- };
201
- });
202
- cb.addParsedExpression({ kind: "exp", op: "or", conditions });
203
- }
204
- else if (f.kind === "in") {
205
- // Split up the ids by constructor
206
- const idsByConstructor = (0, joist_utils_1.groupBy)(f.value, (id) => (0, index_1.getConstructorFromTaggedId)(id).name);
207
- // Or together `parent_book_id in (1,2,3) OR parent_author_id IN (4,5,6)`
208
- // ...if there is a `parent IN [b:1, b:2, a:1, null]` we'd need to pull the `null` out and do an `OR (all columns are null)`...
209
- const conditions = Object.entries(idsByConstructor).map(([cstrName, ids]) => {
210
- const column = field.serde.columns.find(
211
- // tagged ids from subclasses always map to the base class, so we should compare to the base class if we don't directly match
212
- (c) => c.otherMetadata().cstr.name === cstrName || c.otherMetadata().baseType === cstrName) ?? (0, utils_1.fail)(`Invalid tagged ids passed to ${meta.type}.${key}: ${ids}`);
213
- return {
214
- kind: "column",
215
- alias: fa,
216
- column: column.columnName,
217
- dbType: column.dbType,
218
- cond: mapToDb(column, { kind: "in", value: ids }),
219
- };
220
- });
221
- if (conditions.length > 0) {
222
- cb.addParsedExpression({ kind: "exp", op: "or", conditions });
223
- }
224
- }
225
- else {
226
- throw new Error(`Filters on polys for ${f.kind} are not supported`);
227
- }
228
- }
229
- }
230
- else if (field.kind === "o2o") {
231
- // We have to always join into o2os, i.e. we can't probe the filter like we do for m2os
232
- const otherMeta = field.otherMetadata();
233
- const a = getAlias(otherMeta.tableName);
234
- const otherField = otherMeta.allFields[field.otherFieldName];
235
- const otherColumn =
236
- // if our other is a poly, we need to find a matching column rather than just picking the first
237
- otherField.kind === "poly"
238
- ? otherField.components.find((c) => c.otherMetadata() === meta || c.otherMetadata() === (0, EntityMetadata_1.getBaseMeta)(meta)).columnName
239
- : otherField.serde.columns[0].columnName;
240
- addTable(field.otherMetadata(), a, "outer", (0, keywords_1.kqDot)(alias, "id"), (0, keywords_1.kqDot)(a, otherColumn), ef.subFilter[key], field.otherFieldName);
241
- }
242
- else if (field.kind === "o2m") {
243
- const a = getAlias(field.otherMetadata().tableName);
244
- const otherField = field.otherMetadata().allFields[field.otherFieldName];
245
- let otherColumn = otherField.serde.columns[0].columnName;
246
- // If the other field is a poly, we need to find the right column
247
- if (otherField.kind === "poly") {
248
- // For a subcomponent that matches field's metadata
249
- const otherComponent = otherField.components.find((c) => c.otherMetadata() === meta) ??
250
- (0, utils_1.fail)(`No poly component found for ${otherField.fieldName}`);
251
- otherColumn = otherComponent.columnName;
252
- }
253
- addTable(field.otherMetadata(), a, "outer", (0, keywords_1.kqDot)(alias, "id"), (0, keywords_1.kqDot)(a, otherColumn), ef.subFilter[key], field.otherFieldName);
254
- }
255
- else if (field.kind === "m2m") {
256
- // Always join into the m2m table
257
- const ja = getAlias(field.joinTableName);
258
- tables.push({
259
- alias: ja,
260
- join: "outer",
261
- table: field.joinTableName,
262
- col1: (0, keywords_1.kqDot)(alias, "id"),
263
- col2: (0, keywords_1.kqDot)(ja, field.columnNames[0]),
264
- });
265
- // But conditionally join into the alias table
266
- const sub = ef.subFilter[key];
267
- if ((0, Aliases_1.isAlias)(sub)) {
268
- const a = getAlias(field.otherMetadata().tableName);
269
- addTable(field.otherMetadata(), a, "outer", (0, keywords_1.kqDot)(ja, field.columnNames[1]), (0, keywords_1.kqDot)(a, "id"), sub);
270
- }
271
- const f = parseEntityFilter(field.otherMetadata(), sub);
272
- // Probe the filter and see if it's just an id, if so we can avoid the join
273
- if (!f) {
274
- // skip
275
- }
276
- else if (f.kind === "join" || filterSoftDeletes(field.otherMetadata(), softDeletes)) {
277
- const a = getAlias(field.otherMetadata().tableName);
278
- addTable(field.otherMetadata(), a, "outer", (0, keywords_1.kqDot)(ja, field.columnNames[1]), (0, keywords_1.kqDot)(a, "id"), ef.subFilter[key]);
279
- }
280
- else {
281
- const meta = field.otherMetadata();
282
- // We normally don't have `columns` for m2m fields, b/c they don't go through normal serde
283
- // codepaths, so make one up to leverage the existing `mapToDb` function.
284
- const column = {
285
- columnName: field.columnNames[1],
286
- dbType: meta.idDbType,
287
- mapToDb(value) {
288
- // Check for `typeof value === number` in case this is a new entity, and we've been given the nilIdValue
289
- return value === null || isNilIdValue(value)
290
- ? value
291
- : (0, index_1.keyToNumber)(meta, (0, index_1.maybeResolveReferenceToId)(value));
292
- },
293
- };
294
- cb.addSimpleCondition({
295
- kind: "column",
296
- alias: ja,
297
- column: field.columnNames[1],
298
- dbType: meta.idDbType,
299
- cond: mapToDb(column, f),
300
- });
301
- }
302
- }
303
- else {
304
- throw new Error(`Unsupported field ${key}`);
305
- }
306
- });
307
- }
308
- else if (ef) {
309
- const column = meta.fields["id"].serde.columns[0];
310
- cb.addValueFilter(alias, column, ef);
311
- }
312
- }
313
- function addOrderBy(meta, alias, orderBy) {
314
- const entries = Object.entries(orderBy);
315
- if (entries.length === 0)
316
- return;
317
- for (const [key, value] of entries) {
318
- if (!value)
319
- continue; // prune undefined
320
- const field = meta.allFields[key] ?? (0, utils_1.fail)(`${key} not found on ${meta.tableName}`);
321
- if (field.kind === "primitive" || field.kind === "primaryKey" || field.kind === "enum") {
322
- const column = field.serde.columns[0];
323
- orderBys.push({
324
- alias: `${alias}${field.aliasSuffix ?? ""}`,
325
- column: column.columnName,
326
- order: value,
327
- });
328
- }
329
- else if (field.kind === "m2o") {
330
- // Do we already this table joined in?
331
- let table = tables.find((t) => t.table === field.otherMetadata().tableName);
332
- if (table) {
333
- addOrderBy(field.otherMetadata(), table.alias, value);
334
- }
335
- else {
336
- const table = field.otherMetadata().tableName;
337
- const a = getAlias(table);
338
- const column = field.serde.columns[0].columnName;
339
- // If we don't have a join, don't force this to be an inner join
340
- tables.push({
341
- alias: a,
342
- table,
343
- join: "outer",
344
- col1: (0, keywords_1.kqDot)(alias, column),
345
- col2: (0, keywords_1.kqDot)(a, "id"),
346
- distinct: false,
347
- });
348
- addOrderBy(field.otherMetadata(), a, value);
349
- }
350
- }
351
- else {
352
- throw new Error(`Unsupported field ${key}`);
353
- }
354
- }
355
- }
356
- // always add the main table
357
- const alias = getAlias(meta.tableName);
358
- selects.push(`${(0, keywords_1.kq)(alias)}.*`);
359
- addTable(meta, alias, "primary", "n/a", "n/a", filter);
360
- // If they passed extra `conditions: ...`, parse that
361
- if (optsExpression) {
362
- cb.maybeAddExpression(optsExpression);
363
- }
364
- Object.assign(query, {
365
- condition: cb.toExpressionFilter(),
366
- });
367
- if (query.tables.some((t) => t.join === "outer")) {
368
- maybeAddIdNotNulls(query);
369
- }
370
- if (orderBy) {
371
- if (Array.isArray(orderBy)) {
372
- for (const ob of orderBy)
373
- addOrderBy(meta, alias, ob);
374
- }
375
- else {
376
- addOrderBy(meta, alias, orderBy);
377
- }
378
- }
379
- maybeAddOrderBy(query, meta, alias);
380
- if (pruneJoins) {
381
- (0, QueryParser_pruning_1.pruneUnusedJoins)(query, keepAliases);
382
- }
383
- return query;
384
- }
385
- /**
386
- * Look for conditions doing `some_column IS NULL` in an outer join that
387
- * need an `id IS NOT NULL` to make sure they don't match inadvertently on
388
- * the child row simply not existing.
389
- *
390
- * Note: Instead of injecting an extra `id IS NOT NULL` condition, I had tried
391
- * using all INNER JOINs and flipping joins to OUTER only if the user explicit
392
- * had `id IS NULL` in their filter, but that didn't work for queries that wanted
393
- * to do an `OR` across two different children (which queries both children being
394
- * OUTER JOINs, and detecting that case seemed complicated).
395
- */
396
- function maybeAddIdNotNulls(query) {
397
- (0, QueryVisitor_1.visitConditions)(query, {
398
- visitCond(c) {
399
- // Check `c.prunable` to make sure we don't catch our injected `deleted_at is null` conditions
400
- if (c.cond.kind !== "is-null" || c.column === "id" || c.pruneable) {
401
- return c;
402
- }
403
- // This is an `some_column IS NULL`, is it in an outer join?
404
- const table = query.tables.find((t) => t.alias === c.alias);
405
- if (table && table.join === "outer") {
406
- const meta = (0, configure_1.getMetadataForTable)(table.table);
407
- return {
408
- kind: "exp",
409
- op: "and",
410
- conditions: [
411
- c,
412
- {
413
- kind: "column",
414
- alias: c.alias,
415
- column: "id",
416
- dbType: meta.idDbType,
417
- cond: { kind: "not-null" },
418
- },
419
- ],
420
- };
421
- }
422
- return c;
423
- },
424
- });
425
- }
426
- /** Returns the `a` from `"a".*`. */
427
- function parseAlias(alias) {
428
- return alias.split(".")[0].replaceAll(`"`, "");
429
- }
430
- /** Parses an entity filter, which could be "just an id", an array of ids, or a nested filter. */
431
- function parseEntityFilter(meta, filter) {
432
- if (filter === undefined) {
433
- // This matches legacy `em.find(Book, { author: undefined })` behavior
434
- return undefined;
435
- }
436
- else if ((0, Aliases_1.isAlias)(filter)) {
437
- // We're just binding an alias to this position in the join tree
438
- return undefined;
439
- }
440
- else if (filter === null) {
441
- return { kind: "is-null" };
442
- }
443
- else if (typeof filter === "string" || typeof filter === "number") {
444
- return { kind: "eq", value: filter };
445
- }
446
- else if (typeof filter === "boolean") {
447
- return filter ? { kind: "not-null" } : { kind: "is-null" };
448
- }
449
- else if (Array.isArray(filter)) {
450
- return {
451
- kind: "in",
452
- value: filter.map((v) => {
453
- return (0, Entity_1.isEntity)(v) ? (v.idTaggedMaybe ?? nilIdValue(meta)) : v;
454
- }),
455
- };
456
- }
457
- else if ((0, Entity_1.isEntity)(filter)) {
458
- return { kind: "eq", value: filter.idTaggedMaybe || nilIdValue(meta) };
459
- }
460
- else if (typeof filter === "object") {
461
- // Looking for `{ firstName: "f1" }` or `{ ne: "f1" }`
462
- const keys = Object.keys(filter);
463
- // Special case only looking at `ne`
464
- if (keys.length === 1 && keys[0] === "ne") {
465
- const value = filter["ne"];
466
- if (value === undefined) {
467
- return undefined;
468
- }
469
- else if (value === null) {
470
- return { kind: "not-null" };
471
- }
472
- else if (typeof value === "string" || typeof value === "number") {
473
- return { kind: "ne", value };
474
- }
475
- else if ((0, Entity_1.isEntity)(value)) {
476
- return { kind: "ne", value: value.idTaggedMaybe || nilIdValue(meta) };
477
- }
478
- else {
479
- throw new Error(`Unsupported "ne" value ${value}`);
480
- }
481
- }
482
- // Special case only looking at `id`
483
- if (keys.length === 1 && keys[0] === "id") {
484
- const value = filter["id"];
485
- if (value === undefined) {
486
- return undefined;
487
- }
488
- else if (value === null) {
489
- return { kind: "is-null" };
490
- }
491
- else if (typeof value === "string" || typeof value === "number") {
492
- return { kind: "eq", value };
493
- }
494
- else if ((0, Entity_1.isEntity)(value)) {
495
- return { kind: "eq", value: value.idTaggedMaybe || nilIdValue(meta) };
496
- }
497
- else {
498
- return parseValueFilter(value)[0];
499
- }
500
- }
501
- // Look for subFilter values being EntityFilter-ish instances like ManyToOneReference
502
- // that have an id, and so structurally match the entity filter without really being filters,
503
- // and convert them over here before getting into parseValueFilter.
504
- const subFilter = {};
505
- for (const [key, value] of Object.entries(filter)) {
506
- if (value && typeof value === "object" && !(0, joist_utils_1.isPlainObject)(value) && "idTaggedMaybe" in value) {
507
- subFilter[key] = value.idTaggedMaybe || nilIdValue(meta);
508
- }
509
- else {
510
- subFilter[key] = value;
511
- }
512
- }
513
- return { kind: "join", subFilter };
514
- }
515
- else {
516
- throw new Error(`Unrecognized filter ${filter}`);
517
- }
518
- }
519
- /**
520
- * We use this value if users include new (id-less) entities as em.find conditions.
521
- *
522
- * The idea is that this condition would never be met, but we still want to do the em.find
523
- * query in case it's in an `OR` clause that would match false, but some other part of the
524
- * clause would match. I.e. instead of just skipping the DB query all together, which is
525
- * also something we could consider doing.
526
- *
527
- * For int IDs we use -1, and for uuid IDs, we use the nil UUID value:
528
- *
529
- * https://en.wikipedia.org/wiki/Universally_unique_identifier#Nil_UUID
530
- */
531
- function nilIdValue(meta) {
532
- switch (meta.idDbType) {
533
- case "int":
534
- case "bigint":
535
- return -1;
536
- case "uuid":
537
- return "00000000-0000-0000-0000-000000000000";
538
- case "text":
539
- return "0";
540
- default:
541
- return (0, utils_1.assertNever)(meta.idDbType);
542
- }
543
- }
544
- function isNilIdValue(value) {
545
- return value === -1 || value === "00000000-0000-0000-0000-000000000000";
546
- }
547
- /**
548
- * Parses the many/hodgepodge (ergonomic!) patterns of value filters into a `ParsedValueFilter[]`.
549
- *
550
- * Note we return an array because filter might be a `ValueGraphQLFilter` that is allowed to have
551
- * multiple conditions, i.e. `{ lt: 10, gt: 5 }`.
552
- */
553
- function parseValueFilter(filter) {
554
- if (filter === null) {
555
- return [{ kind: "is-null" }];
556
- }
557
- else if (filter === undefined) {
558
- // This is legacy behavior where `em.find(Book, { author: undefined })` would match all books
559
- return [];
560
- }
561
- else if (Array.isArray(filter)) {
562
- return [{ kind: "in", value: filter }];
563
- }
564
- else if ((0, joist_utils_1.isPlainObject)(filter)) {
565
- const keys = Object.keys(filter);
566
- if (keys.length === 0) {
567
- // Should this be an error?
568
- return [];
569
- }
570
- else if (keys.length === 2 && "op" in filter && "value" in filter) {
571
- // Probe for `findGql` op & value
572
- const { op, value } = filter;
573
- if (value === null) {
574
- return [{ kind: "is-null" }];
575
- }
576
- else {
577
- return [{ kind: op, value: value ?? null }];
578
- }
579
- }
580
- else if (keys.length === 2 && "gte" in filter && "lte" in filter) {
581
- const { gte, lte } = filter;
582
- return [{ kind: "between", value: [gte, lte] }];
583
- }
584
- else {
585
- return Object.entries(filter)
586
- .map(([key, value]) => {
587
- // Always do condition pruning on the value
588
- if (value === undefined) {
589
- return undefined;
590
- }
591
- switch (key) {
592
- case "eq":
593
- if (value === null) {
594
- return { kind: "is-null" };
595
- }
596
- else {
597
- return { kind: "eq", value: filter[key] };
598
- }
599
- case "ne":
600
- if (value === null) {
601
- return { kind: "not-null" };
602
- }
603
- else {
604
- return { kind: "ne", value: filter[key] ?? null };
605
- }
606
- case "in":
607
- case "nin":
608
- case "gt":
609
- case "gte":
610
- case "lt":
611
- case "lte":
612
- case "like":
613
- case "nlike":
614
- case "ilike":
615
- case "nilike":
616
- case "regex":
617
- case "nregex":
618
- case "iregex":
619
- case "niregex":
620
- case "contains":
621
- case "overlaps":
622
- case "containedBy":
623
- return { kind: key, value: filter[key] };
624
- case "pathExists":
625
- return { kind: "jsonPathExists", value: filter[key] };
626
- case "pathIsTrue":
627
- return { kind: "jsonPathPredicate", value: filter[key] };
628
- case "search":
629
- return { kind: "ilike", value: makeLike(filter[key]) };
630
- case "between":
631
- return { kind: key, value: filter[key] };
632
- default:
633
- throw new Error(`Unsupported value filter key ${key}`);
634
- }
635
- })
636
- .filter(index_1.isDefined);
637
- }
638
- }
639
- else {
640
- // This is a primitive like a string, number
641
- return [{ kind: "eq", value: filter }];
642
- }
643
- }
644
- /** Converts domain-level values like string ids/enums into their db equivalent. */
645
- function mapToDb(column, filter) {
646
- // ...to teach this `mapToDb` function to handle/rewrite `in: [1, null]` handling, we'd need to:
647
- // 1. return a maybe-simple/maybe-nested condition, so basically a `ParsedExpressionCondition`, because
648
- // this would let `in` return an `{ or: ... }` to all the callers.
649
- // 2. also return `{ parsed: ParsedExpressionCondition, simples: SimpleCondition[] }` tuple, for the
650
- // alias `addCondition` processing to track the `simples` and rewrite their alias when later bound.
651
- switch (filter.kind) {
652
- case "eq":
653
- case "gt":
654
- case "gte":
655
- case "ne":
656
- case "lt":
657
- case "lte":
658
- case "like":
659
- case "nlike":
660
- case "ilike":
661
- case "nilike":
662
- case "regex":
663
- case "nregex":
664
- case "iregex":
665
- case "niregex":
666
- filter.value = column.mapToDb(filter.value);
667
- return filter;
668
- case "in":
669
- if (column.isArray) {
670
- // Arrays need a special operator
671
- return { kind: "contains", value: column.mapToDb(filter.value) };
672
- }
673
- else {
674
- filter.value = filter.value.map((v) => column.mapToDb(v));
675
- }
676
- return filter;
677
- case "nin":
678
- if (column.isArray) {
679
- // Arrays need a special operator
680
- throw new Error("The nin operator is not supported on array columns yet");
681
- }
682
- else {
683
- filter.value = filter.value.map((v) => column.mapToDb(v));
684
- }
685
- return filter;
686
- case "contains":
687
- case "ncontains":
688
- case "overlaps":
689
- case "noverlaps":
690
- case "containedBy":
691
- const supportsContains = column.isArray || column.dbType === "jsonb";
692
- if (!supportsContains) {
693
- throw new Error(`${filter.kind} is only unsupported on array or jsonb columns`);
694
- }
695
- if (column.isArray) {
696
- filter.value = column.mapToDb(filter.value);
697
- }
698
- else {
699
- // leave jsonb values alone
700
- }
701
- return filter;
702
- case "between":
703
- filter.value = [column.mapToDb(filter.value[0]), column.mapToDb(filter.value[1])];
704
- return filter;
705
- case "is-null":
706
- case "not-null":
707
- case "jsonPathExists":
708
- case "jsonPathPredicate":
709
- return filter;
710
- default:
711
- throw (0, utils_1.assertNever)(filter);
712
- }
713
- }
714
- /** Adds any user-configured default order, plus an "always order by id" for determinism. */
715
- function maybeAddOrderBy(query, meta, alias) {
716
- const { orderBys } = query;
717
- if (meta.orderBy) {
718
- const field = meta.allFields[meta.orderBy] ?? (0, utils_1.fail)(`${meta.orderBy} not found on ${meta.tableName}`);
719
- const column = field.serde.columns[0].columnName;
720
- const hasAlready = orderBys.find((o) => o.alias === alias && o.column === column);
721
- if (!hasAlready) {
722
- orderBys.push({ alias, column, order: "ASC" });
723
- }
724
- }
725
- // Even if they already added orders, add id as the last one to get deterministic output
726
- const hasIdOrder = orderBys.find((o) => o.alias === alias && o.column === "id");
727
- if (!hasIdOrder) {
728
- orderBys.push({ alias, column: "id", order: "ASC" });
729
- }
730
- }
731
- function addTablePerClassJoinsAndClassTag(query, meta, alias, isPrimary) {
732
- if (!needsClassPerTableJoins(meta))
733
- return;
734
- const { selects, tables } = query;
735
- // When `.load(SmallPublisher)` is called, join in base tables like `Publisher`
736
- meta.baseTypes.forEach((bt, i) => {
737
- if (isPrimary) {
738
- selects.push(`${alias}_b${i}.*`);
739
- }
740
- tables.push({
741
- alias: `${alias}_b${i}`,
742
- table: bt.tableName,
743
- join: "outer",
744
- col1: (0, keywords_1.kqDot)(alias, "id"),
745
- col2: `${alias}_b${i}.id`,
746
- distinct: false,
747
- });
748
- });
749
- // We always join in the base table in case a query happens to use
750
- // it as a filter, but we only need to do the subtype joins + selects
751
- // if this is the primary table
752
- if (isPrimary) {
753
- // Watch for subTypes that share column names. It'd be great to do
754
- // this statically at codegen time, like a meta.sharedSubtypeColumns.
755
- const stColumns = [];
756
- // When `.load(Publisher)` is called, join in sub tables like `SmallPublisher` and `LargePublisher`
757
- meta.subTypes.forEach((st, i) => {
758
- const stAlias = `${alias}_s${i}`;
759
- selects.push(`${stAlias}.*`);
760
- tables.push({
761
- alias: stAlias,
762
- table: st.tableName,
763
- join: "outer",
764
- col1: (0, keywords_1.kqDot)(alias, "id"),
765
- col2: `${alias}_s${i}.id`,
766
- distinct: false,
767
- });
768
- for (const field of Object.values(st.fields)) {
769
- if (field.fieldName !== "id" && field.serde) {
770
- for (const c of field.serde?.columns) {
771
- stColumns.push({ stAlias, columnName: c.columnName });
772
- }
773
- }
774
- }
775
- });
776
- // Nominate a specific `id` column to avoid ambiguity
777
- selects.push(`${(0, keywords_1.kq)(alias)}.id as id`);
778
- // Add an explicit coalesce for shared columns
779
- Object.values((0, joist_utils_1.groupBy)(stColumns, (c) => c.columnName))
780
- .filter((columns) => columns.length > 1)
781
- .forEach((columns) => {
782
- const { columnName } = columns[0];
783
- selects.push(`COALESCE(${columns.map((c) => `${c.stAlias}.${columnName}`).join(", ")}) as ${columnName}`);
784
- });
785
- // If our meta has no subtypes, we're a left type and don't need a __class
786
- const cases = meta.subTypes.map((st, i) => `WHEN ${alias}_s${i}.id IS NOT NULL THEN '${st.type}'`);
787
- if (cases.length > 0) {
788
- selects.push(`CASE ${cases.join(" ")} ELSE '_' END as __class`);
789
- }
790
- }
791
- }
792
- function maybeAddNotSoftDeleted(conditions, meta, alias, softDeletes) {
793
- if (filterSoftDeletes(meta, softDeletes)) {
794
- const column = meta.allFields[(0, EntityMetadata_1.getBaseMeta)(meta).timestampFields.deletedAt].serde?.columns[0];
795
- conditions.push({
796
- kind: "column",
797
- alias,
798
- column: column.columnName,
799
- dbType: column.dbType,
800
- cond: { kind: "is-null" },
801
- });
802
- }
803
- }
804
- function filterSoftDeletes(meta, softDeletes) {
805
- return (softDeletes === "exclude" &&
806
- !!(0, EntityMetadata_1.getBaseMeta)(meta).timestampFields?.deletedAt &&
807
- // We don't support CTI subtype soft-delete filtering yet
808
- (meta.inheritanceType !== "cti" || meta.baseTypes.length === 0));
809
- }
810
- function getTables(query) {
811
- let primary;
812
- const joins = [];
813
- const laterals = [];
814
- const crosses = [];
815
- for (const table of query.tables) {
816
- if (table.join === "primary") {
817
- primary = table;
818
- }
819
- else if (table.join === "lateral") {
820
- laterals.push(table);
821
- }
822
- else if (table.join === "cross") {
823
- crosses.push(table);
824
- }
825
- else {
826
- joins.push(table);
827
- }
828
- }
829
- return [primary, joins, laterals, crosses];
830
- }
831
- function needsClassPerTableJoins(meta) {
832
- return meta.inheritanceType === "cti" && (meta.subTypes.length > 0 || meta.baseTypes.length > 0);
833
- }
834
- function needsStiDiscriminator(meta) {
835
- return meta.inheritanceType === "sti" && !meta.stiDiscriminatorField;
836
- }
837
- function addStiSubtypeFilter(cb, subtypeMeta, alias) {
838
- const baseMeta = (0, EntityMetadata_1.getBaseMeta)(subtypeMeta);
839
- const column = baseMeta.fields[baseMeta.stiDiscriminatorField].serde?.columns[0];
840
- cb.addSimpleCondition({
841
- kind: "column",
842
- alias,
843
- column: column.columnName,
844
- dbType: column.dbType,
845
- cond: { kind: "eq", value: subtypeMeta.stiDiscriminatorValue },
846
- pruneable: true,
847
- });
848
- }
849
- /** Converts a search term like `foo bar` into a SQL `like` pattern like `%foo%bar%`. */
850
- function makeLike(search) {
851
- return search ? `%${search.replace(/\s+/g, "%")}%` : undefined;
852
- }
853
- //# sourceMappingURL=QueryParser.js.map