uql-codemod 0.48.2 → 0.49.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 +22 -12
- package/dist/builders.d.ts +18 -0
- package/dist/builders.js +588 -0
- package/dist/classOptions.d.ts +9 -0
- package/dist/classOptions.js +240 -0
- package/dist/columnMethods.d.ts +11 -0
- package/dist/columnMethods.js +6 -0
- package/dist/columnRefs.js +1 -8
- package/dist/context.d.ts +18 -5
- package/dist/context.js +22 -4
- package/dist/definers.d.ts +24 -0
- package/dist/definers.js +34 -0
- package/dist/edits.d.ts +26 -5
- package/dist/edits.js +54 -12
- package/dist/entitySql.js +2 -4
- package/dist/imports.d.ts +18 -5
- package/dist/imports.js +85 -31
- package/dist/index.d.ts +3 -3
- package/dist/index.js +9 -12
- package/dist/jsonIndex.d.ts +11 -0
- package/dist/jsonIndex.js +78 -0
- package/dist/keyMaps.d.ts +3 -1
- package/dist/keyMaps.js +5 -1
- package/dist/migrationBuilders.d.ts +13 -0
- package/dist/migrationBuilders.js +182 -0
- package/dist/relationTarget.d.ts +6 -0
- package/dist/relationTarget.js +21 -0
- package/dist/schemaEntity.d.ts +12 -0
- package/dist/schemaEntity.js +518 -0
- package/dist/schemaOptions.d.ts +6 -0
- package/dist/schemaOptions.js +6 -0
- package/dist/syntax.d.ts +54 -0
- package/dist/syntax.js +131 -1
- package/dist/transform.d.ts +11 -2
- package/dist/transform.js +137 -130
- package/dist/tsconfig.d.ts +3 -9
- package/dist/tsconfig.js +18 -21
- package/package.json +1 -1
- package/dist/fieldType.d.ts +0 -13
- package/dist/fieldType.js +0 -56
package/dist/tsconfig.js
CHANGED
|
@@ -1,39 +1,36 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
import { applyEdits, removeFromList } from './edits.js';
|
|
3
2
|
import { propertyAssignment, propertyValue } from './syntax.js';
|
|
4
3
|
/** The flags the standard spec has no use for. Their presence is what keeps a project on the old one. */
|
|
5
4
|
const LEGACY_FLAGS = ['experimentalDecorators', 'emitDecoratorMetadata'];
|
|
6
5
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* What a `tsconfig.json` needs decided by hand for the standard decorator spec. The file is only read, never
|
|
7
|
+
* written: its flags are the project's to remove, and a rewrite would have to keep its comments and formatting.
|
|
9
8
|
*/
|
|
10
|
-
export function
|
|
9
|
+
export function checkTsconfig(fileName, text) {
|
|
11
10
|
const source = ts.parseJsonText(fileName, text);
|
|
12
11
|
const root = source.statements[0]?.expression;
|
|
13
12
|
if (!root || !ts.isObjectLiteralExpression(root)) {
|
|
14
|
-
return
|
|
13
|
+
return [`${fileName}: not an object, so nothing was checked`];
|
|
15
14
|
}
|
|
16
|
-
const edits = [];
|
|
17
15
|
const unresolved = [];
|
|
18
16
|
const compilerOptions = propertyValue(root, 'compilerOptions');
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
17
|
+
const options = compilerOptions && ts.isObjectLiteralExpression(compilerOptions) ? compilerOptions : undefined;
|
|
18
|
+
const legacy = LEGACY_FLAGS.filter((flag) => options && propertyAssignment(options, flag));
|
|
19
|
+
if (legacy.length) {
|
|
20
|
+
unresolved.push(`${fileName}: remove ${legacy.map((flag) => `'${flag}'`).join(' and ')} by hand, ` +
|
|
21
|
+
'since the standard spec is the only one uql-orm supports');
|
|
22
|
+
}
|
|
23
|
+
// `target` is only reported: removing it silently falls back to the compiler default (`es5` for `tsc`), and
|
|
24
|
+
// choosing a replacement means guessing which era the project targets.
|
|
25
|
+
const target = options && propertyValue(options, 'target');
|
|
26
|
+
if (target && ts.isStringLiteral(target) && target.text.toLowerCase() === 'esnext') {
|
|
27
|
+
unresolved.push(`${fileName}: 'target' is 'esnext', the one target that emits decorator syntax untransformed. ` +
|
|
28
|
+
'Change it to any dated target, such as `es2024`.');
|
|
32
29
|
}
|
|
33
30
|
// A value the file inherits cannot be edited here, and silence would read as "there was none".
|
|
34
|
-
if (propertyValue(root, 'extends') && !
|
|
31
|
+
if (propertyValue(root, 'extends') && !legacy.length) {
|
|
35
32
|
unresolved.push(`${fileName}: extends another config, so check the base for 'experimentalDecorators', ` +
|
|
36
33
|
"'emitDecoratorMetadata' and 'target'.");
|
|
37
34
|
}
|
|
38
|
-
return
|
|
35
|
+
return unresolved;
|
|
39
36
|
}
|
package/package.json
CHANGED
package/dist/fieldType.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import ts from 'typescript';
|
|
2
|
-
export declare function isBrandedString(type: ts.Type): boolean;
|
|
3
|
-
/**
|
|
4
|
-
* The `type` option reflection supplied for a property of `type`, mirroring `TypeFor` in `uql-orm`, or nothing
|
|
5
|
-
* for a shape a human decides. Only what reflection could produce is read: a `Json<T>` or vector property got
|
|
6
|
-
* `Object`/`Array` from it, so it already declared its `type`.
|
|
7
|
-
*/
|
|
8
|
-
export declare function fieldTypeFor(type: ts.Type): string | undefined;
|
|
9
|
-
/**
|
|
10
|
-
* The entity name a relation property points at: `Company` for `Company`, `Company[]`, and
|
|
11
|
-
* `Relation<Company>` alike, since `Relation<T>` is an alias for `T` and erases before this runs.
|
|
12
|
-
*/
|
|
13
|
-
export declare function relationTargetFor(type: ts.Type, checker: ts.TypeChecker): string | undefined;
|
package/dist/fieldType.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import ts from 'typescript';
|
|
2
|
-
/** The string types carrying more than `string`, e.g. `` type UUID = `${string}-${string}` ``, still string columns. */
|
|
3
|
-
const BRANDED_STRING = ts.TypeFlags.TemplateLiteral | ts.TypeFlags.StringMapping;
|
|
4
|
-
export function isBrandedString(type) {
|
|
5
|
-
return (type.isUnion() ? type.types : [type]).some((t) => !!(t.getFlags() & BRANDED_STRING));
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Reads a union by requiring its arms to agree, which is what an `'a' | 'b'` enum or a `T | null` looks
|
|
9
|
-
* like. `undefined` and `null` arms are dropped first: they carry no column type of their own.
|
|
10
|
-
*/
|
|
11
|
-
function foldUnion(type, read) {
|
|
12
|
-
const arms = type.types.filter((arm) => !(arm.getFlags() & (ts.TypeFlags.Undefined | ts.TypeFlags.Null)));
|
|
13
|
-
const readings = new Set(arms.map(read));
|
|
14
|
-
return readings.size === 1 ? [...readings][0] : undefined;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* The `type` option reflection supplied for a property of `type`, mirroring `TypeFor` in `uql-orm`, or nothing
|
|
18
|
-
* for a shape a human decides. Only what reflection could produce is read: a `Json<T>` or vector property got
|
|
19
|
-
* `Object`/`Array` from it, so it already declared its `type`.
|
|
20
|
-
*/
|
|
21
|
-
export function fieldTypeFor(type) {
|
|
22
|
-
const flags = type.getFlags();
|
|
23
|
-
if (type.isUnion()) {
|
|
24
|
-
return foldUnion(type, fieldTypeFor);
|
|
25
|
-
}
|
|
26
|
-
if (flags & (ts.TypeFlags.String | ts.TypeFlags.StringLiteral | BRANDED_STRING))
|
|
27
|
-
return 'String';
|
|
28
|
-
if (flags & (ts.TypeFlags.Number | ts.TypeFlags.NumberLiteral))
|
|
29
|
-
return 'Number';
|
|
30
|
-
if (flags & (ts.TypeFlags.BigInt | ts.TypeFlags.BigIntLiteral))
|
|
31
|
-
return 'BigInt';
|
|
32
|
-
if (flags & (ts.TypeFlags.Boolean | ts.TypeFlags.BooleanLiteral))
|
|
33
|
-
return 'Boolean';
|
|
34
|
-
// Matched by declared symbol rather than by the printed type: both of these became generic in the
|
|
35
|
-
// modern lib, so `Uint8Array` prints as `Uint8Array<ArrayBufferLike>` and never compared equal.
|
|
36
|
-
const name = type.getSymbol()?.getName();
|
|
37
|
-
if (name === 'Date')
|
|
38
|
-
return 'Date';
|
|
39
|
-
if (name === 'Buffer' || name === 'Uint8Array')
|
|
40
|
-
return "'blob'";
|
|
41
|
-
return undefined;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* The entity name a relation property points at: `Company` for `Company`, `Company[]`, and
|
|
45
|
-
* `Relation<Company>` alike, since `Relation<T>` is an alias for `T` and erases before this runs.
|
|
46
|
-
*/
|
|
47
|
-
export function relationTargetFor(type, checker) {
|
|
48
|
-
if (type.isUnion()) {
|
|
49
|
-
return foldUnion(type, (arm) => relationTargetFor(arm, checker));
|
|
50
|
-
}
|
|
51
|
-
const elementType = checker.getIndexTypeOfType(type, ts.IndexKind.Number);
|
|
52
|
-
const target = elementType ?? type;
|
|
53
|
-
const symbol = target.getSymbol();
|
|
54
|
-
const name = symbol?.getName();
|
|
55
|
-
return name && name !== '__type' && /^[A-Z][A-Za-z0-9_]*$/.test(name) ? name : undefined;
|
|
56
|
-
}
|