@axiumine/koa-utils 7.2.0 → 8.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (454) hide show
  1. package/README.md +40 -13
  2. package/dist/dataSources/MariaDB.mjs +3 -3
  3. package/dist/dataSources/MongoDB.mjs +2 -2
  4. package/dist/dataSources/PostgreSQL.mjs +3 -3
  5. package/dist/dataSources/Redis.mjs +3 -3
  6. package/dist/email/ISocketLabsClient.d.mts +8 -0
  7. package/dist/email/ISocketLabsClient.mjs +2 -0
  8. package/dist/email/ISocketLabsMessage.d.mts +20 -0
  9. package/dist/email/ISocketLabsMessage.mjs +4 -0
  10. package/dist/email/ISocketLabsSendResult.d.mts +12 -0
  11. package/dist/email/ISocketLabsSendResult.mjs +2 -0
  12. package/dist/email/ISocketLabsSenderOptions.d.mts +30 -0
  13. package/dist/email/ISocketLabsSenderOptions.mjs +3 -0
  14. package/dist/email/SocketLabsLib.d.mts +1 -0
  15. package/dist/email/SocketLabsLib.mjs +30 -21
  16. package/dist/email/createSocketLabsSender.d.mts +20 -0
  17. package/dist/email/createSocketLabsSender.mjs +66 -0
  18. package/dist/files/scanVirus.mjs +1 -1
  19. package/dist/files/storeUploadAsTemp.mjs +2 -2
  20. package/dist/graphQL/schema/mutations/login4Ever.mjs +1 -1
  21. package/dist/graphQL/schema/mutations/loginAdmin.mjs +1 -1
  22. package/dist/graphQL/schema/mutations/loginRememberme.mjs +1 -1
  23. package/dist/graphQL/schema/mutations/logout.mjs +3 -3
  24. package/dist/graphQL/schema/mutations/refresh.mjs +3 -3
  25. package/dist/graphQL/schema/mutations/resetPwd.mjs +1 -1
  26. package/dist/graphQL/schema/mutations/updatePassword.mjs +1 -1
  27. package/dist/koa/IKoaErrorHandlerContext.d.mts +11 -0
  28. package/dist/koa/IKoaErrorHandlerContext.mjs +2 -0
  29. package/dist/koa/IKoaErrorHandlerOptions.d.mts +28 -0
  30. package/dist/koa/IKoaErrorHandlerOptions.mjs +3 -0
  31. package/dist/koa/createKoaErrorHandler.d.mts +11 -0
  32. package/dist/koa/createKoaErrorHandler.mjs +37 -0
  33. package/dist/koa/middleware/authenticatedAuthorizationHandler/index.mjs +2 -2
  34. package/dist/koa/middleware/authenticatedLogoutHandler/index.mjs +2 -2
  35. package/dist/koa/middleware/authenticatedResourceHandler/index.mjs +2 -2
  36. package/dist/koa/tdwKoaErrorHandler.mjs +15 -23
  37. package/dist/lib/Constants.d.mts +0 -2
  38. package/dist/lib/Constants.mjs +0 -2
  39. package/dist/lib/MongoDB/throwMongoErrors.mjs +1 -1
  40. package/dist/lib/OBJECTID_0_OBJ.d.mts +6 -0
  41. package/dist/lib/OBJECTID_0_OBJ.mjs +8 -0
  42. package/dist/lib/PostgreSQL/clock/CLOCK_SQL.d.mts +7 -0
  43. package/dist/lib/PostgreSQL/clock/CLOCK_SQL.mjs +8 -0
  44. package/dist/lib/PostgreSQL/clock/DB_NOW_SQL.d.mts +5 -0
  45. package/dist/lib/PostgreSQL/clock/DB_NOW_SQL.mjs +6 -0
  46. package/dist/lib/PostgreSQL/clock/IClock.d.mts +4 -0
  47. package/dist/lib/PostgreSQL/clock/IClock.mjs +2 -0
  48. package/dist/lib/PostgreSQL/clock/IDbClock.d.mts +11 -0
  49. package/dist/lib/PostgreSQL/clock/IDbClock.mjs +2 -0
  50. package/dist/lib/PostgreSQL/clock/IDbClockOptions.d.mts +11 -0
  51. package/dist/lib/PostgreSQL/clock/IDbClockOptions.mjs +2 -0
  52. package/dist/lib/PostgreSQL/clock/IDbClockSeam.d.mts +10 -0
  53. package/dist/lib/PostgreSQL/clock/IDbClockSeam.mjs +2 -0
  54. package/dist/lib/PostgreSQL/clock/createDbClock.d.mts +23 -0
  55. package/dist/lib/PostgreSQL/clock/createDbClock.mjs +54 -0
  56. package/dist/lib/PostgreSQL/clock/lockTaken.d.mts +11 -0
  57. package/dist/lib/PostgreSQL/clock/lockTaken.mjs +17 -0
  58. package/dist/lib/PostgreSQL/counter/IDbCounter.d.mts +9 -0
  59. package/dist/lib/PostgreSQL/counter/IDbCounter.mjs +2 -0
  60. package/dist/lib/PostgreSQL/error/DB_CLOCK_REASONS.d.mts +12 -0
  61. package/dist/lib/PostgreSQL/error/DB_CLOCK_REASONS.mjs +20 -0
  62. package/dist/lib/PostgreSQL/error/DB_CONNECT_REASONS.d.mts +11 -0
  63. package/dist/lib/PostgreSQL/error/DB_CONNECT_REASONS.mjs +12 -0
  64. package/dist/lib/PostgreSQL/error/DB_INTERNAL_REASONS.d.mts +23 -0
  65. package/dist/lib/PostgreSQL/error/DB_INTERNAL_REASONS.mjs +35 -0
  66. package/dist/lib/PostgreSQL/error/DB_PARSE_REASONS.d.mts +13 -0
  67. package/dist/lib/PostgreSQL/error/DB_PARSE_REASONS.mjs +14 -0
  68. package/dist/lib/PostgreSQL/error/DB_STATE_REASONS.d.mts +7 -0
  69. package/dist/lib/PostgreSQL/error/DB_STATE_REASONS.mjs +8 -0
  70. package/dist/lib/PostgreSQL/error/DB_TX_REASONS.d.mts +9 -0
  71. package/dist/lib/PostgreSQL/error/DB_TX_REASONS.mjs +10 -0
  72. package/dist/lib/PostgreSQL/error/DbClockError.d.mts +6 -0
  73. package/dist/lib/PostgreSQL/error/DbClockError.mjs +27 -0
  74. package/dist/lib/PostgreSQL/error/DbConnectError.d.mts +11 -0
  75. package/dist/lib/PostgreSQL/error/DbConnectError.mjs +18 -0
  76. package/dist/lib/PostgreSQL/error/DbParseError.d.mts +11 -0
  77. package/dist/lib/PostgreSQL/error/DbParseError.mjs +16 -0
  78. package/dist/lib/PostgreSQL/error/DbStateError.d.mts +10 -0
  79. package/dist/lib/PostgreSQL/error/DbStateError.mjs +14 -0
  80. package/dist/lib/PostgreSQL/error/DbTxError.d.mts +6 -0
  81. package/dist/lib/PostgreSQL/error/DbTxError.mjs +10 -0
  82. package/dist/lib/PostgreSQL/error/IConstraintEntry.d.mts +17 -0
  83. package/dist/lib/PostgreSQL/error/IConstraintEntry.mjs +2 -0
  84. package/dist/lib/PostgreSQL/error/IConstraintEntryBuilder.d.mts +20 -0
  85. package/dist/lib/PostgreSQL/error/IConstraintEntryBuilder.mjs +2 -0
  86. package/dist/lib/PostgreSQL/error/IConstraintTable.d.mts +7 -0
  87. package/dist/lib/PostgreSQL/error/IConstraintTable.mjs +2 -0
  88. package/dist/lib/PostgreSQL/error/IDbClockReason.d.mts +3 -0
  89. package/dist/lib/PostgreSQL/error/IDbClockReason.mjs +2 -0
  90. package/dist/lib/PostgreSQL/error/IDbConnectReason.d.mts +3 -0
  91. package/dist/lib/PostgreSQL/error/IDbConnectReason.mjs +2 -0
  92. package/dist/lib/PostgreSQL/error/IDbErrorCounter.d.mts +4 -0
  93. package/dist/lib/PostgreSQL/error/IDbErrorCounter.mjs +2 -0
  94. package/dist/lib/PostgreSQL/error/IDbErrorCounterName.d.mts +7 -0
  95. package/dist/lib/PostgreSQL/error/IDbErrorCounterName.mjs +2 -0
  96. package/dist/lib/PostgreSQL/error/IDbErrorFactory.d.mts +16 -0
  97. package/dist/lib/PostgreSQL/error/IDbErrorFactory.mjs +2 -0
  98. package/dist/lib/PostgreSQL/error/IDbInternalReason.d.mts +3 -0
  99. package/dist/lib/PostgreSQL/error/IDbInternalReason.mjs +2 -0
  100. package/dist/lib/PostgreSQL/error/IDbParseReason.d.mts +3 -0
  101. package/dist/lib/PostgreSQL/error/IDbParseReason.mjs +2 -0
  102. package/dist/lib/PostgreSQL/error/IDbStateReason.d.mts +3 -0
  103. package/dist/lib/PostgreSQL/error/IDbStateReason.mjs +2 -0
  104. package/dist/lib/PostgreSQL/error/IDbTxReason.d.mts +3 -0
  105. package/dist/lib/PostgreSQL/error/IDbTxReason.mjs +2 -0
  106. package/dist/lib/PostgreSQL/error/ILockOrderReason.d.mts +3 -0
  107. package/dist/lib/PostgreSQL/error/ILockOrderReason.mjs +2 -0
  108. package/dist/lib/PostgreSQL/error/IMapDbErrorOptions.d.mts +22 -0
  109. package/dist/lib/PostgreSQL/error/IMapDbErrorOptions.mjs +2 -0
  110. package/dist/lib/PostgreSQL/error/IRoleAssertionReason.d.mts +3 -0
  111. package/dist/lib/PostgreSQL/error/IRoleAssertionReason.mjs +2 -0
  112. package/dist/lib/PostgreSQL/error/IRoleAssertionSubject.d.mts +12 -0
  113. package/dist/lib/PostgreSQL/error/IRoleAssertionSubject.mjs +2 -0
  114. package/dist/lib/PostgreSQL/error/LOCK_ORDER_REASONS.d.mts +11 -0
  115. package/dist/lib/PostgreSQL/error/LOCK_ORDER_REASONS.mjs +12 -0
  116. package/dist/lib/PostgreSQL/error/LockOrderError.d.mts +6 -0
  117. package/dist/lib/PostgreSQL/error/LockOrderError.mjs +10 -0
  118. package/dist/lib/PostgreSQL/error/ROLE_ASSERT_REASONS.d.mts +21 -0
  119. package/dist/lib/PostgreSQL/error/ROLE_ASSERT_REASONS.mjs +35 -0
  120. package/dist/lib/PostgreSQL/error/RoleAssertionError.d.mts +19 -0
  121. package/dist/lib/PostgreSQL/error/RoleAssertionError.mjs +58 -0
  122. package/dist/lib/PostgreSQL/error/buildConstraintEntry.d.mts +15 -0
  123. package/dist/lib/PostgreSQL/error/buildConstraintEntry.mjs +16 -0
  124. package/dist/lib/PostgreSQL/error/constraintNameOf.d.mts +6 -0
  125. package/dist/lib/PostgreSQL/error/constraintNameOf.mjs +17 -0
  126. package/dist/lib/PostgreSQL/error/errorNameOf.d.mts +5 -0
  127. package/dist/lib/PostgreSQL/error/errorNameOf.mjs +12 -0
  128. package/dist/lib/PostgreSQL/error/lookupConstraint.d.mts +7 -0
  129. package/dist/lib/PostgreSQL/error/lookupConstraint.mjs +8 -0
  130. package/dist/lib/PostgreSQL/error/mapDbError.d.mts +28 -0
  131. package/dist/lib/PostgreSQL/error/mapDbError.mjs +52 -0
  132. package/dist/lib/PostgreSQL/error/sqlstateField.d.mts +4 -0
  133. package/dist/lib/PostgreSQL/error/sqlstateField.mjs +5 -0
  134. package/dist/lib/PostgreSQL/error/sqlstateOf.d.mts +5 -0
  135. package/dist/lib/PostgreSQL/error/sqlstateOf.mjs +12 -0
  136. package/dist/lib/PostgreSQL/guard/IAffectedResult.d.mts +4 -0
  137. package/dist/lib/PostgreSQL/guard/IAffectedResult.mjs +2 -0
  138. package/dist/lib/PostgreSQL/guard/IGuardCounter.d.mts +3 -0
  139. package/dist/lib/PostgreSQL/guard/IGuardCounter.mjs +2 -0
  140. package/dist/lib/PostgreSQL/guard/IVersionGuardCode.d.mts +5 -0
  141. package/dist/lib/PostgreSQL/guard/IVersionGuardCode.mjs +2 -0
  142. package/dist/lib/PostgreSQL/guard/IVersionGuardField.d.mts +3 -0
  143. package/dist/lib/PostgreSQL/guard/IVersionGuardField.mjs +2 -0
  144. package/dist/lib/PostgreSQL/guard/IVersionGuardInput.d.mts +29 -0
  145. package/dist/lib/PostgreSQL/guard/IVersionGuardInput.mjs +2 -0
  146. package/dist/lib/PostgreSQL/guard/VERSION_GUARD_FIELDS.d.mts +2 -0
  147. package/dist/lib/PostgreSQL/guard/VERSION_GUARD_FIELDS.mjs +3 -0
  148. package/dist/lib/PostgreSQL/guard/assertAffected.d.mts +10 -0
  149. package/dist/lib/PostgreSQL/guard/assertAffected.mjs +17 -0
  150. package/dist/lib/PostgreSQL/guard/guardVersion.d.mts +21 -0
  151. package/dist/lib/PostgreSQL/guard/guardVersion.mjs +47 -0
  152. package/dist/lib/PostgreSQL/lock/CLAIM_LIMIT_MAX.d.mts +2 -0
  153. package/dist/lib/PostgreSQL/lock/CLAIM_LIMIT_MAX.mjs +3 -0
  154. package/dist/lib/PostgreSQL/lock/IClaimRegistry.d.mts +6 -0
  155. package/dist/lib/PostgreSQL/lock/IClaimRegistry.mjs +2 -0
  156. package/dist/lib/PostgreSQL/lock/IClaimRequest.d.mts +7 -0
  157. package/dist/lib/PostgreSQL/lock/IClaimRequest.mjs +2 -0
  158. package/dist/lib/PostgreSQL/lock/ILockAdmission.d.mts +4 -0
  159. package/dist/lib/PostgreSQL/lock/ILockAdmission.mjs +2 -0
  160. package/dist/lib/PostgreSQL/lock/ILockOrderSpec.d.mts +19 -0
  161. package/dist/lib/PostgreSQL/lock/ILockOrderSpec.mjs +2 -0
  162. package/dist/lib/PostgreSQL/lock/ILockOrderTracker.d.mts +41 -0
  163. package/dist/lib/PostgreSQL/lock/ILockOrderTracker.mjs +2 -0
  164. package/dist/lib/PostgreSQL/lock/ILockTrackerConfig.d.mts +5 -0
  165. package/dist/lib/PostgreSQL/lock/ILockTrackerConfig.mjs +2 -0
  166. package/dist/lib/PostgreSQL/lock/ILockTrackerOptions.d.mts +7 -0
  167. package/dist/lib/PostgreSQL/lock/ILockTrackerOptions.mjs +2 -0
  168. package/dist/lib/PostgreSQL/lock/IRowLockMode.d.mts +3 -0
  169. package/dist/lib/PostgreSQL/lock/IRowLockMode.mjs +2 -0
  170. package/dist/lib/PostgreSQL/lock/ROW_LOCK_MODES.d.mts +2 -0
  171. package/dist/lib/PostgreSQL/lock/ROW_LOCK_MODES.mjs +3 -0
  172. package/dist/lib/PostgreSQL/lock/claimRowsSkipLocked.d.mts +16 -0
  173. package/dist/lib/PostgreSQL/lock/claimRowsSkipLocked.mjs +32 -0
  174. package/dist/lib/PostgreSQL/lock/createLockOrderTracker.d.mts +14 -0
  175. package/dist/lib/PostgreSQL/lock/createLockOrderTracker.mjs +60 -0
  176. package/dist/lib/PostgreSQL/lock/lockedRow.d.mts +7 -0
  177. package/dist/lib/PostgreSQL/lock/lockedRow.mjs +12 -0
  178. package/dist/lib/PostgreSQL/lock/lockedRows.d.mts +3 -0
  179. package/dist/lib/PostgreSQL/lock/lockedRows.mjs +8 -0
  180. package/dist/lib/PostgreSQL/lock/rowLockModeOf.d.mts +3 -0
  181. package/dist/lib/PostgreSQL/lock/rowLockModeOf.mjs +9 -0
  182. package/dist/lib/PostgreSQL/lock/uuidOf.d.mts +2 -0
  183. package/dist/lib/PostgreSQL/lock/uuidOf.mjs +10 -0
  184. package/dist/lib/PostgreSQL/lock/uuidsOf.d.mts +5 -0
  185. package/dist/lib/PostgreSQL/lock/uuidsOf.mjs +13 -0
  186. package/dist/lib/PostgreSQL/parse/IArrayParser.d.mts +2 -0
  187. package/dist/lib/PostgreSQL/parse/IArrayParser.mjs +2 -0
  188. package/dist/lib/PostgreSQL/parse/IDriverTypes.d.mts +4 -0
  189. package/dist/lib/PostgreSQL/parse/IDriverTypes.mjs +2 -0
  190. package/dist/lib/PostgreSQL/parse/IStringParser.d.mts +2 -0
  191. package/dist/lib/PostgreSQL/parse/IStringParser.mjs +2 -0
  192. package/dist/lib/PostgreSQL/parse/ITypeParserEntry.d.mts +9 -0
  193. package/dist/lib/PostgreSQL/parse/ITypeParserEntry.mjs +2 -0
  194. package/dist/lib/PostgreSQL/parse/TYPE_PARSERS.d.mts +12 -0
  195. package/dist/lib/PostgreSQL/parse/TYPE_PARSERS.mjs +38 -0
  196. package/dist/lib/PostgreSQL/parse/arrayOf.d.mts +7 -0
  197. package/dist/lib/PostgreSQL/parse/arrayOf.mjs +50 -0
  198. package/dist/lib/PostgreSQL/parse/createTypeRegistry.d.mts +13 -0
  199. package/dist/lib/PostgreSQL/parse/createTypeRegistry.mjs +26 -0
  200. package/dist/lib/PostgreSQL/parse/parseDate.d.mts +7 -0
  201. package/dist/lib/PostgreSQL/parse/parseDate.mjs +19 -0
  202. package/dist/lib/PostgreSQL/parse/parseInt8.d.mts +6 -0
  203. package/dist/lib/PostgreSQL/parse/parseInt8.mjs +17 -0
  204. package/dist/lib/PostgreSQL/parse/parseTime.d.mts +7 -0
  205. package/dist/lib/PostgreSQL/parse/parseTime.mjs +24 -0
  206. package/dist/lib/PostgreSQL/parse/parseTimestamptz.d.mts +17 -0
  207. package/dist/lib/PostgreSQL/parse/parseTimestamptz.mjs +79 -0
  208. package/dist/lib/PostgreSQL/parse/parseUuid.d.mts +3 -0
  209. package/dist/lib/PostgreSQL/parse/parseUuid.mjs +9 -0
  210. package/dist/lib/PostgreSQL/pool/DEFAULT_CONNECT_TIMEOUT_MS.d.mts +2 -0
  211. package/dist/lib/PostgreSQL/pool/DEFAULT_CONNECT_TIMEOUT_MS.mjs +3 -0
  212. package/dist/lib/PostgreSQL/pool/DEFAULT_KEEPALIVE_INITIAL_DELAY_MS.d.mts +2 -0
  213. package/dist/lib/PostgreSQL/pool/DEFAULT_KEEPALIVE_INITIAL_DELAY_MS.mjs +3 -0
  214. package/dist/lib/PostgreSQL/pool/ICreatePoolOptions.d.mts +28 -0
  215. package/dist/lib/PostgreSQL/pool/ICreatePoolOptions.mjs +2 -0
  216. package/dist/lib/PostgreSQL/pool/IDbDriver.d.mts +12 -0
  217. package/dist/lib/PostgreSQL/pool/IDbDriver.mjs +2 -0
  218. package/dist/lib/PostgreSQL/pool/IPoolCounter.d.mts +4 -0
  219. package/dist/lib/PostgreSQL/pool/IPoolCounter.mjs +2 -0
  220. package/dist/lib/PostgreSQL/pool/IPoolCounterName.d.mts +7 -0
  221. package/dist/lib/PostgreSQL/pool/IPoolCounterName.mjs +2 -0
  222. package/dist/lib/PostgreSQL/pool/IPoolEvents.d.mts +4 -0
  223. package/dist/lib/PostgreSQL/pool/IPoolEvents.mjs +2 -0
  224. package/dist/lib/PostgreSQL/pool/IPoolLogger.d.mts +8 -0
  225. package/dist/lib/PostgreSQL/pool/IPoolLogger.mjs +2 -0
  226. package/dist/lib/PostgreSQL/pool/REQUIRED_SESSION_TIME_ZONE.d.mts +2 -0
  227. package/dist/lib/PostgreSQL/pool/REQUIRED_SESSION_TIME_ZONE.mjs +3 -0
  228. package/dist/lib/PostgreSQL/pool/createPool.d.mts +31 -0
  229. package/dist/lib/PostgreSQL/pool/createPool.mjs +67 -0
  230. package/dist/lib/PostgreSQL/role/IAssertRoleOptions.d.mts +10 -0
  231. package/dist/lib/PostgreSQL/role/IAssertRoleOptions.mjs +2 -0
  232. package/dist/lib/PostgreSQL/role/IRoleAssertion.d.mts +6 -0
  233. package/dist/lib/PostgreSQL/role/IRoleAssertion.mjs +2 -0
  234. package/dist/lib/PostgreSQL/role/IRoleGrant.d.mts +19 -0
  235. package/dist/lib/PostgreSQL/role/IRoleGrant.mjs +2 -0
  236. package/dist/lib/PostgreSQL/role/IRolePool.d.mts +6 -0
  237. package/dist/lib/PostgreSQL/role/IRolePool.mjs +2 -0
  238. package/dist/lib/PostgreSQL/role/assertRole.d.mts +36 -0
  239. package/dist/lib/PostgreSQL/role/assertRole.mjs +54 -0
  240. package/dist/lib/PostgreSQL/tx/DEFAULT_LOCK_TIMEOUT_MS.d.mts +2 -0
  241. package/dist/lib/PostgreSQL/tx/DEFAULT_LOCK_TIMEOUT_MS.mjs +3 -0
  242. package/dist/lib/PostgreSQL/tx/IRetryDelay.d.mts +2 -0
  243. package/dist/lib/PostgreSQL/tx/IRetryDelay.mjs +2 -0
  244. package/dist/lib/PostgreSQL/tx/ITx.d.mts +9 -0
  245. package/dist/lib/PostgreSQL/tx/ITx.mjs +2 -0
  246. package/dist/lib/PostgreSQL/tx/ITxClient.d.mts +12 -0
  247. package/dist/lib/PostgreSQL/tx/ITxClient.mjs +2 -0
  248. package/dist/lib/PostgreSQL/tx/ITxCounter.d.mts +4 -0
  249. package/dist/lib/PostgreSQL/tx/ITxCounter.mjs +2 -0
  250. package/dist/lib/PostgreSQL/tx/ITxCounterName.d.mts +10 -0
  251. package/dist/lib/PostgreSQL/tx/ITxCounterName.mjs +2 -0
  252. package/dist/lib/PostgreSQL/tx/ITxFailureReason.d.mts +3 -0
  253. package/dist/lib/PostgreSQL/tx/ITxFailureReason.mjs +2 -0
  254. package/dist/lib/PostgreSQL/tx/ITxIsolation.d.mts +3 -0
  255. package/dist/lib/PostgreSQL/tx/ITxIsolation.mjs +2 -0
  256. package/dist/lib/PostgreSQL/tx/ITxOptions.d.mts +27 -0
  257. package/dist/lib/PostgreSQL/tx/ITxOptions.mjs +2 -0
  258. package/dist/lib/PostgreSQL/tx/ITxPool.d.mts +5 -0
  259. package/dist/lib/PostgreSQL/tx/ITxPool.mjs +2 -0
  260. package/dist/lib/PostgreSQL/tx/ITxResult.d.mts +6 -0
  261. package/dist/lib/PostgreSQL/tx/ITxResult.mjs +2 -0
  262. package/dist/lib/PostgreSQL/tx/MAX_LOCK_TIMEOUT_MS.d.mts +2 -0
  263. package/dist/lib/PostgreSQL/tx/MAX_LOCK_TIMEOUT_MS.mjs +3 -0
  264. package/dist/lib/PostgreSQL/tx/TX_FAILURE_REASONS.d.mts +7 -0
  265. package/dist/lib/PostgreSQL/tx/TX_FAILURE_REASONS.mjs +8 -0
  266. package/dist/lib/PostgreSQL/tx/TX_ISOLATION_LEVELS.d.mts +2 -0
  267. package/dist/lib/PostgreSQL/tx/TX_ISOLATION_LEVELS.mjs +3 -0
  268. package/dist/lib/PostgreSQL/tx/TX_RETRY_BASE_DELAY_MS.d.mts +2 -0
  269. package/dist/lib/PostgreSQL/tx/TX_RETRY_BASE_DELAY_MS.mjs +3 -0
  270. package/dist/lib/PostgreSQL/tx/TX_RETRY_MAX.d.mts +2 -0
  271. package/dist/lib/PostgreSQL/tx/TX_RETRY_MAX.mjs +3 -0
  272. package/dist/lib/PostgreSQL/tx/TX_RETRY_MAX_CEILING.d.mts +2 -0
  273. package/dist/lib/PostgreSQL/tx/TX_RETRY_MAX_CEILING.mjs +3 -0
  274. package/dist/lib/PostgreSQL/tx/defaultRetryDelay.d.mts +3 -0
  275. package/dist/lib/PostgreSQL/tx/defaultRetryDelay.mjs +4 -0
  276. package/dist/lib/PostgreSQL/tx/jitteredDelay.d.mts +7 -0
  277. package/dist/lib/PostgreSQL/tx/jitteredDelay.mjs +16 -0
  278. package/dist/lib/PostgreSQL/tx/withTx.d.mts +39 -0
  279. package/dist/lib/PostgreSQL/tx/withTx.mjs +41 -0
  280. package/dist/lib/PostgreSQL/url/IDatabaseUrlOptions.d.mts +10 -0
  281. package/dist/lib/PostgreSQL/url/IDatabaseUrlOptions.mjs +2 -0
  282. package/dist/lib/PostgreSQL/url/IDatabaseUrlReason.d.mts +14 -0
  283. package/dist/lib/PostgreSQL/url/IDatabaseUrlReason.mjs +2 -0
  284. package/dist/lib/PostgreSQL/url/LOOPBACK_HOSTS.d.mts +2 -0
  285. package/dist/lib/PostgreSQL/url/LOOPBACK_HOSTS.mjs +3 -0
  286. package/dist/lib/PostgreSQL/url/databaseUrlReason.d.mts +20 -0
  287. package/dist/lib/PostgreSQL/url/databaseUrlReason.mjs +99 -0
  288. package/dist/lib/PostgreSQL/url/isAbsolutePath.d.mts +2 -0
  289. package/dist/lib/PostgreSQL/url/isAbsolutePath.mjs +14 -0
  290. package/dist/lib/PostgreSQL/url/isValidHost.d.mts +6 -0
  291. package/dist/lib/PostgreSQL/url/isValidHost.mjs +20 -0
  292. package/dist/lib/tokenOptions.mjs +2 -2
  293. package/dist/lib/tokens.mjs +3 -2
  294. package/dist/lib/tryCatchRethrow.mjs +1 -1
  295. package/dist/private/email/orFalse.mjs +1 -1
  296. package/dist/private/files/reEncode.mjs +1 -1
  297. package/dist/private/graphQL/schema/mutations/setLastLoginSQL.mjs +1 -1
  298. package/dist/private/graphQL/schema/mutations/setRedisLoginSession.mjs +3 -3
  299. package/dist/private/lib/ISentryClient.d.mts +10 -0
  300. package/dist/private/lib/ISentryClient.mjs +2 -0
  301. package/dist/private/lib/PostgreSQL/ICivilDate.d.mts +6 -0
  302. package/dist/private/lib/PostgreSQL/ICivilDate.mjs +2 -0
  303. package/dist/private/lib/PostgreSQL/IClientConstructor.d.mts +3 -0
  304. package/dist/private/lib/PostgreSQL/IClientConstructor.mjs +2 -0
  305. package/dist/private/lib/PostgreSQL/IClientShape.d.mts +10 -0
  306. package/dist/private/lib/PostgreSQL/IClientShape.mjs +2 -0
  307. package/dist/private/lib/PostgreSQL/IClockSlot.d.mts +11 -0
  308. package/dist/private/lib/PostgreSQL/IClockSlot.mjs +2 -0
  309. package/dist/private/lib/PostgreSQL/IConnectCallback.d.mts +2 -0
  310. package/dist/private/lib/PostgreSQL/IConnectCallback.mjs +2 -0
  311. package/dist/private/lib/PostgreSQL/IConnectSettings.d.mts +8 -0
  312. package/dist/private/lib/PostgreSQL/IConnectSettings.mjs +2 -0
  313. package/dist/private/lib/PostgreSQL/IHelperRank.d.mts +5 -0
  314. package/dist/private/lib/PostgreSQL/IHelperRank.mjs +2 -0
  315. package/dist/private/lib/PostgreSQL/IInternalSink.d.mts +9 -0
  316. package/dist/private/lib/PostgreSQL/IInternalSink.mjs +2 -0
  317. package/dist/private/lib/PostgreSQL/ILockOrderPlan.d.mts +8 -0
  318. package/dist/private/lib/PostgreSQL/ILockOrderPlan.mjs +2 -0
  319. package/dist/private/lib/PostgreSQL/IModeOrder.d.mts +7 -0
  320. package/dist/private/lib/PostgreSQL/IModeOrder.mjs +2 -0
  321. package/dist/private/lib/PostgreSQL/IPostgresState.d.mts +9 -0
  322. package/dist/private/lib/PostgreSQL/IPostgresState.mjs +2 -0
  323. package/dist/private/lib/PostgreSQL/IRoleCheck.d.mts +4 -0
  324. package/dist/private/lib/PostgreSQL/IRoleCheck.mjs +2 -0
  325. package/dist/private/lib/PostgreSQL/IRoleColumnCheck.d.mts +7 -0
  326. package/dist/private/lib/PostgreSQL/IRoleColumnCheck.mjs +2 -0
  327. package/dist/private/lib/PostgreSQL/IRoleObjectCheck.d.mts +6 -0
  328. package/dist/private/lib/PostgreSQL/IRoleObjectCheck.mjs +2 -0
  329. package/dist/private/lib/PostgreSQL/IRolePlan.d.mts +7 -0
  330. package/dist/private/lib/PostgreSQL/IRolePlan.mjs +2 -0
  331. package/dist/private/lib/PostgreSQL/IRoleRow.d.mts +2 -0
  332. package/dist/private/lib/PostgreSQL/IRoleRow.mjs +2 -0
  333. package/dist/private/lib/PostgreSQL/ITrackerState.d.mts +10 -0
  334. package/dist/private/lib/PostgreSQL/ITrackerState.mjs +2 -0
  335. package/dist/private/lib/PostgreSQL/ITxHandleState.d.mts +6 -0
  336. package/dist/private/lib/PostgreSQL/ITxHandleState.mjs +2 -0
  337. package/dist/private/lib/PostgreSQL/ITxSettings.d.mts +14 -0
  338. package/dist/private/lib/PostgreSQL/ITxSettings.mjs +2 -0
  339. package/dist/private/lib/PostgreSQL/POSTGRES_STATE_KEY.d.mts +5 -0
  340. package/dist/private/lib/PostgreSQL/POSTGRES_STATE_KEY.mjs +6 -0
  341. package/dist/private/lib/PostgreSQL/POSTGRES_STATE_LAYOUT.d.mts +6 -0
  342. package/dist/private/lib/PostgreSQL/POSTGRES_STATE_LAYOUT.mjs +7 -0
  343. package/dist/private/lib/PostgreSQL/ROLE_ATTRIBUTES.d.mts +2 -0
  344. package/dist/private/lib/PostgreSQL/ROLE_ATTRIBUTES.mjs +9 -0
  345. package/dist/private/lib/PostgreSQL/ROLE_CATALOG_SQL.d.mts +26 -0
  346. package/dist/private/lib/PostgreSQL/ROLE_CATALOG_SQL.mjs +84 -0
  347. package/dist/private/lib/PostgreSQL/ROLE_PRIVILEGES.d.mts +2 -0
  348. package/dist/private/lib/PostgreSQL/ROLE_PRIVILEGES.mjs +7 -0
  349. package/dist/private/lib/PostgreSQL/TX_BEGIN_STATEMENTS.d.mts +7 -0
  350. package/dist/private/lib/PostgreSQL/TX_BEGIN_STATEMENTS.mjs +11 -0
  351. package/dist/private/lib/PostgreSQL/admitLock.d.mts +10 -0
  352. package/dist/private/lib/PostgreSQL/admitLock.mjs +33 -0
  353. package/dist/private/lib/PostgreSQL/assertPoolOptions.d.mts +12 -0
  354. package/dist/private/lib/PostgreSQL/assertPoolOptions.mjs +19 -0
  355. package/dist/private/lib/PostgreSQL/assertVersionGuardInput.d.mts +6 -0
  356. package/dist/private/lib/PostgreSQL/assertVersionGuardInput.mjs +14 -0
  357. package/dist/private/lib/PostgreSQL/catalogFlag.d.mts +2 -0
  358. package/dist/private/lib/PostgreSQL/catalogFlag.mjs +7 -0
  359. package/dist/private/lib/PostgreSQL/catalogRow.d.mts +4 -0
  360. package/dist/private/lib/PostgreSQL/catalogRow.mjs +11 -0
  361. package/dist/private/lib/PostgreSQL/catalogRows.d.mts +8 -0
  362. package/dist/private/lib/PostgreSQL/catalogRows.mjs +12 -0
  363. package/dist/private/lib/PostgreSQL/catalogText.d.mts +2 -0
  364. package/dist/private/lib/PostgreSQL/catalogText.mjs +7 -0
  365. package/dist/private/lib/PostgreSQL/checkRoleOnClient.d.mts +10 -0
  366. package/dist/private/lib/PostgreSQL/checkRoleOnClient.mjs +31 -0
  367. package/dist/private/lib/PostgreSQL/checkedClient.d.mts +8 -0
  368. package/dist/private/lib/PostgreSQL/checkedClient.mjs +22 -0
  369. package/dist/private/lib/PostgreSQL/civilCalendar.d.mts +13 -0
  370. package/dist/private/lib/PostgreSQL/civilCalendar.mjs +48 -0
  371. package/dist/private/lib/PostgreSQL/clockInstant.d.mts +11 -0
  372. package/dist/private/lib/PostgreSQL/clockInstant.mjs +18 -0
  373. package/dist/private/lib/PostgreSQL/clockSlot.d.mts +3 -0
  374. package/dist/private/lib/PostgreSQL/clockSlot.mjs +11 -0
  375. package/dist/private/lib/PostgreSQL/clockStatement.d.mts +6 -0
  376. package/dist/private/lib/PostgreSQL/clockStatement.mjs +22 -0
  377. package/dist/private/lib/PostgreSQL/connectAndCheck.d.mts +8 -0
  378. package/dist/private/lib/PostgreSQL/connectAndCheck.mjs +47 -0
  379. package/dist/private/lib/PostgreSQL/constraintDetails.d.mts +7 -0
  380. package/dist/private/lib/PostgreSQL/constraintDetails.mjs +21 -0
  381. package/dist/private/lib/PostgreSQL/constraintField.d.mts +4 -0
  382. package/dist/private/lib/PostgreSQL/constraintField.mjs +5 -0
  383. package/dist/private/lib/PostgreSQL/errorCodeOf.d.mts +2 -0
  384. package/dist/private/lib/PostgreSQL/errorCodeOf.mjs +7 -0
  385. package/dist/private/lib/PostgreSQL/internalFailure.d.mts +9 -0
  386. package/dist/private/lib/PostgreSQL/internalFailure.mjs +10 -0
  387. package/dist/private/lib/PostgreSQL/isNameList.d.mts +2 -0
  388. package/dist/private/lib/PostgreSQL/isNameList.mjs +6 -0
  389. package/dist/private/lib/PostgreSQL/isOneOf.d.mts +2 -0
  390. package/dist/private/lib/PostgreSQL/isOneOf.mjs +5 -0
  391. package/dist/private/lib/PostgreSQL/isQualifiedName.d.mts +2 -0
  392. package/dist/private/lib/PostgreSQL/isQualifiedName.mjs +7 -0
  393. package/dist/private/lib/PostgreSQL/isRoleName.d.mts +2 -0
  394. package/dist/private/lib/PostgreSQL/isRoleName.mjs +7 -0
  395. package/dist/private/lib/PostgreSQL/lockOrderPlan.d.mts +8 -0
  396. package/dist/private/lib/PostgreSQL/lockOrderPlan.mjs +66 -0
  397. package/dist/private/lib/PostgreSQL/mapTypedError.d.mts +3 -0
  398. package/dist/private/lib/PostgreSQL/mapTypedError.mjs +28 -0
  399. package/dist/private/lib/PostgreSQL/mapViolation.d.mts +3 -0
  400. package/dist/private/lib/PostgreSQL/mapViolation.mjs +32 -0
  401. package/dist/private/lib/PostgreSQL/membershipOutsider.d.mts +7 -0
  402. package/dist/private/lib/PostgreSQL/membershipOutsider.mjs +17 -0
  403. package/dist/private/lib/PostgreSQL/missingColumn.d.mts +9 -0
  404. package/dist/private/lib/PostgreSQL/missingColumn.mjs +15 -0
  405. package/dist/private/lib/PostgreSQL/missingGrant.d.mts +5 -0
  406. package/dist/private/lib/PostgreSQL/missingGrant.mjs +7 -0
  407. package/dist/private/lib/PostgreSQL/missingObject.d.mts +10 -0
  408. package/dist/private/lib/PostgreSQL/missingObject.mjs +14 -0
  409. package/dist/private/lib/PostgreSQL/poolUrlSecrets.d.mts +8 -0
  410. package/dist/private/lib/PostgreSQL/poolUrlSecrets.mjs +41 -0
  411. package/dist/private/lib/PostgreSQL/postgresState.d.mts +7 -0
  412. package/dist/private/lib/PostgreSQL/postgresState.mjs +32 -0
  413. package/dist/private/lib/PostgreSQL/rankCheckOption.d.mts +2 -0
  414. package/dist/private/lib/PostgreSQL/rankCheckOption.mjs +7 -0
  415. package/dist/private/lib/PostgreSQL/readField.d.mts +5 -0
  416. package/dist/private/lib/PostgreSQL/readField.mjs +10 -0
  417. package/dist/private/lib/PostgreSQL/roleCheckOf.d.mts +7 -0
  418. package/dist/private/lib/PostgreSQL/roleCheckOf.mjs +39 -0
  419. package/dist/private/lib/PostgreSQL/roleFailureSubject.d.mts +7 -0
  420. package/dist/private/lib/PostgreSQL/roleFailureSubject.mjs +12 -0
  421. package/dist/private/lib/PostgreSQL/rolePlan.d.mts +7 -0
  422. package/dist/private/lib/PostgreSQL/rolePlan.mjs +26 -0
  423. package/dist/private/lib/PostgreSQL/runRoleChecks.d.mts +17 -0
  424. package/dist/private/lib/PostgreSQL/runRoleChecks.mjs +48 -0
  425. package/dist/private/lib/PostgreSQL/runTxAttempt.d.mts +12 -0
  426. package/dist/private/lib/PostgreSQL/runTxAttempt.mjs +50 -0
  427. package/dist/private/lib/PostgreSQL/runTxBody.d.mts +11 -0
  428. package/dist/private/lib/PostgreSQL/runTxBody.mjs +19 -0
  429. package/dist/private/lib/PostgreSQL/runTxWithRetries.d.mts +10 -0
  430. package/dist/private/lib/PostgreSQL/runTxWithRetries.mjs +31 -0
  431. package/dist/private/lib/PostgreSQL/scrubSecrets.d.mts +2 -0
  432. package/dist/private/lib/PostgreSQL/scrubSecrets.mjs +6 -0
  433. package/dist/private/lib/PostgreSQL/txFailure.d.mts +4 -0
  434. package/dist/private/lib/PostgreSQL/txFailure.mjs +7 -0
  435. package/dist/private/lib/PostgreSQL/txHandle.d.mts +9 -0
  436. package/dist/private/lib/PostgreSQL/txHandle.mjs +26 -0
  437. package/dist/private/lib/PostgreSQL/txSettings.d.mts +7 -0
  438. package/dist/private/lib/PostgreSQL/txSettings.mjs +48 -0
  439. package/dist/private/lib/PostgreSQL/versionText.d.mts +5 -0
  440. package/dist/private/lib/PostgreSQL/versionText.mjs +12 -0
  441. package/dist/private/lib/access/assertResetAllowed.mjs +1 -1
  442. package/dist/private/lib/access/db/deleteUserByEmail.mjs +1 -1
  443. package/dist/private/lib/access/db/enableEmailAccess.mjs +1 -1
  444. package/dist/private/lib/access/db/userData4VerifyEmail.mjs +1 -1
  445. package/dist/private/lib/access/handleBadDB.mjs +1 -1
  446. package/dist/private/lib/createSentryClient.d.mts +7 -0
  447. package/dist/private/lib/createSentryClient.mjs +20 -0
  448. package/dist/private/lib/importOptional.d.mts +7 -0
  449. package/dist/private/lib/importOptional.mjs +27 -0
  450. package/dist/private/lib/loadEnv.d.mts +12 -0
  451. package/dist/private/lib/loadEnv.mjs +14 -0
  452. package/dist/private/lib/sentry.d.mts +3 -0
  453. package/dist/private/lib/sentry.mjs +12 -0
  454. package/package.json +563 -7
@@ -0,0 +1,4 @@
1
+ import type { IDbCounter } from "../counter/IDbCounter.mjs";
2
+ import type { IPoolCounterName } from "./IPoolCounterName.mjs";
3
+ /** The counter callback of the pool factory: called once per event with one of the two pool names. */
4
+ export type IPoolCounter = IDbCounter<IPoolCounterName>;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IPoolCounter.mjs.map
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The counters the pool factory increments:
3
+ *
4
+ * - `db_pool_idle_client_errors_total`: an idle client of the pool emitted an `error` event.
5
+ * - `db_pool_connect_failures_total`: a connection, its login or its session check failed.
6
+ */
7
+ export type IPoolCounterName = 'db_pool_idle_client_errors_total' | 'db_pool_connect_failures_total';
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IPoolCounterName.mjs.map
@@ -0,0 +1,4 @@
1
+ /** What the factory needs of the driver's pool class: the `error` event. */
2
+ export interface IPoolEvents {
3
+ on(event: 'error', listener: (error: Error) => void): unknown;
4
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IPoolEvents.mjs.map
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The logger of the pool factory: the two levels it writes. Structural, so any logger with these two methods fits (a
3
+ * `{ warn, error }` object, a pino or winston instance, a console wrapper).
4
+ */
5
+ export interface IPoolLogger {
6
+ warn(message: string, fields?: Readonly<Record<string, unknown>>): void;
7
+ error(message: string, fields?: Readonly<Record<string, unknown>>): void;
8
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IPoolLogger.mjs.map
@@ -0,0 +1,2 @@
1
+ /** The only session time zone the pool accepts. */
2
+ export declare const REQUIRED_SESSION_TIME_ZONE = "UTC";
@@ -0,0 +1,3 @@
1
+ /** The only session time zone the pool accepts. */
2
+ export const REQUIRED_SESSION_TIME_ZONE = 'UTC';
3
+ //# sourceMappingURL=REQUIRED_SESSION_TIME_ZONE.mjs.map
@@ -0,0 +1,31 @@
1
+ import type { ICreatePoolOptions } from "./ICreatePoolOptions.mjs";
2
+ import type { IPoolEvents } from "./IPoolEvents.mjs";
3
+ /**
4
+ * Makes the pool of a service, in the order a connection meets the pieces:
5
+ *
6
+ * 1. The driver is a parameter. This module imports nothing from `pg`; it is given the module (`import pg from 'pg'` in
7
+ * the caller) and uses three members of it: `Pool`, `Client` and `types`.
8
+ * 2. The URL is checked before the driver sees it, and the driver is given the URL only through the `connectionString`
9
+ * setting. The query of the URL may hold `sslmode` and `sslrootcert` and nothing else, because node-postgres lets a
10
+ * parameter of the URL replace a setting of the pool. A URL that fails is refused with a `DbConnectError` that holds
11
+ * no part of it.
12
+ * 3. Every client of the pool is an instance of a subclass of the driver's `Client` (the `Client` option of the pool).
13
+ * Its `connect` runs, inside one deadline of `connectTimeoutMs`, the driver's connect, the login and the session
14
+ * check: `SHOW timezone` must answer `UTC`. A failure of any step ends the client and rejects the checkout with a
15
+ * `DbConnectError` that has a closed reason and no text of the driver, so a password in the URL cannot reach a
16
+ * message, a log line or a stack through it.
17
+ * 4. The type parsers of {@link createTypeRegistry} are the `types` option of this pool only: no `Date` is built.
18
+ * 5. An error of an idle client is an event of the pool; with no listener Node throws it and the process ends. The
19
+ * factory registers the listener: the event is logged (the driver's message passed through the scrub of the URL
20
+ * secrets) and counted.
21
+ *
22
+ * The `connectionTimeoutMillis` setting of the driver is not passed. It bounds the socket and the login only; a server
23
+ * that accepts, logs in and then never answers the first query would hang the session check, and the driver's timeout
24
+ * error is plain text that cannot carry a reason. The deadline of this module covers all three steps and has the reason
25
+ * `CONNECT_TIMEOUT`. The keepalive settings are the driver's own (`keepAlive`, `keepAliveInitialDelayMillis`).
26
+ *
27
+ * It returns the instance of the driver's `Pool` class, so the caller's own types (`pg.Pool`) apply. Throws `TypeError`
28
+ * for a parameter that is out of range (before anything is created) and `DbConnectError` with reason `URL_INVALID` for a
29
+ * URL that does not pass the check.
30
+ */
31
+ export declare function createPool<TPool extends IPoolEvents>(options: ICreatePoolOptions<TPool>): TPool;
@@ -0,0 +1,67 @@
1
+ import { createTypeRegistry } from "../parse/createTypeRegistry.mjs";
2
+ import { DEFAULT_CONNECT_TIMEOUT_MS } from "./DEFAULT_CONNECT_TIMEOUT_MS.mjs";
3
+ import { DEFAULT_KEEPALIVE_INITIAL_DELAY_MS } from "./DEFAULT_KEEPALIVE_INITIAL_DELAY_MS.mjs";
4
+ import { assertPoolOptions } from "../../../private/lib/PostgreSQL/assertPoolOptions.mjs";
5
+ import { checkedClient } from "../../../private/lib/PostgreSQL/checkedClient.mjs";
6
+ import { errorCodeOf } from "../../../private/lib/PostgreSQL/errorCodeOf.mjs";
7
+ import { poolUrlSecrets } from "../../../private/lib/PostgreSQL/poolUrlSecrets.mjs";
8
+ import { scrubSecrets } from "../../../private/lib/PostgreSQL/scrubSecrets.mjs";
9
+ const messageOf = (error) => (error instanceof Error ? error.message : 'not an Error');
10
+ /**
11
+ * Makes the pool of a service, in the order a connection meets the pieces:
12
+ *
13
+ * 1. The driver is a parameter. This module imports nothing from `pg`; it is given the module (`import pg from 'pg'` in
14
+ * the caller) and uses three members of it: `Pool`, `Client` and `types`.
15
+ * 2. The URL is checked before the driver sees it, and the driver is given the URL only through the `connectionString`
16
+ * setting. The query of the URL may hold `sslmode` and `sslrootcert` and nothing else, because node-postgres lets a
17
+ * parameter of the URL replace a setting of the pool. A URL that fails is refused with a `DbConnectError` that holds
18
+ * no part of it.
19
+ * 3. Every client of the pool is an instance of a subclass of the driver's `Client` (the `Client` option of the pool).
20
+ * Its `connect` runs, inside one deadline of `connectTimeoutMs`, the driver's connect, the login and the session
21
+ * check: `SHOW timezone` must answer `UTC`. A failure of any step ends the client and rejects the checkout with a
22
+ * `DbConnectError` that has a closed reason and no text of the driver, so a password in the URL cannot reach a
23
+ * message, a log line or a stack through it.
24
+ * 4. The type parsers of {@link createTypeRegistry} are the `types` option of this pool only: no `Date` is built.
25
+ * 5. An error of an idle client is an event of the pool; with no listener Node throws it and the process ends. The
26
+ * factory registers the listener: the event is logged (the driver's message passed through the scrub of the URL
27
+ * secrets) and counted.
28
+ *
29
+ * The `connectionTimeoutMillis` setting of the driver is not passed. It bounds the socket and the login only; a server
30
+ * that accepts, logs in and then never answers the first query would hang the session check, and the driver's timeout
31
+ * error is plain text that cannot carry a reason. The deadline of this module covers all three steps and has the reason
32
+ * `CONNECT_TIMEOUT`. The keepalive settings are the driver's own (`keepAlive`, `keepAliveInitialDelayMillis`).
33
+ *
34
+ * It returns the instance of the driver's `Pool` class, so the caller's own types (`pg.Pool`) apply. Throws `TypeError`
35
+ * for a parameter that is out of range (before anything is created) and `DbConnectError` with reason `URL_INVALID` for a
36
+ * URL that does not pass the check.
37
+ */
38
+ export function createPool(options) {
39
+ const { driver, url, max, applicationName, logger } = options;
40
+ const connectTimeoutMs = options.connectTimeoutMs ?? DEFAULT_CONNECT_TIMEOUT_MS;
41
+ const keepAliveInitialDelayMs = options.keepAliveInitialDelayMs ?? DEFAULT_KEEPALIVE_INITIAL_DELAY_MS;
42
+ const count = options.counter ?? (() => undefined);
43
+ assertPoolOptions({ max, applicationName, connectTimeoutMs, keepAliveInitialDelayMs });
44
+ const secrets = poolUrlSecrets(url);
45
+ const Client = checkedClient(driver.Client, { connectTimeoutMs, logger, count });
46
+ const PoolClass = driver.Pool;
47
+ const pool = new PoolClass({
48
+ connectionString: url,
49
+ max,
50
+ application_name: applicationName,
51
+ keepAlive: options.keepAlive ?? true,
52
+ keepAliveInitialDelayMillis: keepAliveInitialDelayMs,
53
+ types: createTypeRegistry(driver.types),
54
+ Client
55
+ });
56
+ pool.on('error', (error) => {
57
+ count('db_pool_idle_client_errors_total');
58
+ const code = errorCodeOf(error);
59
+ logger.error('database pool idle client error', {
60
+ reason: 'IDLE_CLIENT_ERROR',
61
+ ...(code === undefined ? {} : { errorCode: code }),
62
+ detail: scrubSecrets(messageOf(error), secrets)
63
+ });
64
+ });
65
+ return pool;
66
+ }
67
+ //# sourceMappingURL=createPool.mjs.map
@@ -0,0 +1,10 @@
1
+ import type { IRoleGrant } from './IRoleGrant.mjs';
2
+ /** The input of `assertRole`. */
3
+ export interface IAssertRoleOptions {
4
+ /** The role this service logs in as. */
5
+ readonly expectedRole: string;
6
+ /** What the role needs; an empty list checks the role and nothing else. */
7
+ readonly expectedGrants: readonly IRoleGrant[];
8
+ /** Roles the role may be a member of, by name. Default: none. */
9
+ readonly allowedMemberships?: readonly string[];
10
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IAssertRoleOptions.mjs.map
@@ -0,0 +1,6 @@
1
+ /** The answer of a passed assertion. The pool stays open. */
2
+ export interface IRoleAssertion {
3
+ readonly role: string;
4
+ /** How many entries of `expectedGrants` were checked. */
5
+ readonly grantsChecked: number;
6
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IRoleAssertion.mjs.map
@@ -0,0 +1,19 @@
1
+ /** One privilege the role is expected to hold. */
2
+ export interface IRoleGrant {
3
+ /**
4
+ * What the privilege is on, as the catalog names it: `app` (a schema), `app.orders` (a table, a view or a sequence)
5
+ * or `app.resolve_token` (every function of that name, arguments not given).
6
+ */
7
+ readonly object: string;
8
+ /**
9
+ * `USAGE` or `CREATE` on a schema; `SELECT`, `INSERT`, `UPDATE`, `DELETE`, `TRUNCATE`, `REFERENCES` or `TRIGGER` on a
10
+ * table (`USAGE`, `SELECT` and `UPDATE` on a sequence); `EXECUTE` on a function.
11
+ */
12
+ readonly privilege: string;
13
+ /**
14
+ * For `SELECT`, `INSERT`, `UPDATE` or `REFERENCES` on a table: the columns the role needs the privilege on. The check
15
+ * is `has_column_privilege` for each, which a table-level grant also satisfies. Without it, the check is
16
+ * `has_table_privilege`, which a column-level grant does not satisfy.
17
+ */
18
+ readonly columns?: readonly string[];
19
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IRoleGrant.mjs.map
@@ -0,0 +1,6 @@
1
+ import type { ITxClient } from "../tx/ITxClient.mjs";
2
+ /** What `assertRole` needs of the pool: a checkout (the node-postgres `Pool` has it) and the close. */
3
+ export interface IRolePool {
4
+ connect(): Promise<ITxClient>;
5
+ end(): Promise<void>;
6
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IRolePool.mjs.map
@@ -0,0 +1,36 @@
1
+ import type { IAssertRoleOptions } from './IAssertRoleOptions.mjs';
2
+ import type { IRoleAssertion } from './IRoleAssertion.mjs';
3
+ import type { IRolePool } from './IRolePool.mjs';
4
+ /**
5
+ * The boot assertion of a database role: `assertRole(pool, { expectedRole, expectedGrants })`.
6
+ *
7
+ * A service proves at boot that it runs as the role it believes it is, that the role cannot do what it must not, and
8
+ * that the grants it needs are there. A service wired to a more privileged login (a migration role, an administrator,
9
+ * a superuser) stops before it opens a listener. It is a boot check, run once on one connection; it is not a
10
+ * per-request check, and nothing here is meant for a request path.
11
+ *
12
+ * What it asks the server, in this order, on one checked-out connection (the first failure is reported and ends the
13
+ * check):
14
+ *
15
+ * 1. `current_user` is the expected role (`ROLE_MISMATCH`).
16
+ * 2. The role is not a superuser and has no CREATEROLE, CREATEDB, BYPASSRLS or REPLICATION attribute; the flags are read
17
+ * from `pg_roles`.
18
+ * 3. The role owns nothing: `pg_shdepend`, the shared dependency catalog, holds one `o` row (owner) for every object of
19
+ * every database of the cluster that a role owns, so a single catalog read answers for tables, functions, schemas,
20
+ * types, databases and the rest, with no list of catalogs to keep.
21
+ * 4. The role is a member of no other role, directly or through a chain of roles, except those the caller names in
22
+ * `allowedMemberships` (default none). `pg_auth_members` is walked with a recursive query.
23
+ * 5. `session_user` is `current_user`: the connection did not log in as one role and switch to another.
24
+ * 6. Each expected grant is held, checked with the catalog privilege functions (`has_schema_privilege`,
25
+ * `has_table_privilege`, `has_column_privilege`, `has_sequence_privilege`, `has_function_privilege`) for
26
+ * `current_user`. The first one that is not held is named, object and privilege.
27
+ *
28
+ * The expected grants are a parameter: a list of `{ object, privilege }` pairs (and `columns` for a column-level
29
+ * grant). Nothing about any particular role is built in.
30
+ *
31
+ * Resolves with a short record and leaves the pool open. On any failure it closes the pool first and then throws a
32
+ * `RoleAssertionError` (closed `reason`, the role name, no connection string); a failure that is not an assertion (the
33
+ * connection is refused, a catalog query fails) is `CHECK_FAILED`, never a pass. The error never carries the connection
34
+ * string: the function is given the pool, not the URL, and every name in the message passes a shape check.
35
+ */
36
+ export declare function assertRole(pool: IRolePool, options: IAssertRoleOptions): Promise<IRoleAssertion>;
@@ -0,0 +1,54 @@
1
+ import { RoleAssertionError } from "../error/RoleAssertionError.mjs";
2
+ import { checkRoleOnClient } from "../../../private/lib/PostgreSQL/checkRoleOnClient.mjs";
3
+ import { roleFailureSubject } from "../../../private/lib/PostgreSQL/roleFailureSubject.mjs";
4
+ import { rolePlan } from "../../../private/lib/PostgreSQL/rolePlan.mjs";
5
+ /**
6
+ * The boot assertion of a database role: `assertRole(pool, { expectedRole, expectedGrants })`.
7
+ *
8
+ * A service proves at boot that it runs as the role it believes it is, that the role cannot do what it must not, and
9
+ * that the grants it needs are there. A service wired to a more privileged login (a migration role, an administrator,
10
+ * a superuser) stops before it opens a listener. It is a boot check, run once on one connection; it is not a
11
+ * per-request check, and nothing here is meant for a request path.
12
+ *
13
+ * What it asks the server, in this order, on one checked-out connection (the first failure is reported and ends the
14
+ * check):
15
+ *
16
+ * 1. `current_user` is the expected role (`ROLE_MISMATCH`).
17
+ * 2. The role is not a superuser and has no CREATEROLE, CREATEDB, BYPASSRLS or REPLICATION attribute; the flags are read
18
+ * from `pg_roles`.
19
+ * 3. The role owns nothing: `pg_shdepend`, the shared dependency catalog, holds one `o` row (owner) for every object of
20
+ * every database of the cluster that a role owns, so a single catalog read answers for tables, functions, schemas,
21
+ * types, databases and the rest, with no list of catalogs to keep.
22
+ * 4. The role is a member of no other role, directly or through a chain of roles, except those the caller names in
23
+ * `allowedMemberships` (default none). `pg_auth_members` is walked with a recursive query.
24
+ * 5. `session_user` is `current_user`: the connection did not log in as one role and switch to another.
25
+ * 6. Each expected grant is held, checked with the catalog privilege functions (`has_schema_privilege`,
26
+ * `has_table_privilege`, `has_column_privilege`, `has_sequence_privilege`, `has_function_privilege`) for
27
+ * `current_user`. The first one that is not held is named, object and privilege.
28
+ *
29
+ * The expected grants are a parameter: a list of `{ object, privilege }` pairs (and `columns` for a column-level
30
+ * grant). Nothing about any particular role is built in.
31
+ *
32
+ * Resolves with a short record and leaves the pool open. On any failure it closes the pool first and then throws a
33
+ * `RoleAssertionError` (closed `reason`, the role name, no connection string); a failure that is not an assertion (the
34
+ * connection is refused, a catalog query fails) is `CHECK_FAILED`, never a pass. The error never carries the connection
35
+ * string: the function is given the pool, not the URL, and every name in the message passes a shape check.
36
+ */
37
+ export async function assertRole(pool, options) {
38
+ try {
39
+ return await checkRoleOnClient(pool, rolePlan(options));
40
+ }
41
+ catch (error) {
42
+ try {
43
+ await pool.end();
44
+ }
45
+ catch {
46
+ // The pool is being abandoned; the failure to report is the one below.
47
+ }
48
+ if (error instanceof RoleAssertionError)
49
+ throw error;
50
+ // Only a failure after the plan was made reaches this line, so the role name is a valid one.
51
+ throw new RoleAssertionError('CHECK_FAILED', options.expectedRole, roleFailureSubject(error));
52
+ }
53
+ }
54
+ //# sourceMappingURL=assertRole.mjs.map
@@ -0,0 +1,2 @@
1
+ /** The `lock_timeout` of a transaction, in milliseconds, when `lockTimeoutMs` is not given: 3 seconds. */
2
+ export declare const DEFAULT_LOCK_TIMEOUT_MS = 3000;
@@ -0,0 +1,3 @@
1
+ /** The `lock_timeout` of a transaction, in milliseconds, when `lockTimeoutMs` is not given: 3 seconds. */
2
+ export const DEFAULT_LOCK_TIMEOUT_MS = 3_000;
3
+ //# sourceMappingURL=DEFAULT_LOCK_TIMEOUT_MS.mjs.map
@@ -0,0 +1,2 @@
1
+ /** Waits before retry number `retry` (1 for the first). Injected so that tests wait for nothing. */
2
+ export type IRetryDelay = (retry: number) => Promise<void>;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IRetryDelay.mjs.map
@@ -0,0 +1,9 @@
1
+ import type { ITxResult } from "./ITxResult.mjs";
2
+ /**
3
+ * The transaction handle that the function given to `withTx` receives: one method. It has no `connect`, `release`,
4
+ * `end` or pool, and a statement sent after the transaction ended is refused with `DbTxError` `HANDLE_CLOSED`. The text
5
+ * is a literal and the values are parameters (`$1`, `$2`).
6
+ */
7
+ export interface ITx {
8
+ query<TRow = Record<string, unknown>>(text: string, values?: readonly unknown[]): Promise<ITxResult<TRow>>;
9
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ITx.mjs.map
@@ -0,0 +1,12 @@
1
+ /** What `withTx` needs of a connection: the node-postgres `PoolClient` has all of it. */
2
+ export interface ITxClient {
3
+ query(text: string, values?: readonly unknown[]): Promise<{
4
+ rows: unknown[];
5
+ rowCount: number | null;
6
+ command: string;
7
+ }>;
8
+ on(event: 'error', listener: (error: Error) => void): unknown;
9
+ removeListener(event: 'error', listener: (error: Error) => void): unknown;
10
+ /** `true` destroys the connection instead of returning it to the pool. */
11
+ release(destroy?: boolean): void;
12
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ITxClient.mjs.map
@@ -0,0 +1,4 @@
1
+ import type { IDbCounter } from "../counter/IDbCounter.mjs";
2
+ import type { ITxCounterName } from "./ITxCounterName.mjs";
3
+ /** The counter callback of `withTx`: called once per event with one of the five transaction names. */
4
+ export type ITxCounter = IDbCounter<ITxCounterName>;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ITxCounter.mjs.map
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The counters `withTx` increments:
3
+ *
4
+ * - `db_tx_retries_total`: a transaction was rolled back on SQLSTATE 40001 or 40P01 and will run again.
5
+ * - `db_tx_retry_exhausted_total`: the last retry failed too; the caller got the error for `TX_RETRY_EXHAUSTED`.
6
+ * - `db_tx_lock_timeouts_total`: a statement waited longer than the lock timeout (SQLSTATE 55P03).
7
+ * - `db_tx_rollback_failures_total`: the rollback itself failed; the connection was destroyed.
8
+ * - `db_tx_client_errors_total`: the connection of a running transaction emitted an `error` event.
9
+ */
10
+ export type ITxCounterName = 'db_tx_retries_total' | 'db_tx_retry_exhausted_total' | 'db_tx_lock_timeouts_total' | 'db_tx_rollback_failures_total' | 'db_tx_client_errors_total';
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ITxCounterName.mjs.map
@@ -0,0 +1,3 @@
1
+ import type { TX_FAILURE_REASONS } from './TX_FAILURE_REASONS.mjs';
2
+ /** One of {@link TX_FAILURE_REASONS}. */
3
+ export type ITxFailureReason = (typeof TX_FAILURE_REASONS)[number];
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ITxFailureReason.mjs.map
@@ -0,0 +1,3 @@
1
+ import type { TX_ISOLATION_LEVELS } from './TX_ISOLATION_LEVELS.mjs';
2
+ /** One of {@link TX_ISOLATION_LEVELS}. */
3
+ export type ITxIsolation = (typeof TX_ISOLATION_LEVELS)[number];
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ITxIsolation.mjs.map
@@ -0,0 +1,27 @@
1
+ import type { IDbErrorFactory } from "../error/IDbErrorFactory.mjs";
2
+ import type { IPoolLogger } from "../pool/IPoolLogger.mjs";
3
+ import type { IRetryDelay } from "./IRetryDelay.mjs";
4
+ import type { ITxCounter } from "./ITxCounter.mjs";
5
+ import type { ITxIsolation } from "./ITxIsolation.mjs";
6
+ /** The options of `withTx`. */
7
+ export interface ITxOptions {
8
+ /** The logger of the request or of the service; the retries and the failures are written to it. */
9
+ readonly logger: IPoolLogger;
10
+ /**
11
+ * Builds the error the caller gets when the loop gives up: `errors.internal('TX_RETRY_EXHAUSTED')` or
12
+ * `errors.internal('LOCK_TIMEOUT')`. Any {@link IDbErrorFactory} fits; only `internal` is read.
13
+ */
14
+ readonly errors: Pick<IDbErrorFactory, 'internal'>;
15
+ /** Where `withTx` counts. Default: nowhere. */
16
+ readonly counter?: ITxCounter;
17
+ /** Default `READ COMMITTED`; `REPEATABLE READ` with `readOnly` is the snapshot reader. */
18
+ readonly isolation?: ITxIsolation;
19
+ /** Adds `READ ONLY` at the requested isolation; a write then fails with SQLSTATE 25006. Default `false`. */
20
+ readonly readOnly?: boolean;
21
+ /** `SET LOCAL lock_timeout`, a whole number of milliseconds from 1. Default `DEFAULT_LOCK_TIMEOUT_MS`. */
22
+ readonly lockTimeoutMs?: number;
23
+ /** How many times the function is run again after 40001 or 40P01, from 0 to `TX_RETRY_MAX_CEILING`. Default `TX_RETRY_MAX`. */
24
+ readonly retryMax?: number;
25
+ /** The wait before a retry. Default `defaultRetryDelay`. */
26
+ readonly retryDelay?: IRetryDelay;
27
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ITxOptions.mjs.map
@@ -0,0 +1,5 @@
1
+ import type { ITxClient } from "./ITxClient.mjs";
2
+ /** What `withTx` needs of a pool: the node-postgres `Pool` (made by `createPool`) has it. */
3
+ export interface ITxPool {
4
+ connect(): Promise<ITxClient>;
5
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ITxPool.mjs.map
@@ -0,0 +1,6 @@
1
+ /** What a statement answers: the rows, the count the server reports and the command tag. */
2
+ export interface ITxResult<TRow = Record<string, unknown>> {
3
+ readonly rows: TRow[];
4
+ readonly rowCount: number | null;
5
+ readonly command: string;
6
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ITxResult.mjs.map
@@ -0,0 +1,2 @@
1
+ /** The most `lock_timeout` the server takes (a 32-bit count of milliseconds). */
2
+ export declare const MAX_LOCK_TIMEOUT_MS = 2147483647;
@@ -0,0 +1,3 @@
1
+ /** The most `lock_timeout` the server takes (a 32-bit count of milliseconds). */
2
+ export const MAX_LOCK_TIMEOUT_MS = 2_147_483_647;
3
+ //# sourceMappingURL=MAX_LOCK_TIMEOUT_MS.mjs.map
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The closed reasons of the error that `withTx` asks its error factory for (`internal(reason)`):
3
+ *
4
+ * - `TX_RETRY_EXHAUSTED`: the transaction failed with SQLSTATE 40001 or 40P01 on every attempt, the retries included.
5
+ * - `LOCK_TIMEOUT`: a statement waited longer than the lock timeout (SQLSTATE 55P03). It is not retried.
6
+ */
7
+ export declare const TX_FAILURE_REASONS: readonly ["TX_RETRY_EXHAUSTED", "LOCK_TIMEOUT"];
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The closed reasons of the error that `withTx` asks its error factory for (`internal(reason)`):
3
+ *
4
+ * - `TX_RETRY_EXHAUSTED`: the transaction failed with SQLSTATE 40001 or 40P01 on every attempt, the retries included.
5
+ * - `LOCK_TIMEOUT`: a statement waited longer than the lock timeout (SQLSTATE 55P03). It is not retried.
6
+ */
7
+ export const TX_FAILURE_REASONS = ['TX_RETRY_EXHAUSTED', 'LOCK_TIMEOUT'];
8
+ //# sourceMappingURL=TX_FAILURE_REASONS.mjs.map
@@ -0,0 +1,2 @@
1
+ /** The isolation levels `withTx` opens. `READ UNCOMMITTED` is the server's alias of `READ COMMITTED` and is not offered. */
2
+ export declare const TX_ISOLATION_LEVELS: readonly ["READ COMMITTED", "REPEATABLE READ", "SERIALIZABLE"];
@@ -0,0 +1,3 @@
1
+ /** The isolation levels `withTx` opens. `READ UNCOMMITTED` is the server's alias of `READ COMMITTED` and is not offered. */
2
+ export const TX_ISOLATION_LEVELS = ['READ COMMITTED', 'REPEATABLE READ', 'SERIALIZABLE'];
3
+ //# sourceMappingURL=TX_ISOLATION_LEVELS.mjs.map
@@ -0,0 +1,2 @@
1
+ /** The base of the jittered wait before a retry, in milliseconds (see `jitteredDelay`). */
2
+ export declare const TX_RETRY_BASE_DELAY_MS = 25;
@@ -0,0 +1,3 @@
1
+ /** The base of the jittered wait before a retry, in milliseconds (see `jitteredDelay`). */
2
+ export const TX_RETRY_BASE_DELAY_MS = 25;
3
+ //# sourceMappingURL=TX_RETRY_BASE_DELAY_MS.mjs.map
@@ -0,0 +1,2 @@
1
+ /** How many times a transaction is run again after SQLSTATE 40001 or 40P01, when `retryMax` is not given. */
2
+ export declare const TX_RETRY_MAX = 2;
@@ -0,0 +1,3 @@
1
+ /** How many times a transaction is run again after SQLSTATE 40001 or 40P01, when `retryMax` is not given. */
2
+ export const TX_RETRY_MAX = 2;
3
+ //# sourceMappingURL=TX_RETRY_MAX.mjs.map
@@ -0,0 +1,2 @@
1
+ /** The most an option `retryMax` may ask for, so that a loop is always short. */
2
+ export declare const TX_RETRY_MAX_CEILING = 10;
@@ -0,0 +1,3 @@
1
+ /** The most an option `retryMax` may ask for, so that a loop is always short. */
2
+ export const TX_RETRY_MAX_CEILING = 10;
3
+ //# sourceMappingURL=TX_RETRY_MAX_CEILING.mjs.map
@@ -0,0 +1,3 @@
1
+ import type { IRetryDelay } from "./IRetryDelay.mjs";
2
+ /** The default wait before a retry: `jitteredDelay()`. */
3
+ export declare const defaultRetryDelay: IRetryDelay;
@@ -0,0 +1,4 @@
1
+ import { jitteredDelay } from "./jitteredDelay.mjs";
2
+ /** The default wait before a retry: `jitteredDelay()`. */
3
+ export const defaultRetryDelay = jitteredDelay();
4
+ //# sourceMappingURL=defaultRetryDelay.mjs.map
@@ -0,0 +1,7 @@
1
+ import type { IRetryDelay } from "./IRetryDelay.mjs";
2
+ /**
3
+ * A wait of a random length from 0 to `TX_RETRY_BASE_DELAY_MS` times two to the power of the retry number minus one,
4
+ * both ends included ("full jitter"), so that two transactions that collided do not collide again in step.
5
+ * `random(n)` answers a whole number from 0 up to n, n excluded; the default is `node:crypto` `randomInt`.
6
+ */
7
+ export declare function jitteredDelay(random?: (maxExclusive: number) => number): IRetryDelay;
@@ -0,0 +1,16 @@
1
+ import { randomInt } from 'node:crypto';
2
+ import { TX_RETRY_BASE_DELAY_MS } from "./TX_RETRY_BASE_DELAY_MS.mjs";
3
+ /**
4
+ * A wait of a random length from 0 to `TX_RETRY_BASE_DELAY_MS` times two to the power of the retry number minus one,
5
+ * both ends included ("full jitter"), so that two transactions that collided do not collide again in step.
6
+ * `random(n)` answers a whole number from 0 up to n, n excluded; the default is `node:crypto` `randomInt`.
7
+ */
8
+ export function jitteredDelay(random = (max) => randomInt(max)) {
9
+ return (retry) => {
10
+ const wait = random(TX_RETRY_BASE_DELAY_MS * 2 ** (retry - 1) + 1);
11
+ return new Promise((done) => {
12
+ setTimeout(done, wait);
13
+ });
14
+ };
15
+ }
16
+ //# sourceMappingURL=jitteredDelay.mjs.map
@@ -0,0 +1,39 @@
1
+ import type { ITx } from "./ITx.mjs";
2
+ import type { ITxOptions } from "./ITxOptions.mjs";
3
+ import type { ITxPool } from "./ITxPool.mjs";
4
+ /**
5
+ * Runs `fn` in a transaction and answers what it answers. It is the one transaction wrapper, so that no caller writes
6
+ * its own isolation, lock timeout or retry loop.
7
+ *
8
+ * What one attempt does, in order:
9
+ *
10
+ * 1. Checks a connection out of the pool and listens to its `error` event while it holds it.
11
+ * 2. `BEGIN ISOLATION LEVEL <level> [READ ONLY]`, the text taken from a closed table (never built), then
12
+ * `SET LOCAL lock_timeout = <ms>`. `SET LOCAL` is the only form of `SET` here: the value ends with the transaction,
13
+ * so the role-level value is back for the next user of the connection, and a transaction pooler stays usable.
14
+ * 3. Runs `fn` with a handle that has one member, `query`. The pool and the connection are not reachable from the
15
+ * handle, and the handle stops working when the transaction ends, so a statement cannot run outside the
16
+ * transaction, not even through a handle that `fn` kept.
17
+ * 4. `COMMIT` when `fn` resolved; `ROLLBACK` when anything threw. A rollback that fails does not hide the error that
18
+ * caused it: the original error is thrown, and the connection is destroyed instead of returned to the pool.
19
+ *
20
+ * What the loop does with a failure of an attempt, by SQLSTATE:
21
+ *
22
+ * - `40001` (serialisation failure) and `40P01` (deadlock detected): the whole attempt was rolled back; `fn` runs again
23
+ * in a fresh transaction on a fresh checkout, after the injected delay, up to `retryMax` times (default
24
+ * `TX_RETRY_MAX`). After the last one fails too the caller gets `options.errors.internal('TX_RETRY_EXHAUSTED')`.
25
+ * - `55P03` (lock not available, the lock timeout): no retry; `options.errors.internal('LOCK_TIMEOUT')`.
26
+ * - anything else: rethrown unchanged (the same object) after the rollback.
27
+ *
28
+ * The two errors of the factory are asked for a reason and nothing else: no `cause`, no driver message, no constraint
29
+ * name. The reason goes to the log and to a counter, with the SQLSTATE and the number of attempts and nothing the
30
+ * driver wrote.
31
+ *
32
+ * A swallowed failure is not a success: if `fn` catches the error of a statement and resolves, the server answers
33
+ * `COMMIT` with the tag `ROLLBACK` (the transaction is aborted). The wrapper reads the tag and throws the first failed
34
+ * statement, which then goes through the classification above.
35
+ *
36
+ * Rejects with `TypeError` for an option out of range (before a connection is taken). `fn` may run more than once, so it
37
+ * must hold no state that a failed run leaves behind.
38
+ */
39
+ export declare function withTx<T>(pool: ITxPool, options: ITxOptions, fn: (tx: ITx) => Promise<T>): Promise<T>;