@warlock.js/cascade 4.1.15 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/LICENSE +21 -0
- package/cjs/index.cjs +21388 -0
- package/cjs/index.cjs.map +1 -0
- package/esm/context/database-data-source-context.d.mts +1 -1
- package/esm/context/database-data-source-context.d.mts.map +1 -1
- package/esm/context/database-data-source-context.mjs +1 -1
- package/esm/context/database-data-source-context.mjs.map +1 -1
- package/esm/context/database-transaction-context.d.mts +1 -1
- package/esm/context/database-transaction-context.d.mts.map +1 -1
- package/esm/context/database-transaction-context.mjs +1 -1
- package/esm/context/database-transaction-context.mjs.map +1 -1
- package/esm/contracts/database-driver.contract.d.mts +1 -1
- package/esm/contracts/database-driver.contract.d.mts.map +1 -1
- package/esm/contracts/database-id-generator.contract.d.mts +1 -1
- package/esm/contracts/database-id-generator.contract.d.mts.map +1 -1
- package/esm/contracts/database-remover.contract.d.mts +1 -1
- package/esm/contracts/database-remover.contract.d.mts.map +1 -1
- package/esm/contracts/database-restorer.contract.d.mts +1 -1
- package/esm/contracts/database-restorer.contract.d.mts.map +1 -1
- package/esm/contracts/database-writer.contract.d.mts +1 -1
- package/esm/contracts/database-writer.contract.d.mts.map +1 -1
- package/esm/contracts/driver-blueprint.contract.d.mts +1 -1
- package/esm/contracts/driver-blueprint.contract.d.mts.map +1 -1
- package/esm/contracts/migration-driver.contract.d.mts +1 -1
- package/esm/contracts/migration-driver.contract.d.mts.map +1 -1
- package/esm/contracts/query-builder.contract.d.mts +1 -1
- package/esm/contracts/query-builder.contract.d.mts.map +1 -1
- package/esm/contracts/sync-adapter.contract.d.mts +1 -1
- package/esm/contracts/sync-adapter.contract.d.mts.map +1 -1
- package/esm/data-source/data-source-registry.d.mts +1 -1
- package/esm/data-source/data-source-registry.d.mts.map +1 -1
- package/esm/data-source/data-source-registry.mjs +1 -1
- package/esm/data-source/data-source-registry.mjs.map +1 -1
- package/esm/data-source/data-source.d.mts +1 -1
- package/esm/data-source/data-source.d.mts.map +1 -1
- package/esm/data-source/data-source.mjs +1 -1
- package/esm/data-source/data-source.mjs.map +1 -1
- package/esm/database-dirty-tracker.d.mts +1 -1
- package/esm/database-dirty-tracker.d.mts.map +1 -1
- package/esm/database-dirty-tracker.mjs +1 -1
- package/esm/database-dirty-tracker.mjs.map +1 -1
- package/esm/drivers/mongodb/mongodb-blueprint.mjs +1 -1
- package/esm/drivers/mongodb/mongodb-blueprint.mjs.map +1 -1
- package/esm/drivers/mongodb/mongodb-driver.d.mts +1 -1
- package/esm/drivers/mongodb/mongodb-driver.d.mts.map +1 -1
- package/esm/drivers/mongodb/mongodb-driver.mjs +2 -2
- package/esm/drivers/mongodb/mongodb-driver.mjs.map +1 -1
- package/esm/drivers/mongodb/mongodb-id-generator.d.mts +1 -1
- package/esm/drivers/mongodb/mongodb-id-generator.d.mts.map +1 -1
- package/esm/drivers/mongodb/mongodb-id-generator.mjs +1 -1
- package/esm/drivers/mongodb/mongodb-id-generator.mjs.map +1 -1
- package/esm/drivers/mongodb/mongodb-migration-driver.d.mts +1 -1
- package/esm/drivers/mongodb/mongodb-migration-driver.d.mts.map +1 -1
- package/esm/drivers/mongodb/mongodb-migration-driver.mjs +1 -1
- package/esm/drivers/mongodb/mongodb-migration-driver.mjs.map +1 -1
- package/esm/drivers/mongodb/mongodb-query-builder.d.mts +1 -1
- package/esm/drivers/mongodb/mongodb-query-builder.d.mts.map +1 -1
- package/esm/drivers/mongodb/mongodb-query-builder.mjs +1 -1
- package/esm/drivers/mongodb/mongodb-query-builder.mjs.map +1 -1
- package/esm/drivers/mongodb/mongodb-query-operations.d.mts +1 -1
- package/esm/drivers/mongodb/mongodb-query-operations.d.mts.map +1 -1
- package/esm/drivers/mongodb/mongodb-query-operations.mjs +1 -1
- package/esm/drivers/mongodb/mongodb-query-operations.mjs.map +1 -1
- package/esm/drivers/mongodb/mongodb-query-parser.d.mts +1 -1
- package/esm/drivers/mongodb/mongodb-query-parser.d.mts.map +1 -1
- package/esm/drivers/mongodb/mongodb-query-parser.mjs +1 -1
- package/esm/drivers/mongodb/mongodb-query-parser.mjs.map +1 -1
- package/esm/drivers/mongodb/mongodb-sync-adapter.d.mts +1 -1
- package/esm/drivers/mongodb/mongodb-sync-adapter.d.mts.map +1 -1
- package/esm/drivers/mongodb/mongodb-sync-adapter.mjs +1 -1
- package/esm/drivers/mongodb/mongodb-sync-adapter.mjs.map +1 -1
- package/esm/drivers/mongodb/types.d.mts +1 -1
- package/esm/drivers/mongodb/types.d.mts.map +1 -1
- package/esm/drivers/postgres/postgres-blueprint.d.mts +1 -1
- package/esm/drivers/postgres/postgres-blueprint.d.mts.map +1 -1
- package/esm/drivers/postgres/postgres-blueprint.mjs +1 -1
- package/esm/drivers/postgres/postgres-blueprint.mjs.map +1 -1
- package/esm/drivers/postgres/postgres-dialect.d.mts +1 -1
- package/esm/drivers/postgres/postgres-dialect.d.mts.map +1 -1
- package/esm/drivers/postgres/postgres-dialect.mjs +1 -1
- package/esm/drivers/postgres/postgres-dialect.mjs.map +1 -1
- package/esm/drivers/postgres/postgres-driver.d.mts +1 -1
- package/esm/drivers/postgres/postgres-driver.d.mts.map +1 -1
- package/esm/drivers/postgres/postgres-driver.mjs +2 -2
- package/esm/drivers/postgres/postgres-driver.mjs.map +1 -1
- package/esm/drivers/postgres/postgres-migration-driver.d.mts +1 -1
- package/esm/drivers/postgres/postgres-migration-driver.d.mts.map +1 -1
- package/esm/drivers/postgres/postgres-migration-driver.mjs +1 -1
- package/esm/drivers/postgres/postgres-migration-driver.mjs.map +1 -1
- package/esm/drivers/postgres/postgres-query-builder.d.mts +1 -1
- package/esm/drivers/postgres/postgres-query-builder.d.mts.map +1 -1
- package/esm/drivers/postgres/postgres-query-builder.mjs +7 -5
- package/esm/drivers/postgres/postgres-query-builder.mjs.map +1 -1
- package/esm/drivers/postgres/postgres-query-parser.d.mts +1 -1
- package/esm/drivers/postgres/postgres-query-parser.d.mts.map +1 -1
- package/esm/drivers/postgres/postgres-query-parser.mjs +1 -1
- package/esm/drivers/postgres/postgres-query-parser.mjs.map +1 -1
- package/esm/drivers/postgres/postgres-sql-serializer.mjs +1 -1
- package/esm/drivers/postgres/postgres-sql-serializer.mjs.map +1 -1
- package/esm/drivers/postgres/postgres-sync-adapter.d.mts +1 -1
- package/esm/drivers/postgres/postgres-sync-adapter.d.mts.map +1 -1
- package/esm/drivers/postgres/postgres-sync-adapter.mjs +1 -1
- package/esm/drivers/postgres/postgres-sync-adapter.mjs.map +1 -1
- package/esm/drivers/postgres/types.d.mts +1 -1
- package/esm/drivers/postgres/types.d.mts.map +1 -1
- package/esm/drivers/sql/sql-dialect.contract.d.mts +1 -1
- package/esm/drivers/sql/sql-dialect.contract.d.mts.map +1 -1
- package/esm/drivers/sql/sql-types.d.mts +1 -1
- package/esm/drivers/sql/sql-types.d.mts.map +1 -1
- package/esm/errors/missing-data-source.error.d.mts +1 -1
- package/esm/errors/missing-data-source.error.d.mts.map +1 -1
- package/esm/errors/missing-data-source.error.mjs +1 -1
- package/esm/errors/missing-data-source.error.mjs.map +1 -1
- package/esm/errors/transaction-rollback.error.d.mts +1 -1
- package/esm/errors/transaction-rollback.error.d.mts.map +1 -1
- package/esm/errors/transaction-rollback.error.mjs +1 -1
- package/esm/errors/transaction-rollback.error.mjs.map +1 -1
- package/esm/events/model-events.d.mts +1 -1
- package/esm/events/model-events.d.mts.map +1 -1
- package/esm/events/model-events.mjs +1 -1
- package/esm/events/model-events.mjs.map +1 -1
- package/esm/expressions/aggregate-expressions.d.mts +1 -1
- package/esm/expressions/aggregate-expressions.d.mts.map +1 -1
- package/esm/expressions/aggregate-expressions.mjs +1 -1
- package/esm/expressions/aggregate-expressions.mjs.map +1 -1
- package/esm/migration/column-builder.d.mts +1 -1
- package/esm/migration/column-builder.d.mts.map +1 -1
- package/esm/migration/column-builder.mjs +1 -1
- package/esm/migration/column-builder.mjs.map +1 -1
- package/esm/migration/column-helpers.d.mts +1 -1
- package/esm/migration/column-helpers.d.mts.map +1 -1
- package/esm/migration/column-helpers.mjs +1 -1
- package/esm/migration/column-helpers.mjs.map +1 -1
- package/esm/migration/foreign-key-builder.d.mts +1 -1
- package/esm/migration/foreign-key-builder.d.mts.map +1 -1
- package/esm/migration/foreign-key-builder.mjs +1 -1
- package/esm/migration/foreign-key-builder.mjs.map +1 -1
- package/esm/migration/migration-runner.d.mts +1 -1
- package/esm/migration/migration-runner.d.mts.map +1 -1
- package/esm/migration/migration-runner.mjs +1 -1
- package/esm/migration/migration-runner.mjs.map +1 -1
- package/esm/migration/migration.d.mts +1 -1
- package/esm/migration/migration.d.mts.map +1 -1
- package/esm/migration/migration.mjs +1 -1
- package/esm/migration/migration.mjs.map +1 -1
- package/esm/migration/sql-grammar.mjs +1 -1
- package/esm/migration/sql-grammar.mjs.map +1 -1
- package/esm/migration/sql-serializer.d.mts +1 -1
- package/esm/migration/sql-serializer.d.mts.map +1 -1
- package/esm/migration/sql-serializer.mjs +1 -1
- package/esm/migration/sql-serializer.mjs.map +1 -1
- package/esm/migration/types.d.mts +1 -1
- package/esm/migration/types.d.mts.map +1 -1
- package/esm/model/methods/accessor-methods.mjs +1 -1
- package/esm/model/methods/accessor-methods.mjs.map +1 -1
- package/esm/model/methods/delete-methods.mjs +1 -1
- package/esm/model/methods/delete-methods.mjs.map +1 -1
- package/esm/model/methods/dirty-methods.mjs +1 -1
- package/esm/model/methods/dirty-methods.mjs.map +1 -1
- package/esm/model/methods/hydration-methods.mjs +1 -1
- package/esm/model/methods/hydration-methods.mjs.map +1 -1
- package/esm/model/methods/instance-event-methods.mjs +1 -1
- package/esm/model/methods/instance-event-methods.mjs.map +1 -1
- package/esm/model/methods/meta-methods.mjs +1 -1
- package/esm/model/methods/meta-methods.mjs.map +1 -1
- package/esm/model/methods/pivot-methods.mjs +1 -1
- package/esm/model/methods/pivot-methods.mjs.map +1 -1
- package/esm/model/methods/query-methods.mjs +1 -1
- package/esm/model/methods/query-methods.mjs.map +1 -1
- package/esm/model/methods/restore-methods.mjs +1 -1
- package/esm/model/methods/restore-methods.mjs.map +1 -1
- package/esm/model/methods/scope-methods.mjs +1 -1
- package/esm/model/methods/scope-methods.mjs.map +1 -1
- package/esm/model/methods/serialization-methods.mjs +1 -1
- package/esm/model/methods/serialization-methods.mjs.map +1 -1
- package/esm/model/methods/static-event-methods.mjs +1 -1
- package/esm/model/methods/static-event-methods.mjs.map +1 -1
- package/esm/model/methods/write-methods.mjs +1 -1
- package/esm/model/methods/write-methods.mjs.map +1 -1
- package/esm/model/model.d.mts +1 -1
- package/esm/model/model.d.mts.map +1 -1
- package/esm/model/model.mjs +1 -1
- package/esm/model/model.mjs.map +1 -1
- package/esm/model/model.types.d.mts +1 -1
- package/esm/model/model.types.d.mts.map +1 -1
- package/esm/model/register-model.d.mts +1 -1
- package/esm/model/register-model.d.mts.map +1 -1
- package/esm/model/register-model.mjs +1 -1
- package/esm/model/register-model.mjs.map +1 -1
- package/esm/model/relation-decorators.d.mts +1 -1
- package/esm/model/relation-decorators.d.mts.map +1 -1
- package/esm/model/relation-decorators.mjs +2 -2
- package/esm/model/relation-decorators.mjs.map +1 -1
- package/esm/operations/database.d.mts +1 -1
- package/esm/operations/database.d.mts.map +1 -1
- package/esm/operations/database.mjs +1 -1
- package/esm/operations/database.mjs.map +1 -1
- package/esm/operations/migrations.d.mts +1 -1
- package/esm/operations/migrations.d.mts.map +1 -1
- package/esm/operations/migrations.mjs +1 -1
- package/esm/operations/migrations.mjs.map +1 -1
- package/esm/query-builder/query-builder.d.mts +1 -1
- package/esm/query-builder/query-builder.d.mts.map +1 -1
- package/esm/query-builder/query-builder.mjs +1 -1
- package/esm/query-builder/query-builder.mjs.map +1 -1
- package/esm/relations/key-conventions.mjs +1 -1
- package/esm/relations/key-conventions.mjs.map +1 -1
- package/esm/relations/pivot-operations.d.mts +1 -1
- package/esm/relations/pivot-operations.d.mts.map +1 -1
- package/esm/relations/pivot-operations.mjs +1 -1
- package/esm/relations/pivot-operations.mjs.map +1 -1
- package/esm/relations/relation-hydrator.d.mts +1 -1
- package/esm/relations/relation-hydrator.d.mts.map +1 -1
- package/esm/relations/relation-hydrator.mjs +1 -1
- package/esm/relations/relation-hydrator.mjs.map +1 -1
- package/esm/relations/relation-loader.d.mts +1 -1
- package/esm/relations/relation-loader.d.mts.map +1 -1
- package/esm/relations/relation-loader.mjs +1 -1
- package/esm/relations/relation-loader.mjs.map +1 -1
- package/esm/relations/types.d.mts +1 -1
- package/esm/relations/types.d.mts.map +1 -1
- package/esm/remover/database-remover.d.mts +1 -1
- package/esm/remover/database-remover.d.mts.map +1 -1
- package/esm/remover/database-remover.mjs +1 -1
- package/esm/remover/database-remover.mjs.map +1 -1
- package/esm/restorer/database-restorer.d.mts +1 -1
- package/esm/restorer/database-restorer.d.mts.map +1 -1
- package/esm/restorer/database-restorer.mjs +1 -1
- package/esm/restorer/database-restorer.mjs.map +1 -1
- package/esm/sql-database-dirty-tracker.d.mts +1 -1
- package/esm/sql-database-dirty-tracker.d.mts.map +1 -1
- package/esm/sql-database-dirty-tracker.mjs +1 -1
- package/esm/sql-database-dirty-tracker.mjs.map +1 -1
- package/esm/sync/model-events.mjs +1 -1
- package/esm/sync/model-events.mjs.map +1 -1
- package/esm/sync/model-sync-operation.d.mts +1 -1
- package/esm/sync/model-sync-operation.d.mts.map +1 -1
- package/esm/sync/model-sync-operation.mjs +1 -1
- package/esm/sync/model-sync-operation.mjs.map +1 -1
- package/esm/sync/model-sync.d.mts +1 -1
- package/esm/sync/model-sync.d.mts.map +1 -1
- package/esm/sync/model-sync.mjs +1 -1
- package/esm/sync/model-sync.mjs.map +1 -1
- package/esm/sync/sync-context.d.mts +1 -1
- package/esm/sync/sync-context.d.mts.map +1 -1
- package/esm/sync/sync-context.mjs +1 -1
- package/esm/sync/sync-context.mjs.map +1 -1
- package/esm/sync/sync-manager.d.mts +1 -1
- package/esm/sync/sync-manager.d.mts.map +1 -1
- package/esm/sync/sync-manager.mjs +1 -1
- package/esm/sync/sync-manager.mjs.map +1 -1
- package/esm/sync/types.d.mts +1 -1
- package/esm/sync/types.d.mts.map +1 -1
- package/esm/types.d.mts +1 -1
- package/esm/types.d.mts.map +1 -1
- package/esm/utils/connect-to-database.d.mts +1 -1
- package/esm/utils/connect-to-database.d.mts.map +1 -1
- package/esm/utils/connect-to-database.mjs +1 -1
- package/esm/utils/connect-to-database.mjs.map +1 -1
- package/esm/utils/database-writer.utils.d.mts +1 -1
- package/esm/utils/database-writer.utils.d.mts.map +1 -1
- package/esm/utils/database-writer.utils.mjs +1 -1
- package/esm/utils/database-writer.utils.mjs.map +1 -1
- package/esm/utils/define-model.d.mts +1 -1
- package/esm/utils/define-model.d.mts.map +1 -1
- package/esm/utils/define-model.mjs +1 -1
- package/esm/utils/define-model.mjs.map +1 -1
- package/esm/utils/is-valid-date-value.mjs +1 -1
- package/esm/utils/is-valid-date-value.mjs.map +1 -1
- package/esm/utils/once-connected.d.mts +1 -1
- package/esm/utils/once-connected.d.mts.map +1 -1
- package/esm/utils/once-connected.mjs +1 -1
- package/esm/utils/once-connected.mjs.map +1 -1
- package/esm/validation/database-seal-plugins.mjs +1 -1
- package/esm/validation/database-seal-plugins.mjs.map +1 -1
- package/esm/validation/database-writer-validation-error.d.mts +1 -1
- package/esm/validation/database-writer-validation-error.d.mts.map +1 -1
- package/esm/validation/database-writer-validation-error.mjs +1 -1
- package/esm/validation/database-writer-validation-error.mjs.map +1 -1
- package/esm/validation/mutators/embed-mutator.mjs +1 -1
- package/esm/validation/mutators/embed-mutator.mjs.map +1 -1
- package/esm/validation/plugins/database-rules-plugin.d.mts +1 -1
- package/esm/validation/plugins/database-rules-plugin.d.mts.map +1 -1
- package/esm/validation/plugins/database-rules-plugin.mjs +1 -1
- package/esm/validation/plugins/database-rules-plugin.mjs.map +1 -1
- package/esm/validation/plugins/embed-validator-plugin.d.mts +1 -1
- package/esm/validation/plugins/embed-validator-plugin.d.mts.map +1 -1
- package/esm/validation/plugins/embed-validator-plugin.mjs +1 -1
- package/esm/validation/plugins/embed-validator-plugin.mjs.map +1 -1
- package/esm/validation/rules/database-model-rule.mjs +1 -1
- package/esm/validation/rules/database-model-rule.mjs.map +1 -1
- package/esm/validation/rules/exists-rule.mjs +1 -1
- package/esm/validation/rules/exists-rule.mjs.map +1 -1
- package/esm/validation/rules/unique-rule.mjs +1 -1
- package/esm/validation/rules/unique-rule.mjs.map +1 -1
- package/esm/validation/transformers/embed-model-transformer.mjs +1 -1
- package/esm/validation/transformers/embed-model-transformer.mjs.map +1 -1
- package/esm/validation/types.d.mts +1 -1
- package/esm/validation/types.d.mts.map +1 -1
- package/esm/validation/validators/embed-validator.d.mts +1 -1
- package/esm/validation/validators/embed-validator.d.mts.map +1 -1
- package/esm/validation/validators/embed-validator.mjs +1 -1
- package/esm/validation/validators/embed-validator.mjs.map +1 -1
- package/esm/writer/database-writer.d.mts +1 -1
- package/esm/writer/database-writer.d.mts.map +1 -1
- package/esm/writer/database-writer.mjs +1 -1
- package/esm/writer/database-writer.mjs.map +1 -1
- package/llms-full.txt +535 -0
- package/llms.txt +1 -0
- package/package.json +9 -12
- package/skills/README.md +4 -0
- package/skills/alter-migration/SKILL.md +531 -0
- package/bin/cascade.js +0 -3
- package/bin/cascadejs +0 -3
- package/esm/cli/commands/migrate-export-sql.mjs +0 -48
- package/esm/cli/commands/migrate-export-sql.mjs.map +0 -1
- package/esm/cli/commands/migrate-list.mjs +0 -26
- package/esm/cli/commands/migrate-list.mjs.map +0 -1
- package/esm/cli/commands/migrate-rollback.mjs +0 -50
- package/esm/cli/commands/migrate-rollback.mjs.map +0 -1
- package/esm/cli/commands/migrate.mjs +0 -65
- package/esm/cli/commands/migrate.mjs.map +0 -1
- package/esm/cli/connection-from-env.mjs +0 -181
- package/esm/cli/connection-from-env.mjs.map +0 -1
- package/esm/cli/index.mjs +0 -31
- package/esm/cli/index.mjs.map +0 -1
- package/esm/cli/load-migrations.mjs +0 -78
- package/esm/cli/load-migrations.mjs.map +0 -1
- package/esm/cli/printers.mjs +0 -57
- package/esm/cli/printers.mjs.map +0 -1
- package/esm/cli/setup-logger.mjs +0 -30
- package/esm/cli/setup-logger.mjs.map +0 -1
- package/esm/cli/with-cli-connection.mjs +0 -39
- package/esm/cli/with-cli-connection.mjs.map +0 -1
- package/esm/cli.d.mts +0 -1
- package/esm/cli.mjs +0 -26
- package/esm/cli.mjs.map +0 -1
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { exportMigrationsSQL, freshMigrate, runMigrations } from "../../operations/migrations.mjs";
|
|
2
|
-
import { loadMigrations } from "../load-migrations.mjs";
|
|
3
|
-
import { printRunSummary } from "../printers.mjs";
|
|
4
|
-
import { withCliConnection } from "../with-cli-connection.mjs";
|
|
5
|
-
import { defineCommand } from "citty";
|
|
6
|
-
|
|
7
|
-
//#region ../../@warlock.js/cascade/src/cli/commands/migrate.ts
|
|
8
|
-
/**
|
|
9
|
-
* `cascade migrate` — run all pending migrations against the configured
|
|
10
|
-
* data source. With `--fresh` rolls back everything first and re-runs;
|
|
11
|
-
* with `--sql` writes phase-ordered SQL files instead of executing.
|
|
12
|
-
*/
|
|
13
|
-
const migrateCommand = defineCommand({
|
|
14
|
-
meta: {
|
|
15
|
-
name: "migrate",
|
|
16
|
-
description: "Run all pending migrations against the configured data source."
|
|
17
|
-
},
|
|
18
|
-
args: {
|
|
19
|
-
fresh: {
|
|
20
|
-
type: "boolean",
|
|
21
|
-
alias: "f",
|
|
22
|
-
description: "Roll back every executed migration first, then run them again.",
|
|
23
|
-
default: false
|
|
24
|
-
},
|
|
25
|
-
sql: {
|
|
26
|
-
type: "boolean",
|
|
27
|
-
alias: "s",
|
|
28
|
-
description: "Export migrations to phase-ordered SQL files instead of executing.",
|
|
29
|
-
default: false
|
|
30
|
-
},
|
|
31
|
-
"pending-only": {
|
|
32
|
-
type: "boolean",
|
|
33
|
-
description: "When used with --sql, export only pending migrations.",
|
|
34
|
-
default: false
|
|
35
|
-
},
|
|
36
|
-
compact: {
|
|
37
|
-
type: "boolean",
|
|
38
|
-
alias: "c",
|
|
39
|
-
description: "When used with --sql, strip generated comments and blank lines.",
|
|
40
|
-
default: false
|
|
41
|
-
},
|
|
42
|
-
path: {
|
|
43
|
-
type: "string",
|
|
44
|
-
alias: "p",
|
|
45
|
-
description: "Glob pattern overriding the default ./migrations/**/*.{ts,js,mjs,cjs}."
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
async run({ args }) {
|
|
49
|
-
await withCliConnection(async () => {
|
|
50
|
-
await loadMigrations(args.path);
|
|
51
|
-
if (args.sql) {
|
|
52
|
-
await exportMigrationsSQL({
|
|
53
|
-
pendingOnly: Boolean(args["pending-only"]),
|
|
54
|
-
compact: Boolean(args.compact)
|
|
55
|
-
});
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
printRunSummary(args.fresh ? await freshMigrate() : await runMigrations());
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
//#endregion
|
|
64
|
-
export { migrateCommand };
|
|
65
|
-
//# sourceMappingURL=migrate.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"migrate.mjs","names":[],"sources":["../../../../../../../@warlock.js/cascade/src/cli/commands/migrate.ts"],"sourcesContent":["import { defineCommand } from \"citty\";\nimport {\n exportMigrationsSQL,\n freshMigrate,\n runMigrations,\n} from \"../../operations/migrations\";\nimport { loadMigrations } from \"../load-migrations\";\nimport { printRunSummary } from \"../printers\";\nimport { withCliConnection } from \"../with-cli-connection\";\n\n/**\n * `cascade migrate` — run all pending migrations against the configured\n * data source. With `--fresh` rolls back everything first and re-runs;\n * with `--sql` writes phase-ordered SQL files instead of executing.\n */\nexport const migrateCommand = defineCommand({\n meta: {\n name: \"migrate\",\n description: \"Run all pending migrations against the configured data source.\",\n },\n args: {\n fresh: {\n type: \"boolean\",\n alias: \"f\",\n description: \"Roll back every executed migration first, then run them again.\",\n default: false,\n },\n sql: {\n type: \"boolean\",\n alias: \"s\",\n description: \"Export migrations to phase-ordered SQL files instead of executing.\",\n default: false,\n },\n \"pending-only\": {\n type: \"boolean\",\n description: \"When used with --sql, export only pending migrations.\",\n default: false,\n },\n compact: {\n type: \"boolean\",\n alias: \"c\",\n description: \"When used with --sql, strip generated comments and blank lines.\",\n default: false,\n },\n path: {\n type: \"string\",\n alias: \"p\",\n description: \"Glob pattern overriding the default ./migrations/**/*.{ts,js,mjs,cjs}.\",\n },\n },\n async run({ args }) {\n await withCliConnection(async () => {\n await loadMigrations(args.path);\n\n if (args.sql) {\n await exportMigrationsSQL({\n pendingOnly: Boolean(args[\"pending-only\"]),\n compact: Boolean(args.compact),\n });\n\n return;\n }\n\n const results = args.fresh ? await freshMigrate() : await runMigrations();\n\n printRunSummary(results);\n });\n },\n});\n"],"mappings":";;;;;;;;;;;;AAeA,MAAa,iBAAiB,cAAc;CAC1C,MAAM;EACJ,MAAM;EACN,aAAa;CACf;CACA,MAAM;EACJ,OAAO;GACL,MAAM;GACN,OAAO;GACP,aAAa;GACb,SAAS;EACX;EACA,KAAK;GACH,MAAM;GACN,OAAO;GACP,aAAa;GACb,SAAS;EACX;EACA,gBAAgB;GACd,MAAM;GACN,aAAa;GACb,SAAS;EACX;EACA,SAAS;GACP,MAAM;GACN,OAAO;GACP,aAAa;GACb,SAAS;EACX;EACA,MAAM;GACJ,MAAM;GACN,OAAO;GACP,aAAa;EACf;CACF;CACA,MAAM,IAAI,EAAE,QAAQ;EAClB,MAAM,kBAAkB,YAAY;GAClC,MAAM,eAAe,KAAK,IAAI;GAE9B,IAAI,KAAK,KAAK;IACZ,MAAM,oBAAoB;KACxB,aAAa,QAAQ,KAAK,eAAe;KACzC,SAAS,QAAQ,KAAK,OAAO;IAC/B,CAAC;IAED;GACF;GAIA,gBAFgB,KAAK,QAAQ,MAAM,aAAa,IAAI,MAAM,cAAc,CAEjD;EACzB,CAAC;CACH;AACF,CAAC"}
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import { dataSourceRegistry } from "../data-source/data-source-registry.mjs";
|
|
2
|
-
import { MongoDbDriver } from "../drivers/mongodb/mongodb-driver.mjs";
|
|
3
|
-
import { PostgresDriver } from "../drivers/postgres/postgres-driver.mjs";
|
|
4
|
-
|
|
5
|
-
//#region ../../@warlock.js/cascade/src/cli/connection-from-env.ts
|
|
6
|
-
const VALID_PRIMARY_KEYS = [
|
|
7
|
-
"uuid",
|
|
8
|
-
"int",
|
|
9
|
-
"bigInt"
|
|
10
|
-
];
|
|
11
|
-
const VALID_UUID_STRATEGIES = ["v4", "v7"];
|
|
12
|
-
const POSTGRES_URL_PREFIXES = ["postgres://", "postgresql://"];
|
|
13
|
-
const MONGODB_URL_PREFIXES = ["mongodb://", "mongodb+srv://"];
|
|
14
|
-
/**
|
|
15
|
-
* Validate and normalise the `CASCADE_PRIMARY_KEY` env var. Throws a CLI-
|
|
16
|
-
* shaped error when the value is set but unrecognised.
|
|
17
|
-
*/
|
|
18
|
-
function parsePrimaryKey(raw) {
|
|
19
|
-
if (!raw) return;
|
|
20
|
-
const trimmed = raw.trim();
|
|
21
|
-
const match = VALID_PRIMARY_KEYS.find((value) => value.toLowerCase() === trimmed.toLowerCase());
|
|
22
|
-
if (!match) throw new Error(`Cascade CLI: invalid CASCADE_PRIMARY_KEY="${raw}". Expected one of ${VALID_PRIMARY_KEYS.join(" | ")}.`);
|
|
23
|
-
return match;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Validate and normalise the `CASCADE_UUID_STRATEGY` env var. Throws a CLI-
|
|
27
|
-
* shaped error when the value is set but unrecognised.
|
|
28
|
-
*/
|
|
29
|
-
function parseUuidStrategy(raw) {
|
|
30
|
-
if (!raw) return;
|
|
31
|
-
const trimmed = raw.trim().toLowerCase();
|
|
32
|
-
const match = VALID_UUID_STRATEGIES.find((value) => value === trimmed);
|
|
33
|
-
if (!match) throw new Error(`Cascade CLI: invalid CASCADE_UUID_STRATEGY="${raw}". Expected one of ${VALID_UUID_STRATEGIES.join(" | ")}.`);
|
|
34
|
-
return match;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Read process env and collapse the alias pairs into a single resolved shape.
|
|
38
|
-
*
|
|
39
|
-
* Aliases (canonical → also-accepted):
|
|
40
|
-
* - `DATABASE_URL` → `DB_URL`
|
|
41
|
-
* - `DB_DIALECT` → `DB_DRIVER`
|
|
42
|
-
* - `DB_USER` → `DB_USERNAME`
|
|
43
|
-
*/
|
|
44
|
-
function resolveDbEnv(env) {
|
|
45
|
-
return {
|
|
46
|
-
databaseUrl: env.DATABASE_URL?.trim() || env.DB_URL?.trim() || void 0,
|
|
47
|
-
dialect: env.DB_DIALECT?.trim() || env.DB_DRIVER?.trim() || void 0,
|
|
48
|
-
host: env.DB_HOST?.trim() || void 0,
|
|
49
|
-
port: env.DB_PORT?.toString().trim() || void 0,
|
|
50
|
-
database: env.DB_NAME?.trim() || void 0,
|
|
51
|
-
user: env.DB_USER?.trim() || env.DB_USERNAME?.trim() || void 0,
|
|
52
|
-
password: env.DB_PASSWORD !== void 0 ? String(env.DB_PASSWORD) : void 0,
|
|
53
|
-
primaryKey: parsePrimaryKey(env.CASCADE_PRIMARY_KEY),
|
|
54
|
-
uuidStrategy: parseUuidStrategy(env.CASCADE_UUID_STRATEGY)
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Build the optional `migrationDefaults` shape passed to the data source.
|
|
59
|
-
* Returns `undefined` when neither env var is set — so consumers get the
|
|
60
|
-
* cascade library defaults (`primaryKey: "int"`, `uuidStrategy: "v4"`).
|
|
61
|
-
*/
|
|
62
|
-
function buildMigrationDefaults(resolved) {
|
|
63
|
-
if (!resolved.primaryKey && !resolved.uuidStrategy) return;
|
|
64
|
-
return {
|
|
65
|
-
primaryKey: resolved.primaryKey,
|
|
66
|
-
uuidStrategy: resolved.uuidStrategy
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Parse the path portion of a database URL as the database name, returning
|
|
71
|
-
* `undefined` when the URL is malformed or carries no database segment.
|
|
72
|
-
*/
|
|
73
|
-
function extractDatabaseFromUrl(url) {
|
|
74
|
-
try {
|
|
75
|
-
return new URL(url).pathname.replace(/^\//, "") || void 0;
|
|
76
|
-
} catch {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Detect the database dialect from env. First inspects the URL scheme, then
|
|
82
|
-
* falls back to an explicit `DB_DIALECT` / `DB_DRIVER` env var.
|
|
83
|
-
*
|
|
84
|
-
* @example
|
|
85
|
-
* const dialect = detectDialect();
|
|
86
|
-
*/
|
|
87
|
-
function detectDialect(env = process.env) {
|
|
88
|
-
const resolved = resolveDbEnv(env);
|
|
89
|
-
if (resolved.databaseUrl) {
|
|
90
|
-
if (POSTGRES_URL_PREFIXES.some((prefix) => resolved.databaseUrl.startsWith(prefix))) return "postgres";
|
|
91
|
-
if (MONGODB_URL_PREFIXES.some((prefix) => resolved.databaseUrl.startsWith(prefix))) return "mongodb";
|
|
92
|
-
}
|
|
93
|
-
const dialect = resolved.dialect?.toLowerCase();
|
|
94
|
-
if (dialect === "postgres" || dialect === "postgresql") return "postgres";
|
|
95
|
-
if (dialect === "mongodb" || dialect === "mongo") return "mongodb";
|
|
96
|
-
throw new Error("Cascade CLI: cannot detect database dialect. Set DATABASE_URL / DB_URL (postgres://… or mongodb://…) or DB_DIALECT / DB_DRIVER = postgres | mongodb.");
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Construct a Postgres driver — prefers a connection URL, otherwise builds
|
|
100
|
-
* from discrete env vars.
|
|
101
|
-
*/
|
|
102
|
-
function buildPostgresDriver(resolved) {
|
|
103
|
-
if (resolved.databaseUrl) {
|
|
104
|
-
const database = extractDatabaseFromUrl(resolved.databaseUrl);
|
|
105
|
-
if (!database) throw new Error("Cascade CLI: DATABASE_URL / DB_URL is missing the database name in its path segment.");
|
|
106
|
-
return new PostgresDriver({
|
|
107
|
-
connectionString: resolved.databaseUrl,
|
|
108
|
-
database
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
if (!resolved.database) throw new Error("Cascade CLI: missing required env var DB_NAME.");
|
|
112
|
-
return new PostgresDriver({
|
|
113
|
-
host: resolved.host ?? "localhost",
|
|
114
|
-
port: resolved.port ? Number(resolved.port) : 5432,
|
|
115
|
-
database: resolved.database,
|
|
116
|
-
user: resolved.user,
|
|
117
|
-
password: resolved.password
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Construct a MongoDB driver — prefers a connection URI, otherwise builds
|
|
122
|
-
* from discrete env vars.
|
|
123
|
-
*/
|
|
124
|
-
function buildMongoDriver(resolved) {
|
|
125
|
-
if (resolved.databaseUrl) {
|
|
126
|
-
const database = resolved.database ?? extractDatabaseFromUrl(resolved.databaseUrl);
|
|
127
|
-
if (!database) throw new Error("Cascade CLI: cannot resolve MongoDB database name. Either include it in DATABASE_URL / DB_URL or set DB_NAME.");
|
|
128
|
-
return new MongoDbDriver({
|
|
129
|
-
uri: resolved.databaseUrl,
|
|
130
|
-
database
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
if (!resolved.database) throw new Error("Cascade CLI: missing required env var DB_NAME.");
|
|
134
|
-
return new MongoDbDriver({
|
|
135
|
-
host: resolved.host ?? "localhost",
|
|
136
|
-
port: resolved.port ? Number(resolved.port) : 27017,
|
|
137
|
-
database: resolved.database,
|
|
138
|
-
username: resolved.user,
|
|
139
|
-
password: resolved.password
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Register a `default` data source on `dataSourceRegistry` derived entirely
|
|
144
|
-
* from environment variables and open the underlying driver connection.
|
|
145
|
-
*
|
|
146
|
-
* Reads (canonical name → accepted aliases):
|
|
147
|
-
* - `DATABASE_URL` → `DB_URL` (preferred when present)
|
|
148
|
-
* - `DB_DIALECT` → `DB_DRIVER` (needed only when no URL)
|
|
149
|
-
* - `DB_HOST` / `DB_PORT` / `DB_NAME` / `DB_PASSWORD` (no aliases)
|
|
150
|
-
* - `DB_USER` → `DB_USERNAME`
|
|
151
|
-
*
|
|
152
|
-
* Optional migration defaults — affect how `Migration.create()` chooses the
|
|
153
|
-
* primary-key column and which UUID function the driver emits. Unset means
|
|
154
|
-
* the cascade library defaults apply (`primaryKey: "int"`, `uuidStrategy:
|
|
155
|
-
* "v4"`).
|
|
156
|
-
* - `CASCADE_PRIMARY_KEY` — `uuid` | `int` | `bigInt`
|
|
157
|
-
* - `CASCADE_UUID_STRATEGY` — `v4` | `v7`
|
|
158
|
-
*
|
|
159
|
-
* The driver's pool/socket is opened before this function returns, so the
|
|
160
|
-
* caller can issue queries immediately. Pair every call with
|
|
161
|
-
* `disconnect()` (or use `withCliConnection`) so the process exits cleanly.
|
|
162
|
-
*
|
|
163
|
-
* @example
|
|
164
|
-
* await connectFromEnv();
|
|
165
|
-
* const results = await runMigrations();
|
|
166
|
-
*/
|
|
167
|
-
async function connectFromEnv(env = process.env) {
|
|
168
|
-
const dialect = detectDialect(env);
|
|
169
|
-
const resolved = resolveDbEnv(env);
|
|
170
|
-
const driver = dialect === "postgres" ? buildPostgresDriver(resolved) : buildMongoDriver(resolved);
|
|
171
|
-
await dataSourceRegistry.register({
|
|
172
|
-
name: "default",
|
|
173
|
-
driver,
|
|
174
|
-
isDefault: true,
|
|
175
|
-
migrationDefaults: buildMigrationDefaults(resolved)
|
|
176
|
-
}).driver.connect();
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
//#endregion
|
|
180
|
-
export { connectFromEnv };
|
|
181
|
-
//# sourceMappingURL=connection-from-env.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"connection-from-env.mjs","names":[],"sources":["../../../../../../@warlock.js/cascade/src/cli/connection-from-env.ts"],"sourcesContent":["import { dataSourceRegistry } from \"../data-source/data-source-registry\";\nimport { MongoDbDriver } from \"../drivers/mongodb/mongodb-driver\";\nimport { PostgresDriver } from \"../drivers/postgres/postgres-driver\";\nimport type { MigrationDefaults, UuidStrategy } from \"../types\";\n\nconst VALID_PRIMARY_KEYS = [\"uuid\", \"int\", \"bigInt\"] as const;\nconst VALID_UUID_STRATEGIES: readonly UuidStrategy[] = [\"v4\", \"v7\"];\n\ntype PrimaryKey = (typeof VALID_PRIMARY_KEYS)[number];\n\n/**\n * Supported database dialects for the standalone Cascade CLI.\n */\nexport type CliDialect = \"postgres\" | \"mongodb\";\n\nconst POSTGRES_URL_PREFIXES = [\"postgres://\", \"postgresql://\"];\nconst MONGODB_URL_PREFIXES = [\"mongodb://\", \"mongodb+srv://\"];\n\n/**\n * Canonical env shape Cascade actually consumes. The CLI accepts two\n * synonymous spellings for every var (canonical + warlock-shaped) so an\n * existing warlock project's `.env` works as-is without duplication.\n */\ntype ResolvedDbEnv = {\n readonly databaseUrl?: string;\n readonly dialect?: string;\n readonly host?: string;\n readonly port?: string;\n readonly database?: string;\n readonly user?: string;\n readonly password?: string;\n readonly primaryKey?: PrimaryKey;\n readonly uuidStrategy?: UuidStrategy;\n};\n\n/**\n * Validate and normalise the `CASCADE_PRIMARY_KEY` env var. Throws a CLI-\n * shaped error when the value is set but unrecognised.\n */\nfunction parsePrimaryKey(raw: string | undefined): PrimaryKey | undefined {\n if (!raw) {\n return undefined;\n }\n\n const trimmed = raw.trim();\n\n // Case-insensitive match — accept \"BIGINT\" / \"bigint\" / \"bigInt\".\n const match = VALID_PRIMARY_KEYS.find((value) => value.toLowerCase() === trimmed.toLowerCase());\n\n if (!match) {\n throw new Error(\n `Cascade CLI: invalid CASCADE_PRIMARY_KEY=\"${raw}\". ` +\n `Expected one of ${VALID_PRIMARY_KEYS.join(\" | \")}.`,\n );\n }\n\n return match;\n}\n\n/**\n * Validate and normalise the `CASCADE_UUID_STRATEGY` env var. Throws a CLI-\n * shaped error when the value is set but unrecognised.\n */\nfunction parseUuidStrategy(raw: string | undefined): UuidStrategy | undefined {\n if (!raw) {\n return undefined;\n }\n\n const trimmed = raw.trim().toLowerCase();\n const match = VALID_UUID_STRATEGIES.find((value) => value === trimmed);\n\n if (!match) {\n throw new Error(\n `Cascade CLI: invalid CASCADE_UUID_STRATEGY=\"${raw}\". ` +\n `Expected one of ${VALID_UUID_STRATEGIES.join(\" | \")}.`,\n );\n }\n\n return match;\n}\n\n/**\n * Read process env and collapse the alias pairs into a single resolved shape.\n *\n * Aliases (canonical → also-accepted):\n * - `DATABASE_URL` → `DB_URL`\n * - `DB_DIALECT` → `DB_DRIVER`\n * - `DB_USER` → `DB_USERNAME`\n */\nfunction resolveDbEnv(env: NodeJS.ProcessEnv): ResolvedDbEnv {\n return {\n databaseUrl: env.DATABASE_URL?.trim() || env.DB_URL?.trim() || undefined,\n dialect: env.DB_DIALECT?.trim() || env.DB_DRIVER?.trim() || undefined,\n host: env.DB_HOST?.trim() || undefined,\n port: env.DB_PORT?.toString().trim() || undefined,\n database: env.DB_NAME?.trim() || undefined,\n user: env.DB_USER?.trim() || env.DB_USERNAME?.trim() || undefined,\n password: env.DB_PASSWORD !== undefined ? String(env.DB_PASSWORD) : undefined,\n primaryKey: parsePrimaryKey(env.CASCADE_PRIMARY_KEY),\n uuidStrategy: parseUuidStrategy(env.CASCADE_UUID_STRATEGY),\n };\n}\n\n/**\n * Build the optional `migrationDefaults` shape passed to the data source.\n * Returns `undefined` when neither env var is set — so consumers get the\n * cascade library defaults (`primaryKey: \"int\"`, `uuidStrategy: \"v4\"`).\n */\nfunction buildMigrationDefaults(resolved: ResolvedDbEnv): MigrationDefaults | undefined {\n if (!resolved.primaryKey && !resolved.uuidStrategy) {\n return undefined;\n }\n\n return {\n primaryKey: resolved.primaryKey,\n uuidStrategy: resolved.uuidStrategy,\n };\n}\n\n/**\n * Parse the path portion of a database URL as the database name, returning\n * `undefined` when the URL is malformed or carries no database segment.\n */\nfunction extractDatabaseFromUrl(url: string): string | undefined {\n try {\n const parsed = new URL(url);\n const segment = parsed.pathname.replace(/^\\//, \"\");\n\n return segment || undefined;\n } catch {\n return undefined;\n }\n}\n\n/**\n * Detect the database dialect from env. First inspects the URL scheme, then\n * falls back to an explicit `DB_DIALECT` / `DB_DRIVER` env var.\n *\n * @example\n * const dialect = detectDialect();\n */\nexport function detectDialect(env: NodeJS.ProcessEnv = process.env): CliDialect {\n const resolved = resolveDbEnv(env);\n\n if (resolved.databaseUrl) {\n if (POSTGRES_URL_PREFIXES.some((prefix) => resolved.databaseUrl!.startsWith(prefix))) {\n return \"postgres\";\n }\n\n if (MONGODB_URL_PREFIXES.some((prefix) => resolved.databaseUrl!.startsWith(prefix))) {\n return \"mongodb\";\n }\n }\n\n const dialect = resolved.dialect?.toLowerCase();\n\n if (dialect === \"postgres\" || dialect === \"postgresql\") {\n return \"postgres\";\n }\n\n if (dialect === \"mongodb\" || dialect === \"mongo\") {\n return \"mongodb\";\n }\n\n throw new Error(\n \"Cascade CLI: cannot detect database dialect. \" +\n \"Set DATABASE_URL / DB_URL (postgres://… or mongodb://…) \" +\n \"or DB_DIALECT / DB_DRIVER = postgres | mongodb.\",\n );\n}\n\n/**\n * Construct a Postgres driver — prefers a connection URL, otherwise builds\n * from discrete env vars.\n */\nfunction buildPostgresDriver(resolved: ResolvedDbEnv): PostgresDriver {\n if (resolved.databaseUrl) {\n const database = extractDatabaseFromUrl(resolved.databaseUrl);\n\n if (!database) {\n throw new Error(\n \"Cascade CLI: DATABASE_URL / DB_URL is missing the database name in its path segment.\",\n );\n }\n\n return new PostgresDriver({\n connectionString: resolved.databaseUrl,\n database,\n });\n }\n\n if (!resolved.database) {\n throw new Error(\"Cascade CLI: missing required env var DB_NAME.\");\n }\n\n return new PostgresDriver({\n host: resolved.host ?? \"localhost\",\n port: resolved.port ? Number(resolved.port) : 5432,\n database: resolved.database,\n user: resolved.user,\n password: resolved.password,\n });\n}\n\n/**\n * Construct a MongoDB driver — prefers a connection URI, otherwise builds\n * from discrete env vars.\n */\nfunction buildMongoDriver(resolved: ResolvedDbEnv): MongoDbDriver {\n if (resolved.databaseUrl) {\n const database = resolved.database ?? extractDatabaseFromUrl(resolved.databaseUrl);\n\n if (!database) {\n throw new Error(\n \"Cascade CLI: cannot resolve MongoDB database name. \" +\n \"Either include it in DATABASE_URL / DB_URL or set DB_NAME.\",\n );\n }\n\n return new MongoDbDriver({\n uri: resolved.databaseUrl,\n database,\n });\n }\n\n if (!resolved.database) {\n throw new Error(\"Cascade CLI: missing required env var DB_NAME.\");\n }\n\n return new MongoDbDriver({\n host: resolved.host ?? \"localhost\",\n port: resolved.port ? Number(resolved.port) : 27017,\n database: resolved.database,\n username: resolved.user,\n password: resolved.password,\n });\n}\n\n/**\n * Register a `default` data source on `dataSourceRegistry` derived entirely\n * from environment variables and open the underlying driver connection.\n *\n * Reads (canonical name → accepted aliases):\n * - `DATABASE_URL` → `DB_URL` (preferred when present)\n * - `DB_DIALECT` → `DB_DRIVER` (needed only when no URL)\n * - `DB_HOST` / `DB_PORT` / `DB_NAME` / `DB_PASSWORD` (no aliases)\n * - `DB_USER` → `DB_USERNAME`\n *\n * Optional migration defaults — affect how `Migration.create()` chooses the\n * primary-key column and which UUID function the driver emits. Unset means\n * the cascade library defaults apply (`primaryKey: \"int\"`, `uuidStrategy:\n * \"v4\"`).\n * - `CASCADE_PRIMARY_KEY` — `uuid` | `int` | `bigInt`\n * - `CASCADE_UUID_STRATEGY` — `v4` | `v7`\n *\n * The driver's pool/socket is opened before this function returns, so the\n * caller can issue queries immediately. Pair every call with\n * `disconnect()` (or use `withCliConnection`) so the process exits cleanly.\n *\n * @example\n * await connectFromEnv();\n * const results = await runMigrations();\n */\nexport async function connectFromEnv(env: NodeJS.ProcessEnv = process.env): Promise<void> {\n const dialect = detectDialect(env);\n const resolved = resolveDbEnv(env);\n\n const driver =\n dialect === \"postgres\" ? buildPostgresDriver(resolved) : buildMongoDriver(resolved);\n\n const dataSource = dataSourceRegistry.register({\n name: \"default\",\n driver,\n isDefault: true,\n migrationDefaults: buildMigrationDefaults(resolved),\n });\n\n await dataSource.driver.connect();\n}\n"],"mappings":";;;;;AAKA,MAAM,qBAAqB;CAAC;CAAQ;CAAO;AAAQ;AACnD,MAAM,wBAAiD,CAAC,MAAM,IAAI;AASlE,MAAM,wBAAwB,CAAC,eAAe,eAAe;AAC7D,MAAM,uBAAuB,CAAC,cAAc,gBAAgB;;;;;AAuB5D,SAAS,gBAAgB,KAAiD;CACxE,IAAI,CAAC,KACH;CAGF,MAAM,UAAU,IAAI,KAAK;CAGzB,MAAM,QAAQ,mBAAmB,MAAM,UAAU,MAAM,YAAY,MAAM,QAAQ,YAAY,CAAC;CAE9F,IAAI,CAAC,OACH,MAAM,IAAI,MACR,6CAA6C,IAAI,qBAC5B,mBAAmB,KAAK,KAAK,EAAE,EACtD;CAGF,OAAO;AACT;;;;;AAMA,SAAS,kBAAkB,KAAmD;CAC5E,IAAI,CAAC,KACH;CAGF,MAAM,UAAU,IAAI,KAAK,EAAE,YAAY;CACvC,MAAM,QAAQ,sBAAsB,MAAM,UAAU,UAAU,OAAO;CAErE,IAAI,CAAC,OACH,MAAM,IAAI,MACR,+CAA+C,IAAI,qBAC9B,sBAAsB,KAAK,KAAK,EAAE,EACzD;CAGF,OAAO;AACT;;;;;;;;;AAUA,SAAS,aAAa,KAAuC;CAC3D,OAAO;EACL,aAAa,IAAI,cAAc,KAAK,KAAK,IAAI,QAAQ,KAAK,KAAK;EAC/D,SAAS,IAAI,YAAY,KAAK,KAAK,IAAI,WAAW,KAAK,KAAK;EAC5D,MAAM,IAAI,SAAS,KAAK,KAAK;EAC7B,MAAM,IAAI,SAAS,SAAS,EAAE,KAAK,KAAK;EACxC,UAAU,IAAI,SAAS,KAAK,KAAK;EACjC,MAAM,IAAI,SAAS,KAAK,KAAK,IAAI,aAAa,KAAK,KAAK;EACxD,UAAU,IAAI,gBAAgB,SAAY,OAAO,IAAI,WAAW,IAAI;EACpE,YAAY,gBAAgB,IAAI,mBAAmB;EACnD,cAAc,kBAAkB,IAAI,qBAAqB;CAC3D;AACF;;;;;;AAOA,SAAS,uBAAuB,UAAwD;CACtF,IAAI,CAAC,SAAS,cAAc,CAAC,SAAS,cACpC;CAGF,OAAO;EACL,YAAY,SAAS;EACrB,cAAc,SAAS;CACzB;AACF;;;;;AAMA,SAAS,uBAAuB,KAAiC;CAC/D,IAAI;EAIF,OAFgB,IADG,IAAI,GACF,EAAE,SAAS,QAAQ,OAAO,EAElC,KAAK;CACpB,QAAQ;EACN;CACF;AACF;;;;;;;;AASA,SAAgB,cAAc,MAAyB,QAAQ,KAAiB;CAC9E,MAAM,WAAW,aAAa,GAAG;CAEjC,IAAI,SAAS,aAAa;EACxB,IAAI,sBAAsB,MAAM,WAAW,SAAS,YAAa,WAAW,MAAM,CAAC,GACjF,OAAO;EAGT,IAAI,qBAAqB,MAAM,WAAW,SAAS,YAAa,WAAW,MAAM,CAAC,GAChF,OAAO;CAEX;CAEA,MAAM,UAAU,SAAS,SAAS,YAAY;CAE9C,IAAI,YAAY,cAAc,YAAY,cACxC,OAAO;CAGT,IAAI,YAAY,aAAa,YAAY,SACvC,OAAO;CAGT,MAAM,IAAI,MACR,sJAGF;AACF;;;;;AAMA,SAAS,oBAAoB,UAAyC;CACpE,IAAI,SAAS,aAAa;EACxB,MAAM,WAAW,uBAAuB,SAAS,WAAW;EAE5D,IAAI,CAAC,UACH,MAAM,IAAI,MACR,sFACF;EAGF,OAAO,IAAI,eAAe;GACxB,kBAAkB,SAAS;GAC3B;EACF,CAAC;CACH;CAEA,IAAI,CAAC,SAAS,UACZ,MAAM,IAAI,MAAM,gDAAgD;CAGlE,OAAO,IAAI,eAAe;EACxB,MAAM,SAAS,QAAQ;EACvB,MAAM,SAAS,OAAO,OAAO,SAAS,IAAI,IAAI;EAC9C,UAAU,SAAS;EACnB,MAAM,SAAS;EACf,UAAU,SAAS;CACrB,CAAC;AACH;;;;;AAMA,SAAS,iBAAiB,UAAwC;CAChE,IAAI,SAAS,aAAa;EACxB,MAAM,WAAW,SAAS,YAAY,uBAAuB,SAAS,WAAW;EAEjF,IAAI,CAAC,UACH,MAAM,IAAI,MACR,+GAEF;EAGF,OAAO,IAAI,cAAc;GACvB,KAAK,SAAS;GACd;EACF,CAAC;CACH;CAEA,IAAI,CAAC,SAAS,UACZ,MAAM,IAAI,MAAM,gDAAgD;CAGlE,OAAO,IAAI,cAAc;EACvB,MAAM,SAAS,QAAQ;EACvB,MAAM,SAAS,OAAO,OAAO,SAAS,IAAI,IAAI;EAC9C,UAAU,SAAS;EACnB,UAAU,SAAS;EACnB,UAAU,SAAS;CACrB,CAAC;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,eAAsB,eAAe,MAAyB,QAAQ,KAAoB;CACxF,MAAM,UAAU,cAAc,GAAG;CACjC,MAAM,WAAW,aAAa,GAAG;CAEjC,MAAM,SACJ,YAAY,aAAa,oBAAoB,QAAQ,IAAI,iBAAiB,QAAQ;CASpF,MAPmB,mBAAmB,SAAS;EAC7C,MAAM;EACN;EACA,WAAW;EACX,mBAAmB,uBAAuB,QAAQ;CACpD,CAEe,EAAE,OAAO,QAAQ;AAClC"}
|
package/esm/cli/index.mjs
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { migrateCommand } from "./commands/migrate.mjs";
|
|
2
|
-
import { migrateExportSqlCommand } from "./commands/migrate-export-sql.mjs";
|
|
3
|
-
import { migrateListCommand } from "./commands/migrate-list.mjs";
|
|
4
|
-
import { migrateRollbackCommand } from "./commands/migrate-rollback.mjs";
|
|
5
|
-
import { defineCommand } from "citty";
|
|
6
|
-
|
|
7
|
-
//#region ../../@warlock.js/cascade/src/cli/index.ts
|
|
8
|
-
/**
|
|
9
|
-
* Root command for the standalone `cascade` CLI binary. Scope is restricted
|
|
10
|
-
* to migration operations — database management (`db:create` etc.) stays in
|
|
11
|
-
* the warlock-core CLI where the project context is available.
|
|
12
|
-
*
|
|
13
|
-
* Subcommands follow colon-style naming (`cascade migrate:list`) so each
|
|
14
|
-
* verb stays addressable as a single argv token.
|
|
15
|
-
*/
|
|
16
|
-
const main = defineCommand({
|
|
17
|
-
meta: {
|
|
18
|
-
name: "cascade",
|
|
19
|
-
description: "Standalone Cascade ORM migration CLI."
|
|
20
|
-
},
|
|
21
|
-
subCommands: {
|
|
22
|
-
migrate: migrateCommand,
|
|
23
|
-
"migrate:list": migrateListCommand,
|
|
24
|
-
"migrate:rollback": migrateRollbackCommand,
|
|
25
|
-
"migrate:export-sql": migrateExportSqlCommand
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
//#endregion
|
|
30
|
-
export { main };
|
|
31
|
-
//# sourceMappingURL=index.mjs.map
|
package/esm/cli/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../../../@warlock.js/cascade/src/cli/index.ts"],"sourcesContent":["import { defineCommand } from \"citty\";\nimport { migrateCommand } from \"./commands/migrate\";\nimport { migrateExportSqlCommand } from \"./commands/migrate-export-sql\";\nimport { migrateListCommand } from \"./commands/migrate-list\";\nimport { migrateRollbackCommand } from \"./commands/migrate-rollback\";\n\n/**\n * Root command for the standalone `cascade` CLI binary. Scope is restricted\n * to migration operations — database management (`db:create` etc.) stays in\n * the warlock-core CLI where the project context is available.\n *\n * Subcommands follow colon-style naming (`cascade migrate:list`) so each\n * verb stays addressable as a single argv token.\n */\nexport const main = defineCommand({\n meta: {\n name: \"cascade\",\n description: \"Standalone Cascade ORM migration CLI.\",\n },\n subCommands: {\n migrate: migrateCommand,\n \"migrate:list\": migrateListCommand,\n \"migrate:rollback\": migrateRollbackCommand,\n \"migrate:export-sql\": migrateExportSqlCommand,\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;AAcA,MAAa,OAAO,cAAc;CAChC,MAAM;EACJ,MAAM;EACN,aAAa;CACf;CACA,aAAa;EACX,SAAS;EACT,gBAAgB;EAChB,oBAAoB;EACpB,sBAAsB;CACxB;AACF,CAAC"}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { migrationRunner } from "../migration/migration-runner.mjs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import fastGlob from "fast-glob";
|
|
4
|
-
import { pathToFileURL } from "url";
|
|
5
|
-
|
|
6
|
-
//#region ../../@warlock.js/cascade/src/cli/load-migrations.ts
|
|
7
|
-
const DEFAULT_PATTERN = "./migrations/**/*.{ts,js,mjs,cjs}";
|
|
8
|
-
/**
|
|
9
|
-
* Resolve the migration name from a filename. Mirrors warlock-core's
|
|
10
|
-
* convention: drop the extension, strip a trailing `-migration` /
|
|
11
|
-
* `_migration` suffix.
|
|
12
|
-
*/
|
|
13
|
-
function inferNameFromFile(file) {
|
|
14
|
-
return path.basename(file).split(".")[0].replace(/-migration$/, "").replace(/_migration$/, "");
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Extract a leading `MM-DD-YYYY_HH-MM-SS` (or `DD-MM-YYYY_HH-MM-SS`)
|
|
18
|
-
* timestamp from a migration filename so the runner can sort migrations
|
|
19
|
-
* deterministically. Returns `undefined` when no timestamp is present.
|
|
20
|
-
*/
|
|
21
|
-
function inferCreatedAtFromFile(file) {
|
|
22
|
-
const match = path.basename(file).match(/^(\d{2}-\d{2}-\d{4}_\d{2}-\d{2}-\d{2})/);
|
|
23
|
-
return match ? match[1] : void 0;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Produce a helpful CLI error when Node refuses to import a `.ts` migration
|
|
27
|
-
* file directly — the standalone Cascade CLI ships no TS transpiler, and
|
|
28
|
-
* users hitting this error need to invoke through `tsx`/`tsm` or compile
|
|
29
|
-
* their migrations to JS first.
|
|
30
|
-
*/
|
|
31
|
-
function explainImportFailure(file, error) {
|
|
32
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
33
|
-
if (file.endsWith(".ts") || file.endsWith(".tsx")) return /* @__PURE__ */ new Error(`Cascade CLI: failed to load TypeScript migration ${file}.\nNode cannot import .ts files natively — invoke the CLI through a TS runtime, e.g.:\n npx tsx node_modules/.bin/cascade migrate\nOr pre-compile migrations to JS before running.\nOriginal error: ${message}`);
|
|
34
|
-
return /* @__PURE__ */ new Error(`Cascade CLI: failed to load migration ${file}. ${message}`);
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Discover migration files via `fast-glob`, dynamic-import each, and register
|
|
38
|
-
* the default export on `migrationRunner`. Migration name and `createdAt`
|
|
39
|
-
* are inferred from the filename when the class does not declare them.
|
|
40
|
-
*
|
|
41
|
-
* Default glob: `./migrations/**/*.{ts,js,mjs,cjs}` from `process.cwd()`.
|
|
42
|
-
* Pass an explicit pattern to override.
|
|
43
|
-
*
|
|
44
|
-
* @returns Number of migration files registered.
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* await loadMigrations();
|
|
48
|
-
* await loadMigrations("./db/schema/*.migration.js");
|
|
49
|
-
*/
|
|
50
|
-
async function loadMigrations(pattern) {
|
|
51
|
-
const files = await fastGlob(pattern ?? DEFAULT_PATTERN, {
|
|
52
|
-
absolute: true,
|
|
53
|
-
cwd: process.cwd(),
|
|
54
|
-
onlyFiles: true
|
|
55
|
-
});
|
|
56
|
-
for (const file of files) {
|
|
57
|
-
const fileUrl = pathToFileURL(file).href;
|
|
58
|
-
let loadedModule;
|
|
59
|
-
try {
|
|
60
|
-
loadedModule = await import(fileUrl);
|
|
61
|
-
} catch (error) {
|
|
62
|
-
throw explainImportFailure(file, error);
|
|
63
|
-
}
|
|
64
|
-
const MigrationClass = loadedModule.default;
|
|
65
|
-
if (!MigrationClass) throw new Error(`Cascade CLI: ${file} must export a default migration class.`);
|
|
66
|
-
if (!MigrationClass.migrationName) MigrationClass.migrationName = inferNameFromFile(file);
|
|
67
|
-
if (!MigrationClass.createdAt) {
|
|
68
|
-
const createdAt = inferCreatedAtFromFile(file);
|
|
69
|
-
if (createdAt) MigrationClass.createdAt = createdAt;
|
|
70
|
-
}
|
|
71
|
-
migrationRunner.register(MigrationClass);
|
|
72
|
-
}
|
|
73
|
-
return files.length;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
//#endregion
|
|
77
|
-
export { loadMigrations };
|
|
78
|
-
//# sourceMappingURL=load-migrations.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"load-migrations.mjs","names":[],"sources":["../../../../../../@warlock.js/cascade/src/cli/load-migrations.ts"],"sourcesContent":["import fastGlob from \"fast-glob\";\nimport path from \"path\";\nimport { pathToFileURL } from \"url\";\nimport { migrationRunner } from \"../migration/migration-runner\";\n\nconst DEFAULT_PATTERN = \"./migrations/**/*.{ts,js,mjs,cjs}\";\n\n/**\n * Resolve the migration name from a filename. Mirrors warlock-core's\n * convention: drop the extension, strip a trailing `-migration` /\n * `_migration` suffix.\n */\nfunction inferNameFromFile(file: string): string {\n const basename = path.basename(file).split(\".\")[0];\n\n return basename.replace(/-migration$/, \"\").replace(/_migration$/, \"\");\n}\n\n/**\n * Extract a leading `MM-DD-YYYY_HH-MM-SS` (or `DD-MM-YYYY_HH-MM-SS`)\n * timestamp from a migration filename so the runner can sort migrations\n * deterministically. Returns `undefined` when no timestamp is present.\n */\nfunction inferCreatedAtFromFile(file: string): string | undefined {\n const basename = path.basename(file);\n const match = basename.match(/^(\\d{2}-\\d{2}-\\d{4}_\\d{2}-\\d{2}-\\d{2})/);\n\n return match ? match[1] : undefined;\n}\n\n/**\n * Produce a helpful CLI error when Node refuses to import a `.ts` migration\n * file directly — the standalone Cascade CLI ships no TS transpiler, and\n * users hitting this error need to invoke through `tsx`/`tsm` or compile\n * their migrations to JS first.\n */\nfunction explainImportFailure(file: string, error: unknown): Error {\n const message = error instanceof Error ? error.message : String(error);\n\n if (file.endsWith(\".ts\") || file.endsWith(\".tsx\")) {\n return new Error(\n `Cascade CLI: failed to load TypeScript migration ${file}.\\n` +\n `Node cannot import .ts files natively — invoke the CLI through a TS runtime, e.g.:\\n` +\n ` npx tsx node_modules/.bin/cascade migrate\\n` +\n `Or pre-compile migrations to JS before running.\\n` +\n `Original error: ${message}`,\n );\n }\n\n return new Error(`Cascade CLI: failed to load migration ${file}. ${message}`);\n}\n\n/**\n * Discover migration files via `fast-glob`, dynamic-import each, and register\n * the default export on `migrationRunner`. Migration name and `createdAt`\n * are inferred from the filename when the class does not declare them.\n *\n * Default glob: `./migrations/**/*.{ts,js,mjs,cjs}` from `process.cwd()`.\n * Pass an explicit pattern to override.\n *\n * @returns Number of migration files registered.\n *\n * @example\n * await loadMigrations();\n * await loadMigrations(\"./db/schema/*.migration.js\");\n */\nexport async function loadMigrations(pattern?: string): Promise<number> {\n const resolvedPattern = pattern ?? DEFAULT_PATTERN;\n\n const files = await fastGlob(resolvedPattern, {\n absolute: true,\n cwd: process.cwd(),\n onlyFiles: true,\n });\n\n for (const file of files) {\n const fileUrl = pathToFileURL(file).href;\n\n let loadedModule: { default?: unknown };\n\n try {\n loadedModule = await import(fileUrl);\n } catch (error) {\n throw explainImportFailure(file, error);\n }\n\n const MigrationClass = loadedModule.default as\n | (Function & { migrationName?: string; createdAt?: string })\n | undefined;\n\n if (!MigrationClass) {\n throw new Error(`Cascade CLI: ${file} must export a default migration class.`);\n }\n\n if (!MigrationClass.migrationName) {\n MigrationClass.migrationName = inferNameFromFile(file);\n }\n\n if (!MigrationClass.createdAt) {\n const createdAt = inferCreatedAtFromFile(file);\n\n if (createdAt) {\n MigrationClass.createdAt = createdAt;\n }\n }\n\n // Cast back through the runner's expected shape; the runner validates\n // `migrationName` exists before registration succeeds.\n migrationRunner.register(MigrationClass as never);\n }\n\n return files.length;\n}\n"],"mappings":";;;;;;AAKA,MAAM,kBAAkB;;;;;;AAOxB,SAAS,kBAAkB,MAAsB;CAG/C,OAFiB,KAAK,SAAS,IAAI,EAAE,MAAM,GAAG,EAAE,GAEhC,QAAQ,eAAe,EAAE,EAAE,QAAQ,eAAe,EAAE;AACtE;;;;;;AAOA,SAAS,uBAAuB,MAAkC;CAEhE,MAAM,QADW,KAAK,SAAS,IACV,EAAE,MAAM,wCAAwC;CAErE,OAAO,QAAQ,MAAM,KAAK;AAC5B;;;;;;;AAQA,SAAS,qBAAqB,MAAc,OAAuB;CACjE,MAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;CAErE,IAAI,KAAK,SAAS,KAAK,KAAK,KAAK,SAAS,MAAM,GAC9C,uBAAO,IAAI,MACT,oDAAoD,KAAK,uMAIpC,SACvB;CAGF,uBAAO,IAAI,MAAM,yCAAyC,KAAK,IAAI,SAAS;AAC9E;;;;;;;;;;;;;;;AAgBA,eAAsB,eAAe,SAAmC;CAGtE,MAAM,QAAQ,MAAM,SAFI,WAAW,iBAEW;EAC5C,UAAU;EACV,KAAK,QAAQ,IAAI;EACjB,WAAW;CACb,CAAC;CAED,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,UAAU,cAAc,IAAI,EAAE;EAEpC,IAAI;EAEJ,IAAI;GACF,eAAe,MAAM,OAAO;EAC9B,SAAS,OAAO;GACd,MAAM,qBAAqB,MAAM,KAAK;EACxC;EAEA,MAAM,iBAAiB,aAAa;EAIpC,IAAI,CAAC,gBACH,MAAM,IAAI,MAAM,gBAAgB,KAAK,wCAAwC;EAG/E,IAAI,CAAC,eAAe,eAClB,eAAe,gBAAgB,kBAAkB,IAAI;EAGvD,IAAI,CAAC,eAAe,WAAW;GAC7B,MAAM,YAAY,uBAAuB,IAAI;GAE7C,IAAI,WACF,eAAe,YAAY;EAE/B;EAIA,gBAAgB,SAAS,cAAuB;CAClD;CAEA,OAAO,MAAM;AACf"}
|
package/esm/cli/printers.mjs
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { colors } from "@mongez/copper";
|
|
2
|
-
|
|
3
|
-
//#region ../../@warlock.js/cascade/src/cli/printers.ts
|
|
4
|
-
/**
|
|
5
|
-
* Format a `Date` as `DD-MM-YYYY HH:mm` in the local timezone, or `—` when
|
|
6
|
-
* the value is missing.
|
|
7
|
-
*/
|
|
8
|
-
function formatDate(date) {
|
|
9
|
-
if (!date) return "—";
|
|
10
|
-
return `${String(date.getDate()).padStart(2, "0")}-${String(date.getMonth() + 1).padStart(2, "0")}-${date.getFullYear()} ${String(date.getHours()).padStart(2, "0")}:${String(date.getMinutes()).padStart(2, "0")}`;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Print the executed-migrations table — one entry per migration row in the
|
|
14
|
-
* migrations table, with executed and (when available) created timestamps.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* const executed = await listExecutedMigrations();
|
|
18
|
-
* printExecutedMigrations(executed);
|
|
19
|
-
*/
|
|
20
|
-
function printExecutedMigrations(executed) {
|
|
21
|
-
console.log(`\nTotal Executed Migrations: ${colors.green(String(executed.length))}\n`);
|
|
22
|
-
if (executed.length === 0) {
|
|
23
|
-
console.log(colors.gray(" No migrations have been executed yet.\n"));
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
for (const record of executed) {
|
|
27
|
-
console.log(` ${colors.green("✔")} ${colors.cyanBright(record.name)}`);
|
|
28
|
-
console.log(` ${colors.gray("Executed:")} ${colors.white(formatDate(record.executedAt))}`);
|
|
29
|
-
if (record.createdAt) console.log(` ${colors.gray("Created:")} ${colors.yellow(formatDate(record.createdAt))}`);
|
|
30
|
-
console.log("");
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Print a one-line summary after a run/rollback. The migration runner already
|
|
35
|
-
* logs per-migration progress through `@warlock.js/logger`; this adds a final
|
|
36
|
-
* tally so success/failure is immediately visible at the bottom of the
|
|
37
|
-
* output.
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* const results = await runMigrations();
|
|
41
|
-
* printRunSummary(results);
|
|
42
|
-
*/
|
|
43
|
-
function printRunSummary(results) {
|
|
44
|
-
if (results.length === 0) return;
|
|
45
|
-
const successful = results.filter((result) => result.success).length;
|
|
46
|
-
const failed = results.length - successful;
|
|
47
|
-
console.log("");
|
|
48
|
-
if (failed === 0) {
|
|
49
|
-
console.log(`${colors.green("✔")} ${colors.green(`${successful}/${results.length}`)} migrations completed.`);
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
console.log(`${colors.red("✗")} ${colors.red(`${failed}/${results.length}`)} migrations failed.`);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
//#endregion
|
|
56
|
-
export { printExecutedMigrations, printRunSummary };
|
|
57
|
-
//# sourceMappingURL=printers.mjs.map
|
package/esm/cli/printers.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"printers.mjs","names":[],"sources":["../../../../../../@warlock.js/cascade/src/cli/printers.ts"],"sourcesContent":["import { colors } from \"@mongez/copper\";\nimport type { MigrationRecord, MigrationResult } from \"../migration/types\";\n\n/**\n * Format a `Date` as `DD-MM-YYYY HH:mm` in the local timezone, or `—` when\n * the value is missing.\n */\nfunction formatDate(date: Date | null | undefined): string {\n if (!date) {\n return \"—\";\n }\n\n const day = String(date.getDate()).padStart(2, \"0\");\n const month = String(date.getMonth() + 1).padStart(2, \"0\");\n const year = date.getFullYear();\n const hours = String(date.getHours()).padStart(2, \"0\");\n const minutes = String(date.getMinutes()).padStart(2, \"0\");\n\n return `${day}-${month}-${year} ${hours}:${minutes}`;\n}\n\n/**\n * Print the executed-migrations table — one entry per migration row in the\n * migrations table, with executed and (when available) created timestamps.\n *\n * @example\n * const executed = await listExecutedMigrations();\n * printExecutedMigrations(executed);\n */\nexport function printExecutedMigrations(executed: readonly MigrationRecord[]): void {\n console.log(`\\nTotal Executed Migrations: ${colors.green(String(executed.length))}\\n`);\n\n if (executed.length === 0) {\n console.log(colors.gray(\" No migrations have been executed yet.\\n\"));\n return;\n }\n\n for (const record of executed) {\n console.log(` ${colors.green(\"✔\")} ${colors.cyanBright(record.name)}`);\n console.log(` ${colors.gray(\"Executed:\")} ${colors.white(formatDate(record.executedAt))}`);\n\n if (record.createdAt) {\n console.log(` ${colors.gray(\"Created:\")} ${colors.yellow(formatDate(record.createdAt))}`);\n }\n\n console.log(\"\");\n }\n}\n\n/**\n * Print a one-line summary after a run/rollback. The migration runner already\n * logs per-migration progress through `@warlock.js/logger`; this adds a final\n * tally so success/failure is immediately visible at the bottom of the\n * output.\n *\n * @example\n * const results = await runMigrations();\n * printRunSummary(results);\n */\nexport function printRunSummary(results: readonly MigrationResult[]): void {\n if (results.length === 0) {\n return;\n }\n\n const successful = results.filter((result) => result.success).length;\n const failed = results.length - successful;\n\n console.log(\"\");\n\n if (failed === 0) {\n console.log(\n `${colors.green(\"✔\")} ${colors.green(`${successful}/${results.length}`)} migrations completed.`,\n );\n return;\n }\n\n console.log(\n `${colors.red(\"✗\")} ${colors.red(`${failed}/${results.length}`)} migrations failed.`,\n );\n}\n"],"mappings":";;;;;;;AAOA,SAAS,WAAW,MAAuC;CACzD,IAAI,CAAC,MACH,OAAO;CAST,OAAO,GANK,OAAO,KAAK,QAAQ,CAAC,EAAE,SAAS,GAAG,GAMnC,EAAE,GALA,OAAO,KAAK,SAAS,IAAI,CAAC,EAAE,SAAS,GAAG,GAKjC,EAAE,GAJV,KAAK,YAIW,EAAE,GAHjB,OAAO,KAAK,SAAS,CAAC,EAAE,SAAS,GAAG,GAGZ,EAAE,GAFxB,OAAO,KAAK,WAAW,CAAC,EAAE,SAAS,GAAG,GAEL;AACnD;;;;;;;;;AAUA,SAAgB,wBAAwB,UAA4C;CAClF,QAAQ,IAAI,gCAAgC,OAAO,MAAM,OAAO,SAAS,MAAM,CAAC,EAAE,GAAG;CAErF,IAAI,SAAS,WAAW,GAAG;EACzB,QAAQ,IAAI,OAAO,KAAK,2CAA2C,CAAC;EACpE;CACF;CAEA,KAAK,MAAM,UAAU,UAAU;EAC7B,QAAQ,IAAI,KAAK,OAAO,MAAM,GAAG,EAAE,GAAG,OAAO,WAAW,OAAO,IAAI,GAAG;EACtE,QAAQ,IAAI,OAAO,OAAO,KAAK,WAAW,EAAE,GAAG,OAAO,MAAM,WAAW,OAAO,UAAU,CAAC,GAAG;EAE5F,IAAI,OAAO,WACT,QAAQ,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE,IAAI,OAAO,OAAO,WAAW,OAAO,SAAS,CAAC,GAAG;EAG9F,QAAQ,IAAI,EAAE;CAChB;AACF;;;;;;;;;;;AAYA,SAAgB,gBAAgB,SAA2C;CACzE,IAAI,QAAQ,WAAW,GACrB;CAGF,MAAM,aAAa,QAAQ,QAAQ,WAAW,OAAO,OAAO,EAAE;CAC9D,MAAM,SAAS,QAAQ,SAAS;CAEhC,QAAQ,IAAI,EAAE;CAEd,IAAI,WAAW,GAAG;EAChB,QAAQ,IACN,GAAG,OAAO,MAAM,GAAG,EAAE,GAAG,OAAO,MAAM,GAAG,WAAW,GAAG,QAAQ,QAAQ,EAAE,uBAC1E;EACA;CACF;CAEA,QAAQ,IACN,GAAG,OAAO,IAAI,GAAG,EAAE,GAAG,OAAO,IAAI,GAAG,OAAO,GAAG,QAAQ,QAAQ,EAAE,oBAClE;AACF"}
|
package/esm/cli/setup-logger.mjs
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { ConsoleLog, log } from "@warlock.js/logger";
|
|
2
|
-
|
|
3
|
-
//#region ../../@warlock.js/cascade/src/cli/setup-logger.ts
|
|
4
|
-
/**
|
|
5
|
-
* Configure `@warlock.js/logger` for the standalone Cascade CLI.
|
|
6
|
-
*
|
|
7
|
-
* The logger singleton ships with **zero channels** — without configuring
|
|
8
|
-
* it, every `log.info` / `log.warn` / `log.error` / `log.success` call in
|
|
9
|
-
* the migration runner is a silent no-op. In a warlock application the
|
|
10
|
-
* bootstrap step registers channels; the standalone CLI has no bootstrap,
|
|
11
|
-
* so we do it here.
|
|
12
|
-
*
|
|
13
|
-
* Calling this replaces any previously-configured channels — safe to invoke
|
|
14
|
-
* multiple times to reconfigure mid-process.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* setLoggerConfig();
|
|
18
|
-
* setLoggerConfig({ minLevel: "warn" });
|
|
19
|
-
* setLoggerConfig({ showContext: true });
|
|
20
|
-
*/
|
|
21
|
-
function setLoggerConfig(options = {}) {
|
|
22
|
-
log.configure({
|
|
23
|
-
channels: [new ConsoleLog({ showContext: options.showContext })],
|
|
24
|
-
minLevel: options.minLevel
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
//#endregion
|
|
29
|
-
export { setLoggerConfig };
|
|
30
|
-
//# sourceMappingURL=setup-logger.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setup-logger.mjs","names":[],"sources":["../../../../../../@warlock.js/cascade/src/cli/setup-logger.ts"],"sourcesContent":["import { ConsoleLog, log, type LogLevel } from \"@warlock.js/logger\";\n\n/**\n * Options for {@link setLoggerConfig}. Every field optional — call with no\n * arguments to get the standard CLI logger.\n */\nexport type SetLoggerConfigOptions = {\n /**\n * Pretty-print log entry context as a second line via `util.inspect`.\n * Useful while debugging; noisy for regular CLI use.\n *\n * @default false\n */\n readonly showContext?: boolean;\n /**\n * Logger-wide minimum severity. Entries below this level are dropped\n * before any channel is invoked.\n *\n * @default undefined (every level reaches the console channel)\n */\n readonly minLevel?: LogLevel;\n};\n\n/**\n * Configure `@warlock.js/logger` for the standalone Cascade CLI.\n *\n * The logger singleton ships with **zero channels** — without configuring\n * it, every `log.info` / `log.warn` / `log.error` / `log.success` call in\n * the migration runner is a silent no-op. In a warlock application the\n * bootstrap step registers channels; the standalone CLI has no bootstrap,\n * so we do it here.\n *\n * Calling this replaces any previously-configured channels — safe to invoke\n * multiple times to reconfigure mid-process.\n *\n * @example\n * setLoggerConfig();\n * setLoggerConfig({ minLevel: \"warn\" });\n * setLoggerConfig({ showContext: true });\n */\nexport function setLoggerConfig(options: SetLoggerConfigOptions = {}): void {\n log.configure({\n channels: [new ConsoleLog({ showContext: options.showContext })],\n minLevel: options.minLevel,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAwCA,SAAgB,gBAAgB,UAAkC,CAAC,GAAS;CAC1E,IAAI,UAAU;EACZ,UAAU,CAAC,IAAI,WAAW,EAAE,aAAa,QAAQ,YAAY,CAAC,CAAC;EAC/D,UAAU,QAAQ;CACpB,CAAC;AACH"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { dataSourceRegistry } from "../data-source/data-source-registry.mjs";
|
|
2
|
-
import { connectFromEnv } from "./connection-from-env.mjs";
|
|
3
|
-
|
|
4
|
-
//#region ../../@warlock.js/cascade/src/cli/with-cli-connection.ts
|
|
5
|
-
/**
|
|
6
|
-
* Run a CLI handler with a live data-source connection.
|
|
7
|
-
*
|
|
8
|
-
* Lifecycle:
|
|
9
|
-
* 1. `connectFromEnv()` — register the default data source and open the
|
|
10
|
-
* driver pool/socket.
|
|
11
|
-
* 2. `handler()` — your command logic.
|
|
12
|
-
* 3. Disconnect every data source in the registry — always runs, including
|
|
13
|
-
* when the handler throws, so the Node process can exit cleanly.
|
|
14
|
-
*
|
|
15
|
-
* Errors raised by `disconnect()` are swallowed: they would otherwise mask
|
|
16
|
-
* a real error from the handler and there's nothing useful a caller can do
|
|
17
|
-
* once the process is on its way out.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* await withCliConnection(async () => {
|
|
21
|
-
* await loadMigrations(path);
|
|
22
|
-
* const results = await runMigrations();
|
|
23
|
-
* printRunSummary(results);
|
|
24
|
-
* });
|
|
25
|
-
*/
|
|
26
|
-
async function withCliConnection(handler) {
|
|
27
|
-
await connectFromEnv();
|
|
28
|
-
try {
|
|
29
|
-
return await handler();
|
|
30
|
-
} finally {
|
|
31
|
-
for (const dataSource of dataSourceRegistry.getAllDataSources()) try {
|
|
32
|
-
await dataSource.driver.disconnect();
|
|
33
|
-
} catch {}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
//#endregion
|
|
38
|
-
export { withCliConnection };
|
|
39
|
-
//# sourceMappingURL=with-cli-connection.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"with-cli-connection.mjs","names":[],"sources":["../../../../../../@warlock.js/cascade/src/cli/with-cli-connection.ts"],"sourcesContent":["import { dataSourceRegistry } from \"../data-source/data-source-registry\";\nimport { connectFromEnv } from \"./connection-from-env\";\n\n/**\n * Run a CLI handler with a live data-source connection.\n *\n * Lifecycle:\n * 1. `connectFromEnv()` — register the default data source and open the\n * driver pool/socket.\n * 2. `handler()` — your command logic.\n * 3. Disconnect every data source in the registry — always runs, including\n * when the handler throws, so the Node process can exit cleanly.\n *\n * Errors raised by `disconnect()` are swallowed: they would otherwise mask\n * a real error from the handler and there's nothing useful a caller can do\n * once the process is on its way out.\n *\n * @example\n * await withCliConnection(async () => {\n * await loadMigrations(path);\n * const results = await runMigrations();\n * printRunSummary(results);\n * });\n */\nexport async function withCliConnection<T>(handler: () => Promise<T>): Promise<T> {\n await connectFromEnv();\n\n try {\n return await handler();\n } finally {\n for (const dataSource of dataSourceRegistry.getAllDataSources()) {\n try {\n await dataSource.driver.disconnect();\n } catch {\n // Suppress — masking the handler's real error would be worse.\n }\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,eAAsB,kBAAqB,SAAuC;CAChF,MAAM,eAAe;CAErB,IAAI;EACF,OAAO,MAAM,QAAQ;CACvB,UAAU;EACR,KAAK,MAAM,cAAc,mBAAmB,kBAAkB,GAC5D,IAAI;GACF,MAAM,WAAW,OAAO,WAAW;EACrC,QAAQ,CAER;CAEJ;AACF"}
|
package/esm/cli.d.mts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
package/esm/cli.mjs
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { main } from "./cli/index.mjs";
|
|
2
|
-
import { setLoggerConfig } from "./cli/setup-logger.mjs";
|
|
3
|
-
import { loadEnv } from "@mongez/dotenv";
|
|
4
|
-
import { runMain } from "citty";
|
|
5
|
-
|
|
6
|
-
//#region ../../@warlock.js/cascade/src/cli.ts
|
|
7
|
-
/**
|
|
8
|
-
* Standalone Cascade CLI entrypoint.
|
|
9
|
-
*
|
|
10
|
-
* Executed two ways:
|
|
11
|
-
* - **Dev** — `tsx ./@warlock.js/cascade/src/cli.ts ...` via the root
|
|
12
|
-
* `cascade` / `cascade.migrate` scripts.
|
|
13
|
-
* - **Production** — `bin/cascade.mjs` side-effect-imports the compiled
|
|
14
|
-
* `esm/cli.js`, which kicks off `runMain` on load.
|
|
15
|
-
*
|
|
16
|
-
* Nothing is exported on purpose. Importing this module IS the CLI.
|
|
17
|
-
*/
|
|
18
|
-
setLoggerConfig();
|
|
19
|
-
try {
|
|
20
|
-
loadEnv();
|
|
21
|
-
} catch {}
|
|
22
|
-
runMain(main);
|
|
23
|
-
|
|
24
|
-
//#endregion
|
|
25
|
-
export { };
|
|
26
|
-
//# sourceMappingURL=cli.mjs.map
|
package/esm/cli.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cli.mjs","names":[],"sources":["../../../../../@warlock.js/cascade/src/cli.ts"],"sourcesContent":["/**\n * Standalone Cascade CLI entrypoint.\n *\n * Executed two ways:\n * - **Dev** — `tsx ./@warlock.js/cascade/src/cli.ts ...` via the root\n * `cascade` / `cascade.migrate` scripts.\n * - **Production** — `bin/cascade.mjs` side-effect-imports the compiled\n * `esm/cli.js`, which kicks off `runMain` on load.\n *\n * Nothing is exported on purpose. Importing this module IS the CLI.\n */\n\nimport { loadEnv } from \"@mongez/dotenv\";\nimport { runMain } from \"citty\";\nimport { main } from \"./cli/index\";\nimport { setLoggerConfig } from \"./cli/setup-logger\";\n\n// Wire the framework logger to stdout. Without this the migration runner's\n// log.* calls are silent no-ops in standalone mode.\nsetLoggerConfig();\n\n// Auto-load `.env` (or `.env.<NODE_ENV>`) from cwd before any command runs so\n// `connectFromEnv` sees the same vars an existing warlock project already\n// declares. Absence of an env file is not an error — vars may come from the\n// shell, CI, or `node --env-file=...`.\ntry {\n loadEnv();\n} catch {\n // No .env file at the resolved path — proceed with whatever the shell set.\n}\n\nrunMain(main);\n"],"mappings":";;;;;;;;;;;;;;;;;AAmBA,gBAAgB;AAMhB,IAAI;CACF,QAAQ;AACV,QAAQ,CAER;AAEA,QAAQ,IAAI"}
|