@_linked/core 2.34.0 → 2.35.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 (85) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +24 -0
  3. package/lib/esm/index.d.ts +2 -1
  4. package/lib/esm/index.js +2 -0
  5. package/lib/esm/index.js.map +1 -1
  6. package/lib/esm/live/LiveQueryStore.d.ts +22 -0
  7. package/lib/esm/live/LiveQueryStore.js +86 -19
  8. package/lib/esm/live/LiveQueryStore.js.map +1 -1
  9. package/lib/esm/live/changes.d.ts +9 -1
  10. package/lib/esm/live/changes.js +7 -2
  11. package/lib/esm/live/changes.js.map +1 -1
  12. package/lib/esm/live/keys.d.ts +6 -0
  13. package/lib/esm/live/keys.js +10 -1
  14. package/lib/esm/live/keys.js.map +1 -1
  15. package/lib/esm/live/matcher.d.ts +4 -1
  16. package/lib/esm/live/matcher.js +10 -5
  17. package/lib/esm/live/matcher.js.map +1 -1
  18. package/lib/esm/queries/AskBuilder.d.ts +6 -0
  19. package/lib/esm/queries/AskBuilder.js +14 -0
  20. package/lib/esm/queries/AskBuilder.js.map +1 -1
  21. package/lib/esm/queries/CountBuilder.d.ts +6 -0
  22. package/lib/esm/queries/CountBuilder.js +14 -0
  23. package/lib/esm/queries/CountBuilder.js.map +1 -1
  24. package/lib/esm/queries/CreateBuilder.d.ts +4 -0
  25. package/lib/esm/queries/CreateBuilder.js +15 -1
  26. package/lib/esm/queries/CreateBuilder.js.map +1 -1
  27. package/lib/esm/queries/DeleteBuilder.d.ts +4 -0
  28. package/lib/esm/queries/DeleteBuilder.js +15 -1
  29. package/lib/esm/queries/DeleteBuilder.js.map +1 -1
  30. package/lib/esm/queries/FieldSet.d.ts +10 -0
  31. package/lib/esm/queries/FieldSet.js +85 -18
  32. package/lib/esm/queries/FieldSet.js.map +1 -1
  33. package/lib/esm/queries/IRLower.js +3 -2
  34. package/lib/esm/queries/IRLower.js.map +1 -1
  35. package/lib/esm/queries/IRMutation.js +15 -14
  36. package/lib/esm/queries/IRMutation.js.map +1 -1
  37. package/lib/esm/queries/MutationSerialization.js +2 -2
  38. package/lib/esm/queries/MutationSerialization.js.map +1 -1
  39. package/lib/esm/queries/PropertyPath.js +2 -2
  40. package/lib/esm/queries/PropertyPath.js.map +1 -1
  41. package/lib/esm/queries/QueryBuilder.d.ts +7 -0
  42. package/lib/esm/queries/QueryBuilder.js +40 -3
  43. package/lib/esm/queries/QueryBuilder.js.map +1 -1
  44. package/lib/esm/queries/SelectQuery.js +2 -2
  45. package/lib/esm/queries/SelectQuery.js.map +1 -1
  46. package/lib/esm/queries/UpdateBuilder.d.ts +4 -0
  47. package/lib/esm/queries/UpdateBuilder.js +15 -1
  48. package/lib/esm/queries/UpdateBuilder.js.map +1 -1
  49. package/lib/esm/queries/fromJSON.d.ts +12 -1
  50. package/lib/esm/queries/fromJSON.js +5 -1
  51. package/lib/esm/queries/fromJSON.js.map +1 -1
  52. package/lib/esm/queries/lower.js +12 -5
  53. package/lib/esm/queries/lower.js.map +1 -1
  54. package/lib/esm/queries/queryDependencies.js +14 -10
  55. package/lib/esm/queries/queryDependencies.js.map +1 -1
  56. package/lib/esm/queries/resolveShape.js +14 -2
  57. package/lib/esm/queries/resolveShape.js.map +1 -1
  58. package/lib/esm/shapes/Shape.js +2 -1
  59. package/lib/esm/shapes/Shape.js.map +1 -1
  60. package/lib/esm/shapes/nodeShapeData.js +7 -10
  61. package/lib/esm/shapes/nodeShapeData.js.map +1 -1
  62. package/lib/esm/shapes/registerRuntimeShape.js +3 -1
  63. package/lib/esm/shapes/registerRuntimeShape.js.map +1 -1
  64. package/lib/esm/shapes/syncShapes.d.ts +6 -2
  65. package/lib/esm/shapes/syncShapes.js +16 -9
  66. package/lib/esm/shapes/syncShapes.js.map +1 -1
  67. package/lib/esm/shapes/validation.js +2 -2
  68. package/lib/esm/shapes/validation.js.map +1 -1
  69. package/lib/esm/sparql/irToAlgebra.js +117 -52
  70. package/lib/esm/sparql/irToAlgebra.js.map +1 -1
  71. package/lib/esm/sparql/ownedLinkCheck.js +6 -1
  72. package/lib/esm/sparql/ownedLinkCheck.js.map +1 -1
  73. package/lib/esm/utils/LinkedStorage.d.ts +7 -0
  74. package/lib/esm/utils/LinkedStorage.js +39 -12
  75. package/lib/esm/utils/LinkedStorage.js.map +1 -1
  76. package/lib/esm/utils/ShapeCatalog.d.ts +57 -0
  77. package/lib/esm/utils/ShapeCatalog.js +86 -0
  78. package/lib/esm/utils/ShapeCatalog.js.map +1 -0
  79. package/lib/esm/utils/ShapeClass.d.ts +73 -8
  80. package/lib/esm/utils/ShapeClass.js +245 -66
  81. package/lib/esm/utils/ShapeClass.js.map +1 -1
  82. package/lib/esm/utils/registryCache.d.ts +15 -0
  83. package/lib/esm/utils/registryCache.js +50 -0
  84. package/lib/esm/utils/registryCache.js.map +1 -0
  85. package/package.json +1 -1
@@ -1,3 +1,4 @@
1
+ import { RegistryCache } from '../utils/registryCache.js';
1
2
  import { findPropertyShapeById, getPropertyShapes } from '../shapes/nodeShapeData.js';
2
3
  import { pathExprToSparql, collectPathUris } from '../paths/pathExprToSparql.js';
3
4
  import { generateEntityUri } from './sparqlUtils.js';
@@ -6,8 +7,11 @@ import { rdf } from '../ontologies/rdf.js';
6
7
  import { shacl } from '../ontologies/shacl.js';
7
8
  import { xsd } from '../ontologies/xsd.js';
8
9
  import { getSimplePathId } from '../paths/normalizePropertyPath.js';
9
- import { getAllNodeShapes, getNodeShape, getRegistryVersion, getShapeClass, getSubShapes, getTargetClassId, isSubShapeOf, } from '../utils/ShapeClass.js';
10
+ import { attachCatalog, catalogOf, getActiveShapeCatalog, getAllNodeShapes, getNodeShape, getShapeClass, getSubShapes, getTargetClassId, isSubShapeOf, withShapeCatalog, } from '../utils/ShapeClass.js';
10
11
  import { UnresolvedContextError } from '../queries/QueryContext.js';
12
+ // The `*ToAlgebra` / `*ToSparql` exports compile in the catalog the IR was lowered in (its
13
+ // non-enumerable `catalog` field). An IR without one — built by hand, or copied with a spread,
14
+ // which drops the field — compiles in the active catalog, or globally outside any scope.
11
15
  // ---------------------------------------------------------------------------
12
16
  // Constants
13
17
  // ---------------------------------------------------------------------------
@@ -92,12 +96,11 @@ function resolveShapeScanIri(shapeId) {
92
96
  * better is knowable; the caller passed an id no registered shape declares).
93
97
  */
94
98
  // Memoizes resolved predicate terms across the many call sites that resolve the
95
- // same property. Guarded by the shape-registry size so it self-invalidates when
96
- // new shapes register (e.g. across test-file module instances). Only successful
97
- // resolutions are cached — a not-found fallback is never stored, so a predicate
98
- // resolved before its shape registers can still resolve correctly afterwards.
99
- const predicateTermCache = new Map();
100
- let predicateTermCacheSize = -1;
99
+ // same property. One map per catalog; the global one is rebuilt when the registry
100
+ // version moves. Only successful resolutions are cached — a not-found fallback is never
101
+ // stored, so a predicate resolved before its shape registers can still resolve
102
+ // correctly afterwards.
103
+ const predicateTermCache = new RegistryCache();
101
104
  /**
102
105
  * The `sh:datatype` declared for a property, if any. Lets the serializer emit the
103
106
  * term the shape asks for rather than one inferred from the JavaScript value: a
@@ -109,12 +112,8 @@ function resolvePropertyDatatype(propertyId) {
109
112
  return (_b = (_a = findPropertyShapeById(propertyId)) === null || _a === void 0 ? void 0 : _a.datatype) === null || _b === void 0 ? void 0 : _b.id;
110
113
  }
111
114
  function resolvePropertyPredicateTerm(propertyId) {
112
- const version = getRegistryVersion();
113
- if (version !== predicateTermCacheSize) {
114
- predicateTermCache.clear();
115
- predicateTermCacheSize = version;
116
- }
117
- const cached = predicateTermCache.get(propertyId);
115
+ const cache = predicateTermCache.get();
116
+ const cached = cache.get(propertyId);
118
117
  if (cached)
119
118
  return cached;
120
119
  const propertyShape = findPropertyShapeById(propertyId);
@@ -135,7 +134,7 @@ function resolvePropertyPredicateTerm(propertyId) {
135
134
  uris: collectPathUris(propertyShape.path),
136
135
  };
137
136
  }
138
- predicateTermCache.set(propertyId, term);
137
+ cache.set(propertyId, term);
139
138
  return term;
140
139
  }
141
140
  return iriTerm(propertyId);
@@ -477,6 +476,10 @@ function containsAggregate(expr) {
477
476
  */
478
477
  export function selectToAlgebra(query, _options) {
479
478
  var _a, _b, _c, _d, _e, _f, _g, _h;
479
+ const catalog = catalogOf(query);
480
+ if (catalog !== undefined && catalog !== getActiveShapeCatalog()) {
481
+ return withShapeCatalog(catalog, () => selectToAlgebra(query, _options));
482
+ }
480
483
  const registry = new VariableRegistry();
481
484
  // Promote bindings only when the top-level WHERE would reject rows without
482
485
  // them. This keeps human-like SPARQL for null-rejecting filters without
@@ -1561,6 +1564,10 @@ function generateNodeDataTriples(data, options, blanks, kind = 'iri') {
1561
1564
  * Converts an IRCreateMutation to a SparqlInsertDataPlan.
1562
1565
  */
1563
1566
  export function createToAlgebra(query, options) {
1567
+ const catalog = catalogOf(query);
1568
+ if (catalog !== undefined && catalog !== getActiveShapeCatalog()) {
1569
+ return withShapeCatalog(catalog, () => createToAlgebra(query, options));
1570
+ }
1564
1571
  const { triples } = generateNodeDataTriples(query.data, options, { next: 0 });
1565
1572
  return {
1566
1573
  type: 'insert_data',
@@ -1815,6 +1822,10 @@ function wrapOldValueOptionals(base, oldValueTriples) {
1815
1822
  * Converts an IRUpdateMutation to a SparqlDeleteInsertPlan.
1816
1823
  */
1817
1824
  export function updateToAlgebra(query, options) {
1825
+ const catalog = catalogOf(query);
1826
+ if (catalog !== undefined && catalog !== getActiveShapeCatalog()) {
1827
+ return withShapeCatalog(catalog, () => updateToAlgebra(query, options));
1828
+ }
1818
1829
  return buildDeleteInsertPlan(query, options);
1819
1830
  }
1820
1831
  /**
@@ -1827,6 +1838,10 @@ export function updateToAlgebra(query, options) {
1827
1838
  * needs no guard.
1828
1839
  */
1829
1840
  export function upsertToAlgebra(query, options) {
1841
+ const catalog = catalogOf(query);
1842
+ if (catalog !== undefined && catalog !== getActiveShapeCatalog()) {
1843
+ return withShapeCatalog(catalog, () => upsertToAlgebra(query, options));
1844
+ }
1830
1845
  return buildDeleteInsertPlan(query, options, {
1831
1846
  // Must match the IRI `create` asserts and `select` scans for; the raw shape id is
1832
1847
  // not the same thing, and a node typed with it would be invisible to queries.
@@ -2005,8 +2020,7 @@ function simplePredicates(props) {
2005
2020
  }
2006
2021
  return [...predicates];
2007
2022
  }
2008
- let blankWalkCache = new Map();
2009
- let blankWalkCacheVersion = -1;
2023
+ const blankWalkCache = new RegistryCache();
2010
2024
  /**
2011
2025
  * The predicates the blank-node cascade follows *below* a blank value held by one of `start`:
2012
2026
  * the blank-capable properties of every shape the value (and, transitively, its blank values)
@@ -2017,13 +2031,9 @@ let blankWalkCacheVersion = -1;
2017
2031
  * `buildBlankCascade` refuses any node reached through an IRI.
2018
2032
  */
2019
2033
  function blankWalkPredicates(start) {
2020
- const version = getRegistryVersion();
2021
- if (version !== blankWalkCacheVersion) {
2022
- blankWalkCache = new Map();
2023
- blankWalkCacheVersion = version;
2024
- }
2034
+ const cache = blankWalkCache.get();
2025
2035
  const key = start.map((ps) => ps.id).join('|');
2026
- const cached = blankWalkCache.get(key);
2036
+ const cached = cache.get(key);
2027
2037
  if (cached)
2028
2038
  return cached;
2029
2039
  let everything = false;
@@ -2060,7 +2070,7 @@ function blankWalkPredicates(start) {
2060
2070
  }
2061
2071
  }
2062
2072
  const result = simplePredicates(predicates);
2063
- blankWalkCache.set(key, result);
2073
+ cache.set(key, result);
2064
2074
  return result;
2065
2075
  }
2066
2076
  /** A SPARQL property-path term over `predicates`: `(p1|…|pn)`, then `*` / `+` when given. */
@@ -2203,23 +2213,19 @@ function ownedPredicate(ps) {
2203
2213
  return null;
2204
2214
  return (_b = getSimplePathId(ps.path)) !== null && _b !== void 0 ? _b : null;
2205
2215
  }
2206
- let classHoldersCache = new Map();
2207
- let classHoldersVersion = -1;
2208
- /** Every registered shape id per `targetClass` (memoized per registry version). */
2209
- function classHolders(classId) {
2210
- var _a, _b, _c;
2211
- const version = getRegistryVersion();
2212
- if (version !== classHoldersVersion) {
2213
- classHoldersCache = new Map();
2214
- for (const nodeShape of getAllNodeShapes().values()) {
2215
- const cls = (_a = nodeShape === null || nodeShape === void 0 ? void 0 : nodeShape.targetClass) === null || _a === void 0 ? void 0 : _a.id;
2216
- if (!cls)
2217
- continue;
2218
- classHoldersCache.set(cls, [...((_b = classHoldersCache.get(cls)) !== null && _b !== void 0 ? _b : []), nodeShape.id]);
2219
- }
2220
- classHoldersVersion = version;
2216
+ const classHoldersCache = new RegistryCache((holders) => {
2217
+ var _a, _b;
2218
+ for (const nodeShape of getAllNodeShapes().values()) {
2219
+ const cls = (_a = nodeShape === null || nodeShape === void 0 ? void 0 : nodeShape.targetClass) === null || _a === void 0 ? void 0 : _a.id;
2220
+ if (!cls)
2221
+ continue;
2222
+ holders.set(cls, [...((_b = holders.get(cls)) !== null && _b !== void 0 ? _b : []), nodeShape.id]);
2221
2223
  }
2222
- return (_c = classHoldersCache.get(classId)) !== null && _c !== void 0 ? _c : [];
2224
+ });
2225
+ /** Every registered shape id per `targetClass` (memoized per registry version, or per catalog). */
2226
+ function classHolders(classId) {
2227
+ var _a;
2228
+ return (_a = classHoldersCache.get().get(classId)) !== null && _a !== void 0 ? _a : [];
2223
2229
  }
2224
2230
  /**
2225
2231
  * Why the added `contains` property `ps` of the sub-shape `sub` cannot be followed from nodes of
@@ -2313,8 +2319,7 @@ function shapeClasses(shapeId) {
2313
2319
  }
2314
2320
  return [...classes];
2315
2321
  }
2316
- let ownedWalkCache = new Map();
2317
- let ownedWalkCacheVersion = -1;
2322
+ const ownedWalkCache = new RegistryCache();
2318
2323
  const warnedBranches = new Set();
2319
2324
  /**
2320
2325
  * The owned subtree of a root shape, as hops (memoized per registry version; read-only).
@@ -2326,12 +2331,8 @@ const warnedBranches = new Set();
2326
2331
  * `MAX_OWNED_RECURSION` hops into a shape already on it.
2327
2332
  */
2328
2333
  function ownedWalk(rootShapeId) {
2329
- const version = getRegistryVersion();
2330
- if (version !== ownedWalkCacheVersion) {
2331
- ownedWalkCache = new Map();
2332
- ownedWalkCacheVersion = version;
2333
- }
2334
- const cached = ownedWalkCache.get(rootShapeId);
2334
+ const cache = ownedWalkCache.get();
2335
+ const cached = cache.get(rootShapeId);
2335
2336
  if (cached)
2336
2337
  return cached;
2337
2338
  const edgesOf = new Map();
@@ -2419,7 +2420,7 @@ function ownedWalk(rootShapeId) {
2419
2420
  rootBlankProps: blankCapableProperties(rootShapeId),
2420
2421
  targets,
2421
2422
  };
2422
- ownedWalkCache.set(rootShapeId, walk);
2423
+ cache.set(rootShapeId, walk);
2423
2424
  return walk;
2424
2425
  }
2425
2426
  /** `FILTER(!sameTerm(?n, rdf:nil))`: the walk never deletes `rdf:nil`, which every list ends in. */
@@ -2596,6 +2597,10 @@ export function buildOwnedSelfDelete(subjectTerm, propertyTerm, oldTerm, varPref
2596
2597
  * shape, the WHERE has no solution and nothing is deleted.
2597
2598
  */
2598
2599
  export function deleteToAlgebra(query, _options) {
2600
+ const catalog = catalogOf(query);
2601
+ if (catalog !== undefined && catalog !== getActiveShapeCatalog()) {
2602
+ return withShapeCatalog(catalog, () => deleteToAlgebra(query, _options));
2603
+ }
2599
2604
  const deletePatterns = [];
2600
2605
  const guards = [];
2601
2606
  const blocks = [];
@@ -2669,6 +2674,10 @@ function bulkDeleteUnion(shapeId, subjectVar, rootWildcard, typeTriple, deletePa
2669
2674
  * (see `bulkDeleteUnion`). Unlike a delete by id, incoming references are not deleted.
2670
2675
  */
2671
2676
  export function deleteAllToAlgebra(query, _options) {
2677
+ const catalog = catalogOf(query);
2678
+ if (catalog !== undefined && catalog !== getActiveShapeCatalog()) {
2679
+ return withShapeCatalog(catalog, () => deleteAllToAlgebra(query, _options));
2680
+ }
2672
2681
  const subjectVar = 'a0';
2673
2682
  // DELETE patterns: root wildcard
2674
2683
  const deletePatterns = [
@@ -2696,6 +2705,10 @@ export function deleteAllToAlgebra(query, _options) {
2696
2705
  * so only the matched subjects' children are deleted.
2697
2706
  */
2698
2707
  export function deleteWhereToAlgebra(query, _options) {
2708
+ const catalog = catalogOf(query);
2709
+ if (catalog !== undefined && catalog !== getActiveShapeCatalog()) {
2710
+ return withShapeCatalog(catalog, () => deleteWhereToAlgebra(query, _options));
2711
+ }
2699
2712
  const subjectVar = 'a0';
2700
2713
  const registry = new VariableRegistry();
2701
2714
  // DELETE patterns: root wildcard
@@ -2747,6 +2760,10 @@ export function deleteWhereToAlgebra(query, _options) {
2747
2760
  * filter conditions from the where clause.
2748
2761
  */
2749
2762
  export function updateWhereToAlgebra(query, options) {
2763
+ const catalog = catalogOf(query);
2764
+ if (catalog !== undefined && catalog !== getActiveShapeCatalog()) {
2765
+ return withShapeCatalog(catalog, () => updateWhereToAlgebra(query, options));
2766
+ }
2750
2767
  const subjectTerm = varTerm('a0');
2751
2768
  const result = processUpdateFields(query.data, subjectTerm, options);
2752
2769
  // WHERE: type triple is always required
@@ -2803,6 +2820,10 @@ export function updateWhereToAlgebra(query, options) {
2803
2820
  * lowers to `GROUP BY` + `HAVING` rather than to a `FILTER`; see below.
2804
2821
  */
2805
2822
  export function askToAlgebra(query, options) {
2823
+ const catalog = catalogOf(query);
2824
+ if (catalog !== undefined && catalog !== getActiveShapeCatalog()) {
2825
+ return withShapeCatalog(catalog, () => askToAlgebra(query, options));
2826
+ }
2806
2827
  if (!query.root) {
2807
2828
  if (!query.subjectId) {
2808
2829
  throw new Error('askToAlgebra: a shapeless ask needs a subject — there is no shape to scan ' +
@@ -2817,7 +2838,7 @@ export function askToAlgebra(query, options) {
2817
2838
  };
2818
2839
  return { type: 'ask', algebra: bgp };
2819
2840
  }
2820
- const inner = selectToAlgebra({
2841
+ const inner = selectToAlgebra(attachCatalog({
2821
2842
  kind: 'select',
2822
2843
  root: query.root,
2823
2844
  patterns: query.patterns,
@@ -2825,7 +2846,7 @@ export function askToAlgebra(query, options) {
2825
2846
  where: query.where,
2826
2847
  subjectId: query.subjectId,
2827
2848
  subjectIds: query.subjectIds,
2828
- }, options);
2849
+ }, catalog), options);
2829
2850
  if (inner.having) {
2830
2851
  // Same trap as in `countToAlgebra`: an aggregate in the WHERE clause (e.g.
2831
2852
  // `p.friends.size().gt(2)`) lowers to HAVING + GROUP BY on the select plan, and
@@ -2869,11 +2890,15 @@ export function askToAlgebra(query, options) {
2869
2890
  * nothing to guard against, because {@link IRCountQuery} cannot carry them.
2870
2891
  */
2871
2892
  export function countToAlgebra(query, options) {
2893
+ const catalog = catalogOf(query);
2894
+ if (catalog !== undefined && catalog !== getActiveShapeCatalog()) {
2895
+ return withShapeCatalog(catalog, () => countToAlgebra(query, options));
2896
+ }
2872
2897
  if (!query.root) {
2873
2898
  throw new Error('countToAlgebra: query.root is undefined. A count needs a shape to scan — a ' +
2874
2899
  'shapeless count would count every node in the store.');
2875
2900
  }
2876
- const inner = selectToAlgebra({
2901
+ const inner = selectToAlgebra(attachCatalog({
2877
2902
  kind: 'select',
2878
2903
  root: query.root,
2879
2904
  patterns: query.patterns,
@@ -2881,7 +2906,7 @@ export function countToAlgebra(query, options) {
2881
2906
  where: query.where,
2882
2907
  subjectId: query.subjectId,
2883
2908
  subjectIds: query.subjectIds,
2884
- }, options);
2909
+ }, catalog), options);
2885
2910
  if (inner.having) {
2886
2911
  // An aggregate in the WHERE clause (e.g. `p.friends.size().gt(2)`) lowers to
2887
2912
  // HAVING + GROUP BY on the select plan. Only `algebra` is carried over here, so
@@ -2916,6 +2941,10 @@ export function countToAlgebra(query, options) {
2916
2941
  * Converts an IRSelectQuery to a SPARQL string.
2917
2942
  */
2918
2943
  export function selectToSparql(query, options) {
2944
+ const catalog = catalogOf(query);
2945
+ if (catalog !== undefined && catalog !== getActiveShapeCatalog()) {
2946
+ return withShapeCatalog(catalog, () => selectToSparql(query, options));
2947
+ }
2919
2948
  const plan = selectToAlgebra(query, options);
2920
2949
  return selectPlanToSparql(plan, options);
2921
2950
  }
@@ -2923,6 +2952,10 @@ export function selectToSparql(query, options) {
2923
2952
  * Converts an {@link IRAskQuery} to a SPARQL `ASK` string.
2924
2953
  */
2925
2954
  export function askToSparql(query, options) {
2955
+ const catalog = catalogOf(query);
2956
+ if (catalog !== undefined && catalog !== getActiveShapeCatalog()) {
2957
+ return withShapeCatalog(catalog, () => askToSparql(query, options));
2958
+ }
2926
2959
  const plan = askToAlgebra(query, options);
2927
2960
  return askPlanToSparql(plan, options);
2928
2961
  }
@@ -2931,6 +2964,10 @@ export function askToSparql(query, options) {
2931
2964
  * string, through the same {@link selectPlanToSparql} every select uses.
2932
2965
  */
2933
2966
  export function countToSparql(query, options) {
2967
+ const catalog = catalogOf(query);
2968
+ if (catalog !== undefined && catalog !== getActiveShapeCatalog()) {
2969
+ return withShapeCatalog(catalog, () => countToSparql(query, options));
2970
+ }
2934
2971
  const plan = countToAlgebra(query, options);
2935
2972
  return selectPlanToSparql(plan, options);
2936
2973
  }
@@ -2939,6 +2976,10 @@ export function countToSparql(query, options) {
2939
2976
  * Stub: will be implemented when algebraToString is available.
2940
2977
  */
2941
2978
  export function createToSparql(query, options) {
2979
+ const catalog = catalogOf(query);
2980
+ if (catalog !== undefined && catalog !== getActiveShapeCatalog()) {
2981
+ return withShapeCatalog(catalog, () => createToSparql(query, options));
2982
+ }
2942
2983
  const plan = createToAlgebra(query, options);
2943
2984
  return insertDataPlanToSparql(plan, options);
2944
2985
  }
@@ -2947,11 +2988,19 @@ export function createToSparql(query, options) {
2947
2988
  * Stub: will be implemented when algebraToString is available.
2948
2989
  */
2949
2990
  export function updateToSparql(query, options) {
2991
+ const catalog = catalogOf(query);
2992
+ if (catalog !== undefined && catalog !== getActiveShapeCatalog()) {
2993
+ return withShapeCatalog(catalog, () => updateToSparql(query, options));
2994
+ }
2950
2995
  const plan = updateToAlgebra(query, options);
2951
2996
  return deleteInsertPlanToSparql(plan, options);
2952
2997
  }
2953
2998
  /** Lowers an IRUpsertMutation all the way to a SPARQL update string. */
2954
2999
  export function upsertToSparql(query, options) {
3000
+ const catalog = catalogOf(query);
3001
+ if (catalog !== undefined && catalog !== getActiveShapeCatalog()) {
3002
+ return withShapeCatalog(catalog, () => upsertToSparql(query, options));
3003
+ }
2955
3004
  const plan = upsertToAlgebra(query, options);
2956
3005
  return deleteInsertPlanToSparql(plan, options);
2957
3006
  }
@@ -2959,6 +3008,10 @@ export function upsertToSparql(query, options) {
2959
3008
  * Converts an IRDeleteMutation to a SPARQL string.
2960
3009
  */
2961
3010
  export function deleteToSparql(query, options) {
3011
+ const catalog = catalogOf(query);
3012
+ if (catalog !== undefined && catalog !== getActiveShapeCatalog()) {
3013
+ return withShapeCatalog(catalog, () => deleteToSparql(query, options));
3014
+ }
2962
3015
  const plan = deleteToAlgebra(query, options);
2963
3016
  return deleteInsertPlanToSparql(plan, options);
2964
3017
  }
@@ -2966,6 +3019,10 @@ export function deleteToSparql(query, options) {
2966
3019
  * Converts an IRDeleteAllMutation to a SPARQL string.
2967
3020
  */
2968
3021
  export function deleteAllToSparql(query, options) {
3022
+ const catalog = catalogOf(query);
3023
+ if (catalog !== undefined && catalog !== getActiveShapeCatalog()) {
3024
+ return withShapeCatalog(catalog, () => deleteAllToSparql(query, options));
3025
+ }
2969
3026
  const plan = deleteAllToAlgebra(query, options);
2970
3027
  return deleteInsertPlanToSparql(plan, options);
2971
3028
  }
@@ -2973,6 +3030,10 @@ export function deleteAllToSparql(query, options) {
2973
3030
  * Converts an IRDeleteWhereMutation to a SPARQL string.
2974
3031
  */
2975
3032
  export function deleteWhereToSparql(query, options) {
3033
+ const catalog = catalogOf(query);
3034
+ if (catalog !== undefined && catalog !== getActiveShapeCatalog()) {
3035
+ return withShapeCatalog(catalog, () => deleteWhereToSparql(query, options));
3036
+ }
2976
3037
  const plan = deleteWhereToAlgebra(query, options);
2977
3038
  return deleteInsertPlanToSparql(plan, options);
2978
3039
  }
@@ -2980,6 +3041,10 @@ export function deleteWhereToSparql(query, options) {
2980
3041
  * Converts an IRUpdateWhereMutation to a SPARQL string.
2981
3042
  */
2982
3043
  export function updateWhereToSparql(query, options) {
3044
+ const catalog = catalogOf(query);
3045
+ if (catalog !== undefined && catalog !== getActiveShapeCatalog()) {
3046
+ return withShapeCatalog(catalog, () => updateWhereToSparql(query, options));
3047
+ }
2983
3048
  const plan = updateWhereToAlgebra(query, options);
2984
3049
  return deleteInsertPlanToSparql(plan, options);
2985
3050
  }