@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.
- package/LICENSE +658 -228
- package/README.md +8 -4
- package/dist/dataSources/PostgreSQL.mjs +5 -5
- package/dist/email/SocketLabsLib.d.mts +2 -1
- package/dist/email/SocketLabsLib.mjs +5 -3
- package/dist/files/storeUploadAsTemp.mjs +2 -0
- package/dist/graphQL/schema/mutations/emailChangeHashVerify.mjs +2 -1
- package/dist/graphQL/schema/mutations/logout.mjs +1 -1
- package/dist/graphQL/schema/mutations/resetPwd.mjs +3 -1
- package/dist/koa/middleware/authenticatedAuthorizationHandler/index.d.mts +1 -1
- package/dist/koa/middleware/authenticatedAuthorizationHandler/verifySignedRefreshToken.mjs +12 -9
- package/dist/koa/middleware/authenticatedLogoutHandler/index.d.mts +1 -1
- package/dist/koa/middleware/authenticatedResourceHandler/index.d.mts +1 -1
- package/dist/koa/middleware/debug/index.d.mts +1 -1
- package/dist/lib/ArrayLib.d.mts +0 -1
- package/dist/lib/ArrayLib.mjs +0 -1
- package/dist/lib/DateLib.mjs +1 -1
- package/dist/lib/MariaDB/throwSqlErrors.mjs +3 -1
- package/dist/lib/MongoDB/IMongoDBError.d.mts +2 -3
- package/dist/lib/MongoDB/throwIfMongoErr.mjs +4 -2
- package/dist/lib/NumLib.d.mts +0 -1
- package/dist/lib/NumLib.mjs +1 -1
- package/dist/lib/PostgreSQL/clock/CLOCK_SQL.d.mts +7 -0
- package/dist/lib/PostgreSQL/clock/CLOCK_SQL.mjs +8 -0
- package/dist/lib/PostgreSQL/clock/DB_NOW_SQL.d.mts +5 -0
- package/dist/lib/PostgreSQL/clock/DB_NOW_SQL.mjs +6 -0
- package/dist/lib/PostgreSQL/clock/IClock.d.mts +4 -0
- package/dist/lib/PostgreSQL/clock/IClock.mjs +2 -0
- package/dist/lib/PostgreSQL/clock/IDbClock.d.mts +11 -0
- package/dist/lib/PostgreSQL/clock/IDbClock.mjs +2 -0
- package/dist/lib/PostgreSQL/clock/IDbClockOptions.d.mts +11 -0
- package/dist/lib/PostgreSQL/clock/IDbClockOptions.mjs +2 -0
- package/dist/lib/PostgreSQL/clock/IDbClockSeam.d.mts +10 -0
- package/dist/lib/PostgreSQL/clock/IDbClockSeam.mjs +2 -0
- package/dist/lib/PostgreSQL/clock/createDbClock.d.mts +23 -0
- package/dist/lib/PostgreSQL/clock/createDbClock.mjs +54 -0
- package/dist/lib/PostgreSQL/clock/lockTaken.d.mts +11 -0
- package/dist/lib/PostgreSQL/clock/lockTaken.mjs +17 -0
- package/dist/lib/PostgreSQL/counter/IDbCounter.d.mts +9 -0
- package/dist/lib/PostgreSQL/counter/IDbCounter.mjs +2 -0
- package/dist/lib/PostgreSQL/error/DB_CLOCK_REASONS.d.mts +12 -0
- package/dist/lib/PostgreSQL/error/DB_CLOCK_REASONS.mjs +20 -0
- package/dist/lib/PostgreSQL/error/DB_CONNECT_REASONS.d.mts +11 -0
- package/dist/lib/PostgreSQL/error/DB_CONNECT_REASONS.mjs +12 -0
- package/dist/lib/PostgreSQL/error/DB_INTERNAL_REASONS.d.mts +23 -0
- package/dist/lib/PostgreSQL/error/DB_INTERNAL_REASONS.mjs +35 -0
- package/dist/lib/PostgreSQL/error/DB_PARSE_REASONS.d.mts +13 -0
- package/dist/lib/PostgreSQL/error/DB_PARSE_REASONS.mjs +14 -0
- package/dist/lib/PostgreSQL/error/DB_STATE_REASONS.d.mts +7 -0
- package/dist/lib/PostgreSQL/error/DB_STATE_REASONS.mjs +8 -0
- package/dist/lib/PostgreSQL/error/DB_TX_REASONS.d.mts +9 -0
- package/dist/lib/PostgreSQL/error/DB_TX_REASONS.mjs +10 -0
- package/dist/lib/PostgreSQL/error/DbClockError.d.mts +6 -0
- package/dist/lib/PostgreSQL/error/DbClockError.mjs +27 -0
- package/dist/lib/PostgreSQL/error/DbConnectError.d.mts +11 -0
- package/dist/lib/PostgreSQL/error/DbConnectError.mjs +18 -0
- package/dist/lib/PostgreSQL/error/DbParseError.d.mts +11 -0
- package/dist/lib/PostgreSQL/error/DbParseError.mjs +16 -0
- package/dist/lib/PostgreSQL/error/DbStateError.d.mts +10 -0
- package/dist/lib/PostgreSQL/error/DbStateError.mjs +14 -0
- package/dist/lib/PostgreSQL/error/DbTxError.d.mts +6 -0
- package/dist/lib/PostgreSQL/error/DbTxError.mjs +10 -0
- package/dist/lib/PostgreSQL/error/IConstraintEntry.d.mts +17 -0
- package/dist/lib/PostgreSQL/error/IConstraintEntry.mjs +2 -0
- package/dist/lib/PostgreSQL/error/IConstraintEntryBuilder.d.mts +20 -0
- package/dist/lib/PostgreSQL/error/IConstraintEntryBuilder.mjs +2 -0
- package/dist/lib/PostgreSQL/error/IConstraintTable.d.mts +7 -0
- package/dist/lib/PostgreSQL/error/IConstraintTable.mjs +2 -0
- package/dist/lib/PostgreSQL/error/IDbClockReason.d.mts +3 -0
- package/dist/lib/PostgreSQL/error/IDbClockReason.mjs +2 -0
- package/dist/lib/PostgreSQL/error/IDbConnectReason.d.mts +3 -0
- package/dist/lib/PostgreSQL/error/IDbConnectReason.mjs +2 -0
- package/dist/lib/PostgreSQL/error/IDbErrorCounter.d.mts +4 -0
- package/dist/lib/PostgreSQL/error/IDbErrorCounter.mjs +2 -0
- package/dist/lib/PostgreSQL/error/IDbErrorCounterName.d.mts +7 -0
- package/dist/lib/PostgreSQL/error/IDbErrorCounterName.mjs +2 -0
- package/dist/lib/PostgreSQL/error/IDbErrorFactory.d.mts +16 -0
- package/dist/lib/PostgreSQL/error/IDbErrorFactory.mjs +2 -0
- package/dist/lib/PostgreSQL/error/IDbInternalReason.d.mts +3 -0
- package/dist/lib/PostgreSQL/error/IDbInternalReason.mjs +2 -0
- package/dist/lib/PostgreSQL/error/IDbParseReason.d.mts +3 -0
- package/dist/lib/PostgreSQL/error/IDbParseReason.mjs +2 -0
- package/dist/lib/PostgreSQL/error/IDbStateReason.d.mts +3 -0
- package/dist/lib/PostgreSQL/error/IDbStateReason.mjs +2 -0
- package/dist/lib/PostgreSQL/error/IDbTxReason.d.mts +3 -0
- package/dist/lib/PostgreSQL/error/IDbTxReason.mjs +2 -0
- package/dist/lib/PostgreSQL/error/ILockOrderReason.d.mts +3 -0
- package/dist/lib/PostgreSQL/error/ILockOrderReason.mjs +2 -0
- package/dist/lib/PostgreSQL/error/IMapDbErrorOptions.d.mts +22 -0
- package/dist/lib/PostgreSQL/error/IMapDbErrorOptions.mjs +2 -0
- package/dist/lib/PostgreSQL/error/IRoleAssertionReason.d.mts +3 -0
- package/dist/lib/PostgreSQL/error/IRoleAssertionReason.mjs +2 -0
- package/dist/lib/PostgreSQL/error/IRoleAssertionSubject.d.mts +12 -0
- package/dist/lib/PostgreSQL/error/IRoleAssertionSubject.mjs +2 -0
- package/dist/lib/PostgreSQL/error/LOCK_ORDER_REASONS.d.mts +11 -0
- package/dist/lib/PostgreSQL/error/LOCK_ORDER_REASONS.mjs +12 -0
- package/dist/lib/PostgreSQL/error/LockOrderError.d.mts +6 -0
- package/dist/lib/PostgreSQL/error/LockOrderError.mjs +10 -0
- package/dist/lib/PostgreSQL/error/ROLE_ASSERT_REASONS.d.mts +21 -0
- package/dist/lib/PostgreSQL/error/ROLE_ASSERT_REASONS.mjs +35 -0
- package/dist/lib/PostgreSQL/error/RoleAssertionError.d.mts +19 -0
- package/dist/lib/PostgreSQL/error/RoleAssertionError.mjs +58 -0
- package/dist/lib/PostgreSQL/error/buildConstraintEntry.d.mts +15 -0
- package/dist/lib/PostgreSQL/error/buildConstraintEntry.mjs +16 -0
- package/dist/lib/PostgreSQL/error/constraintNameOf.d.mts +6 -0
- package/dist/lib/PostgreSQL/error/constraintNameOf.mjs +17 -0
- package/dist/lib/PostgreSQL/error/errorNameOf.d.mts +5 -0
- package/dist/lib/PostgreSQL/error/errorNameOf.mjs +12 -0
- package/dist/lib/PostgreSQL/error/lookupConstraint.d.mts +7 -0
- package/dist/lib/PostgreSQL/error/lookupConstraint.mjs +8 -0
- package/dist/lib/PostgreSQL/error/mapDbError.d.mts +28 -0
- package/dist/lib/PostgreSQL/error/mapDbError.mjs +52 -0
- package/dist/lib/PostgreSQL/error/sqlstateField.d.mts +4 -0
- package/dist/lib/PostgreSQL/error/sqlstateField.mjs +5 -0
- package/dist/lib/PostgreSQL/error/sqlstateOf.d.mts +5 -0
- package/dist/lib/PostgreSQL/error/sqlstateOf.mjs +12 -0
- package/dist/lib/PostgreSQL/guard/IAffectedResult.d.mts +4 -0
- package/dist/lib/PostgreSQL/guard/IAffectedResult.mjs +2 -0
- package/dist/lib/PostgreSQL/guard/IGuardCounter.d.mts +3 -0
- package/dist/lib/PostgreSQL/guard/IGuardCounter.mjs +2 -0
- package/dist/lib/PostgreSQL/guard/IVersionGuardCode.d.mts +5 -0
- package/dist/lib/PostgreSQL/guard/IVersionGuardCode.mjs +2 -0
- package/dist/lib/PostgreSQL/guard/IVersionGuardField.d.mts +3 -0
- package/dist/lib/PostgreSQL/guard/IVersionGuardField.mjs +2 -0
- package/dist/lib/PostgreSQL/guard/IVersionGuardInput.d.mts +29 -0
- package/dist/lib/PostgreSQL/guard/IVersionGuardInput.mjs +2 -0
- package/dist/lib/PostgreSQL/guard/VERSION_GUARD_FIELDS.d.mts +2 -0
- package/dist/lib/PostgreSQL/guard/VERSION_GUARD_FIELDS.mjs +3 -0
- package/dist/lib/PostgreSQL/guard/assertAffected.d.mts +10 -0
- package/dist/lib/PostgreSQL/guard/assertAffected.mjs +17 -0
- package/dist/lib/PostgreSQL/guard/guardVersion.d.mts +21 -0
- package/dist/lib/PostgreSQL/guard/guardVersion.mjs +47 -0
- package/dist/lib/PostgreSQL/lock/CLAIM_LIMIT_MAX.d.mts +2 -0
- package/dist/lib/PostgreSQL/lock/CLAIM_LIMIT_MAX.mjs +3 -0
- package/dist/lib/PostgreSQL/lock/IClaimRegistry.d.mts +6 -0
- package/dist/lib/PostgreSQL/lock/IClaimRegistry.mjs +2 -0
- package/dist/lib/PostgreSQL/lock/IClaimRequest.d.mts +7 -0
- package/dist/lib/PostgreSQL/lock/IClaimRequest.mjs +2 -0
- package/dist/lib/PostgreSQL/lock/ILockAdmission.d.mts +4 -0
- package/dist/lib/PostgreSQL/lock/ILockAdmission.mjs +2 -0
- package/dist/lib/PostgreSQL/lock/ILockOrderSpec.d.mts +19 -0
- package/dist/lib/PostgreSQL/lock/ILockOrderSpec.mjs +2 -0
- package/dist/lib/PostgreSQL/lock/ILockOrderTracker.d.mts +41 -0
- package/dist/lib/PostgreSQL/lock/ILockOrderTracker.mjs +2 -0
- package/dist/lib/PostgreSQL/lock/ILockTrackerConfig.d.mts +5 -0
- package/dist/lib/PostgreSQL/lock/ILockTrackerConfig.mjs +2 -0
- package/dist/lib/PostgreSQL/lock/ILockTrackerOptions.d.mts +7 -0
- package/dist/lib/PostgreSQL/lock/ILockTrackerOptions.mjs +2 -0
- package/dist/lib/PostgreSQL/lock/IRowLockMode.d.mts +3 -0
- package/dist/lib/PostgreSQL/lock/IRowLockMode.mjs +2 -0
- package/dist/lib/PostgreSQL/lock/ROW_LOCK_MODES.d.mts +2 -0
- package/dist/lib/PostgreSQL/lock/ROW_LOCK_MODES.mjs +3 -0
- package/dist/lib/PostgreSQL/lock/claimRowsSkipLocked.d.mts +16 -0
- package/dist/lib/PostgreSQL/lock/claimRowsSkipLocked.mjs +32 -0
- package/dist/lib/PostgreSQL/lock/createLockOrderTracker.d.mts +14 -0
- package/dist/lib/PostgreSQL/lock/createLockOrderTracker.mjs +60 -0
- package/dist/lib/PostgreSQL/lock/lockedRow.d.mts +7 -0
- package/dist/lib/PostgreSQL/lock/lockedRow.mjs +12 -0
- package/dist/lib/PostgreSQL/lock/lockedRows.d.mts +3 -0
- package/dist/lib/PostgreSQL/lock/lockedRows.mjs +8 -0
- package/dist/lib/PostgreSQL/lock/rowLockModeOf.d.mts +3 -0
- package/dist/lib/PostgreSQL/lock/rowLockModeOf.mjs +9 -0
- package/dist/lib/PostgreSQL/lock/uuidOf.d.mts +2 -0
- package/dist/lib/PostgreSQL/lock/uuidOf.mjs +10 -0
- package/dist/lib/PostgreSQL/lock/uuidsOf.d.mts +5 -0
- package/dist/lib/PostgreSQL/lock/uuidsOf.mjs +13 -0
- package/dist/lib/PostgreSQL/parse/IArrayParser.d.mts +2 -0
- package/dist/lib/PostgreSQL/parse/IArrayParser.mjs +2 -0
- package/dist/lib/PostgreSQL/parse/IDriverTypes.d.mts +4 -0
- package/dist/lib/PostgreSQL/parse/IDriverTypes.mjs +2 -0
- package/dist/lib/PostgreSQL/parse/IStringParser.d.mts +2 -0
- package/dist/lib/PostgreSQL/parse/IStringParser.mjs +2 -0
- package/dist/lib/PostgreSQL/parse/ITypeParserEntry.d.mts +9 -0
- package/dist/lib/PostgreSQL/parse/ITypeParserEntry.mjs +2 -0
- package/dist/lib/PostgreSQL/parse/TYPE_PARSERS.d.mts +12 -0
- package/dist/lib/PostgreSQL/parse/TYPE_PARSERS.mjs +38 -0
- package/dist/lib/PostgreSQL/parse/arrayOf.d.mts +7 -0
- package/dist/lib/PostgreSQL/parse/arrayOf.mjs +50 -0
- package/dist/lib/PostgreSQL/parse/createTypeRegistry.d.mts +13 -0
- package/dist/lib/PostgreSQL/parse/createTypeRegistry.mjs +26 -0
- package/dist/lib/PostgreSQL/parse/parseDate.d.mts +7 -0
- package/dist/lib/PostgreSQL/parse/parseDate.mjs +19 -0
- package/dist/lib/PostgreSQL/parse/parseInt8.d.mts +6 -0
- package/dist/lib/PostgreSQL/parse/parseInt8.mjs +17 -0
- package/dist/lib/PostgreSQL/parse/parseTime.d.mts +7 -0
- package/dist/lib/PostgreSQL/parse/parseTime.mjs +24 -0
- package/dist/lib/PostgreSQL/parse/parseTimestamptz.d.mts +17 -0
- package/dist/lib/PostgreSQL/parse/parseTimestamptz.mjs +79 -0
- package/dist/lib/PostgreSQL/parse/parseUuid.d.mts +3 -0
- package/dist/lib/PostgreSQL/parse/parseUuid.mjs +9 -0
- package/dist/lib/PostgreSQL/pool/DEFAULT_CONNECT_TIMEOUT_MS.d.mts +2 -0
- package/dist/lib/PostgreSQL/pool/DEFAULT_CONNECT_TIMEOUT_MS.mjs +3 -0
- package/dist/lib/PostgreSQL/pool/DEFAULT_KEEPALIVE_INITIAL_DELAY_MS.d.mts +2 -0
- package/dist/lib/PostgreSQL/pool/DEFAULT_KEEPALIVE_INITIAL_DELAY_MS.mjs +3 -0
- package/dist/lib/PostgreSQL/pool/ICreatePoolOptions.d.mts +28 -0
- package/dist/lib/PostgreSQL/pool/ICreatePoolOptions.mjs +2 -0
- package/dist/lib/PostgreSQL/pool/IDbDriver.d.mts +12 -0
- package/dist/lib/PostgreSQL/pool/IDbDriver.mjs +2 -0
- package/dist/lib/PostgreSQL/pool/IPoolCounter.d.mts +4 -0
- package/dist/lib/PostgreSQL/pool/IPoolCounter.mjs +2 -0
- package/dist/lib/PostgreSQL/pool/IPoolCounterName.d.mts +7 -0
- package/dist/lib/PostgreSQL/pool/IPoolCounterName.mjs +2 -0
- package/dist/lib/PostgreSQL/pool/IPoolEvents.d.mts +4 -0
- package/dist/lib/PostgreSQL/pool/IPoolEvents.mjs +2 -0
- package/dist/lib/PostgreSQL/pool/IPoolLogger.d.mts +8 -0
- package/dist/lib/PostgreSQL/pool/IPoolLogger.mjs +2 -0
- package/dist/lib/PostgreSQL/pool/REQUIRED_SESSION_TIME_ZONE.d.mts +2 -0
- package/dist/lib/PostgreSQL/pool/REQUIRED_SESSION_TIME_ZONE.mjs +3 -0
- package/dist/lib/PostgreSQL/pool/createPool.d.mts +31 -0
- package/dist/lib/PostgreSQL/pool/createPool.mjs +67 -0
- package/dist/lib/PostgreSQL/role/IAssertRoleOptions.d.mts +10 -0
- package/dist/lib/PostgreSQL/role/IAssertRoleOptions.mjs +2 -0
- package/dist/lib/PostgreSQL/role/IRoleAssertion.d.mts +6 -0
- package/dist/lib/PostgreSQL/role/IRoleAssertion.mjs +2 -0
- package/dist/lib/PostgreSQL/role/IRoleGrant.d.mts +19 -0
- package/dist/lib/PostgreSQL/role/IRoleGrant.mjs +2 -0
- package/dist/lib/PostgreSQL/role/IRolePool.d.mts +6 -0
- package/dist/lib/PostgreSQL/role/IRolePool.mjs +2 -0
- package/dist/lib/PostgreSQL/role/assertRole.d.mts +36 -0
- package/dist/lib/PostgreSQL/role/assertRole.mjs +54 -0
- package/dist/lib/PostgreSQL/tx/DEFAULT_LOCK_TIMEOUT_MS.d.mts +2 -0
- package/dist/lib/PostgreSQL/tx/DEFAULT_LOCK_TIMEOUT_MS.mjs +3 -0
- package/dist/lib/PostgreSQL/tx/IRetryDelay.d.mts +2 -0
- package/dist/lib/PostgreSQL/tx/IRetryDelay.mjs +2 -0
- package/dist/lib/PostgreSQL/tx/ITx.d.mts +9 -0
- package/dist/lib/PostgreSQL/tx/ITx.mjs +2 -0
- package/dist/lib/PostgreSQL/tx/ITxClient.d.mts +12 -0
- package/dist/lib/PostgreSQL/tx/ITxClient.mjs +2 -0
- package/dist/lib/PostgreSQL/tx/ITxCounter.d.mts +4 -0
- package/dist/lib/PostgreSQL/tx/ITxCounter.mjs +2 -0
- package/dist/lib/PostgreSQL/tx/ITxCounterName.d.mts +10 -0
- package/dist/lib/PostgreSQL/tx/ITxCounterName.mjs +2 -0
- package/dist/lib/PostgreSQL/tx/ITxFailureReason.d.mts +3 -0
- package/dist/lib/PostgreSQL/tx/ITxFailureReason.mjs +2 -0
- package/dist/lib/PostgreSQL/tx/ITxIsolation.d.mts +3 -0
- package/dist/lib/PostgreSQL/tx/ITxIsolation.mjs +2 -0
- package/dist/lib/PostgreSQL/tx/ITxOptions.d.mts +27 -0
- package/dist/lib/PostgreSQL/tx/ITxOptions.mjs +2 -0
- package/dist/lib/PostgreSQL/tx/ITxPool.d.mts +5 -0
- package/dist/lib/PostgreSQL/tx/ITxPool.mjs +2 -0
- package/dist/lib/PostgreSQL/tx/ITxResult.d.mts +6 -0
- package/dist/lib/PostgreSQL/tx/ITxResult.mjs +2 -0
- package/dist/lib/PostgreSQL/tx/MAX_LOCK_TIMEOUT_MS.d.mts +2 -0
- package/dist/lib/PostgreSQL/tx/MAX_LOCK_TIMEOUT_MS.mjs +3 -0
- package/dist/lib/PostgreSQL/tx/TX_FAILURE_REASONS.d.mts +7 -0
- package/dist/lib/PostgreSQL/tx/TX_FAILURE_REASONS.mjs +8 -0
- package/dist/lib/PostgreSQL/tx/TX_ISOLATION_LEVELS.d.mts +2 -0
- package/dist/lib/PostgreSQL/tx/TX_ISOLATION_LEVELS.mjs +3 -0
- package/dist/lib/PostgreSQL/tx/TX_RETRY_BASE_DELAY_MS.d.mts +2 -0
- package/dist/lib/PostgreSQL/tx/TX_RETRY_BASE_DELAY_MS.mjs +3 -0
- package/dist/lib/PostgreSQL/tx/TX_RETRY_MAX.d.mts +2 -0
- package/dist/lib/PostgreSQL/tx/TX_RETRY_MAX.mjs +3 -0
- package/dist/lib/PostgreSQL/tx/TX_RETRY_MAX_CEILING.d.mts +2 -0
- package/dist/lib/PostgreSQL/tx/TX_RETRY_MAX_CEILING.mjs +3 -0
- package/dist/lib/PostgreSQL/tx/defaultRetryDelay.d.mts +3 -0
- package/dist/lib/PostgreSQL/tx/defaultRetryDelay.mjs +4 -0
- package/dist/lib/PostgreSQL/tx/jitteredDelay.d.mts +7 -0
- package/dist/lib/PostgreSQL/tx/jitteredDelay.mjs +16 -0
- package/dist/lib/PostgreSQL/tx/withTx.d.mts +39 -0
- package/dist/lib/PostgreSQL/tx/withTx.mjs +41 -0
- package/dist/lib/PostgreSQL/url/IDatabaseUrlOptions.d.mts +10 -0
- package/dist/lib/PostgreSQL/url/IDatabaseUrlOptions.mjs +2 -0
- package/dist/lib/PostgreSQL/url/IDatabaseUrlReason.d.mts +14 -0
- package/dist/lib/PostgreSQL/url/IDatabaseUrlReason.mjs +2 -0
- package/dist/lib/PostgreSQL/url/LOOPBACK_HOSTS.d.mts +2 -0
- package/dist/lib/PostgreSQL/url/LOOPBACK_HOSTS.mjs +3 -0
- package/dist/lib/PostgreSQL/url/databaseUrlReason.d.mts +20 -0
- package/dist/lib/PostgreSQL/url/databaseUrlReason.mjs +99 -0
- package/dist/lib/PostgreSQL/url/isAbsolutePath.d.mts +2 -0
- package/dist/lib/PostgreSQL/url/isAbsolutePath.mjs +14 -0
- package/dist/lib/PostgreSQL/url/isValidHost.d.mts +6 -0
- package/dist/lib/PostgreSQL/url/isValidHost.mjs +20 -0
- package/dist/lib/StringLib.d.mts +0 -1
- package/dist/lib/StringLib.mjs +0 -1
- package/dist/lib/db/log/logGraphql.d.mts +8 -6
- package/dist/lib/db/log/logGraphql.mjs +9 -23
- package/dist/lib/db/log/logThrow.d.mts +9 -0
- package/dist/lib/db/log/logThrow.mjs +11 -11
- package/dist/lib/hash.mjs +1 -6
- package/dist/lib/isSessionBlocked.d.mts +1 -1
- package/dist/lib/throwIfNotValidEnumValue.mjs +1 -0
- package/dist/lib/tryCatchRethrow.mjs +5 -3
- package/dist/private/files/reEncode.mjs +2 -0
- package/dist/private/lib/PostgreSQL/ICivilDate.d.mts +6 -0
- package/dist/private/lib/PostgreSQL/ICivilDate.mjs +2 -0
- package/dist/private/lib/PostgreSQL/IClientConstructor.d.mts +3 -0
- package/dist/private/lib/PostgreSQL/IClientConstructor.mjs +2 -0
- package/dist/private/lib/PostgreSQL/IClientShape.d.mts +10 -0
- package/dist/private/lib/PostgreSQL/IClientShape.mjs +2 -0
- package/dist/private/lib/PostgreSQL/IClockSlot.d.mts +11 -0
- package/dist/private/lib/PostgreSQL/IClockSlot.mjs +2 -0
- package/dist/private/lib/PostgreSQL/IConnectCallback.d.mts +2 -0
- package/dist/private/lib/PostgreSQL/IConnectCallback.mjs +2 -0
- package/dist/private/lib/PostgreSQL/IConnectSettings.d.mts +8 -0
- package/dist/private/lib/PostgreSQL/IConnectSettings.mjs +2 -0
- package/dist/private/lib/PostgreSQL/IHelperRank.d.mts +5 -0
- package/dist/private/lib/PostgreSQL/IHelperRank.mjs +2 -0
- package/dist/private/lib/PostgreSQL/IInternalSink.d.mts +9 -0
- package/dist/private/lib/PostgreSQL/IInternalSink.mjs +2 -0
- package/dist/private/lib/PostgreSQL/ILockOrderPlan.d.mts +8 -0
- package/dist/private/lib/PostgreSQL/ILockOrderPlan.mjs +2 -0
- package/dist/private/lib/PostgreSQL/IModeOrder.d.mts +7 -0
- package/dist/private/lib/PostgreSQL/IModeOrder.mjs +2 -0
- package/dist/private/lib/PostgreSQL/IPostgresState.d.mts +9 -0
- package/dist/private/lib/PostgreSQL/IPostgresState.mjs +2 -0
- package/dist/private/lib/PostgreSQL/IRoleCheck.d.mts +4 -0
- package/dist/private/lib/PostgreSQL/IRoleCheck.mjs +2 -0
- package/dist/private/lib/PostgreSQL/IRoleColumnCheck.d.mts +7 -0
- package/dist/private/lib/PostgreSQL/IRoleColumnCheck.mjs +2 -0
- package/dist/private/lib/PostgreSQL/IRoleObjectCheck.d.mts +6 -0
- package/dist/private/lib/PostgreSQL/IRoleObjectCheck.mjs +2 -0
- package/dist/private/lib/PostgreSQL/IRolePlan.d.mts +7 -0
- package/dist/private/lib/PostgreSQL/IRolePlan.mjs +2 -0
- package/dist/private/lib/PostgreSQL/IRoleRow.d.mts +2 -0
- package/dist/private/lib/PostgreSQL/IRoleRow.mjs +2 -0
- package/dist/private/lib/PostgreSQL/ITrackerState.d.mts +10 -0
- package/dist/private/lib/PostgreSQL/ITrackerState.mjs +2 -0
- package/dist/private/lib/PostgreSQL/ITxHandleState.d.mts +6 -0
- package/dist/private/lib/PostgreSQL/ITxHandleState.mjs +2 -0
- package/dist/private/lib/PostgreSQL/ITxSettings.d.mts +14 -0
- package/dist/private/lib/PostgreSQL/ITxSettings.mjs +2 -0
- package/dist/private/lib/PostgreSQL/POSTGRES_STATE_KEY.d.mts +5 -0
- package/dist/private/lib/PostgreSQL/POSTGRES_STATE_KEY.mjs +6 -0
- package/dist/private/lib/PostgreSQL/POSTGRES_STATE_LAYOUT.d.mts +6 -0
- package/dist/private/lib/PostgreSQL/POSTGRES_STATE_LAYOUT.mjs +7 -0
- package/dist/private/lib/PostgreSQL/ROLE_ATTRIBUTES.d.mts +2 -0
- package/dist/private/lib/PostgreSQL/ROLE_ATTRIBUTES.mjs +9 -0
- package/dist/private/lib/PostgreSQL/ROLE_CATALOG_SQL.d.mts +26 -0
- package/dist/private/lib/PostgreSQL/ROLE_CATALOG_SQL.mjs +84 -0
- package/dist/private/lib/PostgreSQL/ROLE_PRIVILEGES.d.mts +2 -0
- package/dist/private/lib/PostgreSQL/ROLE_PRIVILEGES.mjs +7 -0
- package/dist/private/lib/PostgreSQL/TX_BEGIN_STATEMENTS.d.mts +7 -0
- package/dist/private/lib/PostgreSQL/TX_BEGIN_STATEMENTS.mjs +11 -0
- package/dist/private/lib/PostgreSQL/admitLock.d.mts +10 -0
- package/dist/private/lib/PostgreSQL/admitLock.mjs +33 -0
- package/dist/private/lib/PostgreSQL/assertPoolOptions.d.mts +12 -0
- package/dist/private/lib/PostgreSQL/assertPoolOptions.mjs +19 -0
- package/dist/private/lib/PostgreSQL/assertVersionGuardInput.d.mts +6 -0
- package/dist/private/lib/PostgreSQL/assertVersionGuardInput.mjs +14 -0
- package/dist/private/lib/PostgreSQL/catalogFlag.d.mts +2 -0
- package/dist/private/lib/PostgreSQL/catalogFlag.mjs +7 -0
- package/dist/private/lib/PostgreSQL/catalogRow.d.mts +4 -0
- package/dist/private/lib/PostgreSQL/catalogRow.mjs +11 -0
- package/dist/private/lib/PostgreSQL/catalogRows.d.mts +8 -0
- package/dist/private/lib/PostgreSQL/catalogRows.mjs +12 -0
- package/dist/private/lib/PostgreSQL/catalogText.d.mts +2 -0
- package/dist/private/lib/PostgreSQL/catalogText.mjs +7 -0
- package/dist/private/lib/PostgreSQL/checkRoleOnClient.d.mts +10 -0
- package/dist/private/lib/PostgreSQL/checkRoleOnClient.mjs +31 -0
- package/dist/private/lib/PostgreSQL/checkedClient.d.mts +8 -0
- package/dist/private/lib/PostgreSQL/checkedClient.mjs +22 -0
- package/dist/private/lib/PostgreSQL/civilCalendar.d.mts +13 -0
- package/dist/private/lib/PostgreSQL/civilCalendar.mjs +48 -0
- package/dist/private/lib/PostgreSQL/clockInstant.d.mts +11 -0
- package/dist/private/lib/PostgreSQL/clockInstant.mjs +18 -0
- package/dist/private/lib/PostgreSQL/clockSlot.d.mts +3 -0
- package/dist/private/lib/PostgreSQL/clockSlot.mjs +11 -0
- package/dist/private/lib/PostgreSQL/clockStatement.d.mts +6 -0
- package/dist/private/lib/PostgreSQL/clockStatement.mjs +22 -0
- package/dist/private/lib/PostgreSQL/connectAndCheck.d.mts +8 -0
- package/dist/private/lib/PostgreSQL/connectAndCheck.mjs +47 -0
- package/dist/private/lib/PostgreSQL/constraintDetails.d.mts +7 -0
- package/dist/private/lib/PostgreSQL/constraintDetails.mjs +21 -0
- package/dist/private/lib/PostgreSQL/constraintField.d.mts +4 -0
- package/dist/private/lib/PostgreSQL/constraintField.mjs +5 -0
- package/dist/private/lib/PostgreSQL/errorCodeOf.d.mts +2 -0
- package/dist/private/lib/PostgreSQL/errorCodeOf.mjs +7 -0
- package/dist/private/lib/PostgreSQL/internalFailure.d.mts +9 -0
- package/dist/private/lib/PostgreSQL/internalFailure.mjs +10 -0
- package/dist/private/lib/PostgreSQL/isNameList.d.mts +2 -0
- package/dist/private/lib/PostgreSQL/isNameList.mjs +6 -0
- package/dist/private/lib/PostgreSQL/isOneOf.d.mts +2 -0
- package/dist/private/lib/PostgreSQL/isOneOf.mjs +5 -0
- package/dist/private/lib/PostgreSQL/isQualifiedName.d.mts +2 -0
- package/dist/private/lib/PostgreSQL/isQualifiedName.mjs +7 -0
- package/dist/private/lib/PostgreSQL/isRoleName.d.mts +2 -0
- package/dist/private/lib/PostgreSQL/isRoleName.mjs +7 -0
- package/dist/private/lib/PostgreSQL/lockOrderPlan.d.mts +8 -0
- package/dist/private/lib/PostgreSQL/lockOrderPlan.mjs +66 -0
- package/dist/private/lib/PostgreSQL/mapTypedError.d.mts +3 -0
- package/dist/private/lib/PostgreSQL/mapTypedError.mjs +28 -0
- package/dist/private/lib/PostgreSQL/mapViolation.d.mts +3 -0
- package/dist/private/lib/PostgreSQL/mapViolation.mjs +32 -0
- package/dist/private/lib/PostgreSQL/membershipOutsider.d.mts +7 -0
- package/dist/private/lib/PostgreSQL/membershipOutsider.mjs +17 -0
- package/dist/private/lib/PostgreSQL/missingColumn.d.mts +9 -0
- package/dist/private/lib/PostgreSQL/missingColumn.mjs +15 -0
- package/dist/private/lib/PostgreSQL/missingGrant.d.mts +5 -0
- package/dist/private/lib/PostgreSQL/missingGrant.mjs +7 -0
- package/dist/private/lib/PostgreSQL/missingObject.d.mts +10 -0
- package/dist/private/lib/PostgreSQL/missingObject.mjs +14 -0
- package/dist/private/lib/PostgreSQL/poolUrlSecrets.d.mts +8 -0
- package/dist/private/lib/PostgreSQL/poolUrlSecrets.mjs +41 -0
- package/dist/private/lib/PostgreSQL/postgresState.d.mts +7 -0
- package/dist/private/lib/PostgreSQL/postgresState.mjs +32 -0
- package/dist/private/lib/PostgreSQL/rankCheckOption.d.mts +2 -0
- package/dist/private/lib/PostgreSQL/rankCheckOption.mjs +7 -0
- package/dist/private/lib/PostgreSQL/readField.d.mts +5 -0
- package/dist/private/lib/PostgreSQL/readField.mjs +10 -0
- package/dist/private/lib/PostgreSQL/roleCheckOf.d.mts +7 -0
- package/dist/private/lib/PostgreSQL/roleCheckOf.mjs +39 -0
- package/dist/private/lib/PostgreSQL/roleFailureSubject.d.mts +7 -0
- package/dist/private/lib/PostgreSQL/roleFailureSubject.mjs +12 -0
- package/dist/private/lib/PostgreSQL/rolePlan.d.mts +7 -0
- package/dist/private/lib/PostgreSQL/rolePlan.mjs +26 -0
- package/dist/private/lib/PostgreSQL/runRoleChecks.d.mts +17 -0
- package/dist/private/lib/PostgreSQL/runRoleChecks.mjs +48 -0
- package/dist/private/lib/PostgreSQL/runTxAttempt.d.mts +12 -0
- package/dist/private/lib/PostgreSQL/runTxAttempt.mjs +50 -0
- package/dist/private/lib/PostgreSQL/runTxBody.d.mts +11 -0
- package/dist/private/lib/PostgreSQL/runTxBody.mjs +19 -0
- package/dist/private/lib/PostgreSQL/runTxWithRetries.d.mts +10 -0
- package/dist/private/lib/PostgreSQL/runTxWithRetries.mjs +31 -0
- package/dist/private/lib/PostgreSQL/scrubSecrets.d.mts +2 -0
- package/dist/private/lib/PostgreSQL/scrubSecrets.mjs +6 -0
- package/dist/private/lib/PostgreSQL/txFailure.d.mts +4 -0
- package/dist/private/lib/PostgreSQL/txFailure.mjs +7 -0
- package/dist/private/lib/PostgreSQL/txHandle.d.mts +9 -0
- package/dist/private/lib/PostgreSQL/txHandle.mjs +26 -0
- package/dist/private/lib/PostgreSQL/txSettings.d.mts +7 -0
- package/dist/private/lib/PostgreSQL/txSettings.mjs +48 -0
- package/dist/private/lib/PostgreSQL/versionText.d.mts +5 -0
- package/dist/private/lib/PostgreSQL/versionText.mjs +12 -0
- package/dist/private/lib/access/db/abandonUser.mjs +2 -3
- package/dist/private/lib/access/db/getResetPwd.mjs +4 -2
- package/dist/private/lib/access/db/setEmailHash.mjs +3 -1
- package/dist/private/lib/access/db/userData4VerifyEmail.d.mts +1 -1
- package/dist/private/lib/access/db/userData4VerifyEmail.mjs +4 -2
- package/dist/private/lib/access/handleIfHashBad.mjs +1 -0
- package/dist/private/lib/access/pathTools.mjs +2 -5
- package/package.json +504 -4
package/README.md
CHANGED
|
@@ -8,9 +8,9 @@ TypeScript utility library for Koa + GraphQL backends. Ships authentication midd
|
|
|
8
8
|
- **Module format:** ESM only (`.mjs` + `.d.mts`)
|
|
9
9
|
- **Node:** `^24.14.0 || ^26.13.0` (24 and 26 are the LTS lines; the suite runs on both)
|
|
10
10
|
- **TypeScript:** `6.0`
|
|
11
|
-
- **License:** GPL-3.0-or-later
|
|
11
|
+
- **License:** AGPL-3.0-or-later (versions up to 8.1.0: GPL-3.0-or-later)
|
|
12
12
|
- **Maintainers:** [Giovanni Manzoni](https://www.giovannimanzoni.com) and [Vincenzo Favara](https://github.com/vivi7)
|
|
13
|
-
- **Project:** [Contributing](https://github.com/Axiumine/koa-utils/blob/main/CONTRIBUTING.md) · [Governance](https://github.com/Axiumine/koa-utils/blob/main/GOVERNANCE.md) · [Roadmap](https://github.com/Axiumine/koa-utils/blob/main/ROADMAP.md) · [Security policy](https://github.com/Axiumine/koa-utils/blob/main/SECURITY.md) · [Code of Conduct](https://github.com/Axiumine/koa-utils/blob/main/CODE_OF_CONDUCT.md) · [Changelog](https://github.com/Axiumine/koa-utils/blob/main/CHANGELOG.md)
|
|
13
|
+
- **Project:** [Contributing](https://github.com/Axiumine/koa-utils/blob/main/CONTRIBUTING.md) · [Contributor License Agreement](https://github.com/Axiumine/koa-utils/blob/main/CLA.md) · [Governance](https://github.com/Axiumine/koa-utils/blob/main/GOVERNANCE.md) · [Roadmap](https://github.com/Axiumine/koa-utils/blob/main/ROADMAP.md) · [Security policy](https://github.com/Axiumine/koa-utils/blob/main/SECURITY.md) · [Code of Conduct](https://github.com/Axiumine/koa-utils/blob/main/CODE_OF_CONDUCT.md) · [Changelog](https://github.com/Axiumine/koa-utils/blob/main/CHANGELOG.md)
|
|
14
14
|
|
|
15
15
|
## Install
|
|
16
16
|
|
|
@@ -51,6 +51,8 @@ A subpath that reaches no peer needs nothing installed, not even `koa` (it appea
|
|
|
51
51
|
|
|
52
52
|
`email/createSocketLabsSender` needs only `@socketlabs/email`: it builds a function that sends one mail you composed, with your own `serverId` and `apiKey`, and returns `{ ok: true }` or `{ ok: false, code }` instead of throwing on a rejected send. It reads no environment variable and loads no Sentry, no dotenv and no `graphql`; its four type files (`email/ISocketLabsSenderOptions`, `ISocketLabsMessage`, `ISocketLabsSendResult`, `ISocketLabsClient`) need nothing installed. `email/SocketLabsLib` sends through it and adds the copy, the HTML template, the environment variables and the Sentry report.
|
|
53
53
|
|
|
54
|
+
The PostgreSQL kit under `lib/PostgreSQL/{error,parse,pool,url,counter,tx,guard,role,clock,lock}/` reaches no peer either, `pg` included: `lib/PostgreSQL/pool/createPool` takes the `pg` module you imported as its `driver` argument and talks to it through structural types, so you install `pg` yourself for your own code and the kit never imports it. It holds the pool factory (URL allow-list, `SHOW timezone` must answer `UTC`, one connect deadline, a listener for idle-client errors), `lib/PostgreSQL/tx/withTx` (one transaction wrapper: closed `BEGIN`, `SET LOCAL lock_timeout`, a bounded retry on deadlocks and serialisation failures, and an error factory you pass in), string parsers for `date`, `time`, `timestamptz`, `int8`, `uuid` and arrays of them that never build a `Date`, closed-reason `DbParseError`, `DbConnectError` and `DbTxError`, SQLSTATE readers, `lib/PostgreSQL/error/mapDbError` (turns any driver failure into an error of your own family through a constraint table you pass in, and logs a closed reason, never the driver text), `lib/PostgreSQL/guard/assertAffected` and `guardVersion` (say why an update matched no row), `lib/PostgreSQL/role/assertRole` (a boot check that the connected database role has no dangerous attribute, owns nothing, has no unlisted membership and holds the grants you list, with a closed-reason `RoleAssertionError`), `lib/PostgreSQL/clock/createDbClock` (the server time read once per transaction, which a write transaction may read only after a lock), `lib/PostgreSQL/lock/createLockOrderTracker` (the order of the locks of a transaction from a spec you give, checked before each statement) with the small parts for writing your own lock helpers (the kit exports no lock clause), and `databaseUrlReason`, a strict check for a database URL. See [docs/code/lib-postgres.md](https://github.com/Axiumine/koa-utils/blob/main/docs/code/lib-postgres.md).
|
|
55
|
+
|
|
54
56
|
Two peers do not make a subpath fail when they are missing, because the package loads them only if they are installed:
|
|
55
57
|
|
|
56
58
|
| Peer | Used by | Without it |
|
|
@@ -348,7 +350,7 @@ yarn registry:check # exit 1 if yarn.lock names any other host
|
|
|
348
350
|
## Feedback, contributing and security
|
|
349
351
|
|
|
350
352
|
- **Bugs and feature requests:** open an issue at <https://github.com/Axiumine/koa-utils/issues/new/choose>. Issues are public and searchable.
|
|
351
|
-
- **Contributing code:** fork, branch from `main` and open a pull request; larger changes start with an issue. [CONTRIBUTING.md](https://github.com/Axiumine/koa-utils/blob/main/CONTRIBUTING.md) lists the requirements (tests at 100% coverage, docs in the same change, Conventional Commits,
|
|
353
|
+
- **Contributing code:** fork, branch from `main` and open a pull request; larger changes start with an issue. [CONTRIBUTING.md](https://github.com/Axiumine/koa-utils/blob/main/CONTRIBUTING.md) lists the requirements (tests at 100% coverage, docs in the same change, Conventional Commits, acceptance of the [CLA](https://github.com/Axiumine/koa-utils/blob/main/CLA.md), AGPL-3.0-or-later). How decisions are made is in [GOVERNANCE.md](https://github.com/Axiumine/koa-utils/blob/main/GOVERNANCE.md); the direction is in [ROADMAP.md](https://github.com/Axiumine/koa-utils/blob/main/ROADMAP.md).
|
|
352
354
|
- **Security vulnerabilities:** never in a public issue. Use GitHub private vulnerability reporting or the email in [SECURITY.md](https://github.com/Axiumine/koa-utils/blob/main/SECURITY.md), which also states the supported versions and response times.
|
|
353
355
|
- **Security model and design:** what the library does and does not protect against is in [docs/security.md](https://github.com/Axiumine/koa-utils/blob/main/docs/security.md); the structure is in [docs/architecture.md](https://github.com/Axiumine/koa-utils/blob/main/docs/architecture.md). How to check a release (signed tag, rebuild, attestation) is in [docs/verify-release.md](https://github.com/Axiumine/koa-utils/blob/main/docs/verify-release.md).
|
|
354
356
|
- **Release notes:** [CHANGELOG.md](https://github.com/Axiumine/koa-utils/blob/main/CHANGELOG.md), one entry per release, with a `Security` section whenever a release fixes a vulnerability.
|
|
@@ -359,4 +361,6 @@ yarn registry:check # exit 1 if yarn.lock names any other host
|
|
|
359
361
|
|
|
360
362
|
## License
|
|
361
363
|
|
|
362
|
-
|
|
364
|
+
AGPL-3.0-or-later © Giovanni Manzoni
|
|
365
|
+
|
|
366
|
+
Versions up to 8.1.0 were published under GPL-3.0-or-later and stay available under it. From 9.0.0 the package is under the GNU Affero General Public License: if you modify it and let users interact with your modified version over a network, you must offer them its source, and your own application may count as a combined work that the license covers. Read `LICENSE` against how you use the package before you upgrade. For other licensing terms, write to dev@giovannimanzoni.com.
|
|
@@ -49,7 +49,7 @@ export const PostgreSQLClientConnect = async () => {
|
|
|
49
49
|
pgClient.on('notification', (msg) => {
|
|
50
50
|
console.info('[PostgreSQL Client]', msg.channel);
|
|
51
51
|
console.info('[PostgreSQL Client]', msg.payload);
|
|
52
|
-
Sentry.captureMessage(`[PostgreSQL Client] notification: ${msg}`, {
|
|
52
|
+
Sentry.captureMessage(`[PostgreSQL Client] notification: ${msg.channel}`, {
|
|
53
53
|
level: 'warning',
|
|
54
54
|
extra: {
|
|
55
55
|
channel: msg.channel,
|
|
@@ -61,14 +61,14 @@ export const PostgreSQLClientConnect = async () => {
|
|
|
61
61
|
// https://www.postgresql.org/docs/9.6/static/plpgsql-errors-and-messages.html
|
|
62
62
|
if (!pgClient.listenerCount('notice')) {
|
|
63
63
|
pgClient.on('notice', (msg) => {
|
|
64
|
-
Sentry.captureMessage(`[PostgreSQL Client] notice: ${msg}`, 'warning');
|
|
64
|
+
Sentry.captureMessage(`[PostgreSQL Client] notice: ${msg.message}`, 'warning');
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
67
|
console.info('[PostgreSQL Client] OK: PostgreSQL connection has been established successfully.');
|
|
68
68
|
}
|
|
69
69
|
catch (error) {
|
|
70
70
|
throw {
|
|
71
|
-
message: '[PostgreSQL Client] FAIL: Unable to connect to the database: ' + error,
|
|
71
|
+
message: '[PostgreSQL Client] FAIL: Unable to connect to the database: ' + String(error),
|
|
72
72
|
shutdown: true
|
|
73
73
|
};
|
|
74
74
|
}
|
|
@@ -81,7 +81,7 @@ export const PostgreSQLClientDisconnect = async () => {
|
|
|
81
81
|
}
|
|
82
82
|
catch (error) {
|
|
83
83
|
throw {
|
|
84
|
-
message: '[PostgreSQL Client] FAIL: Unable to close the database connection: ' + error,
|
|
84
|
+
message: '[PostgreSQL Client] FAIL: Unable to close the database connection: ' + String(error),
|
|
85
85
|
shutdown: true
|
|
86
86
|
};
|
|
87
87
|
}
|
|
@@ -103,7 +103,7 @@ export const PostgreSQLPoolDisconnect = async () => {
|
|
|
103
103
|
}
|
|
104
104
|
catch (error) {
|
|
105
105
|
throw {
|
|
106
|
-
message: '[PostgreSQL Pool] FAIL: Unable to close the database connection: ' + error,
|
|
106
|
+
message: '[PostgreSQL Pool] FAIL: Unable to close the database connection: ' + String(error),
|
|
107
107
|
shutdown: true
|
|
108
108
|
};
|
|
109
109
|
}
|
|
@@ -42,7 +42,8 @@ export declare class SocketLabsLib {
|
|
|
42
42
|
*/
|
|
43
43
|
sendEmailVerify(emailTo: string, hash: string, name?: string, linkBase?: string, linkPath?: string): Promise<boolean>;
|
|
44
44
|
/**
|
|
45
|
-
*
|
|
45
|
+
* A timed-out send is reported as failed and is not retried by this class. The client is built with
|
|
46
|
+
* `numberOfRetries: 3`; whether the SDK retries a timeout has not been verified.
|
|
46
47
|
*
|
|
47
48
|
statusCode: ECONNABORTED
|
|
48
49
|
Error in sending the email
|
|
@@ -14,7 +14,6 @@ export class SocketLabsLib {
|
|
|
14
14
|
platformName;
|
|
15
15
|
linkBase;
|
|
16
16
|
emailFrom;
|
|
17
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- @socketlabs/email ships no types (untyped module in src/types/socketlabs-email.d.ts), so the client is untyped
|
|
18
17
|
client;
|
|
19
18
|
// Only so a send can hand the sender its required options; the sender ignores them because `client` is injected
|
|
20
19
|
credentials;
|
|
@@ -25,7 +24,9 @@ export class SocketLabsLib {
|
|
|
25
24
|
/* c8 ignore next -- env fallback '0' covered only when SOCKETLABS_SERVER_ID is unset */
|
|
26
25
|
const serverId = parseInt(process.env['SOCKETLABS_SERVER_ID'] || '0');
|
|
27
26
|
const apiKey = `${process.env['SOCKETLABS_SERVER_APIKEY']}`;
|
|
28
|
-
|
|
27
|
+
// The import is `any` (src/types/socketlabs-email.d.ts): one assertion gives the constructor the shape used here
|
|
28
|
+
const Client = SocketLabsClient;
|
|
29
|
+
this.client = new Client(serverId, apiKey, { requestTimeout: 120, numberOfRetries: 3 });
|
|
29
30
|
this.credentials = { serverId, apiKey };
|
|
30
31
|
this.platformName = `${process.env['PLATFORM_NAME']}`;
|
|
31
32
|
this.linkBase = `${process.env['APP_DOMAIN']}`;
|
|
@@ -104,7 +105,8 @@ export class SocketLabsLib {
|
|
|
104
105
|
}
|
|
105
106
|
*/
|
|
106
107
|
/**
|
|
107
|
-
*
|
|
108
|
+
* A timed-out send is reported as failed and is not retried by this class. The client is built with
|
|
109
|
+
* `numberOfRetries: 3`; whether the SDK retries a timeout has not been verified.
|
|
108
110
|
*
|
|
109
111
|
statusCode: ECONNABORTED
|
|
110
112
|
Error in sending the email
|
|
@@ -16,6 +16,7 @@ export async function storeUploadAsTemp(upload, maxFileSize = MAX_FILE_SIZE) {
|
|
|
16
16
|
// Store the file in the filesystem.
|
|
17
17
|
await new Promise((resolve, reject) => {
|
|
18
18
|
// Create a stream to which the upload will be written.
|
|
19
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- the name is a server-side UUID inside UPLOAD_TEMP_DIRECTORY_URL; only the extension comes from the client, and path.extname never returns a path separator
|
|
19
20
|
const writeStream = createWriteStream(storedFileUrl);
|
|
20
21
|
// Check file size during streaming.
|
|
21
22
|
// Only flags and stops the stream — the rejection is issued from the 'close'
|
|
@@ -34,6 +35,7 @@ export async function storeUploadAsTemp(upload, maxFileSize = MAX_FILE_SIZE) {
|
|
|
34
35
|
// Best-effort cleanup, then reject. Cleanup is fire-and-forget by design: the
|
|
35
36
|
// upload has already failed, and an unlink error must not mask the real cause.
|
|
36
37
|
const removeThenReject = (reason) => {
|
|
38
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- same server-built path as the write stream above
|
|
37
39
|
unlink(storedFileUrl, () => {
|
|
38
40
|
reject(reason);
|
|
39
41
|
});
|
|
@@ -28,7 +28,8 @@ export const createEmailChangeHashVerifyMutation = (deps) => {
|
|
|
28
28
|
const ctx = await loadVerifyContext(deps, mailer, args.email.toLowerCase());
|
|
29
29
|
// if email not found, return (do not tell the user the real problem !)
|
|
30
30
|
if (ctx === null) {
|
|
31
|
-
|
|
31
|
+
// `false` is deliberate, not a missing throw: an error here would tell the caller the address is unknown.
|
|
32
|
+
return false;
|
|
32
33
|
}
|
|
33
34
|
if (safeEqualSecret(args.hash, readPath(ctx.user, deps.paths.hash))) {
|
|
34
35
|
return handleValidHash(ctx);
|
|
@@ -16,7 +16,7 @@ export const logout = {
|
|
|
16
16
|
// comes from authenticatedLogoutHandler, so re-adding the prefix here would delete
|
|
17
17
|
// 'refresh:refresh:<uuid>' — a key that was never written — and leave the session alive
|
|
18
18
|
await redisClient.del(`${process.env['REDIS_KEY']}${buildPrefixedRedisKey('refresh:', ctx.state.user.refreshToken)}`);
|
|
19
|
-
const accessToken = ctx.state.user
|
|
19
|
+
const accessToken = ctx.state.user.accessToken || '';
|
|
20
20
|
if (accessToken !== '') {
|
|
21
21
|
await redisClient.del(`${process.env['REDIS_KEY']}${buildPrefixedRedisKey('access:', accessToken)}`);
|
|
22
22
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable sonarjs/no-redundant-optional -- under exactOptionalPropertyTypes `?: T` rejects an explicit `undefined`, so `| undefined` is what lets a caller pass `{ mailer: maybeMailer }` */
|
|
1
2
|
import { socketLabsResetPwdMailer } from "../../../lib/access/resetPwdMailer.mjs";
|
|
2
3
|
import { checkEmailLen } from "../../../lib/checkEmailLen.mjs";
|
|
3
4
|
import { EMAIL_HASH_LEN } from "../../../lib/Constants.mjs";
|
|
@@ -43,7 +44,7 @@ export const createResetPwdMutation = (deps) => ({
|
|
|
43
44
|
// ok, email exists
|
|
44
45
|
// -> wait 10 minutes from the last password reset request
|
|
45
46
|
// if a password request already exists, read the date in seconds.
|
|
46
|
-
const lastReq = typeof resetPwdVal.resetDateReq !== 'undefined' ? new Date(
|
|
47
|
+
const lastReq = typeof resetPwdVal.resetDateReq !== 'undefined' ? new Date(String(resetPwdVal.resetDateReq)) : null;
|
|
47
48
|
// request already made previously?
|
|
48
49
|
// send a new email with the recovery link only if the last one is at least 10 minutes old
|
|
49
50
|
const nowDt = new Date();
|
|
@@ -92,6 +93,7 @@ export const createResetPwdMutation = (deps) => ({
|
|
|
92
93
|
// SocketLabs accepted the message would kill a link already sitting in the user's inbox.
|
|
93
94
|
const mail = pendingMail;
|
|
94
95
|
if (mail !== null) {
|
|
96
|
+
// eslint-disable-next-line sonarjs/no-try-promise -- the try is for a synchronous throw: `deps.mailer` is consumer code and can throw before it returns a promise, which `.catch()` never sees
|
|
95
97
|
try {
|
|
96
98
|
const mailer = deps.mailer ?? socketLabsResetPwdMailer;
|
|
97
99
|
void mailer.sendEmailReset(uEmail, mail.hash, mail.name).catch((e) => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { IContextRefresh } from "../../../graphQL/schema/context/IContextRefresh.mjs";
|
|
2
2
|
import Keygrip from 'keygrip';
|
|
3
3
|
import { Next } from 'koa';
|
|
4
|
-
export declare const authenticatedAuthorizationHandler: (keys: Keygrip) => (ctx: IContextRefresh, next: Next) => Promise<
|
|
4
|
+
export declare const authenticatedAuthorizationHandler: (keys: Keygrip) => (ctx: IContextRefresh, next: Next) => Promise<unknown>;
|
|
@@ -8,22 +8,25 @@ export function verifySignedRefreshToken(ctx, keys) {
|
|
|
8
8
|
if (cookieHeader === undefined) {
|
|
9
9
|
throw throwPreconditionFailedNoAuthCookie();
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
// Only the two cookies this check needs are read, each into its own variable. Copying every pair into one
|
|
12
|
+
// object under its client-chosen name let the request pick the property written, `constructor` included.
|
|
13
|
+
let refreshToken;
|
|
14
|
+
let signature;
|
|
15
|
+
for (const cookie of cookieHeader.split(';')) {
|
|
13
16
|
const [key, value] = cookie.trim().split('=');
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
if (key === 'refresh_token') {
|
|
18
|
+
refreshToken = value;
|
|
19
|
+
}
|
|
20
|
+
else if (key === 'refresh_token.sig') {
|
|
21
|
+
signature = value;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
17
24
|
/**
|
|
18
25
|
* 'refresh_token=27119032-9043-4a9f-bd4c-9d06fd576290; refresh_token.sig=P1gZO6-49xVEMkiMqkOjJ2Cxaf3mQb18GaflDsjibuv4fFWYIOzcW26didnVJ1aridyY40CFzDtufzI6zI8jkQ'
|
|
19
26
|
*/
|
|
20
|
-
// Stryker disable next-line OptionalChaining: cookies is a local object literal assigned above and never null, so ?. never short-circuits
|
|
21
|
-
const refreshToken = cookies?.refresh_token;
|
|
22
27
|
if (!refreshToken) {
|
|
23
28
|
throw throwRefreshTokenRequired();
|
|
24
29
|
}
|
|
25
|
-
// Stryker disable next-line OptionalChaining: cookies is a local object literal assigned above and never null, so ?. never short-circuits
|
|
26
|
-
const signature = cookies?.['refresh_token.sig'];
|
|
27
30
|
if (!signature) {
|
|
28
31
|
throw throwRefreshTokenSignatureRequired();
|
|
29
32
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { IContextLogout } from "../../../graphQL/schema/context/IContextLogout.mjs";
|
|
2
2
|
import Keygrip from 'keygrip';
|
|
3
3
|
import { Next } from 'koa';
|
|
4
|
-
export declare const authenticatedLogoutHandler: (keys: Keygrip) => (ctx: IContextLogout, next: Next) => Promise<
|
|
4
|
+
export declare const authenticatedLogoutHandler: (keys: Keygrip) => (ctx: IContextLogout, next: Next) => Promise<unknown>;
|
|
@@ -3,4 +3,4 @@ import { Next } from 'koa';
|
|
|
3
3
|
/**
|
|
4
4
|
* Find out access token in Bearer header
|
|
5
5
|
*/
|
|
6
|
-
export declare const authenticatedResourceHandler: () => (ctx: IContextAuthenticatedResource, next: Next) => Promise<
|
|
6
|
+
export declare const authenticatedResourceHandler: () => (ctx: IContextAuthenticatedResource, next: Next) => Promise<unknown>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { IContextRefresh } from "../../../graphQL/schema/context/IContextRefresh.mjs";
|
|
2
2
|
import { Next } from 'koa';
|
|
3
|
-
export declare const debugHandler: () => (ctx: IContextRefresh, next: Next) => Promise<
|
|
3
|
+
export declare const debugHandler: () => (ctx: IContextRefresh, next: Next) => Promise<unknown>;
|
package/dist/lib/ArrayLib.d.mts
CHANGED
package/dist/lib/ArrayLib.mjs
CHANGED
package/dist/lib/DateLib.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-extraneous-class -- public API: consumers import the class and call `DateLib.getDate()`; replacing it with plain functions is a breaking change
|
|
1
2
|
export const DateLib = class DateLib {
|
|
2
|
-
constructor() { }
|
|
3
3
|
static getDate(dateNum) {
|
|
4
4
|
const dateStr = dateNum.toString();
|
|
5
5
|
const year = parseInt(dateStr.substring(0, 4));
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { throwErrorWrongUserInput } from "../../graphQL/throw/throwErrorWrongUserInput.mjs";
|
|
2
2
|
import { throwInternalError } from "../../graphQL/throw/throwInternalError.mjs";
|
|
3
3
|
import { MariaDBErrType } from './MariaDBErrType.mjs';
|
|
4
|
+
// The driver reports `code` as an open string: widening the catalogue entry keeps this a string-to-string comparison.
|
|
5
|
+
const DATA_TOO_LONG = MariaDBErrType.ER_DATA_TOO_LONG;
|
|
4
6
|
export function throwSqlErrors(e) {
|
|
5
|
-
if (e.parent && e.parent.sqlMessage && e.parent.code ===
|
|
7
|
+
if (e.parent && e.parent.sqlMessage && e.parent.code === DATA_TOO_LONG) {
|
|
6
8
|
const err = e.parent.sqlMessage.replace(' column', '');
|
|
7
9
|
// Find the index of the first occurrence of the single quote
|
|
8
10
|
const firstQuoteIndex = err.indexOf("'");
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { MongoDBErrType } from "./MongoDBErrType.mjs";
|
|
2
1
|
export interface IMongoDBError {
|
|
3
2
|
errorResponse?: {
|
|
4
|
-
code:
|
|
3
|
+
code: number;
|
|
5
4
|
};
|
|
6
5
|
parent?: {
|
|
7
6
|
errorResponse?: {
|
|
8
|
-
code:
|
|
7
|
+
code: number;
|
|
9
8
|
};
|
|
10
9
|
};
|
|
11
10
|
message: string;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { MongoDBErrType } from "./MongoDBErrType.mjs";
|
|
2
2
|
import { throwConflictError } from "../../graphQL/throw/throwConflictError.mjs";
|
|
3
3
|
import { throwErrorWrongUserInput } from "../../graphQL/throw/throwErrorWrongUserInput.mjs";
|
|
4
|
+
// The driver reports `code` as an open number: widening the catalogue entry keeps this a number-to-number comparison.
|
|
5
|
+
const DUPLICATE_KEY = MongoDBErrType.DuplicateKeyError;
|
|
4
6
|
export function throwIfMongoErr(e) {
|
|
5
|
-
if ((e.errorResponse && e.errorResponse.code ===
|
|
6
|
-
(e.parent && e.parent.errorResponse && e.parent.errorResponse.code ===
|
|
7
|
+
if ((e.errorResponse && e.errorResponse.code === DUPLICATE_KEY) ||
|
|
8
|
+
(e.parent && e.parent.errorResponse && e.parent.errorResponse.code === DUPLICATE_KEY)) {
|
|
7
9
|
throw throwConflictError();
|
|
8
10
|
}
|
|
9
11
|
else if (e.message.startsWith('[Validator]')) {
|
package/dist/lib/NumLib.d.mts
CHANGED
package/dist/lib/NumLib.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-extraneous-class -- public API: consumers import the class and call `NumLib.parseFloatFixed()`; replacing it with plain functions is a breaking change
|
|
1
2
|
export class NumLib {
|
|
2
|
-
constructor() { }
|
|
3
3
|
/************
|
|
4
4
|
* parseFloat wants '.' as the decimal separator !!
|
|
5
5
|
*
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The statement of a clock: one row, one `bigint` column `ms`. `clock_timestamp()` is the wall clock at the moment the
|
|
3
|
+
* statement runs (unlike `now()` and `transaction_timestamp()`, which stay at the start of the transaction), as epoch
|
|
4
|
+
* milliseconds cut toward zero by `trunc` (a cast to `bigint` would round). `extract(epoch FROM <timestamptz>)` does not
|
|
5
|
+
* depend on the session time zone. It takes no parameter: no time is bound from the process.
|
|
6
|
+
*/
|
|
7
|
+
export declare const CLOCK_SQL = "SELECT trunc(extract(epoch FROM clock_timestamp()) * 1000)::bigint AS ms";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The statement of a clock: one row, one `bigint` column `ms`. `clock_timestamp()` is the wall clock at the moment the
|
|
3
|
+
* statement runs (unlike `now()` and `transaction_timestamp()`, which stay at the start of the transaction), as epoch
|
|
4
|
+
* milliseconds cut toward zero by `trunc` (a cast to `bigint` would round). `extract(epoch FROM <timestamptz>)` does not
|
|
5
|
+
* depend on the session time zone. It takes no parameter: no time is bound from the process.
|
|
6
|
+
*/
|
|
7
|
+
export const CLOCK_SQL = 'SELECT trunc(extract(epoch FROM clock_timestamp()) * 1000)::bigint AS ms';
|
|
8
|
+
//# sourceMappingURL=CLOCK_SQL.mjs.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The database time as a SQL expression of type `timestamptz`, for a statement that decides inside the database (a lease
|
|
3
|
+
* that compares with it, say). It is the expression {@link CLOCK_SQL} reads.
|
|
4
|
+
*/
|
|
5
|
+
export const DB_NOW_SQL = 'clock_timestamp()';
|
|
6
|
+
//# sourceMappingURL=DB_NOW_SQL.mjs.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { IClock } from './IClock.mjs';
|
|
2
|
+
/** The clock of one transaction: the plain port plus the asynchronous read behind it. */
|
|
3
|
+
export interface IDbClock extends IClock {
|
|
4
|
+
/** The instant of the transaction in epoch milliseconds; never touches the database. */
|
|
5
|
+
now(): number;
|
|
6
|
+
/**
|
|
7
|
+
* Reads the instant: the first call in the transaction runs the one statement, every later call and every `now()` has
|
|
8
|
+
* the same value. Concurrent first calls share one statement.
|
|
9
|
+
*/
|
|
10
|
+
read(): Promise<number>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { IDbClockSeam } from './IDbClockSeam.mjs';
|
|
2
|
+
/** What `createDbClock` takes. */
|
|
3
|
+
export interface IDbClockOptions {
|
|
4
|
+
/**
|
|
5
|
+
* True for a transaction that writes: its clock refuses to answer before a lock helper has returned. Required, with no
|
|
6
|
+
* default, so that the choice is made in the code that opens the transaction.
|
|
7
|
+
*/
|
|
8
|
+
readonly write: boolean;
|
|
9
|
+
/** A replacement for the statement (a test build). Default: none, the clock reads `CLOCK_SQL`. */
|
|
10
|
+
readonly seam?: IDbClockSeam | undefined;
|
|
11
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A replacement for the clock statement, for a test build. The statement must answer the same shape as `CLOCK_SQL`: one
|
|
3
|
+
* row, one `bigint` column `ms`, and it takes no parameter. `allowed` is computed by the caller from its own environment
|
|
4
|
+
* and must be exactly `true`; anything else, a missing value included, refuses the seam with `DbClockError`
|
|
5
|
+
* `SEAM_REFUSED`, so a forgotten flag fails closed. The kit reads no environment variable itself.
|
|
6
|
+
*/
|
|
7
|
+
export interface IDbClockSeam {
|
|
8
|
+
readonly statement: string;
|
|
9
|
+
readonly allowed: boolean;
|
|
10
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ITx } from "../tx/ITx.mjs";
|
|
2
|
+
import type { IDbClock } from './IDbClock.mjs';
|
|
3
|
+
import type { IDbClockOptions } from './IDbClockOptions.mjs';
|
|
4
|
+
/**
|
|
5
|
+
* Makes the clock of a transaction: the server time as epoch milliseconds, read from the database once per transaction, so
|
|
6
|
+
* that every comparison in one request uses one instant and no application host clock decides a deadline.
|
|
7
|
+
*
|
|
8
|
+
* `now()` is synchronous and never touches the database: it answers the instant that was read. `read()` is the
|
|
9
|
+
* asynchronous one: the first call runs the one statement (`CLOCK_SQL`, or the statement of the seam), every later call
|
|
10
|
+
* returns the same value, and concurrent first calls share one statement. A read that failed is not retried: its failure
|
|
11
|
+
* is the answer of every later call. The lock helpers call `lockTaken` after the lock they took, which reads for a bound
|
|
12
|
+
* clock, so in a write transaction `now()` is ready as soon as the first lock helper returns.
|
|
13
|
+
*
|
|
14
|
+
* A transaction flagged `write: true` must take a lock before it reads the time, so that the instant it stamps on its rows
|
|
15
|
+
* is later than the commit of every transaction that held the same lock before it. `now()` and `read()` before the first
|
|
16
|
+
* lock helper has returned throw `DbClockError` `WRITE_BEFORE_LOCK`, a defect of the calling code. A read-only
|
|
17
|
+
* transaction has no such guard.
|
|
18
|
+
*
|
|
19
|
+
* Call it once, where the transaction opens (inside `withTx`), before or after the first lock helper. The checks, in
|
|
20
|
+
* order: `TypeError` for a `write` that is not a boolean; the seam (`TypeError` out of its type, `SEAM_REFUSED` when it is
|
|
21
|
+
* not allowed); `ALREADY_BOUND` for a second clock on the same handle. Nothing is sent to the database before the first read.
|
|
22
|
+
*/
|
|
23
|
+
export declare function createDbClock(tx: ITx, options: IDbClockOptions): IDbClock;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { DbClockError } from "../error/DbClockError.mjs";
|
|
2
|
+
import { clockInstant } from "../../../private/lib/PostgreSQL/clockInstant.mjs";
|
|
3
|
+
import { clockSlot } from "../../../private/lib/PostgreSQL/clockSlot.mjs";
|
|
4
|
+
import { clockStatement } from "../../../private/lib/PostgreSQL/clockStatement.mjs";
|
|
5
|
+
/**
|
|
6
|
+
* Makes the clock of a transaction: the server time as epoch milliseconds, read from the database once per transaction, so
|
|
7
|
+
* that every comparison in one request uses one instant and no application host clock decides a deadline.
|
|
8
|
+
*
|
|
9
|
+
* `now()` is synchronous and never touches the database: it answers the instant that was read. `read()` is the
|
|
10
|
+
* asynchronous one: the first call runs the one statement (`CLOCK_SQL`, or the statement of the seam), every later call
|
|
11
|
+
* returns the same value, and concurrent first calls share one statement. A read that failed is not retried: its failure
|
|
12
|
+
* is the answer of every later call. The lock helpers call `lockTaken` after the lock they took, which reads for a bound
|
|
13
|
+
* clock, so in a write transaction `now()` is ready as soon as the first lock helper returns.
|
|
14
|
+
*
|
|
15
|
+
* A transaction flagged `write: true` must take a lock before it reads the time, so that the instant it stamps on its rows
|
|
16
|
+
* is later than the commit of every transaction that held the same lock before it. `now()` and `read()` before the first
|
|
17
|
+
* lock helper has returned throw `DbClockError` `WRITE_BEFORE_LOCK`, a defect of the calling code. A read-only
|
|
18
|
+
* transaction has no such guard.
|
|
19
|
+
*
|
|
20
|
+
* Call it once, where the transaction opens (inside `withTx`), before or after the first lock helper. The checks, in
|
|
21
|
+
* order: `TypeError` for a `write` that is not a boolean; the seam (`TypeError` out of its type, `SEAM_REFUSED` when it is
|
|
22
|
+
* not allowed); `ALREADY_BOUND` for a second clock on the same handle. Nothing is sent to the database before the first read.
|
|
23
|
+
*/
|
|
24
|
+
export function createDbClock(tx, options) {
|
|
25
|
+
const { write } = options;
|
|
26
|
+
if (typeof write !== 'boolean')
|
|
27
|
+
throw new TypeError('write must be a boolean');
|
|
28
|
+
const statement = clockStatement(options.seam);
|
|
29
|
+
const slot = clockSlot(tx);
|
|
30
|
+
if (slot.read !== undefined)
|
|
31
|
+
throw new DbClockError('ALREADY_BOUND');
|
|
32
|
+
const fetchInstant = async () => {
|
|
33
|
+
const { rows } = await tx.query(statement);
|
|
34
|
+
const instant = clockInstant(rows);
|
|
35
|
+
slot.instant = instant;
|
|
36
|
+
return instant;
|
|
37
|
+
};
|
|
38
|
+
const read = () => {
|
|
39
|
+
if (write && !slot.locked)
|
|
40
|
+
return Promise.reject(new DbClockError('WRITE_BEFORE_LOCK'));
|
|
41
|
+
slot.pending ??= fetchInstant();
|
|
42
|
+
return slot.pending;
|
|
43
|
+
};
|
|
44
|
+
slot.read = read;
|
|
45
|
+
return {
|
|
46
|
+
now() {
|
|
47
|
+
if (slot.instant !== undefined)
|
|
48
|
+
return slot.instant;
|
|
49
|
+
throw new DbClockError(write && !slot.locked ? 'WRITE_BEFORE_LOCK' : 'NOT_READ');
|
|
50
|
+
},
|
|
51
|
+
read
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=createDbClock.mjs.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ITx } from "../tx/ITx.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* Called by a lock helper after the statement that took its lock. Records that the transaction holds a lock and, when a
|
|
4
|
+
* clock is bound and has not read yet, reads the instant now: the instant of the request is then the first one taken
|
|
5
|
+
* after the first lock. When no clock is bound the read waits for the caller (`IDbClock.read`), which is allowed because
|
|
6
|
+
* the lock is already taken. A transaction without a clock pays nothing: no statement is added.
|
|
7
|
+
*
|
|
8
|
+
* The state sits in a slot keyed by the transaction handle, held by the process-wide registry, so a retry that gets a
|
|
9
|
+
* fresh handle starts with an empty slot, and a second copy of this package reaches the same slot.
|
|
10
|
+
*/
|
|
11
|
+
export declare function lockTaken(tx: ITx): Promise<void>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { clockSlot } from "../../../private/lib/PostgreSQL/clockSlot.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* Called by a lock helper after the statement that took its lock. Records that the transaction holds a lock and, when a
|
|
4
|
+
* clock is bound and has not read yet, reads the instant now: the instant of the request is then the first one taken
|
|
5
|
+
* after the first lock. When no clock is bound the read waits for the caller (`IDbClock.read`), which is allowed because
|
|
6
|
+
* the lock is already taken. A transaction without a clock pays nothing: no statement is added.
|
|
7
|
+
*
|
|
8
|
+
* The state sits in a slot keyed by the transaction handle, held by the process-wide registry, so a retry that gets a
|
|
9
|
+
* fresh handle starts with an empty slot, and a second copy of this package reaches the same slot.
|
|
10
|
+
*/
|
|
11
|
+
export async function lockTaken(tx) {
|
|
12
|
+
const slot = clockSlot(tx);
|
|
13
|
+
slot.locked = true;
|
|
14
|
+
if (slot.read !== undefined)
|
|
15
|
+
await slot.read();
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=lockTaken.mjs.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one function shape that a caller passes to count an event: called once per event with the name of the counter.
|
|
3
|
+
* The kit keeps no registry and exposes no metrics endpoint; a caller that wants a number passes a function, one that
|
|
4
|
+
* does not passes nothing.
|
|
5
|
+
*
|
|
6
|
+
* Generic over the name so each part of the kit narrows it to the names it emits, and so a counter typed over a wider
|
|
7
|
+
* closed list of names is accepted as it is: `(name: 'a' | 'b') => void` is assignable to `IDbCounter<'a'>`.
|
|
8
|
+
*/
|
|
9
|
+
export type IDbCounter<TName extends string = string> = (name: TName) => void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The closed reasons of a {@link DbClockError}, all defects of the calling code or of the configuration:
|
|
3
|
+
*
|
|
4
|
+
* - `WRITE_BEFORE_LOCK`: `now()` or `read()` in a transaction flagged as a write before a lock helper returned.
|
|
5
|
+
* - `NOT_READ`: `now()` before the instant was read (a read-only transaction that did not await `read()`, or a clock
|
|
6
|
+
* created after the lock helpers ran).
|
|
7
|
+
* - `ALREADY_BOUND`: a second clock for the same transaction.
|
|
8
|
+
* - `SEAM_REFUSED`: the test seam was asked for where the caller said it is not allowed.
|
|
9
|
+
* - `BAD_RESULT`: the statement answered no row, or a value that is not the text of an `int8`.
|
|
10
|
+
* - `UNSAFE_INSTANT`: the instant is outside the range of integers a JavaScript number holds exactly.
|
|
11
|
+
*/
|
|
12
|
+
export declare const DB_CLOCK_REASONS: readonly ["WRITE_BEFORE_LOCK", "NOT_READ", "ALREADY_BOUND", "SEAM_REFUSED", "BAD_RESULT", "UNSAFE_INSTANT"];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The closed reasons of a {@link DbClockError}, all defects of the calling code or of the configuration:
|
|
3
|
+
*
|
|
4
|
+
* - `WRITE_BEFORE_LOCK`: `now()` or `read()` in a transaction flagged as a write before a lock helper returned.
|
|
5
|
+
* - `NOT_READ`: `now()` before the instant was read (a read-only transaction that did not await `read()`, or a clock
|
|
6
|
+
* created after the lock helpers ran).
|
|
7
|
+
* - `ALREADY_BOUND`: a second clock for the same transaction.
|
|
8
|
+
* - `SEAM_REFUSED`: the test seam was asked for where the caller said it is not allowed.
|
|
9
|
+
* - `BAD_RESULT`: the statement answered no row, or a value that is not the text of an `int8`.
|
|
10
|
+
* - `UNSAFE_INSTANT`: the instant is outside the range of integers a JavaScript number holds exactly.
|
|
11
|
+
*/
|
|
12
|
+
export const DB_CLOCK_REASONS = [
|
|
13
|
+
'WRITE_BEFORE_LOCK',
|
|
14
|
+
'NOT_READ',
|
|
15
|
+
'ALREADY_BOUND',
|
|
16
|
+
'SEAM_REFUSED',
|
|
17
|
+
'BAD_RESULT',
|
|
18
|
+
'UNSAFE_INSTANT'
|
|
19
|
+
];
|
|
20
|
+
//# sourceMappingURL=DB_CLOCK_REASONS.mjs.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The closed reasons of a connection that the pool refuses (see {@link DbConnectError}):
|
|
3
|
+
*
|
|
4
|
+
* - `URL_INVALID`: the connection string is not a `postgres://` or `postgresql://` URL the pool accepts.
|
|
5
|
+
* - `CONNECT_TIMEOUT`: the connection, the login and the session check did not finish in `connectTimeoutMs`.
|
|
6
|
+
* - `CONNECT_FAILED`: the driver or the server refused (refused connection, name not found, login refused, server
|
|
7
|
+
* shutting down). `code` carries the short driver or SQLSTATE code when there is one.
|
|
8
|
+
* - `TIMEZONE_NOT_UTC`: the session time zone is not `UTC`; the role-level `timezone` setting is missing or was
|
|
9
|
+
* overridden.
|
|
10
|
+
*/
|
|
11
|
+
export declare const DB_CONNECT_REASONS: readonly ["URL_INVALID", "CONNECT_TIMEOUT", "CONNECT_FAILED", "TIMEZONE_NOT_UTC"];
|