@0xsarwagya/ontoly-cache 0.1.0-alpha.19 → 0.1.0-alpha.2
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 +2 -11
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -17
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -4,15 +4,6 @@ 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
|
-
|
|
16
7
|
## Installation
|
|
17
8
|
|
|
18
9
|
```bash
|
|
@@ -21,10 +12,10 @@ pnpm add @0xsarwagya/ontoly-cache
|
|
|
21
12
|
|
|
22
13
|
## Status
|
|
23
14
|
|
|
24
|
-
|
|
15
|
+
Alpha package for Ontoly v0.1.0-alpha.2. The public API is versioned with the Software Graph and RFC process.
|
|
25
16
|
|
|
26
17
|
## Links
|
|
27
18
|
|
|
28
19
|
- [Repository](https://github.com/0xsarwagya/ontoly)
|
|
29
|
-
- [Documentation](https://
|
|
20
|
+
- [Documentation](https://oss.sarwagya.wtf/ontoly)
|
|
30
21
|
- [Issues](https://github.com/0xsarwagya/ontoly/issues)
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SoftwareGraph } from "@0xsarwagya/ontoly-core";
|
|
2
|
-
import { type SemanticIndex } from "@0xsarwagya/ontoly-
|
|
2
|
+
import { type SemanticIndex } from "@0xsarwagya/ontoly-semantic-index";
|
|
3
3
|
export interface GraphArtifactPaths {
|
|
4
4
|
readonly root: string;
|
|
5
5
|
readonly directory: string;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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,
|
|
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,mCAAmC,CAAC;AAE3C,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,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACzC;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,mBAAmB,GAAG,kBAAkB,CAgBtF;AAED,wBAAsB,YAAY,CAChC,KAAK,EAAE,aAAa,EACpB,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,kBAAkB,CAAC,CAgB7B;AAED,wBAAsB,SAAS,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,aAAa,CAAC,CAIpF;AAED,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,aAAa,CAAC,CAI5F;AAED,wBAAsB,yBAAyB,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,aAAa,CAAC,CAapG;AAED,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,mBAAmB,EAC5B,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,kBAAkB,CAAC,CAK7B;AAED,wBAAsB,iBAAiB,CAAC,CAAC,EACvC,OAAO,EAAE,mBAAmB,EAC5B,QAAQ,EAAE,CAAC,GACV,OAAO,CAAC,CAAC,CAAC,CAaZ"}
|
package/dist/index.js
CHANGED
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
import { mkdir, readFile, writeFile } from "fs/promises";
|
|
3
3
|
import { isAbsolute, join } from "path";
|
|
4
4
|
import {
|
|
5
|
-
createSemanticIndex
|
|
6
|
-
|
|
7
|
-
} from "@0xsarwagya/ontoly-core";
|
|
5
|
+
createSemanticIndex
|
|
6
|
+
} from "@0xsarwagya/ontoly-semantic-index";
|
|
8
7
|
function getGraphArtifactPaths(options) {
|
|
9
8
|
const outputDirectory = options.directory ?? ".ontoly";
|
|
10
9
|
const directory = isAbsolute(outputDirectory) ? outputDirectory : join(options.root, outputDirectory);
|
|
@@ -47,27 +46,16 @@ async function loadSemanticIndex(options) {
|
|
|
47
46
|
return JSON.parse(contents);
|
|
48
47
|
}
|
|
49
48
|
async function loadOrCreateSemanticIndex(options) {
|
|
50
|
-
const paths = getGraphArtifactPaths(options);
|
|
51
49
|
try {
|
|
52
|
-
|
|
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;
|
|
50
|
+
return await loadSemanticIndex(options);
|
|
63
51
|
} catch (error) {
|
|
64
52
|
if (!isMissingFileError(error)) {
|
|
65
53
|
throw error;
|
|
66
54
|
}
|
|
67
55
|
const graph = await loadGraph(options);
|
|
68
56
|
const semanticIndex = createSemanticIndex(graph);
|
|
69
|
-
await mkdir(
|
|
70
|
-
await writeJson(
|
|
57
|
+
await mkdir(getGraphArtifactPaths(options).directory, { recursive: true });
|
|
58
|
+
await writeJson(getGraphArtifactPaths(options).semanticIndex, semanticIndex);
|
|
71
59
|
return semanticIndex;
|
|
72
60
|
}
|
|
73
61
|
}
|
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
|
|
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-semantic-index\";\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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AEA,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":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xsarwagya/ontoly-cache",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.2",
|
|
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://
|
|
12
|
+
"homepage": "https://oss.sarwagya.wtf/ontoly",
|
|
13
13
|
"sideEffects": false,
|
|
14
14
|
"exports": {
|
|
15
15
|
".": {
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
"LICENSE"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@0xsarwagya/ontoly-core": "0.1.0-alpha.
|
|
26
|
+
"@0xsarwagya/ontoly-core": "0.1.0-alpha.1",
|
|
27
|
+
"@0xsarwagya/ontoly-semantic-index": "0.1.0-alpha.1"
|
|
27
28
|
},
|
|
28
29
|
"publishConfig": {
|
|
29
30
|
"access": "public"
|