@aiready/core 0.24.3 → 0.24.5

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 CHANGED
@@ -666,13 +666,65 @@ var python_parser_exports = {};
666
666
  __export(python_parser_exports, {
667
667
  PythonParser: () => PythonParser
668
668
  });
669
- var PythonParser;
669
+ var PYTHON_CONSTANTS, PythonParser;
670
670
  var init_python_parser = __esm({
671
671
  "src/parsers/python-parser.ts"() {
672
672
  "use strict";
673
673
  init_language();
674
674
  init_metadata_utils();
675
675
  init_base_parser();
676
+ PYTHON_CONSTANTS = {
677
+ NODES: {
678
+ IMPORT_STATEMENT: "import_statement",
679
+ IMPORT_FROM_STATEMENT: "import_from_statement",
680
+ DOTTED_NAME: "dotted_name",
681
+ ALIASED_IMPORT: "aliased_import",
682
+ WILDCARD_IMPORT: "wildcard_import",
683
+ FUNCTION_DEFINITION: "function_definition",
684
+ CLASS_DEFINITION: "class_definition",
685
+ EXPRESSION_STATEMENT: "expression_statement",
686
+ ASSIGNMENT: "assignment",
687
+ IDENTIFIER: "identifier",
688
+ TYPED_PARAMETER: "typed_parameter",
689
+ DEFAULT_PARAMETER: "default_parameter"
690
+ },
691
+ FIELDS: {
692
+ NAME: "name",
693
+ MODULE_NAME: "module_name",
694
+ LEFT: "left",
695
+ PARAMETERS: "parameters"
696
+ },
697
+ SPECIAL: {
698
+ WILDCARD: "*",
699
+ DUNDER_ALL: "__all__",
700
+ DUNDER_VERSION: "__version__",
701
+ DUNDER_AUTHOR: "__author__",
702
+ DUNDER_INIT: "__init__",
703
+ DUNDER_STR: "__str__",
704
+ DUNDER_REPR: "__repr__",
705
+ DUNDER_NAME: "__name__",
706
+ DUNDER_MAIN: "__main__",
707
+ DUNDER_FILE: "__file__",
708
+ DUNDER_DOC: "__doc__",
709
+ DUNDER_DICT: "__dict__",
710
+ DUNDER_CLASS: "__class__",
711
+ DUNDER_MODULE: "__module__",
712
+ DUNDER_BASES: "__bases__",
713
+ MAIN_VAL: "__main__"
714
+ },
715
+ BUILTINS: {
716
+ PRINT: "print(",
717
+ INPUT: "input(",
718
+ OPEN: "open("
719
+ },
720
+ TYPES: {
721
+ FUNCTION: "function",
722
+ CLASS: "class",
723
+ VARIABLE: "variable",
724
+ CONST: "const",
725
+ DOCSTRING: "docstring"
726
+ }
727
+ };
676
728
  PythonParser = class extends BaseLanguageParser {
677
729
  constructor() {
678
730
  super(...arguments);
@@ -684,28 +736,25 @@ var init_python_parser = __esm({
684
736
  }
685
737
  /**
686
738
  * Analyze metadata for a Python node (purity, side effects).
687
- *
688
- * @param node - Tree-sitter node to analyze.
689
- * @param code - Source code for context.
690
- * @returns Partial ExportInfo containing discovered metadata.
691
739
  */
692
740
  analyzeMetadata(node, code) {
693
741
  return analyzeNodeMetadata(node, code, {
694
- sideEffectSignatures: ["print(", "input(", "open("]
742
+ sideEffectSignatures: [
743
+ PYTHON_CONSTANTS.BUILTINS.PRINT,
744
+ PYTHON_CONSTANTS.BUILTINS.INPUT,
745
+ PYTHON_CONSTANTS.BUILTINS.OPEN
746
+ ]
695
747
  });
696
748
  }
697
749
  /**
698
750
  * Extract import information using AST walk.
699
- *
700
- * @param rootNode - Root node of the Python AST.
701
- * @returns Array of discovered FileImport objects.
702
751
  */
703
752
  extractImportsAST(rootNode) {
704
753
  const imports = [];
705
754
  const processImportNode = (node) => {
706
- if (node.type === "import_statement") {
755
+ if (node.type === PYTHON_CONSTANTS.NODES.IMPORT_STATEMENT) {
707
756
  for (const child of node.children) {
708
- if (child.type === "dotted_name") {
757
+ if (child.type === PYTHON_CONSTANTS.NODES.DOTTED_NAME) {
709
758
  const source = child.text;
710
759
  imports.push({
711
760
  source,
@@ -721,8 +770,10 @@ var init_python_parser = __esm({
721
770
  }
722
771
  }
723
772
  });
724
- } else if (child.type === "aliased_import") {
725
- const nameNode = child.childForFieldName("name");
773
+ } else if (child.type === PYTHON_CONSTANTS.NODES.ALIASED_IMPORT) {
774
+ const nameNode = child.childForFieldName(
775
+ PYTHON_CONSTANTS.FIELDS.NAME
776
+ );
726
777
  if (nameNode) {
727
778
  const source = nameNode.text;
728
779
  imports.push({
@@ -742,19 +793,23 @@ var init_python_parser = __esm({
742
793
  }
743
794
  }
744
795
  }
745
- } else if (node.type === "import_from_statement") {
746
- const moduleNameNode = node.childForFieldName("module_name");
796
+ } else if (node.type === PYTHON_CONSTANTS.NODES.IMPORT_FROM_STATEMENT) {
797
+ const moduleNameNode = node.childForFieldName(
798
+ PYTHON_CONSTANTS.FIELDS.MODULE_NAME
799
+ );
747
800
  if (moduleNameNode) {
748
801
  const source = moduleNameNode.text;
749
802
  const specifiers = [];
750
803
  for (const child of node.children) {
751
- if (child.type === "dotted_name" && child !== moduleNameNode) {
804
+ if (child.type === PYTHON_CONSTANTS.NODES.DOTTED_NAME && child !== moduleNameNode) {
752
805
  specifiers.push(child.text);
753
- } else if (child.type === "aliased_import") {
754
- const nameNode = child.childForFieldName("name");
806
+ } else if (child.type === PYTHON_CONSTANTS.NODES.ALIASED_IMPORT) {
807
+ const nameNode = child.childForFieldName(
808
+ PYTHON_CONSTANTS.FIELDS.NAME
809
+ );
755
810
  if (nameNode) specifiers.push(nameNode.text);
756
- } else if (child.type === "wildcard_import") {
757
- specifiers.push("*");
811
+ } else if (child.type === PYTHON_CONSTANTS.NODES.WILDCARD_IMPORT) {
812
+ specifiers.push(PYTHON_CONSTANTS.SPECIAL.WILDCARD);
758
813
  }
759
814
  }
760
815
  if (specifiers.length > 0) {
@@ -783,16 +838,12 @@ var init_python_parser = __esm({
783
838
  }
784
839
  /**
785
840
  * Extract export information using AST walk.
786
- *
787
- * @param rootNode - Root node of the Python AST.
788
- * @param code - Source code for documentation extraction.
789
- * @returns Array of discovered ExportInfo objects.
790
841
  */
791
842
  extractExportsAST(rootNode, code) {
792
843
  const exports2 = [];
793
844
  for (const node of rootNode.children) {
794
- if (node.type === "function_definition") {
795
- const nameNode = node.childForFieldName("name");
845
+ if (node.type === PYTHON_CONSTANTS.NODES.FUNCTION_DEFINITION) {
846
+ const nameNode = node.childForFieldName(PYTHON_CONSTANTS.FIELDS.NAME);
796
847
  if (nameNode) {
797
848
  const name = nameNode.text;
798
849
  const isPrivate = name.startsWith("_") && !name.startsWith("__");
@@ -800,7 +851,7 @@ var init_python_parser = __esm({
800
851
  const metadata = this.analyzeMetadata(node, code);
801
852
  exports2.push({
802
853
  name,
803
- type: "function",
854
+ type: PYTHON_CONSTANTS.TYPES.FUNCTION,
804
855
  loc: {
805
856
  start: {
806
857
  line: node.startPosition.row + 1,
@@ -816,13 +867,13 @@ var init_python_parser = __esm({
816
867
  });
817
868
  }
818
869
  }
819
- } else if (node.type === "class_definition") {
820
- const nameNode = node.childForFieldName("name");
870
+ } else if (node.type === PYTHON_CONSTANTS.NODES.CLASS_DEFINITION) {
871
+ const nameNode = node.childForFieldName(PYTHON_CONSTANTS.FIELDS.NAME);
821
872
  if (nameNode) {
822
873
  const metadata = this.analyzeMetadata(node, code);
823
874
  exports2.push({
824
875
  name: nameNode.text,
825
- type: "class",
876
+ type: PYTHON_CONSTANTS.TYPES.CLASS,
826
877
  loc: {
827
878
  start: {
828
879
  line: node.startPosition.row + 1,
@@ -836,18 +887,20 @@ var init_python_parser = __esm({
836
887
  ...metadata
837
888
  });
838
889
  }
839
- } else if (node.type === "expression_statement") {
890
+ } else if (node.type === PYTHON_CONSTANTS.NODES.EXPRESSION_STATEMENT) {
840
891
  const assignment = node.firstChild;
841
- if (assignment && assignment.type === "assignment") {
842
- const left = assignment.childForFieldName("left");
843
- if (left && left.type === "identifier") {
892
+ if (assignment && assignment.type === PYTHON_CONSTANTS.NODES.ASSIGNMENT) {
893
+ const left = assignment.childForFieldName(
894
+ PYTHON_CONSTANTS.FIELDS.LEFT
895
+ );
896
+ if (left && left.type === PYTHON_CONSTANTS.NODES.IDENTIFIER) {
844
897
  const name = left.text;
845
- const isInternal = name === "__all__" || name === "__version__" || name === "__author__";
898
+ const isInternal = name === PYTHON_CONSTANTS.SPECIAL.DUNDER_ALL || name === PYTHON_CONSTANTS.SPECIAL.DUNDER_VERSION || name === PYTHON_CONSTANTS.SPECIAL.DUNDER_AUTHOR;
846
899
  const isPrivate = name.startsWith("_") && !name.startsWith("__");
847
900
  if (!isInternal && !isPrivate) {
848
901
  exports2.push({
849
902
  name,
850
- type: name === name.toUpperCase() ? "const" : "variable",
903
+ type: name === name.toUpperCase() ? PYTHON_CONSTANTS.TYPES.CONST : PYTHON_CONSTANTS.TYPES.VARIABLE,
851
904
  loc: {
852
905
  start: {
853
906
  line: node.startPosition.row + 1,
@@ -868,18 +921,17 @@ var init_python_parser = __esm({
868
921
  }
869
922
  /**
870
923
  * Extract parameter names from a function definition node.
871
- *
872
- * @param node - Function definition node.
873
- * @returns Array of parameter name strings.
874
924
  */
875
925
  extractParameters(node) {
876
- const paramsNode = node.childForFieldName("parameters");
926
+ const paramsNode = node.childForFieldName(
927
+ PYTHON_CONSTANTS.FIELDS.PARAMETERS
928
+ );
877
929
  if (!paramsNode) return [];
878
930
  return paramsNode.children.filter(
879
- (c) => c.type === "identifier" || c.type === "typed_parameter" || c.type === "default_parameter"
931
+ (c) => c.type === PYTHON_CONSTANTS.NODES.IDENTIFIER || c.type === PYTHON_CONSTANTS.NODES.TYPED_PARAMETER || c.type === PYTHON_CONSTANTS.NODES.DEFAULT_PARAMETER
880
932
  ).map((c) => {
881
- if (c.type === "identifier") return c.text;
882
- if (c.type === "typed_parameter" || c.type === "default_parameter") {
933
+ if (c.type === PYTHON_CONSTANTS.NODES.IDENTIFIER) return c.text;
934
+ if (c.type === PYTHON_CONSTANTS.NODES.TYPED_PARAMETER || c.type === PYTHON_CONSTANTS.NODES.DEFAULT_PARAMETER) {
883
935
  return c.firstChild?.text || "unknown";
884
936
  }
885
937
  return "unknown";
@@ -887,10 +939,6 @@ var init_python_parser = __esm({
887
939
  }
888
940
  /**
889
941
  * Fallback regex-based parsing when tree-sitter is unavailable.
890
- *
891
- * @param code - Source code content.
892
- * @param filePath - Path to the file being parsed.
893
- * @returns Consolidated ParseResult.
894
942
  */
895
943
  parseRegex(code, filePath) {
896
944
  try {
@@ -919,20 +967,20 @@ var init_python_parser = __esm({
919
967
  classPattern: /^[A-Z][a-zA-Z0-9]*$/,
920
968
  constantPattern: /^[A-Z][A-Z0-9_]*$/,
921
969
  exceptions: [
922
- "__init__",
923
- "__str__",
924
- "__repr__",
925
- "__name__",
926
- "__main__",
927
- "__file__",
928
- "__doc__",
929
- "__all__",
930
- "__version__",
931
- "__author__",
932
- "__dict__",
933
- "__class__",
934
- "__module__",
935
- "__bases__"
970
+ PYTHON_CONSTANTS.SPECIAL.DUNDER_INIT,
971
+ PYTHON_CONSTANTS.SPECIAL.DUNDER_STR,
972
+ PYTHON_CONSTANTS.SPECIAL.DUNDER_REPR,
973
+ PYTHON_CONSTANTS.SPECIAL.DUNDER_NAME,
974
+ PYTHON_CONSTANTS.SPECIAL.DUNDER_MAIN,
975
+ PYTHON_CONSTANTS.SPECIAL.DUNDER_FILE,
976
+ PYTHON_CONSTANTS.SPECIAL.DUNDER_DOC,
977
+ PYTHON_CONSTANTS.SPECIAL.DUNDER_ALL,
978
+ PYTHON_CONSTANTS.SPECIAL.DUNDER_VERSION,
979
+ PYTHON_CONSTANTS.SPECIAL.DUNDER_AUTHOR,
980
+ PYTHON_CONSTANTS.SPECIAL.DUNDER_DICT,
981
+ PYTHON_CONSTANTS.SPECIAL.DUNDER_CLASS,
982
+ PYTHON_CONSTANTS.SPECIAL.DUNDER_MODULE,
983
+ PYTHON_CONSTANTS.SPECIAL.DUNDER_BASES
936
984
  ]
937
985
  };
938
986
  }
@@ -966,10 +1014,10 @@ var init_python_parser = __esm({
966
1014
  if (fromMatch) {
967
1015
  const module2 = fromMatch[1];
968
1016
  const importsStr = fromMatch[2];
969
- if (importsStr.trim() === "*") {
1017
+ if (importsStr.trim() === PYTHON_CONSTANTS.SPECIAL.WILDCARD) {
970
1018
  imports.push({
971
1019
  source: module2,
972
- specifiers: ["*"],
1020
+ specifiers: [PYTHON_CONSTANTS.SPECIAL.WILDCARD],
973
1021
  loc: {
974
1022
  start: { line: idx + 1, column: 0 },
975
1023
  end: { line: idx + 1, column: line.length }
@@ -1003,7 +1051,7 @@ var init_python_parser = __esm({
1003
1051
  if (classMatch) {
1004
1052
  exports2.push({
1005
1053
  name: classMatch[1],
1006
- type: "class",
1054
+ type: PYTHON_CONSTANTS.TYPES.CLASS,
1007
1055
  visibility: "public",
1008
1056
  isPure: true,
1009
1057
  hasSideEffects: false,
@@ -1029,14 +1077,14 @@ var init_python_parser = __esm({
1029
1077
  if (nextLine.trim() && !nextLine.trim().startsWith('"""') && !nextLine.trim().startsWith("'''"))
1030
1078
  break;
1031
1079
  }
1032
- const isImpure = name.toLowerCase().includes("impure") || line.includes("print(") || idx + 1 < lines.length && lines[idx + 1].includes("print(");
1080
+ const isImpure = name.toLowerCase().includes("impure") || line.includes(PYTHON_CONSTANTS.BUILTINS.PRINT) || idx + 1 < lines.length && lines[idx + 1].includes(PYTHON_CONSTANTS.BUILTINS.PRINT);
1033
1081
  exports2.push({
1034
1082
  name,
1035
- type: "function",
1083
+ type: PYTHON_CONSTANTS.TYPES.FUNCTION,
1036
1084
  visibility: "public",
1037
1085
  isPure: !isImpure,
1038
1086
  hasSideEffects: isImpure,
1039
- documentation: docContent ? { content: docContent, type: "docstring" } : void 0,
1087
+ documentation: docContent ? { content: docContent, type: PYTHON_CONSTANTS.TYPES.DOCSTRING } : void 0,
1040
1088
  loc: {
1041
1089
  start: { line: idx + 1, column: 0 },
1042
1090
  end: { line: idx + 1, column: line.length }
package/dist/index.mjs CHANGED
@@ -58,7 +58,7 @@ import {
58
58
  } from "./chunk-UTCRW3N7.mjs";
59
59
  import {
60
60
  PythonParser
61
- } from "./chunk-SM6INS52.mjs";
61
+ } from "./chunk-WH4ZGRVF.mjs";
62
62
  import {
63
63
  JavaParser
64
64
  } from "./chunk-SWZOT67M.mjs";
@@ -912,7 +912,7 @@ var ParserFactory = class _ParserFactory {
912
912
  return new TypeScriptParser2();
913
913
  });
914
914
  this.registerLazyParser("python" /* Python */, async () => {
915
- const { PythonParser: PythonParser2 } = await import("./python-parser-SJ3LFZFJ.mjs");
915
+ const { PythonParser: PythonParser2 } = await import("./python-parser-7QISP7LK.mjs");
916
916
  return new PythonParser2();
917
917
  });
918
918
  this.registerLazyParser("java" /* Java */, async () => {
@@ -0,0 +1,8 @@
1
+ import {
2
+ PythonParser
3
+ } from "./chunk-WH4ZGRVF.mjs";
4
+ import "./chunk-2N7ISIKE.mjs";
5
+ import "./chunk-U3IY2CFC.mjs";
6
+ export {
7
+ PythonParser
8
+ };
@@ -0,0 +1,8 @@
1
+ import {
2
+ PythonParser
3
+ } from "./chunk-MPWWAAHQ.mjs";
4
+ import "./chunk-2N7ISIKE.mjs";
5
+ import "./chunk-U3IY2CFC.mjs";
6
+ export {
7
+ PythonParser
8
+ };
@@ -0,0 +1,8 @@
1
+ import {
2
+ PythonParser
3
+ } from "./chunk-XQSEJ7WN.mjs";
4
+ import "./chunk-2N7ISIKE.mjs";
5
+ import "./chunk-U3IY2CFC.mjs";
6
+ export {
7
+ PythonParser
8
+ };
@@ -0,0 +1,8 @@
1
+ import {
2
+ PythonParser
3
+ } from "./chunk-LEITCMH3.mjs";
4
+ import "./chunk-2N7ISIKE.mjs";
5
+ import "./chunk-U3IY2CFC.mjs";
6
+ export {
7
+ PythonParser
8
+ };
@@ -0,0 +1,8 @@
1
+ import {
2
+ PythonParser
3
+ } from "./chunk-AZRUQG5T.mjs";
4
+ import "./chunk-2N7ISIKE.mjs";
5
+ import "./chunk-U3IY2CFC.mjs";
6
+ export {
7
+ PythonParser
8
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiready/core",
3
- "version": "0.24.3",
3
+ "version": "0.24.5",
4
4
  "description": "Shared utilities for AIReady analysis tools",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",