@axiumine/koa-utils 8.0.0 → 9.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 (431) hide show
  1. package/LICENSE +658 -228
  2. package/README.md +8 -4
  3. package/dist/dataSources/PostgreSQL.mjs +5 -5
  4. package/dist/email/SocketLabsLib.d.mts +2 -1
  5. package/dist/email/SocketLabsLib.mjs +5 -3
  6. package/dist/files/storeUploadAsTemp.mjs +2 -0
  7. package/dist/graphQL/schema/mutations/emailChangeHashVerify.mjs +2 -1
  8. package/dist/graphQL/schema/mutations/logout.mjs +1 -1
  9. package/dist/graphQL/schema/mutations/resetPwd.mjs +3 -1
  10. package/dist/koa/middleware/authenticatedAuthorizationHandler/index.d.mts +1 -1
  11. package/dist/koa/middleware/authenticatedAuthorizationHandler/verifySignedRefreshToken.mjs +12 -9
  12. package/dist/koa/middleware/authenticatedLogoutHandler/index.d.mts +1 -1
  13. package/dist/koa/middleware/authenticatedResourceHandler/index.d.mts +1 -1
  14. package/dist/koa/middleware/debug/index.d.mts +1 -1
  15. package/dist/lib/ArrayLib.d.mts +0 -1
  16. package/dist/lib/ArrayLib.mjs +0 -1
  17. package/dist/lib/DateLib.mjs +1 -1
  18. package/dist/lib/MariaDB/throwSqlErrors.mjs +3 -1
  19. package/dist/lib/MongoDB/IMongoDBError.d.mts +2 -3
  20. package/dist/lib/MongoDB/throwIfMongoErr.mjs +4 -2
  21. package/dist/lib/NumLib.d.mts +0 -1
  22. package/dist/lib/NumLib.mjs +1 -1
  23. package/dist/lib/PostgreSQL/clock/CLOCK_SQL.d.mts +7 -0
  24. package/dist/lib/PostgreSQL/clock/CLOCK_SQL.mjs +8 -0
  25. package/dist/lib/PostgreSQL/clock/DB_NOW_SQL.d.mts +5 -0
  26. package/dist/lib/PostgreSQL/clock/DB_NOW_SQL.mjs +6 -0
  27. package/dist/lib/PostgreSQL/clock/IClock.d.mts +4 -0
  28. package/dist/lib/PostgreSQL/clock/IClock.mjs +2 -0
  29. package/dist/lib/PostgreSQL/clock/IDbClock.d.mts +11 -0
  30. package/dist/lib/PostgreSQL/clock/IDbClock.mjs +2 -0
  31. package/dist/lib/PostgreSQL/clock/IDbClockOptions.d.mts +11 -0
  32. package/dist/lib/PostgreSQL/clock/IDbClockOptions.mjs +2 -0
  33. package/dist/lib/PostgreSQL/clock/IDbClockSeam.d.mts +10 -0
  34. package/dist/lib/PostgreSQL/clock/IDbClockSeam.mjs +2 -0
  35. package/dist/lib/PostgreSQL/clock/createDbClock.d.mts +23 -0
  36. package/dist/lib/PostgreSQL/clock/createDbClock.mjs +54 -0
  37. package/dist/lib/PostgreSQL/clock/lockTaken.d.mts +11 -0
  38. package/dist/lib/PostgreSQL/clock/lockTaken.mjs +17 -0
  39. package/dist/lib/PostgreSQL/counter/IDbCounter.d.mts +9 -0
  40. package/dist/lib/PostgreSQL/counter/IDbCounter.mjs +2 -0
  41. package/dist/lib/PostgreSQL/error/DB_CLOCK_REASONS.d.mts +12 -0
  42. package/dist/lib/PostgreSQL/error/DB_CLOCK_REASONS.mjs +20 -0
  43. package/dist/lib/PostgreSQL/error/DB_CONNECT_REASONS.d.mts +11 -0
  44. package/dist/lib/PostgreSQL/error/DB_CONNECT_REASONS.mjs +12 -0
  45. package/dist/lib/PostgreSQL/error/DB_INTERNAL_REASONS.d.mts +23 -0
  46. package/dist/lib/PostgreSQL/error/DB_INTERNAL_REASONS.mjs +35 -0
  47. package/dist/lib/PostgreSQL/error/DB_PARSE_REASONS.d.mts +13 -0
  48. package/dist/lib/PostgreSQL/error/DB_PARSE_REASONS.mjs +14 -0
  49. package/dist/lib/PostgreSQL/error/DB_STATE_REASONS.d.mts +7 -0
  50. package/dist/lib/PostgreSQL/error/DB_STATE_REASONS.mjs +8 -0
  51. package/dist/lib/PostgreSQL/error/DB_TX_REASONS.d.mts +9 -0
  52. package/dist/lib/PostgreSQL/error/DB_TX_REASONS.mjs +10 -0
  53. package/dist/lib/PostgreSQL/error/DbClockError.d.mts +6 -0
  54. package/dist/lib/PostgreSQL/error/DbClockError.mjs +27 -0
  55. package/dist/lib/PostgreSQL/error/DbConnectError.d.mts +11 -0
  56. package/dist/lib/PostgreSQL/error/DbConnectError.mjs +18 -0
  57. package/dist/lib/PostgreSQL/error/DbParseError.d.mts +11 -0
  58. package/dist/lib/PostgreSQL/error/DbParseError.mjs +16 -0
  59. package/dist/lib/PostgreSQL/error/DbStateError.d.mts +10 -0
  60. package/dist/lib/PostgreSQL/error/DbStateError.mjs +14 -0
  61. package/dist/lib/PostgreSQL/error/DbTxError.d.mts +6 -0
  62. package/dist/lib/PostgreSQL/error/DbTxError.mjs +10 -0
  63. package/dist/lib/PostgreSQL/error/IConstraintEntry.d.mts +17 -0
  64. package/dist/lib/PostgreSQL/error/IConstraintEntry.mjs +2 -0
  65. package/dist/lib/PostgreSQL/error/IConstraintEntryBuilder.d.mts +20 -0
  66. package/dist/lib/PostgreSQL/error/IConstraintEntryBuilder.mjs +2 -0
  67. package/dist/lib/PostgreSQL/error/IConstraintTable.d.mts +7 -0
  68. package/dist/lib/PostgreSQL/error/IConstraintTable.mjs +2 -0
  69. package/dist/lib/PostgreSQL/error/IDbClockReason.d.mts +3 -0
  70. package/dist/lib/PostgreSQL/error/IDbClockReason.mjs +2 -0
  71. package/dist/lib/PostgreSQL/error/IDbConnectReason.d.mts +3 -0
  72. package/dist/lib/PostgreSQL/error/IDbConnectReason.mjs +2 -0
  73. package/dist/lib/PostgreSQL/error/IDbErrorCounter.d.mts +4 -0
  74. package/dist/lib/PostgreSQL/error/IDbErrorCounter.mjs +2 -0
  75. package/dist/lib/PostgreSQL/error/IDbErrorCounterName.d.mts +7 -0
  76. package/dist/lib/PostgreSQL/error/IDbErrorCounterName.mjs +2 -0
  77. package/dist/lib/PostgreSQL/error/IDbErrorFactory.d.mts +16 -0
  78. package/dist/lib/PostgreSQL/error/IDbErrorFactory.mjs +2 -0
  79. package/dist/lib/PostgreSQL/error/IDbInternalReason.d.mts +3 -0
  80. package/dist/lib/PostgreSQL/error/IDbInternalReason.mjs +2 -0
  81. package/dist/lib/PostgreSQL/error/IDbParseReason.d.mts +3 -0
  82. package/dist/lib/PostgreSQL/error/IDbParseReason.mjs +2 -0
  83. package/dist/lib/PostgreSQL/error/IDbStateReason.d.mts +3 -0
  84. package/dist/lib/PostgreSQL/error/IDbStateReason.mjs +2 -0
  85. package/dist/lib/PostgreSQL/error/IDbTxReason.d.mts +3 -0
  86. package/dist/lib/PostgreSQL/error/IDbTxReason.mjs +2 -0
  87. package/dist/lib/PostgreSQL/error/ILockOrderReason.d.mts +3 -0
  88. package/dist/lib/PostgreSQL/error/ILockOrderReason.mjs +2 -0
  89. package/dist/lib/PostgreSQL/error/IMapDbErrorOptions.d.mts +22 -0
  90. package/dist/lib/PostgreSQL/error/IMapDbErrorOptions.mjs +2 -0
  91. package/dist/lib/PostgreSQL/error/IRoleAssertionReason.d.mts +3 -0
  92. package/dist/lib/PostgreSQL/error/IRoleAssertionReason.mjs +2 -0
  93. package/dist/lib/PostgreSQL/error/IRoleAssertionSubject.d.mts +12 -0
  94. package/dist/lib/PostgreSQL/error/IRoleAssertionSubject.mjs +2 -0
  95. package/dist/lib/PostgreSQL/error/LOCK_ORDER_REASONS.d.mts +11 -0
  96. package/dist/lib/PostgreSQL/error/LOCK_ORDER_REASONS.mjs +12 -0
  97. package/dist/lib/PostgreSQL/error/LockOrderError.d.mts +6 -0
  98. package/dist/lib/PostgreSQL/error/LockOrderError.mjs +10 -0
  99. package/dist/lib/PostgreSQL/error/ROLE_ASSERT_REASONS.d.mts +21 -0
  100. package/dist/lib/PostgreSQL/error/ROLE_ASSERT_REASONS.mjs +35 -0
  101. package/dist/lib/PostgreSQL/error/RoleAssertionError.d.mts +19 -0
  102. package/dist/lib/PostgreSQL/error/RoleAssertionError.mjs +58 -0
  103. package/dist/lib/PostgreSQL/error/buildConstraintEntry.d.mts +15 -0
  104. package/dist/lib/PostgreSQL/error/buildConstraintEntry.mjs +16 -0
  105. package/dist/lib/PostgreSQL/error/constraintNameOf.d.mts +6 -0
  106. package/dist/lib/PostgreSQL/error/constraintNameOf.mjs +17 -0
  107. package/dist/lib/PostgreSQL/error/errorNameOf.d.mts +5 -0
  108. package/dist/lib/PostgreSQL/error/errorNameOf.mjs +12 -0
  109. package/dist/lib/PostgreSQL/error/lookupConstraint.d.mts +7 -0
  110. package/dist/lib/PostgreSQL/error/lookupConstraint.mjs +8 -0
  111. package/dist/lib/PostgreSQL/error/mapDbError.d.mts +28 -0
  112. package/dist/lib/PostgreSQL/error/mapDbError.mjs +52 -0
  113. package/dist/lib/PostgreSQL/error/sqlstateField.d.mts +4 -0
  114. package/dist/lib/PostgreSQL/error/sqlstateField.mjs +5 -0
  115. package/dist/lib/PostgreSQL/error/sqlstateOf.d.mts +5 -0
  116. package/dist/lib/PostgreSQL/error/sqlstateOf.mjs +12 -0
  117. package/dist/lib/PostgreSQL/guard/IAffectedResult.d.mts +4 -0
  118. package/dist/lib/PostgreSQL/guard/IAffectedResult.mjs +2 -0
  119. package/dist/lib/PostgreSQL/guard/IGuardCounter.d.mts +3 -0
  120. package/dist/lib/PostgreSQL/guard/IGuardCounter.mjs +2 -0
  121. package/dist/lib/PostgreSQL/guard/IVersionGuardCode.d.mts +5 -0
  122. package/dist/lib/PostgreSQL/guard/IVersionGuardCode.mjs +2 -0
  123. package/dist/lib/PostgreSQL/guard/IVersionGuardField.d.mts +3 -0
  124. package/dist/lib/PostgreSQL/guard/IVersionGuardField.mjs +2 -0
  125. package/dist/lib/PostgreSQL/guard/IVersionGuardInput.d.mts +29 -0
  126. package/dist/lib/PostgreSQL/guard/IVersionGuardInput.mjs +2 -0
  127. package/dist/lib/PostgreSQL/guard/VERSION_GUARD_FIELDS.d.mts +2 -0
  128. package/dist/lib/PostgreSQL/guard/VERSION_GUARD_FIELDS.mjs +3 -0
  129. package/dist/lib/PostgreSQL/guard/assertAffected.d.mts +10 -0
  130. package/dist/lib/PostgreSQL/guard/assertAffected.mjs +17 -0
  131. package/dist/lib/PostgreSQL/guard/guardVersion.d.mts +21 -0
  132. package/dist/lib/PostgreSQL/guard/guardVersion.mjs +47 -0
  133. package/dist/lib/PostgreSQL/lock/CLAIM_LIMIT_MAX.d.mts +2 -0
  134. package/dist/lib/PostgreSQL/lock/CLAIM_LIMIT_MAX.mjs +3 -0
  135. package/dist/lib/PostgreSQL/lock/IClaimRegistry.d.mts +6 -0
  136. package/dist/lib/PostgreSQL/lock/IClaimRegistry.mjs +2 -0
  137. package/dist/lib/PostgreSQL/lock/IClaimRequest.d.mts +7 -0
  138. package/dist/lib/PostgreSQL/lock/IClaimRequest.mjs +2 -0
  139. package/dist/lib/PostgreSQL/lock/ILockAdmission.d.mts +4 -0
  140. package/dist/lib/PostgreSQL/lock/ILockAdmission.mjs +2 -0
  141. package/dist/lib/PostgreSQL/lock/ILockOrderSpec.d.mts +19 -0
  142. package/dist/lib/PostgreSQL/lock/ILockOrderSpec.mjs +2 -0
  143. package/dist/lib/PostgreSQL/lock/ILockOrderTracker.d.mts +41 -0
  144. package/dist/lib/PostgreSQL/lock/ILockOrderTracker.mjs +2 -0
  145. package/dist/lib/PostgreSQL/lock/ILockTrackerConfig.d.mts +5 -0
  146. package/dist/lib/PostgreSQL/lock/ILockTrackerConfig.mjs +2 -0
  147. package/dist/lib/PostgreSQL/lock/ILockTrackerOptions.d.mts +7 -0
  148. package/dist/lib/PostgreSQL/lock/ILockTrackerOptions.mjs +2 -0
  149. package/dist/lib/PostgreSQL/lock/IRowLockMode.d.mts +3 -0
  150. package/dist/lib/PostgreSQL/lock/IRowLockMode.mjs +2 -0
  151. package/dist/lib/PostgreSQL/lock/ROW_LOCK_MODES.d.mts +2 -0
  152. package/dist/lib/PostgreSQL/lock/ROW_LOCK_MODES.mjs +3 -0
  153. package/dist/lib/PostgreSQL/lock/claimRowsSkipLocked.d.mts +16 -0
  154. package/dist/lib/PostgreSQL/lock/claimRowsSkipLocked.mjs +32 -0
  155. package/dist/lib/PostgreSQL/lock/createLockOrderTracker.d.mts +14 -0
  156. package/dist/lib/PostgreSQL/lock/createLockOrderTracker.mjs +60 -0
  157. package/dist/lib/PostgreSQL/lock/lockedRow.d.mts +7 -0
  158. package/dist/lib/PostgreSQL/lock/lockedRow.mjs +12 -0
  159. package/dist/lib/PostgreSQL/lock/lockedRows.d.mts +3 -0
  160. package/dist/lib/PostgreSQL/lock/lockedRows.mjs +8 -0
  161. package/dist/lib/PostgreSQL/lock/rowLockModeOf.d.mts +3 -0
  162. package/dist/lib/PostgreSQL/lock/rowLockModeOf.mjs +9 -0
  163. package/dist/lib/PostgreSQL/lock/uuidOf.d.mts +2 -0
  164. package/dist/lib/PostgreSQL/lock/uuidOf.mjs +10 -0
  165. package/dist/lib/PostgreSQL/lock/uuidsOf.d.mts +5 -0
  166. package/dist/lib/PostgreSQL/lock/uuidsOf.mjs +13 -0
  167. package/dist/lib/PostgreSQL/parse/IArrayParser.d.mts +2 -0
  168. package/dist/lib/PostgreSQL/parse/IArrayParser.mjs +2 -0
  169. package/dist/lib/PostgreSQL/parse/IDriverTypes.d.mts +4 -0
  170. package/dist/lib/PostgreSQL/parse/IDriverTypes.mjs +2 -0
  171. package/dist/lib/PostgreSQL/parse/IStringParser.d.mts +2 -0
  172. package/dist/lib/PostgreSQL/parse/IStringParser.mjs +2 -0
  173. package/dist/lib/PostgreSQL/parse/ITypeParserEntry.d.mts +9 -0
  174. package/dist/lib/PostgreSQL/parse/ITypeParserEntry.mjs +2 -0
  175. package/dist/lib/PostgreSQL/parse/TYPE_PARSERS.d.mts +12 -0
  176. package/dist/lib/PostgreSQL/parse/TYPE_PARSERS.mjs +38 -0
  177. package/dist/lib/PostgreSQL/parse/arrayOf.d.mts +7 -0
  178. package/dist/lib/PostgreSQL/parse/arrayOf.mjs +50 -0
  179. package/dist/lib/PostgreSQL/parse/createTypeRegistry.d.mts +13 -0
  180. package/dist/lib/PostgreSQL/parse/createTypeRegistry.mjs +26 -0
  181. package/dist/lib/PostgreSQL/parse/parseDate.d.mts +7 -0
  182. package/dist/lib/PostgreSQL/parse/parseDate.mjs +19 -0
  183. package/dist/lib/PostgreSQL/parse/parseInt8.d.mts +6 -0
  184. package/dist/lib/PostgreSQL/parse/parseInt8.mjs +17 -0
  185. package/dist/lib/PostgreSQL/parse/parseTime.d.mts +7 -0
  186. package/dist/lib/PostgreSQL/parse/parseTime.mjs +24 -0
  187. package/dist/lib/PostgreSQL/parse/parseTimestamptz.d.mts +17 -0
  188. package/dist/lib/PostgreSQL/parse/parseTimestamptz.mjs +79 -0
  189. package/dist/lib/PostgreSQL/parse/parseUuid.d.mts +3 -0
  190. package/dist/lib/PostgreSQL/parse/parseUuid.mjs +9 -0
  191. package/dist/lib/PostgreSQL/pool/DEFAULT_CONNECT_TIMEOUT_MS.d.mts +2 -0
  192. package/dist/lib/PostgreSQL/pool/DEFAULT_CONNECT_TIMEOUT_MS.mjs +3 -0
  193. package/dist/lib/PostgreSQL/pool/DEFAULT_KEEPALIVE_INITIAL_DELAY_MS.d.mts +2 -0
  194. package/dist/lib/PostgreSQL/pool/DEFAULT_KEEPALIVE_INITIAL_DELAY_MS.mjs +3 -0
  195. package/dist/lib/PostgreSQL/pool/ICreatePoolOptions.d.mts +28 -0
  196. package/dist/lib/PostgreSQL/pool/ICreatePoolOptions.mjs +2 -0
  197. package/dist/lib/PostgreSQL/pool/IDbDriver.d.mts +12 -0
  198. package/dist/lib/PostgreSQL/pool/IDbDriver.mjs +2 -0
  199. package/dist/lib/PostgreSQL/pool/IPoolCounter.d.mts +4 -0
  200. package/dist/lib/PostgreSQL/pool/IPoolCounter.mjs +2 -0
  201. package/dist/lib/PostgreSQL/pool/IPoolCounterName.d.mts +7 -0
  202. package/dist/lib/PostgreSQL/pool/IPoolCounterName.mjs +2 -0
  203. package/dist/lib/PostgreSQL/pool/IPoolEvents.d.mts +4 -0
  204. package/dist/lib/PostgreSQL/pool/IPoolEvents.mjs +2 -0
  205. package/dist/lib/PostgreSQL/pool/IPoolLogger.d.mts +8 -0
  206. package/dist/lib/PostgreSQL/pool/IPoolLogger.mjs +2 -0
  207. package/dist/lib/PostgreSQL/pool/REQUIRED_SESSION_TIME_ZONE.d.mts +2 -0
  208. package/dist/lib/PostgreSQL/pool/REQUIRED_SESSION_TIME_ZONE.mjs +3 -0
  209. package/dist/lib/PostgreSQL/pool/createPool.d.mts +31 -0
  210. package/dist/lib/PostgreSQL/pool/createPool.mjs +67 -0
  211. package/dist/lib/PostgreSQL/role/IAssertRoleOptions.d.mts +10 -0
  212. package/dist/lib/PostgreSQL/role/IAssertRoleOptions.mjs +2 -0
  213. package/dist/lib/PostgreSQL/role/IRoleAssertion.d.mts +6 -0
  214. package/dist/lib/PostgreSQL/role/IRoleAssertion.mjs +2 -0
  215. package/dist/lib/PostgreSQL/role/IRoleGrant.d.mts +19 -0
  216. package/dist/lib/PostgreSQL/role/IRoleGrant.mjs +2 -0
  217. package/dist/lib/PostgreSQL/role/IRolePool.d.mts +6 -0
  218. package/dist/lib/PostgreSQL/role/IRolePool.mjs +2 -0
  219. package/dist/lib/PostgreSQL/role/assertRole.d.mts +36 -0
  220. package/dist/lib/PostgreSQL/role/assertRole.mjs +54 -0
  221. package/dist/lib/PostgreSQL/tx/DEFAULT_LOCK_TIMEOUT_MS.d.mts +2 -0
  222. package/dist/lib/PostgreSQL/tx/DEFAULT_LOCK_TIMEOUT_MS.mjs +3 -0
  223. package/dist/lib/PostgreSQL/tx/IRetryDelay.d.mts +2 -0
  224. package/dist/lib/PostgreSQL/tx/IRetryDelay.mjs +2 -0
  225. package/dist/lib/PostgreSQL/tx/ITx.d.mts +9 -0
  226. package/dist/lib/PostgreSQL/tx/ITx.mjs +2 -0
  227. package/dist/lib/PostgreSQL/tx/ITxClient.d.mts +12 -0
  228. package/dist/lib/PostgreSQL/tx/ITxClient.mjs +2 -0
  229. package/dist/lib/PostgreSQL/tx/ITxCounter.d.mts +4 -0
  230. package/dist/lib/PostgreSQL/tx/ITxCounter.mjs +2 -0
  231. package/dist/lib/PostgreSQL/tx/ITxCounterName.d.mts +10 -0
  232. package/dist/lib/PostgreSQL/tx/ITxCounterName.mjs +2 -0
  233. package/dist/lib/PostgreSQL/tx/ITxFailureReason.d.mts +3 -0
  234. package/dist/lib/PostgreSQL/tx/ITxFailureReason.mjs +2 -0
  235. package/dist/lib/PostgreSQL/tx/ITxIsolation.d.mts +3 -0
  236. package/dist/lib/PostgreSQL/tx/ITxIsolation.mjs +2 -0
  237. package/dist/lib/PostgreSQL/tx/ITxOptions.d.mts +27 -0
  238. package/dist/lib/PostgreSQL/tx/ITxOptions.mjs +2 -0
  239. package/dist/lib/PostgreSQL/tx/ITxPool.d.mts +5 -0
  240. package/dist/lib/PostgreSQL/tx/ITxPool.mjs +2 -0
  241. package/dist/lib/PostgreSQL/tx/ITxResult.d.mts +6 -0
  242. package/dist/lib/PostgreSQL/tx/ITxResult.mjs +2 -0
  243. package/dist/lib/PostgreSQL/tx/MAX_LOCK_TIMEOUT_MS.d.mts +2 -0
  244. package/dist/lib/PostgreSQL/tx/MAX_LOCK_TIMEOUT_MS.mjs +3 -0
  245. package/dist/lib/PostgreSQL/tx/TX_FAILURE_REASONS.d.mts +7 -0
  246. package/dist/lib/PostgreSQL/tx/TX_FAILURE_REASONS.mjs +8 -0
  247. package/dist/lib/PostgreSQL/tx/TX_ISOLATION_LEVELS.d.mts +2 -0
  248. package/dist/lib/PostgreSQL/tx/TX_ISOLATION_LEVELS.mjs +3 -0
  249. package/dist/lib/PostgreSQL/tx/TX_RETRY_BASE_DELAY_MS.d.mts +2 -0
  250. package/dist/lib/PostgreSQL/tx/TX_RETRY_BASE_DELAY_MS.mjs +3 -0
  251. package/dist/lib/PostgreSQL/tx/TX_RETRY_MAX.d.mts +2 -0
  252. package/dist/lib/PostgreSQL/tx/TX_RETRY_MAX.mjs +3 -0
  253. package/dist/lib/PostgreSQL/tx/TX_RETRY_MAX_CEILING.d.mts +2 -0
  254. package/dist/lib/PostgreSQL/tx/TX_RETRY_MAX_CEILING.mjs +3 -0
  255. package/dist/lib/PostgreSQL/tx/defaultRetryDelay.d.mts +3 -0
  256. package/dist/lib/PostgreSQL/tx/defaultRetryDelay.mjs +4 -0
  257. package/dist/lib/PostgreSQL/tx/jitteredDelay.d.mts +7 -0
  258. package/dist/lib/PostgreSQL/tx/jitteredDelay.mjs +16 -0
  259. package/dist/lib/PostgreSQL/tx/withTx.d.mts +39 -0
  260. package/dist/lib/PostgreSQL/tx/withTx.mjs +41 -0
  261. package/dist/lib/PostgreSQL/url/IDatabaseUrlOptions.d.mts +10 -0
  262. package/dist/lib/PostgreSQL/url/IDatabaseUrlOptions.mjs +2 -0
  263. package/dist/lib/PostgreSQL/url/IDatabaseUrlReason.d.mts +14 -0
  264. package/dist/lib/PostgreSQL/url/IDatabaseUrlReason.mjs +2 -0
  265. package/dist/lib/PostgreSQL/url/LOOPBACK_HOSTS.d.mts +2 -0
  266. package/dist/lib/PostgreSQL/url/LOOPBACK_HOSTS.mjs +3 -0
  267. package/dist/lib/PostgreSQL/url/databaseUrlReason.d.mts +20 -0
  268. package/dist/lib/PostgreSQL/url/databaseUrlReason.mjs +99 -0
  269. package/dist/lib/PostgreSQL/url/isAbsolutePath.d.mts +2 -0
  270. package/dist/lib/PostgreSQL/url/isAbsolutePath.mjs +14 -0
  271. package/dist/lib/PostgreSQL/url/isValidHost.d.mts +6 -0
  272. package/dist/lib/PostgreSQL/url/isValidHost.mjs +20 -0
  273. package/dist/lib/StringLib.d.mts +0 -1
  274. package/dist/lib/StringLib.mjs +0 -1
  275. package/dist/lib/db/log/logGraphql.d.mts +8 -6
  276. package/dist/lib/db/log/logGraphql.mjs +9 -23
  277. package/dist/lib/db/log/logThrow.d.mts +9 -0
  278. package/dist/lib/db/log/logThrow.mjs +11 -11
  279. package/dist/lib/hash.mjs +1 -6
  280. package/dist/lib/isSessionBlocked.d.mts +1 -1
  281. package/dist/lib/throwIfNotValidEnumValue.mjs +1 -0
  282. package/dist/lib/tryCatchRethrow.mjs +5 -3
  283. package/dist/private/files/reEncode.mjs +2 -0
  284. package/dist/private/lib/PostgreSQL/ICivilDate.d.mts +6 -0
  285. package/dist/private/lib/PostgreSQL/ICivilDate.mjs +2 -0
  286. package/dist/private/lib/PostgreSQL/IClientConstructor.d.mts +3 -0
  287. package/dist/private/lib/PostgreSQL/IClientConstructor.mjs +2 -0
  288. package/dist/private/lib/PostgreSQL/IClientShape.d.mts +10 -0
  289. package/dist/private/lib/PostgreSQL/IClientShape.mjs +2 -0
  290. package/dist/private/lib/PostgreSQL/IClockSlot.d.mts +11 -0
  291. package/dist/private/lib/PostgreSQL/IClockSlot.mjs +2 -0
  292. package/dist/private/lib/PostgreSQL/IConnectCallback.d.mts +2 -0
  293. package/dist/private/lib/PostgreSQL/IConnectCallback.mjs +2 -0
  294. package/dist/private/lib/PostgreSQL/IConnectSettings.d.mts +8 -0
  295. package/dist/private/lib/PostgreSQL/IConnectSettings.mjs +2 -0
  296. package/dist/private/lib/PostgreSQL/IHelperRank.d.mts +5 -0
  297. package/dist/private/lib/PostgreSQL/IHelperRank.mjs +2 -0
  298. package/dist/private/lib/PostgreSQL/IInternalSink.d.mts +9 -0
  299. package/dist/private/lib/PostgreSQL/IInternalSink.mjs +2 -0
  300. package/dist/private/lib/PostgreSQL/ILockOrderPlan.d.mts +8 -0
  301. package/dist/private/lib/PostgreSQL/ILockOrderPlan.mjs +2 -0
  302. package/dist/private/lib/PostgreSQL/IModeOrder.d.mts +7 -0
  303. package/dist/private/lib/PostgreSQL/IModeOrder.mjs +2 -0
  304. package/dist/private/lib/PostgreSQL/IPostgresState.d.mts +9 -0
  305. package/dist/private/lib/PostgreSQL/IPostgresState.mjs +2 -0
  306. package/dist/private/lib/PostgreSQL/IRoleCheck.d.mts +4 -0
  307. package/dist/private/lib/PostgreSQL/IRoleCheck.mjs +2 -0
  308. package/dist/private/lib/PostgreSQL/IRoleColumnCheck.d.mts +7 -0
  309. package/dist/private/lib/PostgreSQL/IRoleColumnCheck.mjs +2 -0
  310. package/dist/private/lib/PostgreSQL/IRoleObjectCheck.d.mts +6 -0
  311. package/dist/private/lib/PostgreSQL/IRoleObjectCheck.mjs +2 -0
  312. package/dist/private/lib/PostgreSQL/IRolePlan.d.mts +7 -0
  313. package/dist/private/lib/PostgreSQL/IRolePlan.mjs +2 -0
  314. package/dist/private/lib/PostgreSQL/IRoleRow.d.mts +2 -0
  315. package/dist/private/lib/PostgreSQL/IRoleRow.mjs +2 -0
  316. package/dist/private/lib/PostgreSQL/ITrackerState.d.mts +10 -0
  317. package/dist/private/lib/PostgreSQL/ITrackerState.mjs +2 -0
  318. package/dist/private/lib/PostgreSQL/ITxHandleState.d.mts +6 -0
  319. package/dist/private/lib/PostgreSQL/ITxHandleState.mjs +2 -0
  320. package/dist/private/lib/PostgreSQL/ITxSettings.d.mts +14 -0
  321. package/dist/private/lib/PostgreSQL/ITxSettings.mjs +2 -0
  322. package/dist/private/lib/PostgreSQL/POSTGRES_STATE_KEY.d.mts +5 -0
  323. package/dist/private/lib/PostgreSQL/POSTGRES_STATE_KEY.mjs +6 -0
  324. package/dist/private/lib/PostgreSQL/POSTGRES_STATE_LAYOUT.d.mts +6 -0
  325. package/dist/private/lib/PostgreSQL/POSTGRES_STATE_LAYOUT.mjs +7 -0
  326. package/dist/private/lib/PostgreSQL/ROLE_ATTRIBUTES.d.mts +2 -0
  327. package/dist/private/lib/PostgreSQL/ROLE_ATTRIBUTES.mjs +9 -0
  328. package/dist/private/lib/PostgreSQL/ROLE_CATALOG_SQL.d.mts +26 -0
  329. package/dist/private/lib/PostgreSQL/ROLE_CATALOG_SQL.mjs +84 -0
  330. package/dist/private/lib/PostgreSQL/ROLE_PRIVILEGES.d.mts +2 -0
  331. package/dist/private/lib/PostgreSQL/ROLE_PRIVILEGES.mjs +7 -0
  332. package/dist/private/lib/PostgreSQL/TX_BEGIN_STATEMENTS.d.mts +7 -0
  333. package/dist/private/lib/PostgreSQL/TX_BEGIN_STATEMENTS.mjs +11 -0
  334. package/dist/private/lib/PostgreSQL/admitLock.d.mts +10 -0
  335. package/dist/private/lib/PostgreSQL/admitLock.mjs +33 -0
  336. package/dist/private/lib/PostgreSQL/assertPoolOptions.d.mts +12 -0
  337. package/dist/private/lib/PostgreSQL/assertPoolOptions.mjs +19 -0
  338. package/dist/private/lib/PostgreSQL/assertVersionGuardInput.d.mts +6 -0
  339. package/dist/private/lib/PostgreSQL/assertVersionGuardInput.mjs +14 -0
  340. package/dist/private/lib/PostgreSQL/catalogFlag.d.mts +2 -0
  341. package/dist/private/lib/PostgreSQL/catalogFlag.mjs +7 -0
  342. package/dist/private/lib/PostgreSQL/catalogRow.d.mts +4 -0
  343. package/dist/private/lib/PostgreSQL/catalogRow.mjs +11 -0
  344. package/dist/private/lib/PostgreSQL/catalogRows.d.mts +8 -0
  345. package/dist/private/lib/PostgreSQL/catalogRows.mjs +12 -0
  346. package/dist/private/lib/PostgreSQL/catalogText.d.mts +2 -0
  347. package/dist/private/lib/PostgreSQL/catalogText.mjs +7 -0
  348. package/dist/private/lib/PostgreSQL/checkRoleOnClient.d.mts +10 -0
  349. package/dist/private/lib/PostgreSQL/checkRoleOnClient.mjs +31 -0
  350. package/dist/private/lib/PostgreSQL/checkedClient.d.mts +8 -0
  351. package/dist/private/lib/PostgreSQL/checkedClient.mjs +22 -0
  352. package/dist/private/lib/PostgreSQL/civilCalendar.d.mts +13 -0
  353. package/dist/private/lib/PostgreSQL/civilCalendar.mjs +48 -0
  354. package/dist/private/lib/PostgreSQL/clockInstant.d.mts +11 -0
  355. package/dist/private/lib/PostgreSQL/clockInstant.mjs +18 -0
  356. package/dist/private/lib/PostgreSQL/clockSlot.d.mts +3 -0
  357. package/dist/private/lib/PostgreSQL/clockSlot.mjs +11 -0
  358. package/dist/private/lib/PostgreSQL/clockStatement.d.mts +6 -0
  359. package/dist/private/lib/PostgreSQL/clockStatement.mjs +22 -0
  360. package/dist/private/lib/PostgreSQL/connectAndCheck.d.mts +8 -0
  361. package/dist/private/lib/PostgreSQL/connectAndCheck.mjs +47 -0
  362. package/dist/private/lib/PostgreSQL/constraintDetails.d.mts +7 -0
  363. package/dist/private/lib/PostgreSQL/constraintDetails.mjs +21 -0
  364. package/dist/private/lib/PostgreSQL/constraintField.d.mts +4 -0
  365. package/dist/private/lib/PostgreSQL/constraintField.mjs +5 -0
  366. package/dist/private/lib/PostgreSQL/errorCodeOf.d.mts +2 -0
  367. package/dist/private/lib/PostgreSQL/errorCodeOf.mjs +7 -0
  368. package/dist/private/lib/PostgreSQL/internalFailure.d.mts +9 -0
  369. package/dist/private/lib/PostgreSQL/internalFailure.mjs +10 -0
  370. package/dist/private/lib/PostgreSQL/isNameList.d.mts +2 -0
  371. package/dist/private/lib/PostgreSQL/isNameList.mjs +6 -0
  372. package/dist/private/lib/PostgreSQL/isOneOf.d.mts +2 -0
  373. package/dist/private/lib/PostgreSQL/isOneOf.mjs +5 -0
  374. package/dist/private/lib/PostgreSQL/isQualifiedName.d.mts +2 -0
  375. package/dist/private/lib/PostgreSQL/isQualifiedName.mjs +7 -0
  376. package/dist/private/lib/PostgreSQL/isRoleName.d.mts +2 -0
  377. package/dist/private/lib/PostgreSQL/isRoleName.mjs +7 -0
  378. package/dist/private/lib/PostgreSQL/lockOrderPlan.d.mts +8 -0
  379. package/dist/private/lib/PostgreSQL/lockOrderPlan.mjs +66 -0
  380. package/dist/private/lib/PostgreSQL/mapTypedError.d.mts +3 -0
  381. package/dist/private/lib/PostgreSQL/mapTypedError.mjs +28 -0
  382. package/dist/private/lib/PostgreSQL/mapViolation.d.mts +3 -0
  383. package/dist/private/lib/PostgreSQL/mapViolation.mjs +32 -0
  384. package/dist/private/lib/PostgreSQL/membershipOutsider.d.mts +7 -0
  385. package/dist/private/lib/PostgreSQL/membershipOutsider.mjs +17 -0
  386. package/dist/private/lib/PostgreSQL/missingColumn.d.mts +9 -0
  387. package/dist/private/lib/PostgreSQL/missingColumn.mjs +15 -0
  388. package/dist/private/lib/PostgreSQL/missingGrant.d.mts +5 -0
  389. package/dist/private/lib/PostgreSQL/missingGrant.mjs +7 -0
  390. package/dist/private/lib/PostgreSQL/missingObject.d.mts +10 -0
  391. package/dist/private/lib/PostgreSQL/missingObject.mjs +14 -0
  392. package/dist/private/lib/PostgreSQL/poolUrlSecrets.d.mts +8 -0
  393. package/dist/private/lib/PostgreSQL/poolUrlSecrets.mjs +41 -0
  394. package/dist/private/lib/PostgreSQL/postgresState.d.mts +7 -0
  395. package/dist/private/lib/PostgreSQL/postgresState.mjs +32 -0
  396. package/dist/private/lib/PostgreSQL/rankCheckOption.d.mts +2 -0
  397. package/dist/private/lib/PostgreSQL/rankCheckOption.mjs +7 -0
  398. package/dist/private/lib/PostgreSQL/readField.d.mts +5 -0
  399. package/dist/private/lib/PostgreSQL/readField.mjs +10 -0
  400. package/dist/private/lib/PostgreSQL/roleCheckOf.d.mts +7 -0
  401. package/dist/private/lib/PostgreSQL/roleCheckOf.mjs +39 -0
  402. package/dist/private/lib/PostgreSQL/roleFailureSubject.d.mts +7 -0
  403. package/dist/private/lib/PostgreSQL/roleFailureSubject.mjs +12 -0
  404. package/dist/private/lib/PostgreSQL/rolePlan.d.mts +7 -0
  405. package/dist/private/lib/PostgreSQL/rolePlan.mjs +26 -0
  406. package/dist/private/lib/PostgreSQL/runRoleChecks.d.mts +17 -0
  407. package/dist/private/lib/PostgreSQL/runRoleChecks.mjs +48 -0
  408. package/dist/private/lib/PostgreSQL/runTxAttempt.d.mts +12 -0
  409. package/dist/private/lib/PostgreSQL/runTxAttempt.mjs +50 -0
  410. package/dist/private/lib/PostgreSQL/runTxBody.d.mts +11 -0
  411. package/dist/private/lib/PostgreSQL/runTxBody.mjs +19 -0
  412. package/dist/private/lib/PostgreSQL/runTxWithRetries.d.mts +10 -0
  413. package/dist/private/lib/PostgreSQL/runTxWithRetries.mjs +31 -0
  414. package/dist/private/lib/PostgreSQL/scrubSecrets.d.mts +2 -0
  415. package/dist/private/lib/PostgreSQL/scrubSecrets.mjs +6 -0
  416. package/dist/private/lib/PostgreSQL/txFailure.d.mts +4 -0
  417. package/dist/private/lib/PostgreSQL/txFailure.mjs +7 -0
  418. package/dist/private/lib/PostgreSQL/txHandle.d.mts +9 -0
  419. package/dist/private/lib/PostgreSQL/txHandle.mjs +26 -0
  420. package/dist/private/lib/PostgreSQL/txSettings.d.mts +7 -0
  421. package/dist/private/lib/PostgreSQL/txSettings.mjs +48 -0
  422. package/dist/private/lib/PostgreSQL/versionText.d.mts +5 -0
  423. package/dist/private/lib/PostgreSQL/versionText.mjs +12 -0
  424. package/dist/private/lib/access/db/abandonUser.mjs +2 -3
  425. package/dist/private/lib/access/db/getResetPwd.mjs +4 -2
  426. package/dist/private/lib/access/db/setEmailHash.mjs +3 -1
  427. package/dist/private/lib/access/db/userData4VerifyEmail.d.mts +1 -1
  428. package/dist/private/lib/access/db/userData4VerifyEmail.mjs +4 -2
  429. package/dist/private/lib/access/handleIfHashBad.mjs +1 -0
  430. package/dist/private/lib/access/pathTools.mjs +2 -5
  431. package/package.json +504 -4
@@ -0,0 +1,10 @@
1
+ import type { IRoleAssertionSubject } from "../../../lib/PostgreSQL/error/IRoleAssertionSubject.mjs";
2
+ import type { ITxClient } from "../../../lib/PostgreSQL/tx/ITxClient.mjs";
3
+ import type { IRoleObjectCheck } from './IRoleObjectCheck.mjs';
4
+ /**
5
+ * The object and the privilege of a check on a schema, a function, or a table, view or sequence, as a subject, unless
6
+ * the answer is exactly one row whose `held` is the boolean `true`. A missing object, a `NULL`, a `false`, a second row
7
+ * and a value that is not a boolean are all a missing grant. A function check passes the schema and the function name as
8
+ * two values; the others pass the object and the privilege.
9
+ */
10
+ export declare function missingObject(client: ITxClient, check: IRoleObjectCheck): Promise<IRoleAssertionSubject | undefined>;
@@ -0,0 +1,14 @@
1
+ import { catalogRows } from './catalogRows.mjs';
2
+ import { ROLE_CATALOG_SQL } from './ROLE_CATALOG_SQL.mjs';
3
+ /**
4
+ * The object and the privilege of a check on a schema, a function, or a table, view or sequence, as a subject, unless
5
+ * the answer is exactly one row whose `held` is the boolean `true`. A missing object, a `NULL`, a `false`, a second row
6
+ * and a value that is not a boolean are all a missing grant. A function check passes the schema and the function name as
7
+ * two values; the others pass the object and the privilege.
8
+ */
9
+ export async function missingObject(client, check) {
10
+ const values = check.kind === 'function' ? check.object.split('.') : [check.object, check.privilege];
11
+ const rows = await catalogRows(client, ROLE_CATALOG_SQL.grant[check.kind], values);
12
+ return rows.length === 1 && rows[0]?.['held'] === true ? undefined : { object: check.object, privilege: check.privilege };
13
+ }
14
+ //# sourceMappingURL=missingObject.mjs.map
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Checks the URL and answers the strings that must never be written out: the URL and its password, raw and
3
+ * percent-decoded, longest first. The order needs no sort: the URL holds the password, and decoding never makes a
4
+ * password longer. The query may hold `sslmode` and `sslrootcert` and nothing else, because node-postgres
5
+ * lets a parameter of the URL replace a setting of the pool (`application_name`, `host`, `user`). A URL that fails is
6
+ * refused with a `DbConnectError` that holds no part of it.
7
+ */
8
+ export declare function poolUrlSecrets(url: string): string[];
@@ -0,0 +1,41 @@
1
+ import { DbConnectError } from "../../../lib/PostgreSQL/error/DbConnectError.mjs";
2
+ /** The only query parameters a pool URL may carry. */
3
+ const ALLOWED_QUERY = ['sslmode', 'sslrootcert'];
4
+ function assertPoolUrl(parsed) {
5
+ if ((parsed.protocol !== 'postgres:' && parsed.protocol !== 'postgresql:') || parsed.hostname === '' || parsed.hash !== '') {
6
+ throw new DbConnectError('URL_INVALID');
7
+ }
8
+ const seen = new Set();
9
+ for (const key of parsed.searchParams.keys()) {
10
+ if (!ALLOWED_QUERY.includes(key) || seen.has(key))
11
+ throw new DbConnectError('URL_INVALID');
12
+ seen.add(key);
13
+ }
14
+ }
15
+ /**
16
+ * Checks the URL and answers the strings that must never be written out: the URL and its password, raw and
17
+ * percent-decoded, longest first. The order needs no sort: the URL holds the password, and decoding never makes a
18
+ * password longer. The query may hold `sslmode` and `sslrootcert` and nothing else, because node-postgres
19
+ * lets a parameter of the URL replace a setting of the pool (`application_name`, `host`, `user`). A URL that fails is
20
+ * refused with a `DbConnectError` that holds no part of it.
21
+ */
22
+ export function poolUrlSecrets(url) {
23
+ let parsed;
24
+ try {
25
+ parsed = new URL(url);
26
+ }
27
+ catch {
28
+ throw new DbConnectError('URL_INVALID');
29
+ }
30
+ assertPoolUrl(parsed);
31
+ const secrets = new Set([url, parsed.password]);
32
+ try {
33
+ secrets.add(decodeURIComponent(parsed.password));
34
+ }
35
+ catch {
36
+ // A password that is not valid percent-encoding is still in the set in its raw form.
37
+ }
38
+ // nosemgrep: ajinabraham.njsscan.crypto.timing_attack_node.node_timing_attack -- drops empty strings; no secret is compared with another value
39
+ return [...secrets].filter((secret) => secret !== '');
40
+ }
41
+ //# sourceMappingURL=poolUrlSecrets.mjs.map
@@ -0,0 +1,7 @@
1
+ import type { IPostgresState } from './IPostgresState.mjs';
2
+ /**
3
+ * The per-transaction state of the PostgreSQL kit, shared by every copy of the package in the process. It is read once,
4
+ * when this module is loaded, so two copies that cannot share it fail at start. The clock and the lock helpers meet
5
+ * through it: `lockTaken` of one copy reaches the clock that `createDbClock` of another copy bound.
6
+ */
7
+ export declare const postgresState: IPostgresState;
@@ -0,0 +1,32 @@
1
+ import { DbStateError } from "../../../lib/PostgreSQL/error/DbStateError.mjs";
2
+ import { POSTGRES_STATE_KEY } from './POSTGRES_STATE_KEY.mjs';
3
+ import { POSTGRES_STATE_LAYOUT } from './POSTGRES_STATE_LAYOUT.mjs';
4
+ /** True for a registry of this layout. The layout is the contract: a registry that carries it is read as one. */
5
+ function isSharedState(found) {
6
+ return typeof found === 'object' && found !== null && Reflect.get(found, 'layout') === POSTGRES_STATE_LAYOUT;
7
+ }
8
+ /** Makes the registry and puts it on `globalThis`, read-only, not enumerable. Throws if the global object refuses it. */
9
+ function installState() {
10
+ const state = Object.freeze({ layout: POSTGRES_STATE_LAYOUT, slots: new WeakMap() });
11
+ Object.defineProperty(globalThis, POSTGRES_STATE_KEY, { value: state, configurable: true });
12
+ return state;
13
+ }
14
+ /**
15
+ * Finds the registry that an earlier copy of the package put on `globalThis` and uses it, or makes it when this is the
16
+ * first copy. A value of another layout (a copy of another layout, or other code) is `DbStateError` `LAYOUT_MISMATCH`.
17
+ */
18
+ function sharedState() {
19
+ const found = Reflect.get(globalThis, POSTGRES_STATE_KEY);
20
+ if (found === undefined)
21
+ return installState();
22
+ if (isSharedState(found))
23
+ return found;
24
+ throw new DbStateError('LAYOUT_MISMATCH');
25
+ }
26
+ /**
27
+ * The per-transaction state of the PostgreSQL kit, shared by every copy of the package in the process. It is read once,
28
+ * when this module is loaded, so two copies that cannot share it fail at start. The clock and the lock helpers meet
29
+ * through it: `lockTaken` of one copy reaches the clock that `createDbClock` of another copy bound.
30
+ */
31
+ export const postgresState = sharedState();
32
+ //# sourceMappingURL=postgresState.mjs.map
@@ -0,0 +1,2 @@
1
+ /** The `rankCheck` option as given, or a `TypeError` when it is neither a boolean nor missing. */
2
+ export declare function rankCheckOption(value: unknown): boolean | undefined;
@@ -0,0 +1,7 @@
1
+ /** The `rankCheck` option as given, or a `TypeError` when it is neither a boolean nor missing. */
2
+ export function rankCheckOption(value) {
3
+ if (value !== undefined && typeof value !== 'boolean')
4
+ throw new TypeError('rankCheck must be a boolean');
5
+ return value;
6
+ }
7
+ //# sourceMappingURL=rankCheckOption.mjs.map
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Reads one property of a value that is an object, or answers `undefined` for anything else (a primitive, `null`).
3
+ * The read is shape-agnostic on purpose: callers check the type of what comes back.
4
+ */
5
+ export declare function readField(value: unknown, key: string): unknown;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Reads one property of a value that is an object, or answers `undefined` for anything else (a primitive, `null`).
3
+ * The read is shape-agnostic on purpose: callers check the type of what comes back.
4
+ */
5
+ export function readField(value, key) {
6
+ if (typeof value !== 'object' || value === null)
7
+ return undefined;
8
+ return Reflect.get(value, key);
9
+ }
10
+ //# sourceMappingURL=readField.mjs.map
@@ -0,0 +1,7 @@
1
+ import type { IRoleCheck } from './IRoleCheck.mjs';
2
+ /**
3
+ * Reads one entry of `expectedGrants` into a check, or answers `undefined` when its shape is wrong: not an object, an
4
+ * object that is neither a plain name (a schema) nor `schema.name`, a privilege the kind of object cannot hold, or
5
+ * `columns` on anything but a table privilege that a column can hold.
6
+ */
7
+ export declare function roleCheckOf(grant: unknown): IRoleCheck | undefined;
@@ -0,0 +1,39 @@
1
+ import { isNameList } from './isNameList.mjs';
2
+ import { isOneOf } from './isOneOf.mjs';
3
+ import { isQualifiedName } from './isQualifiedName.mjs';
4
+ import { isRoleName } from './isRoleName.mjs';
5
+ import { ROLE_PRIVILEGES } from './ROLE_PRIVILEGES.mjs';
6
+ /** A grant on a schema: `USAGE` or `CREATE`, and no column list. */
7
+ function schemaCheck(object, privilege, columns) {
8
+ return columns === undefined && isOneOf(ROLE_PRIVILEGES.schema, privilege) ? { kind: 'schema', object, privilege } : undefined;
9
+ }
10
+ /** A column-level grant: a privilege a column can hold, on a non-empty list of plain column names. */
11
+ function columnCheck(object, privilege, columns) {
12
+ if (!isOneOf(ROLE_PRIVILEGES.column, privilege))
13
+ return undefined;
14
+ if (!isNameList(columns) || columns.length === 0)
15
+ return undefined;
16
+ return { kind: 'columns', object, privilege, columns };
17
+ }
18
+ /** A grant on `schema.name`: `EXECUTE` on a function, a column-level privilege on a table, or a table or sequence privilege. */
19
+ function qualifiedCheck(object, privilege, columns) {
20
+ if (privilege === 'EXECUTE')
21
+ return columns === undefined ? { kind: 'function', object, privilege } : undefined;
22
+ if (columns !== undefined)
23
+ return columnCheck(object, privilege, columns);
24
+ return isOneOf(ROLE_PRIVILEGES.relation, privilege) ? { kind: 'relation', object, privilege } : undefined;
25
+ }
26
+ /**
27
+ * Reads one entry of `expectedGrants` into a check, or answers `undefined` when its shape is wrong: not an object, an
28
+ * object that is neither a plain name (a schema) nor `schema.name`, a privilege the kind of object cannot hold, or
29
+ * `columns` on anything but a table privilege that a column can hold.
30
+ */
31
+ export function roleCheckOf(grant) {
32
+ if (typeof grant !== 'object' || grant === null)
33
+ return undefined;
34
+ const { object, privilege, columns } = grant;
35
+ if (isRoleName(object))
36
+ return schemaCheck(object, privilege, columns);
37
+ return isQualifiedName(object) ? qualifiedCheck(object, privilege, columns) : undefined;
38
+ }
39
+ //# sourceMappingURL=roleCheckOf.mjs.map
@@ -0,0 +1,7 @@
1
+ import type { IRoleAssertionSubject } from "../../../lib/PostgreSQL/error/IRoleAssertionSubject.mjs";
2
+ /**
3
+ * What a failure that is not an assertion contributes to the `CHECK_FAILED` error: the closed reason of a refused
4
+ * connection, or the driver's own `code` when it is a string, as the `code` of the subject; an empty subject for
5
+ * anything else. `RoleAssertionError` keeps the code only if it is short and made of letters, digits and underscores.
6
+ */
7
+ export declare function roleFailureSubject(error: unknown): IRoleAssertionSubject;
@@ -0,0 +1,12 @@
1
+ import { DbConnectError } from "../../../lib/PostgreSQL/error/DbConnectError.mjs";
2
+ import { readField } from './readField.mjs';
3
+ /**
4
+ * What a failure that is not an assertion contributes to the `CHECK_FAILED` error: the closed reason of a refused
5
+ * connection, or the driver's own `code` when it is a string, as the `code` of the subject; an empty subject for
6
+ * anything else. `RoleAssertionError` keeps the code only if it is short and made of letters, digits and underscores.
7
+ */
8
+ export function roleFailureSubject(error) {
9
+ const code = error instanceof DbConnectError ? error.reason : readField(error, 'code');
10
+ return typeof code === 'string' ? { code } : {};
11
+ }
12
+ //# sourceMappingURL=roleFailureSubject.mjs.map
@@ -0,0 +1,7 @@
1
+ import type { IRolePlan } from './IRolePlan.mjs';
2
+ /**
3
+ * Reads the options of `assertRole` into a plan, or throws `INVALID_EXPECTATION`. Nothing here touches the pool. A
4
+ * caller from plain JavaScript may pass anything, so every field is checked as it is read. The error is given the role
5
+ * as it came: `RoleAssertionError` prints a role that is not a plain name as `?`.
6
+ */
7
+ export declare function rolePlan(options: unknown): IRolePlan;
@@ -0,0 +1,26 @@
1
+ import { RoleAssertionError } from "../../../lib/PostgreSQL/error/RoleAssertionError.mjs";
2
+ import { isNameList } from './isNameList.mjs';
3
+ import { isRoleName } from './isRoleName.mjs';
4
+ import { roleCheckOf } from './roleCheckOf.mjs';
5
+ /**
6
+ * Reads the options of `assertRole` into a plan, or throws `INVALID_EXPECTATION`. Nothing here touches the pool. A
7
+ * caller from plain JavaScript may pass anything, so every field is checked as it is read. The error is given the role
8
+ * as it came: `RoleAssertionError` prints a role that is not a plain name as `?`.
9
+ */
10
+ export function rolePlan(options) {
11
+ const { expectedRole, expectedGrants, allowedMemberships = [] } = (options ?? {});
12
+ const invalid = () => new RoleAssertionError('INVALID_EXPECTATION', expectedRole);
13
+ if (!isRoleName(expectedRole))
14
+ throw invalid();
15
+ if (!Array.isArray(expectedGrants) || !isNameList(allowedMemberships))
16
+ throw invalid();
17
+ const checks = [];
18
+ for (const grant of expectedGrants) {
19
+ const check = roleCheckOf(grant);
20
+ if (check === undefined)
21
+ throw invalid();
22
+ checks.push(check);
23
+ }
24
+ return { role: expectedRole, allowed: new Set(allowedMemberships), checks };
25
+ }
26
+ //# sourceMappingURL=rolePlan.mjs.map
@@ -0,0 +1,17 @@
1
+ import type { ITxClient } from "../../../lib/PostgreSQL/tx/ITxClient.mjs";
2
+ import type { IRolePlan } from './IRolePlan.mjs';
3
+ /**
4
+ * The checks of `assertRole`, on one connection, in this order. The first failure is thrown as a `RoleAssertionError`
5
+ * and ends the check; nothing after it is asked.
6
+ *
7
+ * 1. `current_user` is the expected role (`ROLE_MISMATCH`).
8
+ * 2. The role has none of the five attributes (`ROLE_SUPERUSER`, `ROLE_CREATEROLE`, `ROLE_CREATEDB`, `ROLE_BYPASSRLS`,
9
+ * `ROLE_REPLICATION`), in that order.
10
+ * 3. The role owns nothing (`ROLE_OWNS_OBJECTS`).
11
+ * 4. The role is a member of no role the call did not allow (`ROLE_MEMBERSHIP`).
12
+ * 5. `session_user` is `current_user` (`SESSION_ROLE_DIFFERS`).
13
+ * 6. Each expected grant is held, in the order of the list (`GRANT_MISSING`).
14
+ *
15
+ * Answers the number of grants checked. A catalog answer that is not what the statements give throws a `TypeError`.
16
+ */
17
+ export declare function runRoleChecks(client: ITxClient, plan: IRolePlan): Promise<number>;
@@ -0,0 +1,48 @@
1
+ import { RoleAssertionError } from "../../../lib/PostgreSQL/error/RoleAssertionError.mjs";
2
+ import { catalogFlag } from './catalogFlag.mjs';
3
+ import { catalogRow } from './catalogRow.mjs';
4
+ import { catalogText } from './catalogText.mjs';
5
+ import { membershipOutsider } from './membershipOutsider.mjs';
6
+ import { missingGrant } from './missingGrant.mjs';
7
+ import { readField } from './readField.mjs';
8
+ import { ROLE_ATTRIBUTES } from './ROLE_ATTRIBUTES.mjs';
9
+ import { ROLE_CATALOG_SQL } from './ROLE_CATALOG_SQL.mjs';
10
+ /**
11
+ * The checks of `assertRole`, on one connection, in this order. The first failure is thrown as a `RoleAssertionError`
12
+ * and ends the check; nothing after it is asked.
13
+ *
14
+ * 1. `current_user` is the expected role (`ROLE_MISMATCH`).
15
+ * 2. The role has none of the five attributes (`ROLE_SUPERUSER`, `ROLE_CREATEROLE`, `ROLE_CREATEDB`, `ROLE_BYPASSRLS`,
16
+ * `ROLE_REPLICATION`), in that order.
17
+ * 3. The role owns nothing (`ROLE_OWNS_OBJECTS`).
18
+ * 4. The role is a member of no role the call did not allow (`ROLE_MEMBERSHIP`).
19
+ * 5. `session_user` is `current_user` (`SESSION_ROLE_DIFFERS`).
20
+ * 6. Each expected grant is held, in the order of the list (`GRANT_MISSING`).
21
+ *
22
+ * Answers the number of grants checked. A catalog answer that is not what the statements give throws a `TypeError`.
23
+ */
24
+ export async function runRoleChecks(client, plan) {
25
+ const fail = (reason, subject) => new RoleAssertionError(reason, plan.role, subject);
26
+ const identity = await catalogRow(client, ROLE_CATALOG_SQL.identity);
27
+ const effective = catalogText(identity['effective_role']);
28
+ if (effective !== plan.role)
29
+ throw fail('ROLE_MISMATCH');
30
+ for (const [key, reason] of ROLE_ATTRIBUTES) {
31
+ if (catalogFlag(readField(identity, key)))
32
+ throw fail(reason);
33
+ }
34
+ if (catalogFlag((await catalogRow(client, ROLE_CATALOG_SQL.ownsObjects))['owns']))
35
+ throw fail('ROLE_OWNS_OBJECTS');
36
+ const outsider = await membershipOutsider(client, plan.allowed);
37
+ if (outsider !== undefined)
38
+ throw fail('ROLE_MEMBERSHIP', { object: outsider });
39
+ if (catalogText(identity['login_role']) !== effective)
40
+ throw fail('SESSION_ROLE_DIFFERS');
41
+ for (const check of plan.checks) {
42
+ const missing = await missingGrant(client, check);
43
+ if (missing !== undefined)
44
+ throw fail('GRANT_MISSING', missing);
45
+ }
46
+ return plan.checks.length;
47
+ }
48
+ //# sourceMappingURL=runRoleChecks.mjs.map
@@ -0,0 +1,12 @@
1
+ import type { ITx } from "../../../lib/PostgreSQL/tx/ITx.mjs";
2
+ import type { ITxPool } from "../../../lib/PostgreSQL/tx/ITxPool.mjs";
3
+ import type { ITxSettings } from './ITxSettings.mjs';
4
+ /**
5
+ * One attempt: a connection, the transaction, `fn`, and the commit or the rollback.
6
+ *
7
+ * The connection gets a listener for its `error` event for as long as it is held, because an event nobody handles ends
8
+ * the process. A connection that emitted one, and one whose rollback failed, is destroyed instead of returned to the
9
+ * pool. A rollback that fails does not hide the error that caused it. A `COMMIT` the server answers with the tag
10
+ * `ROLLBACK` throws the first failed statement of the handle, or `DbTxError` `COMMIT_ROLLED_BACK` when none is known.
11
+ */
12
+ export declare function runTxAttempt<T>(pool: ITxPool, settings: ITxSettings, fn: (tx: ITx) => Promise<T>): Promise<T>;
@@ -0,0 +1,50 @@
1
+ import { sqlstateField } from "../../../lib/PostgreSQL/error/sqlstateField.mjs";
2
+ import { sqlstateOf } from "../../../lib/PostgreSQL/error/sqlstateOf.mjs";
3
+ import { runTxBody } from './runTxBody.mjs';
4
+ /**
5
+ * One attempt: a connection, the transaction, `fn`, and the commit or the rollback.
6
+ *
7
+ * The connection gets a listener for its `error` event for as long as it is held, because an event nobody handles ends
8
+ * the process. A connection that emitted one, and one whose rollback failed, is destroyed instead of returned to the
9
+ * pool. A rollback that fails does not hide the error that caused it. A `COMMIT` the server answers with the tag
10
+ * `ROLLBACK` throws the first failed statement of the handle, or `DbTxError` `COMMIT_ROLLED_BACK` when none is known.
11
+ */
12
+ export async function runTxAttempt(pool, settings, fn) {
13
+ const client = await pool.connect();
14
+ let destroy = false;
15
+ const onClientError = (error) => {
16
+ destroy = true;
17
+ settings.count('db_tx_client_errors_total');
18
+ settings.logger.error('database client error during transaction', {
19
+ reason: 'CLIENT_ERROR',
20
+ ...sqlstateField(sqlstateOf(error))
21
+ });
22
+ };
23
+ client.on('error', onClientError);
24
+ const state = { open: true, failed: false, failure: undefined };
25
+ let result;
26
+ try {
27
+ result = await runTxBody(client, settings, fn, state);
28
+ }
29
+ catch (error) {
30
+ state.open = false;
31
+ try {
32
+ await client.query('ROLLBACK');
33
+ }
34
+ catch (rollbackError) {
35
+ destroy = true;
36
+ settings.count('db_tx_rollback_failures_total');
37
+ settings.logger.error('database transaction rollback failed', {
38
+ reason: 'ROLLBACK_FAILED',
39
+ ...sqlstateField(sqlstateOf(rollbackError))
40
+ });
41
+ }
42
+ throw error;
43
+ }
44
+ finally {
45
+ client.removeListener('error', onClientError);
46
+ client.release(destroy);
47
+ }
48
+ return result;
49
+ }
50
+ //# sourceMappingURL=runTxAttempt.mjs.map
@@ -0,0 +1,11 @@
1
+ import type { ITx } from "../../../lib/PostgreSQL/tx/ITx.mjs";
2
+ import type { ITxClient } from "../../../lib/PostgreSQL/tx/ITxClient.mjs";
3
+ import type { ITxHandleState } from './ITxHandleState.mjs';
4
+ import type { ITxSettings } from './ITxSettings.mjs';
5
+ /**
6
+ * The body of one attempt, from `BEGIN` to the answer of `COMMIT`: the two opening statements, `fn` with its handle,
7
+ * then the commit. The handle is closed before the commit starts. A `COMMIT` the server answers with the tag `ROLLBACK`
8
+ * (what it does for a transaction that a failed statement aborted) throws the first failed statement of the handle, or
9
+ * `DbTxError` `COMMIT_ROLLED_BACK` when none is known. It sends no `ROLLBACK`; the caller does that for any throw.
10
+ */
11
+ export declare function runTxBody<T>(client: ITxClient, settings: ITxSettings, fn: (tx: ITx) => Promise<T>, state: ITxHandleState): Promise<T>;
@@ -0,0 +1,19 @@
1
+ import { DbTxError } from "../../../lib/PostgreSQL/error/DbTxError.mjs";
2
+ import { txHandle } from './txHandle.mjs';
3
+ /**
4
+ * The body of one attempt, from `BEGIN` to the answer of `COMMIT`: the two opening statements, `fn` with its handle,
5
+ * then the commit. The handle is closed before the commit starts. A `COMMIT` the server answers with the tag `ROLLBACK`
6
+ * (what it does for a transaction that a failed statement aborted) throws the first failed statement of the handle, or
7
+ * `DbTxError` `COMMIT_ROLLED_BACK` when none is known. It sends no `ROLLBACK`; the caller does that for any throw.
8
+ */
9
+ export async function runTxBody(client, settings, fn, state) {
10
+ await client.query(settings.begin);
11
+ await client.query(settings.setLockTimeout);
12
+ const result = await fn(txHandle(client, state));
13
+ state.open = false;
14
+ const committed = await client.query('COMMIT');
15
+ if (committed.command === 'ROLLBACK')
16
+ throw state.failed ? state.failure : new DbTxError('COMMIT_ROLLED_BACK');
17
+ return result;
18
+ }
19
+ //# sourceMappingURL=runTxBody.mjs.map
@@ -0,0 +1,10 @@
1
+ import type { ITx } from "../../../lib/PostgreSQL/tx/ITx.mjs";
2
+ import type { ITxPool } from "../../../lib/PostgreSQL/tx/ITxPool.mjs";
3
+ import type { ITxSettings } from './ITxSettings.mjs';
4
+ /**
5
+ * The retry loop of `withTx`, written as a recursion so that it has no exit that cannot be reached. `retries` is the
6
+ * number of retries already made. An attempt that fails with 55P03 ends the loop at once; one that fails with 40001 or
7
+ * 40P01 is run again after the injected delay until `settings.retryMax` retries are spent; any other failure is
8
+ * rethrown unchanged. The recursive call is outside the `try`, so a failure of a later attempt is not classified twice.
9
+ */
10
+ export declare function runTxWithRetries<T>(pool: ITxPool, settings: ITxSettings, fn: (tx: ITx) => Promise<T>, retries: number): Promise<T>;
@@ -0,0 +1,31 @@
1
+ import { sqlstateOf } from "../../../lib/PostgreSQL/error/sqlstateOf.mjs";
2
+ import { runTxAttempt } from './runTxAttempt.mjs';
3
+ import { txFailure } from './txFailure.mjs';
4
+ const SERIALIZATION_FAILURE = '40001';
5
+ const DEADLOCK_DETECTED = '40P01';
6
+ const LOCK_NOT_AVAILABLE = '55P03';
7
+ /**
8
+ * The retry loop of `withTx`, written as a recursion so that it has no exit that cannot be reached. `retries` is the
9
+ * number of retries already made. An attempt that fails with 55P03 ends the loop at once; one that fails with 40001 or
10
+ * 40P01 is run again after the injected delay until `settings.retryMax` retries are spent; any other failure is
11
+ * rethrown unchanged. The recursive call is outside the `try`, so a failure of a later attempt is not classified twice.
12
+ */
13
+ export async function runTxWithRetries(pool, settings, fn, retries) {
14
+ try {
15
+ return await runTxAttempt(pool, settings, fn);
16
+ }
17
+ catch (error) {
18
+ const sqlstate = sqlstateOf(error);
19
+ if (sqlstate === LOCK_NOT_AVAILABLE)
20
+ throw txFailure(settings, 'LOCK_TIMEOUT', sqlstate, retries + 1);
21
+ if (sqlstate !== SERIALIZATION_FAILURE && sqlstate !== DEADLOCK_DETECTED)
22
+ throw error;
23
+ if (retries >= settings.retryMax)
24
+ throw txFailure(settings, 'TX_RETRY_EXHAUSTED', sqlstate, retries + 1);
25
+ settings.count('db_tx_retries_total');
26
+ settings.logger.warn('database transaction retried', { reason: 'TX_RETRY', sqlstate, retry: retries + 1 });
27
+ await settings.retryDelay(retries + 1);
28
+ }
29
+ return runTxWithRetries(pool, settings, fn, retries + 1);
30
+ }
31
+ //# sourceMappingURL=runTxWithRetries.mjs.map
@@ -0,0 +1,2 @@
1
+ /** Replaces every occurrence of a secret in a text with a marker. */
2
+ export declare function scrubSecrets(text: string, secrets: readonly string[]): string;
@@ -0,0 +1,6 @@
1
+ const REDACTED = '[REDACTED]';
2
+ /** Replaces every occurrence of a secret in a text with a marker. */
3
+ export function scrubSecrets(text, secrets) {
4
+ return secrets.reduce((current, secret) => current.split(secret).join(REDACTED), text);
5
+ }
6
+ //# sourceMappingURL=scrubSecrets.mjs.map
@@ -0,0 +1,4 @@
1
+ import type { ITxFailureReason } from "../../../lib/PostgreSQL/tx/ITxFailureReason.mjs";
2
+ import type { ITxSettings } from './ITxSettings.mjs';
3
+ /** Counts and logs a failure that ends the loop, and builds the error the caller gets from the error factory. */
4
+ export declare function txFailure(settings: ITxSettings, reason: ITxFailureReason, sqlstate: string, attempts: number): Error;
@@ -0,0 +1,7 @@
1
+ /** Counts and logs a failure that ends the loop, and builds the error the caller gets from the error factory. */
2
+ export function txFailure(settings, reason, sqlstate, attempts) {
3
+ settings.count(reason === 'LOCK_TIMEOUT' ? 'db_tx_lock_timeouts_total' : 'db_tx_retry_exhausted_total');
4
+ settings.logger.error('database transaction failed', { reason, sqlstate, attempts });
5
+ return settings.errors.internal(reason);
6
+ }
7
+ //# sourceMappingURL=txFailure.mjs.map
@@ -0,0 +1,9 @@
1
+ import type { ITx } from "../../../lib/PostgreSQL/tx/ITx.mjs";
2
+ import type { ITxClient } from "../../../lib/PostgreSQL/tx/ITxClient.mjs";
3
+ import type { ITxHandleState } from './ITxHandleState.mjs';
4
+ /**
5
+ * The handle one attempt gives to the function: a frozen object with the one member `query`. It refuses a statement
6
+ * once `state.open` is false, and it remembers the first statement that failed, so a failure the function swallows is
7
+ * still known at commit.
8
+ */
9
+ export declare function txHandle(client: ITxClient, state: ITxHandleState): ITx;
@@ -0,0 +1,26 @@
1
+ import { DbTxError } from "../../../lib/PostgreSQL/error/DbTxError.mjs";
2
+ /**
3
+ * The handle one attempt gives to the function: a frozen object with the one member `query`. It refuses a statement
4
+ * once `state.open` is false, and it remembers the first statement that failed, so a failure the function swallows is
5
+ * still known at commit.
6
+ */
7
+ export function txHandle(client, state) {
8
+ return Object.freeze({
9
+ async query(text, values) {
10
+ if (!state.open)
11
+ throw new DbTxError('HANDLE_CLOSED');
12
+ try {
13
+ const result = values === undefined ? await client.query(text) : await client.query(text, values);
14
+ return result;
15
+ }
16
+ catch (error) {
17
+ if (!state.failed) {
18
+ state.failed = true;
19
+ state.failure = error;
20
+ }
21
+ throw error;
22
+ }
23
+ }
24
+ });
25
+ }
26
+ //# sourceMappingURL=txHandle.mjs.map
@@ -0,0 +1,7 @@
1
+ import type { ITxOptions } from "../../../lib/PostgreSQL/tx/ITxOptions.mjs";
2
+ import type { ITxSettings } from './ITxSettings.mjs';
3
+ /**
4
+ * Checks the options before anything is checked out and builds the two statements that open a transaction. The checks
5
+ * run in the order isolation, lock timeout, retry count; the first that fails throws a `TypeError`.
6
+ */
7
+ export declare function txSettings(options: ITxOptions): ITxSettings;
@@ -0,0 +1,48 @@
1
+ import { DEFAULT_LOCK_TIMEOUT_MS } from "../../../lib/PostgreSQL/tx/DEFAULT_LOCK_TIMEOUT_MS.mjs";
2
+ import { defaultRetryDelay } from "../../../lib/PostgreSQL/tx/defaultRetryDelay.mjs";
3
+ import { MAX_LOCK_TIMEOUT_MS } from "../../../lib/PostgreSQL/tx/MAX_LOCK_TIMEOUT_MS.mjs";
4
+ import { TX_ISOLATION_LEVELS } from "../../../lib/PostgreSQL/tx/TX_ISOLATION_LEVELS.mjs";
5
+ import { TX_RETRY_MAX } from "../../../lib/PostgreSQL/tx/TX_RETRY_MAX.mjs";
6
+ import { TX_RETRY_MAX_CEILING } from "../../../lib/PostgreSQL/tx/TX_RETRY_MAX_CEILING.mjs";
7
+ import { TX_BEGIN_STATEMENTS } from './TX_BEGIN_STATEMENTS.mjs';
8
+ const isWholeNumberIn = (value, min, max) => Number.isInteger(value) && value >= min && value <= max;
9
+ function beginStatementsOf(isolation) {
10
+ const statements = TX_BEGIN_STATEMENTS.get(isolation ?? 'READ COMMITTED');
11
+ if (statements === undefined)
12
+ throw new TypeError(`isolation must be one of ${TX_ISOLATION_LEVELS.join(', ')}`);
13
+ return statements;
14
+ }
15
+ function lockTimeoutMsOf(value) {
16
+ const lockTimeoutMs = value ?? DEFAULT_LOCK_TIMEOUT_MS;
17
+ if (!isWholeNumberIn(lockTimeoutMs, 1, MAX_LOCK_TIMEOUT_MS)) {
18
+ throw new TypeError(`lockTimeoutMs must be a whole number of milliseconds from 1 to ${String(MAX_LOCK_TIMEOUT_MS)}`);
19
+ }
20
+ return lockTimeoutMs;
21
+ }
22
+ function retryMaxOf(value) {
23
+ const retryMax = value ?? TX_RETRY_MAX;
24
+ if (!isWholeNumberIn(retryMax, 0, TX_RETRY_MAX_CEILING)) {
25
+ throw new TypeError(`retryMax must be a whole number from 0 to ${String(TX_RETRY_MAX_CEILING)}`);
26
+ }
27
+ return retryMax;
28
+ }
29
+ /**
30
+ * Checks the options before anything is checked out and builds the two statements that open a transaction. The checks
31
+ * run in the order isolation, lock timeout, retry count; the first that fails throws a `TypeError`.
32
+ */
33
+ export function txSettings(options) {
34
+ const [readWrite, readOnly] = beginStatementsOf(options.isolation);
35
+ const lockTimeoutMs = lockTimeoutMsOf(options.lockTimeoutMs);
36
+ const retryMax = retryMaxOf(options.retryMax);
37
+ return {
38
+ logger: options.logger,
39
+ errors: options.errors,
40
+ count: options.counter ?? (() => undefined),
41
+ begin: options.readOnly === true ? readOnly : readWrite,
42
+ // The number was checked above to be a whole number in range, so the text holds digits only.
43
+ setLockTimeout: `SET LOCAL lock_timeout = ${String(lockTimeoutMs)}`,
44
+ retryMax,
45
+ retryDelay: options.retryDelay ?? defaultRetryDelay
46
+ };
47
+ }
48
+ //# sourceMappingURL=txSettings.mjs.map
@@ -0,0 +1,5 @@
1
+ /**
2
+ * A version column value as text, or `undefined` when it is no version: a safe integer (`integer` columns arrive as
3
+ * numbers) or a string of 1 to 19 digits (`bigint` columns arrive as decimal strings, which a number cannot hold exactly).
4
+ */
5
+ export declare function versionText(value: unknown): string | undefined;
@@ -0,0 +1,12 @@
1
+ /** A decimal string of up to 19 digits: what the driver hands over for a `bigint` column. */
2
+ const BIGINT_TEXT = /^\d{1,19}$/;
3
+ /**
4
+ * A version column value as text, or `undefined` when it is no version: a safe integer (`integer` columns arrive as
5
+ * numbers) or a string of 1 to 19 digits (`bigint` columns arrive as decimal strings, which a number cannot hold exactly).
6
+ */
7
+ export function versionText(value) {
8
+ if (typeof value === 'number')
9
+ return Number.isSafeInteger(value) ? String(value) : undefined;
10
+ return typeof value === 'string' && BIGINT_TEXT.test(value) ? value : undefined;
11
+ }
12
+ //# sourceMappingURL=versionText.mjs.map
@@ -8,10 +8,9 @@ import { createDeleteUserByEmail } from './deleteUserByEmail.mjs';
8
8
  */
9
9
  export const createAbandonUser = ({ model, paths, mode, deletedValue = true }) => {
10
10
  if (mode === 'keep') {
11
- // Stryker disable next-line BlockStatement: the body is only `return undefined`, and an empty async function body also resolves undefined.
12
- return async function keepUser() {
11
+ return function keepUser() {
13
12
  // Nothing to do: the caller disposes of abandoned registrations themselves.
14
- return undefined;
13
+ return Promise.resolve();
15
14
  };
16
15
  }
17
16
  if (mode === 'soft-delete') {