@grafema/types 0.1.0-alpha.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/src/rfdb.ts ADDED
@@ -0,0 +1,279 @@
1
+ /**
2
+ * RFDB Protocol Types - types for RFDB client-server protocol
3
+ */
4
+
5
+ import type { NodeType } from './nodes.js';
6
+ import type { EdgeType } from './edges.js';
7
+
8
+ // === COMMANDS ===
9
+ export type RFDBCommand =
10
+ // Write operations
11
+ | 'addNodes'
12
+ | 'addEdges'
13
+ | 'deleteNode'
14
+ | 'deleteEdge'
15
+ | 'clear'
16
+ | 'updateNodeVersion'
17
+ // Read operations
18
+ | 'getNode'
19
+ | 'nodeExists'
20
+ | 'findByType'
21
+ | 'findByAttr'
22
+ | 'queryNodes'
23
+ | 'getAllNodes'
24
+ | 'getAllEdges'
25
+ | 'isEndpoint'
26
+ | 'getNodeIdentifier'
27
+ // Traversal
28
+ | 'neighbors'
29
+ | 'bfs'
30
+ | 'dfs'
31
+ | 'getOutgoingEdges'
32
+ | 'getIncomingEdges'
33
+ // Stats
34
+ | 'nodeCount'
35
+ | 'edgeCount'
36
+ | 'countNodesByType'
37
+ | 'countEdgesByType'
38
+ // Control
39
+ | 'flush'
40
+ | 'compact'
41
+ | 'ping'
42
+ | 'shutdown'
43
+ // Datalog
44
+ | 'datalogLoadRules'
45
+ | 'datalogClearRules'
46
+ | 'datalogQuery'
47
+ | 'checkGuarantee';
48
+
49
+ // === WIRE FORMAT ===
50
+ // Nodes as sent over the wire
51
+ export interface WireNode {
52
+ id: string;
53
+ nodeType: NodeType;
54
+ name: string;
55
+ file: string;
56
+ exported: boolean;
57
+ metadata: string; // JSON string
58
+ }
59
+
60
+ // Edges as sent over the wire
61
+ export interface WireEdge {
62
+ src: string;
63
+ dst: string;
64
+ edgeType: EdgeType;
65
+ metadata: string; // JSON string
66
+ }
67
+
68
+ // === REQUEST TYPES ===
69
+ export interface RFDBRequest {
70
+ cmd: RFDBCommand;
71
+ [key: string]: unknown;
72
+ }
73
+
74
+ export interface AddNodesRequest extends RFDBRequest {
75
+ cmd: 'addNodes';
76
+ nodes: WireNode[];
77
+ }
78
+
79
+ export interface AddEdgesRequest extends RFDBRequest {
80
+ cmd: 'addEdges';
81
+ edges: WireEdge[];
82
+ skipValidation?: boolean;
83
+ }
84
+
85
+ export interface DeleteNodeRequest extends RFDBRequest {
86
+ cmd: 'deleteNode';
87
+ id: string;
88
+ }
89
+
90
+ export interface DeleteEdgeRequest extends RFDBRequest {
91
+ cmd: 'deleteEdge';
92
+ src: string;
93
+ dst: string;
94
+ edgeType: EdgeType;
95
+ }
96
+
97
+ export interface GetNodeRequest extends RFDBRequest {
98
+ cmd: 'getNode';
99
+ id: string;
100
+ }
101
+
102
+ export interface NodeExistsRequest extends RFDBRequest {
103
+ cmd: 'nodeExists';
104
+ id: string;
105
+ }
106
+
107
+ export interface FindByTypeRequest extends RFDBRequest {
108
+ cmd: 'findByType';
109
+ nodeType: NodeType;
110
+ }
111
+
112
+ export interface FindByAttrRequest extends RFDBRequest {
113
+ cmd: 'findByAttr';
114
+ query: Record<string, unknown>;
115
+ }
116
+
117
+ export interface NeighborsRequest extends RFDBRequest {
118
+ cmd: 'neighbors';
119
+ id: string;
120
+ edgeTypes?: EdgeType[];
121
+ }
122
+
123
+ export interface BfsRequest extends RFDBRequest {
124
+ cmd: 'bfs';
125
+ startIds: string[];
126
+ maxDepth: number;
127
+ edgeTypes?: EdgeType[];
128
+ }
129
+
130
+ export interface GetOutgoingEdgesRequest extends RFDBRequest {
131
+ cmd: 'getOutgoingEdges';
132
+ id: string;
133
+ edgeTypes?: EdgeType[] | null;
134
+ }
135
+
136
+ export interface GetIncomingEdgesRequest extends RFDBRequest {
137
+ cmd: 'getIncomingEdges';
138
+ id: string;
139
+ edgeTypes?: EdgeType[] | null;
140
+ }
141
+
142
+ export interface CountNodesByTypeRequest extends RFDBRequest {
143
+ cmd: 'countNodesByType';
144
+ types?: NodeType[] | null;
145
+ }
146
+
147
+ export interface CountEdgesByTypeRequest extends RFDBRequest {
148
+ cmd: 'countEdgesByType';
149
+ edgeTypes?: EdgeType[] | null;
150
+ }
151
+
152
+ // === RESPONSE TYPES ===
153
+ export interface RFDBResponse {
154
+ error?: string;
155
+ [key: string]: unknown;
156
+ }
157
+
158
+ export interface AddNodesResponse extends RFDBResponse {
159
+ count?: number;
160
+ }
161
+
162
+ export interface AddEdgesResponse extends RFDBResponse {
163
+ count?: number;
164
+ }
165
+
166
+ export interface GetNodeResponse extends RFDBResponse {
167
+ node?: WireNode | null;
168
+ }
169
+
170
+ export interface NodeExistsResponse extends RFDBResponse {
171
+ value: boolean;
172
+ }
173
+
174
+ export interface FindByTypeResponse extends RFDBResponse {
175
+ ids: string[];
176
+ }
177
+
178
+ export interface FindByAttrResponse extends RFDBResponse {
179
+ ids: string[];
180
+ }
181
+
182
+ export interface NeighborsResponse extends RFDBResponse {
183
+ ids: string[];
184
+ }
185
+
186
+ export interface BfsResponse extends RFDBResponse {
187
+ ids: string[];
188
+ }
189
+
190
+ export interface GetEdgesResponse extends RFDBResponse {
191
+ edges: WireEdge[];
192
+ }
193
+
194
+ export interface CountResponse extends RFDBResponse {
195
+ count: number;
196
+ }
197
+
198
+ export interface CountsByTypeResponse extends RFDBResponse {
199
+ counts: Record<string, number>;
200
+ }
201
+
202
+ export interface PingResponse extends RFDBResponse {
203
+ pong: boolean;
204
+ version: string;
205
+ }
206
+
207
+ // === ATTR QUERY ===
208
+ export interface AttrQuery {
209
+ nodeType?: string;
210
+ type?: string;
211
+ kind?: string;
212
+ name?: string;
213
+ file?: string;
214
+ exported?: boolean;
215
+ version?: string;
216
+ }
217
+
218
+ // === DATALOG TYPES ===
219
+ export interface DatalogBinding {
220
+ [key: string]: string;
221
+ }
222
+
223
+ export interface DatalogResult {
224
+ bindings: DatalogBinding;
225
+ }
226
+
227
+ // === CLIENT INTERFACE ===
228
+ export interface IRFDBClient {
229
+ readonly socketPath: string;
230
+ readonly connected: boolean;
231
+
232
+ // Connection
233
+ connect(): Promise<void>;
234
+ close(): Promise<void>;
235
+ ping(): Promise<string | false>;
236
+ shutdown(): Promise<void>;
237
+
238
+ // Write operations
239
+ addNodes(nodes: WireNode[]): Promise<AddNodesResponse>;
240
+ addEdges(edges: WireEdge[], skipValidation?: boolean): Promise<AddEdgesResponse>;
241
+ deleteNode(id: string): Promise<RFDBResponse>;
242
+ deleteEdge(src: string, dst: string, edgeType: EdgeType): Promise<RFDBResponse>;
243
+ clear(): Promise<RFDBResponse>;
244
+ updateNodeVersion(id: string, version: string): Promise<RFDBResponse>;
245
+
246
+ // Read operations
247
+ getNode(id: string): Promise<WireNode | null>;
248
+ nodeExists(id: string): Promise<boolean>;
249
+ findByType(nodeType: NodeType): Promise<string[]>;
250
+ findByAttr(query: Record<string, unknown>): Promise<string[]>;
251
+ queryNodes(query: AttrQuery): AsyncGenerator<WireNode, void, unknown>;
252
+ getAllNodes(query?: AttrQuery): Promise<WireNode[]>;
253
+ getAllEdges(): Promise<WireEdge[]>;
254
+ isEndpoint(id: string): Promise<boolean>;
255
+ getNodeIdentifier(id: string): Promise<string | null>;
256
+
257
+ // Traversal
258
+ neighbors(id: string, edgeTypes?: EdgeType[]): Promise<string[]>;
259
+ bfs(startIds: string[], maxDepth: number, edgeTypes?: EdgeType[]): Promise<string[]>;
260
+ dfs(startIds: string[], maxDepth: number, edgeTypes?: EdgeType[]): Promise<string[]>;
261
+ getOutgoingEdges(id: string, edgeTypes?: EdgeType[] | null): Promise<WireEdge[]>;
262
+ getIncomingEdges(id: string, edgeTypes?: EdgeType[] | null): Promise<WireEdge[]>;
263
+
264
+ // Stats
265
+ nodeCount(): Promise<number>;
266
+ edgeCount(): Promise<number>;
267
+ countNodesByType(types?: NodeType[] | null): Promise<Record<string, number>>;
268
+ countEdgesByType(edgeTypes?: EdgeType[] | null): Promise<Record<string, number>>;
269
+
270
+ // Control
271
+ flush(): Promise<RFDBResponse>;
272
+ compact(): Promise<RFDBResponse>;
273
+
274
+ // Datalog
275
+ datalogLoadRules(source: string): Promise<number>;
276
+ datalogClearRules(): Promise<RFDBResponse>;
277
+ datalogQuery(query: string): Promise<DatalogResult[]>;
278
+ checkGuarantee(ruleSource: string): Promise<DatalogResult[]>;
279
+ }