tskb 0.0.1

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 (75) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1086 -0
  3. package/dist/cli/commands/build.d.ts +55 -0
  4. package/dist/cli/commands/build.d.ts.map +1 -0
  5. package/dist/cli/commands/build.js +105 -0
  6. package/dist/cli/commands/build.js.map +1 -0
  7. package/dist/cli/commands/query.d.ts +10 -0
  8. package/dist/cli/commands/query.d.ts.map +1 -0
  9. package/dist/cli/commands/query.js +399 -0
  10. package/dist/cli/commands/query.js.map +1 -0
  11. package/dist/cli/commands/visualize.d.ts +10 -0
  12. package/dist/cli/commands/visualize.d.ts.map +1 -0
  13. package/dist/cli/commands/visualize.js +26 -0
  14. package/dist/cli/commands/visualize.js.map +1 -0
  15. package/dist/cli/index.d.ts +9 -0
  16. package/dist/cli/index.d.ts.map +1 -0
  17. package/dist/cli/index.js +109 -0
  18. package/dist/cli/index.js.map +1 -0
  19. package/dist/core/extraction/documentation.d.ts +28 -0
  20. package/dist/core/extraction/documentation.d.ts.map +1 -0
  21. package/dist/core/extraction/documentation.js +330 -0
  22. package/dist/core/extraction/documentation.js.map +1 -0
  23. package/dist/core/extraction/index.d.ts +11 -0
  24. package/dist/core/extraction/index.d.ts.map +1 -0
  25. package/dist/core/extraction/index.js +9 -0
  26. package/dist/core/extraction/index.js.map +1 -0
  27. package/dist/core/extraction/registry.d.ts +40 -0
  28. package/dist/core/extraction/registry.d.ts.map +1 -0
  29. package/dist/core/extraction/registry.js +604 -0
  30. package/dist/core/extraction/registry.js.map +1 -0
  31. package/dist/core/graph/builder.d.ts +37 -0
  32. package/dist/core/graph/builder.d.ts.map +1 -0
  33. package/dist/core/graph/builder.js +421 -0
  34. package/dist/core/graph/builder.js.map +1 -0
  35. package/dist/core/graph/index.d.ts +23 -0
  36. package/dist/core/graph/index.d.ts.map +1 -0
  37. package/dist/core/graph/index.js +25 -0
  38. package/dist/core/graph/index.js.map +1 -0
  39. package/dist/core/graph/types.d.ts +128 -0
  40. package/dist/core/graph/types.d.ts.map +1 -0
  41. package/dist/core/graph/types.js +9 -0
  42. package/dist/core/graph/types.js.map +1 -0
  43. package/dist/core/visualization/dot-generator.d.ts +13 -0
  44. package/dist/core/visualization/dot-generator.d.ts.map +1 -0
  45. package/dist/core/visualization/dot-generator.js +200 -0
  46. package/dist/core/visualization/dot-generator.js.map +1 -0
  47. package/dist/core/visualization/index.d.ts +20 -0
  48. package/dist/core/visualization/index.d.ts.map +1 -0
  49. package/dist/core/visualization/index.js +23 -0
  50. package/dist/core/visualization/index.js.map +1 -0
  51. package/dist/index.d.ts +9 -0
  52. package/dist/index.d.ts.map +1 -0
  53. package/dist/index.js +8 -0
  54. package/dist/index.js.map +1 -0
  55. package/dist/jsx-runtime.d.ts +7 -0
  56. package/dist/jsx-runtime.d.ts.map +1 -0
  57. package/dist/jsx-runtime.js +11 -0
  58. package/dist/jsx-runtime.js.map +1 -0
  59. package/dist/runtime/jsx.d.ts +84 -0
  60. package/dist/runtime/jsx.d.ts.map +1 -0
  61. package/dist/runtime/jsx.js +93 -0
  62. package/dist/runtime/jsx.js.map +1 -0
  63. package/dist/runtime/registry.d.ts +61 -0
  64. package/dist/runtime/registry.d.ts.map +1 -0
  65. package/dist/runtime/registry.js +2 -0
  66. package/dist/runtime/registry.js.map +1 -0
  67. package/dist/typescript/index.d.ts +7 -0
  68. package/dist/typescript/index.d.ts.map +1 -0
  69. package/dist/typescript/index.js +7 -0
  70. package/dist/typescript/index.js.map +1 -0
  71. package/dist/typescript/program.d.ts +33 -0
  72. package/dist/typescript/program.d.ts.map +1 -0
  73. package/dist/typescript/program.js +84 -0
  74. package/dist/typescript/program.js.map +1 -0
  75. package/package.json +73 -0
@@ -0,0 +1,84 @@
1
+ import ts from "typescript";
2
+ import path from "node:path";
3
+ /**
4
+ * Creates a TypeScript Program from a list of files and a tsconfig.
5
+ *
6
+ * WHAT IS A TYPESCRIPT PROGRAM?
7
+ * It's TypeScript compiler's internal representation of your code:
8
+ * - Source files (parsed into AST)
9
+ * - Type checker (resolves types, finds symbols)
10
+ * - Compiler options (from tsconfig.json)
11
+ *
12
+ * WHY WE NEED IT:
13
+ * We're not compiling code, we're ANALYZING it. The TypeScript compiler
14
+ * API gives us tools to:
15
+ * 1. Parse .ts/.tsx files into syntax trees
16
+ * 2. Resolve types (what is Context<{...}>?)
17
+ * 3. Find symbols (where is "tskb" namespace defined?)
18
+ * 4. Walk ASTs to extract information
19
+ *
20
+ * THE PROCESS:
21
+ * 1. Read tsconfig.json using ts.readConfigFile
22
+ * 2. Parse it to get compiler options
23
+ * 3. Create a Program with our files + those options
24
+ * 4. Set noEmit=true because we're only reading, not compiling
25
+ *
26
+ * RESULT:
27
+ * A Program object we can query to extract registry and docs.
28
+ *
29
+ * @param files - Array of absolute file paths to analyze
30
+ * @param tsconfigPath - Path to tsconfig.json (for compiler options)
31
+ * @returns TypeScript Program ready for analysis
32
+ */
33
+ export function createProgram(files, tsconfigPath) {
34
+ // Read and parse tsconfig.json to get compiler options
35
+ const configFile = ts.readConfigFile(tsconfigPath, ts.sys.readFile);
36
+ if (configFile.error) {
37
+ throw new Error(`Failed to read tsconfig: ${configFile.error.messageText}`);
38
+ }
39
+ const configParseResult = ts.parseJsonConfigFileContent(configFile.config, ts.sys, path.dirname(tsconfigPath));
40
+ if (configParseResult.errors.length > 0) {
41
+ const errorMessages = configParseResult.errors.map((err) => err.messageText).join("\n");
42
+ throw new Error(`Failed to parse tsconfig: ${errorMessages}`);
43
+ }
44
+ // Create compiler options, merging with our needs
45
+ const compilerOptions = {
46
+ ...configParseResult.options,
47
+ noEmit: true, // We don't need to emit JavaScript, just analyze the TypeScript AST
48
+ };
49
+ // Create the TypeScript Program
50
+ // This parses all files, builds the AST, and creates a type checker
51
+ const program = ts.createProgram({
52
+ rootNames: files,
53
+ options: compilerOptions,
54
+ });
55
+ // Check for TypeScript errors only in the specified files (not dependencies)
56
+ const fileSet = new Set(files.map((f) => path.normalize(f)));
57
+ const allDiagnostics = [
58
+ ...program.getSyntacticDiagnostics(),
59
+ ...program.getSemanticDiagnostics(),
60
+ ];
61
+ // Filter diagnostics to only include errors from the files we're analyzing
62
+ const diagnostics = allDiagnostics.filter((diagnostic) => {
63
+ if (!diagnostic.file)
64
+ return false;
65
+ return fileSet.has(path.normalize(diagnostic.file.fileName));
66
+ });
67
+ if (diagnostics.length > 0) {
68
+ const errorMessages = diagnostics
69
+ .map((diagnostic) => {
70
+ if (diagnostic.file) {
71
+ const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
72
+ const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
73
+ return `${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`;
74
+ }
75
+ else {
76
+ return ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
77
+ }
78
+ })
79
+ .join("\n");
80
+ throw new Error(`TypeScript compilation errors:\n${errorMessages}`);
81
+ }
82
+ return program;
83
+ }
84
+ //# sourceMappingURL=program.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"program.js","sourceRoot":"","sources":["../../src/typescript/program.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,UAAU,aAAa,CAAC,KAAe,EAAE,YAAoB;IACjE,uDAAuD;IACvD,MAAM,UAAU,GAAG,EAAE,CAAC,cAAc,CAAC,YAAY,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAEpE,IAAI,UAAU,CAAC,KAAK,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,4BAA4B,UAAU,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC;IAC9E,CAAC;IAED,MAAM,iBAAiB,GAAG,EAAE,CAAC,0BAA0B,CACrD,UA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,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC3B,MAAM,aAAa,GAAG,WAAW;aAC9B,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE;YAClB,IAAI,UAAU,CAAC,IAAI,EAAE,CAAC;gBACpB,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,UAAU,CAAC,IAAI,CAAC,6BAA6B,CACvE,UAAU,CAAC,KAAM,CAClB,CAAC;gBACF,MAAM,OAAO,GAAG,EAAE,CAAC,4BAA4B,CAAC,UAAU,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;gBAC9E,OAAO,GAAG,UAAU,CAAC,IAAI,CAAC,QAAQ,KAAK,IAAI,GAAG,CAAC,IAAI,SAAS,GAAG,CAAC,MAAM,OAAO,EAAE,CAAC;YAClF,CAAC;iBAAM,CAAC;gBACN,OAAO,EAAE,CAAC,4BAA4B,CAAC,UAAU,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;YACvE,CAAC;QACH,CAAC,CAAC;aACD,IAAI,CAAC,IAAI,CAAC,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,mCAAmC,aAAa,EAAE,CAAC,CAAC;IACtE,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "tskb",
3
+ "version": "0.0.1",
4
+ "description": "TS Knowledge Base. A TypeScript-native DSL for expressing architectural intent as typed declarations. Produces renderable docs/diagrams and a queryable knowledge graph, supporting type-checked snippet references, semantic relations, and constraints.",
5
+ "type": "module",
6
+ "bin": {
7
+ "tskb": "./dist/cli/index.js"
8
+ },
9
+ "main": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "files": [
12
+ "dist",
13
+ "LICENSE"
14
+ ],
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/index.d.ts",
18
+ "import": "./dist/index.js"
19
+ },
20
+ "./jsx-runtime": {
21
+ "types": "./dist/jsx-runtime.d.ts",
22
+ "import": "./dist/jsx-runtime.js"
23
+ }
24
+ },
25
+ "scripts": {
26
+ "build": "tsc",
27
+ "dev": "tsc --watch",
28
+ "clean": "rimraf dist",
29
+ "pack:test": "npm run build && npm pack",
30
+ "prepublishOnly": "npm run clean && npm run build",
31
+ "test": "echo \"Error: no test specified\" && exit 0"
32
+ },
33
+ "author": "Dimitar Mihaylov",
34
+ "license": "MIT",
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "https://github.com/mitk0936/tskb.git"
38
+ },
39
+ "keywords": [
40
+ "typescript",
41
+ "documentation",
42
+ "architecture",
43
+ "knowledge-graph",
44
+ "docs-as-code",
45
+ "architecture-as-code",
46
+ "jsx",
47
+ "tsx",
48
+ "type-safe",
49
+ "compiler",
50
+ "validation",
51
+ "ai",
52
+ "graphviz",
53
+ "monorepo",
54
+ "diagrams",
55
+ "visualization",
56
+ "architectural-documentation",
57
+ "dsl",
58
+ "developer-tools",
59
+ "code-documentation",
60
+ "living-documentation",
61
+ "static-analysis",
62
+ "code-graph"
63
+ ],
64
+ "dependencies": {
65
+ "glob": "^13.0.0"
66
+ },
67
+ "peerDependencies": {
68
+ "typescript": ">=5.0.0"
69
+ },
70
+ "devDependencies": {
71
+ "typescript": "^5.9.3"
72
+ }
73
+ }