@pod-os/core 0.30.0-rc.22aea6d.0 → 0.30.0-rc.68feb28.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.
Files changed (3) hide show
  1. package/dist/index.js +245 -58
  2. package/lib/index.js +245 -58
  3. package/package.json +13 -13
package/dist/index.js CHANGED
@@ -22395,10 +22395,10 @@ function createStatement(kb, id4, property4, value7, base2) {
22395
22395
  return kb.rdfFactory.quad(id4, predicate4, object8, kb.rdfFactory.namedNode(base2));
22396
22396
  }
22397
22397
 
22398
- // ../node_modules/n3/src/N3Lexer.js
22398
+ // node_modules/n3/src/N3Lexer.js
22399
22399
  var import_buffer = __toESM(require_buffer());
22400
22400
 
22401
- // ../node_modules/n3/src/IRIs.js
22401
+ // node_modules/n3/src/IRIs.js
22402
22402
  var RDF2 = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
22403
22403
  var XSD = "http://www.w3.org/2001/XMLSchema#";
22404
22404
  var SWAP = "http://www.w3.org/2000/10/swap/";
@@ -22415,7 +22415,9 @@ var IRIs_default = {
22415
22415
  nil: `${RDF2}nil`,
22416
22416
  first: `${RDF2}first`,
22417
22417
  rest: `${RDF2}rest`,
22418
- langString: `${RDF2}langString`
22418
+ langString: `${RDF2}langString`,
22419
+ dirLangString: `${RDF2}dirLangString`,
22420
+ reifies: `${RDF2}reifies`
22419
22421
  },
22420
22422
  owl: {
22421
22423
  sameAs: "http://www.w3.org/2002/07/owl#sameAs"
@@ -22430,7 +22432,7 @@ var IRIs_default = {
22430
22432
  }
22431
22433
  };
22432
22434
 
22433
- // ../node_modules/n3/src/N3Lexer.js
22435
+ // node_modules/n3/src/N3Lexer.js
22434
22436
  var { xsd } = IRIs_default;
22435
22437
  var escapeSequence = /\\u([a-fA-F0-9]{4})|\\U([a-fA-F0-9]{8})|\\([^])/g;
22436
22438
  var escapeReplacements = {
@@ -22468,6 +22470,7 @@ var lineModeRegExps = {
22468
22470
  _unescapedIri: true,
22469
22471
  _simpleQuotedString: true,
22470
22472
  _langcode: true,
22473
+ _dircode: true,
22471
22474
  _blank: true,
22472
22475
  _newline: true,
22473
22476
  _comment: true,
@@ -22481,15 +22484,16 @@ var N3Lexer = class {
22481
22484
  this._unescapedIri = /^<([^\x00-\x20<>\\"\{\}\|\^\`]*)>[ \t]*/;
22482
22485
  this._simpleQuotedString = /^"([^"\\\r\n]*)"(?=[^"])/;
22483
22486
  this._simpleApostropheString = /^'([^'\\\r\n]*)'(?=[^'])/;
22484
- this._langcode = /^@([a-z]+(?:-[a-z0-9]+)*)(?=[^a-z0-9\-])/i;
22487
+ this._langcode = /^@([a-z]+(?:-[a-z0-9]+)*)(?=[^a-z0-9])/i;
22488
+ this._dircode = /^--(ltr)|(rtl)/;
22485
22489
  this._prefix = /^((?:[A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])(?:\.?[\-0-9A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])*)?:(?=[#\s<])/;
22486
22490
  this._prefixed = /^((?:[A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])(?:\.?[\-0-9A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])*)?:((?:(?:[0-:A-Z_a-z\xc0-\xd6\xd8-\xf6\xf8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff]|%[0-9a-fA-F]{2}|\\[!#-\/;=?\-@_~])(?:(?:[\.\-0-:A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff]|%[0-9a-fA-F]{2}|\\[!#-\/;=?\-@_~])*(?:[\-0-:A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff]|%[0-9a-fA-F]{2}|\\[!#-\/;=?\-@_~]))?)?)(?:[ \t]+|(?=\.?[,;!\^\s#()\[\]\{\}"'<>]))/;
22487
22491
  this._variable = /^\?(?:(?:[A-Z_a-z\xc0-\xd6\xd8-\xf6\xf8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])(?:[\-0-:A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])*)(?=[.,;!\^\s#()\[\]\{\}"'<>])/;
22488
22492
  this._blank = /^_:((?:[0-9A-Z_a-z\xc0-\xd6\xd8-\xf6\xf8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])(?:\.?[\-0-9A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])*)(?:[ \t]+|(?=\.?[,;:\s#()\[\]\{\}"'<>]))/;
22489
22493
  this._number = /^[\-+]?(?:(\d+\.\d*|\.?\d+)[eE][\-+]?|\d*(\.)?)\d+(?=\.?[,;:\s#()\[\]\{\}"'<>])/;
22490
22494
  this._boolean = /^(?:true|false)(?=[.,;\s#()\[\]\{\}"'<>])/;
22491
- this._keyword = /^@[a-z]+(?=[\s#<:])/i;
22492
- this._sparqlKeyword = /^(?:PREFIX|BASE|GRAPH)(?=[\s#<])/i;
22495
+ this._atKeyword = /^@[a-z]+(?=[\s#<:])/i;
22496
+ this._keyword = /^(?:PREFIX|BASE|VERSION|GRAPH)(?=[\s#<])/i;
22493
22497
  this._shortPredicates = /^a(?=[\s#()\[\]\{\}"'<>])/;
22494
22498
  this._newline = /^[ \t]*(?:#[^\n\r]*)?(?:\r\n|\n|\r)[ \t]*/;
22495
22499
  this._comment = /#([^\n\r]*)/;
@@ -22563,7 +22567,9 @@ var N3Lexer = class {
22563
22567
  if (value7 === null || illegalIriChars.test(value7))
22564
22568
  return reportSyntaxError(this);
22565
22569
  type5 = "IRI";
22566
- } else if (input2.length > 1 && input2[1] === "<")
22570
+ } else if (input2.length > 2 && input2[1] === "<" && input2[2] === "(")
22571
+ type5 = "<<(", matchLength = 3;
22572
+ else if (!this._lineMode && input2.length > (inputFinished ? 1 : 2) && input2[1] === "<")
22567
22573
  type5 = "<<", matchLength = 2;
22568
22574
  else if (this._n3Mode && input2.length > 1 && input2[1] === "=") {
22569
22575
  matchLength = 2;
@@ -22612,9 +22618,9 @@ var N3Lexer = class {
22612
22618
  type5 = "var", value7 = match[0];
22613
22619
  break;
22614
22620
  case "@":
22615
- if (this._previousMarker === "literal" && (match = this._langcode.exec(input2)))
22621
+ if (this._previousMarker === "literal" && (match = this._langcode.exec(input2)) && match[1] !== "version")
22616
22622
  type5 = "langcode", value7 = match[1];
22617
- else if (match = this._keyword.exec(input2))
22623
+ else if (match = this._atKeyword.exec(input2))
22618
22624
  type5 = match[0];
22619
22625
  break;
22620
22626
  case ".":
@@ -22636,6 +22642,11 @@ var N3Lexer = class {
22636
22642
  case "9":
22637
22643
  case "+":
22638
22644
  case "-":
22645
+ if (input2[1] === "-") {
22646
+ if (this._previousMarker === "langcode" && (match = this._dircode.exec(input2)))
22647
+ type5 = "dircode", matchLength = 2, value7 = match[1] || match[2], matchLength = value7.length + 2;
22648
+ break;
22649
+ }
22639
22650
  if (match = this._number.exec(input2) || inputFinished && (match = this._number.exec(`${input2} `))) {
22640
22651
  type5 = "literal", value7 = match[0];
22641
22652
  prefix3 = typeof match[1] === "string" ? xsd.double : typeof match[2] === "string" ? xsd.decimal : xsd.integer;
@@ -22647,7 +22658,9 @@ var N3Lexer = class {
22647
22658
  case "P":
22648
22659
  case "G":
22649
22660
  case "g":
22650
- if (match = this._sparqlKeyword.exec(input2))
22661
+ case "V":
22662
+ case "v":
22663
+ if (match = this._keyword.exec(input2))
22651
22664
  type5 = match[0].toUpperCase();
22652
22665
  else
22653
22666
  inconclusive = true;
@@ -22677,13 +22690,21 @@ var N3Lexer = class {
22677
22690
  case "!":
22678
22691
  if (!this._n3Mode)
22679
22692
  break;
22693
+ case ")":
22694
+ if (!inputFinished && (input2.length === 1 || input2.length === 2 && input2[1] === ">")) {
22695
+ break;
22696
+ }
22697
+ if (input2.length > 2 && input2[1] === ">" && input2[2] === ">") {
22698
+ type5 = ")>>", matchLength = 3;
22699
+ break;
22700
+ }
22680
22701
  case ",":
22681
22702
  case ";":
22682
22703
  case "[":
22683
22704
  case "]":
22684
22705
  case "(":
22685
- case ")":
22686
22706
  case "}":
22707
+ case "~":
22687
22708
  if (!this._lineMode) {
22688
22709
  matchLength = 1;
22689
22710
  type5 = firstChar;
@@ -22848,7 +22869,7 @@ var N3Lexer = class {
22848
22869
  }
22849
22870
  };
22850
22871
 
22851
- // ../node_modules/n3/src/N3DataFactory.js
22872
+ // node_modules/n3/src/N3DataFactory.js
22852
22873
  var { rdf: rdf2, xsd: xsd2 } = IRIs_default;
22853
22874
  var DEFAULTGRAPH;
22854
22875
  var _blankNodeCounter = 0;
@@ -22910,7 +22931,15 @@ var Literal2 = class _Literal extends Term {
22910
22931
  get language() {
22911
22932
  const id4 = this.id;
22912
22933
  let atPos = id4.lastIndexOf('"') + 1;
22913
- return atPos < id4.length && id4[atPos++] === "@" ? id4.substr(atPos).toLowerCase() : "";
22934
+ const dirPos = id4.lastIndexOf("--");
22935
+ return atPos < id4.length && id4[atPos++] === "@" ? (dirPos > atPos ? id4.substr(0, dirPos) : id4).substr(atPos).toLowerCase() : "";
22936
+ }
22937
+ // ### The direction of this literal
22938
+ get direction() {
22939
+ const id4 = this.id;
22940
+ const endPos = id4.lastIndexOf('"');
22941
+ const dirPos = id4.lastIndexOf("--");
22942
+ return dirPos > endPos && dirPos + 2 < id4.length ? id4.substr(dirPos + 2).toLowerCase() : "";
22914
22943
  }
22915
22944
  // ### The datatype IRI of this literal
22916
22945
  get datatype() {
@@ -22921,21 +22950,22 @@ var Literal2 = class _Literal extends Term {
22921
22950
  const id4 = this.id, dtPos = id4.lastIndexOf('"') + 1;
22922
22951
  const char = dtPos < id4.length ? id4[dtPos] : "";
22923
22952
  return char === "^" ? id4.substr(dtPos + 2) : (
22924
- // If "@" follows, return rdf:langString; xsd:string otherwise
22925
- char !== "@" ? xsd2.string : rdf2.langString
22953
+ // If "@" follows, return rdf:langString or rdf:dirLangString; xsd:string otherwise
22954
+ char !== "@" ? xsd2.string : id4.indexOf("--", dtPos) > 0 ? rdf2.dirLangString : rdf2.langString
22926
22955
  );
22927
22956
  }
22928
22957
  // ### Returns whether this object represents the same term as the other
22929
22958
  equals(other2) {
22930
22959
  if (other2 instanceof _Literal)
22931
22960
  return this.id === other2.id;
22932
- return !!other2 && !!other2.datatype && this.termType === other2.termType && this.value === other2.value && this.language === other2.language && this.datatype.value === other2.datatype.value;
22961
+ return !!other2 && !!other2.datatype && this.termType === other2.termType && this.value === other2.value && this.language === other2.language && (this.direction === other2.direction || this.direction === "" && !other2.direction) && this.datatype.value === other2.datatype.value;
22933
22962
  }
22934
22963
  toJSON() {
22935
22964
  return {
22936
22965
  termType: this.termType,
22937
22966
  value: this.value,
22938
22967
  language: this.language,
22968
+ direction: this.direction,
22939
22969
  datatype: { termType: "NamedNode", value: this.datatypeString }
22940
22970
  };
22941
22971
  }
@@ -23029,6 +23059,9 @@ function blankNode(name9) {
23029
23059
  function literal(value7, languageOrDataType) {
23030
23060
  if (typeof languageOrDataType === "string")
23031
23061
  return new Literal2(`"${value7}"@${languageOrDataType.toLowerCase()}`);
23062
+ if (languageOrDataType !== void 0 && !("termType" in languageOrDataType)) {
23063
+ return new Literal2(`"${value7}"@${languageOrDataType.language.toLowerCase()}${languageOrDataType.direction ? `--${languageOrDataType.direction.toLowerCase()}` : ""}`);
23064
+ }
23032
23065
  let datatype3 = languageOrDataType ? languageOrDataType.value : "";
23033
23066
  if (datatype3 === "") {
23034
23067
  if (typeof value7 === "boolean")
@@ -23082,9 +23115,9 @@ function fromQuad(inQuad) {
23082
23115
  return quad(fromTerm(inQuad.subject), fromTerm(inQuad.predicate), fromTerm(inQuad.object), fromTerm(inQuad.graph));
23083
23116
  }
23084
23117
 
23085
- // ../node_modules/n3/src/N3Parser.js
23118
+ // node_modules/n3/src/N3Parser.js
23086
23119
  var blankNodePrefix = 0;
23087
- var N3Parser = class {
23120
+ var N3Parser = class _N3Parser {
23088
23121
  constructor(options) {
23089
23122
  this._contextStack = [];
23090
23123
  this._graph = null;
@@ -23096,7 +23129,6 @@ var N3Parser = class {
23096
23129
  this._readPredicateOrNamedGraph = this._readPredicate;
23097
23130
  this._supportsQuads = !(isTurtle || isTriG || isNTriples || isN3);
23098
23131
  this._isImpliedBy = options.isImpliedBy;
23099
- this._supportsRDFStar = format4 === "" || /star|\*$/.test(format4);
23100
23132
  if (isLineMode)
23101
23133
  this._resolveRelativeIRI = (iri) => {
23102
23134
  return null;
@@ -23104,6 +23136,8 @@ var N3Parser = class {
23104
23136
  this._blankNodePrefix = typeof options.blankNodePrefix !== "string" ? "" : options.blankNodePrefix.replace(/^(?!_:)/, "_:");
23105
23137
  this._lexer = options.lexer || new N3Lexer({ lineMode: isLineMode, n3: isN3, isImpliedBy: this._isImpliedBy });
23106
23138
  this._explicitQuantifiers = !!options.explicitQuantifiers;
23139
+ this._parseUnsupportedVersions = !!options.parseUnsupportedVersions;
23140
+ this._version = options.version;
23107
23141
  }
23108
23142
  // ## Static class methods
23109
23143
  // ### `_resetBlankNodePrefix` restarts blank node prefix identification
@@ -23163,6 +23197,12 @@ var N3Parser = class {
23163
23197
  this._quantified = context4.quantified;
23164
23198
  }
23165
23199
  }
23200
+ // ### `_readBeforeTopContext` is called once only at the start of parsing.
23201
+ _readBeforeTopContext(token2) {
23202
+ if (this._version && !this._isValidVersion(this._version))
23203
+ return this._error(`Detected unsupported version as media type parameter: "${this._version}"`, token2);
23204
+ return this._readInTopContext(token2);
23205
+ }
23166
23206
  // ### `_readInTopContext` reads a token when in the top context
23167
23207
  _readInTopContext(token2) {
23168
23208
  switch (token2.type) {
@@ -23182,6 +23222,11 @@ var N3Parser = class {
23182
23222
  this._sparqlStyle = true;
23183
23223
  case "@base":
23184
23224
  return this._readBaseIRI;
23225
+ // It could be a version declaration
23226
+ case "VERSION":
23227
+ this._sparqlStyle = true;
23228
+ case "@version":
23229
+ return this._readVersion;
23185
23230
  // It could be a graph
23186
23231
  case "{":
23187
23232
  if (this._supportsNamedGraphs) {
@@ -23247,6 +23292,10 @@ var N3Parser = class {
23247
23292
  );
23248
23293
  return this._readBlankNodeHead;
23249
23294
  case "(":
23295
+ const stack = this._contextStack, parent4 = stack.length && stack[stack.length - 1];
23296
+ if (parent4.type === "<<") {
23297
+ return this._error("Unexpected list in reified triple", token2);
23298
+ }
23250
23299
  this._saveContext("list", this._graph, this.RDF_NIL, null, null);
23251
23300
  this._subject = null;
23252
23301
  return this._readListItem;
@@ -23286,9 +23335,13 @@ var N3Parser = class {
23286
23335
  } else
23287
23336
  this._subject = this._factory.literal(token2.value, this._factory.namedNode(token2.prefix));
23288
23337
  break;
23338
+ case "<<(":
23339
+ if (!this._n3Mode)
23340
+ return this._error("Disallowed triple term as subject", token2);
23341
+ this._saveContext("<<(", this._graph, null, null, null);
23342
+ this._graph = null;
23343
+ return this._readSubject;
23289
23344
  case "<<":
23290
- if (!this._supportsRDFStar)
23291
- return this._error("Unexpected RDF-star syntax", token2);
23292
23345
  this._saveContext("<<", this._graph, null, null, null);
23293
23346
  this._graph = null;
23294
23347
  return this._readSubject;
@@ -23312,6 +23365,7 @@ var N3Parser = class {
23312
23365
  case ".":
23313
23366
  case "]":
23314
23367
  case "}":
23368
+ case "|}":
23315
23369
  if (this._predicate === null)
23316
23370
  return this._error(`Unexpected ${type5}`, token2);
23317
23371
  this._subject = null;
@@ -23336,6 +23390,7 @@ var N3Parser = class {
23336
23390
  if ((this._predicate = this._readEntity(token2)) === void 0)
23337
23391
  return;
23338
23392
  }
23393
+ this._validAnnotation = true;
23339
23394
  return this._readObject;
23340
23395
  }
23341
23396
  // ### `_readObject` reads a quad's object
@@ -23358,6 +23413,10 @@ var N3Parser = class {
23358
23413
  );
23359
23414
  return this._readBlankNodeHead;
23360
23415
  case "(":
23416
+ const stack = this._contextStack, parent4 = stack.length && stack[stack.length - 1];
23417
+ if (parent4.type === "<<") {
23418
+ return this._error("Unexpected list in reified triple", token2);
23419
+ }
23361
23420
  this._saveContext("list", this._graph, this._subject, this._predicate, this.RDF_NIL);
23362
23421
  this._subject = null;
23363
23422
  return this._readListItem;
@@ -23372,9 +23431,11 @@ var N3Parser = class {
23372
23431
  this._graph = this._factory.blankNode()
23373
23432
  );
23374
23433
  return this._readSubject;
23434
+ case "<<(":
23435
+ this._saveContext("<<(", this._graph, this._subject, this._predicate, null);
23436
+ this._graph = null;
23437
+ return this._readSubject;
23375
23438
  case "<<":
23376
- if (!this._supportsRDFStar)
23377
- return this._error("Unexpected RDF-star syntax", token2);
23378
23439
  this._saveContext("<<", this._graph, this._subject, this._predicate, null);
23379
23440
  this._graph = null;
23380
23441
  return this._readSubject;
@@ -23403,6 +23464,10 @@ var N3Parser = class {
23403
23464
  this._subject = null;
23404
23465
  return this._readBlankNodeTail(token2);
23405
23466
  } else {
23467
+ const stack = this._contextStack, parentParent = stack.length > 1 && stack[stack.length - 2];
23468
+ if (parentParent.type === "<<") {
23469
+ return this._error("Unexpected compound blank node expression in reified triple", token2);
23470
+ }
23406
23471
  this._predicate = null;
23407
23472
  return this._readPredicate(token2);
23408
23473
  }
@@ -23493,12 +23558,19 @@ var N3Parser = class {
23493
23558
  this._graph = this._factory.blankNode()
23494
23559
  );
23495
23560
  return this._readSubject;
23561
+ case "<<":
23562
+ this._saveContext("<<", this._graph, null, null, null);
23563
+ this._graph = null;
23564
+ next4 = this._readSubject;
23565
+ break;
23496
23566
  default:
23497
23567
  if ((item4 = this._readEntity(token2)) === void 0)
23498
23568
  return;
23499
23569
  }
23500
23570
  if (list === null)
23501
23571
  this._subject = list = this._factory.blankNode();
23572
+ if (token2.type === "<<")
23573
+ stack[stack.length - 1].subject = this._subject;
23502
23574
  if (previousList === null) {
23503
23575
  if (parent4.predicate === null)
23504
23576
  parent4.subject = list;
@@ -23526,43 +23598,73 @@ var N3Parser = class {
23526
23598
  return this._completeObjectLiteral(token2, true);
23527
23599
  }
23528
23600
  // ### `_completeLiteral` completes a literal with an optional datatype or language
23529
- _completeLiteral(token2) {
23601
+ _completeLiteral(token2, component2) {
23530
23602
  let literal4 = this._factory.literal(this._literalValue);
23603
+ let readCb;
23531
23604
  switch (token2.type) {
23532
23605
  // Create a datatyped literal
23533
23606
  case "type":
23534
23607
  case "typeIRI":
23535
23608
  const datatype3 = this._readEntity(token2);
23536
23609
  if (datatype3 === void 0) return;
23610
+ if (datatype3.value === IRIs_default.rdf.langString || datatype3.value === IRIs_default.rdf.dirLangString) {
23611
+ return this._error("Detected illegal (directional) languaged-tagged string with explicit datatype", token2);
23612
+ }
23537
23613
  literal4 = this._factory.literal(this._literalValue, datatype3);
23538
23614
  token2 = null;
23539
23615
  break;
23540
23616
  // Create a language-tagged string
23541
23617
  case "langcode":
23618
+ if (token2.value.split("-").some((t) => t.length > 8))
23619
+ return this._error("Detected language tag with subtag longer than 8 characters", token2);
23542
23620
  literal4 = this._factory.literal(this._literalValue, token2.value);
23621
+ this._literalLanguage = token2.value;
23543
23622
  token2 = null;
23623
+ readCb = this._readDirCode.bind(this, component2);
23544
23624
  break;
23545
23625
  }
23546
- return { token: token2, literal: literal4 };
23626
+ return { token: token2, literal: literal4, readCb };
23627
+ }
23628
+ _readDirCode(component2, listItem, token2) {
23629
+ if (token2.type === "dircode") {
23630
+ const term3 = this._factory.literal(this._literalValue, { language: this._literalLanguage, direction: token2.value });
23631
+ if (component2 === "subject")
23632
+ this._subject = term3;
23633
+ else
23634
+ this._object = term3;
23635
+ this._literalLanguage = void 0;
23636
+ token2 = null;
23637
+ }
23638
+ if (component2 === "subject")
23639
+ return token2 === null ? this._readPredicateOrNamedGraph : this._readPredicateOrNamedGraph(token2);
23640
+ return this._completeObjectLiteralPost(token2, listItem);
23547
23641
  }
23548
23642
  // Completes a literal in subject position
23549
23643
  _completeSubjectLiteral(token2) {
23550
- this._subject = this._completeLiteral(token2).literal;
23644
+ const completed2 = this._completeLiteral(token2, "subject");
23645
+ this._subject = completed2.literal;
23646
+ if (completed2.readCb)
23647
+ return completed2.readCb.bind(this, false);
23551
23648
  return this._readPredicateOrNamedGraph;
23552
23649
  }
23553
23650
  // Completes a literal in object position
23554
23651
  _completeObjectLiteral(token2, listItem) {
23555
- const completed2 = this._completeLiteral(token2);
23652
+ const completed2 = this._completeLiteral(token2, "object");
23556
23653
  if (!completed2)
23557
23654
  return;
23558
23655
  this._object = completed2.literal;
23656
+ if (completed2.readCb)
23657
+ return completed2.readCb.bind(this, listItem);
23658
+ return this._completeObjectLiteralPost(completed2.token, listItem);
23659
+ }
23660
+ _completeObjectLiteralPost(token2, listItem) {
23559
23661
  if (listItem)
23560
23662
  this._emit(this._subject, this.RDF_FIRST, this._object, this._graph);
23561
- if (completed2.token === null)
23663
+ if (token2 === null)
23562
23664
  return this._getContextEndReader();
23563
23665
  else {
23564
23666
  this._readCallback = this._getContextEndReader();
23565
- return this._readCallback(completed2.token);
23667
+ return this._readCallback(token2);
23566
23668
  }
23567
23669
  }
23568
23670
  // ### `_readFormulaTail` reads the end of a formula
@@ -23576,7 +23678,7 @@ var N3Parser = class {
23576
23678
  }
23577
23679
  // ### `_readPunctuation` reads punctuation between quads or quad parts
23578
23680
  _readPunctuation(token2) {
23579
- let next4, graph3 = this._graph;
23681
+ let next4, graph3 = this._graph, startingAnnotation = false;
23580
23682
  const subject8 = this._subject, inversePredicate = this._inversePredicate;
23581
23683
  switch (token2.type) {
23582
23684
  // A closing brace ends a graph
@@ -23589,6 +23691,7 @@ var N3Parser = class {
23589
23691
  // A dot just ends the statement, without sharing anything with the next
23590
23692
  case ".":
23591
23693
  this._subject = null;
23694
+ this._tripleTerm = null;
23592
23695
  next4 = this._contextStack.length ? this._readSubject : this._readInTopContext;
23593
23696
  if (inversePredicate) this._inversePredicate = false;
23594
23697
  break;
@@ -23600,19 +23703,26 @@ var N3Parser = class {
23600
23703
  case ",":
23601
23704
  next4 = this._readObject;
23602
23705
  break;
23706
+ // ~ is allowed in the annotation syntax
23707
+ case "~":
23708
+ next4 = this._readReifierInAnnotation;
23709
+ startingAnnotation = true;
23710
+ break;
23603
23711
  // {| means that the current triple is annotated with predicate-object pairs.
23604
23712
  case "{|":
23605
- if (!this._supportsRDFStar)
23606
- return this._error("Unexpected RDF-star syntax", token2);
23607
- const predicate4 = this._predicate, object8 = this._object;
23608
- this._subject = this._factory.quad(subject8, predicate4, object8, this.DEFAULTGRAPH);
23713
+ this._subject = this._readTripleTerm();
23714
+ this._validAnnotation = false;
23715
+ startingAnnotation = true;
23609
23716
  next4 = this._readPredicate;
23610
23717
  break;
23611
- // |} means that the current quoted triple in annotation syntax is finalized.
23718
+ // |} means that the current reified triple in annotation syntax is finalized.
23612
23719
  case "|}":
23613
- if (this._subject.termType !== "Quad")
23614
- return this._error("Unexpected asserted triple closing", token2);
23720
+ if (!this._annotation)
23721
+ return this._error("Unexpected annotation syntax closing", token2);
23722
+ if (!this._validAnnotation)
23723
+ return this._error("Annotation block can not be empty", token2);
23615
23724
  this._subject = null;
23725
+ this._annotation = false;
23616
23726
  next4 = this._readPunctuation;
23617
23727
  break;
23618
23728
  default:
@@ -23622,13 +23732,16 @@ var N3Parser = class {
23622
23732
  }
23623
23733
  return this._error(`Expected punctuation to follow "${this._object.id}"`, token2);
23624
23734
  }
23625
- if (subject8 !== null) {
23735
+ if (subject8 !== null && (!startingAnnotation || startingAnnotation && !this._annotation)) {
23626
23736
  const predicate4 = this._predicate, object8 = this._object;
23627
23737
  if (!inversePredicate)
23628
23738
  this._emit(subject8, predicate4, object8, graph3);
23629
23739
  else
23630
23740
  this._emit(object8, predicate4, subject8, graph3);
23631
23741
  }
23742
+ if (startingAnnotation) {
23743
+ this._annotation = true;
23744
+ }
23632
23745
  return next4;
23633
23746
  }
23634
23747
  // ### `_readBlankNodePunctuation` reads punctuation in a blank node
@@ -23679,6 +23792,21 @@ var N3Parser = class {
23679
23792
  this._setBase(iri);
23680
23793
  return this._readDeclarationPunctuation;
23681
23794
  }
23795
+ // ### `_isValidVersion` checks if the given version is valid for this parser to handle.
23796
+ _isValidVersion(version6) {
23797
+ return this._parseUnsupportedVersions || _N3Parser.SUPPORTED_VERSIONS.includes(version6);
23798
+ }
23799
+ // ### `_readVersion` reads version string declaration
23800
+ _readVersion(token2) {
23801
+ if (token2.type !== "literal")
23802
+ return this._error("Expected literal to follow version declaration", token2);
23803
+ if (token2.end - token2.start !== token2.value.length + 2)
23804
+ return this._error("Version declarations must use single quotes", token2);
23805
+ this._versionCallback(token2.value);
23806
+ if (!this._isValidVersion(token2.value))
23807
+ return this._error(`Detected unsupported version: "${token2.value}"`, token2);
23808
+ return this._readDeclarationPunctuation;
23809
+ }
23682
23810
  // ### `_readNamedGraphLabel` reads the label of a named graph
23683
23811
  _readNamedGraphLabel(token2) {
23684
23812
  switch (token2.type) {
@@ -23805,26 +23933,17 @@ var N3Parser = class {
23805
23933
  this._emit(subject8, predicate4, object8, this._graph);
23806
23934
  return this._readPath;
23807
23935
  }
23808
- // ### `_readRDFStarTailOrGraph` reads the graph of a nested RDF-star quad or the end of a nested RDF-star triple
23809
- _readRDFStarTailOrGraph(token2) {
23810
- if (token2.type !== ">>") {
23811
- if (this._supportsQuads && this._graph === null && (this._graph = this._readEntity(token2)) !== void 0)
23812
- return this._readRDFStarTail;
23813
- return this._error(`Expected >> to follow "${this._object.id}"`, token2);
23814
- }
23815
- return this._readRDFStarTail(token2);
23816
- }
23817
- // ### `_readRDFStarTail` reads the end of a nested RDF-star triple
23818
- _readRDFStarTail(token2) {
23819
- if (token2.type !== ">>")
23820
- return this._error(`Expected >> but got ${token2.type}`, token2);
23936
+ // ### `_readTripleTermTail` reads the end of a triple term
23937
+ _readTripleTermTail(token2) {
23938
+ if (token2.type !== ")>>")
23939
+ return this._error(`Expected )>> but got ${token2.type}`, token2);
23821
23940
  const quad3 = this._factory.quad(
23822
23941
  this._subject,
23823
23942
  this._predicate,
23824
23943
  this._object,
23825
23944
  this._graph || this.DEFAULTGRAPH
23826
23945
  );
23827
- this._restoreContext("<<", token2);
23946
+ this._restoreContext("<<(", token2);
23828
23947
  if (this._subject === null) {
23829
23948
  this._subject = quad3;
23830
23949
  return this._readPredicate;
@@ -23833,6 +23952,63 @@ var N3Parser = class {
23833
23952
  return this._getContextEndReader();
23834
23953
  }
23835
23954
  }
23955
+ // ### `_readReifiedTripleTailOrReifier` reads a reifier or the end of a nested reified triple
23956
+ _readReifiedTripleTailOrReifier(token2) {
23957
+ if (token2.type === "~") {
23958
+ return this._readReifier;
23959
+ }
23960
+ return this._readReifiedTripleTail(token2);
23961
+ }
23962
+ // ### `_readReifiedTripleTail` reads the end of a nested reified triple
23963
+ _readReifiedTripleTail(token2) {
23964
+ if (token2.type !== ">>")
23965
+ return this._error(`Expected >> but got ${token2.type}`, token2);
23966
+ this._tripleTerm = null;
23967
+ const reifier = this._readTripleTerm();
23968
+ this._restoreContext("<<", token2);
23969
+ const stack = this._contextStack, parent4 = stack.length && stack[stack.length - 1];
23970
+ if (parent4 && parent4.type === "list") {
23971
+ this._emit(this._subject, this.RDF_FIRST, reifier, this._graph);
23972
+ return this._getContextEndReader();
23973
+ } else if (this._subject === null) {
23974
+ this._subject = reifier;
23975
+ return this._readPredicateOrReifierTripleEnd;
23976
+ } else {
23977
+ this._object = reifier;
23978
+ return this._getContextEndReader();
23979
+ }
23980
+ }
23981
+ _readPredicateOrReifierTripleEnd(token2) {
23982
+ if (token2.type === ".") {
23983
+ this._subject = null;
23984
+ return this._readPunctuation(token2);
23985
+ }
23986
+ return this._readPredicate(token2);
23987
+ }
23988
+ // ### `_readReifier` reads the triple term identifier after a tilde when in a reifying triple.
23989
+ _readReifier(token2) {
23990
+ this._reifier = this._readEntity(token2);
23991
+ return this._readReifiedTripleTail;
23992
+ }
23993
+ // ### `_readReifier` reads the optional triple term identifier after a tilde when in annotation syntax.
23994
+ _readReifierInAnnotation(token2) {
23995
+ if (token2.type === "IRI" || token2.type === "typeIRI" || token2.type === "type" || token2.type === "prefixed" || token2.type === "blank" || token2.type === "var") {
23996
+ this._reifier = this._readEntity(token2);
23997
+ return this._readPunctuation;
23998
+ }
23999
+ this._readTripleTerm();
24000
+ this._subject = null;
24001
+ return this._readPunctuation(token2);
24002
+ }
24003
+ _readTripleTerm() {
24004
+ const stack = this._contextStack, parent4 = stack.length && stack[stack.length - 1];
24005
+ const parentGraph = parent4 ? parent4.graph : void 0;
24006
+ const reifier = this._reifier || this._factory.blankNode();
24007
+ this._reifier = null;
24008
+ this._tripleTerm = this._tripleTerm || this._factory.quad(this._subject, this._predicate, this._object);
24009
+ this._emit(reifier, this.RDF_REIFIES, this._tripleTerm, parentGraph || this.DEFAULTGRAPH);
24010
+ return reifier;
24011
+ }
23836
24012
  // ### `_getContextEndReader` gets the next reader function at the end of a context
23837
24013
  _getContextEndReader() {
23838
24014
  const contextStack = this._contextStack;
@@ -23845,8 +24021,10 @@ var N3Parser = class {
23845
24021
  return this._readListItem;
23846
24022
  case "formula":
23847
24023
  return this._readFormulaTail;
24024
+ case "<<(":
24025
+ return this._readTripleTermTail;
23848
24026
  case "<<":
23849
- return this._readRDFStarTailOrGraph;
24027
+ return this._readReifiedTripleTailOrReifier;
23850
24028
  }
23851
24029
  }
23852
24030
  // ### `_emit` sends a quad through the callback
@@ -23944,21 +24122,24 @@ var N3Parser = class {
23944
24122
  }
23945
24123
  // ## Public methods
23946
24124
  // ### `parse` parses the N3 input and emits each parsed quad through the onQuad callback.
23947
- parse(input2, quadCallback, prefixCallback) {
23948
- let onQuad, onPrefix, onComment;
23949
- if (quadCallback && (quadCallback.onQuad || quadCallback.onPrefix || quadCallback.onComment)) {
24125
+ parse(input2, quadCallback, prefixCallback, versionCallback) {
24126
+ let onQuad, onPrefix, onComment, onVersion;
24127
+ if (quadCallback && (quadCallback.onQuad || quadCallback.onPrefix || quadCallback.onComment || quadCallback.onVersion)) {
23950
24128
  onQuad = quadCallback.onQuad;
23951
24129
  onPrefix = quadCallback.onPrefix;
23952
24130
  onComment = quadCallback.onComment;
24131
+ onVersion = quadCallback.onVersion;
23953
24132
  } else {
23954
24133
  onQuad = quadCallback;
23955
24134
  onPrefix = prefixCallback;
24135
+ onVersion = versionCallback;
23956
24136
  }
23957
- this._readCallback = this._readInTopContext;
24137
+ this._readCallback = this._readBeforeTopContext;
23958
24138
  this._sparqlStyle = false;
23959
24139
  this._prefixes = /* @__PURE__ */ Object.create(null);
23960
24140
  this._prefixes._ = this._blankNodePrefix ? this._blankNodePrefix.substr(2) : `b${blankNodePrefix++}_`;
23961
24141
  this._prefixCallback = onPrefix || noop2;
24142
+ this._versionCallback = onVersion || noop2;
23962
24143
  this._inversePredicate = false;
23963
24144
  this._quantified = /* @__PURE__ */ Object.create(null);
23964
24145
  if (!onQuad) {
@@ -24004,6 +24185,7 @@ function initDataFactory(parser, factory) {
24004
24185
  parser.RDF_FIRST = factory.namedNode(IRIs_default.rdf.first);
24005
24186
  parser.RDF_REST = factory.namedNode(IRIs_default.rdf.rest);
24006
24187
  parser.RDF_NIL = factory.namedNode(IRIs_default.rdf.nil);
24188
+ parser.RDF_REIFIES = factory.namedNode(IRIs_default.rdf.reifies);
24007
24189
  parser.N3_FORALL = factory.namedNode(IRIs_default.r.forAll);
24008
24190
  parser.N3_FORSOME = factory.namedNode(IRIs_default.r.forSome);
24009
24191
  parser.ABBREVIATIONS = {
@@ -24014,6 +24196,11 @@ function initDataFactory(parser, factory) {
24014
24196
  };
24015
24197
  parser.QUANTIFIERS_GRAPH = factory.namedNode("urn:n3:quantifiers");
24016
24198
  }
24199
+ N3Parser.SUPPORTED_VERSIONS = [
24200
+ "1.2",
24201
+ "1.2-basic",
24202
+ "1.1"
24203
+ ];
24017
24204
  initDataFactory(N3Parser.prototype, N3DataFactory_default);
24018
24205
 
24019
24206
  // node_modules/rdflib/esm/rdfaparser.js