rete-graph 0.3.1 → 0.3.4

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.
Binary file
package/index.d.ts CHANGED
@@ -19,17 +19,111 @@ export class Term {
19
19
  export type Row = Record<string, Term>;
20
20
  export type Triple = [Term, Term, Term];
21
21
 
22
+ /** `[subject, predicate, object, graph]`; `graph` is null in the default graph. */
23
+ export type Quad = [Term, Term, Term, Term | null];
24
+ /** The same, as the engine's raw N-Triples term tokens (`dump({raw: true})`). */
25
+ export type RawQuad = [string, string, string, string | null];
26
+
22
27
  export interface QueryOptions {
23
28
  /** OWL 2 QL entailment by query rewriting. */
24
29
  reason?: boolean;
25
30
  }
26
31
 
32
+ /**
33
+ * A diagnostic from the last query: a class of SPARQL type errors that FILTER
34
+ * silently treated as false (or BIND left unbound), or a hint for an empty result.
35
+ */
36
+ export interface QueryWarning {
37
+ /** `"type-error"`: an error was raised and absorbed. `"hint"`: a suggestion only. */
38
+ severity: "type-error" | "hint";
39
+ /**
40
+ * The SPARQL function, e.g. `"CONTAINS"`, or an operator's spelling:
41
+ * `+ - * /`, `= != < <= > >=`, `IN`.
42
+ */
43
+ function: string;
44
+ /** 1-based argument position (for an operator: 1 left, 2 right). */
45
+ argument: number;
46
+ /**
47
+ * `iri`, `blank-node`, `quoted-triple`, `numeric`, `typed-literal`,
48
+ * `string`, `language-tagged`, `invalid-number`, `language-mismatch`,
49
+ * `unbound`, `invalid-regex`, `not-a-datetime`, `division-by-zero`, or
50
+ * `case-sensitive` (the hint).
51
+ */
52
+ argKind: string;
53
+ /** Evaluations that raised it (LIMIT / ASK stop early: not a data count). */
54
+ count: number;
55
+ /** The first offending value, truncated to 80 characters. */
56
+ sample: string | null;
57
+ /** What to change, e.g. "wrap it in STR() to match the IRI's text". */
58
+ hint: string;
59
+ /** The whole warning as one sentence. */
60
+ message: string;
61
+ }
62
+
63
+ export interface DumpOptions {
64
+ /**
65
+ * Omit for the default graph followed by every named graph; `null` for the
66
+ * default graph only; an IRI for that named graph only.
67
+ */
68
+ graph?: string | null;
69
+ /**
70
+ * Restrict the dump to a triple pattern. These **prune index tiles** rather
71
+ * than filtering rows: the engine routes the scan to the permutation that
72
+ * sorts on the bound components and drops every tile whose synopsis proves it
73
+ * cannot match, without fetching it. Dumping one predicate of a large remote
74
+ * graph therefore costs the slice, not the graph.
75
+ *
76
+ * A clean IRI (`"http://ex/p"`), an N-Triples token (`'"x"@en'`, `"_:b"`), or
77
+ * a `Term`. A term the file's dictionary does not contain yields nothing.
78
+ *
79
+ * Order follows the permutation the scan routes to, so a filtered dump is the
80
+ * same *set* as the unfiltered one filtered but not the same order: a bound
81
+ * predicate streams predicate-then-object-then-subject. Sort if you need one.
82
+ */
83
+ subject?: string | Term | null;
84
+ predicate?: string | Term | null;
85
+ object?: string | Term | null;
86
+ /** Quads pulled per wasm call (default 10 000). Bounds memory, not results. */
87
+ batch?: number;
88
+ }
89
+
90
+ /**
91
+ * How a quoted triple is spelled — `rete build/export --quoted-triple-syntax`.
92
+ * `"rdf12"`: the RDF 1.2 triple term `<<( s p o )>>` (and, when reading
93
+ * Turtle/TriG, `<< … >>` is a reifier). `"rdf-star"`: `<<s p o>>`, a quoted
94
+ * triple — rete's stored token.
95
+ */
96
+ export type QuotedTripleSyntax = "rdf12" | "rdf-star";
97
+
98
+ export interface NQuadsOptions extends DumpOptions {
99
+ /** Default `"rdf12"`, like `rete export`. */
100
+ quotedTripleSyntax?: QuotedTripleSyntax;
101
+ }
102
+
103
+ /** `signals.quoted_triples` of a card, measured from the file header on read. */
104
+ export interface QuotedTriplesSignal {
105
+ present: boolean;
106
+ export_surfaces?: QuotedTripleSyntax[];
107
+ export_default?: QuotedTripleSyntax;
108
+ }
109
+
110
+ /** A sink for {@link Graph.writeNQuads}: Node stream, web stream, or callback. */
111
+ export type NQuadsSink =
112
+ | { write(chunk: string): unknown; once?(event: string, cb: () => void): unknown }
113
+ | { getWriter(): { ready: Promise<void>; write(chunk: string): unknown; releaseLock(): void } }
114
+ | ((chunk: string) => unknown);
115
+
27
116
  export class Graph {
28
117
  readonly source: string;
29
118
  /** SELECT → Row[]; ASK → boolean; CONSTRUCT/DESCRIBE → Triple[]. */
30
119
  query(query: string, opts?: QueryOptions): Row[] | boolean | Triple[];
31
120
  /** The engine's raw JSON result envelope. */
32
121
  queryRaw(query: string, opts?: QueryOptions): unknown;
122
+ /**
123
+ * Warnings from the most recent `query()` / `queryRaw()` on this graph; empty
124
+ * when there is nothing to report. Results are never changed by them.
125
+ */
126
+ lastWarnings(): QueryWarning[];
33
127
  prefixSearch(prefix: string, limit?: number): { label: string; subject: string }[];
34
128
  textSearch(
35
129
  words: string | string[],
@@ -40,7 +134,11 @@ export class Graph {
40
134
  relations: [s: string, p: string, o: string, count: number][];
41
135
  };
42
136
  info(): { quads: number; terms: number; pyramidLevels: number; namedGraphs: number };
43
- /** The embedded Dataset Card, or null when the file carries none. */
137
+ /**
138
+ * The embedded Dataset Card, or null when the file carries none. Its
139
+ * `signals.quoted_triples` ({@link QuotedTriplesSignal}) is measured from the
140
+ * header on read, so files built before the signal existed carry it too.
141
+ */
44
142
  card(): Record<string, unknown> | null;
45
143
  /** Example SPARQL queries from the card; `sparql` plus optional rich fields. */
46
144
  examples(): { sparql: string; title?: string; question?: string }[];
@@ -49,7 +147,20 @@ export class Graph {
49
147
  shapesTurtle: string,
50
148
  opts?: { graph?: string | null; format?: "json" | "text" },
51
149
  ): unknown;
150
+ /** The dataset's quad count (the streaming dump is {@link Graph.dump}). */
52
151
  readonly quads: number;
152
+ /**
153
+ * Every quad, streamed lazily and in memory that does not grow with the
154
+ * graph: `for await (const [s, p, o, g] of graph.dump())`.
155
+ */
156
+ dump(opts?: DumpOptions & { raw?: false }): AsyncGenerator<Quad>;
157
+ dump(opts: DumpOptions & { raw: true }): AsyncGenerator<RawQuad>;
158
+ /** The graph as N-Quads text, in whole-line chunks — constant memory. */
159
+ nquads(opts?: NQuadsOptions): AsyncGenerator<string>;
160
+ /** Stream the graph as N-Quads into a sink; returns the length written. */
161
+ writeNQuads(sink: NQuadsSink, opts?: NQuadsOptions): Promise<number>;
162
+ /** The whole graph as ONE N-Quads string (materializes it — see nquads). */
163
+ toNQuads(opts?: NQuadsOptions): Promise<string>;
53
164
  graphNames(): string[];
54
165
  /** Remote graphs only: cumulative fetch counters; null for bytes graphs. */
55
166
  stats(): { fileLength: number; bytes: number; requests: number } | null;
@@ -72,12 +183,27 @@ export function open(
72
183
  /** The raw wasm engine — escape hatch for exports this wrapper doesn't wrap. */
73
184
  export const wasm: Record<string, (...args: never[]) => unknown>;
74
185
 
75
- /** Build a complete `.rete` file image from RDF text ("nt", "nq", "ttl"). */
76
- export function build(text: string, format?: "nt" | "nq" | "ttl"): Promise<Uint8Array>;
186
+ /**
187
+ * Build a complete `.rete` file image from RDF text. `quotedTripleSyntax`
188
+ * (default `"rdf-star"`, like `rete build`) decides what Turtle/TriG `<< … >>`
189
+ * means; N-Triples and N-Quads ignore it.
190
+ */
191
+ export function build(
192
+ text: string,
193
+ format?: "nt" | "nq" | "ttl" | "trig",
194
+ opts?: { quotedTripleSyntax?: QuotedTripleSyntax },
195
+ ): Promise<Uint8Array>;
77
196
 
78
197
  /** Initialize the wasm engine explicitly (open()/build() do it lazily). */
79
198
  export function init(source?: BufferSource | WebAssembly.Module | URL | string | null): Promise<void>;
80
199
 
200
+ /**
201
+ * The engine's wasm linear memory in bytes — a high-water mark, since wasm
202
+ * memory grows but never shrinks. Sample it around a dump to verify that
203
+ * streaming really does not grow with the graph.
204
+ */
205
+ export function heapBytes(): number;
206
+
81
207
  /**
82
208
  * RDF/JS Source over an open Graph — plugs `.rete` files into Comunica,
83
209
  * LDflex, GraphQL-LD, and anything speaking the RDF/JS Source interface:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rete-graph",
3
- "version": "0.3.1",
3
+ "version": "0.3.4",
4
4
  "description": "Query local and remote .rete graph files with SPARQL — WebAssembly client for browsers and Node, with lazy byte-range reads over HTTP and local files.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -29,6 +29,7 @@
29
29
  },
30
30
  "devDependencies": {
31
31
  "@comunica/query-sparql": "^4.0.0",
32
- "esbuild": "^0.25.0"
32
+ "esbuild": "^0.25.0",
33
+ "oxigraph": "^0.5.9"
33
34
  }
34
35
  }