uql-codemod 0.44.0 → 0.45.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.
Files changed (2) hide show
  1. package/dist/transform.js +26 -0
  2. package/package.json +1 -1
package/dist/transform.js CHANGED
@@ -489,6 +489,31 @@ function rewriteBuilderCall(call, ctx) {
489
489
  const options = call.arguments[at];
490
490
  rewriteIndexWhere(options && ts.isObjectLiteralExpression(options) ? options : undefined, ctx);
491
491
  }
492
+ const UPSERT_CALLS = new Set(['upsertOne', 'upsertMany', 'upsertInto']);
493
+ /**
494
+ * Rewrites an upsert's options holding `update` alone into that update, its fourth argument now. Read wherever it is
495
+ * called, since a querier is seldom imported from uql where it is used. Any other fourth argument is already an
496
+ * update, `{}` included, so a second run changes nothing.
497
+ */
498
+ function rewriteUpsertCall(call, ctx) {
499
+ const callee = call.expression;
500
+ const name = ts.isPropertyAccessExpression(callee) ? callee.name : callee;
501
+ const options = call.arguments[3];
502
+ const update = options && upsertUpdate(options);
503
+ if (ts.isIdentifier(name) && UPSERT_CALLS.has(name.text) && options && update) {
504
+ ctx.edits.push(replaced(options, update.getText()));
505
+ }
506
+ }
507
+ /** The value of options holding `update` alone, `{ update: value }` or `{ update }`. */
508
+ function upsertUpdate(options) {
509
+ const [property] = ts.isObjectLiteralExpression(options) && options.properties.length === 1 ? options.properties : [];
510
+ if (property && ts.isPropertyAssignment(property) && propertyKey(property.name) === 'update') {
511
+ return property.initializer;
512
+ }
513
+ return property && ts.isShorthandPropertyAssignment(property) && property.name.text === 'update'
514
+ ? property.name
515
+ : undefined;
516
+ }
492
517
  /**
493
518
  * `owner` is the declaring class's parameter and `target` the related one's, read off the `entity`
494
519
  * getter unless the caller knows it from the property's type.
@@ -1092,6 +1117,7 @@ export function transformFile(source, checker) {
1092
1117
  }
1093
1118
  if (ts.isCallExpression(node)) {
1094
1119
  rewriteDefineCall(node, ctx);
1120
+ rewriteUpsertCall(node, ctx);
1095
1121
  if (importsUql) {
1096
1122
  rewriteBuilderCall(node, ctx);
1097
1123
  }
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.44.0",
5
+ "version": "0.45.0",
6
6
  "type": "module",
7
7
  "engines": {
8
8
  "node": ">=24"