@warlock.js/cascade 5.30.0 → 5.32.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 +17 -0
- package/README.md +1 -5
- package/cjs/index.cjs +104 -86
- package/cjs/index.cjs.map +1 -1
- package/esm/context/database-data-source-context.d.mts +2 -3
- package/esm/context/database-data-source-context.d.mts.map +1 -1
- package/esm/context/database-transaction-context.d.mts +2 -3
- package/esm/context/database-transaction-context.d.mts.map +1 -1
- package/esm/contracts/database-driver.contract.d.mts +56 -36
- package/esm/contracts/database-driver.contract.d.mts.map +1 -1
- package/esm/contracts/database-id-generator.contract.d.mts +7 -5
- package/esm/contracts/database-id-generator.contract.d.mts.map +1 -1
- package/esm/contracts/database-remover.contract.d.mts +3 -5
- package/esm/contracts/database-remover.contract.d.mts.map +1 -1
- package/esm/contracts/database-restorer.contract.d.mts +6 -6
- package/esm/contracts/database-restorer.contract.d.mts.map +1 -1
- package/esm/contracts/database-writer.contract.d.mts +4 -6
- package/esm/contracts/database-writer.contract.d.mts.map +1 -1
- package/esm/contracts/driver-blueprint.contract.d.mts +2 -3
- package/esm/contracts/driver-blueprint.contract.d.mts.map +1 -1
- package/esm/contracts/index.d.mts +2 -1
- package/esm/contracts/migration-driver.contract.d.mts +101 -53
- package/esm/contracts/migration-driver.contract.d.mts.map +1 -1
- package/esm/contracts/query-builder.contract.d.mts +51 -33
- package/esm/contracts/query-builder.contract.d.mts.map +1 -1
- package/esm/contracts/sync-adapter.contract.d.mts +25 -14
- package/esm/contracts/sync-adapter.contract.d.mts.map +1 -1
- package/esm/data-source/data-source-registry.d.mts +4 -5
- package/esm/data-source/data-source-registry.d.mts.map +1 -1
- package/esm/data-source/data-source-registry.mjs.map +1 -1
- package/esm/data-source/data-source.d.mts +8 -5
- package/esm/data-source/data-source.d.mts.map +1 -1
- package/esm/database-dirty-tracker.d.mts +2 -2
- package/esm/database-dirty-tracker.d.mts.map +1 -1
- package/esm/database-dirty-tracker.mjs +3 -2
- package/esm/database-dirty-tracker.mjs.map +1 -1
- package/esm/drivers/mongodb/mongodb-driver.d.mts +3 -4
- package/esm/drivers/mongodb/mongodb-driver.d.mts.map +1 -1
- package/esm/drivers/mongodb/mongodb-driver.mjs.map +1 -1
- package/esm/drivers/mongodb/mongodb-id-generator.d.mts +2 -3
- package/esm/drivers/mongodb/mongodb-id-generator.d.mts.map +1 -1
- package/esm/drivers/mongodb/mongodb-id-generator.mjs.map +1 -1
- package/esm/drivers/mongodb/mongodb-migration-driver.d.mts +1 -3
- package/esm/drivers/mongodb/mongodb-migration-driver.d.mts.map +1 -1
- package/esm/drivers/mongodb/mongodb-query-builder.d.mts +2 -3
- package/esm/drivers/mongodb/mongodb-query-builder.d.mts.map +1 -1
- package/esm/drivers/mongodb/mongodb-query-builder.mjs +8 -5
- package/esm/drivers/mongodb/mongodb-query-builder.mjs.map +1 -1
- package/esm/drivers/mongodb/mongodb-query-operations.d.mts +1 -3
- package/esm/drivers/mongodb/mongodb-query-operations.d.mts.map +1 -1
- package/esm/drivers/mongodb/mongodb-query-operations.mjs.map +1 -1
- package/esm/drivers/mongodb/mongodb-query-parser.d.mts +7 -6
- package/esm/drivers/mongodb/mongodb-query-parser.d.mts.map +1 -1
- package/esm/drivers/mongodb/mongodb-query-parser.mjs +2 -6
- package/esm/drivers/mongodb/mongodb-query-parser.mjs.map +1 -1
- package/esm/drivers/mongodb/mongodb-sync-adapter.d.mts +1 -3
- package/esm/drivers/mongodb/mongodb-sync-adapter.d.mts.map +1 -1
- package/esm/drivers/mongodb/types.d.mts +11 -9
- package/esm/drivers/mongodb/types.d.mts.map +1 -1
- package/esm/drivers/postgres/index.d.mts +2 -1
- package/esm/drivers/postgres/index.mjs +1 -1
- package/esm/drivers/postgres/naming.mjs +1 -1
- package/esm/drivers/postgres/naming.mjs.map +1 -1
- package/esm/drivers/postgres/postgres-blueprint.d.mts +1 -3
- package/esm/drivers/postgres/postgres-blueprint.d.mts.map +1 -1
- package/esm/drivers/postgres/postgres-dialect.d.mts +4 -6
- package/esm/drivers/postgres/postgres-dialect.d.mts.map +1 -1
- package/esm/drivers/postgres/postgres-dialect.mjs.map +1 -1
- package/esm/drivers/postgres/postgres-driver.d.mts +4 -5
- package/esm/drivers/postgres/postgres-driver.d.mts.map +1 -1
- package/esm/drivers/postgres/postgres-driver.mjs.map +1 -1
- package/esm/drivers/postgres/postgres-migration-driver.d.mts +1 -3
- package/esm/drivers/postgres/postgres-migration-driver.d.mts.map +1 -1
- package/esm/drivers/postgres/postgres-migration-driver.mjs +13 -10
- package/esm/drivers/postgres/postgres-migration-driver.mjs.map +1 -1
- package/esm/drivers/postgres/postgres-query-builder.d.mts +4 -4
- package/esm/drivers/postgres/postgres-query-builder.d.mts.map +1 -1
- package/esm/drivers/postgres/postgres-query-builder.mjs +14 -10
- package/esm/drivers/postgres/postgres-query-builder.mjs.map +1 -1
- package/esm/drivers/postgres/postgres-query-parser.d.mts +16 -11
- package/esm/drivers/postgres/postgres-query-parser.d.mts.map +1 -1
- package/esm/drivers/postgres/postgres-query-parser.mjs +1 -2
- package/esm/drivers/postgres/postgres-query-parser.mjs.map +1 -1
- package/esm/drivers/postgres/postgres-sql-serializer.mjs +13 -10
- package/esm/drivers/postgres/postgres-sql-serializer.mjs.map +1 -1
- package/esm/drivers/postgres/postgres-ttl-purge.mjs +1 -1
- package/esm/drivers/postgres/postgres-ttl-purge.mjs.map +1 -1
- package/esm/drivers/postgres/postgres-type-converters.mjs +2 -2
- package/esm/drivers/postgres/postgres-type-converters.mjs.map +1 -1
- package/esm/drivers/postgres/postgres-update-validator.mjs +1 -1
- package/esm/drivers/postgres/postgres-update-validator.mjs.map +1 -1
- package/esm/drivers/postgres/types.d.mts +87 -45
- package/esm/drivers/postgres/types.d.mts.map +1 -1
- package/esm/drivers/sql/sql-dialect.contract.d.mts +1 -3
- package/esm/drivers/sql/sql-dialect.contract.d.mts.map +1 -1
- package/esm/drivers/sql/sql-types.d.mts +113 -59
- package/esm/drivers/sql/sql-types.d.mts.map +1 -1
- package/esm/errors/missing-data-source.error.d.mts +1 -2
- package/esm/errors/missing-data-source.error.d.mts.map +1 -1
- package/esm/errors/transaction-rollback.error.d.mts +1 -2
- package/esm/errors/transaction-rollback.error.d.mts.map +1 -1
- package/esm/errors/undefined-where-value.error.d.mts +1 -2
- package/esm/errors/undefined-where-value.error.d.mts.map +1 -1
- package/esm/errors/unsafe-filter.error.d.mts +1 -2
- package/esm/errors/unsafe-filter.error.d.mts.map +1 -1
- package/esm/errors/unsafe-raw-expression.error.d.mts +1 -2
- package/esm/errors/unsafe-raw-expression.error.d.mts.map +1 -1
- package/esm/errors/unsupported-lean-operation.error.d.mts +1 -2
- package/esm/errors/unsupported-lean-operation.error.d.mts.map +1 -1
- package/esm/errors/unsupported-lock-for-update.error.d.mts +1 -2
- package/esm/errors/unsupported-lock-for-update.error.d.mts.map +1 -1
- package/esm/errors/unsupported-query-operation.error.d.mts +1 -2
- package/esm/errors/unsupported-query-operation.error.d.mts.map +1 -1
- package/esm/errors/unsupported-query-operation.error.mjs.map +1 -1
- package/esm/errors/unsupported-update-operation.error.d.mts +1 -2
- package/esm/errors/unsupported-update-operation.error.d.mts.map +1 -1
- package/esm/events/model-events.d.mts +8 -6
- package/esm/events/model-events.d.mts.map +1 -1
- package/esm/expressions/aggregate-expressions.d.mts +7 -7
- package/esm/expressions/aggregate-expressions.d.mts.map +1 -1
- package/esm/expressions/column-expressions.d.mts +11 -11
- package/esm/expressions/column-expressions.d.mts.map +1 -1
- package/esm/expressions/column-expressions.mjs.map +1 -1
- package/esm/index.d.mts +7 -2
- package/esm/index.mjs +1 -1
- package/esm/migration/column-builder.d.mts +2 -3
- package/esm/migration/column-builder.d.mts.map +1 -1
- package/esm/migration/column-helpers.d.mts +49 -50
- package/esm/migration/column-helpers.d.mts.map +1 -1
- package/esm/migration/column-helpers.mjs +1 -1
- package/esm/migration/foreign-key-builder.d.mts +2 -3
- package/esm/migration/foreign-key-builder.d.mts.map +1 -1
- package/esm/migration/foreign-key-builder.mjs.map +1 -1
- package/esm/migration/index.d.mts +3 -2
- package/esm/migration/index.mjs +2 -2
- package/esm/migration/migration-runner.d.mts +7 -6
- package/esm/migration/migration-runner.d.mts.map +1 -1
- package/esm/migration/migration-runner.mjs +15 -11
- package/esm/migration/migration-runner.mjs.map +1 -1
- package/esm/migration/migration.d.mts +50 -32
- package/esm/migration/migration.d.mts.map +1 -1
- package/esm/migration/migration.mjs +1 -3
- package/esm/migration/migration.mjs.map +1 -1
- package/esm/migration/parse-created-at.mjs.map +1 -1
- package/esm/migration/sql-grammar.mjs.map +1 -1
- package/esm/migration/sql-serializer.d.mts +1 -3
- package/esm/migration/sql-serializer.d.mts.map +1 -1
- package/esm/migration/types.d.mts +7 -7
- package/esm/migration/types.d.mts.map +1 -1
- package/esm/model/generate-model-id.mjs.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/dirty-methods.mjs.map +1 -1
- package/esm/model/methods/hydration-methods.mjs.map +1 -1
- package/esm/model/methods/meta-methods.mjs +4 -2
- package/esm/model/methods/meta-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/scope-methods.mjs.map +1 -1
- package/esm/model/methods/static-event-methods.mjs.map +1 -1
- package/esm/model/methods/write-methods.d.mts +3 -2
- package/esm/model/methods/write-methods.d.mts.map +1 -1
- package/esm/model/methods/write-methods.mjs +5 -2
- package/esm/model/methods/write-methods.mjs.map +1 -1
- package/esm/model/model.d.mts +9 -9
- package/esm/model/model.d.mts.map +1 -1
- package/esm/model/model.mjs.map +1 -1
- package/esm/model/model.types.d.mts +7 -7
- package/esm/model/model.types.d.mts.map +1 -1
- package/esm/model/register-model.d.mts +13 -15
- package/esm/model/register-model.d.mts.map +1 -1
- package/esm/model/register-model.mjs.map +1 -1
- package/esm/model/relation-decorators.d.mts +6 -8
- package/esm/model/relation-decorators.d.mts.map +1 -1
- package/esm/operations/database.d.mts +13 -8
- package/esm/operations/database.d.mts.map +1 -1
- package/esm/operations/index.d.mts +2 -1
- package/esm/operations/index.mjs +1 -1
- package/esm/operations/migrations.d.mts +18 -14
- package/esm/operations/migrations.d.mts.map +1 -1
- package/esm/operations/migrations.mjs.map +1 -1
- package/esm/query-builder/query-builder.d.mts +2 -4
- package/esm/query-builder/query-builder.d.mts.map +1 -1
- package/esm/query-builder/query-builder.mjs +12 -11
- package/esm/query-builder/query-builder.mjs.map +1 -1
- package/esm/relations/index.d.mts +2 -1
- package/esm/relations/index.mjs +1 -1
- package/esm/relations/key-conventions.mjs +2 -1
- package/esm/relations/key-conventions.mjs.map +1 -1
- package/esm/relations/pivot-operations.d.mts +3 -5
- package/esm/relations/pivot-operations.d.mts.map +1 -1
- package/esm/relations/pivot-operations.mjs.map +1 -1
- package/esm/relations/relation-hydrator.d.mts +3 -5
- package/esm/relations/relation-hydrator.d.mts.map +1 -1
- package/esm/relations/relation-loader.d.mts +2 -4
- package/esm/relations/relation-loader.d.mts.map +1 -1
- package/esm/relations/relation-loader.mjs +4 -5
- package/esm/relations/relation-loader.mjs.map +1 -1
- package/esm/relations/types.d.mts +14 -15
- package/esm/relations/types.d.mts.map +1 -1
- package/esm/remover/database-remover.d.mts +1 -3
- package/esm/remover/database-remover.d.mts.map +1 -1
- package/esm/remover/database-remover.mjs.map +1 -1
- package/esm/restorer/database-restorer.d.mts +1 -3
- package/esm/restorer/database-restorer.d.mts.map +1 -1
- package/esm/restorer/database-restorer.mjs +2 -1
- package/esm/restorer/database-restorer.mjs.map +1 -1
- package/esm/sql-database-dirty-tracker.d.mts +1 -3
- package/esm/sql-database-dirty-tracker.d.mts.map +1 -1
- package/esm/sync/model-events.mjs +1 -1
- package/esm/sync/model-sync-operation.d.mts +2 -4
- package/esm/sync/model-sync-operation.d.mts.map +1 -1
- package/esm/sync/model-sync.d.mts +3 -4
- package/esm/sync/model-sync.d.mts.map +1 -1
- package/esm/sync/sync-context.d.mts +2 -4
- package/esm/sync/sync-context.d.mts.map +1 -1
- package/esm/sync/sync-context.mjs.map +1 -1
- package/esm/sync/sync-fanout.mjs +1 -1
- package/esm/sync/sync-fanout.mjs.map +1 -1
- package/esm/sync/sync-manager.d.mts +2 -4
- package/esm/sync/sync-manager.d.mts.map +1 -1
- package/esm/sync/sync-manager.mjs.map +1 -1
- package/esm/sync/types.d.mts +121 -64
- package/esm/sync/types.d.mts.map +1 -1
- package/esm/transactions/after-commit.d.mts +2 -2
- package/esm/transactions/after-commit.d.mts.map +1 -1
- package/esm/types.d.mts +7 -8
- package/esm/types.d.mts.map +1 -1
- package/esm/utils/connect-to-database.d.mts +7 -8
- package/esm/utils/connect-to-database.d.mts.map +1 -1
- package/esm/utils/database-writer.utils.d.mts +3 -4
- package/esm/utils/database-writer.utils.d.mts.map +1 -1
- package/esm/utils/database-writer.utils.mjs.map +1 -1
- package/esm/utils/define-model.d.mts +3 -5
- package/esm/utils/define-model.d.mts.map +1 -1
- package/esm/utils/escape-regex.d.mts +3 -4
- package/esm/utils/escape-regex.d.mts.map +1 -1
- package/esm/utils/is-valid-date-value.mjs.map +1 -1
- package/esm/utils/once-connected.d.mts +2 -4
- package/esm/utils/once-connected.d.mts.map +1 -1
- package/esm/utils/sanitize-filter.d.mts +3 -4
- package/esm/utils/sanitize-filter.d.mts.map +1 -1
- package/esm/validation/database-seal-plugins.d.mts +2 -1
- package/esm/validation/database-writer-validation-error.d.mts +1 -3
- package/esm/validation/database-writer-validation-error.d.mts.map +1 -1
- package/esm/validation/index.d.mts +3 -1
- package/esm/validation/index.mjs +1 -1
- package/esm/validation/plugins/database-rules-plugin.d.mts +2 -3
- package/esm/validation/plugins/database-rules-plugin.d.mts.map +1 -1
- package/esm/validation/plugins/embed-validator-plugin.d.mts +4 -3
- package/esm/validation/plugins/embed-validator-plugin.d.mts.map +1 -1
- package/esm/validation/types.d.mts +14 -10
- package/esm/validation/types.d.mts.map +1 -1
- package/esm/validation/validators/embed-validator.d.mts +2 -3
- package/esm/validation/validators/embed-validator.d.mts.map +1 -1
- package/esm/writer/database-writer.d.mts +1 -3
- 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 +541 -434
- package/package.json +5 -5
- package/skills/aggregate-data/SKILL.md +28 -17
- package/skills/alter-migration/SKILL.md +325 -233
- package/skills/cascade-basics/SKILL.md +19 -19
- package/skills/configure-delete-strategy/SKILL.md +11 -11
- package/skills/define-model/SKILL.md +19 -17
- package/skills/define-relations/SKILL.md +13 -18
- package/skills/index.md +3 -0
- package/skills/manage-transactions/SKILL.md +18 -12
- package/skills/paginate-results/SKILL.md +6 -8
- package/skills/perform-atomic-ops/SKILL.md +26 -21
- package/skills/query-data/SKILL.md +27 -33
- package/skills/run-cascade-cli/SKILL.md +11 -10
- package/skills/search-by-vector/SKILL.md +8 -5
- package/skills/subscribe-to-model-events/SKILL.md +17 -17
- package/skills/track-changes/SKILL.md +9 -9
- package/skills/write-migration/SKILL.md +4 -4
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ChildModel, ModelSchema } from "./model.types.mjs";
|
|
2
2
|
import { Model } from "./model.mjs";
|
|
3
3
|
import { Lazy } from "@mongez/reinforcements";
|
|
4
|
-
|
|
5
4
|
//#region ../../packages/cascade/src/model/register-model.d.ts
|
|
6
5
|
/**
|
|
7
6
|
* Any way a relation target can be expressed: a string name registered
|
|
@@ -15,11 +14,11 @@ import { Lazy } from "@mongez/reinforcements";
|
|
|
15
14
|
* class to `ChildModel<Model>` internally; the user's `lazy(() => X)`
|
|
16
15
|
* call already guarantees the shape at the source.
|
|
17
16
|
*/
|
|
18
|
-
type ModelRef = ChildModel<Model> | string | Lazy<unknown>;
|
|
17
|
+
export type ModelRef = ChildModel<Model> | string | Lazy<unknown>;
|
|
19
18
|
/**
|
|
20
19
|
* Options for the RegisterModel decorator
|
|
21
20
|
*/
|
|
22
|
-
type RegisterModelOptions = {
|
|
21
|
+
export type RegisterModelOptions = {
|
|
23
22
|
/**
|
|
24
23
|
* Custom name for the model in the global registry.
|
|
25
24
|
* If not provided, uses the class name.
|
|
@@ -61,8 +60,8 @@ type RegisterModelOptions = {
|
|
|
61
60
|
* const UserModel = getModelFromRegistry("User");
|
|
62
61
|
* ```
|
|
63
62
|
*/
|
|
64
|
-
declare function RegisterModel(options?: RegisterModelOptions): <T extends ChildModel<Model>>(value: T, context: ClassDecoratorContext<T>) => T;
|
|
65
|
-
declare function registerModelInRegistry(name: string, model: ChildModel<Model>): void;
|
|
63
|
+
export declare function RegisterModel(options?: RegisterModelOptions): <T extends ChildModel<Model>>(value: T, context: ClassDecoratorContext<T>) => T;
|
|
64
|
+
export declare function registerModelInRegistry(name: string, model: ChildModel<Model>): void;
|
|
66
65
|
/**
|
|
67
66
|
* Get a model class by its name from the global registry.
|
|
68
67
|
*
|
|
@@ -77,7 +76,7 @@ declare function registerModelInRegistry(name: string, model: ChildModel<Model>)
|
|
|
77
76
|
* }
|
|
78
77
|
* ```
|
|
79
78
|
*/
|
|
80
|
-
declare function getModelFromRegistry(name: string): ChildModel<Model<ModelSchema>> | undefined;
|
|
79
|
+
export declare function getModelFromRegistry(name: string): ChildModel<Model<ModelSchema>> | undefined;
|
|
81
80
|
/**
|
|
82
81
|
* Get all registered models from the global registry.
|
|
83
82
|
*
|
|
@@ -91,25 +90,25 @@ declare function getModelFromRegistry(name: string): ChildModel<Model<ModelSchem
|
|
|
91
90
|
* }
|
|
92
91
|
* ```
|
|
93
92
|
*/
|
|
94
|
-
declare function getAllModelsFromRegistry(): Map<string, ChildModel<Model<ModelSchema>>>;
|
|
93
|
+
export declare function getAllModelsFromRegistry(): Map<string, ChildModel<Model<ModelSchema>>>;
|
|
95
94
|
/**
|
|
96
95
|
* Clean up all models from register
|
|
97
96
|
*/
|
|
98
|
-
declare function cleanupModelsRegistery(): void;
|
|
99
|
-
declare function removeModelFromRegistery(name: string): void;
|
|
100
|
-
declare function resolveModelClass(model: ModelRef): ChildModel<Model>;
|
|
97
|
+
export declare function cleanupModelsRegistery(): void;
|
|
98
|
+
export declare function removeModelFromRegistery(name: string): void;
|
|
99
|
+
export declare function resolveModelClass(model: ModelRef): ChildModel<Model>;
|
|
101
100
|
/**
|
|
102
101
|
* Like `resolveModelClass`, but throws a descriptive error when a string
|
|
103
102
|
* ref isn't registered instead of returning `undefined`.
|
|
104
103
|
*/
|
|
105
|
-
declare function requireModelClass(model: ModelRef): ChildModel<Model>;
|
|
104
|
+
export declare function requireModelClass(model: ModelRef): ChildModel<Model>;
|
|
106
105
|
/**
|
|
107
106
|
* Like `resolveModelClass`, but returns `undefined` instead of asserting
|
|
108
107
|
* a non-null result when a string ref isn't in the registry. Use this
|
|
109
108
|
* at call sites that already handle the missing-model case explicitly
|
|
110
109
|
* (e.g. join builders that throw their own contextual error).
|
|
111
110
|
*/
|
|
112
|
-
declare function tryResolveModelClass(model: ModelRef | undefined): ChildModel<Model> | undefined;
|
|
111
|
+
export declare function tryResolveModelClass(model: ModelRef | undefined): ChildModel<Model> | undefined;
|
|
113
112
|
/**
|
|
114
113
|
* Read the model's registered name from any `ModelRef`. Used by
|
|
115
114
|
* convention helpers (`inferPivotTable`, `inferPivotKey`) that derive
|
|
@@ -119,7 +118,7 @@ declare function tryResolveModelClass(model: ModelRef | undefined): ChildModel<M
|
|
|
119
118
|
* the class's `.name` is returned — same string the registry would
|
|
120
119
|
* key the class under, so conventions stay consistent across ref shapes.
|
|
121
120
|
*/
|
|
122
|
-
declare function resolveModelName(model: ModelRef): string;
|
|
121
|
+
export declare function resolveModelName(model: ModelRef): string;
|
|
123
122
|
/**
|
|
124
123
|
* Walk every registered model and verify that every relation declared on it
|
|
125
124
|
* points at another registered model. Throws fast at boot with a clear error
|
|
@@ -139,7 +138,6 @@ declare function resolveModelName(model: ModelRef): string;
|
|
|
139
138
|
* verifyRegisteredRelations();
|
|
140
139
|
* ```
|
|
141
140
|
*/
|
|
142
|
-
declare function verifyRegisteredRelations(): number;
|
|
141
|
+
export declare function verifyRegisteredRelations(): number;
|
|
143
142
|
//#endregion
|
|
144
|
-
export { ModelRef, RegisterModel, RegisterModelOptions, cleanupModelsRegistery, getAllModelsFromRegistry, getModelFromRegistry, registerModelInRegistry, removeModelFromRegistery, requireModelClass, resolveModelClass, resolveModelName, tryResolveModelClass, verifyRegisteredRelations };
|
|
145
143
|
//# sourceMappingURL=register-model.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register-model.d.mts","names":[],"sources":["../../../../../../../../packages/cascade/src/model/register-model.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"register-model.d.mts","names":["_$__model_types0.ModelSchema"],"sources":["../../../../../../../../packages/cascade/src/model/register-model.ts"],"mappings":";;;;;;;;;;;;;;;;YAiBY,WAAW,WAAW,kBAAkB;;;;YAKxC;;;;;;;;;;;EAWV;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAsCc,cAAc,UAAU,wBACrB,UAAU,WAAW,QAAM,OAAS,GAAC,SAAW,sBAAsB,OAAK;wBAoD9E,wBAAwB,cAAc,OAAO,WAAW;;;;;;;;;;;;;;;wBAkBxD,qBAAqB,eAAY,WAAA,MAAjCA;;;;;;;;;;;;;;wBAiBA,4BAAwB,YAAA,WAAA,MAAxBA;;;;wBAOA;wBAIA,yBAAyB;wBAIzB,kBAAkB,OAAO,WAAW,WAAW;;;;;wBAW/C,kBAAkB,OAAO,WAAW,WAAW;;;;;;;wBAwB/C,qBAAqB,OAAO,uBAAuB,WAAW;;;;;;;;;;wBAiB9D,iBAAiB,OAAO;;;;;;;;;;;;;;;;;;;;wBA0BxB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register-model.mjs","names":[],"sources":["../../../../../../../../packages/cascade/src/model/register-model.ts"],"sourcesContent":["import { isLazy, type Lazy } from \"@mongez/reinforcements\";\nimport type { RelationDefinition } from \"../relations/types\";\nimport type { ChildModel, Model } from \"./model\";\nimport { RELATION_METADATA_KEY } from \"./relation-decorators\";\n\n/**\n * Any way a relation target can be expressed: a string name registered\n * via `@RegisterModel()`, a direct class reference, or a `lazy(() => X)`\n * deferred class reference (for cycle-prone pairs).\n *\n * The lazy variant is typed as `Lazy<unknown>` (not `Lazy<ChildModel<Model>>`)\n * because `RelationDefinition.model` storage uses the same broader shape —\n * keeping the parameter type aligned avoids forcing every call site to\n * narrow before invoking the resolver. The helpers cast the resolved\n * class to `ChildModel<Model>` internally; the user's `lazy(() => X)`\n * call already guarantees the shape at the source.\n */\nexport type ModelRef = ChildModel<Model> | string | Lazy<unknown>;\n\n/**\n * Options for the RegisterModel decorator\n */\nexport type RegisterModelOptions = {\n /**\n * Custom name for the model in the global registry.\n * If not provided, uses the class name.\n *\n * @example\n * ```typescript\n * @RegisterModel({ name: \"CustomUser\" })\n * export class User extends Model {}\n * ```\n */\n name?: string;\n};\n\n/**\n * Global model registry that maps model class names to their constructors.\n * This allows for string-based model references to avoid circular dependencies.\n */\nconst modelsRegistry = new Map<string, ChildModel<Model>>();\n\n/**\n * Class decorator that registers a model in the global registry.\n *\n * This is an opt-in mechanism that allows models to be referenced by string name\n * instead of direct class imports, helping avoid circular dependencies.\n *\n * Uses the **TC39 Stage 3 decorator** signature (standard since TypeScript 5.0).\n * Requires `experimentalDecorators: false` (or unset) in `tsconfig.json`.\n *\n * @param options - Optional configuration for registration\n *\n * @example\n * ```typescript\n * // Auto-capture class name\n * @RegisterModel()\n * export class User extends Model {\n * static table = \"users\";\n * }\n *\n * // Custom name\n * @RegisterModel({ name: \"UserModel\" })\n * export class User extends Model {\n * static table = \"users\";\n * }\n *\n * // Later, retrieve by name:\n * const UserModel = getModelFromRegistry(\"User\");\n * ```\n */\nexport function RegisterModel(options?: RegisterModelOptions) {\n return function <T extends ChildModel<Model>>(value: T, context: ClassDecoratorContext<T>): T {\n if (context.kind !== \"class\") {\n throw new Error(`@RegisterModel can only be applied to classes — got \"${context.kind}\".`);\n }\n\n const modelName = options?.name || (context.name ?? value.name);\n\n if (!modelName) {\n throw new Error(\n \"@RegisterModel decorator: Unable to determine model name. \" +\n \"Please provide a name in options or ensure your class has a name.\",\n );\n }\n\n if (modelsRegistry.has(modelName)) {\n console.warn(\n `⚠️ Model \"${modelName}\" is already registered. ` +\n `This will overwrite the previous registration.`,\n );\n }\n\n // Hoist relation definitions stashed by `@BelongsTo` / `@HasMany` /\n // etc. on this class's decorator-metadata bag onto the class's static\n // `relations` map. Field-decorator initializers are instance-level in\n // TC39 stage 3 — they never fire for class-level operations like\n // `Model.withCount(\"rel\")`. Reading via shared `context.metadata` is\n // the right hand-off point because all field decorators have already\n // run by the time the class decorator executes.\n const decoratorRelations = context.metadata?.[RELATION_METADATA_KEY] as\n | Record<string, RelationDefinition>\n | undefined;\n\n if (decoratorRelations && Object.keys(decoratorRelations).length > 0) {\n const ownRelations = Object.prototype.hasOwnProperty.call(value, \"relations\")\n ? (value as unknown as { relations: Record<string, RelationDefinition> }).relations\n : { ...((value as unknown as { relations?: Record<string, RelationDefinition> }).relations ?? {}) };\n\n (value as unknown as { relations: Record<string, RelationDefinition> }).relations = {\n ...ownRelations,\n ...decoratorRelations,\n };\n }\n\n modelsRegistry.set(modelName, value);\n\n return value;\n };\n}\n\nexport function registerModelInRegistry(name: string, model: ChildModel<Model>) {\n modelsRegistry.set(name, model);\n}\n\n/**\n * Get a model class by its name from the global registry.\n *\n * @param name - The model class name\n * @returns The model class or undefined if not found\n *\n * @example\n * ```typescript\n * const UserModel = getModelFromRegistry(\"User\");\n * if (UserModel) {\n * const user = await UserModel.find(1);\n * }\n * ```\n */\nexport function getModelFromRegistry(name: string) {\n return modelsRegistry.get(name);\n}\n\n/**\n * Get all registered models from the global registry.\n *\n * @returns A Map of all registered model classes by name\n *\n * @example\n * ```typescript\n * const allModels = getAllModelsFromRegistry();\n * for (const [name, ModelClass] of allModels) {\n * console.log(`Found model: ${name}`);\n * }\n * ```\n */\nexport function getAllModelsFromRegistry() {\n return new Map(modelsRegistry);\n}\n\n/**\n * Clean up all models from register\n */\nexport function cleanupModelsRegistery() {\n modelsRegistry.clear();\n}\n\nexport function removeModelFromRegistery(name: string) {\n modelsRegistry.delete(name);\n}\n\nexport function resolveModelClass(model: ModelRef): ChildModel<Model> {\n if (typeof model === \"string\") return getModelFromRegistry(model)!;\n if (isLazy(model)) return model.resolve() as ChildModel<Model>;\n\n return model;\n}\n\n/**\n * Like `resolveModelClass`, but throws a descriptive error when a string\n * ref isn't registered instead of returning `undefined`.\n */\nexport function requireModelClass(model: ModelRef): ChildModel<Model> {\n if (typeof model === \"string\") {\n const found = getModelFromRegistry(model);\n\n if (!found) {\n const registered = [...modelsRegistry.keys()].join(\", \") || \"none\";\n\n throw new Error(\n `Model \"${model}\" is not registered (did you forget @RegisterModel()?). Registered: ${registered}`,\n );\n }\n\n return found;\n }\n\n return resolveModelClass(model);\n}\n\n/**\n * Like `resolveModelClass`, but returns `undefined` instead of asserting\n * a non-null result when a string ref isn't in the registry. Use this\n * at call sites that already handle the missing-model case explicitly\n * (e.g. join builders that throw their own contextual error).\n */\nexport function tryResolveModelClass(\n model: ModelRef | undefined,\n): ChildModel<Model> | undefined {\n if (model === undefined) return undefined;\n if (typeof model === \"string\") return getModelFromRegistry(model);\n if (isLazy(model)) return model.resolve() as ChildModel<Model>;\n\n return model;\n}\n\n/**\n * Read the model's registered name from any `ModelRef`. Used by\n * convention helpers (`inferPivotTable`, `inferPivotKey`) that derive\n * table / column names from the related model's class name.\n *\n * For string refs the value passes through. For class and lazy refs\n * the class's `.name` is returned — same string the registry would\n * key the class under, so conventions stay consistent across ref shapes.\n */\nexport function resolveModelName(model: ModelRef): string {\n if (typeof model === \"string\") return model;\n if (isLazy(model)) return (model.resolve() as ChildModel<Model>).name;\n\n return model.name;\n}\n\n/**\n * Walk every registered model and verify that every relation declared on it\n * points at another registered model. Throws fast at boot with a clear error\n * naming the unresolved target — much better signal than the runtime\n * \"Model not found\" thrown deep inside a query.\n *\n * Call this once during app bootstrap, after every `@RegisterModel`-decorated\n * model module has been imported.\n *\n * @returns The number of relations verified (success case)\n * @throws Error listing every unresolved relation target if any are missing\n *\n * @example\n * ```typescript\n * // Inside your app bootstrap, after model imports:\n * import { verifyRegisteredRelations } from \"@warlock.js/cascade\";\n * verifyRegisteredRelations();\n * ```\n */\nexport function verifyRegisteredRelations(): number {\n type RelationDef = { type: string; model: string };\n const failures: Array<{ caller: string; relation: string; target: string }> = [];\n\n let verifiedCount = 0;\n\n for (const [callerName, ModelClass] of modelsRegistry) {\n const relations = (ModelClass as { relations?: Record<string, RelationDef> }).relations;\n\n if (!relations) {\n continue;\n }\n\n for (const [relationName, definition] of Object.entries(relations)) {\n verifiedCount++;\n const targetName = definition.model;\n\n if (typeof targetName !== \"string\") {\n // Direct class reference or `lazy(() => X)` — class binding is\n // captured by the decorator at definition time; can't drift.\n continue;\n }\n\n if (!modelsRegistry.has(targetName)) {\n failures.push({ caller: callerName, relation: relationName, target: targetName });\n }\n }\n }\n\n if (failures.length > 0) {\n const list = failures\n .map((f) => ` - ${f.caller}.${f.relation} → \"${f.target}\" is not registered`)\n .join(\"\\n\");\n throw new Error(\n `verifyRegisteredRelations: ${failures.length} unresolved relation target(s):\\n${list}\\n` +\n `Each target must be decorated with @RegisterModel() and imported before bootstrap.`,\n );\n }\n\n return verifiedCount;\n}\n"],"mappings":";;;;;;;;AAwCA,MAAM,iCAAiB,IAAI,IAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+B1D,SAAgB,cAAc,SAAgC;CAC5D,OAAO,SAAuC,OAAU,SAAsC;EAC5F,IAAI,QAAQ,SAAS,SACnB,MAAM,IAAI,MAAM,wDAAwD,QAAQ,KAAK,GAAG;EAG1F,MAAM,YAAY,SAAS,SAAS,QAAQ,QAAQ,MAAM;EAE1D,IAAI,CAAC,WACH,MAAM,IAAI,MACR,6HAEF;EAGF,IAAI,eAAe,IAAI,S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AqB,KAAK;CAChE,IAAI,OAAO,KAAK,GAAG,OAAO,MAAM,QAAQ;CAExC,OAAO;AACT;;;;;;;;;;AAWA,SAAgB,iBAAiB,OAAyB;CACxD,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,IAAI,OAAO,KAAK,GAAG,OAAQ,MAAM,QAAQ,CAAC,CAAuB;CAEjE,OAAO,MAAM;AACf;;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,4BAAoC;CAElD,MAAM,WAAwE,CAAC;CAE/E,IAAI,gBAAgB;CAEpB,KAAK,MAAM,CAAC,YAAY,eAAe,gBAAgB;EACrD,MAAM,YAAa,WAA2D;EAE9E,IAAI,CAAC,WACH;EAGF,KAAK,MAAM,CAAC,cAAc,eAAe,OAAO,QAAQ,SAAS,GAAG;GAClE;GACA,MAAM,aAAa,WAAW;GAE9B,IAAI,OAAO,eAAe,UAGxB;GAGF,IAAI,CAAC,eAAe,IAAI,UAAU,GAChC,SAAS,KAAK;IAAE,QAAQ;IAAY,UAAU;IAAc,QAAQ;GAAW,CAAC;EAEpF;CACF;CAEA,IAAI,SAAS,SAAS,GAAG;EACvB,MAAM,OAAO,SACV,KAAK,MAAM,OAAO,EAAE,OAAO,GAAG,EAAE,SAAS,MAAM,EAAE,OAAO,oBAAoB,CAAC,CAC7E,KAAK,IAAI;EACZ,MAAM,IAAI,MACR,8BAA8B,SAAS,OAAO,mCAAmC,KAAK,qFAExF;CACF;CAEA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"register-model.mjs","names":[],"sources":["../../../../../../../../packages/cascade/src/model/register-model.ts"],"sourcesContent":["import { isLazy, type Lazy } from \"@mongez/reinforcements\";\nimport type { RelationDefinition } from \"../relations/types\";\nimport type { ChildModel, Model } from \"./model\";\nimport { RELATION_METADATA_KEY } from \"./relation-decorators\";\n\n/**\n * Any way a relation target can be expressed: a string name registered\n * via `@RegisterModel()`, a direct class reference, or a `lazy(() => X)`\n * deferred class reference (for cycle-prone pairs).\n *\n * The lazy variant is typed as `Lazy<unknown>` (not `Lazy<ChildModel<Model>>`)\n * because `RelationDefinition.model` storage uses the same broader shape —\n * keeping the parameter type aligned avoids forcing every call site to\n * narrow before invoking the resolver. The helpers cast the resolved\n * class to `ChildModel<Model>` internally; the user's `lazy(() => X)`\n * call already guarantees the shape at the source.\n */\nexport type ModelRef = ChildModel<Model> | string | Lazy<unknown>;\n\n/**\n * Options for the RegisterModel decorator\n */\nexport type RegisterModelOptions = {\n /**\n * Custom name for the model in the global registry.\n * If not provided, uses the class name.\n *\n * @example\n * ```typescript\n * @RegisterModel({ name: \"CustomUser\" })\n * export class User extends Model {}\n * ```\n */\n name?: string;\n};\n\n/**\n * Global model registry that maps model class names to their constructors.\n * This allows for string-based model references to avoid circular dependencies.\n */\nconst modelsRegistry = new Map<string, ChildModel<Model>>();\n\n/**\n * Class decorator that registers a model in the global registry.\n *\n * This is an opt-in mechanism that allows models to be referenced by string name\n * instead of direct class imports, helping avoid circular dependencies.\n *\n * Uses the **TC39 Stage 3 decorator** signature (standard since TypeScript 5.0).\n * Requires `experimentalDecorators: false` (or unset) in `tsconfig.json`.\n *\n * @param options - Optional configuration for registration\n *\n * @example\n * ```typescript\n * // Auto-capture class name\n * @RegisterModel()\n * export class User extends Model {\n * static table = \"users\";\n * }\n *\n * // Custom name\n * @RegisterModel({ name: \"UserModel\" })\n * export class User extends Model {\n * static table = \"users\";\n * }\n *\n * // Later, retrieve by name:\n * const UserModel = getModelFromRegistry(\"User\");\n * ```\n */\nexport function RegisterModel(options?: RegisterModelOptions) {\n return function <T extends ChildModel<Model>>(value: T, context: ClassDecoratorContext<T>): T {\n if (context.kind !== \"class\") {\n throw new Error(`@RegisterModel can only be applied to classes — got \"${context.kind}\".`);\n }\n\n const modelName = options?.name || (context.name ?? value.name);\n\n if (!modelName) {\n throw new Error(\n \"@RegisterModel decorator: Unable to determine model name. \" +\n \"Please provide a name in options or ensure your class has a name.\",\n );\n }\n\n if (modelsRegistry.has(modelName)) {\n console.warn(\n `⚠️ Model \"${modelName}\" is already registered. ` +\n `This will overwrite the previous registration.`,\n );\n }\n\n // Hoist relation definitions stashed by `@BelongsTo` / `@HasMany` /\n // etc. on this class's decorator-metadata bag onto the class's static\n // `relations` map. Field-decorator initializers are instance-level in\n // TC39 stage 3 — they never fire for class-level operations like\n // `Model.withCount(\"rel\")`. Reading via shared `context.metadata` is\n // the right hand-off point because all field decorators have already\n // run by the time the class decorator executes.\n const decoratorRelations = context.metadata?.[RELATION_METADATA_KEY] as\n | Record<string, RelationDefinition>\n | undefined;\n\n if (decoratorRelations && Object.keys(decoratorRelations).length > 0) {\n const ownRelations = Object.prototype.hasOwnProperty.call(value, \"relations\")\n ? (value as unknown as { relations: Record<string, RelationDefinition> }).relations\n : {\n ...((value as unknown as { relations?: Record<string, RelationDefinition> })\n .relations ?? {}),\n };\n\n (value as unknown as { relations: Record<string, RelationDefinition> }).relations = {\n ...ownRelations,\n ...decoratorRelations,\n };\n }\n\n modelsRegistry.set(modelName, value);\n\n return value;\n };\n}\n\nexport function registerModelInRegistry(name: string, model: ChildModel<Model>) {\n modelsRegistry.set(name, model);\n}\n\n/**\n * Get a model class by its name from the global registry.\n *\n * @param name - The model class name\n * @returns The model class or undefined if not found\n *\n * @example\n * ```typescript\n * const UserModel = getModelFromRegistry(\"User\");\n * if (UserModel) {\n * const user = await UserModel.find(1);\n * }\n * ```\n */\nexport function getModelFromRegistry(name: string) {\n return modelsRegistry.get(name);\n}\n\n/**\n * Get all registered models from the global registry.\n *\n * @returns A Map of all registered model classes by name\n *\n * @example\n * ```typescript\n * const allModels = getAllModelsFromRegistry();\n * for (const [name, ModelClass] of allModels) {\n * console.log(`Found model: ${name}`);\n * }\n * ```\n */\nexport function getAllModelsFromRegistry() {\n return new Map(modelsRegistry);\n}\n\n/**\n * Clean up all models from register\n */\nexport function cleanupModelsRegistery() {\n modelsRegistry.clear();\n}\n\nexport function removeModelFromRegistery(name: string) {\n modelsRegistry.delete(name);\n}\n\nexport function resolveModelClass(model: ModelRef): ChildModel<Model> {\n if (typeof model === \"string\") return getModelFromRegistry(model)!;\n if (isLazy(model)) return model.resolve() as ChildModel<Model>;\n\n return model;\n}\n\n/**\n * Like `resolveModelClass`, but throws a descriptive error when a string\n * ref isn't registered instead of returning `undefined`.\n */\nexport function requireModelClass(model: ModelRef): ChildModel<Model> {\n if (typeof model === \"string\") {\n const found = getModelFromRegistry(model);\n\n if (!found) {\n const registered = [...modelsRegistry.keys()].join(\", \") || \"none\";\n\n throw new Error(\n `Model \"${model}\" is not registered (did you forget @RegisterModel()?). Registered: ${registered}`,\n );\n }\n\n return found;\n }\n\n return resolveModelClass(model);\n}\n\n/**\n * Like `resolveModelClass`, but returns `undefined` instead of asserting\n * a non-null result when a string ref isn't in the registry. Use this\n * at call sites that already handle the missing-model case explicitly\n * (e.g. join builders that throw their own contextual error).\n */\nexport function tryResolveModelClass(model: ModelRef | undefined): ChildModel<Model> | undefined {\n if (model === undefined) return undefined;\n if (typeof model === \"string\") return getModelFromRegistry(model);\n if (isLazy(model)) return model.resolve() as ChildModel<Model>;\n\n return model;\n}\n\n/**\n * Read the model's registered name from any `ModelRef`. Used by\n * convention helpers (`inferPivotTable`, `inferPivotKey`) that derive\n * table / column names from the related model's class name.\n *\n * For string refs the value passes through. For class and lazy refs\n * the class's `.name` is returned — same string the registry would\n * key the class under, so conventions stay consistent across ref shapes.\n */\nexport function resolveModelName(model: ModelRef): string {\n if (typeof model === \"string\") return model;\n if (isLazy(model)) return (model.resolve() as ChildModel<Model>).name;\n\n return model.name;\n}\n\n/**\n * Walk every registered model and verify that every relation declared on it\n * points at another registered model. Throws fast at boot with a clear error\n * naming the unresolved target — much better signal than the runtime\n * \"Model not found\" thrown deep inside a query.\n *\n * Call this once during app bootstrap, after every `@RegisterModel`-decorated\n * model module has been imported.\n *\n * @returns The number of relations verified (success case)\n * @throws Error listing every unresolved relation target if any are missing\n *\n * @example\n * ```typescript\n * // Inside your app bootstrap, after model imports:\n * import { verifyRegisteredRelations } from \"@warlock.js/cascade\";\n * verifyRegisteredRelations();\n * ```\n */\nexport function verifyRegisteredRelations(): number {\n type RelationDef = { type: string; model: string };\n const failures: Array<{ caller: string; relation: string; target: string }> = [];\n\n let verifiedCount = 0;\n\n for (const [callerName, ModelClass] of modelsRegistry) {\n const relations = (ModelClass as { relations?: Record<string, RelationDef> }).relations;\n\n if (!relations) {\n continue;\n }\n\n for (const [relationName, definition] of Object.entries(relations)) {\n verifiedCount++;\n const targetName = definition.model;\n\n if (typeof targetName !== \"string\") {\n // Direct class reference or `lazy(() => X)` — class binding is\n // captured by the decorator at definition time; can't drift.\n continue;\n }\n\n if (!modelsRegistry.has(targetName)) {\n failures.push({ caller: callerName, relation: relationName, target: targetName });\n }\n }\n }\n\n if (failures.length > 0) {\n const list = failures\n .map((f) => ` - ${f.caller}.${f.relation} → \"${f.target}\" is not registered`)\n .join(\"\\n\");\n throw new Error(\n `verifyRegisteredRelations: ${failures.length} unresolved relation target(s):\\n${list}\\n` +\n `Each target must be decorated with @RegisterModel() and imported before bootstrap.`,\n );\n }\n\n return verifiedCount;\n}\n"],"mappings":";;;;;;;;AAwCA,MAAM,iCAAiB,IAAI,IAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+B1D,SAAgB,cAAc,SAAgC;CAC5D,OAAO,SAAuC,OAAU,SAAsC;EAC5F,IAAI,QAAQ,SAAS,SACnB,MAAM,IAAI,MAAM,wDAAwD,QAAQ,KAAK,GAAG;EAG1F,MAAM,YAAY,SAAS,SAAS,QAAQ,QAAQ,MAAM;EAE1D,IAAI,CAAC,WACH,MAAM,IAAI,MACR,6HAEF;EAGF,IAAI,eAAe,IAAI,SAAS,GAC9B,QAAQ,KACN,cAAc,UAAU,wEAE1B;EAUF,MAAM,qBAAqB,QAAQ,WAAW;EAI9C,IAAI,sBAAsB,OAAO,KAAK,kBAAkB,CAAC,CAAC,SAAS,GAQjE,AAAC,MAAuE,YAAY;GAClF,GARmB,OAAO,UAAU,eAAe,K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AQ,CAAC,CAAuB;CAEjE,OAAO,MAAM;AACf;;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,4BAAoC;CAElD,MAAM,WAAwE,CAAC;CAE/E,IAAI,gBAAgB;CAEpB,KAAK,MAAM,CAAC,YAAY,eAAe,gBAAgB;EACrD,MAAM,YAAa,WAA2D;EAE9E,IAAI,CAAC,WACH;EAGF,KAAK,MAAM,CAAC,cAAc,eAAe,OAAO,QAAQ,SAAS,GAAG;GAClE;GACA,MAAM,aAAa,WAAW;GAE9B,IAAI,OAAO,eAAe,UAGxB;GAGF,IAAI,CAAC,eAAe,IAAI,UAAU,GAChC,SAAS,KAAK;IAAE,QAAQ;IAAY,UAAU;IAAc,QAAQ;GAAW,CAAC;EAEpF;CACF;CAEA,IAAI,SAAS,SAAS,GAAG;EACvB,MAAM,OAAO,SACV,KAAK,MAAM,OAAO,EAAE,OAAO,GAAG,EAAE,SAAS,MAAM,EAAE,OAAO,oBAAoB,CAAC,CAC7E,KAAK,IAAI;EACZ,MAAM,IAAI,MACR,8BAA8B,SAAS,OAAO,mCAAmC,KAAK,qFAExF;CACF;CAEA,OAAO;AACT"}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { ChildModel } from "./model.types.mjs";
|
|
2
1
|
import { BelongsToManyOptions, BelongsToOptions, HasManyOptions, HasOneOptions } from "../relations/types.mjs";
|
|
2
|
+
import { ChildModel } from "./model.types.mjs";
|
|
3
3
|
import { Model } from "./model.mjs";
|
|
4
4
|
import { Lazy } from "@mongez/reinforcements";
|
|
5
|
-
|
|
6
5
|
//#region ../../packages/cascade/src/model/relation-decorators.d.ts
|
|
7
6
|
/**
|
|
8
7
|
* Key used to stash relation definitions on the decorator metadata object.
|
|
9
8
|
* Exported so `@RegisterModel` (in `register-model.ts`) can read it back.
|
|
10
9
|
*/
|
|
11
|
-
declare const RELATION_METADATA_KEY: unique symbol;
|
|
10
|
+
export declare const RELATION_METADATA_KEY: unique symbol;
|
|
12
11
|
/**
|
|
13
12
|
* Declares a `belongsTo` relation on a model field.
|
|
14
13
|
*
|
|
@@ -34,7 +33,7 @@ declare const RELATION_METADATA_KEY: unique symbol;
|
|
|
34
33
|
* }
|
|
35
34
|
* ```
|
|
36
35
|
*/
|
|
37
|
-
declare const BelongsTo: (modelRelation: string | ChildModel<Model> | Lazy<unknown>, options?: string | BelongsToOptions | undefined) => <This>(_value: undefined, context: ClassFieldDecoratorContext<This>) => void;
|
|
36
|
+
export declare const BelongsTo: (modelRelation: string | ChildModel<Model> | Lazy<unknown>, options?: string | BelongsToOptions | undefined) => <This>(_value: undefined, context: ClassFieldDecoratorContext<This, unknown>) => void;
|
|
38
37
|
/**
|
|
39
38
|
* Declares a `hasOne` relation on a model field.
|
|
40
39
|
*
|
|
@@ -50,7 +49,7 @@ declare const BelongsTo: (modelRelation: string | ChildModel<Model> | Lazy<unkno
|
|
|
50
49
|
* }
|
|
51
50
|
* ```
|
|
52
51
|
*/
|
|
53
|
-
declare const HasOne: (modelRelation: string | ChildModel<Model> | Lazy<unknown>, options?: string | HasOneOptions | undefined) => <This>(_value: undefined, context: ClassFieldDecoratorContext<This>) => void;
|
|
52
|
+
export declare const HasOne: (modelRelation: string | ChildModel<Model> | Lazy<unknown>, options?: string | HasOneOptions | undefined) => <This>(_value: undefined, context: ClassFieldDecoratorContext<This, unknown>) => void;
|
|
54
53
|
/**
|
|
55
54
|
* Declares a `hasMany` relation on a model field.
|
|
56
55
|
*
|
|
@@ -66,7 +65,7 @@ declare const HasOne: (modelRelation: string | ChildModel<Model> | Lazy<unknown>
|
|
|
66
65
|
* }
|
|
67
66
|
* ```
|
|
68
67
|
*/
|
|
69
|
-
declare const HasMany: (modelRelation: string | ChildModel<Model> | Lazy<unknown>, options?: string | HasManyOptions | undefined) => <This>(_value: undefined, context: ClassFieldDecoratorContext<This>) => void;
|
|
68
|
+
export declare const HasMany: (modelRelation: string | ChildModel<Model> | Lazy<unknown>, options?: string | HasManyOptions | undefined) => <This>(_value: undefined, context: ClassFieldDecoratorContext<This, unknown>) => void;
|
|
70
69
|
/**
|
|
71
70
|
* Declares a `belongsToMany` relation on a model field.
|
|
72
71
|
*
|
|
@@ -82,7 +81,6 @@ declare const HasMany: (modelRelation: string | ChildModel<Model> | Lazy<unknown
|
|
|
82
81
|
* }
|
|
83
82
|
* ```
|
|
84
83
|
*/
|
|
85
|
-
declare const BelongsToMany: (modelRelation: string | ChildModel<Model> | Lazy<unknown>, options?: string | BelongsToManyOptions | undefined) => <This>(_value: undefined, context: ClassFieldDecoratorContext<This>) => void;
|
|
84
|
+
export declare const BelongsToMany: (modelRelation: string | ChildModel<Model> | Lazy<unknown>, options?: string | BelongsToManyOptions | undefined) => <This>(_value: undefined, context: ClassFieldDecoratorContext<This, unknown>) => void;
|
|
86
85
|
//#endregion
|
|
87
|
-
export { BelongsTo, BelongsToMany, HasMany, HasOne, RELATION_METADATA_KEY };
|
|
88
86
|
//# sourceMappingURL=relation-decorators.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relation-decorators.d.mts","names":[],"sources":["../../../../../../../../packages/cascade/src/model/relation-decorators.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"relation-decorators.d.mts","names":[],"sources":["../../../../../../../../packages/cascade/src/model/relation-decorators.ts"],"mappings":";;;;;;;;;qBA2Ha;;;;;;;;;;;;;;;;;;;;;;;;;;qBAsFA,YAAS,wBAzEM,WAAW,SAAS,eAAa,mBAAA,kCAGxC,MAAI,mBAAmB,SAAA,2BAAA;;;;;;;;;;;;;;;;qBAuF/B,SAAM,wBA1FS,WAAW,SAAS,eAAa,mBAAA,+BAGxC,MAAI,mBAAmB,SAAA,2BAAA;;;;;;;;;;;;;;;;qBAwG/B,UAAO,wBA3GQ,WAAW,SAAS,eAAa,mBAAA,gCAGxC,MAAI,mBAAmB,SAAA,2BAAA;;;;;;;;;;;;;;;;qBAyH/B,gBAAa,wBA5HE,WAAW,SAAS,eAAa,mBAAA,sCAGxC,MAAI,mBAAmB,SAAA,2BAAA"}
|
|
@@ -5,20 +5,25 @@
|
|
|
5
5
|
* beyond "look up by registry name".
|
|
6
6
|
*/
|
|
7
7
|
type DataSourceSelector = {
|
|
8
|
-
/** Data source name from the registry. Omit to use the default source. */
|
|
8
|
+
/** Data source name from the registry. Omit to use the default source. */
|
|
9
|
+
readonly connection?: string;
|
|
9
10
|
};
|
|
10
11
|
/**
|
|
11
12
|
* Result of {@link createDatabase}.
|
|
12
13
|
*/
|
|
13
|
-
type CreateDatabaseResult = {
|
|
14
|
-
/** True if a new database was created; false if it already existed. */
|
|
14
|
+
export type CreateDatabaseResult = {
|
|
15
|
+
/** True if a new database was created; false if it already existed. */
|
|
16
|
+
readonly created: boolean;
|
|
17
|
+
/** The database name that was passed to the operation. */
|
|
15
18
|
readonly name: string;
|
|
16
19
|
};
|
|
17
20
|
/**
|
|
18
21
|
* Result of {@link dropAllTables}.
|
|
19
22
|
*/
|
|
20
|
-
type DropAllTablesResult = {
|
|
21
|
-
/** Names of tables that were dropped, in the order returned by the driver. */
|
|
23
|
+
export type DropAllTablesResult = {
|
|
24
|
+
/** Names of tables that were dropped, in the order returned by the driver. */
|
|
25
|
+
readonly tables: string[];
|
|
26
|
+
/** Count of dropped tables (equal to `tables.length`). */
|
|
22
27
|
readonly dropped: number;
|
|
23
28
|
};
|
|
24
29
|
/**
|
|
@@ -30,7 +35,7 @@ type DropAllTablesResult = {
|
|
|
30
35
|
* await createDatabase("analytics");
|
|
31
36
|
* await createDatabase("analytics", { connection: "warehouse" });
|
|
32
37
|
*/
|
|
33
|
-
declare function createDatabase(name: string, options?: DataSourceSelector): Promise<CreateDatabaseResult>;
|
|
38
|
+
export declare function createDatabase(name: string, options?: DataSourceSelector): Promise<CreateDatabaseResult>;
|
|
34
39
|
/**
|
|
35
40
|
* Drop every table on the configured data source. Lists tables first so the
|
|
36
41
|
* caller receives the names that were affected — useful for printing,
|
|
@@ -40,7 +45,7 @@ declare function createDatabase(name: string, options?: DataSourceSelector): Pro
|
|
|
40
45
|
* const { tables, dropped } = await dropAllTables();
|
|
41
46
|
* console.log(`Dropped ${dropped} tables: ${tables.join(", ")}`);
|
|
42
47
|
*/
|
|
43
|
-
declare function dropAllTables(options?: DataSourceSelector): Promise<DropAllTablesResult>;
|
|
48
|
+
export declare function dropAllTables(options?: DataSourceSelector): Promise<DropAllTablesResult>;
|
|
44
49
|
//#endregion
|
|
45
|
-
export {
|
|
50
|
+
export {};
|
|
46
51
|
//# sourceMappingURL=database.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.d.mts","names":[],"sources":["../../../../../../../../packages/cascade/src/operations/database.ts"],"mappings":";;;;;;KAOK
|
|
1
|
+
{"version":3,"file":"database.d.mts","names":[],"sources":["../../../../../../../../packages/cascade/src/operations/database.ts"],"mappings":";;;;;;KAOK;;WAEM;;;;;YAMC;;WAED;;WAEA;;;;;YAMC;;WAED;;WAEA;;;;;;;;;;;wBAYW,eACpB,cACA,UAAS,qBACR,QAAQ;;;;;;;;;;wBAgBW,cACpB,UAAS,qBACR,QAAQ"}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { CreateDatabaseResult, DropAllTablesResult, createDatabase, dropAllTables } from "./database.mjs";
|
|
2
|
-
import { ExportMigrationsSQLOptions, PendingMigration, RollbackMigrationsOptions, exportMigrationsSQL, freshMigrate, listExecutedMigrations, listPendingMigrations, rollbackMigrations, runMigrations } from "./migrations.mjs";
|
|
2
|
+
import { ExportMigrationsSQLOptions, PendingMigration, RollbackMigrationsOptions, exportMigrationsSQL, freshMigrate, listExecutedMigrations, listPendingMigrations, rollbackMigrations, runMigrations } from "./migrations.mjs";
|
|
3
|
+
export { CreateDatabaseResult, DropAllTablesResult, ExportMigrationsSQLOptions, PendingMigration, RollbackMigrationsOptions, createDatabase, dropAllTables, exportMigrationsSQL, freshMigrate, listExecutedMigrations, listPendingMigrations, rollbackMigrations, runMigrations };
|
package/esm/operations/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { createDatabase, dropAllTables } from "./database.mjs";
|
|
2
2
|
import { exportMigrationsSQL, freshMigrate, listExecutedMigrations, listPendingMigrations, rollbackMigrations, runMigrations } from "./migrations.mjs";
|
|
3
3
|
|
|
4
|
-
export {
|
|
4
|
+
export { createDatabase, dropAllTables, exportMigrationsSQL, freshMigrate, listExecutedMigrations, listPendingMigrations, rollbackMigrations, runMigrations };
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import { MigrationRecord, MigrationResult } from "../migration/types.mjs";
|
|
2
|
-
|
|
3
2
|
//#region ../../packages/cascade/src/operations/migrations.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* Options for exporting migrations as SQL files.
|
|
6
5
|
*/
|
|
7
|
-
type ExportMigrationsSQLOptions = {
|
|
8
|
-
/** Export only pending migrations. Default: false (exports all registered). */
|
|
6
|
+
export type ExportMigrationsSQLOptions = {
|
|
7
|
+
/** Export only pending migrations. Default: false (exports all registered). */
|
|
8
|
+
readonly pendingOnly?: boolean;
|
|
9
|
+
/** Strip generated block comments and blank lines from the output. */
|
|
9
10
|
readonly compact?: boolean;
|
|
10
11
|
};
|
|
11
12
|
/**
|
|
12
13
|
* Options for rolling back migrations.
|
|
13
14
|
*/
|
|
14
|
-
type RollbackMigrationsOptions = {
|
|
15
|
-
/** Roll back every executed migration. Overrides `batches` when true. */
|
|
15
|
+
export type RollbackMigrationsOptions = {
|
|
16
|
+
/** Roll back every executed migration. Overrides `batches` when true. */
|
|
17
|
+
readonly all?: boolean;
|
|
18
|
+
/** Number of batches to roll back when `all` is not set. Default: 1. */
|
|
16
19
|
readonly batches?: number;
|
|
17
20
|
};
|
|
18
21
|
/**
|
|
@@ -26,7 +29,7 @@ type RollbackMigrationsOptions = {
|
|
|
26
29
|
* migrationRunner.registerMany([CreateUsersTable, AddEmailIndex]);
|
|
27
30
|
* const results = await runMigrations();
|
|
28
31
|
*/
|
|
29
|
-
declare function runMigrations(): Promise<MigrationResult[]>;
|
|
32
|
+
export declare function runMigrations(): Promise<MigrationResult[]>;
|
|
30
33
|
/**
|
|
31
34
|
* Roll back executed migrations. By default rolls back the most recent batch;
|
|
32
35
|
* pass `all: true` to undo every executed migration, or `batches: N` to undo
|
|
@@ -37,7 +40,7 @@ declare function runMigrations(): Promise<MigrationResult[]>;
|
|
|
37
40
|
* await rollbackMigrations({ batches: 3 }); // last three batches
|
|
38
41
|
* await rollbackMigrations({ all: true }); // everything
|
|
39
42
|
*/
|
|
40
|
-
declare function rollbackMigrations(options?: RollbackMigrationsOptions): Promise<MigrationResult[]>;
|
|
43
|
+
export declare function rollbackMigrations(options?: RollbackMigrationsOptions): Promise<MigrationResult[]>;
|
|
41
44
|
/**
|
|
42
45
|
* Roll back every executed migration, then run every registered migration.
|
|
43
46
|
* Equivalent to `rollbackMigrations({ all: true })` followed by
|
|
@@ -46,7 +49,7 @@ declare function rollbackMigrations(options?: RollbackMigrationsOptions): Promis
|
|
|
46
49
|
* @example
|
|
47
50
|
* await freshMigrate();
|
|
48
51
|
*/
|
|
49
|
-
declare function freshMigrate(): Promise<MigrationResult[]>;
|
|
52
|
+
export declare function freshMigrate(): Promise<MigrationResult[]>;
|
|
50
53
|
/**
|
|
51
54
|
* Export registered migrations as phase-ordered `.up.sql` and `.down.sql`
|
|
52
55
|
* files under `<cwd>/database/sql/`.
|
|
@@ -55,7 +58,7 @@ declare function freshMigrate(): Promise<MigrationResult[]>;
|
|
|
55
58
|
* await exportMigrationsSQL();
|
|
56
59
|
* await exportMigrationsSQL({ pendingOnly: true, compact: true });
|
|
57
60
|
*/
|
|
58
|
-
declare function exportMigrationsSQL(options?: ExportMigrationsSQLOptions): Promise<void>;
|
|
61
|
+
export declare function exportMigrationsSQL(options?: ExportMigrationsSQLOptions): Promise<void>;
|
|
59
62
|
/**
|
|
60
63
|
* Return the migration records persisted in the migrations table — one entry
|
|
61
64
|
* per migration that has ever been executed against the configured data
|
|
@@ -65,13 +68,15 @@ declare function exportMigrationsSQL(options?: ExportMigrationsSQLOptions): Prom
|
|
|
65
68
|
* const executed = await listExecutedMigrations();
|
|
66
69
|
* console.log(executed.map((record) => record.name));
|
|
67
70
|
*/
|
|
68
|
-
declare function listExecutedMigrations(): Promise<MigrationRecord[]>;
|
|
71
|
+
export declare function listExecutedMigrations(): Promise<MigrationRecord[]>;
|
|
69
72
|
/**
|
|
70
73
|
* A registered migration that has not yet been executed against the configured
|
|
71
74
|
* data source.
|
|
72
75
|
*/
|
|
73
|
-
type PendingMigration = {
|
|
74
|
-
/** Migration name/identifier, as it will be recorded once executed. */
|
|
76
|
+
export type PendingMigration = {
|
|
77
|
+
/** Migration name/identifier, as it will be recorded once executed. */
|
|
78
|
+
readonly name: string;
|
|
79
|
+
/** Creation timestamp, when the migration carries one. */
|
|
75
80
|
readonly createdAt?: string;
|
|
76
81
|
};
|
|
77
82
|
/**
|
|
@@ -89,7 +94,6 @@ type PendingMigration = {
|
|
|
89
94
|
* const pending = await listPendingMigrations();
|
|
90
95
|
* console.log(pending.map((migration) => migration.name));
|
|
91
96
|
*/
|
|
92
|
-
declare function listPendingMigrations(): Promise<PendingMigration[]>;
|
|
97
|
+
export declare function listPendingMigrations(): Promise<PendingMigration[]>;
|
|
93
98
|
//#endregion
|
|
94
|
-
export { ExportMigrationsSQLOptions, PendingMigration, RollbackMigrationsOptions, exportMigrationsSQL, freshMigrate, listExecutedMigrations, listPendingMigrations, rollbackMigrations, runMigrations };
|
|
95
99
|
//# sourceMappingURL=migrations.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrations.d.mts","names":[],"sources":["../../../../../../../../packages/cascade/src/operations/migrations.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"migrations.d.mts","names":[],"sources":["../../../../../../../../packages/cascade/src/operations/migrations.ts"],"mappings":";;;;;YAMY;;WAED;;WAEA;;;;;YAMC;;WAED;;WAEA;;;;;;;;;;;;;wBAcW,iBAAiB,QAAQ;;;;;;;;;;;wBAczB,mBACpB,UAAS,4BACR,QAAQ;;;;;;;;;wBAkBW,gBAAgB,QAAQ;;;;;;;;;wBAYxB,oBAAoB,UAAS,6BAAkC;;;;;;;;;;wBAa/D,0BAA0B,QAAQ;;;;;YAQ5C;;WAED;;WAEA;;;;;;;;;;;;;;;;;wBAkBW,yBAAyB,QAAQ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrations.mjs","names":[],"sources":["../../../../../../../../packages/cascade/src/operations/migrations.ts"],"sourcesContent":["import { migrationRunner } from \"../migration/migration-runner\";\nimport type { MigrationRecord, MigrationResult } from \"../migration/types\";\n\n/**\n * Options for exporting migrations as SQL files.\n */\nexport type ExportMigrationsSQLOptions = {\n /** Export only pending migrations. Default: false (exports all registered). */\n readonly pendingOnly?: boolean;\n /** Strip generated block comments and blank lines from the output. */\n readonly compact?: boolean;\n};\n\n/**\n * Options for rolling back migrations.\n */\nexport type RollbackMigrationsOptions = {\n /** Roll back every executed migration. Overrides `batches` when true. */\n readonly all?: boolean;\n /** Number of batches to roll back when `all` is not set. Default: 1. */\n readonly batches?: number;\n};\n\n/**\n * Run every pending migration registered on the migration runner.\n *\n * Caller is responsible for registering migration classes first via\n * `migrationRunner.register()` / `migrationRunner.registerMany()`. Returns one\n * result entry per executed migration.\n *\n * @example\n * migrationRunner.registerMany([CreateUsersTable, AddEmailIndex]);\n * const results = await runMigrations();\n */\nexport async function runMigrations(): Promise<MigrationResult[]> {\n return migrationRunner.runAll();\n}\n\n/**\n * Roll back executed migrations. By default rolls back the most recent batch;\n * pass `all: true` to undo every executed migration, or `batches: N` to undo\n * the last N batches.\n *\n * @example\n * await rollbackMigrations(); // last batch\n * await rollbackMigrations({ batches: 3 }); // last three batches\n * await rollbackMigrations({ all: true }); // everything\n */\nexport async function rollbackMigrations(\n options: RollbackMigrationsOptions = {},\n): Promise<MigrationResult[]> {\n if (options.all) {\n return migrationRunner.rollbackAll();\n }\n\n const batches = options.batches ?? 1;\n\n return migrationRunner.rollbackBatches(batches);\n}\n\n/**\n * Roll back every executed migration, then run every registered migration.\n * Equivalent to `rollbackMigrations({ all: true })` followed by\n * `runMigrations()`.\n *\n * @example\n * await freshMigrate();\n */\nexport async function freshMigrate(): Promise<MigrationResult[]> {\n return migrationRunner.fresh();\n}\n\n/**\n * Export registered migrations as phase-ordered `.up.sql` and `.down.sql`\n * files under `<cwd>/database/sql/`.\n *\n * @example\n * await exportMigrationsSQL();\n * await exportMigrationsSQL({ pendingOnly: true, compact: true });\n */\nexport async function exportMigrationsSQL(
|
|
1
|
+
{"version":3,"file":"migrations.mjs","names":[],"sources":["../../../../../../../../packages/cascade/src/operations/migrations.ts"],"sourcesContent":["import { migrationRunner } from \"../migration/migration-runner\";\nimport type { MigrationRecord, MigrationResult } from \"../migration/types\";\n\n/**\n * Options for exporting migrations as SQL files.\n */\nexport type ExportMigrationsSQLOptions = {\n /** Export only pending migrations. Default: false (exports all registered). */\n readonly pendingOnly?: boolean;\n /** Strip generated block comments and blank lines from the output. */\n readonly compact?: boolean;\n};\n\n/**\n * Options for rolling back migrations.\n */\nexport type RollbackMigrationsOptions = {\n /** Roll back every executed migration. Overrides `batches` when true. */\n readonly all?: boolean;\n /** Number of batches to roll back when `all` is not set. Default: 1. */\n readonly batches?: number;\n};\n\n/**\n * Run every pending migration registered on the migration runner.\n *\n * Caller is responsible for registering migration classes first via\n * `migrationRunner.register()` / `migrationRunner.registerMany()`. Returns one\n * result entry per executed migration.\n *\n * @example\n * migrationRunner.registerMany([CreateUsersTable, AddEmailIndex]);\n * const results = await runMigrations();\n */\nexport async function runMigrations(): Promise<MigrationResult[]> {\n return migrationRunner.runAll();\n}\n\n/**\n * Roll back executed migrations. By default rolls back the most recent batch;\n * pass `all: true` to undo every executed migration, or `batches: N` to undo\n * the last N batches.\n *\n * @example\n * await rollbackMigrations(); // last batch\n * await rollbackMigrations({ batches: 3 }); // last three batches\n * await rollbackMigrations({ all: true }); // everything\n */\nexport async function rollbackMigrations(\n options: RollbackMigrationsOptions = {},\n): Promise<MigrationResult[]> {\n if (options.all) {\n return migrationRunner.rollbackAll();\n }\n\n const batches = options.batches ?? 1;\n\n return migrationRunner.rollbackBatches(batches);\n}\n\n/**\n * Roll back every executed migration, then run every registered migration.\n * Equivalent to `rollbackMigrations({ all: true })` followed by\n * `runMigrations()`.\n *\n * @example\n * await freshMigrate();\n */\nexport async function freshMigrate(): Promise<MigrationResult[]> {\n return migrationRunner.fresh();\n}\n\n/**\n * Export registered migrations as phase-ordered `.up.sql` and `.down.sql`\n * files under `<cwd>/database/sql/`.\n *\n * @example\n * await exportMigrationsSQL();\n * await exportMigrationsSQL({ pendingOnly: true, compact: true });\n */\nexport async function exportMigrationsSQL(options: ExportMigrationsSQLOptions = {}): Promise<void> {\n return migrationRunner.exportSQL(options);\n}\n\n/**\n * Return the migration records persisted in the migrations table — one entry\n * per migration that has ever been executed against the configured data\n * source.\n *\n * @example\n * const executed = await listExecutedMigrations();\n * console.log(executed.map((record) => record.name));\n */\nexport async function listExecutedMigrations(): Promise<MigrationRecord[]> {\n return migrationRunner.getExecutedMigrations();\n}\n\n/**\n * A registered migration that has not yet been executed against the configured\n * data source.\n */\nexport type PendingMigration = {\n /** Migration name/identifier, as it will be recorded once executed. */\n readonly name: string;\n /** Creation timestamp, when the migration carries one. */\n readonly createdAt?: string;\n};\n\n/**\n * Return the registered migrations that have NOT been executed, **in the order\n * they will execute**. The order is the point: it makes the result a dry run\n * rather than a set.\n *\n * ⚠️ Only registered migrations can be pending. Register them first — via\n * `migrationRunner.register()` / `registerMany()`, or whatever the host\n * framework's loader does — or this returns `[]`, which reads as \"nothing\n * pending\" and is not the same thing.\n *\n * @example\n * migrationRunner.registerMany([CreateUsersTable, AddEmailIndex]);\n * const pending = await listPendingMigrations();\n * console.log(pending.map((migration) => migration.name));\n */\nexport async function listPendingMigrations(): Promise<PendingMigration[]> {\n const pending = await migrationRunner.getPendingMigrations();\n\n return pending.map((MigrationClass) => ({\n name: MigrationClass.migrationName,\n createdAt: MigrationClass.createdAt,\n }));\n}\n"],"mappings":";;;;;;;;;;;;;;AAkCA,eAAsB,gBAA4C;CAChE,OAAO,gBAAgB,OAAO;AAChC;;;;;;;;;;;AAYA,eAAsB,mBACpB,UAAqC,CAAC,GACV;CAC5B,IAAI,QAAQ,KACV,OAAO,gBAAgB,YAAY;CAGrC,MAAM,UAAU,QAAQ,WAAW;CAEnC,OAAO,gBAAgB,gBAAgB,OAAO;AAChD;;;;;;;;;AAUA,eAAsB,eAA2C;CAC/D,OAAO,gBAAgB,MAAM;AAC/B;;;;;;;;;AAUA,eAAsB,oBAAoB,UAAsC,CAAC,GAAkB;CACjG,OAAO,gBAAgB,UAAU,OAAO;AAC1C;;;;;;;;;;AAWA,eAAsB,yBAAqD;CACzE,OAAO,gBAAgB,sBAAsB;AAC/C;;;;;;;;;;;;;;;;AA4BA,eAAsB,wBAAqD;CAGzE,QAAO,MAFe,gBAAgB,qBAAqB,EAE7C,CAAC,KAAK,oBAAoB;EACtC,MAAM,eAAe;EACrB,WAAW,eAAe;CAC5B,EAAE;AACJ"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { GroupByInput, HavingInput, JoinOptions, LeanDocument, LockForUpdateOptions, OrderDirection, RawExpression, WhereCallback, WhereObject, WhereOperator } from "../contracts/query-builder.contract.mjs";
|
|
2
|
-
|
|
3
2
|
//#region ../../packages/cascade/src/query-builder/query-builder.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* A single recorded query operation.
|
|
6
5
|
* `type` is the discriminator; `data` carries all parameters.
|
|
7
6
|
*/
|
|
8
|
-
type Op = {
|
|
7
|
+
export type Op = {
|
|
9
8
|
readonly type: string;
|
|
10
9
|
readonly data: Record<string, unknown>;
|
|
11
10
|
};
|
|
@@ -32,7 +31,7 @@ type Op = {
|
|
|
32
31
|
* // The sub-QB's operations[] are captured and stored in the joinWith op data.
|
|
33
32
|
* ```
|
|
34
33
|
*/
|
|
35
|
-
declare class QueryBuilder<T = unknown> {
|
|
34
|
+
export declare class QueryBuilder<T = unknown> {
|
|
36
35
|
/** Flat, ordered list of recorded operations. Public for parser access. */
|
|
37
36
|
operations: Op[];
|
|
38
37
|
/**
|
|
@@ -619,5 +618,4 @@ declare class QueryBuilder<T = unknown> {
|
|
|
619
618
|
when<V>(condition: V | boolean, callback: (builder: this, value: V) => void, otherwise?: (builder: this) => void): this;
|
|
620
619
|
}
|
|
621
620
|
//#endregion
|
|
622
|
-
export { Op, QueryBuilder };
|
|
623
621
|
//# sourceMappingURL=query-builder.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-builder.d.mts","names":[],"sources":["../../../../../../../../packages/cascade/src/query-builder/query-builder.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"query-builder.d.mts","names":[],"sources":["../../../../../../../../packages/cascade/src/query-builder/query-builder.ts"],"mappings":";;;;;;YAmDY;WACD;WACA,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;qBA0CJ,aAAa;;EAMjB,YAAY;;;;;;;;;;YAWT,SAAS;;EAOZ,sBAAsB;;EAEtB,uBAAuB,gBAAgB;;EAEvC,sBAAsB;;EAEtB;;EAOA,oBAAoB,wBAAwB;;EAE5C,gBAAgB;IAAc;IAAkB,gBAAgB;;;EAEhE,sBAAsB;;EAEtB;;EAOA;;;;;YAUG,aAAa,cAAc,MAAM;;;;;;;;EAkBpC,UAAU,kBAAkB;;;;;;;EA8B5B;;;;;;;;;;;;;;YA+BG,YAAY;;;;;;;EAUf;;;;;;;;;;EAyBA,QAAQ,aAAa,aAAa;;EAUlC,sBAAsB;;EAMtB;;;;;EASA,MAAM,sBAAsB;;;;;;;;;;EAuB5B,MAAM,eAAe;EACrB,MAAM,eAAe,UAAU,eAAe;EAC9C,MAAM,YAAY;EAClB,MAAM,UAAU,cAAc;;;;;EAqC9B,aAAa,YAAY;;;;;;;EAczB,QAAQ,eAAe;EACvB,QAAQ,eAAe,UAAU,eAAe;EAChD,QAAQ,YAAY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YAAY;;EAK/C,WAAW,cAAc;;EASzB,cAAc,eAAe,YAAY,eAAe;;EAKxD,aAAa;;EAKb,aAAa,QAAQ,eAAe,gBAAgB;;EAOpD,eAAe,QAAQ,eAAe,gBAAgB;;EAOtD,aAAa,MAAM;;EAMnB,SAAS;;;;;EAST;;EASA;;EAKA;;EAKA,UAAU;;;;;EASV,eAAe;;;;;;;;EAiBf,QAAQ,eAAe,YAAY;EACnC,QAAQ,QAAQ,eAAe;;EAgB/B,YAAY;;;;;;EASZ,WAAW,YAAY,eAAe;;;;;EAStC,cAAc;;EAOd,OAAO;;YAKJ;;;;;YAQA,YAAY;;YAKZ,aAAa;;EAYhB,MAAM;;EAMN,KAAK;;EAML,OAAO;;EAKP,KAAK;;;;;;;;;;;EAkBL,cAAc,UAAU;;;;;;EAsBxB,QAAQ,OAAO;;EAOf,WAAW,YAAY,eAAe;;;;;;;;;EAatC,OAAO,eAAe;EACtB,OAAO,eAAe,UAAU,eAAe;EAC/C,OAAO,WAAW;;EAwBlB,UAAU,YAAY,eAAe;;;;;EAarC,IAAI,WAAW;;;;;;;;EAYf,KAAK,GACV,WAAW,aACX,WAAW,eAAe,OAAO,YACjC,aAAa"}
|
|
@@ -1209,17 +1209,18 @@ var QueryBuilder = class QueryBuilder {
|
|
|
1209
1209
|
having(...args) {
|
|
1210
1210
|
if (args.length === 1) {
|
|
1211
1211
|
const input = args[0];
|
|
1212
|
-
if (Array.isArray(input))
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1212
|
+
if (Array.isArray(input)) {
|
|
1213
|
+
if (input.length === 2) this.addOperation("having", {
|
|
1214
|
+
field: input[0],
|
|
1215
|
+
operator: "=",
|
|
1216
|
+
value: input[1]
|
|
1217
|
+
});
|
|
1218
|
+
else this.addOperation("having", {
|
|
1219
|
+
field: input[0],
|
|
1220
|
+
operator: input[1],
|
|
1221
|
+
value: input[2]
|
|
1222
|
+
});
|
|
1223
|
+
} else for (const [key, value] of Object.entries(input)) this.addOperation("having", {
|
|
1223
1224
|
field: key,
|
|
1224
1225
|
operator: "=",
|
|
1225
1226
|
value
|