uql-codemod 0.31.0 → 0.33.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 CHANGED
@@ -39,6 +39,7 @@ It reports rather than guesses, and exits non-zero when anything is left for you
39
39
  - **`target: esnext`** is reported, not changed. Removing the line falls back to the compiler default (`es5` for `tsc`), and choosing a replacement means guessing which era the project targets. Any dated target works; `esnext` is the one where TypeScript emits decorator syntax untransformed.
40
40
  - **A value inherited through `extends`** cannot be edited here, so the base config is reported instead.
41
41
  - **`@Log()`, `@Serialized()`, `@Transactional()` and `@InjectQuerier()`** are reported and left in place. They no longer exist, and what to do instead is a judgement call - a `@Transactional()` method becomes a `pool.transaction(async (querier) => { ... })` around its body, and the codemod cannot know which pool.
42
+ - **An export that no longer exists** (`setQuerierPool`, `getQuerier`, `QueryWhereMap`, `augmentWhere`, ...) is reported with what replaces it. A `$where` given an id, a list of them or a bare `raw()` needs no report: it is a compile error on that value, fixed by naming the key (`{ id: [1, 2] }`) or wrapping the raw in `$and`.
42
43
  - **A key written under a computed name** (`@Id() [KEY]?: string`) is reported: the brand has to spell the name out, and only you know what that expression evaluates to.
43
44
  - **Options it cannot read** (`@Field(sharedOptions)`, a spread, or a `@Field` never called at all) are left exactly as written. Replacing an argument it cannot parse would silently drop the options.
44
45
  - **A property whose type it cannot map to a column** (a `Json<T>`, a vector, a union that disagrees with itself) is reported as `needs a decision`. Those always had to declare `type` by hand anyway, because `design:type` reported the useless `Object`/`Array` for them.
package/dist/transform.js CHANGED
@@ -16,12 +16,26 @@ const REMOVED_DECORATORS = new Map([
16
16
  ]);
17
17
  /**
18
18
  * Exports that no longer exist, mapped to what to do instead. Reported rather than rewritten, for the
19
- * same reason as the decorators: which pool belongs at a given call site is a judgement call.
19
+ * same reason as the decorators: what replaces each is decided at its call site.
20
20
  */
21
21
  const REMOVED_EXPORTS = new Map([
22
22
  ['setQuerierPool', 'pass the pool where it is used: `createFetchHandler({ pool })`, `querierMiddleware({ pool })`'],
23
23
  ['getQuerierPool', 'take the pool from the module that builds it, or from Nest DI'],
24
24
  ['getQuerier', 'use `pool.withQuerier(...)` / `pool.transaction(...)`, which release the connection'],
25
+ ['QueryWhereMap', 'it is `QueryWhere` now'],
26
+ ['QueryWhereFieldMap', 'use `QueryWhere`'],
27
+ ['augmentWhere', 'spread the two maps: `{ ...where, ...extra }`'],
28
+ ['buildQueryWhereAsMap', 'a `$where` is a map already; name the key for ids: `{ id: [1, 2] }`'],
29
+ ['PgDialect', 'the pools build `PostgresDialect` (`uql-orm/postgres`); name that where a dialect is typed'],
30
+ ['NeonDialect', 'the pools build `PostgresDialect` (`uql-orm/postgres`); name that where a dialect is typed'],
31
+ ['PgliteDialect', 'the pools build `PostgresDialect` (`uql-orm/postgres`); name that where a dialect is typed'],
32
+ ['MySql2Dialect', 'the pool builds `MySqlDialect` (`uql-orm/mysql`)'],
33
+ ['MongodbNativeDialect', 'the pool builds `MongoDialect` (`uql-orm/mongo`)'],
34
+ ['AbstractPgQuerier', 'every pg-compatible pool returns `PgQuerier` (`uql-orm/postgres`), which is concrete'],
35
+ ['CrdbQuerier', 'every pg-compatible pool returns `PgQuerier` (`uql-orm/postgres`)'],
36
+ ['NeonQuerier', 'every pg-compatible pool returns `PgQuerier` (`uql-orm/postgres`)'],
37
+ ['LibsqlQuerier', 'the libSQL and Turso pools return `HranaQuerier` (`uql-orm/sqlite`)'],
38
+ ['TursoQuerier', 'the libSQL and Turso pools return `HranaQuerier` (`uql-orm/sqlite`)'],
25
39
  ]);
26
40
  /** A node's decorators, or none where it is a kind that cannot carry them. */
27
41
  function decoratorsOf(node) {
@@ -327,9 +341,9 @@ function reportRemovedDecorators(node, ctx) {
327
341
  }
328
342
  }
329
343
  }
330
- /** Names an export that no longer exists, where it is imported from the package. */
344
+ /** Names an export that no longer exists, where it is imported from the package or one of its entries. */
331
345
  function reportRemovedExports(source, ctx) {
332
- for (const element of uqlImports(source)) {
346
+ for (const element of uqlImports(source, true)) {
333
347
  const name = importedName(element);
334
348
  const advice = REMOVED_EXPORTS.get(name);
335
349
  if (advice) {
@@ -337,13 +351,18 @@ function reportRemovedExports(source, ctx) {
337
351
  }
338
352
  }
339
353
  }
340
- /** What the file imports from `uql-orm` by name, which is every import this codemod reads or writes. */
341
- function uqlImports(source) {
354
+ /**
355
+ * What the file imports from `uql-orm` by name, which is every import this codemod reads or writes.
356
+ * `entries` adds the driver entries (`uql-orm/postgres`, ...), for reporting only: an import written
357
+ * into one of those would land on an entry that may not export it.
358
+ */
359
+ function uqlImports(source, entries = false) {
342
360
  return source.statements.flatMap((statement) => {
343
361
  if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier)) {
344
362
  return [];
345
363
  }
346
- if (statement.moduleSpecifier.text !== 'uql-orm') {
364
+ const specifier = statement.moduleSpecifier.text;
365
+ if (specifier !== 'uql-orm' && !(entries && specifier.startsWith('uql-orm/'))) {
347
366
  return [];
348
367
  }
349
368
  const bindings = statement.importClause?.namedBindings;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "uql-codemod",
3
3
  "description": "Upgrade uql-orm across versions that introduce breaking changes",
4
4
  "license": "MIT",
5
- "version": "0.31.0",
5
+ "version": "0.33.0",
6
6
  "type": "module",
7
7
  "engines": {
8
8
  "node": ">=24"