@lark-apaas/fullstack-cli 1.1.54-beta.0 → 1.1.55-alpha.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/index.js +141 -28
- package/package.json +1 -1
- package/templates/.spark_project +2 -2
package/dist/index.js
CHANGED
|
@@ -847,6 +847,117 @@ var tweakImportsTransform = {
|
|
|
847
847
|
}
|
|
848
848
|
};
|
|
849
849
|
|
|
850
|
+
// src/commands/db/gen-dbschema/transforms/ast/fix-opclass.ts
|
|
851
|
+
import { Node as Node9 } from "ts-morph";
|
|
852
|
+
var TYPE_TO_OPCLASS = {
|
|
853
|
+
uuid: "uuid_ops",
|
|
854
|
+
date: "date_ops",
|
|
855
|
+
varchar: "text_ops",
|
|
856
|
+
text: "text_ops",
|
|
857
|
+
boolean: "bool_ops",
|
|
858
|
+
integer: "int4_ops",
|
|
859
|
+
serial: "int4_ops",
|
|
860
|
+
numeric: "numeric_ops",
|
|
861
|
+
jsonb: "jsonb_ops",
|
|
862
|
+
customTimestamptz: "timestamptz_ops",
|
|
863
|
+
bigint: "int8_ops",
|
|
864
|
+
smallint: "int2_ops",
|
|
865
|
+
real: "float4_ops",
|
|
866
|
+
doublePrecision: "float8_ops"
|
|
867
|
+
};
|
|
868
|
+
var fixOpclassTransform = {
|
|
869
|
+
name: "fix-opclass",
|
|
870
|
+
transform(ctx) {
|
|
871
|
+
const { sourceFile } = ctx;
|
|
872
|
+
sourceFile.forEachDescendant((node) => {
|
|
873
|
+
if (!Node9.isCallExpression(node)) return;
|
|
874
|
+
const expr = node.getExpression();
|
|
875
|
+
if (!Node9.isIdentifier(expr)) return;
|
|
876
|
+
const fnName = expr.getText();
|
|
877
|
+
if (fnName !== "pgTable") return;
|
|
878
|
+
const args = node.getArguments();
|
|
879
|
+
if (args.length < 3) return;
|
|
880
|
+
const tableColumns = collectTableColumns(args[1]);
|
|
881
|
+
if (!tableColumns.size) return;
|
|
882
|
+
const indexFn = args[2];
|
|
883
|
+
if (!Node9.isArrowFunction(indexFn)) return;
|
|
884
|
+
fixOpclassInIndexes(indexFn, tableColumns);
|
|
885
|
+
});
|
|
886
|
+
}
|
|
887
|
+
};
|
|
888
|
+
function collectTableColumns(columnsArg) {
|
|
889
|
+
const columns = /* @__PURE__ */ new Map();
|
|
890
|
+
if (!Node9.isObjectLiteralExpression(columnsArg)) return columns;
|
|
891
|
+
for (const prop of columnsArg.getProperties()) {
|
|
892
|
+
if (!Node9.isPropertyAssignment(prop)) continue;
|
|
893
|
+
const colName = prop.getName();
|
|
894
|
+
const initializer = prop.getInitializer();
|
|
895
|
+
if (!initializer) continue;
|
|
896
|
+
const colType = extractColumnType(initializer);
|
|
897
|
+
if (colType) {
|
|
898
|
+
columns.set(colName, colType);
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
return columns;
|
|
902
|
+
}
|
|
903
|
+
function extractColumnType(node) {
|
|
904
|
+
const text = node.getText();
|
|
905
|
+
for (const typeName of Object.keys(TYPE_TO_OPCLASS)) {
|
|
906
|
+
const pattern = new RegExp(`\\b${typeName}\\s*\\(`);
|
|
907
|
+
if (pattern.test(text)) {
|
|
908
|
+
return typeName;
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
return void 0;
|
|
912
|
+
}
|
|
913
|
+
function fixOpclassInIndexes(indexFn, tableColumns) {
|
|
914
|
+
const paramName = getArrowParam(indexFn);
|
|
915
|
+
if (!paramName) return;
|
|
916
|
+
indexFn.forEachDescendant((node) => {
|
|
917
|
+
if (!Node9.isCallExpression(node)) return;
|
|
918
|
+
const expr = node.getExpression();
|
|
919
|
+
if (!Node9.isPropertyAccessExpression(expr)) return;
|
|
920
|
+
if (expr.getName() !== "op") return;
|
|
921
|
+
const opArgs = node.getArguments();
|
|
922
|
+
if (opArgs.length !== 1) return;
|
|
923
|
+
const currentOp = opArgs[0];
|
|
924
|
+
if (!Node9.isStringLiteral(currentOp)) return;
|
|
925
|
+
const colName = resolveColumnName(expr.getExpression(), paramName);
|
|
926
|
+
if (!colName) return;
|
|
927
|
+
const colType = tableColumns.get(colName);
|
|
928
|
+
if (!colType) return;
|
|
929
|
+
const correctOp = TYPE_TO_OPCLASS[colType];
|
|
930
|
+
if (!correctOp) return;
|
|
931
|
+
const currentValue = currentOp.getLiteralValue();
|
|
932
|
+
if (currentValue !== correctOp) {
|
|
933
|
+
currentOp.setLiteralValue(correctOp);
|
|
934
|
+
}
|
|
935
|
+
});
|
|
936
|
+
}
|
|
937
|
+
function getArrowParam(node) {
|
|
938
|
+
if (!Node9.isArrowFunction(node)) return void 0;
|
|
939
|
+
const params = node.getParameters();
|
|
940
|
+
if (params.length !== 1) return void 0;
|
|
941
|
+
return params[0].getName();
|
|
942
|
+
}
|
|
943
|
+
function resolveColumnName(node, tableParam) {
|
|
944
|
+
if (Node9.isPropertyAccessExpression(node)) {
|
|
945
|
+
const obj = node.getExpression();
|
|
946
|
+
const propName = node.getName();
|
|
947
|
+
if (Node9.isIdentifier(obj) && obj.getText() === tableParam) {
|
|
948
|
+
return propName;
|
|
949
|
+
}
|
|
950
|
+
return resolveColumnName(obj, tableParam);
|
|
951
|
+
}
|
|
952
|
+
if (Node9.isCallExpression(node)) {
|
|
953
|
+
const callExpr = node.getExpression();
|
|
954
|
+
if (Node9.isPropertyAccessExpression(callExpr)) {
|
|
955
|
+
return resolveColumnName(callExpr.getExpression(), tableParam);
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
return void 0;
|
|
959
|
+
}
|
|
960
|
+
|
|
850
961
|
// src/commands/db/gen-dbschema/transforms/ast/index.ts
|
|
851
962
|
var defaultTransforms = [
|
|
852
963
|
patchDefectsTransform,
|
|
@@ -865,6 +976,8 @@ var defaultTransforms = [
|
|
|
865
976
|
// #9 Replace .defaultNow()
|
|
866
977
|
removeSystemFieldsTransform,
|
|
867
978
|
// #10 Remove conflicting system fields
|
|
979
|
+
fixOpclassTransform,
|
|
980
|
+
// #11 Fix multi-column index opclass mapping
|
|
868
981
|
tweakImportsTransform
|
|
869
982
|
// #12 Adjust imports
|
|
870
983
|
];
|
|
@@ -1901,7 +2014,7 @@ export class ${className}Module {}
|
|
|
1901
2014
|
}
|
|
1902
2015
|
|
|
1903
2016
|
// src/commands/db/gen-nest-resource/schema-parser.ts
|
|
1904
|
-
import { Project as Project2, Node as
|
|
2017
|
+
import { Project as Project2, Node as Node10 } from "ts-morph";
|
|
1905
2018
|
var DrizzleSchemaParser = class {
|
|
1906
2019
|
constructor(projectOptions) {
|
|
1907
2020
|
this.project = new Project2(projectOptions);
|
|
@@ -1914,7 +2027,7 @@ var DrizzleSchemaParser = class {
|
|
|
1914
2027
|
const declarations = statement.getDeclarations();
|
|
1915
2028
|
for (const declaration of declarations) {
|
|
1916
2029
|
const initializer = declaration.getInitializer();
|
|
1917
|
-
if (initializer &&
|
|
2030
|
+
if (initializer && Node10.isCallExpression(initializer)) {
|
|
1918
2031
|
const expression = initializer.getExpression();
|
|
1919
2032
|
if (expression.getText() === "pgTable") {
|
|
1920
2033
|
const tableInfo = this.parsePgTable(
|
|
@@ -1937,13 +2050,13 @@ var DrizzleSchemaParser = class {
|
|
|
1937
2050
|
}
|
|
1938
2051
|
const tableName = args[0].getText().replace(/['"]/g, "");
|
|
1939
2052
|
const fieldsArg = args[1];
|
|
1940
|
-
if (!
|
|
2053
|
+
if (!Node10.isObjectLiteralExpression(fieldsArg)) {
|
|
1941
2054
|
return null;
|
|
1942
2055
|
}
|
|
1943
2056
|
const fields = [];
|
|
1944
2057
|
const properties = fieldsArg.getProperties();
|
|
1945
2058
|
for (const prop of properties) {
|
|
1946
|
-
if (
|
|
2059
|
+
if (Node10.isPropertyAssignment(prop)) {
|
|
1947
2060
|
const fieldName = prop.getName();
|
|
1948
2061
|
const initializer = prop.getInitializer();
|
|
1949
2062
|
const leadingComments = prop.getLeadingCommentRanges();
|
|
@@ -1951,7 +2064,7 @@ var DrizzleSchemaParser = class {
|
|
|
1951
2064
|
if (leadingComments.length > 0) {
|
|
1952
2065
|
comment = leadingComments.map((c) => c.getText()).join("\n").replace(/\/\//g, "").trim();
|
|
1953
2066
|
}
|
|
1954
|
-
if (initializer &&
|
|
2067
|
+
if (initializer && Node10.isCallExpression(initializer)) {
|
|
1955
2068
|
const fieldInfo = this.parseField(fieldName, initializer, comment);
|
|
1956
2069
|
fields.push(fieldInfo);
|
|
1957
2070
|
}
|
|
@@ -1983,10 +2096,10 @@ var DrizzleSchemaParser = class {
|
|
|
1983
2096
|
parseBaseType(callExpr, fieldInfo) {
|
|
1984
2097
|
let current = callExpr;
|
|
1985
2098
|
let baseCall = null;
|
|
1986
|
-
while (
|
|
2099
|
+
while (Node10.isCallExpression(current)) {
|
|
1987
2100
|
baseCall = current;
|
|
1988
2101
|
const expression2 = current.getExpression();
|
|
1989
|
-
if (
|
|
2102
|
+
if (Node10.isPropertyAccessExpression(expression2)) {
|
|
1990
2103
|
current = expression2.getExpression();
|
|
1991
2104
|
} else {
|
|
1992
2105
|
break;
|
|
@@ -1997,7 +2110,7 @@ var DrizzleSchemaParser = class {
|
|
|
1997
2110
|
}
|
|
1998
2111
|
const expression = baseCall.getExpression();
|
|
1999
2112
|
let typeName = "";
|
|
2000
|
-
if (
|
|
2113
|
+
if (Node10.isPropertyAccessExpression(expression)) {
|
|
2001
2114
|
typeName = expression.getName();
|
|
2002
2115
|
} else {
|
|
2003
2116
|
typeName = expression.getText();
|
|
@@ -2006,25 +2119,25 @@ var DrizzleSchemaParser = class {
|
|
|
2006
2119
|
const args = baseCall.getArguments();
|
|
2007
2120
|
if (args.length > 0) {
|
|
2008
2121
|
const firstArg = args[0];
|
|
2009
|
-
if (
|
|
2122
|
+
if (Node10.isStringLiteral(firstArg)) {
|
|
2010
2123
|
fieldInfo.columnName = firstArg.getLiteralText();
|
|
2011
|
-
} else if (
|
|
2124
|
+
} else if (Node10.isObjectLiteralExpression(firstArg)) {
|
|
2012
2125
|
this.parseTypeConfig(firstArg, fieldInfo);
|
|
2013
|
-
} else if (
|
|
2126
|
+
} else if (Node10.isArrayLiteralExpression(firstArg)) {
|
|
2014
2127
|
fieldInfo.enumValues = firstArg.getElements().map((el) => el.getText().replace(/['"]/g, ""));
|
|
2015
2128
|
}
|
|
2016
2129
|
}
|
|
2017
|
-
if (args.length > 1 &&
|
|
2130
|
+
if (args.length > 1 && Node10.isObjectLiteralExpression(args[1])) {
|
|
2018
2131
|
this.parseTypeConfig(args[1], fieldInfo);
|
|
2019
2132
|
}
|
|
2020
2133
|
}
|
|
2021
2134
|
parseTypeConfig(objLiteral, fieldInfo) {
|
|
2022
|
-
if (!
|
|
2135
|
+
if (!Node10.isObjectLiteralExpression(objLiteral)) {
|
|
2023
2136
|
return;
|
|
2024
2137
|
}
|
|
2025
2138
|
const properties = objLiteral.getProperties();
|
|
2026
2139
|
for (const prop of properties) {
|
|
2027
|
-
if (
|
|
2140
|
+
if (Node10.isPropertyAssignment(prop)) {
|
|
2028
2141
|
const propName = prop.getName();
|
|
2029
2142
|
const value = prop.getInitializer()?.getText();
|
|
2030
2143
|
switch (propName) {
|
|
@@ -2056,9 +2169,9 @@ var DrizzleSchemaParser = class {
|
|
|
2056
2169
|
}
|
|
2057
2170
|
parseCallChain(callExpr, fieldInfo) {
|
|
2058
2171
|
let current = callExpr;
|
|
2059
|
-
while (
|
|
2172
|
+
while (Node10.isCallExpression(current)) {
|
|
2060
2173
|
const expression = current.getExpression();
|
|
2061
|
-
if (
|
|
2174
|
+
if (Node10.isPropertyAccessExpression(expression)) {
|
|
2062
2175
|
const methodName = expression.getName();
|
|
2063
2176
|
const args = current.getArguments();
|
|
2064
2177
|
switch (methodName) {
|
|
@@ -5647,17 +5760,17 @@ function analyzeImports(sourceFile) {
|
|
|
5647
5760
|
}
|
|
5648
5761
|
|
|
5649
5762
|
// src/commands/migration/versions/v001_capability/code-migrator/analyzers/call-site-analyzer.ts
|
|
5650
|
-
import { SyntaxKind as
|
|
5763
|
+
import { SyntaxKind as SyntaxKind5 } from "ts-morph";
|
|
5651
5764
|
function analyzeCallSites(sourceFile, imports) {
|
|
5652
5765
|
const callSites = [];
|
|
5653
5766
|
const importMap = /* @__PURE__ */ new Map();
|
|
5654
5767
|
for (const imp of imports) {
|
|
5655
5768
|
importMap.set(imp.importName, imp.capabilityId);
|
|
5656
5769
|
}
|
|
5657
|
-
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
5770
|
+
const callExpressions = sourceFile.getDescendantsOfKind(SyntaxKind5.CallExpression);
|
|
5658
5771
|
for (const callExpr of callExpressions) {
|
|
5659
5772
|
const expression = callExpr.getExpression();
|
|
5660
|
-
if (expression.getKind() ===
|
|
5773
|
+
if (expression.getKind() === SyntaxKind5.Identifier) {
|
|
5661
5774
|
const functionName = expression.getText();
|
|
5662
5775
|
const capabilityId = importMap.get(functionName);
|
|
5663
5776
|
if (capabilityId) {
|
|
@@ -5670,11 +5783,11 @@ function analyzeCallSites(sourceFile, imports) {
|
|
|
5670
5783
|
text: callExpr.getText()
|
|
5671
5784
|
});
|
|
5672
5785
|
}
|
|
5673
|
-
} else if (expression.getKind() ===
|
|
5674
|
-
const propAccess = expression.asKind(
|
|
5786
|
+
} else if (expression.getKind() === SyntaxKind5.PropertyAccessExpression) {
|
|
5787
|
+
const propAccess = expression.asKind(SyntaxKind5.PropertyAccessExpression);
|
|
5675
5788
|
if (propAccess) {
|
|
5676
5789
|
const objectExpr = propAccess.getExpression();
|
|
5677
|
-
if (objectExpr.getKind() ===
|
|
5790
|
+
if (objectExpr.getKind() === SyntaxKind5.Identifier) {
|
|
5678
5791
|
const objectName = objectExpr.getText();
|
|
5679
5792
|
const capabilityId = importMap.get(objectName);
|
|
5680
5793
|
if (capabilityId) {
|
|
@@ -5903,7 +6016,7 @@ function addInjection(sourceFile) {
|
|
|
5903
6016
|
}
|
|
5904
6017
|
|
|
5905
6018
|
// src/commands/migration/versions/v001_capability/code-migrator/transformers/call-site-transformer.ts
|
|
5906
|
-
import { SyntaxKind as
|
|
6019
|
+
import { SyntaxKind as SyntaxKind6 } from "ts-morph";
|
|
5907
6020
|
var DEFAULT_ACTION_NAME = "run";
|
|
5908
6021
|
function generateNewCallText(capabilityId, actionName, args) {
|
|
5909
6022
|
const argsText = args.trim() || "{}";
|
|
@@ -5918,19 +6031,19 @@ function transformCallSites(sourceFile, imports) {
|
|
|
5918
6031
|
});
|
|
5919
6032
|
}
|
|
5920
6033
|
let replacedCount = 0;
|
|
5921
|
-
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
6034
|
+
const callExpressions = sourceFile.getDescendantsOfKind(SyntaxKind6.CallExpression);
|
|
5922
6035
|
const sortedCalls = [...callExpressions].sort((a, b) => b.getStart() - a.getStart());
|
|
5923
6036
|
for (const callExpr of sortedCalls) {
|
|
5924
6037
|
const expression = callExpr.getExpression();
|
|
5925
6038
|
let importInfo;
|
|
5926
|
-
if (expression.getKind() ===
|
|
6039
|
+
if (expression.getKind() === SyntaxKind6.Identifier) {
|
|
5927
6040
|
const functionName = expression.getText();
|
|
5928
6041
|
importInfo = importMap.get(functionName);
|
|
5929
|
-
} else if (expression.getKind() ===
|
|
5930
|
-
const propAccess = expression.asKind(
|
|
6042
|
+
} else if (expression.getKind() === SyntaxKind6.PropertyAccessExpression) {
|
|
6043
|
+
const propAccess = expression.asKind(SyntaxKind6.PropertyAccessExpression);
|
|
5931
6044
|
if (propAccess) {
|
|
5932
6045
|
const objectExpr = propAccess.getExpression();
|
|
5933
|
-
if (objectExpr.getKind() ===
|
|
6046
|
+
if (objectExpr.getKind() === SyntaxKind6.Identifier) {
|
|
5934
6047
|
const objectName = objectExpr.getText();
|
|
5935
6048
|
importInfo = importMap.get(objectName);
|
|
5936
6049
|
}
|
package/package.json
CHANGED
package/templates/.spark_project
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
run = ["npm", "run", "dev"] # 默认 spark-cli dev
|
|
2
|
-
hidden = [".config", ".git", "scripts", "node_modules", "dist", ".spark", ".agent", ".agents", "
|
|
2
|
+
hidden = [".config", ".git", "scripts", "node_modules", "dist", ".spark", ".agent", ".agents", "tmp", ".spark_project", ".playwright-cli"]
|
|
3
3
|
lint = ["npm", "run", "lint"]
|
|
4
4
|
test = ["npm", "run", "test"]
|
|
5
5
|
genDbSchema = ["npm", "run", "gen:db-schema"]
|
|
@@ -13,4 +13,4 @@ run = ["npm", "run", "start"]
|
|
|
13
13
|
[files.restrict]
|
|
14
14
|
pathPatterns = ["client/src/api/gen", "package.json", ".spark_project", ".gitignore"]
|
|
15
15
|
[files.hidden]
|
|
16
|
-
pathPatterns = [".config", ".git", "scripts", "node_modules", "dist", ".spark", ".agent", ".agents", "
|
|
16
|
+
pathPatterns = [".config", ".git", "scripts", "node_modules", "dist", ".spark", ".agent", ".agents", "tmp", ".spark_project", ".playwright-cli"]
|