eyeling 1.5.8 → 1.5.11

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.
Files changed (3) hide show
  1. package/README.md +48 -0
  2. package/index.js +61 -0
  3. package/package.json +9 -1
package/README.md CHANGED
@@ -34,6 +34,53 @@ This link preloads a small “Socrates is Mortal” ruleset:
34
34
 
35
35
  - A reasonably recent Node.js (anything modern with `BigInt` support is fine).
36
36
 
37
+ ```md
38
+ ## Install (npm)
39
+
40
+ ```bash
41
+ npm i eyeling
42
+ ```
43
+
44
+ ## CLI (npm)
45
+
46
+ Run on a file:
47
+
48
+ ```bash
49
+ npx eyeling examples/socrates.n3
50
+ ```
51
+
52
+ (Or install globally: `npm i -g eyeling` and run `eyeling ...`.)
53
+
54
+ ## JavaScript API (Node)
55
+
56
+ ```js
57
+ const { reason } = require('eyeling');
58
+
59
+ const input = `
60
+ @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
61
+ @prefix : <http://example.org/socrates#>.
62
+
63
+ :Socrates a :Human.
64
+ :Human rdfs:subClassOf :Mortal.
65
+
66
+ { ?S a ?A. ?A rdfs:subClassOf ?B } => { ?S a ?B }.
67
+ `;
68
+
69
+ const output = reason({ proofComments: false }, input);
70
+ console.log(output);
71
+ ```
72
+
73
+ ESM:
74
+
75
+ ```js
76
+ import eyeling from 'eyeling';
77
+
78
+ const output = eyeling.reason({ proofComments: false }, input);
79
+ console.log(output);
80
+ ```
81
+
82
+ Note: the API currently shells out to the bundled `eyeling.js` CLI under the hood (simple + robust).
83
+
37
84
  ### Run a single file
38
85
 
39
86
  From the repo root:
@@ -186,3 +233,4 @@ As soon as the premise is provable, `eyeling` exits with status code `2`.
186
233
  ## License
187
234
 
188
235
  MIT (see [LICENSE](https://github.com/eyereasoner/eyeling/blob/main/LICENSE.md)).
236
+
package/index.js ADDED
@@ -0,0 +1,61 @@
1
+ 'use strict';
2
+
3
+ const fs = require('node:fs');
4
+ const os = require('node:os');
5
+ const path = require('node:path');
6
+ const cp = require('node:child_process');
7
+
8
+ function reason(opt = {}, n3_input = '') {
9
+ if (n3_input == null) n3_input = '';
10
+ if (typeof n3_input !== 'string') {
11
+ throw new TypeError('reason(opt, n3_input): n3_input must be a string');
12
+ }
13
+
14
+ // allow passing an args array directly
15
+ if (Array.isArray(opt)) opt = { args: opt };
16
+
17
+ const args = [];
18
+
19
+ // default: proof comments OFF for API output (machine-friendly)
20
+ // set { proofComments: true } to keep them
21
+ const proofComments =
22
+ (typeof opt.proofComments === 'boolean') ? opt.proofComments :
23
+ (typeof opt.noProofComments === 'boolean') ? !opt.noProofComments :
24
+ false;
25
+
26
+ if (!proofComments) args.push('--no-proof-comments'); // CLI already supports this :contentReference[oaicite:1]{index=1}
27
+
28
+ if (Array.isArray(opt.args)) args.push(...opt.args);
29
+
30
+ const maxBuffer = Number.isFinite(opt.maxBuffer) ? opt.maxBuffer : 50 * 1024 * 1024;
31
+
32
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'eyeling-'));
33
+ const inputFile = path.join(dir, 'input.n3');
34
+
35
+ try {
36
+ fs.writeFileSync(inputFile, n3_input, 'utf8');
37
+
38
+ const eyelingPath = path.join(__dirname, 'eyeling.js');
39
+ const res = cp.spawnSync(process.execPath, [eyelingPath, ...args, inputFile], {
40
+ encoding: 'utf8',
41
+ maxBuffer,
42
+ });
43
+
44
+ if (res.error) throw res.error;
45
+ if (res.status !== 0) {
46
+ const err = new Error(res.stderr || `eyeling exited with code ${res.status}`);
47
+ err.code = res.status;
48
+ err.stdout = res.stdout;
49
+ err.stderr = res.stderr;
50
+ throw err;
51
+ }
52
+ return res.stdout;
53
+ } finally {
54
+ fs.rmSync(dir, { recursive: true, force: true });
55
+ }
56
+ }
57
+
58
+ module.exports = { reason };
59
+ // small interop nicety for ESM default import
60
+ module.exports.default = module.exports;
61
+
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "eyeling",
3
- "version": "1.5.8",
3
+ "version": "1.5.11",
4
4
  "description": "A minimal Notation3 (N3) reasoner in JavaScript.",
5
+ "main": "./index.js",
5
6
  "keywords": [
6
7
  "N3",
7
8
  "reasoner"
@@ -17,11 +18,18 @@
17
18
  "eyeling": "./eyeling.js"
18
19
  },
19
20
  "files": [
21
+ "index.js",
20
22
  "eyeling.js",
21
23
  "README.md",
22
24
  "LICENSE.md"
23
25
  ],
24
26
  "engines": {
25
27
  "node": ">=18"
28
+ },
29
+ "dependencies": {
30
+ "eyeling": "^1.5.10"
31
+ },
32
+ "scripts": {
33
+ "test": "node test/api.test.js"
26
34
  }
27
35
  }