prostgles-server 4.2.187 → 4.2.188

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 (338) hide show
  1. package/.eslintignore +2 -1
  2. package/.eslintrc.json +2 -0
  3. package/dist/Auth/AuthHandler.d.ts +18 -11
  4. package/dist/Auth/AuthHandler.d.ts.map +1 -1
  5. package/dist/Auth/AuthHandler.js +94 -120
  6. package/dist/Auth/AuthHandler.js.map +1 -1
  7. package/dist/Auth/AuthTypes.d.ts +78 -71
  8. package/dist/Auth/AuthTypes.d.ts.map +1 -1
  9. package/dist/Auth/{setEmailProvider.d.ts → authProviders/setEmailProvider.d.ts} +1 -1
  10. package/dist/Auth/authProviders/setEmailProvider.d.ts.map +1 -0
  11. package/dist/Auth/authProviders/setEmailProvider.js +27 -0
  12. package/dist/Auth/authProviders/setEmailProvider.js.map +1 -0
  13. package/dist/Auth/authProviders/setOAuthProviders.d.ts +5 -0
  14. package/dist/Auth/authProviders/setOAuthProviders.d.ts.map +1 -0
  15. package/dist/Auth/authProviders/setOAuthProviders.js +78 -0
  16. package/dist/Auth/authProviders/setOAuthProviders.js.map +1 -0
  17. package/dist/Auth/endpoints/getConfirmEmailRequestHandler.d.ts +7 -0
  18. package/dist/Auth/endpoints/getConfirmEmailRequestHandler.d.ts.map +1 -0
  19. package/dist/Auth/endpoints/getConfirmEmailRequestHandler.js +29 -0
  20. package/dist/Auth/endpoints/getConfirmEmailRequestHandler.js.map +1 -0
  21. package/dist/Auth/endpoints/getRegisterRequestHandler.d.ts +7 -0
  22. package/dist/Auth/endpoints/getRegisterRequestHandler.d.ts.map +1 -0
  23. package/dist/Auth/endpoints/getRegisterRequestHandler.js +74 -0
  24. package/dist/Auth/endpoints/getRegisterRequestHandler.js.map +1 -0
  25. package/dist/Auth/setAuthProviders.d.ts.map +1 -1
  26. package/dist/Auth/setAuthProviders.js +4 -74
  27. package/dist/Auth/setAuthProviders.js.map +1 -1
  28. package/dist/Auth/setupAuthRoutes.d.ts.map +1 -1
  29. package/dist/Auth/setupAuthRoutes.js +23 -33
  30. package/dist/Auth/setupAuthRoutes.js.map +1 -1
  31. package/dist/Auth/utils/checkDmarc.d.ts +2 -0
  32. package/dist/Auth/utils/checkDmarc.d.ts.map +1 -0
  33. package/dist/Auth/utils/checkDmarc.js +22 -0
  34. package/dist/Auth/utils/checkDmarc.js.map +1 -0
  35. package/dist/Auth/utils/getClientRequestIPsInfo.d.ts +3 -0
  36. package/dist/Auth/utils/getClientRequestIPsInfo.d.ts.map +1 -0
  37. package/dist/Auth/utils/getClientRequestIPsInfo.js +29 -0
  38. package/dist/Auth/utils/getClientRequestIPsInfo.js.map +1 -0
  39. package/dist/Auth/utils/getReturnUrl.d.ts +3 -0
  40. package/dist/Auth/utils/getReturnUrl.d.ts.map +1 -0
  41. package/dist/Auth/utils/getReturnUrl.js +15 -0
  42. package/dist/Auth/utils/getReturnUrl.js.map +1 -0
  43. package/dist/Auth/utils/getSafeReturnURL.d.ts.map +1 -0
  44. package/dist/Auth/utils/getSafeReturnURL.js.map +1 -0
  45. package/dist/DBEventsManager.d.ts.map +1 -1
  46. package/dist/DBEventsManager.js +4 -5
  47. package/dist/DBEventsManager.js.map +1 -1
  48. package/dist/DBSchemaBuilder.js +1 -1
  49. package/dist/DBSchemaBuilder.js.map +1 -1
  50. package/dist/DboBuilder/DboBuilder.d.ts +0 -1
  51. package/dist/DboBuilder/DboBuilder.d.ts.map +1 -1
  52. package/dist/DboBuilder/DboBuilder.js +3 -12
  53. package/dist/DboBuilder/DboBuilder.js.map +1 -1
  54. package/dist/DboBuilder/DboBuilderTypes.d.ts +4 -4
  55. package/dist/DboBuilder/DboBuilderTypes.d.ts.map +1 -1
  56. package/dist/DboBuilder/DboBuilderTypes.js.map +1 -1
  57. package/dist/DboBuilder/QueryBuilder/Functions.d.ts.map +1 -1
  58. package/dist/DboBuilder/QueryBuilder/Functions.js +38 -76
  59. package/dist/DboBuilder/QueryBuilder/Functions.js.map +1 -1
  60. package/dist/DboBuilder/QueryBuilder/QueryBuilder.d.ts.map +1 -1
  61. package/dist/DboBuilder/QueryBuilder/QueryBuilder.js +4 -12
  62. package/dist/DboBuilder/QueryBuilder/QueryBuilder.js.map +1 -1
  63. package/dist/DboBuilder/QueryBuilder/getNewQuery.d.ts.map +1 -1
  64. package/dist/DboBuilder/QueryBuilder/getNewQuery.js +23 -33
  65. package/dist/DboBuilder/QueryBuilder/getNewQuery.js.map +1 -1
  66. package/dist/DboBuilder/QueryBuilder/getSelectQuery.d.ts +1 -1
  67. package/dist/DboBuilder/QueryBuilder/getSelectQuery.d.ts.map +1 -1
  68. package/dist/DboBuilder/QueryBuilder/getSelectQuery.js +6 -6
  69. package/dist/DboBuilder/QueryBuilder/getSelectQuery.js.map +1 -1
  70. package/dist/DboBuilder/QueryStreamer.d.ts.map +1 -1
  71. package/dist/DboBuilder/QueryStreamer.js +13 -19
  72. package/dist/DboBuilder/QueryStreamer.js.map +1 -1
  73. package/dist/DboBuilder/TableHandler/DataValidator.d.ts +1 -1
  74. package/dist/DboBuilder/TableHandler/DataValidator.d.ts.map +1 -1
  75. package/dist/DboBuilder/TableHandler/DataValidator.js +7 -16
  76. package/dist/DboBuilder/TableHandler/DataValidator.js.map +1 -1
  77. package/dist/DboBuilder/TableHandler/TableHandler.d.ts.map +1 -1
  78. package/dist/DboBuilder/TableHandler/TableHandler.js +7 -5
  79. package/dist/DboBuilder/TableHandler/TableHandler.js.map +1 -1
  80. package/dist/DboBuilder/TableHandler/delete.d.ts.map +1 -1
  81. package/dist/DboBuilder/TableHandler/delete.js +5 -8
  82. package/dist/DboBuilder/TableHandler/delete.js.map +1 -1
  83. package/dist/DboBuilder/TableHandler/insert.d.ts.map +1 -1
  84. package/dist/DboBuilder/TableHandler/insert.js +10 -15
  85. package/dist/DboBuilder/TableHandler/insert.js.map +1 -1
  86. package/dist/DboBuilder/TableHandler/insertTest.js +1 -1
  87. package/dist/DboBuilder/TableHandler/insertTest.js.map +1 -1
  88. package/dist/DboBuilder/TableHandler/runInsertUpdateQuery.d.ts.map +1 -1
  89. package/dist/DboBuilder/TableHandler/runInsertUpdateQuery.js +1 -1
  90. package/dist/DboBuilder/TableHandler/runInsertUpdateQuery.js.map +1 -1
  91. package/dist/DboBuilder/TableHandler/update.d.ts.map +1 -1
  92. package/dist/DboBuilder/TableHandler/update.js +5 -9
  93. package/dist/DboBuilder/TableHandler/update.js.map +1 -1
  94. package/dist/DboBuilder/TableHandler/updateFile.d.ts +1 -1
  95. package/dist/DboBuilder/TableHandler/updateFile.d.ts.map +1 -1
  96. package/dist/DboBuilder/TableHandler/updateFile.js +7 -9
  97. package/dist/DboBuilder/TableHandler/updateFile.js.map +1 -1
  98. package/dist/DboBuilder/TableHandler/upsert.d.ts.map +1 -1
  99. package/dist/DboBuilder/TableHandler/upsert.js +1 -1
  100. package/dist/DboBuilder/TableHandler/upsert.js.map +1 -1
  101. package/dist/DboBuilder/ViewHandler/ViewHandler.d.ts.map +1 -1
  102. package/dist/DboBuilder/ViewHandler/ViewHandler.js +11 -13
  103. package/dist/DboBuilder/ViewHandler/ViewHandler.js.map +1 -1
  104. package/dist/DboBuilder/ViewHandler/count.js +1 -1
  105. package/dist/DboBuilder/ViewHandler/count.js.map +1 -1
  106. package/dist/DboBuilder/ViewHandler/find.d.ts.map +1 -1
  107. package/dist/DboBuilder/ViewHandler/find.js +20 -27
  108. package/dist/DboBuilder/ViewHandler/find.js.map +1 -1
  109. package/dist/DboBuilder/ViewHandler/getExistsCondition.d.ts.map +1 -1
  110. package/dist/DboBuilder/ViewHandler/getExistsCondition.js +4 -10
  111. package/dist/DboBuilder/ViewHandler/getExistsCondition.js.map +1 -1
  112. package/dist/DboBuilder/ViewHandler/getInfo.js +2 -2
  113. package/dist/DboBuilder/ViewHandler/getInfo.js.map +1 -1
  114. package/dist/DboBuilder/ViewHandler/getTableJoinQuery.d.ts.map +1 -1
  115. package/dist/DboBuilder/ViewHandler/getTableJoinQuery.js +6 -22
  116. package/dist/DboBuilder/ViewHandler/getTableJoinQuery.js.map +1 -1
  117. package/dist/DboBuilder/ViewHandler/parseFieldFilter.d.ts.map +1 -1
  118. package/dist/DboBuilder/ViewHandler/parseFieldFilter.js +6 -10
  119. package/dist/DboBuilder/ViewHandler/parseFieldFilter.js.map +1 -1
  120. package/dist/DboBuilder/ViewHandler/parseJoinPath.d.ts.map +1 -1
  121. package/dist/DboBuilder/ViewHandler/parseJoinPath.js +8 -11
  122. package/dist/DboBuilder/ViewHandler/parseJoinPath.js.map +1 -1
  123. package/dist/DboBuilder/ViewHandler/prepareSortItems.d.ts.map +1 -1
  124. package/dist/DboBuilder/ViewHandler/prepareSortItems.js +7 -12
  125. package/dist/DboBuilder/ViewHandler/prepareSortItems.js.map +1 -1
  126. package/dist/DboBuilder/ViewHandler/prepareWhere.d.ts.map +1 -1
  127. package/dist/DboBuilder/ViewHandler/prepareWhere.js +6 -10
  128. package/dist/DboBuilder/ViewHandler/prepareWhere.js.map +1 -1
  129. package/dist/DboBuilder/dboBuilderUtils.d.ts.map +1 -1
  130. package/dist/DboBuilder/dboBuilderUtils.js +8 -23
  131. package/dist/DboBuilder/dboBuilderUtils.js.map +1 -1
  132. package/dist/DboBuilder/getColumns.d.ts.map +1 -1
  133. package/dist/DboBuilder/getColumns.js +19 -26
  134. package/dist/DboBuilder/getColumns.js.map +1 -1
  135. package/dist/DboBuilder/getCondition.d.ts.map +1 -1
  136. package/dist/DboBuilder/getCondition.js +7 -9
  137. package/dist/DboBuilder/getCondition.js.map +1 -1
  138. package/dist/DboBuilder/getSubscribeRelatedTables.js +2 -2
  139. package/dist/DboBuilder/getSubscribeRelatedTables.js.map +1 -1
  140. package/dist/DboBuilder/getTablesForSchemaPostgresSQL.d.ts.map +1 -1
  141. package/dist/DboBuilder/getTablesForSchemaPostgresSQL.js +14 -15
  142. package/dist/DboBuilder/getTablesForSchemaPostgresSQL.js.map +1 -1
  143. package/dist/DboBuilder/insertNestedRecords.d.ts.map +1 -1
  144. package/dist/DboBuilder/insertNestedRecords.js +26 -40
  145. package/dist/DboBuilder/insertNestedRecords.js.map +1 -1
  146. package/dist/DboBuilder/parseUpdateRules.js +1 -1
  147. package/dist/DboBuilder/parseUpdateRules.js.map +1 -1
  148. package/dist/DboBuilder/prepareShortestJoinPaths.d.ts.map +1 -1
  149. package/dist/DboBuilder/prepareShortestJoinPaths.js +12 -18
  150. package/dist/DboBuilder/prepareShortestJoinPaths.js.map +1 -1
  151. package/dist/DboBuilder/runSQL.d.ts +1 -1
  152. package/dist/DboBuilder/runSQL.d.ts.map +1 -1
  153. package/dist/DboBuilder/runSQL.js +14 -27
  154. package/dist/DboBuilder/runSQL.js.map +1 -1
  155. package/dist/DboBuilder/uploadFile.d.ts +1 -1
  156. package/dist/DboBuilder/uploadFile.d.ts.map +1 -1
  157. package/dist/DboBuilder/uploadFile.js +4 -11
  158. package/dist/DboBuilder/uploadFile.js.map +1 -1
  159. package/dist/FileManager/FileManager.d.ts.map +1 -1
  160. package/dist/FileManager/FileManager.js +11 -13
  161. package/dist/FileManager/FileManager.js.map +1 -1
  162. package/dist/FileManager/initFileManager.d.ts.map +1 -1
  163. package/dist/FileManager/initFileManager.js +60 -62
  164. package/dist/FileManager/initFileManager.js.map +1 -1
  165. package/dist/FileManager/uploadStream.js +2 -2
  166. package/dist/FileManager/uploadStream.js.map +1 -1
  167. package/dist/Filtering.d.ts +1 -1
  168. package/dist/Filtering.d.ts.map +1 -1
  169. package/dist/Filtering.js +12 -35
  170. package/dist/Filtering.js.map +1 -1
  171. package/dist/JSONBValidation/validation.d.ts.map +1 -1
  172. package/dist/JSONBValidation/validation.js +20 -26
  173. package/dist/JSONBValidation/validation.js.map +1 -1
  174. package/dist/Logging.d.ts +1 -0
  175. package/dist/Logging.d.ts.map +1 -1
  176. package/dist/PostgresNotifListenManager.d.ts.map +1 -1
  177. package/dist/PostgresNotifListenManager.js +1 -5
  178. package/dist/PostgresNotifListenManager.js.map +1 -1
  179. package/dist/Prostgles.d.ts +1 -1
  180. package/dist/Prostgles.d.ts.map +1 -1
  181. package/dist/Prostgles.js +18 -33
  182. package/dist/Prostgles.js.map +1 -1
  183. package/dist/PubSubManager/PubSubManager.d.ts.map +1 -1
  184. package/dist/PubSubManager/PubSubManager.js +8 -13
  185. package/dist/PubSubManager/PubSubManager.js.map +1 -1
  186. package/dist/PubSubManager/addSub.d.ts.map +1 -1
  187. package/dist/PubSubManager/addSub.js +1 -1
  188. package/dist/PubSubManager/addSub.js.map +1 -1
  189. package/dist/PubSubManager/addSync.d.ts.map +1 -1
  190. package/dist/PubSubManager/addSync.js +4 -7
  191. package/dist/PubSubManager/addSync.js.map +1 -1
  192. package/dist/PubSubManager/getCreatePubSubManagerError.js +6 -6
  193. package/dist/PubSubManager/getCreatePubSubManagerError.js.map +1 -1
  194. package/dist/PubSubManager/initPubSubManager.d.ts.map +1 -1
  195. package/dist/PubSubManager/initPubSubManager.js +2 -3
  196. package/dist/PubSubManager/initPubSubManager.js.map +1 -1
  197. package/dist/PubSubManager/pushSubData.d.ts.map +1 -1
  198. package/dist/PubSubManager/pushSubData.js +0 -2
  199. package/dist/PubSubManager/pushSubData.js.map +1 -1
  200. package/dist/PublishParser/PublishParser.d.ts.map +1 -1
  201. package/dist/PublishParser/PublishParser.js +8 -13
  202. package/dist/PublishParser/PublishParser.js.map +1 -1
  203. package/dist/PublishParser/getFileTableRules.js +1 -1
  204. package/dist/PublishParser/getFileTableRules.js.map +1 -1
  205. package/dist/PublishParser/getSchemaFromPublish.d.ts.map +1 -1
  206. package/dist/PublishParser/getSchemaFromPublish.js +6 -13
  207. package/dist/PublishParser/getSchemaFromPublish.js.map +1 -1
  208. package/dist/PublishParser/getTableRulesWithoutFileTable.d.ts.map +1 -1
  209. package/dist/PublishParser/getTableRulesWithoutFileTable.js +14 -19
  210. package/dist/PublishParser/getTableRulesWithoutFileTable.js.map +1 -1
  211. package/dist/RestApi.d.ts +1 -1
  212. package/dist/RestApi.d.ts.map +1 -1
  213. package/dist/RestApi.js +2 -2
  214. package/dist/RestApi.js.map +1 -1
  215. package/dist/SchemaWatch/SchemaWatch.d.ts.map +1 -1
  216. package/dist/SchemaWatch/SchemaWatch.js +2 -2
  217. package/dist/SchemaWatch/SchemaWatch.js.map +1 -1
  218. package/dist/SyncReplication.d.ts.map +1 -1
  219. package/dist/SyncReplication.js +31 -41
  220. package/dist/SyncReplication.js.map +1 -1
  221. package/dist/TableConfig/TableConfig.d.ts.map +1 -1
  222. package/dist/TableConfig/TableConfig.js +7 -9
  223. package/dist/TableConfig/TableConfig.js.map +1 -1
  224. package/dist/TableConfig/getConstraintDefinitionQueries.d.ts.map +1 -1
  225. package/dist/TableConfig/getConstraintDefinitionQueries.js +1 -6
  226. package/dist/TableConfig/getConstraintDefinitionQueries.js.map +1 -1
  227. package/dist/TableConfig/getFutureTableSchema.d.ts.map +1 -1
  228. package/dist/TableConfig/getFutureTableSchema.js +16 -28
  229. package/dist/TableConfig/getFutureTableSchema.js.map +1 -1
  230. package/dist/TableConfig/getTableColumnQueries.d.ts.map +1 -1
  231. package/dist/TableConfig/getTableColumnQueries.js +5 -9
  232. package/dist/TableConfig/getTableColumnQueries.js.map +1 -1
  233. package/dist/TableConfig/initTableConfig.d.ts.map +1 -1
  234. package/dist/TableConfig/initTableConfig.js +22 -25
  235. package/dist/TableConfig/initTableConfig.js.map +1 -1
  236. package/dist/initProstgles.js +1 -1
  237. package/dist/initProstgles.js.map +1 -1
  238. package/dist/onSocketConnected.d.ts.map +1 -1
  239. package/dist/onSocketConnected.js +2 -4
  240. package/dist/onSocketConnected.js.map +1 -1
  241. package/dist/runClientRequest.d.ts.map +1 -1
  242. package/dist/runClientRequest.js +14 -13
  243. package/dist/runClientRequest.js.map +1 -1
  244. package/lib/Auth/AuthHandler.ts +117 -137
  245. package/lib/Auth/AuthTypes.ts +97 -81
  246. package/lib/Auth/authProviders/setEmailProvider.ts +29 -0
  247. package/lib/Auth/authProviders/setOAuthProviders.ts +97 -0
  248. package/lib/Auth/endpoints/getConfirmEmailRequestHandler.ts +39 -0
  249. package/lib/Auth/endpoints/getRegisterRequestHandler.ts +83 -0
  250. package/lib/Auth/setAuthProviders.ts +8 -111
  251. package/lib/Auth/setupAuthRoutes.ts +105 -148
  252. package/lib/Auth/utils/checkDmarc.ts +19 -0
  253. package/lib/Auth/utils/getClientRequestIPsInfo.ts +25 -0
  254. package/lib/Auth/utils/getReturnUrl.ts +13 -0
  255. package/lib/DBEventsManager.ts +12 -26
  256. package/lib/DBSchemaBuilder.ts +1 -1
  257. package/lib/DboBuilder/DboBuilder.ts +23 -52
  258. package/lib/DboBuilder/DboBuilderTypes.ts +9 -23
  259. package/lib/DboBuilder/QueryBuilder/Functions.ts +86 -188
  260. package/lib/DboBuilder/QueryBuilder/QueryBuilder.ts +11 -36
  261. package/lib/DboBuilder/QueryBuilder/getNewQuery.ts +102 -129
  262. package/lib/DboBuilder/QueryBuilder/getSelectQuery.ts +14 -27
  263. package/lib/DboBuilder/QueryStreamer.ts +26 -57
  264. package/lib/DboBuilder/TableHandler/DataValidator.ts +58 -90
  265. package/lib/DboBuilder/TableHandler/TableHandler.ts +19 -45
  266. package/lib/DboBuilder/TableHandler/delete.ts +9 -18
  267. package/lib/DboBuilder/TableHandler/insert.ts +18 -31
  268. package/lib/DboBuilder/TableHandler/insertTest.ts +1 -1
  269. package/lib/DboBuilder/TableHandler/runInsertUpdateQuery.ts +8 -19
  270. package/lib/DboBuilder/TableHandler/update.ts +17 -46
  271. package/lib/DboBuilder/TableHandler/updateFile.ts +18 -21
  272. package/lib/DboBuilder/TableHandler/upsert.ts +7 -24
  273. package/lib/DboBuilder/ViewHandler/ViewHandler.ts +13 -15
  274. package/lib/DboBuilder/ViewHandler/count.ts +1 -1
  275. package/lib/DboBuilder/ViewHandler/find.ts +28 -35
  276. package/lib/DboBuilder/ViewHandler/getExistsCondition.ts +8 -30
  277. package/lib/DboBuilder/ViewHandler/getInfo.ts +2 -2
  278. package/lib/DboBuilder/ViewHandler/getTableJoinQuery.ts +16 -32
  279. package/lib/DboBuilder/ViewHandler/parseFieldFilter.ts +9 -16
  280. package/lib/DboBuilder/ViewHandler/parseJoinPath.ts +26 -44
  281. package/lib/DboBuilder/ViewHandler/prepareSortItems.ts +58 -82
  282. package/lib/DboBuilder/ViewHandler/prepareWhere.ts +14 -27
  283. package/lib/DboBuilder/dboBuilderUtils.ts +19 -46
  284. package/lib/DboBuilder/getColumns.ts +24 -46
  285. package/lib/DboBuilder/getCondition.ts +18 -30
  286. package/lib/DboBuilder/getSubscribeRelatedTables.ts +2 -2
  287. package/lib/DboBuilder/getTablesForSchemaPostgresSQL.ts +44 -62
  288. package/lib/DboBuilder/insertNestedRecords.ts +67 -135
  289. package/lib/DboBuilder/parseUpdateRules.ts +1 -1
  290. package/lib/DboBuilder/prepareShortestJoinPaths.ts +23 -58
  291. package/lib/DboBuilder/runSQL.ts +41 -76
  292. package/lib/DboBuilder/uploadFile.ts +26 -37
  293. package/lib/FileManager/FileManager.ts +27 -58
  294. package/lib/FileManager/initFileManager.ts +68 -76
  295. package/lib/FileManager/uploadStream.ts +2 -2
  296. package/lib/Filtering.ts +30 -87
  297. package/lib/JSONBValidation/validation.ts +36 -75
  298. package/lib/Logging.ts +1 -1
  299. package/lib/PostgresNotifListenManager.ts +11 -35
  300. package/lib/Prostgles.ts +42 -100
  301. package/lib/PubSubManager/PubSubManager.ts +30 -66
  302. package/lib/PubSubManager/addSub.ts +11 -18
  303. package/lib/PubSubManager/addSync.ts +5 -12
  304. package/lib/PubSubManager/getCreatePubSubManagerError.ts +9 -9
  305. package/lib/PubSubManager/initPubSubManager.ts +7 -13
  306. package/lib/PubSubManager/pushSubData.ts +1 -7
  307. package/lib/PublishParser/PublishParser.ts +8 -12
  308. package/lib/PublishParser/getFileTableRules.ts +1 -1
  309. package/lib/PublishParser/getSchemaFromPublish.ts +26 -42
  310. package/lib/PublishParser/getTableRulesWithoutFileTable.ts +22 -37
  311. package/lib/RestApi.ts +4 -12
  312. package/lib/SchemaWatch/SchemaWatch.ts +11 -24
  313. package/lib/SyncReplication.ts +96 -190
  314. package/lib/TableConfig/TableConfig.ts +16 -38
  315. package/lib/TableConfig/getConstraintDefinitionQueries.ts +2 -8
  316. package/lib/TableConfig/getFutureTableSchema.ts +20 -34
  317. package/lib/TableConfig/getTableColumnQueries.ts +13 -35
  318. package/lib/TableConfig/initTableConfig.ts +40 -64
  319. package/lib/initProstgles.ts +1 -1
  320. package/lib/onSocketConnected.ts +8 -12
  321. package/lib/runClientRequest.ts +31 -54
  322. package/package.json +2 -2
  323. package/dist/Auth/getSafeReturnURL.d.ts.map +0 -1
  324. package/dist/Auth/getSafeReturnURL.js.map +0 -1
  325. package/dist/Auth/setEmailProvider.d.ts.map +0 -1
  326. package/dist/Auth/setEmailProvider.js +0 -133
  327. package/dist/Auth/setEmailProvider.js.map +0 -1
  328. package/dist/DboBuilder/runTransaction.d.ts +0 -9
  329. package/dist/DboBuilder/runTransaction.d.ts.map +0 -1
  330. package/dist/DboBuilder/runTransaction.js +0 -49
  331. package/dist/DboBuilder/runTransaction.js.map +0 -1
  332. package/lib/Auth/setEmailProvider.ts +0 -132
  333. package/lib/DboBuilder/QueryBuilder/prepareHaving.ts +0 -27
  334. package/lib/DboBuilder/runTransaction.ts +0 -61
  335. package/lib/SchemaWatch/createSchemaWatchEventTrigger.ts +0 -3
  336. /package/dist/Auth/{getSafeReturnURL.d.ts → utils/getSafeReturnURL.d.ts} +0 -0
  337. /package/dist/Auth/{getSafeReturnURL.js → utils/getSafeReturnURL.js} +0 -0
  338. /package/lib/Auth/{getSafeReturnURL.ts → utils/getSafeReturnURL.ts} +0 -0
@@ -1,10 +1,4 @@
1
- import {
2
- getKeys,
3
- isEmpty,
4
- isObject,
5
- JSONB,
6
- TableSchema,
7
- } from "prostgles-types";
1
+ import { getKeys, isEmpty, isObject, JSONB, TableSchema } from "prostgles-types";
8
2
  import { postgresToTsType } from "../DboBuilder/DboBuilder";
9
3
  import { asValue } from "../PubSubManager/PubSubManager";
10
4
 
@@ -14,33 +8,21 @@ const getFieldTypeObj = (rawFieldType: JSONB.FieldType): JSONB.FieldTypeObj => {
14
8
  return rawFieldType;
15
9
  };
16
10
 
17
- export function validate<T>(
18
- obj: T,
19
- key: keyof T,
20
- rawFieldType: JSONB.FieldType,
21
- ): boolean {
11
+ export function validate<T>(obj: T, key: keyof T, rawFieldType: JSONB.FieldType): boolean {
22
12
  let err = `The provided value for ${JSON.stringify(key)} is of invalid type. Expecting `;
23
13
  const val = obj[key];
24
14
  const fieldType = getFieldTypeObj(rawFieldType);
25
15
  if ("type" in fieldType && fieldType.type) {
26
16
  if (typeof fieldType.type !== "string") {
27
17
  getKeys(fieldType.type).forEach((subKey) => {
28
- validate(
29
- val,
30
- subKey as any,
31
- (fieldType.type as JSONB.ObjectType["type"])[subKey]!,
32
- );
18
+ validate(val, subKey as any, (fieldType.type as JSONB.ObjectType["type"])[subKey]!);
33
19
  });
34
20
  }
35
21
  err += fieldType.type;
36
- if (fieldType.type === "boolean" && typeof val !== fieldType.type)
37
- throw new Error(err);
38
- if (fieldType.type === "string" && typeof val !== fieldType.type)
39
- throw new Error(err);
40
- if (fieldType.type === "number" && !Number.isFinite(val))
41
- throw new Error(err);
42
- if (fieldType.type === "integer" && !Number.isInteger(val))
43
- throw new Error(err);
22
+ if (fieldType.type === "boolean" && typeof val !== fieldType.type) throw new Error(err);
23
+ if (fieldType.type === "string" && typeof val !== fieldType.type) throw new Error(err);
24
+ if (fieldType.type === "number" && !Number.isFinite(val)) throw new Error(err);
25
+ if (fieldType.type === "integer" && !Number.isInteger(val)) throw new Error(err);
44
26
  } else if (fieldType.enum) {
45
27
  err += `on of: ${fieldType.enum}`;
46
28
  if (!fieldType.enum.includes(val)) throw new Error(err);
@@ -52,10 +34,9 @@ export function validateSchema<S extends JSONB.ObjectType["type"]>(
52
34
  schema: S,
53
35
  obj: JSONB.GetObjectType<S>,
54
36
  objName?: string,
55
- optional = false,
37
+ optional = false
56
38
  ) {
57
- if ((!schema || isEmpty(schema)) && !optional)
58
- throw new Error(`Expecting ${objName} to be defined`);
39
+ if (isEmpty(schema) && !optional) throw new Error(`Expecting ${objName} to be defined`);
59
40
  getKeys(schema).forEach((k) => validate(obj as any, k, schema[k]!));
60
41
  }
61
42
 
@@ -65,19 +46,19 @@ export function getJSONBSchemaTSTypes(
65
46
  schema: JSONB.JSONBSchema,
66
47
  colOpts: ColOpts,
67
48
  outerLeading = "",
68
- tables: TableSchema[],
49
+ tables: TableSchema[]
69
50
  ): string {
70
51
  const getFieldType = (
71
52
  rawFieldType: JSONB.FieldType,
72
53
  isOneOf = false,
73
54
  innerLeading = "",
74
- depth = 0,
55
+ depth = 0
75
56
  ): string => {
76
57
  const fieldType = getFieldTypeObj(rawFieldType);
77
58
  const nullType = fieldType.nullable ? `null | ` : "";
78
59
 
79
60
  /** Primitives */
80
- if (typeof fieldType?.type === "string") {
61
+ if (typeof fieldType.type === "string") {
81
62
  const correctType = fieldType.type
82
63
  .replace("integer", "number")
83
64
  .replace("time", "string")
@@ -86,16 +67,14 @@ export function getJSONBSchemaTSTypes(
86
67
 
87
68
  if (fieldType.allowedValues && fieldType.type.endsWith("[]")) {
88
69
  return (
89
- nullType +
90
- ` (${fieldType.allowedValues.map((v) => JSON.stringify(v)).join(" | ")})[]`
70
+ nullType + ` (${fieldType.allowedValues.map((v) => JSON.stringify(v)).join(" | ")})[]`
91
71
  );
92
72
  }
93
73
  return nullType + correctType;
94
74
 
95
75
  /** Object */
96
76
  } else if (isObject(fieldType.type)) {
97
- const addSemicolonIfMissing = (v: string) =>
98
- v.trim().endsWith(";") ? v : v.trim() + ";";
77
+ const addSemicolonIfMissing = (v: string) => (v.trim().endsWith(";") ? v : v.trim() + ";");
99
78
  const { type } = fieldType;
100
79
  const spacing = isOneOf ? " " : " ";
101
80
  let objDef =
@@ -103,14 +82,10 @@ export function getJSONBSchemaTSTypes(
103
82
  getKeys(type)
104
83
  .map((key) => {
105
84
  const fieldType = getFieldTypeObj(type[key]!);
106
- const escapedKey = isValidIdentifier(key)
107
- ? key
108
- : JSON.stringify(key);
85
+ const escapedKey = isValidIdentifier(key) ? key : JSON.stringify(key);
109
86
  return (
110
87
  `${spacing}${escapedKey}${fieldType.optional ? "?" : ""}: ` +
111
- addSemicolonIfMissing(
112
- getFieldType(fieldType, true, undefined, depth + 1),
113
- )
88
+ addSemicolonIfMissing(getFieldType(fieldType, true, undefined, depth + 1))
114
89
  );
115
90
  })
116
91
  .join(" ") +
@@ -124,31 +99,25 @@ export function getJSONBSchemaTSTypes(
124
99
  objDef = objDef.split("\n").join("");
125
100
  }
126
101
  return nullType + objDef;
127
- } else if (fieldType?.enum) {
102
+ } else if (fieldType.enum) {
128
103
  return nullType + fieldType.enum.map((v) => asValue(v)).join(" | ");
129
- } else if (fieldType?.oneOf || fieldType?.oneOfType) {
130
- const oneOf =
131
- fieldType?.oneOf || fieldType?.oneOfType.map((type) => ({ type }));
104
+ } else if (fieldType.oneOf || fieldType.oneOfType) {
105
+ const oneOf = fieldType.oneOf || fieldType.oneOfType.map((type) => ({ type }));
132
106
  return (
133
107
  (fieldType.nullable ? `\n${innerLeading} | null` : "") +
134
108
  oneOf
135
- .map(
136
- (v) =>
137
- `\n${innerLeading} | ` +
138
- getFieldType(v, true, undefined, depth + 1),
139
- )
109
+ .map((v) => `\n${innerLeading} | ` + getFieldType(v, true, undefined, depth + 1))
140
110
  .join("")
141
111
  );
142
- } else if (fieldType?.arrayOf || fieldType?.arrayOfType) {
143
- const arrayOf = fieldType?.arrayOf || { type: fieldType?.arrayOfType };
112
+ } else if (fieldType.arrayOf || fieldType.arrayOfType) {
113
+ const arrayOf = fieldType.arrayOf || { type: fieldType.arrayOfType };
144
114
  return `${fieldType.nullable ? `null | ` : ""} ( ${getFieldType(arrayOf, true, undefined, depth + 1)} )[]`;
145
- } else if (fieldType?.record) {
115
+ } else if (fieldType.record) {
146
116
  const { keysEnum, values, partial } = fieldType.record;
147
117
  // TODO: ensure props with undefined values are not allowed in the TS type (strict union)
148
- const getRecord = (v: string) =>
149
- partial ? `Partial<Record<${v}>>` : `Record<${v}>`;
118
+ const getRecord = (v: string) => (partial ? `Partial<Record<${v}>>` : `Record<${v}>`);
150
119
  return `${fieldType.nullable ? `null |` : ""} ${getRecord(`${keysEnum?.map((v) => asValue(v)).join(" | ") ?? "string"}, ${!values ? "any" : getFieldType(values, true, undefined, depth + 1)}`)}`;
151
- } else if (fieldType?.lookup) {
120
+ } else if (fieldType.lookup) {
152
121
  const l = fieldType.lookup;
153
122
  if (l.type === "data-def") {
154
123
  return `${fieldType.nullable ? `null |` : ""} ${getFieldType({
@@ -170,36 +139,28 @@ export function getJSONBSchemaTSTypes(
170
139
  }
171
140
 
172
141
  const isSChema = l.type === "schema";
173
- let type = isSChema
174
- ? l.object === "table"
175
- ? "string"
142
+ let type =
143
+ isSChema ?
144
+ l.object === "table" ?
145
+ "string"
176
146
  : `{ "table": string; "column": string; }`
177
147
  : "";
178
148
  if (!isSChema) {
179
149
  const cols = tables.find((t) => t.name === l.table)?.columns;
180
150
  if (!l.isFullRow) {
181
- type = postgresToTsType(
182
- cols?.find((c) => c.name === l.column)?.udt_name ?? "text",
183
- );
151
+ type = postgresToTsType(cols?.find((c) => c.name === l.column)?.udt_name ?? "text");
184
152
  } else {
185
- type = !cols
186
- ? "any"
187
- : `{ ${cols.map((c) => `${JSON.stringify(c.name)}: ${c.is_nullable ? "null | " : ""} ${postgresToTsType(c.udt_name)}; `).join(" ")} }`;
153
+ type =
154
+ !cols ? "any" : (
155
+ `{ ${cols.map((c) => `${JSON.stringify(c.name)}: ${c.is_nullable ? "null | " : ""} ${postgresToTsType(c.udt_name)}; `).join(" ")} }`
156
+ );
188
157
  }
189
158
  }
190
159
  return `${fieldType.nullable ? `null | ` : ""}${type}${l.isArray ? "[]" : ""}`;
191
- } else
192
- throw (
193
- "Unexpected getSchemaTSTypes: " +
194
- JSON.stringify({ fieldType, schema }, null, 2)
195
- );
160
+ } else throw "Unexpected getSchemaTSTypes: " + JSON.stringify({ fieldType, schema }, null, 2);
196
161
  };
197
162
 
198
- return getFieldType(
199
- { ...(schema as any), nullable: colOpts.nullable },
200
- undefined,
201
- outerLeading,
202
- );
163
+ return getFieldType({ ...(schema as any), nullable: colOpts.nullable }, undefined, outerLeading);
203
164
  }
204
165
 
205
166
  const isValidIdentifier = (str: string) => {
package/lib/Logging.ts CHANGED
@@ -97,7 +97,7 @@ export namespace EventTypes {
97
97
  export type Auth = ClientInfo &
98
98
  DebugInfo & {
99
99
  type: "auth";
100
- } & ({ command: "getClientInfo" } | { command: "login" });
100
+ } & ({ command: "getClientInfo" } | { command: "login"; success: boolean });
101
101
 
102
102
  export type Debug = DebugInfo &
103
103
  (
@@ -26,14 +26,9 @@ export class PostgresNotifListenManager {
26
26
  static create = (
27
27
  db_pg: DB,
28
28
  notifListener: PrglNotifListener,
29
- db_channel_name: string,
29
+ db_channel_name: string
30
30
  ): Promise<PostgresNotifListenManager> => {
31
- const res = new PostgresNotifListenManager(
32
- db_pg,
33
- notifListener,
34
- db_channel_name,
35
- true,
36
- );
31
+ const res = new PostgresNotifListenManager(db_pg, notifListener, db_channel_name, true);
37
32
  return res.init();
38
33
  };
39
34
 
@@ -41,9 +36,9 @@ export class PostgresNotifListenManager {
41
36
  db_pg: DB,
42
37
  notifListener: PrglNotifListener,
43
38
  db_channel_name: string,
44
- noInit = false,
39
+ noInit = false
45
40
  ) {
46
- if (!db_pg || !notifListener || !db_channel_name)
41
+ if (!db_channel_name)
47
42
  throw "PostgresNotifListenManager: db_pg OR notifListener OR db_channel_name MISSING";
48
43
  this.db_pg = db_pg;
49
44
  this.notifListener = notifListener;
@@ -64,14 +59,8 @@ export class PostgresNotifListenManager {
64
59
  }
65
60
 
66
61
  startListening() {
67
- if (!this.db_pg || !this.notifListener)
68
- throw "PostgresNotifListenManager: db_pg OR notifListener missing";
69
-
70
62
  return this.reconnect().catch((error) => {
71
- console.log(
72
- "PostgresNotifListenManager: Failed Initial Connection:",
73
- error,
74
- );
63
+ console.log("PostgresNotifListenManager: Failed Initial Connection:", error);
75
64
  });
76
65
  }
77
66
 
@@ -92,13 +81,7 @@ export class PostgresNotifListenManager {
92
81
  }
93
82
  };
94
83
 
95
- reconnect(
96
- delay: number | undefined = 0,
97
- maxAttempts: number | undefined = 0,
98
- ) {
99
- if (!this.db_pg || !this.notifListener)
100
- throw "db_pg OR notifListener missing";
101
-
84
+ reconnect(delay: number | undefined = 0, maxAttempts: number | undefined = 0) {
102
85
  if (this.destroyed) {
103
86
  return Promise.reject("Destroyed");
104
87
  }
@@ -109,7 +92,7 @@ export class PostgresNotifListenManager {
109
92
  const setListeners = (
110
93
  client: pg.IClient,
111
94
  notifListener: PrglNotifListener,
112
- db_channel_name: string,
95
+ db_channel_name: string
113
96
  ) => {
114
97
  client.on("notification", notifListener);
115
98
  this.client = client;
@@ -117,13 +100,10 @@ export class PostgresNotifListenManager {
117
100
  return this.connection
118
101
  .none(
119
102
  `/* prostgles-server internal query used for subscriptions and schema hot reload */ \nLISTEN $1~`,
120
- db_channel_name,
103
+ db_channel_name
121
104
  )
122
105
  .catch((error) => {
123
- console.log(
124
- "PostgresNotifListenManager: unexpected error: ",
125
- error,
126
- ); // unlikely to ever happen
106
+ console.log("PostgresNotifListenManager: unexpected error: ", error); // unlikely to ever happen
127
107
  });
128
108
  },
129
109
  removeListeners = (client: pg.IClient) => {
@@ -141,7 +121,7 @@ export class PostgresNotifListenManager {
141
121
  .catch(() => {
142
122
  // failed after 10 attempts
143
123
  console.log(
144
- "PostgresNotifListenManager: Connection Lost Permanently. No more retryies",
124
+ "PostgresNotifListenManager: Connection Lost Permanently. No more retryies"
145
125
  );
146
126
  // process.exit(); // exiting the process
147
127
  });
@@ -154,11 +134,7 @@ export class PostgresNotifListenManager {
154
134
  .then((obj) => {
155
135
  this.connection = obj; // global connection is now available
156
136
  resolve(obj);
157
- return setListeners(
158
- obj.client,
159
- this.notifListener,
160
- this.db_channel_name,
161
- );
137
+ return setListeners(obj.client, this.notifListener, this.db_channel_name);
162
138
  })
163
139
  .catch((error) => {
164
140
  /** Database was destroyed */
package/lib/Prostgles.ts CHANGED
@@ -9,10 +9,7 @@ import { FileManager } from "./FileManager/FileManager";
9
9
  import { SchemaWatch } from "./SchemaWatch/SchemaWatch";
10
10
  import { OnInitReason, initProstgles } from "./initProstgles";
11
11
  import { makeSocketError, onSocketConnected } from "./onSocketConnected";
12
- import {
13
- clientCanRunSqlRequest,
14
- runClientSqlRequest,
15
- } from "./runClientRequest";
12
+ import { clientCanRunSqlRequest, runClientSqlRequest } from "./runClientRequest";
16
13
  import pg = require("pg-promise/typescript/pg-subset");
17
14
  const { version } = require("../package.json");
18
15
 
@@ -30,33 +27,15 @@ import {
30
27
  export { DBHandlerServer };
31
28
  export type PGP = pgPromise.IMain<{}, pg.IClient>;
32
29
 
33
- import {
34
- CHANNELS,
35
- ClientSchema,
36
- SQLRequest,
37
- isObject,
38
- omitKeys,
39
- tryCatch,
40
- } from "prostgles-types";
30
+ import { CHANNELS, ClientSchema, SQLRequest, isObject, omitKeys, tryCatch } from "prostgles-types";
41
31
  import { DBEventsManager } from "./DBEventsManager";
42
32
  import { PublishParser } from "./PublishParser/PublishParser";
43
- export {
44
- getOrSetTransporter,
45
- sendEmail,
46
- verifySMTPConfig,
47
- } from "./Auth/sendEmail";
33
+ export { getOrSetTransporter, sendEmail, verifySMTPConfig } from "./Auth/sendEmail";
48
34
 
49
35
  export type DB = pgPromise.IDatabase<{}, pg.IClient>;
50
36
  export type DBorTx = DB | pgPromise.ITask<{}>;
51
37
 
52
- export const TABLE_METHODS = [
53
- "update",
54
- "find",
55
- "findOne",
56
- "insert",
57
- "delete",
58
- "upsert",
59
- ] as const;
38
+ export const TABLE_METHODS = ["update", "find", "findOne", "insert", "delete", "upsert"] as const;
60
39
 
61
40
  /*
62
41
  1. Connect to db
@@ -132,12 +111,10 @@ export class Prostgles {
132
111
  tableConfigurator?: TableConfigurator;
133
112
 
134
113
  isMedia(tableName: string) {
135
- return this.opts?.fileTable?.tableName === tableName;
114
+ return this.opts.fileTable?.tableName === tableName;
136
115
  }
137
116
 
138
117
  constructor(params: ProstglesInitOptions) {
139
- if (!params) throw "ProstglesInitOptions missing";
140
-
141
118
  const config: Record<keyof ProstglesInitOptions, 1> = {
142
119
  transactions: 1,
143
120
  joins: 1,
@@ -167,18 +144,16 @@ export class Prostgles {
167
144
  testRulesOnConnect: 1,
168
145
  };
169
146
  const unknownParams = Object.keys(params).filter(
170
- (key: string) => !Object.keys(config).includes(key),
147
+ (key: string) => !Object.keys(config).includes(key)
171
148
  );
172
149
  if (unknownParams.length) {
173
- console.error(
174
- `Unrecognised ProstglesInitOptions params: ${unknownParams.join()}`,
175
- );
150
+ console.error(`Unrecognised ProstglesInitOptions params: ${unknownParams.join()}`);
176
151
  }
177
152
 
178
153
  Object.assign(this.opts, params);
179
154
 
180
155
  /* set defaults */
181
- if (this.opts?.fileTable) {
156
+ if (this.opts.fileTable) {
182
157
  this.opts.fileTable.tableName ??= "media";
183
158
  }
184
159
  this.opts.schemaFilter ??= { public: 1 };
@@ -191,8 +166,7 @@ export class Prostgles {
191
166
  destroyed = false;
192
167
 
193
168
  checkDb() {
194
- if (!this.db || !this.db.connect)
195
- throw "something went wrong getting a db connection";
169
+ if (!this.db || !(this.db as any).connect) throw "something went wrong getting a db connection";
196
170
  }
197
171
 
198
172
  getTSFileName() {
@@ -230,16 +204,11 @@ export class Prostgles {
230
204
  fs.readFile(fullPath, "utf8", function (err, data) {
231
205
  if (err || force || data !== fileContent) {
232
206
  fs.writeFileSync(fullPath, fileContent);
233
- console.log(
234
- "Prostgles: Created typescript schema definition file: \n " +
235
- fileName,
236
- );
207
+ console.log("Prostgles: Created typescript schema definition file: \n " + fileName);
237
208
  }
238
209
  });
239
210
  } else if (force) {
240
- console.error(
241
- "Schema changed. tsGeneratedTypesDir needs to be set to reload server",
242
- );
211
+ console.error("Schema changed. tsGeneratedTypesDir needs to be set to reload server");
243
212
  }
244
213
  }
245
214
 
@@ -259,7 +228,6 @@ export class Prostgles {
259
228
  } else {
260
229
  this.dboBuilder = await DboBuilder.create(this);
261
230
  }
262
- if (!this.dboBuilder) throw "this.dboBuilder";
263
231
  this.dbo = this.dboBuilder.dbo;
264
232
  await this.opts.onLog?.({
265
233
  type: "debug",
@@ -280,7 +248,10 @@ export class Prostgles {
280
248
 
281
249
  initAuthHandler = async () => {
282
250
  this.authHandler?.destroy();
283
- this.authHandler = new AuthHandler(this as any);
251
+ if (!this.opts.auth) {
252
+ return;
253
+ }
254
+ this.authHandler = new AuthHandler(this);
284
255
  await this.authHandler.init();
285
256
  };
286
257
 
@@ -330,10 +301,7 @@ export class Prostgles {
330
301
  if (!cloudClient && !localConfig)
331
302
  throw "fileTable missing param: Must provide awsS3Config OR localConfig";
332
303
 
333
- this.fileManager = new FileManager(
334
- cloudClient || localConfig!,
335
- imageOptions,
336
- );
304
+ this.fileManager = new FileManager(cloudClient || localConfig!, imageOptions);
337
305
 
338
306
  try {
339
307
  await this.fileManager.init(this);
@@ -368,9 +336,7 @@ export class Prostgles {
368
336
  const result = await this.db
369
337
  ?.multi(fileContent)
370
338
  .then((data) => {
371
- console.log(
372
- "Prostgles: SQL file executed successfuly \n -> " + filePath,
373
- );
339
+ console.log("Prostgles: SQL file executed successfuly \n -> " + filePath);
374
340
  return data;
375
341
  })
376
342
  .catch((err) => {
@@ -381,17 +347,14 @@ export class Prostgles {
381
347
  if (position && length && fileContent) {
382
348
  const startLine = Math.max(
383
349
  0,
384
- fileContent.substring(0, position).split("\n").length - 2,
350
+ fileContent.substring(0, position).split("\n").length - 2
385
351
  ),
386
352
  endLine = startLine + 3;
387
353
 
388
354
  errMsg += "\n\n";
389
355
  errMsg += lines
390
356
  .slice(startLine, endLine)
391
- .map(
392
- (txt, i) =>
393
- `${startLine + i + 1} ${i === 1 ? "->" : " "} ${txt}`,
394
- )
357
+ .map((txt, i) => `${startLine + i + 1} ${i === 1 ? "->" : " "} ${txt}`)
395
358
  .join("\n");
396
359
  errMsg += "\n\n";
397
360
  }
@@ -418,7 +381,7 @@ export class Prostgles {
418
381
  this.opts.publishRawSQL,
419
382
  this.dbo,
420
383
  this.db!,
421
- this,
384
+ this
422
385
  );
423
386
  this.publishParser = publishParser;
424
387
 
@@ -437,29 +400,22 @@ export class Prostgles {
437
400
  this.opts.io.removeAllListeners("connection");
438
401
  this.opts.io.on("connection", this.onSocketConnected);
439
402
  /** In some cases io will re-init with already connected sockets */
440
- this.opts.io?.sockets.sockets.forEach((socket) =>
441
- this.onSocketConnected(socket),
442
- );
403
+ this.opts.io.sockets.sockets.forEach((socket) => this.onSocketConnected(socket));
443
404
  }
444
405
 
445
406
  onSocketConnected = onSocketConnected.bind(this);
446
407
 
447
- getClientSchema = async (
448
- clientReq: Pick<LocalParams, "socket" | "httpReq">,
449
- ) => {
408
+ getClientSchema = async (clientReq: Pick<LocalParams, "socket" | "httpReq">) => {
450
409
  const result = await tryCatch(async () => {
451
- const clientInfo = clientReq.socket
452
- ? { type: "socket" as const, socket: clientReq.socket }
453
- : clientReq.httpReq
454
- ? { type: "http" as const, httpReq: clientReq.httpReq }
455
- : undefined;
410
+ const clientInfo =
411
+ clientReq.socket ? { type: "socket" as const, socket: clientReq.socket }
412
+ : clientReq.httpReq ? { type: "http" as const, httpReq: clientReq.httpReq }
413
+ : undefined;
456
414
  if (!clientInfo) throw "Invalid client";
457
- if (!this.authHandler) throw "this.authHandler missing";
458
- const userData = await this.authHandler.getClientInfo(clientInfo);
415
+ // if (!this.authHandler) throw "this.authHandler missing";
416
+ const userData = await this.authHandler?.getClientInfo(clientInfo);
459
417
  const { publishParser } = this;
460
- let fullSchema:
461
- | Awaited<ReturnType<PublishParser["getSchemaFromPublish"]>>
462
- | undefined;
418
+ let fullSchema: Awaited<ReturnType<PublishParser["getSchemaFromPublish"]>> | undefined;
463
419
  let publishValidationError;
464
420
 
465
421
  try {
@@ -470,16 +426,10 @@ export class Prostgles {
470
426
  });
471
427
  } catch (e) {
472
428
  publishValidationError = e;
473
- console.error(
474
- `\nProstgles Publish validation failed (after socket connected):\n ->`,
475
- e,
476
- );
429
+ console.error(`\nProstgles Publish validation failed (after socket connected):\n ->`, e);
477
430
  }
478
431
  let rawSQL = false;
479
- if (
480
- this.opts.publishRawSQL &&
481
- typeof this.opts.publishRawSQL === "function"
482
- ) {
432
+ if (this.opts.publishRawSQL && typeof this.opts.publishRawSQL === "function") {
483
433
  const { allowed } = await clientCanRunSqlRequest.bind(this)(clientInfo);
484
434
  rawSQL = allowed;
485
435
  }
@@ -493,10 +443,7 @@ export class Prostgles {
493
443
  if (this.opts.joins) {
494
444
  const _joinTables2 = this.dboBuilder
495
445
  .getAllJoinPaths()
496
- .filter(
497
- (jp) =>
498
- ![jp.t1, jp.t2].find((t) => !schema[t] || !schema[t]?.findOne),
499
- )
446
+ .filter((jp) => ![jp.t1, jp.t2].find((t) => !schema[t] || !schema[t]?.findOne))
500
447
  .map((jp) => [jp.t1, jp.t2].sort());
501
448
  _joinTables2.map((jt) => {
502
449
  if (!joinTables2.find((_jt) => _jt.join() === jt.join())) {
@@ -505,13 +452,11 @@ export class Prostgles {
505
452
  });
506
453
  }
507
454
 
508
- const methods = await publishParser?.getAllowedMethods(
509
- clientInfo,
510
- userData,
511
- );
455
+ const methods = await publishParser?.getAllowedMethods(clientInfo, userData);
512
456
 
513
- const methodSchema: ClientSchema["methods"] = !methods
514
- ? []
457
+ const methodSchema: ClientSchema["methods"] =
458
+ !methods ?
459
+ []
515
460
  : Object.entries(methods)
516
461
  .map(([methodName, method]) => {
517
462
  if (isObject(method) && "run" in method) {
@@ -528,7 +473,7 @@ export class Prostgles {
528
473
  return aName.localeCompare(bName);
529
474
  });
530
475
 
531
- const { auth } = await this.authHandler.getClientAuth(clientReq);
476
+ const authInfo = await this.authHandler?.getClientAuth(clientReq);
532
477
 
533
478
  const clientSchema: ClientSchema = {
534
479
  schema,
@@ -537,11 +482,9 @@ export class Prostgles {
537
482
  rawSQL,
538
483
  joinTables: joinTables2,
539
484
  tableSchemaErrors,
540
- auth,
485
+ auth: authInfo?.auth,
541
486
  version,
542
- err: publishValidationError
543
- ? "Server Error: User publish validation failed."
544
- : undefined,
487
+ err: publishValidationError ? "Server Error: User publish validation failed." : undefined,
545
488
  };
546
489
 
547
490
  return {
@@ -550,8 +493,7 @@ export class Prostgles {
550
493
  userData,
551
494
  };
552
495
  });
553
- const sid =
554
- result.userData?.sid ?? this.authHandler?.getSIDNoError(clientReq);
496
+ const sid = result.userData?.sid ?? this.authHandler?.getSIDNoError(clientReq);
555
497
  await this.opts.onLog?.({
556
498
  type: "connect.getClientSchema",
557
499
  duration: result.duration,
@@ -575,7 +517,7 @@ export class Prostgles {
575
517
  { query, params, options }: SQLRequest,
576
518
  cb = (..._callback: any) => {
577
519
  /* Empty */
578
- },
520
+ }
579
521
  ) => {
580
522
  runClientSqlRequest
581
523
  .bind(this)({
@@ -591,7 +533,7 @@ export class Prostgles {
591
533
  .catch((err) => {
592
534
  makeSocketError(cb, err);
593
535
  });
594
- },
536
+ }
595
537
  );
596
538
  }
597
539
  await this.dboBuilder.prostgles.opts.onLog?.({