flowquery 1.0.63 → 1.0.64
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/compute/runner.js +2 -2
- package/dist/compute/runner.js.map +1 -1
- package/dist/flowquery.min.js +1 -1
- package/dist/graph/data_resolver.d.ts +37 -0
- package/dist/graph/data_resolver.d.ts.map +1 -0
- package/dist/graph/data_resolver.js +221 -0
- package/dist/graph/data_resolver.js.map +1 -0
- package/dist/graph/database.d.ts +8 -20
- package/dist/graph/database.d.ts.map +1 -1
- package/dist/graph/database.js +47 -190
- package/dist/graph/database.js.map +1 -1
- package/dist/graph/pattern.js +3 -3
- package/dist/graph/pattern.js.map +1 -1
- package/dist/parsing/functions/schema.js +2 -2
- package/dist/parsing/functions/schema.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import DataCache from "./data_cache";
|
|
2
|
+
import Node from "./node";
|
|
3
|
+
import NodeData from "./node_data";
|
|
4
|
+
import Relationship from "./relationship";
|
|
5
|
+
import RelationshipData from "./relationship_data";
|
|
6
|
+
/**
|
|
7
|
+
* Resolves pattern elements (nodes and relationships) to data by querying
|
|
8
|
+
* the Database registry. Handles label compatibility, caching, and schema
|
|
9
|
+
* introspection — keeping query-resolution concerns separate from storage.
|
|
10
|
+
*/
|
|
11
|
+
declare class DataResolver {
|
|
12
|
+
private static instance;
|
|
13
|
+
private _dataCache;
|
|
14
|
+
static getInstance(): DataResolver;
|
|
15
|
+
/**
|
|
16
|
+
* Sets the data cache for the current query execution.
|
|
17
|
+
* Each top-level Runner creates its own DataCache instance.
|
|
18
|
+
*/
|
|
19
|
+
set dataCache(cache: DataCache);
|
|
20
|
+
schema(): Promise<Record<string, any>[]>;
|
|
21
|
+
getData(element: Node | Relationship): Promise<NodeData | RelationshipData>;
|
|
22
|
+
/** Resolve labels from a node, following NodeReference if needed. */
|
|
23
|
+
private static resolveLabels;
|
|
24
|
+
/**
|
|
25
|
+
* Check whether a MATCH pattern's endpoint labels are compatible with
|
|
26
|
+
* a stored physical relationship's source/target labels.
|
|
27
|
+
*/
|
|
28
|
+
private static isRelationshipCompatible;
|
|
29
|
+
/**
|
|
30
|
+
* Collect all physical relationships matching the pattern's types and endpoint labels.
|
|
31
|
+
* If types is empty, all registered relationship types are considered.
|
|
32
|
+
*/
|
|
33
|
+
private getRelationshipEntries;
|
|
34
|
+
private static extractArgs;
|
|
35
|
+
}
|
|
36
|
+
export default DataResolver;
|
|
37
|
+
//# sourceMappingURL=data_resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data_resolver.d.ts","sourceRoot":"","sources":["../../src/graph/data_resolver.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,OAAO,IAAI,MAAM,QAAQ,CAAC;AAC1B,OAAO,QAAwB,MAAM,aAAa,CAAC;AAGnD,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAC1C,OAAO,gBAAwC,MAAM,qBAAqB,CAAC;AAE3E;;;;GAIG;AACH,cAAM,YAAY;IACd,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAe;IACtC,OAAO,CAAC,UAAU,CAA8B;WAElC,WAAW,IAAI,YAAY;IAMzC;;;OAGG;IACH,IAAW,SAAS,CAAC,KAAK,EAAE,SAAS,EAEpC;IAEY,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC;IA0CxC,OAAO,CAAC,OAAO,EAAE,IAAI,GAAG,YAAY,GAAG,OAAO,CAAC,QAAQ,GAAG,gBAAgB,CAAC;IAkExF,qEAAqE;IACrE,OAAO,CAAC,MAAM,CAAC,aAAa;IAU5B;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,wBAAwB;IAevC;;;OAGG;IACH,OAAO,CAAC,sBAAsB;IAsB9B,OAAO,CAAC,MAAM,CAAC,WAAW;CAU7B;AAED,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const data_cache_1 = __importDefault(require("./data_cache"));
|
|
27
|
+
const database_1 = __importDefault(require("./database"));
|
|
28
|
+
const node_1 = __importDefault(require("./node"));
|
|
29
|
+
const node_data_1 = __importDefault(require("./node_data"));
|
|
30
|
+
const node_reference_1 = __importDefault(require("./node_reference"));
|
|
31
|
+
const relationship_1 = __importDefault(require("./relationship"));
|
|
32
|
+
const relationship_data_1 = __importDefault(require("./relationship_data"));
|
|
33
|
+
/**
|
|
34
|
+
* Resolves pattern elements (nodes and relationships) to data by querying
|
|
35
|
+
* the Database registry. Handles label compatibility, caching, and schema
|
|
36
|
+
* introspection — keeping query-resolution concerns separate from storage.
|
|
37
|
+
*/
|
|
38
|
+
class DataResolver {
|
|
39
|
+
constructor() {
|
|
40
|
+
this._dataCache = new data_cache_1.default();
|
|
41
|
+
}
|
|
42
|
+
static getInstance() {
|
|
43
|
+
if (!DataResolver.instance) {
|
|
44
|
+
DataResolver.instance = new DataResolver();
|
|
45
|
+
}
|
|
46
|
+
return DataResolver.instance;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Sets the data cache for the current query execution.
|
|
50
|
+
* Each top-level Runner creates its own DataCache instance.
|
|
51
|
+
*/
|
|
52
|
+
set dataCache(cache) {
|
|
53
|
+
this._dataCache = cache;
|
|
54
|
+
}
|
|
55
|
+
schema() {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
var _a, _b;
|
|
58
|
+
const db = database_1.default.getInstance();
|
|
59
|
+
const result = [];
|
|
60
|
+
for (const [label, physical] of db.nodes) {
|
|
61
|
+
const records = yield physical.data();
|
|
62
|
+
const entry = { kind: "Node", label };
|
|
63
|
+
if (records.length > 0) {
|
|
64
|
+
const _c = records[0], { id } = _c, sample = __rest(_c, ["id"]);
|
|
65
|
+
const properties = Object.keys(sample);
|
|
66
|
+
if (properties.length > 0) {
|
|
67
|
+
entry.properties = properties;
|
|
68
|
+
entry.sample = sample;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
result.push(entry);
|
|
72
|
+
}
|
|
73
|
+
for (const [type, typeMap] of db.relationships) {
|
|
74
|
+
for (const physical of typeMap.values()) {
|
|
75
|
+
const records = yield physical.data();
|
|
76
|
+
const entry = {
|
|
77
|
+
kind: "Relationship",
|
|
78
|
+
type,
|
|
79
|
+
from_label: ((_a = physical.source) === null || _a === void 0 ? void 0 : _a.label) || null,
|
|
80
|
+
to_label: ((_b = physical.target) === null || _b === void 0 ? void 0 : _b.label) || null,
|
|
81
|
+
};
|
|
82
|
+
if (records.length > 0) {
|
|
83
|
+
const _d = records[0], { left_id, right_id } = _d, sample = __rest(_d, ["left_id", "right_id"]);
|
|
84
|
+
const properties = Object.keys(sample);
|
|
85
|
+
if (properties.length > 0) {
|
|
86
|
+
entry.properties = properties;
|
|
87
|
+
entry.sample = sample;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
result.push(entry);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return result;
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
getData(element) {
|
|
97
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
var _a, _b, _c, _d;
|
|
99
|
+
const db = database_1.default.getInstance();
|
|
100
|
+
if (element instanceof node_1.default) {
|
|
101
|
+
const args = DataResolver.extractArgs(element.properties);
|
|
102
|
+
if (element.labels.length === 0) {
|
|
103
|
+
// Unlabeled node: match all physical nodes in the database
|
|
104
|
+
const allRecords = [];
|
|
105
|
+
for (const [label, physical] of db.nodes) {
|
|
106
|
+
const data = yield this._dataCache.get(`node:${label}`, physical, null);
|
|
107
|
+
for (const record of data) {
|
|
108
|
+
allRecords.push(Object.assign(Object.assign({}, record), { _label: label }));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return new node_data_1.default(allRecords);
|
|
112
|
+
}
|
|
113
|
+
if (element.labels.length > 1) {
|
|
114
|
+
// ORed labels: collect from all matching physical nodes
|
|
115
|
+
const allRecords = [];
|
|
116
|
+
for (const lbl of element.labels) {
|
|
117
|
+
const physical = db.nodes.get(lbl);
|
|
118
|
+
if (physical) {
|
|
119
|
+
const data = yield this._dataCache.get(`node:${lbl}`, physical, args);
|
|
120
|
+
for (const record of data) {
|
|
121
|
+
allRecords.push(Object.assign(Object.assign({}, record), { _label: lbl }));
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return new node_data_1.default(allRecords);
|
|
126
|
+
}
|
|
127
|
+
const node = db.getNode(element);
|
|
128
|
+
if (node === null) {
|
|
129
|
+
throw new Error(`Physical node not found for label ${element.label}`);
|
|
130
|
+
}
|
|
131
|
+
const data = yield this._dataCache.get(`node:${element.label}`, node, args);
|
|
132
|
+
const label = element.label;
|
|
133
|
+
const records = data.map((record) => (Object.assign(Object.assign({}, record), { _label: label })));
|
|
134
|
+
return new node_data_1.default(records);
|
|
135
|
+
}
|
|
136
|
+
else if (element instanceof relationship_1.default) {
|
|
137
|
+
const args = DataResolver.extractArgs(element.properties);
|
|
138
|
+
const entries = this.getRelationshipEntries(element, db);
|
|
139
|
+
if (entries.length === 0) {
|
|
140
|
+
if (element.types.length === 0) {
|
|
141
|
+
return new relationship_data_1.default([]);
|
|
142
|
+
}
|
|
143
|
+
throw new Error(`No physical relationships found for type${element.types.length > 1 ? "s" : ""} ${element.types.join(", ")}`);
|
|
144
|
+
}
|
|
145
|
+
const allRecords = [];
|
|
146
|
+
for (const [typeName, physical] of entries) {
|
|
147
|
+
const cacheKey = `rel:${(_b = (_a = physical.source) === null || _a === void 0 ? void 0 : _a.label) !== null && _b !== void 0 ? _b : ""}:${typeName}:${(_d = (_c = physical.target) === null || _c === void 0 ? void 0 : _c.label) !== null && _d !== void 0 ? _d : ""}`;
|
|
148
|
+
const records = (yield this._dataCache.get(cacheKey, physical, args));
|
|
149
|
+
for (const record of records) {
|
|
150
|
+
allRecords.push(Object.assign(Object.assign({}, record), { _type: typeName }));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return new relationship_data_1.default(allRecords);
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
throw new Error("Element is neither Node nor Relationship");
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
/** Resolve labels from a node, following NodeReference if needed. */
|
|
161
|
+
static resolveLabels(node) {
|
|
162
|
+
if (!node)
|
|
163
|
+
return [];
|
|
164
|
+
if (node.labels.length > 0)
|
|
165
|
+
return node.labels;
|
|
166
|
+
if (node instanceof node_reference_1.default) {
|
|
167
|
+
const ref = node.reference;
|
|
168
|
+
if (ref instanceof node_1.default)
|
|
169
|
+
return ref.labels;
|
|
170
|
+
}
|
|
171
|
+
return [];
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Check whether a MATCH pattern's endpoint labels are compatible with
|
|
175
|
+
* a stored physical relationship's source/target labels.
|
|
176
|
+
*/
|
|
177
|
+
static isRelationshipCompatible(relationship, physical) {
|
|
178
|
+
var _a, _b, _c, _d;
|
|
179
|
+
const match = (pattern, label) => pattern.length === 0 || (label !== null && pattern.includes(label));
|
|
180
|
+
const srcLabels = DataResolver.resolveLabels(relationship.source);
|
|
181
|
+
const tgtLabels = DataResolver.resolveLabels(relationship.target);
|
|
182
|
+
const physSrc = (_b = (_a = physical.source) === null || _a === void 0 ? void 0 : _a.label) !== null && _b !== void 0 ? _b : null;
|
|
183
|
+
const physTgt = (_d = (_c = physical.target) === null || _c === void 0 ? void 0 : _c.label) !== null && _d !== void 0 ? _d : null;
|
|
184
|
+
return relationship.direction === "left"
|
|
185
|
+
? match(srcLabels, physTgt) && match(tgtLabels, physSrc)
|
|
186
|
+
: match(srcLabels, physSrc) && match(tgtLabels, physTgt);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Collect all physical relationships matching the pattern's types and endpoint labels.
|
|
190
|
+
* If types is empty, all registered relationship types are considered.
|
|
191
|
+
*/
|
|
192
|
+
getRelationshipEntries(relationship, db) {
|
|
193
|
+
const types = relationship.types.length === 0
|
|
194
|
+
? Array.from(db.relationships.keys())
|
|
195
|
+
: relationship.types;
|
|
196
|
+
const result = [];
|
|
197
|
+
for (const type of types) {
|
|
198
|
+
const typeMap = db.relationships.get(type);
|
|
199
|
+
if (!typeMap)
|
|
200
|
+
continue;
|
|
201
|
+
for (const physical of typeMap.values()) {
|
|
202
|
+
if (DataResolver.isRelationshipCompatible(relationship, physical)) {
|
|
203
|
+
result.push([type, physical]);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return result;
|
|
208
|
+
}
|
|
209
|
+
static extractArgs(properties) {
|
|
210
|
+
if (properties.size === 0) {
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
const args = {};
|
|
214
|
+
for (const [key, expression] of properties) {
|
|
215
|
+
args[key] = expression.value();
|
|
216
|
+
}
|
|
217
|
+
return args;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
exports.default = DataResolver;
|
|
221
|
+
//# sourceMappingURL=data_resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data_resolver.js","sourceRoot":"","sources":["../../src/graph/data_resolver.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8DAAqC;AACrC,0DAAkC;AAClC,kDAA0B;AAC1B,4DAAmD;AACnD,sEAA6C;AAE7C,kEAA0C;AAC1C,4EAA2E;AAE3E;;;;GAIG;AACH,MAAM,YAAY;IAAlB;QAEY,eAAU,GAAc,IAAI,oBAAS,EAAE,CAAC;IA8LpD,CAAC;IA5LU,MAAM,CAAC,WAAW;QACrB,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC;YACzB,YAAY,CAAC,QAAQ,GAAG,IAAI,YAAY,EAAE,CAAC;QAC/C,CAAC;QACD,OAAO,YAAY,CAAC,QAAQ,CAAC;IACjC,CAAC;IACD;;;OAGG;IACH,IAAW,SAAS,CAAC,KAAgB;QACjC,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;IAC5B,CAAC;IAEY,MAAM;;;YACf,MAAM,EAAE,GAAG,kBAAQ,CAAC,WAAW,EAAE,CAAC;YAClC,MAAM,MAAM,GAA0B,EAAE,CAAC;YAEzC,KAAK,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,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ache";
|
|
3
2
|
import Node from "./node";
|
|
4
|
-
import NodeData from "./node_data";
|
|
5
3
|
import PhysicalNode from "./physical_node";
|
|
6
4
|
import PhysicalRelationship from "./physical_relationship";
|
|
7
5
|
import Relationship from "./relationship";
|
|
8
|
-
import RelationshipData from "./relationship_data";
|
|
9
6
|
declare class Database {
|
|
10
7
|
private static instance;
|
|
11
|
-
private static
|
|
12
|
-
private static
|
|
13
|
-
private _dataCache;
|
|
8
|
+
private static _nodes;
|
|
9
|
+
private static _relationships;
|
|
14
10
|
static getInstance(): Database;
|
|
11
|
+
/** Read-only access to registered nodes. */
|
|
12
|
+
get nodes(): Map<string, PhysicalNode>;
|
|
13
|
+
/** Read-only access to registered relationships (type → endpoint-key → physical). */
|
|
14
|
+
get relationships(): Map<string, Map<string, PhysicalRelationship>>;
|
|
15
15
|
addNode(node: Node, statement: ASTNode): void;
|
|
16
16
|
removeNode(node: Node): void;
|
|
17
17
|
getNode(node: Node): PhysicalNode | null;
|
|
18
|
+
/** Endpoint-only key: "Source:Target" */
|
|
19
|
+
private static endpointKey;
|
|
18
20
|
addRelationship(relationship: Relationship, statement: ASTNode): void;
|
|
19
21
|
removeRelationship(relationship: Relationship): void;
|
|
20
22
|
getRelationship(relationship: Relationship): PhysicalRelationship | null;
|
|
21
|
-
private isRelationshipCompatible;
|
|
22
|
-
private getRelationshipEntries;
|
|
23
|
-
/**
|
|
24
|
-
* Sets the data cache for the current query execution.
|
|
25
|
-
* Each top-level Runner creates its own DataCache instance.
|
|
26
|
-
*/
|
|
27
|
-
set dataCache(cache: DataCache);
|
|
28
|
-
schema(): Promise<Record<string, any>[]>;
|
|
29
|
-
getData(element: Node | Relationship): Promise<NodeData | RelationshipData>;
|
|
30
|
-
/**
|
|
31
|
-
* Extracts property constraint values from a node/relationship's properties map
|
|
32
|
-
* to pass as $args to the inner virtual definition query.
|
|
33
|
-
*/
|
|
34
|
-
private extractArgs;
|
|
35
23
|
}
|
|
36
24
|
export default Database;
|
|
37
25
|
//# sourceMappingURL=database.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/graph/database.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,qBAAqB,CAAC;AAC1C,OAAO,
|
|
1
|
+
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/graph/database.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,qBAAqB,CAAC;AAC1C,OAAO,IAAI,MAAM,QAAQ,CAAC;AAC1B,OAAO,YAAY,MAAM,iBAAiB,CAAC;AAC3C,OAAO,oBAAoB,MAAM,yBAAyB,CAAC;AAC3D,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAE1C,cAAM,QAAQ;IACV,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAW;IAClC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAwC;IAC7D,OAAO,CAAC,MAAM,CAAC,cAAc,CAA6D;WAE5E,WAAW,IAAI,QAAQ;IAMrC,4CAA4C;IAC5C,IAAW,KAAK,IAAI,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAE5C;IACD,qFAAqF;IACrF,IAAW,aAAa,IAAI,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC,CAEzE;IACM,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,GAAG,IAAI;IAQ7C,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAM5B,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,YAAY,GAAG,IAAI;IAG/C,yCAAyC;IACzC,OAAO,CAAC,MAAM,CAAC,WAAW;IAGnB,eAAe,CAAC,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,OAAO,GAAG,IAAI;IAmBrE,kBAAkB,CAAC,YAAY,EAAE,YAAY,GAAG,IAAI;IAepD,eAAe,CAAC,YAAY,EAAE,YAAY,GAAG,oBAAoB,GAAG,IAAI;CAclF;AAED,eAAe,QAAQ,CAAC"}
|
package/dist/graph/database.js
CHANGED
|
@@ -1,63 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
-
var t = {};
|
|
13
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
-
t[p] = s[p];
|
|
15
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
-
t[p[i]] = s[p[i]];
|
|
19
|
-
}
|
|
20
|
-
return t;
|
|
21
|
-
};
|
|
22
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
4
|
};
|
|
25
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
const data_cache_1 = __importDefault(require("./data_cache"));
|
|
27
|
-
const node_1 = __importDefault(require("./node"));
|
|
28
|
-
const node_data_1 = __importDefault(require("./node_data"));
|
|
29
6
|
const physical_node_1 = __importDefault(require("./physical_node"));
|
|
30
7
|
const physical_relationship_1 = __importDefault(require("./physical_relationship"));
|
|
31
|
-
const relationship_1 = __importDefault(require("./relationship"));
|
|
32
|
-
const relationship_data_1 = __importDefault(require("./relationship_data"));
|
|
33
8
|
class Database {
|
|
34
|
-
constructor() {
|
|
35
|
-
this._dataCache = new data_cache_1.default();
|
|
36
|
-
}
|
|
37
9
|
static getInstance() {
|
|
38
10
|
if (!Database.instance) {
|
|
39
11
|
Database.instance = new Database();
|
|
40
12
|
}
|
|
41
13
|
return Database.instance;
|
|
42
14
|
}
|
|
15
|
+
/** Read-only access to registered nodes. */
|
|
16
|
+
get nodes() {
|
|
17
|
+
return Database._nodes;
|
|
18
|
+
}
|
|
19
|
+
/** Read-only access to registered relationships (type → endpoint-key → physical). */
|
|
20
|
+
get relationships() {
|
|
21
|
+
return Database._relationships;
|
|
22
|
+
}
|
|
43
23
|
addNode(node, statement) {
|
|
44
24
|
if (node.label === null) {
|
|
45
25
|
throw new Error("Node label is null");
|
|
46
26
|
}
|
|
47
27
|
const physical = new physical_node_1.default(null, node.label);
|
|
48
28
|
physical.statement = statement;
|
|
49
|
-
Database.
|
|
29
|
+
Database._nodes.set(node.label, physical);
|
|
50
30
|
}
|
|
51
31
|
removeNode(node) {
|
|
52
32
|
if (node.label === null) {
|
|
53
33
|
throw new Error("Node label is null");
|
|
54
34
|
}
|
|
55
|
-
Database.
|
|
35
|
+
Database._nodes.delete(node.label);
|
|
56
36
|
}
|
|
57
37
|
getNode(node) {
|
|
58
|
-
return Database.
|
|
38
|
+
return Database._nodes.get(node.label) || null;
|
|
39
|
+
}
|
|
40
|
+
/** Endpoint-only key: "Source:Target" */
|
|
41
|
+
static endpointKey(sourceLabel, targetLabel) {
|
|
42
|
+
return `${sourceLabel !== null && sourceLabel !== void 0 ? sourceLabel : ""}:${targetLabel !== null && targetLabel !== void 0 ? targetLabel : ""}`;
|
|
59
43
|
}
|
|
60
44
|
addRelationship(relationship, statement) {
|
|
45
|
+
var _a, _b, _c, _d;
|
|
61
46
|
if (relationship.type === null) {
|
|
62
47
|
throw new Error("Relationship type is null");
|
|
63
48
|
}
|
|
@@ -65,175 +50,47 @@ class Database {
|
|
|
65
50
|
physical.statement = statement;
|
|
66
51
|
physical.source = relationship.source;
|
|
67
52
|
physical.target = relationship.target;
|
|
68
|
-
Database.
|
|
53
|
+
const key = Database.endpointKey((_b = (_a = relationship.source) === null || _a === void 0 ? void 0 : _a.label) !== null && _b !== void 0 ? _b : null, (_d = (_c = relationship.target) === null || _c === void 0 ? void 0 : _c.label) !== null && _d !== void 0 ? _d : null);
|
|
54
|
+
let typeMap = Database._relationships.get(relationship.type);
|
|
55
|
+
if (!typeMap) {
|
|
56
|
+
typeMap = new Map();
|
|
57
|
+
Database._relationships.set(relationship.type, typeMap);
|
|
58
|
+
}
|
|
59
|
+
typeMap.set(key, physical);
|
|
69
60
|
}
|
|
70
61
|
removeRelationship(relationship) {
|
|
62
|
+
var _a, _b, _c, _d;
|
|
71
63
|
if (relationship.type === null) {
|
|
72
64
|
throw new Error("Relationship type is null");
|
|
73
65
|
}
|
|
74
|
-
Database.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const patternSourceLabels = (_b = (_a = relationship.source) === null || _a === void 0 ? void 0 : _a.labels) !== null && _b !== void 0 ? _b : [];
|
|
82
|
-
const patternTargetLabels = (_d = (_c = relationship.target) === null || _c === void 0 ? void 0 : _c.labels) !== null && _d !== void 0 ? _d : [];
|
|
83
|
-
const physicalSourceLabel = (_f = (_e = physical.source) === null || _e === void 0 ? void 0 : _e.label) !== null && _f !== void 0 ? _f : null;
|
|
84
|
-
const physicalTargetLabel = (_h = (_g = physical.target) === null || _g === void 0 ? void 0 : _g.label) !== null && _h !== void 0 ? _h : null;
|
|
85
|
-
const matchesLabel = (patternLabels, physicalLabel) => patternLabels.length === 0 ||
|
|
86
|
-
(physicalLabel !== null && patternLabels.includes(physicalLabel));
|
|
87
|
-
if (relationship.direction === "left") {
|
|
88
|
-
return (matchesLabel(patternSourceLabels, physicalTargetLabel) &&
|
|
89
|
-
matchesLabel(patternTargetLabels, physicalSourceLabel));
|
|
90
|
-
}
|
|
91
|
-
return (matchesLabel(patternSourceLabels, physicalSourceLabel) &&
|
|
92
|
-
matchesLabel(patternTargetLabels, physicalTargetLabel));
|
|
93
|
-
}
|
|
94
|
-
getRelationshipEntries(relationship) {
|
|
95
|
-
if (relationship.types.length === 0) {
|
|
96
|
-
return Array.from(Database.relationships.entries()).filter(([, physical]) => this.isRelationshipCompatible(relationship, physical));
|
|
66
|
+
const typeMap = Database._relationships.get(relationship.type);
|
|
67
|
+
if (!typeMap)
|
|
68
|
+
return;
|
|
69
|
+
const key = Database.endpointKey((_b = (_a = relationship.source) === null || _a === void 0 ? void 0 : _a.label) !== null && _b !== void 0 ? _b : null, (_d = (_c = relationship.target) === null || _c === void 0 ? void 0 : _c.label) !== null && _d !== void 0 ? _d : null);
|
|
70
|
+
typeMap.delete(key);
|
|
71
|
+
if (typeMap.size === 0) {
|
|
72
|
+
Database._relationships.delete(relationship.type);
|
|
97
73
|
}
|
|
98
|
-
const result = [];
|
|
99
|
-
for (const type of relationship.types) {
|
|
100
|
-
const physical = Database.relationships.get(type);
|
|
101
|
-
if (physical && this.isRelationshipCompatible(relationship, physical)) {
|
|
102
|
-
result.push([type, physical]);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
return result;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Sets the data cache for the current query execution.
|
|
109
|
-
* Each top-level Runner creates its own DataCache instance.
|
|
110
|
-
*/
|
|
111
|
-
set dataCache(cache) {
|
|
112
|
-
this._dataCache = cache;
|
|
113
74
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
for (const [label, physical] of Database.nodes) {
|
|
119
|
-
const records = yield physical.data();
|
|
120
|
-
const entry = { kind: "Node", label };
|
|
121
|
-
if (records.length > 0) {
|
|
122
|
-
const _c = records[0], { id } = _c, sample = __rest(_c, ["id"]);
|
|
123
|
-
const properties = Object.keys(sample);
|
|
124
|
-
if (properties.length > 0) {
|
|
125
|
-
entry.properties = properties;
|
|
126
|
-
entry.sample = sample;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
result.push(entry);
|
|
130
|
-
}
|
|
131
|
-
for (const [type, physical] of Database.relationships) {
|
|
132
|
-
const records = yield physical.data();
|
|
133
|
-
const entry = {
|
|
134
|
-
kind: "Relationship",
|
|
135
|
-
type,
|
|
136
|
-
from_label: ((_a = physical.source) === null || _a === void 0 ? void 0 : _a.label) || null,
|
|
137
|
-
to_label: ((_b = physical.target) === null || _b === void 0 ? void 0 : _b.label) || null,
|
|
138
|
-
};
|
|
139
|
-
if (records.length > 0) {
|
|
140
|
-
const _d = records[0], { left_id, right_id } = _d, sample = __rest(_d, ["left_id", "right_id"]);
|
|
141
|
-
const properties = Object.keys(sample);
|
|
142
|
-
if (properties.length > 0) {
|
|
143
|
-
entry.properties = properties;
|
|
144
|
-
entry.sample = sample;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
result.push(entry);
|
|
148
|
-
}
|
|
149
|
-
return result;
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
getData(element) {
|
|
153
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
154
|
-
if (element instanceof node_1.default) {
|
|
155
|
-
const args = this.extractArgs(element.properties);
|
|
156
|
-
if (element.labels.length === 0) {
|
|
157
|
-
// Unlabeled node: match all physical nodes in the database
|
|
158
|
-
const allRecords = [];
|
|
159
|
-
for (const [label, physical] of Database.nodes) {
|
|
160
|
-
const data = yield this._dataCache.get(`node:${label}`, physical, null);
|
|
161
|
-
for (const record of data) {
|
|
162
|
-
allRecords.push(Object.assign(Object.assign({}, record), { _label: label }));
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
return new node_data_1.default(allRecords);
|
|
166
|
-
}
|
|
167
|
-
if (element.labels.length > 1) {
|
|
168
|
-
// ORed labels: collect from all matching physical nodes
|
|
169
|
-
const allRecords = [];
|
|
170
|
-
for (const lbl of element.labels) {
|
|
171
|
-
const physical = Database.nodes.get(lbl);
|
|
172
|
-
if (physical) {
|
|
173
|
-
const data = yield this._dataCache.get(`node:${lbl}`, physical, args);
|
|
174
|
-
for (const record of data) {
|
|
175
|
-
allRecords.push(Object.assign(Object.assign({}, record), { _label: lbl }));
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
return new node_data_1.default(allRecords);
|
|
180
|
-
}
|
|
181
|
-
const node = this.getNode(element);
|
|
182
|
-
if (node === null) {
|
|
183
|
-
throw new Error(`Physical node not found for label ${element.label}`);
|
|
184
|
-
}
|
|
185
|
-
const data = yield this._dataCache.get(`node:${element.label}`, node, args);
|
|
186
|
-
const label = element.label;
|
|
187
|
-
const records = data.map((record) => (Object.assign(Object.assign({}, record), { _label: label })));
|
|
188
|
-
return new node_data_1.default(records);
|
|
189
|
-
}
|
|
190
|
-
else if (element instanceof relationship_1.default) {
|
|
191
|
-
const args = this.extractArgs(element.properties);
|
|
192
|
-
if (element.types.length !== 1) {
|
|
193
|
-
const physicalEntries = this.getRelationshipEntries(element);
|
|
194
|
-
if (physicalEntries.length === 0) {
|
|
195
|
-
if (element.types.length === 0) {
|
|
196
|
-
return new relationship_data_1.default([]);
|
|
197
|
-
}
|
|
198
|
-
throw new Error(`No physical relationships found for types ${element.types.join(", ")}`);
|
|
199
|
-
}
|
|
200
|
-
const allRecords = [];
|
|
201
|
-
for (const [typeName, physical] of physicalEntries) {
|
|
202
|
-
const records = (yield this._dataCache.get(`rel:${typeName}`, physical, args));
|
|
203
|
-
for (const record of records) {
|
|
204
|
-
allRecords.push(Object.assign(Object.assign({}, record), { _type: typeName }));
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
return new relationship_data_1.default(allRecords);
|
|
208
|
-
}
|
|
209
|
-
const relationship = this.getRelationship(element);
|
|
210
|
-
if (relationship === null) {
|
|
211
|
-
throw new Error(`Physical relationship not found for type ${element.type}`);
|
|
212
|
-
}
|
|
213
|
-
const data = yield this._dataCache.get(`rel:${element.type}`, relationship, args);
|
|
214
|
-
return new relationship_data_1.default(data);
|
|
215
|
-
}
|
|
216
|
-
else {
|
|
217
|
-
throw new Error("Element is neither Node nor Relationship");
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* Extracts property constraint values from a node/relationship's properties map
|
|
223
|
-
* to pass as $args to the inner virtual definition query.
|
|
224
|
-
*/
|
|
225
|
-
extractArgs(properties) {
|
|
226
|
-
if (properties.size === 0) {
|
|
75
|
+
getRelationship(relationship) {
|
|
76
|
+
var _a, _b, _c, _d, _e;
|
|
77
|
+
const typeMap = Database._relationships.get(relationship.type);
|
|
78
|
+
if (!typeMap)
|
|
227
79
|
return null;
|
|
80
|
+
const src = (_b = (_a = relationship.source) === null || _a === void 0 ? void 0 : _a.label) !== null && _b !== void 0 ? _b : null;
|
|
81
|
+
const tgt = (_d = (_c = relationship.target) === null || _c === void 0 ? void 0 : _c.label) !== null && _d !== void 0 ? _d : null;
|
|
82
|
+
// Exact match when labels are specified
|
|
83
|
+
if (src !== null || tgt !== null) {
|
|
84
|
+
return (_e = typeMap.get(Database.endpointKey(src, tgt))) !== null && _e !== void 0 ? _e : null;
|
|
228
85
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
return
|
|
86
|
+
// Null labels = wildcard: return last entry
|
|
87
|
+
let last = null;
|
|
88
|
+
for (const p of typeMap.values())
|
|
89
|
+
last = p;
|
|
90
|
+
return last;
|
|
234
91
|
}
|
|
235
92
|
}
|
|
236
|
-
Database.
|
|
237
|
-
Database.
|
|
93
|
+
Database._nodes = new Map();
|
|
94
|
+
Database._relationships = new Map();
|
|
238
95
|
exports.default = Database;
|
|
239
96
|
//# sourceMappingURL=database.js.map
|