uql-codemod 0.41.0 → 0.42.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/transform.js +14 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -32,7 +32,7 @@ Only `--flag=value` is read, and anything unrecognised is an error. It exits `0`
|
|
|
32
32
|
- A partial-index `where` string to `raw`, importing it, on entities and in the migration builder.
|
|
33
33
|
- `col('cost')` to the ref it names, ``(product) => raw`${product.cost}` `` in a `computed` and `refs(Item).cost` in a statement, and `$lock: { wait: 'skip' }` to `{ $wait: 'skip' }`, or to `true` for `{}` and a `'block'` wait.
|
|
34
34
|
- An aggregate's `$agg` to `$select`, and each field it or `$text`'s `$fields` names to a key: `{ $sum: { amount: true } }`.
|
|
35
|
-
- Renamed exports, at the import and every use: `QueryWhereMap` to `QueryWhere`, `RelationKeyMap` to `KeyMap`, `FilterCondition` to `FilterWhere`, `SqlMigrationModuleOptions` to `MigrationModuleOptions`, `buildSqlQuerierMigrationModule` to `buildMigrationModule`, `QueryDialect` to `SqlQueryDialect`, `EngineFeatures` to `DialectFeatures`, `KnownMigratorDialect` to `DialectName`, `D1Preparer`/`D1Database` to `D1Queryable`, and the removed driver classes to the one each extended: `PgDialect`/`NeonDialect`/`PgliteDialect` to `PostgresDialect`, `CrdbQuerier`/`NeonQuerier` to `PgQuerier`, `LibsqlQuerier`/`TursoQuerier` to `HranaQuerier`, `TursoLocalQuerier` to `SqliteQuerier` and `TursoDatabase` to `SqliteDatabase`, `MySql2Dialect` to `MySqlDialect`, `MongodbNativeDialect` to `MongoDialect`, moving the import to the entry that exports it
|
|
35
|
+
- Renamed exports, at the import and every use: `QueryWhereMap` to `QueryWhere`, `RelationKeyMap` to `KeyMap`, `FilterCondition` to `FilterWhere`, `SqlMigrationModuleOptions` to `MigrationModuleOptions`, `buildSqlQuerierMigrationModule` to `buildMigrationModule`, `QueryDialect` to `SqlQueryDialect`, `EngineFeatures` to `DialectFeatures`, `KnownMigratorDialect` to `DialectName`, `D1Preparer`/`D1Database` to `D1Queryable`, and the removed driver classes to the one each extended: `PgDialect`/`NeonDialect`/`PgliteDialect` to `PostgresDialect`, `CrdbQuerier`/`NeonQuerier` to `PgQuerier`, `LibsqlQuerier`/`TursoQuerier` to `HranaQuerier`, `TursoLocalQuerier` to `SqliteQuerier` and `TursoDatabase` to `SqliteDatabase`, `MySql2Dialect` to `MySqlDialect`, `MongodbNativeDialect` to `MongoDialect`, moving the import to the entry that exports it; and `MongoQuerier`, `isMongoQuerier`, `MongoMigrationStorage` and `MongoSchemaIntrospector` to `uql-orm/mongo`.
|
|
36
36
|
- The `[idKey]?: '...'` brand, and its import, on a key not called `id`, `_id` or `uuid` and on every composite.
|
|
37
37
|
- `import 'reflect-metadata'`, and `experimentalDecorators`/`emitDecoratorMetadata` in `tsconfig.json`, comments and formatting kept.
|
|
38
38
|
|
package/dist/transform.js
CHANGED
|
@@ -61,8 +61,8 @@ const REMOVED_EXPORTS = new Map([
|
|
|
61
61
|
['createSchemaGenerator', 'use `new SqlSchemaGenerator(dialect)`, or `migrator.getSchemaGenerator()`'],
|
|
62
62
|
]);
|
|
63
63
|
/**
|
|
64
|
-
* Exports renamed and nothing else - the driver classes were empty subclasses - so the import and
|
|
65
|
-
* use follow, the import moving to `from` where the
|
|
64
|
+
* Exports renamed or moved and nothing else - the driver classes were empty subclasses - so the import and
|
|
65
|
+
* every use follow, the import moving to `from` where the name lives in another entry.
|
|
66
66
|
*/
|
|
67
67
|
const RENAMED_EXPORTS = new Map([
|
|
68
68
|
['QueryWhereMap', { to: 'QueryWhere' }],
|
|
@@ -86,6 +86,10 @@ const RENAMED_EXPORTS = new Map([
|
|
|
86
86
|
['KnownMigratorDialect', { to: 'DialectName', from: 'uql-orm' }],
|
|
87
87
|
['D1Preparer', { to: 'D1Queryable' }],
|
|
88
88
|
['D1Database', { to: 'D1Queryable', from: 'uql-orm/d1' }],
|
|
89
|
+
['MongoQuerier', { to: 'MongoQuerier', from: 'uql-orm/mongo' }],
|
|
90
|
+
['isMongoQuerier', { to: 'isMongoQuerier', from: 'uql-orm/mongo' }],
|
|
91
|
+
['MongoMigrationStorage', { to: 'MongoMigrationStorage', from: 'uql-orm/mongo' }],
|
|
92
|
+
['MongoSchemaIntrospector', { to: 'MongoSchemaIntrospector', from: 'uql-orm/mongo' }],
|
|
89
93
|
]);
|
|
90
94
|
/** A node's decorators, or none where it is a kind that cannot carry them. */
|
|
91
95
|
function decoratorsOf(node) {
|
|
@@ -785,16 +789,16 @@ function reportRemovedExports(source, ctx) {
|
|
|
785
789
|
*/
|
|
786
790
|
function renameExports(source, dead, ctx) {
|
|
787
791
|
const imports = uqlImportDeclarations(source, true);
|
|
788
|
-
const kept = imports.flatMap(({ elements }) => elements
|
|
792
|
+
const kept = imports.flatMap(({ entry, elements }) => elements.filter((element) => !renamedTo(element, entry)));
|
|
789
793
|
const bound = new Set(kept.map((element) => element.name.text));
|
|
790
794
|
const rewritten = new Set();
|
|
791
795
|
for (const { declaration, entry, elements } of imports) {
|
|
792
|
-
if (!elements.some(renamedTo)) {
|
|
796
|
+
if (!elements.some((element) => renamedTo(element, entry))) {
|
|
793
797
|
continue;
|
|
794
798
|
}
|
|
795
799
|
const byEntry = new Map([[entry, []]]);
|
|
796
800
|
for (const element of elements.filter(({ name }) => !dead.has(name.text))) {
|
|
797
|
-
const rename = renamedTo(element);
|
|
801
|
+
const rename = renamedTo(element, entry);
|
|
798
802
|
const local = element.propertyName || !rename ? element.name.text : rename.to;
|
|
799
803
|
if (rename && !element.propertyName) {
|
|
800
804
|
ctx.edits.push(...usesOf(source, element.name, ctx.checker).map((use) => replaced(use, rename.to)));
|
|
@@ -820,8 +824,11 @@ function renameExports(source, dead, ctx) {
|
|
|
820
824
|
}
|
|
821
825
|
return rewritten;
|
|
822
826
|
}
|
|
823
|
-
|
|
824
|
-
|
|
827
|
+
/** The rename `element` still needs, none where it already names the export at its entry. */
|
|
828
|
+
function renamedTo(element, entry) {
|
|
829
|
+
const name = importedName(element);
|
|
830
|
+
const rename = RENAMED_EXPORTS.get(name);
|
|
831
|
+
return rename?.to === name && (rename.from ?? entry) === entry ? undefined : rename;
|
|
825
832
|
}
|
|
826
833
|
/** Every identifier in the file bound to the same symbol as `name`, besides `name` itself. */
|
|
827
834
|
function usesOf(source, name, checker) {
|