eyereasoner 2.15.0 → 3.0.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/dist/index.d.ts CHANGED
@@ -1,44 +1,6 @@
1
1
  /// <reference types="emscripten" />
2
- import { Quad } from '@rdfjs/types';
3
2
  import type { SWIPLModule } from 'swipl-wasm/dist/common';
4
- import { IQueryOptions } from './transformers';
5
3
  export * from './query';
6
4
  export * from './transformers';
7
5
  export declare const SWIPL: (options?: Partial<EmscriptenModule>) => Promise<SWIPLModule>;
8
6
  export { default as EYE_PVM } from './eye';
9
- /**
10
- * Executes a basic query using the EYE Reasoner and default build of SWIPL
11
- * @param data The data for the query as RDF/JS quads
12
- * @param query The query as RDF/JS quads
13
- * @param options The reasoner options
14
- * - output: What to output with implicit queries (default: undefined)
15
- * - blogic: Whether to use blogic (default: false)
16
- * - outputType: The type of output, either 'string' or 'quads' (default: type of input data)
17
- * @returns The result of the query as RDF/JS quads
18
- */
19
- export declare function n3reasoner(data: Quad[] | string, query: Quad[] | string | undefined, options: ({
20
- outputType: 'string';
21
- } & IQueryOptions)): Promise<string>;
22
- export declare function n3reasoner(data: Quad[] | string, query: Quad[] | string | undefined, options: ({
23
- outputType: 'quads';
24
- } & IQueryOptions)): Promise<Quad[]>;
25
- export declare function n3reasoner(data: Quad[], query: Quad[] | string | undefined, options?: ({
26
- outputType?: undefined;
27
- } & IQueryOptions)): Promise<Quad[]>;
28
- export declare function n3reasoner(data: string, query: Quad[] | string | undefined, options?: ({
29
- outputType?: undefined;
30
- } & IQueryOptions)): Promise<string>;
31
- export declare function n3reasoner(data: Quad[] | string, query?: Quad[] | string | undefined, options?: IQueryOptions): Promise<Quad[] | string>;
32
- export declare function basicQuery(data: Quad[] | string, query: Quad[] | string | undefined, options: ({
33
- outputType: 'string';
34
- } & IQueryOptions)): Promise<string>;
35
- export declare function basicQuery(data: Quad[] | string, query: Quad[] | string | undefined, options: ({
36
- outputType: 'quads';
37
- } & IQueryOptions)): Promise<Quad[]>;
38
- export declare function basicQuery(data: Quad[], query: Quad[] | string | undefined, options?: ({
39
- outputType?: undefined;
40
- } & IQueryOptions)): Promise<Quad[]>;
41
- export declare function basicQuery(data: string, query: Quad[] | string | undefined, options?: ({
42
- outputType?: undefined;
43
- } & IQueryOptions)): Promise<string>;
44
- export declare function basicQuery(data: Quad[] | string, query?: Quad[] | string | undefined, options?: IQueryOptions): Promise<Quad[] | string>;
package/dist/index.js CHANGED
@@ -18,21 +18,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
18
18
  return (mod && mod.__esModule) ? mod : { "default": mod };
19
19
  };
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.basicQuery = exports.n3reasoner = exports.EYE_PVM = exports.SWIPL = void 0;
21
+ exports.EYE_PVM = exports.SWIPL = void 0;
22
22
  // @ts-ignore
23
23
  const swipl_bundled_temp_1 = __importDefault(require("./swipl-bundled.temp"));
24
- const transformers_1 = require("./transformers");
25
24
  __exportStar(require("./query"), exports);
26
25
  __exportStar(require("./transformers"), exports);
27
26
  // eslint-disable-next-line no-unused-vars
28
27
  exports.SWIPL = swipl_bundled_temp_1.default;
29
28
  var eye_1 = require("./eye");
30
29
  Object.defineProperty(exports, "EYE_PVM", { enumerable: true, get: function () { return __importDefault(eye_1).default; } });
31
- function n3reasoner(data, query, options) {
32
- return (0, transformers_1.executeBasicEyeQuery)(swipl_bundled_temp_1.default, data, query, options);
33
- }
34
- exports.n3reasoner = n3reasoner;
35
- function basicQuery(data, query, options = {}) {
36
- return n3reasoner(data, query, { output: query ? undefined : 'deductive_closure', ...options });
37
- }
38
- exports.basicQuery = basicQuery;
package/dist/query.js CHANGED
@@ -9,7 +9,9 @@ exports.queryOnce = exports.query = void 0;
9
9
  * @returns The result of the query
10
10
  */
11
11
  function query(Module, name, args) {
12
- const queryString = `${name}(${typeof args === 'string'
12
+ const queryString = `${name}(${
13
+ /* istanbul ignore next */
14
+ typeof args === 'string'
13
15
  ? `"${args}"`
14
16
  : `[${args.map((arg) => `'${arg}'`).join(', ')}]`}).`;
15
17
  return Module.prolog.query(queryString);
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.strToBuffer = void 0;
4
4
  /* eslint-disable no-param-reassign,no-plusplus,no-bitwise,no-use-before-define,no-multi-assign */
5
+ /* istanbul ignore file */
5
6
  /**
6
7
  * A function that converts a string into a buffer.
7
8
  * This is required *only* for the conversion of the inlined
@@ -1 +1,3 @@
1
- declare var SWIPL: (SWIPL: any) => any;
1
+ import SWIPL = require('swipl-wasm/dist/common');
2
+
3
+ export = SWIPL;
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ /* istanbul ignore file */
2
3
  // This file is temporary until https://github.com/rla/npm-swipl-wasm/pull/8 is released.
3
4
  // @ts-nocheck
4
5
  var SWIPL = (() => {
@@ -85,10 +86,6 @@ var SWIPL = (() => {
85
86
  thisProgram = process["argv"][1].replace(/\\/g, "/");
86
87
  }
87
88
  arguments_ = process["argv"].slice(2);
88
- process["on"]("uncaughtException", function (ex) { if (!(ex instanceof ExitStatus)) {
89
- throw ex;
90
- } });
91
- process["on"]("unhandledRejection", function (reason) { throw reason; });
92
89
  quit_ = (status, toThrow) => { if (keepRuntimeAlive()) {
93
90
  process["exitCode"] = status;
94
91
  throw toThrow;
@@ -2,11 +2,17 @@
2
2
  import type { SWIPLModule } from 'swipl-wasm/dist/swipl/swipl';
3
3
  import { Quad } from '@rdfjs/types';
4
4
  import type SWIPL_TYPE from 'swipl-wasm/dist/common';
5
- export interface IQueryOptions {
6
- blogic?: boolean;
5
+ export type ICoreQueryOptions = {
6
+ blogic: true;
7
+ output?: undefined;
8
+ } | {
9
+ blogic?: false;
10
+ output?: 'derivations' | 'deductive_closure' | 'deductive_closure_plus_rules' | 'grounded_deductive_closure_plus_rules';
11
+ };
12
+ export type Options = ICoreQueryOptions & {
7
13
  outputType?: 'string' | 'quads';
8
- output?: undefined | 'derivations' | 'deductive_closure' | 'deductive_closure_plus_rules' | 'grounded_deductive_closure_plus_rules';
9
- }
14
+ SWIPL?: typeof SWIPL_TYPE;
15
+ };
10
16
  export declare function loadEyeImage(swipl: typeof SWIPL_TYPE): (options?: Partial<EmscriptenModule> | undefined) => Promise<SWIPLModule>;
11
17
  /**
12
18
  * Creates default SWIPL image loaded with EYE
@@ -22,40 +28,54 @@ export declare function SwiplEye(options?: Partial<EmscriptenModule> | undefined
22
28
  * - blogic: Whether to use blogic (default: false)
23
29
  * @returns The same SWIPL module
24
30
  */
25
- export declare function runQuery(Module: SWIPLModule, data: string, queryString?: string, options?: IQueryOptions): SWIPLModule;
31
+ export declare function runQuery(Module: SWIPLModule, data: string, queryString?: string, { blogic, output }?: Options): SWIPLModule;
32
+ export type Data = Quad[] | string;
33
+ export type Query = Data | undefined;
26
34
  /**
27
- * @param swipl The base SWIPL module to use
28
- * @param data The data for the query (in N3 format)
29
- * @param query The query (in N3 format)
35
+ * Executes a basic query using the EYE Reasoner and default build of SWIPL
36
+ * @param data The data for the query as RDF/JS quads
37
+ * @param query The query as RDF/JS quads
30
38
  * @param options The reasoner options
31
39
  * - output: What to output with implicit queries (default: undefined)
32
40
  * - blogic: Whether to use blogic (default: false)
33
- * - outputType: The type of output, either 'string' or 'quads' (default: 'string')
34
- * @returns The result of the query
41
+ * - outputType: The type of output, either 'string' or 'quads' (default: type of input data)
42
+ * - SWIPL: The SWIPL module to use (default: bundled SWIPL)
43
+ * @returns The result of the query as RDF/JS quads
35
44
  */
36
- export declare function executeBasicEyeQuery(swipl: typeof SWIPL_TYPE, data: Quad[] | string, query: Quad[] | string | undefined, options: {
45
+ export declare function executeBasicEyeQuery(swipl: typeof SWIPL_TYPE, data: Data, query: Query, options: {
37
46
  outputType: 'string';
38
- } & IQueryOptions): Promise<string>;
39
- export declare function executeBasicEyeQuery(swipl: typeof SWIPL_TYPE, data: Quad[] | string, query: Quad[] | string | undefined, options: {
47
+ } & Options): Promise<string>;
48
+ export declare function executeBasicEyeQuery(swipl: typeof SWIPL_TYPE, data: Data, query: Query, options: {
40
49
  outputType: 'quads';
41
- } & IQueryOptions): Promise<Quad[]>;
42
- export declare function executeBasicEyeQuery(swipl: typeof SWIPL_TYPE, data: Quad[], query?: Quad[] | string | undefined, options?: {
50
+ } & Options): Promise<Quad[]>;
51
+ export declare function executeBasicEyeQuery(swipl: typeof SWIPL_TYPE, data: Quad[], query?: Query, options?: {
43
52
  outputType?: undefined;
44
- } & IQueryOptions): Promise<Quad[]>;
45
- export declare function executeBasicEyeQuery(swipl: typeof SWIPL_TYPE, data: string, query?: Quad[] | string | undefined, options?: {
53
+ } & Options): Promise<Quad[]>;
54
+ export declare function executeBasicEyeQuery(swipl: typeof SWIPL_TYPE, data: string, query?: Query, options?: {
46
55
  outputType?: undefined;
47
- } & IQueryOptions): Promise<string>;
48
- export declare function executeBasicEyeQuery(swipl: typeof SWIPL_TYPE, data: Quad[] | string, query?: Quad[] | string | undefined, options?: IQueryOptions): Promise<Quad[] | string>;
56
+ } & Options): Promise<string>;
57
+ export declare function executeBasicEyeQuery(swipl: typeof SWIPL_TYPE, data: Data, query?: Query, options?: Options): Promise<Quad[] | string>;
49
58
  /**
50
- * @deprecated Use executeBasicEyeQuery instead
51
- *
59
+ * Executes a basic query using the EYE Reasoner and default build of SWIPL
52
60
  * @param swipl The base SWIPL module to use
53
- * @param data The data for the query (in N3 format)
54
- * @param query The query (in N3 format)
61
+ * @param data The data for the query as RDF/JS quads
62
+ * @param query The query as RDF/JS quads
55
63
  * @param options The reasoner options
56
64
  * - output: What to output with implicit queries (default: undefined)
57
65
  * - blogic: Whether to use blogic (default: false)
58
- * - outputType: The type of output, either 'string' or 'quads' (default: 'quads')
59
- * @returns The result of the query
66
+ * - outputType: The type of output, either 'string' or 'quads' (default: type of input data)
67
+ * @returns The result of the query as RDF/JS quads
60
68
  */
61
- export declare function executeBasicEyeQueryQuads(swipl: typeof SWIPL_TYPE, data: Quad[] | string, query?: Quad[] | string | undefined, options?: Omit<IQueryOptions, 'outputType'>): Promise<Quad[]>;
69
+ export declare function n3reasoner(data: Data, query: Query, options: {
70
+ outputType: 'string';
71
+ } & Options): Promise<string>;
72
+ export declare function n3reasoner(data: Data, query: Query, options: {
73
+ outputType: 'quads';
74
+ } & Options): Promise<Quad[]>;
75
+ export declare function n3reasoner(data: Quad[], query?: Query, options?: {
76
+ outputType?: undefined;
77
+ } & Options): Promise<Quad[]>;
78
+ export declare function n3reasoner(data: string, query?: Query, options?: {
79
+ outputType?: undefined;
80
+ } & Options): Promise<string>;
81
+ export declare function n3reasoner(data: Data, query?: Query, options?: Options): Promise<Quad[] | string>;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.executeBasicEyeQueryQuads = exports.executeBasicEyeQuery = exports.runQuery = exports.SwiplEye = exports.loadEyeImage = void 0;
6
+ exports.n3reasoner = exports.executeBasicEyeQuery = exports.runQuery = exports.SwiplEye = exports.loadEyeImage = void 0;
7
7
  const n3_1 = require("n3");
8
8
  // @ts-ignore
9
9
  const swipl_bundled_temp_1 = __importDefault(require("./swipl-bundled.temp"));
@@ -37,58 +37,76 @@ exports.SwiplEye = SwiplEye;
37
37
  * - blogic: Whether to use blogic (default: false)
38
38
  * @returns The same SWIPL module
39
39
  */
40
- function runQuery(Module, data, queryString, options) {
41
- let pass;
42
- switch (options?.output) {
43
- case undefined:
44
- break;
45
- case 'derivations':
46
- pass = '--pass-only-new';
47
- break;
48
- case 'deductive_closure':
49
- pass = '--pass';
50
- break;
51
- case 'deductive_closure_plus_rules':
52
- pass = '--pass-all';
53
- break;
54
- case 'grounded_deductive_closure_plus_rules':
55
- pass = '--pass-all-ground';
56
- break;
57
- default:
58
- throw new Error(`Unknown output option: ${options?.output}`);
40
+ function runQuery(Module, data, queryString, { blogic, output } = {}) {
41
+ const args = ['--quiet', 'data.nq'];
42
+ if (blogic) {
43
+ if (output || queryString) {
44
+ throw new Error('Cannot use blogic with explicit output or query');
45
+ }
46
+ args.push('--blogic');
59
47
  }
60
- const blogic = options?.blogic;
61
- Module.FS.writeFile('data.nq', data);
62
- if (queryString && !blogic) {
63
- Module.FS.writeFile('query.nq', queryString);
48
+ else {
49
+ args.push('--nope');
50
+ if (queryString) {
51
+ if (output) {
52
+ throw new Error('Cannot use explicit output with explicit query');
53
+ }
54
+ Module.FS.writeFile('query.nq', queryString);
55
+ args.push('--query', './query.nq');
56
+ }
57
+ else {
58
+ switch (output) {
59
+ case undefined:
60
+ case 'derivations':
61
+ args.push('--pass-only-new');
62
+ break;
63
+ case 'deductive_closure':
64
+ args.push('--pass');
65
+ break;
66
+ case 'deductive_closure_plus_rules':
67
+ args.push('--pass-all');
68
+ break;
69
+ case 'grounded_deductive_closure_plus_rules':
70
+ args.push('--pass-all-ground');
71
+ break;
72
+ default:
73
+ throw new Error(`Unknown output option: ${output}`);
74
+ }
75
+ }
64
76
  }
65
- (0, query_1.queryOnce)(Module, 'main', [blogic ? '--blogic' : '--nope', '--quiet', ...(pass ? [pass] : []), 'data.nq', ...(queryString ? ['--query', './query.nq'] : [])]);
77
+ Module.FS.writeFile('data.nq', data);
78
+ (0, query_1.queryOnce)(Module, 'main', args);
66
79
  return Module;
67
80
  }
68
81
  exports.runQuery = runQuery;
82
+ function parse(res) {
83
+ const parser = new n3_1.Parser({ format: 'text/n3' });
84
+ // Workaround for https://github.com/rdfjs/N3.js/issues/324
85
+ // @ts-expect-error
86
+ // eslint-disable-next-line no-underscore-dangle
87
+ parser._supportsRDFStar = true;
88
+ return parser.parse(res);
89
+ }
69
90
  async function executeBasicEyeQuery(swipl, data, query, options) {
91
+ /* eslint-enable max-len */
70
92
  const outputType = options?.outputType;
71
93
  let res = '';
72
- const Module = await loadEyeImage(swipl)({ print: (str) => { res += `${str}\n`; } });
94
+ const err = [];
95
+ const Module = await loadEyeImage(swipl)({
96
+ print: (str) => { res += `${str}\n`; },
97
+ printErr: (str) => { err.push(str); },
98
+ });
73
99
  runQuery(Module, typeof data === 'string' ? data : (0, n3Writer_temp_1.write)(data), query && (typeof query === 'string' ? query : (0, n3Writer_temp_1.write)(query)), options);
100
+ if (err.length > 0) {
101
+ throw new Error(`Error while executing query: ${err.join('\n')}`);
102
+ }
74
103
  return (outputType === 'quads' || (typeof data !== 'string' && outputType !== 'string'))
75
- ? (new n3_1.Parser({ format: 'text/n3' })).parse(res)
104
+ ? parse(res)
76
105
  : res;
77
106
  }
78
107
  exports.executeBasicEyeQuery = executeBasicEyeQuery;
79
- /**
80
- * @deprecated Use executeBasicEyeQuery instead
81
- *
82
- * @param swipl The base SWIPL module to use
83
- * @param data The data for the query (in N3 format)
84
- * @param query The query (in N3 format)
85
- * @param options The reasoner options
86
- * - output: What to output with implicit queries (default: undefined)
87
- * - blogic: Whether to use blogic (default: false)
88
- * - outputType: The type of output, either 'string' or 'quads' (default: 'quads')
89
- * @returns The result of the query
90
- */
91
- async function executeBasicEyeQueryQuads(swipl, data, query, options) {
92
- return executeBasicEyeQuery(swipl, data, query, { ...options, outputType: 'quads' });
108
+ async function n3reasoner(data, query, options) {
109
+ /* eslint-enable max-len */
110
+ return executeBasicEyeQuery(options?.SWIPL || swipl_bundled_temp_1.default, data, query, options);
93
111
  }
94
- exports.executeBasicEyeQueryQuads = executeBasicEyeQueryQuads;
112
+ exports.n3reasoner = n3reasoner;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eyereasoner",
3
- "version": "2.15.0",
3
+ "version": "3.0.1",
4
4
  "description": "Distributing the [EYE](https://github.com/josd/eye) reasoner for browser and node using WebAssembly.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.js",
@@ -13,10 +13,15 @@
13
13
  "scripts": {
14
14
  "test:coverage": "npm test -- --coverage",
15
15
  "test:badges": "npm run test:coverage && jest-coverage-badges",
16
- "test": "jest",
17
- "lint": "eslint lib/** __tests__/** scripts/** --ext .ts",
16
+ "test:unit": "npm run bundle:webpack && jest",
17
+ "test:memory": "npm run test:memory:node && npm run test:memory:node:error && npm run test:memory:browser",
18
+ "test:memory:node": "node __tests_memory__/leakTest",
19
+ "test:memory:node:error": "node __tests_memory__/leakTestOnError",
20
+ "test:memory:browser": "npm run bundle:webpack && node __tests_memory__/browserLeakTest",
21
+ "test": "npm run test:unit && npm run test:memory",
22
+ "lint": "eslint lib/** __tests__/**.ts scripts/** --ext .ts",
18
23
  "lint:fix": "npm run lint -- --fix",
19
- "build": "npm run eye:prepare && tsc",
24
+ "build": "npm run eye:prepare && tsc && rm dist/swipl-bundled.temp.d.ts && cp ./lib/swipl-bundled.temp.d.ts ./dist/swipl-bundled.temp.d.ts",
20
25
  "bundle:webpack": "webpack --config webpack.config.js",
21
26
  "bundle:latest": "ts-node scripts/post-webpack",
22
27
  "semantic-release": "semantic-release",
@@ -52,8 +57,10 @@
52
57
  },
53
58
  "homepage": "https://github.com/eyereasoner/eye-js#readme",
54
59
  "devDependencies": {
60
+ "@memlab/api": "^1.0.20",
55
61
  "@qiwi/semantic-release-gh-pages-plugin": "^5.2.4",
56
62
  "@rollup/plugin-commonjs": "^24.0.1",
63
+ "@types/express": "^4.17.17",
57
64
  "@types/fs-extra": "^11.0.1",
58
65
  "@types/jest": "^29.4.0",
59
66
  "@types/n3": "^1.10.4",
@@ -63,11 +70,15 @@
63
70
  "eslint": "^8.34.0",
64
71
  "eslint-config-airbnb-base": "^15.0.0",
65
72
  "eslint-plugin-import": "^2.27.5",
73
+ "express": "^4.18.2",
74
+ "express-rate-limit": "^6.7.0",
66
75
  "fs-extra": "^11.1.0",
67
76
  "jest": "^29.4.2",
68
77
  "jest-environment-jsdom": "^29.4.2",
78
+ "jest-mock-console": "^2.0.0",
69
79
  "jest-rdf": "^1.8.0",
70
80
  "parse-url": "^8.1.0",
81
+ "playwright": "^1.30.0",
71
82
  "pre-commit": "^1.2.2",
72
83
  "semantic-release": "^20.1.0",
73
84
  "ts-jest": "^29.0.5",
@@ -82,7 +93,7 @@
82
93
  "pre-commit": [
83
94
  "lint",
84
95
  "build",
85
- "test"
96
+ "test:unit"
86
97
  ],
87
98
  "release": {
88
99
  "branches": [
@@ -122,8 +133,8 @@
122
133
  },
123
134
  "config": {
124
135
  "eye": {
125
- "name": "v2.12.0",
126
- "url": "https://api.github.com/repos/eyereasoner/eye/releases/92625267"
136
+ "name": "v2.12.2",
137
+ "url": "https://api.github.com/repos/eyereasoner/eye/releases/92865042"
127
138
  }
128
139
  },
129
140
  "dependencies": {