@0xsarwagya/ontoly-cache 0.1.0-alpha.13 → 0.1.0-alpha.15

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 CHANGED
@@ -4,6 +4,15 @@ Local graph artifact persistence for Ontoly.
4
4
 
5
5
  This package is part of [Ontoly](https://github.com/0xsarwagya/ontoly), a TypeScript-native software intelligence engine that builds a deterministic Software Graph.
6
6
 
7
+ ## Responsibility
8
+
9
+ `@0xsarwagya/ontoly-cache` reads and writes local graph artifacts, indexes, and
10
+ cache metadata. It does not decide artifact meaning, perform graph construction,
11
+ run queries, or expose user-facing commands.
12
+
13
+ See the repository [architecture map](../../ARCHITECTURE.md) for package
14
+ boundaries.
15
+
7
16
  ## Installation
8
17
 
9
18
  ```bash
@@ -12,10 +21,10 @@ pnpm add @0xsarwagya/ontoly-cache
12
21
 
13
22
  ## Status
14
23
 
15
- Alpha package for Ontoly v0.1.0-alpha.13. The public API is versioned with the Software Graph and RFC process.
24
+ Public Preview package for Ontoly v0.1.0-alpha.15. The public API is versioned with the Software Graph and RFC process.
16
25
 
17
26
  ## Links
18
27
 
19
28
  - [Repository](https://github.com/0xsarwagya/ontoly)
20
- - [Documentation](https://oss.sarwagya.wtf/ontoly)
29
+ - [Documentation](https://ontoly.sarwagya.wtf)
21
30
  - [Issues](https://github.com/0xsarwagya/ontoly/issues)
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAEL,KAAK,aAAa,EACnB,MAAM,yBAAyB,CAAC;AAEjC,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ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B,iBAAiB,CAAC,CAAC,EACvC,OAAO,EAAE,mBAAmB,EAC5B,QAAQ,EAAE,CAAC,GACV,OAAO,CAAC,CAAC,CAAC,CAaZ"}
package/dist/index.js CHANGED
@@ -2,7 +2,8 @@
2
2
  import { mkdir, readFile, writeFile } from "fs/promises";
3
3
  import { isAbsolute, join } from "path";
4
4
  import {
5
- createSemanticIndex
5
+ createSemanticIndex,
6
+ validateSemanticIndex
6
7
  } from "@0xsarwagya/ontoly-core";
7
8
  function getGraphArtifactPaths(options) {
8
9
  const outputDirectory = options.directory ?? ".ontoly";
@@ -46,16 +47,27 @@ async function loadSemanticIndex(options) {
46
47
  return JSON.parse(contents);
47
48
  }
48
49
  async function loadOrCreateSemanticIndex(options) {
50
+ const paths = getGraphArtifactPaths(options);
49
51
  try {
50
- return await loadSemanticIndex(options);
52
+ const [semanticIndex, graph] = await Promise.all([
53
+ loadSemanticIndex(options),
54
+ loadGraph(options)
55
+ ]);
56
+ if (validateSemanticIndex(semanticIndex, graph).length === 0) {
57
+ return semanticIndex;
58
+ }
59
+ const rebuilt = createSemanticIndex(graph);
60
+ await mkdir(paths.directory, { recursive: true });
61
+ await writeJson(paths.semanticIndex, rebuilt);
62
+ return rebuilt;
51
63
  } catch (error) {
52
64
  if (!isMissingFileError(error)) {
53
65
  throw error;
54
66
  }
55
67
  const graph = await loadGraph(options);
56
68
  const semanticIndex = createSemanticIndex(graph);
57
- await mkdir(getGraphArtifactPaths(options).directory, { recursive: true });
58
- await writeJson(getGraphArtifactPaths(options).semanticIndex, semanticIndex);
69
+ await mkdir(paths.directory, { recursive: true });
70
+ await writeJson(paths.semanticIndex, semanticIndex);
59
71
  return semanticIndex;
60
72
  }
61
73
  }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport { isAbsolute, join } from \"node:path\";\nimport type { SoftwareGraph } from \"@0xsarwagya/ontoly-core\";\nimport {\n createSemanticIndex,\n type SemanticIndex,\n} from \"@0xsarwagya/ontoly-core\";\n\nexport interface GraphArtifactPaths {\n readonly root: string;\n readonly directory: string;\n readonly graph: string;\n readonly legacyGraph: string;\n readonly diagnostics: string;\n readonly metadata: string;\n readonly indexes: string;\n readonly semanticIndex: string;\n readonly statistics: string;\n readonly cache: string;\n}\n\nexport interface PersistGraphOptions {\n readonly root: string;\n readonly directory?: string | undefined;\n}\n\nexport function getGraphArtifactPaths(options: PersistGraphOptions): GraphArtifactPaths {\n const outputDirectory = options.directory ?? \".ontoly\";\n const directory = isAbsolute(outputDirectory) ? outputDirectory : join(options.root, outputDirectory);\n\n return {\n root: options.root,\n directory,\n graph: join(directory, \"SoftwareGraph.json\"),\n legacyGraph: join(directory, \"graph.json\"),\n diagnostics: join(directory, \"diagnostics.json\"),\n metadata: join(directory, \"metadata.json\"),\n indexes: join(directory, \"indexes.json\"),\n semanticIndex: join(directory, \"index.json\"),\n statistics: join(directory, \"statistics.json\"),\n cache: join(directory, \"cache.json\"),\n };\n}\n\nexport async function persistGraph(\n graph: SoftwareGraph,\n options: PersistGraphOptions,\n): Promise<GraphArtifactPaths> {\n const paths = getGraphArtifactPaths(options);\n const semanticIndex = createSemanticIndex(graph);\n await mkdir(paths.directory, { recursive: true });\n\n await Promise.all([\n writeJson(paths.graph, graph),\n writeJson(paths.legacyGraph, graph),\n writeJson(paths.diagnostics, graph.diagnostics),\n writeJson(paths.metadata, graph.metadata),\n writeJson(paths.indexes, graph.indexes),\n writeJson(paths.semanticIndex, semanticIndex),\n writeJson(paths.statistics, createGraphStatistics(graph)),\n ]);\n\n return paths;\n}\n\nexport async function loadGraph(options: PersistGraphOptions): Promise<SoftwareGraph> {\n const paths = getGraphArtifactPaths(options);\n const contents = await readFirstExisting([paths.graph, paths.legacyGraph]);\n return JSON.parse(contents) as SoftwareGraph;\n}\n\nexport async function loadSemanticIndex(options: PersistGraphOptions): Promise<SemanticIndex> {\n const paths = getGraphArtifactPaths(options);\n const contents = await readFile(paths.semanticIndex, \"utf8\");\n return JSON.parse(contents) as SemanticIndex;\n}\n\nexport async function loadOrCreateSemanticIndex(options: PersistGraphOptions): Promise<SemanticIndex> {\n try {\n return await loadSemanticIndex(options);\n } catch (error) {\n if (!isMissingFileError(error)) {\n throw error;\n }\n const graph = await loadGraph(options);\n const semanticIndex = createSemanticIndex(graph);\n await mkdir(getGraphArtifactPaths(options).directory, { recursive: true });\n await writeJson(getGraphArtifactPaths(options).semanticIndex, semanticIndex);\n return semanticIndex;\n }\n}\n\nexport async function persistCompilerCache(\n options: PersistGraphOptions,\n cache: unknown,\n): Promise<GraphArtifactPaths> {\n const paths = getGraphArtifactPaths(options);\n await mkdir(paths.directory, { recursive: true });\n await writeJson(paths.cache, cache);\n return paths;\n}\n\nexport async function loadCompilerCache<T>(\n options: PersistGraphOptions,\n fallback: T,\n): Promise<T> {\n const paths = getGraphArtifactPaths(options);\n\n try {\n const contents = await readFile(paths.cache, \"utf8\");\n return JSON.parse(contents) as T;\n } catch (error) {\n if (isMissingFileError(error)) {\n return fallback;\n }\n\n throw error;\n }\n}\n\nasync function writeJson(path: string, value: unknown): Promise<void> {\n await writeFile(path, `${JSON.stringify(value, null, 2)}\\n`, \"utf8\");\n}\n\nasync function readFirstExisting(paths: readonly string[]): Promise<string> {\n let lastError: unknown;\n\n for (const path of paths) {\n try {\n return await readFile(path, \"utf8\");\n } catch (error) {\n lastError = error;\n }\n }\n\n throw lastError;\n}\n\nfunction createGraphStatistics(graph: SoftwareGraph): Record<string, unknown> {\n return {\n files: graph.metadata.fileCount,\n nodes: graph.nodes.length,\n edges: graph.edges.length,\n diagnostics: graph.diagnostics.length,\n nodesByType: countBy(graph.nodes.map((node) => node.type)),\n edgesByType: countBy(graph.edges.map((edge) => edge.type)),\n parserVersions: graph.metadata.parserVersions,\n deterministicHash: graph.metadata.deterministicHash,\n };\n}\n\nfunction countBy(values: readonly string[]): Record<string, number> {\n return Object.fromEntries(\n [...values.reduce((counts, value) => {\n counts.set(value, (counts.get(value) ?? 0) + 1);\n return counts;\n }, new Map<string, number>()).entries()].sort(([left], [right]) => left.localeCompare(right)),\n );\n}\n\nfunction isMissingFileError(error: unknown): boolean {\n return (\n typeof error === \"object\" &&\n error !== null &&\n \"code\" in error &&\n (error as { readonly code?: unknown }).code === \"ENOENT\"\n );\n}\n"],"mappings":";AAAA,SAAS,OAAO,UAAU,iBAAiB;AAC3C,SAAS,YAAY,YAAY;AAEjC;AAAA,EACE;AAAA,OAEK;AAoBA,SAAS,sBAAsB,SAAkD;AACtF,QAAM,kBAAkB,QAAQ,aAAa;AAC7C,QAAM,YAAY,WAAW,eAAe,IAAI,kBAAkB,KAAK,QAAQ,MAAM,eAAe;AAEpG,SAAO;AAAA,IACL,MAAM,QAAQ;AAAA,IACd;AAAA,IACA,OAAO,KAAK,WAAW,oBAAoB;AAAA,IAC3C,aAAa,KAAK,WAAW,YAAY;AAAA,IACzC,aAAa,KAAK,WAAW,kBAAkB;AAAA,IAC/C,UAAU,KAAK,WAAW,eAAe;AAAA,IACzC,SAAS,KAAK,WAAW,cAAc;AAAA,IACvC,eAAe,KAAK,WAAW,YAAY;AAAA,IAC3C,YAAY,KAAK,WAAW,iBAAiB;AAAA,IAC7C,OAAO,KAAK,WAAW,YAAY;AAAA,EACrC;AACF;AAEA,eAAsB,aACpB,OACA,SAC6B;AAC7B,QAAM,QAAQ,sBAAsB,OAAO;AAC3C,QAAM,gBAAgB,oBAAoB,KAAK;AAC/C,QAAM,MAAM,MAAM,WAAW,EAAE,WAAW,KAAK,CAAC;AAEhD,QAAM,QAAQ,IAAI;AAAA,IAChB,UAAU,MAAM,OAAO,KAAK;AAAA,IAC5B,UAAU,MAAM,aAAa,KAAK;AAAA,IAClC,UAAU,MAAM,aAAa,MAAM,WAAW;AAAA,IAC9C,UAAU,MAAM,UAAU,MAAM,QAAQ;AAAA,IACxC,UAAU,MAAM,SAAS,MAAM,OAAO;AAAA,IACtC,UAAU,MAAM,eAAe,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AEA,eAAe,UAAU,MAAc,OAA+B;AACpE,QAAM,UAAU,MAAM,GAAG,KAAK,UAAU,OAAO,MAAM,CAAC,CAAC;AAAA,GAAM,MAAM;AACrE;AAEA,eAAe,kBAAkB,OAA2C;AAC1E,MAAI;AAEJ,aAAW,QAAQ,OAAO;AACxB,QAAI;AACF,aAAO,MAAM,SAAS,MAAM,MAAM;AAAA,IACpC,SAAS,OAAO;AACd,kBAAY;AAAA,IACd;AAAA,EACF;AAEA,QAAM;AACR;AAEA,SAAS,sBAAsB,OAA+C;AAC5E,SAAO;AAAA,IACL,OAAO,MAAM,SAAS;AAAA,IACtB,OAAO,MAAM,MAAM;AAAA,IACnB,OAAO,MAAM,MAAM;AAAA,IACnB,aAAa,MAAM,YAAY;AAAA,IAC/B,aAAa,QAAQ,MAAM,MAAM,IAAI,CAAC,SAAS,KAAK,IAAI,CAAC;AAAA,IACzD,aAAa,QAAQ,MAAM,MAAM,IAAI,CAAC,SAAS,KAAK,IAAI,CAAC;AAAA,IACzD,gBAAgB,MAAM,SAAS;AAAA,IAC/B,mBAAmB,MAAM,SAAS;AAAA,EACpC;AACF;AAEA,SAAS,QAAQ,QAAmD;AAClE,SAAO,OAAO;AAAA,IACZ,CAAC,GAAG,OAAO,OAAO,CAAC,QAAQ,UAAU;AACnC,aAAO,IAAI,QAAQ,OAAO,IAAI,KAAK,KAAK,KAAK,CAAC;AAC9C,aAAO;AAAA,IACT,GAAG,oBAAI,IAAoB,CAAC,EAAE,QAAQ,CAAC,EAAE,KAAK,CAAC,CAAC,IAAI,GAAG,CAAC,KAAK,MAAM,KAAK,cAAc,KAAK,CAAC;AAAA,EAC9F;AACF;AAEA,SAAS,mBAAmB,OAAyB;AACnD,SACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACT,MAAsC,SAAS;AAEpD;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport { isAbsolute, join } from \"node:path\";\nimport type { SoftwareGraph } from \"@0xsarwagya/ontoly-core\";\nimport {\n createSemanticIndex,\n validateSemanticIndex,\n type SemanticIndex,\n} from \"@0xsarwagya/ontoly-core\";\n\nexport interface GraphArtifactPaths {\n readonly root: string;\n readonly directory: string;\n readonly graph: string;\n readonly legacyGraph: string;\n readonly diagnostics: string;\n readonly metadata: string;\n readonly indexes: string;\n readonly semanticIndex: string;\n readonly statistics: string;\n readonly cache: string;\n}\n\nexport interface PersistGraphOptions {\n readonly root: string;\n readonly directory?: string | undefined;\n}\n\nexport function getGraphArtifactPaths(options: PersistGraphOptions): GraphArtifactPaths {\n const outputDirectory = options.directory ?? \".ontoly\";\n const directory = isAbsolute(outputDirectory) ? outputDirectory : join(options.root, outputDirectory);\n\n return {\n root: options.root,\n directory,\n graph: join(directory, \"SoftwareGraph.json\"),\n legacyGraph: join(directory, \"graph.json\"),\n diagnostics: join(directory, \"diagnostics.json\"),\n metadata: join(directory, \"metadata.json\"),\n indexes: join(directory, \"indexes.json\"),\n semanticIndex: join(directory, \"index.json\"),\n statistics: join(directory, \"statistics.json\"),\n cache: join(directory, \"cache.json\"),\n };\n}\n\nexport async function persistGraph(\n graph: SoftwareGraph,\n options: PersistGraphOptions,\n): Promise<GraphArtifactPaths> {\n const paths = getGraphArtifactPaths(options);\n const semanticIndex = createSemanticIndex(graph);\n await mkdir(paths.directory, { recursive: true });\n\n await Promise.all([\n writeJson(paths.graph, graph),\n writeJson(paths.legacyGraph, graph),\n writeJson(paths.diagnostics, graph.diagnostics),\n writeJson(paths.metadata, graph.metadata),\n writeJson(paths.indexes, graph.indexes),\n writeJson(paths.semanticIndex, semanticIndex),\n writeJson(paths.statistics, createGraphStatistics(graph)),\n ]);\n\n return paths;\n}\n\nexport async function loadGraph(options: PersistGraphOptions): Promise<SoftwareGraph> {\n const paths = getGraphArtifactPaths(options);\n const contents = await readFirstExisting([paths.graph, paths.legacyGraph]);\n return JSON.parse(contents) as SoftwareGraph;\n}\n\nexport async function loadSemanticIndex(options: PersistGraphOptions): Promise<SemanticIndex> {\n const paths = getGraphArtifactPaths(options);\n const contents = await readFile(paths.semanticIndex, \"utf8\");\n return JSON.parse(contents) as SemanticIndex;\n}\n\nexport async function loadOrCreateSemanticIndex(options: PersistGraphOptions): Promise<SemanticIndex> {\n const paths = getGraphArtifactPaths(options);\n\n try {\n const [semanticIndex, graph] = await Promise.all([\n loadSemanticIndex(options),\n loadGraph(options),\n ]);\n if (validateSemanticIndex(semanticIndex, graph).length === 0) {\n return semanticIndex;\n }\n const rebuilt = createSemanticIndex(graph);\n await mkdir(paths.directory, { recursive: true });\n await writeJson(paths.semanticIndex, rebuilt);\n return rebuilt;\n } catch (error) {\n if (!isMissingFileError(error)) {\n throw error;\n }\n const graph = await loadGraph(options);\n const semanticIndex = createSemanticIndex(graph);\n await mkdir(paths.directory, { recursive: true });\n await writeJson(paths.semanticIndex, semanticIndex);\n return semanticIndex;\n }\n}\n\nexport async function persistCompilerCache(\n options: PersistGraphOptions,\n cache: unknown,\n): Promise<GraphArtifactPaths> {\n const paths = getGraphArtifactPaths(options);\n await mkdir(paths.directory, { recursive: true });\n await writeJson(paths.cache, cache);\n return paths;\n}\n\nexport async function loadCompilerCache<T>(\n options: PersistGraphOptions,\n fallback: T,\n): Promise<T> {\n const paths = getGraphArtifactPaths(options);\n\n try {\n const contents = await readFile(paths.cache, \"utf8\");\n return JSON.parse(contents) as T;\n } catch (error) {\n if (isMissingFileError(error)) {\n return fallback;\n }\n\n throw error;\n }\n}\n\nasync function writeJson(path: string, value: unknown): Promise<void> {\n await writeFile(path, `${JSON.stringify(value, null, 2)}\\n`, \"utf8\");\n}\n\nasync function readFirstExisting(paths: readonly string[]): Promise<string> {\n let lastError: unknown;\n\n for (const path of paths) {\n try {\n return await readFile(path, \"utf8\");\n } catch (error) {\n lastError = error;\n }\n }\n\n throw lastError;\n}\n\nfunction createGraphStatistics(graph: SoftwareGraph): Record<string, unknown> {\n return {\n files: graph.metadata.fileCount,\n nodes: graph.nodes.length,\n edges: graph.edges.length,\n diagnostics: graph.diagnostics.length,\n nodesByType: countBy(graph.nodes.map((node) => node.type)),\n edgesByType: countBy(graph.edges.map((edge) => edge.type)),\n parserVersions: graph.metadata.parserVersions,\n deterministicHash: graph.metadata.deterministicHash,\n };\n}\n\nfunction countBy(values: readonly string[]): Record<string, number> {\n return Object.fromEntries(\n [...values.reduce((counts, value) => {\n counts.set(value, (counts.get(value) ?? 0) + 1);\n return counts;\n }, new Map<string, number>()).entries()].sort(([left], [right]) => left.localeCompare(right)),\n );\n}\n\nfunction isMissingFileError(error: unknown): boolean {\n return (\n typeof error === \"object\" &&\n error !== null &&\n \"code\" in error &&\n (error as { readonly code?: unknown }).code === \"ENOENT\"\n );\n}\n"],"mappings":";AAAA,SAAS,OAAO,UAAU,iBAAiB;AAC3C,SAAS,YAAY,YAAY;AAEjC;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AAoBA,SAAS,sBAAsB,SAAkD;AACtF,QAAM,kBAAkB,QAAQ,aAAa;AAC7C,QAAM,YAAY,WAAW,eAAe,IAAI,kBAAkB,KAAK,QAAQ,MAAM,eAAe;AAEpG,SAAO;AAAA,IACL,MAAM,QAAQ;AAAA,IACd;AAAA,IACA,OAAO,KAAK,WAAW,oBAAoB;AAAA,IAC3C,aAAa,KAAK,WAAW,YAAY;AAAA,IACzC,aAAa,KAAK,WAAW,kBAAkB;AAAA,IAC/C,UAAU,KAAK,WAAW,eAAe;AAAA,IACzC,SAAS,KAAK,WAAW,cAAc;AAAA,IACvC,eAAe,KAAK,WAAW,YAAY;AAAA,IAC3C,YAAY,KAAK,WAAW,iBAAiB;AAAA,IAC7C,OAAO,KAAK,WAAW,YAAY;AAAA,EACrC;AACF;AAEA,eAAsB,aACpB,OACA,SAC6B;AAC7B,QAAM,QAAQ,sBAAsB,OAAO;AAC3C,QAAM,gBAAgB,oBAAoB,KAAK;AAC/C,QAAM,MAAM,MAAM,WAAW,EAAE,WAAW,KAAK,CAAC;AAEhD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M,SAAS;AAAA,EACpC;AACF;AAEA,SAAS,QAAQ,QAAmD;AAClE,SAAO,OAAO;AAAA,IACZ,CAAC,GAAG,OAAO,OAAO,CAAC,QAAQ,UAAU;AACnC,aAAO,IAAI,QAAQ,OAAO,IAAI,KAAK,KAAK,KAAK,CAAC;AAC9C,aAAO;AAAA,IACT,GAAG,oBAAI,IAAoB,CAAC,EAAE,QAAQ,CAAC,EAAE,KAAK,CAAC,CAAC,IAAI,GAAG,CAAC,KAAK,MAAM,KAAK,cAAc,KAAK,CAAC;AAAA,EAC9F;AACF;AAEA,SAAS,mBAAmB,OAAyB;AACnD,SACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACT,MAAsC,SAAS;AAEpD;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xsarwagya/ontoly-cache",
3
- "version": "0.1.0-alpha.13",
3
+ "version": "0.1.0-alpha.15",
4
4
  "description": "Local graph artifact persistence for Ontoly.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -9,7 +9,7 @@
9
9
  "url": "git+https://github.com/0xsarwagya/ontoly.git",
10
10
  "directory": "packages/cache"
11
11
  },
12
- "homepage": "https://oss.sarwagya.wtf/ontoly",
12
+ "homepage": "https://ontoly.sarwagya.wtf",
13
13
  "sideEffects": false,
14
14
  "exports": {
15
15
  ".": {
@@ -23,7 +23,7 @@
23
23
  "LICENSE"
24
24
  ],
25
25
  "dependencies": {
26
- "@0xsarwagya/ontoly-core": "0.1.0-alpha.13"
26
+ "@0xsarwagya/ontoly-core": "0.1.0-alpha.15"
27
27
  },
28
28
  "publishConfig": {
29
29
  "access": "public"