diff --git a/package-lock.json b/package-lock.json index ead45f5df..1ed2ed9db 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1634,6 +1634,15 @@ } } }, + "backbone": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/backbone/-/backbone-1.4.0.tgz", + "integrity": "sha512-RLmDrRXkVdouTg38jcgHhyQ/2zjg7a8E6sz2zxfz21Hh17xDJYUHBZimVIt5fUyS8vbfpeSmTL3gUjTEvUV3qQ==", + "dev": true, + "requires": { + "underscore": ">=1.8.3" + } + }, "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", @@ -2038,15 +2047,6 @@ "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=" }, - "catharsis": { - "version": "0.8.11", - "resolved": "https://registry.npmjs.org/catharsis/-/catharsis-0.8.11.tgz", - "integrity": "sha512-a+xUyMV7hD1BrDQA/3iPV7oc+6W26BgVJO05PGEoatMyIuPScQKsde6i3YorWX1qs+AZjnJ18NqdKoCtKiNh1g==", - "dev": true, - "requires": { - "lodash": "^4.17.14" - } - }, "chai": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/chai/-/chai-4.2.0.tgz", @@ -2839,12 +2839,6 @@ "tapable": "^1.0.0" } }, - "entities": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/entities/-/entities-1.1.2.tgz", - "integrity": "sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w==", - "dev": true - }, "errno": { "version": "0.1.7", "resolved": "https://registry.npmjs.org/errno/-/errno-0.1.7.tgz", @@ -4236,6 +4230,26 @@ "integrity": "sha512-d4sze1JNC454Wdo2fkuyzCr6aHcbL6PGGuFAz0Li/NcOm1tCHGnWDRmJP85dh9IhQErTc2svWFEX5xHIOo//kQ==", "dev": true }, + "handlebars": { + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.4.2.tgz", + "integrity": "sha512-cIv17+GhL8pHHnRJzGu2wwcthL5sb8uDKBHvZ2Dtu5s1YNt0ljbzKbamnc+gr69y7bzwQiBdr5+hOpRd5pnOdg==", + "dev": true, + "requires": { + "neo-async": "^2.6.0", + "optimist": "^0.6.1", + "source-map": "^0.6.1", + "uglify-js": "^3.1.4" + }, + "dependencies": { + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true + } + } + }, "har-schema": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz", @@ -4328,6 +4342,12 @@ "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==", "dev": true }, + "highlight.js": { + "version": "9.15.10", + "resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-9.15.10.tgz", + "integrity": "sha512-RoV7OkQm0T3os3Dd2VHLNMoaoDVx77Wygln3n9l5YV172XonWG6rgQD3XnF/BuFFZw9A0TJgmMSO8FEWQgvcXw==", + "dev": true + }, "hmac-drbg": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/hmac-drbg/-/hmac-drbg-1.0.1.tgz", @@ -4842,6 +4862,12 @@ "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=" }, + "jquery": { + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.4.1.tgz", + "integrity": "sha512-36+AdBzCL+y6qjw5Tx7HgzeGCzC81MDDgaUP8ld2zhx58HdqXGoBd+tHdrBMiyjGQs0Hxs/MLZTu/eHNJJuWPw==", + "dev": true + }, "js-levenshtein": { "version": "1.1.6", "resolved": "https://registry.npmjs.org/js-levenshtein/-/js-levenshtein-1.1.6.tgz", @@ -4864,59 +4890,11 @@ "esprima": "^4.0.0" } }, - "js2xmlparser": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/js2xmlparser/-/js2xmlparser-4.0.0.tgz", - "integrity": "sha512-WuNgdZOXVmBk5kUPMcTcVUpbGRzLfNkv7+7APq7WiDihpXVKrgxo6wwRpRl9OQeEBgKCVk9mR7RbzrnNWC8oBw==", - "dev": true, - "requires": { - "xmlcreate": "^2.0.0" - } - }, "jsbn": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=" }, - "jsdoc": { - "version": "3.6.3", - "resolved": "https://registry.npmjs.org/jsdoc/-/jsdoc-3.6.3.tgz", - "integrity": "sha512-Yf1ZKA3r9nvtMWHO1kEuMZTlHOF8uoQ0vyo5eH7SQy5YeIiHM+B0DgKnn+X6y6KDYZcF7G2SPkKF+JORCXWE/A==", - "dev": true, - "requires": { - "@babel/parser": "^7.4.4", - "bluebird": "^3.5.4", - "catharsis": "^0.8.11", - "escape-string-regexp": "^2.0.0", - "js2xmlparser": "^4.0.0", - "klaw": "^3.0.0", - "markdown-it": "^8.4.2", - "markdown-it-anchor": "^5.0.2", - "marked": "^0.7.0", - "mkdirp": "^0.5.1", - "requizzle": "^0.2.3", - "strip-json-comments": "^3.0.1", - "taffydb": "2.6.2", - "underscore": "~1.9.1" - }, - "dependencies": { - "escape-string-regexp": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz", - "integrity": "sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w==", - "dev": true - }, - "mkdirp": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", - "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", - "dev": true, - "requires": { - "minimist": "0.0.8" - } - } - } - }, "jsesc": { "version": "2.5.2", "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz", @@ -5022,15 +5000,6 @@ "integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA==", "dev": true }, - "klaw": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/klaw/-/klaw-3.0.0.tgz", - "integrity": "sha512-0Fo5oir+O9jnXu5EefYbVK+mHMBeEVEy2cmctR1O1NECcCkPRreJKrS6Qt/j3KC2C148Dfo9i3pCmCMsdqGr0g==", - "dev": true, - "requires": { - "graceful-fs": "^4.1.9" - } - }, "lcid": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/lcid/-/lcid-2.0.0.tgz", @@ -5040,15 +5009,6 @@ "invert-kv": "^2.0.0" } }, - "linkify-it": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-2.2.0.tgz", - "integrity": "sha512-GnAl/knGn+i1U/wjBz3akz2stz+HrHLsxMwHQGofCDfPvlf+gDKN58UtfmUquTY4/MXeE2x7k19KQmeoZi94Iw==", - "dev": true, - "requires": { - "uc.micro": "^1.0.1" - } - }, "loader-runner": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/loader-runner/-/loader-runner-2.4.0.tgz", @@ -5142,6 +5102,12 @@ "yallist": "^3.0.2" } }, + "lunr": { + "version": "2.3.7", + "resolved": "https://registry.npmjs.org/lunr/-/lunr-2.3.7.tgz", + "integrity": "sha512-HjFSiy0Y0qZoW5OA1I6qBi7OnsDdqQnaUr03jhorh30maQoaP+4lQCKklYE3Nq3WJMSUfuBl6N+bKY5wxCb9hw==", + "dev": true + }, "make-dir": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-2.1.0.tgz", @@ -5182,25 +5148,6 @@ "object-visit": "^1.0.0" } }, - "markdown-it": { - "version": "8.4.2", - "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-8.4.2.tgz", - "integrity": "sha512-GcRz3AWTqSUphY3vsUqQSFMbgR38a4Lh3GWlHRh/7MRwz8mcu9n2IO7HOh+bXHrR9kOPDl5RNCaEsrneb+xhHQ==", - "dev": true, - "requires": { - "argparse": "^1.0.7", - "entities": "~1.1.1", - "linkify-it": "^2.0.0", - "mdurl": "^1.0.1", - "uc.micro": "^1.0.5" - } - }, - "markdown-it-anchor": { - "version": "5.2.4", - "resolved": "https://registry.npmjs.org/markdown-it-anchor/-/markdown-it-anchor-5.2.4.tgz", - "integrity": "sha512-n8zCGjxA3T+Mx1pG8HEgbJbkB8JFUuRkeTZQuIM8iPY6oQ8sWOPRZJDFC9a/pNg2QkHEjjGkhBEl/RSyzaDZ3A==", - "dev": true - }, "marked": { "version": "0.7.0", "resolved": "https://registry.npmjs.org/marked/-/marked-0.7.0.tgz", @@ -5218,12 +5165,6 @@ "safe-buffer": "^5.1.2" } }, - "mdurl": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/mdurl/-/mdurl-1.0.1.tgz", - "integrity": "sha1-/oWy7HWlkDfyrf7BAP1sYBdhFS4=", - "dev": true - }, "media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", @@ -6089,6 +6030,16 @@ "is-wsl": "^1.1.0" } }, + "optimist": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/optimist/-/optimist-0.6.1.tgz", + "integrity": "sha1-2j6nRob6IaGaERwybpDrFaAZZoY=", + "dev": true, + "requires": { + "minimist": "~0.0.1", + "wordwrap": "~0.0.2" + } + }, "original": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/original/-/original-1.0.2.tgz", @@ -6462,6 +6413,12 @@ "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==", "dev": true }, + "progress": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz", + "integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==", + "dev": true + }, "promise-inflight": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/promise-inflight/-/promise-inflight-1.0.1.tgz", @@ -6677,6 +6634,15 @@ } } }, + "rechoir": { + "version": "0.6.2", + "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz", + "integrity": "sha1-hSBLVNuoLVdC4oyWdW70OvUOM4Q=", + "dev": true, + "requires": { + "resolve": "^1.1.6" + } + }, "regenerate": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/regenerate/-/regenerate-1.4.0.tgz", @@ -6822,15 +6788,6 @@ "integrity": "sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8=", "dev": true }, - "requizzle": { - "version": "0.2.3", - "resolved": "https://registry.npmjs.org/requizzle/-/requizzle-0.2.3.tgz", - "integrity": "sha512-YanoyJjykPxGHii0fZP0uUPEXpvqfBDxWV7s6GKAiiOsiqhX6vHNyW3Qzdmqp/iq/ExbhaGbVrjB4ruEVSM4GQ==", - "dev": true, - "requires": { - "lodash": "^4.17.14" - } - }, "resolve": { "version": "1.12.0", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.12.0.tgz", @@ -7136,6 +7093,17 @@ "integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=", "dev": true }, + "shelljs": { + "version": "0.8.3", + "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.3.tgz", + "integrity": "sha512-fc0BKlAWiLpwZljmOvAOTE/gXawtCoNrP5oaY7KIaQbbyHeQVg01pSEuEGvGh3HEdBU4baCD7wQBwADmM/7f7A==", + "dev": true, + "requires": { + "glob": "^7.0.0", + "interpret": "^1.0.0", + "rechoir": "^0.6.2" + } + }, "signal-exit": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", @@ -7749,12 +7717,6 @@ "integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=", "dev": true }, - "strip-json-comments": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.0.1.tgz", - "integrity": "sha512-VTyMAUfdm047mwKl+u79WIdrZxtFtn+nBxHeb844XBQ9uMNTuTHdx2hc5RiAJYqwTj3wc/xe5HLSdJSkJ+WfZw==", - "dev": true - }, "supports-color": { "version": "5.5.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", @@ -7764,12 +7726,6 @@ "has-flag": "^3.0.0" } }, - "taffydb": { - "version": "2.6.2", - "resolved": "https://registry.npmjs.org/taffydb/-/taffydb-2.6.2.tgz", - "integrity": "sha1-fLy2S1oUG2ou/CxdLGe04VCyomg=", - "dev": true - }, "tapable": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/tapable/-/tapable-1.1.3.tgz", @@ -8018,17 +7974,70 @@ "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=" }, + "typedoc": { + "version": "0.15.0", + "resolved": "https://registry.npmjs.org/typedoc/-/typedoc-0.15.0.tgz", + "integrity": "sha512-NOtfq5Tis4EFt+J2ozhVq9RCeUnfEYMFKoU6nCXCXUULJz1UQynOM+yH3TkfZCPLzigbqB0tQYGVlktUWweKlw==", + "dev": true, + "requires": { + "@types/minimatch": "3.0.3", + "fs-extra": "^8.1.0", + "handlebars": "^4.1.2", + "highlight.js": "^9.15.8", + "lodash": "^4.17.15", + "marked": "^0.7.0", + "minimatch": "^3.0.0", + "progress": "^2.0.3", + "shelljs": "^0.8.3", + "typedoc-default-themes": "^0.6.0", + "typescript": "3.5.x" + }, + "dependencies": { + "typescript": { + "version": "3.5.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.5.3.tgz", + "integrity": "sha512-ACzBtm/PhXBDId6a6sDJfroT2pOWt/oOnk4/dElG5G33ZL776N3Y6/6bKZJBFpd+b05F3Ct9qDjMeJmRWtE2/g==", + "dev": true + } + } + }, + "typedoc-default-themes": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/typedoc-default-themes/-/typedoc-default-themes-0.6.0.tgz", + "integrity": "sha512-MdTROOojxod78CEv22rIA69o7crMPLnVZPefuDLt/WepXqJwgiSu8Xxq+H36x0Jj3YGc7lOglI2vPJ2GhoOybw==", + "dev": true, + "requires": { + "backbone": "^1.4.0", + "jquery": "^3.4.1", + "lunr": "^2.3.6", + "underscore": "^1.9.1" + } + }, "typescript": { "version": "3.6.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.6.3.tgz", "integrity": "sha512-N7bceJL1CtRQ2RiG0AQME13ksR7DiuQh/QehubYcghzv20tnh+MQnQIuJddTmsbqYj+dztchykemz0zFzlvdQw==", "dev": true }, - "uc.micro": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.6.tgz", - "integrity": "sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA==", - "dev": true + "uglify-js": { + "version": "3.6.1", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.6.1.tgz", + "integrity": "sha512-+dSJLJpXBb6oMHP+Yvw8hUgElz4gLTh82XuX68QiJVTXaE5ibl6buzhNkQdYhBlIhozWOC9ge16wyRmjG4TwVQ==", + "dev": true, + "optional": true, + "requires": { + "commander": "2.20.0", + "source-map": "~0.6.1" + }, + "dependencies": { + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true, + "optional": true + } + } }, "underscore": { "version": "1.9.1", @@ -8674,6 +8683,12 @@ "integrity": "sha1-+OGqHuWlPsW/FR/6CXQqatdpeHY=", "dev": true }, + "wordwrap": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.3.tgz", + "integrity": "sha1-o9XabNXAvAAI03I0u68b7WMFkQc=", + "dev": true + }, "worker-farm": { "version": "1.7.0", "resolved": "https://registry.npmjs.org/worker-farm/-/worker-farm-1.7.0.tgz", @@ -8754,12 +8769,6 @@ "async-limiter": "~1.0.0" } }, - "xmlcreate": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/xmlcreate/-/xmlcreate-2.0.1.tgz", - "integrity": "sha512-MjGsXhKG8YjTKrDCXseFo3ClbMGvUD4en29H2Cev1dv4P/chlpw6KdYmlCWDkhosBVKRDjM836+3e3pm1cBNJA==", - "dev": true - }, "xmldom": { "version": "0.1.27", "resolved": "https://registry.npmjs.org/xmldom/-/xmldom-0.1.27.tgz", diff --git a/package.json b/package.json index f00cbba91..7ab6add6f 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,14 @@ { "name": "Daniel Friedman", "url": "https://github.com/dan-f/" + }, + { + "name": "Cénotélie", + "url": "https://github.com/cenotelie/" + }, + { + "name": "Joep Meindertsma", + "url": "https://github.com/joepio/" } ], "license": "MIT", @@ -55,7 +63,6 @@ "diff": "^4.0.1", "dirty-chai": "^2.0.1", "fs-grep": "^0.0.5", - "jsdoc": "^3.6.3", "mocha": "^6.2.0", "nock": "^10.0.6", "node-fetch": "^2.6.0", @@ -64,6 +71,7 @@ "sinon": "^7.4.1", "sinon-chai": "^3.3.0", "source-map-loader": "^0.2.4", + "typedoc": "^0.15.0", "typescript": "^3.6.3", "webpack": "^4.39.2", "webpack-cli": "^3.3.6", @@ -74,7 +82,7 @@ "build": "babel src --extensions \".ts,.js\" -d lib", "build:browser": "webpack --progress", "build:types": "tsc --emitDeclarationOnly -d --declarationDir lib --allowJs false", - "doc": "rm -r doc ; jsdoc -d doc README.md src/*.js", + "doc": "rm -r doc ; typedoc", "prepare": "npm run build && npm run build:browser", "start": "webpack-dev-server --https --port 4800", "test": "npm run test:unit && npm run test:serialize", diff --git a/src/blank-node.js b/src/blank-node.ts similarity index 60% rename from src/blank-node.js rename to src/blank-node.ts index 40aaffa36..2f997d632 100644 --- a/src/blank-node.js +++ b/src/blank-node.ts @@ -1,11 +1,39 @@ -'use strict' import ClassOrder from './class-order' import Node from './node-internal' +import { IndexedFormula } from './index'; +/** + * An RDF blank node is a Node without a URI + * @link https://rdf.js.org/data-model-spec/#blanknode-interface + */ export default class BlankNode extends Node { - constructor (id) { + + static termType: 'BlankNode'; + + /** + * The identifier for the blank node + */ + id: string; + + /** + * Whether this is a blank node + */ + isBlank: boolean; + + /** + * The next unique identifier for blank nodes + */ + static nextId: number; + static NTAnonymousNodePrefix: string; + + /** + * Initializes this node + * @param id The identifier for the blank node + */ + constructor (id?: string) { super() this.termType = BlankNode.termType + this.isBlank = true if (id) { if (typeof id !== 'string') { @@ -42,7 +70,11 @@ export default class BlankNode extends Node { return 0 } - copy (formula) { // depends on the formula + /** + * Gets a copy of this blank node in the specified formula + * @param formula The formula + */ + copy (formula: IndexedFormula): BlankNode { // depends on the formula var bnodeNew = new BlankNode() formula.copyTo(this, bnodeNew) return bnodeNew @@ -61,5 +93,5 @@ BlankNode.nextId = 0 BlankNode.termType = 'BlankNode' BlankNode.NTAnonymousNodePrefix = '_:' BlankNode.prototype.classOrder = ClassOrder['BlankNode'] -BlankNode.prototype.isBlank = 1 -BlankNode.prototype.isVar = 1 +BlankNode.prototype.isBlank = true +BlankNode.prototype.isVar = true diff --git a/src/class-order.js b/src/class-order.ts similarity index 50% rename from src/class-order.js rename to src/class-order.ts index f2529983e..d614b56e5 100644 --- a/src/class-order.js +++ b/src/class-order.ts @@ -1,4 +1,9 @@ -export default { +/** +* Class orders +*/ +const ClassOrder: { + [id: string]: number; +} = { 'Literal': 1, 'Collection': 3, 'Graph': 4, @@ -6,3 +11,5 @@ export default { 'BlankNode': 6, 'Variable': 7 } + +export default ClassOrder diff --git a/src/collection.js b/src/collection.js deleted file mode 100644 index e73d2fa76..000000000 --- a/src/collection.js +++ /dev/null @@ -1,48 +0,0 @@ -'use strict' -import BlankNode from './blank-node' -import ClassOrder from './class-order' -import Node from './node-internal' - -export default class Collection extends Node { - constructor (initial) { - super() - this.termType = Collection.termType - this.id = BlankNode.nextId++ - this.elements = [] - this.closed = false - if (initial && initial.length > 0) { - initial.forEach(element => { - this.elements.push(Node.fromValue(element)) - }) - } - } - append (element) { - return this.elements.push(element) - } - close () { - this.closed = true - return this.closed - } - shift () { - return this.elements.shift() - } - substitute (bindings) { - var elementsCopy = this.elements.map(function (ea) { - ea.substitute(bindings) - }) - return new Collection(elementsCopy) - } - toNT () { - return BlankNode.NTAnonymousNodePrefix + this.id - } - toString () { - return '(' + this.elements.join(' ') + ')' - } - unshift (element) { - return this.elements.unshift(element) - } -} -Collection.termType = 'Collection' -Collection.prototype.classOrder = ClassOrder['Collection'] -Collection.prototype.compareTerm = BlankNode.prototype.compareTerm -Collection.prototype.isVar = 0 diff --git a/src/collection.ts b/src/collection.ts new file mode 100644 index 000000000..79852277f --- /dev/null +++ b/src/collection.ts @@ -0,0 +1,102 @@ +import BlankNode from './blank-node' +import ClassOrder from './class-order' +import Node from './node-internal' +import { ValueType, Bindings } from './types'; + +/** +* A collection of other RDF nodes +*/ +export default class Collection extends Node { + + static termType: 'Collection'; + + /** + * The identifier for this collection + */ + id: number; + + /** + * The nodes in this collection + */ + + elements: Node[]; + + /** + * Whether this collection is closed + */ + closed: boolean; + + /** + * Initializes this collection + * @param initial The initial elements + */ + constructor(initial: ReadonlyArray) { + super() + this.termType = Collection.termType + this.id = BlankNode.nextId++ + this.elements = [] + this.closed = false + if (initial && initial.length > 0) { + initial.forEach(element => { + this.elements.push(Node.fromValue(element)) + }) + } + } + + /** + * Appends an element to this collection + * @param element The new element + */ + append (element: Node): number { + return this.elements.push(element) + } + + /** + * Closes this collection + */ + close (): boolean { + this.closed = true + return this.closed + } + + /** + * Removes the first element from the collection (and return it) + */ + shift (): Node | undefined { + return this.elements.shift() + } + + /** + * Gets a new Collection with the substituting bindings applied + * @param bindings The bindings to substitute + */ + substitute(bindings: Bindings): Collection { + var elementsCopy = this.elements.map(function (ea) { + ea.substitute(bindings) + }) + return new Collection(elementsCopy as []) + } + toNT () { + return BlankNode.NTAnonymousNodePrefix + this.id + } + + /** + * Serializes the collection to a string. + * Surounded by (parantheses) and seperated by spaces. + */ + toString () { + return '(' + this.elements.join(' ') + ')' + } + + /** + * Preprends the specified element to the colelction's front + * @param element The element to preprend + */ + unshift (element: Node): number { + return this.elements.unshift(element) + } +} +Collection.termType = 'Collection' +Collection.prototype.classOrder = ClassOrder['Collection'] +Collection.prototype.compareTerm = BlankNode.prototype.compareTerm +Collection.prototype.isVar = false diff --git a/src/default-graph.js b/src/default-graph.js index a45cd7af5..3183c021c 100644 --- a/src/default-graph.js +++ b/src/default-graph.js @@ -1,5 +1,5 @@ 'use strict' -import Node from './node' +import Node from './node-internal' export default class DefaultGraph extends Node { constructor () { diff --git a/src/empty.js b/src/empty.ts similarity index 66% rename from src/empty.js rename to src/empty.ts index a24ee039d..30eabad51 100644 --- a/src/empty.js +++ b/src/empty.ts @@ -1,10 +1,12 @@ -'use strict' -import Node from './node' +import Node from './node-internal' /** - * Singleton subclass of an empty Collection. - */ +* An empty node +*/ export default class Empty extends Node { + + static termType: 'empty' + constructor () { super() this.termType = Empty.termType diff --git a/src/formula.js b/src/formula.js index b5c0e32fb..645c96ffd 100644 --- a/src/formula.js +++ b/src/formula.js @@ -6,7 +6,7 @@ import Literal from './literal' import log from './log' import NamedNode from './named-node' import Namespace from './namespace' -import Node from './node' +import Node from './node-internal' import Serializer from './serialize' import Statement from './statement' import Variable from './variable' @@ -644,7 +644,7 @@ export default class Formula extends Node { Formula.termType = 'Graph' Formula.prototype.classOrder = ClassOrder['Graph'] -Formula.prototype.isVar = 0 +Formula.prototype.isVar = false Formula.prototype.ns = Namespace Formula.prototype.variable = name => new Variable(name) diff --git a/src/literal.js b/src/literal.ts similarity index 61% rename from src/literal.js rename to src/literal.ts index c1e89f027..847241c99 100644 --- a/src/literal.js +++ b/src/literal.ts @@ -1,27 +1,62 @@ -'use strict' -import ClassOrder from './class-order' import NamedNode from './named-node' import Node from './node-internal' import XSD from './xsd' +import { ValueType } from './types' +import classOrder from './class-order' +/** + * An RDF literal node, containing something different than a URI. + * @link https://rdf.js.org/data-model-spec/#literal-interface + */ export default class Literal extends Node { - constructor (value, language, datatype) { + + termType: 'Literal' + + /** + * The language for the literal + */ + lang!: string + + /** + * The literal's datatype as a named node + */ + datatype!: NamedNode + + /** + * Initializes this literal + * @param value The literal's lexical value + * @param language The language for the literal + * @param datatype The literal's datatype as a named node + */ + constructor (value: string, language?: string | null, datatype?: NamedNode) { super() - this.termType = Literal.termType + this.termType = 'Literal' this.value = value if (language) { this.lang = language - datatype = XSD.langString + this.datatype = XSD.langString } // If not specified, a literal has the implied XSD.string default datatype if (datatype) { this.datatype = NamedNode.fromValue(datatype) } + if (!datatype && !this.datatype) { + this.datatype = XSD.string + } } - copy () { + + /** + * Gets a copy of this literal + */ + copy (): Literal { return new Literal(this.value, this.lang, this.datatype) } - equals (other) { + + /** + * Gets whether two literals are the same + * @param other The other statement + */ + equals (other: Literal): boolean { if (!other) { return false } @@ -31,7 +66,10 @@ export default class Literal extends Node { ((!this.datatype && !other.datatype) || (this.datatype && this.datatype.equals(other.datatype))) } - get language () { + /** + * The language for the literal + */ + get language (): string { return this.lang } set language (language) { @@ -61,23 +99,21 @@ export default class Literal extends Node { toString () { return '' + this.value } + /** - * @method fromBoolean - * @static - * @param value {Boolean} - * @return {Literal} + * Builds a literal node from a boolean value + * @param value The value */ - static fromBoolean (value) { + static fromBoolean(value: boolean): Literal { let strValue = value ? '1' : '0' return new Literal(strValue, null, XSD.boolean) } + /** - * @method fromDate - * @static - * @param value {Date} - * @return {Literal} + * Builds a literal node from a date value + * @param value The value */ - static fromDate (value) { + static fromDate(value: Date): Literal { if (!(value instanceof Date)) { throw new TypeError('Invalid argument to Literal.fromDate()') } @@ -89,13 +125,12 @@ export default class Literal extends Node { d2(value.getUTCMinutes()) + ':' + d2(value.getUTCSeconds()) + 'Z' return new Literal(date, null, XSD.dateTime) } + /** - * @method fromNumber - * @static - * @param value {Number} - * @return {Literal} + * Builds a literal node from a number value + * @param value The value */ - static fromNumber (value) { + static fromNumber(value: number): Literal { if (typeof value !== 'number') { throw new TypeError('Invalid argument to Literal.fromNumber()') } @@ -108,17 +143,17 @@ export default class Literal extends Node { } return new Literal(strValue, null, datatype) } + /** - * @method fromValue - * @param value - * @return {Literal} + * Builds a literal node from an input value + * @param value The input value */ - static fromValue (value) { + static fromValue(value: ValueType): Literal | Node | undefined | null { if (typeof value === 'undefined' || value === null) { return value } - if (typeof value === 'object' && value.termType) { // this is a Node instance - return value + if (Object.prototype.hasOwnProperty.call(value, 'termType')) { // this is a Node instance + return value as Node } switch (typeof value) { case 'object': @@ -126,7 +161,7 @@ export default class Literal extends Node { return Literal.fromDate(value) } case 'boolean': - return Literal.fromBoolean(value) + return Literal.fromBoolean(value as boolean) case 'number': return Literal.fromNumber(value) case 'string': @@ -137,8 +172,7 @@ export default class Literal extends Node { } } -Literal.termType = 'Literal' -Literal.prototype.classOrder = ClassOrder['Literal'] -Literal.prototype.datatype = XSD.string + +Literal.prototype.classOrder = classOrder['Literal'] Literal.prototype.lang = '' -Literal.prototype.isVar = 0 +Literal.prototype.isVar = false diff --git a/src/named-node.js b/src/named-node.ts similarity index 54% rename from src/named-node.js rename to src/named-node.ts index b806386ca..30849945f 100644 --- a/src/named-node.js +++ b/src/named-node.ts @@ -1,54 +1,60 @@ -'use strict' import ClassOrder from './class-order' import Node from './node-internal' +import { ValueType } from './types'; /** - * @class NamedNode - * @extends Node - */ +* A named (IRI) RDF node +*/ export default class NamedNode extends Node { + + static termType: 'NamedNode'; + /** - * @constructor - * @param iri {String} + * Initializes this node + * @param iri The IRI for this node */ - constructor (iri) { + constructor (iri: NamedNode | string) { super() this.termType = NamedNode.termType - if (iri && iri.termType === NamedNode.termType) { // param is a named node - iri = iri.value + if (iri && (iri as NamedNode).termType === NamedNode.termType) { // param is a named node + iri = (iri as NamedNode).value } if (!iri) { throw new Error('Missing IRI for NamedNode') } - if (!iri.includes(':')) { + const iriString = iri as string + + if (!iriString.includes(':')) { throw new Error('NamedNode IRI "' + iri + '" must be absolute.') } - if (iri.includes(' ')) { + if (iriString.includes(' ')) { var message = 'Error: NamedNode IRI "' + iri + '" must not contain unencoded spaces.' throw new Error(message) } - this.value = iri + this.value = iriString } + /** - * Returns an $rdf node for the containing directory, ending in slash. + * Returns an RDF node for the containing directory, ending in slash. */ - dir () { + dir (): NamedNode | null{ var str = this.uri.split('#')[0] var p = str.slice(0, -1).lastIndexOf('/') var q = str.indexOf('//') if ((q >= 0 && p < q + 2) || p < 0) return null return new NamedNode(str.slice(0, p + 1)) } - /** - * Returns an NN for the whole web site, ending in slash. - * Contrast with the "origin" which does NOT have a trailing slash - */ - site () { + + /** + * Returns a NamedNode for the whole web site, ending in slash. + * Contrast with the "origin" which does NOT have a trailing slash + */ + site (): NamedNode { var str = this.uri.split('#')[0] var p = str.indexOf('//') if (p < 0) throw new Error('This URI does not have a web site part (origin)') @@ -59,19 +65,28 @@ export default class NamedNode extends Node { return new NamedNode(str.slice(0, q + 1)) } } - doc () { + + /** + * Gets the named node for the document + */ + doc (): NamedNode { if (this.uri.indexOf('#') < 0) { return this } else { return new NamedNode(this.uri.split('#')[0]) } } - toString () { + + /** + * Returns the URI including + */ + toString (): string { return '<' + this.uri + '>' } - /* The local identifier with the document - */ + /** + * The local identifier with the document + */ id () { return this.uri.split('#')[1] } @@ -79,23 +94,28 @@ export default class NamedNode extends Node { /** * Legacy getter and setter alias, node.uri */ - get uri () { + get uri (): string { return this.value } - set uri (uri) { + set uri (uri: string) { this.value = uri } - static fromValue (value) { + + /** + * Gets a named node from the specified input value + * @param value An input value + */ + static fromValue(value: ValueType): NamedNode | null | undefined | Node { if (typeof value === 'undefined' || value === null) { return value } - const isNode = value && value.termType + const isNode = value && (value as Node).termType if (isNode) { - return value + return value as NamedNode } - return new NamedNode(value) + return new NamedNode(value as string) } } NamedNode.termType = 'NamedNode' NamedNode.prototype.classOrder = ClassOrder['NamedNode'] -NamedNode.prototype.isVar = 0 +NamedNode.prototype.isVar = false diff --git a/src/node-internal.js b/src/node-internal.js deleted file mode 100644 index 2c5e63b8d..000000000 --- a/src/node-internal.js +++ /dev/null @@ -1,51 +0,0 @@ -'use strict' - -/** - * The superclass of all RDF Statement objects, that is - * NamedNode, Literal, BlankNode, etc. - * @class Node - */ - -export default class Node { - substitute (bindings) { - console.log('@@@ node substitute' + this) - return this - } - compareTerm (other) { - if (this.classOrder < other.classOrder) { - return -1 - } - if (this.classOrder > other.classOrder) { - return +1 - } - if (this.value < other.value) { - return -1 - } - if (this.value > other.value) { - return +1 - } - return 0 - } - equals (other) { - if (!other) { - return false - } - return (this.termType === other.termType) && - (this.value === other.value) - } - hashString () { - return this.toCanonical() - } - sameTerm (other) { - return this.equals(other) - } - toCanonical () { - return this.toNT() - } - toNT () { - return this.toString() - } - toString () { - throw new Error('Node.toString() is abstract - see the subclasses instead') - } -} diff --git a/src/node-internal.ts b/src/node-internal.ts new file mode 100644 index 000000000..4b24aff9c --- /dev/null +++ b/src/node-internal.ts @@ -0,0 +1,120 @@ +import { ValueType, Bindings } from './types' +import Collection from './collection' +import Literal from './literal' + +/** + * The superclass of all RDF Statement objects, that is + * NamedNode, Literal, BlankNode, etc. + * Also called Term. + * @link https://rdf.js.org/data-model-spec/#term-interface + * @class Node + */ +export default abstract class Node { + /** + * The nodes in this collection + */ + elements!: Node[]; + + /** + * The type of node + */ + termType!: string; + + /** + * Whether this node is a variable + */ + isVar!: boolean; + + /** + * The class order for this node + */ + classOrder!: number; + + /** + * The node's value + */ + value!: string; + + // Specified in './node.ts' to prevent circulur dependency + static fromValue: (value: ValueType | null) => Node | Literal | undefined | null | Collection + + // Specified in './node.ts' to prevent circulur dependency + static toJS: (term: Node | Literal) => any + + /** + * Gets the substituted node for this one, according to the specified bindings + * @param bindings Bindings of identifiers to nodes + */ + substitute (bindings: Bindings): Node { + console.log('@@@ node substitute' + this) + return this + } + + /** + * Compares this node with another + * @param term The other node + */ + compareTerm (other: Node): number { + if (this.classOrder < other.classOrder) { + return -1 + } + if (this.classOrder > other.classOrder) { + return +1 + } + if (this.value && this.value < other.value) { + return -1 + } + if (this.value && this.value > other.value) { + return +1 + } + return 0 + } + + /** + * Gets whether the two nodes are equal + * @param other The other node + */ + equals (other: Node): boolean { + if (!other) { + return false + } + return (this.termType === other.termType) && + (this.value === other.value) + } + + /** + * Gets a hash for this node + */ + hashString (): string { + return this.toCanonical() + } + + /** + * Gets whether this node is the same as the other one + * @param other Another node + */ + sameTerm(other: Node): boolean { + return this.equals(other) + } + + /** + * Gets the canonical string representation of this node + */ + toCanonical (): string { + return this.toNT() + } + + /** + * Gets the n-triples string representation of this node + */ + toNT (): string { + return this.toString() + } + + /** + * Gets the string representation of this node + */ + toString (): string { + throw new Error('Node.toString() is abstract - see the subclasses instead') + } +} diff --git a/src/node.js b/src/node.js deleted file mode 100644 index a9df9975c..000000000 --- a/src/node.js +++ /dev/null @@ -1,57 +0,0 @@ -'use strict' - -// This file attaches all functionality to Node -// that would otherwise require circular dependencies. -import Node from './node-internal' -import Collection from './collection' -import Literal from './literal' - -export default Node - -/** - * Creates an RDF Node from a native javascript value. - * RDF Nodes are returned unchanged, undefined returned as itself. - * @method fromValue - * @static - * @param value {Node|Date|String|Number|Boolean|Undefined} - * @return {Node|Collection} - */ -Node.fromValue = function fromValue (value) { - if (typeof value === 'undefined' || value === null) { - return value - } - const isNode = value && value.termType - if (isNode) { // a Node subclass or a Collection - return value - } - if (Array.isArray(value)) { - return new Collection(value) - } - return Literal.fromValue(value) -} - -import Namespace from './namespace' -const ns = { xsd: Namespace('http://www.w3.org/2001/XMLSchema#') } - -Node.toJS = function toJS (term) { - if (term.elements) { - return term.elements.map(Node.toJS) // Array node (not standard RDFJS) - } - if (!term.datatype) return term // Objects remain objects - if (term.datatype.sameTerm(ns.xsd('boolean'))) { - return term.value === '1' - } - if (term.datatype.sameTerm(ns.xsd('dateTime')) || - term.datatype.sameTerm(ns.xsd('date'))) { - return new Date(term.value) - } - if ( - term.datatype.sameTerm(ns.xsd('integer')) || - term.datatype.sameTerm(ns.xsd('float')) || - term.datatype.sameTerm(ns.xsd('decimal')) - ) { - let z = Number(term.value) - return Number(term.value) - } - return term.value -} diff --git a/src/node.ts b/src/node.ts new file mode 100644 index 000000000..4b0aca7aa --- /dev/null +++ b/src/node.ts @@ -0,0 +1,61 @@ +// This file attaches all functionality to Node +// that would otherwise require circular dependencies. +import Node from './node-internal' +import Collection from './collection' +import Literal from './literal' +import { ValueType } from './types' +import Namespace from './namespace' + +export default Node + +/** + * Creates an RDF Node from a native javascript value. + * RDF Nodes are returned unchanged, undefined returned as itself. + * @method fromValue + * @param value - Any native Javascript value + */ +Node.fromValue = function (value: ValueType): Node | Literal | undefined | null | Collection { + if (typeof value === 'undefined' || value === null) { + return value + } + const isNode = Object.prototype.hasOwnProperty.call(value, 'termType') + if (isNode) { // a Node subclass or a Collection + return value + } + if (Array.isArray(value)) { + return new Collection(value) + } + return Literal.fromValue(value) +} + +const ns = { xsd: Namespace('http://www.w3.org/2001/XMLSchema#') } + +/** + * Gets the javascript object equivalent to a node + * @param term The RDF node + */ +Node.toJS = function (term: Node | Literal) { + if (term.elements) { + return term.elements.map(Node.toJS) // Array node (not standard RDFJS) + } + // Node remains Node + if (!term.datatype) return term // Objects remain objects + const literalTerm = term as Literal + // if (!Object.prototype.hasOwnProperty.call(term, 'dataType')) return term // Objects remain objects + if (literalTerm.datatype.sameTerm(ns.xsd('boolean'))) { + return literalTerm.value === '1' + } + if (literalTerm.datatype.sameTerm(ns.xsd('dateTime')) || + literalTerm.datatype.sameTerm(ns.xsd('date'))) { + return new Date(literalTerm.value) + } + if ( + literalTerm.datatype.sameTerm(ns.xsd('integer')) || + literalTerm.datatype.sameTerm(ns.xsd('float')) || + literalTerm.datatype.sameTerm(ns.xsd('decimal')) + ) { + let z = Number(literalTerm.value) + return Number(literalTerm.value) + } + return literalTerm.value +} diff --git a/src/statement.js b/src/statement.js deleted file mode 100644 index 006eb7f12..000000000 --- a/src/statement.js +++ /dev/null @@ -1,64 +0,0 @@ -'use strict' -import Node from './node' - -export default class Statement { - /* Construct a new statment - ** - ** @param {Term} subject - The subject of the triple. What the efact is about - ** @ param {Term} predciate - The relationship which is assrted between the subject and object - ** @param {Term} object - The thing or data value which is asserted to be related to the subject - ** @param {NamedNode} why - The document where thr triple is or was or will be stored on the web. - ** - ** The why param is a named node of the document in which the triple when - ** it is stored on the web. - ** It is called “why” because when you have read data from varou slaces the - ** “why” tells you why you have the triple. (At the moment, it is just the - ** document, in future it could be an inference step). When you do - ** UpdateManager.update() then the why’s of all the statmemts must be the same, - ** and give the document you are patching. In future, we may have a more - ** powerful update() which can update more than one docment. - */ - constructor (subject, predicate, object, graph) { - this.subject = Node.fromValue(subject) - this.predicate = Node.fromValue(predicate) - this.object = Node.fromValue(object) - this.why = graph // property currently used by rdflib - } - get graph () { - return this.why - } - set graph (g) { - this.why = g - } - equals (other) { - return other.subject.equals(this.subject) && other.predicate.equals(this.predicate) && - other.object.equals(this.object) && other.graph.equals(this.graph) - } - substitute (bindings) { - const y = new Statement( - this.subject.substitute(bindings), - this.predicate.substitute(bindings), - this.object.substitute(bindings), - this.why.substitute(bindings)) // 2016 - console.log('@@@ statement substitute:' + y) - return y - } - toCanonical () { - let terms = [ - this.subject.toCanonical(), - this.predicate.toCanonical(), - this.object.toCanonical() - ] - if (this.graph && this.graph.termType !== 'DefaultGraph') { - terms.push(this.graph.toCanonical()) - } - return terms.join(' ') + ' .' - } - toNT () { - return [this.subject.toNT(), this.predicate.toNT(), - this.object.toNT()].join(' ') + ' .' - } - toString () { - return this.toNT() - } -} diff --git a/src/statement.ts b/src/statement.ts new file mode 100644 index 000000000..122b96398 --- /dev/null +++ b/src/statement.ts @@ -0,0 +1,118 @@ +import { Bindings, ValueType } from './types' +import Literal from './literal' +import Node from './node-internal' +import Collection from './collection' + +/** A Statement represents an RDF Triple or Quad. */ +export default class Statement { + /** The subject of the triple. What the Statement is about. */ + subject: Node; + + /** The relationship which is asserted between the subject and object */ + predicate: Node; + + /** The thing or data value which is asserted to be related to the subject */ + object: Node | Literal | Collection; + + /** + * The why param is a named node of the document in which the triple when + * it is stored on the web. + */ + why: Node; + + /** + * Construct a new Triple Statment + * + * @param subject - The subject of the triple. What the Statement is about. + * @param predicate - The relationship which is asserted between the subject and object. + * @param object - The thing or data value which is asserted to be related to the subject. + * @param why - The document where the triple is or was or will be stored on the web. + * The why param is a named node of the document in which the triple when + * it is stored on the web. + * It is called “why” because when you have read data from varou slaces the + * “why” tells you why you have the triple. (At the moment, it is just the + * document, in future it could be an inference step). When you do + * UpdateManager.update() then the why’s of all the statmemts must be the same, + * and give the document you are patching. In future, we may have a more + * powerful update() which can update more than one docment. + */ + constructor ( + subject: Node, + predicate: Node, + object: Node | ValueType, + why, + ) { + this.subject = Node.fromValue(subject) as Node + this.predicate = Node.fromValue(predicate) as Node + this.object = Node.fromValue(object) as Node + this.why = why // property currently used by rdflib + } + + /** + * The graph param is a named node of the document in which the triple is stored on the web. + */ + get graph (): Node { + return this.why + } + + set graph (g) { + this.why = g + } + + /** + * Gets whether two statements are the same + * @param other The other statement + */ + equals (other: Statement): boolean { + return ( + other.subject.equals(this.subject) && + other.predicate.equals(this.predicate) && + other.object.equals(this.object as Literal) && + other.graph.equals(this.graph) + ) + } + + /** + * Gets this statement with the bindings substituted + * @param bindings The bindings + */ + substitute (bindings: Bindings): Statement { + const y = new Statement( + this.subject.substitute(bindings), + this.predicate.substitute(bindings), + this.object.substitute(bindings) as Node, + this.why.substitute(bindings)) // 2016 + console.log('@@@ statement substitute:' + y) + return y + } + + /** + * Gets the canonical string representation of this statement + */ + toCanonical (): string { + let terms = [ + this.subject.toCanonical(), + this.predicate.toCanonical(), + this.object.toCanonical() + ] + if (this.graph && this.graph.termType !== 'DefaultGraph') { + terms.push(this.graph.toCanonical()) + } + return terms.join(' ') + ' .' + } + + /** + * Gets the n-triples string representation of this statement + */ + toNT (): string { + return [this.subject.toNT(), this.predicate.toNT(), + this.object.toNT()].join(' ') + ' .' + } + + /** + * Gets the string representation of this statement + */ + toString (): string { + return this.toNT() + } +} diff --git a/src/types.ts b/src/types.ts new file mode 100644 index 000000000..4c84edb92 --- /dev/null +++ b/src/types.ts @@ -0,0 +1,10 @@ +import Node from './node-internal'; + +/** +* A type for values that serves as inputs +*/ +export type ValueType = Node | Date | string | number | boolean | undefined | null; + +export interface Bindings { + [id: string]: Node; +} diff --git a/src/variable.js b/src/variable.js index 5632e7965..0ac8d6f81 100644 --- a/src/variable.js +++ b/src/variable.js @@ -42,4 +42,4 @@ export default class Variable extends Node { Variable.termType = 'Variable' Variable.prototype.classOrder = ClassOrder['Variable'] -Variable.prototype.isVar = 1 +Variable.prototype.isVar = true diff --git a/tsconfig.json b/tsconfig.json index 4b78c20c4..def80648e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,7 +3,7 @@ "allowSyntheticDefaultImports": true, "checkJs": false, "allowJs": true, - "target": "es6", + "target": "es5", "module": "es6", "strict": true, "noImplicitAny": false, diff --git a/typedoc.js b/typedoc.js new file mode 100644 index 000000000..c3592bae5 --- /dev/null +++ b/typedoc.js @@ -0,0 +1,18 @@ +module.exports = { + src: ['./src'], + mode: "file", + out: "doc", + tsconfig: "tsconfig.json", + theme: "default", + hideGenerator: true, + ignoreCompilerErrors: true, + excludePrivate: true, + excludeNotExported: "true", + target: "ES6", + moduleResolution: "node", + preserveConstEnums: "true", + stripInternal: "true", + suppressExcessPropertyErrors: "true", + suppressImplicitAnyIndexErrors: "true", + module: "commonjs" +} diff --git a/types-temp.ts b/types-temp.ts new file mode 100644 index 000000000..0a8d6d738 --- /dev/null +++ b/types-temp.ts @@ -0,0 +1,1114 @@ +// This is a Temporary file to help with the migration to typescript. +// See issue: https://github.com/linkeddata/rdflib.js/issues/355 +// Migrate these types and comments to the according files, then remove them from this list. +// Don't import types from this file. +// When you do want to use a type from this file, move it to `./types.ts` +// And import it here. + +import { + Bindings, + ValueType, +} from './src/types'; +import { NamedNode } from './src'; + +// Type definitions for rdflib 0.20 +// Project: http://github.com/linkeddata/rdflib.js +// Definitions by: Cénotélie +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.0 +// Acknowledgements: This work has been financed by Logilab SA, FRANCE, logilab.fr + +/** +* Variables are placeholders used in patterns to be matched. +* In cwm they are symbols which are the formula's list of quantified variables. +* In sparql they are not visibly URIs. Here we compromise, by having +* a common special base URI for variables. Their names are uris, +* but the ? notation has an implicit base uri of 'varid:' +*/ +export interface Variable extends Node { + /** + * The base string for a variable's name + */ + base: string; + /** + * The unique identifier of this variable + */ + uri: string; + /** + * Initializes this variable + * @param name The variable's name + */ + constructor(name?: string); + static termType: string; +} +/** +* The RDF default graph +*/ +export interface DefaultGraph extends Node { + /** + * Initializes this graph + */ + constructor(); +} +export namespace uri { + /** + * Gets the document part of an URI + * @param uri The URI + */ + function docpart(uri: string): string; + /** + * Gets the document part of an URI as a named node + * @param x The URI + */ + function document(x: string): NamedNode; + /** + * Gets the hostname in an URI + * @param u The URI + */ + function hostpart(u: string): string; + /** + * Joins an URI with a base + * @param given The relative part + * @param base The base URI + */ + function join(given: string, base: string): string; + /** + * Gets the protocol part of an URI + * @param uri The URI + */ + function protocol(uri: string): string; + /** + * Gets a relative uri + * @param base The base URI + * @param uri The absolute URI + */ + function refTo(base: string, uri: string): string; +} +export namespace log { + /** + * Logs a debug event + * @param x The event + */ + function debug(x: any): void; + /** + * Logs a warning event + * @param x The event + */ + function warn(x: any): void; + /** + * Logs an information event + * @param x The event + */ + function info(x: any): void; + /** + * Logs an error event + * @param x The event + */ + function error(x: any): void; + /** + * Logs a success event + * @param x The event + */ + function success(x: any): void; + /** + * Logs a message event + * @param x The event + */ + function msg(x: any): void; +} + +export namespace convert { + /** + * Converts an n3 string to JSON + * @param n3String The n3 string + * @param jsonCallback Callback when the operation terminated + */ + function convertToJson( + n3String: string, + jsonCallback: (err: string, jsonString: string) => void + ): void; + /** + * Converts an n3 string to n-quads + * @param n3String The n3 string + * @param nquadCallback Callback when the operation terminated + */ + function convertToNQuads( + n3String: string, + nquadCallback: (err: string, nquadString: string) => void + ): void; +} +/** +* A formula, or store of RDF statements +*/ +export interface Formula extends Node { + /** + * The stored statements + */ + statements: Statement[]; + /** + * Initializes this formula + * @param statements The initial statements in this formulat + * @param constraints The additional constraints + * @param initBindings The initial bindings + * @param optional + */ + constructor( + statements: ReadonlyArray, + constraints: ReadonlyArray, + initBindings: { + [id: string]: Node; + }, + optional: ReadonlyArray + ); + /** + * Adds a statement to this formula + * @param s The subject + * @param p The predicate + * @param o The object + * @param g The graph that contains the statement + */ + add(s: Node, p: NamedNode, o: Node, g: NamedNode): number; + /** + * Adds a statement to this formula + * @param st The statement to add + */ + addStatement(st: Statement): number; + /** + * Gets a blank node + * @param id The node's identifier + */ + bnode(id: string): BlankNode; + /** + * Adds all the statements to this formula + * @param statements A collection of statements + */ + addAll(statements: Iterable): void; + /** + * Gets a node that matches the specified pattern + * @param s The subject + * @param p The predicate + * @param o The object + * @param g The graph that contains the statement + */ + any( + s?: Node | null, + p?: Node | null, + o?: Node | null, + g?: Node | null + ): Node | null; + /** + * Gets the value of a node that matches the specified pattern + * @param s The subject + * @param p The predicate + * @param o The object + * @param g The graph that contains the statement + */ + anyValue( + s?: Node | null, + p?: Node | null, + o?: Node | null, + g?: Node | null + ): string; + /** + * Gets the first JavaScript object equivalent to a node based on the specified pattern + * @param s The subject + * @param p The predicate + * @param o The object + * @param g The graph that contains the statement + */ + anyJS( + s?: Node | null, + p?: Node | null, + o?: Node | null, + g?: Node | null + ): any; + /** + * Gets the first statement that matches the specified pattern + * @param subj The subject + * @param pred The predicate + * @param obj The object + * @param why The graph that contains the statement + */ + anyStatementMatching( + subj?: Node | null, + pred?: Node | null, + obj?: Node | null, + why?: Node | null + ): Statement; + /** + * Gets the statements matching the specified pattern + * @param subj The subject + * @param pred The predicate + * @param obj The object + * @param why The graph that contains the statement + * @param justOne Whether to only get one statement + */ + statementsMatching( + subj?: Node | null, + pred?: Node | null, + obj?: Node | null, + why?: Node | null, + justOne?: boolean + ): Statement[]; + /** + * Finds the types in the list which have no *stored* subtypes + * These are a set of classes which provide by themselves complete + * information -- the other classes are redundant for those who + * know the class DAG. + * @param types A map of the types + */ + bottomTypeURIs(types: { + [id: string]: string | NamedNode; + }): { + [id: string]: string | NamedNode; + }; + /** + * Gets a new collection + */ + collection(): Collection; + /** + * Gets each node that matches the specified pattern + * @param s The subject + * @param p The predicate + * @param o The object + * @param g The graph that contains the statement + */ + each( + s?: Node | null, + p?: Node | null, + o?: Node | null, + g?: Node | null + ): Node[]; + /** + * Gets whether this formula is equals to the other one + * @param other The other formula + */ + equals(other: Formula): boolean; + /** + * For thisClass or any subclass, anything which has it is its type + * or is the object of something which has the type as its range, or subject + * of something which has the type as its domain + * We don't bother doing subproperty (yet?)as it doesn't seeem to be used + * much. + * Get all the Classes of which we can RDFS-infer the subject is a member + * @param thisClass A named node + */ + findMembersNT( + thisClass: Node + ): { + [uri: string]: Statement; + }; + /** + * For thisClass or any subclass, anything which has it is its type + * or is the object of something which has the type as its range, or subject + * of something which has the type as its domain + * We don't bother doing subproperty (yet?)as it doesn't seeem to be used + * much. + * Get all the Classes of which we can RDFS-infer the subject is a member + * @param subject A named node + */ + findMemberURIs( + subject: Node + ): { + [uri: string]: Statement; + }; + /** + * Get all the Classes of which we can RDFS-infer the subject is a superclass + * Returns a hash table where key is NT of type and value is statement why we + * think so. + * Does NOT return terms, returns URI strings. + * We use NT representations in this version because they handle blank nodes. + * @param subject A subject node + */ + findSubClassesNT( + subject: Node + ): { + [uri: string]: boolean; + }; + /** + * Get all the Classes of which we can RDFS-infer the subject is a subclass + * Returns a hash table where key is NT of type and value is statement why we + * think so. + * Does NOT return terms, returns URI strings. + * We use NT representations in this version because they handle blank nodes. + * @param subject A subject node + */ + findSuperClassesNT( + subject: Node + ): { + [uri: string]: boolean; + }; + /** + * Get all the Classes of which we can RDFS-infer the subject is a member + * todo: This will loop is there is a class subclass loop (Sublass loops are + * not illegal) + * Returns a hash table where key is NT of type and value is statement why we + * think so. + * Does NOT return terms, returns URI strings. + * We use NT representations in this version because they handle blank nodes. + * @param subject A subject node + */ + findTypesNT( + subject: Node + ): { + [uri: string]: boolean; + }; + /** + * Get all the Classes of which we can RDFS-infer the subject is a member + * todo: This will loop is there is a class subclass loop (Sublass loops are + * not illegal) + * Returns a hash table where key is NT of type and value is statement why we + * think so. + * Does NOT return terms, returns URI strings. + * We use NT representations in this version because they handle blank nodes. + * @param subject A subject node + */ + findTypeURIs( + subject: Node + ): { + [uri: string]: boolean; + }; + /** + * Trace the statements which connect directly, or through bnodes + * Returns an array of statements + * doc param may be null to search all documents in store + * @param subject A subject node + * @param doc A document (the graph that contains statements) + * @param excludePredicateURIs The predicate URIs to exclude + */ + connectedStatements( + subject: Node, + doc: ValueType, + excludePredicateURIs: ReadonlyArray + ): Statement[]; + /** + * Creates a new empty formula - features not applicable, but necessary for typing to pass + */ + formula(features?: ReadonlyArray): Formula; + /** + * Transforms an NTriples string format into a Node. + * The bnode bit should not be used on program-external values; designed + * for internal work such as storing a bnode id in an HTML attribute. + * This will only parse the strings generated by the vaious toNT() methods. + * @param str A string representation + */ + fromNT(str: string): Node; + /** + * Gets whether this formula holds the specified statement + * @param s A subject + * @param p A predicate + * @param o An object + * @param g A containing graph + */ + holds( + s?: Node | null, + p?: Node | null, + o?: Node | null, + g?: Node | null + ): boolean; + /** + * Gets whether this formula holds the specified statement + * @param st A statement + */ + holdsStatement(st: Statement): boolean; + /** + * Gets a collection from a list of values + * @param values The values + */ + list(values: Iterable): Collection; + /** + * Gets a literal node + * @param val The literal's lexical value + * @param lang The language + * @param dt The datatype as a named node + */ + literal(val: string, lang: string, dt: NamedNode): Literal; + /** + * Transform a collection of NTriple URIs into their URI strings + * @param t some iterable colletion of NTriple URI strings + * @return a collection of the URIs as strings + */ + NTtoURI(t: { + [uri: string]: any; + }): { + [uri: string]: any; + }; + /** + * Serializes this formula + * @param base The base string + * @param contentType The content type of the syntax to use + * @param provenance The provenance URI + */ + serialize(base: string, contentType: string, provenance: string): string; + /** + * Gets a new formula with the substituting bindings applied + * @param bindings The bindings to substitute + */ + substitute(bindings: Bindings): Formula; + /** + * Gets an named node for an URI + * @param uri The URI + */ + sym(uri: string | NamedNode): NamedNode; + /** + * Gets the node matching the specified pattern + * @param s The subject + * @param p The predicate + * @param o The object + * @param g The graph that contains the statement + */ + the( + s?: Node | null, + p?: Node | null, + o?: Node | null, + g?: Node | null + ): Node; + /** + * RDFS Inference + * These are hand-written implementations of a backward-chaining reasoner + * over the RDFS axioms. + * @param seeds A hash of NTs of classes to start with + * @param predicate The property to trace though + * @param inverse Trace inverse direction + */ + transitiveClosure( + seeds: { + [uri: string]: boolean; + }, + predicate: Node, + inverse: Node + ): { + [uri: string]: boolean; + }; + /** + * Finds the types in the list which have no *stored* supertypes + * We exclude the universal class, owl:Things and rdf:Resource, as it is + * information-free. + * @param types The types + */ + topTypeURIs(types: { + [id: string]: string | NamedNode; + }): { + [id: string]: string | NamedNode; + }; + /** + * Gets the number of statements in this formulat that matches the specified pattern + * @param s The subject + * @param p The predicate + * @param o The object + * @param g The graph that contains the statement + */ + whether( + s?: Node | null, + p?: Node | null, + o?: Node | null, + g?: Node | null + ): number; + /** + * Serializes this formulat to a string + */ + toString(): string; + /** + * Gets a namespace for the specified namespace's URI + * @param nsuri The URI for the namespace + */ + ns(nsuri: string): (ln: string) => NamedNode; + /** + * Gets a new variable + * @param name The variable's name + */ + variable(name: string): Variable; + static termType: string; +} + +export class Query { + pat: IndexedFormula; + name: string; + id?: string; + constructor(name: string, id?: any); + } + +/** +* A formula (set of triples) which indexes by predicate, subject and object. +* It "smushes" (merges into a single node) things which are identical +* according to owl:sameAs or an owl:InverseFunctionalProperty +* or an owl:FunctionalProperty +*/ +export class IndexedFormula extends Formula { + /** + * An UpdateManager initialised to this store + */ + updater?: UpdateManager; + /** + * Creates a new formula + * @param features The list of features to support + */ + constructor(features: ReadonlyArray); + /** + * Dictionary of namespace prefixes + */ + namespaces: {[key: string]: string}; + /** + * Gets the URI of the default graph + */ + static defaultGraphURI(): string; + /** + * Gets this graph with the bindings substituted + * @param bindings The bindings + */ + substitute(bindings: Bindings): IndexedFormula; + + /** + * Apply a set of statements to be deleted and to be inserted + * + * @param patch The set of statements to be deleted and to be inserted + * @param target The name of the document to patch + * @param patchCallback Callback to be called when patching is complete + */ + applyPatch( + patch: { + delete?: ReadonlyArray, + patch?: ReadonlyArray + }, + target: NamedNode, + patchCallback: () => void + ): void; + + /** + * N3 allows for declaring blank nodes, this function enables that support + * + * @param x The blank node to be declared, supported in N3 + */ + declareExistential(x: Node): Node; + + /** + * @param features + */ + initPropertyActions(features: Array<('sameAs' | 'InverseFunctionalProperty' | 'FunctionalProperty')>): boolean; + /** + * Returns the symbol with canonical URI as smushed + * @param term A RDF node + */ + canon(term: Node): Node; + /** + * Checks this formula for consistency + */ + check(): void; + /** + * Checks a list of statements for consistency + * @param sts The list of statements to check + * @param from An index with the array ['subject', 'predicate', 'object', 'why'] + */ + checkStatementList(sts: ReadonlyArray, from: number): boolean; + /** + * Closes this formula (and return it) + */ + close(): IndexedFormula; + /** + * replaces @template with @target and add appropriate triples + * removes no triples by default and is a one-direction replication + * @param template node to copy + * @param target node to copy to + * @param flags Whether or not to do a two-directional copy and/or delete triples + * + */ + copyTo( + template: Node, + target: Node, + flags?: Array<('two-direction' | 'delete')> + ): void; + /** + * Simplify graph in store when we realize two identifiers are equivalent + * We replace the bigger with the smaller. + * @param u1 The first node + * @param u2 The second node + */ + equate(u1: Node, u2: Node): boolean; + /** + * Creates a new empty indexed formula + * Only applicable for IndexedFormula, but TypeScript won't allow a subclass to override a property + * @param features The list of features + */ + formula(features: ReadonlyArray): IndexedFormula; + /** + * The number of statements in this formula + */ + length: number; + /** + * eturns any quads matching the given arguments. + * Standard RDFJS Taskforce method for Source objects, implemented as an + * alias to `statementsMatching()` + * @param subject The subject + * @param predicate The predicate + * @param object The object + * @param graph The graph that contains the statement + */ + match( + subject: ValueType, + predicate: ValueType, + object: ValueType, + graph: ValueType + ): Statement[]; + /** + * Find out whether a given URI is used as symbol in the formula + * @param uri The URI to look for + */ + mentionsURI(uri: string): boolean; + /** + * Existentials are BNodes - something exists without naming + * @param uri An URI + */ + newExistential(uri: string): Node; + + /** + * Adds a new property action + * @param pred the predicate that the function should be triggered on + * @param action the function that should trigger + */ + newPropertyAction(pred: Node, action: (store: IndexedFormula, subject: NamedNode, object: NamedNode) => boolean): boolean; + /** + * Creates a new universal node + * Universals are Variables + * @param uri An URI + */ + newUniversal(uri: string): Node; + /** + * Find an unused id for a file being edited: return a symbol + * (Note: Slow iff a lot of them -- could be O(log(k)) ) + * @param doc A document named node + */ + nextSymbol(doc: NamedNode): NamedNode; + + /** + * Query this store asynchronously, return bindings in callback + * + * @param myQuery The query to be run + * @param callback Function to call when bindings + * @param dummy OBSOLETE - do not use this + * @param onDone OBSOLETE - do not use this + */ + query( + myQuery: Query, + callback: (bindings: Bindings) => void, + dummy?: null, + onDone?: () => void + ): void; + /** + * Query this store synchronously and return bindings + * + * @param myQuery The query to be run + */ + querySync(myQuery: Query): Bindings[]; + /** + * Removes a statement from this formula + * @param st A statement to remove + */ + remove(st: Statement): IndexedFormula; + /** + * Removes all statemnts in a doc + * @param doc The document + */ + removeDocument(doc: NamedNode): IndexedFormula; + /** + * Remove all statements matching args (within limit) * + * @param subj The subject + * @param pred The predicate + * @param obj The object + * @param why The graph that contains the statement + * @param limit The number of statements to remove + */ + removeMany( + subj?: Node | null, + pred?: Node | null, + obj?: Node | null, + why?: Node | null, + limit?: number + ): void; + /** + * Remove all matching statements + * @param subject The subject + * @param predicate The predicate + * @param object The object + * @param graph The graph that contains the statement + */ + removeMatches( + subject?: Node | null, + predicate?: Node | null, + object?: Node | null, + graph?: Node | null + ): void; + /** + * Removes a statement + * @param st The statement to remove + */ + removeStatement(st: Statement): Formula; + /** + * Removes statements + * @param sts The statements to remove + */ + removeStatements(sts: ReadonlyArray): Formula; + /** + * Return all equivalent URIs by which this is known + * @param x A named node + */ + allAliases(x: NamedNode): NamedNode[]; + /** + * Compare by canonical URI as smushed + * @param x A named node + * @param y Another named node + */ + sameThings(x: NamedNode, y: NamedNode): boolean; + /** + * A list of all the URIs by which this thing is known + * @param term + */ + uris(term: NamedNode): string[]; +} +export namespace DataFactory { + /** + * Creates a new blank node + * @param value The blank node's identifier + */ + function blankNode(value: string): BlankNode; + /** + * Creates a new collection + * @param elements The initial element + */ + function collection(elements: ReadonlyArray): Collection; + /** + * Gets the default graph + */ + function defaultGraph(): DefaultGraph; + /** + * Creates a new fetcher + * @param store The store to use + * @param options The options + */ + function fetcher(store: Formula, options: any): Fetcher; + /** + * Creates a new graph (store) + */ + function graph(): IndexedFormula; + /** + * Creates a new literal node + * @param val The lexical value + * @param lang The language + * @param dt The datatype + */ + function lit(val: string, lang?: string, dt?: NamedNode): Literal; + /** + * Creates a new literal node + * @param value The lexical value + * @param languageOrDatatype Either the language or the datatype + */ + function literal( + value: string, + languageOrDatatype?: string | NamedNode + ): Literal; + /** + * Creates a new named node + * @param value The new named node + */ + function namedNode(value: string): NamedNode; + /** + * Creates a new statement + * @param subject The subject + * @param predicate The predicate + * @param object The object + * @param graph The containing graph + */ + function quad( + subject: Node, + predicate: Node, + object: Node, + graph: Node + ): Statement; + /** + * Creates a new statement + * @param subject The subject + * @param predicate The predicate + * @param object The object + * @param graph The containing graph + */ + function st( + subject: Node, + predicate: Node, + object: Node, + graph: Node + ): Statement; + /** + * Creates a new statement + * @param subject The subject + * @param predicate The predicate + * @param object The object + */ + function triple(subject: Node, predicate: Node, object: Node): Statement; + /** + * Creates a new variable + * @param name The name for the variable + */ + function variable(name?: string): Variable; +} +export namespace Util { + /** + * Gets a named node for a media type + * @param mediaType A media type + */ + function mediaTypeClass(mediaType: string): NamedNode; + /** + * Gets a named node from the name of a relation + * @param relation The name of a relation + */ + function linkRelationProperty(relation: string): NamedNode; + /** + * Loads ontologies of the data we load (this is the callback from the kb to + * the fetcher). Exports as `AJAR_handleNewTerm` + * @param kb The store + * @param p A property + * @param requestedBy + */ + function AJAR_handleNewTerm( + kb: Formula, + p: NamedNode, + requestedBy: string + ): Promise; +} +/** +* A datatype-specific handler for fetching data +*/ +export interface Handler { + response: any; + dom: any; +} +export interface FetchOptions { + fetch?: typeof fetch; + /** + * The resource which referred to this (for tracking bad links). + */ + referringTerm?: NamedNode; + /** + * Provided content type (for writes). + */ + contentType?: string; + /** + * Override the incoming header to force the data to be treated as this content-type (for reads). + */ + forceContentType?: string; + /** + * Load the data even if loaded before. Also sets the `Cache-Control:` header to `no-cache`. + */ + force?: boolean; + /** + * Original uri to preserve through proxying etc (`xhr.original`). + */ + baseUri?: Node | string; + /** + * Whether this request is a retry via a proxy (generally done from an error handler). + */ + proxyUsed?: boolean; + /** + * Flag for XHR/CORS etc + */ + withCredentials?: boolean; + /** + * Before we parse new data, clear old, but only on status 200 responses. + */ + clearPreviousData?: boolean; + /** + * Prevents the addition of various metadata triples (about the fetch request) to the store. + */ + noMeta?: boolean; + noRDFa?: boolean; +} +/** +* Responsible for fetching RDF data +*/ +export class Fetcher { + store: any; + timeout: number; + appNode: BlankNode; + requested: { + [uri: string]: any; + }; + timeouts: any; + redirectedTo: any; + constructor(store: any, options: any); + static HANDLERS: { + RDFXMLHandler: Handler; + XHTMLHandler: Handler; + XMLHandler: Handler; + HTMLHandler: Handler; + TextHandler: Handler; + N3Handler: Handler; + }; + static CONTENT_TYPE_BY_EXT: { + [ext: string]: string; + }; + /** + * Loads a web resource or resources into the store. + * @param uri Resource to load, provided either as a NamedNode object or a plain URL. If multiple resources are passed as an array, they will be fetched in parallel. + */ + load: (uri: ReadonlyArray | ReadonlyArray | NamedNode | string, options?: FetchOptions) => Promise; +} +/** +* Gets a node for the specified input +* @param value An input value +*/ +export function term(value: ValueType): Node | Collection | ValueType; +/** +* Gets a namespace +* @param nsuri The URI for the namespace +*/ +export function Namespace(nsuri: string): (ln: string) => NamedNode; +/** +* Transforms an NTriples string format into a Node. +* The bnode bit should not be used on program-external values; designed +* for internal work such as storing a bnode id in an HTML attribute. +* This will only parse the strings generated by the vaious toNT() methods. +* @param str A string representation +*/ +export function fromNT(str: string): Node; +/** +* Creates a new fetcher +* @param store The store to use +* @param options The options +*/ +export function fetcher(store: Formula, options: any): Fetcher; +/** +* Creates a new graph (store) +*/ +export function graph(): IndexedFormula; +/** +* Creates a new literal node +* @param val The lexical value +* @param lang The language +* @param dt The datatype +*/ +export function lit(val: string, lang: string, dt: NamedNode): Literal; +/** +* Creates a new statement +* @param subject The subject +* @param predicate The predicate +* @param object The object +* @param graph The containing graph +*/ +export function st( + subject: Node | Date | string, + predicate: Node, + object: Node | Date | string, + graph: Node +): Statement; +/** +* Creates a new named node +* @param value The new named node +*/ +export function sym(value: string): NamedNode; +/** +* Creates a new variable +* @param name The name for the variable +*/ +export function variable(name: string): Variable; +/** +* Creates a new blank node +* @param value The blank node's identifier +*/ +export function blankNode(value: string): BlankNode; +/** +* Gets the default graph +*/ +export function defaultGraph(): DefaultGraph; +/** +* Creates a new literal node +* @param value The lexical value +* @param languageOrDatatype Either the language or the datatype +*/ +export function literal( + value: string, + languageOrDatatype: string | NamedNode +): Literal; +/** +* Creates a new named node +* @param value The new named node +*/ +export function namedNode(value: string): NamedNode; +/** +* Creates a new statement +* @param subject The subject +* @param predicate The predicate +* @param object The object +* @param graph The containing graph +*/ +export function quad( + subject: Node, + predicate: Node, + object: Node, + graph: Node +): Statement; +/** +* Creates a new statement +* @param subject The subject +* @param predicate The predicate +* @param object The object +*/ +export function triple(subject: Node, predicate: Node, object: Node): Statement; +/** +* Parse a string and put the result into the graph kb. +* Normal method is sync. +* Unfortunately jsdonld is currently written to need to be called async. +* Hence the mess below with executeCallback. +* @param str The input string to parse +* @param kb The store to use +* @param base The base URI to use +* @param contentType The content type for the input +* @param callback The callback to call when the data has been loaded +*/ +export function parse( + str: string, + kb: Formula, + base: string, + contentType: string, + callback: (error: any, kb: Formula) => void +): void; +/** +* Get the next available unique identifier +*/ +export let NextId: number; + +/** +* The update manager is a helper object for a store. +* Just as a Fetcher provides the store with the ability to read and write, the Update Manager provides functionality for making small patches in real time, +* and also looking out for concurrent updates from other agents. +*/ +export class UpdateManager { + /** + * @param store The quadstore to store data and metadata. Created if not passed. + */ + constructor(store?: IndexedFormula) + + /** + * This is suitable for an initial creation of a document. + * @param document + * @param data + * @param contentType + * @param callback + */ + put( + document: Node, + data: string | ReadonlyArray, + contentType: string, + callback: (uri: string, ok: boolean, errorMessage: string, response?: unknown) => void, + ): Promise; + + /** + * This high-level function updates the local store iff the web is changed successfully. + * Deletions, insertions may be undefined or single statements or lists or formulae (may contain bnodes which can be indirectly identified by a where clause). + * The `why` property of each statement must be the same and give the web document to be updated. + * @param statementsToDelete Statement or statements to be deleted. + * @param statementsToAdd Statement or statements to be inserted. + * @param callback + */ + update( + statementsToDelete: ReadonlyArray, + statementsToAdd: ReadonlyArray, + callback: (uri: string | undefined, success: boolean, errorBody?: string) => void + ): void; diff --git a/webpack.config.js b/webpack.config.js index 5198dab44..5d76939a2 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -26,6 +26,7 @@ module.exports = (env, args) => { } ] }, + resolve: { extensions: ['.js', '.ts'] }, plugins: [ new WrapperPlugin({ // Fall back to window.fetch when solid-auth-client is not present,