@traqula/generator-sparql-1-2 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 +104 -41
  2. package/package.json +8 -8
package/lib/index.cjs CHANGED
@@ -9674,58 +9674,115 @@ function createToken2(config) {
9674
9674
  return createToken(config);
9675
9675
  }
9676
9676
 
9677
- // ../../packages/core/lib/Transformer.ts
9678
- var Transformer = class {
9679
- transformNode(curObject, searchType, patch) {
9680
- const copy3 = { ...curObject };
9681
- for (const [key, value] of Object.entries(copy3)) {
9682
- copy3[key] = this.safeObjectVisit(value, (obj) => this.transformNode(obj, searchType, patch));
9683
- }
9684
- if (copy3.type === searchType) {
9685
- return patch(copy3);
9677
+ // ../../packages/core/lib/Transformers.ts
9678
+ var TransformerType = class {
9679
+ safeObjectVisit(value, mapper) {
9680
+ if (value && typeof value === "object") {
9681
+ if (Array.isArray(value)) {
9682
+ return value.map((x) => this.safeObjectVisit(x, mapper));
9683
+ }
9684
+ return mapper(value);
9686
9685
  }
9687
- return copy3;
9686
+ return value;
9688
9687
  }
9689
- transformNodeSpecific(curObject, searchType, searchSubType, patch) {
9688
+ transformNode(curObject, nodeCallBacks) {
9689
+ let continueCheck;
9690
+ let transformation;
9691
+ const casted = curObject;
9692
+ if (casted.type) {
9693
+ continueCheck = nodeCallBacks[casted.type]?.continue;
9694
+ transformation = nodeCallBacks[casted.type]?.transform;
9695
+ }
9696
+ let shouldContinue = true;
9697
+ if (continueCheck) {
9698
+ shouldContinue = continueCheck(curObject);
9699
+ }
9700
+ if (!shouldContinue) {
9701
+ return curObject;
9702
+ }
9690
9703
  const copy3 = { ...curObject };
9691
9704
  for (const [key, value] of Object.entries(copy3)) {
9692
- copy3[key] = this.safeObjectVisit(value, (obj) => this.transformNodeSpecific(obj, searchType, searchSubType, patch));
9705
+ copy3[key] = this.safeObjectVisit(value, (obj) => this.transformNode(obj, nodeCallBacks));
9693
9706
  }
9694
- if (copy3.type === searchType && copy3.subType === searchSubType) {
9695
- return patch(copy3);
9707
+ if (transformation) {
9708
+ return transformation(copy3);
9696
9709
  }
9697
9710
  return copy3;
9698
9711
  }
9699
- visitObjects(curObject, visitor) {
9700
- for (const value of Object.values(curObject)) {
9701
- this.safeObjectVisit(value, (obj) => this.visitObjects(obj, visitor));
9712
+ visitNode(curObject, nodeCallBacks) {
9713
+ let callback;
9714
+ const casted = curObject;
9715
+ if (casted.type) {
9716
+ callback = nodeCallBacks[casted.type];
9702
9717
  }
9703
- }
9704
- visitNode(curObject, searchType, visitor) {
9705
- for (const value of Object.values(curObject)) {
9706
- this.safeObjectVisit(value, (obj) => this.visitNode(obj, searchType, visitor));
9718
+ let shouldIterate = true;
9719
+ if (callback) {
9720
+ shouldIterate = callback(curObject);
9707
9721
  }
9708
- if (curObject.type === searchType) {
9709
- visitor(curObject);
9722
+ if (shouldIterate) {
9723
+ for (const value of Object.values(curObject)) {
9724
+ this.safeObjectVisit(value, (obj) => this.visitNode(obj, nodeCallBacks));
9725
+ }
9710
9726
  }
9711
9727
  }
9712
- visitNodeSpecific(curObject, searchType, searchSubType, visitor) {
9713
- for (const value of Object.values(curObject)) {
9714
- this.safeObjectVisit(value, (obj) => this.visitNodeSpecific(obj, searchType, searchSubType, visitor));
9728
+ };
9729
+ var TransformerSubType = class extends TransformerType {
9730
+ // Public visitObjects(curObject: object, visitor: (current: object) => void): void {
9731
+ // for (const value of Object.values(curObject)) {
9732
+ // this.safeObjectVisit(value, obj => this.visitObjects(obj, visitor));
9733
+ // }
9734
+ // }
9735
+ transformNodeSpecific(curObject, nodeCallBacks, nodeSpecificCallBacks = {}) {
9736
+ let continueCheck;
9737
+ let transformation;
9738
+ const casted = curObject;
9739
+ if (casted.type && casted.subType) {
9740
+ const specific = nodeSpecificCallBacks[casted.type];
9741
+ if (specific) {
9742
+ continueCheck = specific[casted.subType]?.continue;
9743
+ transformation = specific[casted.subType]?.transform;
9744
+ }
9715
9745
  }
9716
- const cast = curObject;
9717
- if (cast.type === searchType && cast.subType === searchSubType) {
9718
- visitor(curObject);
9746
+ let shouldContinue = true;
9747
+ if (continueCheck) {
9748
+ shouldContinue = continueCheck(curObject);
9719
9749
  }
9750
+ if (!shouldContinue) {
9751
+ return curObject;
9752
+ }
9753
+ const copy3 = { ...curObject };
9754
+ for (const [key, value] of Object.entries(copy3)) {
9755
+ copy3[key] = this.safeObjectVisit(value, (obj) => this.transformNodeSpecific(obj, nodeCallBacks, nodeSpecificCallBacks));
9756
+ }
9757
+ if (transformation) {
9758
+ return transformation(copy3);
9759
+ }
9760
+ return copy3;
9720
9761
  }
9721
- safeObjectVisit(value, mapper) {
9722
- if (value && typeof value === "object") {
9723
- if (Array.isArray(value)) {
9724
- return value.map((x) => this.safeObjectVisit(x, mapper));
9762
+ /**
9763
+ * When both nodeCallBack and NodeSpecific callBack are matched, will only look at nodeSpecifCallback
9764
+ */
9765
+ visitNodeSpecific(curObject, nodeCallBacks, nodeSpecificCallBacks = {}) {
9766
+ let callback;
9767
+ const casted = curObject;
9768
+ if (casted.type && casted.subType) {
9769
+ const specific = nodeSpecificCallBacks[casted.type];
9770
+ if (specific) {
9771
+ callback = specific[casted.subType];
9772
+ }
9773
+ }
9774
+ if (!callback && casted.type) {
9775
+ callback = nodeCallBacks[curObject.type];
9776
+ }
9777
+ let shouldIterate = true;
9778
+ if (callback) {
9779
+ shouldIterate = callback(curObject) ?? true;
9780
+ }
9781
+ if (shouldIterate) {
9782
+ for (const value of Object.values(curObject)) {
9783
+ this.safeObjectVisit(value, (obj) => this.visitNodeSpecific(obj, nodeCallBacks, nodeSpecificCallBacks));
9725
9784
  }
9726
- return mapper(value);
9727
9785
  }
9728
- return value;
9729
9786
  }
9730
9787
  };
9731
9788
 
@@ -11375,9 +11432,13 @@ var Factory = class extends asArg(CoreFactory).call(ContextFactoryMixin).call(Ex
11375
11432
  }
11376
11433
  };
11377
11434
 
11435
+ // ../../packages/rules-sparql-1-1/lib/utils.ts
11436
+ var TransformerSparql11 = class extends TransformerSubType {
11437
+ };
11438
+
11378
11439
  // ../../packages/rules-sparql-1-1/lib/validation/validators.ts
11379
11440
  var F = new Factory();
11380
- var transformer = new Transformer();
11441
+ var transformer = new TransformerSparql11();
11381
11442
  function getAggregatesOfExpression(expression2) {
11382
11443
  if (F.isExpressionAggregate(expression2)) {
11383
11444
  return [expression2];
@@ -11526,7 +11587,9 @@ function checkNote13(patterns) {
11526
11587
  if (F.isPatternBind(pattern) && index > 0 && F.isPatternBgp(patterns[index - 1])) {
11527
11588
  const bgp = patterns[index - 1];
11528
11589
  const variables = [];
11529
- transformer.visitNodeSpecific(bgp, "term", "variable", (var_2) => variables.push(var_2));
11590
+ transformer.visitNodeSpecific(bgp, {}, { term: { variable: (var_2) => {
11591
+ variables.push(var_2);
11592
+ } } });
11530
11593
  if (variables.some((var_2) => var_2.value === pattern.variable.value)) {
11531
11594
  throw new Error(`Variable used to bind is already bound (?${pattern.variable.value})`);
11532
11595
  }
@@ -11552,12 +11615,12 @@ function updateNoReuseBlankNodeLabels(updateQuery) {
11552
11615
  const operation = update2.operation;
11553
11616
  if (operation.subType === "insertdata") {
11554
11617
  const blankNodesHere = /* @__PURE__ */ new Set();
11555
- transformer.visitNodeSpecific(operation, "term", "blankNode", (blankNode2) => {
11618
+ transformer.visitNodeSpecific(operation, {}, { term: { blankNode: (blankNode2) => {
11556
11619
  blankNodesHere.add(blankNode2.label);
11557
11620
  if (blankLabelsUsedInInsertData.has(blankNode2.label)) {
11558
11621
  throw new Error("Detected reuse blank node across different INSERT DATA clauses");
11559
11622
  }
11560
- });
11623
+ } } });
11561
11624
  for (const blankNode2 of blankNodesHere) {
11562
11625
  blankLabelsUsedInInsertData.add(blankNode2);
11563
11626
  }
@@ -12392,7 +12455,7 @@ var aggregate = {
12392
12455
  },
12393
12456
  gImpl: ({ SUBRULE, PRINT_WORD }) => (ast, { factory: F3 }) => {
12394
12457
  F3.printFilter(ast, () => {
12395
- PRINT_WORD(ast.aggregation, "(");
12458
+ PRINT_WORD(ast.aggregation.toUpperCase(), "(");
12396
12459
  if (ast.distinct) {
12397
12460
  PRINT_WORD("DISTINCT");
12398
12461
  }
@@ -14856,7 +14919,7 @@ var sparql12LexerBuilder = LexerBuilder.create(lexer_exports.sparql11LexerBuilde
14856
14919
  buildInOBJECT
14857
14920
  ).addBefore(lexer_exports.terminals.langTag, LANG_DIR).delete(lexer_exports.terminals.langTag);
14858
14921
 
14859
- // ../../packages/rules-sparql-1-2/lib/validator.ts
14922
+ // ../../packages/rules-sparql-1-2/lib/validators.ts
14860
14923
  var F2 = new Factory();
14861
14924
  function isLangDir(dir) {
14862
14925
  return dir === "ltr" || dir === "rtl";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@traqula/generator-sparql-1-2",
3
3
  "type": "module",
4
- "version": "0.0.9",
4
+ "version": "0.0.12",
5
5
  "description": "SPARQL 1.2 generator",
6
6
  "lsd:module": true,
7
7
  "license": "MIT",
@@ -41,14 +41,14 @@
41
41
  "build:transpile": " node \"../../node_modules/esbuild/bin/esbuild\" --format=cjs --bundle --log-level=error --outfile=lib/index.cjs lib/index.ts"
42
42
  },
43
43
  "dependencies": {
44
- "@traqula/core": "^0.0.9",
45
- "@traqula/generator-sparql-1-1": "^0.0.9",
46
- "@traqula/rules-sparql-1-1": "^0.0.9",
47
- "@traqula/rules-sparql-1-2": "^0.0.9"
44
+ "@traqula/core": "^0.0.12",
45
+ "@traqula/generator-sparql-1-1": "^0.0.12",
46
+ "@traqula/rules-sparql-1-1": "^0.0.12",
47
+ "@traqula/rules-sparql-1-2": "^0.0.12"
48
48
  },
49
49
  "devDependencies": {
50
- "@traqula/parser-sparql-1-2": "^0.0.9",
51
- "@traqula/test-utils": "^0.0.9"
50
+ "@traqula/parser-sparql-1-2": "^0.0.12",
51
+ "@traqula/test-utils": "^0.0.12"
52
52
  },
53
- "gitHead": "c13cd255122c688daad98bf313a3397cbffdc45d"
53
+ "gitHead": "3517d5a5223c64dc61184b5f603f6d98c12bd166"
54
54
  }