@unrdf/knowledge-engine 5.0.1 → 26.4.2
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/package.json +23 -17
- package/src/ai-enhanced-search.mjs +371 -0
- package/src/anomaly-detector.mjs +226 -0
- package/src/artifact-generator.mjs +252 -0
- package/src/browser.mjs +1 -1
- package/src/chatman/disruption-arithmetic.mjs +140 -0
- package/src/chatman/market-dynamics.mjs +140 -0
- package/src/chatman/organizational-dynamics.mjs +140 -0
- package/src/chatman/strategic-dynamics.mjs +140 -0
- package/src/chatman-config-loader.mjs +282 -0
- package/src/chatman-engine.mjs +435 -0
- package/src/chatman-operator.mjs +343 -0
- package/src/dark-field-detector.mjs +332 -0
- package/src/formation-theorems.mjs +345 -0
- package/src/index.mjs +20 -2
- package/src/knowledge-hook-manager.mjs +1 -1
- package/src/lockchain-writer-browser.mjs +2 -2
- package/src/observability.mjs +40 -4
- package/src/query-optimizer.mjs +1 -1
- package/src/resolution-layer.mjs +1 -1
- package/src/transaction.mjs +11 -9
- package/README.md +0 -84
- package/src/browser-shims.mjs +0 -343
- package/src/canonicalize.mjs +0 -414
- package/src/condition-cache.mjs +0 -109
- package/src/condition-evaluator.mjs +0 -722
- package/src/dark-matter-core.mjs +0 -742
- package/src/define-hook.mjs +0 -213
- package/src/effect-sandbox-browser.mjs +0 -283
- package/src/effect-sandbox-worker.mjs +0 -170
- package/src/effect-sandbox.mjs +0 -517
- package/src/engines/index.mjs +0 -11
- package/src/engines/rdf-engine.mjs +0 -299
- package/src/file-resolver.mjs +0 -387
- package/src/hook-executor-batching.mjs +0 -277
- package/src/hook-executor.mjs +0 -870
- package/src/hook-management.mjs +0 -150
- package/src/ken-parliment.mjs +0 -119
- package/src/ken.mjs +0 -149
- package/src/knowledge-engine/builtin-rules.mjs +0 -190
- package/src/knowledge-engine/inference-engine.mjs +0 -418
- package/src/knowledge-engine/knowledge-engine.mjs +0 -317
- package/src/knowledge-engine/pattern-dsl.mjs +0 -142
- package/src/knowledge-engine/pattern-matcher.mjs +0 -215
- package/src/knowledge-engine/rules.mjs +0 -184
- package/src/knowledge-engine.mjs +0 -319
- package/src/knowledge-hook-engine.mjs +0 -360
- package/src/knowledge-substrate-core.mjs +0 -927
- package/src/lite.mjs +0 -222
- package/src/lockchain-writer.mjs +0 -602
- package/src/monitoring/andon-signals.mjs +0 -775
- package/src/parse.mjs +0 -290
- package/src/performance-optimizer.mjs +0 -678
- package/src/policy-pack.mjs +0 -572
- package/src/query-cache.mjs +0 -116
- package/src/query.mjs +0 -306
- package/src/reason.mjs +0 -350
- package/src/schemas.mjs +0 -1063
- package/src/security/error-sanitizer.mjs +0 -257
- package/src/security/path-validator.mjs +0 -194
- package/src/security/sandbox-restrictions.mjs +0 -331
- package/src/security-validator.mjs +0 -389
- package/src/store-cache.mjs +0 -137
- package/src/telemetry.mjs +0 -167
- package/src/utils/adaptive-monitor.mjs +0 -746
- package/src/utils/circuit-breaker.mjs +0 -513
- package/src/utils/edge-case-handler.mjs +0 -503
- package/src/utils/memory-manager.mjs +0 -498
- package/src/utils/ring-buffer.mjs +0 -282
- package/src/validate.mjs +0 -319
- package/src/validators/index.mjs +0 -338
package/src/lite.mjs
DELETED
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file knowledge-engine/lite.mjs
|
|
3
|
-
* @description Minimal RDF functionality entry point for bundle size optimization
|
|
4
|
-
*
|
|
5
|
-
* This lite bundle exports ONLY the core RDF primitives from n3:
|
|
6
|
-
* - Store: In-memory quad storage
|
|
7
|
-
* - Parser: Turtle/N-Triples/N-Quads parsing
|
|
8
|
-
* - Writer: RDF serialization
|
|
9
|
-
* - DataFactory: RDF term creation
|
|
10
|
-
*
|
|
11
|
-
* EXCLUDES (for 60%+ bundle reduction):
|
|
12
|
-
* - @comunica/query-sparql (~2.5MB)
|
|
13
|
-
* - isolated-vm (~5MB native bindings)
|
|
14
|
-
* - testcontainers (dev-only)
|
|
15
|
-
* - eyereasoner
|
|
16
|
-
* - rdf-validate-shacl
|
|
17
|
-
* - All hook/policy infrastructure
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* // Minimal import for basic RDF operations
|
|
21
|
-
* import { Store, Parser, Writer, DataFactory, parseTurtle, toTurtle } from 'unrdf/knowledge-engine/lite';
|
|
22
|
-
*
|
|
23
|
-
* const store = createStore();
|
|
24
|
-
* const { namedNode, literal, quad } = DataFactory;
|
|
25
|
-
*
|
|
26
|
-
* store.addQuad(quad(
|
|
27
|
-
* namedNode('http://example.org/alice'),
|
|
28
|
-
* namedNode('http://xmlns.com/foaf/0.1/name'),
|
|
29
|
-
* literal('Alice')
|
|
30
|
-
* ));
|
|
31
|
-
*
|
|
32
|
-
* @module knowledge-engine/lite
|
|
33
|
-
* @see {@link https://github.com/rdfjs/N3.js} for N3.js documentation
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* JUSTIFIED N3 USAGE (μ(O) Compliance):
|
|
38
|
-
* This lite.mjs module is a justified boundary for N3 exports because:
|
|
39
|
-
* 1. It provides streaming parsing with backpressure control (N3.Parser)
|
|
40
|
-
* 2. It's explicitly designed for lightweight RDF operations without Oxigraph
|
|
41
|
-
* 3. Users opting into lite.mjs accept N3-based implementation
|
|
42
|
-
*
|
|
43
|
-
* For full Oxigraph-based functionality, use the main knowledge-engine exports.
|
|
44
|
-
*/
|
|
45
|
-
|
|
46
|
-
// Core N3 exports - the essential RDF primitives
|
|
47
|
-
export { Parser, Writer, UnrdfDataFactory as DataFactory } from '@unrdf/core/rdf/n3-justified-only';
|
|
48
|
-
import { createStore as _createStore } from '@unrdf/oxigraph'; // Oxigraph Store implementation
|
|
49
|
-
export { _createStore as createStore };
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Parse a Turtle string into a Store (lite version - no OTEL tracing)
|
|
53
|
-
* @param {string} ttl - The Turtle string to parse
|
|
54
|
-
* @param {string} [baseIRI='http://example.org/'] - Base IRI for resolving relative URIs
|
|
55
|
-
* @returns {Promise<import('n3').Store>} Promise resolving to a Store containing the parsed quads
|
|
56
|
-
* @throws {TypeError} If ttl is not a string
|
|
57
|
-
* @throws {Error} If parsing fails
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* const ttl = `
|
|
61
|
-
* @prefix ex: <http://example.org/> .
|
|
62
|
-
* ex:alice ex:knows ex:bob .
|
|
63
|
-
* `;
|
|
64
|
-
* const store = await parseTurtle(ttl);
|
|
65
|
-
*/
|
|
66
|
-
export async function parseTurtle(ttl, baseIRI = 'http://example.org/') {
|
|
67
|
-
if (typeof ttl !== 'string') {
|
|
68
|
-
throw new TypeError('parseTurtle: ttl must be a string');
|
|
69
|
-
}
|
|
70
|
-
if (typeof baseIRI !== 'string') {
|
|
71
|
-
throw new TypeError('parseTurtle: baseIRI must be a string');
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const { Parser } = await import('n3');
|
|
75
|
-
const parser = new Parser({ baseIRI });
|
|
76
|
-
const quads = parser.parse(ttl);
|
|
77
|
-
return _createStore(quads);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Serialize a Store to Turtle format (lite version - no OTEL tracing)
|
|
82
|
-
* @param {import('n3').Store} store - The store to serialize
|
|
83
|
-
* @param {Object} [options={}] - Serialization options
|
|
84
|
-
* @param {Object} [options.prefixes] - Prefix mappings for compact output
|
|
85
|
-
* @param {string} [options.baseIRI] - Base IRI for the output
|
|
86
|
-
* @returns {Promise<string>} Promise resolving to the Turtle string
|
|
87
|
-
* @throws {TypeError} If store is not a valid Store instance
|
|
88
|
-
* @throws {Error} If serialization fails
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* const turtle = await toTurtle(store, {
|
|
92
|
-
* prefixes: { ex: 'http://example.org/' }
|
|
93
|
-
* });
|
|
94
|
-
*/
|
|
95
|
-
export async function toTurtle(store, options = {}) {
|
|
96
|
-
if (!store || typeof store.getQuads !== 'function') {
|
|
97
|
-
throw new TypeError('toTurtle: store must be a valid Store instance');
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const { Writer } = await import('n3');
|
|
101
|
-
const writer = new Writer({
|
|
102
|
-
format: 'Turtle',
|
|
103
|
-
prefixes: options.prefixes || {},
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
const quads = store.getQuads();
|
|
107
|
-
writer.addQuads(quads);
|
|
108
|
-
|
|
109
|
-
return new Promise((resolve, reject) => {
|
|
110
|
-
writer.end((error, result) => {
|
|
111
|
-
if (error) {
|
|
112
|
-
reject(new Error(`Failed to serialize to Turtle: ${error.message}`));
|
|
113
|
-
} else {
|
|
114
|
-
if (options.baseIRI) {
|
|
115
|
-
result = `@base <${options.baseIRI}> .\n\n${result}`;
|
|
116
|
-
}
|
|
117
|
-
resolve(result);
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Serialize a Store to N-Quads format (lite version - no OTEL tracing)
|
|
125
|
-
* @param {import('n3').Store} store - The store to serialize
|
|
126
|
-
* @param {Object} [options={}] - Serialization options
|
|
127
|
-
* @returns {Promise<string>} Promise resolving to the N-Quads string
|
|
128
|
-
* @throws {TypeError} If store is not a valid Store instance
|
|
129
|
-
* @throws {Error} If serialization fails
|
|
130
|
-
*
|
|
131
|
-
* @example
|
|
132
|
-
* const nquads = await toNQuads(store);
|
|
133
|
-
*/
|
|
134
|
-
export async function toNQuads(store, options = {}) {
|
|
135
|
-
if (!store || typeof store.getQuads !== 'function') {
|
|
136
|
-
throw new TypeError('toNQuads: store must be a valid Store instance');
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const { Writer } = await import('n3');
|
|
140
|
-
const writer = new Writer({
|
|
141
|
-
format: 'N-Quads',
|
|
142
|
-
...options,
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
const quads = store.getQuads();
|
|
146
|
-
writer.addQuads(quads);
|
|
147
|
-
|
|
148
|
-
return new Promise((resolve, reject) => {
|
|
149
|
-
writer.end((error, result) => {
|
|
150
|
-
if (error) {
|
|
151
|
-
reject(new Error(`Failed to serialize to N-Quads: ${error.message}`));
|
|
152
|
-
} else {
|
|
153
|
-
resolve(result);
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Create a quad using DataFactory (convenience function)
|
|
161
|
-
* @param {string} subject - Subject IRI
|
|
162
|
-
* @param {string} predicate - Predicate IRI
|
|
163
|
-
* @param {string|{value: string, language?: string, datatype?: string}} object - Object value
|
|
164
|
-
* @param {string} [graph] - Optional graph IRI
|
|
165
|
-
* @returns {import('n3').Quad} The created quad
|
|
166
|
-
*
|
|
167
|
-
* @example
|
|
168
|
-
* const q = createQuad(
|
|
169
|
-
* 'http://example.org/alice',
|
|
170
|
-
* 'http://xmlns.com/foaf/0.1/name',
|
|
171
|
-
* { value: 'Alice', language: 'en' }
|
|
172
|
-
* );
|
|
173
|
-
*/
|
|
174
|
-
export function createQuad(subject, predicate, object, graph) {
|
|
175
|
-
const { DataFactory } = require('n3');
|
|
176
|
-
const { namedNode, literal, quad, defaultGraph } = DataFactory;
|
|
177
|
-
|
|
178
|
-
const subjectNode = namedNode(subject);
|
|
179
|
-
const predicateNode = namedNode(predicate);
|
|
180
|
-
|
|
181
|
-
let objectNode;
|
|
182
|
-
if (typeof object === 'string') {
|
|
183
|
-
// Check if it looks like a URI
|
|
184
|
-
if (
|
|
185
|
-
object.startsWith('http://') ||
|
|
186
|
-
object.startsWith('https://') ||
|
|
187
|
-
object.startsWith('urn:')
|
|
188
|
-
) {
|
|
189
|
-
objectNode = namedNode(object);
|
|
190
|
-
} else {
|
|
191
|
-
objectNode = literal(object);
|
|
192
|
-
}
|
|
193
|
-
} else if (typeof object === 'object') {
|
|
194
|
-
if (object.language) {
|
|
195
|
-
objectNode = literal(object.value, object.language);
|
|
196
|
-
} else if (object.datatype) {
|
|
197
|
-
objectNode = literal(object.value, namedNode(object.datatype));
|
|
198
|
-
} else {
|
|
199
|
-
objectNode = literal(object.value);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
const graphNode = graph ? namedNode(graph) : defaultGraph();
|
|
204
|
-
return quad(subjectNode, predicateNode, objectNode, graphNode);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Bundle size comparison (approximate):
|
|
209
|
-
*
|
|
210
|
-
* Full knowledge-engine: ~8-10MB
|
|
211
|
-
* - @comunica/query-sparql: ~2.5MB
|
|
212
|
-
* - isolated-vm: ~5MB (native)
|
|
213
|
-
* - eyereasoner: ~500KB
|
|
214
|
-
* - rdf-validate-shacl: ~200KB
|
|
215
|
-
* - n3: ~150KB
|
|
216
|
-
* - hooks/policy: ~100KB
|
|
217
|
-
*
|
|
218
|
-
* Lite knowledge-engine: ~150KB
|
|
219
|
-
* - n3 only: ~150KB
|
|
220
|
-
*
|
|
221
|
-
* Savings: ~98% for basic RDF operations
|
|
222
|
-
*/
|