@blockml/graph 0.9.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.
- package/blocks/org/blockml/bml/graph/BuildIndexResult.bml +43 -0
- package/blocks/org/blockml/bml/graph/GraphEdge.bml +49 -0
- package/blocks/org/blockml/bml/graph/GraphIndexOptions.bml +43 -0
- package/blocks/org/blockml/bml/graph/GraphMember.bml +46 -0
- package/blocks/org/blockml/bml/graph/GraphNeighbor.bml +52 -0
- package/blocks/org/blockml/bml/graph/GraphNode.bml +58 -0
- package/blocks/org/blockml/bml/graph/GraphPath.bml +40 -0
- package/blocks/org/blockml/bml/graph/GraphQueryResult.bml +37 -0
- package/blocks/org/blockml/bml/graph/GraphType.bml +33 -0
- package/blocks/org/blockml/bml/graph/IndexStatus.bml +43 -0
- package/blocks/org/blockml/bml/graph/Library.bml +95 -0
- package/blocks/org/blockml/bml/graph/README.bml +36 -0
- package/blocks/org/blockml/bml/graph/capability/Ancestors.bml +40 -0
- package/blocks/org/blockml/bml/graph/capability/BuildIndex.bml +41 -0
- package/blocks/org/blockml/bml/graph/capability/Descendants.bml +43 -0
- package/blocks/org/blockml/bml/graph/capability/Members.bml +37 -0
- package/blocks/org/blockml/bml/graph/capability/Neighbors.bml +53 -0
- package/blocks/org/blockml/bml/graph/capability/OpenIndex.bml +40 -0
- package/blocks/org/blockml/bml/graph/capability/Path.bml +43 -0
- package/blocks/org/blockml/bml/graph/capability/Query.bml +43 -0
- package/blocks/org/blockml/bml/graph/capability/RebuildIndex.bml +40 -0
- package/blocks/org/blockml/bml/graph/capability/Schema.bml +37 -0
- package/blocks/org/blockml/bml/graph/capability/UsedBy.bml +52 -0
- package/blocks/org/blockml/bml/graph/capability/Uses.bml +49 -0
- package/blocks/org/blockml/bml/graph/documentation/ArchitectureOverview.bml +39 -0
- package/blocks/org/blockml/bml/graph/documentation/Introduction.bml +37 -0
- package/blocks/org/blockml/bml/graph/documentation/LayerSeparation.bml +39 -0
- package/blocks/org/blockml/bml/graph/documentation/PackageOwnership.bml +36 -0
- package/blocks/org/blockml/bml/graph/documentation/PublicApi.bml +44 -0
- package/blocks/org/blockml/bml/graph/documentation/ScopeExclusions.bml +40 -0
- package/blocks/org/blockml/bml/graph/documentation/V1Scope.bml +41 -0
- package/dist/fingerprint.d.ts +27 -0
- package/dist/fingerprint.d.ts.map +1 -0
- package/dist/fingerprint.js +146 -0
- package/dist/fingerprint.js.map +1 -0
- package/dist/graph-index.d.ts +23 -0
- package/dist/graph-index.d.ts.map +1 -0
- package/dist/graph-index.js +49 -0
- package/dist/graph-index.js.map +1 -0
- package/dist/graph-lock.d.ts +6 -0
- package/dist/graph-lock.d.ts.map +1 -0
- package/dist/graph-lock.js +106 -0
- package/dist/graph-lock.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +159 -0
- package/dist/index.js.map +1 -0
- package/dist/ladybug-store.d.ts +19 -0
- package/dist/ladybug-store.d.ts.map +1 -0
- package/dist/ladybug-store.js +133 -0
- package/dist/ladybug-store.js.map +1 -0
- package/dist/mapper.d.ts +40 -0
- package/dist/mapper.d.ts.map +1 -0
- package/dist/mapper.js +245 -0
- package/dist/mapper.js.map +1 -0
- package/dist/operations.d.ts +14 -0
- package/dist/operations.d.ts.map +1 -0
- package/dist/operations.js +375 -0
- package/dist/operations.js.map +1 -0
- package/dist/schema.d.ts +8 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +42 -0
- package/dist/schema.js.map +1 -0
- package/dist/store.d.ts +10 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +2 -0
- package/dist/store.js.map +1 -0
- package/dist/type-refs.d.ts +8 -0
- package/dist/type-refs.d.ts.map +1 -0
- package/dist/type-refs.js +48 -0
- package/dist/type-refs.js.map +1 -0
- package/dist/types.d.ts +103 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +4 -0
- package/dist/types.js.map +1 -0
- package/package.json +43 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Graph Documentation — PublicApi
|
|
3
|
+
FQN: org.blockml.bml.graph.documentation.PublicApi
|
|
4
|
+
-->
|
|
5
|
+
<block
|
|
6
|
+
xmlns="http://blockml.org/bml"
|
|
7
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
8
|
+
xsi:schemaLocation="http://blockml.org/bml https://blockml.org/schemas/bml.xsd
|
|
9
|
+
"
|
|
10
|
+
xmlns:blockml="org.blockml.bml"
|
|
11
|
+
xmlns:bom="org.blockml.bml.bom"
|
|
12
|
+
xmlns:bomapi="org.blockml.bml.bom.api"
|
|
13
|
+
xmlns:bomcommon="org.blockml.bml.bom.common"
|
|
14
|
+
xmlns:bomdoc="org.blockml.bml.bom.document"
|
|
15
|
+
xmlns:core="org.blockml.bml.core"
|
|
16
|
+
xmlns:def="org.blockml.bml.definition"
|
|
17
|
+
xmlns:framework="org.blockml.bml.framework"
|
|
18
|
+
xmlns:fwcap="org.blockml.bml.framework.capability"
|
|
19
|
+
xmlns:graph="org.blockml.bml.graph"
|
|
20
|
+
xmlns:graphcap="org.blockml.bml.graph.capability"
|
|
21
|
+
xmlns:graphdocumentation="org.blockml.bml.graph.documentation"
|
|
22
|
+
xmlns:type="org.blockml.bml.type">
|
|
23
|
+
|
|
24
|
+
<name>PublicApi</name>
|
|
25
|
+
<type>graphdocumentation:PublicApi</type>
|
|
26
|
+
<baseType>core:Documentation</baseType>
|
|
27
|
+
<is>Exported API from packages/graph/src/index.ts</is>
|
|
28
|
+
<documentation>buildIndex(options?) → BuildIndexResult
|
|
29
|
+
buildMemoryIndex(registry, options?) → GraphIndex
|
|
30
|
+
rebuildIndex(options?) → BuildIndexResult
|
|
31
|
+
loadIndex(options?) → GraphIndex | undefined
|
|
32
|
+
getIndexStatus(options?) → IndexStatus
|
|
33
|
+
openGraph(options?) → BuildIndexResult
|
|
34
|
+
|
|
35
|
+
GraphIndex: uses, usedBy, neighbors, ancestors, descendants, path, members, schema, query, block, close.
|
|
36
|
+
uses/usedBy/neighbors take GraphDepthOptions (default 1 hop). Further hops set GraphNeighbor.source.
|
|
37
|
+
schema() includes a Ladybug Cypher subset description and example. No type() or shortestPath().
|
|
38
|
+
path follows outgoing authored edges only. block(fqn) returns the Block node or absent.
|
|
39
|
+
Ladybug types are not exported.</documentation>
|
|
40
|
+
<references>
|
|
41
|
+
<see type="graphcap:BuildIndex" relation="Defines" />
|
|
42
|
+
<see type="graphcap:Query" relation="Defines" />
|
|
43
|
+
</references>
|
|
44
|
+
</block>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Graph Documentation — ScopeExclusions
|
|
3
|
+
FQN: org.blockml.bml.graph.documentation.ScopeExclusions
|
|
4
|
+
-->
|
|
5
|
+
<block
|
|
6
|
+
xmlns="http://blockml.org/bml"
|
|
7
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
8
|
+
xsi:schemaLocation="http://blockml.org/bml https://blockml.org/schemas/bml.xsd
|
|
9
|
+
"
|
|
10
|
+
xmlns:blockml="org.blockml.bml"
|
|
11
|
+
xmlns:bom="org.blockml.bml.bom"
|
|
12
|
+
xmlns:bomapi="org.blockml.bml.bom.api"
|
|
13
|
+
xmlns:bomcommon="org.blockml.bml.bom.common"
|
|
14
|
+
xmlns:bomdoc="org.blockml.bml.bom.document"
|
|
15
|
+
xmlns:core="org.blockml.bml.core"
|
|
16
|
+
xmlns:def="org.blockml.bml.definition"
|
|
17
|
+
xmlns:framework="org.blockml.bml.framework"
|
|
18
|
+
xmlns:fwcap="org.blockml.bml.framework.capability"
|
|
19
|
+
xmlns:graph="org.blockml.bml.graph"
|
|
20
|
+
xmlns:graphcap="org.blockml.bml.graph.capability"
|
|
21
|
+
xmlns:graphdocumentation="org.blockml.bml.graph.documentation"
|
|
22
|
+
xmlns:type="org.blockml.bml.type">
|
|
23
|
+
|
|
24
|
+
<name>ScopeExclusions</name>
|
|
25
|
+
<type>graphdocumentation:ScopeExclusions</type>
|
|
26
|
+
<baseType>core:Documentation</baseType>
|
|
27
|
+
<is>Explicit out-of-scope for @blockml/graph V1</is>
|
|
28
|
+
<documentation>Out of scope:
|
|
29
|
+
• Composition instance / containment graph
|
|
30
|
+
• Documentation see-also as structural edges
|
|
31
|
+
• Materialized derived / transitive edges
|
|
32
|
+
• --direction CLI flag
|
|
33
|
+
• First-class impact, cycles, subgraph operations
|
|
34
|
+
• Incremental indexing
|
|
35
|
+
• Second BML discovery or parser
|
|
36
|
+
• Exporting Ladybug types on the public API</documentation>
|
|
37
|
+
<references>
|
|
38
|
+
<see type="graphdocumentation:Introduction" relation="SeeAlso" />
|
|
39
|
+
</references>
|
|
40
|
+
</block>
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Graph Documentation — V1Scope
|
|
3
|
+
FQN: org.blockml.bml.graph.documentation.V1Scope
|
|
4
|
+
-->
|
|
5
|
+
<block
|
|
6
|
+
xmlns="http://blockml.org/bml"
|
|
7
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
8
|
+
xsi:schemaLocation="http://blockml.org/bml https://blockml.org/schemas/bml.xsd
|
|
9
|
+
"
|
|
10
|
+
xmlns:blockml="org.blockml.bml"
|
|
11
|
+
xmlns:bom="org.blockml.bml.bom"
|
|
12
|
+
xmlns:bomapi="org.blockml.bml.bom.api"
|
|
13
|
+
xmlns:bomcommon="org.blockml.bml.bom.common"
|
|
14
|
+
xmlns:bomdoc="org.blockml.bml.bom.document"
|
|
15
|
+
xmlns:core="org.blockml.bml.core"
|
|
16
|
+
xmlns:def="org.blockml.bml.definition"
|
|
17
|
+
xmlns:framework="org.blockml.bml.framework"
|
|
18
|
+
xmlns:fwcap="org.blockml.bml.framework.capability"
|
|
19
|
+
xmlns:graph="org.blockml.bml.graph"
|
|
20
|
+
xmlns:graphcap="org.blockml.bml.graph.capability"
|
|
21
|
+
xmlns:graphdocumentation="org.blockml.bml.graph.documentation"
|
|
22
|
+
xmlns:type="org.blockml.bml.type">
|
|
23
|
+
|
|
24
|
+
<name>V1Scope</name>
|
|
25
|
+
<type>graphdocumentation:V1Scope</type>
|
|
26
|
+
<baseType>core:Documentation</baseType>
|
|
27
|
+
<is>Explicit V1 capabilities</is>
|
|
28
|
+
<documentation>In scope V1:
|
|
29
|
+
• Full effective classpath graph (workspace, dependencies, node_modules)
|
|
30
|
+
• Authored Block and Member nodes
|
|
31
|
+
• Semantic ops: uses, usedBy, neighbors, ancestors, descendants, path, members
|
|
32
|
+
• Cypher query escape hatch and schema()
|
|
33
|
+
• Local persisted index under .blockml/graph/
|
|
34
|
+
• Auto-build when the index is missing or stale
|
|
35
|
+
• CLI: blockml graph SUBCOMMAND
|
|
36
|
+
|
|
37
|
+
Out of scope: see ScopeExclusions.</documentation>
|
|
38
|
+
<references>
|
|
39
|
+
<see type="graphdocumentation:ScopeExclusions" relation="SeeAlso" />
|
|
40
|
+
</references>
|
|
41
|
+
</block>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare const DB_DIR = "lbug";
|
|
2
|
+
export declare const MANIFEST_FILE = "manifest.json";
|
|
3
|
+
export interface FileFingerprint {
|
|
4
|
+
path: string;
|
|
5
|
+
mtimeMs: number;
|
|
6
|
+
size: number;
|
|
7
|
+
}
|
|
8
|
+
export interface IndexManifest {
|
|
9
|
+
version: number;
|
|
10
|
+
blocks: number;
|
|
11
|
+
members: number;
|
|
12
|
+
packageJsonHash: string;
|
|
13
|
+
lockfileHash: string;
|
|
14
|
+
files: FileFingerprint[];
|
|
15
|
+
}
|
|
16
|
+
export declare function defaultIndexDir(rootDir: string): string;
|
|
17
|
+
export declare function resolveIndexDir(rootDir: string, indexDir?: string): string;
|
|
18
|
+
export declare function resolveDbDir(indexDir: string): string;
|
|
19
|
+
export declare function fingerprintProject(rootDir: string): {
|
|
20
|
+
packageJsonHash: string;
|
|
21
|
+
lockfileHash: string;
|
|
22
|
+
};
|
|
23
|
+
export declare function fingerprintFiles(filePaths: string[]): FileFingerprint[];
|
|
24
|
+
export declare function buildManifest(rootDir: string, filePaths: string[], blocks: number, members: number): IndexManifest;
|
|
25
|
+
export declare function manifestIsCurrent(manifest: IndexManifest, rootDir: string, srcDir?: string): boolean;
|
|
26
|
+
export declare function readManifest(indexDir: string): IndexManifest | undefined;
|
|
27
|
+
//# sourceMappingURL=fingerprint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fingerprint.d.ts","sourceRoot":"","sources":["../src/fingerprint.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,MAAM,SAAS,CAAC;AAC7B,eAAO,MAAM,aAAa,kBAAkB,CAAC;AAE7C,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,eAAe,EAAE,CAAC;CAC1B;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAE1E;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAErD;AAqBD,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG;IACnD,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;CACtB,CAKA;AAED,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,eAAe,EAAE,CAYvE;AAuCD,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EAAE,EACnB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GACd,aAAa,CAUf;AAED,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,aAAa,EACvB,OAAO,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAmCT;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAUxE"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
3
|
+
import { join, resolve } from "node:path";
|
|
4
|
+
import { projectSourceRoots } from "@blockml/framework";
|
|
5
|
+
import { INDEX_FORMAT_VERSION } from "./types.js";
|
|
6
|
+
export const DB_DIR = "lbug";
|
|
7
|
+
export const MANIFEST_FILE = "manifest.json";
|
|
8
|
+
export function defaultIndexDir(rootDir) {
|
|
9
|
+
return join(rootDir, ".blockml", "graph");
|
|
10
|
+
}
|
|
11
|
+
export function resolveIndexDir(rootDir, indexDir) {
|
|
12
|
+
return indexDir ? resolve(rootDir, indexDir) : defaultIndexDir(rootDir);
|
|
13
|
+
}
|
|
14
|
+
export function resolveDbDir(indexDir) {
|
|
15
|
+
return join(indexDir, DB_DIR);
|
|
16
|
+
}
|
|
17
|
+
function hashFileOrEmpty(path) {
|
|
18
|
+
if (!existsSync(path)) {
|
|
19
|
+
return "";
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
return createHash("sha256").update(readFileSync(path)).digest("hex");
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return "";
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function lockfilePath(rootDir) {
|
|
29
|
+
const lock = join(rootDir, "package-lock.json");
|
|
30
|
+
if (existsSync(lock)) {
|
|
31
|
+
return lock;
|
|
32
|
+
}
|
|
33
|
+
return join(rootDir, "npm-shrinkwrap.json");
|
|
34
|
+
}
|
|
35
|
+
export function fingerprintProject(rootDir) {
|
|
36
|
+
return {
|
|
37
|
+
packageJsonHash: hashFileOrEmpty(join(rootDir, "package.json")),
|
|
38
|
+
lockfileHash: hashFileOrEmpty(lockfilePath(rootDir)),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export function fingerprintFiles(filePaths) {
|
|
42
|
+
const unique = [...new Set(filePaths)].sort();
|
|
43
|
+
const files = [];
|
|
44
|
+
for (const filePath of unique) {
|
|
45
|
+
try {
|
|
46
|
+
const st = statSync(filePath);
|
|
47
|
+
files.push({ path: filePath, mtimeMs: st.mtimeMs, size: st.size });
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
files.push({ path: filePath, mtimeMs: 0, size: 0 });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return files;
|
|
54
|
+
}
|
|
55
|
+
function collectBmlFiles(dir, out = []) {
|
|
56
|
+
let entries;
|
|
57
|
+
try {
|
|
58
|
+
entries = readdirSync(dir);
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
for (const entry of entries) {
|
|
64
|
+
const full = join(dir, entry);
|
|
65
|
+
try {
|
|
66
|
+
const st = statSync(full);
|
|
67
|
+
if (st.isDirectory()) {
|
|
68
|
+
collectBmlFiles(full, out);
|
|
69
|
+
}
|
|
70
|
+
else if (entry.endsWith(".bml")) {
|
|
71
|
+
out.push(full);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return out;
|
|
79
|
+
}
|
|
80
|
+
function fingerprintsEqual(a, b) {
|
|
81
|
+
if (a.length !== b.length) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
for (let i = 0; i < a.length; i++) {
|
|
85
|
+
const left = a[i];
|
|
86
|
+
const right = b[i];
|
|
87
|
+
if (left.path !== right.path || left.mtimeMs !== right.mtimeMs || left.size !== right.size) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
export function buildManifest(rootDir, filePaths, blocks, members) {
|
|
94
|
+
const hashes = fingerprintProject(rootDir);
|
|
95
|
+
return {
|
|
96
|
+
version: INDEX_FORMAT_VERSION,
|
|
97
|
+
blocks,
|
|
98
|
+
members,
|
|
99
|
+
packageJsonHash: hashes.packageJsonHash,
|
|
100
|
+
lockfileHash: hashes.lockfileHash,
|
|
101
|
+
files: fingerprintFiles(filePaths),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
export function manifestIsCurrent(manifest, rootDir, srcDir) {
|
|
105
|
+
if (manifest.version !== INDEX_FORMAT_VERSION) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
const hashes = fingerprintProject(rootDir);
|
|
109
|
+
if (hashes.packageJsonHash !== manifest.packageJsonHash ||
|
|
110
|
+
hashes.lockfileHash !== manifest.lockfileHash) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
const currentIndexed = fingerprintFiles(manifest.files.map((file) => file.path));
|
|
114
|
+
if (!fingerprintsEqual(currentIndexed, manifest.files)) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
const localFiles = new Set();
|
|
118
|
+
for (const root of projectSourceRoots(rootDir, srcDir)) {
|
|
119
|
+
for (const file of collectBmlFiles(root)) {
|
|
120
|
+
localFiles.add(resolve(file));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const indexedLocal = new Set(manifest.files.map((file) => resolve(file.path)).filter((path) => localFiles.has(path)));
|
|
124
|
+
if (localFiles.size !== indexedLocal.size) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
for (const file of localFiles) {
|
|
128
|
+
if (!indexedLocal.has(file)) {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
export function readManifest(indexDir) {
|
|
135
|
+
const path = join(indexDir, MANIFEST_FILE);
|
|
136
|
+
if (!existsSync(path)) {
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
139
|
+
try {
|
|
140
|
+
return JSON.parse(readFileSync(path, "utf8"));
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=fingerprint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fingerprint.js","sourceRoot":"","sources":["../src/fingerprint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAElD,MAAM,CAAC,MAAM,MAAM,GAAG,MAAM,CAAC;AAC7B,MAAM,CAAC,MAAM,aAAa,GAAG,eAAe,CAAC;AAiB7C,MAAM,UAAU,eAAe,CAAC,OAAe;IAC7C,OAAO,IAAI,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;AAC5C,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,OAAe,EAAE,QAAiB;IAChE,OAAO,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;AAC1E,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,QAAgB;IAC3C,OAAO,IAAI,CAAC,QAAQ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AAC;IACnB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Diagnostic } from "@blockml/bom";
|
|
2
|
+
import type { GraphStore } from "./store.js";
|
|
3
|
+
import type { GraphDepthOptions, GraphIndexHandle, GraphMember, GraphNeighbor, GraphNode, GraphPath, GraphQueryResult, GraphSchema } from "./types.js";
|
|
4
|
+
export declare class GraphIndex implements GraphIndexHandle {
|
|
5
|
+
readonly diagnostics: Diagnostic[];
|
|
6
|
+
readonly blocks: number;
|
|
7
|
+
readonly memberCount: number;
|
|
8
|
+
readonly filePaths: string[];
|
|
9
|
+
private readonly store;
|
|
10
|
+
constructor(store: GraphStore, blocks: number, memberCount: number, filePaths: string[], diagnostics?: Diagnostic[]);
|
|
11
|
+
uses(fqn: string, options?: GraphDepthOptions): Promise<GraphNeighbor[]>;
|
|
12
|
+
usedBy(fqn: string, options?: GraphDepthOptions): Promise<GraphNeighbor[]>;
|
|
13
|
+
neighbors(fqn: string, options?: GraphDepthOptions): Promise<GraphNeighbor[]>;
|
|
14
|
+
ancestors(fqn: string, options?: GraphDepthOptions): Promise<GraphNode[]>;
|
|
15
|
+
descendants(fqn: string, options?: GraphDepthOptions): Promise<GraphNode[]>;
|
|
16
|
+
path(from: string, to: string, options?: GraphDepthOptions): Promise<GraphPath | undefined>;
|
|
17
|
+
members(fqn: string): Promise<GraphMember[]>;
|
|
18
|
+
block(fqn: string): Promise<GraphNode | undefined>;
|
|
19
|
+
schema(): GraphSchema;
|
|
20
|
+
query(cypher: string, params?: Record<string, unknown>): Promise<GraphQueryResult>;
|
|
21
|
+
close(): Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=graph-index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-index.d.ts","sourceRoot":"","sources":["../src/graph-index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAa/C,OA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GAAG,SAAS,CAAC;IAI3F,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAI5C,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IAIlD,MAAM,IAAI,WAAW;IAIrB,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAIlF,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAGvB"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ancestors as walkAncestors, descendants as walkDescendants, graphSchema, loadBlock, members as listMembers, neighbors as listNeighbors, runQuery, shortestPath, usedBy as listUsedBy, uses as listUses, } from "./operations.js";
|
|
2
|
+
export class GraphIndex {
|
|
3
|
+
diagnostics;
|
|
4
|
+
blocks;
|
|
5
|
+
memberCount;
|
|
6
|
+
filePaths;
|
|
7
|
+
store;
|
|
8
|
+
constructor(store, blocks, memberCount, filePaths, diagnostics = []) {
|
|
9
|
+
this.store = store;
|
|
10
|
+
this.blocks = blocks;
|
|
11
|
+
this.memberCount = memberCount;
|
|
12
|
+
this.filePaths = filePaths;
|
|
13
|
+
this.diagnostics = diagnostics;
|
|
14
|
+
}
|
|
15
|
+
uses(fqn, options) {
|
|
16
|
+
return listUses(this.store, fqn, options?.depth);
|
|
17
|
+
}
|
|
18
|
+
usedBy(fqn, options) {
|
|
19
|
+
return listUsedBy(this.store, fqn, options?.depth);
|
|
20
|
+
}
|
|
21
|
+
neighbors(fqn, options) {
|
|
22
|
+
return listNeighbors(this.store, fqn, options?.depth);
|
|
23
|
+
}
|
|
24
|
+
ancestors(fqn, options) {
|
|
25
|
+
return walkAncestors(this.store, fqn, options?.depth);
|
|
26
|
+
}
|
|
27
|
+
descendants(fqn, options) {
|
|
28
|
+
return walkDescendants(this.store, fqn, options?.depth);
|
|
29
|
+
}
|
|
30
|
+
path(from, to, options) {
|
|
31
|
+
return shortestPath(this.store, from, to, options?.depth);
|
|
32
|
+
}
|
|
33
|
+
members(fqn) {
|
|
34
|
+
return listMembers(this.store, fqn);
|
|
35
|
+
}
|
|
36
|
+
block(fqn) {
|
|
37
|
+
return loadBlock(this.store, fqn);
|
|
38
|
+
}
|
|
39
|
+
schema() {
|
|
40
|
+
return graphSchema();
|
|
41
|
+
}
|
|
42
|
+
query(cypher, params) {
|
|
43
|
+
return runQuery(this.store, cypher, params);
|
|
44
|
+
}
|
|
45
|
+
close() {
|
|
46
|
+
return this.store.close();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=graph-index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-index.js","sourceRoot":"","sources":["../src/graph-index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,IAAI,aAAa,EAC1B,WAAW,IAAI,eAAe,EAC9B,WAAW,EACX,SAAS,EACT,OAAO,IAAI,WAAW,EACtB,SAAS,IAAI,aAAa,EAC1B,QAAQ,EACR,YAAY,EACZ,MAAM,IAAI,UAAU,EACpB,IAAI,IAAI,QAAQ,GACjB,MAAM,iBAAiB,CAAC;AAazB,MAAM,OAAO,UAAU;IACZ,WAAW,CAAe;IAC1B,MAAM,CAAS;IACf,WAAW,CAAS;IACpB,SAAS,CAAW;IACZ,KAAK,CAAa;IAEnC,YACE,KAAiB,EACjB,MAAc,EACd,WAAmB,EACnB,SAAmB,EACnB,cAA4B,EAAE;QAE9B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IAED,IAAI,CAAC,GAAW,EAAE,OAA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IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IAC5B,CAAC;CACF"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const INDEX_LOCK_FILE = "index.lock";
|
|
2
|
+
export declare function isLadybugLockError(error: unknown): boolean;
|
|
3
|
+
export declare function delay(ms: number): Promise<void>;
|
|
4
|
+
export declare function withLadybugLockRetry<T>(run: () => Promise<T>): Promise<T>;
|
|
5
|
+
export declare function acquireGraphLock(indexDir: string): Promise<() => Promise<void>>;
|
|
6
|
+
//# sourceMappingURL=graph-lock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-lock.d.ts","sourceRoot":"","sources":["../src/graph-lock.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,eAAe,eAAe,CAAC;AAM5C,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAG1D;AAED,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAI/C;AAID,wBAAsB,oBAAoB,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAc/E;AA2DD,wBAAsB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,CAcrF"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
export const INDEX_LOCK_FILE = "index.lock";
|
|
4
|
+
const LOCK_WAIT_MS = 120_000;
|
|
5
|
+
const LOCK_POLL_MS = 50;
|
|
6
|
+
const STALE_LOCK_MS = 120_000;
|
|
7
|
+
export function isLadybugLockError(error) {
|
|
8
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
9
|
+
return /Could not set lock|Resource temporarily unavailable/i.test(message);
|
|
10
|
+
}
|
|
11
|
+
export function delay(ms) {
|
|
12
|
+
return new Promise((resolve) => {
|
|
13
|
+
setTimeout(resolve, ms);
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
const LADYBUG_RETRY_DELAYS_MS = [50, 100, 200, 400, 800, 1600, 3200, 5000, 5000, 5000];
|
|
17
|
+
export async function withLadybugLockRetry(run) {
|
|
18
|
+
let lastError;
|
|
19
|
+
for (let attempt = 0; attempt <= LADYBUG_RETRY_DELAYS_MS.length; attempt++) {
|
|
20
|
+
try {
|
|
21
|
+
return await run();
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
lastError = error;
|
|
25
|
+
if (!isLadybugLockError(error) || attempt === LADYBUG_RETRY_DELAYS_MS.length) {
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
await delay(LADYBUG_RETRY_DELAYS_MS[attempt]);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
throw lastError;
|
|
32
|
+
}
|
|
33
|
+
function lockPath(indexDir) {
|
|
34
|
+
return join(indexDir, INDEX_LOCK_FILE);
|
|
35
|
+
}
|
|
36
|
+
function processAlive(pid) {
|
|
37
|
+
try {
|
|
38
|
+
process.kill(pid, 0);
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function lockIsStale(path) {
|
|
46
|
+
try {
|
|
47
|
+
const text = readFileSync(path, "utf8");
|
|
48
|
+
const pid = Number(text.split("\n")[0]);
|
|
49
|
+
if (Number.isInteger(pid) && pid > 0) {
|
|
50
|
+
return !processAlive(pid);
|
|
51
|
+
}
|
|
52
|
+
return Date.now() - statSync(path).mtimeMs > STALE_LOCK_MS;
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function tryAcquireFileLock(indexDir) {
|
|
59
|
+
mkdirSync(indexDir, { recursive: true });
|
|
60
|
+
const path = lockPath(indexDir);
|
|
61
|
+
try {
|
|
62
|
+
writeFileSync(path, `${process.pid}\n${Date.now()}\n`, { flag: "wx" });
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
const code = error.code;
|
|
66
|
+
if (code !== "EEXIST") {
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
if (lockIsStale(path)) {
|
|
70
|
+
rmSync(path, { force: true });
|
|
71
|
+
try {
|
|
72
|
+
writeFileSync(path, `${process.pid}\n${Date.now()}\n`, { flag: "wx" });
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
let released = false;
|
|
83
|
+
return () => {
|
|
84
|
+
if (released) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
released = true;
|
|
88
|
+
rmSync(path, { force: true });
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
export async function acquireGraphLock(indexDir) {
|
|
92
|
+
const started = Date.now();
|
|
93
|
+
let releaseFile = tryAcquireFileLock(indexDir);
|
|
94
|
+
while (!releaseFile) {
|
|
95
|
+
if (Date.now() - started > LOCK_WAIT_MS) {
|
|
96
|
+
throw new Error("Timed out waiting for the graph index lock.");
|
|
97
|
+
}
|
|
98
|
+
await delay(LOCK_POLL_MS + Math.floor(Math.random() * LOCK_POLL_MS));
|
|
99
|
+
releaseFile = tryAcquireFileLock(indexDir);
|
|
100
|
+
}
|
|
101
|
+
const release = releaseFile;
|
|
102
|
+
return async () => {
|
|
103
|
+
release();
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=graph-lock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-lock.js","sourceRoot":"","sources":["../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,YAAY,EAAE,CAAC;YACxC,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;QACjE,CAAC;QACD,MAAM,KAAK,CAAC,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,YAAY,CAAC,CAAC,CAAC;QACrE,WAAW,GAAG,kBAAkB,CAAC,QAAQ,CAAC,CAAC;IAC7C,CAAC;IACD,MAAM,OAAO,GAAG,WAAW,CAAC;IAC5B,OAAO,KAAK,IAAI,EAAE;QAChB,OAAO,EAAE,CAAC;IACZ,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Diagnostic } from "@blockml/bom";
|
|
2
|
+
import { type TypeRegistry } from "@blockml/framework";
|
|
3
|
+
import { GraphIndex } from "./graph-index.js";
|
|
4
|
+
import type { BuildIndexResult, GraphIndexOptions, IndexStatus } from "./types.js";
|
|
5
|
+
export type { BuildIndexResult, GraphDepthOptions, GraphEdge, GraphIndexHandle, GraphIndexOptions, GraphMember, GraphNeighbor, GraphNode, GraphNodeKind, GraphOrigin, GraphPath, GraphPathHop, GraphQueryResult, GraphQueryRow, GraphRelation, GraphSchema, IndexState, IndexStatus, MemberKind, } from "./types.js";
|
|
6
|
+
export { DEFAULT_GRAPH_DEPTH, DEFAULT_USES_DEPTH, INDEX_FORMAT_VERSION } from "./types.js";
|
|
7
|
+
export { GraphIndex } from "./graph-index.js";
|
|
8
|
+
export { graphDataFromRegistry } from "./mapper.js";
|
|
9
|
+
export { collectNamedTypes } from "./type-refs.js";
|
|
10
|
+
export { defaultIndexDir, resolveIndexDir } from "./fingerprint.js";
|
|
11
|
+
export { graphSchema, GRAPH_RELATIONS, GRAPH_CYPHER_EXAMPLE } from "./schema.js";
|
|
12
|
+
export declare function buildMemoryIndex(registry: TypeRegistry, options?: {
|
|
13
|
+
rootDir?: string;
|
|
14
|
+
srcDir?: string;
|
|
15
|
+
diagnostics?: Diagnostic[];
|
|
16
|
+
}): Promise<GraphIndex>;
|
|
17
|
+
export declare function buildIndex(options?: GraphIndexOptions): Promise<BuildIndexResult>;
|
|
18
|
+
export declare function getIndexStatus(options?: GraphIndexOptions): Promise<IndexStatus>;
|
|
19
|
+
export declare function loadIndex(options?: GraphIndexOptions): Promise<GraphIndex | undefined>;
|
|
20
|
+
export declare function rebuildIndex(options?: GraphIndexOptions): Promise<BuildIndexResult>;
|
|
21
|
+
export declare function openGraph(options?: GraphIndexOptions): Promise<BuildIndexResult>;
|
|
22
|
+
export type { GraphIndexHandle as Graph } from "./types.js";
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAgC,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AASrF,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAK9C,OAAO,KAAK,EACV,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,EACZ,MAAM,YAAY,CAAC;AAEpB,YAAY,EACV,gBAAgB,EAChB,iBAAiB,EACjB,SAAS,EACT,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,EACX,aAAa,EACb,SAAS,EACT,aAAa,EACb,WAAW,EACX,SAAS,EACT,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,WAAW,EACX,UAAU,EACV,WAAW,EACX,UAAU,GACX,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAC3F,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,iBAAiB,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