@wazootech/sparql-engine 0.5.8 → 0.5.10

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/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { a as SparqlRequest, c as SparqlValue, i as SparqlEngineInterface, n as SparqlBinding, o as SparqlResponse, r as SparqlConstructResults, s as SparqlSelectResults, t as SparqlAskResults } from "./sparql-engine-interface-Bies9KjE.js";
2
2
  import { i as RdfQuad, l as RdfTerm, o as RdfSource, s as RdfStore } from "./rdf-terms-DGpxNnyn.js";
3
3
  import { B as Triple, z as Term } from "./ast-CIKmrXH9.js";
4
- import { n as SparqlSyntaxError, t as parseTurtleQuads } from "./turtle-parser-CzWF7KXf.js";
5
- import { n as MemoryStream, t as MemoryStore } from "./memory-store-DhAGI-j6.js";
4
+ import { n as SparqlSyntaxError, t as parseTurtleQuads } from "./turtle-parser-G8iweqtS.js";
5
+ import { n as MemoryStream, t as MemoryStore } from "./memory-store-CeZeEaF3.js";
6
6
  import { A as canonicalizeRdfTerm, C as XSD_INTEGER, I as sameRdfTerm, L as termKey, M as rdfTermToSparqlValue, N as sparqlTermToRdfTerm, O as numericValue, S as XSD_FLOAT, T as compareNumericValues, _ as XSD_BOOLEAN, b as XSD_DECIMAL, g as XSD, h as NUMERIC_DATATYPES, i as compareRdfTerms, j as canonicalizeSparqlValue, k as CanonicalTerm, m as formatNumber, r as dataFactory, t as DataFactory, w as XSD_STRING, x as XSD_DOUBLE } from "./public-BNHiaGho.js";
7
7
  import { a as serializeJsonResults, i as serializeXmlResults, n as TurtleWriterOptions, r as serializeTurtle, t as TurtleFormat } from "./mod-C4GFefO7.js";
8
8
  /** LoadHttpResponse is the fetch reply surface the guarded LOAD path reads. */
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { n as parseTurtleQuads, r as SparqlSyntaxError, t as Parser } from "./parser-CTZiNJfu.js";
1
+ import { n as parseTurtleQuads, r as SparqlSyntaxError, t as Parser } from "./parser-BnLGz638.js";
2
2
  import { a as narrowQuadObject, c as quadDedupKey, d as sameRdfTerm, f as termKey, h as blankNodeTerm, i as defaultGraphInstance, l as requireQuadGraph, o as narrowQuadPredicate, s as narrowQuadSubject, t as DataFactory$1 } from "./data-factory-76Dxrf0g.js";
3
3
  import { C as XSD_INTEGER, D as numberFromNumeric, E as doubleFromText, O as numberFromText, S as XSD_FLOAT, T as compareNumericValues, _ as XSD_BOOLEAN, a as md5Hex, b as XSD_DECIMAL, c as parseDateTime, d as canonicalizeRdfTerm, f as canonicalizeSparqlValue, g as XSD, h as NUMERIC_DATATYPES, i as typedValuesEqual, k as numericValue, l as timezoneDurationLexical, m as sparqlTermToRdfTerm, n as orderTypedValues, o as XSD_DATE, p as rdfTermToSparqlValue, r as typedValue, s as parseCalendar, t as compareRdfTerms, u as timezoneOf, v as XSD_DATETIME, w as XSD_STRING, x as XSD_DOUBLE, y as XSD_DAYTIME_DURATION } from "./term-s9I2y-ck.js";
4
- import { n as MemoryStream, r as matchQuadStream, t as MemoryStore } from "./memory-store-Mq4x2Ya1.js";
4
+ import { n as MemoryStream, r as matchQuadStream, t as MemoryStore } from "./memory-store-BbPo3tpx.js";
5
5
  import { a as sha256Hex, c as formatNumber, i as sha512Hex, n as dataFactory, o as sha1Hex, r as sha384Hex, s as canonicalDouble, t as DataFactory } from "./public-D0uwoGhU.js";
6
6
  import { n as serializeXmlResults, r as serializeJsonResults, t as serializeTurtle } from "./serialize-BSkHhuBp.js";
7
7
  // \0rolldown/runtime.js
@@ -104,13 +104,15 @@ var MemoryStream = class extends MiniEventEmitter {
104
104
  _ended = false;
105
105
  _flowing = false;
106
106
  _readStarted = false;
107
+ /** Index of the next quad. `quads.shift()` is slow for big arrays in V8. */
108
+ _next = 0;
107
109
  constructor(quads) {
108
110
  super();
109
111
  this.quads = quads;
110
112
  }
111
113
  read() {
112
114
  this._readStarted = true;
113
- const quad = this.quads.shift();
115
+ const quad = this._take();
114
116
  if (quad === void 0) {
115
117
  this._end();
116
118
  return null;
@@ -118,7 +120,7 @@ var MemoryStream = class extends MiniEventEmitter {
118
120
  return quad;
119
121
  }
120
122
  [Symbol.iterator]() {
121
- return this.quads[Symbol.iterator]();
123
+ return this.quads.slice(this._next)[Symbol.iterator]();
122
124
  }
123
125
  destroy(error) {
124
126
  if (error) this.emit("error", error);
@@ -128,14 +130,23 @@ var MemoryStream = class extends MiniEventEmitter {
128
130
  on(eventName, listener) {
129
131
  this.onRaw(eventName, listener);
130
132
  if (eventName === "data" && !this._ended && !this._flowing) this._startFlowing();
131
- if (eventName === "readable" && !this._ended && this.quads.length > 0) queueMicrotask(() => {
132
- if (!this._ended && this.quads.length > 0 && this.listenerCount("readable") > 0) this.emit("readable");
133
+ if (eventName === "readable" && !this._ended && this._hasNext()) queueMicrotask(() => {
134
+ if (!this._ended && this._hasNext() && this.listenerCount("readable") > 0) this.emit("readable");
133
135
  });
134
136
  if (eventName === "end" && !this._ended) queueMicrotask(() => {
135
137
  if (!this._ended && !this._flowing && !this._readStarted && this.listenerCount("data") === 0 && this.listenerCount("readable") === 0) this._end();
136
138
  });
137
139
  return this;
138
140
  }
141
+ _hasNext() {
142
+ return this._next < this.quads.length;
143
+ }
144
+ _take() {
145
+ if (!this._hasNext()) return void 0;
146
+ const quad = this.quads[this._next];
147
+ this._next += 1;
148
+ return quad;
149
+ }
139
150
  _startFlowing() {
140
151
  this._flowing = true;
141
152
  queueMicrotask(() => this._drain());
@@ -143,11 +154,11 @@ var MemoryStream = class extends MiniEventEmitter {
143
154
  _drain() {
144
155
  if (this._ended || !this._flowing) return;
145
156
  while (this.listenerCount("data") > 0) {
146
- const quad = this.quads.shift();
157
+ const quad = this._take();
147
158
  if (quad === void 0) break;
148
159
  this.emit("data", quad);
149
160
  }
150
- if (this.quads.length === 0) this._end();
161
+ if (!this._hasNext()) this._end();
151
162
  }
152
163
  _end() {
153
164
  if (this._ended) return;
@@ -46,11 +46,15 @@ declare class MemoryStream extends MiniEventEmitter implements RdfStream<RdfQuad
46
46
  private _ended;
47
47
  private _flowing;
48
48
  private _readStarted;
49
+ /** Index of the next quad. `quads.shift()` is slow for big arrays in V8. */
50
+ private _next;
49
51
  constructor(quads: RdfQuad[]);
50
52
  read(): RdfQuad | null;
51
53
  [Symbol.iterator](): Iterator<RdfQuad>;
52
54
  destroy(error?: Error): void;
53
55
  on(eventName: string | symbol, listener: Listener): this;
56
+ private _hasNext;
57
+ private _take;
54
58
  private _startFlowing;
55
59
  private _drain;
56
60
  private _end;
@@ -60012,6 +60012,24 @@ var SparqlLrParser = class extends LrParser {
60012
60012
  function parseSparql(input) {
60013
60013
  new SparqlLrParser().parse(new SparqlLexer(input));
60014
60014
  }
60015
+ // src/parser/turtle-labels.ts
60016
+ /**
60017
+ * createLabelMaker returns a function that makes up blank node labels for one
60018
+ * document: `b1`, `b2` and so on, without the ones the document writes itself
60019
+ * anywhere in its text.
60020
+ */
60021
+ function createLabelMaker(text) {
60022
+ const written = new Set(Array.from(text.matchAll(/_:(b\d+)/g), (match) => match[1]));
60023
+ let count = 0;
60024
+ return () => {
60025
+ let label;
60026
+ do {
60027
+ count += 1;
60028
+ label = `b${count}`;
60029
+ } while (written.has(label));
60030
+ return label;
60031
+ };
60032
+ }
60015
60033
  // src/parser/turtle-context.ts
60016
60034
  /**
60017
60035
  * Typed parse context and semantic actions for the generated Turtle / TriG /
@@ -60046,7 +60064,7 @@ const XSD_DECIMAL = XSD + "decimal";
60046
60064
  const XSD_DOUBLE = XSD + "double";
60047
60065
  const XSD_BOOLEAN = XSD + "boolean";
60048
60066
  /** createTurtleParseState returns the empty statement-level state. */
60049
- function createTurtleParseState() {
60067
+ function createTurtleParseState(text = "") {
60050
60068
  return {
60051
60069
  graph: void 0,
60052
60070
  subject: void 0,
@@ -60054,7 +60072,7 @@ function createTurtleParseState() {
60054
60072
  object: void 0,
60055
60073
  reifier: void 0,
60056
60074
  tripleTerm: void 0,
60057
- bnodeCounter: 0,
60075
+ nextLabel: createLabelMaker(text),
60058
60076
  saveStack: [],
60059
60077
  reifierStack: [],
60060
60078
  collectionStack: [],
@@ -60076,12 +60094,12 @@ const turtleContext = {
60076
60094
  * resetTurtleContext prepares `turtleContext` for a new document: a fresh
60077
60095
  * state, empty prefix map, empty quad buffer, and the given base IRI.
60078
60096
  */
60079
- function resetTurtleContext(baseIri) {
60097
+ function resetTurtleContext(baseIri, text) {
60080
60098
  turtleContext.factory = DataFactory;
60081
60099
  turtleContext.base = baseIri;
60082
60100
  turtleContext.prefixes = /* @__PURE__ */ new Map();
60083
60101
  turtleContext.quads = [];
60084
- turtleContext.state = createTurtleParseState();
60102
+ turtleContext.state = createTurtleParseState(text);
60085
60103
  }
60086
60104
  function graphTerm() {
60087
60105
  const graph = turtleContext.state.graph;
@@ -60142,8 +60160,7 @@ function rdfTypeTerm() {
60142
60160
  }
60143
60161
  /** freshBlankNode mints a blank node unique within the current document. */
60144
60162
  function freshBlankNode() {
60145
- turtleContext.state.bnodeCounter += 1;
60146
- return turtleContext.factory.blankNode("b" + turtleContext.state.bnodeCounter);
60163
+ return turtleContext.factory.blankNode(turtleContext.state.nextLabel());
60147
60164
  }
60148
60165
  /** labelledBlankNode builds the blank node of a `_:label` token. */
60149
60166
  function labelledBlankNode(token) {
@@ -69094,8 +69111,9 @@ function parseTurtleDocument(input) {
69094
69111
  * statements carry their named graph; unlabeled triples go to the default
69095
69112
  * graph.
69096
69113
  *
69097
- * Blank nodes are standardized apart per document (a fresh counter per
69098
- * parse), so LOADs of different documents never collide.
69114
+ * Labels are unique within the document only: the counter starts again for each
69115
+ * parse. To store the quads of several documents together, relabel their blank
69116
+ * nodes first, as LOAD does.
69099
69117
  *
69100
69118
  * Parse state lives in the typed `turtleContext` (`turtle-context.ts`), which
69101
69119
  * this function resets before each document; the generated parser reads and
@@ -69107,7 +69125,7 @@ function parseTurtleDocument(input) {
69107
69125
  * @returns the parsed quads, with graph labels preserved
69108
69126
  */
69109
69127
  function parseTurtleQuads(text, baseIri = "") {
69110
- resetTurtleContext(baseIri);
69128
+ resetTurtleContext(baseIri, text);
69111
69129
  parseTurtleDocument(text);
69112
69130
  return turtleContext.quads;
69113
69131
  }
package/dist/parser.d.ts CHANGED
@@ -26,7 +26,7 @@
26
26
  * replacement for the `sparqljs` `Parser` export.
27
27
  */
28
28
  import { A as Quads, B as Triple, C as MinusPattern, D as PathElement, E as Ordering, F as SelectQuery, G as ValuePatternRow, H as UnionPattern, I as SelectSubQuery, J as VariableTerm, K as ValuesPattern, L as ServicePattern, M as Query, N as QueryModifiers, O as Pattern, P as ReifiedQuad, R as SparqlQuery, S as MembershipExpression, T as OptionalPattern, U as UpdateOperation, V as TriplePredicate, W as UpdateQuery, Y as Wildcard, _ as GraphRefAll, a as ClearDropOperation, b as InsertDeleteOperation, c as CreateOperation, d as Expression, f as FilterPattern, g as GraphPattern, h as GraphOrDefault, i as BindPattern, j as QuadsPattern, k as PropertyPath, l as DescribeQuery, m as FunctionCallExpression, n as AskQuery, o as ConstructQuery, p as FromClause, q as VariableExpression, r as BgpPattern, s as CopyMoveOperation, t as AggregateExpression, u as ExistsExpression, v as GroupPattern, w as OperationExpression, x as LoadOperation, y as Grouping, z as Term } from "./ast-CIKmrXH9.js";
29
- import { n as SparqlSyntaxError, t as parseTurtleQuads } from "./turtle-parser-CzWF7KXf.js";
29
+ import { n as SparqlSyntaxError, t as parseTurtleQuads } from "./turtle-parser-G8iweqtS.js";
30
30
  export interface SparqlParserOptions {
31
31
  /** Pre-registered prefixes; the standard `xsd:` prefix is always included. */
32
32
  prefixes?: Record<string, string>;
package/dist/parser.js CHANGED
@@ -1 +1 @@
1
- export { t as Parser, t as SparqlParser, r as SparqlSyntaxError, n as parseTurtleQuads } from "./parser-CTZiNJfu.js";
1
+ export { t as Parser, t as SparqlParser, r as SparqlSyntaxError, n as parseTurtleQuads } from "./parser-BnLGz638.js";
package/dist/store.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { n as MemoryStream, t as MemoryStore } from "./memory-store-DhAGI-j6.js";
1
+ import { n as MemoryStream, t as MemoryStore } from "./memory-store-CeZeEaF3.js";
2
2
  export { MemoryStore, MemoryStream };
package/dist/store.js CHANGED
@@ -1 +1 @@
1
- export { t as MemoryStore, n as MemoryStream } from "./memory-store-Mq4x2Ya1.js";
1
+ export { t as MemoryStore, n as MemoryStream } from "./memory-store-BbPo3tpx.js";
@@ -67,8 +67,9 @@ declare class SparqlSyntaxError extends Error {
67
67
  * statements carry their named graph; unlabeled triples go to the default
68
68
  * graph.
69
69
  *
70
- * Blank nodes are standardized apart per document (a fresh counter per
71
- * parse), so LOADs of different documents never collide.
70
+ * Labels are unique within the document only: the counter starts again for each
71
+ * parse. To store the quads of several documents together, relabel their blank
72
+ * nodes first, as LOAD does.
72
73
  *
73
74
  * Parse state lives in the typed `turtleContext` (`turtle-context.ts`), which
74
75
  * this function resets before each document; the generated parser reads and
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wazootech/sparql-engine",
3
- "version": "0.5.8",
3
+ "version": "0.5.10",
4
4
  "description": "Run SPARQL 1.1 and 1.2 queries and updates over your RDF data in TypeScript, on Node.js, Bun, Deno and in the browser. No WebAssembly, no framework.",
5
5
  "keywords": [
6
6
  "sparql",