eyeling 1.19.6 → 1.21.0

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/HANDBOOK.md CHANGED
@@ -54,7 +54,7 @@ That last point is the heart of Eyeling’s design: _forward rules are executed
54
54
 
55
55
  Eyeling deliberately keeps the implementation small and dependency-free:
56
56
 
57
- - the published package includes a single bundled file (`eyeling.js`)
57
+ - the published package includes a Node-oriented bundle (`eyeling.js`) and a dedicated browser bundle (`dist/browser/eyeling.browser.js`)
58
58
  - the source is organized into `lib/*` modules that read like a miniature compiler + logic engine.
59
59
 
60
60
  This handbook is a tour of that miniature system.
@@ -1757,7 +1757,9 @@ The same API can now also emit RDF/JS output. When `rdfjs: true` is passed, ever
1757
1757
  - `triple` — Eyeling’s N3 string form
1758
1758
  - `quad` — the same fact as an RDF/JS default-graph quad
1759
1759
 
1760
- For fully stream-oriented RDF/JS consumers there is also `reasonRdfJs(...)`, which exposes the derived facts as an async iterable of RDF/JS quads.
1760
+ If your closure may contain N3-only terms such as quoted formulas (`GraphTerm`), RDF/JS conversion can fail because those terms have no standard RDF/JS representation. In that case, pass `skipUnsupportedRdfJs: true` to keep the full N3 closure while silently omitting any derived triples that cannot be represented as RDF/JS quads. When this flag is enabled, `onDerived(...)` still fires for every derived fact, but `quad` is only present for the representable ones.
1761
+
1762
+ For fully stream-oriented RDF/JS consumers there is also `reasonRdfJs(...)`, which exposes the derived facts as an async iterable of RDF/JS quads. The same `skipUnsupportedRdfJs: true` flag applies there as well.
1761
1763
 
1762
1764
  ---
1763
1765
 
@@ -1805,7 +1807,7 @@ Custom builtins can be loaded explicitly from the CLI:
1805
1807
  npx eyeling --builtin lib/builtin-sudoku.js examples/sudoku.n3
1806
1808
  ```
1807
1809
 
1808
- ### 14.2 The bundled CLI (`eyeling.js`)
1810
+ ### 14.2 The bundled Node CLI/runtime (`eyeling.js`)
1809
1811
 
1810
1812
  The bundle contains the whole engine. The CLI path is the “canonical behavior”:
1811
1813
 
@@ -1831,6 +1833,42 @@ The current CLI supports a small set of flags (see `lib/cli.js`):
1831
1833
  - With no positional argument, Eyeling reads from stdin when input is piped.
1832
1834
  - Use `-` as the input path to read explicitly from stdin.
1833
1835
 
1836
+ ### 14.3 Package entrypoint split for Node, browser, and CLI
1837
+
1838
+ The repo now publishes three distinct surfaces instead of forcing browser tooling through the Node-first bundle entry:
1839
+
1840
+ - `index.js` remains the **Node API** used by `require('eyeling')` and `import eyeling from 'eyeling'` in Node.
1841
+ - `bin/eyeling.cjs` is the **CLI shim** with the shebang. It loads the Node bundle and calls `main()`.
1842
+ - `dist/browser/eyeling.browser.js` is the **browser-safe bundle asset** with **no shebang**.
1843
+ - `dist/browser/index.mjs` is the **browser import surface** exported as `eyeling/browser`.
1844
+
1845
+ That gives the intended mental model:
1846
+
1847
+ ```js
1848
+ import eyeling from 'eyeling'; // Node
1849
+ import eyelingBrowser from 'eyeling/browser'; // Browser / worker
1850
+ ```
1851
+
1852
+ ```bash
1853
+ npx eyeling … # CLI
1854
+ ```
1855
+
1856
+ The `package.json` `exports` map points the `browser` condition at `dist/browser/index.mjs`, so browser-oriented bundlers stop resolving the package root to the Node wrapper in `index.js`.
1857
+
1858
+ `dist/browser/index.mjs` intentionally re-exports only the browser-safe surface:
1859
+
1860
+ - `reasonStream(...)`
1861
+ - `reasonRdfJs(...)`
1862
+ - `rdfjs`
1863
+ - `registerBuiltin(...)`
1864
+ - `unregisterBuiltin(...)`
1865
+ - `registerBuiltinModule(...)`
1866
+ - `listBuiltinIris()`
1867
+
1868
+ It deliberately does **not** expose `loadBuiltinModule(...)`, because loading builtin files by module specifier is a Node-only pattern. In browsers, custom builtins should be registered directly in-process (for example with `registerBuiltin(...)` or `registerBuiltinModule(...)`).
1869
+
1870
+ For browser apps, prefer running Eyeling in a **Web Worker** and importing `eyeling/browser` there.
1871
+
1834
1872
  ### 14.3 `lib/entry.js`: bundler-friendly exports
1835
1873
 
1836
1874
  `lib/entry.js` exports:
@@ -1845,7 +1883,7 @@ The current CLI supports a small set of flags (see `lib/cli.js`):
1845
1883
  Eyeling exposes two JavaScript entry styles:
1846
1884
 
1847
1885
  - `reason(...)` from `index.js` when you want the same text output as the CLI
1848
- - `reasonStream(...)` / `reasonRdfJs(...)` from the bundle entry when you want in-process reasoning and structured RDF/JS results
1886
+ - `reasonStream(...)` / `reasonRdfJs(...)` from the Node bundle or `eyeling/browser` when you want in-process reasoning and structured RDF/JS results
1849
1887
 
1850
1888
  #### 14.4.1 npm helper: `reason(...)`
1851
1889
 
@@ -1966,8 +2004,11 @@ import eyeling from './eyeling.js';
1966
2004
 
1967
2005
  const result = eyeling.reasonStream(input, {
1968
2006
  proof: false,
1969
- onDerived: ({ quad }) => {
2007
+ rdfjs: true,
2008
+ skipUnsupportedRdfJs: true,
2009
+ onDerived: ({ triple, quad }) => {
1970
2010
  if (quad) console.log(quad);
2011
+ else console.warn('Skipped non-RDF/JS derived triple:', triple);
1971
2012
  },
1972
2013
  });
1973
2014
  ```
@@ -1975,11 +2016,15 @@ const result = eyeling.reasonStream(input, {
1975
2016
  That same path also lets derived results be consumed as an async stream of RDF/JS quads:
1976
2017
 
1977
2018
  ```js
1978
- for await (const quad of eyeling.reasonRdfJs(input)) {
2019
+ for await (const quad of eyeling.reasonRdfJs(input, {
2020
+ skipUnsupportedRdfJs: true,
2021
+ })) {
1979
2022
  console.log(quad);
1980
2023
  }
1981
2024
  ```
1982
2025
 
2026
+ Use `skipUnsupportedRdfJs: true` when you want RDF/JS consumers to ignore derived triples that contain N3-only terms such as quoted formulas. This affects only RDF/JS export. The underlying Eyeling closure and `closureN3` output remain unchanged.
2027
+
1983
2028
  Use these entry points when you need one or more of the following:
1984
2029
 
1985
2030
  - RDF/JS quads as fact input
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const bundle = require('../eyeling.js');
5
+
6
+ if (!bundle || typeof bundle.main !== 'function') {
7
+ throw new Error('Eyeling CLI bundle did not expose main()');
8
+ }
9
+
10
+ bundle.main();