simple-graph-query 1.0.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +96 -51
- package/dist/ForgeExprEvaluator.d.ts +61 -0
- package/dist/ForgeExprFreeVariableFinder.d.ts +45 -0
- package/dist/errorListener.d.ts +4 -0
- package/dist/forge-antlr/ForgeLexer.d.ts +134 -0
- package/dist/forge-antlr/ForgeListener.d.ts +942 -0
- package/dist/forge-antlr/ForgeListenerImpl.d.ts +127 -0
- package/dist/forge-antlr/ForgeParser.d.ts +1377 -0
- package/dist/forge-antlr/ForgeSyntaxConstructs.d.ts +86 -0
- package/dist/forge-antlr/ForgeVisitor.d.ts +605 -0
- package/dist/index.d.ts +17 -0
- package/dist/simple-graph-query.bundle.js +60984 -0
- package/dist/types.d.ts +26 -0
- package/package.json +56 -14
- package/dist/bundle.js +0 -1
- package/dist/evaluator.js +0 -180
- package/dist/index.js +0 -23
- package/dist/interface.js +0 -2
- package/dist/parser.js +0 -11
- package/dist/types/evaluator.d.ts +0 -12
- package/dist/types/index.d.ts +0 -2
- package/dist/types/interface.d.ts +0 -86
- package/dist/types/parser.d.ts +0 -2
- package/dist/types/types.d.ts +0 -18
- package/dist/types.js +0 -2
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface IAtom {
|
|
2
|
+
id: string;
|
|
3
|
+
type: string;
|
|
4
|
+
}
|
|
5
|
+
export interface ITuple {
|
|
6
|
+
atoms: string[];
|
|
7
|
+
types: string[];
|
|
8
|
+
}
|
|
9
|
+
export interface IType {
|
|
10
|
+
id: string;
|
|
11
|
+
types: string[];
|
|
12
|
+
atoms: IAtom[];
|
|
13
|
+
isBuiltin: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface IRelation {
|
|
16
|
+
id: string;
|
|
17
|
+
name: string;
|
|
18
|
+
types: string[];
|
|
19
|
+
tuples: ITuple[];
|
|
20
|
+
}
|
|
21
|
+
export interface IDataInstance {
|
|
22
|
+
getAtomType(id: string): IType;
|
|
23
|
+
getTypes(): readonly IType[];
|
|
24
|
+
getAtoms(): readonly IAtom[];
|
|
25
|
+
getRelations(): readonly IRelation[];
|
|
26
|
+
}
|
package/package.json
CHANGED
|
@@ -1,23 +1,65 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "simple-graph-query",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "
|
|
5
|
-
"main": "dist/bundle.js",
|
|
6
|
-
"types": "dist/
|
|
7
|
-
"
|
|
8
|
-
"license": "MIT",
|
|
3
|
+
"version": "1.1.2",
|
|
4
|
+
"description": "TypeScript evaluator for Forge expressions with browser-compatible UMD bundle",
|
|
5
|
+
"main": "dist/simple-graph-query.bundle.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"browser": "dist/simple-graph-query.bundle.js",
|
|
9
8
|
"files": [
|
|
10
|
-
"dist",
|
|
11
|
-
"dist/
|
|
9
|
+
"dist/simple-graph-query.bundle.js",
|
|
10
|
+
"dist/simple-graph-query.bundle.js.LICENSE.txt",
|
|
11
|
+
"dist/*.d.ts",
|
|
12
|
+
"dist/forge-antlr/*.d.ts",
|
|
13
|
+
"README.md",
|
|
14
|
+
"LICENSE"
|
|
12
15
|
],
|
|
16
|
+
"keywords": [
|
|
17
|
+
"forge",
|
|
18
|
+
"alloy",
|
|
19
|
+
"expression-evaluator",
|
|
20
|
+
"formal-methods",
|
|
21
|
+
"antlr",
|
|
22
|
+
"typescript",
|
|
23
|
+
"browser",
|
|
24
|
+
"umd"
|
|
25
|
+
],
|
|
26
|
+
"directories": {
|
|
27
|
+
"test": "test"
|
|
28
|
+
},
|
|
13
29
|
"scripts": {
|
|
14
|
-
"build": "
|
|
15
|
-
"
|
|
30
|
+
"build": "webpack",
|
|
31
|
+
"build:types": "tsc --emitDeclarationOnly",
|
|
32
|
+
"build:full": "tsc && webpack",
|
|
33
|
+
"prepublishOnly": "npm run build:full",
|
|
34
|
+
"serve": "python3 -m http.server 8080",
|
|
35
|
+
"test": "jest",
|
|
36
|
+
"antlr4ts": "cd src/forge-antlr && antlr4ts -visitor ForgeLexer.g4 Forge.g4 && cd ../.."
|
|
16
37
|
},
|
|
38
|
+
"author": "Siddhartha Prasad",
|
|
39
|
+
"license": "MIT",
|
|
17
40
|
"devDependencies": {
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
41
|
+
"@types/jest": "^29.5.14",
|
|
42
|
+
"antlr4ts-cli": "^0.5.0-alpha.4",
|
|
43
|
+
"assert": "^2.1.0",
|
|
44
|
+
"buffer": "^6.0.3",
|
|
45
|
+
"husky": "^9.1.7",
|
|
46
|
+
"jest": "^29.7.0",
|
|
47
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
48
|
+
"process": "^0.11.10",
|
|
49
|
+
"semver": "^7.7.2",
|
|
50
|
+
"stream-browserify": "^3.0.0",
|
|
51
|
+
"ts-jest": "^29.3.1",
|
|
52
|
+
"ts-loader": "^9.5.2",
|
|
53
|
+
"typescript": "^5.8.2",
|
|
54
|
+
"util": "^0.12.5",
|
|
55
|
+
"webpack": "^5.99.9",
|
|
56
|
+
"webpack-cli": "^6.0.1"
|
|
57
|
+
},
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"@types/lodash": "^4.17.16",
|
|
60
|
+
"@types/node": "^22.14.0",
|
|
61
|
+
"antlr4ts": "^0.5.0-alpha.4",
|
|
62
|
+
"entities": "^6.0.0",
|
|
63
|
+
"lodash": "^4.17.21"
|
|
22
64
|
}
|
|
23
65
|
}
|
package/dist/bundle.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Evaluator=e():t.Evaluator=e()}(this,()=>(()=>{"use strict";var t={5:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Evaluator=void 0,e.runQuery=u;var n=r(337),i=function(){function t(t,e){this.result=t,this.expression=e}return t.prototype.prettyPrint=function(){return JSON.stringify(this.result,null,2)},t.prototype.noResult=function(){return Array.isArray(this.result)?0===this.result.length:"object"==typeof this.result&&"error"in this.result},t.prototype.singleResult=function(){if(Array.isArray(this.result)&&1===this.result.length&&1===this.result[0].length)return this.result[0][0];throw new Error("Result is not a singleton")},t.prototype.selectedAtoms=function(){return Array.isArray(this.result)?this.result.filter(function(t){return 1===t.length}).map(function(t){return String(t[0])}):[]},t.prototype.selectedTwoples=function(){return Array.isArray(this.result)?this.result.filter(function(t){return 2===t.length}).map(function(t){return[String(t[0]),String(t[1])]}):[]},t.prototype.selectedTuplesAll=function(){return Array.isArray(this.result)?this.result.map(function(t){return t.map(String)}):[]},t.prototype.isError=function(){return"object"==typeof this.result&&"error"in this.result},t.prototype.isSingleton=function(){return!!Array.isArray(this.result)&&1===this.result.length&&1===this.result[0].length},t.prototype.getExpression=function(){return this.expression},t.prototype.getRawResult=function(){return this.result},t}(),o=function(){function t(){this.context=null,this.graph=null}return t.prototype.initialize=function(t){this.context=t,t.processedData&&Array.isArray(t.processedData.nodes)&&Array.isArray(t.processedData.edges)?this.graph=t.processedData:this.graph=null},t.prototype.isReady=function(){return!!this.graph},t.prototype.evaluate=function(t,e){if(!this.graph)throw new Error("Evaluator not initialized");try{var r=u(this.graph,t);return new i(r,t)}catch(e){return new i({error:{message:e.message}},t)}},t}();function u(t,e){for(var r,i=(0,n.parse)(e),o=i.vars,u=i.type,a=i.condition,l=t.nodes.filter(function(t){return t.type===u}).map(function(t){return t.id}),p=[],f=0,c=l;f<c.length;f++)for(var h=c[f],y=0,d=l;y<d.length;y++){var g=d[y];s(a,((r={})[o[0]]=h,r[o[1]]=g,r),t)&&p.push([h,g])}return p}function s(t,e,r){return t.includes("=")?function(t,e,r){var n=t.split("=").map(function(t){return t.trim()}),i=n[0],o=n[1],u=a(i,e,r),s=a(o,e,r).values().next().value;return"string"==typeof s&&u.has(s)}(t,e,r):!!t.includes("in")&&function(t,e,r){var n=t.split("in").map(function(t){return t.trim()}),i=n[0],o=n[1],u=e[i],s=o.split("."),a=s[s.length-1].endsWith("*"),p=s[s.length-1].replace("*",""),f=a?l(u,p,r):function(t,e,r){return new Set(r.edges.filter(function(r){return r.from===t&&r.label===e}).map(function(t){return t.to}))}(u,p,r);return f.has(e[s[0]])}(t,e,r)}function a(t,e,r){if(t.includes(".")){var n=t.replace("*","").split("."),i=n[0],o=n[1],u=e[i];return"string"==typeof u?l(u,o,r):new Set}var s=e[t];return"string"==typeof s?new Set([s]):new Set}function l(t,e,r){for(var n=new Set,i=[t];i.length;){var o=i.pop();if(!n.has(o)){n.add(o);for(var u=0,s=r.edges;u<s.length;u++){var a=s[u];a.from!==o||a.label!==e||n.has(a.to)||i.push(a.to)}}}return n}e.Evaluator=o,e.default=o},156:function(t,e,r){var n=this&&this.__createBinding||(Object.create?function(t,e,r,n){void 0===n&&(n=r);var i=Object.getOwnPropertyDescriptor(e,r);i&&!("get"in i?!e.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,i)}:function(t,e,r,n){void 0===n&&(n=r),t[n]=e[r]}),i=this&&this.__exportStar||function(t,e){for(var r in t)"default"===r||Object.prototype.hasOwnProperty.call(e,r)||n(e,t,r)},o=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var u=r(5);Object.defineProperty(e,"default",{enumerable:!0,get:function(){return o(u).default}}),i(r(613),e)},337:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.parse=function(t){var e=t.match(/\{\s*(.*?)\s*:\s*(\w+)\s*\|\s*(.*?)\s*\}/);if(!e)throw new Error("Parse error");e[0];var r=e[1],n=e[2],i=e[3];return{vars:r.split(",").map(function(t){return t.trim()}),type:n,condition:i}}},613:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})}},e={},r=function r(n){var i=e[n];if(void 0!==i)return i.exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(156);return r.default})());
|
package/dist/evaluator.js
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Evaluator = void 0;
|
|
4
|
-
exports.runQuery = runQuery;
|
|
5
|
-
var parser_1 = require("./parser");
|
|
6
|
-
var EvaluatorResultImpl = /** @class */ (function () {
|
|
7
|
-
function EvaluatorResultImpl(result, expression) {
|
|
8
|
-
this.result = result;
|
|
9
|
-
this.expression = expression;
|
|
10
|
-
}
|
|
11
|
-
EvaluatorResultImpl.prototype.prettyPrint = function () {
|
|
12
|
-
return JSON.stringify(this.result, null, 2);
|
|
13
|
-
};
|
|
14
|
-
EvaluatorResultImpl.prototype.noResult = function () {
|
|
15
|
-
if (Array.isArray(this.result))
|
|
16
|
-
return this.result.length === 0;
|
|
17
|
-
if (typeof this.result === 'object' && 'error' in this.result)
|
|
18
|
-
return true;
|
|
19
|
-
return false;
|
|
20
|
-
};
|
|
21
|
-
EvaluatorResultImpl.prototype.singleResult = function () {
|
|
22
|
-
if (Array.isArray(this.result) && this.result.length === 1 && this.result[0].length === 1) {
|
|
23
|
-
return this.result[0][0];
|
|
24
|
-
}
|
|
25
|
-
throw new Error('Result is not a singleton');
|
|
26
|
-
};
|
|
27
|
-
EvaluatorResultImpl.prototype.selectedAtoms = function () {
|
|
28
|
-
if (Array.isArray(this.result)) {
|
|
29
|
-
return this.result.filter(function (t) { return t.length === 1; }).map(function (t) { return String(t[0]); });
|
|
30
|
-
}
|
|
31
|
-
return [];
|
|
32
|
-
};
|
|
33
|
-
EvaluatorResultImpl.prototype.selectedTwoples = function () {
|
|
34
|
-
if (Array.isArray(this.result)) {
|
|
35
|
-
return this.result.filter(function (t) { return t.length === 2; }).map(function (t) { return [String(t[0]), String(t[1])]; });
|
|
36
|
-
}
|
|
37
|
-
return [];
|
|
38
|
-
};
|
|
39
|
-
EvaluatorResultImpl.prototype.selectedTuplesAll = function () {
|
|
40
|
-
if (Array.isArray(this.result)) {
|
|
41
|
-
return this.result.map(function (t) { return t.map(String); });
|
|
42
|
-
}
|
|
43
|
-
return [];
|
|
44
|
-
};
|
|
45
|
-
EvaluatorResultImpl.prototype.isError = function () {
|
|
46
|
-
return typeof this.result === 'object' && 'error' in this.result;
|
|
47
|
-
};
|
|
48
|
-
EvaluatorResultImpl.prototype.isSingleton = function () {
|
|
49
|
-
if (Array.isArray(this.result))
|
|
50
|
-
return this.result.length === 1 && this.result[0].length === 1;
|
|
51
|
-
return false;
|
|
52
|
-
};
|
|
53
|
-
EvaluatorResultImpl.prototype.getExpression = function () {
|
|
54
|
-
return this.expression;
|
|
55
|
-
};
|
|
56
|
-
EvaluatorResultImpl.prototype.getRawResult = function () {
|
|
57
|
-
return this.result;
|
|
58
|
-
};
|
|
59
|
-
return EvaluatorResultImpl;
|
|
60
|
-
}());
|
|
61
|
-
var Evaluator = /** @class */ (function () {
|
|
62
|
-
function Evaluator() {
|
|
63
|
-
this.context = null;
|
|
64
|
-
this.graph = null;
|
|
65
|
-
}
|
|
66
|
-
Evaluator.prototype.initialize = function (_context) {
|
|
67
|
-
this.context = _context;
|
|
68
|
-
// Validate processedData as Graph
|
|
69
|
-
if (_context.processedData &&
|
|
70
|
-
Array.isArray(_context.processedData.nodes) &&
|
|
71
|
-
Array.isArray(_context.processedData.edges)) {
|
|
72
|
-
this.graph = _context.processedData;
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
this.graph = null;
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
Evaluator.prototype.isReady = function () {
|
|
79
|
-
return !!this.graph;
|
|
80
|
-
};
|
|
81
|
-
Evaluator.prototype.evaluate = function (_expression, _config) {
|
|
82
|
-
if (!this.graph)
|
|
83
|
-
throw new Error('Evaluator not initialized');
|
|
84
|
-
try {
|
|
85
|
-
var tuples = runQuery(this.graph, _expression);
|
|
86
|
-
return new EvaluatorResultImpl(tuples, _expression);
|
|
87
|
-
}
|
|
88
|
-
catch (e) {
|
|
89
|
-
return new EvaluatorResultImpl({ error: { message: e.message } }, _expression);
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
return Evaluator;
|
|
93
|
-
}());
|
|
94
|
-
exports.Evaluator = Evaluator;
|
|
95
|
-
function runQuery(graph, query) {
|
|
96
|
-
var _a;
|
|
97
|
-
var parsed = (0, parser_1.parse)(query);
|
|
98
|
-
var vars = parsed.vars, type = parsed.type, condition = parsed.condition;
|
|
99
|
-
var domain = graph.nodes.filter(function (n) { return n.type === type; }).map(function (n) { return n.id; });
|
|
100
|
-
var results = [];
|
|
101
|
-
for (var _i = 0, domain_1 = domain; _i < domain_1.length; _i++) {
|
|
102
|
-
var x = domain_1[_i];
|
|
103
|
-
for (var _b = 0, domain_2 = domain; _b < domain_2.length; _b++) {
|
|
104
|
-
var y = domain_2[_b];
|
|
105
|
-
var ctx = (_a = {}, _a[vars[0]] = x, _a[vars[1]] = y, _a);
|
|
106
|
-
if (evaluateCondition(condition, ctx, graph)) {
|
|
107
|
-
results.push([x, y]);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
return results;
|
|
112
|
-
}
|
|
113
|
-
function evaluateCondition(expr, ctx, graph) {
|
|
114
|
-
if (expr.includes('='))
|
|
115
|
-
return evalEq(expr, ctx, graph);
|
|
116
|
-
if (expr.includes('in'))
|
|
117
|
-
return evalIn(expr, ctx, graph);
|
|
118
|
-
return false;
|
|
119
|
-
}
|
|
120
|
-
function evalEq(expr, ctx, graph) {
|
|
121
|
-
var _a = expr.split('=').map(function (x) { return x.trim(); }), lhs = _a[0], rhs = _a[1];
|
|
122
|
-
var leftSet = resolve(lhs, ctx, graph);
|
|
123
|
-
var rightSet = resolve(rhs, ctx, graph);
|
|
124
|
-
var rightVal = rightSet.values().next().value;
|
|
125
|
-
if (typeof rightVal === 'string') {
|
|
126
|
-
return leftSet.has(rightVal);
|
|
127
|
-
}
|
|
128
|
-
return false;
|
|
129
|
-
}
|
|
130
|
-
function evalIn(expr, ctx, graph) {
|
|
131
|
-
var _a = expr.split('in').map(function (s) { return s.trim(); }), x = _a[0], path = _a[1];
|
|
132
|
-
var xVal = ctx[x];
|
|
133
|
-
var steps = path.split('.');
|
|
134
|
-
var star = steps[steps.length - 1].endsWith('*');
|
|
135
|
-
var label = steps[steps.length - 1].replace('*', '');
|
|
136
|
-
var reachable = star ? closure(xVal, label, graph) : direct(xVal, label, graph);
|
|
137
|
-
return reachable.has(ctx[steps[0]]);
|
|
138
|
-
}
|
|
139
|
-
function resolve(term, ctx, graph) {
|
|
140
|
-
if (term.includes('.')) {
|
|
141
|
-
var _a = term.replace('*', '').split('.'), base = _a[0], label = _a[1];
|
|
142
|
-
var baseVal = ctx[base];
|
|
143
|
-
if (typeof baseVal === 'string') {
|
|
144
|
-
return closure(baseVal, label, graph);
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
return new Set();
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
var val = ctx[term];
|
|
152
|
-
if (typeof val === 'string') {
|
|
153
|
-
return new Set([val]);
|
|
154
|
-
}
|
|
155
|
-
else {
|
|
156
|
-
return new Set();
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
function direct(start, label, graph) {
|
|
161
|
-
return new Set(graph.edges.filter(function (e) { return e.from === start && e.label === label; }).map(function (e) { return e.to; }));
|
|
162
|
-
}
|
|
163
|
-
function closure(start, label, graph) {
|
|
164
|
-
var seen = new Set();
|
|
165
|
-
var stack = [start];
|
|
166
|
-
while (stack.length) {
|
|
167
|
-
var current = stack.pop();
|
|
168
|
-
if (!seen.has(current)) {
|
|
169
|
-
seen.add(current);
|
|
170
|
-
for (var _i = 0, _a = graph.edges; _i < _a.length; _i++) {
|
|
171
|
-
var edge = _a[_i];
|
|
172
|
-
if (edge.from === current && edge.label === label && !seen.has(edge.to)) {
|
|
173
|
-
stack.push(edge.to);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
return seen;
|
|
179
|
-
}
|
|
180
|
-
exports.default = Evaluator;
|
package/dist/index.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
-
};
|
|
19
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.default = void 0;
|
|
21
|
-
var evaluator_1 = require("./evaluator");
|
|
22
|
-
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(evaluator_1).default; } });
|
|
23
|
-
__exportStar(require("./types"), exports);
|
package/dist/interface.js
DELETED
package/dist/parser.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parse = parse;
|
|
4
|
-
function parse(query) {
|
|
5
|
-
var m = query.match(/\{\s*(.*?)\s*:\s*(\w+)\s*\|\s*(.*?)\s*\}/);
|
|
6
|
-
if (!m)
|
|
7
|
-
throw new Error("Parse error");
|
|
8
|
-
var _ = m[0], vars = m[1], type = m[2], cond = m[3];
|
|
9
|
-
var varList = vars.split(',').map(function (v) { return v.trim(); });
|
|
10
|
-
return { vars: varList, type: type, condition: cond };
|
|
11
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import IEvaluator, { IEvaluatorResult, EvaluatorConfig, EvaluationContext } from './interface';
|
|
2
|
-
import { Graph } from './types';
|
|
3
|
-
declare class Evaluator implements IEvaluator {
|
|
4
|
-
private context;
|
|
5
|
-
private graph;
|
|
6
|
-
initialize(_context: EvaluationContext): void;
|
|
7
|
-
isReady(): boolean;
|
|
8
|
-
evaluate(_expression: string, _config?: EvaluatorConfig): IEvaluatorResult;
|
|
9
|
-
}
|
|
10
|
-
export declare function runQuery(graph: Graph, query: string): string[][];
|
|
11
|
-
export { Evaluator };
|
|
12
|
-
export default Evaluator;
|
package/dist/types/index.d.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Result types for evaluator operations
|
|
3
|
-
*/
|
|
4
|
-
export type EvaluatorResult = SingleValue | Tuple[] | ErrorResult;
|
|
5
|
-
export type SingleValue = string | number | boolean;
|
|
6
|
-
export type Tuple = SingleValue[];
|
|
7
|
-
export interface ErrorResult {
|
|
8
|
-
error: {
|
|
9
|
-
message: string;
|
|
10
|
-
code?: string;
|
|
11
|
-
details?: Record<string, unknown>;
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Configuration options for evaluators
|
|
16
|
-
*/
|
|
17
|
-
export interface EvaluatorConfig {
|
|
18
|
-
/** Enable debug mode for additional logging */
|
|
19
|
-
debug?: boolean;
|
|
20
|
-
/** Timeout for evaluation in milliseconds */
|
|
21
|
-
timeout?: number;
|
|
22
|
-
/** Maximum number of results to return */
|
|
23
|
-
maxResults?: number;
|
|
24
|
-
/** Instance index to evaluate against (for multi-instance contexts) */
|
|
25
|
-
instanceIndex?: number;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Context data that evaluators operate on
|
|
29
|
-
*/
|
|
30
|
-
export interface EvaluationContext {
|
|
31
|
-
/** Raw data source (XML, JSON, etc.) */
|
|
32
|
-
sourceData: string | Record<string, unknown>;
|
|
33
|
-
/** Parsed/processed data structure */
|
|
34
|
-
processedData?: Record<string, unknown>;
|
|
35
|
-
/** Source code associated with the data (if applicable) */
|
|
36
|
-
sourceCode?: string;
|
|
37
|
-
/** Additional metadata */
|
|
38
|
-
metadata?: Record<string, unknown>;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Wrapped result that provides convenient access methods
|
|
42
|
-
*/
|
|
43
|
-
export interface IEvaluatorResult {
|
|
44
|
-
/** Get a pretty-printed string representation */
|
|
45
|
-
prettyPrint(): string;
|
|
46
|
-
noResult(): boolean;
|
|
47
|
-
/** Get result as a single value (throws if not singleton) */
|
|
48
|
-
singleResult(): SingleValue;
|
|
49
|
-
/** Get selected atoms (arity 1 results) */
|
|
50
|
-
selectedAtoms(): string[];
|
|
51
|
-
/** Get selected pairs (arity 2 results, first and last elements) */
|
|
52
|
-
selectedTwoples(): string[][];
|
|
53
|
-
/** Get all selected tuples with all elements */
|
|
54
|
-
selectedTuplesAll(): string[][];
|
|
55
|
-
/** Check if result is an error */
|
|
56
|
-
isError(): boolean;
|
|
57
|
-
/** Check if result is a singleton value */
|
|
58
|
-
isSingleton(): boolean;
|
|
59
|
-
/** Get the original expression that produced this result */
|
|
60
|
-
getExpression(): string;
|
|
61
|
-
/** Get the raw result data */
|
|
62
|
-
getRawResult(): EvaluatorResult;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Main evaluator interface that different evaluators must implement
|
|
66
|
-
*/
|
|
67
|
-
interface IEvaluator {
|
|
68
|
-
/**
|
|
69
|
-
* Initialize the evaluator with context data
|
|
70
|
-
* @param _context The evaluation context containing data and metadata
|
|
71
|
-
*/
|
|
72
|
-
initialize(_context: EvaluationContext): void;
|
|
73
|
-
/**
|
|
74
|
-
* Check if the evaluator is properly initialized and ready
|
|
75
|
-
*/
|
|
76
|
-
isReady(): boolean;
|
|
77
|
-
/**
|
|
78
|
-
* Evaluate an expression and return the wrapped result
|
|
79
|
-
* @param _expression The expression to evaluate
|
|
80
|
-
* @param _config Optional configuration for this evaluation
|
|
81
|
-
* @returns Wrapped result with convenience methods
|
|
82
|
-
* @throws Error if the evaluation fails
|
|
83
|
-
*/
|
|
84
|
-
evaluate(_expression: string, _config?: EvaluatorConfig): IEvaluatorResult;
|
|
85
|
-
}
|
|
86
|
-
export default IEvaluator;
|
package/dist/types/parser.d.ts
DELETED
package/dist/types/types.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export interface Expr {
|
|
2
|
-
vars: string[];
|
|
3
|
-
type: string;
|
|
4
|
-
condition: string;
|
|
5
|
-
}
|
|
6
|
-
export interface Node {
|
|
7
|
-
id: string;
|
|
8
|
-
type: string;
|
|
9
|
-
}
|
|
10
|
-
export interface Edge {
|
|
11
|
-
from: string;
|
|
12
|
-
to: string;
|
|
13
|
-
label: string;
|
|
14
|
-
}
|
|
15
|
-
export interface Graph {
|
|
16
|
-
nodes: Node[];
|
|
17
|
-
edges: Edge[];
|
|
18
|
-
}
|
package/dist/types.js
DELETED