uql-codemod 0.44.0 → 0.46.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/dist/transform.js +27 -4
- 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.
|
|
@@ -768,9 +793,6 @@ function admitNull(options, node, ctx) {
|
|
|
768
793
|
* so the declaration is found there rather than under a decorator.
|
|
769
794
|
*/
|
|
770
795
|
function admitNullOnDefined(field, owner, ctx) {
|
|
771
|
-
if (!ts.isPropertyAssignment(field)) {
|
|
772
|
-
return;
|
|
773
|
-
}
|
|
774
796
|
const key = propertyKey(field.name);
|
|
775
797
|
const declaration = key
|
|
776
798
|
? instanceTypeOf(owner.entity, ctx.checker)
|
|
@@ -862,7 +884,7 @@ function renameExports(source, dead, ctx) {
|
|
|
862
884
|
function renamedTo(element, entry) {
|
|
863
885
|
const name = importedName(element);
|
|
864
886
|
const rename = RENAMED_EXPORTS.get(name);
|
|
865
|
-
return rename?.to === name &&
|
|
887
|
+
return rename?.to === name && rename.from === entry ? undefined : rename;
|
|
866
888
|
}
|
|
867
889
|
/** Every identifier in the file bound to the same symbol as `name`, besides `name` itself. */
|
|
868
890
|
function usesOf(source, name, checker) {
|
|
@@ -1092,6 +1114,7 @@ export function transformFile(source, checker) {
|
|
|
1092
1114
|
}
|
|
1093
1115
|
if (ts.isCallExpression(node)) {
|
|
1094
1116
|
rewriteDefineCall(node, ctx);
|
|
1117
|
+
rewriteUpsertCall(node, ctx);
|
|
1095
1118
|
if (importsUql) {
|
|
1096
1119
|
rewriteBuilderCall(node, ctx);
|
|
1097
1120
|
}
|