uql-codemod 0.40.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/bin.js +0 -0
- package/dist/transform.js +18 -8
- 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/bin.js
CHANGED
|
File without changes
|
package/dist/transform.js
CHANGED
|
@@ -23,7 +23,10 @@ const REMOVED_DECORATORS = new Map([
|
|
|
23
23
|
* same reason as the decorators: what replaces each is decided at its call site.
|
|
24
24
|
*/
|
|
25
25
|
const REMOVED_EXPORTS = new Map([
|
|
26
|
-
[
|
|
26
|
+
[
|
|
27
|
+
'setQuerierPool',
|
|
28
|
+
'pass the pool where it is used: `createFetchHandler({ pool, include })`, `querierMiddleware({ pool, include })`',
|
|
29
|
+
],
|
|
27
30
|
['getQuerierPool', 'take the pool from the module that builds it, or from Nest DI'],
|
|
28
31
|
['getQuerier', 'use `pool.withQuerier(...)` / `pool.transaction(...)`, which release the connection'],
|
|
29
32
|
['QueryWhereFieldMap', 'use `QueryWhere`'],
|
|
@@ -58,8 +61,8 @@ const REMOVED_EXPORTS = new Map([
|
|
|
58
61
|
['createSchemaGenerator', 'use `new SqlSchemaGenerator(dialect)`, or `migrator.getSchemaGenerator()`'],
|
|
59
62
|
]);
|
|
60
63
|
/**
|
|
61
|
-
* Exports renamed and nothing else - the driver classes were empty subclasses - so the import and
|
|
62
|
-
* 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.
|
|
63
66
|
*/
|
|
64
67
|
const RENAMED_EXPORTS = new Map([
|
|
65
68
|
['QueryWhereMap', { to: 'QueryWhere' }],
|
|
@@ -83,6 +86,10 @@ const RENAMED_EXPORTS = new Map([
|
|
|
83
86
|
['KnownMigratorDialect', { to: 'DialectName', from: 'uql-orm' }],
|
|
84
87
|
['D1Preparer', { to: 'D1Queryable' }],
|
|
85
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' }],
|
|
86
93
|
]);
|
|
87
94
|
/** A node's decorators, or none where it is a kind that cannot carry them. */
|
|
88
95
|
function decoratorsOf(node) {
|
|
@@ -782,16 +789,16 @@ function reportRemovedExports(source, ctx) {
|
|
|
782
789
|
*/
|
|
783
790
|
function renameExports(source, dead, ctx) {
|
|
784
791
|
const imports = uqlImportDeclarations(source, true);
|
|
785
|
-
const kept = imports.flatMap(({ elements }) => elements
|
|
792
|
+
const kept = imports.flatMap(({ entry, elements }) => elements.filter((element) => !renamedTo(element, entry)));
|
|
786
793
|
const bound = new Set(kept.map((element) => element.name.text));
|
|
787
794
|
const rewritten = new Set();
|
|
788
795
|
for (const { declaration, entry, elements } of imports) {
|
|
789
|
-
if (!elements.some(renamedTo)) {
|
|
796
|
+
if (!elements.some((element) => renamedTo(element, entry))) {
|
|
790
797
|
continue;
|
|
791
798
|
}
|
|
792
799
|
const byEntry = new Map([[entry, []]]);
|
|
793
800
|
for (const element of elements.filter(({ name }) => !dead.has(name.text))) {
|
|
794
|
-
const rename = renamedTo(element);
|
|
801
|
+
const rename = renamedTo(element, entry);
|
|
795
802
|
const local = element.propertyName || !rename ? element.name.text : rename.to;
|
|
796
803
|
if (rename && !element.propertyName) {
|
|
797
804
|
ctx.edits.push(...usesOf(source, element.name, ctx.checker).map((use) => replaced(use, rename.to)));
|
|
@@ -817,8 +824,11 @@ function renameExports(source, dead, ctx) {
|
|
|
817
824
|
}
|
|
818
825
|
return rewritten;
|
|
819
826
|
}
|
|
820
|
-
|
|
821
|
-
|
|
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;
|
|
822
832
|
}
|
|
823
833
|
/** Every identifier in the file bound to the same symbol as `name`, besides `name` itself. */
|
|
824
834
|
function usesOf(source, name, checker) {
|