@lark-apaas/fullstack-cli 1.1.16-alpha.5 → 1.1.16-alpha.6

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/index.js +67 -35
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -631,7 +631,41 @@ var SYSTEM_TO_BUSINESS = {
631
631
  _updated_at: ["updated_at", "updatedAt"],
632
632
  _updated_by: ["updated_by", "updatedBy"]
633
633
  };
634
+ var SYSTEM_FIELD_COLUMNS = new Set(Object.keys(SYSTEM_TO_BUSINESS));
634
635
  var TABLE_FACTORIES = ["pgTable", "pgView", "pgMaterializedView", "table", "view", "materializedView"];
636
+ function extractColumnName(prop) {
637
+ const initializer = prop.getInitializer();
638
+ if (!initializer) return void 0;
639
+ let callExpr = initializer;
640
+ while (Node8.isCallExpression(callExpr)) {
641
+ const expr = callExpr.getExpression();
642
+ if (Node8.isPropertyAccessExpression(expr)) {
643
+ const baseExpr = expr.getExpression();
644
+ if (Node8.isCallExpression(baseExpr)) {
645
+ callExpr = baseExpr;
646
+ continue;
647
+ }
648
+ }
649
+ break;
650
+ }
651
+ if (!Node8.isCallExpression(callExpr)) return void 0;
652
+ const args = callExpr.getArguments();
653
+ if (args.length === 0) return void 0;
654
+ const firstArg = args[0];
655
+ if (Node8.isStringLiteral(firstArg)) {
656
+ return firstArg.getLiteralText();
657
+ }
658
+ return void 0;
659
+ }
660
+ function getPropertyName(prop) {
661
+ const nameNode = prop.getNameNode();
662
+ if (Node8.isStringLiteral(nameNode)) {
663
+ return nameNode.getLiteralText();
664
+ } else if (Node8.isIdentifier(nameNode)) {
665
+ return nameNode.getText();
666
+ }
667
+ return "";
668
+ }
635
669
  var removeSystemFieldsTransform = {
636
670
  name: "remove-system-fields",
637
671
  transform(ctx) {
@@ -658,21 +692,20 @@ var removeSystemFieldsTransform = {
658
692
  if (!Node8.isObjectLiteralExpression(columnsArg)) {
659
693
  return;
660
694
  }
661
- const fieldNames = /* @__PURE__ */ new Set();
662
695
  const properties = columnsArg.getProperties();
696
+ const allPropertyNames = /* @__PURE__ */ new Set();
697
+ const allColumnNames = /* @__PURE__ */ new Set();
663
698
  for (const prop of properties) {
664
699
  if (!Node8.isPropertyAssignment(prop)) {
665
700
  continue;
666
701
  }
667
- const nameNode = prop.getNameNode();
668
- let fieldName = "";
669
- if (Node8.isStringLiteral(nameNode)) {
670
- fieldName = nameNode.getLiteralText();
671
- } else if (Node8.isIdentifier(nameNode)) {
672
- fieldName = nameNode.getText();
702
+ const propName = getPropertyName(prop);
703
+ if (propName) {
704
+ allPropertyNames.add(propName);
673
705
  }
674
- if (fieldName) {
675
- fieldNames.add(fieldName);
706
+ const columnName = extractColumnName(prop);
707
+ if (columnName) {
708
+ allColumnNames.add(columnName);
676
709
  }
677
710
  }
678
711
  const propsToRemove = [];
@@ -680,25 +713,24 @@ var removeSystemFieldsTransform = {
680
713
  if (!Node8.isPropertyAssignment(prop)) {
681
714
  continue;
682
715
  }
683
- const nameNode = prop.getNameNode();
684
- let fieldName = "";
685
- if (Node8.isStringLiteral(nameNode)) {
686
- fieldName = nameNode.getLiteralText();
687
- } else if (Node8.isIdentifier(nameNode)) {
688
- fieldName = nameNode.getText();
716
+ const propName = getPropertyName(prop);
717
+ const columnName = extractColumnName(prop);
718
+ const systemFieldKey = SYSTEM_FIELD_COLUMNS.has(propName) ? propName : columnName && SYSTEM_FIELD_COLUMNS.has(columnName) ? columnName : null;
719
+ if (!systemFieldKey) {
720
+ continue;
721
+ }
722
+ const businessFields = SYSTEM_TO_BUSINESS[systemFieldKey];
723
+ if (!businessFields) {
724
+ continue;
689
725
  }
690
- const businessFields = SYSTEM_TO_BUSINESS[fieldName];
691
- if (businessFields && businessFields.some((bf) => fieldNames.has(bf))) {
726
+ const hasBusinessField = businessFields.some(
727
+ (bf) => allPropertyNames.has(bf) || allColumnNames.has(bf)
728
+ );
729
+ if (hasBusinessField) {
692
730
  propsToRemove.push(prop);
693
731
  }
694
732
  }
695
733
  for (const prop of propsToRemove) {
696
- const leadingCommentRanges = prop.getLeadingCommentRanges();
697
- for (const comment of leadingCommentRanges) {
698
- const commentText = comment.getText();
699
- if (commentText.includes("System field:")) {
700
- }
701
- }
702
734
  prop.remove();
703
735
  stats.removedSystemFields++;
704
736
  }
@@ -3606,17 +3638,17 @@ function analyzeImports(sourceFile) {
3606
3638
  }
3607
3639
 
3608
3640
  // src/commands/migration/versions/v001_capability/code-migrator/analyzers/call-site-analyzer.ts
3609
- import { SyntaxKind as SyntaxKind5 } from "ts-morph";
3641
+ import { SyntaxKind as SyntaxKind4 } from "ts-morph";
3610
3642
  function analyzeCallSites(sourceFile, imports) {
3611
3643
  const callSites = [];
3612
3644
  const importMap = /* @__PURE__ */ new Map();
3613
3645
  for (const imp of imports) {
3614
3646
  importMap.set(imp.importName, imp.capabilityId);
3615
3647
  }
3616
- const callExpressions = sourceFile.getDescendantsOfKind(SyntaxKind5.CallExpression);
3648
+ const callExpressions = sourceFile.getDescendantsOfKind(SyntaxKind4.CallExpression);
3617
3649
  for (const callExpr of callExpressions) {
3618
3650
  const expression = callExpr.getExpression();
3619
- if (expression.getKind() === SyntaxKind5.Identifier) {
3651
+ if (expression.getKind() === SyntaxKind4.Identifier) {
3620
3652
  const functionName = expression.getText();
3621
3653
  const capabilityId = importMap.get(functionName);
3622
3654
  if (capabilityId) {
@@ -3629,11 +3661,11 @@ function analyzeCallSites(sourceFile, imports) {
3629
3661
  text: callExpr.getText()
3630
3662
  });
3631
3663
  }
3632
- } else if (expression.getKind() === SyntaxKind5.PropertyAccessExpression) {
3633
- const propAccess = expression.asKind(SyntaxKind5.PropertyAccessExpression);
3664
+ } else if (expression.getKind() === SyntaxKind4.PropertyAccessExpression) {
3665
+ const propAccess = expression.asKind(SyntaxKind4.PropertyAccessExpression);
3634
3666
  if (propAccess) {
3635
3667
  const objectExpr = propAccess.getExpression();
3636
- if (objectExpr.getKind() === SyntaxKind5.Identifier) {
3668
+ if (objectExpr.getKind() === SyntaxKind4.Identifier) {
3637
3669
  const objectName = objectExpr.getText();
3638
3670
  const capabilityId = importMap.get(objectName);
3639
3671
  if (capabilityId) {
@@ -3862,7 +3894,7 @@ function addInjection(sourceFile) {
3862
3894
  }
3863
3895
 
3864
3896
  // src/commands/migration/versions/v001_capability/code-migrator/transformers/call-site-transformer.ts
3865
- import { SyntaxKind as SyntaxKind6 } from "ts-morph";
3897
+ import { SyntaxKind as SyntaxKind5 } from "ts-morph";
3866
3898
  var DEFAULT_ACTION_NAME = "run";
3867
3899
  function generateNewCallText(capabilityId, actionName, args) {
3868
3900
  const argsText = args.trim() || "{}";
@@ -3877,19 +3909,19 @@ function transformCallSites(sourceFile, imports) {
3877
3909
  });
3878
3910
  }
3879
3911
  let replacedCount = 0;
3880
- const callExpressions = sourceFile.getDescendantsOfKind(SyntaxKind6.CallExpression);
3912
+ const callExpressions = sourceFile.getDescendantsOfKind(SyntaxKind5.CallExpression);
3881
3913
  const sortedCalls = [...callExpressions].sort((a, b) => b.getStart() - a.getStart());
3882
3914
  for (const callExpr of sortedCalls) {
3883
3915
  const expression = callExpr.getExpression();
3884
3916
  let importInfo;
3885
- if (expression.getKind() === SyntaxKind6.Identifier) {
3917
+ if (expression.getKind() === SyntaxKind5.Identifier) {
3886
3918
  const functionName = expression.getText();
3887
3919
  importInfo = importMap.get(functionName);
3888
- } else if (expression.getKind() === SyntaxKind6.PropertyAccessExpression) {
3889
- const propAccess = expression.asKind(SyntaxKind6.PropertyAccessExpression);
3920
+ } else if (expression.getKind() === SyntaxKind5.PropertyAccessExpression) {
3921
+ const propAccess = expression.asKind(SyntaxKind5.PropertyAccessExpression);
3890
3922
  if (propAccess) {
3891
3923
  const objectExpr = propAccess.getExpression();
3892
- if (objectExpr.getKind() === SyntaxKind6.Identifier) {
3924
+ if (objectExpr.getKind() === SyntaxKind5.Identifier) {
3893
3925
  const objectName = objectExpr.getText();
3894
3926
  importInfo = importMap.get(objectName);
3895
3927
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/fullstack-cli",
3
- "version": "1.1.16-alpha.5",
3
+ "version": "1.1.16-alpha.6",
4
4
  "description": "CLI tool for fullstack template management",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",