@faubulous/mentor-rdf 1.4.2 → 2.0.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.
@@ -0,0 +1,94 @@
1
+ import * as rdfjs from "@rdfjs/types";
2
+ import type { Store } from "./store";
3
+ /**
4
+ * Options for creating a {@link DatasetView}.
5
+ */
6
+ export interface DatasetViewOptions {
7
+ /**
8
+ * URIs of the named graphs to scope the view to. If undefined, the view spans all quads in the store.
9
+ */
10
+ graphUris?: readonly string[];
11
+ /**
12
+ * Graph terms to scope the view to. Takes precedence over `graphUris`. Use this to scope
13
+ * the view to graphs that cannot be expressed as URIs, such as the default graph.
14
+ */
15
+ graphs?: readonly rdfjs.Quad_Graph[];
16
+ /**
17
+ * Restrict the view to quads with this subject.
18
+ */
19
+ subject?: rdfjs.Term | null;
20
+ /**
21
+ * Restrict the view to quads with this predicate.
22
+ */
23
+ predicate?: rdfjs.Term | null;
24
+ /**
25
+ * Restrict the view to quads with this object.
26
+ */
27
+ object?: rdfjs.Term | null;
28
+ /**
29
+ * Whether to include inferred triples from the inference graphs associated with the scoped
30
+ * graphs. If undefined, inferred triples are included when a reasoner is available. If `true`
31
+ * without a reasoner, an error is thrown. Only applies when the view is scoped to graphs.
32
+ */
33
+ includeInferred?: boolean;
34
+ }
35
+ /**
36
+ * A lazy, read-only RDF/JS DatasetCore view over a {@link Store}, optionally scoped to a set
37
+ * of graphs and a quad pattern. The view does not copy any quads: iteration, counting and
38
+ * containment checks delegate to the store's indexes, so the view always reflects the current
39
+ * contents of the store.
40
+ */
41
+ export declare class DatasetView implements rdfjs.DatasetCore<rdfjs.Quad> {
42
+ private readonly _store;
43
+ private readonly _s;
44
+ private readonly _p;
45
+ private readonly _o;
46
+ /**
47
+ * The graph terms the view is scoped to, including inference graphs if enabled.
48
+ * `undefined` means the view spans all graphs; an empty array means the view is provably empty.
49
+ */
50
+ private readonly _scope?;
51
+ private _cachedSize?;
52
+ private _cachedSizeVersion;
53
+ constructor(store: Store, options?: DatasetViewOptions);
54
+ private static _resolveScope;
55
+ /**
56
+ * Get the number of quads in the view. Computed from the store's indexes and memoized
57
+ * until the store is modified.
58
+ */
59
+ get size(): number;
60
+ /**
61
+ * Not supported: the view is read-only.
62
+ * @throws An error indicating that the view is read-only.
63
+ */
64
+ add(_quad: rdfjs.Quad): this;
65
+ /**
66
+ * Not supported: the view is read-only.
67
+ * @throws An error indicating that the view is read-only.
68
+ */
69
+ delete(_quad: rdfjs.Quad): this;
70
+ /**
71
+ * Indicates if the view contains a specific quad.
72
+ * @param quad The quad to be checked.
73
+ * @returns `true` if the quad matches the view's pattern and scope and exists in the store.
74
+ */
75
+ has(quad: rdfjs.Quad): boolean;
76
+ /**
77
+ * Get a new view narrowed to the quads matching the given pattern. The constraints of this
78
+ * view are intersected with the given pattern: a term that conflicts with an existing
79
+ * constraint results in an empty view.
80
+ * @param subject The optional subject.
81
+ * @param predicate The optional predicate.
82
+ * @param object The optional object.
83
+ * @param graph The optional graph.
84
+ * @returns A new read-only dataset view of the matching quads.
85
+ */
86
+ match(subject?: rdfjs.Term | null, predicate?: rdfjs.Term | null, object?: rdfjs.Term | null, graph?: rdfjs.Term | null): DatasetView;
87
+ /**
88
+ * Intersect an existing term constraint with an incoming one.
89
+ * @returns The effective term constraint, or `undefined` if the terms conflict.
90
+ */
91
+ private static _intersectTerm;
92
+ [Symbol.iterator](): Iterator<rdfjs.Quad>;
93
+ private _iterate;
94
+ }
@@ -1,5 +1,6 @@
1
1
  export * from "./class-repository";
2
2
  export * from "./data-factory";
3
+ export * from "./dataset-view";
3
4
  export * from "./individual-repository";
4
5
  export * from "./property-repository";
5
6
  export * from "./reasoners/owl-reasoner";
@@ -1,6 +1,7 @@
1
1
  import * as rdfjs from "@rdfjs/types";
2
2
  import { EventEmitter } from "stream";
3
3
  import { Reasoner } from "./reasoners/reasoner";
4
+ import { DatasetView } from "./dataset-view";
4
5
  /**
5
6
  * Indicates an error when a triple is not found in the store.
6
7
  */
@@ -11,7 +12,7 @@ export declare class TripleNotFoundError extends Error {
11
12
  */
12
13
  constructor(subject: rdfjs.Quad_Subject | null, predicate: rdfjs.Quad_Predicate | null, object: rdfjs.Quad_Object | null);
13
14
  }
14
- export declare class Store implements rdfjs.Source<rdfjs.Quad> {
15
+ export declare class Store implements rdfjs.DatasetCore<rdfjs.Quad> {
15
16
  /**
16
17
  * The adapted RDF.js triple store implementation.
17
18
  *
@@ -27,6 +28,19 @@ export declare class Store implements rdfjs.Source<rdfjs.Quad> {
27
28
  * The reasoner to be used for inference.
28
29
  */
29
30
  readonly reasoner?: Reasoner;
31
+ /**
32
+ * A monotonic counter that is incremented on every mutation of the store.
33
+ */
34
+ private _version;
35
+ /**
36
+ * Monotonic counters per graph URI, incremented on every mutation of the graph.
37
+ */
38
+ private readonly _graphVersions;
39
+ /**
40
+ * Get a monotonic counter that is incremented on every mutation of the store.
41
+ * Can be used to cheaply detect whether the store has changed.
42
+ */
43
+ get version(): number;
30
44
  /**
31
45
  * Get the number of triples in all graphs of the store.
32
46
  */
@@ -41,6 +55,14 @@ export declare class Store implements rdfjs.Source<rdfjs.Quad> {
41
55
  */
42
56
  constructor(reasoner?: Reasoner);
43
57
  [Symbol.iterator](): Iterator<rdfjs.Quad, any, any>;
58
+ /**
59
+ * Get a monotonic counter for a single graph, incremented on every mutation of the graph.
60
+ * Can be used to cheaply detect whether the contents of a graph have changed.
61
+ * @param graphUri A graph URI.
62
+ * @returns The current version of the graph; `0` if the graph was never modified.
63
+ */
64
+ getGraphVersion(graphUri: string): number;
65
+ private _touchGraph;
44
66
  /**
45
67
  * Loads a set of W3C Standard ontologies into the store (RDF, RDFA, RDFS, OWL, SKOS, SHACL, XSD).
46
68
  */
@@ -150,14 +172,30 @@ export declare class Store implements rdfjs.Source<rdfjs.Quad> {
150
172
  */
151
173
  countQuads(subject?: rdfjs.Term | null, predicate?: rdfjs.Term | null, object?: rdfjs.Term | null, graph?: rdfjs.Term | null): number;
152
174
  /**
153
- * Returns a stream of quads matching the given pattern.
175
+ * Returns a lazy, read-only dataset view of the quads matching the given pattern.
176
+ * Implements the RDF/JS `DatasetCore.match` semantics: the result reflects the
177
+ * current contents of the store and does not copy any quads.
154
178
  * @param subject The optional subject.
155
179
  * @param predicate The optional predicate.
156
180
  * @param object The optional object.
157
181
  * @param graph The optional graph.
158
- * @returns A stream of matching quads.
182
+ * @returns A read-only dataset view of the matching quads.
183
+ */
184
+ match(subject?: rdfjs.Term | null, predicate?: rdfjs.Term | null, object?: rdfjs.Term | null, graph?: rdfjs.Term | null): DatasetView;
185
+ /**
186
+ * Synchronously iterate the quads matching a single pattern.
187
+ * @param subject The optional subject.
188
+ * @param predicate The optional predicate.
189
+ * @param object The optional object.
190
+ * @param graph The optional graph.
191
+ */
192
+ matchQuads(subject?: rdfjs.Term | null, predicate?: rdfjs.Term | null, object?: rdfjs.Term | null, graph?: rdfjs.Term | null): Generator<rdfjs.Quad>;
193
+ /**
194
+ * Get an RDF/JS `Source` interface for the store that streams matching quads.
195
+ * Primarily intended for query engines such as Comunica that operate on quad streams.
196
+ * @returns A source that returns a stream of quads for a given pattern.
159
197
  */
160
- match(subject?: rdfjs.Term | null, predicate?: rdfjs.Term | null, object?: rdfjs.Term | null, graph?: rdfjs.Term | null): rdfjs.Stream<rdfjs.Quad>;
198
+ asSource(): rdfjs.Source<rdfjs.Quad>;
161
199
  /**
162
200
  * Query the store for triples matching the given pattern supporting multiple graphs.
163
201
  * @param graphUris Optional graph URI or array of graph URIs to query.
@@ -176,12 +214,16 @@ export declare class Store implements rdfjs.Source<rdfjs.Quad> {
176
214
  */
177
215
  any(graphUris: string | string[] | undefined, subject: rdfjs.Quad_Subject | null, predicate: rdfjs.Quad_Predicate | null, object: rdfjs.Quad_Object | null, includeInferred?: boolean): boolean;
178
216
  /**
179
- * Get a new DatasetCore containing all quads from the specified graphs.
217
+ * Get a read-only DatasetCore view of all quads in the specified graphs.
218
+ * The view is lazy and live: it reflects the current contents of the store without
219
+ * copying any quads. If you need an immutable snapshot, copy the view into a new
220
+ * dataset, e.g. `RdfStore.createDefault().asDataset()`.
180
221
  * @param graphUris Optional graph URI or array of graph URIs. If undefined, all quads are included.
181
- * @param includeInferred Whether to include inferred triples. Defaults to false.
182
- * @returns A new DatasetCore instance with the matching quads.
222
+ * @param includeInferred Whether to include inferred triples. If undefined, inferred triples
223
+ * are included when a reasoner is available. If `true` without a reasoner, an error is thrown.
224
+ * @returns A read-only dataset view of the matching quads.
183
225
  */
184
- getDataset(graphUris?: string | string[], includeInferred?: boolean): rdfjs.DatasetCore;
226
+ getDataset(graphUris?: string | string[], includeInferred?: boolean): DatasetView;
185
227
  /**
186
228
  * Get the first triple matching the given pattern in the store.
187
229
  * @param graphUris Optional graph URI or array of graph URIs to query.
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "ontology",
11
11
  "vocabulary"
12
12
  ],
13
- "version": "1.4.2",
13
+ "version": "2.0.0",
14
14
  "private": false,
15
15
  "author": {
16
16
  "name": "Sebastian Faubel"
@@ -60,6 +60,14 @@
60
60
  "typescript": "^6.0.3",
61
61
  "vitest": "^4.1.9"
62
62
  },
63
+ "overrides": {
64
+ "got": "^11.8.6",
65
+ "tmp": "^0.2.7",
66
+ "gry": "^6.1.1",
67
+ "git-url-parse": "^16.1.0",
68
+ "git-up": "^8.1.1",
69
+ "parse-url": "^11.1.0"
70
+ },
63
71
  "dependencies": {
64
72
  "@faubulous/mentor-rdf-parsers": "^1.9.0",
65
73
  "memory-level": "^3.1.0",