@zyno-io/ts-server-foundation 26.712.36
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 +31 -0
- package/dist/devconsole/assets/index-BlWLbczn.css +1 -0
- package/dist/devconsole/assets/index-lSF6DUY3.js +3 -0
- package/dist/devconsole/index.html +13 -0
- package/dist/src/app/base.d.ts +66 -0
- package/dist/src/app/base.d.ts.map +1 -0
- package/dist/src/app/base.js +577 -0
- package/dist/src/app/base.js.map +1 -0
- package/dist/src/app/commands.d.ts +20 -0
- package/dist/src/app/commands.d.ts.map +1 -0
- package/dist/src/app/commands.js +17 -0
- package/dist/src/app/commands.js.map +1 -0
- package/dist/src/app/config-loader.d.ts +9 -0
- package/dist/src/app/config-loader.d.ts.map +1 -0
- package/dist/src/app/config-loader.js +91 -0
- package/dist/src/app/config-loader.js.map +1 -0
- package/dist/src/app/config.d.ts +96 -0
- package/dist/src/app/config.d.ts.map +1 -0
- package/dist/src/app/config.js +114 -0
- package/dist/src/app/config.js.map +1 -0
- package/dist/src/app/const.d.ts +5 -0
- package/dist/src/app/const.d.ts.map +1 -0
- package/dist/src/app/const.js +17 -0
- package/dist/src/app/const.js.map +1 -0
- package/dist/src/app/current.d.ts +5 -0
- package/dist/src/app/current.d.ts.map +1 -0
- package/dist/src/app/current.js +14 -0
- package/dist/src/app/current.js.map +1 -0
- package/dist/src/app/index.d.ts +8 -0
- package/dist/src/app/index.d.ts.map +1 -0
- package/dist/src/app/index.js +13 -0
- package/dist/src/app/index.js.map +1 -0
- package/dist/src/app/lifecycle.d.ts +9 -0
- package/dist/src/app/lifecycle.d.ts.map +1 -0
- package/dist/src/app/lifecycle.js +21 -0
- package/dist/src/app/lifecycle.js.map +1 -0
- package/dist/src/app/migrations-entrypoint.d.ts +3 -0
- package/dist/src/app/migrations-entrypoint.d.ts.map +1 -0
- package/dist/src/app/migrations-entrypoint.js +35 -0
- package/dist/src/app/migrations-entrypoint.js.map +1 -0
- package/dist/src/app/resolver.d.ts +6 -0
- package/dist/src/app/resolver.d.ts.map +1 -0
- package/dist/src/app/resolver.js +15 -0
- package/dist/src/app/resolver.js.map +1 -0
- package/dist/src/auth/index.d.ts +3 -0
- package/dist/src/auth/index.d.ts.map +1 -0
- package/dist/src/auth/index.js +15 -0
- package/dist/src/auth/index.js.map +1 -0
- package/dist/src/auth/jwt.d.ts +61 -0
- package/dist/src/auth/jwt.d.ts.map +1 -0
- package/dist/src/auth/jwt.js +379 -0
- package/dist/src/auth/jwt.js.map +1 -0
- package/dist/src/auth/provider.d.ts +21 -0
- package/dist/src/auth/provider.d.ts.map +1 -0
- package/dist/src/auth/provider.js +148 -0
- package/dist/src/auth/provider.js.map +1 -0
- package/dist/src/cli/common.d.ts +13 -0
- package/dist/src/cli/common.d.ts.map +1 -0
- package/dist/src/cli/common.js +99 -0
- package/dist/src/cli/common.js.map +1 -0
- package/dist/src/cli/tsf-create-app.d.ts +3 -0
- package/dist/src/cli/tsf-create-app.d.ts.map +1 -0
- package/dist/src/cli/tsf-create-app.js +89 -0
- package/dist/src/cli/tsf-create-app.js.map +1 -0
- package/dist/src/cli/tsf-dev.d.ts +3 -0
- package/dist/src/cli/tsf-dev.d.ts.map +1 -0
- package/dist/src/cli/tsf-dev.js +753 -0
- package/dist/src/cli/tsf-dev.js.map +1 -0
- package/dist/src/cli/tsf-gen-proto.d.ts +3 -0
- package/dist/src/cli/tsf-gen-proto.d.ts.map +1 -0
- package/dist/src/cli/tsf-gen-proto.js +134 -0
- package/dist/src/cli/tsf-gen-proto.js.map +1 -0
- package/dist/src/cli/tsf-install.d.ts +8 -0
- package/dist/src/cli/tsf-install.d.ts.map +1 -0
- package/dist/src/cli/tsf-install.js +424 -0
- package/dist/src/cli/tsf-install.js.map +1 -0
- package/dist/src/cli/tsf-migrate.d.ts +3 -0
- package/dist/src/cli/tsf-migrate.d.ts.map +1 -0
- package/dist/src/cli/tsf-migrate.js +271 -0
- package/dist/src/cli/tsf-migrate.js.map +1 -0
- package/dist/src/cli/tsf-test.d.ts +4 -0
- package/dist/src/cli/tsf-test.d.ts.map +1 -0
- package/dist/src/cli/tsf-test.js +350 -0
- package/dist/src/cli/tsf-test.js.map +1 -0
- package/dist/src/cli/tsf-update.d.ts +3 -0
- package/dist/src/cli/tsf-update.d.ts.map +1 -0
- package/dist/src/cli/tsf-update.js +12 -0
- package/dist/src/cli/tsf-update.js.map +1 -0
- package/dist/src/cli/tsf.d.ts +3 -0
- package/dist/src/cli/tsf.d.ts.map +1 -0
- package/dist/src/cli/tsf.js +29 -0
- package/dist/src/cli/tsf.js.map +1 -0
- package/dist/src/database/database.d.ts +54 -0
- package/dist/src/database/database.d.ts.map +1 -0
- package/dist/src/database/database.js +695 -0
- package/dist/src/database/database.js.map +1 -0
- package/dist/src/database/driver.d.ts +28 -0
- package/dist/src/database/driver.d.ts.map +1 -0
- package/dist/src/database/driver.js +5 -0
- package/dist/src/database/driver.js.map +1 -0
- package/dist/src/database/drivers/index.d.ts +4 -0
- package/dist/src/database/drivers/index.d.ts.map +1 -0
- package/dist/src/database/drivers/index.js +9 -0
- package/dist/src/database/drivers/index.js.map +1 -0
- package/dist/src/database/drivers/mysql-session-rpc.d.ts +40 -0
- package/dist/src/database/drivers/mysql-session-rpc.d.ts.map +1 -0
- package/dist/src/database/drivers/mysql-session-rpc.js +180 -0
- package/dist/src/database/drivers/mysql-session-rpc.js.map +1 -0
- package/dist/src/database/drivers/mysql-session.d.ts +25 -0
- package/dist/src/database/drivers/mysql-session.d.ts.map +1 -0
- package/dist/src/database/drivers/mysql-session.js +124 -0
- package/dist/src/database/drivers/mysql-session.js.map +1 -0
- package/dist/src/database/drivers/mysql.d.ts +20 -0
- package/dist/src/database/drivers/mysql.d.ts.map +1 -0
- package/dist/src/database/drivers/mysql.js +84 -0
- package/dist/src/database/drivers/mysql.js.map +1 -0
- package/dist/src/database/drivers/postgres.d.ts +22 -0
- package/dist/src/database/drivers/postgres.d.ts.map +1 -0
- package/dist/src/database/drivers/postgres.js +80 -0
- package/dist/src/database/drivers/postgres.js.map +1 -0
- package/dist/src/database/entity.d.ts +112 -0
- package/dist/src/database/entity.d.ts.map +1 -0
- package/dist/src/database/entity.js +333 -0
- package/dist/src/database/entity.js.map +1 -0
- package/dist/src/database/errors.d.ts +7 -0
- package/dist/src/database/errors.d.ts.map +1 -0
- package/dist/src/database/errors.js +34 -0
- package/dist/src/database/errors.js.map +1 -0
- package/dist/src/database/factory.d.ts +48 -0
- package/dist/src/database/factory.d.ts.map +1 -0
- package/dist/src/database/factory.js +139 -0
- package/dist/src/database/factory.js.map +1 -0
- package/dist/src/database/identifiers.d.ts +8 -0
- package/dist/src/database/identifiers.d.ts.map +1 -0
- package/dist/src/database/identifiers.js +46 -0
- package/dist/src/database/identifiers.js.map +1 -0
- package/dist/src/database/index.d.ts +14 -0
- package/dist/src/database/index.d.ts.map +1 -0
- package/dist/src/database/index.js +33 -0
- package/dist/src/database/index.js.map +1 -0
- package/dist/src/database/metadata.d.ts +27 -0
- package/dist/src/database/metadata.d.ts.map +1 -0
- package/dist/src/database/metadata.js +70 -0
- package/dist/src/database/metadata.js.map +1 -0
- package/dist/src/database/migration/create/comparator.d.ts +3 -0
- package/dist/src/database/migration/create/comparator.d.ts.map +1 -0
- package/dist/src/database/migration/create/comparator.js +302 -0
- package/dist/src/database/migration/create/comparator.js.map +1 -0
- package/dist/src/database/migration/create/db-reader.d.ts +9 -0
- package/dist/src/database/migration/create/db-reader.d.ts.map +1 -0
- package/dist/src/database/migration/create/db-reader.js +478 -0
- package/dist/src/database/migration/create/db-reader.js.map +1 -0
- package/dist/src/database/migration/create/ddl-generator.d.ts +4 -0
- package/dist/src/database/migration/create/ddl-generator.d.ts.map +1 -0
- package/dist/src/database/migration/create/ddl-generator.js +431 -0
- package/dist/src/database/migration/create/ddl-generator.js.map +1 -0
- package/dist/src/database/migration/create/entity-reader.d.ts +7 -0
- package/dist/src/database/migration/create/entity-reader.d.ts.map +1 -0
- package/dist/src/database/migration/create/entity-reader.js +169 -0
- package/dist/src/database/migration/create/entity-reader.js.map +1 -0
- package/dist/src/database/migration/create/file-generator.d.ts +7 -0
- package/dist/src/database/migration/create/file-generator.d.ts.map +1 -0
- package/dist/src/database/migration/create/file-generator.js +60 -0
- package/dist/src/database/migration/create/file-generator.js.map +1 -0
- package/dist/src/database/migration/create/index.d.ts +19 -0
- package/dist/src/database/migration/create/index.d.ts.map +1 -0
- package/dist/src/database/migration/create/index.js +102 -0
- package/dist/src/database/migration/create/index.js.map +1 -0
- package/dist/src/database/migration/create/schema-model.d.ts +99 -0
- package/dist/src/database/migration/create/schema-model.d.ts.map +1 -0
- package/dist/src/database/migration/create/schema-model.js +24 -0
- package/dist/src/database/migration/create/schema-model.js.map +1 -0
- package/dist/src/database/migration/create/type-mapper.d.ts +13 -0
- package/dist/src/database/migration/create/type-mapper.d.ts.map +1 -0
- package/dist/src/database/migration/create/type-mapper.js +293 -0
- package/dist/src/database/migration/create/type-mapper.js.map +1 -0
- package/dist/src/database/migration/index.d.ts +33 -0
- package/dist/src/database/migration/index.d.ts.map +1 -0
- package/dist/src/database/migration/index.js +165 -0
- package/dist/src/database/migration/index.js.map +1 -0
- package/dist/src/database/migration/maintenance.d.ts +26 -0
- package/dist/src/database/migration/maintenance.d.ts.map +1 -0
- package/dist/src/database/migration/maintenance.js +65 -0
- package/dist/src/database/migration/maintenance.js.map +1 -0
- package/dist/src/database/query.d.ts +79 -0
- package/dist/src/database/query.d.ts.map +1 -0
- package/dist/src/database/query.js +435 -0
- package/dist/src/database/query.js.map +1 -0
- package/dist/src/database/schema.d.ts +147 -0
- package/dist/src/database/schema.d.ts.map +1 -0
- package/dist/src/database/schema.js +709 -0
- package/dist/src/database/schema.js.map +1 -0
- package/dist/src/database/session.d.ts +63 -0
- package/dist/src/database/session.d.ts.map +1 -0
- package/dist/src/database/session.js +226 -0
- package/dist/src/database/session.js.map +1 -0
- package/dist/src/database/sql.d.ts +37 -0
- package/dist/src/database/sql.d.ts.map +1 -0
- package/dist/src/database/sql.js +143 -0
- package/dist/src/database/sql.js.map +1 -0
- package/dist/src/database/values.d.ts +6 -0
- package/dist/src/database/values.d.ts.map +1 -0
- package/dist/src/database/values.js +237 -0
- package/dist/src/database/values.js.map +1 -0
- package/dist/src/devconsole/controller.d.ts +11 -0
- package/dist/src/devconsole/controller.d.ts.map +1 -0
- package/dist/src/devconsole/controller.js +78 -0
- package/dist/src/devconsole/controller.js.map +1 -0
- package/dist/src/devconsole/generated/devconsole.d.ts +306 -0
- package/dist/src/devconsole/generated/devconsole.d.ts.map +1 -0
- package/dist/src/devconsole/generated/devconsole.js +4029 -0
- package/dist/src/devconsole/generated/devconsole.js.map +1 -0
- package/dist/src/devconsole/index.d.ts +10 -0
- package/dist/src/devconsole/index.d.ts.map +1 -0
- package/dist/src/devconsole/index.js +26 -0
- package/dist/src/devconsole/index.js.map +1 -0
- package/dist/src/devconsole/observers.d.ts +4 -0
- package/dist/src/devconsole/observers.d.ts.map +1 -0
- package/dist/src/devconsole/observers.js +170 -0
- package/dist/src/devconsole/observers.js.map +1 -0
- package/dist/src/devconsole/runtime.d.ts +16 -0
- package/dist/src/devconsole/runtime.d.ts.map +1 -0
- package/dist/src/devconsole/runtime.js +48 -0
- package/dist/src/devconsole/runtime.js.map +1 -0
- package/dist/src/devconsole/security.d.ts +8 -0
- package/dist/src/devconsole/security.d.ts.map +1 -0
- package/dist/src/devconsole/security.js +33 -0
- package/dist/src/devconsole/security.js.map +1 -0
- package/dist/src/devconsole/server.d.ts +25 -0
- package/dist/src/devconsole/server.d.ts.map +1 -0
- package/dist/src/devconsole/server.js +452 -0
- package/dist/src/devconsole/server.js.map +1 -0
- package/dist/src/devconsole/store.d.ts +111 -0
- package/dist/src/devconsole/store.d.ts.map +1 -0
- package/dist/src/devconsole/store.js +177 -0
- package/dist/src/devconsole/store.js.map +1 -0
- package/dist/src/di/container.d.ts +38 -0
- package/dist/src/di/container.d.ts.map +1 -0
- package/dist/src/di/container.js +252 -0
- package/dist/src/di/container.js.map +1 -0
- package/dist/src/di/errors.d.ts +18 -0
- package/dist/src/di/errors.d.ts.map +1 -0
- package/dist/src/di/errors.js +71 -0
- package/dist/src/di/errors.js.map +1 -0
- package/dist/src/di/index.d.ts +5 -0
- package/dist/src/di/index.d.ts.map +1 -0
- package/dist/src/di/index.js +10 -0
- package/dist/src/di/index.js.map +1 -0
- package/dist/src/di/module.d.ts +29 -0
- package/dist/src/di/module.d.ts.map +1 -0
- package/dist/src/di/module.js +42 -0
- package/dist/src/di/module.js.map +1 -0
- package/dist/src/di/provider.d.ts +34 -0
- package/dist/src/di/provider.d.ts.map +1 -0
- package/dist/src/di/provider.js +24 -0
- package/dist/src/di/provider.js.map +1 -0
- package/dist/src/env.d.ts +122 -0
- package/dist/src/env.d.ts.map +1 -0
- package/dist/src/env.js +61 -0
- package/dist/src/env.js.map +1 -0
- package/dist/src/events/event-bus.d.ts +26 -0
- package/dist/src/events/event-bus.d.ts.map +1 -0
- package/dist/src/events/event-bus.js +67 -0
- package/dist/src/events/event-bus.js.map +1 -0
- package/dist/src/events/index.d.ts +2 -0
- package/dist/src/events/index.d.ts.map +1 -0
- package/dist/src/events/index.js +7 -0
- package/dist/src/events/index.js.map +1 -0
- package/dist/src/health/healthcheck.controller.d.ts +9 -0
- package/dist/src/health/healthcheck.controller.d.ts.map +1 -0
- package/dist/src/health/healthcheck.controller.js +33 -0
- package/dist/src/health/healthcheck.controller.js.map +1 -0
- package/dist/src/health/healthcheck.service.d.ts +13 -0
- package/dist/src/health/healthcheck.service.d.ts.map +1 -0
- package/dist/src/health/healthcheck.service.js +37 -0
- package/dist/src/health/healthcheck.service.js.map +1 -0
- package/dist/src/health/index.d.ts +3 -0
- package/dist/src/health/index.d.ts.map +1 -0
- package/dist/src/health/index.js +8 -0
- package/dist/src/health/index.js.map +1 -0
- package/dist/src/helpers/async/context.d.ts +10 -0
- package/dist/src/helpers/async/context.d.ts.map +1 -0
- package/dist/src/helpers/async/context.js +52 -0
- package/dist/src/helpers/async/context.js.map +1 -0
- package/dist/src/helpers/async/process.d.ts +16 -0
- package/dist/src/helpers/async/process.d.ts.map +1 -0
- package/dist/src/helpers/async/process.js +62 -0
- package/dist/src/helpers/async/process.js.map +1 -0
- package/dist/src/helpers/async/promise.d.ts +11 -0
- package/dist/src/helpers/async/promise.d.ts.map +1 -0
- package/dist/src/helpers/async/promise.js +32 -0
- package/dist/src/helpers/async/promise.js.map +1 -0
- package/dist/src/helpers/data/array.d.ts +5 -0
- package/dist/src/helpers/data/array.d.ts.map +1 -0
- package/dist/src/helpers/data/array.js +27 -0
- package/dist/src/helpers/data/array.js.map +1 -0
- package/dist/src/helpers/data/objects.d.ts +13 -0
- package/dist/src/helpers/data/objects.d.ts.map +1 -0
- package/dist/src/helpers/data/objects.js +55 -0
- package/dist/src/helpers/data/objects.js.map +1 -0
- package/dist/src/helpers/data/serialization.d.ts +5 -0
- package/dist/src/helpers/data/serialization.d.ts.map +1 -0
- package/dist/src/helpers/data/serialization.js +25 -0
- package/dist/src/helpers/data/serialization.js.map +1 -0
- package/dist/src/helpers/data/transformer.d.ts +13 -0
- package/dist/src/helpers/data/transformer.d.ts.map +1 -0
- package/dist/src/helpers/data/transformer.js +50 -0
- package/dist/src/helpers/data/transformer.js.map +1 -0
- package/dist/src/helpers/index.d.ts +19 -0
- package/dist/src/helpers/index.d.ts.map +1 -0
- package/dist/src/helpers/index.js +30 -0
- package/dist/src/helpers/index.js.map +1 -0
- package/dist/src/helpers/io/package.d.ts +10 -0
- package/dist/src/helpers/io/package.d.ts.map +1 -0
- package/dist/src/helpers/io/package.js +35 -0
- package/dist/src/helpers/io/package.js.map +1 -0
- package/dist/src/helpers/io/stream.d.ts +18 -0
- package/dist/src/helpers/io/stream.d.ts.map +1 -0
- package/dist/src/helpers/io/stream.js +131 -0
- package/dist/src/helpers/io/stream.js.map +1 -0
- package/dist/src/helpers/redis/broadcast.d.ts +15 -0
- package/dist/src/helpers/redis/broadcast.d.ts.map +1 -0
- package/dist/src/helpers/redis/broadcast.js +93 -0
- package/dist/src/helpers/redis/broadcast.js.map +1 -0
- package/dist/src/helpers/redis/cache.d.ts +20 -0
- package/dist/src/helpers/redis/cache.d.ts.map +1 -0
- package/dist/src/helpers/redis/cache.js +57 -0
- package/dist/src/helpers/redis/cache.js.map +1 -0
- package/dist/src/helpers/redis/mutex.d.ts +45 -0
- package/dist/src/helpers/redis/mutex.d.ts.map +1 -0
- package/dist/src/helpers/redis/mutex.js +446 -0
- package/dist/src/helpers/redis/mutex.js.map +1 -0
- package/dist/src/helpers/redis/redis.d.ts +12 -0
- package/dist/src/helpers/redis/redis.d.ts.map +1 -0
- package/dist/src/helpers/redis/redis.js +62 -0
- package/dist/src/helpers/redis/redis.js.map +1 -0
- package/dist/src/helpers/security/crypto.d.ts +31 -0
- package/dist/src/helpers/security/crypto.d.ts.map +1 -0
- package/dist/src/helpers/security/crypto.js +108 -0
- package/dist/src/helpers/security/crypto.js.map +1 -0
- package/dist/src/helpers/security/validation.d.ts +3 -0
- package/dist/src/helpers/security/validation.d.ts.map +1 -0
- package/dist/src/helpers/security/validation.js +14 -0
- package/dist/src/helpers/security/validation.js.map +1 -0
- package/dist/src/helpers/utils/date.d.ts +4 -0
- package/dist/src/helpers/utils/date.d.ts.map +1 -0
- package/dist/src/helpers/utils/date.js +16 -0
- package/dist/src/helpers/utils/date.js.map +1 -0
- package/dist/src/helpers/utils/error.d.ts +20 -0
- package/dist/src/helpers/utils/error.d.ts.map +1 -0
- package/dist/src/helpers/utils/error.js +164 -0
- package/dist/src/helpers/utils/error.js.map +1 -0
- package/dist/src/helpers/utils/uuid.d.ts +5 -0
- package/dist/src/helpers/utils/uuid.d.ts.map +1 -0
- package/dist/src/helpers/utils/uuid.js +13 -0
- package/dist/src/helpers/utils/uuid.js.map +1 -0
- package/dist/src/http/auth.d.ts +20 -0
- package/dist/src/http/auth.d.ts.map +1 -0
- package/dist/src/http/auth.js +68 -0
- package/dist/src/http/auth.js.map +1 -0
- package/dist/src/http/base.d.ts +57 -0
- package/dist/src/http/base.d.ts.map +1 -0
- package/dist/src/http/base.js +331 -0
- package/dist/src/http/base.js.map +1 -0
- package/dist/src/http/context.d.ts +6 -0
- package/dist/src/http/context.d.ts.map +1 -0
- package/dist/src/http/context.js +26 -0
- package/dist/src/http/context.js.map +1 -0
- package/dist/src/http/cors.d.ts +25 -0
- package/dist/src/http/cors.d.ts.map +1 -0
- package/dist/src/http/cors.js +124 -0
- package/dist/src/http/cors.js.map +1 -0
- package/dist/src/http/decorators.d.ts +64 -0
- package/dist/src/http/decorators.d.ts.map +1 -0
- package/dist/src/http/decorators.js +102 -0
- package/dist/src/http/decorators.js.map +1 -0
- package/dist/src/http/errors.d.ts +50 -0
- package/dist/src/http/errors.d.ts.map +1 -0
- package/dist/src/http/errors.js +158 -0
- package/dist/src/http/errors.js.map +1 -0
- package/dist/src/http/index.d.ts +31 -0
- package/dist/src/http/index.d.ts.map +1 -0
- package/dist/src/http/index.js +33 -0
- package/dist/src/http/index.js.map +1 -0
- package/dist/src/http/middleware.d.ts +12 -0
- package/dist/src/http/middleware.d.ts.map +1 -0
- package/dist/src/http/middleware.js +31 -0
- package/dist/src/http/middleware.js.map +1 -0
- package/dist/src/http/parameter-resolvers.d.ts +3 -0
- package/dist/src/http/parameter-resolvers.d.ts.map +1 -0
- package/dist/src/http/parameter-resolvers.js +8 -0
- package/dist/src/http/parameter-resolvers.js.map +1 -0
- package/dist/src/http/request-logging.d.ts +34 -0
- package/dist/src/http/request-logging.d.ts.map +1 -0
- package/dist/src/http/request-logging.js +130 -0
- package/dist/src/http/request-logging.js.map +1 -0
- package/dist/src/http/request.d.ts +69 -0
- package/dist/src/http/request.d.ts.map +1 -0
- package/dist/src/http/request.js +366 -0
- package/dist/src/http/request.js.map +1 -0
- package/dist/src/http/response.d.ts +98 -0
- package/dist/src/http/response.d.ts.map +1 -0
- package/dist/src/http/response.js +292 -0
- package/dist/src/http/response.js.map +1 -0
- package/dist/src/http/router.d.ts +100 -0
- package/dist/src/http/router.d.ts.map +1 -0
- package/dist/src/http/router.js +1085 -0
- package/dist/src/http/router.js.map +1 -0
- package/dist/src/http/startup-logging.d.ts +8 -0
- package/dist/src/http/startup-logging.d.ts.map +1 -0
- package/dist/src/http/startup-logging.js +55 -0
- package/dist/src/http/startup-logging.js.map +1 -0
- package/dist/src/http/static-files.d.ts +15 -0
- package/dist/src/http/static-files.d.ts.map +1 -0
- package/dist/src/http/static-files.js +110 -0
- package/dist/src/http/static-files.js.map +1 -0
- package/dist/src/http/store.d.ts +8 -0
- package/dist/src/http/store.d.ts.map +1 -0
- package/dist/src/http/store.js +47 -0
- package/dist/src/http/store.js.map +1 -0
- package/dist/src/http/types.d.ts +23 -0
- package/dist/src/http/types.d.ts.map +1 -0
- package/dist/src/http/types.js +3 -0
- package/dist/src/http/types.js.map +1 -0
- package/dist/src/http/upgrade.d.ts +22 -0
- package/dist/src/http/upgrade.d.ts.map +1 -0
- package/dist/src/http/upgrade.js +164 -0
- package/dist/src/http/upgrade.js.map +1 -0
- package/dist/src/http/uploads.d.ts +36 -0
- package/dist/src/http/uploads.d.ts.map +1 -0
- package/dist/src/http/uploads.js +287 -0
- package/dist/src/http/uploads.js.map +1 -0
- package/dist/src/http/workflow.d.ts +34 -0
- package/dist/src/http/workflow.d.ts.map +1 -0
- package/dist/src/http/workflow.js +40 -0
- package/dist/src/http/workflow.js.map +1 -0
- package/dist/src/index.d.ts +21 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +88 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/openapi/controller.d.ts +9 -0
- package/dist/src/openapi/controller.d.ts.map +1 -0
- package/dist/src/openapi/controller.js +45 -0
- package/dist/src/openapi/controller.js.map +1 -0
- package/dist/src/openapi/index.d.ts +5 -0
- package/dist/src/openapi/index.d.ts.map +1 -0
- package/dist/src/openapi/index.js +21 -0
- package/dist/src/openapi/index.js.map +1 -0
- package/dist/src/openapi/schema.d.ts +26 -0
- package/dist/src/openapi/schema.d.ts.map +1 -0
- package/dist/src/openapi/schema.js +1128 -0
- package/dist/src/openapi/schema.js.map +1 -0
- package/dist/src/openapi/serializer.d.ts +16 -0
- package/dist/src/openapi/serializer.d.ts.map +1 -0
- package/dist/src/openapi/serializer.js +506 -0
- package/dist/src/openapi/serializer.js.map +1 -0
- package/dist/src/openapi/types.d.ts +84 -0
- package/dist/src/openapi/types.d.ts.map +1 -0
- package/dist/src/openapi/types.js +5 -0
- package/dist/src/openapi/types.js.map +1 -0
- package/dist/src/reflection/annotations.d.ts +15 -0
- package/dist/src/reflection/annotations.d.ts.map +1 -0
- package/dist/src/reflection/annotations.js +228 -0
- package/dist/src/reflection/annotations.js.map +1 -0
- package/dist/src/reflection/conversion.d.ts +15 -0
- package/dist/src/reflection/conversion.d.ts.map +1 -0
- package/dist/src/reflection/conversion.js +360 -0
- package/dist/src/reflection/conversion.js.map +1 -0
- package/dist/src/reflection/deserializer.d.ts +15 -0
- package/dist/src/reflection/deserializer.d.ts.map +1 -0
- package/dist/src/reflection/deserializer.js +42 -0
- package/dist/src/reflection/deserializer.js.map +1 -0
- package/dist/src/reflection/entity.d.ts +9 -0
- package/dist/src/reflection/entity.d.ts.map +1 -0
- package/dist/src/reflection/entity.js +74 -0
- package/dist/src/reflection/entity.js.map +1 -0
- package/dist/src/reflection/errors.d.ts +8 -0
- package/dist/src/reflection/errors.d.ts.map +1 -0
- package/dist/src/reflection/errors.js +21 -0
- package/dist/src/reflection/errors.js.map +1 -0
- package/dist/src/reflection/index.d.ts +8 -0
- package/dist/src/reflection/index.d.ts.map +1 -0
- package/dist/src/reflection/index.js +13 -0
- package/dist/src/reflection/index.js.map +1 -0
- package/dist/src/reflection/metadata-store.d.ts +14 -0
- package/dist/src/reflection/metadata-store.d.ts.map +1 -0
- package/dist/src/reflection/metadata-store.js +18 -0
- package/dist/src/reflection/metadata-store.js.map +1 -0
- package/dist/src/reflection/model.d.ts +271 -0
- package/dist/src/reflection/model.d.ts.map +1 -0
- package/dist/src/reflection/model.js +36 -0
- package/dist/src/reflection/model.js.map +1 -0
- package/dist/src/reflection/reflection-class.d.ts +60 -0
- package/dist/src/reflection/reflection-class.d.ts.map +1 -0
- package/dist/src/reflection/reflection-class.js +263 -0
- package/dist/src/reflection/reflection-class.js.map +1 -0
- package/dist/src/reflection/type-utils.d.ts +34 -0
- package/dist/src/reflection/type-utils.d.ts.map +1 -0
- package/dist/src/reflection/type-utils.js +485 -0
- package/dist/src/reflection/type-utils.js.map +1 -0
- package/dist/src/reflection.d.ts +2 -0
- package/dist/src/reflection.d.ts.map +1 -0
- package/dist/src/reflection.js +5 -0
- package/dist/src/reflection.js.map +1 -0
- package/dist/src/services/cli.d.ts +9 -0
- package/dist/src/services/cli.d.ts.map +1 -0
- package/dist/src/services/cli.js +47 -0
- package/dist/src/services/cli.js.map +1 -0
- package/dist/src/services/index.d.ts +8 -0
- package/dist/src/services/index.d.ts.map +1 -0
- package/dist/src/services/index.js +13 -0
- package/dist/src/services/index.js.map +1 -0
- package/dist/src/services/leader.d.ts +31 -0
- package/dist/src/services/leader.d.ts.map +1 -0
- package/dist/src/services/leader.js +176 -0
- package/dist/src/services/leader.js.map +1 -0
- package/dist/src/services/logger.d.ts +60 -0
- package/dist/src/services/logger.d.ts.map +1 -0
- package/dist/src/services/logger.js +349 -0
- package/dist/src/services/logger.js.map +1 -0
- package/dist/src/services/mail/index.d.ts +57 -0
- package/dist/src/services/mail/index.d.ts.map +1 -0
- package/dist/src/services/mail/index.js +89 -0
- package/dist/src/services/mail/index.js.map +1 -0
- package/dist/src/services/mail/postmark.d.ts +11 -0
- package/dist/src/services/mail/postmark.d.ts.map +1 -0
- package/dist/src/services/mail/postmark.js +41 -0
- package/dist/src/services/mail/postmark.js.map +1 -0
- package/dist/src/services/mail/smtp.d.ts +11 -0
- package/dist/src/services/mail/smtp.d.ts.map +1 -0
- package/dist/src/services/mail/smtp.js +50 -0
- package/dist/src/services/mail/smtp.js.map +1 -0
- package/dist/src/services/mesh-client/index.d.ts +9 -0
- package/dist/src/services/mesh-client/index.d.ts.map +1 -0
- package/dist/src/services/mesh-client/index.js +18 -0
- package/dist/src/services/mesh-client/index.js.map +1 -0
- package/dist/src/services/mesh-client/mesh-client-redis-registry.d.ts +23 -0
- package/dist/src/services/mesh-client/mesh-client-redis-registry.d.ts.map +1 -0
- package/dist/src/services/mesh-client/mesh-client-redis-registry.js +360 -0
- package/dist/src/services/mesh-client/mesh-client-redis-registry.js.map +1 -0
- package/dist/src/services/mesh-client/mesh-client-registry.d.ts +16 -0
- package/dist/src/services/mesh-client/mesh-client-registry.d.ts.map +1 -0
- package/dist/src/services/mesh-client/mesh-client-registry.js +44 -0
- package/dist/src/services/mesh-client/mesh-client-registry.js.map +1 -0
- package/dist/src/services/mesh-client/mesh-client-service.d.ts +88 -0
- package/dist/src/services/mesh-client/mesh-client-service.d.ts.map +1 -0
- package/dist/src/services/mesh-client/mesh-client-service.js +222 -0
- package/dist/src/services/mesh-client/mesh-client-service.js.map +1 -0
- package/dist/src/services/mesh-client/mesh-srpc-server.d.ts +95 -0
- package/dist/src/services/mesh-client/mesh-srpc-server.d.ts.map +1 -0
- package/dist/src/services/mesh-client/mesh-srpc-server.js +475 -0
- package/dist/src/services/mesh-client/mesh-srpc-server.js.map +1 -0
- package/dist/src/services/mesh-client/types.d.ts +36 -0
- package/dist/src/services/mesh-client/types.d.ts.map +1 -0
- package/dist/src/services/mesh-client/types.js +38 -0
- package/dist/src/services/mesh-client/types.js.map +1 -0
- package/dist/src/services/mesh.d.ts +73 -0
- package/dist/src/services/mesh.d.ts.map +1 -0
- package/dist/src/services/mesh.js +511 -0
- package/dist/src/services/mesh.js.map +1 -0
- package/dist/src/services/worker/entity.d.ts +26 -0
- package/dist/src/services/worker/entity.d.ts.map +1 -0
- package/dist/src/services/worker/entity.js +30 -0
- package/dist/src/services/worker/entity.js.map +1 -0
- package/dist/src/services/worker/index.d.ts +25 -0
- package/dist/src/services/worker/index.d.ts.map +1 -0
- package/dist/src/services/worker/index.js +52 -0
- package/dist/src/services/worker/index.js.map +1 -0
- package/dist/src/services/worker/observer.d.ts +13 -0
- package/dist/src/services/worker/observer.d.ts.map +1 -0
- package/dist/src/services/worker/observer.js +22 -0
- package/dist/src/services/worker/observer.js.map +1 -0
- package/dist/src/services/worker/queue.d.ts +38 -0
- package/dist/src/services/worker/queue.d.ts.map +1 -0
- package/dist/src/services/worker/queue.js +227 -0
- package/dist/src/services/worker/queue.js.map +1 -0
- package/dist/src/services/worker/recorder.d.ts +17 -0
- package/dist/src/services/worker/recorder.d.ts.map +1 -0
- package/dist/src/services/worker/recorder.js +88 -0
- package/dist/src/services/worker/recorder.js.map +1 -0
- package/dist/src/services/worker/runner.d.ts +37 -0
- package/dist/src/services/worker/runner.d.ts.map +1 -0
- package/dist/src/services/worker/runner.js +319 -0
- package/dist/src/services/worker/runner.js.map +1 -0
- package/dist/src/services/worker/types.d.ts +63 -0
- package/dist/src/services/worker/types.d.ts.map +1 -0
- package/dist/src/services/worker/types.js +38 -0
- package/dist/src/services/worker/types.js.map +1 -0
- package/dist/src/srpc/SrpcByteStream.d.ts +60 -0
- package/dist/src/srpc/SrpcByteStream.d.ts.map +1 -0
- package/dist/src/srpc/SrpcByteStream.js +237 -0
- package/dist/src/srpc/SrpcByteStream.js.map +1 -0
- package/dist/src/srpc/SrpcClient.d.ts +67 -0
- package/dist/src/srpc/SrpcClient.d.ts.map +1 -0
- package/dist/src/srpc/SrpcClient.js +406 -0
- package/dist/src/srpc/SrpcClient.js.map +1 -0
- package/dist/src/srpc/SrpcServer.d.ts +56 -0
- package/dist/src/srpc/SrpcServer.d.ts.map +1 -0
- package/dist/src/srpc/SrpcServer.js +519 -0
- package/dist/src/srpc/SrpcServer.js.map +1 -0
- package/dist/src/srpc/index.d.ts +9 -0
- package/dist/src/srpc/index.d.ts.map +1 -0
- package/dist/src/srpc/index.js +17 -0
- package/dist/src/srpc/index.js.map +1 -0
- package/dist/src/srpc/observer.d.ts +21 -0
- package/dist/src/srpc/observer.d.ts.map +1 -0
- package/dist/src/srpc/observer.js +22 -0
- package/dist/src/srpc/observer.js.map +1 -0
- package/dist/src/srpc/types.d.ts +92 -0
- package/dist/src/srpc/types.d.ts.map +1 -0
- package/dist/src/srpc/types.js +28 -0
- package/dist/src/srpc/types.js.map +1 -0
- package/dist/src/telemetry/index.d.ts +3 -0
- package/dist/src/telemetry/index.d.ts.map +1 -0
- package/dist/src/telemetry/index.js +22 -0
- package/dist/src/telemetry/index.js.map +1 -0
- package/dist/src/telemetry/otel/helpers.d.ts +45 -0
- package/dist/src/telemetry/otel/helpers.d.ts.map +1 -0
- package/dist/src/telemetry/otel/helpers.js +142 -0
- package/dist/src/telemetry/otel/helpers.js.map +1 -0
- package/dist/src/telemetry/otel/index.d.ts +22 -0
- package/dist/src/telemetry/otel/index.d.ts.map +1 -0
- package/dist/src/telemetry/otel/index.js +268 -0
- package/dist/src/telemetry/otel/index.js.map +1 -0
- package/dist/src/telemetry/otel/metrics.controller.d.ts +5 -0
- package/dist/src/telemetry/otel/metrics.controller.d.ts.map +1 -0
- package/dist/src/telemetry/otel/metrics.controller.js +82 -0
- package/dist/src/telemetry/otel/metrics.controller.js.map +1 -0
- package/dist/src/telemetry/otel/metrics.d.ts +2 -0
- package/dist/src/telemetry/otel/metrics.d.ts.map +1 -0
- package/dist/src/telemetry/otel/metrics.js +16 -0
- package/dist/src/telemetry/otel/metrics.js.map +1 -0
- package/dist/src/telemetry/sentry.d.ts +9 -0
- package/dist/src/telemetry/sentry.d.ts.map +1 -0
- package/dist/src/telemetry/sentry.js +63 -0
- package/dist/src/telemetry/sentry.js.map +1 -0
- package/dist/src/testing/database-readiness.d.ts +11 -0
- package/dist/src/testing/database-readiness.d.ts.map +1 -0
- package/dist/src/testing/database-readiness.js +102 -0
- package/dist/src/testing/database-readiness.js.map +1 -0
- package/dist/src/testing/expect.d.ts +21 -0
- package/dist/src/testing/expect.d.ts.map +1 -0
- package/dist/src/testing/expect.js +110 -0
- package/dist/src/testing/expect.js.map +1 -0
- package/dist/src/testing/fixtures.d.ts +18 -0
- package/dist/src/testing/fixtures.d.ts.map +1 -0
- package/dist/src/testing/fixtures.js +46 -0
- package/dist/src/testing/fixtures.js.map +1 -0
- package/dist/src/testing/index.d.ts +143 -0
- package/dist/src/testing/index.d.ts.map +1 -0
- package/dist/src/testing/index.js +993 -0
- package/dist/src/testing/index.js.map +1 -0
- package/dist/src/testing/mysql-session-manager-process.d.ts +3 -0
- package/dist/src/testing/mysql-session-manager-process.d.ts.map +1 -0
- package/dist/src/testing/mysql-session-manager-process.js +77 -0
- package/dist/src/testing/mysql-session-manager-process.js.map +1 -0
- package/dist/src/testing/mysql-session-manager.d.ts +59 -0
- package/dist/src/testing/mysql-session-manager.d.ts.map +1 -0
- package/dist/src/testing/mysql-session-manager.js +910 -0
- package/dist/src/testing/mysql-session-manager.js.map +1 -0
- package/dist/src/testing/sql.d.ts +47 -0
- package/dist/src/testing/sql.d.ts.map +1 -0
- package/dist/src/testing/sql.js +313 -0
- package/dist/src/testing/sql.js.map +1 -0
- package/dist/src/type-compiler/go/ast_expression.go +161 -0
- package/dist/src/type-compiler/go/ast_metadata.go +355 -0
- package/dist/src/type-compiler/go/collect.go +806 -0
- package/dist/src/type-compiler/go/emission_plan.go +205 -0
- package/dist/src/type-compiler/go/emit_ast.go +406 -0
- package/dist/src/type-compiler/go/emit_ast_test.go +248 -0
- package/dist/src/type-compiler/go/go.mod +10 -0
- package/dist/src/type-compiler/go/plugin.go +308 -0
- package/dist/src/type-compiler/go/plugin_test.go +752 -0
- package/dist/src/type-compiler/go/precompute.go +86 -0
- package/dist/src/type-compiler/go/receive_type.go +837 -0
- package/dist/src/type-compiler/go/resolve.go +265 -0
- package/dist/src/type-compiler/go/source_scan.go +51 -0
- package/dist/src/type-compiler/go/text_parse.go +671 -0
- package/dist/src/type-compiler/go/type_expr.go +1227 -0
- package/dist/src/type-compiler/go/typia_expr.go +2119 -0
- package/dist/src/type-compiler/index.cjs +6 -0
- package/dist/src/types/index.d.ts +7 -0
- package/dist/src/types/index.d.ts.map +1 -0
- package/dist/src/types/index.js +14 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/types/phone.d.ts +6 -0
- package/dist/src/types/phone.d.ts.map +1 -0
- package/dist/src/types/phone.js +64 -0
- package/dist/src/types/phone.js.map +1 -0
- package/dist/src/types/primitives.d.ts +33 -0
- package/dist/src/types/primitives.d.ts.map +1 -0
- package/dist/src/types/primitives.js +5 -0
- package/dist/src/types/primitives.js.map +1 -0
- package/dist/src/types/runtime.d.ts +5 -0
- package/dist/src/types/runtime.d.ts.map +1 -0
- package/dist/src/types/runtime.js +20 -0
- package/dist/src/types/runtime.js.map +1 -0
- package/dist/src/types/type-annotations.d.ts +28 -0
- package/dist/src/types/type-annotations.d.ts.map +1 -0
- package/dist/src/types/type-annotations.js +33 -0
- package/dist/src/types/type-annotations.js.map +1 -0
- package/dist/src/types.d.ts +2 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +7 -0
- package/dist/src/types.js.map +1 -0
- package/docs/.vitepress/config.mts +85 -0
- package/docs/content/CONTRIBUTING.md +53 -0
- package/docs/content/README-DEV.md +59 -0
- package/docs/content/README.md +52 -0
- package/docs/content/authentication.md +213 -0
- package/docs/content/cli.md +214 -0
- package/docs/content/configuration.md +191 -0
- package/docs/content/database.md +476 -0
- package/docs/content/devconsole.md +148 -0
- package/docs/content/di.md +212 -0
- package/docs/content/documentation-plan.md +182 -0
- package/docs/content/env.md +120 -0
- package/docs/content/getting-started.md +324 -0
- package/docs/content/health.md +64 -0
- package/docs/content/helpers.md +294 -0
- package/docs/content/http.md +402 -0
- package/docs/content/index.md +109 -0
- package/docs/content/leader-service.md +98 -0
- package/docs/content/logging.md +225 -0
- package/docs/content/mail.md +171 -0
- package/docs/content/mesh-client.md +333 -0
- package/docs/content/mesh-service.md +255 -0
- package/docs/content/migrations.md +190 -0
- package/docs/content/openapi.md +134 -0
- package/docs/content/overview.md +98 -0
- package/docs/content/public/images/devconsole/01-dashboard.png +0 -0
- package/docs/content/public/images/devconsole/02-routes.png +0 -0
- package/docs/content/public/images/devconsole/03-openapi.png +0 -0
- package/docs/content/public/images/devconsole/04-requests.png +0 -0
- package/docs/content/public/images/devconsole/05-srpc.png +0 -0
- package/docs/content/public/images/devconsole/06-database.png +0 -0
- package/docs/content/public/images/devconsole/06b-database-log.png +0 -0
- package/docs/content/public/images/devconsole/07-health.png +0 -0
- package/docs/content/public/images/devconsole/08-mutex.png +0 -0
- package/docs/content/public/images/devconsole/09-repl.png +0 -0
- package/docs/content/public/images/devconsole/10-workers.png +0 -0
- package/docs/content/public-api.md +84 -0
- package/docs/content/redis.md +174 -0
- package/docs/content/reflection.md +180 -0
- package/docs/content/release.md +100 -0
- package/docs/content/sql.md +121 -0
- package/docs/content/srpc.md +292 -0
- package/docs/content/telemetry.md +173 -0
- package/docs/content/testing.md +327 -0
- package/docs/content/type-reflection-architecture.md +149 -0
- package/docs/content/types.md +286 -0
- package/docs/content/uploads.md +145 -0
- package/docs/content/worker.md +182 -0
- package/docs/openapi.md +3 -0
- package/package.json +124 -0
- package/resources/proto/devconsole.proto +286 -0
- package/template-app/.env.development +10 -0
- package/template-app/gitignore.tmpl +11 -0
- package/template-app/package.json.tmpl +25 -0
- package/template-app/src/app.ts +13 -0
- package/template-app/src/config.ts +5 -0
- package/template-app/src/controllers/Example.controller.ts +19 -0
- package/template-app/src/database.ts +5 -0
- package/template-app/src/entities/Example.entity.ts +9 -0
- package/template-app/src/index.ts +7 -0
- package/template-app/src/migrations/.gitkeep +2 -0
- package/template-app/src/services/Example.service.ts +20 -0
- package/template-app/tests/app.spec.ts +8 -0
- package/template-app/tsconfig.json +26 -0
- package/template-app/tsconfig.test.json +5 -0
- package/types.d.ts +4 -0
|
@@ -0,0 +1,993 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.__tsfTypeAliases = exports.TestingHelpers = exports.TestingFacade = void 0;
|
|
4
|
+
exports.createTestingFacade = createTestingFacade;
|
|
5
|
+
exports.createTestingFacadeWithDatabase = createTestingFacadeWithDatabase;
|
|
6
|
+
exports.createTestingFacadeBuilder = createTestingFacadeBuilder;
|
|
7
|
+
exports.makeMockRequest = makeMockRequest;
|
|
8
|
+
exports.installStandardHooks = installStandardHooks;
|
|
9
|
+
exports.resetSrcModuleCache = resetSrcModuleCache;
|
|
10
|
+
exports.setDefaultDatabaseConfig = setDefaultDatabaseConfig;
|
|
11
|
+
exports.cleanupTestDatabases = cleanupTestDatabases;
|
|
12
|
+
const tslib_1 = require("tslib");
|
|
13
|
+
const node_test_1 = require("node:test");
|
|
14
|
+
const node_path_1 = require("node:path");
|
|
15
|
+
const app_1 = require("../app");
|
|
16
|
+
const database_1 = require("../database");
|
|
17
|
+
const env_1 = require("../env");
|
|
18
|
+
const http_1 = require("../http");
|
|
19
|
+
const sql_1 = require("../database/sql");
|
|
20
|
+
const logger_1 = require("../services/logger");
|
|
21
|
+
const entity_1 = require("../services/worker/entity");
|
|
22
|
+
const database_readiness_1 = require("./database-readiness");
|
|
23
|
+
const fixtures_1 = require("./fixtures");
|
|
24
|
+
const sql_2 = require("./sql");
|
|
25
|
+
tslib_1.__exportStar(require("./expect"), exports);
|
|
26
|
+
tslib_1.__exportStar(require("./fixtures"), exports);
|
|
27
|
+
tslib_1.__exportStar(require("./sql"), exports);
|
|
28
|
+
let _TestingFacadeMetadata_1;
|
|
29
|
+
class TestingFacade {
|
|
30
|
+
app;
|
|
31
|
+
options;
|
|
32
|
+
databaseName;
|
|
33
|
+
dbAdapter;
|
|
34
|
+
migrationExecutions = [];
|
|
35
|
+
sql = new sql_2.SqlTestingHelper();
|
|
36
|
+
savepointIsolationActive = false;
|
|
37
|
+
originalDatabaseEnv;
|
|
38
|
+
originalAppDatabaseConfig;
|
|
39
|
+
savepointConnection;
|
|
40
|
+
savepointCleanup;
|
|
41
|
+
savepointIsolationLocksReady = false;
|
|
42
|
+
sharedDatabaseState;
|
|
43
|
+
sharedMySQLSessionKey;
|
|
44
|
+
sharedMySQLSessionLeaseId;
|
|
45
|
+
databaseCreated = false;
|
|
46
|
+
logger = (0, logger_1.createLogger)('TestingFacade');
|
|
47
|
+
constructor(app, options = {}, originalDatabaseEnv) {
|
|
48
|
+
this.app = app;
|
|
49
|
+
this.options = options;
|
|
50
|
+
this.originalDatabaseEnv = originalDatabaseEnv ?? (options.enableDatabase ? snapshotDatabaseEnv() : undefined);
|
|
51
|
+
this.dbAdapter = options.enableDatabase ? resolveTestDbAdapter(app.config, options.dbAdapter) : options.dbAdapter;
|
|
52
|
+
this.originalAppDatabaseConfig = snapshotAppDatabaseConfig(app.config);
|
|
53
|
+
}
|
|
54
|
+
async start() {
|
|
55
|
+
try {
|
|
56
|
+
this.logger.info('Starting test facade', {
|
|
57
|
+
enableDatabase: this.options.enableDatabase === true,
|
|
58
|
+
dbAdapter: this.dbAdapter,
|
|
59
|
+
migrations: this.shouldRunMigrations(),
|
|
60
|
+
useSavepoints: this.shouldUseSavepoints
|
|
61
|
+
});
|
|
62
|
+
(0, app_1.setCurrentApp)(this.app);
|
|
63
|
+
if (this.options.enableDatabase)
|
|
64
|
+
await this.createDatabase();
|
|
65
|
+
if (this.shouldPrepareDatabaseSchema())
|
|
66
|
+
await this.prepareDatabaseSchema();
|
|
67
|
+
if (this.options.enableDatabase && this.shouldUseSavepoints)
|
|
68
|
+
await this.initSavepointIsolation();
|
|
69
|
+
await this.options.onBeforeStart?.(this);
|
|
70
|
+
(0, app_1.setCurrentApp)(this.app);
|
|
71
|
+
await this.app.start();
|
|
72
|
+
await this.options.onStart?.(this);
|
|
73
|
+
if (this.options.autoSeedData && !this.shouldUseSavepoints)
|
|
74
|
+
await this.seed();
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
await this.app.stop().catch(() => { });
|
|
78
|
+
await this.cleanupDatabase();
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
async stop() {
|
|
83
|
+
(0, app_1.setCurrentApp)(this.app);
|
|
84
|
+
let errorToThrow;
|
|
85
|
+
try {
|
|
86
|
+
await this.options.onBeforeStop?.(this);
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
errorToThrow ??= error;
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
await this.teardownSavepointIsolation();
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
errorToThrow ??= error;
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
await this.app.stop();
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
errorToThrow ??= error;
|
|
102
|
+
}
|
|
103
|
+
try {
|
|
104
|
+
await this.cleanupDatabase();
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
errorToThrow ??= error;
|
|
108
|
+
}
|
|
109
|
+
try {
|
|
110
|
+
await this.options.onStop?.(this);
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
errorToThrow ??= error;
|
|
114
|
+
}
|
|
115
|
+
if (errorToThrow)
|
|
116
|
+
throw errorToThrow;
|
|
117
|
+
}
|
|
118
|
+
async createDatabase() {
|
|
119
|
+
if (!this.options.enableDatabase)
|
|
120
|
+
return;
|
|
121
|
+
if (this.databaseCreated)
|
|
122
|
+
return;
|
|
123
|
+
const adapter = this.requireDbAdapter();
|
|
124
|
+
await (0, database_readiness_1.waitForTestDatabaseReady)(adapter, this.app.config);
|
|
125
|
+
const sharedKey = this.getSharedDatabaseKey(adapter);
|
|
126
|
+
if (adapter === 'mysql' && sharedKey && (0, database_1.getSharedMySQLSessionManagerConfig)()) {
|
|
127
|
+
await this.createManagedSharedMySQLDatabase(sharedKey);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
if (sharedKey) {
|
|
131
|
+
await this.createSharedDatabase(adapter, sharedKey);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
this.databaseName = createTestDatabaseName(this.options.databasePrefix);
|
|
135
|
+
const adminDb = this.createAdminDatabase(adapter);
|
|
136
|
+
try {
|
|
137
|
+
await adminDb.rawExecute((0, sql_1.sql) `CREATE DATABASE ${sql_1.sql.identifier(this.databaseName)}`);
|
|
138
|
+
}
|
|
139
|
+
finally {
|
|
140
|
+
await adminDb.driver.close();
|
|
141
|
+
}
|
|
142
|
+
this.databaseCreated = true;
|
|
143
|
+
this.applyDatabaseConfig(adapter, this.databaseName);
|
|
144
|
+
}
|
|
145
|
+
async destroyDatabase() {
|
|
146
|
+
if (this.sharedMySQLSessionKey) {
|
|
147
|
+
await (0, database_1.releaseSharedMySQLSessionDatabase)(this.sharedMySQLSessionKey, this.sharedMySQLSessionLeaseId).catch(() => { });
|
|
148
|
+
this.sharedMySQLSessionKey = undefined;
|
|
149
|
+
this.sharedMySQLSessionLeaseId = undefined;
|
|
150
|
+
this.databaseCreated = false;
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (this.sharedDatabaseState) {
|
|
154
|
+
this.releaseSharedDatabase();
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (!this.databaseCreated || !this.databaseName || this.options.keepDatabase || env_1.Env.TEST_KEEP_DB)
|
|
158
|
+
return;
|
|
159
|
+
await this.dropDatabase(this.requireDbAdapter(), this.databaseName);
|
|
160
|
+
this.databaseCreated = false;
|
|
161
|
+
}
|
|
162
|
+
async truncateTables() {
|
|
163
|
+
if (!this.options.enableDatabase || !this.databaseCreated)
|
|
164
|
+
return;
|
|
165
|
+
const db = this.get(database_1.BaseDatabase);
|
|
166
|
+
if (db.driver.dialect === 'postgres') {
|
|
167
|
+
const rows = await db.rawFind((0, sql_1.sql) `SELECT tablename FROM pg_tables WHERE schemaname = 'public' AND tablename <> '_migrations'`);
|
|
168
|
+
if (!rows.length)
|
|
169
|
+
return;
|
|
170
|
+
await db.rawExecute((0, sql_1.sql) `TRUNCATE TABLE ${sql_1.sql.join(rows.map(row => sql_1.sql.identifier(row.tablename)))} RESTART IDENTITY CASCADE`);
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
const rows = await db.rawFind((0, sql_1.sql) `SHOW TABLES`);
|
|
174
|
+
const tables = rows
|
|
175
|
+
.map(row => String(Object.values(row)[0]))
|
|
176
|
+
.filter(table => table && table !== '_migrations')
|
|
177
|
+
.sort();
|
|
178
|
+
if (!tables.length)
|
|
179
|
+
return;
|
|
180
|
+
await db.transaction(async (session) => {
|
|
181
|
+
await db.rawExecute((0, sql_1.sql) `SET FOREIGN_KEY_CHECKS = 0`, session);
|
|
182
|
+
try {
|
|
183
|
+
for (const table of tables) {
|
|
184
|
+
await db.rawExecute((0, sql_1.sql) `TRUNCATE TABLE ${sql_1.sql.identifier(table)}`, session);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
finally {
|
|
188
|
+
await db.rawExecute((0, sql_1.sql) `SET FOREIGN_KEY_CHECKS = 1`, session);
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
async request(request) {
|
|
193
|
+
return (await this.app.request(request, new http_1.MemoryHttpResponse()));
|
|
194
|
+
}
|
|
195
|
+
async seed() {
|
|
196
|
+
await this.options.seedData?.(this);
|
|
197
|
+
}
|
|
198
|
+
async runMigrations() {
|
|
199
|
+
if (!this.app.options.db)
|
|
200
|
+
throw new Error('TestingFacade migrations require an app database provider');
|
|
201
|
+
const db = this.get(database_1.BaseDatabase);
|
|
202
|
+
const migrations = await this.loadTestingMigrations();
|
|
203
|
+
const executions = await new database_1.MigrationRunner(db).run(migrations, {
|
|
204
|
+
beforeRun: () => this.prepareInternalMigrationTables(db)
|
|
205
|
+
});
|
|
206
|
+
this.migrationExecutions.push(...executions);
|
|
207
|
+
return executions;
|
|
208
|
+
}
|
|
209
|
+
async resetToSeed() {
|
|
210
|
+
if (this.options.enableDatabase && this.shouldUseSavepoints) {
|
|
211
|
+
if (!this.savepointIsolationActive) {
|
|
212
|
+
await this.initSavepointIsolation();
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
if (!this.savepointConnection)
|
|
216
|
+
throw new Error('Savepoint isolation is active without a database connection');
|
|
217
|
+
await this.savepointConnection.rollbackToSavepoint('after_seed');
|
|
218
|
+
}
|
|
219
|
+
if (this.savepointIsolationActive)
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
if (this.options.enableDatabase)
|
|
223
|
+
await this.truncateTables();
|
|
224
|
+
await this.seed();
|
|
225
|
+
}
|
|
226
|
+
async createSeedSavepoint(name, seedData) {
|
|
227
|
+
if (!this.options.enableDatabase || !this.shouldUseSavepoints || !this.getDatabaseProvider())
|
|
228
|
+
return false;
|
|
229
|
+
if (!this.savepointIsolationActive)
|
|
230
|
+
await this.initSavepointIsolation();
|
|
231
|
+
if (!this.savepointConnection)
|
|
232
|
+
throw new Error('Savepoint isolation is active without a database connection');
|
|
233
|
+
await seedData?.(this);
|
|
234
|
+
await this.savepointConnection.savepoint(name);
|
|
235
|
+
return true;
|
|
236
|
+
}
|
|
237
|
+
async resetToSeedSavepoint(name) {
|
|
238
|
+
if (!this.options.enableDatabase || !this.shouldUseSavepoints || !this.getDatabaseProvider())
|
|
239
|
+
return false;
|
|
240
|
+
if (!this.savepointIsolationActive)
|
|
241
|
+
await this.initSavepointIsolation();
|
|
242
|
+
if (!this.savepointConnection)
|
|
243
|
+
throw new Error('Savepoint isolation is active without a database connection');
|
|
244
|
+
await this.savepointConnection.rollbackToSavepoint(name);
|
|
245
|
+
return true;
|
|
246
|
+
}
|
|
247
|
+
get(token) {
|
|
248
|
+
return this.app.get(token);
|
|
249
|
+
}
|
|
250
|
+
async cleanupDatabase() {
|
|
251
|
+
try {
|
|
252
|
+
await this.teardownSavepointIsolation();
|
|
253
|
+
await this.closeDatabaseProvider();
|
|
254
|
+
await this.destroyDatabase();
|
|
255
|
+
}
|
|
256
|
+
finally {
|
|
257
|
+
this.restoreDatabaseConfig();
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
async prepareDatabaseSchema() {
|
|
261
|
+
if (this.sharedMySQLSessionKey) {
|
|
262
|
+
await this.prepareManagedSharedMySQLSchema(this.sharedMySQLSessionKey, this.sharedMySQLSessionLeaseId);
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
const sharedState = this.sharedDatabaseState;
|
|
266
|
+
if (!sharedState) {
|
|
267
|
+
await this.createSchemaFromEntities();
|
|
268
|
+
if (this.shouldRunMigrations())
|
|
269
|
+
await this.runMigrations();
|
|
270
|
+
if (this.shouldTruncateAfterMigrations())
|
|
271
|
+
await this.truncateTables();
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
if (!sharedState.schemaReady) {
|
|
275
|
+
sharedState.schemaReady = (async () => {
|
|
276
|
+
try {
|
|
277
|
+
await this.createSchemaFromEntities();
|
|
278
|
+
if (this.shouldRunMigrations())
|
|
279
|
+
await this.runMigrations();
|
|
280
|
+
if (this.shouldTruncateAfterMigrations())
|
|
281
|
+
await this.truncateTables();
|
|
282
|
+
}
|
|
283
|
+
catch (error) {
|
|
284
|
+
sharedTestDatabases.delete(sharedState.key);
|
|
285
|
+
if (!sharedState.keepDatabase && !env_1.Env.TEST_KEEP_DB)
|
|
286
|
+
await sharedState.destroy().catch(() => { });
|
|
287
|
+
throw error;
|
|
288
|
+
}
|
|
289
|
+
})();
|
|
290
|
+
}
|
|
291
|
+
await sharedState.schemaReady;
|
|
292
|
+
}
|
|
293
|
+
async prepareManagedSharedMySQLSchema(key, leaseId) {
|
|
294
|
+
const preparation = await (0, database_1.prepareSharedMySQLSessionSchema)(key, leaseId);
|
|
295
|
+
if (!preparation.run)
|
|
296
|
+
return;
|
|
297
|
+
try {
|
|
298
|
+
await this.createSchemaFromEntities();
|
|
299
|
+
if (this.shouldRunMigrations())
|
|
300
|
+
await this.runMigrations();
|
|
301
|
+
if (this.shouldTruncateAfterMigrations())
|
|
302
|
+
await this.truncateTables();
|
|
303
|
+
}
|
|
304
|
+
catch (error) {
|
|
305
|
+
await (0, database_1.completeSharedMySQLSessionSchema)(key, leaseId, preparation.preparationId, error).catch(() => { });
|
|
306
|
+
throw error;
|
|
307
|
+
}
|
|
308
|
+
await (0, database_1.completeSharedMySQLSessionSchema)(key, leaseId, preparation.preparationId);
|
|
309
|
+
}
|
|
310
|
+
async closeDatabaseProvider() {
|
|
311
|
+
if (!this.app.options.db)
|
|
312
|
+
return;
|
|
313
|
+
try {
|
|
314
|
+
const db = this.app.get(this.app.options.db);
|
|
315
|
+
await db.driver.close();
|
|
316
|
+
}
|
|
317
|
+
catch {
|
|
318
|
+
// The DB may never have been constructed, or start() may have failed before it was usable.
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
createAdminDatabase(adapter) {
|
|
322
|
+
return adapter === 'postgres'
|
|
323
|
+
? new database_1.BaseDatabase(new database_1.PostgresDriver({
|
|
324
|
+
host: this.app.config.PG_HOST,
|
|
325
|
+
port: this.app.config.PG_PORT,
|
|
326
|
+
user: this.app.config.PG_USER,
|
|
327
|
+
password: this.app.config.PG_PASSWORD_SECRET,
|
|
328
|
+
database: 'postgres',
|
|
329
|
+
ssl: this.app.config.PG_SSL ? { rejectUnauthorized: this.app.config.PG_SSL_REJECT_UNAUTHORIZED ?? true } : undefined,
|
|
330
|
+
max: 1
|
|
331
|
+
}))
|
|
332
|
+
: new database_1.BaseDatabase(new database_1.MySQLDriver({
|
|
333
|
+
host: this.app.config.MYSQL_HOST,
|
|
334
|
+
port: this.app.config.MYSQL_PORT,
|
|
335
|
+
user: this.app.config.MYSQL_USER,
|
|
336
|
+
password: this.app.config.MYSQL_PASSWORD_SECRET,
|
|
337
|
+
database: 'mysql',
|
|
338
|
+
connectionLimit: 1
|
|
339
|
+
}));
|
|
340
|
+
}
|
|
341
|
+
async dropDatabase(adapter, databaseName) {
|
|
342
|
+
const adminDb = this.createAdminDatabase(adapter);
|
|
343
|
+
try {
|
|
344
|
+
if (adapter === 'postgres') {
|
|
345
|
+
await adminDb.rawExecute((0, sql_1.sql) `SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = ${databaseName} AND pid <> pg_backend_pid()`);
|
|
346
|
+
}
|
|
347
|
+
await adminDb.rawExecute((0, sql_1.sql) `DROP DATABASE IF EXISTS ${sql_1.sql.identifier(databaseName)}`);
|
|
348
|
+
}
|
|
349
|
+
finally {
|
|
350
|
+
await adminDb.driver.close();
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
async createSharedDatabase(adapter, key) {
|
|
354
|
+
let state = sharedTestDatabases.get(key);
|
|
355
|
+
if (!state) {
|
|
356
|
+
const databaseName = createTestDatabaseName(this.options.databasePrefix);
|
|
357
|
+
state = {
|
|
358
|
+
key,
|
|
359
|
+
adapter,
|
|
360
|
+
databaseName,
|
|
361
|
+
references: 0,
|
|
362
|
+
keepDatabase: !!this.options.keepDatabase,
|
|
363
|
+
destroy: () => this.dropDatabase(adapter, databaseName)
|
|
364
|
+
};
|
|
365
|
+
sharedTestDatabases.set(key, state);
|
|
366
|
+
installSharedDatabaseCleanup();
|
|
367
|
+
state.databaseReady = this.initializeSharedDatabase(state);
|
|
368
|
+
}
|
|
369
|
+
else {
|
|
370
|
+
state.keepDatabase = state.keepDatabase || !!this.options.keepDatabase;
|
|
371
|
+
}
|
|
372
|
+
state.references++;
|
|
373
|
+
this.sharedDatabaseState = state;
|
|
374
|
+
try {
|
|
375
|
+
await state.databaseReady;
|
|
376
|
+
}
|
|
377
|
+
catch (error) {
|
|
378
|
+
this.releaseSharedDatabase();
|
|
379
|
+
sharedTestDatabases.delete(key);
|
|
380
|
+
throw error;
|
|
381
|
+
}
|
|
382
|
+
this.databaseName = state.databaseName;
|
|
383
|
+
this.databaseCreated = true;
|
|
384
|
+
this.applyDatabaseConfig(adapter, state.databaseName);
|
|
385
|
+
}
|
|
386
|
+
async createManagedSharedMySQLDatabase(key) {
|
|
387
|
+
const state = await (0, database_1.ensureSharedMySQLSessionDatabase)({
|
|
388
|
+
key,
|
|
389
|
+
prefix: this.options.databasePrefix ?? 'test',
|
|
390
|
+
keepDatabase: !!this.options.keepDatabase
|
|
391
|
+
});
|
|
392
|
+
this.sharedMySQLSessionKey = key;
|
|
393
|
+
this.sharedMySQLSessionLeaseId = state.leaseId;
|
|
394
|
+
this.databaseName = state.databaseName;
|
|
395
|
+
this.databaseCreated = true;
|
|
396
|
+
this.applyDatabaseConfig('mysql', state.databaseName);
|
|
397
|
+
env_1.Env.TSF_TEST_MYSQL_SESSION_KEY = key;
|
|
398
|
+
env_1.Env.TSF_TEST_MYSQL_SESSION_LEASE_ID = state.leaseId;
|
|
399
|
+
env_1.Env.TSF_TEST_MYSQL_SESSION_DATABASE = state.databaseName;
|
|
400
|
+
}
|
|
401
|
+
async initializeSharedDatabase(state) {
|
|
402
|
+
const adminDb = this.createAdminDatabase(state.adapter);
|
|
403
|
+
try {
|
|
404
|
+
await adminDb.rawExecute((0, sql_1.sql) `CREATE DATABASE ${sql_1.sql.identifier(state.databaseName)}`);
|
|
405
|
+
}
|
|
406
|
+
finally {
|
|
407
|
+
await adminDb.driver.close();
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
releaseSharedDatabase() {
|
|
411
|
+
const state = this.sharedDatabaseState;
|
|
412
|
+
if (!state)
|
|
413
|
+
return;
|
|
414
|
+
state.references = Math.max(0, state.references - 1);
|
|
415
|
+
this.sharedDatabaseState = undefined;
|
|
416
|
+
this.databaseCreated = false;
|
|
417
|
+
}
|
|
418
|
+
applyDatabaseConfig(adapter, databaseName) {
|
|
419
|
+
this.app.config.DB_ADAPTER = adapter;
|
|
420
|
+
env_1.Env.DB_ADAPTER = adapter;
|
|
421
|
+
env_1.Env.TSF_TEST_DATABASE_NAME = databaseName;
|
|
422
|
+
if (adapter === 'postgres') {
|
|
423
|
+
this.app.config.PG_DATABASE = databaseName;
|
|
424
|
+
env_1.Env.PG_DATABASE = databaseName;
|
|
425
|
+
}
|
|
426
|
+
else {
|
|
427
|
+
this.app.config.MYSQL_DATABASE = databaseName;
|
|
428
|
+
env_1.Env.MYSQL_DATABASE = databaseName;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
restoreDatabaseConfig() {
|
|
432
|
+
Object.assign(this.app.config, this.originalAppDatabaseConfig);
|
|
433
|
+
if (this.originalDatabaseEnv)
|
|
434
|
+
restoreDatabaseEnv(this.originalDatabaseEnv);
|
|
435
|
+
}
|
|
436
|
+
requireDbAdapter() {
|
|
437
|
+
if (!this.dbAdapter)
|
|
438
|
+
throw new Error("TestingFacade enableDatabase requires dbAdapter or DB_ADAPTER to be 'mysql' or 'postgres'");
|
|
439
|
+
return this.dbAdapter;
|
|
440
|
+
}
|
|
441
|
+
shouldRunMigrations() {
|
|
442
|
+
if (this.options.enableMigrations !== undefined)
|
|
443
|
+
return this.options.enableMigrations;
|
|
444
|
+
if (this.options.enableDatabase)
|
|
445
|
+
return !!this.app.options.db;
|
|
446
|
+
return !!this.options.migrations?.length || this.options.migrationsDir !== undefined;
|
|
447
|
+
}
|
|
448
|
+
shouldCreateSchemaFromEntities() {
|
|
449
|
+
return !!this.options.schemaFromEntities;
|
|
450
|
+
}
|
|
451
|
+
shouldPrepareDatabaseSchema() {
|
|
452
|
+
return !!this.options.enableDatabase && (this.shouldCreateSchemaFromEntities() || this.shouldRunMigrations());
|
|
453
|
+
}
|
|
454
|
+
async createSchemaFromEntities() {
|
|
455
|
+
const option = this.options.schemaFromEntities;
|
|
456
|
+
if (!option)
|
|
457
|
+
return;
|
|
458
|
+
const db = this.getDatabaseProvider();
|
|
459
|
+
if (!db)
|
|
460
|
+
throw new Error('TestingFacade schemaFromEntities requires an app database provider');
|
|
461
|
+
const plan = await (0, database_1.createMigrationPlan)(db, option === true ? {} : option);
|
|
462
|
+
for (const statement of plan.statements) {
|
|
463
|
+
if (statement.startsWith('\0table:'))
|
|
464
|
+
continue;
|
|
465
|
+
await db.rawExecuteUnsafe(statement);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
shouldTruncateAfterMigrations() {
|
|
469
|
+
if (!this.options.enableDatabase)
|
|
470
|
+
return false;
|
|
471
|
+
return this.options.truncateAfterMigrations ?? true;
|
|
472
|
+
}
|
|
473
|
+
shouldPrepareWorkerJobsTable() {
|
|
474
|
+
return !!this.options.enableDatabase && !!this.app.options.enableWorker && !!this.app.options.db;
|
|
475
|
+
}
|
|
476
|
+
async prepareInternalMigrationTables(db) {
|
|
477
|
+
await (0, database_1.ensureMySQLLocksTable)(db);
|
|
478
|
+
if (db.driver.dialect === 'mysql' && db.options.enableLocksTable)
|
|
479
|
+
this.savepointIsolationLocksReady = true;
|
|
480
|
+
if (this.shouldPrepareWorkerJobsTable())
|
|
481
|
+
await this.prepareWorkerJobsTableForDatabase(db);
|
|
482
|
+
}
|
|
483
|
+
async prepareWorkerJobsTableForDatabase(db) {
|
|
484
|
+
if (!db.entityRegistry.includes(entity_1.JobEntity))
|
|
485
|
+
db.entityRegistry.push(entity_1.JobEntity);
|
|
486
|
+
entity_1.JobEntity.registerDatabase(db);
|
|
487
|
+
const plan = await (0, database_1.createMigrationPlan)(db, { tableNames: ['_jobs'] });
|
|
488
|
+
for (const statement of plan.statements) {
|
|
489
|
+
if (statement.startsWith('\0table:'))
|
|
490
|
+
continue;
|
|
491
|
+
await db.rawExecuteUnsafe(statement);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
async loadTestingMigrations() {
|
|
495
|
+
const migrations = [...(this.options.migrations ?? [])];
|
|
496
|
+
const dirs = this.getMigrationDirectories();
|
|
497
|
+
for (const dir of dirs) {
|
|
498
|
+
migrations.push(...(await (0, database_1.loadMigrationsFromDirectory)(dir)));
|
|
499
|
+
}
|
|
500
|
+
return migrations;
|
|
501
|
+
}
|
|
502
|
+
getMigrationDirectories() {
|
|
503
|
+
if (this.options.migrationsDir !== undefined) {
|
|
504
|
+
return typeof this.options.migrationsDir === 'string' ? [this.options.migrationsDir] : this.options.migrationsDir;
|
|
505
|
+
}
|
|
506
|
+
if (this.options.migrations !== undefined)
|
|
507
|
+
return [];
|
|
508
|
+
return ['src/migrations'];
|
|
509
|
+
}
|
|
510
|
+
get shouldUseSavepoints() {
|
|
511
|
+
if (!readEnvBoolean(env_1.Env.TSF_TEST_ALLOW_SAVEPOINTS, true))
|
|
512
|
+
return false;
|
|
513
|
+
if (this.options.useSavepoints !== undefined)
|
|
514
|
+
return this.options.useSavepoints;
|
|
515
|
+
return !!this.options.enableDatabase;
|
|
516
|
+
}
|
|
517
|
+
getSharedDatabaseKey(adapter) {
|
|
518
|
+
if (!this.options.enableDatabase || !this.shouldUseSavepoints)
|
|
519
|
+
return undefined;
|
|
520
|
+
const migrations = this.options.migrations ?? [];
|
|
521
|
+
const inlineMigrations = migrations.map(migration => `${migration.name}:${getInlineMigrationIdentity(migration)}`).sort();
|
|
522
|
+
const migrationDirs = this.getMigrationDirectories()
|
|
523
|
+
.map(dir => (0, node_path_1.resolve)(dir))
|
|
524
|
+
.sort();
|
|
525
|
+
const schemaFromEntities = this.options.schemaFromEntities === true
|
|
526
|
+
? true
|
|
527
|
+
: this.options.schemaFromEntities
|
|
528
|
+
? {
|
|
529
|
+
pgSchema: this.options.schemaFromEntities.pgSchema,
|
|
530
|
+
tableNames: this.options.schemaFromEntities.tableNames ? [...this.options.schemaFromEntities.tableNames].sort() : undefined
|
|
531
|
+
}
|
|
532
|
+
: false;
|
|
533
|
+
return JSON.stringify({
|
|
534
|
+
adapter,
|
|
535
|
+
prefix: this.options.databasePrefix ?? 'test',
|
|
536
|
+
schemaFromEntities,
|
|
537
|
+
migrations: this.shouldRunMigrations() ? { inlineMigrations, migrationDirs } : false,
|
|
538
|
+
truncateAfterMigrations: this.shouldTruncateAfterMigrations(),
|
|
539
|
+
workerJobsTable: this.shouldPrepareWorkerJobsTable()
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
getDatabaseProvider() {
|
|
543
|
+
if (!this.app.options.db)
|
|
544
|
+
return undefined;
|
|
545
|
+
try {
|
|
546
|
+
return this.app.get(this.app.options.db);
|
|
547
|
+
}
|
|
548
|
+
catch {
|
|
549
|
+
try {
|
|
550
|
+
return this.get(database_1.BaseDatabase);
|
|
551
|
+
}
|
|
552
|
+
catch {
|
|
553
|
+
return undefined;
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
async initSavepointIsolation() {
|
|
558
|
+
const db = this.getDatabaseProvider();
|
|
559
|
+
if (!db)
|
|
560
|
+
return;
|
|
561
|
+
if (!this.savepointIsolationLocksReady)
|
|
562
|
+
await this.ensureSavepointIsolationLocksReady(db);
|
|
563
|
+
const originalAcquire = db.driver.acquire.bind(db.driver);
|
|
564
|
+
const connection = await originalAcquire();
|
|
565
|
+
const originalBegin = connection.begin.bind(connection);
|
|
566
|
+
const originalCommit = connection.commit.bind(connection);
|
|
567
|
+
const originalRollback = connection.rollback.bind(connection);
|
|
568
|
+
const originalSavepoint = connection.savepoint.bind(connection);
|
|
569
|
+
const originalRollbackToSavepoint = connection.rollbackToSavepoint.bind(connection);
|
|
570
|
+
const originalRelease = connection.release.bind(connection);
|
|
571
|
+
const transactionStack = [];
|
|
572
|
+
let savepointId = 0;
|
|
573
|
+
const cleanup = () => {
|
|
574
|
+
db.driver.acquire = originalAcquire;
|
|
575
|
+
connection.begin = originalBegin;
|
|
576
|
+
connection.commit = originalCommit;
|
|
577
|
+
connection.rollback = originalRollback;
|
|
578
|
+
connection.release = originalRelease;
|
|
579
|
+
};
|
|
580
|
+
try {
|
|
581
|
+
await originalBegin();
|
|
582
|
+
db.driver.acquire = async () => connection;
|
|
583
|
+
connection.begin = async () => {
|
|
584
|
+
const name = `tsf_test_tx_${++savepointId}`;
|
|
585
|
+
transactionStack.push(name);
|
|
586
|
+
await originalSavepoint(name);
|
|
587
|
+
};
|
|
588
|
+
connection.commit = async () => {
|
|
589
|
+
transactionStack.pop();
|
|
590
|
+
};
|
|
591
|
+
connection.rollback = async () => {
|
|
592
|
+
const name = transactionStack.pop();
|
|
593
|
+
if (name)
|
|
594
|
+
await originalRollbackToSavepoint(name);
|
|
595
|
+
};
|
|
596
|
+
connection.release = async () => { };
|
|
597
|
+
this.savepointConnection = connection;
|
|
598
|
+
this.savepointCleanup = cleanup;
|
|
599
|
+
await this.seed();
|
|
600
|
+
await originalSavepoint('after_seed');
|
|
601
|
+
this.savepointIsolationActive = true;
|
|
602
|
+
}
|
|
603
|
+
catch (error) {
|
|
604
|
+
cleanup();
|
|
605
|
+
this.savepointConnection = undefined;
|
|
606
|
+
this.savepointCleanup = undefined;
|
|
607
|
+
try {
|
|
608
|
+
await originalRollback();
|
|
609
|
+
}
|
|
610
|
+
finally {
|
|
611
|
+
await originalRelease();
|
|
612
|
+
}
|
|
613
|
+
throw error;
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
async teardownSavepointIsolation() {
|
|
617
|
+
if (!this.savepointConnection)
|
|
618
|
+
return;
|
|
619
|
+
const connection = this.savepointConnection;
|
|
620
|
+
this.savepointCleanup?.();
|
|
621
|
+
this.savepointConnection = undefined;
|
|
622
|
+
this.savepointCleanup = undefined;
|
|
623
|
+
this.savepointIsolationActive = false;
|
|
624
|
+
try {
|
|
625
|
+
await connection.rollback();
|
|
626
|
+
}
|
|
627
|
+
finally {
|
|
628
|
+
await connection.release();
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
async ensureSavepointIsolationLocksReady(db = this.getDatabaseProvider()) {
|
|
632
|
+
if (!db)
|
|
633
|
+
return;
|
|
634
|
+
await (0, database_1.ensureMySQLLocksTable)(db);
|
|
635
|
+
this.savepointIsolationLocksReady = true;
|
|
636
|
+
}
|
|
637
|
+
static __tsfType = _TestingFacadeMetadata_1 = ({ kind: 16, name: "TestingFacade", typeName: "TestingFacade", classType: () => TestingFacade, properties: [{ name: "databaseName", type: { kind: 6 }, optional: true }, { name: "dbAdapter", type: { kind: 12, types: [{ kind: 10, literal: "mysql" }, { kind: 10, literal: "postgres" }], typeName: "DatabaseDialect", typeName: "TestDbAdapter" }, optional: true }, { name: "migrationExecutions", type: { kind: 14, type: { kind: 18, typeName: "MigrationExecution", types: [{ kind: 20, name: "name", type: { kind: 6 }, optional: false }, { kind: 20, name: "executedAt", type: { kind: 16, typeName: "Date", classType: () => (typeof Date !== "undefined" ? Date : (typeof exports !== "undefined" ? exports.Date : undefined)) }, optional: false }, { kind: 20, name: "durationMs", type: { kind: 7 }, optional: false }] } }, optional: false }, { name: "sql", type: { kind: 2 }, optional: false }, { name: "savepointIsolationActive", type: { kind: 2 }, optional: false }], methods: [{ name: "start", parameters: [], returnType: { kind: 22, type: { kind: 3 } } }, { name: "stop", parameters: [], returnType: { kind: 22, type: { kind: 3 } } }, { name: "createDatabase", parameters: [], returnType: { kind: 22, type: { kind: 3 } } }, { name: "destroyDatabase", parameters: [], returnType: { kind: 22, type: { kind: 3 } } }, { name: "truncateTables", parameters: [], returnType: { kind: 22, type: { kind: 3 } } }, { name: "request", parameters: [{ name: "request", type: { kind: 16, typeName: "HttpRequest", classType: () => (typeof require !== "undefined" ? require("../http/index").HttpRequest : undefined) }, optional: false, default: false }], returnType: { kind: 22, type: { kind: 16, typeName: "MemoryHttpResponse", classType: () => (typeof require !== "undefined" ? require("../http/index").MemoryHttpResponse : undefined) } } }, { name: "seed", parameters: [], returnType: { kind: 22, type: { kind: 3 } } }, { name: "runMigrations", parameters: [], returnType: { kind: 22, type: { kind: 14, type: { kind: 18, typeName: "MigrationExecution", types: [{ kind: 20, name: "name", type: { kind: 6 }, optional: false }, { kind: 20, name: "executedAt", type: { kind: 16, typeName: "Date", classType: () => (typeof Date !== "undefined" ? Date : (typeof exports !== "undefined" ? exports.Date : undefined)) }, optional: false }, { kind: 20, name: "durationMs", type: { kind: 7 }, optional: false }] } } } }, { name: "resetToSeed", parameters: [], returnType: { kind: 22, type: { kind: 3 } } }, { name: "createSeedSavepoint", parameters: [{ name: "name", type: { kind: 6 }, optional: false, default: false }, { name: "seedData", type: { kind: 2, typeName: "TestingFacadeSeedData", typeArguments: [{ kind: 2, typeName: "C" }] }, optional: true, default: false }], returnType: { kind: 22, type: { kind: 8 } } }, { name: "resetToSeedSavepoint", parameters: [{ name: "name", type: { kind: 6 }, optional: false, default: false }], returnType: { kind: 22, type: { kind: 8 } } }, { name: "get", parameters: [{ name: "token", type: { kind: 2, typeName: "Parameters<App<C>['get']>[0]" }, optional: false, default: false }], returnType: { kind: 2, typeName: "T" } }], hasConstructor: true, constructorParameters: [{ name: "app", type: { kind: 16, typeName: "App", classType: () => (typeof require !== "undefined" ? require("../app/index").App : undefined), typeArguments: [{ kind: 1 }] }, optional: false, default: false }, { name: "options", type: { kind: 16, typeName: "TestingFacadeOptions", classType: () => (typeof TestingFacadeOptions !== "undefined" ? TestingFacadeOptions : (typeof exports !== "undefined" ? exports.TestingFacadeOptions : undefined)), typeArguments: [{ kind: 1 }] }, optional: true, default: true }, { name: "originalDatabaseEnv", type: { kind: 18, typeName: "Partial", utilityType: "Partial", typeArguments: [{ kind: 18, typeName: "Record", utilityType: "Record", typeArguments: [{ kind: 2, typeName: "(typeof DATABASE_ENV_KEYS)[number]" }, { kind: 6 }], index: { kind: 6 }, types: [] }], utilityKeys: [], types: [], typeName: "DatabaseEnvSnapshot" }, optional: true, default: false }] });
|
|
638
|
+
}
|
|
639
|
+
exports.TestingFacade = TestingFacade;
|
|
640
|
+
_TestingFacadeMetadata_1.classType = TestingFacade;
|
|
641
|
+
TestingFacade.__tsfType = _TestingFacadeMetadata_1;
|
|
642
|
+
function createTestingFacade(appOptions, options = {}) {
|
|
643
|
+
const originalDatabaseEnv = options.enableDatabase ? snapshotDatabaseEnv() : undefined;
|
|
644
|
+
const app = (0, app_1.createApp)({
|
|
645
|
+
config: app_1.BaseAppConfig,
|
|
646
|
+
...appOptions,
|
|
647
|
+
frameworkConfig: {
|
|
648
|
+
...appOptions.frameworkConfig,
|
|
649
|
+
port: 0
|
|
650
|
+
}
|
|
651
|
+
});
|
|
652
|
+
if (originalDatabaseEnv)
|
|
653
|
+
restoreDatabaseEnv(originalDatabaseEnv);
|
|
654
|
+
return new TestingFacade(app, options, originalDatabaseEnv);
|
|
655
|
+
}
|
|
656
|
+
function createTestingFacadeWithDatabase(appOptions, options = {}) {
|
|
657
|
+
return createTestingFacade(appOptions, { ...options, enableDatabase: true });
|
|
658
|
+
}
|
|
659
|
+
function createTestingFacadeBuilder(defaultAppOptions, defaultOptions = {}) {
|
|
660
|
+
return (appOptions = {}, options = {}) => {
|
|
661
|
+
const resolvedAppOptions = typeof defaultAppOptions === 'function'
|
|
662
|
+
? defaultAppOptions(normalizeTestingAppOptions(appOptions))
|
|
663
|
+
: mergeTestingAppOptions(defaultAppOptions, appOptions);
|
|
664
|
+
const resolvedOptions = typeof defaultOptions === 'function' ? defaultOptions(options) : mergeTestingFacadeOptions(defaultOptions, options);
|
|
665
|
+
return createTestingFacade(resolvedAppOptions, resolvedOptions);
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
function mergeTestingAppOptions(defaults, overrides) {
|
|
669
|
+
const merged = {
|
|
670
|
+
...defaults,
|
|
671
|
+
...overrides,
|
|
672
|
+
imports: mergeTestingArrays(defaults.imports, overrides.imports),
|
|
673
|
+
exports: mergeTestingArrays(defaults.exports, overrides.exports),
|
|
674
|
+
providers: mergeTestingArrays(defaults.providers, overrides.providers),
|
|
675
|
+
controllers: mergeTestingArrays(defaults.controllers, overrides.controllers),
|
|
676
|
+
listeners: mergeTestingArrays(defaults.listeners, overrides.listeners),
|
|
677
|
+
commands: mergeTestingArrays(defaults.commands, overrides.commands)
|
|
678
|
+
};
|
|
679
|
+
const defaultConfig = mergeTestingObjects(defaults.defaultConfig, overrides.defaultConfig);
|
|
680
|
+
if (defaultConfig)
|
|
681
|
+
merged.defaultConfig = defaultConfig;
|
|
682
|
+
const frameworkConfig = mergeTestingObjects(defaults.frameworkConfig, overrides.frameworkConfig);
|
|
683
|
+
if (frameworkConfig)
|
|
684
|
+
merged.frameworkConfig = frameworkConfig;
|
|
685
|
+
const serverConfig = mergeTestingObjects(defaults.serverConfig, overrides.serverConfig);
|
|
686
|
+
if (serverConfig)
|
|
687
|
+
merged.serverConfig = serverConfig;
|
|
688
|
+
return merged;
|
|
689
|
+
}
|
|
690
|
+
function normalizeTestingAppOptions(options) {
|
|
691
|
+
return {
|
|
692
|
+
...options,
|
|
693
|
+
imports: [...(options.imports ?? [])],
|
|
694
|
+
exports: [...(options.exports ?? [])],
|
|
695
|
+
providers: [...(options.providers ?? [])],
|
|
696
|
+
controllers: [...(options.controllers ?? [])],
|
|
697
|
+
listeners: [...(options.listeners ?? [])],
|
|
698
|
+
commands: [...(options.commands ?? [])]
|
|
699
|
+
};
|
|
700
|
+
}
|
|
701
|
+
function mergeTestingFacadeOptions(defaults, overrides) {
|
|
702
|
+
const merged = {
|
|
703
|
+
...defaults,
|
|
704
|
+
...overrides,
|
|
705
|
+
defaultTestHeaders: mergeTestingObjects(defaults.defaultTestHeaders, overrides.defaultTestHeaders),
|
|
706
|
+
migrations: mergeTestingArrays(defaults.migrations, overrides.migrations),
|
|
707
|
+
migrationsDir: mergeTestingMigrationDirs(defaults.migrationsDir, overrides.migrationsDir),
|
|
708
|
+
seedData: composeTestingFacadeCallbacks(defaults.seedData, overrides.seedData),
|
|
709
|
+
onBeforeStart: composeTestingFacadeCallbacks(defaults.onBeforeStart, overrides.onBeforeStart),
|
|
710
|
+
onStart: composeTestingFacadeCallbacks(defaults.onStart, overrides.onStart),
|
|
711
|
+
onBeforeStop: composeTestingFacadeCallbacks(defaults.onBeforeStop, overrides.onBeforeStop),
|
|
712
|
+
onStop: composeTestingFacadeCallbacks(defaults.onStop, overrides.onStop)
|
|
713
|
+
};
|
|
714
|
+
return merged;
|
|
715
|
+
}
|
|
716
|
+
function mergeTestingArrays(defaults, overrides) {
|
|
717
|
+
if (!defaults?.length && !overrides?.length)
|
|
718
|
+
return undefined;
|
|
719
|
+
return [...(defaults ?? []), ...(overrides ?? [])];
|
|
720
|
+
}
|
|
721
|
+
function mergeTestingObjects(defaults, overrides) {
|
|
722
|
+
if (!defaults && !overrides)
|
|
723
|
+
return undefined;
|
|
724
|
+
return { ...(defaults ?? {}), ...(overrides ?? {}) };
|
|
725
|
+
}
|
|
726
|
+
function mergeTestingMigrationDirs(defaults, overrides) {
|
|
727
|
+
if (defaults === undefined)
|
|
728
|
+
return overrides;
|
|
729
|
+
if (overrides === undefined)
|
|
730
|
+
return defaults;
|
|
731
|
+
return [...toTestingStringArray(defaults), ...toTestingStringArray(overrides)];
|
|
732
|
+
}
|
|
733
|
+
function toTestingStringArray(value) {
|
|
734
|
+
return typeof value === 'string' ? [value] : value;
|
|
735
|
+
}
|
|
736
|
+
function composeTestingFacadeCallbacks(first, second) {
|
|
737
|
+
if (!first)
|
|
738
|
+
return second;
|
|
739
|
+
if (!second)
|
|
740
|
+
return first;
|
|
741
|
+
return async (facade) => {
|
|
742
|
+
await first(facade);
|
|
743
|
+
await second(facade);
|
|
744
|
+
};
|
|
745
|
+
}
|
|
746
|
+
async function makeMockRequest(tf, method, url, headersOrBody = {}, body) {
|
|
747
|
+
const bodyless = method === 'GET';
|
|
748
|
+
const hasSeparateBody = arguments.length >= 5;
|
|
749
|
+
const hasBody = hasSeparateBody || !bodyless;
|
|
750
|
+
const headers = normalizeMockHeaders({
|
|
751
|
+
'content-type': 'application/json',
|
|
752
|
+
...tf.options.defaultTestHeaders,
|
|
753
|
+
...(hasSeparateBody || (bodyless && !hasSeparateBody) ? headersOrBody : {})
|
|
754
|
+
});
|
|
755
|
+
const payload = hasSeparateBody ? body : headersOrBody;
|
|
756
|
+
if (!hasBody)
|
|
757
|
+
return tf.request(new http_1.HttpRequest(method, url, headers));
|
|
758
|
+
return tf.request(new http_1.HttpRequest(method, url, headers, payload));
|
|
759
|
+
}
|
|
760
|
+
function normalizeMockHeaders(headers) {
|
|
761
|
+
return Object.fromEntries(Object.entries(headers)
|
|
762
|
+
.filter((entry) => entry[1] !== undefined)
|
|
763
|
+
.map(([key, value]) => [key, Array.isArray(value) ? value.map(String).join(', ') : String(value)]));
|
|
764
|
+
}
|
|
765
|
+
function installStandardHooks(tf, options = {}) {
|
|
766
|
+
const suiteSeedSavepoint = 'after_suite_seed';
|
|
767
|
+
let suiteSeedUsesSavepoint = false;
|
|
768
|
+
(0, node_test_1.before)(async () => {
|
|
769
|
+
await tf.start();
|
|
770
|
+
if (options.suiteSeedData)
|
|
771
|
+
suiteSeedUsesSavepoint = await tf.createSeedSavepoint(suiteSeedSavepoint, options.suiteSeedData);
|
|
772
|
+
});
|
|
773
|
+
(0, node_test_1.after)(() => tf.stop());
|
|
774
|
+
(0, node_test_1.beforeEach)(async () => {
|
|
775
|
+
if (!options.suiteSeedData) {
|
|
776
|
+
await tf.resetToSeed();
|
|
777
|
+
return;
|
|
778
|
+
}
|
|
779
|
+
if (suiteSeedUsesSavepoint && (await tf.resetToSeedSavepoint(suiteSeedSavepoint)))
|
|
780
|
+
return;
|
|
781
|
+
await tf.resetToSeed();
|
|
782
|
+
await options.suiteSeedData(tf);
|
|
783
|
+
});
|
|
784
|
+
(0, node_test_1.afterEach)(() => {
|
|
785
|
+
tf.sql.clearMocks();
|
|
786
|
+
node_test_1.mock.timers.reset();
|
|
787
|
+
node_test_1.mock.restoreAll();
|
|
788
|
+
});
|
|
789
|
+
}
|
|
790
|
+
function resetSrcModuleCache() {
|
|
791
|
+
for (const key of Object.keys(require.cache)) {
|
|
792
|
+
if (key.includes('/dist/') || key.includes('/src/'))
|
|
793
|
+
delete require.cache[key];
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
function setDefaultDatabaseConfig(config) {
|
|
797
|
+
for (const [key, value] of Object.entries(config)) {
|
|
798
|
+
if (value === undefined || env_1.Env[key] !== undefined)
|
|
799
|
+
continue;
|
|
800
|
+
env_1.Env[key] = String(value);
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
async function cleanupTestDatabases(prefix = 'test', adapter) {
|
|
804
|
+
clearSharedTestDatabases(prefix, adapter);
|
|
805
|
+
const adapters = adapter ? [adapter] : ['mysql', 'postgres'].filter(item => hasDatabaseConfig(item));
|
|
806
|
+
for (const dbAdapter of adapters) {
|
|
807
|
+
const adminDb = createCleanupAdminDatabase(dbAdapter);
|
|
808
|
+
try {
|
|
809
|
+
if (dbAdapter === 'postgres') {
|
|
810
|
+
const rows = await adminDb.rawFindUnsafe('SELECT datname AS name FROM pg_database WHERE datname LIKE ?', [
|
|
811
|
+
`${prefix}%`
|
|
812
|
+
]);
|
|
813
|
+
for (const row of rows) {
|
|
814
|
+
await adminDb.rawExecute((0, sql_1.sql) `SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = ${row.name} AND pid <> pg_backend_pid()`);
|
|
815
|
+
await adminDb.rawExecute((0, sql_1.sql) `DROP DATABASE IF EXISTS ${sql_1.sql.identifier(row.name)}`);
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
else {
|
|
819
|
+
const rows = await adminDb.rawFindUnsafe('SELECT SCHEMA_NAME AS name FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME LIKE ?', [`${prefix}%`]);
|
|
820
|
+
for (const row of rows) {
|
|
821
|
+
await adminDb.rawExecute((0, sql_1.sql) `DROP DATABASE IF EXISTS ${sql_1.sql.identifier(row.name)}`);
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
finally {
|
|
826
|
+
await adminDb.driver.close();
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
function hasDatabaseConfig(adapter) {
|
|
831
|
+
return adapter === 'postgres' ? !!env_1.Env.PG_HOST : !!env_1.Env.MYSQL_HOST;
|
|
832
|
+
}
|
|
833
|
+
function createCleanupAdminDatabase(adapter) {
|
|
834
|
+
if (adapter === 'postgres') {
|
|
835
|
+
return new database_1.BaseDatabase(new database_1.PostgresDriver({
|
|
836
|
+
host: env_1.Env.PG_HOST,
|
|
837
|
+
port: env_1.Env.PG_PORT ? Number(env_1.Env.PG_PORT) : 5432,
|
|
838
|
+
user: env_1.Env.PG_USER,
|
|
839
|
+
password: env_1.Env.PG_PASSWORD_SECRET,
|
|
840
|
+
database: 'postgres',
|
|
841
|
+
ssl: readEnvBoolean(env_1.Env.PG_SSL) ? { rejectUnauthorized: readEnvBoolean(env_1.Env.PG_SSL_REJECT_UNAUTHORIZED, true) } : undefined,
|
|
842
|
+
max: 1
|
|
843
|
+
}));
|
|
844
|
+
}
|
|
845
|
+
return new database_1.BaseDatabase(new database_1.MySQLDriver({
|
|
846
|
+
host: env_1.Env.MYSQL_HOST,
|
|
847
|
+
port: env_1.Env.MYSQL_PORT ? Number(env_1.Env.MYSQL_PORT) : 3306,
|
|
848
|
+
user: env_1.Env.MYSQL_USER,
|
|
849
|
+
password: env_1.Env.MYSQL_PASSWORD_SECRET,
|
|
850
|
+
database: 'mysql',
|
|
851
|
+
connectionLimit: 1
|
|
852
|
+
}));
|
|
853
|
+
}
|
|
854
|
+
function readEnvBoolean(value, defaultValue = false) {
|
|
855
|
+
if (value === undefined)
|
|
856
|
+
return defaultValue;
|
|
857
|
+
if (typeof value === 'boolean')
|
|
858
|
+
return value;
|
|
859
|
+
return value === '1' || value === 'true';
|
|
860
|
+
}
|
|
861
|
+
exports.TestingHelpers = {
|
|
862
|
+
cleanupTestDatabases,
|
|
863
|
+
createTestingFacade,
|
|
864
|
+
createTestingFacadeBuilder,
|
|
865
|
+
createTestingFacadeWithDatabase,
|
|
866
|
+
defineEntityFixtures: fixtures_1.defineEntityFixtures,
|
|
867
|
+
installStandardHooks,
|
|
868
|
+
loadEntityFixtures: fixtures_1.loadEntityFixtures,
|
|
869
|
+
makeMockRequest,
|
|
870
|
+
prepareEntityFixtures: fixtures_1.prepareEntityFixtures,
|
|
871
|
+
resetSrcModuleCache,
|
|
872
|
+
SqlTestingHelper: sql_2.SqlTestingHelper,
|
|
873
|
+
setDefaultDatabaseConfig
|
|
874
|
+
};
|
|
875
|
+
const DATABASE_ENV_KEYS = [
|
|
876
|
+
'DB_ADAPTER',
|
|
877
|
+
'MYSQL_HOST',
|
|
878
|
+
'MYSQL_PORT',
|
|
879
|
+
'MYSQL_USER',
|
|
880
|
+
'MYSQL_PASSWORD_SECRET',
|
|
881
|
+
'MYSQL_DATABASE',
|
|
882
|
+
'MYSQL_CONNECTION_LIMIT',
|
|
883
|
+
'MYSQL_MIN_IDLE_CONNECTIONS',
|
|
884
|
+
'MYSQL_IDLE_TIMEOUT_SECONDS',
|
|
885
|
+
'PG_HOST',
|
|
886
|
+
'PG_PORT',
|
|
887
|
+
'PG_USER',
|
|
888
|
+
'PG_PASSWORD_SECRET',
|
|
889
|
+
'PG_DATABASE',
|
|
890
|
+
'PG_SCHEMA',
|
|
891
|
+
'PG_SSL',
|
|
892
|
+
'PG_SSL_REJECT_UNAUTHORIZED',
|
|
893
|
+
'PG_CONNECTION_LIMIT',
|
|
894
|
+
'PG_IDLE_TIMEOUT_SECONDS',
|
|
895
|
+
'TSF_TEST_DATABASE_NAME',
|
|
896
|
+
'TSF_TEST_ALLOW_SAVEPOINTS',
|
|
897
|
+
'TSF_TEST_MYSQL_SESSION_KEY',
|
|
898
|
+
'TSF_TEST_MYSQL_SESSION_LEASE_ID',
|
|
899
|
+
'TSF_TEST_MYSQL_SESSION_DATABASE'
|
|
900
|
+
];
|
|
901
|
+
let nextDatabaseId = 1;
|
|
902
|
+
let nextInlineMigrationId = 1;
|
|
903
|
+
let sharedDatabaseCleanupInstalled = false;
|
|
904
|
+
let sharedDatabaseCleanupStarted = false;
|
|
905
|
+
const inlineMigrationIds = new WeakMap();
|
|
906
|
+
const sharedTestDatabases = new Map();
|
|
907
|
+
function resolveTestDbAdapter(config, explicit) {
|
|
908
|
+
if (explicit)
|
|
909
|
+
return explicit;
|
|
910
|
+
if (config.DB_ADAPTER === 'mysql' || config.DB_ADAPTER === 'postgres')
|
|
911
|
+
return config.DB_ADAPTER;
|
|
912
|
+
if (env_1.Env.DB_ADAPTER === 'mysql' || env_1.Env.DB_ADAPTER === 'postgres')
|
|
913
|
+
return env_1.Env.DB_ADAPTER;
|
|
914
|
+
const hasPostgres = !!(config.PG_HOST ?? env_1.Env.PG_HOST);
|
|
915
|
+
const hasMySQL = !!(config.MYSQL_HOST ?? env_1.Env.MYSQL_HOST);
|
|
916
|
+
if (hasPostgres && !hasMySQL)
|
|
917
|
+
return 'postgres';
|
|
918
|
+
if (hasMySQL && !hasPostgres)
|
|
919
|
+
return 'mysql';
|
|
920
|
+
throw new Error("TestingFacade enableDatabase requires dbAdapter or DB_ADAPTER to be 'mysql' or 'postgres'");
|
|
921
|
+
}
|
|
922
|
+
function createTestDatabaseName(prefix = 'test') {
|
|
923
|
+
const ts = env_1.Env.TEST_RUN_TS ?? String(Math.floor(Date.now() / 1000));
|
|
924
|
+
const safePrefix = prefix.replace(/[^a-zA-Z0-9_]/g, '_') || 'test';
|
|
925
|
+
return `${safePrefix}_${ts}_${process.pid}_${nextDatabaseId++}`;
|
|
926
|
+
}
|
|
927
|
+
function getInlineMigrationIdentity(migration) {
|
|
928
|
+
let id = inlineMigrationIds.get(migration);
|
|
929
|
+
if (!id) {
|
|
930
|
+
id = nextInlineMigrationId++;
|
|
931
|
+
inlineMigrationIds.set(migration, id);
|
|
932
|
+
}
|
|
933
|
+
return id;
|
|
934
|
+
}
|
|
935
|
+
function installSharedDatabaseCleanup() {
|
|
936
|
+
if (sharedDatabaseCleanupInstalled)
|
|
937
|
+
return;
|
|
938
|
+
sharedDatabaseCleanupInstalled = true;
|
|
939
|
+
process.once('beforeExit', () => {
|
|
940
|
+
void cleanupSharedTestDatabases();
|
|
941
|
+
});
|
|
942
|
+
}
|
|
943
|
+
async function cleanupSharedTestDatabases() {
|
|
944
|
+
if (sharedDatabaseCleanupStarted)
|
|
945
|
+
return;
|
|
946
|
+
sharedDatabaseCleanupStarted = true;
|
|
947
|
+
const states = [...sharedTestDatabases.values()];
|
|
948
|
+
sharedTestDatabases.clear();
|
|
949
|
+
for (const state of states) {
|
|
950
|
+
if (state.keepDatabase || env_1.Env.TEST_KEEP_DB)
|
|
951
|
+
continue;
|
|
952
|
+
try {
|
|
953
|
+
await state.destroy();
|
|
954
|
+
}
|
|
955
|
+
catch {
|
|
956
|
+
// Best-effort process cleanup should not mask the original test result.
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
function clearSharedTestDatabases(prefix, adapter) {
|
|
961
|
+
for (const [key, state] of sharedTestDatabases) {
|
|
962
|
+
if (adapter && state.adapter !== adapter)
|
|
963
|
+
continue;
|
|
964
|
+
if (!state.databaseName.startsWith(prefix))
|
|
965
|
+
continue;
|
|
966
|
+
sharedTestDatabases.delete(key);
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
function snapshotDatabaseEnv() {
|
|
970
|
+
const snapshot = {};
|
|
971
|
+
for (const key of DATABASE_ENV_KEYS) {
|
|
972
|
+
if (env_1.Env[key] !== undefined)
|
|
973
|
+
snapshot[key] = env_1.Env[key];
|
|
974
|
+
}
|
|
975
|
+
return snapshot;
|
|
976
|
+
}
|
|
977
|
+
function restoreDatabaseEnv(snapshot) {
|
|
978
|
+
for (const key of DATABASE_ENV_KEYS) {
|
|
979
|
+
if (snapshot[key] === undefined)
|
|
980
|
+
delete env_1.Env[key];
|
|
981
|
+
else
|
|
982
|
+
env_1.Env[key] = snapshot[key];
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
function snapshotAppDatabaseConfig(config) {
|
|
986
|
+
return {
|
|
987
|
+
DB_ADAPTER: config.DB_ADAPTER,
|
|
988
|
+
MYSQL_DATABASE: config.MYSQL_DATABASE,
|
|
989
|
+
PG_DATABASE: config.PG_DATABASE
|
|
990
|
+
};
|
|
991
|
+
}
|
|
992
|
+
exports.__tsfTypeAliases = ({ "AsymmetricMatcher": { kind: 18, typeName: "AsymmetricMatcher", types: [], index: { kind: 10, literal: true } }, "BodyMockMethod": { kind: 16, typeName: "Exclude", classType: () => (typeof Exclude !== "undefined" ? Exclude : (typeof exports !== "undefined" ? exports.Exclude : undefined)), typeArguments: [{ kind: 12, types: [{ kind: 10, literal: "GET" }, { kind: 10, literal: "PUT" }, { kind: 10, literal: "POST" }, { kind: 10, literal: "PATCH" }, { kind: 10, literal: "DELETE" }], typeName: "MockMethod" }, { kind: 10, literal: "GET", typeName: "BodylessMockMethod" }], typeName: "BodyMockMethod" }, "BodylessMockMethod": { kind: 10, literal: "GET", typeName: "BodylessMockMethod" }, "DatabaseEnvSnapshot": { kind: 18, typeName: "Partial", utilityType: "Partial", typeArguments: [{ kind: 18, typeName: "Record", utilityType: "Record", typeArguments: [{ kind: 2, typeName: "(typeof DATABASE_ENV_KEYS)[number]" }, { kind: 6 }], index: { kind: 6 }, types: [] }], utilityKeys: [], types: [], typeName: "DatabaseEnvSnapshot" }, "MockBody": { kind: 2, typeName: "MockBody" }, "MockHeaders": { kind: 18, typeName: "Record", utilityType: "Record", typeArguments: [{ kind: 6 }, { kind: 2 }], index: { kind: 2 }, types: [], typeName: "MockHeaders" }, "MockMethod": { kind: 12, types: [{ kind: 10, literal: "GET" }, { kind: 10, literal: "PUT" }, { kind: 10, literal: "POST" }, { kind: 10, literal: "PATCH" }, { kind: 10, literal: "DELETE" }], typeName: "MockMethod" }, "SharedTestDatabaseState": { kind: 18, typeName: "SharedTestDatabaseState", types: [{ kind: 20, name: "key", type: { kind: 6 }, optional: false }, { kind: 20, name: "adapter", type: { kind: 12, types: [{ kind: 10, literal: "mysql" }, { kind: 10, literal: "postgres" }], typeName: "DatabaseDialect", typeName: "TestDbAdapter" }, optional: false }, { kind: 20, name: "databaseName", type: { kind: 6 }, optional: false }, { kind: 20, name: "databaseReady", type: { kind: 12, types: [{ kind: 22, type: { kind: 3 } }, { kind: 4 }] }, optional: true }, { kind: 20, name: "schemaReady", type: { kind: 12, types: [{ kind: 22, type: { kind: 3 } }, { kind: 4 }] }, optional: true }, { kind: 20, name: "references", type: { kind: 7 }, optional: false }, { kind: 20, name: "keepDatabase", type: { kind: 8 }, optional: false }, { kind: 20, name: "destroy", type: { kind: 2, typeName: "() => Promise<void>" }, optional: false }] }, "StandardHookOptions": { kind: 18, typeName: "StandardHookOptions", types: [{ kind: 20, name: "suiteSeedData", type: { kind: 12, types: [{ kind: 2, typeName: "TestingFacadeSeedData", typeArguments: [{ kind: 2, typeName: "C" }] }, { kind: 4 }] }, optional: true }] }, "TestDbAdapter": { kind: 12, types: [{ kind: 10, literal: "mysql" }, { kind: 10, literal: "postgres" }], typeName: "DatabaseDialect", typeName: "TestDbAdapter" }, "TestingFacadeOptions": { kind: 18, typeName: "TestingFacadeOptions", types: [{ kind: 20, name: "defaultTestHeaders", type: { kind: 12, types: [{ kind: 18, typeName: "Record", utilityType: "Record", typeArguments: [{ kind: 6 }, { kind: 6 }], index: { kind: 6 }, types: [] }, { kind: 4 }] }, optional: true }, { kind: 20, name: "seedData", type: { kind: 12, types: [{ kind: 2, typeName: "TestingFacadeSeedData", typeArguments: [{ kind: 2, typeName: "C" }] }, { kind: 4 }] }, optional: true }, { kind: 20, name: "autoSeedData", type: { kind: 12, types: [{ kind: 8 }, { kind: 4 }] }, optional: true }, { kind: 20, name: "onBeforeStart", type: { kind: 12, types: [{ kind: 2, typeName: "(facade: TestingFacade<C>) => Promise<void> | void" }, { kind: 4 }] }, optional: true }, { kind: 20, name: "onStart", type: { kind: 12, types: [{ kind: 2, typeName: "(facade: TestingFacade<C>) => Promise<void> | void" }, { kind: 4 }] }, optional: true }, { kind: 20, name: "onBeforeStop", type: { kind: 12, types: [{ kind: 2, typeName: "(facade: TestingFacade<C>) => Promise<void> | void" }, { kind: 4 }] }, optional: true }, { kind: 20, name: "onStop", type: { kind: 12, types: [{ kind: 2, typeName: "(facade: TestingFacade<C>) => Promise<void> | void" }, { kind: 4 }] }, optional: true }, { kind: 20, name: "enableDatabase", type: { kind: 12, types: [{ kind: 8 }, { kind: 4 }] }, optional: true }, { kind: 20, name: "dbAdapter", type: { kind: 12, types: [{ kind: 12, types: [{ kind: 10, literal: "mysql" }, { kind: 10, literal: "postgres" }], typeName: "DatabaseDialect", typeName: "TestDbAdapter" }, { kind: 4 }] }, optional: true }, { kind: 20, name: "useSavepoints", type: { kind: 12, types: [{ kind: 8 }, { kind: 4 }] }, optional: true }, { kind: 20, name: "databasePrefix", type: { kind: 12, types: [{ kind: 6 }, { kind: 4 }] }, optional: true }, { kind: 20, name: "keepDatabase", type: { kind: 12, types: [{ kind: 8 }, { kind: 4 }] }, optional: true }, { kind: 20, name: "enableMigrations", type: { kind: 12, types: [{ kind: 8 }, { kind: 4 }] }, optional: true }, { kind: 20, name: "schemaFromEntities", type: { kind: 12, types: [{ kind: 12, types: [{ kind: 8 }, { kind: 18, typeName: "CreateMigrationPlanOptions", types: [{ kind: 20, name: "pgSchema", type: { kind: 12, types: [{ kind: 6 }, { kind: 4 }] }, optional: true }, { kind: 20, name: "tableNames", type: { kind: 12, types: [{ kind: 14, type: { kind: 6 } }, { kind: 4 }] }, optional: true }] }] }, { kind: 4 }] }, optional: true }, { kind: 20, name: "migrations", type: { kind: 12, types: [{ kind: 14, type: { kind: 18, typeName: "Migration", types: [{ kind: 20, name: "name", type: { kind: 6 }, optional: false }, { kind: 20, name: "up", type: { kind: 2, typeName: "MigrationFunction", typeArguments: [{ kind: 2, typeName: "T" }] }, optional: false }] } }, { kind: 4 }] }, optional: true }, { kind: 20, name: "migrationsDir", type: { kind: 12, types: [{ kind: 12, types: [{ kind: 6 }, { kind: 14, type: { kind: 6 } }] }, { kind: 4 }] }, optional: true }, { kind: 20, name: "truncateAfterMigrations", type: { kind: 12, types: [{ kind: 8 }, { kind: 4 }] }, optional: true }] } });
|
|
993
|
+
//# sourceMappingURL=index.js.map
|