@axiumine/koa-utils 8.0.0 → 8.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- 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/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/package.json +501 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { catalogRows } from './catalogRows.mjs';
|
|
2
|
+
import { catalogText } from './catalogText.mjs';
|
|
3
|
+
import { ROLE_CATALOG_SQL } from './ROLE_CATALOG_SQL.mjs';
|
|
4
|
+
/**
|
|
5
|
+
* The first role, in name order, that `current_user` is a member of and `allowed` does not list; `undefined` when there
|
|
6
|
+
* is none. The names are sorted here, by code unit, and not by a clause of the statement, so the one that is reported
|
|
7
|
+
* does not depend on the collation of the database.
|
|
8
|
+
*/
|
|
9
|
+
export async function membershipOutsider(client, allowed) {
|
|
10
|
+
const rows = await catalogRows(client, ROLE_CATALOG_SQL.memberships);
|
|
11
|
+
return (rows
|
|
12
|
+
.map((row) => catalogText(row['member_of']))
|
|
13
|
+
// eslint-disable-next-line sonarjs/no-alphabetical-sort -- the default order is by UTF-16 code unit, which is the order wanted; localeCompare would depend on the host locale
|
|
14
|
+
.sort()
|
|
15
|
+
.find((name) => !allowed.has(name)));
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=membershipOutsider.mjs.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { IRoleAssertionSubject } from "../../../lib/PostgreSQL/error/IRoleAssertionSubject.mjs";
|
|
2
|
+
import type { ITxClient } from "../../../lib/PostgreSQL/tx/ITxClient.mjs";
|
|
3
|
+
import type { IRoleColumnCheck } from './IRoleColumnCheck.mjs';
|
|
4
|
+
/**
|
|
5
|
+
* The first column of a column-level check that the role does not hold the privilege on, in the order of the list, named
|
|
6
|
+
* as a subject; `undefined` when it holds all. A column the table does not have is missing too: the statement answers
|
|
7
|
+
* a row only for a column that exists.
|
|
8
|
+
*/
|
|
9
|
+
export declare function missingColumn(client: ITxClient, check: IRoleColumnCheck): Promise<IRoleAssertionSubject | undefined>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { catalogRows } from './catalogRows.mjs';
|
|
2
|
+
import { catalogText } from './catalogText.mjs';
|
|
3
|
+
import { ROLE_CATALOG_SQL } from './ROLE_CATALOG_SQL.mjs';
|
|
4
|
+
/**
|
|
5
|
+
* The first column of a column-level check that the role does not hold the privilege on, in the order of the list, named
|
|
6
|
+
* as a subject; `undefined` when it holds all. A column the table does not have is missing too: the statement answers
|
|
7
|
+
* a row only for a column that exists.
|
|
8
|
+
*/
|
|
9
|
+
export async function missingColumn(client, check) {
|
|
10
|
+
const rows = await catalogRows(client, ROLE_CATALOG_SQL.grant.columns, [check.object, check.privilege, check.columns]);
|
|
11
|
+
const held = new Set(rows.filter((row) => row['held'] === true).map((row) => catalogText(row['name'])));
|
|
12
|
+
const column = check.columns.find((name) => !held.has(name));
|
|
13
|
+
return column === undefined ? undefined : { object: check.object, privilege: check.privilege, column };
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=missingColumn.mjs.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { IRoleAssertionSubject } from "../../../lib/PostgreSQL/error/IRoleAssertionSubject.mjs";
|
|
2
|
+
import type { ITxClient } from "../../../lib/PostgreSQL/tx/ITxClient.mjs";
|
|
3
|
+
import type { IRoleCheck } from './IRoleCheck.mjs';
|
|
4
|
+
/** What `check` finds missing, as a subject naming the object, the privilege and for a column the column; `undefined` when it is held. */
|
|
5
|
+
export declare function missingGrant(client: ITxClient, check: IRoleCheck): Promise<IRoleAssertionSubject | undefined>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { missingColumn } from './missingColumn.mjs';
|
|
2
|
+
import { missingObject } from './missingObject.mjs';
|
|
3
|
+
/** What `check` finds missing, as a subject naming the object, the privilege and for a column the column; `undefined` when it is held. */
|
|
4
|
+
export function missingGrant(client, check) {
|
|
5
|
+
return check.kind === 'columns' ? missingColumn(client, check) : missingObject(client, check);
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=missingGrant.mjs.map
|
|
@@ -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,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,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;
|