@contember/database 2.1.0-alpha.37 → 2.1.0-alpha.39
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/dist/development/index.cjs +104 -0
- package/dist/development/index.cjs.map +1 -0
- package/dist/development/index.js +92 -0
- package/dist/development/index.js.map +1 -0
- package/dist/development/src/Literal.cjs +37 -0
- package/dist/development/src/Literal.cjs.map +1 -0
- package/dist/development/src/Literal.js +37 -0
- package/dist/development/src/Literal.js.map +1 -0
- package/dist/development/src/builders/CaseStatement.cjs +47 -0
- package/dist/development/src/builders/CaseStatement.cjs.map +1 -0
- package/dist/development/src/builders/CaseStatement.js +47 -0
- package/dist/development/src/builders/CaseStatement.js.map +1 -0
- package/dist/development/src/builders/ColumnExpressionFactory.cjs +41 -0
- package/dist/development/src/builders/ColumnExpressionFactory.cjs.map +1 -0
- package/dist/development/src/builders/ColumnExpressionFactory.js +41 -0
- package/dist/development/src/builders/ColumnExpressionFactory.js.map +1 -0
- package/dist/development/src/builders/Compiler.cjs +219 -0
- package/dist/development/src/builders/Compiler.cjs.map +1 -0
- package/dist/development/src/builders/Compiler.js +219 -0
- package/dist/development/src/builders/Compiler.js.map +1 -0
- package/dist/development/src/builders/ConditionBuilder.cjs +167 -0
- package/dist/development/src/builders/ConditionBuilder.cjs.map +1 -0
- package/dist/development/src/builders/ConditionBuilder.js +167 -0
- package/dist/development/src/builders/ConditionBuilder.js.map +1 -0
- package/dist/development/src/builders/ConflictActionType.cjs +9 -0
- package/dist/development/src/builders/ConflictActionType.cjs.map +1 -0
- package/dist/development/src/builders/ConflictActionType.js +9 -0
- package/dist/development/src/builders/ConflictActionType.js.map +1 -0
- package/dist/development/src/builders/DeleteBuilder.cjs +54 -0
- package/dist/development/src/builders/DeleteBuilder.cjs.map +1 -0
- package/dist/development/src/builders/DeleteBuilder.js +54 -0
- package/dist/development/src/builders/DeleteBuilder.js.map +1 -0
- package/dist/development/src/builders/InsertBuilder.cjs +106 -0
- package/dist/development/src/builders/InsertBuilder.cjs.map +1 -0
- package/dist/development/src/builders/InsertBuilder.js +106 -0
- package/dist/development/src/builders/InsertBuilder.js.map +1 -0
- package/dist/development/src/builders/LimitByGroupWrapper.cjs +37 -0
- package/dist/development/src/builders/LimitByGroupWrapper.cjs.map +1 -0
- package/dist/development/src/builders/LimitByGroupWrapper.js +37 -0
- package/dist/development/src/builders/LimitByGroupWrapper.js.map +1 -0
- package/dist/development/src/builders/LockType.cjs +17 -0
- package/dist/development/src/builders/LockType.cjs.map +1 -0
- package/dist/development/src/builders/LockType.js +17 -0
- package/dist/development/src/builders/LockType.js.map +1 -0
- package/dist/development/src/builders/SelectBuilder.cjs +149 -0
- package/dist/development/src/builders/SelectBuilder.cjs.map +1 -0
- package/dist/development/src/builders/SelectBuilder.js +149 -0
- package/dist/development/src/builders/SelectBuilder.js.map +1 -0
- package/dist/development/src/builders/UpdateBuilder.cjs +82 -0
- package/dist/development/src/builders/UpdateBuilder.cjs.map +1 -0
- package/dist/development/src/builders/UpdateBuilder.js +82 -0
- package/dist/development/src/builders/UpdateBuilder.js.map +1 -0
- package/dist/development/src/builders/WindowFunction.cjs +60 -0
- package/dist/development/src/builders/WindowFunction.cjs.map +1 -0
- package/dist/development/src/builders/WindowFunction.js +60 -0
- package/dist/development/src/builders/WindowFunction.js.map +1 -0
- package/dist/development/src/builders/internal/Returning.cjs +34 -0
- package/dist/development/src/builders/internal/Returning.cjs.map +1 -0
- package/dist/development/src/builders/internal/Returning.js +34 -0
- package/dist/development/src/builders/internal/Returning.js.map +1 -0
- package/dist/development/src/builders/internal/Subqueries.cjs +15 -0
- package/dist/development/src/builders/internal/Subqueries.cjs.map +1 -0
- package/dist/development/src/builders/internal/Subqueries.js +15 -0
- package/dist/development/src/builders/internal/Subqueries.js.map +1 -0
- package/dist/development/src/builders/internal/Where.cjs +53 -0
- package/dist/development/src/builders/internal/Where.cjs.map +1 -0
- package/dist/development/src/builders/internal/Where.js +54 -0
- package/dist/development/src/builders/internal/Where.js.map +1 -0
- package/dist/development/src/builders/internal/With.cjs +52 -0
- package/dist/development/src/builders/internal/With.cjs.map +1 -0
- package/dist/development/src/builders/internal/With.js +53 -0
- package/dist/development/src/builders/internal/With.js.map +1 -0
- package/dist/development/src/builders/utils.cjs +35 -0
- package/dist/development/src/builders/utils.cjs.map +1 -0
- package/dist/development/src/builders/utils.js +35 -0
- package/dist/development/src/builders/utils.js.map +1 -0
- package/dist/development/src/client/AcquiredConnection.cjs +91 -0
- package/dist/development/src/client/AcquiredConnection.cjs.map +1 -0
- package/dist/development/src/client/AcquiredConnection.js +91 -0
- package/dist/development/src/client/AcquiredConnection.js.map +1 -0
- package/dist/development/src/client/Client.cjs +87 -0
- package/dist/development/src/client/Client.cjs.map +1 -0
- package/dist/development/src/client/Client.js +87 -0
- package/dist/development/src/client/Client.js.map +1 -0
- package/dist/development/src/client/Connection.cjs +62 -0
- package/dist/development/src/client/Connection.cjs.map +1 -0
- package/dist/development/src/client/Connection.js +62 -0
- package/dist/development/src/client/Connection.js.map +1 -0
- package/dist/development/src/client/EventManager.cjs +36 -0
- package/dist/development/src/client/EventManager.cjs.map +1 -0
- package/dist/development/src/client/EventManager.js +36 -0
- package/dist/development/src/client/EventManager.js.map +1 -0
- package/dist/development/src/client/Pool.cjs +380 -0
- package/dist/development/src/client/Pool.cjs.map +1 -0
- package/dist/development/src/client/Pool.js +380 -0
- package/dist/development/src/client/Pool.js.map +1 -0
- package/dist/development/src/client/Transaction.cjs +148 -0
- package/dist/development/src/client/Transaction.cjs.map +1 -0
- package/dist/development/src/client/Transaction.js +148 -0
- package/dist/development/src/client/Transaction.js.map +1 -0
- package/dist/development/src/client/errorCodes.cjs +266 -0
- package/dist/development/src/client/errorCodes.cjs.map +1 -0
- package/dist/development/src/client/errorCodes.js +266 -0
- package/dist/development/src/client/errorCodes.js.map +1 -0
- package/dist/development/src/client/errors.cjs +68 -0
- package/dist/development/src/client/errors.cjs.map +1 -0
- package/dist/development/src/client/errors.js +68 -0
- package/dist/development/src/client/errors.js.map +1 -0
- package/dist/development/src/exceptions.cjs +6 -0
- package/dist/development/src/exceptions.cjs.map +1 -0
- package/dist/development/src/exceptions.js +6 -0
- package/dist/development/src/exceptions.js.map +1 -0
- package/dist/development/src/metadata/DatabaseMetadata.cjs +18 -0
- package/dist/development/src/metadata/DatabaseMetadata.cjs.map +1 -0
- package/dist/development/src/metadata/DatabaseMetadata.js +18 -0
- package/dist/development/src/metadata/DatabaseMetadata.js.map +1 -0
- package/dist/development/src/metadata/DatabaseMetadataResolver.cjs +103 -0
- package/dist/development/src/metadata/DatabaseMetadataResolver.cjs.map +1 -0
- package/dist/development/src/metadata/DatabaseMetadataResolver.js +103 -0
- package/dist/development/src/metadata/DatabaseMetadataResolver.js.map +1 -0
- package/dist/development/src/metadata/ForeignKeyConstraintMetadata.cjs +56 -0
- package/dist/development/src/metadata/ForeignKeyConstraintMetadata.cjs.map +1 -0
- package/dist/development/src/metadata/ForeignKeyConstraintMetadata.js +56 -0
- package/dist/development/src/metadata/ForeignKeyConstraintMetadata.js.map +1 -0
- package/dist/development/src/metadata/IndexMetadata.cjs +33 -0
- package/dist/development/src/metadata/IndexMetadata.cjs.map +1 -0
- package/dist/development/src/metadata/IndexMetadata.js +33 -0
- package/dist/development/src/metadata/IndexMetadata.js.map +1 -0
- package/dist/development/src/metadata/UniqueConstraintMetadata.cjs +39 -0
- package/dist/development/src/metadata/UniqueConstraintMetadata.cjs.map +1 -0
- package/dist/development/src/metadata/UniqueConstraintMetadata.js +39 -0
- package/dist/development/src/metadata/UniqueConstraintMetadata.js.map +1 -0
- package/dist/development/src/metadata/stringArrayEquals.cjs +12 -0
- package/dist/development/src/metadata/stringArrayEquals.cjs.map +1 -0
- package/dist/development/src/metadata/stringArrayEquals.js +12 -0
- package/dist/development/src/metadata/stringArrayEquals.js.map +1 -0
- package/dist/development/src/queryable/DatabaseQuery.cjs +16 -0
- package/dist/development/src/queryable/DatabaseQuery.cjs.map +1 -0
- package/dist/development/src/queryable/DatabaseQuery.js +16 -0
- package/dist/development/src/queryable/DatabaseQuery.js.map +1 -0
- package/dist/development/src/queryable/DatabaseQueryable.cjs +13 -0
- package/dist/development/src/queryable/DatabaseQueryable.cjs.map +1 -0
- package/dist/development/src/queryable/DatabaseQueryable.js +13 -0
- package/dist/development/src/queryable/DatabaseQueryable.js.map +1 -0
- package/dist/development/src/utils/ConstraintHelper.cjs +44 -0
- package/dist/development/src/utils/ConstraintHelper.cjs.map +1 -0
- package/dist/development/src/utils/ConstraintHelper.js +44 -0
- package/dist/development/src/utils/ConstraintHelper.js.map +1 -0
- package/dist/development/src/utils/Mutex.cjs +49 -0
- package/dist/development/src/utils/Mutex.cjs.map +1 -0
- package/dist/development/src/utils/Mutex.js +49 -0
- package/dist/development/src/utils/Mutex.js.map +1 -0
- package/dist/development/src/utils/assertNever.cjs +7 -0
- package/dist/development/src/utils/assertNever.cjs.map +1 -0
- package/dist/development/src/utils/assertNever.js +7 -0
- package/dist/development/src/utils/assertNever.js.map +1 -0
- package/dist/development/src/utils/asyncIterableTransaction.cjs +26 -0
- package/dist/development/src/utils/asyncIterableTransaction.cjs.map +1 -0
- package/dist/development/src/utils/asyncIterableTransaction.js +26 -0
- package/dist/development/src/utils/asyncIterableTransaction.js.map +1 -0
- package/dist/development/src/utils/createDatabaseIfNotExists.cjs +34 -0
- package/dist/development/src/utils/createDatabaseIfNotExists.cjs.map +1 -0
- package/dist/development/src/utils/createDatabaseIfNotExists.js +34 -0
- package/dist/development/src/utils/createDatabaseIfNotExists.js.map +1 -0
- package/dist/development/src/utils/listen.cjs +118 -0
- package/dist/development/src/utils/listen.cjs.map +1 -0
- package/dist/development/src/utils/listen.js +118 -0
- package/dist/development/src/utils/listen.js.map +1 -0
- package/dist/development/src/utils/pgClientFactory.cjs +13 -0
- package/dist/development/src/utils/pgClientFactory.cjs.map +1 -0
- package/dist/development/src/utils/pgClientFactory.js +13 -0
- package/dist/development/src/utils/pgClientFactory.js.map +1 -0
- package/dist/development/src/utils/retryTransaction.cjs +49 -0
- package/dist/development/src/utils/retryTransaction.cjs.map +1 -0
- package/dist/development/src/utils/retryTransaction.js +49 -0
- package/dist/development/src/utils/retryTransaction.js.map +1 -0
- package/dist/development/src/utils/sql.cjs +30 -0
- package/dist/development/src/utils/sql.cjs.map +1 -0
- package/dist/development/src/utils/sql.js +30 -0
- package/dist/development/src/utils/sql.js.map +1 -0
- package/dist/development/src/utils/withDatabaseAdvisoryLock.cjs +15 -0
- package/dist/development/src/utils/withDatabaseAdvisoryLock.cjs.map +1 -0
- package/dist/development/src/utils/withDatabaseAdvisoryLock.js +15 -0
- package/dist/development/src/utils/withDatabaseAdvisoryLock.js.map +1 -0
- package/dist/production/index.cjs +104 -0
- package/dist/production/index.cjs.map +1 -0
- package/dist/production/index.js +92 -0
- package/dist/production/index.js.map +1 -0
- package/dist/production/src/Literal.cjs +37 -0
- package/dist/production/src/Literal.cjs.map +1 -0
- package/dist/production/src/Literal.js +37 -0
- package/dist/production/src/Literal.js.map +1 -0
- package/dist/production/src/builders/CaseStatement.cjs +47 -0
- package/dist/production/src/builders/CaseStatement.cjs.map +1 -0
- package/dist/production/src/builders/CaseStatement.js +47 -0
- package/dist/production/src/builders/CaseStatement.js.map +1 -0
- package/dist/production/src/builders/ColumnExpressionFactory.cjs +41 -0
- package/dist/production/src/builders/ColumnExpressionFactory.cjs.map +1 -0
- package/dist/production/src/builders/ColumnExpressionFactory.js +41 -0
- package/dist/production/src/builders/ColumnExpressionFactory.js.map +1 -0
- package/dist/production/src/builders/Compiler.cjs +219 -0
- package/dist/production/src/builders/Compiler.cjs.map +1 -0
- package/dist/production/src/builders/Compiler.js +219 -0
- package/dist/production/src/builders/Compiler.js.map +1 -0
- package/dist/production/src/builders/ConditionBuilder.cjs +167 -0
- package/dist/production/src/builders/ConditionBuilder.cjs.map +1 -0
- package/dist/production/src/builders/ConditionBuilder.js +167 -0
- package/dist/production/src/builders/ConditionBuilder.js.map +1 -0
- package/dist/production/src/builders/ConflictActionType.cjs +9 -0
- package/dist/production/src/builders/ConflictActionType.cjs.map +1 -0
- package/dist/production/src/builders/ConflictActionType.js +9 -0
- package/dist/production/src/builders/ConflictActionType.js.map +1 -0
- package/dist/production/src/builders/DeleteBuilder.cjs +54 -0
- package/dist/production/src/builders/DeleteBuilder.cjs.map +1 -0
- package/dist/production/src/builders/DeleteBuilder.js +54 -0
- package/dist/production/src/builders/DeleteBuilder.js.map +1 -0
- package/dist/production/src/builders/InsertBuilder.cjs +106 -0
- package/dist/production/src/builders/InsertBuilder.cjs.map +1 -0
- package/dist/production/src/builders/InsertBuilder.js +106 -0
- package/dist/production/src/builders/InsertBuilder.js.map +1 -0
- package/dist/production/src/builders/LimitByGroupWrapper.cjs +37 -0
- package/dist/production/src/builders/LimitByGroupWrapper.cjs.map +1 -0
- package/dist/production/src/builders/LimitByGroupWrapper.js +37 -0
- package/dist/production/src/builders/LimitByGroupWrapper.js.map +1 -0
- package/dist/production/src/builders/LockType.cjs +17 -0
- package/dist/production/src/builders/LockType.cjs.map +1 -0
- package/dist/production/src/builders/LockType.js +17 -0
- package/dist/production/src/builders/LockType.js.map +1 -0
- package/dist/production/src/builders/SelectBuilder.cjs +149 -0
- package/dist/production/src/builders/SelectBuilder.cjs.map +1 -0
- package/dist/production/src/builders/SelectBuilder.js +149 -0
- package/dist/production/src/builders/SelectBuilder.js.map +1 -0
- package/dist/production/src/builders/UpdateBuilder.cjs +82 -0
- package/dist/production/src/builders/UpdateBuilder.cjs.map +1 -0
- package/dist/production/src/builders/UpdateBuilder.js +82 -0
- package/dist/production/src/builders/UpdateBuilder.js.map +1 -0
- package/dist/production/src/builders/WindowFunction.cjs +60 -0
- package/dist/production/src/builders/WindowFunction.cjs.map +1 -0
- package/dist/production/src/builders/WindowFunction.js +60 -0
- package/dist/production/src/builders/WindowFunction.js.map +1 -0
- package/dist/production/src/builders/internal/Returning.cjs +34 -0
- package/dist/production/src/builders/internal/Returning.cjs.map +1 -0
- package/dist/production/src/builders/internal/Returning.js +34 -0
- package/dist/production/src/builders/internal/Returning.js.map +1 -0
- package/dist/production/src/builders/internal/Subqueries.cjs +15 -0
- package/dist/production/src/builders/internal/Subqueries.cjs.map +1 -0
- package/dist/production/src/builders/internal/Subqueries.js +15 -0
- package/dist/production/src/builders/internal/Subqueries.js.map +1 -0
- package/dist/production/src/builders/internal/Where.cjs +53 -0
- package/dist/production/src/builders/internal/Where.cjs.map +1 -0
- package/dist/production/src/builders/internal/Where.js +54 -0
- package/dist/production/src/builders/internal/Where.js.map +1 -0
- package/dist/production/src/builders/internal/With.cjs +52 -0
- package/dist/production/src/builders/internal/With.cjs.map +1 -0
- package/dist/production/src/builders/internal/With.js +53 -0
- package/dist/production/src/builders/internal/With.js.map +1 -0
- package/dist/production/src/builders/utils.cjs +35 -0
- package/dist/production/src/builders/utils.cjs.map +1 -0
- package/dist/production/src/builders/utils.js +35 -0
- package/dist/production/src/builders/utils.js.map +1 -0
- package/dist/production/src/client/AcquiredConnection.cjs +91 -0
- package/dist/production/src/client/AcquiredConnection.cjs.map +1 -0
- package/dist/production/src/client/AcquiredConnection.js +91 -0
- package/dist/production/src/client/AcquiredConnection.js.map +1 -0
- package/dist/production/src/client/Client.cjs +87 -0
- package/dist/production/src/client/Client.cjs.map +1 -0
- package/dist/production/src/client/Client.js +87 -0
- package/dist/production/src/client/Client.js.map +1 -0
- package/dist/production/src/client/Connection.cjs +62 -0
- package/dist/production/src/client/Connection.cjs.map +1 -0
- package/dist/production/src/client/Connection.js +62 -0
- package/dist/production/src/client/Connection.js.map +1 -0
- package/dist/production/src/client/EventManager.cjs +36 -0
- package/dist/production/src/client/EventManager.cjs.map +1 -0
- package/dist/production/src/client/EventManager.js +36 -0
- package/dist/production/src/client/EventManager.js.map +1 -0
- package/dist/production/src/client/Pool.cjs +380 -0
- package/dist/production/src/client/Pool.cjs.map +1 -0
- package/dist/production/src/client/Pool.js +380 -0
- package/dist/production/src/client/Pool.js.map +1 -0
- package/dist/production/src/client/Transaction.cjs +148 -0
- package/dist/production/src/client/Transaction.cjs.map +1 -0
- package/dist/production/src/client/Transaction.js +148 -0
- package/dist/production/src/client/Transaction.js.map +1 -0
- package/dist/production/src/client/errorCodes.cjs +266 -0
- package/dist/production/src/client/errorCodes.cjs.map +1 -0
- package/dist/production/src/client/errorCodes.js +266 -0
- package/dist/production/src/client/errorCodes.js.map +1 -0
- package/dist/production/src/client/errors.cjs +68 -0
- package/dist/production/src/client/errors.cjs.map +1 -0
- package/dist/production/src/client/errors.js +68 -0
- package/dist/production/src/client/errors.js.map +1 -0
- package/dist/production/src/exceptions.cjs +6 -0
- package/dist/production/src/exceptions.cjs.map +1 -0
- package/dist/production/src/exceptions.js +6 -0
- package/dist/production/src/exceptions.js.map +1 -0
- package/dist/production/src/metadata/DatabaseMetadata.cjs +18 -0
- package/dist/production/src/metadata/DatabaseMetadata.cjs.map +1 -0
- package/dist/production/src/metadata/DatabaseMetadata.js +18 -0
- package/dist/production/src/metadata/DatabaseMetadata.js.map +1 -0
- package/dist/production/src/metadata/DatabaseMetadataResolver.cjs +103 -0
- package/dist/production/src/metadata/DatabaseMetadataResolver.cjs.map +1 -0
- package/dist/production/src/metadata/DatabaseMetadataResolver.js +103 -0
- package/dist/production/src/metadata/DatabaseMetadataResolver.js.map +1 -0
- package/dist/production/src/metadata/ForeignKeyConstraintMetadata.cjs +56 -0
- package/dist/production/src/metadata/ForeignKeyConstraintMetadata.cjs.map +1 -0
- package/dist/production/src/metadata/ForeignKeyConstraintMetadata.js +56 -0
- package/dist/production/src/metadata/ForeignKeyConstraintMetadata.js.map +1 -0
- package/dist/production/src/metadata/IndexMetadata.cjs +33 -0
- package/dist/production/src/metadata/IndexMetadata.cjs.map +1 -0
- package/dist/production/src/metadata/IndexMetadata.js +33 -0
- package/dist/production/src/metadata/IndexMetadata.js.map +1 -0
- package/dist/production/src/metadata/UniqueConstraintMetadata.cjs +39 -0
- package/dist/production/src/metadata/UniqueConstraintMetadata.cjs.map +1 -0
- package/dist/production/src/metadata/UniqueConstraintMetadata.js +39 -0
- package/dist/production/src/metadata/UniqueConstraintMetadata.js.map +1 -0
- package/dist/production/src/metadata/stringArrayEquals.cjs +12 -0
- package/dist/production/src/metadata/stringArrayEquals.cjs.map +1 -0
- package/dist/production/src/metadata/stringArrayEquals.js +12 -0
- package/dist/production/src/metadata/stringArrayEquals.js.map +1 -0
- package/dist/production/src/queryable/DatabaseQuery.cjs +16 -0
- package/dist/production/src/queryable/DatabaseQuery.cjs.map +1 -0
- package/dist/production/src/queryable/DatabaseQuery.js +16 -0
- package/dist/production/src/queryable/DatabaseQuery.js.map +1 -0
- package/dist/production/src/queryable/DatabaseQueryable.cjs +13 -0
- package/dist/production/src/queryable/DatabaseQueryable.cjs.map +1 -0
- package/dist/production/src/queryable/DatabaseQueryable.js +13 -0
- package/dist/production/src/queryable/DatabaseQueryable.js.map +1 -0
- package/dist/production/src/utils/ConstraintHelper.cjs +44 -0
- package/dist/production/src/utils/ConstraintHelper.cjs.map +1 -0
- package/dist/production/src/utils/ConstraintHelper.js +44 -0
- package/dist/production/src/utils/ConstraintHelper.js.map +1 -0
- package/dist/production/src/utils/Mutex.cjs +49 -0
- package/dist/production/src/utils/Mutex.cjs.map +1 -0
- package/dist/production/src/utils/Mutex.js +49 -0
- package/dist/production/src/utils/Mutex.js.map +1 -0
- package/dist/production/src/utils/assertNever.cjs +7 -0
- package/dist/production/src/utils/assertNever.cjs.map +1 -0
- package/dist/production/src/utils/assertNever.js +7 -0
- package/dist/production/src/utils/assertNever.js.map +1 -0
- package/dist/production/src/utils/asyncIterableTransaction.cjs +26 -0
- package/dist/production/src/utils/asyncIterableTransaction.cjs.map +1 -0
- package/dist/production/src/utils/asyncIterableTransaction.js +26 -0
- package/dist/production/src/utils/asyncIterableTransaction.js.map +1 -0
- package/dist/production/src/utils/createDatabaseIfNotExists.cjs +34 -0
- package/dist/production/src/utils/createDatabaseIfNotExists.cjs.map +1 -0
- package/dist/production/src/utils/createDatabaseIfNotExists.js +34 -0
- package/dist/production/src/utils/createDatabaseIfNotExists.js.map +1 -0
- package/dist/production/src/utils/listen.cjs +118 -0
- package/dist/production/src/utils/listen.cjs.map +1 -0
- package/dist/production/src/utils/listen.js +118 -0
- package/dist/production/src/utils/listen.js.map +1 -0
- package/dist/production/src/utils/pgClientFactory.cjs +13 -0
- package/dist/production/src/utils/pgClientFactory.cjs.map +1 -0
- package/dist/production/src/utils/pgClientFactory.js +13 -0
- package/dist/production/src/utils/pgClientFactory.js.map +1 -0
- package/dist/production/src/utils/retryTransaction.cjs +49 -0
- package/dist/production/src/utils/retryTransaction.cjs.map +1 -0
- package/dist/production/src/utils/retryTransaction.js +49 -0
- package/dist/production/src/utils/retryTransaction.js.map +1 -0
- package/dist/production/src/utils/sql.cjs +30 -0
- package/dist/production/src/utils/sql.cjs.map +1 -0
- package/dist/production/src/utils/sql.js +30 -0
- package/dist/production/src/utils/sql.js.map +1 -0
- package/dist/production/src/utils/withDatabaseAdvisoryLock.cjs +15 -0
- package/dist/production/src/utils/withDatabaseAdvisoryLock.cjs.map +1 -0
- package/dist/production/src/utils/withDatabaseAdvisoryLock.js +15 -0
- package/dist/production/src/utils/withDatabaseAdvisoryLock.js.map +1 -0
- package/dist/tests/cases/unit/connection.test.d.ts +2 -0
- package/dist/tests/cases/unit/connection.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/createConnectionMockAlt.d.ts +7 -0
- package/dist/tests/cases/unit/createConnectionMockAlt.d.ts.map +1 -0
- package/dist/tests/cases/unit/eventManager.test.d.ts +2 -0
- package/dist/tests/cases/unit/eventManager.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/pool.test.d.ts +2 -0
- package/dist/tests/cases/unit/pool.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/queryBuilder.test.d.ts +2 -0
- package/dist/tests/cases/unit/queryBuilder.test.d.ts.map +1 -0
- package/dist/tests/src/tags.d.ts +2 -0
- package/dist/tests/src/tags.d.ts.map +1 -0
- package/dist/tests/tsconfig.tsbuildinfo +1 -0
- package/dist/types/Literal.d.ts +12 -0
- package/dist/types/Literal.d.ts.map +1 -0
- package/dist/types/builders/CaseStatement.d.ts +21 -0
- package/dist/types/builders/CaseStatement.d.ts.map +1 -0
- package/dist/types/builders/ColumnExpressionFactory.d.ts +15 -0
- package/dist/types/builders/ColumnExpressionFactory.d.ts.map +1 -0
- package/dist/types/builders/Compiler.d.ts +39 -0
- package/dist/types/builders/Compiler.d.ts.map +1 -0
- package/dist/types/builders/ConditionBuilder.d.ts +46 -0
- package/dist/types/builders/ConditionBuilder.d.ts.map +1 -0
- package/dist/types/builders/ConflictActionType.d.ts +5 -0
- package/dist/types/builders/ConflictActionType.d.ts.map +1 -0
- package/dist/types/builders/DeleteBuilder.d.ts +34 -0
- package/dist/types/builders/DeleteBuilder.d.ts.map +1 -0
- package/dist/types/builders/InsertBuilder.d.ts +66 -0
- package/dist/types/builders/InsertBuilder.d.ts.map +1 -0
- package/dist/types/builders/LimitByGroupWrapper.d.ts +14 -0
- package/dist/types/builders/LimitByGroupWrapper.d.ts.map +1 -0
- package/dist/types/builders/LockType.d.ts +11 -0
- package/dist/types/builders/LockType.d.ts.map +1 -0
- package/dist/types/builders/QueryBuilder.d.ts +31 -0
- package/dist/types/builders/QueryBuilder.d.ts.map +1 -0
- package/dist/types/builders/SelectBuilder.d.ts +72 -0
- package/dist/types/builders/SelectBuilder.d.ts.map +1 -0
- package/dist/types/builders/UpdateBuilder.d.ts +42 -0
- package/dist/types/builders/UpdateBuilder.d.ts.map +1 -0
- package/dist/types/builders/WindowFunction.d.ts +16 -0
- package/dist/types/builders/WindowFunction.d.ts.map +1 -0
- package/dist/types/builders/index.d.ts +13 -0
- package/dist/types/builders/index.d.ts.map +1 -0
- package/dist/types/builders/internal/Returning.d.ts +18 -0
- package/dist/types/builders/internal/Returning.d.ts.map +1 -0
- package/dist/types/builders/internal/Subqueries.d.ts +8 -0
- package/dist/types/builders/internal/Subqueries.d.ts.map +1 -0
- package/dist/types/builders/internal/Where.d.ts +26 -0
- package/dist/types/builders/internal/Where.d.ts.map +1 -0
- package/dist/types/builders/internal/With.d.ts +31 -0
- package/dist/types/builders/internal/With.d.ts.map +1 -0
- package/dist/types/builders/utils.d.ts +5 -0
- package/dist/types/builders/utils.d.ts.map +1 -0
- package/dist/types/client/AcquiredConnection.d.ts +19 -0
- package/dist/types/client/AcquiredConnection.d.ts.map +1 -0
- package/dist/types/client/Client.d.ts +24 -0
- package/dist/types/client/Client.d.ts.map +1 -0
- package/dist/types/client/Connection.d.ts +76 -0
- package/dist/types/client/Connection.d.ts.map +1 -0
- package/dist/types/client/EventManager.d.ts +29 -0
- package/dist/types/client/EventManager.d.ts.map +1 -0
- package/dist/types/client/PgClient.d.ts +11 -0
- package/dist/types/client/PgClient.d.ts.map +1 -0
- package/dist/types/client/Pool.d.ts +131 -0
- package/dist/types/client/Pool.d.ts.map +1 -0
- package/dist/types/client/Transaction.d.ts +38 -0
- package/dist/types/client/Transaction.d.ts.map +1 -0
- package/dist/types/client/errorCodes.d.ts +262 -0
- package/dist/types/client/errorCodes.d.ts.map +1 -0
- package/dist/types/client/errors.d.ts +34 -0
- package/dist/types/client/errors.d.ts.map +1 -0
- package/dist/types/client/index.d.ts +8 -0
- package/dist/types/client/index.d.ts.map +1 -0
- package/dist/types/exceptions.d.ts +3 -0
- package/dist/types/exceptions.d.ts.map +1 -0
- package/dist/types/index.d.ts +14 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/metadata/DatabaseMetadata.d.ts +15 -0
- package/dist/types/metadata/DatabaseMetadata.d.ts.map +1 -0
- package/dist/types/metadata/DatabaseMetadataResolver.d.ts +8 -0
- package/dist/types/metadata/DatabaseMetadataResolver.d.ts.map +1 -0
- package/dist/types/metadata/ForeignKeyConstraintMetadata.d.ts +27 -0
- package/dist/types/metadata/ForeignKeyConstraintMetadata.d.ts.map +1 -0
- package/dist/types/metadata/IndexMetadata.d.ts +15 -0
- package/dist/types/metadata/IndexMetadata.d.ts.map +1 -0
- package/dist/types/metadata/UniqueConstraintMetadata.d.ts +17 -0
- package/dist/types/metadata/UniqueConstraintMetadata.d.ts.map +1 -0
- package/dist/types/metadata/index.d.ts +6 -0
- package/dist/types/metadata/index.d.ts.map +1 -0
- package/dist/types/metadata/stringArrayEquals.d.ts +2 -0
- package/dist/types/metadata/stringArrayEquals.d.ts.map +1 -0
- package/dist/types/queryable/DatabaseQuery.d.ts +7 -0
- package/dist/types/queryable/DatabaseQuery.d.ts.map +1 -0
- package/dist/types/queryable/DatabaseQueryable.d.ts +9 -0
- package/dist/types/queryable/DatabaseQueryable.d.ts.map +1 -0
- package/dist/types/queryable/index.d.ts +3 -0
- package/dist/types/queryable/index.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/dist/types/types.d.ts +23 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/utils/ConstraintHelper.d.ts +15 -0
- package/dist/types/utils/ConstraintHelper.d.ts.map +1 -0
- package/dist/types/utils/Mutex.d.ts +11 -0
- package/dist/types/utils/Mutex.d.ts.map +1 -0
- package/dist/types/utils/assertNever.d.ts +2 -0
- package/dist/types/utils/assertNever.d.ts.map +1 -0
- package/dist/types/utils/asyncIterableTransaction.d.ts +7 -0
- package/dist/types/utils/asyncIterableTransaction.d.ts.map +1 -0
- package/dist/types/utils/createDatabaseIfNotExists.d.ts +3 -0
- package/dist/types/utils/createDatabaseIfNotExists.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +11 -0
- package/dist/types/utils/index.d.ts.map +1 -0
- package/dist/types/utils/listen.d.ts +32 -0
- package/dist/types/utils/listen.d.ts.map +1 -0
- package/dist/types/utils/pgClientFactory.d.ts +6 -0
- package/dist/types/utils/pgClientFactory.d.ts.map +1 -0
- package/dist/types/utils/retryTransaction.d.ts +7 -0
- package/dist/types/utils/retryTransaction.d.ts.map +1 -0
- package/dist/types/utils/sql.d.ts +6 -0
- package/dist/types/utils/sql.d.ts.map +1 -0
- package/dist/types/utils/withDatabaseAdvisoryLock.d.ts +3 -0
- package/dist/types/utils/withDatabaseAdvisoryLock.d.ts.map +1 -0
- package/package.json +6 -6
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const exceptions = require("../exceptions.cjs");
|
|
4
|
+
const errorCodes = require("./errorCodes.cjs");
|
|
5
|
+
const errors = require("./errors.cjs");
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
9
|
+
const poolStatsDescription = {
|
|
10
|
+
connection_started_count: "Total number of connection attempts when started.",
|
|
11
|
+
connection_established_count: "Total number of established connections.",
|
|
12
|
+
connection_recoverable_error_count: "Number of connections that failed on recoverable error (e.g. 53300) and retry was tried.",
|
|
13
|
+
connection_error_count: "Number of non-recoverable errors or recoverable errors reaching max attempts.",
|
|
14
|
+
connection_disposed_idle_timeout_count: "Number of idle connection, that was disposed after configured timeout.",
|
|
15
|
+
connection_disposed_idle_max_count: "Number of idle connections, that was immediately disposed, because maximum number of idle connection was reached.",
|
|
16
|
+
connection_disposed_old_count: "Number of connections, that was too old after it was released.",
|
|
17
|
+
connection_disposed_manual_count: "Number of manually disposed connection (e.g. due to exception on given connection).",
|
|
18
|
+
connection_released_count: "Number of connection returned to the pool.",
|
|
19
|
+
connection_reused_immediately_count: "Number of connections, that was reused by pending item immediately after it was returned to the pool.",
|
|
20
|
+
connection_reused_later_count: "Number of idle connections, that was reused later.",
|
|
21
|
+
connection_established_idle_count: "Number of newly established connections, which was not used (e.g. some connection was returned earlier).",
|
|
22
|
+
item_queued_count: "Number of queued items requesting a connection.",
|
|
23
|
+
item_timeout_count: "Number of items waiting for connection, which timed out.",
|
|
24
|
+
item_rejected_count: "Number of items rejected with an error.",
|
|
25
|
+
item_resolved_new_ms_count: "Number of queued items resolved with newly established connection.",
|
|
26
|
+
item_resolved_new_ms_sum: "Waiting time of queued items, which was resolved with a new connection.",
|
|
27
|
+
item_resolved_released_ms_count: "Number of queued items resolved with released connection.",
|
|
28
|
+
item_resolved_released_ms_sum: "Waiting time of queued items, which was resolved with a released connection."
|
|
29
|
+
};
|
|
30
|
+
class PoolConnection {
|
|
31
|
+
constructor(client) {
|
|
32
|
+
this.client = client;
|
|
33
|
+
__publicField(this, "disposed", false);
|
|
34
|
+
__publicField(this, "uses", 0);
|
|
35
|
+
__publicField(this, "createdAt", Date.now());
|
|
36
|
+
__publicField(this, "timerId", null);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
class PendingItem {
|
|
40
|
+
constructor(resolve, reject) {
|
|
41
|
+
this.resolve = resolve;
|
|
42
|
+
this.reject = reject;
|
|
43
|
+
__publicField(this, "createdAt", Date.now());
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
class Pool {
|
|
47
|
+
constructor(clientFactory, poolConfig) {
|
|
48
|
+
this.clientFactory = clientFactory;
|
|
49
|
+
__publicField(this, "ended", false);
|
|
50
|
+
__publicField(this, "connectingCount", 0);
|
|
51
|
+
__publicField(this, "remainingRateLimit");
|
|
52
|
+
__publicField(this, "idle", []);
|
|
53
|
+
__publicField(this, "active", /* @__PURE__ */ new Set());
|
|
54
|
+
__publicField(this, "queue", []);
|
|
55
|
+
__publicField(this, "poolConfig");
|
|
56
|
+
__publicField(this, "poolStats", {
|
|
57
|
+
connection_started_count: 0,
|
|
58
|
+
connection_established_count: 0,
|
|
59
|
+
connection_recoverable_error_count: 0,
|
|
60
|
+
connection_error_count: 0,
|
|
61
|
+
connection_disposed_idle_timeout_count: 0,
|
|
62
|
+
connection_disposed_idle_max_count: 0,
|
|
63
|
+
connection_disposed_old_count: 0,
|
|
64
|
+
connection_disposed_manual_count: 0,
|
|
65
|
+
connection_released_count: 0,
|
|
66
|
+
connection_reused_immediately_count: 0,
|
|
67
|
+
connection_reused_later_count: 0,
|
|
68
|
+
connection_established_idle_count: 0,
|
|
69
|
+
item_queued_count: 0,
|
|
70
|
+
item_timeout_count: 0,
|
|
71
|
+
item_rejected_count: 0,
|
|
72
|
+
item_resolved_new_ms_count: 0,
|
|
73
|
+
item_resolved_new_ms_sum: 0,
|
|
74
|
+
item_resolved_released_ms_count: 0,
|
|
75
|
+
item_resolved_released_ms_sum: 0
|
|
76
|
+
});
|
|
77
|
+
__publicField(this, "lastRecoverableError");
|
|
78
|
+
const maxConnections = poolConfig.maxConnections ?? 10;
|
|
79
|
+
const maxConnecting = Math.ceil(maxConnections / 2);
|
|
80
|
+
this.poolConfig = {
|
|
81
|
+
maxConnections,
|
|
82
|
+
maxConnecting,
|
|
83
|
+
maxIdle: maxConnections,
|
|
84
|
+
rateLimitCount: maxConnecting * 5,
|
|
85
|
+
rateLimitPeriodMs: 1e3,
|
|
86
|
+
idleTimeoutMs: 1e4,
|
|
87
|
+
acquireTimeoutMs: 1e4,
|
|
88
|
+
reconnectIntervalMs: 100,
|
|
89
|
+
...poolConfig
|
|
90
|
+
};
|
|
91
|
+
this.remainingRateLimit = this.poolConfig.rateLimitCount;
|
|
92
|
+
}
|
|
93
|
+
acquire() {
|
|
94
|
+
if (this.ended) {
|
|
95
|
+
throw new PoolClosedError();
|
|
96
|
+
}
|
|
97
|
+
const poolConnection = this.idle.pop();
|
|
98
|
+
if (poolConnection !== void 0) {
|
|
99
|
+
if (poolConnection.timerId) {
|
|
100
|
+
clearTimeout(poolConnection.timerId);
|
|
101
|
+
}
|
|
102
|
+
poolConnection.uses++;
|
|
103
|
+
this.active.add(poolConnection);
|
|
104
|
+
this.poolStats.connection_reused_later_count++;
|
|
105
|
+
this.log("Item fulfilled with an idle connection.");
|
|
106
|
+
return Promise.resolve(poolConnection);
|
|
107
|
+
}
|
|
108
|
+
const pendingItem = this.createPendingItem();
|
|
109
|
+
this.maybeCreateNew();
|
|
110
|
+
return pendingItem;
|
|
111
|
+
}
|
|
112
|
+
release(poolConnection) {
|
|
113
|
+
if (this.ended) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
this.log("Releasing a connection.");
|
|
117
|
+
if (!this.active.delete(poolConnection)) {
|
|
118
|
+
throw new exceptions.ImplementationException("Connection does not belong to this pool.");
|
|
119
|
+
}
|
|
120
|
+
if (this.poolConfig.maxUses && poolConnection.uses >= this.poolConfig.maxUses || this.poolConfig.maxAgeMs && poolConnection.createdAt + this.poolConfig.maxAgeMs < Date.now()) {
|
|
121
|
+
setImmediate(async () => {
|
|
122
|
+
await this.disposeConnection(poolConnection);
|
|
123
|
+
this.poolStats.connection_disposed_old_count++;
|
|
124
|
+
this.log("Connection has reached max age or usage and was disposed.");
|
|
125
|
+
});
|
|
126
|
+
this.maybeCreateNew();
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
this.handleAvailableConnection(poolConnection);
|
|
130
|
+
}
|
|
131
|
+
dispose(poolConnection) {
|
|
132
|
+
if (this.ended) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
this.poolStats.connection_disposed_manual_count++;
|
|
136
|
+
this.log("Releasing and disposing a connection.");
|
|
137
|
+
if (!this.active.delete(poolConnection)) {
|
|
138
|
+
throw new exceptions.ImplementationException("Connection does not belong to this pool.");
|
|
139
|
+
}
|
|
140
|
+
setImmediate(async () => {
|
|
141
|
+
await this.disposeConnection(poolConnection);
|
|
142
|
+
this.log("Connection errored and was disposed.");
|
|
143
|
+
});
|
|
144
|
+
this.maybeCreateNew();
|
|
145
|
+
}
|
|
146
|
+
async end() {
|
|
147
|
+
this.ended = true;
|
|
148
|
+
this.queue.forEach((it) => it.reject(new PoolClosedError()));
|
|
149
|
+
this.queue = [];
|
|
150
|
+
const allConnections = [...this.idle, ...Array.from(this.active)];
|
|
151
|
+
await Promise.allSettled(allConnections.map((it) => this.disposeConnection(it)));
|
|
152
|
+
this.idle = [];
|
|
153
|
+
this.active.clear();
|
|
154
|
+
}
|
|
155
|
+
async closeIdle() {
|
|
156
|
+
this.log("Disposing all idle connection on request.");
|
|
157
|
+
const idle = this.idle;
|
|
158
|
+
this.idle = [];
|
|
159
|
+
await Promise.allSettled(idle.map((it) => this.disposeConnection(it)));
|
|
160
|
+
}
|
|
161
|
+
getPoolStatus() {
|
|
162
|
+
return {
|
|
163
|
+
max: this.poolConfig.maxConnections,
|
|
164
|
+
active: this.active.size,
|
|
165
|
+
idle: this.idle.length,
|
|
166
|
+
pending: this.queue.length,
|
|
167
|
+
connecting: this.connectingCount,
|
|
168
|
+
stats: this.poolStats
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
async maybeCreateNew() {
|
|
172
|
+
if (this.ended) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (this.queue.length === 0) {
|
|
176
|
+
this.log("Not connecting, queue is empty.");
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const connectingCount = this.connectingCount;
|
|
180
|
+
if (connectingCount >= this.queue.length) {
|
|
181
|
+
this.log("Not connecting, already establishing connection for all queued items.");
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
const idleCount = this.idle.length;
|
|
185
|
+
if (this.active.size + idleCount + connectingCount >= this.poolConfig.maxConnections) {
|
|
186
|
+
this.log("Not connecting, max connections reached.");
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (connectingCount >= this.poolConfig.maxConnecting) {
|
|
190
|
+
this.log("Not connecting, maximum concurrent connection attempts in progress.");
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
if (this.remainingRateLimit <= 0) {
|
|
194
|
+
this.log("Not connecting, rate limit reached.");
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
this.log("Creating a new connection");
|
|
198
|
+
const client = this.clientFactory();
|
|
199
|
+
const poolConnection = new PoolConnection(client);
|
|
200
|
+
client.on("error", (e) => {
|
|
201
|
+
this.log("Client error on idle connection has occurred: " + e.message);
|
|
202
|
+
this.poolConfig.logError(new errors.ClientError(e, "runtime error"));
|
|
203
|
+
this.poolStats.connection_error_count++;
|
|
204
|
+
if (!this.active.has(poolConnection)) {
|
|
205
|
+
this.removeIdleConnection(poolConnection);
|
|
206
|
+
this.disposeConnection(poolConnection);
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
try {
|
|
210
|
+
this.connectingCount++;
|
|
211
|
+
this.remainingRateLimit--;
|
|
212
|
+
this.poolStats.connection_started_count++;
|
|
213
|
+
await client.connect();
|
|
214
|
+
this.poolStats.connection_established_count++;
|
|
215
|
+
this.connectingCount--;
|
|
216
|
+
this.log("Connection established");
|
|
217
|
+
if (this.ended) {
|
|
218
|
+
return this.disposeConnection(poolConnection);
|
|
219
|
+
}
|
|
220
|
+
this.handleAvailableConnection(poolConnection);
|
|
221
|
+
this.maybeCreateNew();
|
|
222
|
+
} catch (e) {
|
|
223
|
+
this.log("Connection error occurred: " + e.message);
|
|
224
|
+
this.disposeConnection(poolConnection);
|
|
225
|
+
if (e.code === errorCodes.ClientErrorCodes.TOO_MANY_CONNECTIONS || e.code === errorCodes.ClientErrorCodes.CANNOT_CONNECT_NOW || e.message === "timeout expired" || e.code === "ETIMEDOUT") {
|
|
226
|
+
this.lastRecoverableError = { error: e, time: Date.now() };
|
|
227
|
+
this.poolStats.connection_recoverable_error_count++;
|
|
228
|
+
this.log("Recoverable error, retrying in a moment.");
|
|
229
|
+
this.poolConfig.logError(new errors.ClientError(e, "recoverable connection error"));
|
|
230
|
+
setTimeout(() => {
|
|
231
|
+
this.connectingCount--;
|
|
232
|
+
this.log("Retrying");
|
|
233
|
+
this.maybeCreateNew();
|
|
234
|
+
}, this.poolConfig.reconnectIntervalMs);
|
|
235
|
+
} else {
|
|
236
|
+
this.poolStats.connection_error_count++;
|
|
237
|
+
this.connectingCount--;
|
|
238
|
+
const clientError = new errors.ClientError(e, "connection error");
|
|
239
|
+
if (this.active.size === 0 && this.queue.length > 0) {
|
|
240
|
+
const pendingItem = this.queue.shift();
|
|
241
|
+
if (!pendingItem) throw new Error();
|
|
242
|
+
this.log("Connecting failed, rejecting pending item");
|
|
243
|
+
pendingItem.reject(clientError);
|
|
244
|
+
this.poolStats.item_rejected_count++;
|
|
245
|
+
} else {
|
|
246
|
+
this.log("Connecting failed, emitting error");
|
|
247
|
+
this.poolConfig.logError(clientError);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
} finally {
|
|
251
|
+
setTimeout(() => {
|
|
252
|
+
if (this.remainingRateLimit === 0) {
|
|
253
|
+
this.log("Rate limit renewed.");
|
|
254
|
+
}
|
|
255
|
+
this.remainingRateLimit++;
|
|
256
|
+
this.maybeCreateNew();
|
|
257
|
+
}, this.poolConfig.rateLimitPeriodMs);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
createPendingItem() {
|
|
261
|
+
return new Promise((resolve, reject) => {
|
|
262
|
+
const timeout = setTimeout(() => {
|
|
263
|
+
const acquireTimeoutError = new AcquireTimeoutError(
|
|
264
|
+
this.lastRecoverableError && this.lastRecoverableError.time > item.createdAt ? this.lastRecoverableError.error : void 0
|
|
265
|
+
);
|
|
266
|
+
item.reject(acquireTimeoutError);
|
|
267
|
+
const index = this.queue.indexOf(item);
|
|
268
|
+
if (index > -1) {
|
|
269
|
+
this.queue.splice(index, 1);
|
|
270
|
+
}
|
|
271
|
+
this.poolStats.item_timeout_count++;
|
|
272
|
+
this.log("Queued item timed out");
|
|
273
|
+
}, this.poolConfig.acquireTimeoutMs);
|
|
274
|
+
const item = new PendingItem((it) => {
|
|
275
|
+
const duration = Date.now() - item.createdAt;
|
|
276
|
+
const isNew = it.uses === 0;
|
|
277
|
+
this.log(`Queued item fulfilled with ${!isNew ? "released" : "new"} connection.`);
|
|
278
|
+
if (isNew) {
|
|
279
|
+
this.poolStats.item_resolved_new_ms_count++;
|
|
280
|
+
this.poolStats.item_resolved_new_ms_sum += duration;
|
|
281
|
+
} else {
|
|
282
|
+
this.poolStats.item_resolved_released_ms_count++;
|
|
283
|
+
this.poolStats.item_resolved_released_ms_sum += duration;
|
|
284
|
+
}
|
|
285
|
+
clearTimeout(timeout);
|
|
286
|
+
resolve(it);
|
|
287
|
+
}, (it) => {
|
|
288
|
+
clearTimeout(timeout);
|
|
289
|
+
reject(it);
|
|
290
|
+
});
|
|
291
|
+
this.poolStats.item_queued_count++;
|
|
292
|
+
this.queue.push(item);
|
|
293
|
+
this.log(`Item added to a queue.`);
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
handleAvailableConnection(poolConnection) {
|
|
297
|
+
const item = this.queue.shift();
|
|
298
|
+
const isNew = poolConnection.uses === 0;
|
|
299
|
+
if (!isNew) {
|
|
300
|
+
this.poolStats.connection_released_count++;
|
|
301
|
+
}
|
|
302
|
+
if (item) {
|
|
303
|
+
this.active.add(poolConnection);
|
|
304
|
+
item.resolve(poolConnection);
|
|
305
|
+
if (!isNew) {
|
|
306
|
+
this.poolStats.connection_reused_immediately_count++;
|
|
307
|
+
}
|
|
308
|
+
poolConnection.uses++;
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
if (isNew) {
|
|
312
|
+
this.poolStats.connection_established_idle_count++;
|
|
313
|
+
}
|
|
314
|
+
if (this.idle.length >= this.poolConfig.maxIdle) {
|
|
315
|
+
setImmediate(async () => {
|
|
316
|
+
await this.disposeConnection(poolConnection);
|
|
317
|
+
this.poolStats.connection_disposed_idle_max_count++;
|
|
318
|
+
this.log("Too many idle connections, connection disposed.");
|
|
319
|
+
});
|
|
320
|
+
} else {
|
|
321
|
+
poolConnection.timerId = setTimeout(async () => {
|
|
322
|
+
if (this.removeIdleConnection(poolConnection)) {
|
|
323
|
+
await this.disposeConnection(poolConnection);
|
|
324
|
+
this.poolStats.connection_disposed_idle_timeout_count++;
|
|
325
|
+
this.log("Idle connection disposed after timeout.");
|
|
326
|
+
}
|
|
327
|
+
}, this.poolConfig.idleTimeoutMs);
|
|
328
|
+
this.idle.push(poolConnection);
|
|
329
|
+
this.log("Connection is idle and available.");
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
removeIdleConnection(poolConnection) {
|
|
333
|
+
const index = this.idle.indexOf(poolConnection);
|
|
334
|
+
if (index > -1) {
|
|
335
|
+
this.idle.splice(index, 1);
|
|
336
|
+
return true;
|
|
337
|
+
}
|
|
338
|
+
return false;
|
|
339
|
+
}
|
|
340
|
+
async disposeConnection(connection) {
|
|
341
|
+
if (connection.disposed) {
|
|
342
|
+
throw new PoolError("Connection is already disposed");
|
|
343
|
+
}
|
|
344
|
+
connection.disposed = true;
|
|
345
|
+
const doEnd = async () => {
|
|
346
|
+
try {
|
|
347
|
+
await connection.client.end();
|
|
348
|
+
} catch (e) {
|
|
349
|
+
this.poolConfig.logError(new errors.ClientError(e, "disposal error"));
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
await Promise.race([
|
|
353
|
+
doEnd(),
|
|
354
|
+
new Promise((resolve) => setTimeout(resolve, 5e3))
|
|
355
|
+
]);
|
|
356
|
+
}
|
|
357
|
+
log(message) {
|
|
358
|
+
if (!this.poolConfig.log) return;
|
|
359
|
+
const poolStatus = this.getPoolStatus();
|
|
360
|
+
this.poolConfig.log(message, poolStatus);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
class PoolError extends errors.DatabaseError {
|
|
364
|
+
}
|
|
365
|
+
class AcquireTimeoutError extends PoolError {
|
|
366
|
+
constructor(previous) {
|
|
367
|
+
super("Failed to acquire a connection" + (previous && "message" in previous ? `. Last error: ${previous.message}` : ""), previous);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
class PoolClosedError extends PoolError {
|
|
371
|
+
constructor() {
|
|
372
|
+
super("Pool is already closed");
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
exports.AcquireTimeoutError = AcquireTimeoutError;
|
|
376
|
+
exports.Pool = Pool;
|
|
377
|
+
exports.PoolClosedError = PoolClosedError;
|
|
378
|
+
exports.PoolError = PoolError;
|
|
379
|
+
exports.poolStatsDescription = poolStatsDescription;
|
|
380
|
+
//# sourceMappingURL=Pool.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Pool.cjs","sources":["../../../../../packages/database/src/client/Pool.ts"],"sourcesContent":["import { ImplementationException } from '../exceptions'\nimport { ClientErrorCodes } from './errorCodes'\nimport { EventEmitter } from 'node:events'\nimport { ClientError, DatabaseError } from './errors'\nimport { PgClientFactory } from '../utils'\nimport { PgClient } from './PgClient'\n\nexport type PoolLogger = (message: string, status: PoolStatus) => void\n\nexport type PoolConfig = Partial<PoolConfigInternal> & Pick<PoolConfigInternal, 'logError'>\n\ninterface PoolConfigInternal {\n\t/** maximum number of connections in a pool */\n\tmaxConnections: number\n\t/** maximum number of connections concurrently establishing*/\n\tmaxConnecting: number\n\t/** maximum connection attempts during given period */\n\trateLimitCount: number\n\t/** period for rate limiting */\n\trateLimitPeriodMs: number\n\t/** maximum number of idle connections. when reached, will be disposed immediately */\n\tmaxIdle: number\n\t/** interval between retries of recoverable errors */\n\treconnectIntervalMs: number\n\t/** timeout to dispose idle connections */\n\tidleTimeoutMs: number\n\t/** timeout of pending item waiting for a connection. also used for retries of recoverable errors */\n\tacquireTimeoutMs: number\n\t/** how many times can a single connection be acquired */\n\tmaxUses?: number\n\t/** max age of connection. when reached, connection will be disposed after returning to a pool */\n\tmaxAgeMs?: number\n\t/** internal logging, mainly for debugging and testing */\n\tlog?: PoolLogger\n\t/** logging of out-of-stack errors */\n\tlogError: (error: ClientError) => void\n}\n\nexport type PoolStats = { [K in keyof typeof poolStatsDescription]: number }\n\nexport interface PoolStatus {\n\t/** maximum number of connections in a pool */\n\tmax: number\n\t/** number of items waiting for a connections */\n\tpending: number\n\t/** number of active (acquired) connections */\n\tactive: number\n\t/** number of available idle connections */\n\tidle: number\n\t/** number of currently establishing connections */\n\tconnecting: number\n\tstats: PoolStats\n}\n\nexport const poolStatsDescription = {\n\tconnection_started_count: 'Total number of connection attempts when started.',\n\tconnection_established_count: 'Total number of established connections.',\n\tconnection_recoverable_error_count: 'Number of connections that failed on recoverable error (e.g. 53300) and retry was tried.',\n\tconnection_error_count: 'Number of non-recoverable errors or recoverable errors reaching max attempts.',\n\tconnection_disposed_idle_timeout_count: 'Number of idle connection, that was disposed after configured timeout.',\n\tconnection_disposed_idle_max_count:\n\t\t'Number of idle connections, that was immediately disposed, because maximum number of idle connection was reached.',\n\tconnection_disposed_old_count: 'Number of connections, that was too old after it was released.',\n\tconnection_disposed_manual_count: 'Number of manually disposed connection (e.g. due to exception on given connection).',\n\tconnection_released_count: 'Number of connection returned to the pool.',\n\tconnection_reused_immediately_count: 'Number of connections, that was reused by pending item immediately after it was returned to the pool.',\n\tconnection_reused_later_count: 'Number of idle connections, that was reused later.',\n\n\tconnection_established_idle_count: 'Number of newly established connections, which was not used (e.g. some connection was returned earlier).',\n\n\titem_queued_count: 'Number of queued items requesting a connection.',\n\titem_timeout_count: 'Number of items waiting for connection, which timed out.',\n\titem_rejected_count: 'Number of items rejected with an error.',\n\n\titem_resolved_new_ms_count: 'Number of queued items resolved with newly established connection.',\n\titem_resolved_new_ms_sum: 'Waiting time of queued items, which was resolved with a new connection.',\n\titem_resolved_released_ms_count: 'Number of queued items resolved with released connection.',\n\titem_resolved_released_ms_sum: 'Waiting time of queued items, which was resolved with a released connection.',\n}\n\nclass PoolConnection {\n\tpublic disposed = false\n\tpublic uses = 0\n\tpublic createdAt = Date.now()\n\tpublic timerId: ReturnType<typeof setTimeout> | null = null\n\n\tconstructor(\n\t\tpublic readonly client: PgClient,\n\t) {\n\t}\n}\n\nclass PendingItem {\n\tpublic readonly createdAt = Date.now()\n\n\tconstructor(\n\t\tpublic resolve: (connection: PoolConnection) => void,\n\t\tpublic reject: (error: Error) => void,\n\t) {\n\t}\n}\n\nclass Pool {\n\t/**\n\t * pool was closed by calling end().\n\t * All connection was disposed, and it is not possible to acquire new one\n\t */\n\tprivate ended = false\n\n\t/**\n\t * current count of connection attempts\n\t * also includes timeout between recoverable retries\n\t */\n\tprivate connectingCount = 0\n\n\t/**\n\t * Remaining number of connections per floating period.\n\t */\n\tprivate remainingRateLimit: number\n\n\t/**\n\t * available idle connections\n\t */\n\tprivate idle: PoolConnection[] = []\n\n\t/**\n\t * currently acquired connections\n\t */\n\tprivate active = new Set<PoolConnection>()\n\n\t/**\n\t * items waiting for released or newly established connection\n\t */\n\tprivate queue: PendingItem[] = []\n\n\tprivate poolConfig: PoolConfigInternal\n\n\tprivate poolStats: PoolStats = {\n\t\tconnection_started_count: 0,\n\t\tconnection_established_count: 0,\n\t\tconnection_recoverable_error_count: 0,\n\t\tconnection_error_count: 0,\n\t\tconnection_disposed_idle_timeout_count: 0,\n\t\tconnection_disposed_idle_max_count: 0,\n\t\tconnection_disposed_old_count: 0,\n\t\tconnection_disposed_manual_count: 0,\n\t\tconnection_released_count: 0,\n\t\tconnection_reused_immediately_count: 0,\n\t\tconnection_reused_later_count: 0,\n\t\tconnection_established_idle_count: 0,\n\t\titem_queued_count: 0,\n\t\titem_timeout_count: 0,\n\t\titem_rejected_count: 0,\n\t\titem_resolved_new_ms_count: 0,\n\t\titem_resolved_new_ms_sum: 0,\n\t\titem_resolved_released_ms_count: 0,\n\t\titem_resolved_released_ms_sum: 0,\n\t}\n\n\tprivate lastRecoverableError: {\n\t\terror: any\n\t\ttime: number\n\t} | undefined\n\n\tconstructor(\n\t\tprivate clientFactory: PgClientFactory,\n\t\tpoolConfig: PoolConfig,\n\t) {\n\t\tconst maxConnections = poolConfig.maxConnections ?? 10\n\t\tconst maxConnecting = Math.ceil(maxConnections / 2)\n\t\tthis.poolConfig = {\n\t\t\tmaxConnections,\n\t\t\tmaxConnecting,\n\t\t\tmaxIdle: maxConnections,\n\t\t\trateLimitCount: maxConnecting * 5,\n\t\t\trateLimitPeriodMs: 1000,\n\t\t\tidleTimeoutMs: 10_000,\n\t\t\tacquireTimeoutMs: 10_000,\n\t\t\treconnectIntervalMs: 100,\n\t\t\t...poolConfig,\n\t\t}\n\t\tthis.remainingRateLimit = this.poolConfig.rateLimitCount\n\t}\n\n\tpublic acquire(): Promise<PoolConnection> {\n\t\tif (this.ended) {\n\t\t\tthrow new PoolClosedError()\n\t\t}\n\t\tconst poolConnection = this.idle.pop()\n\t\tif (poolConnection !== undefined) {\n\t\t\tif (poolConnection.timerId) {\n\t\t\t\tclearTimeout(poolConnection.timerId)\n\t\t\t}\n\t\t\tpoolConnection.uses++\n\t\t\tthis.active.add(poolConnection)\n\t\t\tthis.poolStats.connection_reused_later_count++\n\t\t\tthis.log('Item fulfilled with an idle connection.')\n\n\t\t\treturn Promise.resolve(poolConnection)\n\t\t}\n\t\tconst pendingItem = this.createPendingItem()\n\t\tthis.maybeCreateNew()\n\t\treturn pendingItem\n\t}\n\n\tpublic release(poolConnection: PoolConnection): void {\n\t\tif (this.ended) {\n\t\t\treturn\n\t\t}\n\t\tthis.log('Releasing a connection.')\n\t\tif (!this.active.delete(poolConnection)) {\n\t\t\tthrow new ImplementationException('Connection does not belong to this pool.')\n\t\t}\n\t\tif (\n\t\t\t(this.poolConfig.maxUses && poolConnection.uses >= this.poolConfig.maxUses)\n\t\t\t|| (this.poolConfig.maxAgeMs && poolConnection.createdAt + this.poolConfig.maxAgeMs < Date.now())\n\t\t) {\n\t\t\tsetImmediate(async () => {\n\t\t\t\tawait this.disposeConnection(poolConnection)\n\t\t\t\tthis.poolStats.connection_disposed_old_count++\n\t\t\t\tthis.log('Connection has reached max age or usage and was disposed.')\n\t\t\t})\n\t\t\tthis.maybeCreateNew()\n\t\t\treturn\n\t\t}\n\t\tthis.handleAvailableConnection(poolConnection)\n\t}\n\n\tpublic dispose(poolConnection: PoolConnection): void {\n\t\tif (this.ended) {\n\t\t\treturn\n\t\t}\n\t\tthis.poolStats.connection_disposed_manual_count++\n\t\tthis.log('Releasing and disposing a connection.')\n\t\tif (!this.active.delete(poolConnection)) {\n\t\t\tthrow new ImplementationException('Connection does not belong to this pool.')\n\t\t}\n\t\tsetImmediate(async () => {\n\t\t\tawait this.disposeConnection(poolConnection)\n\t\t\tthis.log('Connection errored and was disposed.')\n\t\t})\n\t\tthis.maybeCreateNew()\n\t}\n\n\tpublic async end(): Promise<void> {\n\t\tthis.ended = true\n\t\tthis.queue.forEach(it => it.reject(new PoolClosedError()))\n\t\tthis.queue = []\n\t\tconst allConnections = [...this.idle, ...Array.from(this.active)]\n\t\tawait Promise.allSettled(allConnections.map(it => this.disposeConnection(it)))\n\t\tthis.idle = []\n\t\tthis.active.clear()\n\t}\n\n\tpublic async closeIdle(): Promise<void> {\n\t\tthis.log('Disposing all idle connection on request.')\n\t\tconst idle = this.idle\n\t\tthis.idle = []\n\t\tawait Promise.allSettled(idle.map(it => this.disposeConnection(it)))\n\t}\n\n\tpublic getPoolStatus(): PoolStatus {\n\t\treturn {\n\t\t\tmax: this.poolConfig.maxConnections,\n\t\t\tactive: this.active.size,\n\t\t\tidle: this.idle.length,\n\t\t\tpending: this.queue.length,\n\t\t\tconnecting: this.connectingCount,\n\t\t\tstats: this.poolStats,\n\t\t}\n\t}\n\n\tprivate async maybeCreateNew(): Promise<void> {\n\t\tif (this.ended) {\n\t\t\treturn\n\t\t}\n\t\tif (this.queue.length === 0) {\n\t\t\tthis.log('Not connecting, queue is empty.')\n\t\t\treturn\n\t\t}\n\t\tconst connectingCount = this.connectingCount\n\t\tif (connectingCount >= this.queue.length) {\n\t\t\tthis.log('Not connecting, already establishing connection for all queued items.')\n\t\t\treturn\n\t\t}\n\t\tconst idleCount = this.idle.length\n\t\tif ((this.active.size + idleCount + connectingCount) >= this.poolConfig.maxConnections) {\n\t\t\tthis.log('Not connecting, max connections reached.')\n\t\t\treturn\n\t\t}\n\t\tif (connectingCount >= this.poolConfig.maxConnecting) {\n\t\t\tthis.log('Not connecting, maximum concurrent connection attempts in progress.')\n\t\t\treturn\n\t\t}\n\t\tif (this.remainingRateLimit <= 0) {\n\t\t\tthis.log('Not connecting, rate limit reached.')\n\t\t\treturn\n\t\t}\n\n\t\tthis.log('Creating a new connection')\n\t\tconst client = this.clientFactory()\n\t\tconst poolConnection = new PoolConnection(client)\n\n\t\tclient.on('error', e => {\n\t\t\tthis.log('Client error on idle connection has occurred: ' + e.message)\n\t\t\tthis.poolConfig.logError(new ClientError(e, 'runtime error'))\n\t\t\tthis.poolStats.connection_error_count++\n\n\t\t\tif (!this.active.has(poolConnection)) {\n\t\t\t\tthis.removeIdleConnection(poolConnection)\n\t\t\t\tthis.disposeConnection(poolConnection)\n\t\t\t}\n\t\t})\n\n\t\ttry {\n\t\t\tthis.connectingCount++\n\t\t\tthis.remainingRateLimit--\n\t\t\tthis.poolStats.connection_started_count++\n\n\t\t\tawait client.connect()\n\n\t\t\tthis.poolStats.connection_established_count++\n\t\t\tthis.connectingCount--\n\n\t\t\tthis.log('Connection established')\n\n\t\t\tif (this.ended) {\n\t\t\t\treturn this.disposeConnection(poolConnection)\n\t\t\t}\n\n\t\t\tthis.handleAvailableConnection(poolConnection)\n\t\t\tthis.maybeCreateNew()\n\t\t} catch (e: any) {\n\t\t\tthis.log('Connection error occurred: ' + e.message)\n\t\t\tthis.disposeConnection(poolConnection)\n\n\t\t\tif (\n\t\t\t\te.code === ClientErrorCodes.TOO_MANY_CONNECTIONS\n\t\t\t\t|| e.code === ClientErrorCodes.CANNOT_CONNECT_NOW // server starting\n\t\t\t\t|| e.message === 'timeout expired' // https://github.com/brianc/node-postgres/blob/c7dc621d3fb52c158eb23aa31dea6bd440700a4a/packages/pg/lib/client.js#L105\n\t\t\t\t|| e.code === 'ETIMEDOUT'\n\t\t\t) {\n\t\t\t\tthis.lastRecoverableError = { error: e, time: Date.now() }\n\t\t\t\tthis.poolStats.connection_recoverable_error_count++\n\t\t\t\tthis.log('Recoverable error, retrying in a moment.')\n\t\t\t\tthis.poolConfig.logError(new ClientError(e, 'recoverable connection error'))\n\t\t\t\tsetTimeout(() => {\n\t\t\t\t\tthis.connectingCount--\n\t\t\t\t\tthis.log('Retrying')\n\t\t\t\t\tthis.maybeCreateNew()\n\t\t\t\t}, this.poolConfig.reconnectIntervalMs)\n\t\t\t} else {\n\t\t\t\tthis.poolStats.connection_error_count++\n\t\t\t\tthis.connectingCount--\n\t\t\t\tconst clientError = new ClientError(e, 'connection error')\n\t\t\t\tif (this.active.size === 0 && this.queue.length > 0) {\n\t\t\t\t\tconst pendingItem = this.queue.shift()\n\t\t\t\t\tif (!pendingItem) throw new Error()\n\t\t\t\t\tthis.log('Connecting failed, rejecting pending item')\n\t\t\t\t\tpendingItem.reject(clientError)\n\t\t\t\t\tthis.poolStats.item_rejected_count++\n\t\t\t\t} else {\n\t\t\t\t\tthis.log('Connecting failed, emitting error')\n\t\t\t\t\tthis.poolConfig.logError(clientError)\n\t\t\t\t}\n\t\t\t}\n\t\t} finally {\n\t\t\tsetTimeout(() => {\n\t\t\t\tif (this.remainingRateLimit === 0) {\n\t\t\t\t\tthis.log('Rate limit renewed.')\n\t\t\t\t}\n\t\t\t\tthis.remainingRateLimit++\n\t\t\t\tthis.maybeCreateNew()\n\t\t\t}, this.poolConfig.rateLimitPeriodMs)\n\t\t}\n\t}\n\n\tprivate createPendingItem(): Promise<PoolConnection> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst timeout = setTimeout(() => {\n\t\t\t\tconst acquireTimeoutError = new AcquireTimeoutError(\n\t\t\t\t\tthis.lastRecoverableError && this.lastRecoverableError.time > item.createdAt\n\t\t\t\t\t\t? this.lastRecoverableError.error\n\t\t\t\t\t\t: undefined,\n\t\t\t\t)\n\t\t\t\titem.reject(acquireTimeoutError)\n\t\t\t\tconst index = this.queue.indexOf(item)\n\t\t\t\tif (index > -1) {\n\t\t\t\t\tthis.queue.splice(index, 1)\n\t\t\t\t}\n\t\t\t\tthis.poolStats.item_timeout_count++\n\t\t\t\tthis.log('Queued item timed out')\n\t\t\t}, this.poolConfig.acquireTimeoutMs)\n\n\t\t\tconst item = new PendingItem(it => {\n\t\t\t\tconst duration = Date.now() - item.createdAt\n\t\t\t\tconst isNew = it.uses === 0\n\t\t\t\tthis.log(`Queued item fulfilled with ${!isNew ? 'released' : 'new'} connection.`)\n\n\t\t\t\tif (isNew) {\n\t\t\t\t\tthis.poolStats.item_resolved_new_ms_count++\n\t\t\t\t\tthis.poolStats.item_resolved_new_ms_sum += duration\n\t\t\t\t} else {\n\t\t\t\t\tthis.poolStats.item_resolved_released_ms_count++\n\t\t\t\t\tthis.poolStats.item_resolved_released_ms_sum += duration\n\t\t\t\t}\n\t\t\t\tclearTimeout(timeout)\n\t\t\t\tresolve(it)\n\t\t\t}, it => {\n\t\t\t\tclearTimeout(timeout)\n\t\t\t\treject(it)\n\t\t\t})\n\n\t\t\tthis.poolStats.item_queued_count++\n\t\t\tthis.queue.push(item)\n\t\t\tthis.log(`Item added to a queue.`)\n\t\t})\n\t}\n\n\tprivate handleAvailableConnection(poolConnection: PoolConnection) {\n\t\tconst item = this.queue.shift()\n\t\tconst isNew = poolConnection.uses === 0\n\t\tif (!isNew) {\n\t\t\tthis.poolStats.connection_released_count++\n\t\t}\n\t\tif (item) {\n\t\t\tthis.active.add(poolConnection)\n\t\t\titem.resolve(poolConnection)\n\t\t\tif (!isNew) {\n\t\t\t\tthis.poolStats.connection_reused_immediately_count++\n\t\t\t}\n\t\t\tpoolConnection.uses++\n\t\t\treturn\n\t\t}\n\t\tif (isNew) {\n\t\t\tthis.poolStats.connection_established_idle_count++\n\t\t}\n\t\tif (this.idle.length >= this.poolConfig.maxIdle) {\n\t\t\tsetImmediate(async () => {\n\t\t\t\tawait this.disposeConnection(poolConnection)\n\t\t\t\tthis.poolStats.connection_disposed_idle_max_count++\n\t\t\t\tthis.log('Too many idle connections, connection disposed.')\n\t\t\t})\n\t\t} else {\n\t\t\tpoolConnection.timerId = setTimeout(async () => {\n\t\t\t\tif (this.removeIdleConnection(poolConnection)) {\n\t\t\t\t\tawait this.disposeConnection(poolConnection)\n\t\t\t\t\tthis.poolStats.connection_disposed_idle_timeout_count++\n\t\t\t\t\tthis.log('Idle connection disposed after timeout.')\n\t\t\t\t}\n\t\t\t}, this.poolConfig.idleTimeoutMs)\n\t\t\tthis.idle.push(poolConnection)\n\t\t\tthis.log('Connection is idle and available.')\n\t\t}\n\t}\n\n\tprivate removeIdleConnection(poolConnection: PoolConnection) {\n\t\tconst index = this.idle.indexOf(poolConnection)\n\t\tif (index > -1) {\n\t\t\tthis.idle.splice(index, 1)\n\t\t\treturn true\n\t\t}\n\t\treturn false\n\t}\n\n\tprivate async disposeConnection(connection: PoolConnection) {\n\t\tif (connection.disposed) {\n\t\t\tthrow new PoolError('Connection is already disposed')\n\t\t}\n\t\tconnection.disposed = true\n\t\tconst doEnd = async () => {\n\t\t\ttry {\n\t\t\t\tawait connection.client.end()\n\t\t\t} catch (e: any) {\n\t\t\t\tthis.poolConfig.logError(new ClientError(e, 'disposal error'))\n\t\t\t}\n\t\t}\n\t\tawait Promise.race([\n\t\t\tdoEnd(),\n\t\t\tnew Promise(resolve => setTimeout(resolve, 5_000)),\n\t\t])\n\t}\n\n\tprivate log(message: string) {\n\t\tif (!this.poolConfig.log) return\n\t\tconst poolStatus = this.getPoolStatus()\n\t\tthis.poolConfig.log(message, poolStatus)\n\t}\n}\n\nexport { Pool }\n\nexport class PoolError extends DatabaseError {\n}\n\nexport class AcquireTimeoutError extends PoolError {\n\tconstructor(previous: any) {\n\t\tsuper('Failed to acquire a connection' + (previous && 'message' in previous ? `. Last error: ${previous.message}` : ''), previous)\n\t}\n}\n\nexport class PoolClosedError extends PoolError {\n\tconstructor() {\n\t\tsuper('Pool is already closed')\n\t}\n}\n"],"names":["ImplementationException","ClientError","ClientErrorCodes","DatabaseError"],"mappings":";;;;;;;;AAsDO,MAAM,uBAAuB;AAAA,EACnC,0BAA0B;AAAA,EAC1B,8BAA8B;AAAA,EAC9B,oCAAoC;AAAA,EACpC,wBAAwB;AAAA,EACxB,wCAAwC;AAAA,EACxC,oCACC;AAAA,EACD,+BAA+B;AAAA,EAC/B,k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