prostgles-server 4.2.183 → 4.2.185

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 (432) hide show
  1. package/.github/workflows/main.yml +15 -15
  2. package/.prettierignore +2 -0
  3. package/README.md +1 -1
  4. package/dist/Auth/AuthHandler.d.ts +1 -1
  5. package/dist/Auth/AuthHandler.d.ts.map +1 -1
  6. package/dist/Auth/AuthHandler.js +64 -32
  7. package/dist/Auth/AuthHandler.js.map +1 -1
  8. package/dist/Auth/AuthTypes.d.ts +15 -1
  9. package/dist/Auth/AuthTypes.d.ts.map +1 -1
  10. package/dist/Auth/getSafeReturnURL.d.ts.map +1 -1
  11. package/dist/Auth/getSafeReturnURL.js.map +1 -1
  12. package/dist/Auth/sendEmail.d.ts.map +1 -1
  13. package/dist/Auth/sendEmail.js +6 -6
  14. package/dist/Auth/sendEmail.js.map +1 -1
  15. package/dist/Auth/setAuthProviders.d.ts +1 -1
  16. package/dist/Auth/setAuthProviders.d.ts.map +1 -1
  17. package/dist/Auth/setAuthProviders.js +15 -8
  18. package/dist/Auth/setAuthProviders.js.map +1 -1
  19. package/dist/Auth/setEmailProvider.d.ts.map +1 -1
  20. package/dist/Auth/setEmailProvider.js +23 -4
  21. package/dist/Auth/setEmailProvider.js.map +1 -1
  22. package/dist/Auth/setupAuthRoutes.d.ts.map +1 -1
  23. package/dist/Auth/setupAuthRoutes.js +27 -9
  24. package/dist/Auth/setupAuthRoutes.js.map +1 -1
  25. package/dist/DBEventsManager.d.ts.map +1 -1
  26. package/dist/DBEventsManager.js +24 -19
  27. package/dist/DBEventsManager.js.map +1 -1
  28. package/dist/DBSchemaBuilder.d.ts.map +1 -1
  29. package/dist/DBSchemaBuilder.js +18 -5
  30. package/dist/DBSchemaBuilder.js.map +1 -1
  31. package/dist/DboBuilder/DboBuilder.d.ts.map +1 -1
  32. package/dist/DboBuilder/DboBuilder.js +7 -2
  33. package/dist/DboBuilder/DboBuilder.js.map +1 -1
  34. package/dist/DboBuilder/DboBuilderTypes.d.ts +4 -4
  35. package/dist/DboBuilder/DboBuilderTypes.d.ts.map +1 -1
  36. package/dist/DboBuilder/DboBuilderTypes.js.map +1 -1
  37. package/dist/DboBuilder/QueryBuilder/Functions.d.ts +2 -2
  38. package/dist/DboBuilder/QueryBuilder/Functions.d.ts.map +1 -1
  39. package/dist/DboBuilder/QueryBuilder/Functions.js +293 -173
  40. package/dist/DboBuilder/QueryBuilder/Functions.js.map +1 -1
  41. package/dist/DboBuilder/QueryBuilder/QueryBuilder.d.ts +2 -2
  42. package/dist/DboBuilder/QueryBuilder/QueryBuilder.d.ts.map +1 -1
  43. package/dist/DboBuilder/QueryBuilder/QueryBuilder.js +52 -29
  44. package/dist/DboBuilder/QueryBuilder/QueryBuilder.js.map +1 -1
  45. package/dist/DboBuilder/QueryBuilder/getJoinQuery.d.ts.map +1 -1
  46. package/dist/DboBuilder/QueryBuilder/getJoinQuery.js +51 -32
  47. package/dist/DboBuilder/QueryBuilder/getJoinQuery.js.map +1 -1
  48. package/dist/DboBuilder/QueryBuilder/getNewQuery.d.ts.map +1 -1
  49. package/dist/DboBuilder/QueryBuilder/getNewQuery.js +48 -25
  50. package/dist/DboBuilder/QueryBuilder/getNewQuery.js.map +1 -1
  51. package/dist/DboBuilder/QueryBuilder/getSelectQuery.d.ts +1 -1
  52. package/dist/DboBuilder/QueryBuilder/getSelectQuery.d.ts.map +1 -1
  53. package/dist/DboBuilder/QueryBuilder/getSelectQuery.js +32 -23
  54. package/dist/DboBuilder/QueryBuilder/getSelectQuery.js.map +1 -1
  55. package/dist/DboBuilder/QueryStreamer.d.ts +2 -2
  56. package/dist/DboBuilder/QueryStreamer.d.ts.map +1 -1
  57. package/dist/DboBuilder/QueryStreamer.js +68 -23
  58. package/dist/DboBuilder/QueryStreamer.js.map +1 -1
  59. package/dist/DboBuilder/TableHandler/DataValidator.d.ts +1 -1
  60. package/dist/DboBuilder/TableHandler/DataValidator.d.ts.map +1 -1
  61. package/dist/DboBuilder/TableHandler/DataValidator.js +79 -43
  62. package/dist/DboBuilder/TableHandler/DataValidator.js.map +1 -1
  63. package/dist/DboBuilder/TableHandler/TableHandler.d.ts.map +1 -1
  64. package/dist/DboBuilder/TableHandler/TableHandler.js +39 -15
  65. package/dist/DboBuilder/TableHandler/TableHandler.js.map +1 -1
  66. package/dist/DboBuilder/TableHandler/delete.d.ts.map +1 -1
  67. package/dist/DboBuilder/TableHandler/delete.js +44 -13
  68. package/dist/DboBuilder/TableHandler/delete.js.map +1 -1
  69. package/dist/DboBuilder/TableHandler/insert.d.ts.map +1 -1
  70. package/dist/DboBuilder/TableHandler/insert.js +81 -22
  71. package/dist/DboBuilder/TableHandler/insert.js.map +1 -1
  72. package/dist/DboBuilder/TableHandler/insertTest.d.ts.map +1 -1
  73. package/dist/DboBuilder/TableHandler/insertTest.js.map +1 -1
  74. package/dist/DboBuilder/TableHandler/onDeleteFromFileTable.d.ts +1 -1
  75. package/dist/DboBuilder/TableHandler/onDeleteFromFileTable.d.ts.map +1 -1
  76. package/dist/DboBuilder/TableHandler/onDeleteFromFileTable.js +7 -4
  77. package/dist/DboBuilder/TableHandler/onDeleteFromFileTable.js.map +1 -1
  78. package/dist/DboBuilder/TableHandler/runInsertUpdateQuery.d.ts.map +1 -1
  79. package/dist/DboBuilder/TableHandler/runInsertUpdateQuery.js +24 -5
  80. package/dist/DboBuilder/TableHandler/runInsertUpdateQuery.js.map +1 -1
  81. package/dist/DboBuilder/TableHandler/update.d.ts.map +1 -1
  82. package/dist/DboBuilder/TableHandler/update.js +16 -4
  83. package/dist/DboBuilder/TableHandler/update.js.map +1 -1
  84. package/dist/DboBuilder/TableHandler/updateBatch.d.ts.map +1 -1
  85. package/dist/DboBuilder/TableHandler/updateBatch.js +33 -10
  86. package/dist/DboBuilder/TableHandler/updateBatch.js.map +1 -1
  87. package/dist/DboBuilder/TableHandler/updateFile.d.ts.map +1 -1
  88. package/dist/DboBuilder/TableHandler/updateFile.js +24 -6
  89. package/dist/DboBuilder/TableHandler/updateFile.js.map +1 -1
  90. package/dist/DboBuilder/TableHandler/upsert.d.ts.map +1 -1
  91. package/dist/DboBuilder/TableHandler/upsert.js +22 -6
  92. package/dist/DboBuilder/TableHandler/upsert.js.map +1 -1
  93. package/dist/DboBuilder/ViewHandler/ViewHandler.d.ts +5 -5
  94. package/dist/DboBuilder/ViewHandler/ViewHandler.d.ts.map +1 -1
  95. package/dist/DboBuilder/ViewHandler/ViewHandler.js +64 -36
  96. package/dist/DboBuilder/ViewHandler/ViewHandler.js.map +1 -1
  97. package/dist/DboBuilder/ViewHandler/count.d.ts.map +1 -1
  98. package/dist/DboBuilder/ViewHandler/count.js +21 -7
  99. package/dist/DboBuilder/ViewHandler/count.js.map +1 -1
  100. package/dist/DboBuilder/ViewHandler/find.d.ts.map +1 -1
  101. package/dist/DboBuilder/ViewHandler/find.js +76 -22
  102. package/dist/DboBuilder/ViewHandler/find.js.map +1 -1
  103. package/dist/DboBuilder/ViewHandler/getExistsCondition.d.ts.map +1 -1
  104. package/dist/DboBuilder/ViewHandler/getExistsCondition.js +19 -10
  105. package/dist/DboBuilder/ViewHandler/getExistsCondition.js.map +1 -1
  106. package/dist/DboBuilder/ViewHandler/getExistsFilters.d.ts.map +1 -1
  107. package/dist/DboBuilder/ViewHandler/getExistsFilters.js +12 -5
  108. package/dist/DboBuilder/ViewHandler/getExistsFilters.js.map +1 -1
  109. package/dist/DboBuilder/ViewHandler/getInfo.d.ts.map +1 -1
  110. package/dist/DboBuilder/ViewHandler/getInfo.js +27 -9
  111. package/dist/DboBuilder/ViewHandler/getInfo.js.map +1 -1
  112. package/dist/DboBuilder/ViewHandler/getTableJoinQuery.d.ts +2 -2
  113. package/dist/DboBuilder/ViewHandler/getTableJoinQuery.d.ts.map +1 -1
  114. package/dist/DboBuilder/ViewHandler/getTableJoinQuery.js +42 -23
  115. package/dist/DboBuilder/ViewHandler/getTableJoinQuery.js.map +1 -1
  116. package/dist/DboBuilder/ViewHandler/parseComplexFilter.d.ts.map +1 -1
  117. package/dist/DboBuilder/ViewHandler/parseComplexFilter.js +22 -9
  118. package/dist/DboBuilder/ViewHandler/parseComplexFilter.js.map +1 -1
  119. package/dist/DboBuilder/ViewHandler/parseFieldFilter.d.ts +4 -4
  120. package/dist/DboBuilder/ViewHandler/parseFieldFilter.d.ts.map +1 -1
  121. package/dist/DboBuilder/ViewHandler/parseFieldFilter.js +13 -11
  122. package/dist/DboBuilder/ViewHandler/parseFieldFilter.js.map +1 -1
  123. package/dist/DboBuilder/ViewHandler/parseJoinPath.d.ts +1 -1
  124. package/dist/DboBuilder/ViewHandler/parseJoinPath.d.ts.map +1 -1
  125. package/dist/DboBuilder/ViewHandler/parseJoinPath.js +44 -29
  126. package/dist/DboBuilder/ViewHandler/parseJoinPath.js.map +1 -1
  127. package/dist/DboBuilder/ViewHandler/prepareSortItems.d.ts.map +1 -1
  128. package/dist/DboBuilder/ViewHandler/prepareSortItems.js +36 -27
  129. package/dist/DboBuilder/ViewHandler/prepareSortItems.js.map +1 -1
  130. package/dist/DboBuilder/ViewHandler/prepareWhere.d.ts.map +1 -1
  131. package/dist/DboBuilder/ViewHandler/prepareWhere.js +16 -12
  132. package/dist/DboBuilder/ViewHandler/prepareWhere.js.map +1 -1
  133. package/dist/DboBuilder/ViewHandler/size.d.ts.map +1 -1
  134. package/dist/DboBuilder/ViewHandler/size.js +24 -7
  135. package/dist/DboBuilder/ViewHandler/size.js.map +1 -1
  136. package/dist/DboBuilder/ViewHandler/subscribe.d.ts.map +1 -1
  137. package/dist/DboBuilder/ViewHandler/subscribe.js +40 -12
  138. package/dist/DboBuilder/ViewHandler/subscribe.js.map +1 -1
  139. package/dist/DboBuilder/ViewHandler/validateViewRules.d.ts.map +1 -1
  140. package/dist/DboBuilder/ViewHandler/validateViewRules.js +20 -5
  141. package/dist/DboBuilder/ViewHandler/validateViewRules.js.map +1 -1
  142. package/dist/DboBuilder/dboBuilderUtils.d.ts.map +1 -1
  143. package/dist/DboBuilder/dboBuilderUtils.js +18 -7
  144. package/dist/DboBuilder/dboBuilderUtils.js.map +1 -1
  145. package/dist/DboBuilder/getColumns.d.ts.map +1 -1
  146. package/dist/DboBuilder/getColumns.js +22 -7
  147. package/dist/DboBuilder/getColumns.js.map +1 -1
  148. package/dist/DboBuilder/getCondition.d.ts.map +1 -1
  149. package/dist/DboBuilder/getCondition.js +43 -30
  150. package/dist/DboBuilder/getCondition.js.map +1 -1
  151. package/dist/DboBuilder/getSubscribeRelatedTables.d.ts.map +1 -1
  152. package/dist/DboBuilder/getSubscribeRelatedTables.js +38 -27
  153. package/dist/DboBuilder/getSubscribeRelatedTables.js.map +1 -1
  154. package/dist/DboBuilder/getTablesForSchemaPostgresSQL.d.ts.map +1 -1
  155. package/dist/DboBuilder/getTablesForSchemaPostgresSQL.js +9 -9
  156. package/dist/DboBuilder/getTablesForSchemaPostgresSQL.js.map +1 -1
  157. package/dist/DboBuilder/insertNestedRecords.d.ts +3 -3
  158. package/dist/DboBuilder/insertNestedRecords.d.ts.map +1 -1
  159. package/dist/DboBuilder/insertNestedRecords.js +79 -44
  160. package/dist/DboBuilder/insertNestedRecords.js.map +1 -1
  161. package/dist/DboBuilder/parseUpdateRules.d.ts.map +1 -1
  162. package/dist/DboBuilder/parseUpdateRules.js +38 -14
  163. package/dist/DboBuilder/parseUpdateRules.js.map +1 -1
  164. package/dist/DboBuilder/prepareShortestJoinPaths.d.ts.map +1 -1
  165. package/dist/DboBuilder/prepareShortestJoinPaths.js +56 -31
  166. package/dist/DboBuilder/prepareShortestJoinPaths.js.map +1 -1
  167. package/dist/DboBuilder/runSQL.d.ts.map +1 -1
  168. package/dist/DboBuilder/runSQL.js +41 -21
  169. package/dist/DboBuilder/runSQL.js.map +1 -1
  170. package/dist/DboBuilder/runTransaction.d.ts +1 -1
  171. package/dist/DboBuilder/runTransaction.d.ts.map +1 -1
  172. package/dist/DboBuilder/runTransaction.js +2 -2
  173. package/dist/DboBuilder/runTransaction.js.map +1 -1
  174. package/dist/DboBuilder/sqlErrCodeToMsg.d.ts.map +1 -1
  175. package/dist/DboBuilder/sqlErrCodeToMsg.js +297 -38
  176. package/dist/DboBuilder/sqlErrCodeToMsg.js.map +1 -1
  177. package/dist/DboBuilder/uploadFile.d.ts.map +1 -1
  178. package/dist/DboBuilder/uploadFile.js +33 -9
  179. package/dist/DboBuilder/uploadFile.js.map +1 -1
  180. package/dist/Event_Trigger_Tags.d.ts +1 -1
  181. package/dist/Event_Trigger_Tags.d.ts.map +1 -1
  182. package/dist/Event_Trigger_Tags.js +1 -1
  183. package/dist/Event_Trigger_Tags.js.map +1 -1
  184. package/dist/FileManager/FileManager.d.ts.map +1 -1
  185. package/dist/FileManager/FileManager.js +6 -3
  186. package/dist/FileManager/FileManager.js.map +1 -1
  187. package/dist/FileManager/getValidatedFileType.d.ts.map +1 -1
  188. package/dist/FileManager/getValidatedFileType.js +18 -16
  189. package/dist/FileManager/getValidatedFileType.js.map +1 -1
  190. package/dist/FileManager/initFileManager.d.ts.map +1 -1
  191. package/dist/FileManager/initFileManager.js +7 -1
  192. package/dist/FileManager/initFileManager.js.map +1 -1
  193. package/dist/FileManager/upload.d.ts +1 -1
  194. package/dist/FileManager/upload.d.ts.map +1 -1
  195. package/dist/FileManager/upload.js +3 -3
  196. package/dist/FileManager/upload.js.map +1 -1
  197. package/dist/FileManager/uploadStream.d.ts +1 -1
  198. package/dist/FileManager/uploadStream.d.ts.map +1 -1
  199. package/dist/FileManager/uploadStream.js +6 -7
  200. package/dist/FileManager/uploadStream.js.map +1 -1
  201. package/dist/Filtering.d.ts +3 -3
  202. package/dist/Filtering.d.ts.map +1 -1
  203. package/dist/Filtering.js +70 -37
  204. package/dist/Filtering.js.map +1 -1
  205. package/dist/JSONBValidation/validate_jsonb_schema_sql.d.ts.map +1 -1
  206. package/dist/JSONBValidation/validate_jsonb_schema_sql.js +1 -4
  207. package/dist/JSONBValidation/validate_jsonb_schema_sql.js.map +1 -1
  208. package/dist/JSONBValidation/validation.d.ts.map +1 -1
  209. package/dist/JSONBValidation/validation.js +46 -24
  210. package/dist/JSONBValidation/validation.js.map +1 -1
  211. package/dist/Logging.d.ts +2 -2
  212. package/dist/Logging.d.ts.map +1 -1
  213. package/dist/PostgresNotifListenManager.d.ts.map +1 -1
  214. package/dist/PostgresNotifListenManager.js +20 -22
  215. package/dist/PostgresNotifListenManager.js.map +1 -1
  216. package/dist/Prostgles.d.ts +1 -1
  217. package/dist/Prostgles.d.ts.map +1 -1
  218. package/dist/Prostgles.js +37 -11
  219. package/dist/Prostgles.js.map +1 -1
  220. package/dist/ProstglesTypes.d.ts.map +1 -1
  221. package/dist/ProstglesTypes.js +6 -1
  222. package/dist/ProstglesTypes.js.map +1 -1
  223. package/dist/PubSubManager/PubSubManager.d.ts.map +1 -1
  224. package/dist/PubSubManager/PubSubManager.js +10 -5
  225. package/dist/PubSubManager/PubSubManager.js.map +1 -1
  226. package/dist/PubSubManager/addSub.d.ts.map +1 -1
  227. package/dist/PubSubManager/addSub.js +4 -6
  228. package/dist/PubSubManager/addSub.js.map +1 -1
  229. package/dist/PubSubManager/addSync.d.ts.map +1 -1
  230. package/dist/PubSubManager/addSync.js +10 -6
  231. package/dist/PubSubManager/addSync.js.map +1 -1
  232. package/dist/PubSubManager/getCreatePubSubManagerError.d.ts.map +1 -1
  233. package/dist/PubSubManager/getCreatePubSubManagerError.js +3 -1
  234. package/dist/PubSubManager/getCreatePubSubManagerError.js.map +1 -1
  235. package/dist/PubSubManager/getPubSubManagerInitQuery.d.ts.map +1 -1
  236. package/dist/PubSubManager/getPubSubManagerInitQuery.js +8 -8
  237. package/dist/PubSubManager/getPubSubManagerInitQuery.js.map +1 -1
  238. package/dist/PubSubManager/initPubSubManager.d.ts.map +1 -1
  239. package/dist/PubSubManager/initPubSubManager.js +7 -9
  240. package/dist/PubSubManager/initPubSubManager.js.map +1 -1
  241. package/dist/PubSubManager/notifListener.d.ts.map +1 -1
  242. package/dist/PubSubManager/notifListener.js +23 -12
  243. package/dist/PubSubManager/notifListener.js.map +1 -1
  244. package/dist/PubSubManager/orphanTriggerCheck.d.ts.map +1 -1
  245. package/dist/PubSubManager/orphanTriggerCheck.js.map +1 -1
  246. package/dist/PubSubManager/pushSubData.d.ts.map +1 -1
  247. package/dist/PubSubManager/pushSubData.js +1 -1
  248. package/dist/PubSubManager/pushSubData.js.map +1 -1
  249. package/dist/PublishParser/PublishParser.d.ts +1 -1
  250. package/dist/PublishParser/PublishParser.d.ts.map +1 -1
  251. package/dist/PublishParser/PublishParser.js +25 -14
  252. package/dist/PublishParser/PublishParser.js.map +1 -1
  253. package/dist/PublishParser/getFileTableRules.d.ts.map +1 -1
  254. package/dist/PublishParser/getFileTableRules.js +23 -16
  255. package/dist/PublishParser/getFileTableRules.js.map +1 -1
  256. package/dist/PublishParser/getSchemaFromPublish.d.ts.map +1 -1
  257. package/dist/PublishParser/getSchemaFromPublish.js +39 -16
  258. package/dist/PublishParser/getSchemaFromPublish.js.map +1 -1
  259. package/dist/PublishParser/getTableRulesWithoutFileTable.d.ts.map +1 -1
  260. package/dist/PublishParser/getTableRulesWithoutFileTable.js +42 -22
  261. package/dist/PublishParser/getTableRulesWithoutFileTable.js.map +1 -1
  262. package/dist/PublishParser/publishTypesAndUtils.d.ts.map +1 -1
  263. package/dist/PublishParser/publishTypesAndUtils.js +5 -1
  264. package/dist/PublishParser/publishTypesAndUtils.js.map +1 -1
  265. package/dist/RestApi.d.ts +1 -1
  266. package/dist/RestApi.d.ts.map +1 -1
  267. package/dist/RestApi.js +1 -1
  268. package/dist/RestApi.js.map +1 -1
  269. package/dist/SchemaWatch/SchemaWatch.d.ts +2 -2
  270. package/dist/SchemaWatch/SchemaWatch.d.ts.map +1 -1
  271. package/dist/SchemaWatch/SchemaWatch.js +11 -9
  272. package/dist/SchemaWatch/SchemaWatch.js.map +1 -1
  273. package/dist/SchemaWatch/getValidatedWatchSchemaType.d.ts.map +1 -1
  274. package/dist/SchemaWatch/getValidatedWatchSchemaType.js +3 -3
  275. package/dist/SchemaWatch/getValidatedWatchSchemaType.js.map +1 -1
  276. package/dist/SchemaWatch/getWatchSchemaTagList.d.ts.map +1 -1
  277. package/dist/SchemaWatch/getWatchSchemaTagList.js +12 -6
  278. package/dist/SchemaWatch/getWatchSchemaTagList.js.map +1 -1
  279. package/dist/SyncReplication.d.ts.map +1 -1
  280. package/dist/SyncReplication.js +84 -42
  281. package/dist/SyncReplication.js.map +1 -1
  282. package/dist/TableConfig/TableConfig.d.ts +5 -5
  283. package/dist/TableConfig/TableConfig.d.ts.map +1 -1
  284. package/dist/TableConfig/TableConfig.js +18 -5
  285. package/dist/TableConfig/TableConfig.js.map +1 -1
  286. package/dist/TableConfig/getColumnDefinitionQuery.d.ts +2 -2
  287. package/dist/TableConfig/getColumnDefinitionQuery.d.ts.map +1 -1
  288. package/dist/TableConfig/getColumnDefinitionQuery.js +20 -9
  289. package/dist/TableConfig/getColumnDefinitionQuery.js.map +1 -1
  290. package/dist/TableConfig/getConstraintDefinitionQueries.d.ts +3 -3
  291. package/dist/TableConfig/getConstraintDefinitionQueries.d.ts.map +1 -1
  292. package/dist/TableConfig/getConstraintDefinitionQueries.js +12 -7
  293. package/dist/TableConfig/getConstraintDefinitionQueries.js.map +1 -1
  294. package/dist/TableConfig/getFutureTableSchema.d.ts +1 -1
  295. package/dist/TableConfig/getFutureTableSchema.d.ts.map +1 -1
  296. package/dist/TableConfig/getFutureTableSchema.js +6 -4
  297. package/dist/TableConfig/getFutureTableSchema.js.map +1 -1
  298. package/dist/TableConfig/getPGIndexes.d.ts.map +1 -1
  299. package/dist/TableConfig/getPGIndexes.js.map +1 -1
  300. package/dist/TableConfig/getTableColumnQueries.d.ts +1 -1
  301. package/dist/TableConfig/getTableColumnQueries.d.ts.map +1 -1
  302. package/dist/TableConfig/getTableColumnQueries.js +38 -19
  303. package/dist/TableConfig/getTableColumnQueries.js.map +1 -1
  304. package/dist/TableConfig/initTableConfig.d.ts.map +1 -1
  305. package/dist/TableConfig/initTableConfig.js +91 -43
  306. package/dist/TableConfig/initTableConfig.js.map +1 -1
  307. package/dist/index.d.ts.map +1 -1
  308. package/dist/index.js.map +1 -1
  309. package/dist/initProstgles.d.ts.map +1 -1
  310. package/dist/initProstgles.js +14 -10
  311. package/dist/initProstgles.js.map +1 -1
  312. package/dist/onSocketConnected.d.ts.map +1 -1
  313. package/dist/onSocketConnected.js +38 -16
  314. package/dist/onSocketConnected.js.map +1 -1
  315. package/dist/runClientRequest.d.ts.map +1 -1
  316. package/dist/runClientRequest.js +33 -14
  317. package/dist/runClientRequest.js.map +1 -1
  318. package/dist/shortestPath.d.ts.map +1 -1
  319. package/dist/shortestPath.js +1 -1
  320. package/dist/shortestPath.js.map +1 -1
  321. package/dist/typeTests/dboTypeCheck.js.map +1 -1
  322. package/examples/full-example-typescript/DBoGenerated.d.ts +112 -54
  323. package/examples/full-example-typescript/DBoGenerated.js +3 -3
  324. package/examples/full-example-typescript/home.html +28 -26
  325. package/examples/full-example-typescript/index.d.ts +1 -1
  326. package/examples/full-example-typescript/index.js +80 -53
  327. package/examples/full-example-vanilla/home.html +151 -125
  328. package/examples/server/javascript/index.js +17 -19
  329. package/lib/Auth/AuthHandler.ts +234 -155
  330. package/lib/Auth/AuthTypes.ts +27 -4
  331. package/lib/Auth/getSafeReturnURL.ts +35 -21
  332. package/lib/Auth/sendEmail.ts +34 -31
  333. package/lib/Auth/setAuthProviders.ts +94 -71
  334. package/lib/Auth/setEmailProvider.ts +45 -27
  335. package/lib/Auth/setupAuthRoutes.ts +164 -100
  336. package/lib/DBEventsManager.ts +87 -65
  337. package/lib/DBSchemaBuilder.ts +62 -28
  338. package/lib/DboBuilder/DboBuilder.ts +45 -21
  339. package/lib/DboBuilder/DboBuilderTypes.ts +99 -95
  340. package/lib/DboBuilder/QueryBuilder/Functions.ts +862 -580
  341. package/lib/DboBuilder/QueryBuilder/QueryBuilder.ts +202 -141
  342. package/lib/DboBuilder/QueryBuilder/getJoinQuery.ts +199 -124
  343. package/lib/DboBuilder/QueryBuilder/getNewQuery.ts +209 -148
  344. package/lib/DboBuilder/QueryBuilder/getSelectQuery.ts +101 -75
  345. package/lib/DboBuilder/QueryBuilder/prepareHaving.ts +10 -5
  346. package/lib/DboBuilder/QueryStreamer.ts +207 -100
  347. package/lib/DboBuilder/TableHandler/DataValidator.ts +253 -148
  348. package/lib/DboBuilder/TableHandler/TableHandler.ts +155 -60
  349. package/lib/DboBuilder/TableHandler/delete.ts +82 -29
  350. package/lib/DboBuilder/TableHandler/insert.ts +177 -81
  351. package/lib/DboBuilder/TableHandler/insertTest.ts +13 -7
  352. package/lib/DboBuilder/TableHandler/onDeleteFromFileTable.ts +35 -21
  353. package/lib/DboBuilder/TableHandler/runInsertUpdateQuery.ts +95 -45
  354. package/lib/DboBuilder/TableHandler/update.ts +54 -14
  355. package/lib/DboBuilder/TableHandler/updateBatch.ts +59 -21
  356. package/lib/DboBuilder/TableHandler/updateFile.ts +57 -26
  357. package/lib/DboBuilder/TableHandler/upsert.ts +58 -13
  358. package/lib/DboBuilder/ViewHandler/ViewHandler.ts +264 -121
  359. package/lib/DboBuilder/ViewHandler/count.ts +56 -25
  360. package/lib/DboBuilder/ViewHandler/find.ts +153 -68
  361. package/lib/DboBuilder/ViewHandler/getExistsCondition.ts +59 -32
  362. package/lib/DboBuilder/ViewHandler/getExistsFilters.ts +31 -19
  363. package/lib/DboBuilder/ViewHandler/getInfo.ts +47 -16
  364. package/lib/DboBuilder/ViewHandler/getTableJoinQuery.ts +91 -57
  365. package/lib/DboBuilder/ViewHandler/parseComplexFilter.ts +51 -29
  366. package/lib/DboBuilder/ViewHandler/parseFieldFilter.ts +35 -29
  367. package/lib/DboBuilder/ViewHandler/parseJoinPath.ts +130 -76
  368. package/lib/DboBuilder/ViewHandler/prepareSortItems.ts +140 -92
  369. package/lib/DboBuilder/ViewHandler/prepareWhere.ts +66 -26
  370. package/lib/DboBuilder/ViewHandler/size.ts +56 -22
  371. package/lib/DboBuilder/ViewHandler/subscribe.ts +122 -46
  372. package/lib/DboBuilder/ViewHandler/validateViewRules.ts +39 -14
  373. package/lib/DboBuilder/dboBuilderUtils.ts +41 -18
  374. package/lib/DboBuilder/getColumns.ts +44 -12
  375. package/lib/DboBuilder/getCondition.ts +120 -79
  376. package/lib/DboBuilder/getSubscribeRelatedTables.ts +144 -83
  377. package/lib/DboBuilder/getTablesForSchemaPostgresSQL.ts +61 -44
  378. package/lib/DboBuilder/insertNestedRecords.ts +370 -235
  379. package/lib/DboBuilder/parseUpdateRules.ts +117 -61
  380. package/lib/DboBuilder/prepareShortestJoinPaths.ts +115 -56
  381. package/lib/DboBuilder/runSQL.ts +135 -74
  382. package/lib/DboBuilder/runTransaction.ts +27 -16
  383. package/lib/DboBuilder/sqlErrCodeToMsg.ts +502 -244
  384. package/lib/DboBuilder/uploadFile.ts +67 -31
  385. package/lib/Event_Trigger_Tags.ts +6 -4
  386. package/lib/FileManager/FileManager.ts +53 -21
  387. package/lib/FileManager/getValidatedFileType.ts +79 -35
  388. package/lib/FileManager/initFileManager.ts +21 -9
  389. package/lib/FileManager/upload.ts +21 -19
  390. package/lib/FileManager/uploadStream.ts +33 -34
  391. package/lib/Filtering.ts +249 -197
  392. package/lib/JSONBValidation/validate_jsonb_schema_sql.ts +2 -7
  393. package/lib/JSONBValidation/validation.ts +147 -82
  394. package/lib/Logging.ts +107 -97
  395. package/lib/PostgresNotifListenManager.ts +96 -63
  396. package/lib/Prostgles.ts +106 -35
  397. package/lib/ProstglesTypes.ts +31 -9
  398. package/lib/PubSubManager/PubSubManager.ts +62 -27
  399. package/lib/PubSubManager/addSub.ts +56 -37
  400. package/lib/PubSubManager/addSync.ts +50 -33
  401. package/lib/PubSubManager/getCreatePubSubManagerError.ts +29 -21
  402. package/lib/PubSubManager/getPubSubManagerInitQuery.ts +45 -27
  403. package/lib/PubSubManager/initPubSubManager.ts +27 -18
  404. package/lib/PubSubManager/notifListener.ts +77 -59
  405. package/lib/PubSubManager/orphanTriggerCheck.ts +5 -4
  406. package/lib/PubSubManager/pushSubData.ts +11 -9
  407. package/lib/PublishParser/PublishParser.ts +102 -44
  408. package/lib/PublishParser/getFileTableRules.ts +97 -54
  409. package/lib/PublishParser/getSchemaFromPublish.ts +146 -74
  410. package/lib/PublishParser/getTableRulesWithoutFileTable.ts +101 -51
  411. package/lib/PublishParser/publishTypesAndUtils.ts +74 -23
  412. package/lib/RestApi.ts +10 -2
  413. package/lib/SchemaWatch/SchemaWatch.ts +52 -34
  414. package/lib/SchemaWatch/createSchemaWatchEventTrigger.ts +1 -1
  415. package/lib/SchemaWatch/getValidatedWatchSchemaType.ts +32 -22
  416. package/lib/SchemaWatch/getWatchSchemaTagList.ts +24 -16
  417. package/lib/SyncReplication.ts +376 -190
  418. package/lib/TableConfig/TableConfig.ts +200 -136
  419. package/lib/TableConfig/getColumnDefinitionQuery.ts +65 -44
  420. package/lib/TableConfig/getConstraintDefinitionQueries.ts +41 -25
  421. package/lib/TableConfig/getFutureTableSchema.ts +31 -21
  422. package/lib/TableConfig/getPGIndexes.ts +7 -4
  423. package/lib/TableConfig/getTableColumnQueries.ts +101 -54
  424. package/lib/TableConfig/initTableConfig.ts +192 -101
  425. package/lib/index.ts +6 -5
  426. package/lib/initProstgles.ts +57 -51
  427. package/lib/onSocketConnected.ts +75 -40
  428. package/lib/runClientRequest.ts +148 -79
  429. package/lib/shortestPath.ts +80 -76
  430. package/lib/typeTests/DBoGenerated.d.ts +5 -1
  431. package/lib/typeTests/dboTypeCheck.ts +8 -8
  432. package/package.json +1 -1
@@ -7,76 +7,93 @@ type parseJoinPathArgs = {
7
7
  viewHandler: ViewHandler;
8
8
  allowMultiOrJoin?: boolean;
9
9
  addShortestJoinIfMissing?: boolean;
10
- }
10
+ };
11
11
  export type ParsedJoinPath = { table: string; on: Record<string, string>[] };
12
12
 
13
13
  /**
14
14
  * Return a valid join path
15
15
  */
16
- export const parseJoinPath = ({ rawPath, rootTable, viewHandler, allowMultiOrJoin = false, addShortestJoinIfMissing }: parseJoinPathArgs): ParsedJoinPath[] => {
16
+ export const parseJoinPath = ({
17
+ rawPath,
18
+ rootTable,
19
+ viewHandler,
20
+ allowMultiOrJoin = false,
21
+ addShortestJoinIfMissing,
22
+ }: parseJoinPathArgs): ParsedJoinPath[] => {
17
23
  const result: ParsedJoinPath[] = [];
18
- let cleanPath = typeof rawPath === "string"? [{ table: rawPath }] : rawPath;
19
- if(addShortestJoinIfMissing && cleanPath[0] !== "**"){
20
- cleanPath = ["**", ...cleanPath]
24
+ let cleanPath = typeof rawPath === "string" ? [{ table: rawPath }] : rawPath;
25
+ if (addShortestJoinIfMissing && cleanPath[0] !== "**") {
26
+ cleanPath = ["**", ...cleanPath];
21
27
  }
22
28
  cleanPath.forEach((item, i) => {
23
29
  const prevTable = result.at(-1)?.table ?? rootTable;
24
- if(!prevTable) throw `prevTable missing`;
30
+ if (!prevTable) throw `prevTable missing`;
25
31
 
26
32
  const pushJoinPath = (targetPath: JoinPath) => {
27
33
  const getShortestJoin = i === 1 && cleanPath[0] === "**";
28
- const joinInfo = getJoins(viewHandler, prevTable, [targetPath], { allowMultiOrJoin, getShortestJoin });
29
-
30
- joinInfo.paths.forEach(path => {
34
+ const joinInfo = getJoins(viewHandler, prevTable, [targetPath], {
35
+ allowMultiOrJoin,
36
+ getShortestJoin,
37
+ });
31
38
 
39
+ joinInfo.paths.forEach((path) => {
32
40
  /** Check if join tables are valid */
33
41
  if (!viewHandler.dboBuilder.dbo[path.table]) {
34
- throw { stack: ["prepareExistCondition()"], message: `Invalid or dissallowed table in join path: ${path.table}` };
42
+ throw {
43
+ stack: ["prepareExistCondition()"],
44
+ message: `Invalid or dissallowed table in join path: ${path.table}`,
45
+ };
35
46
  }
36
47
  result.push({
37
48
  table: path.table,
38
- on: path.on.map(constraint => Object.fromEntries(constraint))
49
+ on: path.on.map((constraint) => Object.fromEntries(constraint)),
39
50
  });
40
- })
41
- }
51
+ });
52
+ };
42
53
 
43
54
  /** Shortest join */
44
- if(item === "**"){
45
-
46
- } else if(typeof item === "string"){
55
+ if (item === "**") {
56
+ } else if (typeof item === "string") {
47
57
  const table = item;
48
- pushJoinPath({ table })
58
+ pushJoinPath({ table });
49
59
  } else {
50
60
  pushJoinPath(item);
51
61
  }
52
62
  });
53
63
 
54
- const missingPath = result.find(r => !r.on.length || r.on.some(v => !Object.keys(v).length));
55
- if(missingPath){
56
- throw `Missing join on condition for: ${missingPath.table}`
64
+ const missingPath = result.find(
65
+ (r) => !r.on.length || r.on.some((v) => !Object.keys(v).length),
66
+ );
67
+ if (missingPath) {
68
+ throw `Missing join on condition for: ${missingPath.table}`;
57
69
  }
58
70
 
59
71
  return result;
60
- }
72
+ };
61
73
 
62
74
  import { JoinInfo } from "../DboBuilder";
63
75
 
64
76
  type Opts = {
65
77
  allowMultiOrJoin?: boolean;
66
78
  getShortestJoin?: boolean;
67
- }
79
+ };
68
80
 
69
81
  /**
70
82
  * Returns all tables and fields required to join from source table to target table
71
83
  * Respecting the path.on condition
72
84
  */
73
- function getJoins(viewHandler: ViewHandler, source: string, path: JoinPath[], { allowMultiOrJoin = true, getShortestJoin }: Opts = {}): JoinInfo {
85
+ function getJoins(
86
+ viewHandler: ViewHandler,
87
+ source: string,
88
+ path: JoinPath[],
89
+ { allowMultiOrJoin = true, getShortestJoin }: Opts = {},
90
+ ): JoinInfo {
74
91
  const [lastItem] = path;
75
- if(!lastItem){
92
+ if (!lastItem) {
76
93
  throw `Empty path`;
77
94
  }
78
- if(getShortestJoin && path.length !== 1){
79
- throw `getShortestJoin requires exactly 1 path item`
95
+ if (getShortestJoin && path.length !== 1) {
96
+ throw `getShortestJoin requires exactly 1 path item`;
80
97
  }
81
98
  const target = lastItem.table;
82
99
  if (!viewHandler.joinPaths) {
@@ -85,52 +102,77 @@ function getJoins(viewHandler: ViewHandler, source: string, path: JoinPath[], {
85
102
 
86
103
  /* Self join */
87
104
  if (source === target) {
88
- const tableHandler = viewHandler.dboBuilder.tablesOrViews?.find(t => t.name === source);
105
+ const tableHandler = viewHandler.dboBuilder.tablesOrViews?.find(
106
+ (t) => t.name === source,
107
+ );
89
108
  if (!tableHandler) throw `Table not found for joining ${source}`;
90
109
 
91
- const fcols = tableHandler.columns.filter(c => c.references?.some(({ ftable }) => ftable === viewHandler.name));
92
- if(!fcols.length){
93
- throw `There is no self-join foreign key relationship for table ${JSON.stringify(target)}`
110
+ const fcols = tableHandler.columns.filter((c) =>
111
+ c.references?.some(({ ftable }) => ftable === viewHandler.name),
112
+ );
113
+ if (!fcols.length) {
114
+ throw `There is no self-join foreign key relationship for table ${JSON.stringify(target)}`;
94
115
  }
95
116
  let allOnJoins: [string, string][][] = [];
96
- fcols.forEach(fc => {
117
+ fcols.forEach((fc) => {
97
118
  fc.references!.forEach(({ fcols, cols }) => {
98
- const fieldArr = fcols.map((fcol, i) => [fcol, cols[i]!] as [string, string]);
119
+ const fieldArr = fcols.map(
120
+ (fcol, i) => [fcol, cols[i]!] as [string, string],
121
+ );
99
122
  allOnJoins.push(fieldArr);
100
- })
123
+ });
101
124
  });
102
125
  allOnJoins = [
103
126
  ...allOnJoins,
104
127
  /** Reverse as well */
105
- ...allOnJoins.map(constraint => (constraint).map(([left, right]) => [right, left] as [string, string]))
106
- ]
128
+ ...allOnJoins.map((constraint) =>
129
+ constraint.map(([left, right]) => [right, left] as [string, string]),
130
+ ),
131
+ ];
107
132
  return {
108
- paths: [{
109
- source,
110
- target,
111
- table: target,
112
- on: getValidOn(lastItem.on, allOnJoins.map(v => Object.fromEntries(v)))
113
- }],
114
- expectOne: false
115
- }
133
+ paths: [
134
+ {
135
+ source,
136
+ target,
137
+ table: target,
138
+ on: getValidOn(
139
+ lastItem.on,
140
+ allOnJoins.map((v) => Object.fromEntries(v)),
141
+ ),
142
+ },
143
+ ],
144
+ expectOne: false,
145
+ };
116
146
  }
117
147
 
118
148
  /* Find the join path between tables */
119
- const tableConfigJoinInfo = viewHandler.dboBuilder?.prostgles?.tableConfigurator?.getJoinInfo(source, target);
149
+ const tableConfigJoinInfo =
150
+ viewHandler.dboBuilder?.prostgles?.tableConfigurator?.getJoinInfo(
151
+ source,
152
+ target,
153
+ );
120
154
  if (tableConfigJoinInfo) return tableConfigJoinInfo;
121
155
 
122
- const actualPath = getShortestJoin?
123
- viewHandler.joinPaths.find(j => {
124
- return j.t1 === source && j.t2 === target
125
- })?.path.map(table => ({ table, on: undefined })).slice(1) :
126
- viewHandler.joinPaths.find(j => {
127
- return j.path.join() === [{ table: source }, ...path].map(p => p.table).join()
128
- })? path : undefined;
156
+ const actualPath = getShortestJoin
157
+ ? viewHandler.joinPaths
158
+ .find((j) => {
159
+ return j.t1 === source && j.t2 === target;
160
+ })
161
+ ?.path.map((table) => ({ table, on: undefined }))
162
+ .slice(1)
163
+ : viewHandler.joinPaths.find((j) => {
164
+ return (
165
+ j.path.join() ===
166
+ [{ table: source }, ...path].map((p) => p.table).join()
167
+ );
168
+ })
169
+ ? path
170
+ : undefined;
129
171
 
130
- if(getShortestJoin && actualPath?.length && lastItem.on?.length){
131
- actualPath[actualPath.length-1]!.on = lastItem.on;
172
+ if (getShortestJoin && actualPath?.length && lastItem.on?.length) {
173
+ actualPath[actualPath.length - 1]!.on = lastItem.on;
132
174
  }
133
-
175
+
134
176
  if (!actualPath) {
135
177
  throw `Joining ${source} <-...-> ${target} dissallowed or missing`;
136
178
  }
@@ -144,19 +186,21 @@ function getJoins(viewHandler: ViewHandler, source: string, path: JoinPath[], {
144
186
  viewHandler.joins ??= viewHandler.dboBuilder.joins;
145
187
 
146
188
  /* Get join options */
147
- const join = viewHandler.joins.find(j => j.tables.includes(t1) && j.tables.includes(tablePath.table));
189
+ const join = viewHandler.joins.find(
190
+ (j) => j.tables.includes(t1) && j.tables.includes(tablePath.table),
191
+ );
148
192
  if (!join) {
149
193
  throw `Joining ${t1} <-> ${tablePath} dissallowed or missing`;
150
194
  }
151
195
  const isLtr = join.tables[0] === t1;
152
- const joinOn = isLtr? join.on : reverseJoinOn(join.on);
196
+ const joinOn = isLtr ? join.on : reverseJoinOn(join.on);
153
197
 
154
198
  const on = getValidOn(tablePath.on, joinOn);
155
199
  paths.push({
156
200
  source,
157
201
  target,
158
202
  table: tablePath.table,
159
- on
203
+ on,
160
204
  });
161
205
  });
162
206
  const expectOne = false;
@@ -172,37 +216,47 @@ function getJoins(viewHandler: ViewHandler, source: string, path: JoinPath[], {
172
216
  // }
173
217
  // })
174
218
 
175
- const isMultiOrJoin = paths.find(p => p.on.length > 1);
176
- if(!allowMultiOrJoin && isMultiOrJoin){
177
- throw `Table ${JSON.stringify(source)} can join to ${JSON.stringify(target)} through multiple constraints. Must chose one of ${JSON.stringify(isMultiOrJoin.on)}`
219
+ const isMultiOrJoin = paths.find((p) => p.on.length > 1);
220
+ if (!allowMultiOrJoin && isMultiOrJoin) {
221
+ throw `Table ${JSON.stringify(source)} can join to ${JSON.stringify(target)} through multiple constraints. Must chose one of ${JSON.stringify(isMultiOrJoin.on)}`;
178
222
  }
179
223
  return {
180
224
  paths,
181
- expectOne
225
+ expectOne,
182
226
  };
183
227
  }
184
228
 
185
- const getValidOn = (requested: JoinPath["on"], possible: ParsedJoinPath["on"]) => {
186
-
187
- if(!requested){
188
- return possible.map(v => Object.entries(v));
229
+ const getValidOn = (
230
+ requested: JoinPath["on"],
231
+ possible: ParsedJoinPath["on"],
232
+ ) => {
233
+ if (!requested) {
234
+ return possible.map((v) => Object.entries(v));
189
235
  }
190
- if(!requested.length){
191
- throw `Invalid requested "tablePath.on". Cannot be empty`
236
+ if (!requested.length) {
237
+ throw `Invalid requested "tablePath.on". Cannot be empty`;
192
238
  }
193
- const isValid = requested.every(requestedConstraint => {
194
- return possible.some(possibleConstraint => conditionsMatch(possibleConstraint, requestedConstraint));
239
+ const isValid = requested.every((requestedConstraint) => {
240
+ return possible.some((possibleConstraint) =>
241
+ conditionsMatch(possibleConstraint, requestedConstraint),
242
+ );
195
243
  });
196
244
 
197
- if(!isValid){
198
- throw `Invalid path specified for join: ${JSON.stringify(requested)}. Allowed paths: ${JSON.stringify(possible)}`
245
+ if (!isValid) {
246
+ throw `Invalid path specified for join: ${JSON.stringify(requested)}. Allowed paths: ${JSON.stringify(possible)}`;
199
247
  }
200
248
 
201
- return requested.map(v => Object.entries(v));
202
- }
249
+ return requested.map((v) => Object.entries(v));
250
+ };
203
251
 
204
- const conditionsMatch = (c1: Record<string, string>, c2: Record<string, string>) => {
252
+ const conditionsMatch = (
253
+ c1: Record<string, string>,
254
+ c2: Record<string, string>,
255
+ ) => {
205
256
  const keys1 = Object.keys(c1);
206
257
  const keys2 = Object.keys(c2);
207
- return keys1.sort().join() === keys2.sort().join() && keys1.every(key => c1[key] === c2[key]);
208
- }
258
+ return (
259
+ keys1.sort().join() === keys2.sort().join() &&
260
+ keys1.every((key) => c1[key] === c2[key])
261
+ );
262
+ };
@@ -1,6 +1,16 @@
1
- import { OrderBy, asName, isDefined, isEmpty, isObject } from "prostgles-types/dist";
1
+ import {
2
+ OrderBy,
3
+ asName,
4
+ isDefined,
5
+ isEmpty,
6
+ isObject,
7
+ } from "prostgles-types/dist";
2
8
  import { SortItem } from "../DboBuilder";
3
- import { NewQueryJoin, SelectItemValidated, asNameAlias } from "../QueryBuilder/QueryBuilder";
9
+ import {
10
+ NewQueryJoin,
11
+ SelectItemValidated,
12
+ asNameAlias,
13
+ } from "../QueryBuilder/QueryBuilder";
4
14
 
5
15
  /* This relates only to SELECT */
6
16
  export const prepareSortItems = (
@@ -10,127 +20,160 @@ export const prepareSortItems = (
10
20
  select: SelectItemValidated[],
11
21
  joinQueries: NewQueryJoin[],
12
22
  ): SortItem[] => {
13
-
14
23
  if (!rawOrderBy) return [];
15
24
 
16
- let orderBy: { key: string, asc: boolean, nulls?: "first" | "last", nullEmpty?: boolean }[] = [];
25
+ let orderBy: {
26
+ key: string;
27
+ asc: boolean;
28
+ nulls?: "first" | "last";
29
+ nullEmpty?: boolean;
30
+ }[] = [];
17
31
  if (isObject(rawOrderBy)) {
18
32
  orderBy = parseOrderObj(rawOrderBy);
19
33
  } else if (typeof rawOrderBy === "string") {
20
34
  /* string */
21
35
  orderBy = [{ key: rawOrderBy, asc: true }];
22
36
  } else if (Array.isArray(rawOrderBy)) {
23
-
24
37
  /* Order by is formed of a list of ascending field names */
25
- const _orderBy = (rawOrderBy as any[]);
26
- if (_orderBy && !_orderBy.find(v => typeof v !== "string")) {
38
+ const _orderBy = rawOrderBy as any[];
39
+ if (_orderBy && !_orderBy.find((v) => typeof v !== "string")) {
27
40
  /* [string] */
28
- orderBy = _orderBy.map(key => ({ key, asc: true }));
29
- } else if (_orderBy.find(v => isObject(v) && !isEmpty(v))) {
30
- orderBy = _orderBy.map(v => parseOrderObj(v, true)[0]!);
41
+ orderBy = _orderBy.map((key) => ({ key, asc: true }));
42
+ } else if (_orderBy.find((v) => isObject(v) && !isEmpty(v))) {
43
+ orderBy = _orderBy.map((v) => parseOrderObj(v, true)[0]!);
31
44
  } else return throwErr(rawOrderBy);
32
45
  } else return throwErr(rawOrderBy);
33
46
 
34
47
  if (!orderBy || !orderBy.length) return [];
35
48
 
36
- const validatedAggAliases = select.filter(s =>
37
- s.type !== "joinedColumn" &&
38
- (!s.fields.length || s.fields.every(f => allowed_cols.includes(f)))
39
- ).map(s => s.alias)
40
-
41
- const sortableNestedColumns = joinQueries.flatMap(jq => jq.select.map(selectItem => {
42
- const joinAlias = jq.tableAlias ?? jq.table;
43
- return {
44
- ...jq,
45
- selectItem,
46
- joinAlias,
47
- key: `${joinAlias}.${selectItem.alias}`
48
- }
49
- }));
50
- const bad_param = orderBy.find(({ key }) =>
51
- !sortableNestedColumns.some(v => v.key === key) &&
52
- !validatedAggAliases.includes(key) &&
53
- !allowed_cols.includes(key)
49
+ const validatedAggAliases = select
50
+ .filter(
51
+ (s) =>
52
+ s.type !== "joinedColumn" &&
53
+ (!s.fields.length || s.fields.every((f) => allowed_cols.includes(f))),
54
+ )
55
+ .map((s) => s.alias);
56
+
57
+ const sortableNestedColumns = joinQueries.flatMap((jq) =>
58
+ jq.select.map((selectItem) => {
59
+ const joinAlias = jq.tableAlias ?? jq.table;
60
+ return {
61
+ ...jq,
62
+ selectItem,
63
+ joinAlias,
64
+ key: `${joinAlias}.${selectItem.alias}`,
65
+ };
66
+ }),
67
+ );
68
+ const bad_param = orderBy.find(
69
+ ({ key }) =>
70
+ !sortableNestedColumns.some((v) => v.key === key) &&
71
+ !validatedAggAliases.includes(key) &&
72
+ !allowed_cols.includes(key),
54
73
  );
55
74
  if (bad_param) {
56
75
  throw "Invalid/disallowed orderBy fields or params: " + bad_param.key;
57
76
  }
58
77
 
59
- const selectedAliases = select.filter(s => s.selected).map(s => s.alias);
60
-
61
- const result: SortItem[] = orderBy.map(({ key, asc, nulls, nullEmpty = false }) => {
62
-
63
- const nestedField = sortableNestedColumns.find(f => f.key === key);
64
- if (nestedField) {
65
- const { table, selectItem, joinAlias } = nestedField;
66
-
67
- const comparableDataTypeCast = ["uuid", "xml"].includes(selectItem.column_udt_type ?? "")? "::TEXT" : "";
68
- const sortItemAlias = asName(`prostgles_nested_sort_${selectItem.alias}`)
69
-
70
- return {
71
- key,
72
- type: "query",
73
- asc,
74
- nulls,
75
- nullEmpty,
76
- nested: {
77
- table,
78
- joinAlias,
79
- selectItemAlias: selectItem.alias,
80
- isNumeric: selectItem.tsDataType === "number",
81
- wrapperQuerySortItem: `${asc? "MIN" : "MAX"}(${asNameAlias(selectItem.alias, joinAlias)}${comparableDataTypeCast}) as ${sortItemAlias}`,
82
- },
83
- fieldQuery: `${asName(joinAlias)}.${sortItemAlias + (asc? "" : " DESC")} ${nulls? `NULLS ${nulls === "last"? "LAST" : "FIRST" }` : ""}`,
78
+ const selectedAliases = select.filter((s) => s.selected).map((s) => s.alias);
79
+
80
+ const result: SortItem[] = orderBy.map(
81
+ ({ key, asc, nulls, nullEmpty = false }) => {
82
+ const nestedField = sortableNestedColumns.find((f) => f.key === key);
83
+ if (nestedField) {
84
+ const { table, selectItem, joinAlias } = nestedField;
85
+
86
+ const comparableDataTypeCast = ["uuid", "xml"].includes(
87
+ selectItem.column_udt_type ?? "",
88
+ )
89
+ ? "::TEXT"
90
+ : "";
91
+ const sortItemAlias = asName(
92
+ `prostgles_nested_sort_${selectItem.alias}`,
93
+ );
94
+
95
+ return {
96
+ key,
97
+ type: "query",
98
+ asc,
99
+ nulls,
100
+ nullEmpty,
101
+ nested: {
102
+ table,
103
+ joinAlias,
104
+ selectItemAlias: selectItem.alias,
105
+ isNumeric: selectItem.tsDataType === "number",
106
+ wrapperQuerySortItem: `${asc ? "MIN" : "MAX"}(${asNameAlias(selectItem.alias, joinAlias)}${comparableDataTypeCast}) as ${sortItemAlias}`,
107
+ },
108
+ fieldQuery: `${asName(joinAlias)}.${sortItemAlias + (asc ? "" : " DESC")} ${nulls ? `NULLS ${nulls === "last" ? "LAST" : "FIRST"}` : ""}`,
109
+ };
84
110
  }
85
- }
86
- /* Order by column index when possible to bypass name collision when ordering by a computed column.
111
+ /* Order by column index when possible to bypass name collision when ordering by a computed column.
87
112
  (Postgres will sort by existing columns wheundefined possible)
88
113
  */
89
-
90
- const index = selectedAliases.indexOf(key) + 1;
91
- let colKey = (index > 0 && !nullEmpty) ? index : [tableAlias, key].filter(isDefined).map(asName).join(".");
92
- if (nullEmpty) {
93
- colKey = `nullif(trim(${colKey}::text), '')`
94
- }
95
114
 
96
- if (typeof colKey === "number") {
115
+ const index = selectedAliases.indexOf(key) + 1;
116
+ let colKey =
117
+ index > 0 && !nullEmpty
118
+ ? index
119
+ : [tableAlias, key].filter(isDefined).map(asName).join(".");
120
+ if (nullEmpty) {
121
+ colKey = `nullif(trim(${colKey}::text), '')`;
122
+ }
123
+
124
+ if (typeof colKey === "number") {
125
+ return {
126
+ key,
127
+ type: "position",
128
+ asc,
129
+ nulls,
130
+ nullEmpty,
131
+ fieldPosition: colKey,
132
+ };
133
+ }
134
+
97
135
  return {
98
136
  key,
99
- type: "position",
100
- asc,
137
+ type: "query",
138
+ fieldQuery: colKey,
101
139
  nulls,
102
140
  nullEmpty,
103
- fieldPosition: colKey
104
- }
105
- }
106
-
107
- return {
108
- key,
109
- type: "query",
110
- fieldQuery: colKey,
111
- nulls,
112
- nullEmpty,
113
- asc,
114
- }
115
- });
141
+ asc,
142
+ };
143
+ },
144
+ );
116
145
 
117
146
  return result;
118
- }
147
+ };
119
148
 
120
149
  const throwErr = (rawOrderBy: any) => {
121
- throw "\nInvalid orderBy option -> " + JSON.stringify(rawOrderBy) +
122
- "Expecting: \
150
+ throw (
151
+ "\nInvalid orderBy option -> " +
152
+ JSON.stringify(rawOrderBy) +
153
+ "Expecting: \
123
154
  { key2: false, \"nested.key2\": false, key1: true } \
124
155
  { key1: 1, key2: -1 } \
125
156
  [{ key1: true }, { key2: false }] \
126
157
  [{ key: 'colName', asc: true, nulls: 'first', nullEmpty: true }]"
158
+ );
127
159
  };
128
160
 
129
- const parseOrderObj = (orderBy: any, expectOne = false): { key: string, asc: boolean, nulls?: "first" | "last", nullEmpty?: boolean }[] => {
161
+ const parseOrderObj = (
162
+ orderBy: any,
163
+ expectOne = false,
164
+ ): {
165
+ key: string;
166
+ asc: boolean;
167
+ nulls?: "first" | "last";
168
+ nullEmpty?: boolean;
169
+ }[] => {
130
170
  if (!isObject(orderBy)) return throwErr(orderBy);
131
171
 
132
172
  const keys = Object.keys(orderBy);
133
- if (keys.length && keys.find(k => ["key", "asc", "nulls", "nullEmpty"].includes(k))) {
173
+ if (
174
+ keys.length &&
175
+ keys.find((k) => ["key", "asc", "nulls", "nullEmpty"].includes(k))
176
+ ) {
134
177
  const { key, asc, nulls, nullEmpty = false } = orderBy;
135
178
  if (
136
179
  !["string"].includes(typeof key) ||
@@ -139,25 +182,30 @@ const parseOrderObj = (orderBy: any, expectOne = false): { key: string, asc: boo
139
182
  !["boolean"].includes(typeof nullEmpty)
140
183
  ) {
141
184
  throw `Invalid orderBy option (${JSON.stringify(orderBy, null, 2)}) \n
142
- Expecting { key: string, asc?: boolean, nulls?: 'first' | 'last' | null | undefined, nullEmpty?: boolean } `
185
+ Expecting { key: string, asc?: boolean, nulls?: 'first' | 'last' | null | undefined, nullEmpty?: boolean } `;
143
186
  }
144
187
  return [{ key, asc, nulls, nullEmpty }];
145
188
  }
146
189
 
147
190
  if (expectOne && keys.length > 1) {
148
- throw "\nInvalid orderBy " + JSON.stringify(orderBy) +
149
- "\nEach orderBy array element cannot have more than one key";
191
+ throw (
192
+ "\nInvalid orderBy " +
193
+ JSON.stringify(orderBy) +
194
+ "\nEach orderBy array element cannot have more than one key"
195
+ );
150
196
  }
151
197
  /* { key2: true, key1: false } */
152
- if (!Object.values(orderBy).find(v => ![true, false].includes(<any>v))) {
153
- return keys.map(key => ({ key, asc: Boolean(orderBy[key]) }))
198
+ if (!Object.values(orderBy).find((v) => ![true, false].includes(<any>v))) {
199
+ return keys.map((key) => ({ key, asc: Boolean(orderBy[key]) }));
154
200
 
155
201
  /* { key2: -1, key1: 1 } */
156
- } else if (!Object.values(orderBy).find(v => ![-1, 1].includes(<any>v))) {
157
- return keys.map(key => ({ key, asc: orderBy[key] === 1 }))
202
+ } else if (!Object.values(orderBy).find((v) => ![-1, 1].includes(<any>v))) {
203
+ return keys.map((key) => ({ key, asc: orderBy[key] === 1 }));
158
204
 
159
205
  /* { key2: "asc", key1: "desc" } */
160
- } else if (!Object.values(orderBy).find(v => !["asc", "desc"].includes(<any>v))) {
161
- return keys.map(key => ({ key, asc: orderBy[key] === "asc" }))
206
+ } else if (
207
+ !Object.values(orderBy).find((v) => !["asc", "desc"].includes(<any>v))
208
+ ) {
209
+ return keys.map((key) => ({ key, asc: orderBy[key] === "asc" }));
162
210
  } else return throwErr(orderBy);
163
- };
211
+ };