n3 2.2.6 → 2.2.7

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/lib/N3Parser.js CHANGED
@@ -1093,7 +1093,10 @@ class N3Parser {
1093
1093
 
1094
1094
  // ### `_error` emits an error message through the callback
1095
1095
  _error(message, token) {
1096
- const err = new Error(`${message} on line ${token.line}.`);
1096
+ // Bound input-derived content while preserving the line suffix and full token context.
1097
+ const suffix = ` on line ${token.line}.`;
1098
+ if (message.length + suffix.length > 200) message = `${message.slice(0, 199 - suffix.length)}…`;
1099
+ const err = new Error(`${message}${suffix}`);
1097
1100
  err.context = {
1098
1101
  token: token,
1099
1102
  line: token.line,
package/lib/N3Store.js CHANGED
@@ -14,6 +14,11 @@ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r
14
14
  // **N3Store** objects store N3 quads by graph in memory.
15
15
 
16
16
  const ITERATOR = Symbol('iter');
17
+ function hasInIndex(index0, key0, key1, key2) {
18
+ const index1 = index0 && index0[key0];
19
+ const index2 = index1 && index1[key1];
20
+ return !!index2 && key2 in index2;
21
+ }
17
22
  function merge(target, source, depth = 4) {
18
23
  if (depth === 0) return Object.assign(target, source);
19
24
  for (const key in source) target[key] = merge(target[key] || Object.create(null), source[key], depth - 1);
@@ -404,6 +409,15 @@ class N3Store {
404
409
  object,
405
410
  graph
406
411
  } = subjectOrQuad);
412
+ // Fully bound quads can bypass the generator machinery of `readQuads`.
413
+ if (subjectOrQuad && predicate && object && graph !== undefined && graph !== null) {
414
+ const subjectId = this._termToNumericId(subjectOrQuad);
415
+ const predicateId = this._termToNumericId(predicate);
416
+ const objectId = this._termToNumericId(object);
417
+ const graphId = graph === '' || (0, _N3Util.isDefaultGraph)(graph) ? 1 : this._termToNumericId(graph);
418
+ const graphItem = graphId && this._graphs[graphId];
419
+ return !!subjectId && !!predicateId && !!objectId && !!graphItem && hasInIndex(graphItem.subjects, subjectId, predicateId, objectId);
420
+ }
407
421
  return !this.readQuads(subjectOrQuad, predicate, object, graph).next().done;
408
422
  }
409
423
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n3",
3
- "version": "2.2.6",
3
+ "version": "2.2.7",
4
4
  "description": "Lightning fast, asynchronous, streaming Turtle / N3 / RDF library.",
5
5
  "author": "Ruben Verborgh <ruben.verborgh@gmail.com>",
6
6
  "keywords": [
package/src/N3Parser.js CHANGED
@@ -1183,7 +1183,11 @@ export default class N3Parser {
1183
1183
 
1184
1184
  // ### `_error` emits an error message through the callback
1185
1185
  _error(message, token) {
1186
- const err = new Error(`${message} on line ${token.line}.`);
1186
+ // Bound input-derived content while preserving the line suffix and full token context.
1187
+ const suffix = ` on line ${token.line}.`;
1188
+ if (message.length + suffix.length > 200)
1189
+ message = `${message.slice(0, 199 - suffix.length)}…`;
1190
+ const err = new Error(`${message}${suffix}`);
1187
1191
  err.context = {
1188
1192
  token: token,
1189
1193
  line: token.line,
package/src/N3Store.js CHANGED
@@ -7,6 +7,12 @@ import N3Writer from './N3Writer';
7
7
 
8
8
  const ITERATOR = Symbol('iter');
9
9
 
10
+ function hasInIndex(index0, key0, key1, key2) {
11
+ const index1 = index0 && index0[key0];
12
+ const index2 = index1 && index1[key1];
13
+ return !!index2 && key2 in index2;
14
+ }
15
+
10
16
  function merge(target, source, depth = 4) {
11
17
  if (depth === 0)
12
18
  return Object.assign(target, source);
@@ -418,6 +424,16 @@ export default class N3Store {
418
424
  has(subjectOrQuad, predicate, object, graph) {
419
425
  if (subjectOrQuad && subjectOrQuad.subject)
420
426
  ({ subject: subjectOrQuad, predicate, object, graph } = subjectOrQuad);
427
+ // Fully bound quads can bypass the generator machinery of `readQuads`.
428
+ if (subjectOrQuad && predicate && object && graph !== undefined && graph !== null) {
429
+ const subjectId = this._termToNumericId(subjectOrQuad);
430
+ const predicateId = this._termToNumericId(predicate);
431
+ const objectId = this._termToNumericId(object);
432
+ const graphId = graph === '' || isDefaultGraph(graph) ? 1 : this._termToNumericId(graph);
433
+ const graphItem = graphId && this._graphs[graphId];
434
+ return !!subjectId && !!predicateId && !!objectId && !!graphItem &&
435
+ hasInIndex(graphItem.subjects, subjectId, predicateId, objectId);
436
+ }
421
437
  return !this.readQuads(subjectOrQuad, predicate, object, graph).next().done;
422
438
  }
423
439