@traqula/parser-sparql-1-1 0.0.9 → 0.0.12

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 (2) hide show
  1. package/lib/index.cjs +124 -63
  2. package/package.json +5 -5
package/lib/index.cjs CHANGED
@@ -9754,58 +9754,115 @@ function createToken2(config) {
9754
9754
  return createToken(config);
9755
9755
  }
9756
9756
 
9757
- // ../../packages/core/lib/Transformer.ts
9758
- var Transformer = class {
9759
- transformNode(curObject, searchType, patch) {
9760
- const copy3 = { ...curObject };
9761
- for (const [key, value] of Object.entries(copy3)) {
9762
- copy3[key] = this.safeObjectVisit(value, (obj) => this.transformNode(obj, searchType, patch));
9763
- }
9764
- if (copy3.type === searchType) {
9765
- return patch(copy3);
9757
+ // ../../packages/core/lib/Transformers.ts
9758
+ var TransformerType = class {
9759
+ safeObjectVisit(value, mapper) {
9760
+ if (value && typeof value === "object") {
9761
+ if (Array.isArray(value)) {
9762
+ return value.map((x) => this.safeObjectVisit(x, mapper));
9763
+ }
9764
+ return mapper(value);
9766
9765
  }
9767
- return copy3;
9766
+ return value;
9768
9767
  }
9769
- transformNodeSpecific(curObject, searchType, searchSubType, patch) {
9768
+ transformNode(curObject, nodeCallBacks) {
9769
+ let continueCheck;
9770
+ let transformation;
9771
+ const casted = curObject;
9772
+ if (casted.type) {
9773
+ continueCheck = nodeCallBacks[casted.type]?.continue;
9774
+ transformation = nodeCallBacks[casted.type]?.transform;
9775
+ }
9776
+ let shouldContinue = true;
9777
+ if (continueCheck) {
9778
+ shouldContinue = continueCheck(curObject);
9779
+ }
9780
+ if (!shouldContinue) {
9781
+ return curObject;
9782
+ }
9770
9783
  const copy3 = { ...curObject };
9771
9784
  for (const [key, value] of Object.entries(copy3)) {
9772
- copy3[key] = this.safeObjectVisit(value, (obj) => this.transformNodeSpecific(obj, searchType, searchSubType, patch));
9785
+ copy3[key] = this.safeObjectVisit(value, (obj) => this.transformNode(obj, nodeCallBacks));
9773
9786
  }
9774
- if (copy3.type === searchType && copy3.subType === searchSubType) {
9775
- return patch(copy3);
9787
+ if (transformation) {
9788
+ return transformation(copy3);
9776
9789
  }
9777
9790
  return copy3;
9778
9791
  }
9779
- visitObjects(curObject, visitor) {
9780
- for (const value of Object.values(curObject)) {
9781
- this.safeObjectVisit(value, (obj) => this.visitObjects(obj, visitor));
9792
+ visitNode(curObject, nodeCallBacks) {
9793
+ let callback;
9794
+ const casted = curObject;
9795
+ if (casted.type) {
9796
+ callback = nodeCallBacks[casted.type];
9782
9797
  }
9783
- }
9784
- visitNode(curObject, searchType, visitor) {
9785
- for (const value of Object.values(curObject)) {
9786
- this.safeObjectVisit(value, (obj) => this.visitNode(obj, searchType, visitor));
9798
+ let shouldIterate = true;
9799
+ if (callback) {
9800
+ shouldIterate = callback(curObject);
9787
9801
  }
9788
- if (curObject.type === searchType) {
9789
- visitor(curObject);
9802
+ if (shouldIterate) {
9803
+ for (const value of Object.values(curObject)) {
9804
+ this.safeObjectVisit(value, (obj) => this.visitNode(obj, nodeCallBacks));
9805
+ }
9790
9806
  }
9791
9807
  }
9792
- visitNodeSpecific(curObject, searchType, searchSubType, visitor) {
9793
- for (const value of Object.values(curObject)) {
9794
- this.safeObjectVisit(value, (obj) => this.visitNodeSpecific(obj, searchType, searchSubType, visitor));
9808
+ };
9809
+ var TransformerSubType = class extends TransformerType {
9810
+ // Public visitObjects(curObject: object, visitor: (current: object) => void): void {
9811
+ // for (const value of Object.values(curObject)) {
9812
+ // this.safeObjectVisit(value, obj => this.visitObjects(obj, visitor));
9813
+ // }
9814
+ // }
9815
+ transformNodeSpecific(curObject, nodeCallBacks, nodeSpecificCallBacks = {}) {
9816
+ let continueCheck;
9817
+ let transformation;
9818
+ const casted = curObject;
9819
+ if (casted.type && casted.subType) {
9820
+ const specific = nodeSpecificCallBacks[casted.type];
9821
+ if (specific) {
9822
+ continueCheck = specific[casted.subType]?.continue;
9823
+ transformation = specific[casted.subType]?.transform;
9824
+ }
9825
+ }
9826
+ let shouldContinue = true;
9827
+ if (continueCheck) {
9828
+ shouldContinue = continueCheck(curObject);
9829
+ }
9830
+ if (!shouldContinue) {
9831
+ return curObject;
9832
+ }
9833
+ const copy3 = { ...curObject };
9834
+ for (const [key, value] of Object.entries(copy3)) {
9835
+ copy3[key] = this.safeObjectVisit(value, (obj) => this.transformNodeSpecific(obj, nodeCallBacks, nodeSpecificCallBacks));
9795
9836
  }
9796
- const cast = curObject;
9797
- if (cast.type === searchType && cast.subType === searchSubType) {
9798
- visitor(curObject);
9837
+ if (transformation) {
9838
+ return transformation(copy3);
9799
9839
  }
9840
+ return copy3;
9800
9841
  }
9801
- safeObjectVisit(value, mapper) {
9802
- if (value && typeof value === "object") {
9803
- if (Array.isArray(value)) {
9804
- return value.map((x) => this.safeObjectVisit(x, mapper));
9842
+ /**
9843
+ * When both nodeCallBack and NodeSpecific callBack are matched, will only look at nodeSpecifCallback
9844
+ */
9845
+ visitNodeSpecific(curObject, nodeCallBacks, nodeSpecificCallBacks = {}) {
9846
+ let callback;
9847
+ const casted = curObject;
9848
+ if (casted.type && casted.subType) {
9849
+ const specific = nodeSpecificCallBacks[casted.type];
9850
+ if (specific) {
9851
+ callback = specific[casted.subType];
9852
+ }
9853
+ }
9854
+ if (!callback && casted.type) {
9855
+ callback = nodeCallBacks[curObject.type];
9856
+ }
9857
+ let shouldIterate = true;
9858
+ if (callback) {
9859
+ shouldIterate = callback(curObject) ?? true;
9860
+ }
9861
+ if (shouldIterate) {
9862
+ for (const value of Object.values(curObject)) {
9863
+ this.safeObjectVisit(value, (obj) => this.visitNodeSpecific(obj, nodeCallBacks, nodeSpecificCallBacks));
9805
9864
  }
9806
- return mapper(value);
9807
9865
  }
9808
- return value;
9809
9866
  }
9810
9867
  };
9811
9868
 
@@ -11455,9 +11512,34 @@ var Factory = class extends asArg(CoreFactory).call(ContextFactoryMixin).call(Ex
11455
11512
  }
11456
11513
  };
11457
11514
 
11515
+ // ../../packages/rules-sparql-1-1/lib/utils.ts
11516
+ function sparqlCodepointEscape(input) {
11517
+ const sanitizedInput = input.replaceAll(
11518
+ /\\u([0-9a-fA-F]{4})|\\U([0-9a-fA-F]{8})/gu,
11519
+ (_, unicode4, unicode8) => {
11520
+ if (unicode4) {
11521
+ const charCode2 = Number.parseInt(unicode4, 16);
11522
+ return String.fromCodePoint(charCode2);
11523
+ }
11524
+ const charCode = Number.parseInt(unicode8, 16);
11525
+ if (charCode < 65535) {
11526
+ return String.fromCodePoint(charCode);
11527
+ }
11528
+ const substractedCharCode = charCode - 65536;
11529
+ return String.fromCodePoint(55296 + (substractedCharCode >> 10), 56320 + (substractedCharCode & 1023));
11530
+ }
11531
+ );
11532
+ if (/[\uD800-\uDBFF](?:[^\uDC00-\uDFFF]|$)/u.test(sanitizedInput)) {
11533
+ throw new Error(`Invalid unicode codepoint of surrogate pair without corresponding codepoint`);
11534
+ }
11535
+ return sanitizedInput;
11536
+ }
11537
+ var TransformerSparql11 = class extends TransformerSubType {
11538
+ };
11539
+
11458
11540
  // ../../packages/rules-sparql-1-1/lib/validation/validators.ts
11459
11541
  var F = new Factory();
11460
- var transformer = new Transformer();
11542
+ var transformer = new TransformerSparql11();
11461
11543
  function getAggregatesOfExpression(expression2) {
11462
11544
  if (F.isExpressionAggregate(expression2)) {
11463
11545
  return [expression2];
@@ -11606,7 +11688,9 @@ function checkNote13(patterns) {
11606
11688
  if (F.isPatternBind(pattern) && index > 0 && F.isPatternBgp(patterns[index - 1])) {
11607
11689
  const bgp = patterns[index - 1];
11608
11690
  const variables = [];
11609
- transformer.visitNodeSpecific(bgp, "term", "variable", (var_2) => variables.push(var_2));
11691
+ transformer.visitNodeSpecific(bgp, {}, { term: { variable: (var_2) => {
11692
+ variables.push(var_2);
11693
+ } } });
11610
11694
  if (variables.some((var_2) => var_2.value === pattern.variable.value)) {
11611
11695
  throw new Error(`Variable used to bind is already bound (?${pattern.variable.value})`);
11612
11696
  }
@@ -11632,12 +11716,12 @@ function updateNoReuseBlankNodeLabels(updateQuery) {
11632
11716
  const operation = update2.operation;
11633
11717
  if (operation.subType === "insertdata") {
11634
11718
  const blankNodesHere = /* @__PURE__ */ new Set();
11635
- transformer.visitNodeSpecific(operation, "term", "blankNode", (blankNode2) => {
11719
+ transformer.visitNodeSpecific(operation, {}, { term: { blankNode: (blankNode2) => {
11636
11720
  blankNodesHere.add(blankNode2.label);
11637
11721
  if (blankLabelsUsedInInsertData.has(blankNode2.label)) {
11638
11722
  throw new Error("Detected reuse blank node across different INSERT DATA clauses");
11639
11723
  }
11640
- });
11724
+ } } });
11641
11725
  for (const blankNode2 of blankNodesHere) {
11642
11726
  blankLabelsUsedInInsertData.add(blankNode2);
11643
11727
  }
@@ -11645,29 +11729,6 @@ function updateNoReuseBlankNodeLabels(updateQuery) {
11645
11729
  }
11646
11730
  }
11647
11731
 
11648
- // ../../packages/rules-sparql-1-1/lib/utils.ts
11649
- function sparqlCodepointEscape(input) {
11650
- const sanitizedInput = input.replaceAll(
11651
- /\\u([0-9a-fA-F]{4})|\\U([0-9a-fA-F]{8})/gu,
11652
- (_, unicode4, unicode8) => {
11653
- if (unicode4) {
11654
- const charCode2 = Number.parseInt(unicode4, 16);
11655
- return String.fromCodePoint(charCode2);
11656
- }
11657
- const charCode = Number.parseInt(unicode8, 16);
11658
- if (charCode < 65535) {
11659
- return String.fromCodePoint(charCode);
11660
- }
11661
- const substractedCharCode = charCode - 65536;
11662
- return String.fromCodePoint(55296 + (substractedCharCode >> 10), 56320 + (substractedCharCode & 1023));
11663
- }
11664
- );
11665
- if (/[\uD800-\uDBFF](?:[^\uDC00-\uDFFF]|$)/u.test(sanitizedInput)) {
11666
- throw new Error(`Invalid unicode codepoint of surrogate pair without corresponding codepoint`);
11667
- }
11668
- return sanitizedInput;
11669
- }
11670
-
11671
11732
  // ../../packages/rules-sparql-1-1/lib/grammar/literals.ts
11672
11733
  function stringEscapedLexical(str2) {
11673
11734
  const lexical = str2.replaceAll(/["\\\t\n\r\b\f]/gu, (char) => {
@@ -12495,7 +12556,7 @@ var aggregate = {
12495
12556
  },
12496
12557
  gImpl: ({ SUBRULE, PRINT_WORD }) => (ast, { factory: F2 }) => {
12497
12558
  F2.printFilter(ast, () => {
12498
- PRINT_WORD(ast.aggregation, "(");
12559
+ PRINT_WORD(ast.aggregation.toUpperCase(), "(");
12499
12560
  if (ast.distinct) {
12500
12561
  PRINT_WORD("DISTINCT");
12501
12562
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@traqula/parser-sparql-1-1",
3
3
  "type": "module",
4
- "version": "0.0.9",
4
+ "version": "0.0.12",
5
5
  "description": "SPARQL 1.1 parser",
6
6
  "lsd:module": true,
7
7
  "license": "MIT",
@@ -49,16 +49,16 @@
49
49
  "spec:earl": "yarn spec:earl:query && yarn spec:earl:update"
50
50
  },
51
51
  "dependencies": {
52
- "@traqula/core": "^0.0.9",
53
- "@traqula/rules-sparql-1-1": "^0.0.9"
52
+ "@traqula/core": "^0.0.12",
53
+ "@traqula/rules-sparql-1-1": "^0.0.12"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@rdfjs/types": "^2.0.0",
57
- "@traqula/test-utils": "^0.0.9",
57
+ "@traqula/test-utils": "^0.0.12",
58
58
  "@types/sparqljs": "^3.1.12",
59
59
  "rdf-data-factory": "^2.0.1",
60
60
  "rdf-test-suite": "^2.0.0",
61
61
  "sparqljs": "^3.7.3"
62
62
  },
63
- "gitHead": "c13cd255122c688daad98bf313a3397cbffdc45d"
63
+ "gitHead": "3517d5a5223c64dc61184b5f603f6d98c12bd166"
64
64
  }