@powerhousedao/knowledge-note 1.0.0 → 1.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.
- package/dist/editors/knowledge-vault/hooks/use-drive-init.d.ts.map +1 -1
- package/dist/editors/knowledge-vault/hooks/use-drive-init.js +76 -70
- package/dist/package.json +45 -1
- package/dist/processors/factory.d.ts.map +1 -1
- package/dist/processors/factory.js +4 -1
- package/dist/processors/methodology-indexer/factory.d.ts +4 -0
- package/dist/processors/methodology-indexer/factory.d.ts.map +1 -0
- package/dist/processors/methodology-indexer/factory.js +23 -0
- package/dist/processors/methodology-indexer/index.d.ts +11 -0
- package/dist/processors/methodology-indexer/index.d.ts.map +1 -0
- package/dist/processors/methodology-indexer/index.js +118 -0
- package/dist/processors/methodology-indexer/migrations.d.ts +4 -0
- package/dist/processors/methodology-indexer/migrations.d.ts.map +1 -0
- package/dist/processors/methodology-indexer/migrations.js +39 -0
- package/dist/processors/methodology-indexer/query.d.ts +35 -0
- package/dist/processors/methodology-indexer/query.d.ts.map +1 -0
- package/dist/processors/methodology-indexer/query.js +102 -0
- package/dist/processors/methodology-indexer/schema.d.ts +22 -0
- package/dist/processors/methodology-indexer/schema.d.ts.map +1 -0
- package/dist/processors/methodology-indexer/schema.js +1 -0
- package/dist/subgraphs/index.d.ts +1 -0
- package/dist/subgraphs/index.d.ts.map +1 -1
- package/dist/subgraphs/index.js +1 -0
- package/dist/subgraphs/methodology/index.d.ts +2 -0
- package/dist/subgraphs/methodology/index.d.ts.map +1 -0
- package/dist/subgraphs/methodology/index.js +1 -0
- package/dist/subgraphs/methodology/subgraph.d.ts +47 -0
- package/dist/subgraphs/methodology/subgraph.d.ts.map +1 -0
- package/dist/subgraphs/methodology/subgraph.js +87 -0
- package/package.json +45 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-drive-init.d.ts","sourceRoot":"","sources":["../../../../editors/knowledge-vault/hooks/use-drive-init.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-drive-init.d.ts","sourceRoot":"","sources":["../../../../editors/knowledge-vault/hooks/use-drive-init.ts"],"names":[],"mappings":"AA2DA,wBAAgB,YAAY,SAqB3B;AAsFD;;;GAGG;AACH,wBAAgB,YAAY,wBAI3B"}
|
|
@@ -1,65 +1,95 @@
|
|
|
1
|
-
import { useEffect
|
|
1
|
+
import { useEffect } from "react";
|
|
2
2
|
import { useSelectedDrive, useNodesInSelectedDrive, addDocument, addFolder, } from "@powerhousedao/reactor-browser";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Drive folder structure matching Ars Contexta layout:
|
|
5
|
+
*
|
|
6
|
+
* /knowledge/ <- notes, MOCs, knowledge graph
|
|
7
|
+
* /knowledge/notes/ <- knowledge notes
|
|
8
|
+
* /knowledge/inbox/ <- unprocessed captures
|
|
9
|
+
* /knowledge/insights/ <- synthesized insights
|
|
10
|
+
* /sources/ <- archived source material
|
|
11
|
+
* /ops/ <- operational coordination
|
|
12
|
+
* /ops/sessions/ <- session transcripts
|
|
13
|
+
* /ops/health/ <- health reports
|
|
14
|
+
* /ops/queue/ <- pipeline queue singleton
|
|
15
|
+
* /self/ <- system identity & config
|
|
16
|
+
* /self/methodology/ <- methodology notes
|
|
17
|
+
* /research/ <- bundled research claims
|
|
18
|
+
*
|
|
19
|
+
* Pattern: follows contributor-billing's proven approach —
|
|
20
|
+
* module-level tracking Set per drive prevents duplicates,
|
|
21
|
+
* sequential creation with delays for sync compatibility.
|
|
22
|
+
*/
|
|
23
|
+
// ─── Module-level state (survives re-renders, prevents duplicates) ───
|
|
24
|
+
const initStartedForDrives = new Set();
|
|
25
|
+
// Flat list of folders to create (order matters — parents first)
|
|
26
|
+
const FOLDERS = [
|
|
27
|
+
{ name: "knowledge" },
|
|
28
|
+
{ name: "notes", parentPath: "knowledge" },
|
|
29
|
+
{ name: "inbox", parentPath: "knowledge" },
|
|
30
|
+
{ name: "insights", parentPath: "knowledge" },
|
|
8
31
|
{ name: "sources" },
|
|
9
|
-
{
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
|
|
15
|
-
children: [{ name: "methodology" }],
|
|
16
|
-
},
|
|
32
|
+
{ name: "ops" },
|
|
33
|
+
{ name: "sessions", parentPath: "ops" },
|
|
34
|
+
{ name: "health", parentPath: "ops" },
|
|
35
|
+
{ name: "queue", parentPath: "ops" },
|
|
36
|
+
{ name: "self" },
|
|
37
|
+
{ name: "methodology", parentPath: "self" },
|
|
17
38
|
{ name: "research" },
|
|
18
39
|
];
|
|
19
40
|
const SINGLETONS = [
|
|
20
|
-
{
|
|
21
|
-
|
|
22
|
-
type: "bai/pipeline-queue",
|
|
23
|
-
folderPath: "ops/queue",
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
name: "HealthReport",
|
|
27
|
-
type: "bai/health-report",
|
|
28
|
-
folderPath: "ops/health",
|
|
29
|
-
},
|
|
41
|
+
{ name: "PipelineQueue", type: "bai/pipeline-queue", folderPath: "ops/queue" },
|
|
42
|
+
{ name: "HealthReport", type: "bai/health-report", folderPath: "ops/health" },
|
|
30
43
|
{ name: "KnowledgeGraph", type: "bai/knowledge-graph", folderPath: "self" },
|
|
31
44
|
{ name: "VaultConfig", type: "bai/vault-config", folderPath: "self" },
|
|
32
45
|
];
|
|
33
46
|
export function useDriveInit() {
|
|
34
|
-
// Use the drive ID (UUID), never the slug
|
|
35
47
|
const [selectedDrive] = useSelectedDrive();
|
|
36
48
|
const driveId = selectedDrive?.header.id;
|
|
37
49
|
const nodes = useNodesInSelectedDrive();
|
|
38
|
-
const initAttempted = useRef(false);
|
|
39
50
|
useEffect(() => {
|
|
40
|
-
if (!driveId ||
|
|
51
|
+
if (!driveId || nodes === undefined)
|
|
41
52
|
return;
|
|
42
|
-
if (
|
|
43
|
-
return;
|
|
44
|
-
// Check if
|
|
53
|
+
if (initStartedForDrives.has(driveId))
|
|
54
|
+
return;
|
|
55
|
+
// Check if already initialized (knowledge folder exists)
|
|
45
56
|
const hasKnowledgeFolder = (nodes ?? []).some((n) => n.kind === "folder" && n.name === "knowledge" && n.parentFolder == null);
|
|
46
|
-
if (hasKnowledgeFolder)
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
57
|
+
if (hasKnowledgeFolder) {
|
|
58
|
+
initStartedForDrives.add(driveId);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
initStartedForDrives.add(driveId);
|
|
62
|
+
void initDrive(driveId, nodes ?? []);
|
|
50
63
|
}, [driveId, nodes]);
|
|
51
64
|
}
|
|
65
|
+
// ─── Single sequential init: folders then singletons ───
|
|
52
66
|
async function initDrive(driveId, existingNodes) {
|
|
53
67
|
try {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
const folderIds = new Map(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
68
|
+
// Phase 1: Create folders
|
|
69
|
+
console.log(`[VaultInit] Creating folders for drive ${driveId}...`);
|
|
70
|
+
const existingFolderMap = buildExistingFolderMap(existingNodes);
|
|
71
|
+
const folderIds = new Map(existingFolderMap);
|
|
72
|
+
for (const folder of FOLDERS) {
|
|
73
|
+
const path = folder.parentPath ? `${folder.parentPath}/${folder.name}` : folder.name;
|
|
74
|
+
if (folderIds.has(path)) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
const parentId = folder.parentPath ? folderIds.get(folder.parentPath) : undefined;
|
|
78
|
+
try {
|
|
79
|
+
const result = await addFolder(driveId, folder.name, parentId);
|
|
80
|
+
folderIds.set(path, result.id);
|
|
81
|
+
console.log(`[VaultInit] Created folder: /${path}/`);
|
|
82
|
+
await new Promise((r) => setTimeout(r, 500));
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
console.error(`[VaultInit] Failed to create folder /${path}/:`, err);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
console.log("[VaultInit] Folders complete");
|
|
89
|
+
// Wait for reactor to process all folder operations
|
|
90
|
+
await new Promise((r) => setTimeout(r, 1500));
|
|
91
|
+
// Phase 2: Create singletons
|
|
92
|
+
console.log(`[VaultInit] Creating singletons...`);
|
|
63
93
|
const existingTypes = new Set(existingNodes
|
|
64
94
|
.filter((n) => n.kind === "file")
|
|
65
95
|
.map((n) => n.documentType));
|
|
@@ -70,11 +100,9 @@ async function initDrive(driveId, existingNodes) {
|
|
|
70
100
|
}
|
|
71
101
|
const parentFolderId = folderIds.get(singleton.folderPath);
|
|
72
102
|
try {
|
|
73
|
-
// addDocument uses the drive UUID internally
|
|
74
103
|
await addDocument(driveId, singleton.name, singleton.type, parentFolderId);
|
|
75
104
|
console.log(`[VaultInit] Created ${singleton.name} in /${singleton.folderPath}/`);
|
|
76
|
-
|
|
77
|
-
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
105
|
+
await new Promise((r) => setTimeout(r, 1000));
|
|
78
106
|
}
|
|
79
107
|
catch (err) {
|
|
80
108
|
console.error(`[VaultInit] Failed to create ${singleton.name}:`, err);
|
|
@@ -86,27 +114,7 @@ async function initDrive(driveId, existingNodes) {
|
|
|
86
114
|
console.error("[VaultInit] Drive initialization failed:", err);
|
|
87
115
|
}
|
|
88
116
|
}
|
|
89
|
-
|
|
90
|
-
for (const def of defs) {
|
|
91
|
-
const path = pathPrefix ? `${pathPrefix}/${def.name}` : def.name;
|
|
92
|
-
if (!folderIds.has(path)) {
|
|
93
|
-
try {
|
|
94
|
-
const result = await addFolder(driveId, def.name, parentFolderId);
|
|
95
|
-
folderIds.set(path, result.id);
|
|
96
|
-
console.log(`[VaultInit] Created folder: /${path}/`);
|
|
97
|
-
// Small delay to avoid revision conflicts
|
|
98
|
-
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
99
|
-
}
|
|
100
|
-
catch (err) {
|
|
101
|
-
console.error(`[VaultInit] Failed to create folder /${path}/:`, err);
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
if (def.children) {
|
|
106
|
-
await createFolderTree(driveId, def.children, folderIds.get(path), path, folderIds);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
117
|
+
// ─── Helpers ───
|
|
110
118
|
function buildExistingFolderMap(nodes) {
|
|
111
119
|
const map = new Map();
|
|
112
120
|
const folders = nodes.filter((n) => n.kind === "folder");
|
|
@@ -116,9 +124,7 @@ function buildExistingFolderMap(nodes) {
|
|
|
116
124
|
let current = folder;
|
|
117
125
|
while (current) {
|
|
118
126
|
pathParts.unshift(current.name);
|
|
119
|
-
current = current.parentFolder
|
|
120
|
-
? folderById.get(current.parentFolder)
|
|
121
|
-
: undefined;
|
|
127
|
+
current = current.parentFolder ? folderById.get(current.parentFolder) : undefined;
|
|
122
128
|
}
|
|
123
129
|
map.set(pathParts.join("/"), folder.id);
|
|
124
130
|
}
|
package/dist/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powerhousedao/knowledge-note",
|
|
3
3
|
"description": "Knowledge Note document model package for Powerhouse",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.1",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"files": [
|
|
@@ -23,6 +23,50 @@
|
|
|
23
23
|
"types": "./dist/editors/index.d.ts",
|
|
24
24
|
"import": "./dist/editors/index.js"
|
|
25
25
|
},
|
|
26
|
+
"./document-models/derivation": {
|
|
27
|
+
"types": "./dist/document-models/derivation/index.d.ts",
|
|
28
|
+
"import": "./dist/document-models/derivation/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./document-models/health-report": {
|
|
31
|
+
"types": "./dist/document-models/health-report/index.d.ts",
|
|
32
|
+
"import": "./dist/document-models/health-report/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./document-models/knowledge-graph": {
|
|
35
|
+
"types": "./dist/document-models/knowledge-graph/index.d.ts",
|
|
36
|
+
"import": "./dist/document-models/knowledge-graph/index.js"
|
|
37
|
+
},
|
|
38
|
+
"./document-models/knowledge-note": {
|
|
39
|
+
"types": "./dist/document-models/knowledge-note/index.d.ts",
|
|
40
|
+
"import": "./dist/document-models/knowledge-note/index.js"
|
|
41
|
+
},
|
|
42
|
+
"./document-models/moc": {
|
|
43
|
+
"types": "./dist/document-models/moc/index.d.ts",
|
|
44
|
+
"import": "./dist/document-models/moc/index.js"
|
|
45
|
+
},
|
|
46
|
+
"./document-models/observation": {
|
|
47
|
+
"types": "./dist/document-models/observation/index.d.ts",
|
|
48
|
+
"import": "./dist/document-models/observation/index.js"
|
|
49
|
+
},
|
|
50
|
+
"./document-models/pipeline-queue": {
|
|
51
|
+
"types": "./dist/document-models/pipeline-queue/index.d.ts",
|
|
52
|
+
"import": "./dist/document-models/pipeline-queue/index.js"
|
|
53
|
+
},
|
|
54
|
+
"./document-models/research-claim": {
|
|
55
|
+
"types": "./dist/document-models/research-claim/index.d.ts",
|
|
56
|
+
"import": "./dist/document-models/research-claim/index.js"
|
|
57
|
+
},
|
|
58
|
+
"./document-models/source": {
|
|
59
|
+
"types": "./dist/document-models/source/index.d.ts",
|
|
60
|
+
"import": "./dist/document-models/source/index.js"
|
|
61
|
+
},
|
|
62
|
+
"./document-models/tension": {
|
|
63
|
+
"types": "./dist/document-models/tension/index.d.ts",
|
|
64
|
+
"import": "./dist/document-models/tension/index.js"
|
|
65
|
+
},
|
|
66
|
+
"./document-models/vault-config": {
|
|
67
|
+
"types": "./dist/document-models/vault-config/index.d.ts",
|
|
68
|
+
"import": "./dist/document-models/vault-config/index.js"
|
|
69
|
+
},
|
|
26
70
|
"./document-models/*": {
|
|
27
71
|
"types": "./dist/document-models/*/index.d.ts",
|
|
28
72
|
"import": "./dist/document-models/*/index.js"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../processors/factory.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,eAAe,EACf,oBAAoB,EAErB,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../processors/factory.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,eAAe,EACf,oBAAoB,EAErB,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAIvD,eAAO,MAAM,gBAAgB,GAAI,QAAQ,oBAAoB,MAgB7C,aAAa,gBAAgB,KAAG,OAAO,CAAC,eAAe,EAAE,CAUxE,CAAC"}
|
|
@@ -2,11 +2,14 @@
|
|
|
2
2
|
* This file aggregates all processor factories
|
|
3
3
|
*/
|
|
4
4
|
import { graphIndexerProcessorFactory } from "./graph-indexer/factory.js";
|
|
5
|
+
import { methodologyIndexerProcessorFactory } from "./methodology-indexer/factory.js";
|
|
5
6
|
export const processorFactory = (module) => {
|
|
6
7
|
console.log(`[processorFactory] Initializing with processorApp: ${module.processorApp}`);
|
|
7
8
|
const factories = [];
|
|
8
|
-
// Register graph indexer
|
|
9
|
+
// Register graph indexer (watches bai/knowledge-note)
|
|
9
10
|
factories.push(graphIndexerProcessorFactory(module));
|
|
11
|
+
// Register methodology indexer (watches bai/research-claim)
|
|
12
|
+
factories.push(methodologyIndexerProcessorFactory(module));
|
|
10
13
|
console.log(`[processorFactory] Loaded ${factories.length} factories`);
|
|
11
14
|
// Return the inner function that will be called for each drive
|
|
12
15
|
return async (driveHeader) => {
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ProcessorRecord, IProcessorHostModule } from "@powerhousedao/reactor-browser";
|
|
2
|
+
import type { PHDocumentHeader } from "document-model";
|
|
3
|
+
export declare const methodologyIndexerProcessorFactory: (module: IProcessorHostModule) => (driveHeader: PHDocumentHeader) => Promise<ProcessorRecord[]>;
|
|
4
|
+
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../processors/methodology-indexer/factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,oBAAoB,EACrB,MAAM,gCAAgC,CAAC;AAExC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGvD,eAAO,MAAM,kCAAkC,GAC5C,QAAQ,oBAAoB,MACtB,aAAa,gBAAgB,KAAG,OAAO,CAAC,eAAe,EAAE,CAoC/D,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {} from "@powerhousedao/shared/processors";
|
|
2
|
+
import { MethodologyIndexerProcessor } from "./index.js";
|
|
3
|
+
export const methodologyIndexerProcessorFactory = (module) => async (driveHeader) => {
|
|
4
|
+
const namespace = MethodologyIndexerProcessor.getNamespace(driveHeader.id);
|
|
5
|
+
console.log(`[MethodologyIndexer] Factory called for drive: ${driveHeader.id}, namespace: ${namespace}`);
|
|
6
|
+
const store = await module.relationalDb.createNamespace(namespace);
|
|
7
|
+
const filter = {
|
|
8
|
+
branch: ["main"],
|
|
9
|
+
documentId: ["*"],
|
|
10
|
+
documentType: ["bai/research-claim", "powerhouse/document-drive"],
|
|
11
|
+
scope: ["global"],
|
|
12
|
+
};
|
|
13
|
+
const processor = new MethodologyIndexerProcessor(namespace, filter, store);
|
|
14
|
+
await processor.initAndUpgrade();
|
|
15
|
+
console.log(`[MethodologyIndexer] Processor created for drive: ${driveHeader.id}`);
|
|
16
|
+
return [
|
|
17
|
+
{
|
|
18
|
+
processor,
|
|
19
|
+
filter,
|
|
20
|
+
startFrom: "beginning",
|
|
21
|
+
},
|
|
22
|
+
];
|
|
23
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RelationalDbProcessor } from "@powerhousedao/shared/processors";
|
|
2
|
+
import type { OperationWithContext } from "@powerhousedao/shared/document-model";
|
|
3
|
+
import type { MethodologyDB } from "./schema.js";
|
|
4
|
+
export declare class MethodologyIndexerProcessor extends RelationalDbProcessor<MethodologyDB> {
|
|
5
|
+
static getNamespace(driveId: string): string;
|
|
6
|
+
initAndUpgrade(): Promise<void>;
|
|
7
|
+
onOperations(operations: OperationWithContext[]): Promise<void>;
|
|
8
|
+
onDisconnect(): Promise<void>;
|
|
9
|
+
private deleteClaim;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../processors/methodology-indexer/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AACzE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAEjF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,qBAAa,2BAA4B,SAAQ,qBAAqB,CAAC,aAAa,CAAC;WACnE,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAItC,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAI/B,YAAY,CACzB,UAAU,EAAE,oBAAoB,EAAE,GACjC,OAAO,CAAC,IAAI,CAAC;IAsGV,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;YAcrB,WAAW;CAkB1B"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { RelationalDbProcessor } from "@powerhousedao/shared/processors";
|
|
2
|
+
import { up } from "./migrations.js";
|
|
3
|
+
export class MethodologyIndexerProcessor extends RelationalDbProcessor {
|
|
4
|
+
static getNamespace(driveId) {
|
|
5
|
+
return super.getNamespace(driveId);
|
|
6
|
+
}
|
|
7
|
+
async initAndUpgrade() {
|
|
8
|
+
await up(this.relationalDb);
|
|
9
|
+
}
|
|
10
|
+
async onOperations(operations) {
|
|
11
|
+
if (operations.length === 0)
|
|
12
|
+
return;
|
|
13
|
+
const lastByDocument = new Map();
|
|
14
|
+
for (const entry of operations) {
|
|
15
|
+
const { operation, context } = entry;
|
|
16
|
+
const documentId = context.documentId;
|
|
17
|
+
// Handle deletion from drive
|
|
18
|
+
if (context.documentType === "powerhouse/document-drive" &&
|
|
19
|
+
operation.action.type === "DELETE_NODE") {
|
|
20
|
+
const deleteInput = operation.action.input;
|
|
21
|
+
await this.deleteClaim(deleteInput.id);
|
|
22
|
+
lastByDocument.delete(deleteInput.id);
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
// Only process research-claim documents
|
|
26
|
+
if (context.documentType !== "bai/research-claim")
|
|
27
|
+
continue;
|
|
28
|
+
if (context.resultingState) {
|
|
29
|
+
lastByDocument.set(documentId, entry);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
for (const [documentId, entry] of lastByDocument) {
|
|
33
|
+
try {
|
|
34
|
+
const stateJson = entry.context.resultingState;
|
|
35
|
+
if (!stateJson)
|
|
36
|
+
continue;
|
|
37
|
+
const parsed = JSON.parse(stateJson);
|
|
38
|
+
const global = (parsed.global ?? parsed);
|
|
39
|
+
const now = new Date().toISOString();
|
|
40
|
+
// Upsert claim
|
|
41
|
+
const topics = global.topics ?? [];
|
|
42
|
+
const methodology = global.methodology ?? [];
|
|
43
|
+
await this.relationalDb
|
|
44
|
+
.insertInto("methodology_claims")
|
|
45
|
+
.values({
|
|
46
|
+
id: documentId,
|
|
47
|
+
document_id: documentId,
|
|
48
|
+
title: global.title ?? null,
|
|
49
|
+
description: global.description ?? null,
|
|
50
|
+
kind: global.kind ?? null,
|
|
51
|
+
topics: JSON.stringify(topics),
|
|
52
|
+
methodology: JSON.stringify(methodology),
|
|
53
|
+
updated_at: now,
|
|
54
|
+
})
|
|
55
|
+
.onConflict((oc) => oc.column("document_id").doUpdateSet({
|
|
56
|
+
title: global.title ?? null,
|
|
57
|
+
description: global.description ?? null,
|
|
58
|
+
kind: global.kind ?? null,
|
|
59
|
+
topics: JSON.stringify(topics),
|
|
60
|
+
methodology: JSON.stringify(methodology),
|
|
61
|
+
updated_at: now,
|
|
62
|
+
}))
|
|
63
|
+
.execute();
|
|
64
|
+
// Reconcile connections
|
|
65
|
+
await this.relationalDb
|
|
66
|
+
.deleteFrom("methodology_connections")
|
|
67
|
+
.where("source_document_id", "=", documentId)
|
|
68
|
+
.execute();
|
|
69
|
+
const connections = global.connections ?? [];
|
|
70
|
+
if (connections.length > 0) {
|
|
71
|
+
await this.relationalDb
|
|
72
|
+
.insertInto("methodology_connections")
|
|
73
|
+
.values(connections.map((conn) => ({
|
|
74
|
+
id: conn.id ??
|
|
75
|
+
`${documentId}-${conn.targetRef}`,
|
|
76
|
+
source_document_id: documentId,
|
|
77
|
+
target_ref: conn.targetRef ?? "",
|
|
78
|
+
context_phrase: conn.contextPhrase ?? null,
|
|
79
|
+
updated_at: now,
|
|
80
|
+
})))
|
|
81
|
+
.execute();
|
|
82
|
+
}
|
|
83
|
+
console.log(`[MethodologyIndexer] Reconciled ${documentId}: ${connections.length} connections`);
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
console.error(`[MethodologyIndexer] Error reconciling ${documentId}:`, err);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
async onDisconnect() {
|
|
91
|
+
try {
|
|
92
|
+
await this.relationalDb
|
|
93
|
+
.deleteFrom("methodology_connections")
|
|
94
|
+
.execute();
|
|
95
|
+
await this.relationalDb.deleteFrom("methodology_claims").execute();
|
|
96
|
+
console.log(`[MethodologyIndexer] Cleaned up namespace: ${this.namespace}`);
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
console.error(`[MethodologyIndexer] Error cleaning up:`, err);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
async deleteClaim(documentId) {
|
|
103
|
+
try {
|
|
104
|
+
await this.relationalDb
|
|
105
|
+
.deleteFrom("methodology_connections")
|
|
106
|
+
.where("source_document_id", "=", documentId)
|
|
107
|
+
.execute();
|
|
108
|
+
await this.relationalDb
|
|
109
|
+
.deleteFrom("methodology_claims")
|
|
110
|
+
.where("document_id", "=", documentId)
|
|
111
|
+
.execute();
|
|
112
|
+
console.log(`[MethodologyIndexer] Deleted claim ${documentId}`);
|
|
113
|
+
}
|
|
114
|
+
catch (err) {
|
|
115
|
+
console.error(`[MethodologyIndexer] Error deleting claim ${documentId}:`, err);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../../../processors/methodology-indexer/migrations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AAEtE,wBAAsB,EAAE,CAAC,EAAE,EAAE,aAAa,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAqC9D;AAED,wBAAsB,IAAI,CAAC,EAAE,EAAE,aAAa,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAGhE"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export async function up(db) {
|
|
2
|
+
await db.schema
|
|
3
|
+
.createTable("methodology_claims")
|
|
4
|
+
.addColumn("id", "varchar(255)", (col) => col.primaryKey())
|
|
5
|
+
.addColumn("document_id", "varchar(255)", (col) => col.notNull().unique())
|
|
6
|
+
.addColumn("title", "varchar(1024)")
|
|
7
|
+
.addColumn("description", "text")
|
|
8
|
+
.addColumn("kind", "varchar(100)")
|
|
9
|
+
.addColumn("topics", "text") // JSON array as string
|
|
10
|
+
.addColumn("methodology", "text") // JSON array as string
|
|
11
|
+
.addColumn("updated_at", "varchar(50)", (col) => col.notNull())
|
|
12
|
+
.ifNotExists()
|
|
13
|
+
.execute();
|
|
14
|
+
await db.schema
|
|
15
|
+
.createTable("methodology_connections")
|
|
16
|
+
.addColumn("id", "varchar(255)", (col) => col.primaryKey())
|
|
17
|
+
.addColumn("source_document_id", "varchar(255)", (col) => col.notNull())
|
|
18
|
+
.addColumn("target_ref", "varchar(255)", (col) => col.notNull())
|
|
19
|
+
.addColumn("context_phrase", "text")
|
|
20
|
+
.addColumn("updated_at", "varchar(50)", (col) => col.notNull())
|
|
21
|
+
.ifNotExists()
|
|
22
|
+
.execute();
|
|
23
|
+
await db.schema
|
|
24
|
+
.createIndex("idx_methodology_claims_kind")
|
|
25
|
+
.on("methodology_claims")
|
|
26
|
+
.column("kind")
|
|
27
|
+
.ifNotExists()
|
|
28
|
+
.execute();
|
|
29
|
+
await db.schema
|
|
30
|
+
.createIndex("idx_methodology_connections_source")
|
|
31
|
+
.on("methodology_connections")
|
|
32
|
+
.column("source_document_id")
|
|
33
|
+
.ifNotExists()
|
|
34
|
+
.execute();
|
|
35
|
+
}
|
|
36
|
+
export async function down(db) {
|
|
37
|
+
await db.schema.dropTable("methodology_connections").ifExists().execute();
|
|
38
|
+
await db.schema.dropTable("methodology_claims").ifExists().execute();
|
|
39
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Kysely } from "kysely";
|
|
2
|
+
import type { MethodologyDB } from "./schema.js";
|
|
3
|
+
export interface ClaimResult {
|
|
4
|
+
id: string;
|
|
5
|
+
documentId: string;
|
|
6
|
+
title: string | null;
|
|
7
|
+
description: string | null;
|
|
8
|
+
kind: string | null;
|
|
9
|
+
topics: string[];
|
|
10
|
+
methodology: string[];
|
|
11
|
+
updatedAt: string;
|
|
12
|
+
}
|
|
13
|
+
export interface ConnectionResult {
|
|
14
|
+
id: string;
|
|
15
|
+
sourceDocumentId: string;
|
|
16
|
+
targetRef: string;
|
|
17
|
+
contextPhrase: string | null;
|
|
18
|
+
updatedAt: string;
|
|
19
|
+
}
|
|
20
|
+
export declare function createMethodologyQuery(db: Kysely<MethodologyDB>): {
|
|
21
|
+
allClaims(): Promise<ClaimResult[]>;
|
|
22
|
+
claimCount(): Promise<number>;
|
|
23
|
+
claimByDocumentId(documentId: string): Promise<ClaimResult | undefined>;
|
|
24
|
+
claimsByKind(kind: string): Promise<ClaimResult[]>;
|
|
25
|
+
searchClaims(query: string, limit?: number): Promise<ClaimResult[]>;
|
|
26
|
+
claimsByTopic(topic: string): Promise<ClaimResult[]>;
|
|
27
|
+
connectionsFrom(documentId: string): Promise<ConnectionResult[]>;
|
|
28
|
+
connectionsTo(targetRef: string): Promise<ConnectionResult[]>;
|
|
29
|
+
stats(): Promise<{
|
|
30
|
+
claimCount: number;
|
|
31
|
+
connectionCount: number;
|
|
32
|
+
kindDistribution: Record<string, number>;
|
|
33
|
+
}>;
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=query.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../../processors/methodology-indexer/query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,aAAa,EAA2C,MAAM,aAAa,CAAC;AAE1F,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,gBAAgB,EAAE,MAAM,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC;CACnB;AAyBD,wBAAgB,sBAAsB,CAAC,EAAE,EAAE,MAAM,CAAC,aAAa,CAAC;iBAEzC,OAAO,CAAC,WAAW,EAAE,CAAC;kBAKrB,OAAO,CAAC,MAAM,CAAC;kCAKC,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;uBASpD,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;wBAS9B,MAAM,mBAAe,OAAO,CAAC,WAAW,EAAE,CAAC;yBAiB1C,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;gCAUxB,MAAM,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;6BASvC,MAAM,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;aASpD,OAAO,CAAC;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,eAAe,EAAE,MAAM,CAAC;QAAC,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE,CAAC;EAiBpH"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
function rowToClaim(row) {
|
|
2
|
+
return {
|
|
3
|
+
id: row.id,
|
|
4
|
+
documentId: row.document_id,
|
|
5
|
+
title: row.title,
|
|
6
|
+
description: row.description,
|
|
7
|
+
kind: row.kind,
|
|
8
|
+
topics: row.topics ? JSON.parse(row.topics) : [],
|
|
9
|
+
methodology: row.methodology ? JSON.parse(row.methodology) : [],
|
|
10
|
+
updatedAt: row.updated_at,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function rowToConnection(row) {
|
|
14
|
+
return {
|
|
15
|
+
id: row.id,
|
|
16
|
+
sourceDocumentId: row.source_document_id,
|
|
17
|
+
targetRef: row.target_ref,
|
|
18
|
+
contextPhrase: row.context_phrase,
|
|
19
|
+
updatedAt: row.updated_at,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export function createMethodologyQuery(db) {
|
|
23
|
+
return {
|
|
24
|
+
async allClaims() {
|
|
25
|
+
const rows = await db.selectFrom("methodology_claims").selectAll().execute();
|
|
26
|
+
return rows.map(rowToClaim);
|
|
27
|
+
},
|
|
28
|
+
async claimCount() {
|
|
29
|
+
const rows = await db.selectFrom("methodology_claims").selectAll().execute();
|
|
30
|
+
return rows.length;
|
|
31
|
+
},
|
|
32
|
+
async claimByDocumentId(documentId) {
|
|
33
|
+
const row = await db
|
|
34
|
+
.selectFrom("methodology_claims")
|
|
35
|
+
.where("document_id", "=", documentId)
|
|
36
|
+
.selectAll()
|
|
37
|
+
.executeTakeFirst();
|
|
38
|
+
return row ? rowToClaim(row) : undefined;
|
|
39
|
+
},
|
|
40
|
+
async claimsByKind(kind) {
|
|
41
|
+
const rows = await db
|
|
42
|
+
.selectFrom("methodology_claims")
|
|
43
|
+
.where("kind", "=", kind)
|
|
44
|
+
.selectAll()
|
|
45
|
+
.execute();
|
|
46
|
+
return rows.map(rowToClaim);
|
|
47
|
+
},
|
|
48
|
+
async searchClaims(query, limit = 50) {
|
|
49
|
+
const q = `%${query.toLowerCase()}%`;
|
|
50
|
+
const rows = await db
|
|
51
|
+
.selectFrom("methodology_claims")
|
|
52
|
+
.where((eb) => eb.or([
|
|
53
|
+
eb(eb.fn("lower", ["title"]), "like", q),
|
|
54
|
+
eb(eb.fn("lower", ["description"]), "like", q),
|
|
55
|
+
eb(eb.fn("lower", ["topics"]), "like", q),
|
|
56
|
+
]))
|
|
57
|
+
.selectAll()
|
|
58
|
+
.limit(limit)
|
|
59
|
+
.execute();
|
|
60
|
+
return rows.map(rowToClaim);
|
|
61
|
+
},
|
|
62
|
+
async claimsByTopic(topic) {
|
|
63
|
+
const q = `%"${topic.toLowerCase()}"%`;
|
|
64
|
+
const rows = await db
|
|
65
|
+
.selectFrom("methodology_claims")
|
|
66
|
+
.where(eb => eb(eb.fn("lower", ["topics"]), "like", q))
|
|
67
|
+
.selectAll()
|
|
68
|
+
.execute();
|
|
69
|
+
return rows.map(rowToClaim);
|
|
70
|
+
},
|
|
71
|
+
async connectionsFrom(documentId) {
|
|
72
|
+
const rows = await db
|
|
73
|
+
.selectFrom("methodology_connections")
|
|
74
|
+
.where("source_document_id", "=", documentId)
|
|
75
|
+
.selectAll()
|
|
76
|
+
.execute();
|
|
77
|
+
return rows.map(rowToConnection);
|
|
78
|
+
},
|
|
79
|
+
async connectionsTo(targetRef) {
|
|
80
|
+
const rows = await db
|
|
81
|
+
.selectFrom("methodology_connections")
|
|
82
|
+
.where("target_ref", "=", targetRef)
|
|
83
|
+
.selectAll()
|
|
84
|
+
.execute();
|
|
85
|
+
return rows.map(rowToConnection);
|
|
86
|
+
},
|
|
87
|
+
async stats() {
|
|
88
|
+
const claims = await db.selectFrom("methodology_claims").selectAll().execute();
|
|
89
|
+
const connections = await db.selectFrom("methodology_connections").selectAll().execute();
|
|
90
|
+
const kindDist = {};
|
|
91
|
+
for (const c of claims) {
|
|
92
|
+
const k = c.kind ?? "unknown";
|
|
93
|
+
kindDist[k] = (kindDist[k] ?? 0) + 1;
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
claimCount: claims.length,
|
|
97
|
+
connectionCount: connections.length,
|
|
98
|
+
kindDistribution: kindDist,
|
|
99
|
+
};
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface MethodologyClaim {
|
|
2
|
+
id: string;
|
|
3
|
+
document_id: string;
|
|
4
|
+
title: string | null;
|
|
5
|
+
description: string | null;
|
|
6
|
+
kind: string | null;
|
|
7
|
+
topics: string | null;
|
|
8
|
+
methodology: string | null;
|
|
9
|
+
updated_at: string;
|
|
10
|
+
}
|
|
11
|
+
export interface MethodologyConnection {
|
|
12
|
+
id: string;
|
|
13
|
+
source_document_id: string;
|
|
14
|
+
target_ref: string;
|
|
15
|
+
context_phrase: string | null;
|
|
16
|
+
updated_at: string;
|
|
17
|
+
}
|
|
18
|
+
export interface MethodologyDB {
|
|
19
|
+
methodology_claims: MethodologyClaim;
|
|
20
|
+
methodology_connections: MethodologyConnection;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../processors/methodology-indexer/schema.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,qBAAqB;IACpC,EAAE,EAAE,MAAM,CAAC;IACX,kBAAkB,EAAE,MAAM,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B,kBAAkB,EAAE,gBAAgB,CAAC;IACrC,uBAAuB,EAAE,qBAAqB,CAAC;CAChD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../subgraphs/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,sBAAsB,MAAM,4BAA4B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../subgraphs/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,sBAAsB,MAAM,4BAA4B,CAAC;AACrE,OAAO,KAAK,mBAAmB,MAAM,wBAAwB,CAAC"}
|
package/dist/subgraphs/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../subgraphs/methodology/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { MethodologySubgraph } from "./subgraph.js";
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { BaseSubgraph, type SubgraphArgs } from "@powerhousedao/reactor-api";
|
|
2
|
+
export declare class MethodologySubgraph extends BaseSubgraph {
|
|
3
|
+
name: string;
|
|
4
|
+
typeDefs: import("graphql").DocumentNode;
|
|
5
|
+
resolvers: {
|
|
6
|
+
Query: {
|
|
7
|
+
methodologySearch: (_: unknown, args: {
|
|
8
|
+
driveId: string;
|
|
9
|
+
query: string;
|
|
10
|
+
limit?: number;
|
|
11
|
+
}) => Promise<import("../../processors/methodology-indexer/query.js").ClaimResult[]>;
|
|
12
|
+
methodologyClaims: (_: unknown, args: {
|
|
13
|
+
driveId: string;
|
|
14
|
+
}) => Promise<import("../../processors/methodology-indexer/query.js").ClaimResult[]>;
|
|
15
|
+
methodologyClaimsByKind: (_: unknown, args: {
|
|
16
|
+
driveId: string;
|
|
17
|
+
kind: string;
|
|
18
|
+
}) => Promise<import("../../processors/methodology-indexer/query.js").ClaimResult[]>;
|
|
19
|
+
methodologyClaimsByTopic: (_: unknown, args: {
|
|
20
|
+
driveId: string;
|
|
21
|
+
topic: string;
|
|
22
|
+
}) => Promise<import("../../processors/methodology-indexer/query.js").ClaimResult[]>;
|
|
23
|
+
methodologyClaimById: (_: unknown, args: {
|
|
24
|
+
driveId: string;
|
|
25
|
+
documentId: string;
|
|
26
|
+
}) => Promise<import("../../processors/methodology-indexer/query.js").ClaimResult | undefined>;
|
|
27
|
+
methodologyStats: (_: unknown, args: {
|
|
28
|
+
driveId: string;
|
|
29
|
+
}) => Promise<{
|
|
30
|
+
claimCount: number;
|
|
31
|
+
connectionCount: number;
|
|
32
|
+
kindDistribution: Record<string, number>;
|
|
33
|
+
}>;
|
|
34
|
+
methodologyConnectionsFrom: (_: unknown, args: {
|
|
35
|
+
driveId: string;
|
|
36
|
+
documentId: string;
|
|
37
|
+
}) => Promise<import("../../processors/methodology-indexer/query.js").ConnectionResult[]>;
|
|
38
|
+
methodologyConnectionsTo: (_: unknown, args: {
|
|
39
|
+
driveId: string;
|
|
40
|
+
targetRef: string;
|
|
41
|
+
}) => Promise<import("../../processors/methodology-indexer/query.js").ConnectionResult[]>;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
constructor(args: SubgraphArgs);
|
|
45
|
+
private getQuery;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=subgraph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subgraph.d.ts","sourceRoot":"","sources":["../../../subgraphs/methodology/subgraph.ts"],"names":[],"mappings":"AACA,OAAO,EACL,YAAY,EACZ,KAAK,YAAY,EAClB,MAAM,4BAA4B,CAAC;AAMpC,qBAAa,mBAAoB,SAAQ,YAAY;IAC1C,IAAI,SAAiB;IAErB,QAAQ,iCAoCf;IAEO,SAAS;;mCAGT,OAAO,QACJ;gBAAE,OAAO,EAAE,MAAM,CAAC;gBAAC,KAAK,EAAE,MAAM,CAAC;gBAAC,KAAK,CAAC,EAAE,MAAM,CAAA;aAAE;mCAOrD,OAAO,QACJ;gBAAE,OAAO,EAAE,MAAM,CAAA;aAAE;yCAOtB,OAAO,QACJ;gBAAE,OAAO,EAAE,MAAM,CAAC;gBAAC,IAAI,EAAE,MAAM,CAAA;aAAE;0CAOpC,OAAO,QACJ;gBAAE,OAAO,EAAE,MAAM,CAAC;gBAAC,KAAK,EAAE,MAAM,CAAA;aAAE;sCAOrC,OAAO,QACJ;gBAAE,OAAO,EAAE,MAAM,CAAC;gBAAC,UAAU,EAAE,MAAM,CAAA;aAAE;kCAO1C,OAAO,QACJ;gBAAE,OAAO,EAAE,MAAM,CAAA;aAAE;;;;;4CAOtB,OAAO,QACJ;gBAAE,OAAO,EAAE,MAAM,CAAC;gBAAC,UAAU,EAAE,MAAM,CAAA;aAAE;0CAO1C,OAAO,QACJ;gBAAE,OAAO,EAAE,MAAM,CAAC;gBAAC,SAAS,EAAE,MAAM,CAAA;aAAE;;MAMhD;gBAEU,IAAI,EAAE,YAAY;IAI9B,OAAO,CAAC,QAAQ;CAOjB"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { gql } from "graphql-tag";
|
|
2
|
+
import { BaseSubgraph, } from "@powerhousedao/reactor-api";
|
|
3
|
+
import { MethodologyIndexerProcessor } from "../../processors/methodology-indexer/index.js";
|
|
4
|
+
import { createMethodologyQuery } from "../../processors/methodology-indexer/query.js";
|
|
5
|
+
export class MethodologySubgraph extends BaseSubgraph {
|
|
6
|
+
name = "methodology";
|
|
7
|
+
typeDefs = gql `
|
|
8
|
+
type MethodologyClaim {
|
|
9
|
+
id: String!
|
|
10
|
+
documentId: String!
|
|
11
|
+
title: String
|
|
12
|
+
description: String
|
|
13
|
+
kind: String
|
|
14
|
+
topics: [String!]!
|
|
15
|
+
methodology: [String!]!
|
|
16
|
+
updatedAt: String!
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type MethodologyConnection {
|
|
20
|
+
id: String!
|
|
21
|
+
sourceDocumentId: String!
|
|
22
|
+
targetRef: String!
|
|
23
|
+
contextPhrase: String
|
|
24
|
+
updatedAt: String!
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
type MethodologyStats {
|
|
28
|
+
claimCount: Int!
|
|
29
|
+
connectionCount: Int!
|
|
30
|
+
kindDistribution: JSONObject
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
extend type Query {
|
|
34
|
+
methodologySearch(driveId: ID!, query: String!, limit: Int): [MethodologyClaim!]!
|
|
35
|
+
methodologyClaims(driveId: ID!): [MethodologyClaim!]!
|
|
36
|
+
methodologyClaimsByKind(driveId: ID!, kind: String!): [MethodologyClaim!]!
|
|
37
|
+
methodologyClaimsByTopic(driveId: ID!, topic: String!): [MethodologyClaim!]!
|
|
38
|
+
methodologyClaimById(driveId: ID!, documentId: String!): MethodologyClaim
|
|
39
|
+
methodologyStats(driveId: ID!): MethodologyStats!
|
|
40
|
+
methodologyConnectionsFrom(driveId: ID!, documentId: String!): [MethodologyConnection!]!
|
|
41
|
+
methodologyConnectionsTo(driveId: ID!, targetRef: String!): [MethodologyConnection!]!
|
|
42
|
+
}
|
|
43
|
+
`;
|
|
44
|
+
resolvers = {
|
|
45
|
+
Query: {
|
|
46
|
+
methodologySearch: async (_, args) => {
|
|
47
|
+
const query = this.getQuery(args.driveId);
|
|
48
|
+
return query.searchClaims(args.query, args.limit ?? 50);
|
|
49
|
+
},
|
|
50
|
+
methodologyClaims: async (_, args) => {
|
|
51
|
+
const query = this.getQuery(args.driveId);
|
|
52
|
+
return query.allClaims();
|
|
53
|
+
},
|
|
54
|
+
methodologyClaimsByKind: async (_, args) => {
|
|
55
|
+
const query = this.getQuery(args.driveId);
|
|
56
|
+
return query.claimsByKind(args.kind);
|
|
57
|
+
},
|
|
58
|
+
methodologyClaimsByTopic: async (_, args) => {
|
|
59
|
+
const query = this.getQuery(args.driveId);
|
|
60
|
+
return query.claimsByTopic(args.topic);
|
|
61
|
+
},
|
|
62
|
+
methodologyClaimById: async (_, args) => {
|
|
63
|
+
const query = this.getQuery(args.driveId);
|
|
64
|
+
return query.claimByDocumentId(args.documentId) ?? null;
|
|
65
|
+
},
|
|
66
|
+
methodologyStats: async (_, args) => {
|
|
67
|
+
const query = this.getQuery(args.driveId);
|
|
68
|
+
return query.stats();
|
|
69
|
+
},
|
|
70
|
+
methodologyConnectionsFrom: async (_, args) => {
|
|
71
|
+
const query = this.getQuery(args.driveId);
|
|
72
|
+
return query.connectionsFrom(args.documentId);
|
|
73
|
+
},
|
|
74
|
+
methodologyConnectionsTo: async (_, args) => {
|
|
75
|
+
const query = this.getQuery(args.driveId);
|
|
76
|
+
return query.connectionsTo(args.targetRef);
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
constructor(args) {
|
|
81
|
+
super(args);
|
|
82
|
+
}
|
|
83
|
+
getQuery(driveId) {
|
|
84
|
+
const queryBuilder = MethodologyIndexerProcessor.query(driveId, this.relationalDb);
|
|
85
|
+
return createMethodologyQuery(queryBuilder);
|
|
86
|
+
}
|
|
87
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powerhousedao/knowledge-note",
|
|
3
3
|
"description": "Knowledge Note document model package for Powerhouse",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.1",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"files": [
|
|
@@ -23,6 +23,50 @@
|
|
|
23
23
|
"types": "./dist/editors/index.d.ts",
|
|
24
24
|
"import": "./dist/editors/index.js"
|
|
25
25
|
},
|
|
26
|
+
"./document-models/derivation": {
|
|
27
|
+
"types": "./dist/document-models/derivation/index.d.ts",
|
|
28
|
+
"import": "./dist/document-models/derivation/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./document-models/health-report": {
|
|
31
|
+
"types": "./dist/document-models/health-report/index.d.ts",
|
|
32
|
+
"import": "./dist/document-models/health-report/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./document-models/knowledge-graph": {
|
|
35
|
+
"types": "./dist/document-models/knowledge-graph/index.d.ts",
|
|
36
|
+
"import": "./dist/document-models/knowledge-graph/index.js"
|
|
37
|
+
},
|
|
38
|
+
"./document-models/knowledge-note": {
|
|
39
|
+
"types": "./dist/document-models/knowledge-note/index.d.ts",
|
|
40
|
+
"import": "./dist/document-models/knowledge-note/index.js"
|
|
41
|
+
},
|
|
42
|
+
"./document-models/moc": {
|
|
43
|
+
"types": "./dist/document-models/moc/index.d.ts",
|
|
44
|
+
"import": "./dist/document-models/moc/index.js"
|
|
45
|
+
},
|
|
46
|
+
"./document-models/observation": {
|
|
47
|
+
"types": "./dist/document-models/observation/index.d.ts",
|
|
48
|
+
"import": "./dist/document-models/observation/index.js"
|
|
49
|
+
},
|
|
50
|
+
"./document-models/pipeline-queue": {
|
|
51
|
+
"types": "./dist/document-models/pipeline-queue/index.d.ts",
|
|
52
|
+
"import": "./dist/document-models/pipeline-queue/index.js"
|
|
53
|
+
},
|
|
54
|
+
"./document-models/research-claim": {
|
|
55
|
+
"types": "./dist/document-models/research-claim/index.d.ts",
|
|
56
|
+
"import": "./dist/document-models/research-claim/index.js"
|
|
57
|
+
},
|
|
58
|
+
"./document-models/source": {
|
|
59
|
+
"types": "./dist/document-models/source/index.d.ts",
|
|
60
|
+
"import": "./dist/document-models/source/index.js"
|
|
61
|
+
},
|
|
62
|
+
"./document-models/tension": {
|
|
63
|
+
"types": "./dist/document-models/tension/index.d.ts",
|
|
64
|
+
"import": "./dist/document-models/tension/index.js"
|
|
65
|
+
},
|
|
66
|
+
"./document-models/vault-config": {
|
|
67
|
+
"types": "./dist/document-models/vault-config/index.d.ts",
|
|
68
|
+
"import": "./dist/document-models/vault-config/index.js"
|
|
69
|
+
},
|
|
26
70
|
"./document-models/*": {
|
|
27
71
|
"types": "./dist/document-models/*/index.d.ts",
|
|
28
72
|
"import": "./dist/document-models/*/index.js"
|