orcaq 1.0.20

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 (1018) hide show
  1. package/.output/nitro.json +15 -0
  2. package/.output/public/_nuxt/8qASMGdV.js +1 -0
  3. package/.output/public/_nuxt/9lJACZIQ.js +19 -0
  4. package/.output/public/_nuxt/B2DnNiWd.js +1 -0
  5. package/.output/public/_nuxt/B6E6ObS_.js +8 -0
  6. package/.output/public/_nuxt/BH83_dXo.js +39 -0
  7. package/.output/public/_nuxt/BIKqrFbQ.js +1 -0
  8. package/.output/public/_nuxt/BNjPC06x.js +1 -0
  9. package/.output/public/_nuxt/BPQ-Pz1w.js +39 -0
  10. package/.output/public/_nuxt/BRpgKkVT.js +51 -0
  11. package/.output/public/_nuxt/BTCLPbPY.js +4 -0
  12. package/.output/public/_nuxt/BUV-RarV.js +1 -0
  13. package/.output/public/_nuxt/Bh6RgYlO.js +1 -0
  14. package/.output/public/_nuxt/Bq3cyzOD.js +1 -0
  15. package/.output/public/_nuxt/Bt9sU68B.js +9 -0
  16. package/.output/public/_nuxt/BwpH2ZxJ.js +1 -0
  17. package/.output/public/_nuxt/C25Tmn1m.js +1 -0
  18. package/.output/public/_nuxt/C2HlI1ss.js +1 -0
  19. package/.output/public/_nuxt/CU3ZV9iV.js +1 -0
  20. package/.output/public/_nuxt/CbcyysXi.js +1 -0
  21. package/.output/public/_nuxt/CepyvMhE.js +1 -0
  22. package/.output/public/_nuxt/CrgoNCm2.js +2 -0
  23. package/.output/public/_nuxt/CuBKbBH_.js +1 -0
  24. package/.output/public/_nuxt/CulD8qYQ.js +193 -0
  25. package/.output/public/_nuxt/CustomEdge.BNBpjEHb.css +1 -0
  26. package/.output/public/_nuxt/CylkLpwm.js +1 -0
  27. package/.output/public/_nuxt/D-bWLYHw.js +1 -0
  28. package/.output/public/_nuxt/D-zecHND.js +1 -0
  29. package/.output/public/_nuxt/D8vj6kFe.js +160 -0
  30. package/.output/public/_nuxt/DIETYtCL.js +1 -0
  31. package/.output/public/_nuxt/DJ4vUzxS.js +1 -0
  32. package/.output/public/_nuxt/DK-itzXx.js +8 -0
  33. package/.output/public/_nuxt/DL3T5jYo.js +3867 -0
  34. package/.output/public/_nuxt/DUsuhY9i.js +1 -0
  35. package/.output/public/_nuxt/DXV2HFBA.js +224 -0
  36. package/.output/public/_nuxt/Dh2zppOR.js +1 -0
  37. package/.output/public/_nuxt/DlAUqK2U.js +1 -0
  38. package/.output/public/_nuxt/DlmSeCnw.js +5 -0
  39. package/.output/public/_nuxt/DswTpYG4.js +1 -0
  40. package/.output/public/_nuxt/DynamicTable.DJeANwbG.css +1 -0
  41. package/.output/public/_nuxt/G830WtVn.js +1 -0
  42. package/.output/public/_nuxt/ICwM1E4-.js +15 -0
  43. package/.output/public/_nuxt/QZbJy9YW.js +31 -0
  44. package/.output/public/_nuxt/QuickQueryTable.DS_ON57S.css +1 -0
  45. package/.output/public/_nuxt/UXhX8z2W.js +1 -0
  46. package/.output/public/_nuxt/WrapperErdDiagram.DwhUd9Wr.css +1 -0
  47. package/.output/public/_nuxt/_fileId_.DmPfwyyD.css +1 -0
  48. package/.output/public/_nuxt/_tabViewId_.9Axt3zoi.css +1 -0
  49. package/.output/public/_nuxt/builds/latest.json +1 -0
  50. package/.output/public/_nuxt/builds/meta/6364d5cf-4642-479f-ba12-6440c56702af.json +1 -0
  51. package/.output/public/_nuxt/default.DixIpIal.css +1 -0
  52. package/.output/public/_nuxt/entry.GqPNPe1e.css +1 -0
  53. package/.output/public/_nuxt/index.CrXmf4gr.css +1 -0
  54. package/.output/public/_nuxt/ivUnXl9B.js +1 -0
  55. package/.output/public/_nuxt/pAheHeBV.js +36 -0
  56. package/.output/public/_nuxt/s5fCn4j5.js +1 -0
  57. package/.output/public/favicon.ico +0 -0
  58. package/.output/public/logo.png +0 -0
  59. package/.output/public/manifest.json +25 -0
  60. package/.output/public/robots.txt +1 -0
  61. package/.output/public/vite.svg +1 -0
  62. package/.output/server/chunks/_/error-500.mjs +8 -0
  63. package/.output/server/chunks/_/error-500.mjs.map +1 -0
  64. package/.output/server/chunks/build/client.manifest.mjs +773 -0
  65. package/.output/server/chunks/build/client.manifest.mjs.map +1 -0
  66. package/.output/server/chunks/nitro/nitro.mjs +6432 -0
  67. package/.output/server/chunks/nitro/nitro.mjs.map +1 -0
  68. package/.output/server/chunks/routes/api/ai/chat.mjs +77 -0
  69. package/.output/server/chunks/routes/api/ai/chat.mjs.map +1 -0
  70. package/.output/server/chunks/routes/api/execute-bulk-delete.mjs +100 -0
  71. package/.output/server/chunks/routes/api/execute-bulk-delete.mjs.map +1 -0
  72. package/.output/server/chunks/routes/api/execute-bulk-update.mjs +105 -0
  73. package/.output/server/chunks/routes/api/execute-bulk-update.mjs.map +1 -0
  74. package/.output/server/chunks/routes/api/execute.mjs +47 -0
  75. package/.output/server/chunks/routes/api/execute.mjs.map +1 -0
  76. package/.output/server/chunks/routes/api/get-one-function.mjs +28 -0
  77. package/.output/server/chunks/routes/api/get-one-function.mjs.map +1 -0
  78. package/.output/server/chunks/routes/api/get-one-table.mjs +180 -0
  79. package/.output/server/chunks/routes/api/get-one-table.mjs.map +1 -0
  80. package/.output/server/chunks/routes/api/get-over-view-function.mjs +41 -0
  81. package/.output/server/chunks/routes/api/get-over-view-function.mjs.map +1 -0
  82. package/.output/server/chunks/routes/api/get-over-view-tables.mjs +53 -0
  83. package/.output/server/chunks/routes/api/get-over-view-tables.mjs.map +1 -0
  84. package/.output/server/chunks/routes/api/get-reverse-table-schemas.mjs +112 -0
  85. package/.output/server/chunks/routes/api/get-reverse-table-schemas.mjs.map +1 -0
  86. package/.output/server/chunks/routes/api/get-schema-meta-data.mjs +152 -0
  87. package/.output/server/chunks/routes/api/get-schema-meta-data.mjs.map +1 -0
  88. package/.output/server/chunks/routes/api/get-table-size.mjs +49 -0
  89. package/.output/server/chunks/routes/api/get-table-size.mjs.map +1 -0
  90. package/.output/server/chunks/routes/api/get-table-structure.mjs +111 -0
  91. package/.output/server/chunks/routes/api/get-table-structure.mjs.map +1 -0
  92. package/.output/server/chunks/routes/api/get-tables.mjs +287 -0
  93. package/.output/server/chunks/routes/api/get-tables.mjs.map +1 -0
  94. package/.output/server/chunks/routes/api/getMetricMonitor.mjs +46 -0
  95. package/.output/server/chunks/routes/api/getMetricMonitor.mjs.map +1 -0
  96. package/.output/server/chunks/routes/api/managment-connection/health-check.mjs +28 -0
  97. package/.output/server/chunks/routes/api/managment-connection/health-check.mjs.map +1 -0
  98. package/.output/server/chunks/routes/api/raw-execute.mjs +48 -0
  99. package/.output/server/chunks/routes/api/raw-execute.mjs.map +1 -0
  100. package/.output/server/chunks/routes/renderer.mjs +316 -0
  101. package/.output/server/chunks/routes/renderer.mjs.map +1 -0
  102. package/.output/server/chunks/virtual/_virtual_spa-template.mjs +4 -0
  103. package/.output/server/chunks/virtual/_virtual_spa-template.mjs.map +1 -0
  104. package/.output/server/index.mjs +14 -0
  105. package/.output/server/index.mjs.map +1 -0
  106. package/.output/server/node_modules/@ai-sdk/anthropic/dist/index.mjs +4374 -0
  107. package/.output/server/node_modules/@ai-sdk/anthropic/package.json +74 -0
  108. package/.output/server/node_modules/@ai-sdk/gateway/dist/index.mjs +1082 -0
  109. package/.output/server/node_modules/@ai-sdk/gateway/package.json +69 -0
  110. package/.output/server/node_modules/@ai-sdk/google/dist/index.mjs +2007 -0
  111. package/.output/server/node_modules/@ai-sdk/google/package.json +74 -0
  112. package/.output/server/node_modules/@ai-sdk/openai/dist/index.mjs +5956 -0
  113. package/.output/server/node_modules/@ai-sdk/openai/package.json +74 -0
  114. package/.output/server/node_modules/@ai-sdk/openai-compatible/dist/index.mjs +1551 -0
  115. package/.output/server/node_modules/@ai-sdk/openai-compatible/package.json +74 -0
  116. package/.output/server/node_modules/@ai-sdk/provider/dist/index.mjs +377 -0
  117. package/.output/server/node_modules/@ai-sdk/provider/package.json +57 -0
  118. package/.output/server/node_modules/@ai-sdk/provider-utils/dist/index.mjs +2549 -0
  119. package/.output/server/node_modules/@ai-sdk/provider-utils/package.json +75 -0
  120. package/.output/server/node_modules/@ai-sdk/xai/dist/index.mjs +2214 -0
  121. package/.output/server/node_modules/@ai-sdk/xai/package.json +68 -0
  122. package/.output/server/node_modules/@babel/parser/lib/index.js +14246 -0
  123. package/.output/server/node_modules/@babel/parser/package.json +50 -0
  124. package/.output/server/node_modules/@iconify/utils/lib/colors/index.mjs +350 -0
  125. package/.output/server/node_modules/@iconify/utils/lib/colors/keywords.mjs +188 -0
  126. package/.output/server/node_modules/@iconify/utils/lib/css/common.mjs +90 -0
  127. package/.output/server/node_modules/@iconify/utils/lib/css/format.mjs +38 -0
  128. package/.output/server/node_modules/@iconify/utils/lib/css/icon.mjs +76 -0
  129. package/.output/server/node_modules/@iconify/utils/lib/css/icons.mjs +168 -0
  130. package/.output/server/node_modules/@iconify/utils/lib/customisations/bool.mjs +22 -0
  131. package/.output/server/node_modules/@iconify/utils/lib/customisations/defaults.mjs +14 -0
  132. package/.output/server/node_modules/@iconify/utils/lib/customisations/flip.mjs +16 -0
  133. package/.output/server/node_modules/@iconify/utils/lib/customisations/merge.mjs +22 -0
  134. package/.output/server/node_modules/@iconify/utils/lib/customisations/rotate.mjs +33 -0
  135. package/.output/server/node_modules/@iconify/utils/lib/emoji/cleanup.mjs +51 -0
  136. package/.output/server/node_modules/@iconify/utils/lib/emoji/convert.mjs +84 -0
  137. package/.output/server/node_modules/@iconify/utils/lib/emoji/data.mjs +16 -0
  138. package/.output/server/node_modules/@iconify/utils/lib/emoji/format.mjs +44 -0
  139. package/.output/server/node_modules/@iconify/utils/lib/emoji/parse.mjs +58 -0
  140. package/.output/server/node_modules/@iconify/utils/lib/emoji/regex/base.mjs +231 -0
  141. package/.output/server/node_modules/@iconify/utils/lib/emoji/regex/create.mjs +31 -0
  142. package/.output/server/node_modules/@iconify/utils/lib/emoji/regex/numbers.mjs +164 -0
  143. package/.output/server/node_modules/@iconify/utils/lib/emoji/regex/similar.mjs +216 -0
  144. package/.output/server/node_modules/@iconify/utils/lib/emoji/regex/tree.mjs +113 -0
  145. package/.output/server/node_modules/@iconify/utils/lib/emoji/replace/find.mjs +104 -0
  146. package/.output/server/node_modules/@iconify/utils/lib/emoji/replace/replace.mjs +34 -0
  147. package/.output/server/node_modules/@iconify/utils/lib/emoji/test/components.mjs +75 -0
  148. package/.output/server/node_modules/@iconify/utils/lib/emoji/test/missing.mjs +97 -0
  149. package/.output/server/node_modules/@iconify/utils/lib/emoji/test/name.mjs +54 -0
  150. package/.output/server/node_modules/@iconify/utils/lib/emoji/test/parse.mjs +97 -0
  151. package/.output/server/node_modules/@iconify/utils/lib/emoji/test/similar.mjs +45 -0
  152. package/.output/server/node_modules/@iconify/utils/lib/emoji/test/tree.mjs +105 -0
  153. package/.output/server/node_modules/@iconify/utils/lib/emoji/test/variations.mjs +54 -0
  154. package/.output/server/node_modules/@iconify/utils/lib/icon/defaults.mjs +24 -0
  155. package/.output/server/node_modules/@iconify/utils/lib/icon/merge.mjs +20 -0
  156. package/.output/server/node_modules/@iconify/utils/lib/icon/name.mjs +53 -0
  157. package/.output/server/node_modules/@iconify/utils/lib/icon/square.mjs +23 -0
  158. package/.output/server/node_modules/@iconify/utils/lib/icon/transformations.mjs +16 -0
  159. package/.output/server/node_modules/@iconify/utils/lib/icon-set/convert-info.mjs +182 -0
  160. package/.output/server/node_modules/@iconify/utils/lib/icon-set/expand.mjs +22 -0
  161. package/.output/server/node_modules/@iconify/utils/lib/icon-set/get-icon.mjs +28 -0
  162. package/.output/server/node_modules/@iconify/utils/lib/icon-set/get-icons.mjs +46 -0
  163. package/.output/server/node_modules/@iconify/utils/lib/icon-set/minify.mjs +66 -0
  164. package/.output/server/node_modules/@iconify/utils/lib/icon-set/parse.mjs +51 -0
  165. package/.output/server/node_modules/@iconify/utils/lib/icon-set/tree.mjs +23 -0
  166. package/.output/server/node_modules/@iconify/utils/lib/icon-set/validate-basic.mjs +62 -0
  167. package/.output/server/node_modules/@iconify/utils/lib/icon-set/validate.mjs +161 -0
  168. package/.output/server/node_modules/@iconify/utils/lib/index.mjs +64 -0
  169. package/.output/server/node_modules/@iconify/utils/lib/loader/custom.mjs +50 -0
  170. package/.output/server/node_modules/@iconify/utils/lib/loader/loader.mjs +59 -0
  171. package/.output/server/node_modules/@iconify/utils/lib/loader/modern.mjs +80 -0
  172. package/.output/server/node_modules/@iconify/utils/lib/loader/utils.mjs +92 -0
  173. package/.output/server/node_modules/@iconify/utils/lib/misc/objects.mjs +30 -0
  174. package/.output/server/node_modules/@iconify/utils/lib/misc/strings.mjs +17 -0
  175. package/.output/server/node_modules/@iconify/utils/lib/misc/title.mjs +5 -0
  176. package/.output/server/node_modules/@iconify/utils/lib/svg/build.mjs +119 -0
  177. package/.output/server/node_modules/@iconify/utils/lib/svg/defs.mjs +30 -0
  178. package/.output/server/node_modules/@iconify/utils/lib/svg/encode-svg-for-css.mjs +20 -0
  179. package/.output/server/node_modules/@iconify/utils/lib/svg/html.mjs +9 -0
  180. package/.output/server/node_modules/@iconify/utils/lib/svg/id.mjs +28 -0
  181. package/.output/server/node_modules/@iconify/utils/lib/svg/inner-html.mjs +19 -0
  182. package/.output/server/node_modules/@iconify/utils/lib/svg/parse.mjs +83 -0
  183. package/.output/server/node_modules/@iconify/utils/lib/svg/pretty.mjs +70 -0
  184. package/.output/server/node_modules/@iconify/utils/lib/svg/size.mjs +40 -0
  185. package/.output/server/node_modules/@iconify/utils/lib/svg/trim.mjs +5 -0
  186. package/.output/server/node_modules/@iconify/utils/lib/svg/url.mjs +11 -0
  187. package/.output/server/node_modules/@iconify/utils/lib/svg/viewbox.mjs +8 -0
  188. package/.output/server/node_modules/@iconify/utils/package.json +447 -0
  189. package/.output/server/node_modules/@ioredis/commands/built/commands.json +2447 -0
  190. package/.output/server/node_modules/@ioredis/commands/built/index.js +208 -0
  191. package/.output/server/node_modules/@ioredis/commands/package.json +52 -0
  192. package/.output/server/node_modules/@opentelemetry/api/build/src/api/context.js +81 -0
  193. package/.output/server/node_modules/@opentelemetry/api/build/src/api/diag.js +93 -0
  194. package/.output/server/node_modules/@opentelemetry/api/build/src/api/metrics.js +61 -0
  195. package/.output/server/node_modules/@opentelemetry/api/build/src/api/propagation.js +89 -0
  196. package/.output/server/node_modules/@opentelemetry/api/build/src/api/trace.js +79 -0
  197. package/.output/server/node_modules/@opentelemetry/api/build/src/baggage/context-helpers.js +63 -0
  198. package/.output/server/node_modules/@opentelemetry/api/build/src/baggage/internal/baggage-impl.js +55 -0
  199. package/.output/server/node_modules/@opentelemetry/api/build/src/baggage/internal/symbol.js +23 -0
  200. package/.output/server/node_modules/@opentelemetry/api/build/src/baggage/utils.js +51 -0
  201. package/.output/server/node_modules/@opentelemetry/api/build/src/context/NoopContextManager.js +38 -0
  202. package/.output/server/node_modules/@opentelemetry/api/build/src/context/context.js +55 -0
  203. package/.output/server/node_modules/@opentelemetry/api/build/src/context-api.js +24 -0
  204. package/.output/server/node_modules/@opentelemetry/api/build/src/diag/ComponentLogger.js +59 -0
  205. package/.output/server/node_modules/@opentelemetry/api/build/src/diag/consoleLogger.js +57 -0
  206. package/.output/server/node_modules/@opentelemetry/api/build/src/diag/internal/logLevelLogger.js +45 -0
  207. package/.output/server/node_modules/@opentelemetry/api/build/src/diag/types.js +44 -0
  208. package/.output/server/node_modules/@opentelemetry/api/build/src/diag-api.js +29 -0
  209. package/.output/server/node_modules/@opentelemetry/api/build/src/index.js +81 -0
  210. package/.output/server/node_modules/@opentelemetry/api/build/src/internal/global-utils.js +64 -0
  211. package/.output/server/node_modules/@opentelemetry/api/build/src/internal/semver.js +122 -0
  212. package/.output/server/node_modules/@opentelemetry/api/build/src/metrics/Metric.js +25 -0
  213. package/.output/server/node_modules/@opentelemetry/api/build/src/metrics/NoopMeter.js +127 -0
  214. package/.output/server/node_modules/@opentelemetry/api/build/src/metrics/NoopMeterProvider.js +31 -0
  215. package/.output/server/node_modules/@opentelemetry/api/build/src/metrics-api.js +24 -0
  216. package/.output/server/node_modules/@opentelemetry/api/build/src/platform/index.js +29 -0
  217. package/.output/server/node_modules/@opentelemetry/api/build/src/platform/node/globalThis.js +22 -0
  218. package/.output/server/node_modules/@opentelemetry/api/build/src/platform/node/index.js +29 -0
  219. package/.output/server/node_modules/@opentelemetry/api/build/src/propagation/NoopTextMapPropagator.js +34 -0
  220. package/.output/server/node_modules/@opentelemetry/api/build/src/propagation/TextMapPropagator.js +41 -0
  221. package/.output/server/node_modules/@opentelemetry/api/build/src/propagation-api.js +24 -0
  222. package/.output/server/node_modules/@opentelemetry/api/build/src/trace/NonRecordingSpan.js +69 -0
  223. package/.output/server/node_modules/@opentelemetry/api/build/src/trace/NoopTracer.js +75 -0
  224. package/.output/server/node_modules/@opentelemetry/api/build/src/trace/NoopTracerProvider.js +32 -0
  225. package/.output/server/node_modules/@opentelemetry/api/build/src/trace/ProxyTracer.js +55 -0
  226. package/.output/server/node_modules/@opentelemetry/api/build/src/trace/ProxyTracerProvider.js +54 -0
  227. package/.output/server/node_modules/@opentelemetry/api/build/src/trace/SamplingResult.js +42 -0
  228. package/.output/server/node_modules/@opentelemetry/api/build/src/trace/context-utils.js +82 -0
  229. package/.output/server/node_modules/@opentelemetry/api/build/src/trace/internal/tracestate-impl.js +103 -0
  230. package/.output/server/node_modules/@opentelemetry/api/build/src/trace/internal/tracestate-validators.js +46 -0
  231. package/.output/server/node_modules/@opentelemetry/api/build/src/trace/internal/utils.js +24 -0
  232. package/.output/server/node_modules/@opentelemetry/api/build/src/trace/invalid-span-constants.js +27 -0
  233. package/.output/server/node_modules/@opentelemetry/api/build/src/trace/span_kind.js +46 -0
  234. package/.output/server/node_modules/@opentelemetry/api/build/src/trace/spancontext-utils.js +49 -0
  235. package/.output/server/node_modules/@opentelemetry/api/build/src/trace/status.js +23 -0
  236. package/.output/server/node_modules/@opentelemetry/api/build/src/trace/trace_flags.js +26 -0
  237. package/.output/server/node_modules/@opentelemetry/api/build/src/trace-api.js +24 -0
  238. package/.output/server/node_modules/@opentelemetry/api/build/src/version.js +21 -0
  239. package/.output/server/node_modules/@opentelemetry/api/package.json +113 -0
  240. package/.output/server/node_modules/@sqltools/formatter/lib/core/Formatter.js +234 -0
  241. package/.output/server/node_modules/@sqltools/formatter/lib/core/Indentation.js +42 -0
  242. package/.output/server/node_modules/@sqltools/formatter/lib/core/InlineBlock.js +60 -0
  243. package/.output/server/node_modules/@sqltools/formatter/lib/core/Params.js +21 -0
  244. package/.output/server/node_modules/@sqltools/formatter/lib/core/Tokenizer.js +272 -0
  245. package/.output/server/node_modules/@sqltools/formatter/lib/core/escapeRegExp.js +10 -0
  246. package/.output/server/node_modules/@sqltools/formatter/lib/core/last.js +7 -0
  247. package/.output/server/node_modules/@sqltools/formatter/lib/core/types.js +22 -0
  248. package/.output/server/node_modules/@sqltools/formatter/lib/languages/Db2Formatter.js +585 -0
  249. package/.output/server/node_modules/@sqltools/formatter/lib/languages/N1qlFormatter.js +257 -0
  250. package/.output/server/node_modules/@sqltools/formatter/lib/languages/PlSqlFormatter.js +459 -0
  251. package/.output/server/node_modules/@sqltools/formatter/lib/languages/StandardSqlFormatter.js +369 -0
  252. package/.output/server/node_modules/@sqltools/formatter/lib/languages/utils/abstract.js +23 -0
  253. package/.output/server/node_modules/@sqltools/formatter/lib/sqlFormatter.js +34 -0
  254. package/.output/server/node_modules/@sqltools/formatter/package.json +59 -0
  255. package/.output/server/node_modules/@standard-schema/spec/dist/index.js +0 -0
  256. package/.output/server/node_modules/@standard-schema/spec/package.json +52 -0
  257. package/.output/server/node_modules/@vercel/oidc/dist/auth-config.js +84 -0
  258. package/.output/server/node_modules/@vercel/oidc/dist/get-context.js +34 -0
  259. package/.output/server/node_modules/@vercel/oidc/dist/get-vercel-oidc-token.js +80 -0
  260. package/.output/server/node_modules/@vercel/oidc/dist/index.js +33 -0
  261. package/.output/server/node_modules/@vercel/oidc/dist/oauth.js +88 -0
  262. package/.output/server/node_modules/@vercel/oidc/dist/token-error.js +40 -0
  263. package/.output/server/node_modules/@vercel/oidc/dist/token-io.js +78 -0
  264. package/.output/server/node_modules/@vercel/oidc/dist/token-util.js +198 -0
  265. package/.output/server/node_modules/@vercel/oidc/dist/token.js +53 -0
  266. package/.output/server/node_modules/@vercel/oidc/package.json +52 -0
  267. package/.output/server/node_modules/@vue/compiler-core/dist/compiler-core.cjs.prod.js +6690 -0
  268. package/.output/server/node_modules/@vue/compiler-core/package.json +58 -0
  269. package/.output/server/node_modules/@vue/compiler-dom/dist/compiler-dom.cjs.prod.js +686 -0
  270. package/.output/server/node_modules/@vue/compiler-dom/package.json +57 -0
  271. package/.output/server/node_modules/@vue/compiler-ssr/dist/compiler-ssr.cjs.js +1404 -0
  272. package/.output/server/node_modules/@vue/compiler-ssr/package.json +34 -0
  273. package/.output/server/node_modules/@vue/reactivity/dist/reactivity.cjs.prod.js +1789 -0
  274. package/.output/server/node_modules/@vue/reactivity/package.json +55 -0
  275. package/.output/server/node_modules/@vue/runtime-core/dist/runtime-core.cjs.prod.js +6654 -0
  276. package/.output/server/node_modules/@vue/runtime-core/package.json +52 -0
  277. package/.output/server/node_modules/@vue/runtime-dom/dist/runtime-dom.cjs.prod.js +1669 -0
  278. package/.output/server/node_modules/@vue/runtime-dom/package.json +60 -0
  279. package/.output/server/node_modules/@vue/server-renderer/dist/server-renderer.cjs.prod.js +857 -0
  280. package/.output/server/node_modules/@vue/server-renderer/package.json +55 -0
  281. package/.output/server/node_modules/@vue/shared/dist/shared.cjs.prod.js +594 -0
  282. package/.output/server/node_modules/@vue/shared/package.json +47 -0
  283. package/.output/server/node_modules/ai/dist/index.mjs +12363 -0
  284. package/.output/server/node_modules/ai/package.json +106 -0
  285. package/.output/server/node_modules/ansis/index.js +1 -0
  286. package/.output/server/node_modules/ansis/package.json +28 -0
  287. package/.output/server/node_modules/app-root-path/index.js +4 -0
  288. package/.output/server/node_modules/app-root-path/lib/app-root-path.js +30 -0
  289. package/.output/server/node_modules/app-root-path/lib/resolve.js +128 -0
  290. package/.output/server/node_modules/app-root-path/package.json +66 -0
  291. package/.output/server/node_modules/balanced-match/index.js +62 -0
  292. package/.output/server/node_modules/balanced-match/package.json +48 -0
  293. package/.output/server/node_modules/bindings/bindings.js +221 -0
  294. package/.output/server/node_modules/bindings/package.json +28 -0
  295. package/.output/server/node_modules/brace-expansion/index.js +203 -0
  296. package/.output/server/node_modules/brace-expansion/package.json +46 -0
  297. package/.output/server/node_modules/cluster-key-slot/lib/index.js +166 -0
  298. package/.output/server/node_modules/cluster-key-slot/package.json +56 -0
  299. package/.output/server/node_modules/consola/dist/chunks/prompt.mjs +280 -0
  300. package/.output/server/node_modules/consola/dist/core.mjs +512 -0
  301. package/.output/server/node_modules/consola/dist/index.mjs +651 -0
  302. package/.output/server/node_modules/consola/dist/shared/consola.DRwqZj3T.mjs +72 -0
  303. package/.output/server/node_modules/consola/dist/shared/consola.DXBYu-KD.mjs +288 -0
  304. package/.output/server/node_modules/consola/package.json +136 -0
  305. package/.output/server/node_modules/dayjs/dayjs.min.js +1 -0
  306. package/.output/server/node_modules/dayjs/package.json +84 -0
  307. package/.output/server/node_modules/debug/package.json +65 -0
  308. package/.output/server/node_modules/debug/src/browser.js +272 -0
  309. package/.output/server/node_modules/debug/src/common.js +292 -0
  310. package/.output/server/node_modules/debug/src/index.js +10 -0
  311. package/.output/server/node_modules/debug/src/node.js +263 -0
  312. package/.output/server/node_modules/dedent/dist/dedent.js +73 -0
  313. package/.output/server/node_modules/dedent/package.json +119 -0
  314. package/.output/server/node_modules/denque/index.js +481 -0
  315. package/.output/server/node_modules/denque/package.json +58 -0
  316. package/.output/server/node_modules/devalue/index.js +3 -0
  317. package/.output/server/node_modules/devalue/package.json +34 -0
  318. package/.output/server/node_modules/devalue/src/base64.js +110 -0
  319. package/.output/server/node_modules/devalue/src/constants.js +6 -0
  320. package/.output/server/node_modules/devalue/src/parse.js +160 -0
  321. package/.output/server/node_modules/devalue/src/stringify.js +232 -0
  322. package/.output/server/node_modules/devalue/src/uneval.js +351 -0
  323. package/.output/server/node_modules/devalue/src/utils.js +113 -0
  324. package/.output/server/node_modules/dotenv/lib/main.js +361 -0
  325. package/.output/server/node_modules/dotenv/package.json +61 -0
  326. package/.output/server/node_modules/entities/lib/decode.js +536 -0
  327. package/.output/server/node_modules/entities/lib/decode_codepoint.js +76 -0
  328. package/.output/server/node_modules/entities/lib/generated/decode-data-html.js +9 -0
  329. package/.output/server/node_modules/entities/lib/generated/decode-data-xml.js +9 -0
  330. package/.output/server/node_modules/entities/package.json +90 -0
  331. package/.output/server/node_modules/estree-walker/dist/umd/estree-walker.js +344 -0
  332. package/.output/server/node_modules/estree-walker/package.json +37 -0
  333. package/.output/server/node_modules/eventsource-parser/dist/index.js +106 -0
  334. package/.output/server/node_modules/eventsource-parser/dist/stream.js +29 -0
  335. package/.output/server/node_modules/eventsource-parser/package.json +115 -0
  336. package/.output/server/node_modules/file-uri-to-path/index.js +66 -0
  337. package/.output/server/node_modules/file-uri-to-path/package.json +32 -0
  338. package/.output/server/node_modules/glob/dist/commonjs/glob.js +247 -0
  339. package/.output/server/node_modules/glob/dist/commonjs/has-magic.js +27 -0
  340. package/.output/server/node_modules/glob/dist/commonjs/ignore.js +119 -0
  341. package/.output/server/node_modules/glob/dist/commonjs/index.js +68 -0
  342. package/.output/server/node_modules/glob/dist/commonjs/package.json +3 -0
  343. package/.output/server/node_modules/glob/dist/commonjs/pattern.js +219 -0
  344. package/.output/server/node_modules/glob/dist/commonjs/processor.js +301 -0
  345. package/.output/server/node_modules/glob/dist/commonjs/walker.js +387 -0
  346. package/.output/server/node_modules/glob/package.json +99 -0
  347. package/.output/server/node_modules/has-flag/index.js +8 -0
  348. package/.output/server/node_modules/has-flag/package.json +46 -0
  349. package/.output/server/node_modules/hookable/dist/index.mjs +290 -0
  350. package/.output/server/node_modules/hookable/package.json +49 -0
  351. package/.output/server/node_modules/inherits/inherits.js +9 -0
  352. package/.output/server/node_modules/inherits/inherits_browser.js +27 -0
  353. package/.output/server/node_modules/inherits/package.json +29 -0
  354. package/.output/server/node_modules/ioredis/built/Command.js +349 -0
  355. package/.output/server/node_modules/ioredis/built/DataHandler.js +220 -0
  356. package/.output/server/node_modules/ioredis/built/Pipeline.js +334 -0
  357. package/.output/server/node_modules/ioredis/built/Redis.js +697 -0
  358. package/.output/server/node_modules/ioredis/built/ScanStream.js +51 -0
  359. package/.output/server/node_modules/ioredis/built/Script.js +62 -0
  360. package/.output/server/node_modules/ioredis/built/SubscriptionSet.js +41 -0
  361. package/.output/server/node_modules/ioredis/built/autoPipelining.js +159 -0
  362. package/.output/server/node_modules/ioredis/built/cluster/ClusterOptions.js +22 -0
  363. package/.output/server/node_modules/ioredis/built/cluster/ClusterSubscriber.js +202 -0
  364. package/.output/server/node_modules/ioredis/built/cluster/ClusterSubscriberGroup.js +224 -0
  365. package/.output/server/node_modules/ioredis/built/cluster/ConnectionPool.js +154 -0
  366. package/.output/server/node_modules/ioredis/built/cluster/DelayQueue.js +53 -0
  367. package/.output/server/node_modules/ioredis/built/cluster/index.js +862 -0
  368. package/.output/server/node_modules/ioredis/built/cluster/util.js +100 -0
  369. package/.output/server/node_modules/ioredis/built/connectors/AbstractConnector.js +26 -0
  370. package/.output/server/node_modules/ioredis/built/connectors/SentinelConnector/FailoverDetector.js +45 -0
  371. package/.output/server/node_modules/ioredis/built/connectors/SentinelConnector/SentinelIterator.js +37 -0
  372. package/.output/server/node_modules/ioredis/built/connectors/SentinelConnector/index.js +305 -0
  373. package/.output/server/node_modules/ioredis/built/connectors/StandaloneConnector.js +69 -0
  374. package/.output/server/node_modules/ioredis/built/connectors/index.js +7 -0
  375. package/.output/server/node_modules/ioredis/built/constants/TLSProfiles.js +149 -0
  376. package/.output/server/node_modules/ioredis/built/errors/ClusterAllFailedError.js +15 -0
  377. package/.output/server/node_modules/ioredis/built/errors/MaxRetriesPerRequestError.js +14 -0
  378. package/.output/server/node_modules/ioredis/built/errors/index.js +5 -0
  379. package/.output/server/node_modules/ioredis/built/index.js +62 -0
  380. package/.output/server/node_modules/ioredis/built/redis/RedisOptions.js +55 -0
  381. package/.output/server/node_modules/ioredis/built/redis/event_handler.js +292 -0
  382. package/.output/server/node_modules/ioredis/built/transaction.js +93 -0
  383. package/.output/server/node_modules/ioredis/built/utils/Commander.js +117 -0
  384. package/.output/server/node_modules/ioredis/built/utils/applyMixin.js +8 -0
  385. package/.output/server/node_modules/ioredis/built/utils/debug.js +95 -0
  386. package/.output/server/node_modules/ioredis/built/utils/index.js +297 -0
  387. package/.output/server/node_modules/ioredis/built/utils/lodash.js +9 -0
  388. package/.output/server/node_modules/ioredis/package.json +100 -0
  389. package/.output/server/node_modules/lodash.defaults/index.js +668 -0
  390. package/.output/server/node_modules/lodash.defaults/package.json +19 -0
  391. package/.output/server/node_modules/lodash.isarguments/index.js +229 -0
  392. package/.output/server/node_modules/lodash.isarguments/package.json +19 -0
  393. package/.output/server/node_modules/lru-cache/dist/commonjs/index.js +1546 -0
  394. package/.output/server/node_modules/lru-cache/dist/commonjs/package.json +3 -0
  395. package/.output/server/node_modules/lru-cache/package.json +116 -0
  396. package/.output/server/node_modules/minimatch/dist/commonjs/assert-valid-pattern.js +14 -0
  397. package/.output/server/node_modules/minimatch/dist/commonjs/ast.js +592 -0
  398. package/.output/server/node_modules/minimatch/dist/commonjs/brace-expressions.js +152 -0
  399. package/.output/server/node_modules/minimatch/dist/commonjs/escape.js +22 -0
  400. package/.output/server/node_modules/minimatch/dist/commonjs/index.js +1017 -0
  401. package/.output/server/node_modules/minimatch/dist/commonjs/package.json +3 -0
  402. package/.output/server/node_modules/minimatch/dist/commonjs/unescape.js +24 -0
  403. package/.output/server/node_modules/minimatch/package.json +82 -0
  404. package/.output/server/node_modules/minipass/dist/commonjs/index.js +1028 -0
  405. package/.output/server/node_modules/minipass/dist/commonjs/package.json +3 -0
  406. package/.output/server/node_modules/minipass/package.json +82 -0
  407. package/.output/server/node_modules/ms/index.js +162 -0
  408. package/.output/server/node_modules/ms/package.json +38 -0
  409. package/.output/server/node_modules/path-scurry/dist/commonjs/index.js +2014 -0
  410. package/.output/server/node_modules/path-scurry/dist/commonjs/package.json +3 -0
  411. package/.output/server/node_modules/path-scurry/package.json +89 -0
  412. package/.output/server/node_modules/pg/lib/client.js +650 -0
  413. package/.output/server/node_modules/pg/lib/connection-parameters.js +167 -0
  414. package/.output/server/node_modules/pg/lib/connection.js +222 -0
  415. package/.output/server/node_modules/pg/lib/crypto/cert-signatures.js +121 -0
  416. package/.output/server/node_modules/pg/lib/crypto/sasl.js +212 -0
  417. package/.output/server/node_modules/pg/lib/crypto/utils-legacy.js +43 -0
  418. package/.output/server/node_modules/pg/lib/crypto/utils-webcrypto.js +88 -0
  419. package/.output/server/node_modules/pg/lib/crypto/utils.js +9 -0
  420. package/.output/server/node_modules/pg/lib/defaults.js +84 -0
  421. package/.output/server/node_modules/pg/lib/index.js +58 -0
  422. package/.output/server/node_modules/pg/lib/native/client.js +307 -0
  423. package/.output/server/node_modules/pg/lib/native/index.js +2 -0
  424. package/.output/server/node_modules/pg/lib/native/query.js +168 -0
  425. package/.output/server/node_modules/pg/lib/query.js +253 -0
  426. package/.output/server/node_modules/pg/lib/result.js +108 -0
  427. package/.output/server/node_modules/pg/lib/stream.js +81 -0
  428. package/.output/server/node_modules/pg/lib/type-overrides.js +35 -0
  429. package/.output/server/node_modules/pg/lib/utils.js +206 -0
  430. package/.output/server/node_modules/pg/package.json +62 -0
  431. package/.output/server/node_modules/pg-cloudflare/dist/empty.js +4 -0
  432. package/.output/server/node_modules/pg-cloudflare/package.json +32 -0
  433. package/.output/server/node_modules/pg-connection-string/index.js +112 -0
  434. package/.output/server/node_modules/pg-connection-string/package.json +40 -0
  435. package/.output/server/node_modules/pg-cursor/index.js +265 -0
  436. package/.output/server/node_modules/pg-cursor/package.json +38 -0
  437. package/.output/server/node_modules/pg-int8/index.js +100 -0
  438. package/.output/server/node_modules/pg-int8/package.json +24 -0
  439. package/.output/server/node_modules/pg-pool/index.js +471 -0
  440. package/.output/server/node_modules/pg-pool/package.json +41 -0
  441. package/.output/server/node_modules/pg-protocol/dist/buffer-reader.js +55 -0
  442. package/.output/server/node_modules/pg-protocol/dist/buffer-writer.js +81 -0
  443. package/.output/server/node_modules/pg-protocol/dist/index.js +15 -0
  444. package/.output/server/node_modules/pg-protocol/dist/messages.js +160 -0
  445. package/.output/server/node_modules/pg-protocol/dist/parser.js +304 -0
  446. package/.output/server/node_modules/pg-protocol/dist/serializer.js +189 -0
  447. package/.output/server/node_modules/pg-protocol/package.json +35 -0
  448. package/.output/server/node_modules/pg-query-stream/dist/index.js +48 -0
  449. package/.output/server/node_modules/pg-query-stream/package.json +60 -0
  450. package/.output/server/node_modules/pg-types/index.js +47 -0
  451. package/.output/server/node_modules/pg-types/lib/arrayParser.js +11 -0
  452. package/.output/server/node_modules/pg-types/lib/binaryParsers.js +257 -0
  453. package/.output/server/node_modules/pg-types/lib/builtins.js +73 -0
  454. package/.output/server/node_modules/pg-types/lib/textParsers.js +215 -0
  455. package/.output/server/node_modules/pg-types/package.json +42 -0
  456. package/.output/server/node_modules/pgpass/lib/helper.js +233 -0
  457. package/.output/server/node_modules/pgpass/lib/index.js +23 -0
  458. package/.output/server/node_modules/pgpass/package.json +41 -0
  459. package/.output/server/node_modules/postgres-array/index.js +97 -0
  460. package/.output/server/node_modules/postgres-array/package.json +35 -0
  461. package/.output/server/node_modules/postgres-bytea/index.js +31 -0
  462. package/.output/server/node_modules/postgres-bytea/package.json +34 -0
  463. package/.output/server/node_modules/postgres-date/index.js +116 -0
  464. package/.output/server/node_modules/postgres-date/package.json +33 -0
  465. package/.output/server/node_modules/postgres-interval/index.js +125 -0
  466. package/.output/server/node_modules/postgres-interval/package.json +36 -0
  467. package/.output/server/node_modules/redis-errors/index.js +7 -0
  468. package/.output/server/node_modules/redis-errors/lib/modern.js +59 -0
  469. package/.output/server/node_modules/redis-errors/lib/old.js +119 -0
  470. package/.output/server/node_modules/redis-errors/package.json +41 -0
  471. package/.output/server/node_modules/redis-parser/index.js +3 -0
  472. package/.output/server/node_modules/redis-parser/lib/parser.js +552 -0
  473. package/.output/server/node_modules/redis-parser/package.json +53 -0
  474. package/.output/server/node_modules/reflect-metadata/Reflect.js +1415 -0
  475. package/.output/server/node_modules/reflect-metadata/package.json +68 -0
  476. package/.output/server/node_modules/safe-buffer/index.js +65 -0
  477. package/.output/server/node_modules/safe-buffer/package.json +51 -0
  478. package/.output/server/node_modules/sha.js/hash.js +81 -0
  479. package/.output/server/node_modules/sha.js/index.js +15 -0
  480. package/.output/server/node_modules/sha.js/package.json +30 -0
  481. package/.output/server/node_modules/sha.js/sha.js +94 -0
  482. package/.output/server/node_modules/sha.js/sha1.js +99 -0
  483. package/.output/server/node_modules/sha.js/sha224.js +53 -0
  484. package/.output/server/node_modules/sha.js/sha256.js +135 -0
  485. package/.output/server/node_modules/sha.js/sha384.js +57 -0
  486. package/.output/server/node_modules/sha.js/sha512.js +260 -0
  487. package/.output/server/node_modules/source-map-js/lib/array-set.js +121 -0
  488. package/.output/server/node_modules/source-map-js/lib/base64-vlq.js +140 -0
  489. package/.output/server/node_modules/source-map-js/lib/base64.js +67 -0
  490. package/.output/server/node_modules/source-map-js/lib/binary-search.js +111 -0
  491. package/.output/server/node_modules/source-map-js/lib/mapping-list.js +79 -0
  492. package/.output/server/node_modules/source-map-js/lib/quick-sort.js +132 -0
  493. package/.output/server/node_modules/source-map-js/lib/source-map-consumer.js +1188 -0
  494. package/.output/server/node_modules/source-map-js/lib/source-map-generator.js +444 -0
  495. package/.output/server/node_modules/source-map-js/lib/source-node.js +413 -0
  496. package/.output/server/node_modules/source-map-js/lib/util.js +594 -0
  497. package/.output/server/node_modules/source-map-js/package.json +71 -0
  498. package/.output/server/node_modules/source-map-js/source-map.js +8 -0
  499. package/.output/server/node_modules/split2/index.js +141 -0
  500. package/.output/server/node_modules/split2/package.json +39 -0
  501. package/.output/server/node_modules/sql-highlight/lib/escapeHtml.js +59 -0
  502. package/.output/server/node_modules/sql-highlight/lib/index.js +85 -0
  503. package/.output/server/node_modules/sql-highlight/lib/keywords.js +145 -0
  504. package/.output/server/node_modules/sql-highlight/package.json +49 -0
  505. package/.output/server/node_modules/sqlite3/build/Release/node_sqlite3.node +0 -0
  506. package/.output/server/node_modules/sqlite3/build/Release/node_sqlite3.node.bak +0 -0
  507. package/.output/server/node_modules/sqlite3/lib/sqlite3-binding.js +1 -0
  508. package/.output/server/node_modules/sqlite3/lib/sqlite3.js +207 -0
  509. package/.output/server/node_modules/sqlite3/lib/trace.js +38 -0
  510. package/.output/server/node_modules/sqlite3/package.json +89 -0
  511. package/.output/server/node_modules/standard-as-callback/built/index.js +41 -0
  512. package/.output/server/node_modules/standard-as-callback/built/utils.js +23 -0
  513. package/.output/server/node_modules/standard-as-callback/package.json +40 -0
  514. package/.output/server/node_modules/supports-color/index.js +152 -0
  515. package/.output/server/node_modules/supports-color/package.json +58 -0
  516. package/.output/server/node_modules/tslib/package.json +47 -0
  517. package/.output/server/node_modules/tslib/tslib.js +484 -0
  518. package/.output/server/node_modules/typeorm/cache/DbQueryResultCache.js +264 -0
  519. package/.output/server/node_modules/typeorm/cache/QueryResultCacheFactory.js +42 -0
  520. package/.output/server/node_modules/typeorm/cache/RedisQueryResultCache.js +197 -0
  521. package/.output/server/node_modules/typeorm/common/DeepPartial.js +4 -0
  522. package/.output/server/node_modules/typeorm/common/EntityTarget.js +4 -0
  523. package/.output/server/node_modules/typeorm/common/MixedList.js +4 -0
  524. package/.output/server/node_modules/typeorm/common/ObjectLiteral.js +4 -0
  525. package/.output/server/node_modules/typeorm/common/ObjectType.js +4 -0
  526. package/.output/server/node_modules/typeorm/common/RelationType.js +4 -0
  527. package/.output/server/node_modules/typeorm/connection/Connection.js +16 -0
  528. package/.output/server/node_modules/typeorm/connection/ConnectionManager.js +66 -0
  529. package/.output/server/node_modules/typeorm/connection/ConnectionMetadataBuilder.js +74 -0
  530. package/.output/server/node_modules/typeorm/connection/ConnectionOptionsReader.js +198 -0
  531. package/.output/server/node_modules/typeorm/connection/options-reader/ConnectionOptionsEnvReader.js +111 -0
  532. package/.output/server/node_modules/typeorm/container.js +60 -0
  533. package/.output/server/node_modules/typeorm/data-source/DataSource.js +517 -0
  534. package/.output/server/node_modules/typeorm/decorator/Check.js +27 -0
  535. package/.output/server/node_modules/typeorm/decorator/EntityRepository.js +21 -0
  536. package/.output/server/node_modules/typeorm/decorator/Exclusion.js +27 -0
  537. package/.output/server/node_modules/typeorm/decorator/ForeignKey.js +44 -0
  538. package/.output/server/node_modules/typeorm/decorator/Generated.js +24 -0
  539. package/.output/server/node_modules/typeorm/decorator/Index.js +56 -0
  540. package/.output/server/node_modules/typeorm/decorator/Unique.js +50 -0
  541. package/.output/server/node_modules/typeorm/decorator/columns/Column.js +78 -0
  542. package/.output/server/node_modules/typeorm/decorator/columns/CreateDateColumn.js +21 -0
  543. package/.output/server/node_modules/typeorm/decorator/columns/DeleteDateColumn.js +20 -0
  544. package/.output/server/node_modules/typeorm/decorator/columns/ObjectIdColumn.js +27 -0
  545. package/.output/server/node_modules/typeorm/decorator/columns/PrimaryColumn.js +63 -0
  546. package/.output/server/node_modules/typeorm/decorator/columns/PrimaryGeneratedColumn.js +59 -0
  547. package/.output/server/node_modules/typeorm/decorator/columns/UpdateDateColumn.js +20 -0
  548. package/.output/server/node_modules/typeorm/decorator/columns/VersionColumn.js +21 -0
  549. package/.output/server/node_modules/typeorm/decorator/columns/ViewColumn.js +19 -0
  550. package/.output/server/node_modules/typeorm/decorator/columns/VirtualColumn.js +49 -0
  551. package/.output/server/node_modules/typeorm/decorator/entity/ChildEntity.js +25 -0
  552. package/.output/server/node_modules/typeorm/decorator/entity/Entity.js +31 -0
  553. package/.output/server/node_modules/typeorm/decorator/entity/TableInheritance.js +22 -0
  554. package/.output/server/node_modules/typeorm/decorator/entity-view/ViewEntity.js +32 -0
  555. package/.output/server/node_modules/typeorm/decorator/listeners/AfterInsert.js +19 -0
  556. package/.output/server/node_modules/typeorm/decorator/listeners/AfterLoad.js +19 -0
  557. package/.output/server/node_modules/typeorm/decorator/listeners/AfterRecover.js +19 -0
  558. package/.output/server/node_modules/typeorm/decorator/listeners/AfterRemove.js +19 -0
  559. package/.output/server/node_modules/typeorm/decorator/listeners/AfterSoftRemove.js +19 -0
  560. package/.output/server/node_modules/typeorm/decorator/listeners/AfterUpdate.js +19 -0
  561. package/.output/server/node_modules/typeorm/decorator/listeners/BeforeInsert.js +19 -0
  562. package/.output/server/node_modules/typeorm/decorator/listeners/BeforeRecover.js +19 -0
  563. package/.output/server/node_modules/typeorm/decorator/listeners/BeforeRemove.js +19 -0
  564. package/.output/server/node_modules/typeorm/decorator/listeners/BeforeSoftRemove.js +19 -0
  565. package/.output/server/node_modules/typeorm/decorator/listeners/BeforeUpdate.js +19 -0
  566. package/.output/server/node_modules/typeorm/decorator/listeners/EventSubscriber.js +17 -0
  567. package/.output/server/node_modules/typeorm/decorator/options/ColumnOptions.js +4 -0
  568. package/.output/server/node_modules/typeorm/decorator/options/EntityOptions.js +4 -0
  569. package/.output/server/node_modules/typeorm/decorator/options/IndexOptions.js +4 -0
  570. package/.output/server/node_modules/typeorm/decorator/options/JoinColumnOptions.js +4 -0
  571. package/.output/server/node_modules/typeorm/decorator/options/JoinTableOptions.js +4 -0
  572. package/.output/server/node_modules/typeorm/decorator/options/RelationOptions.js +4 -0
  573. package/.output/server/node_modules/typeorm/decorator/options/ValueTransformer.js +4 -0
  574. package/.output/server/node_modules/typeorm/decorator/relations/JoinColumn.js +27 -0
  575. package/.output/server/node_modules/typeorm/decorator/relations/JoinTable.js +34 -0
  576. package/.output/server/node_modules/typeorm/decorator/relations/ManyToMany.js +46 -0
  577. package/.output/server/node_modules/typeorm/decorator/relations/ManyToOne.js +46 -0
  578. package/.output/server/node_modules/typeorm/decorator/relations/OneToMany.js +37 -0
  579. package/.output/server/node_modules/typeorm/decorator/relations/OneToOne.js +45 -0
  580. package/.output/server/node_modules/typeorm/decorator/relations/RelationCount.js +23 -0
  581. package/.output/server/node_modules/typeorm/decorator/relations/RelationId.js +22 -0
  582. package/.output/server/node_modules/typeorm/decorator/tree/Tree.js +21 -0
  583. package/.output/server/node_modules/typeorm/decorator/tree/TreeChildren.js +34 -0
  584. package/.output/server/node_modules/typeorm/decorator/tree/TreeLevelColumn.js +19 -0
  585. package/.output/server/node_modules/typeorm/decorator/tree/TreeParent.js +33 -0
  586. package/.output/server/node_modules/typeorm/driver/DriverFactory.js +98 -0
  587. package/.output/server/node_modules/typeorm/driver/DriverUtils.js +228 -0
  588. package/.output/server/node_modules/typeorm/driver/Query.js +16 -0
  589. package/.output/server/node_modules/typeorm/driver/SqlInMemory.js +15 -0
  590. package/.output/server/node_modules/typeorm/driver/aurora-mysql/AuroraMysqlDriver.js +847 -0
  591. package/.output/server/node_modules/typeorm/driver/aurora-mysql/AuroraMysqlQueryRunner.js +1709 -0
  592. package/.output/server/node_modules/typeorm/driver/aurora-postgres/AuroraPostgresDriver.js +103 -0
  593. package/.output/server/node_modules/typeorm/driver/aurora-postgres/AuroraPostgresQueryRunner.js +146 -0
  594. package/.output/server/node_modules/typeorm/driver/better-sqlite3/BetterSqlite3Driver.js +153 -0
  595. package/.output/server/node_modules/typeorm/driver/better-sqlite3/BetterSqlite3QueryRunner.js +126 -0
  596. package/.output/server/node_modules/typeorm/driver/capacitor/CapacitorDriver.js +78 -0
  597. package/.output/server/node_modules/typeorm/driver/capacitor/CapacitorQueryRunner.js +98 -0
  598. package/.output/server/node_modules/typeorm/driver/cockroachdb/CockroachDriver.js +885 -0
  599. package/.output/server/node_modules/typeorm/driver/cockroachdb/CockroachQueryRunner.js +2453 -0
  600. package/.output/server/node_modules/typeorm/driver/cordova/CordovaDriver.js +76 -0
  601. package/.output/server/node_modules/typeorm/driver/cordova/CordovaQueryRunner.js +170 -0
  602. package/.output/server/node_modules/typeorm/driver/expo/ExpoDriver.js +29 -0
  603. package/.output/server/node_modules/typeorm/driver/expo/ExpoDriverFactory.js +22 -0
  604. package/.output/server/node_modules/typeorm/driver/expo/ExpoQueryRunner.js +65 -0
  605. package/.output/server/node_modules/typeorm/driver/expo/legacy/ExpoLegacyDriver.js +75 -0
  606. package/.output/server/node_modules/typeorm/driver/expo/legacy/ExpoLegacyQueryRunner.js +169 -0
  607. package/.output/server/node_modules/typeorm/driver/mongodb/MongoDriver.js +404 -0
  608. package/.output/server/node_modules/typeorm/driver/mongodb/MongoQueryRunner.js +701 -0
  609. package/.output/server/node_modules/typeorm/driver/mongodb/bson.typings.js +5 -0
  610. package/.output/server/node_modules/typeorm/driver/mongodb/typings.js +23 -0
  611. package/.output/server/node_modules/typeorm/driver/mysql/MysqlDriver.js +1105 -0
  612. package/.output/server/node_modules/typeorm/driver/mysql/MysqlQueryRunner.js +2139 -0
  613. package/.output/server/node_modules/typeorm/driver/nativescript/NativescriptDriver.js +94 -0
  614. package/.output/server/node_modules/typeorm/driver/nativescript/NativescriptQueryRunner.js +92 -0
  615. package/.output/server/node_modules/typeorm/driver/oracle/OracleDriver.js +869 -0
  616. package/.output/server/node_modules/typeorm/driver/oracle/OracleQueryRunner.js +1884 -0
  617. package/.output/server/node_modules/typeorm/driver/postgres/PostgresDriver.js +1259 -0
  618. package/.output/server/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js +2729 -0
  619. package/.output/server/node_modules/typeorm/driver/react-native/ReactNativeDriver.js +728 -0
  620. package/.output/server/node_modules/typeorm/driver/react-native/ReactNativeQueryRunner.js +107 -0
  621. package/.output/server/node_modules/typeorm/driver/sap/SapDriver.js +681 -0
  622. package/.output/server/node_modules/typeorm/driver/sap/SapQueryRunner.js +2054 -0
  623. package/.output/server/node_modules/typeorm/driver/spanner/SpannerDriver.js +613 -0
  624. package/.output/server/node_modules/typeorm/driver/spanner/SpannerQueryRunner.js +1464 -0
  625. package/.output/server/node_modules/typeorm/driver/sqlite/SqliteDriver.js +174 -0
  626. package/.output/server/node_modules/typeorm/driver/sqlite/SqliteQueryRunner.js +124 -0
  627. package/.output/server/node_modules/typeorm/driver/sqlite-abstract/AbstractSqliteDriver.js +695 -0
  628. package/.output/server/node_modules/typeorm/driver/sqlite-abstract/AbstractSqliteQueryRunner.js +1511 -0
  629. package/.output/server/node_modules/typeorm/driver/sqljs/SqljsDriver.js +250 -0
  630. package/.output/server/node_modules/typeorm/driver/sqljs/SqljsQueryRunner.js +123 -0
  631. package/.output/server/node_modules/typeorm/driver/sqlserver/MssqlParameter.js +23 -0
  632. package/.output/server/node_modules/typeorm/driver/sqlserver/SqlServerDriver.js +922 -0
  633. package/.output/server/node_modules/typeorm/driver/sqlserver/SqlServerQueryRunner.js +2484 -0
  634. package/.output/server/node_modules/typeorm/driver/types/DatabaseType.js +4 -0
  635. package/.output/server/node_modules/typeorm/driver/types/GeoJsonTypes.js +4 -0
  636. package/.output/server/node_modules/typeorm/driver/types/MetadataTableType.js +11 -0
  637. package/.output/server/node_modules/typeorm/driver/types/ReplicationMode.js +4 -0
  638. package/.output/server/node_modules/typeorm/entity-manager/EntityManager.js +853 -0
  639. package/.output/server/node_modules/typeorm/entity-manager/EntityManagerFactory.js +24 -0
  640. package/.output/server/node_modules/typeorm/entity-manager/MongoEntityManager.js +668 -0
  641. package/.output/server/node_modules/typeorm/entity-manager/SqljsEntityManager.js +44 -0
  642. package/.output/server/node_modules/typeorm/entity-schema/EntitySchema.js +15 -0
  643. package/.output/server/node_modules/typeorm/entity-schema/EntitySchemaEmbeddedColumnOptions.js +8 -0
  644. package/.output/server/node_modules/typeorm/entity-schema/EntitySchemaEmbeddedError.js +18 -0
  645. package/.output/server/node_modules/typeorm/entity-schema/EntitySchemaOptions.js +11 -0
  646. package/.output/server/node_modules/typeorm/entity-schema/EntitySchemaTransformer.js +333 -0
  647. package/.output/server/node_modules/typeorm/error/AlreadyHasActiveConnectionError.js +16 -0
  648. package/.output/server/node_modules/typeorm/error/CannotAttachTreeChildrenEntityError.js +16 -0
  649. package/.output/server/node_modules/typeorm/error/CannotConnectAlreadyConnectedError.js +15 -0
  650. package/.output/server/node_modules/typeorm/error/CannotCreateEntityIdMapError.js +21 -0
  651. package/.output/server/node_modules/typeorm/error/CannotDetermineEntityError.js +16 -0
  652. package/.output/server/node_modules/typeorm/error/CannotExecuteNotConnectedError.js +15 -0
  653. package/.output/server/node_modules/typeorm/error/CannotGetEntityManagerNotConnectedError.js +15 -0
  654. package/.output/server/node_modules/typeorm/error/CannotReflectMethodParameterTypeError.js +18 -0
  655. package/.output/server/node_modules/typeorm/error/CircularRelationsError.js +16 -0
  656. package/.output/server/node_modules/typeorm/error/ColumnTypeUndefinedError.js +19 -0
  657. package/.output/server/node_modules/typeorm/error/ConnectionIsNotSetError.js +15 -0
  658. package/.output/server/node_modules/typeorm/error/ConnectionNotFoundError.js +15 -0
  659. package/.output/server/node_modules/typeorm/error/CustomRepositoryCannotInheritRepositoryError.js +18 -0
  660. package/.output/server/node_modules/typeorm/error/CustomRepositoryDoesNotHaveEntityError.js +18 -0
  661. package/.output/server/node_modules/typeorm/error/CustomRepositoryNotFoundError.js +18 -0
  662. package/.output/server/node_modules/typeorm/error/DataTypeNotSupportedError.js +14 -0
  663. package/.output/server/node_modules/typeorm/error/DriverOptionNotSetError.js +16 -0
  664. package/.output/server/node_modules/typeorm/error/DriverPackageNotInstalledError.js +16 -0
  665. package/.output/server/node_modules/typeorm/error/EntityMetadataNotFoundError.js +29 -0
  666. package/.output/server/node_modules/typeorm/error/EntityNotFoundError.js +42 -0
  667. package/.output/server/node_modules/typeorm/error/EntityPropertyNotFoundError.js +17 -0
  668. package/.output/server/node_modules/typeorm/error/FindRelationsNotFoundError.js +23 -0
  669. package/.output/server/node_modules/typeorm/error/ForbiddenTransactionModeOverrideError.js +16 -0
  670. package/.output/server/node_modules/typeorm/error/InitializedRelationError.js +20 -0
  671. package/.output/server/node_modules/typeorm/error/InsertValuesMissingError.js +16 -0
  672. package/.output/server/node_modules/typeorm/error/LimitOnUpdateNotSupportedError.js +15 -0
  673. package/.output/server/node_modules/typeorm/error/LockNotSupportedOnGivenDriverError.js +15 -0
  674. package/.output/server/node_modules/typeorm/error/MetadataAlreadyExistsError.js +18 -0
  675. package/.output/server/node_modules/typeorm/error/MetadataWithSuchNameAlreadyExistsError.js +16 -0
  676. package/.output/server/node_modules/typeorm/error/MissingDeleteDateColumnError.js +12 -0
  677. package/.output/server/node_modules/typeorm/error/MissingDriverError.js +16 -0
  678. package/.output/server/node_modules/typeorm/error/MissingJoinColumnError.js +23 -0
  679. package/.output/server/node_modules/typeorm/error/MissingJoinTableError.js +23 -0
  680. package/.output/server/node_modules/typeorm/error/MissingPrimaryColumnError.js +13 -0
  681. package/.output/server/node_modules/typeorm/error/MustBeEntityError.js +15 -0
  682. package/.output/server/node_modules/typeorm/error/NestedSetMultipleRootError.js +12 -0
  683. package/.output/server/node_modules/typeorm/error/NoConnectionForRepositoryError.js +16 -0
  684. package/.output/server/node_modules/typeorm/error/NoConnectionOptionError.js +16 -0
  685. package/.output/server/node_modules/typeorm/error/NoNeedToReleaseEntityManagerError.js +17 -0
  686. package/.output/server/node_modules/typeorm/error/NoVersionOrUpdateDateColumnError.js +15 -0
  687. package/.output/server/node_modules/typeorm/error/OffsetWithoutLimitNotSupportedError.js +17 -0
  688. package/.output/server/node_modules/typeorm/error/OptimisticLockCanNotBeUsedError.js +15 -0
  689. package/.output/server/node_modules/typeorm/error/OptimisticLockVersionMismatchError.js +15 -0
  690. package/.output/server/node_modules/typeorm/error/PersistedEntityNotFoundError.js +15 -0
  691. package/.output/server/node_modules/typeorm/error/PessimisticLockTransactionRequiredError.js +15 -0
  692. package/.output/server/node_modules/typeorm/error/PrimaryColumnCannotBeNullableError.js +13 -0
  693. package/.output/server/node_modules/typeorm/error/QueryFailedError.js +30 -0
  694. package/.output/server/node_modules/typeorm/error/QueryRunnerAlreadyReleasedError.js +12 -0
  695. package/.output/server/node_modules/typeorm/error/QueryRunnerProviderAlreadyReleasedError.js +16 -0
  696. package/.output/server/node_modules/typeorm/error/RepositoryNotTreeError.js +32 -0
  697. package/.output/server/node_modules/typeorm/error/ReturningStatementNotSupportedError.js +16 -0
  698. package/.output/server/node_modules/typeorm/error/SubjectRemovedAndUpdatedError.js +16 -0
  699. package/.output/server/node_modules/typeorm/error/SubjectWithoutIdentifierError.js +17 -0
  700. package/.output/server/node_modules/typeorm/error/TransactionAlreadyStartedError.js +15 -0
  701. package/.output/server/node_modules/typeorm/error/TransactionNotStartedError.js +15 -0
  702. package/.output/server/node_modules/typeorm/error/TreeRepositoryNotSupportedError.js +12 -0
  703. package/.output/server/node_modules/typeorm/error/TypeORMError.js +23 -0
  704. package/.output/server/node_modules/typeorm/error/UpdateValuesMissingError.js +12 -0
  705. package/.output/server/node_modules/typeorm/error/UsingJoinColumnIsNotAllowedError.js +13 -0
  706. package/.output/server/node_modules/typeorm/error/UsingJoinColumnOnlyOnOneSideAllowedError.js +14 -0
  707. package/.output/server/node_modules/typeorm/error/UsingJoinTableIsNotAllowedError.js +14 -0
  708. package/.output/server/node_modules/typeorm/error/UsingJoinTableOnlyOnOneSideAllowedError.js +14 -0
  709. package/.output/server/node_modules/typeorm/error/index.js +66 -0
  710. package/.output/server/node_modules/typeorm/find-options/EqualOperator.js +13 -0
  711. package/.output/server/node_modules/typeorm/find-options/FindManyOptions.js +4 -0
  712. package/.output/server/node_modules/typeorm/find-options/FindOneOptions.js +4 -0
  713. package/.output/server/node_modules/typeorm/find-options/FindOperator.js +96 -0
  714. package/.output/server/node_modules/typeorm/find-options/FindOperatorType.js +4 -0
  715. package/.output/server/node_modules/typeorm/find-options/FindOptionsOrder.js +4 -0
  716. package/.output/server/node_modules/typeorm/find-options/FindOptionsRelations.js +4 -0
  717. package/.output/server/node_modules/typeorm/find-options/FindOptionsSelect.js +4 -0
  718. package/.output/server/node_modules/typeorm/find-options/FindOptionsUtils.js +350 -0
  719. package/.output/server/node_modules/typeorm/find-options/FindOptionsWhere.js +4 -0
  720. package/.output/server/node_modules/typeorm/find-options/FindTreeOptions.js +4 -0
  721. package/.output/server/node_modules/typeorm/find-options/JoinOptions.js +4 -0
  722. package/.output/server/node_modules/typeorm/find-options/OrderByCondition.js +4 -0
  723. package/.output/server/node_modules/typeorm/find-options/operator/And.js +9 -0
  724. package/.output/server/node_modules/typeorm/find-options/operator/Any.js +13 -0
  725. package/.output/server/node_modules/typeorm/find-options/operator/ArrayContainedBy.js +13 -0
  726. package/.output/server/node_modules/typeorm/find-options/operator/ArrayContains.js +13 -0
  727. package/.output/server/node_modules/typeorm/find-options/operator/ArrayOverlap.js +13 -0
  728. package/.output/server/node_modules/typeorm/find-options/operator/Between.js +13 -0
  729. package/.output/server/node_modules/typeorm/find-options/operator/Equal.js +17 -0
  730. package/.output/server/node_modules/typeorm/find-options/operator/ILike.js +13 -0
  731. package/.output/server/node_modules/typeorm/find-options/operator/In.js +13 -0
  732. package/.output/server/node_modules/typeorm/find-options/operator/IsNull.js +13 -0
  733. package/.output/server/node_modules/typeorm/find-options/operator/JsonContains.js +13 -0
  734. package/.output/server/node_modules/typeorm/find-options/operator/LessThan.js +13 -0
  735. package/.output/server/node_modules/typeorm/find-options/operator/LessThanOrEqual.js +13 -0
  736. package/.output/server/node_modules/typeorm/find-options/operator/Like.js +13 -0
  737. package/.output/server/node_modules/typeorm/find-options/operator/MoreThan.js +13 -0
  738. package/.output/server/node_modules/typeorm/find-options/operator/MoreThanOrEqual.js +13 -0
  739. package/.output/server/node_modules/typeorm/find-options/operator/Not.js +14 -0
  740. package/.output/server/node_modules/typeorm/find-options/operator/Or.js +9 -0
  741. package/.output/server/node_modules/typeorm/find-options/operator/Raw.js +12 -0
  742. package/.output/server/node_modules/typeorm/globals.js +182 -0
  743. package/.output/server/node_modules/typeorm/index.js +196 -0
  744. package/.output/server/node_modules/typeorm/index.mjs +422 -0
  745. package/.output/server/node_modules/typeorm/logger/AbstractLogger.js +238 -0
  746. package/.output/server/node_modules/typeorm/logger/AdvancedConsoleLogger.js +56 -0
  747. package/.output/server/node_modules/typeorm/logger/DebugLogger.js +78 -0
  748. package/.output/server/node_modules/typeorm/logger/FileLogger.js +88 -0
  749. package/.output/server/node_modules/typeorm/logger/FormattedConsoleLogger.js +59 -0
  750. package/.output/server/node_modules/typeorm/logger/Logger.js +4 -0
  751. package/.output/server/node_modules/typeorm/logger/LoggerFactory.js +39 -0
  752. package/.output/server/node_modules/typeorm/logger/LoggerOptions.js +4 -0
  753. package/.output/server/node_modules/typeorm/logger/SimpleConsoleLogger.js +57 -0
  754. package/.output/server/node_modules/typeorm/metadata/CheckMetadata.js +35 -0
  755. package/.output/server/node_modules/typeorm/metadata/ColumnMetadata.js +618 -0
  756. package/.output/server/node_modules/typeorm/metadata/EmbeddedMetadata.js +224 -0
  757. package/.output/server/node_modules/typeorm/metadata/EntityListenerMetadata.js +77 -0
  758. package/.output/server/node_modules/typeorm/metadata/EntityMetadata.js +692 -0
  759. package/.output/server/node_modules/typeorm/metadata/ExclusionMetadata.js +35 -0
  760. package/.output/server/node_modules/typeorm/metadata/ForeignKeyMetadata.js +57 -0
  761. package/.output/server/node_modules/typeorm/metadata/IndexMetadata.js +144 -0
  762. package/.output/server/node_modules/typeorm/metadata/RelationCountMetadata.js +39 -0
  763. package/.output/server/node_modules/typeorm/metadata/RelationIdMetadata.js +62 -0
  764. package/.output/server/node_modules/typeorm/metadata/RelationMetadata.js +440 -0
  765. package/.output/server/node_modules/typeorm/metadata/UniqueMetadata.js +101 -0
  766. package/.output/server/node_modules/typeorm/metadata/types/EventListenerTypes.js +22 -0
  767. package/.output/server/node_modules/typeorm/metadata-args/MetadataArgsStorage.js +236 -0
  768. package/.output/server/node_modules/typeorm/metadata-builder/ClosureJunctionEntityMetadataBuilder.js +145 -0
  769. package/.output/server/node_modules/typeorm/metadata-builder/EntityMetadataBuilder.js +838 -0
  770. package/.output/server/node_modules/typeorm/metadata-builder/EntityMetadataValidator.js +258 -0
  771. package/.output/server/node_modules/typeorm/metadata-builder/JunctionEntityMetadataBuilder.js +287 -0
  772. package/.output/server/node_modules/typeorm/metadata-builder/MetadataUtils.js +44 -0
  773. package/.output/server/node_modules/typeorm/metadata-builder/RelationJoinColumnBuilder.js +185 -0
  774. package/.output/server/node_modules/typeorm/migration/Migration.js +21 -0
  775. package/.output/server/node_modules/typeorm/migration/MigrationExecutor.js +534 -0
  776. package/.output/server/node_modules/typeorm/naming-strategy/DefaultNamingStrategy.js +145 -0
  777. package/.output/server/node_modules/typeorm/naming-strategy/LegacyOracleNamingStrategy.js +50 -0
  778. package/.output/server/node_modules/typeorm/package.json +268 -0
  779. package/.output/server/node_modules/typeorm/persistence/EntityPersistExecutor.js +170 -0
  780. package/.output/server/node_modules/typeorm/persistence/Subject.js +239 -0
  781. package/.output/server/node_modules/typeorm/persistence/SubjectChangedColumnsComputer.js +216 -0
  782. package/.output/server/node_modules/typeorm/persistence/SubjectDatabaseEntityLoader.js +135 -0
  783. package/.output/server/node_modules/typeorm/persistence/SubjectExecutor.js +760 -0
  784. package/.output/server/node_modules/typeorm/persistence/SubjectTopologicalSorter.js +174 -0
  785. package/.output/server/node_modules/typeorm/persistence/subject-builder/CascadesSubjectBuilder.js +107 -0
  786. package/.output/server/node_modules/typeorm/persistence/subject-builder/ManyToManySubjectBuilder.js +218 -0
  787. package/.output/server/node_modules/typeorm/persistence/subject-builder/OneToManySubjectBuilder.js +181 -0
  788. package/.output/server/node_modules/typeorm/persistence/subject-builder/OneToOneInverseSideSubjectBuilder.js +155 -0
  789. package/.output/server/node_modules/typeorm/persistence/tree/ClosureSubjectExecutor.js +241 -0
  790. package/.output/server/node_modules/typeorm/persistence/tree/MaterializedPathSubjectExecutor.js +125 -0
  791. package/.output/server/node_modules/typeorm/persistence/tree/NestedSetSubjectExecutor.js +271 -0
  792. package/.output/server/node_modules/typeorm/platform/PlatformTools.js +243 -0
  793. package/.output/server/node_modules/typeorm/query-builder/Alias.js +29 -0
  794. package/.output/server/node_modules/typeorm/query-builder/Brackets.js +19 -0
  795. package/.output/server/node_modules/typeorm/query-builder/DeleteQueryBuilder.js +200 -0
  796. package/.output/server/node_modules/typeorm/query-builder/InsertQueryBuilder.js +745 -0
  797. package/.output/server/node_modules/typeorm/query-builder/JoinAttribute.js +175 -0
  798. package/.output/server/node_modules/typeorm/query-builder/NotBrackets.js +17 -0
  799. package/.output/server/node_modules/typeorm/query-builder/QueryBuilder.js +1139 -0
  800. package/.output/server/node_modules/typeorm/query-builder/QueryBuilderUtils.js +32 -0
  801. package/.output/server/node_modules/typeorm/query-builder/QueryExpressionMap.js +328 -0
  802. package/.output/server/node_modules/typeorm/query-builder/RelationIdLoader.js +503 -0
  803. package/.output/server/node_modules/typeorm/query-builder/RelationLoader.js +283 -0
  804. package/.output/server/node_modules/typeorm/query-builder/RelationQueryBuilder.js +155 -0
  805. package/.output/server/node_modules/typeorm/query-builder/RelationRemover.js +143 -0
  806. package/.output/server/node_modules/typeorm/query-builder/RelationUpdater.js +152 -0
  807. package/.output/server/node_modules/typeorm/query-builder/ReturningResultsEntityUpdator.js +176 -0
  808. package/.output/server/node_modules/typeorm/query-builder/SelectQueryBuilder.js +2656 -0
  809. package/.output/server/node_modules/typeorm/query-builder/SoftDeleteQueryBuilder.js +368 -0
  810. package/.output/server/node_modules/typeorm/query-builder/UpdateQueryBuilder.js +498 -0
  811. package/.output/server/node_modules/typeorm/query-builder/index.js +20 -0
  812. package/.output/server/node_modules/typeorm/query-builder/relation-count/RelationCountAttribute.js +80 -0
  813. package/.output/server/node_modules/typeorm/query-builder/relation-count/RelationCountLoader.js +168 -0
  814. package/.output/server/node_modules/typeorm/query-builder/relation-count/RelationCountMetadataToAttributeTransformer.js +55 -0
  815. package/.output/server/node_modules/typeorm/query-builder/relation-id/RelationIdAttribute.js +88 -0
  816. package/.output/server/node_modules/typeorm/query-builder/relation-id/RelationIdLoader.js +275 -0
  817. package/.output/server/node_modules/typeorm/query-builder/relation-id/RelationIdMetadataToAttributeTransformer.js +55 -0
  818. package/.output/server/node_modules/typeorm/query-builder/result/DeleteResult.js +17 -0
  819. package/.output/server/node_modules/typeorm/query-builder/result/InsertResult.js +28 -0
  820. package/.output/server/node_modules/typeorm/query-builder/result/UpdateResult.js +29 -0
  821. package/.output/server/node_modules/typeorm/query-builder/transformer/DocumentToEntityTransformer.js +196 -0
  822. package/.output/server/node_modules/typeorm/query-builder/transformer/PlainObjectToDatabaseEntityTransformer.js +112 -0
  823. package/.output/server/node_modules/typeorm/query-builder/transformer/PlainObjectToNewEntityTransformer.js +92 -0
  824. package/.output/server/node_modules/typeorm/query-builder/transformer/RawSqlResultsToEntityTransformer.js +447 -0
  825. package/.output/server/node_modules/typeorm/query-runner/BaseQueryRunner.js +454 -0
  826. package/.output/server/node_modules/typeorm/query-runner/QueryLock.js +28 -0
  827. package/.output/server/node_modules/typeorm/query-runner/QueryResult.js +17 -0
  828. package/.output/server/node_modules/typeorm/repository/AbstractRepository.js +92 -0
  829. package/.output/server/node_modules/typeorm/repository/BaseEntity.js +328 -0
  830. package/.output/server/node_modules/typeorm/repository/MongoRepository.js +305 -0
  831. package/.output/server/node_modules/typeorm/repository/RemoveOptions.js +4 -0
  832. package/.output/server/node_modules/typeorm/repository/Repository.js +379 -0
  833. package/.output/server/node_modules/typeorm/repository/SaveOptions.js +4 -0
  834. package/.output/server/node_modules/typeorm/repository/TreeRepository.js +255 -0
  835. package/.output/server/node_modules/typeorm/schema-builder/MongoSchemaBuilder.js +66 -0
  836. package/.output/server/node_modules/typeorm/schema-builder/RdbmsSchemaBuilder.js +929 -0
  837. package/.output/server/node_modules/typeorm/schema-builder/options/TableCheckOptions.js +4 -0
  838. package/.output/server/node_modules/typeorm/schema-builder/options/TableColumnOptions.js +4 -0
  839. package/.output/server/node_modules/typeorm/schema-builder/options/TableExclusionOptions.js +4 -0
  840. package/.output/server/node_modules/typeorm/schema-builder/options/TableForeignKeyOptions.js +4 -0
  841. package/.output/server/node_modules/typeorm/schema-builder/options/TableIndexOptions.js +4 -0
  842. package/.output/server/node_modules/typeorm/schema-builder/options/TableOptions.js +4 -0
  843. package/.output/server/node_modules/typeorm/schema-builder/options/TableUniqueOptions.js +4 -0
  844. package/.output/server/node_modules/typeorm/schema-builder/options/ViewOptions.js +4 -0
  845. package/.output/server/node_modules/typeorm/schema-builder/table/Table.js +296 -0
  846. package/.output/server/node_modules/typeorm/schema-builder/table/TableCheck.js +49 -0
  847. package/.output/server/node_modules/typeorm/schema-builder/table/TableColumn.js +117 -0
  848. package/.output/server/node_modules/typeorm/schema-builder/table/TableExclusion.js +43 -0
  849. package/.output/server/node_modules/typeorm/schema-builder/table/TableForeignKey.js +72 -0
  850. package/.output/server/node_modules/typeorm/schema-builder/table/TableIndex.js +68 -0
  851. package/.output/server/node_modules/typeorm/schema-builder/table/TableUnique.js +50 -0
  852. package/.output/server/node_modules/typeorm/schema-builder/util/TableUtils.js +41 -0
  853. package/.output/server/node_modules/typeorm/schema-builder/util/ViewUtils.js +27 -0
  854. package/.output/server/node_modules/typeorm/schema-builder/view/View.js +71 -0
  855. package/.output/server/node_modules/typeorm/subscriber/Broadcaster.js +660 -0
  856. package/.output/server/node_modules/typeorm/subscriber/BroadcasterResult.js +30 -0
  857. package/.output/server/node_modules/typeorm/subscriber/event/QueryEvent.js +4 -0
  858. package/.output/server/node_modules/typeorm/util/ApplyValueTransformers.js +25 -0
  859. package/.output/server/node_modules/typeorm/util/DateUtils.js +229 -0
  860. package/.output/server/node_modules/typeorm/util/DepGraph.js +230 -0
  861. package/.output/server/node_modules/typeorm/util/DirectoryExportedClassesLoader.js +65 -0
  862. package/.output/server/node_modules/typeorm/util/ImportUtils.js +66 -0
  863. package/.output/server/node_modules/typeorm/util/InstanceChecker.js +104 -0
  864. package/.output/server/node_modules/typeorm/util/ObjectUtils.js +49 -0
  865. package/.output/server/node_modules/typeorm/util/OrmUtils.js +443 -0
  866. package/.output/server/node_modules/typeorm/util/PathUtils.js +33 -0
  867. package/.output/server/node_modules/typeorm/util/RandomGenerator.js +154 -0
  868. package/.output/server/node_modules/typeorm/util/SqlTagUtils.js +43 -0
  869. package/.output/server/node_modules/typeorm/util/StringUtils.js +113 -0
  870. package/.output/server/node_modules/typeorm/util/TreeRepositoryUtils.js +67 -0
  871. package/.output/server/node_modules/typeorm/util/VersionUtils.js +27 -0
  872. package/.output/server/node_modules/typeorm/util/escapeRegExp.js +10 -0
  873. package/.output/server/node_modules/ufo/dist/index.mjs +630 -0
  874. package/.output/server/node_modules/ufo/package.json +47 -0
  875. package/.output/server/node_modules/unhead/dist/plugins.mjs +94 -0
  876. package/.output/server/node_modules/unhead/dist/server.mjs +220 -0
  877. package/.output/server/node_modules/unhead/dist/shared/unhead.C13swrCa.mjs +48 -0
  878. package/.output/server/node_modules/unhead/dist/shared/unhead.CApf5sj3.mjs +148 -0
  879. package/.output/server/node_modules/unhead/dist/shared/unhead.Cp0iF6eN.mjs +177 -0
  880. package/.output/server/node_modules/unhead/dist/shared/unhead.DGkFBTYv.mjs +172 -0
  881. package/.output/server/node_modules/unhead/dist/shared/unhead.DQc16pHI.mjs +196 -0
  882. package/.output/server/node_modules/unhead/dist/shared/unhead.DZbvapt-.mjs +70 -0
  883. package/.output/server/node_modules/unhead/dist/shared/unhead.DeCxexjU.mjs +166 -0
  884. package/.output/server/node_modules/unhead/dist/shared/unhead.yem5I2v_.mjs +38 -0
  885. package/.output/server/node_modules/unhead/dist/utils.mjs +5 -0
  886. package/.output/server/node_modules/unhead/package.json +101 -0
  887. package/.output/server/node_modules/uuid/dist/cjs/index.js +31 -0
  888. package/.output/server/node_modules/uuid/dist/cjs/max.js +3 -0
  889. package/.output/server/node_modules/uuid/dist/cjs/md5.js +13 -0
  890. package/.output/server/node_modules/uuid/dist/cjs/native.js +4 -0
  891. package/.output/server/node_modules/uuid/dist/cjs/nil.js +3 -0
  892. package/.output/server/node_modules/uuid/dist/cjs/package.json +1 -0
  893. package/.output/server/node_modules/uuid/dist/cjs/parse.js +11 -0
  894. package/.output/server/node_modules/uuid/dist/cjs/regex.js +3 -0
  895. package/.output/server/node_modules/uuid/dist/cjs/rng.js +13 -0
  896. package/.output/server/node_modules/uuid/dist/cjs/sha1.js +13 -0
  897. package/.output/server/node_modules/uuid/dist/cjs/stringify.js +39 -0
  898. package/.output/server/node_modules/uuid/dist/cjs/v1.js +87 -0
  899. package/.output/server/node_modules/uuid/dist/cjs/v1ToV6.js +13 -0
  900. package/.output/server/node_modules/uuid/dist/cjs/v3.js +14 -0
  901. package/.output/server/node_modules/uuid/dist/cjs/v35.js +41 -0
  902. package/.output/server/node_modules/uuid/dist/cjs/v4.js +29 -0
  903. package/.output/server/node_modules/uuid/dist/cjs/v5.js +14 -0
  904. package/.output/server/node_modules/uuid/dist/cjs/v6.js +19 -0
  905. package/.output/server/node_modules/uuid/dist/cjs/v6ToV1.js +13 -0
  906. package/.output/server/node_modules/uuid/dist/cjs/v7.js +69 -0
  907. package/.output/server/node_modules/uuid/dist/cjs/validate.js +7 -0
  908. package/.output/server/node_modules/uuid/dist/cjs/version.js +10 -0
  909. package/.output/server/node_modules/uuid/package.json +132 -0
  910. package/.output/server/node_modules/vue/dist/vue.cjs.js +80 -0
  911. package/.output/server/node_modules/vue/dist/vue.cjs.prod.js +66 -0
  912. package/.output/server/node_modules/vue/index.js +7 -0
  913. package/.output/server/node_modules/vue/index.mjs +1 -0
  914. package/.output/server/node_modules/vue/package.json +112 -0
  915. package/.output/server/node_modules/vue/server-renderer/index.mjs +1 -0
  916. package/.output/server/node_modules/vue-bundle-renderer/dist/runtime.mjs +196 -0
  917. package/.output/server/node_modules/vue-bundle-renderer/package.json +50 -0
  918. package/.output/server/node_modules/xtend/mutable.js +17 -0
  919. package/.output/server/node_modules/xtend/package.json +55 -0
  920. package/.output/server/node_modules/zod/index.js +4 -0
  921. package/.output/server/node_modules/zod/package.json +135 -0
  922. package/.output/server/node_modules/zod/v3/ZodError.js +133 -0
  923. package/.output/server/node_modules/zod/v3/errors.js +9 -0
  924. package/.output/server/node_modules/zod/v3/external.js +6 -0
  925. package/.output/server/node_modules/zod/v3/helpers/errorUtil.js +6 -0
  926. package/.output/server/node_modules/zod/v3/helpers/parseUtil.js +109 -0
  927. package/.output/server/node_modules/zod/v3/helpers/typeAliases.js +1 -0
  928. package/.output/server/node_modules/zod/v3/helpers/util.js +133 -0
  929. package/.output/server/node_modules/zod/v3/index.js +4 -0
  930. package/.output/server/node_modules/zod/v3/locales/en.js +109 -0
  931. package/.output/server/node_modules/zod/v3/package.json +6 -0
  932. package/.output/server/node_modules/zod/v3/types.js +3695 -0
  933. package/.output/server/node_modules/zod/v4/classic/checks.js +1 -0
  934. package/.output/server/node_modules/zod/v4/classic/coerce.js +17 -0
  935. package/.output/server/node_modules/zod/v4/classic/compat.js +31 -0
  936. package/.output/server/node_modules/zod/v4/classic/errors.js +48 -0
  937. package/.output/server/node_modules/zod/v4/classic/external.js +20 -0
  938. package/.output/server/node_modules/zod/v4/classic/from-json-schema.js +584 -0
  939. package/.output/server/node_modules/zod/v4/classic/index.js +4 -0
  940. package/.output/server/node_modules/zod/v4/classic/iso.js +30 -0
  941. package/.output/server/node_modules/zod/v4/classic/package.json +6 -0
  942. package/.output/server/node_modules/zod/v4/classic/parse.js +15 -0
  943. package/.output/server/node_modules/zod/v4/classic/schemas.js +1157 -0
  944. package/.output/server/node_modules/zod/v4/core/api.js +1082 -0
  945. package/.output/server/node_modules/zod/v4/core/checks.js +575 -0
  946. package/.output/server/node_modules/zod/v4/core/core.js +76 -0
  947. package/.output/server/node_modules/zod/v4/core/doc.js +35 -0
  948. package/.output/server/node_modules/zod/v4/core/errors.js +182 -0
  949. package/.output/server/node_modules/zod/v4/core/index.js +16 -0
  950. package/.output/server/node_modules/zod/v4/core/json-schema-generator.js +95 -0
  951. package/.output/server/node_modules/zod/v4/core/json-schema-processors.js +605 -0
  952. package/.output/server/node_modules/zod/v4/core/json-schema.js +1 -0
  953. package/.output/server/node_modules/zod/v4/core/package.json +6 -0
  954. package/.output/server/node_modules/zod/v4/core/parse.js +93 -0
  955. package/.output/server/node_modules/zod/v4/core/regexes.js +133 -0
  956. package/.output/server/node_modules/zod/v4/core/registries.js +51 -0
  957. package/.output/server/node_modules/zod/v4/core/schemas.js +2095 -0
  958. package/.output/server/node_modules/zod/v4/core/to-json-schema.js +437 -0
  959. package/.output/server/node_modules/zod/v4/core/util.js +651 -0
  960. package/.output/server/node_modules/zod/v4/core/versions.js +5 -0
  961. package/.output/server/node_modules/zod/v4/index.js +3 -0
  962. package/.output/server/node_modules/zod/v4/locales/ar.js +106 -0
  963. package/.output/server/node_modules/zod/v4/locales/az.js +105 -0
  964. package/.output/server/node_modules/zod/v4/locales/be.js +156 -0
  965. package/.output/server/node_modules/zod/v4/locales/bg.js +120 -0
  966. package/.output/server/node_modules/zod/v4/locales/ca.js +107 -0
  967. package/.output/server/node_modules/zod/v4/locales/cs.js +111 -0
  968. package/.output/server/node_modules/zod/v4/locales/da.js +115 -0
  969. package/.output/server/node_modules/zod/v4/locales/de.js +108 -0
  970. package/.output/server/node_modules/zod/v4/locales/en.js +109 -0
  971. package/.output/server/node_modules/zod/v4/locales/eo.js +109 -0
  972. package/.output/server/node_modules/zod/v4/locales/es.js +132 -0
  973. package/.output/server/node_modules/zod/v4/locales/fa.js +114 -0
  974. package/.output/server/node_modules/zod/v4/locales/fi.js +112 -0
  975. package/.output/server/node_modules/zod/v4/locales/fr-CA.js +107 -0
  976. package/.output/server/node_modules/zod/v4/locales/fr.js +108 -0
  977. package/.output/server/node_modules/zod/v4/locales/he.js +214 -0
  978. package/.output/server/node_modules/zod/v4/locales/hu.js +108 -0
  979. package/.output/server/node_modules/zod/v4/locales/hy.js +147 -0
  980. package/.output/server/node_modules/zod/v4/locales/id.js +106 -0
  981. package/.output/server/node_modules/zod/v4/locales/index.js +49 -0
  982. package/.output/server/node_modules/zod/v4/locales/is.js +109 -0
  983. package/.output/server/node_modules/zod/v4/locales/it.js +108 -0
  984. package/.output/server/node_modules/zod/v4/locales/ja.js +107 -0
  985. package/.output/server/node_modules/zod/v4/locales/ka.js +112 -0
  986. package/.output/server/node_modules/zod/v4/locales/kh.js +5 -0
  987. package/.output/server/node_modules/zod/v4/locales/km.js +110 -0
  988. package/.output/server/node_modules/zod/v4/locales/ko.js +111 -0
  989. package/.output/server/node_modules/zod/v4/locales/lt.js +203 -0
  990. package/.output/server/node_modules/zod/v4/locales/mk.js +109 -0
  991. package/.output/server/node_modules/zod/v4/locales/ms.js +107 -0
  992. package/.output/server/node_modules/zod/v4/locales/nl.js +110 -0
  993. package/.output/server/node_modules/zod/v4/locales/no.js +108 -0
  994. package/.output/server/node_modules/zod/v4/locales/ota.js +109 -0
  995. package/.output/server/node_modules/zod/v4/locales/package.json +6 -0
  996. package/.output/server/node_modules/zod/v4/locales/pl.js +109 -0
  997. package/.output/server/node_modules/zod/v4/locales/ps.js +114 -0
  998. package/.output/server/node_modules/zod/v4/locales/pt.js +108 -0
  999. package/.output/server/node_modules/zod/v4/locales/ru.js +156 -0
  1000. package/.output/server/node_modules/zod/v4/locales/sl.js +109 -0
  1001. package/.output/server/node_modules/zod/v4/locales/sv.js +110 -0
  1002. package/.output/server/node_modules/zod/v4/locales/ta.js +110 -0
  1003. package/.output/server/node_modules/zod/v4/locales/th.js +110 -0
  1004. package/.output/server/node_modules/zod/v4/locales/tr.js +105 -0
  1005. package/.output/server/node_modules/zod/v4/locales/ua.js +5 -0
  1006. package/.output/server/node_modules/zod/v4/locales/uk.js +108 -0
  1007. package/.output/server/node_modules/zod/v4/locales/ur.js +110 -0
  1008. package/.output/server/node_modules/zod/v4/locales/uz.js +109 -0
  1009. package/.output/server/node_modules/zod/v4/locales/vi.js +108 -0
  1010. package/.output/server/node_modules/zod/v4/locales/yo.js +107 -0
  1011. package/.output/server/node_modules/zod/v4/locales/zh-CN.js +109 -0
  1012. package/.output/server/node_modules/zod/v4/locales/zh-TW.js +107 -0
  1013. package/.output/server/node_modules/zod/v4/package.json +6 -0
  1014. package/.output/server/package.json +95 -0
  1015. package/README.md +46 -0
  1016. package/bin/cli.mjs +113 -0
  1017. package/bin/entry.cjs +84 -0
  1018. package/package.json +48 -0
@@ -0,0 +1,2656 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SelectQueryBuilder = void 0;
4
+ const RawSqlResultsToEntityTransformer_1 = require("./transformer/RawSqlResultsToEntityTransformer");
5
+ const PessimisticLockTransactionRequiredError_1 = require("../error/PessimisticLockTransactionRequiredError");
6
+ const NoVersionOrUpdateDateColumnError_1 = require("../error/NoVersionOrUpdateDateColumnError");
7
+ const OptimisticLockVersionMismatchError_1 = require("../error/OptimisticLockVersionMismatchError");
8
+ const OptimisticLockCanNotBeUsedError_1 = require("../error/OptimisticLockCanNotBeUsedError");
9
+ const JoinAttribute_1 = require("./JoinAttribute");
10
+ const RelationIdAttribute_1 = require("./relation-id/RelationIdAttribute");
11
+ const RelationCountAttribute_1 = require("./relation-count/RelationCountAttribute");
12
+ const RelationIdLoader_1 = require("./relation-id/RelationIdLoader");
13
+ const RelationIdLoader_2 = require("./RelationIdLoader");
14
+ const RelationIdMetadataToAttributeTransformer_1 = require("./relation-id/RelationIdMetadataToAttributeTransformer");
15
+ const RelationCountLoader_1 = require("./relation-count/RelationCountLoader");
16
+ const RelationCountMetadataToAttributeTransformer_1 = require("./relation-count/RelationCountMetadataToAttributeTransformer");
17
+ const QueryBuilder_1 = require("./QueryBuilder");
18
+ const LockNotSupportedOnGivenDriverError_1 = require("../error/LockNotSupportedOnGivenDriverError");
19
+ const OffsetWithoutLimitNotSupportedError_1 = require("../error/OffsetWithoutLimitNotSupportedError");
20
+ const ObjectUtils_1 = require("../util/ObjectUtils");
21
+ const DriverUtils_1 = require("../driver/DriverUtils");
22
+ const EntityNotFoundError_1 = require("../error/EntityNotFoundError");
23
+ const error_1 = require("../error");
24
+ const FindOptionsUtils_1 = require("../find-options/FindOptionsUtils");
25
+ const OrmUtils_1 = require("../util/OrmUtils");
26
+ const EntityPropertyNotFoundError_1 = require("../error/EntityPropertyNotFoundError");
27
+ const InstanceChecker_1 = require("../util/InstanceChecker");
28
+ const FindOperator_1 = require("../find-options/FindOperator");
29
+ const ApplyValueTransformers_1 = require("../util/ApplyValueTransformers");
30
+ /**
31
+ * Allows to build complex sql queries in a fashion way and execute those queries.
32
+ */
33
+ class SelectQueryBuilder extends QueryBuilder_1.QueryBuilder {
34
+ constructor() {
35
+ super(...arguments);
36
+ this["@instanceof"] = Symbol.for("SelectQueryBuilder");
37
+ this.findOptions = {};
38
+ this.selects = [];
39
+ this.joins = [];
40
+ this.conditions = "";
41
+ this.orderBys = [];
42
+ this.relationMetadatas = [];
43
+ }
44
+ // -------------------------------------------------------------------------
45
+ // Public Implemented Methods
46
+ // -------------------------------------------------------------------------
47
+ /**
48
+ * Gets generated SQL query without parameters being replaced.
49
+ */
50
+ getQuery() {
51
+ let sql = this.createComment();
52
+ sql += this.createCteExpression();
53
+ sql += this.createSelectExpression();
54
+ sql += this.createJoinExpression();
55
+ sql += this.createWhereExpression();
56
+ sql += this.createGroupByExpression();
57
+ sql += this.createHavingExpression();
58
+ sql += this.createOrderByExpression();
59
+ sql += this.createLimitOffsetExpression();
60
+ sql += this.createLockExpression();
61
+ sql = sql.trim();
62
+ if (this.expressionMap.subQuery)
63
+ sql = "(" + sql + ")";
64
+ return this.replacePropertyNamesForTheWholeQuery(sql);
65
+ }
66
+ // -------------------------------------------------------------------------
67
+ // Public Methods
68
+ // -------------------------------------------------------------------------
69
+ setFindOptions(findOptions) {
70
+ this.findOptions = findOptions;
71
+ this.applyFindOptions();
72
+ return this;
73
+ }
74
+ /**
75
+ * Creates a subquery - query that can be used inside other queries.
76
+ */
77
+ subQuery() {
78
+ const qb = this.createQueryBuilder();
79
+ qb.expressionMap.subQuery = true;
80
+ qb.parentQueryBuilder = this;
81
+ return qb;
82
+ }
83
+ /**
84
+ * Creates SELECT query and selects given data.
85
+ * Replaces all previous selections if they exist.
86
+ */
87
+ select(selection, selectionAliasName) {
88
+ this.expressionMap.queryType = "select";
89
+ if (Array.isArray(selection)) {
90
+ this.expressionMap.selects = selection.map((selection) => ({
91
+ selection: selection,
92
+ }));
93
+ }
94
+ else if (typeof selection === "function") {
95
+ const subQueryBuilder = selection(this.subQuery());
96
+ this.setParameters(subQueryBuilder.getParameters());
97
+ this.expressionMap.selects.push({
98
+ selection: subQueryBuilder.getQuery(),
99
+ aliasName: selectionAliasName,
100
+ });
101
+ }
102
+ else if (selection) {
103
+ this.expressionMap.selects = [
104
+ { selection: selection, aliasName: selectionAliasName },
105
+ ];
106
+ }
107
+ return this;
108
+ }
109
+ /**
110
+ * Adds new selection to the SELECT query.
111
+ */
112
+ addSelect(selection, selectionAliasName) {
113
+ if (!selection)
114
+ return this;
115
+ if (Array.isArray(selection)) {
116
+ this.expressionMap.selects = this.expressionMap.selects.concat(selection.map((selection) => ({ selection: selection })));
117
+ }
118
+ else if (typeof selection === "function") {
119
+ const subQueryBuilder = selection(this.subQuery());
120
+ this.setParameters(subQueryBuilder.getParameters());
121
+ this.expressionMap.selects.push({
122
+ selection: subQueryBuilder.getQuery(),
123
+ aliasName: selectionAliasName,
124
+ });
125
+ }
126
+ else if (selection) {
127
+ this.expressionMap.selects.push({
128
+ selection: selection,
129
+ aliasName: selectionAliasName,
130
+ });
131
+ }
132
+ return this;
133
+ }
134
+ /**
135
+ * Set max execution time.
136
+ * @param milliseconds
137
+ */
138
+ maxExecutionTime(milliseconds) {
139
+ this.expressionMap.maxExecutionTime = milliseconds;
140
+ return this;
141
+ }
142
+ /**
143
+ * Sets whether the selection is DISTINCT.
144
+ */
145
+ distinct(distinct = true) {
146
+ this.expressionMap.selectDistinct = distinct;
147
+ return this;
148
+ }
149
+ /**
150
+ * Sets the distinct on clause for Postgres.
151
+ */
152
+ distinctOn(distinctOn) {
153
+ this.expressionMap.selectDistinctOn = distinctOn;
154
+ return this;
155
+ }
156
+ fromDummy() {
157
+ return this.from(this.connection.driver.dummyTableName ??
158
+ "(SELECT 1 AS dummy_column)", "dummy_table");
159
+ }
160
+ /**
161
+ * Specifies FROM which entity's table select/update/delete will be executed.
162
+ * Also sets a main string alias of the selection data.
163
+ * Removes all previously set from-s.
164
+ */
165
+ from(entityTarget, aliasName) {
166
+ const mainAlias = this.createFromAlias(entityTarget, aliasName);
167
+ this.expressionMap.setMainAlias(mainAlias);
168
+ return this;
169
+ }
170
+ /**
171
+ * Specifies FROM which entity's table select/update/delete will be executed.
172
+ * Also sets a main string alias of the selection data.
173
+ */
174
+ addFrom(entityTarget, aliasName) {
175
+ const alias = this.createFromAlias(entityTarget, aliasName);
176
+ if (!this.expressionMap.mainAlias)
177
+ this.expressionMap.setMainAlias(alias);
178
+ return this;
179
+ }
180
+ /**
181
+ * INNER JOINs (without selection).
182
+ * You also need to specify an alias of the joined data.
183
+ * Optionally, you can add condition and parameters used in condition.
184
+ */
185
+ innerJoin(entityOrProperty, alias, condition, parameters) {
186
+ this.join("INNER", entityOrProperty, alias, condition, parameters);
187
+ return this;
188
+ }
189
+ /**
190
+ * LEFT JOINs (without selection).
191
+ * You also need to specify an alias of the joined data.
192
+ * Optionally, you can add condition and parameters used in condition.
193
+ */
194
+ leftJoin(entityOrProperty, alias, condition, parameters) {
195
+ this.join("LEFT", entityOrProperty, alias, condition, parameters);
196
+ return this;
197
+ }
198
+ /**
199
+ * INNER JOINs and adds all selection properties to SELECT.
200
+ * You also need to specify an alias of the joined data.
201
+ * Optionally, you can add condition and parameters used in condition.
202
+ */
203
+ innerJoinAndSelect(entityOrProperty, alias, condition, parameters) {
204
+ this.addSelect(alias);
205
+ this.innerJoin(entityOrProperty, alias, condition, parameters);
206
+ return this;
207
+ }
208
+ /**
209
+ * LEFT JOINs and adds all selection properties to SELECT.
210
+ * You also need to specify an alias of the joined data.
211
+ * Optionally, you can add condition and parameters used in condition.
212
+ */
213
+ leftJoinAndSelect(entityOrProperty, alias, condition, parameters) {
214
+ this.addSelect(alias);
215
+ this.leftJoin(entityOrProperty, alias, condition, parameters);
216
+ return this;
217
+ }
218
+ /**
219
+ * INNER JOINs, SELECTs the data returned by a join and MAPs all that data to some entity's property.
220
+ * This is extremely useful when you want to select some data and map it to some virtual property.
221
+ * It will assume that there are multiple rows of selecting data, and mapped result will be an array.
222
+ * You also need to specify an alias of the joined data.
223
+ * Optionally, you can add condition and parameters used in condition.
224
+ */
225
+ innerJoinAndMapMany(mapToProperty, entityOrProperty, alias, condition, parameters) {
226
+ this.addSelect(alias);
227
+ this.join("INNER", entityOrProperty, alias, condition, parameters, mapToProperty, true);
228
+ return this;
229
+ }
230
+ /**
231
+ * INNER JOINs, SELECTs the data returned by a join and MAPs all that data to some entity's property.
232
+ * This is extremely useful when you want to select some data and map it to some virtual property.
233
+ * It will assume that there is a single row of selecting data, and mapped result will be a single selected value.
234
+ * You also need to specify an alias of the joined data.
235
+ * Optionally, you can add condition and parameters used in condition.
236
+ */
237
+ innerJoinAndMapOne(mapToProperty, entityOrProperty, alias, condition, parameters, mapAsEntity) {
238
+ this.addSelect(alias);
239
+ this.join("INNER", entityOrProperty, alias, condition, parameters, mapToProperty, false, mapAsEntity);
240
+ return this;
241
+ }
242
+ /**
243
+ * LEFT JOINs, SELECTs the data returned by a join and MAPs all that data to some entity's property.
244
+ * This is extremely useful when you want to select some data and map it to some virtual property.
245
+ * It will assume that there are multiple rows of selecting data, and mapped result will be an array.
246
+ * You also need to specify an alias of the joined data.
247
+ * Optionally, you can add condition and parameters used in condition.
248
+ */
249
+ leftJoinAndMapMany(mapToProperty, entityOrProperty, alias, condition, parameters) {
250
+ this.addSelect(alias);
251
+ this.join("LEFT", entityOrProperty, alias, condition, parameters, mapToProperty, true);
252
+ return this;
253
+ }
254
+ /**
255
+ * LEFT JOINs, SELECTs the data returned by a join and MAPs all that data to some entity's property.
256
+ * This is extremely useful when you want to select some data and map it to some virtual property.
257
+ * It will assume that there is a single row of selecting data, and mapped result will be a single selected value.
258
+ * You also need to specify an alias of the joined data.
259
+ * Optionally, you can add condition and parameters used in condition.
260
+ */
261
+ leftJoinAndMapOne(mapToProperty, entityOrProperty, alias, condition, parameters, mapAsEntity) {
262
+ this.addSelect(alias);
263
+ this.join("LEFT", entityOrProperty, alias, condition, parameters, mapToProperty, false, mapAsEntity);
264
+ return this;
265
+ }
266
+ /**
267
+ * LEFT JOINs relation id and maps it into some entity's property.
268
+ * Optionally, you can add condition and parameters used in condition.
269
+ */
270
+ loadRelationIdAndMap(mapToProperty, relationName, aliasNameOrOptions, queryBuilderFactory) {
271
+ const relationIdAttribute = new RelationIdAttribute_1.RelationIdAttribute(this.expressionMap);
272
+ relationIdAttribute.mapToProperty = mapToProperty;
273
+ relationIdAttribute.relationName = relationName;
274
+ if (typeof aliasNameOrOptions === "string")
275
+ relationIdAttribute.alias = aliasNameOrOptions;
276
+ if (typeof aliasNameOrOptions === "object" &&
277
+ aliasNameOrOptions.disableMixedMap)
278
+ relationIdAttribute.disableMixedMap = true;
279
+ relationIdAttribute.queryBuilderFactory = queryBuilderFactory;
280
+ this.expressionMap.relationIdAttributes.push(relationIdAttribute);
281
+ if (relationIdAttribute.relation.junctionEntityMetadata) {
282
+ this.expressionMap.createAlias({
283
+ type: "other",
284
+ name: relationIdAttribute.junctionAlias,
285
+ metadata: relationIdAttribute.relation.junctionEntityMetadata,
286
+ });
287
+ }
288
+ return this;
289
+ }
290
+ /**
291
+ * Counts number of entities of entity's relation and maps the value into some entity's property.
292
+ * Optionally, you can add condition and parameters used in condition.
293
+ */
294
+ loadRelationCountAndMap(mapToProperty, relationName, aliasName, queryBuilderFactory) {
295
+ const relationCountAttribute = new RelationCountAttribute_1.RelationCountAttribute(this.expressionMap);
296
+ relationCountAttribute.mapToProperty = mapToProperty;
297
+ relationCountAttribute.relationName = relationName;
298
+ relationCountAttribute.alias = aliasName;
299
+ relationCountAttribute.queryBuilderFactory = queryBuilderFactory;
300
+ this.expressionMap.relationCountAttributes.push(relationCountAttribute);
301
+ this.expressionMap.createAlias({
302
+ type: "other",
303
+ name: relationCountAttribute.junctionAlias,
304
+ });
305
+ if (relationCountAttribute.relation.junctionEntityMetadata) {
306
+ this.expressionMap.createAlias({
307
+ type: "other",
308
+ name: relationCountAttribute.junctionAlias,
309
+ metadata: relationCountAttribute.relation.junctionEntityMetadata,
310
+ });
311
+ }
312
+ return this;
313
+ }
314
+ /**
315
+ * Loads all relation ids for all relations of the selected entity.
316
+ * All relation ids will be mapped to relation property themself.
317
+ * If array of strings is given then loads only relation ids of the given properties.
318
+ */
319
+ loadAllRelationIds(options) {
320
+ // todo: add skip relations
321
+ this.expressionMap.mainAlias.metadata.relations.forEach((relation) => {
322
+ if (options !== undefined &&
323
+ options.relations !== undefined &&
324
+ options.relations.indexOf(relation.propertyPath) === -1)
325
+ return;
326
+ this.loadRelationIdAndMap(this.expressionMap.mainAlias.name +
327
+ "." +
328
+ relation.propertyPath, this.expressionMap.mainAlias.name +
329
+ "." +
330
+ relation.propertyPath, options);
331
+ });
332
+ return this;
333
+ }
334
+ /**
335
+ * Sets WHERE condition in the query builder.
336
+ * If you had previously WHERE expression defined,
337
+ * calling this function will override previously set WHERE conditions.
338
+ * Additionally you can add parameters used in where expression.
339
+ */
340
+ where(where, parameters) {
341
+ this.expressionMap.wheres = []; // don't move this block below since computeWhereParameter can add where expressions
342
+ const condition = this.getWhereCondition(where);
343
+ if (condition) {
344
+ this.expressionMap.wheres = [
345
+ { type: "simple", condition: condition },
346
+ ];
347
+ }
348
+ if (parameters)
349
+ this.setParameters(parameters);
350
+ return this;
351
+ }
352
+ /**
353
+ * Adds new AND WHERE condition in the query builder.
354
+ * Additionally you can add parameters used in where expression.
355
+ */
356
+ andWhere(where, parameters) {
357
+ this.expressionMap.wheres.push({
358
+ type: "and",
359
+ condition: this.getWhereCondition(where),
360
+ });
361
+ if (parameters)
362
+ this.setParameters(parameters);
363
+ return this;
364
+ }
365
+ /**
366
+ * Adds new OR WHERE condition in the query builder.
367
+ * Additionally you can add parameters used in where expression.
368
+ */
369
+ orWhere(where, parameters) {
370
+ this.expressionMap.wheres.push({
371
+ type: "or",
372
+ condition: this.getWhereCondition(where),
373
+ });
374
+ if (parameters)
375
+ this.setParameters(parameters);
376
+ return this;
377
+ }
378
+ /**
379
+ * Sets a new where EXISTS clause
380
+ */
381
+ whereExists(subQuery) {
382
+ return this.where(...this.getExistsCondition(subQuery));
383
+ }
384
+ /**
385
+ * Adds a new AND where EXISTS clause
386
+ */
387
+ andWhereExists(subQuery) {
388
+ return this.andWhere(...this.getExistsCondition(subQuery));
389
+ }
390
+ /**
391
+ * Adds a new OR where EXISTS clause
392
+ */
393
+ orWhereExists(subQuery) {
394
+ return this.orWhere(...this.getExistsCondition(subQuery));
395
+ }
396
+ /**
397
+ * Adds new AND WHERE with conditions for the given ids.
398
+ *
399
+ * Ids are mixed.
400
+ * It means if you have single primary key you can pass a simple id values, for example [1, 2, 3].
401
+ * If you have multiple primary keys you need to pass object with property names and values specified,
402
+ * for example [{ firstId: 1, secondId: 2 }, { firstId: 2, secondId: 3 }, ...]
403
+ */
404
+ whereInIds(ids) {
405
+ return this.where(this.getWhereInIdsCondition(ids));
406
+ }
407
+ /**
408
+ * Adds new AND WHERE with conditions for the given ids.
409
+ *
410
+ * Ids are mixed.
411
+ * It means if you have single primary key you can pass a simple id values, for example [1, 2, 3].
412
+ * If you have multiple primary keys you need to pass object with property names and values specified,
413
+ * for example [{ firstId: 1, secondId: 2 }, { firstId: 2, secondId: 3 }, ...]
414
+ */
415
+ andWhereInIds(ids) {
416
+ return this.andWhere(this.getWhereInIdsCondition(ids));
417
+ }
418
+ /**
419
+ * Adds new OR WHERE with conditions for the given ids.
420
+ *
421
+ * Ids are mixed.
422
+ * It means if you have single primary key you can pass a simple id values, for example [1, 2, 3].
423
+ * If you have multiple primary keys you need to pass object with property names and values specified,
424
+ * for example [{ firstId: 1, secondId: 2 }, { firstId: 2, secondId: 3 }, ...]
425
+ */
426
+ orWhereInIds(ids) {
427
+ return this.orWhere(this.getWhereInIdsCondition(ids));
428
+ }
429
+ /**
430
+ * Sets HAVING condition in the query builder.
431
+ * If you had previously HAVING expression defined,
432
+ * calling this function will override previously set HAVING conditions.
433
+ * Additionally you can add parameters used in where expression.
434
+ */
435
+ having(having, parameters) {
436
+ this.expressionMap.havings.push({ type: "simple", condition: having });
437
+ if (parameters)
438
+ this.setParameters(parameters);
439
+ return this;
440
+ }
441
+ /**
442
+ * Adds new AND HAVING condition in the query builder.
443
+ * Additionally you can add parameters used in where expression.
444
+ */
445
+ andHaving(having, parameters) {
446
+ this.expressionMap.havings.push({ type: "and", condition: having });
447
+ if (parameters)
448
+ this.setParameters(parameters);
449
+ return this;
450
+ }
451
+ /**
452
+ * Adds new OR HAVING condition in the query builder.
453
+ * Additionally you can add parameters used in where expression.
454
+ */
455
+ orHaving(having, parameters) {
456
+ this.expressionMap.havings.push({ type: "or", condition: having });
457
+ if (parameters)
458
+ this.setParameters(parameters);
459
+ return this;
460
+ }
461
+ /**
462
+ * Sets GROUP BY condition in the query builder.
463
+ * If you had previously GROUP BY expression defined,
464
+ * calling this function will override previously set GROUP BY conditions.
465
+ */
466
+ groupBy(groupBy) {
467
+ if (groupBy) {
468
+ this.expressionMap.groupBys = [groupBy];
469
+ }
470
+ else {
471
+ this.expressionMap.groupBys = [];
472
+ }
473
+ return this;
474
+ }
475
+ /**
476
+ * Adds GROUP BY condition in the query builder.
477
+ */
478
+ addGroupBy(groupBy) {
479
+ this.expressionMap.groupBys.push(groupBy);
480
+ return this;
481
+ }
482
+ /**
483
+ * Enables time travelling for the current query (only supported by cockroach currently)
484
+ */
485
+ timeTravelQuery(timeTravelFn) {
486
+ if (this.connection.driver.options.type === "cockroachdb") {
487
+ if (timeTravelFn === undefined) {
488
+ this.expressionMap.timeTravel = "follower_read_timestamp()";
489
+ }
490
+ else {
491
+ this.expressionMap.timeTravel = timeTravelFn;
492
+ }
493
+ }
494
+ return this;
495
+ }
496
+ /**
497
+ * Sets ORDER BY condition in the query builder.
498
+ * If you had previously ORDER BY expression defined,
499
+ * calling this function will override previously set ORDER BY conditions.
500
+ */
501
+ orderBy(sort, order = "ASC", nulls) {
502
+ if (order !== undefined && order !== "ASC" && order !== "DESC")
503
+ throw new error_1.TypeORMError(`SelectQueryBuilder.addOrderBy "order" can accept only "ASC" and "DESC" values.`);
504
+ if (nulls !== undefined &&
505
+ nulls !== "NULLS FIRST" &&
506
+ nulls !== "NULLS LAST")
507
+ throw new error_1.TypeORMError(`SelectQueryBuilder.addOrderBy "nulls" can accept only "NULLS FIRST" and "NULLS LAST" values.`);
508
+ if (sort) {
509
+ if (typeof sort === "object") {
510
+ this.expressionMap.orderBys = sort;
511
+ }
512
+ else {
513
+ if (nulls) {
514
+ this.expressionMap.orderBys = {
515
+ [sort]: { order, nulls },
516
+ };
517
+ }
518
+ else {
519
+ this.expressionMap.orderBys = { [sort]: order };
520
+ }
521
+ }
522
+ }
523
+ else {
524
+ this.expressionMap.orderBys = {};
525
+ }
526
+ return this;
527
+ }
528
+ /**
529
+ * Adds ORDER BY condition in the query builder.
530
+ */
531
+ addOrderBy(sort, order = "ASC", nulls) {
532
+ if (order !== undefined && order !== "ASC" && order !== "DESC")
533
+ throw new error_1.TypeORMError(`SelectQueryBuilder.addOrderBy "order" can accept only "ASC" and "DESC" values.`);
534
+ if (nulls !== undefined &&
535
+ nulls !== "NULLS FIRST" &&
536
+ nulls !== "NULLS LAST")
537
+ throw new error_1.TypeORMError(`SelectQueryBuilder.addOrderBy "nulls" can accept only "NULLS FIRST" and "NULLS LAST" values.`);
538
+ if (nulls) {
539
+ this.expressionMap.orderBys[sort] = { order, nulls };
540
+ }
541
+ else {
542
+ this.expressionMap.orderBys[sort] = order;
543
+ }
544
+ return this;
545
+ }
546
+ /**
547
+ * Sets LIMIT - maximum number of rows to be selected.
548
+ * NOTE that it may not work as you expect if you are using joins.
549
+ * If you want to implement pagination, and you are having join in your query,
550
+ * then use the take method instead.
551
+ */
552
+ limit(limit) {
553
+ this.expressionMap.limit = this.normalizeNumber(limit);
554
+ if (this.expressionMap.limit !== undefined &&
555
+ isNaN(this.expressionMap.limit))
556
+ throw new error_1.TypeORMError(`Provided "limit" value is not a number. Please provide a numeric value.`);
557
+ return this;
558
+ }
559
+ /**
560
+ * Sets OFFSET - selection offset.
561
+ * NOTE that it may not work as you expect if you are using joins.
562
+ * If you want to implement pagination, and you are having join in your query,
563
+ * then use the skip method instead.
564
+ */
565
+ offset(offset) {
566
+ this.expressionMap.offset = this.normalizeNumber(offset);
567
+ if (this.expressionMap.offset !== undefined &&
568
+ isNaN(this.expressionMap.offset))
569
+ throw new error_1.TypeORMError(`Provided "offset" value is not a number. Please provide a numeric value.`);
570
+ return this;
571
+ }
572
+ /**
573
+ * Sets maximal number of entities to take.
574
+ */
575
+ take(take) {
576
+ this.expressionMap.take = this.normalizeNumber(take);
577
+ if (this.expressionMap.take !== undefined &&
578
+ isNaN(this.expressionMap.take))
579
+ throw new error_1.TypeORMError(`Provided "take" value is not a number. Please provide a numeric value.`);
580
+ return this;
581
+ }
582
+ /**
583
+ * Sets number of entities to skip.
584
+ */
585
+ skip(skip) {
586
+ this.expressionMap.skip = this.normalizeNumber(skip);
587
+ if (this.expressionMap.skip !== undefined &&
588
+ isNaN(this.expressionMap.skip))
589
+ throw new error_1.TypeORMError(`Provided "skip" value is not a number. Please provide a numeric value.`);
590
+ return this;
591
+ }
592
+ /**
593
+ * Set certain index to be used by the query.
594
+ *
595
+ * @param index Name of index to be used.
596
+ */
597
+ useIndex(index) {
598
+ this.expressionMap.useIndex = index;
599
+ return this;
600
+ }
601
+ /**
602
+ * Sets locking mode.
603
+ */
604
+ setLock(lockMode, lockVersion, lockTables) {
605
+ this.expressionMap.lockMode = lockMode;
606
+ this.expressionMap.lockVersion = lockVersion;
607
+ this.expressionMap.lockTables = lockTables;
608
+ return this;
609
+ }
610
+ /**
611
+ * Sets lock handling by adding NO WAIT or SKIP LOCKED.
612
+ */
613
+ setOnLocked(onLocked) {
614
+ this.expressionMap.onLocked = onLocked;
615
+ return this;
616
+ }
617
+ /**
618
+ * Disables the global condition of "non-deleted" for the entity with delete date columns.
619
+ */
620
+ withDeleted() {
621
+ this.expressionMap.withDeleted = true;
622
+ return this;
623
+ }
624
+ /**
625
+ * Gets first raw result returned by execution of generated query builder sql.
626
+ */
627
+ async getRawOne() {
628
+ return (await this.getRawMany())[0];
629
+ }
630
+ /**
631
+ * Gets all raw results returned by execution of generated query builder sql.
632
+ */
633
+ async getRawMany() {
634
+ if (this.expressionMap.lockMode === "optimistic")
635
+ throw new OptimisticLockCanNotBeUsedError_1.OptimisticLockCanNotBeUsedError();
636
+ this.expressionMap.queryEntity = false;
637
+ const queryRunner = this.obtainQueryRunner();
638
+ let transactionStartedByUs = false;
639
+ try {
640
+ // start transaction if it was enabled
641
+ if (this.expressionMap.useTransaction === true &&
642
+ queryRunner.isTransactionActive === false) {
643
+ await queryRunner.startTransaction();
644
+ transactionStartedByUs = true;
645
+ }
646
+ const results = await this.loadRawResults(queryRunner);
647
+ // close transaction if we started it
648
+ if (transactionStartedByUs) {
649
+ await queryRunner.commitTransaction();
650
+ }
651
+ return results;
652
+ }
653
+ catch (error) {
654
+ // rollback transaction if we started it
655
+ if (transactionStartedByUs) {
656
+ try {
657
+ await queryRunner.rollbackTransaction();
658
+ }
659
+ catch (rollbackError) { }
660
+ }
661
+ throw error;
662
+ }
663
+ finally {
664
+ if (queryRunner !== this.queryRunner) {
665
+ // means we created our own query runner
666
+ await queryRunner.release();
667
+ }
668
+ }
669
+ }
670
+ /**
671
+ * Executes sql generated by query builder and returns object with raw results and entities created from them.
672
+ */
673
+ async getRawAndEntities() {
674
+ const queryRunner = this.obtainQueryRunner();
675
+ let transactionStartedByUs = false;
676
+ try {
677
+ // start transaction if it was enabled
678
+ if (this.expressionMap.useTransaction === true &&
679
+ queryRunner.isTransactionActive === false) {
680
+ await queryRunner.startTransaction();
681
+ transactionStartedByUs = true;
682
+ }
683
+ this.expressionMap.queryEntity = true;
684
+ const results = await this.executeEntitiesAndRawResults(queryRunner);
685
+ // close transaction if we started it
686
+ if (transactionStartedByUs) {
687
+ await queryRunner.commitTransaction();
688
+ }
689
+ return results;
690
+ }
691
+ catch (error) {
692
+ // rollback transaction if we started it
693
+ if (transactionStartedByUs) {
694
+ try {
695
+ await queryRunner.rollbackTransaction();
696
+ }
697
+ catch (rollbackError) { }
698
+ }
699
+ throw error;
700
+ }
701
+ finally {
702
+ if (queryRunner !== this.queryRunner)
703
+ // means we created our own query runner
704
+ await queryRunner.release();
705
+ }
706
+ }
707
+ /**
708
+ * Gets single entity returned by execution of generated query builder sql.
709
+ */
710
+ async getOne() {
711
+ const results = await this.getRawAndEntities();
712
+ const result = results.entities[0];
713
+ if (result &&
714
+ this.expressionMap.lockMode === "optimistic" &&
715
+ this.expressionMap.lockVersion) {
716
+ const metadata = this.expressionMap.mainAlias.metadata;
717
+ if (this.expressionMap.lockVersion instanceof Date) {
718
+ const actualVersion = metadata.updateDateColumn.getEntityValue(result); // what if columns arent set?
719
+ if (actualVersion.getTime() !==
720
+ this.expressionMap.lockVersion.getTime())
721
+ throw new OptimisticLockVersionMismatchError_1.OptimisticLockVersionMismatchError(metadata.name, this.expressionMap.lockVersion, actualVersion);
722
+ }
723
+ else {
724
+ const actualVersion = metadata.versionColumn.getEntityValue(result); // what if columns arent set?
725
+ if (actualVersion !== this.expressionMap.lockVersion)
726
+ throw new OptimisticLockVersionMismatchError_1.OptimisticLockVersionMismatchError(metadata.name, this.expressionMap.lockVersion, actualVersion);
727
+ }
728
+ }
729
+ if (result === undefined) {
730
+ return null;
731
+ }
732
+ return result;
733
+ }
734
+ /**
735
+ * Gets the first entity returned by execution of generated query builder sql or rejects the returned promise on error.
736
+ */
737
+ async getOneOrFail() {
738
+ const entity = await this.getOne();
739
+ if (!entity) {
740
+ throw new EntityNotFoundError_1.EntityNotFoundError(this.expressionMap.mainAlias.target, this.expressionMap.parameters);
741
+ }
742
+ return entity;
743
+ }
744
+ /**
745
+ * Gets entities returned by execution of generated query builder sql.
746
+ */
747
+ async getMany() {
748
+ if (this.expressionMap.lockMode === "optimistic")
749
+ throw new OptimisticLockCanNotBeUsedError_1.OptimisticLockCanNotBeUsedError();
750
+ const results = await this.getRawAndEntities();
751
+ return results.entities;
752
+ }
753
+ /**
754
+ * Gets count - number of entities selected by sql generated by this query builder.
755
+ * Count excludes all limitations set by offset, limit, skip, and take.
756
+ */
757
+ async getCount() {
758
+ if (this.expressionMap.lockMode === "optimistic")
759
+ throw new OptimisticLockCanNotBeUsedError_1.OptimisticLockCanNotBeUsedError();
760
+ const queryRunner = this.obtainQueryRunner();
761
+ let transactionStartedByUs = false;
762
+ try {
763
+ // start transaction if it was enabled
764
+ if (this.expressionMap.useTransaction === true &&
765
+ queryRunner.isTransactionActive === false) {
766
+ await queryRunner.startTransaction();
767
+ transactionStartedByUs = true;
768
+ }
769
+ this.expressionMap.queryEntity = false;
770
+ const results = await this.executeCountQuery(queryRunner);
771
+ // close transaction if we started it
772
+ if (transactionStartedByUs) {
773
+ await queryRunner.commitTransaction();
774
+ }
775
+ return results;
776
+ }
777
+ catch (error) {
778
+ // rollback transaction if we started it
779
+ if (transactionStartedByUs) {
780
+ try {
781
+ await queryRunner.rollbackTransaction();
782
+ }
783
+ catch (rollbackError) { }
784
+ }
785
+ throw error;
786
+ }
787
+ finally {
788
+ if (queryRunner !== this.queryRunner)
789
+ // means we created our own query runner
790
+ await queryRunner.release();
791
+ }
792
+ }
793
+ /**
794
+ * Gets exists
795
+ * Returns whether any rows exists matching current query.
796
+ */
797
+ async getExists() {
798
+ if (this.expressionMap.lockMode === "optimistic")
799
+ throw new OptimisticLockCanNotBeUsedError_1.OptimisticLockCanNotBeUsedError();
800
+ const queryRunner = this.obtainQueryRunner();
801
+ let transactionStartedByUs = false;
802
+ try {
803
+ // start transaction if it was enabled
804
+ if (this.expressionMap.useTransaction === true &&
805
+ queryRunner.isTransactionActive === false) {
806
+ await queryRunner.startTransaction();
807
+ transactionStartedByUs = true;
808
+ }
809
+ this.expressionMap.queryEntity = false;
810
+ const results = await this.executeExistsQuery(queryRunner);
811
+ // close transaction if we started it
812
+ if (transactionStartedByUs) {
813
+ await queryRunner.commitTransaction();
814
+ }
815
+ return results;
816
+ }
817
+ catch (error) {
818
+ // rollback transaction if we started it
819
+ if (transactionStartedByUs) {
820
+ try {
821
+ await queryRunner.rollbackTransaction();
822
+ }
823
+ catch (rollbackError) { }
824
+ }
825
+ throw error;
826
+ }
827
+ finally {
828
+ if (queryRunner !== this.queryRunner)
829
+ // means we created our own query runner
830
+ await queryRunner.release();
831
+ }
832
+ }
833
+ /**
834
+ * Executes built SQL query and returns entities and overall entities count (without limitation).
835
+ * This method is useful to build pagination.
836
+ */
837
+ async getManyAndCount() {
838
+ if (this.expressionMap.lockMode === "optimistic")
839
+ throw new OptimisticLockCanNotBeUsedError_1.OptimisticLockCanNotBeUsedError();
840
+ const queryRunner = this.obtainQueryRunner();
841
+ let transactionStartedByUs = false;
842
+ try {
843
+ // start transaction if it was enabled
844
+ if (this.expressionMap.useTransaction === true &&
845
+ queryRunner.isTransactionActive === false) {
846
+ await queryRunner.startTransaction();
847
+ transactionStartedByUs = true;
848
+ }
849
+ this.expressionMap.queryEntity = true;
850
+ const entitiesAndRaw = await this.executeEntitiesAndRawResults(queryRunner);
851
+ this.expressionMap.queryEntity = false;
852
+ const cacheId = this.expressionMap.cacheId;
853
+ // Creates a new cacheId for the count query, or it will retreive the above query results
854
+ // and count will return 0.
855
+ this.expressionMap.cacheId = cacheId ? `${cacheId}-count` : cacheId;
856
+ const count = await this.executeCountQuery(queryRunner);
857
+ const results = [entitiesAndRaw.entities, count];
858
+ // close transaction if we started it
859
+ if (transactionStartedByUs) {
860
+ await queryRunner.commitTransaction();
861
+ }
862
+ return results;
863
+ }
864
+ catch (error) {
865
+ // rollback transaction if we started it
866
+ if (transactionStartedByUs) {
867
+ try {
868
+ await queryRunner.rollbackTransaction();
869
+ }
870
+ catch (rollbackError) { }
871
+ }
872
+ throw error;
873
+ }
874
+ finally {
875
+ if (queryRunner !== this.queryRunner)
876
+ // means we created our own query runner
877
+ await queryRunner.release();
878
+ }
879
+ }
880
+ /**
881
+ * Executes built SQL query and returns raw data stream.
882
+ */
883
+ async stream() {
884
+ this.expressionMap.queryEntity = false;
885
+ const [sql, parameters] = this.getQueryAndParameters();
886
+ const queryRunner = this.obtainQueryRunner();
887
+ let transactionStartedByUs = false;
888
+ try {
889
+ // start transaction if it was enabled
890
+ if (this.expressionMap.useTransaction === true &&
891
+ queryRunner.isTransactionActive === false) {
892
+ await queryRunner.startTransaction();
893
+ transactionStartedByUs = true;
894
+ }
895
+ const releaseFn = () => {
896
+ if (queryRunner !== this.queryRunner)
897
+ // means we created our own query runner
898
+ return queryRunner.release();
899
+ return;
900
+ };
901
+ const results = queryRunner.stream(sql, parameters, releaseFn, releaseFn);
902
+ // close transaction if we started it
903
+ if (transactionStartedByUs) {
904
+ await queryRunner.commitTransaction();
905
+ }
906
+ return results;
907
+ }
908
+ catch (error) {
909
+ // rollback transaction if we started it
910
+ if (transactionStartedByUs) {
911
+ try {
912
+ await queryRunner.rollbackTransaction();
913
+ }
914
+ catch (rollbackError) { }
915
+ }
916
+ throw error;
917
+ }
918
+ }
919
+ /**
920
+ * Enables or disables query result caching.
921
+ */
922
+ cache(enabledOrMillisecondsOrId, maybeMilliseconds) {
923
+ if (typeof enabledOrMillisecondsOrId === "boolean") {
924
+ this.expressionMap.cache = enabledOrMillisecondsOrId;
925
+ }
926
+ else if (typeof enabledOrMillisecondsOrId === "number") {
927
+ this.expressionMap.cache = true;
928
+ this.expressionMap.cacheDuration = enabledOrMillisecondsOrId;
929
+ }
930
+ else if (typeof enabledOrMillisecondsOrId === "string" ||
931
+ typeof enabledOrMillisecondsOrId === "number") {
932
+ this.expressionMap.cache = true;
933
+ this.expressionMap.cacheId = enabledOrMillisecondsOrId;
934
+ }
935
+ if (maybeMilliseconds) {
936
+ this.expressionMap.cacheDuration = maybeMilliseconds;
937
+ }
938
+ return this;
939
+ }
940
+ /**
941
+ * Sets extra options that can be used to configure how query builder works.
942
+ */
943
+ setOption(option) {
944
+ this.expressionMap.options.push(option);
945
+ return this;
946
+ }
947
+ // -------------------------------------------------------------------------
948
+ // Protected Methods
949
+ // -------------------------------------------------------------------------
950
+ join(direction, entityOrProperty, aliasName, condition, parameters, mapToProperty, isMappingMany, mapAsEntity) {
951
+ if (parameters) {
952
+ this.setParameters(parameters);
953
+ }
954
+ const joinAttribute = new JoinAttribute_1.JoinAttribute(this.connection, this.expressionMap);
955
+ joinAttribute.direction = direction;
956
+ joinAttribute.mapAsEntity = mapAsEntity;
957
+ joinAttribute.mapToProperty = mapToProperty;
958
+ joinAttribute.isMappingMany = isMappingMany;
959
+ joinAttribute.entityOrProperty = entityOrProperty; // relationName
960
+ joinAttribute.condition = condition; // joinInverseSideCondition
961
+ // joinAttribute.junctionAlias = joinAttribute.relation.isOwning ? parentAlias + "_" + destinationTableAlias : destinationTableAlias + "_" + parentAlias;
962
+ this.expressionMap.joinAttributes.push(joinAttribute);
963
+ const joinAttributeMetadata = joinAttribute.metadata;
964
+ if (joinAttributeMetadata) {
965
+ if (joinAttributeMetadata.deleteDateColumn &&
966
+ !this.expressionMap.withDeleted) {
967
+ const conditionDeleteColumn = `${aliasName}.${joinAttributeMetadata.deleteDateColumn.propertyName} IS NULL`;
968
+ joinAttribute.condition = joinAttribute.condition
969
+ ? ` ${joinAttribute.condition} AND ${conditionDeleteColumn}`
970
+ : `${conditionDeleteColumn}`;
971
+ }
972
+ // todo: find and set metadata right there?
973
+ joinAttribute.alias = this.expressionMap.createAlias({
974
+ type: "join",
975
+ name: aliasName,
976
+ metadata: joinAttributeMetadata,
977
+ });
978
+ if (joinAttribute.relation &&
979
+ joinAttribute.relation.junctionEntityMetadata) {
980
+ this.expressionMap.createAlias({
981
+ type: "join",
982
+ name: joinAttribute.junctionAlias,
983
+ metadata: joinAttribute.relation.junctionEntityMetadata,
984
+ });
985
+ }
986
+ }
987
+ else {
988
+ let subQuery = "";
989
+ if (typeof entityOrProperty === "function") {
990
+ const subQueryBuilder = entityOrProperty(this.subQuery());
991
+ this.setParameters(subQueryBuilder.getParameters());
992
+ subQuery = subQueryBuilder.getQuery();
993
+ }
994
+ else {
995
+ subQuery = entityOrProperty;
996
+ }
997
+ const isSubQuery = typeof entityOrProperty === "function" ||
998
+ (entityOrProperty.substr(0, 1) === "(" &&
999
+ entityOrProperty.substr(-1) === ")");
1000
+ joinAttribute.alias = this.expressionMap.createAlias({
1001
+ type: "join",
1002
+ name: aliasName,
1003
+ tablePath: isSubQuery === false
1004
+ ? entityOrProperty
1005
+ : undefined,
1006
+ subQuery: isSubQuery === true ? subQuery : undefined,
1007
+ });
1008
+ }
1009
+ }
1010
+ /**
1011
+ * Creates "SELECT FROM" part of SQL query.
1012
+ */
1013
+ createSelectExpression() {
1014
+ if (!this.expressionMap.mainAlias)
1015
+ throw new error_1.TypeORMError("Cannot build query because main alias is not set (call qb#from method)");
1016
+ // todo throw exception if selects or from is missing
1017
+ const allSelects = [];
1018
+ const excludedSelects = [];
1019
+ if (this.expressionMap.mainAlias.hasMetadata) {
1020
+ const metadata = this.expressionMap.mainAlias.metadata;
1021
+ allSelects.push(...this.buildEscapedEntityColumnSelects(this.expressionMap.mainAlias.name, metadata));
1022
+ excludedSelects.push(...this.findEntityColumnSelects(this.expressionMap.mainAlias.name, metadata));
1023
+ }
1024
+ // add selects from joins
1025
+ this.expressionMap.joinAttributes.forEach((join) => {
1026
+ if (join.metadata) {
1027
+ allSelects.push(...this.buildEscapedEntityColumnSelects(join.alias.name, join.metadata));
1028
+ excludedSelects.push(...this.findEntityColumnSelects(join.alias.name, join.metadata));
1029
+ }
1030
+ else {
1031
+ const hasMainAlias = this.expressionMap.selects.some((select) => select.selection === join.alias.name);
1032
+ if (hasMainAlias) {
1033
+ allSelects.push({
1034
+ selection: this.escape(join.alias.name) + ".*",
1035
+ });
1036
+ const excludedSelect = this.expressionMap.selects.find((select) => select.selection === join.alias.name);
1037
+ excludedSelects.push(excludedSelect);
1038
+ }
1039
+ }
1040
+ });
1041
+ // add all other selects
1042
+ this.expressionMap.selects
1043
+ .filter((select) => excludedSelects.indexOf(select) === -1)
1044
+ .forEach((select) => allSelects.push({
1045
+ selection: this.replacePropertyNames(select.selection),
1046
+ aliasName: select.aliasName,
1047
+ }));
1048
+ // if still selection is empty, then simply set it to all (*)
1049
+ if (allSelects.length === 0)
1050
+ allSelects.push({ selection: "*" });
1051
+ // Use certain index
1052
+ let useIndex = "";
1053
+ if (this.expressionMap.useIndex) {
1054
+ if (DriverUtils_1.DriverUtils.isMySQLFamily(this.connection.driver)) {
1055
+ useIndex = ` USE INDEX (${this.expressionMap.useIndex})`;
1056
+ }
1057
+ }
1058
+ // create a selection query
1059
+ const froms = this.expressionMap.aliases
1060
+ .filter((alias) => alias.type === "from" &&
1061
+ (alias.tablePath || alias.subQuery))
1062
+ .map((alias) => {
1063
+ if (alias.subQuery)
1064
+ return alias.subQuery + " " + this.escape(alias.name);
1065
+ return (this.getTableName(alias.tablePath) +
1066
+ " " +
1067
+ this.escape(alias.name));
1068
+ });
1069
+ const select = this.createSelectDistinctExpression();
1070
+ const selection = allSelects
1071
+ .map((select) => select.selection +
1072
+ (select.aliasName
1073
+ ? " AS " + this.escape(select.aliasName)
1074
+ : ""))
1075
+ .join(", ");
1076
+ return (select +
1077
+ selection +
1078
+ " FROM " +
1079
+ froms.join(", ") +
1080
+ this.createTableLockExpression() +
1081
+ useIndex);
1082
+ }
1083
+ /**
1084
+ * Creates select | select distinct part of SQL query.
1085
+ */
1086
+ createSelectDistinctExpression() {
1087
+ const { selectDistinct, selectDistinctOn, maxExecutionTime } = this.expressionMap;
1088
+ const { driver } = this.connection;
1089
+ let select = "SELECT ";
1090
+ if (maxExecutionTime > 0) {
1091
+ if (DriverUtils_1.DriverUtils.isMySQLFamily(driver)) {
1092
+ select += `/*+ MAX_EXECUTION_TIME(${this.expressionMap.maxExecutionTime}) */ `;
1093
+ }
1094
+ }
1095
+ if (DriverUtils_1.DriverUtils.isPostgresFamily(driver) &&
1096
+ selectDistinctOn.length > 0) {
1097
+ const selectDistinctOnMap = selectDistinctOn
1098
+ .map((on) => this.replacePropertyNames(on))
1099
+ .join(", ");
1100
+ select = `SELECT DISTINCT ON (${selectDistinctOnMap}) `;
1101
+ }
1102
+ else if (selectDistinct) {
1103
+ select = "SELECT DISTINCT ";
1104
+ }
1105
+ return select;
1106
+ }
1107
+ /**
1108
+ * Creates "JOIN" part of SQL query.
1109
+ */
1110
+ createJoinExpression() {
1111
+ // examples:
1112
+ // select from owning side
1113
+ // qb.select("post")
1114
+ // .leftJoinAndSelect("post.category", "category");
1115
+ // select from non-owning side
1116
+ // qb.select("category")
1117
+ // .leftJoinAndSelect("category.post", "post");
1118
+ const joins = this.expressionMap.joinAttributes.map((joinAttr) => {
1119
+ const relation = joinAttr.relation;
1120
+ const destinationTableName = joinAttr.tablePath;
1121
+ const destinationTableAlias = joinAttr.alias.name;
1122
+ let appendedCondition = joinAttr.condition
1123
+ ? " AND (" + joinAttr.condition + ")"
1124
+ : "";
1125
+ const parentAlias = joinAttr.parentAlias;
1126
+ // if join was build without relation (e.g. without "post.category") then it means that we have direct
1127
+ // table to join, without junction table involved. This means we simply join direct table.
1128
+ if (!parentAlias || !relation) {
1129
+ const destinationJoin = joinAttr.alias.subQuery
1130
+ ? joinAttr.alias.subQuery
1131
+ : this.getTableName(destinationTableName);
1132
+ return (" " +
1133
+ joinAttr.direction +
1134
+ " JOIN " +
1135
+ destinationJoin +
1136
+ " " +
1137
+ this.escape(destinationTableAlias) +
1138
+ this.createTableLockExpression() +
1139
+ (joinAttr.condition
1140
+ ? " ON " + this.replacePropertyNames(joinAttr.condition)
1141
+ : ""));
1142
+ }
1143
+ // if real entity relation is involved
1144
+ if (relation.isManyToOne || relation.isOneToOneOwner) {
1145
+ // JOIN `category` `category` ON `category`.`id` = `post`.`categoryId`
1146
+ const condition = relation.joinColumns
1147
+ .map((joinColumn) => {
1148
+ return (destinationTableAlias +
1149
+ "." +
1150
+ joinColumn.referencedColumn.propertyPath +
1151
+ "=" +
1152
+ parentAlias +
1153
+ "." +
1154
+ relation.propertyPath +
1155
+ "." +
1156
+ joinColumn.referencedColumn.propertyPath);
1157
+ })
1158
+ .join(" AND ");
1159
+ return (" " +
1160
+ joinAttr.direction +
1161
+ " JOIN " +
1162
+ this.getTableName(destinationTableName) +
1163
+ " " +
1164
+ this.escape(destinationTableAlias) +
1165
+ this.createTableLockExpression() +
1166
+ " ON " +
1167
+ this.replacePropertyNames(condition + appendedCondition));
1168
+ }
1169
+ else if (relation.isOneToMany || relation.isOneToOneNotOwner) {
1170
+ // JOIN `post` `post` ON `post`.`categoryId` = `category`.`id`
1171
+ const condition = relation
1172
+ .inverseRelation.joinColumns.map((joinColumn) => {
1173
+ if (relation.inverseEntityMetadata.tableType ===
1174
+ "entity-child" &&
1175
+ relation.inverseEntityMetadata.discriminatorColumn) {
1176
+ appendedCondition +=
1177
+ " AND " +
1178
+ destinationTableAlias +
1179
+ "." +
1180
+ relation.inverseEntityMetadata
1181
+ .discriminatorColumn.databaseName +
1182
+ "='" +
1183
+ relation.inverseEntityMetadata
1184
+ .discriminatorValue +
1185
+ "'";
1186
+ }
1187
+ return (destinationTableAlias +
1188
+ "." +
1189
+ relation.inverseRelation.propertyPath +
1190
+ "." +
1191
+ joinColumn.referencedColumn.propertyPath +
1192
+ "=" +
1193
+ parentAlias +
1194
+ "." +
1195
+ joinColumn.referencedColumn.propertyPath);
1196
+ })
1197
+ .join(" AND ");
1198
+ if (!condition)
1199
+ throw new error_1.TypeORMError(`Relation ${relation.entityMetadata.name}.${relation.propertyName} does not have join columns.`);
1200
+ return (" " +
1201
+ joinAttr.direction +
1202
+ " JOIN " +
1203
+ this.getTableName(destinationTableName) +
1204
+ " " +
1205
+ this.escape(destinationTableAlias) +
1206
+ this.createTableLockExpression() +
1207
+ " ON " +
1208
+ this.replacePropertyNames(condition + appendedCondition));
1209
+ }
1210
+ else {
1211
+ // means many-to-many
1212
+ const junctionTableName = relation.junctionEntityMetadata.tablePath;
1213
+ const junctionAlias = joinAttr.junctionAlias;
1214
+ let junctionCondition = "", destinationCondition = "";
1215
+ if (relation.isOwning) {
1216
+ junctionCondition = relation.joinColumns
1217
+ .map((joinColumn) => {
1218
+ // `post_category`.`postId` = `post`.`id`
1219
+ return (junctionAlias +
1220
+ "." +
1221
+ joinColumn.propertyPath +
1222
+ "=" +
1223
+ parentAlias +
1224
+ "." +
1225
+ joinColumn.referencedColumn.propertyPath);
1226
+ })
1227
+ .join(" AND ");
1228
+ destinationCondition = relation.inverseJoinColumns
1229
+ .map((joinColumn) => {
1230
+ // `category`.`id` = `post_category`.`categoryId`
1231
+ return (destinationTableAlias +
1232
+ "." +
1233
+ joinColumn.referencedColumn.propertyPath +
1234
+ "=" +
1235
+ junctionAlias +
1236
+ "." +
1237
+ joinColumn.propertyPath);
1238
+ })
1239
+ .join(" AND ");
1240
+ }
1241
+ else {
1242
+ junctionCondition = relation
1243
+ .inverseRelation.inverseJoinColumns.map((joinColumn) => {
1244
+ // `post_category`.`categoryId` = `category`.`id`
1245
+ return (junctionAlias +
1246
+ "." +
1247
+ joinColumn.propertyPath +
1248
+ "=" +
1249
+ parentAlias +
1250
+ "." +
1251
+ joinColumn.referencedColumn.propertyPath);
1252
+ })
1253
+ .join(" AND ");
1254
+ destinationCondition = relation
1255
+ .inverseRelation.joinColumns.map((joinColumn) => {
1256
+ // `post`.`id` = `post_category`.`postId`
1257
+ return (destinationTableAlias +
1258
+ "." +
1259
+ joinColumn.referencedColumn.propertyPath +
1260
+ "=" +
1261
+ junctionAlias +
1262
+ "." +
1263
+ joinColumn.propertyPath);
1264
+ })
1265
+ .join(" AND ");
1266
+ }
1267
+ return (" " +
1268
+ joinAttr.direction +
1269
+ " JOIN " +
1270
+ this.getTableName(junctionTableName) +
1271
+ " " +
1272
+ this.escape(junctionAlias) +
1273
+ this.createTableLockExpression() +
1274
+ " ON " +
1275
+ this.replacePropertyNames(junctionCondition) +
1276
+ " " +
1277
+ joinAttr.direction +
1278
+ " JOIN " +
1279
+ this.getTableName(destinationTableName) +
1280
+ " " +
1281
+ this.escape(destinationTableAlias) +
1282
+ this.createTableLockExpression() +
1283
+ " ON " +
1284
+ this.replacePropertyNames(destinationCondition + appendedCondition));
1285
+ }
1286
+ });
1287
+ return joins.join(" ");
1288
+ }
1289
+ /**
1290
+ * Creates "GROUP BY" part of SQL query.
1291
+ */
1292
+ createGroupByExpression() {
1293
+ if (!this.expressionMap.groupBys || !this.expressionMap.groupBys.length)
1294
+ return "";
1295
+ return (" GROUP BY " +
1296
+ this.replacePropertyNames(this.expressionMap.groupBys.join(", ")));
1297
+ }
1298
+ /**
1299
+ * Creates "ORDER BY" part of SQL query.
1300
+ */
1301
+ createOrderByExpression() {
1302
+ const orderBys = this.expressionMap.allOrderBys;
1303
+ if (Object.keys(orderBys).length === 0)
1304
+ return "";
1305
+ return (" ORDER BY " +
1306
+ Object.keys(orderBys)
1307
+ .map((columnName) => {
1308
+ const orderValue = typeof orderBys[columnName] === "string"
1309
+ ? orderBys[columnName]
1310
+ : orderBys[columnName].order +
1311
+ " " +
1312
+ orderBys[columnName].nulls;
1313
+ const selection = this.expressionMap.selects.find((s) => s.selection === columnName);
1314
+ if (selection &&
1315
+ !selection.aliasName &&
1316
+ columnName.indexOf(".") !== -1) {
1317
+ const criteriaParts = columnName.split(".");
1318
+ const aliasName = criteriaParts[0];
1319
+ const propertyPath = criteriaParts.slice(1).join(".");
1320
+ const alias = this.expressionMap.aliases.find((alias) => alias.name === aliasName);
1321
+ if (alias) {
1322
+ const column = alias.metadata.findColumnWithPropertyPath(propertyPath);
1323
+ if (column) {
1324
+ const orderAlias = DriverUtils_1.DriverUtils.buildAlias(this.connection.driver, undefined, aliasName, column.databaseName);
1325
+ return (this.escape(orderAlias) + " " + orderValue);
1326
+ }
1327
+ }
1328
+ }
1329
+ return (this.replacePropertyNames(columnName) + " " + orderValue);
1330
+ })
1331
+ .join(", "));
1332
+ }
1333
+ /**
1334
+ * Creates "LIMIT" and "OFFSET" parts of SQL query.
1335
+ */
1336
+ createLimitOffsetExpression() {
1337
+ // in the case if nothing is joined in the query builder we don't need to make two requests to get paginated results
1338
+ // we can use regular limit / offset, that's why we add offset and limit construction here based on skip and take values
1339
+ let offset = this.expressionMap.offset, limit = this.expressionMap.limit;
1340
+ if (!offset &&
1341
+ !limit &&
1342
+ this.expressionMap.joinAttributes.length === 0) {
1343
+ offset = this.expressionMap.skip;
1344
+ limit = this.expressionMap.take;
1345
+ }
1346
+ if (this.connection.driver.options.type === "mssql") {
1347
+ // Due to a limitation in SQL Server's parser implementation it does not support using
1348
+ // OFFSET or FETCH NEXT without an ORDER BY clause being provided. In cases where the
1349
+ // user does not request one we insert a dummy ORDER BY that does nothing and should
1350
+ // have no effect on the query planner or on the order of the results returned.
1351
+ // https://dba.stackexchange.com/a/193799
1352
+ let prefix = "";
1353
+ if ((limit || offset) &&
1354
+ Object.keys(this.expressionMap.allOrderBys).length <= 0) {
1355
+ prefix = " ORDER BY (SELECT NULL)";
1356
+ }
1357
+ if (limit && offset)
1358
+ return (prefix +
1359
+ " OFFSET " +
1360
+ offset +
1361
+ " ROWS FETCH NEXT " +
1362
+ limit +
1363
+ " ROWS ONLY");
1364
+ if (limit)
1365
+ return (prefix + " OFFSET 0 ROWS FETCH NEXT " + limit + " ROWS ONLY");
1366
+ if (offset)
1367
+ return prefix + " OFFSET " + offset + " ROWS";
1368
+ }
1369
+ else if (DriverUtils_1.DriverUtils.isMySQLFamily(this.connection.driver) ||
1370
+ this.connection.driver.options.type === "aurora-mysql" ||
1371
+ this.connection.driver.options.type === "sap" ||
1372
+ this.connection.driver.options.type === "spanner") {
1373
+ if (limit && offset)
1374
+ return " LIMIT " + limit + " OFFSET " + offset;
1375
+ if (limit)
1376
+ return " LIMIT " + limit;
1377
+ if (offset)
1378
+ throw new OffsetWithoutLimitNotSupportedError_1.OffsetWithoutLimitNotSupportedError();
1379
+ }
1380
+ else if (DriverUtils_1.DriverUtils.isSQLiteFamily(this.connection.driver)) {
1381
+ if (limit && offset)
1382
+ return " LIMIT " + limit + " OFFSET " + offset;
1383
+ if (limit)
1384
+ return " LIMIT " + limit;
1385
+ if (offset)
1386
+ return " LIMIT -1 OFFSET " + offset;
1387
+ }
1388
+ else if (this.connection.driver.options.type === "oracle") {
1389
+ if (limit && offset)
1390
+ return (" OFFSET " +
1391
+ offset +
1392
+ " ROWS FETCH NEXT " +
1393
+ limit +
1394
+ " ROWS ONLY");
1395
+ if (limit)
1396
+ return " FETCH NEXT " + limit + " ROWS ONLY";
1397
+ if (offset)
1398
+ return " OFFSET " + offset + " ROWS";
1399
+ }
1400
+ else {
1401
+ if (limit && offset)
1402
+ return " LIMIT " + limit + " OFFSET " + offset;
1403
+ if (limit)
1404
+ return " LIMIT " + limit;
1405
+ if (offset)
1406
+ return " OFFSET " + offset;
1407
+ }
1408
+ return "";
1409
+ }
1410
+ /**
1411
+ * Creates "LOCK" part of SELECT Query after table Clause
1412
+ * ex.
1413
+ * SELECT 1
1414
+ * FROM USER U WITH (NOLOCK)
1415
+ * JOIN ORDER O WITH (NOLOCK)
1416
+ * ON U.ID=O.OrderID
1417
+ */
1418
+ createTableLockExpression() {
1419
+ if (this.connection.driver.options.type === "mssql") {
1420
+ switch (this.expressionMap.lockMode) {
1421
+ case "pessimistic_read":
1422
+ return " WITH (HOLDLOCK, ROWLOCK)";
1423
+ case "pessimistic_write":
1424
+ return " WITH (UPDLOCK, ROWLOCK)";
1425
+ case "dirty_read":
1426
+ return " WITH (NOLOCK)";
1427
+ }
1428
+ }
1429
+ return "";
1430
+ }
1431
+ /**
1432
+ * Creates "LOCK" part of SQL query.
1433
+ */
1434
+ createLockExpression() {
1435
+ const driver = this.connection.driver;
1436
+ let lockTablesClause = "";
1437
+ if (this.expressionMap.lockTables) {
1438
+ if (!(DriverUtils_1.DriverUtils.isPostgresFamily(driver) ||
1439
+ driver.options.type === "cockroachdb")) {
1440
+ throw new error_1.TypeORMError("Lock tables not supported in selected driver");
1441
+ }
1442
+ if (this.expressionMap.lockTables.length < 1) {
1443
+ throw new error_1.TypeORMError("lockTables cannot be an empty array");
1444
+ }
1445
+ lockTablesClause = " OF " + this.expressionMap.lockTables.join(", ");
1446
+ }
1447
+ let onLockExpression = "";
1448
+ if (this.expressionMap.onLocked === "nowait") {
1449
+ onLockExpression = " NOWAIT";
1450
+ }
1451
+ else if (this.expressionMap.onLocked === "skip_locked") {
1452
+ onLockExpression = " SKIP LOCKED";
1453
+ }
1454
+ switch (this.expressionMap.lockMode) {
1455
+ case "pessimistic_read":
1456
+ if (driver.options.type === "mysql" ||
1457
+ driver.options.type === "aurora-mysql") {
1458
+ if (DriverUtils_1.DriverUtils.isReleaseVersionOrGreater(driver, "8.0.0")) {
1459
+ return (" FOR SHARE" + lockTablesClause + onLockExpression);
1460
+ }
1461
+ else {
1462
+ return " LOCK IN SHARE MODE";
1463
+ }
1464
+ }
1465
+ else if (driver.options.type === "mariadb") {
1466
+ return " LOCK IN SHARE MODE";
1467
+ }
1468
+ else if (DriverUtils_1.DriverUtils.isPostgresFamily(driver)) {
1469
+ return " FOR SHARE" + lockTablesClause + onLockExpression;
1470
+ }
1471
+ else if (driver.options.type === "oracle") {
1472
+ return " FOR UPDATE";
1473
+ }
1474
+ else if (driver.options.type === "mssql") {
1475
+ return "";
1476
+ }
1477
+ else {
1478
+ throw new LockNotSupportedOnGivenDriverError_1.LockNotSupportedOnGivenDriverError();
1479
+ }
1480
+ case "pessimistic_write":
1481
+ if (DriverUtils_1.DriverUtils.isMySQLFamily(driver) ||
1482
+ driver.options.type === "aurora-mysql" ||
1483
+ driver.options.type === "oracle") {
1484
+ return " FOR UPDATE" + onLockExpression;
1485
+ }
1486
+ else if (DriverUtils_1.DriverUtils.isPostgresFamily(driver) ||
1487
+ driver.options.type === "cockroachdb") {
1488
+ return " FOR UPDATE" + lockTablesClause + onLockExpression;
1489
+ }
1490
+ else if (driver.options.type === "mssql") {
1491
+ return "";
1492
+ }
1493
+ else {
1494
+ throw new LockNotSupportedOnGivenDriverError_1.LockNotSupportedOnGivenDriverError();
1495
+ }
1496
+ case "pessimistic_partial_write":
1497
+ if (DriverUtils_1.DriverUtils.isPostgresFamily(driver)) {
1498
+ return " FOR UPDATE" + lockTablesClause + " SKIP LOCKED";
1499
+ }
1500
+ else if (DriverUtils_1.DriverUtils.isMySQLFamily(driver)) {
1501
+ return " FOR UPDATE SKIP LOCKED";
1502
+ }
1503
+ else {
1504
+ throw new LockNotSupportedOnGivenDriverError_1.LockNotSupportedOnGivenDriverError();
1505
+ }
1506
+ case "pessimistic_write_or_fail":
1507
+ if (DriverUtils_1.DriverUtils.isPostgresFamily(driver) ||
1508
+ driver.options.type === "cockroachdb") {
1509
+ return " FOR UPDATE" + lockTablesClause + " NOWAIT";
1510
+ }
1511
+ else if (DriverUtils_1.DriverUtils.isMySQLFamily(driver)) {
1512
+ return " FOR UPDATE NOWAIT";
1513
+ }
1514
+ else {
1515
+ throw new LockNotSupportedOnGivenDriverError_1.LockNotSupportedOnGivenDriverError();
1516
+ }
1517
+ case "for_no_key_update":
1518
+ if (DriverUtils_1.DriverUtils.isPostgresFamily(driver) ||
1519
+ driver.options.type === "cockroachdb") {
1520
+ return (" FOR NO KEY UPDATE" +
1521
+ lockTablesClause +
1522
+ onLockExpression);
1523
+ }
1524
+ else {
1525
+ throw new LockNotSupportedOnGivenDriverError_1.LockNotSupportedOnGivenDriverError();
1526
+ }
1527
+ case "for_key_share":
1528
+ if (DriverUtils_1.DriverUtils.isPostgresFamily(driver)) {
1529
+ return (" FOR KEY SHARE" + lockTablesClause + onLockExpression);
1530
+ }
1531
+ else {
1532
+ throw new LockNotSupportedOnGivenDriverError_1.LockNotSupportedOnGivenDriverError();
1533
+ }
1534
+ default:
1535
+ return "";
1536
+ }
1537
+ }
1538
+ /**
1539
+ * Creates "HAVING" part of SQL query.
1540
+ */
1541
+ createHavingExpression() {
1542
+ if (!this.expressionMap.havings || !this.expressionMap.havings.length)
1543
+ return "";
1544
+ const conditions = this.expressionMap.havings
1545
+ .map((having, index) => {
1546
+ switch (having.type) {
1547
+ case "and":
1548
+ return ((index > 0 ? "AND " : "") +
1549
+ this.replacePropertyNames(having.condition));
1550
+ case "or":
1551
+ return ((index > 0 ? "OR " : "") +
1552
+ this.replacePropertyNames(having.condition));
1553
+ default:
1554
+ return this.replacePropertyNames(having.condition);
1555
+ }
1556
+ })
1557
+ .join(" ");
1558
+ if (!conditions.length)
1559
+ return "";
1560
+ return " HAVING " + conditions;
1561
+ }
1562
+ buildEscapedEntityColumnSelects(aliasName, metadata) {
1563
+ const hasMainAlias = this.expressionMap.selects.some((select) => select.selection === aliasName);
1564
+ const columns = [];
1565
+ if (hasMainAlias) {
1566
+ columns.push(...metadata.columns.filter((column) => column.isSelect === true));
1567
+ }
1568
+ columns.push(...metadata.columns.filter((column) => {
1569
+ return this.expressionMap.selects.some((select) => select.selection ===
1570
+ aliasName + "." + column.propertyPath);
1571
+ }));
1572
+ // if user used partial selection and did not select some primary columns which are required to be selected
1573
+ // we select those primary columns and mark them as "virtual". Later virtual column values will be removed from final entity
1574
+ // to make entity contain exactly what user selected
1575
+ if (columns.length === 0)
1576
+ // however not in the case when nothing (even partial) was selected from this target (for example joins without selection)
1577
+ return [];
1578
+ const nonSelectedPrimaryColumns = this.expressionMap.queryEntity
1579
+ ? metadata.primaryColumns.filter((primaryColumn) => columns.indexOf(primaryColumn) === -1)
1580
+ : [];
1581
+ const allColumns = [...columns, ...nonSelectedPrimaryColumns];
1582
+ const finalSelects = [];
1583
+ const escapedAliasName = this.escape(aliasName);
1584
+ allColumns.forEach((column) => {
1585
+ let selectionPath = escapedAliasName + "." + this.escape(column.databaseName);
1586
+ if (column.isVirtualProperty && column.query) {
1587
+ selectionPath = `(${column.query(escapedAliasName)})`;
1588
+ }
1589
+ if (this.connection.driver.spatialTypes.indexOf(column.type) !== -1) {
1590
+ if (DriverUtils_1.DriverUtils.isMySQLFamily(this.connection.driver) ||
1591
+ this.connection.driver.options.type === "aurora-mysql") {
1592
+ const useLegacy = this.connection.driver.options.legacySpatialSupport;
1593
+ const asText = useLegacy ? "AsText" : "ST_AsText";
1594
+ selectionPath = `${asText}(${selectionPath})`;
1595
+ }
1596
+ if (DriverUtils_1.DriverUtils.isPostgresFamily(this.connection.driver))
1597
+ if (column.precision) {
1598
+ // cast to JSON to trigger parsing in the driver
1599
+ selectionPath = `ST_AsGeoJSON(${selectionPath}, ${column.precision})::json`;
1600
+ }
1601
+ else {
1602
+ selectionPath = `ST_AsGeoJSON(${selectionPath})::json`;
1603
+ }
1604
+ if (this.connection.driver.options.type === "mssql")
1605
+ selectionPath = `${selectionPath}.ToString()`;
1606
+ }
1607
+ const selections = this.expressionMap.selects.filter((select) => select.selection === aliasName + "." + column.propertyPath);
1608
+ if (selections.length) {
1609
+ selections.forEach((selection) => {
1610
+ finalSelects.push({
1611
+ selection: selectionPath,
1612
+ aliasName: selection.aliasName
1613
+ ? selection.aliasName
1614
+ : DriverUtils_1.DriverUtils.buildAlias(this.connection.driver, undefined, aliasName, column.databaseName),
1615
+ // todo: need to keep in mind that custom selection.aliasName breaks hydrator. fix it later!
1616
+ virtual: selection.virtual,
1617
+ });
1618
+ });
1619
+ }
1620
+ else {
1621
+ finalSelects.push({
1622
+ selection: selectionPath,
1623
+ aliasName: DriverUtils_1.DriverUtils.buildAlias(this.connection.driver, undefined, aliasName, column.databaseName),
1624
+ // todo: need to keep in mind that custom selection.aliasName breaks hydrator. fix it later!
1625
+ virtual: hasMainAlias,
1626
+ });
1627
+ }
1628
+ });
1629
+ return finalSelects;
1630
+ }
1631
+ findEntityColumnSelects(aliasName, metadata) {
1632
+ const mainSelect = this.expressionMap.selects.find((select) => select.selection === aliasName);
1633
+ if (mainSelect)
1634
+ return [mainSelect];
1635
+ return this.expressionMap.selects.filter((select) => {
1636
+ return metadata.columns.some((column) => select.selection === aliasName + "." + column.propertyPath);
1637
+ });
1638
+ }
1639
+ computeCountExpression() {
1640
+ const mainAlias = this.expressionMap.mainAlias.name; // todo: will this work with "fromTableName"?
1641
+ const metadata = this.expressionMap.mainAlias.metadata;
1642
+ const primaryColumns = metadata.primaryColumns;
1643
+ const distinctAlias = this.escape(mainAlias);
1644
+ // If we aren't doing anything that will create a join, we can use a simpler `COUNT` instead
1645
+ // so we prevent poor query patterns in the most likely cases
1646
+ if (this.expressionMap.joinAttributes.length === 0 &&
1647
+ this.expressionMap.relationIdAttributes.length === 0 &&
1648
+ this.expressionMap.relationCountAttributes.length === 0) {
1649
+ return "COUNT(1)";
1650
+ }
1651
+ // For everything else, we'll need to do some hackery to get the correct count values.
1652
+ if (this.connection.driver.options.type === "cockroachdb" ||
1653
+ DriverUtils_1.DriverUtils.isPostgresFamily(this.connection.driver)) {
1654
+ // Postgres and CockroachDB can pass multiple parameters to the `DISTINCT` function
1655
+ // https://www.postgresql.org/docs/9.5/sql-select.html#SQL-DISTINCT
1656
+ return ("COUNT(DISTINCT(" +
1657
+ primaryColumns
1658
+ .map((c) => `${distinctAlias}.${this.escape(c.databaseName)}`)
1659
+ .join(", ") +
1660
+ "))");
1661
+ }
1662
+ if (DriverUtils_1.DriverUtils.isMySQLFamily(this.connection.driver)) {
1663
+ // MySQL & MariaDB can pass multiple parameters to the `DISTINCT` language construct
1664
+ // https://mariadb.com/kb/en/count-distinct/
1665
+ return ("COUNT(DISTINCT " +
1666
+ primaryColumns
1667
+ .map((c) => `${distinctAlias}.${this.escape(c.databaseName)}`)
1668
+ .join(", ") +
1669
+ ")");
1670
+ }
1671
+ if (this.connection.driver.options.type === "mssql") {
1672
+ // SQL Server has gotta be different from everyone else. They don't support
1673
+ // distinct counting multiple columns & they don't have the same operator
1674
+ // characteristic for concatenating, so we gotta use the `CONCAT` function.
1675
+ // However, If it's exactly 1 column we can omit the `CONCAT` for better performance.
1676
+ const columnsExpression = primaryColumns
1677
+ .map((primaryColumn) => `${distinctAlias}.${this.escape(primaryColumn.databaseName)}`)
1678
+ .join(", '|;|', ");
1679
+ if (primaryColumns.length === 1) {
1680
+ return `COUNT(DISTINCT(${columnsExpression}))`;
1681
+ }
1682
+ return `COUNT(DISTINCT(CONCAT(${columnsExpression})))`;
1683
+ }
1684
+ if (this.connection.driver.options.type === "spanner") {
1685
+ // spanner also has gotta be different from everyone else.
1686
+ // they do not support concatenation of different column types without casting them to string
1687
+ if (primaryColumns.length === 1) {
1688
+ return `COUNT(DISTINCT(${distinctAlias}.${this.escape(primaryColumns[0].databaseName)}))`;
1689
+ }
1690
+ const columnsExpression = primaryColumns
1691
+ .map((primaryColumn) => `CAST(${distinctAlias}.${this.escape(primaryColumn.databaseName)} AS STRING)`)
1692
+ .join(", '|;|', ");
1693
+ return `COUNT(DISTINCT(CONCAT(${columnsExpression})))`;
1694
+ }
1695
+ // If all else fails, fall back to a `COUNT` and `DISTINCT` across all the primary columns concatenated.
1696
+ // Per the SQL spec, this is the canonical string concatenation mechanism which is most
1697
+ // likely to work across servers implementing the SQL standard.
1698
+ // Please note, if there is only one primary column that the concatenation does not occur in this
1699
+ // query and the query is a standard `COUNT DISTINCT` in that case.
1700
+ return (`COUNT(DISTINCT(` +
1701
+ primaryColumns
1702
+ .map((c) => `${distinctAlias}.${this.escape(c.databaseName)}`)
1703
+ .join(" || '|;|' || ") +
1704
+ "))");
1705
+ }
1706
+ async executeCountQuery(queryRunner) {
1707
+ const countSql = this.computeCountExpression();
1708
+ const results = await this.clone()
1709
+ .orderBy()
1710
+ .groupBy()
1711
+ .offset(undefined)
1712
+ .limit(undefined)
1713
+ .skip(undefined)
1714
+ .take(undefined)
1715
+ .select(countSql, "cnt")
1716
+ .setOption("disable-global-order")
1717
+ .loadRawResults(queryRunner);
1718
+ if (!results || !results[0] || !results[0]["cnt"])
1719
+ return 0;
1720
+ return parseInt(results[0]["cnt"]);
1721
+ }
1722
+ async executeExistsQuery(queryRunner) {
1723
+ const results = await this.connection
1724
+ .createQueryBuilder()
1725
+ .fromDummy()
1726
+ .select("1", "row_exists")
1727
+ .whereExists(this)
1728
+ .limit(1)
1729
+ .loadRawResults(queryRunner);
1730
+ return results.length > 0;
1731
+ }
1732
+ applyFindOptions() {
1733
+ // todo: convert relations: string[] to object map to simplify code
1734
+ // todo: same with selects
1735
+ if (this.expressionMap.mainAlias.metadata) {
1736
+ if (this.findOptions.relationLoadStrategy) {
1737
+ this.expressionMap.relationLoadStrategy =
1738
+ this.findOptions.relationLoadStrategy;
1739
+ }
1740
+ if (this.findOptions.comment) {
1741
+ this.comment(this.findOptions.comment);
1742
+ }
1743
+ if (this.findOptions.withDeleted) {
1744
+ this.withDeleted();
1745
+ }
1746
+ if (this.findOptions.select) {
1747
+ const select = Array.isArray(this.findOptions.select)
1748
+ ? OrmUtils_1.OrmUtils.propertyPathsToTruthyObject(this.findOptions.select)
1749
+ : this.findOptions.select;
1750
+ this.buildSelect(select, this.expressionMap.mainAlias.metadata, this.expressionMap.mainAlias.name);
1751
+ }
1752
+ if (this.selects.length) {
1753
+ this.select(this.selects);
1754
+ }
1755
+ this.selects = [];
1756
+ if (this.findOptions.relations) {
1757
+ const relations = Array.isArray(this.findOptions.relations)
1758
+ ? OrmUtils_1.OrmUtils.propertyPathsToTruthyObject(this.findOptions.relations)
1759
+ : this.findOptions.relations;
1760
+ this.buildRelations(relations, typeof this.findOptions.select === "object"
1761
+ ? this.findOptions.select
1762
+ : undefined, this.expressionMap.mainAlias.metadata, this.expressionMap.mainAlias.name);
1763
+ if (this.findOptions.loadEagerRelations !== false &&
1764
+ this.expressionMap.relationLoadStrategy === "join") {
1765
+ this.buildEagerRelations(relations, typeof this.findOptions.select === "object"
1766
+ ? this.findOptions
1767
+ .select
1768
+ : undefined, this.expressionMap.mainAlias.metadata, this.expressionMap.mainAlias.name);
1769
+ }
1770
+ }
1771
+ if (this.selects.length) {
1772
+ this.addSelect(this.selects);
1773
+ }
1774
+ if (this.findOptions.where) {
1775
+ this.conditions = this.buildWhere(this.findOptions.where, this.expressionMap.mainAlias.metadata, this.expressionMap.mainAlias.name);
1776
+ if (this.conditions.length)
1777
+ this.andWhere(this.conditions.substr(0, 1) !== "("
1778
+ ? "(" + this.conditions + ")"
1779
+ : this.conditions); // temporary and where and braces
1780
+ }
1781
+ if (this.findOptions.order) {
1782
+ this.buildOrder(this.findOptions.order, this.expressionMap.mainAlias.metadata, this.expressionMap.mainAlias.name);
1783
+ }
1784
+ // apply joins
1785
+ if (this.joins.length) {
1786
+ this.joins.forEach((join) => {
1787
+ if (join.select && !join.selection) {
1788
+ // if (join.selection) {
1789
+ //
1790
+ // } else {
1791
+ if (join.type === "inner") {
1792
+ this.innerJoinAndSelect(`${join.parentAlias}.${join.relationMetadata.propertyPath}`, join.alias);
1793
+ }
1794
+ else {
1795
+ this.leftJoinAndSelect(`${join.parentAlias}.${join.relationMetadata.propertyPath}`, join.alias);
1796
+ }
1797
+ // }
1798
+ }
1799
+ else {
1800
+ if (join.type === "inner") {
1801
+ this.innerJoin(`${join.parentAlias}.${join.relationMetadata.propertyPath}`, join.alias);
1802
+ }
1803
+ else {
1804
+ this.leftJoin(`${join.parentAlias}.${join.relationMetadata.propertyPath}`, join.alias);
1805
+ }
1806
+ }
1807
+ // if (join.select) {
1808
+ // if (this.findOptions.loadEagerRelations !== false) {
1809
+ // FindOptionsUtils.joinEagerRelations(
1810
+ // this,
1811
+ // join.alias,
1812
+ // join.relationMetadata.inverseEntityMetadata
1813
+ // );
1814
+ // }
1815
+ // }
1816
+ });
1817
+ }
1818
+ // if (this.conditions.length) {
1819
+ // this.where(this.conditions.join(" AND "));
1820
+ // }
1821
+ // apply offset
1822
+ if (this.findOptions.skip !== undefined) {
1823
+ // if (this.findOptions.options && this.findOptions.options.pagination === false) {
1824
+ // this.offset(this.findOptions.skip);
1825
+ // } else {
1826
+ this.skip(this.findOptions.skip);
1827
+ // }
1828
+ }
1829
+ // apply limit
1830
+ if (this.findOptions.take !== undefined) {
1831
+ // if (this.findOptions.options && this.findOptions.options.pagination === false) {
1832
+ // this.limit(this.findOptions.take);
1833
+ // } else {
1834
+ this.take(this.findOptions.take);
1835
+ // }
1836
+ }
1837
+ // apply caching options
1838
+ if (typeof this.findOptions.cache === "number") {
1839
+ this.cache(this.findOptions.cache);
1840
+ }
1841
+ else if (typeof this.findOptions.cache === "boolean") {
1842
+ this.cache(this.findOptions.cache);
1843
+ }
1844
+ else if (typeof this.findOptions.cache === "object") {
1845
+ this.cache(this.findOptions.cache.id, this.findOptions.cache.milliseconds);
1846
+ }
1847
+ if (this.findOptions.join) {
1848
+ if (this.findOptions.join.leftJoin)
1849
+ Object.keys(this.findOptions.join.leftJoin).forEach((key) => {
1850
+ this.leftJoin(this.findOptions.join.leftJoin[key], key);
1851
+ });
1852
+ if (this.findOptions.join.innerJoin)
1853
+ Object.keys(this.findOptions.join.innerJoin).forEach((key) => {
1854
+ this.innerJoin(this.findOptions.join.innerJoin[key], key);
1855
+ });
1856
+ if (this.findOptions.join.leftJoinAndSelect)
1857
+ Object.keys(this.findOptions.join.leftJoinAndSelect).forEach((key) => {
1858
+ this.leftJoinAndSelect(this.findOptions.join.leftJoinAndSelect[key], key);
1859
+ });
1860
+ if (this.findOptions.join.innerJoinAndSelect)
1861
+ Object.keys(this.findOptions.join.innerJoinAndSelect).forEach((key) => {
1862
+ this.innerJoinAndSelect(this.findOptions.join.innerJoinAndSelect[key], key);
1863
+ });
1864
+ }
1865
+ if (this.findOptions.lock) {
1866
+ if (this.findOptions.lock.mode === "optimistic") {
1867
+ this.setLock(this.findOptions.lock.mode, this.findOptions.lock.version);
1868
+ }
1869
+ else if (this.findOptions.lock.mode === "pessimistic_read" ||
1870
+ this.findOptions.lock.mode === "pessimistic_write" ||
1871
+ this.findOptions.lock.mode === "dirty_read" ||
1872
+ this.findOptions.lock.mode ===
1873
+ "pessimistic_partial_write" ||
1874
+ this.findOptions.lock.mode ===
1875
+ "pessimistic_write_or_fail" ||
1876
+ this.findOptions.lock.mode === "for_no_key_update" ||
1877
+ this.findOptions.lock.mode === "for_key_share") {
1878
+ const tableNames = this.findOptions.lock.tables
1879
+ ? this.findOptions.lock.tables.map((table) => {
1880
+ const tableAlias = this.expressionMap.aliases.find((alias) => {
1881
+ return (alias.metadata
1882
+ .tableNameWithoutPrefix === table);
1883
+ });
1884
+ if (!tableAlias) {
1885
+ throw new error_1.TypeORMError(`"${table}" is not part of this query`);
1886
+ }
1887
+ return this.escape(tableAlias.name);
1888
+ })
1889
+ : undefined;
1890
+ this.setLock(this.findOptions.lock.mode, undefined, tableNames);
1891
+ if (this.findOptions.lock.onLocked) {
1892
+ this.setOnLocked(this.findOptions.lock.onLocked);
1893
+ }
1894
+ }
1895
+ }
1896
+ if (this.findOptions.loadRelationIds === true) {
1897
+ this.loadAllRelationIds();
1898
+ }
1899
+ else if (typeof this.findOptions.loadRelationIds === "object") {
1900
+ this.loadAllRelationIds(this.findOptions.loadRelationIds);
1901
+ }
1902
+ if (this.findOptions.loadEagerRelations !== false) {
1903
+ FindOptionsUtils_1.FindOptionsUtils.joinEagerRelations(this, this.expressionMap.mainAlias.name, this.expressionMap.mainAlias.metadata);
1904
+ }
1905
+ if (this.findOptions.transaction === true) {
1906
+ this.expressionMap.useTransaction = true;
1907
+ }
1908
+ // if (this.orderBys.length) {
1909
+ // this.orderBys.forEach(orderBy => {
1910
+ // this.addOrderBy(orderBy.alias, orderBy.direction, orderBy.nulls);
1911
+ // });
1912
+ // }
1913
+ // todo
1914
+ // if (this.options.options && this.options.options.eagerRelations) {
1915
+ // this.queryBuilder
1916
+ // }
1917
+ // todo
1918
+ // if (this.findOptions.options && this.findOptions.listeners === false) {
1919
+ // this.callListeners(false);
1920
+ // }
1921
+ }
1922
+ }
1923
+ concatRelationMetadata(relationMetadata) {
1924
+ this.relationMetadatas.push(relationMetadata);
1925
+ }
1926
+ /**
1927
+ * Executes sql generated by query builder and returns object with raw results and entities created from them.
1928
+ */
1929
+ async executeEntitiesAndRawResults(queryRunner) {
1930
+ if (!this.expressionMap.mainAlias)
1931
+ throw new error_1.TypeORMError(`Alias is not set. Use "from" method to set an alias.`);
1932
+ if ((this.expressionMap.lockMode === "pessimistic_read" ||
1933
+ this.expressionMap.lockMode === "pessimistic_write" ||
1934
+ this.expressionMap.lockMode === "pessimistic_partial_write" ||
1935
+ this.expressionMap.lockMode === "pessimistic_write_or_fail" ||
1936
+ this.expressionMap.lockMode === "for_no_key_update" ||
1937
+ this.expressionMap.lockMode === "for_key_share") &&
1938
+ !queryRunner.isTransactionActive)
1939
+ throw new PessimisticLockTransactionRequiredError_1.PessimisticLockTransactionRequiredError();
1940
+ if (this.expressionMap.lockMode === "optimistic") {
1941
+ const metadata = this.expressionMap.mainAlias.metadata;
1942
+ if (!metadata.versionColumn && !metadata.updateDateColumn)
1943
+ throw new NoVersionOrUpdateDateColumnError_1.NoVersionOrUpdateDateColumnError(metadata.name);
1944
+ }
1945
+ const relationIdLoader = new RelationIdLoader_1.RelationIdLoader(this.connection, queryRunner, this.expressionMap.relationIdAttributes);
1946
+ const relationCountLoader = new RelationCountLoader_1.RelationCountLoader(this.connection, queryRunner, this.expressionMap.relationCountAttributes);
1947
+ const relationIdMetadataTransformer = new RelationIdMetadataToAttributeTransformer_1.RelationIdMetadataToAttributeTransformer(this.expressionMap);
1948
+ relationIdMetadataTransformer.transform();
1949
+ const relationCountMetadataTransformer = new RelationCountMetadataToAttributeTransformer_1.RelationCountMetadataToAttributeTransformer(this.expressionMap);
1950
+ relationCountMetadataTransformer.transform();
1951
+ let rawResults = [], entities = [];
1952
+ // for pagination enabled (e.g. skip and take) its much more complicated - its a special process
1953
+ // where we make two queries to find the data we need
1954
+ // first query find ids in skip and take range
1955
+ // and second query loads the actual data in given ids range
1956
+ if ((this.expressionMap.skip || this.expressionMap.take) &&
1957
+ this.expressionMap.joinAttributes.length > 0) {
1958
+ // we are skipping order by here because its not working in subqueries anyway
1959
+ // to make order by working we need to apply it on a distinct query
1960
+ const [selects, orderBys] = this.createOrderByCombinedWithSelectExpression("distinctAlias");
1961
+ const metadata = this.expressionMap.mainAlias.metadata;
1962
+ const mainAliasName = this.expressionMap.mainAlias.name;
1963
+ const querySelects = metadata.primaryColumns.map((primaryColumn) => {
1964
+ const distinctAlias = this.escape("distinctAlias");
1965
+ const columnAlias = this.escape(DriverUtils_1.DriverUtils.buildAlias(this.connection.driver, undefined, mainAliasName, primaryColumn.databaseName));
1966
+ if (!orderBys[columnAlias])
1967
+ // make sure we aren't overriding user-defined order in inverse direction
1968
+ orderBys[columnAlias] = "ASC";
1969
+ const alias = DriverUtils_1.DriverUtils.buildAlias(this.connection.driver, undefined, "ids_" + mainAliasName, primaryColumn.databaseName);
1970
+ return `${distinctAlias}.${columnAlias} AS ${this.escape(alias)}`;
1971
+ });
1972
+ const originalQuery = this.clone();
1973
+ // preserve original timeTravel value since we set it to "false" in subquery
1974
+ const originalQueryTimeTravel = originalQuery.expressionMap.timeTravel;
1975
+ rawResults = await new SelectQueryBuilder(this.connection, queryRunner)
1976
+ .select(`DISTINCT ${querySelects.join(", ")}`)
1977
+ .addSelect(selects)
1978
+ .from(`(${originalQuery
1979
+ .orderBy()
1980
+ .timeTravelQuery(false) // set it to "false" since time travel clause must appear at the very end and applies to the entire SELECT clause.
1981
+ .getQuery()})`, "distinctAlias")
1982
+ .timeTravelQuery(originalQueryTimeTravel)
1983
+ .offset(this.expressionMap.skip)
1984
+ .limit(this.expressionMap.take)
1985
+ .orderBy(orderBys)
1986
+ .cache(this.expressionMap.cache && this.expressionMap.cacheId
1987
+ ? `${this.expressionMap.cacheId}-pagination`
1988
+ : this.expressionMap.cache, this.expressionMap.cacheDuration)
1989
+ .setParameters(this.getParameters())
1990
+ .setNativeParameters(this.expressionMap.nativeParameters)
1991
+ .getRawMany();
1992
+ if (rawResults.length > 0) {
1993
+ let condition = "";
1994
+ const parameters = {};
1995
+ if (metadata.hasMultiplePrimaryKeys) {
1996
+ condition = rawResults
1997
+ .map((result, index) => {
1998
+ return metadata.primaryColumns
1999
+ .map((primaryColumn) => {
2000
+ const paramKey = `orm_distinct_ids_${index}_${primaryColumn.databaseName}`;
2001
+ const paramKeyResult = DriverUtils_1.DriverUtils.buildAlias(this.connection.driver, undefined, "ids_" + mainAliasName, primaryColumn.databaseName);
2002
+ parameters[paramKey] =
2003
+ result[paramKeyResult];
2004
+ return `${mainAliasName}.${primaryColumn.propertyPath}=:${paramKey}`;
2005
+ })
2006
+ .join(" AND ");
2007
+ })
2008
+ .join(" OR ");
2009
+ }
2010
+ else {
2011
+ const alias = DriverUtils_1.DriverUtils.buildAlias(this.connection.driver, undefined, "ids_" + mainAliasName, metadata.primaryColumns[0].databaseName);
2012
+ const ids = rawResults.map((result) => result[alias]);
2013
+ const areAllNumbers = ids.every((id) => typeof id === "number");
2014
+ if (areAllNumbers) {
2015
+ // fixes #190. if all numbers then its safe to perform query without parameter
2016
+ condition = `${mainAliasName}.${metadata.primaryColumns[0].propertyPath} IN (${ids.join(", ")})`;
2017
+ }
2018
+ else {
2019
+ parameters["orm_distinct_ids"] = ids;
2020
+ condition =
2021
+ mainAliasName +
2022
+ "." +
2023
+ metadata.primaryColumns[0].propertyPath +
2024
+ " IN (:...orm_distinct_ids)";
2025
+ }
2026
+ }
2027
+ rawResults = await this.clone()
2028
+ .mergeExpressionMap({
2029
+ extraAppendedAndWhereCondition: condition,
2030
+ })
2031
+ .setParameters(parameters)
2032
+ .loadRawResults(queryRunner);
2033
+ }
2034
+ }
2035
+ else {
2036
+ rawResults = await this.loadRawResults(queryRunner);
2037
+ }
2038
+ if (rawResults.length > 0) {
2039
+ // transform raw results into entities
2040
+ const rawRelationIdResults = await relationIdLoader.load(rawResults);
2041
+ const rawRelationCountResults = await relationCountLoader.load(rawResults);
2042
+ const transformer = new RawSqlResultsToEntityTransformer_1.RawSqlResultsToEntityTransformer(this.expressionMap, this.connection.driver, rawRelationIdResults, rawRelationCountResults, this.queryRunner);
2043
+ entities = transformer.transform(rawResults, this.expressionMap.mainAlias);
2044
+ // broadcast all "after load" events
2045
+ if (this.expressionMap.callListeners === true &&
2046
+ this.expressionMap.mainAlias.hasMetadata) {
2047
+ await queryRunner.broadcaster.broadcast("Load", this.expressionMap.mainAlias.metadata, entities);
2048
+ }
2049
+ }
2050
+ if (this.expressionMap.relationLoadStrategy === "query") {
2051
+ const queryStrategyRelationIdLoader = new RelationIdLoader_2.RelationIdLoader(this.connection, queryRunner);
2052
+ await Promise.all(this.relationMetadatas.map(async (relation) => {
2053
+ const relationTarget = relation.inverseEntityMetadata.target;
2054
+ const relationAlias = relation.inverseEntityMetadata.targetName;
2055
+ const select = Array.isArray(this.findOptions.select)
2056
+ ? OrmUtils_1.OrmUtils.propertyPathsToTruthyObject(this.findOptions.select)
2057
+ : this.findOptions.select;
2058
+ const relations = Array.isArray(this.findOptions.relations)
2059
+ ? OrmUtils_1.OrmUtils.propertyPathsToTruthyObject(this.findOptions.relations)
2060
+ : this.findOptions.relations;
2061
+ const queryBuilder = this.createQueryBuilder(queryRunner)
2062
+ .select(relationAlias)
2063
+ .from(relationTarget, relationAlias)
2064
+ .setFindOptions({
2065
+ select: select
2066
+ ? OrmUtils_1.OrmUtils.deepValue(select, relation.propertyPath)
2067
+ : undefined,
2068
+ order: this.findOptions.order
2069
+ ? OrmUtils_1.OrmUtils.deepValue(this.findOptions.order, relation.propertyPath)
2070
+ : undefined,
2071
+ relations: relations
2072
+ ? OrmUtils_1.OrmUtils.deepValue(relations, relation.propertyPath)
2073
+ : undefined,
2074
+ withDeleted: this.findOptions.withDeleted,
2075
+ relationLoadStrategy: this.findOptions.relationLoadStrategy,
2076
+ });
2077
+ if (entities.length > 0) {
2078
+ const relatedEntityGroups = await queryStrategyRelationIdLoader.loadManyToManyRelationIdsAndGroup(relation, entities, undefined, queryBuilder);
2079
+ entities.forEach((entity) => {
2080
+ const relatedEntityGroup = relatedEntityGroups.find((group) => group.entity === entity);
2081
+ if (relatedEntityGroup) {
2082
+ const value = relatedEntityGroup.related === undefined
2083
+ ? null
2084
+ : relatedEntityGroup.related;
2085
+ relation.setEntityValue(entity, value);
2086
+ }
2087
+ });
2088
+ }
2089
+ }));
2090
+ }
2091
+ return {
2092
+ raw: rawResults,
2093
+ entities: entities,
2094
+ };
2095
+ }
2096
+ createOrderByCombinedWithSelectExpression(parentAlias) {
2097
+ // if table has a default order then apply it
2098
+ const orderBys = this.expressionMap.allOrderBys;
2099
+ const selectString = Object.keys(orderBys)
2100
+ .map((orderCriteria) => {
2101
+ if (orderCriteria.indexOf(".") !== -1) {
2102
+ const criteriaParts = orderCriteria.split(".");
2103
+ const aliasName = criteriaParts[0];
2104
+ const propertyPath = criteriaParts.slice(1).join(".");
2105
+ const alias = this.expressionMap.findAliasByName(aliasName);
2106
+ const column = alias.metadata.findColumnWithPropertyPath(propertyPath);
2107
+ return (this.escape(parentAlias) +
2108
+ "." +
2109
+ this.escape(DriverUtils_1.DriverUtils.buildAlias(this.connection.driver, undefined, aliasName, column.databaseName)));
2110
+ }
2111
+ else {
2112
+ if (this.expressionMap.selects.find((select) => select.selection === orderCriteria ||
2113
+ select.aliasName === orderCriteria))
2114
+ return (this.escape(parentAlias) +
2115
+ "." +
2116
+ this.escape(orderCriteria));
2117
+ return "";
2118
+ }
2119
+ })
2120
+ .join(", ");
2121
+ const orderByObject = {};
2122
+ Object.keys(orderBys).forEach((orderCriteria) => {
2123
+ if (orderCriteria.indexOf(".") !== -1) {
2124
+ const criteriaParts = orderCriteria.split(".");
2125
+ const aliasName = criteriaParts[0];
2126
+ const propertyPath = criteriaParts.slice(1).join(".");
2127
+ const alias = this.expressionMap.findAliasByName(aliasName);
2128
+ const column = alias.metadata.findColumnWithPropertyPath(propertyPath);
2129
+ orderByObject[this.escape(parentAlias) +
2130
+ "." +
2131
+ this.escape(DriverUtils_1.DriverUtils.buildAlias(this.connection.driver, undefined, aliasName, column.databaseName))] = orderBys[orderCriteria];
2132
+ }
2133
+ else {
2134
+ if (this.expressionMap.selects.find((select) => select.selection === orderCriteria ||
2135
+ select.aliasName === orderCriteria)) {
2136
+ orderByObject[this.escape(parentAlias) +
2137
+ "." +
2138
+ this.escape(orderCriteria)] = orderBys[orderCriteria];
2139
+ }
2140
+ else {
2141
+ orderByObject[orderCriteria] = orderBys[orderCriteria];
2142
+ }
2143
+ }
2144
+ });
2145
+ return [selectString, orderByObject];
2146
+ }
2147
+ /**
2148
+ * Loads raw results from the database.
2149
+ */
2150
+ async loadRawResults(queryRunner) {
2151
+ const [sql, parameters] = this.getQueryAndParameters();
2152
+ const queryId = sql +
2153
+ " -- PARAMETERS: " +
2154
+ JSON.stringify(parameters, (_, value) => typeof value === "bigint" ? value.toString() : value);
2155
+ const cacheOptions = typeof this.connection.options.cache === "object"
2156
+ ? this.connection.options.cache
2157
+ : {};
2158
+ let savedQueryResultCacheOptions = undefined;
2159
+ const isCachingEnabled =
2160
+ // Caching is enabled globally and isn't disabled locally.
2161
+ (cacheOptions.alwaysEnabled &&
2162
+ this.expressionMap.cache !== false) ||
2163
+ // ...or it's enabled locally explicitly.
2164
+ this.expressionMap.cache === true;
2165
+ let cacheError = false;
2166
+ if (this.connection.queryResultCache && isCachingEnabled) {
2167
+ try {
2168
+ savedQueryResultCacheOptions =
2169
+ await this.connection.queryResultCache.getFromCache({
2170
+ identifier: this.expressionMap.cacheId,
2171
+ query: queryId,
2172
+ duration: this.expressionMap.cacheDuration ||
2173
+ cacheOptions.duration ||
2174
+ 1000,
2175
+ }, queryRunner);
2176
+ if (savedQueryResultCacheOptions &&
2177
+ !this.connection.queryResultCache.isExpired(savedQueryResultCacheOptions)) {
2178
+ return JSON.parse(savedQueryResultCacheOptions.result);
2179
+ }
2180
+ }
2181
+ catch (error) {
2182
+ if (!cacheOptions.ignoreErrors) {
2183
+ throw error;
2184
+ }
2185
+ cacheError = true;
2186
+ }
2187
+ }
2188
+ const results = await queryRunner.query(sql, parameters, true);
2189
+ if (!cacheError &&
2190
+ this.connection.queryResultCache &&
2191
+ isCachingEnabled) {
2192
+ try {
2193
+ await this.connection.queryResultCache.storeInCache({
2194
+ identifier: this.expressionMap.cacheId,
2195
+ query: queryId,
2196
+ time: Date.now(),
2197
+ duration: this.expressionMap.cacheDuration ||
2198
+ cacheOptions.duration ||
2199
+ 1000,
2200
+ result: JSON.stringify(results.records),
2201
+ }, savedQueryResultCacheOptions, queryRunner);
2202
+ }
2203
+ catch (error) {
2204
+ if (!cacheOptions.ignoreErrors) {
2205
+ throw error;
2206
+ }
2207
+ }
2208
+ }
2209
+ return results.records;
2210
+ }
2211
+ /**
2212
+ * Merges into expression map given expression map properties.
2213
+ */
2214
+ mergeExpressionMap(expressionMap) {
2215
+ ObjectUtils_1.ObjectUtils.assign(this.expressionMap, expressionMap);
2216
+ return this;
2217
+ }
2218
+ /**
2219
+ * Normalizes a give number - converts to int if possible.
2220
+ */
2221
+ normalizeNumber(num) {
2222
+ if (typeof num === "number" || num === undefined || num === null)
2223
+ return num;
2224
+ return Number(num);
2225
+ }
2226
+ /**
2227
+ * Creates a query builder used to execute sql queries inside this query builder.
2228
+ */
2229
+ obtainQueryRunner() {
2230
+ return (this.queryRunner ||
2231
+ this.connection.createQueryRunner(this.connection.defaultReplicationModeForReads()));
2232
+ }
2233
+ buildSelect(select, metadata, alias, embedPrefix) {
2234
+ for (const key in select) {
2235
+ if (select[key] === undefined || select[key] === false)
2236
+ continue;
2237
+ const propertyPath = embedPrefix ? embedPrefix + "." + key : key;
2238
+ const column = metadata.findColumnWithPropertyPathStrict(propertyPath);
2239
+ const embed = metadata.findEmbeddedWithPropertyPath(propertyPath);
2240
+ const relation = metadata.findRelationWithPropertyPath(propertyPath);
2241
+ if (!embed && !column && !relation)
2242
+ throw new EntityPropertyNotFoundError_1.EntityPropertyNotFoundError(propertyPath, metadata);
2243
+ if (column) {
2244
+ this.selects.push(alias + "." + propertyPath);
2245
+ // this.addSelect(alias + "." + propertyPath);
2246
+ }
2247
+ else if (embed) {
2248
+ this.buildSelect(select[key], metadata, alias, propertyPath);
2249
+ // } else if (relation) {
2250
+ // const joinAlias = alias + "_" + relation.propertyName;
2251
+ // const existJoin = this.joins.find(join => join.alias === joinAlias);
2252
+ // if (!existJoin) {
2253
+ // this.joins.push({
2254
+ // type: "left",
2255
+ // select: false,
2256
+ // alias: joinAlias,
2257
+ // parentAlias: alias,
2258
+ // relationMetadata: relation
2259
+ // });
2260
+ // }
2261
+ // this.buildOrder(select[key] as FindOptionsOrder<any>, relation.inverseEntityMetadata, joinAlias);
2262
+ }
2263
+ }
2264
+ }
2265
+ buildRelations(relations, selection, metadata, alias, embedPrefix) {
2266
+ if (!relations)
2267
+ return;
2268
+ Object.keys(relations).forEach((relationName) => {
2269
+ const relationValue = relations[relationName];
2270
+ const propertyPath = embedPrefix
2271
+ ? embedPrefix + "." + relationName
2272
+ : relationName;
2273
+ const embed = metadata.findEmbeddedWithPropertyPath(propertyPath);
2274
+ const relation = metadata.findRelationWithPropertyPath(propertyPath);
2275
+ if (!embed && !relation)
2276
+ throw new EntityPropertyNotFoundError_1.EntityPropertyNotFoundError(propertyPath, metadata);
2277
+ if (embed) {
2278
+ this.buildRelations(relationValue, typeof selection === "object"
2279
+ ? OrmUtils_1.OrmUtils.deepValue(selection, embed.propertyPath)
2280
+ : undefined, metadata, alias, propertyPath);
2281
+ }
2282
+ else if (relation) {
2283
+ let joinAlias = alias + "_" + propertyPath.replace(".", "_");
2284
+ joinAlias = DriverUtils_1.DriverUtils.buildAlias(this.connection.driver, { joiner: "__" }, alias, joinAlias);
2285
+ if (relationValue === true ||
2286
+ typeof relationValue === "object") {
2287
+ if (this.expressionMap.relationLoadStrategy === "query") {
2288
+ this.concatRelationMetadata(relation);
2289
+ }
2290
+ else {
2291
+ // join
2292
+ this.joins.push({
2293
+ type: "left",
2294
+ select: true,
2295
+ selection: selection &&
2296
+ typeof selection[relationName] === "object"
2297
+ ? selection[relationName]
2298
+ : undefined,
2299
+ alias: joinAlias,
2300
+ parentAlias: alias,
2301
+ relationMetadata: relation,
2302
+ });
2303
+ if (selection &&
2304
+ typeof selection[relationName] === "object") {
2305
+ this.buildSelect(selection[relationName], relation.inverseEntityMetadata, joinAlias);
2306
+ }
2307
+ }
2308
+ }
2309
+ if (typeof relationValue === "object" &&
2310
+ this.expressionMap.relationLoadStrategy === "join") {
2311
+ this.buildRelations(relationValue, typeof selection === "object"
2312
+ ? OrmUtils_1.OrmUtils.deepValue(selection, relation.propertyPath)
2313
+ : undefined, relation.inverseEntityMetadata, joinAlias, undefined);
2314
+ }
2315
+ }
2316
+ });
2317
+ }
2318
+ buildEagerRelations(relations, selection, metadata, alias, embedPrefix) {
2319
+ if (!relations)
2320
+ return;
2321
+ Object.keys(relations).forEach((relationName) => {
2322
+ const relationValue = relations[relationName];
2323
+ const propertyPath = embedPrefix
2324
+ ? embedPrefix + "." + relationName
2325
+ : relationName;
2326
+ const embed = metadata.findEmbeddedWithPropertyPath(propertyPath);
2327
+ const relation = metadata.findRelationWithPropertyPath(propertyPath);
2328
+ if (!embed && !relation)
2329
+ throw new EntityPropertyNotFoundError_1.EntityPropertyNotFoundError(propertyPath, metadata);
2330
+ if (embed) {
2331
+ this.buildEagerRelations(relationValue, typeof selection === "object"
2332
+ ? OrmUtils_1.OrmUtils.deepValue(selection, embed.propertyPath)
2333
+ : undefined, metadata, alias, propertyPath);
2334
+ }
2335
+ else if (relation) {
2336
+ let joinAlias = alias + "_" + propertyPath.replace(".", "_");
2337
+ joinAlias = DriverUtils_1.DriverUtils.buildAlias(this.connection.driver, { joiner: "__" }, alias, joinAlias);
2338
+ if (relationValue === true ||
2339
+ typeof relationValue === "object") {
2340
+ relation.inverseEntityMetadata.eagerRelations.forEach((eagerRelation) => {
2341
+ let eagerRelationJoinAlias = joinAlias +
2342
+ "_" +
2343
+ eagerRelation.propertyPath.replace(".", "_");
2344
+ eagerRelationJoinAlias = DriverUtils_1.DriverUtils.buildAlias(this.connection.driver, { joiner: "__" }, joinAlias, eagerRelationJoinAlias);
2345
+ const existJoin = this.joins.find((join) => join.alias === eagerRelationJoinAlias);
2346
+ if (!existJoin) {
2347
+ this.joins.push({
2348
+ type: "left",
2349
+ select: true,
2350
+ alias: eagerRelationJoinAlias,
2351
+ parentAlias: joinAlias,
2352
+ selection: undefined,
2353
+ relationMetadata: eagerRelation,
2354
+ });
2355
+ }
2356
+ if (selection &&
2357
+ typeof selection[relationName] === "object") {
2358
+ this.buildSelect(selection[relationName], relation.inverseEntityMetadata, joinAlias);
2359
+ }
2360
+ });
2361
+ }
2362
+ if (typeof relationValue === "object") {
2363
+ this.buildEagerRelations(relationValue, typeof selection === "object"
2364
+ ? OrmUtils_1.OrmUtils.deepValue(selection, relation.propertyPath)
2365
+ : undefined, relation.inverseEntityMetadata, joinAlias, undefined);
2366
+ }
2367
+ }
2368
+ });
2369
+ }
2370
+ buildOrder(order, metadata, alias, embedPrefix) {
2371
+ for (const key in order) {
2372
+ if (order[key] === undefined)
2373
+ continue;
2374
+ const propertyPath = embedPrefix ? embedPrefix + "." + key : key;
2375
+ const column = metadata.findColumnWithPropertyPathStrict(propertyPath);
2376
+ const embed = metadata.findEmbeddedWithPropertyPath(propertyPath);
2377
+ const relation = metadata.findRelationWithPropertyPath(propertyPath);
2378
+ if (!embed && !column && !relation)
2379
+ throw new EntityPropertyNotFoundError_1.EntityPropertyNotFoundError(propertyPath, metadata);
2380
+ if (column) {
2381
+ let direction = typeof order[key] === "object"
2382
+ ? order[key].direction
2383
+ : order[key];
2384
+ direction =
2385
+ direction === "DESC" ||
2386
+ direction === "desc" ||
2387
+ direction === -1
2388
+ ? "DESC"
2389
+ : "ASC";
2390
+ let nulls = typeof order[key] === "object"
2391
+ ? order[key].nulls
2392
+ : undefined;
2393
+ nulls =
2394
+ nulls?.toLowerCase() === "first"
2395
+ ? "NULLS FIRST"
2396
+ : nulls?.toLowerCase() === "last"
2397
+ ? "NULLS LAST"
2398
+ : undefined;
2399
+ const aliasPath = `${alias}.${propertyPath}`;
2400
+ // const selection = this.expressionMap.selects.find(
2401
+ // (s) => s.selection === aliasPath,
2402
+ // )
2403
+ // if (selection) {
2404
+ // // this is not building correctly now???
2405
+ // aliasPath = this.escape(
2406
+ // DriverUtils.buildAlias(
2407
+ // this.connection.driver,
2408
+ // undefined,
2409
+ // alias,
2410
+ // column.databaseName,
2411
+ // ),
2412
+ // )
2413
+ // // selection.aliasName = aliasPath
2414
+ // } else {
2415
+ // if (column.isVirtualProperty && column.query) {
2416
+ // aliasPath = `(${column.query(alias)})`
2417
+ // }
2418
+ // }
2419
+ // console.log("add sort", selection, aliasPath, direction, nulls)
2420
+ this.addOrderBy(aliasPath, direction, nulls);
2421
+ // this.orderBys.push({ alias: alias + "." + propertyPath, direction, nulls });
2422
+ }
2423
+ else if (embed) {
2424
+ this.buildOrder(order[key], metadata, alias, propertyPath);
2425
+ }
2426
+ else if (relation) {
2427
+ let joinAlias = alias + "_" + propertyPath.replace(".", "_");
2428
+ joinAlias = DriverUtils_1.DriverUtils.buildAlias(this.connection.driver, { joiner: "__" }, alias, joinAlias);
2429
+ // console.log("joinAlias", joinAlias, joinAlias.length, this.connection.driver.maxAliasLength)
2430
+ // todo: use expressionMap.joinAttributes, and create a new one using
2431
+ // const joinAttribute = new JoinAttribute(this.connection, this.expressionMap);
2432
+ const existJoin = this.joins.find((join) => join.alias === joinAlias);
2433
+ if (!existJoin) {
2434
+ this.joins.push({
2435
+ type: "left",
2436
+ select: false,
2437
+ alias: joinAlias,
2438
+ parentAlias: alias,
2439
+ selection: undefined,
2440
+ relationMetadata: relation,
2441
+ });
2442
+ }
2443
+ this.buildOrder(order[key], relation.inverseEntityMetadata, joinAlias);
2444
+ }
2445
+ }
2446
+ }
2447
+ buildWhere(where, metadata, alias, embedPrefix) {
2448
+ let condition = "";
2449
+ // let parameterIndex = Object.keys(this.expressionMap.nativeParameters).length;
2450
+ if (Array.isArray(where)) {
2451
+ if (where.length) {
2452
+ condition = where
2453
+ .map((whereItem) => {
2454
+ return this.buildWhere(whereItem, metadata, alias, embedPrefix);
2455
+ })
2456
+ .filter((condition) => !!condition)
2457
+ .map((condition) => "(" + condition + ")")
2458
+ .join(" OR ");
2459
+ }
2460
+ }
2461
+ else {
2462
+ const andConditions = [];
2463
+ for (const key in where) {
2464
+ if (where[key] === undefined || where[key] === null)
2465
+ continue;
2466
+ const propertyPath = embedPrefix ? embedPrefix + "." + key : key;
2467
+ const column = metadata.findColumnWithPropertyPathStrict(propertyPath);
2468
+ const embed = metadata.findEmbeddedWithPropertyPath(propertyPath);
2469
+ const relation = metadata.findRelationWithPropertyPath(propertyPath);
2470
+ if (!embed && !column && !relation)
2471
+ throw new EntityPropertyNotFoundError_1.EntityPropertyNotFoundError(propertyPath, metadata);
2472
+ if (column) {
2473
+ let aliasPath = `${alias}.${propertyPath}`;
2474
+ if (column.isVirtualProperty && column.query) {
2475
+ aliasPath = `(${column.query(this.escape(alias))})`;
2476
+ }
2477
+ // const parameterName = alias + "_" + propertyPath.split(".").join("_") + "_" + parameterIndex;
2478
+ // todo: we need to handle other operators as well?
2479
+ let parameterValue = where[key];
2480
+ if (InstanceChecker_1.InstanceChecker.isEqualOperator(where[key])) {
2481
+ parameterValue = where[key].value;
2482
+ }
2483
+ if (column.transformer) {
2484
+ if (parameterValue instanceof FindOperator_1.FindOperator) {
2485
+ parameterValue.transformValue(column.transformer);
2486
+ }
2487
+ else {
2488
+ parameterValue = ApplyValueTransformers_1.ApplyValueTransformers.transformTo(column.transformer, parameterValue);
2489
+ }
2490
+ }
2491
+ // MSSQL requires parameters to carry extra type information
2492
+ if (this.connection.driver.options.type === "mssql") {
2493
+ parameterValue = this.connection.driver.parametrizeValues(column, parameterValue);
2494
+ }
2495
+ // if (parameterValue === null) {
2496
+ // andConditions.push(`${aliasPath} IS NULL`);
2497
+ //
2498
+ // } else if (parameterValue instanceof FindOperator) {
2499
+ // // let parameters: any[] = [];
2500
+ // // if (parameterValue.useParameter) {
2501
+ // // const realParameterValues: any[] = parameterValue.multipleParameters ? parameterValue.value : [parameterValue.value];
2502
+ // // realParameterValues.forEach((realParameterValue, realParameterValueIndex) => {
2503
+ // //
2504
+ // // // don't create parameters for number to prevent max number of variables issues as much as possible
2505
+ // // if (typeof realParameterValue === "number") {
2506
+ // // parameters.push(realParameterValue);
2507
+ // //
2508
+ // // } else {
2509
+ // // this.expressionMap.nativeParameters[parameterName + realParameterValueIndex] = realParameterValue;
2510
+ // // parameterIndex++;
2511
+ // // parameters.push(this.connection.driver.createParameter(parameterName + realParameterValueIndex, parameterIndex - 1));
2512
+ // // }
2513
+ // // });
2514
+ // // }
2515
+ // andConditions.push(
2516
+ // this.createWhereConditionExpression(this.getWherePredicateCondition(aliasPath, parameterValue))
2517
+ // // parameterValue.toSql(this.connection, aliasPath, parameters));
2518
+ // )
2519
+ //
2520
+ // } else {
2521
+ // this.expressionMap.nativeParameters[parameterName] = parameterValue;
2522
+ // parameterIndex++;
2523
+ // const parameter = this.connection.driver.createParameter(parameterName, parameterIndex - 1);
2524
+ // andConditions.push(`${aliasPath} = ${parameter}`);
2525
+ // }
2526
+ andConditions.push(this.createWhereConditionExpression(this.getWherePredicateCondition(aliasPath, parameterValue)));
2527
+ // this.conditions.push(`${alias}.${propertyPath} = :${paramName}`);
2528
+ // this.expressionMap.parameters[paramName] = where[key]; // todo: handle functions and other edge cases
2529
+ }
2530
+ else if (embed) {
2531
+ const condition = this.buildWhere(where[key], metadata, alias, propertyPath);
2532
+ if (condition)
2533
+ andConditions.push(condition);
2534
+ }
2535
+ else if (relation) {
2536
+ // if all properties of where are undefined we don't need to join anything
2537
+ // this can happen when user defines map with conditional queries inside
2538
+ if (typeof where[key] === "object") {
2539
+ const allAllUndefined = Object.keys(where[key]).every((k) => where[key][k] === undefined);
2540
+ if (allAllUndefined) {
2541
+ continue;
2542
+ }
2543
+ }
2544
+ if (InstanceChecker_1.InstanceChecker.isFindOperator(where[key])) {
2545
+ if (where[key].type === "moreThan" ||
2546
+ where[key].type === "lessThan" ||
2547
+ where[key].type === "moreThanOrEqual" ||
2548
+ where[key].type === "lessThanOrEqual") {
2549
+ let sqlOperator = "";
2550
+ if (where[key].type === "moreThan") {
2551
+ sqlOperator = ">";
2552
+ }
2553
+ else if (where[key].type === "lessThan") {
2554
+ sqlOperator = "<";
2555
+ }
2556
+ else if (where[key].type === "moreThanOrEqual") {
2557
+ sqlOperator = ">=";
2558
+ }
2559
+ else if (where[key].type === "lessThanOrEqual") {
2560
+ sqlOperator = "<=";
2561
+ }
2562
+ // basically relation count functionality
2563
+ const qb = this.subQuery();
2564
+ if (relation.isManyToManyOwner) {
2565
+ qb.select("COUNT(*)")
2566
+ .from(relation.joinTableName, relation.joinTableName)
2567
+ .where(relation.joinColumns
2568
+ .map((column) => {
2569
+ return `${relation.joinTableName}.${column.propertyName} = ${alias}.${column.referencedColumn
2570
+ .propertyName}`;
2571
+ })
2572
+ .join(" AND "));
2573
+ }
2574
+ else if (relation.isManyToManyNotOwner) {
2575
+ qb.select("COUNT(*)")
2576
+ .from(relation.inverseRelation.joinTableName, relation.inverseRelation.joinTableName)
2577
+ .where(relation
2578
+ .inverseRelation.inverseJoinColumns.map((column) => {
2579
+ return `${relation.inverseRelation
2580
+ .joinTableName}.${column.propertyName} = ${alias}.${column.referencedColumn
2581
+ .propertyName}`;
2582
+ })
2583
+ .join(" AND "));
2584
+ }
2585
+ else if (relation.isOneToMany) {
2586
+ qb.select("COUNT(*)")
2587
+ .from(relation.inverseEntityMetadata.target, relation.inverseEntityMetadata
2588
+ .tableName)
2589
+ .where(relation
2590
+ .inverseRelation.joinColumns.map((column) => {
2591
+ return `${relation
2592
+ .inverseEntityMetadata
2593
+ .tableName}.${column.propertyName} = ${alias}.${column.referencedColumn
2594
+ .propertyName}`;
2595
+ })
2596
+ .join(" AND "));
2597
+ }
2598
+ else {
2599
+ throw new Error(`This relation isn't supported by given find operator`);
2600
+ }
2601
+ // this
2602
+ // .addSelect(qb.getSql(), relation.propertyAliasName + "_cnt")
2603
+ // .andWhere(this.escape(relation.propertyAliasName + "_cnt") + " " + sqlOperator + " " + parseInt(where[key].value));
2604
+ this.andWhere(qb.getSql() +
2605
+ " " +
2606
+ sqlOperator +
2607
+ " " +
2608
+ parseInt(where[key].value));
2609
+ }
2610
+ else {
2611
+ if (relation.isManyToOne ||
2612
+ (relation.isOneToOne &&
2613
+ relation.isOneToOneOwner)) {
2614
+ const aliasPath = `${alias}.${propertyPath}`;
2615
+ andConditions.push(this.createWhereConditionExpression(this.getWherePredicateCondition(aliasPath, where[key])));
2616
+ }
2617
+ else {
2618
+ throw new Error(`This relation isn't supported by given find operator`);
2619
+ }
2620
+ }
2621
+ }
2622
+ else {
2623
+ // const joinAlias = alias + "_" + relation.propertyName;
2624
+ let joinAlias = alias +
2625
+ "_" +
2626
+ relation.propertyPath.replace(".", "_");
2627
+ joinAlias = DriverUtils_1.DriverUtils.buildAlias(this.connection.driver, { joiner: "__" }, alias, joinAlias);
2628
+ const existJoin = this.joins.find((join) => join.alias === joinAlias);
2629
+ if (!existJoin) {
2630
+ this.joins.push({
2631
+ type: "left",
2632
+ select: false,
2633
+ selection: undefined,
2634
+ alias: joinAlias,
2635
+ parentAlias: alias,
2636
+ relationMetadata: relation,
2637
+ });
2638
+ }
2639
+ const condition = this.buildWhere(where[key], relation.inverseEntityMetadata, joinAlias);
2640
+ if (condition) {
2641
+ andConditions.push(condition);
2642
+ // parameterIndex = Object.keys(this.expressionMap.nativeParameters).length;
2643
+ }
2644
+ }
2645
+ }
2646
+ }
2647
+ condition = andConditions.length
2648
+ ? "(" + andConditions.join(") AND (") + ")"
2649
+ : andConditions.join(" AND ");
2650
+ }
2651
+ return condition.length ? "(" + condition + ")" : condition;
2652
+ }
2653
+ }
2654
+ exports.SelectQueryBuilder = SelectQueryBuilder;
2655
+
2656
+ //# sourceMappingURL=SelectQueryBuilder.js.map