simple-graph-query 1.0.0 → 1.1.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/README.md +96 -51
- package/dist/ForgeExprEvaluator.d.ts +58 -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 +60971 -0
- package/dist/types.d.ts +26 -0
- package/package.json +53 -10
- package/dist/bundle.js +0 -1
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,21 +1,64 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "simple-graph-query",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "
|
|
5
|
-
"main": "dist/bundle.js",
|
|
3
|
+
"version": "1.1.1",
|
|
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",
|
|
6
8
|
"files": [
|
|
7
|
-
"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"
|
|
8
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
|
+
},
|
|
9
29
|
"scripts": {
|
|
10
|
-
"build": "webpack
|
|
11
|
-
"
|
|
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 ../.."
|
|
12
37
|
},
|
|
13
38
|
"author": "Siddhartha Prasad",
|
|
14
39
|
"license": "MIT",
|
|
15
40
|
"devDependencies": {
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
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
|
+
"stream-browserify": "^3.0.0",
|
|
50
|
+
"ts-jest": "^29.3.1",
|
|
51
|
+
"ts-loader": "^9.5.2",
|
|
52
|
+
"typescript": "^5.8.2",
|
|
53
|
+
"util": "^0.12.5",
|
|
54
|
+
"webpack": "^5.99.9",
|
|
55
|
+
"webpack-cli": "^6.0.1"
|
|
56
|
+
},
|
|
57
|
+
"dependencies": {
|
|
58
|
+
"@types/lodash": "^4.17.16",
|
|
59
|
+
"@types/node": "^22.14.0",
|
|
60
|
+
"antlr4ts": "^0.5.0-alpha.4",
|
|
61
|
+
"entities": "^6.0.0",
|
|
62
|
+
"lodash": "^4.17.21"
|
|
20
63
|
}
|
|
21
64
|
}
|
package/dist/bundle.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
!function(t,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.SimpleGraphQuery=r():t.SimpleGraphQuery=r()}(this,()=>(()=>{"use strict";var t={d:(r,e)=>{for(var n in e)t.o(e,n)&&!t.o(r,n)&&Object.defineProperty(r,n,{enumerable:!0,get:e[n]})},o:(t,r)=>Object.prototype.hasOwnProperty.call(t,r),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},r={};t.r(r),t.d(r,{default:()=>u,runQuery:()=>n});var e=function(){function t(t,r){this.result=t,this.expression=r}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}();function n(t,r){for(var e,n=function(t){var r=t.match(/\{\s*(.*?)\s*:\s*(\w+)\s*\|\s*(.*?)\s*\}/);if(!r)throw new Error("Parse error");r[0];var e=r[1],n=r[2],i=r[3];return{vars:e.split(",").map(function(t){return t.trim()}),type:n,condition:i}}(r),o=n.vars,s=n.type,u=n.condition,l=t.nodes.filter(function(t){return t.type===s}).map(function(t){return t.id}),a=[],p=0,f=l;p<f.length;p++)for(var c=f[p],h=0,y=l;h<y.length;h++){var g=y[h];i(u,((e={})[o[0]]=c,e[o[1]]=g,e),t)&&a.push([c,g])}return a}function i(t,r,e){return t.includes("=")?function(t,r,e){var n=t.split("=").map(function(t){return t.trim()}),i=n[0],s=n[1],u=o(i,r,e),l=o(s,r,e).values().next().value;return"string"==typeof l&&u.has(l)}(t,r,e):!!t.includes("in")&&function(t,r,e){var n=t.split("in").map(function(t){return t.trim()}),i=n[0],o=n[1],u=r[i],l=o.split("."),a=l[l.length-1].endsWith("*"),p=l[l.length-1].replace("*",""),f=a?s(u,p,e):function(t,r,e){return new Set(e.edges.filter(function(e){return e.from===t&&e.label===r}).map(function(t){return t.to}))}(u,p,e);return f.has(r[l[0]])}(t,r,e)}function o(t,r,e){if(t.includes(".")){var n=t.replace("*","").split("."),i=n[0],o=n[1],u=r[i];return"string"==typeof u?s(u,o,e):new Set}var l=r[t];return"string"==typeof l?new Set([l]):new Set}function s(t,r,e){for(var n=new Set,i=[t];i.length;){var o=i.pop();if(!n.has(o)){n.add(o);for(var s=0,u=e.edges;s<u.length;s++){var l=u[s];l.from!==o||l.label!==r||n.has(l.to)||i.push(l.to)}}}return n}const u=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,r){if(!this.graph)throw new Error("Evaluator not initialized");try{var i=n(this.graph,t);return new e(i,t)}catch(r){return new e({error:{message:r.message}},t)}},t}();return r})());
|