@holistics/cli-core 2.3.8 → 2.3.9

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/dist/commands.js +455 -393
  2. package/package.json +1 -1
package/dist/commands.js CHANGED
@@ -27799,7 +27799,7 @@ var require_dist3 = __commonJS((exports2) => {
27799
27799
  exports2.default = deferred;
27800
27800
  });
27801
27801
  // package.json
27802
- var version = "2.3.8";
27802
+ var version = "2.3.9";
27803
27803
 
27804
27804
  // ../../node_modules/.pnpm/@commander-js+extra-typings@13.1.0_commander@13.1.0/node_modules/@commander-js/extra-typings/esm.mjs
27805
27805
  var import__ = __toESM(require_extra_typings(), 1);
@@ -38201,7 +38201,7 @@ import fs from "fs";
38201
38201
  import os from "os";
38202
38202
  import path2 from "path";
38203
38203
 
38204
- // ../../node_modules/.pnpm/js-yaml@4.3.0/node_modules/js-yaml/dist/js-yaml.mjs
38204
+ // ../../node_modules/.pnpm/js-yaml@4.3.1/node_modules/js-yaml/dist/js-yaml.mjs
38205
38205
  function getDefaultExportFromCjs(x) {
38206
38206
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
38207
38207
  }
@@ -39105,7 +39105,7 @@ function requireOmap() {
39105
39105
  function resolveYamlOmap(data) {
39106
39106
  if (data === null)
39107
39107
  return true;
39108
- const objectKeys = [];
39108
+ const objectKeys = {};
39109
39109
  const object = data;
39110
39110
  for (let index = 0, length = object.length;index < length; index += 1) {
39111
39111
  const pair = object[index];
@@ -39123,10 +39123,9 @@ function requireOmap() {
39123
39123
  }
39124
39124
  if (!pairHasKey)
39125
39125
  return false;
39126
- if (objectKeys.indexOf(pairKey) === -1)
39127
- objectKeys.push(pairKey);
39128
- else
39126
+ if (_hasOwnProperty.call(objectKeys, pairKey))
39129
39127
  return false;
39128
+ Object.defineProperty(objectKeys, pairKey, { value: true });
39130
39129
  }
39131
39130
  return true;
39132
39131
  }
@@ -112837,29 +112836,29 @@ function transformInUserAttribute(e10, t, n, r3) {
112837
112836
  let a = normalizeUserAttribute(e10, n, undefined, true);
112838
112837
  if (a === UserAttributeConstant.ALL)
112839
112838
  return wrapSql(truefalseOp(!i, e10.store.dataSource.dbtype), SqlType.TRUEFALSE);
112840
- let s3 = getSqlFromRowLevelObject(e10, getRowLevelObjectFromExpression(e10, t, false));
112841
- return import_lodash2.isArray(a) ? wrapSql(createOperation(i ? OperationType.NOT_IN : OperationType.IN, [s3, ...a]), SqlType.TRUEFALSE) : wrapSql(createOperation(i ? OperationType.NE : OperationType.EQ, [s3, a]), SqlType.TRUEFALSE);
112839
+ let s3 = getRowLevelObjectFromExpression(e10, t, false), c3 = getSqlFromRowLevelObject(e10, s3), l3 = getFieldFlags(s3);
112840
+ return import_lodash2.isArray(a) ? wrapSql(createOperation(i ? OperationType.NOT_IN : OperationType.IN, [c3, ...a]), SqlType.TRUEFALSE, l3) : wrapSql(createOperation(i ? OperationType.NE : OperationType.EQ, [c3, a]), SqlType.TRUEFALSE, l3);
112842
112841
  }
112843
112842
  function transformInTableLiteral(e10, t, n, r3) {
112844
- let i = !!r3.not, a = getRowLevelObjectFromExpression(e10, n, false).evaluatedRows.map((t3) => normalizeLiteral(e10, t3[0])) || [];
112845
- if (import_lodash2.isEmpty(a))
112843
+ let i = !!r3.not, a = getRowLevelObjectFromExpression(e10, n, false), s3 = a.evaluatedRows.map((t3) => normalizeLiteral(e10, t3[0])) || [];
112844
+ if (import_lodash2.isEmpty(s3))
112846
112845
  return wrapSql(truefalseOp(i, e10.store.dataSource.dbtype), SqlType.TRUEFALSE);
112847
- let s3 = getSqlFromRowLevelObject(e10, getRowLevelObjectFromExpression(e10, t, false));
112848
- return wrapSql(createOperation(i ? OperationType.NOT_IN : OperationType.IN, [s3, ...a]), SqlType.TRUEFALSE);
112846
+ let c3 = getRowLevelObjectFromExpression(e10, t, false), l3 = getSqlFromRowLevelObject(e10, c3);
112847
+ return wrapSql(createOperation(i ? OperationType.NOT_IN : OperationType.IN, [l3, ...s3]), SqlType.TRUEFALSE, getFieldFlags(c3, a));
112849
112848
  }
112850
112849
  function transformInRangeLiteral(e10, t, n, r3) {
112851
- let i = !!r3.not, a, s3, c3 = getSqlFromRowLevelObject(e10, getRowLevelObjectFromExpression(e10, t, false));
112852
- if (n.start && (a = createOperation(i ? OperationType.LT : OperationType.GTE, [c3, createOperation(OperationType.NORMALIZE_NUMBER_VALUE, [n.start.toString()])])), n.end && (s3 = createOperation(i ? OperationType.GT : OperationType.LTE, [c3, createOperation(OperationType.NORMALIZE_NUMBER_VALUE, [n.end.toString()])])), a && s3)
112853
- return n.start > n.end ? wrapSql(truefalseOp(i, e10.store.dataSource.dbtype), SqlType.TRUEFALSE) : wrapSql(createOperation(OperationType.AND, [a, s3]), SqlType.TRUEFALSE);
112854
- let l3 = truefalseOp(!i, e10.store.dataSource.dbtype);
112855
- return wrapSql(a || s3 || l3, SqlType.TRUEFALSE);
112850
+ let i = !!r3.not, a, s3, c3 = getRowLevelObjectFromExpression(e10, t, false), l3 = getSqlFromRowLevelObject(e10, c3), u = getFieldFlags(c3);
112851
+ if (n.start && (a = createOperation(i ? OperationType.LT : OperationType.GTE, [l3, createOperation(OperationType.NORMALIZE_NUMBER_VALUE, [n.start.toString()])])), n.end && (s3 = createOperation(i ? OperationType.GT : OperationType.LTE, [l3, createOperation(OperationType.NORMALIZE_NUMBER_VALUE, [n.end.toString()])])), a && s3)
112852
+ return n.start > n.end ? wrapSql(truefalseOp(i, e10.store.dataSource.dbtype), SqlType.TRUEFALSE) : wrapSql(createOperation(i ? OperationType.OR : OperationType.AND, [a, s3]), SqlType.TRUEFALSE, u);
112853
+ let f3 = truefalseOp(!i, e10.store.dataSource.dbtype);
112854
+ return wrapSql(a || s3 || f3, SqlType.TRUEFALSE, u);
112856
112855
  }
112857
112856
  function evalInDatetimeTableLiteral(e10, t, n, r3) {
112858
112857
  let i = !!r3.not, a = getRowLevelObjectFromExpression(e10, n, false).evaluatedRows.map((e11) => e11[0]) || [];
112859
112858
  if (import_lodash2.isEmpty(a))
112860
112859
  return wrapSql(truefalseOp(i, e10.store.dataSource.dbtype), SqlType.TRUEFALSE);
112861
- let s3 = createInfixOperatorToken(Kind.MATCHES_KEYWORD, r3.loc, i);
112862
- return wrapSql(createOperation(i ? OperationType.AND : OperationType.OR, a.map((n3) => evalDatetimeInfixExpression(e10, t, n3, s3).sql)), SqlType.TRUEFALSE);
112860
+ let s3 = createInfixOperatorToken(Kind.MATCHES_KEYWORD, r3.loc, i), c3 = a.map((n3) => evalDatetimeInfixExpression(e10, t, n3, s3));
112861
+ return wrapSql(createOperation(i ? OperationType.AND : OperationType.OR, c3.map((e11) => e11.sql)), SqlType.TRUEFALSE, getFieldFlags(...c3));
112863
112862
  }
112864
112863
  function evalInDatetimeUserAttribute(e10, t, n, r3) {
112865
112864
  let i = !!r3.not, a = getRowLevelObjectFromExpression(e10, n, false);
@@ -112869,8 +112868,8 @@ function evalInDatetimeUserAttribute(e10, t, n, r3) {
112869
112868
  return wrapSql(truefalseOp(!i, e10.store.dataSource.dbtype), SqlType.TRUEFALSE);
112870
112869
  if (import_lodash2.isEmpty(a.values))
112871
112870
  return wrapSql(truefalseOp(i, e10.store.dataSource.dbtype), SqlType.TRUEFALSE);
112872
- let s3 = a.values.map((t3) => assertAqlType(e10.eval(createDatetimeLiteral(t3, n.loc)), isFieldFragment)).map((e11) => getLiteralFromFieldFragment(e11, isDatetimeValue)), c3 = createInfixOperatorToken(Kind.MATCHES_KEYWORD, r3.loc, i);
112873
- return wrapSql(createOperation(i ? OperationType.AND : OperationType.OR, s3.map((n3) => evalDatetimeRangeInfixExpression(e10, t, n3, c3).sql)), SqlType.TRUEFALSE);
112871
+ let s3 = a.values.map((t3) => assertAqlType(e10.eval(createDatetimeLiteral(t3, n.loc)), isFieldFragment)).map((e11) => getLiteralFromFieldFragment(e11, isDatetimeValue)), c3 = createInfixOperatorToken(Kind.MATCHES_KEYWORD, r3.loc, i), l3 = s3.map((n3) => evalDatetimeRangeInfixExpression(e10, t, n3, c3));
112872
+ return wrapSql(createOperation(i ? OperationType.AND : OperationType.OR, l3.map((e11) => e11.sql)), SqlType.TRUEFALSE, getFieldFlags(...l3));
112874
112873
  }
112875
112874
  function evalDatetimeRangeInfixExpression(e10, t, n, r3) {
112876
112875
  let i = getUnderlyingType(e10, t), a = getRowLevelObjectFromExpression(e10, t, false), s3 = getRowLevelObjectFromExpression(e10, n, false), c3;
@@ -114817,38 +114816,38 @@ function buildApplyFiltersPlan(e10, t, n, r3, i, a = true, s3 = true, c3 = false
114817
114816
  f3(e10, l3, t3, t3.targetFields[n3]);
114818
114817
  return l3;
114819
114818
  function f3(e11, n3, r4, i3, a3, s4 = false) {
114820
- let { rootModel: S3 } = n3, w3 = refIsGenericTimeSpine(i3) ? substituteTimeSpine(e11, i3) : i3, E3 = r4.isRowLevelPermission ? e11.graphContext.rlpGraph() : null, N = (E3 ?? t).findPath(S3, w3.modelName);
114821
- if (!p3(S3, w3.modelName, a3, r4, N, l3))
114819
+ let { rootModel: S3 } = n3, w3 = refIsGenericTimeSpine(i3) ? substituteTimeSpine(e11, i3) : i3, E3 = r4.isRowLevelPermission ? e11.graphContext.rlpGraph() : null, N = E3 ?? t, I3 = N.findPath(S3, w3.modelName);
114820
+ if (!p3(S3, w3.modelName, a3, r4, I3, l3))
114822
114821
  return;
114823
- let [I3, L3] = N, U3 = false, W3 = false;
114822
+ let [L3, U3] = I3, W3 = false, me3 = false;
114824
114823
  if (E3 && E3 !== t) {
114825
114824
  let e12 = t.findPath(S3, w3.modelName);
114826
- U3 = e12 === null || formatPathToString(e12) !== formatPathToString(N), W3 = e12 !== null && !e12[1] && !!L3;
114825
+ W3 = e12 === null || formatPathToString(e12) !== formatPathToString(I3), me3 = e12 !== null && !e12[1] && !!U3;
114827
114826
  }
114828
- if (S3 === w3.modelName || U3 && W3 || !U3 && (!import_lodash2.isEmpty(I3) && (!L3 || s4 && !c3) || n3.availableModels?.has(w3.modelName))) {
114829
- addRefToFilterSet(n3, r4, w3);
114827
+ if (S3 === w3.modelName || W3 && me3 || !W3 && (!import_lodash2.isEmpty(L3) && (!U3 || s4 && !c3) || n3.availableModels?.has(w3.modelName))) {
114828
+ addRefToFilterSet(n3, r4, w3, L3);
114830
114829
  return;
114831
114830
  }
114832
- if (L3 && c3) {
114831
+ if (U3 && c3) {
114833
114832
  l3.unappliedFilters.add(r4);
114834
114833
  return;
114835
114834
  }
114836
- if (U3 && !import_lodash2.isEmpty(I3)) {
114837
- let e12 = n3.rootModel, t3 = I3[0].from, i4 = t3;
114838
- if (L3) {
114839
- let r5 = I3[m3(n3.rootModel, I3)];
114835
+ if (W3 && !import_lodash2.isEmpty(L3)) {
114836
+ let e12 = n3.rootModel, t3 = L3[0].from, i4 = t3;
114837
+ if (U3) {
114838
+ let r5 = L3[m3(n3.rootModel, L3)];
114840
114839
  e12 = r5.to.modelName, t3 = r5.to, i4 = r5.from;
114841
114840
  }
114842
- let a4 = modelFieldRefAsKey(t3), s5 = n3.get(a4);
114843
- s5 || (s5 = createApplyFiltersPlan(e12, [], t3, i4), s5.useRlpGraph = true, n3.set(a4, s5)), addRefToFilterSet(s5, r4, w3);
114841
+ let a4 = N.findPath(e12, w3.modelName)?.[0] ?? [];
114842
+ addRefToFilterSet(findOrCreateSubPlan(n3, e12, t3, i4, [a4], true), r4, w3, a4);
114844
114843
  return;
114845
114844
  }
114846
- let me3 = m3(n3.rootModel, I3), He4 = I3[me3], oi3 = u;
114845
+ let He4 = m3(n3.rootModel, L3), oi3 = L3[He4], ci3 = u;
114847
114846
  u = new Set([...u]);
114848
- let ci3 = false;
114849
- for (let e12 = me3 - 1;e12 >= 0; e12--) {
114850
- let t3 = I3[e12];
114851
- if (ci3) {
114847
+ let li3 = false;
114848
+ for (let e12 = He4 - 1;e12 >= 0; e12--) {
114849
+ let t3 = L3[e12];
114850
+ if (li3) {
114852
114851
  u.add(t3.from.modelName);
114853
114852
  continue;
114854
114853
  }
@@ -114856,20 +114855,23 @@ function buildApplyFiltersPlan(e10, t, n, r3, i, a = true, s3 = true, c3 = false
114856
114855
  case LinkType.ONE_TO_ONE:
114857
114856
  break;
114858
114857
  case LinkType.MANY_TO_ONE:
114859
- ci3 = true, u.add(t3.from.modelName);
114858
+ li3 = true, u.add(t3.from.modelName);
114860
114859
  break;
114861
114860
  default:
114862
114861
  t3.type;
114863
114862
  break;
114864
114863
  }
114865
114864
  }
114866
- let li3 = modelFieldRefAsKey(He4.to), di3 = n3.get(li3);
114867
- if (di3 || (di3 = createApplyFiltersPlan(He4.to.modelName, [], He4.to, He4.from), n3.set(li3, di3)), isConstantFilter(r4))
114868
- f3(e11, di3, r4, r4.targetField, r4.condition.left.loc, true);
114865
+ let di3 = oi3.to.modelName, fi3 = import_lodash2.compact((isConstantFilter(r4) ? [r4.targetField] : r4.targetFields.filter((e12) => !u.has(e12.modelName))).map((t3) => {
114866
+ let n4 = refIsGenericTimeSpine(t3) ? substituteTimeSpine(e11, t3) : t3;
114867
+ return N.findPath(di3, n4.modelName)?.[0];
114868
+ })), pi3 = findOrCreateSubPlan(n3, di3, oi3.to, oi3.from, fi3);
114869
+ if (isConstantFilter(r4))
114870
+ f3(e11, pi3, r4, r4.targetField, r4.condition.left.loc, true);
114869
114871
  else
114870
114872
  for (let t3 = 0;t3 < r4.targetFields.length; t3++)
114871
- u.has(r4.targetFields[t3].modelName) || f3(e11, di3, r4, r4.targetFields[t3], undefined, true);
114872
- u = oi3;
114873
+ u.has(r4.targetFields[t3].modelName) || f3(e11, pi3, r4, r4.targetFields[t3], undefined, true);
114874
+ u = ci3;
114873
114875
  }
114874
114876
  function p3(t3, n3, r4, i3, c4, l4) {
114875
114877
  if (!c4) {
@@ -114901,12 +114903,49 @@ function isRlpStrictBypassed(e10, t, n) {
114901
114903
  return r3 ? hasExplicitRlpPropagation(r3[0]) : false;
114902
114904
  }
114903
114905
  function createApplyFiltersPlan(e10, t, n, r3, i) {
114904
- let a = /* @__PURE__ */ new Map;
114905
- return a.rootModel = e10, a.availableModels = new Set(i), a.filters = new Map(t.map((e11) => [e11, /* @__PURE__ */ new Set])), a.ref = n, a.refTarget = r3, a.unappliedFilters = /* @__PURE__ */ new Set, a;
114906
+ return {
114907
+ rootModel: e10,
114908
+ availableModels: new Set(i),
114909
+ filters: new Map(t.map((e11) => [e11, /* @__PURE__ */ new Set])),
114910
+ subPlans: [],
114911
+ modelPathKeyMap: /* @__PURE__ */ new Map,
114912
+ ref: n,
114913
+ refTarget: r3,
114914
+ useRlpGraph: false,
114915
+ unappliedFilters: /* @__PURE__ */ new Set
114916
+ };
114917
+ }
114918
+ function addRefToFilterSet(e10, t, n, r3) {
114919
+ let i = e10.filters.get(t);
114920
+ i ? i.add(n) : e10.filters.set(t, new Set([n])), recordPathKeys(e10, r3);
114921
+ }
114922
+ function relationshipKey(e10) {
114923
+ return `${modelFieldRefAsKey(e10.from)}>${modelFieldRefAsKey(e10.to)}:${e10.type}`;
114906
114924
  }
114907
- function addRefToFilterSet(e10, t, n) {
114908
- let r3 = e10.filters.get(t);
114909
- r3 ? r3.add(n) : e10.filters.set(t, new Set([n]));
114925
+ function stepAcross$1(e10, t) {
114926
+ return t.from.modelName === e10 ? t.to.modelName : t.from.modelName;
114927
+ }
114928
+ function recordPathKeys(e10, t) {
114929
+ let n = e10.rootModel, r3 = "";
114930
+ for (let i of t)
114931
+ n = stepAcross$1(n, i), r3 += `${relationshipKey(i)} -> `, e10.modelPathKeyMap.has(n) || e10.modelPathKeyMap.set(n, r3);
114932
+ }
114933
+ function planFitsPath(e10, t) {
114934
+ let n = e10.rootModel, r3 = "";
114935
+ for (let i of t) {
114936
+ n = stepAcross$1(n, i), r3 += `${relationshipKey(i)} -> `;
114937
+ let t3 = e10.modelPathKeyMap.get(n);
114938
+ if (t3 !== undefined && t3 !== r3)
114939
+ return false;
114940
+ }
114941
+ return true;
114942
+ }
114943
+ function findOrCreateSubPlan(e10, t, n, r3, i, a = false) {
114944
+ let s3 = e10.subPlans.find((e11) => e11.rootModel === t && e11.useRlpGraph === a && e11.ref && refEq(e11.ref, n) && i.every((t3) => planFitsPath(e11, t3)));
114945
+ if (s3)
114946
+ return s3;
114947
+ let c3 = createApplyFiltersPlan(t, [], n, r3);
114948
+ return c3.useRlpGraph = a, e10.subPlans.push(c3), c3;
114910
114949
  }
114911
114950
  function runApplyFiltersPlan(e10, t, n) {
114912
114951
  let { filters: r3 } = t, i = 0;
@@ -114925,22 +114964,22 @@ function runApplyFiltersPlan(e10, t, n) {
114925
114964
  r4 ? n.conditions.push(...r4) : (i++, applyTableFilter(e10, t3, a, n, i));
114926
114965
  }
114927
114966
  n.conditions = import_lodash2.uniqBy(import_lodash2.compact([...n.conditions]), stableStringify);
114928
- for (let [r4, i3] of t) {
114929
- let { ref: t3, refTarget: r5 } = i3;
114930
- if (!t3 || !r5)
114967
+ for (let r4 of t.subPlans) {
114968
+ let { ref: t3, refTarget: i3 } = r4;
114969
+ if (!t3 || !i3)
114931
114970
  continue;
114932
114971
  e10.eval(dotExpressionFromModelFieldRef(t3));
114933
- let a = filtersPlanKey(i3), s3 = e10.globals.filterPlansCache.get(a);
114972
+ let a = filtersPlanKey(r4), s3 = e10.globals.filterPlansCache.get(a);
114934
114973
  if (!s3) {
114935
- let n3 = createFunctionCallExpression(createIdentifier("select"), [createIdentifier(t3.modelName), createDotExpression(createIdentifier(t3.modelName), createIdentifier(t3.fieldName))]), r6 = i3.useRlpGraph === true;
114936
- r6 && e10.graphContext.graphs.push(e10.graphContext.rlpGraph());
114974
+ let n3 = createFunctionCallExpression(createIdentifier("select"), [createIdentifier(t3.modelName), createDotExpression(createIdentifier(t3.modelName), createIdentifier(t3.fieldName))]), i4 = r4.useRlpGraph === true;
114975
+ i4 && e10.graphContext.graphs.push(e10.graphContext.rlpGraph());
114937
114976
  try {
114938
114977
  let t4 = e10.filters;
114939
114978
  e10.filters = [], s3 = assertAqlType(e10.eval(n3), isExploreId);
114940
- let r7 = e10.getExplore(s3);
114941
- r7.allowFanoutJoin = true, e10.filters = t4, r7.groupBy = r7.groups = [...r7.fields], runApplyFiltersPlan(e10, i3, r7), e10.globals.filterPlansCache.set(a, s3);
114979
+ let i5 = e10.getExplore(s3);
114980
+ i5.allowFanoutJoin = true, e10.filters = t4, i5.groupBy = i5.groups = [...i5.fields], runApplyFiltersPlan(e10, r4, i5), e10.globals.filterPlansCache.set(a, s3);
114942
114981
  } finally {
114943
- r6 && e10.graphContext.dropGraph();
114982
+ i4 && e10.graphContext.dropGraph();
114944
114983
  }
114945
114984
  }
114946
114985
  let c3 = e10.getExplore(s3), l3 = c3.fields.find((e11) => e11.origin && refEq(e11.origin, t3));
@@ -115072,7 +115111,7 @@ function applyTableFilter(e10, t, n, r3, i) {
115072
115111
  r3.joins = import_lodash2.uniqWith([...r3.joins, S3], import_lodash2.isEqual), t.notIn && (r3.conditions = import_lodash2.uniqBy(import_lodash2.compact([...r3.conditions, createCondition(a.name, createOperation(OperationType.AND, p3.map((e11) => createOperation(OperationType.IS_NULL, [e11]))))]), stableStringify));
115073
115112
  }
115074
115113
  function filtersPlanKey(e10) {
115075
- let { ref: t, rootModel: n, filters: r3 } = e10, i = [...e10.entries()].flatMap(([e11, t3]) => `${e11}: ${filtersPlanKey(t3)}`.split(`
115114
+ let { ref: t, rootModel: n, filters: r3 } = e10, i = e10.subPlans.flatMap((e11) => `${e11.ref ? modelFieldRefAsKey(e11.ref) : e11.rootModel}: ${filtersPlanKey(e11)}`.split(`
115076
115115
  `).map((e12) => ` ${e12}`)).join(`
115077
115116
  `), a = [...r3.entries()].map(([e11, t3]) => isConstantFilter(e11) ? stringifyLogic(e11) : `${stringifyLogic(e11)} <${[...t3.values()].map((e12) => `${e12.modelName}.${e12.fieldName}`)}>`).join(`,
115078
115117
  `);
@@ -124429,7 +124468,6 @@ function makeTransform(e10, t, n, r3, i) {
124429
124468
  id: e10.newNodeId(i),
124430
124469
  ty: r3,
124431
124470
  input: n[0],
124432
- graphId: e10.currentGraphId,
124433
124471
  iterationDepth: iterationDepthOf(n[0])
124434
124472
  };
124435
124473
  switch (t) {
@@ -124478,8 +124516,7 @@ function makeCall(e10, t, n, r3, i, a) {
124478
124516
  id: e10.newNodeId(a),
124479
124517
  ty: r3,
124480
124518
  name: makeIdent(e10, t, [], errType, i),
124481
- args: n,
124482
- graphId: e10.currentGraphId
124519
+ args: n
124483
124520
  };
124484
124521
  }
124485
124522
  function projectColumns(e10, t, n) {
@@ -124513,6 +124550,7 @@ function unwrapScopeWrappers(e10) {
124513
124550
  case "block":
124514
124551
  return unwrapScopeWrappers(e10.result);
124515
124552
  case "where":
124553
+ case "with_relationships":
124516
124554
  case "lod":
124517
124555
  case "period":
124518
124556
  case "rolling":
@@ -125211,33 +125249,14 @@ function withParamBindings(e10, t, n) {
125211
125249
  e10.paramBindings = r3;
125212
125250
  }
125213
125251
  }
125214
- function currentGraph(e10) {
125215
- return e10.dataset.graphs.get(e10.currentGraphId);
125216
- }
125217
125252
  function baseGraph(e10) {
125218
- return e10.dataset.graphs.get(0);
125219
- }
125220
- function registerGraph(e10, t) {
125221
- let n = e10.dataset.graphs.size;
125222
- return e10.dataset.graphs.set(n, t), n;
125223
- }
125224
- function rlpGraphId(e10) {
125225
- if (e10.rlpViewGraphId !== undefined)
125226
- return e10.rlpViewGraphId;
125227
- let t = baseGraph(e10);
125228
- return e10.rlpViewGraphId = t.relationships.some((e11) => e11.rlp_propagation && e11.rlp_propagation !== "inherit") ? registerGraph(e10, new ModelGraph(t.models, t.relationships.map(toRlpViewRelationship), undefined, t.allowAmbiguousPaths, t.shouldPrioritizeLengthForMixedPaths)) : 0, e10.rlpViewGraphId;
125253
+ return e10.dataset.graph;
125229
125254
  }
125230
125255
  function rlpGraph(e10) {
125231
- return e10.dataset.graphs.get(rlpGraphId(e10));
125232
- }
125233
- function withGraph(e10, t, n) {
125234
- let r3 = e10.currentGraphId;
125235
- e10.currentGraphId = registerGraph(e10, t);
125236
- try {
125237
- return n();
125238
- } finally {
125239
- e10.currentGraphId = r3;
125240
- }
125256
+ if (e10.rlpViewGraph !== undefined)
125257
+ return e10.rlpViewGraph;
125258
+ let t = baseGraph(e10);
125259
+ return e10.rlpViewGraph = t.relationships.some((e11) => e11.rlp_propagation && e11.rlp_propagation !== "inherit") ? new ModelGraph(t.models, t.relationships.map(toRlpViewRelationship), undefined, t.allowAmbiguousPaths, t.shouldPrioritizeLengthForMixedPaths) : t, e10.rlpViewGraph;
125241
125260
  }
125242
125261
  function declKey(e10, t, n) {
125243
125262
  switch (e10) {
@@ -125290,7 +125309,7 @@ function recordJoinKeyDeps(e10, t, n) {
125290
125309
  let r3 = currentDeclFrame(e10);
125291
125310
  if (!r3 || r3.kind !== "dimension" || !r3.modelName || r3.modelName === n)
125292
125311
  return;
125293
- let i = currentGraph(e10).findPath(r3.modelName, n);
125312
+ let i = baseGraph(e10).findPath(r3.modelName, n);
125294
125313
  if (!i)
125295
125314
  return;
125296
125315
  let [a] = i;
@@ -125448,8 +125467,8 @@ function buildGlobals(e10) {
125448
125467
  }
125449
125468
  if (!r3.members.has("calendar")) {
125450
125469
  nestModel(n, buildModelShell(e10, buildCalendarModel(e10.datetimeContext, e10.store.dataSource)));
125451
- let t3 = e10.dataset.graphs.get(0);
125452
- t3 && !t3.models.includes("H.calendar") && e10.dataset.graphs.set(0, new ModelGraph([...t3.models, GENERIC_CAL_MODEL_NAME], t3.relationships, t3.root, t3.allowAmbiguousPaths, t3.shouldPrioritizeLengthForMixedPaths));
125470
+ let t3 = e10.dataset.graph;
125471
+ t3.models.includes("H.calendar") || (e10.dataset.graph = new ModelGraph([...t3.models, GENERIC_CAL_MODEL_NAME], t3.relationships, t3.root, t3.allowAmbiguousPaths, t3.shouldPrioritizeLengthForMixedPaths));
125453
125472
  }
125454
125473
  }
125455
125474
  function nestModel(e10, t) {
@@ -125687,8 +125706,7 @@ function coerceBodyToDeclaredType(e10, t, n) {
125687
125706
  id: e10.newNodeId(),
125688
125707
  ty: getScalarTypeFromSqlType(r3.sqlType),
125689
125708
  name: makeIdent(e10, "read_cast", [], errType),
125690
- args: [n.result, a],
125691
- graphId: e10.currentGraphId
125709
+ args: [n.result, a]
125692
125710
  }, n.ty = n.result.ty;
125693
125711
  }
125694
125712
  function reportTableAsDimension(e10, t, n) {
@@ -125937,6 +125955,8 @@ var HirFold = class {
125937
125955
  return this.foldPivotContext(e10);
125938
125956
  case "where":
125939
125957
  return this.foldWhere(e10);
125958
+ case "with_relationships":
125959
+ return this.foldWithRelationships(e10);
125940
125960
  case "explore_context":
125941
125961
  return this.foldExploreContext(e10);
125942
125962
  case "in_table_condition":
@@ -126063,6 +126083,12 @@ var HirFold = class {
126063
126083
  conditions: this.foldExprs(e10.conditions)
126064
126084
  };
126065
126085
  }
126086
+ foldWithRelationships(e10) {
126087
+ return {
126088
+ ...e10,
126089
+ value: this.foldExpr(e10.value)
126090
+ };
126091
+ }
126066
126092
  foldExploreContext(e10) {
126067
126093
  return {
126068
126094
  ...e10,
@@ -126315,8 +126341,7 @@ function makeAggregate(e11, t, n, r3, i) {
126315
126341
  id: e11.newNodeId(i),
126316
126342
  ty: c3[0].ty,
126317
126343
  name: makeIdent(e11, r3.fieldName, [], r3, i),
126318
- expr: c3[0],
126319
- graphId: e11.currentGraphId
126344
+ expr: c3[0]
126320
126345
  }, a3 = createTableType(createRowType(projectColumns(e11, [n3], [i])), isTableType(s3.ty) ? s3.ty.rootModel : undefined);
126321
126346
  u = makeTransform(e11, "select", [s3, n3], a3, i), l3 = makeCall(e11, t, [columnRef(e11, r3.fieldName, c3[0].ty, i)], r3, i, i);
126322
126347
  } else if (s3 && c3.length >= 2 && c3.some((e12) => AggregationArgFold.inspect(e12).producesRelation)) {
@@ -126325,8 +126350,7 @@ function makeAggregate(e11, t, n, r3, i) {
126325
126350
  id: e11.newNodeId(i),
126326
126351
  ty: t3.ty,
126327
126352
  name: makeIdent(e11, `_f${n4 + 1}`, [], t3.ty, i),
126328
- expr: t3,
126329
- graphId: e11.currentGraphId
126353
+ expr: t3
126330
126354
  })), f4 = createTableType(createRowType(projectColumns(e11, a3, a3.map(() => i))), n3);
126331
126355
  u = makeTransform(e11, "select", [s3, ...a3], f4, i), l3 = makeCall(e11, t, c3.map((t3, n4) => columnRef(e11, `_f${n4 + 1}`, t3.ty, i)), r3, i, i);
126332
126356
  } else if (s3 && c3.length === 0) {
@@ -126339,8 +126363,7 @@ function makeAggregate(e11, t, n, r3, i) {
126339
126363
  id: e11.newNodeId(i),
126340
126364
  ty: a3,
126341
126365
  name: makeIdent(e11, a3.fieldName, [], r3, i),
126342
- expr: c4,
126343
- graphId: e11.currentGraphId
126366
+ expr: c4
126344
126367
  }, l4 = createTableType(createRowType(projectColumns(e11, [t3], [i])), n3.rootModel);
126345
126368
  u = makeTransform(e11, "select", [s3, t3], l4, i);
126346
126369
  }
@@ -126348,14 +126371,13 @@ function makeAggregate(e11, t, n, r3, i) {
126348
126371
  l3 = makeCall(e11, t, c3, r3, i, i), u = s3 ?? (a ? synthRef(e11, a, [], resolveModel(e11, a)?.ty ?? errType, i) : undefined);
126349
126372
  if (!u)
126350
126373
  return l3;
126351
- let f3 = buildAggRelation(e11, u, [], [l3], e11.currentGraphId, i);
126374
+ let f3 = buildAggRelation(e11, u, [], [l3], i);
126352
126375
  return {
126353
126376
  kind: "computed_ref",
126354
126377
  id: e11.newNodeId(i),
126355
126378
  ty: r3,
126356
126379
  reduce: f3,
126357
- column: r3.fieldName,
126358
- graphId: e11.currentGraphId
126380
+ column: r3.fieldName
126359
126381
  };
126360
126382
  }
126361
126383
  function columnRef(e11, t, n, r3) {
@@ -126365,20 +126387,18 @@ function columnRef(e11, t, n, r3) {
126365
126387
  id: e11.newNodeId(r3),
126366
126388
  ty: i,
126367
126389
  name: t,
126368
- path: [],
126369
- graphId: e11.currentGraphId
126390
+ path: []
126370
126391
  };
126371
126392
  }
126372
- function buildAggRelation(e11, t, n, r3, i, a) {
126373
- let s3 = isTableType(t.ty) ? t.ty.rootModel : undefined, c3 = [...n.map((e12) => e12.expr), ...r3], l3 = createTableType(createRowType(projectColumns(e11, c3, c3.map(() => a))), s3);
126393
+ function buildAggRelation(e11, t, n, r3, i) {
126394
+ let a = isTableType(t.ty) ? t.ty.rootModel : undefined, s3 = [...n.map((e12) => e12.expr), ...r3], c3 = createTableType(createRowType(projectColumns(e11, s3, s3.map(() => i))), a);
126374
126395
  return {
126375
126396
  kind: "reduce",
126376
- id: e11.newNodeId(a),
126377
- ty: l3,
126397
+ id: e11.newNodeId(i),
126398
+ ty: c3,
126378
126399
  input: t,
126379
126400
  by: n,
126380
- aggregates: r3,
126381
- graphId: i
126401
+ aggregates: r3
126382
126402
  };
126383
126403
  }
126384
126404
  function aggregationFieldType(e11, t, n, r3, i, a) {
@@ -126426,7 +126446,7 @@ function clearOrigin(e11, t) {
126426
126446
  return;
126427
126447
  if (t.length === 1)
126428
126448
  return t[0];
126429
- let n = currentGraph(e11), r3 = t.filter((e12) => !!resolveJoinTree(t.filter((t3) => t3 !== e12), n, e12, false));
126449
+ let n = baseGraph(e11), r3 = t.filter((e12) => !!resolveJoinTree(t.filter((t3) => t3 !== e12), n, e12, false));
126430
126450
  return r3.length === 1 ? r3[0] : undefined;
126431
126451
  }
126432
126452
  function aggregateRelations(e11) {
@@ -126448,6 +126468,7 @@ function aggregateRelations(e11) {
126448
126468
  break;
126449
126469
  case "lod":
126450
126470
  case "where":
126471
+ case "with_relationships":
126451
126472
  case "period":
126452
126473
  case "rolling":
126453
126474
  case "time_spine":
@@ -126588,7 +126609,7 @@ function expandTreeOf(e11) {
126588
126609
  t = t.result;
126589
126610
  continue;
126590
126611
  }
126591
- if (t.kind === "explore_context") {
126612
+ if (t.kind === "explore_context" || t.kind === "with_relationships") {
126592
126613
  t = t.value;
126593
126614
  continue;
126594
126615
  }
@@ -126643,7 +126664,7 @@ function dimLines(e11, t) {
126643
126664
  return dedupeLines(e11.map((e12) => dimLine(e12.origin, n, r3)));
126644
126665
  }
126645
126666
  function grainSource(e11) {
126646
- return e11.kind === "block" ? grainSource(e11.result) : e11.kind === "explore_context" ? grainSource(e11.value) : ("input" in e11) ? e11.input : undefined;
126667
+ return e11.kind === "block" ? grainSource(e11.result) : e11.kind === "explore_context" || e11.kind === "with_relationships" ? grainSource(e11.value) : ("input" in e11) ? e11.input : undefined;
126647
126668
  }
126648
126669
  function dedupeLines(e11) {
126649
126670
  let t = /* @__PURE__ */ new Set;
@@ -126679,7 +126700,7 @@ function aggregateSources(e11, t) {
126679
126700
  return r3(t), n;
126680
126701
  }
126681
126702
  function unwrapResult(e11) {
126682
- return e11.kind === "block" ? unwrapResult(e11.result) : e11.kind === "explore_context" ? unwrapResult(e11.value) : e11.kind === "sort" || e11.kind === "filter" ? unwrapResult(e11.input) : e11;
126703
+ return e11.kind === "block" ? unwrapResult(e11.result) : e11.kind === "explore_context" || e11.kind === "with_relationships" ? unwrapResult(e11.value) : e11.kind === "sort" || e11.kind === "filter" ? unwrapResult(e11.input) : e11;
126683
126704
  }
126684
126705
  function resultMetricSources(e11, t) {
126685
126706
  let n = unwrapResult(t);
@@ -126707,6 +126728,7 @@ function resultGrainKeys(e11) {
126707
126728
  case "block":
126708
126729
  return resultGrainKeys(e11.result);
126709
126730
  case "explore_context":
126731
+ case "with_relationships":
126710
126732
  return resultGrainKeys(e11.value);
126711
126733
  default:
126712
126734
  return "input" in e11 ? resultGrainKeys(e11.input) : [];
@@ -126998,8 +127020,7 @@ var TableToJsonFold = class extends HirFold {
126998
127020
  id: this.resolver.newNodeId(t),
126999
127021
  ty: e11,
127000
127022
  name: e11.fieldName,
127001
- path: [],
127002
- graphId: this.resolver.currentGraphId
127023
+ path: []
127003
127024
  }, { origin: r3 } = e11;
127004
127025
  if (r3) {
127005
127026
  let e12 = resolveModel(this.resolver, r3.modelName), t3 = e12 ? findField(e12, r3.fieldName) : undefined;
@@ -127011,12 +127032,11 @@ var TableToJsonFold = class extends HirFold {
127011
127032
  function castTablesToJson(e11, t) {
127012
127033
  return new TableToJsonFold(e11).foldExpr(t);
127013
127034
  }
127014
- function makeCondition(e11, t, n, r3) {
127035
+ function makeCondition(e11, t, n) {
127015
127036
  return {
127016
127037
  predicate: t,
127017
127038
  targets: conditionSubjects(e11, t),
127018
- role: n,
127019
- graphId: r3
127039
+ role: n
127020
127040
  };
127021
127041
  }
127022
127042
  function conditionSubjects(e11, t) {
@@ -127228,10 +127248,8 @@ function resolveBareName(e11, t, n, r3, i) {
127228
127248
  }
127229
127249
  function resolveModuleRef(e11, t, n, r3, i, a, s3 = i) {
127230
127250
  let c3 = lookupModuleTarget(e11, [...n, t], enclosingModelOf(r3), !!a);
127231
- if (c3?.kind === "model") {
127232
- let t3 = makeRef(e11, c3.model.name, [], c3.model.ty, i, a);
127233
- return t3.graphId = e11.currentGraphId, t3;
127234
- }
127251
+ if (c3?.kind === "model")
127252
+ return makeRef(e11, c3.model.name, [], c3.model.ty, i, a);
127235
127253
  if (c3?.kind === "module")
127236
127254
  return makeRef(e11, t, n, moduleTargetType(c3.module), i, a);
127237
127255
  if (c3?.kind === "userattribute") {
@@ -127241,11 +127259,7 @@ function resolveModuleRef(e11, t, n, r3, i, a, s3 = i) {
127241
127259
  }
127242
127260
  if (c3?.kind === "field") {
127243
127261
  let s4 = lookupColumn(r3, genUniqueFieldName({ name: c3.field.name.name }, c3.model.name));
127244
- if (s4) {
127245
- let r4 = makeRef(e11, t, n, s4, i, a);
127246
- return r4.graphId = e11.currentGraphId, r4;
127247
- }
127248
- return resolveFieldRef(e11, c3.model, c3.field, t, n, i, a);
127262
+ return s4 ? makeRef(e11, t, n, s4, i, a) : resolveFieldRef(e11, c3.model, c3.field, t, n, i, a);
127249
127263
  }
127250
127264
  if (n.length >= 1) {
127251
127265
  let c4 = resolveBlockDecl(e11, t, n, r3, i, a);
@@ -127280,7 +127294,7 @@ function resolveFieldRef(e11, t, n, r3, i, a, s3) {
127280
127294
  };
127281
127295
  }
127282
127296
  let u = makeRef(e11, r3, i, l3, a, s3);
127283
- if (u.graphId = e11.currentGraphId, n.kind === "dimension") {
127297
+ if (n.kind === "dimension") {
127284
127298
  let t3 = n.id;
127285
127299
  u.declId = t3, e11.declarationsMap.set(t3, n);
127286
127300
  }
@@ -128126,45 +128140,43 @@ function makeUnique(e11, t, n, r3) {
128126
128140
  kind: "unique",
128127
128141
  id: e11.newNodeId(r3),
128128
128142
  ty: n,
128129
- keys: modelFieldExprs(e11, t),
128130
- graphId: e11.currentGraphId
128143
+ keys: modelFieldExprs(e11, t)
128131
128144
  };
128132
128145
  }
128133
128146
  var AMBIGUOUS_PATHS_WARNING = "WARNING: There are ambiguities in dimensions' relationships, leading to multiple possible interpretations. Results may not match expectations.";
128134
- function resolveUnique(e11, t, n, r3, i = [], a = [], s3 = undefined) {
128135
- let c3 = t.map((e12) => e12.expr), l3 = keyOrigins(c3), u = uniqueKeyModels(c3);
128136
- if (u.length === 0)
128137
- return selectOneReduce(e11, r3);
128138
- let f3 = currentGraph(e11), p3 = buildMostEncompassingTree(u, f3), m3 = import_lodash2.uniq([...u, ...i]), S3 = buildComponentTrees(m3, [], f3), w3 = f3.minimalSubGraph(m3, [], true).isCyclic() ? [AMBIGUOUS_PATHS_WARNING] : undefined, E3 = (e12) => w3 && (e12.kind === "fanout" || e12.kind === "reduce") ? {
128147
+ function resolveUnique(e11, t, n, r3, i, a = [], s3 = [], c3 = undefined) {
128148
+ let l3 = n.map((e12) => e12.expr), u = keyOrigins(l3), f3 = uniqueKeyModels(l3);
128149
+ if (f3.length === 0)
128150
+ return selectOneReduce(e11, i);
128151
+ let p3 = buildMostEncompassingTree(f3, t), m3 = import_lodash2.uniq([...f3, ...a]), S3 = buildComponentTrees(m3, [], t), w3 = t.minimalSubGraph(m3, [], true).isCyclic() ? [AMBIGUOUS_PATHS_WARNING] : undefined, E3 = (e12) => w3 && (e12.kind === "fanout" || e12.kind === "reduce") ? {
128139
128152
  ...e12,
128140
128153
  annotations: [...e12.annotations ?? [], ...w3]
128141
128154
  } : e12, N = S3.length > 0 && !p3;
128142
128155
  if (!N && p3) {
128143
- let e12 = new Set(p3.models()), t3 = u.some((t4) => !e12.has(t4)), n3 = i.some((e13) => !buildMostEncompassingTree(import_lodash2.uniq([...u, e13]), f3));
128144
- N = S3.length > 1 && (t3 || n3);
128156
+ let e12 = new Set(p3.models()), n3 = f3.some((t3) => !e12.has(t3)), r4 = a.some((e13) => !buildMostEncompassingTree(import_lodash2.uniq([...f3, e13]), t));
128157
+ N = S3.length > 1 && (n3 || r4);
128145
128158
  }
128146
128159
  if (N) {
128147
- let [t3, i3, s4] = connectComponents(e11, c3, S3[0], S3.slice(1), c3, a);
128148
- if (i3.length === l3.length && s4.length === 0)
128160
+ let [t3, n3, a3] = connectComponents(e11, l3, S3[0], S3.slice(1), l3, s3);
128161
+ if (n3.length === u.length && a3.length === 0)
128149
128162
  return E3({
128150
128163
  kind: "fanout",
128151
- id: e11.newNodeId(r3),
128152
- ty: n,
128164
+ id: e11.newNodeId(i),
128165
+ ty: r3,
128153
128166
  root: t3,
128154
- outerDims: i3,
128155
- graphId: e11.currentGraphId
128167
+ outerDims: n3
128156
128168
  });
128157
128169
  }
128158
128170
  if (p3) {
128159
- let a3 = i.length > 0 ? buildMostEncompassingTree(import_lodash2.uniq([...u, ...i]), f3) ?? p3 : p3;
128160
- if (s3) {
128161
- let e12 = s3(a3.root);
128171
+ let s4 = a.length > 0 ? buildMostEncompassingTree(import_lodash2.uniq([...f3, ...a]), t) ?? p3 : p3;
128172
+ if (c3) {
128173
+ let e12 = c3(s4.root);
128162
128174
  if (e12)
128163
128175
  return E3(e12);
128164
128176
  }
128165
- return E3(distinctReduce(e11, t, n, a3.root, buildExpansions(e11, a3, c3), r3));
128177
+ return E3(distinctReduce(e11, n, r3, s4.root, buildExpansions(e11, s4, l3), i));
128166
128178
  }
128167
- return e11.dataset.diagnostics.push(createError(ErrorCode.RELATIONSHIP_NOT_FOUND_0, r3, undefined, "Cannot resolve relationship between selected fields")), distinctReduce(e11, t, n, u[0] ?? "", [], r3);
128179
+ return e11.dataset.diagnostics.push(createError(ErrorCode.RELATIONSHIP_NOT_FOUND_0, i, undefined, "Cannot resolve relationship between selected fields")), distinctReduce(e11, n, r3, f3[0] ?? "", [], i);
128168
128180
  }
128169
128181
  function selectOneReduce(e11, t) {
128170
128182
  let n = createFieldType("one", numberType, createModelFieldReference(selectOneModelName, "one"), selectOneModelName, "dimension"), r3 = {
@@ -128172,8 +128184,7 @@ function selectOneReduce(e11, t) {
128172
128184
  id: e11.newNodeId(t),
128173
128185
  ty: n,
128174
128186
  name: "one",
128175
- path: [],
128176
- graphId: e11.currentGraphId
128187
+ path: []
128177
128188
  }, i = createTableType(createRowType([n]), selectOneModelName);
128178
128189
  return distinctReduce(e11, modelFieldExprs(e11, [r3]), i, selectOneModelName, [], t);
128179
128190
  }
@@ -128185,8 +128196,7 @@ function distinctReduce(e11, t, n, r3, i, a) {
128185
128196
  root: r3,
128186
128197
  expansions: i,
128187
128198
  expandedTables: [],
128188
- fields: [],
128189
- graphId: e11.currentGraphId
128199
+ fields: []
128190
128200
  };
128191
128201
  return {
128192
128202
  kind: "reduce",
@@ -128194,8 +128204,7 @@ function distinctReduce(e11, t, n, r3, i, a) {
128194
128204
  ty: n,
128195
128205
  input: s3,
128196
128206
  by: t,
128197
- aggregates: [],
128198
- graphId: e11.currentGraphId
128207
+ aggregates: []
128199
128208
  };
128200
128209
  }
128201
128210
  function uniqueKeyModels(e11) {
@@ -128558,6 +128567,8 @@ function grainOf(e11, t) {
128558
128567
  case "filter":
128559
128568
  case "select":
128560
128569
  return grainOf(e11.input, t);
128570
+ case "with_relationships":
128571
+ return grainOf(e11.value, t);
128561
128572
  default:
128562
128573
  return t;
128563
128574
  }
@@ -128936,15 +128947,15 @@ function resolveWithRelationships(e11, t, n, r3) {
128936
128947
  }
128937
128948
  if (c3)
128938
128949
  return e11.resolveExpr(i, r3);
128939
- try {
128940
- return withGraph(e11, currentGraph(e11).derivedGraph(s3.map(relTypeToRel), false), () => e11.resolveExpr(i, r3));
128941
- } catch (t3) {
128942
- if (t3.code === ErrorCode.RELATIONSHIP_NOT_FOUND_0) {
128943
- let r4 = t3.args;
128944
- return e11.dataset.diagnostics.push(createError(ErrorCode.RELATIONSHIP_NOT_FOUND_0, n, undefined, r4?.[0])), synthIdent(e11, "<with_relationships>", [], errType, n);
128945
- }
128946
- throw t3;
128947
- }
128950
+ let l3 = e11.resolveExpr(i, r3);
128951
+ return {
128952
+ kind: "with_relationships",
128953
+ id: e11.newNodeId(n),
128954
+ ty: l3.ty,
128955
+ value: l3,
128956
+ relationships: s3.map(relTypeToRel),
128957
+ allowNewRelationships: false
128958
+ };
128948
128959
  }
128949
128960
  registerMacro("with_relationships", (e11, t, n, r3) => resolveWithRelationships(e11, t, r3, n));
128950
128961
  function resolveRow(e11, t, n) {
@@ -129227,8 +129238,7 @@ function buildBranch(e11, t) {
129227
129238
  id: n.newNodeId(r3),
129228
129239
  ty: c3,
129229
129240
  grains: modelFieldExprs(n, u),
129230
- output: m3,
129231
- graphId: n.currentGraphId
129241
+ output: m3
129232
129242
  } : makeTransform(n, "select", [makeUnique(n, u, createTableType(createRowType(u.map((e12) => isFieldType(e12.ty) ? e12.ty : createFieldType("", unknownType))), undefined), r3), ...m3], c3, r3);
129233
129243
  }
129234
129244
  function filterFieldOrigins(e11) {
@@ -129281,7 +129291,6 @@ function relationFieldRef(e11, t, n) {
129281
129291
  name: n.fieldName,
129282
129292
  path: [],
129283
129293
  qualifier: t,
129284
- graphId: r3.currentGraphId,
129285
129294
  synthetic: true
129286
129295
  };
129287
129296
  }
@@ -129292,8 +129301,7 @@ function boolCall(e11, t, n) {
129292
129301
  id: r3.newNodeId(i),
129293
129302
  ty: a,
129294
129303
  name: makeIdent(r3, t, [], a, i),
129295
- args: n,
129296
- graphId: r3.currentGraphId
129304
+ args: n
129297
129305
  };
129298
129306
  }
129299
129307
  function buildEmptyChildrenChain(e11, t, n, r3, i) {
@@ -129317,8 +129325,7 @@ function buildEmptyChildrenChain(e11, t, n, r3, i) {
129317
129325
  joinKind: "left_outer",
129318
129326
  on: i3,
129319
129327
  leftAlias: t3 === 1 ? n3.alias : undefined,
129320
- rightAlias: r4.alias,
129321
- graphId: a.currentGraphId
129328
+ rightAlias: r4.alias
129322
129329
  };
129323
129330
  }
129324
129331
  let S3 = (e12) => {
@@ -129334,8 +129341,7 @@ function buildEmptyChildrenChain(e11, t, n, r3, i) {
129334
129341
  id: a.newNodeId(s3),
129335
129342
  ty: t3,
129336
129343
  name: makeIdent(a, "coalesce", [], t3, s3),
129337
- args: [n3, ...r4.map((e12) => cloneResolved(a, e12))],
129338
- graphId: a.currentGraphId
129344
+ args: [n3, ...r4.map((e12) => cloneResolved(a, e12))]
129339
129345
  };
129340
129346
  return {
129341
129347
  kind: Kind.NAMED_EXPRESSION,
@@ -129347,11 +129353,17 @@ function buildEmptyChildrenChain(e11, t, n, r3, i) {
129347
129353
  })], r3.ty, s3);
129348
129354
  }
129349
129355
  function resolveDynamicExplore(e11, t, n) {
129350
- let r3 = exploreRelationshipGraph(e11, t.relationships, n, t.loc), i = () => {
129351
- let { bindings: r4, inputs: i3 } = resolveExploreParams(e11, t.params, n);
129352
- return i3.length > 0 && (e11.dataset.paramInputs ??= []).push(...i3), withParamBindings(e11, r4, () => resolveDynamicExploreInner(e11, t, n));
129356
+ let r3 = exploreRelationships(e11, t.relationships, n), { bindings: i, inputs: a } = resolveExploreParams(e11, t.params, n);
129357
+ a.length > 0 && (e11.dataset.paramInputs ??= []).push(...a);
129358
+ let s3 = withParamBindings(e11, i, () => resolveDynamicExploreInner(e11, t, n));
129359
+ return r3.length === 0 ? s3 : {
129360
+ kind: "with_relationships",
129361
+ id: e11.newNodeId(t.loc),
129362
+ ty: s3.ty,
129363
+ value: s3,
129364
+ relationships: r3.map(relTypeToRel),
129365
+ allowNewRelationships: true
129353
129366
  };
129354
- return r3 ? withGraph(e11, r3, i) : i();
129355
129367
  }
129356
129368
  function resolveExploreParams(e11, t, n) {
129357
129369
  let r3 = [], i = [];
@@ -129376,25 +129388,15 @@ function resolveExploreParams(e11, t, n) {
129376
129388
  inputs: i
129377
129389
  };
129378
129390
  }
129379
- function exploreRelationshipGraph(e11, t, n, r3) {
129380
- if (t.length === 0)
129381
- return;
129382
- let i = [], a = false;
129383
- for (let r4 of t) {
129384
- let t3 = resolveRelationshipArg(e11, r4, n);
129385
- t3 ? i.push(t3) : a = true;
129391
+ function exploreRelationships(e11, t, n) {
129392
+ let r3 = [];
129393
+ for (let i of t) {
129394
+ let t3 = resolveRelationshipArg(e11, i, n);
129395
+ if (!t3)
129396
+ return [];
129397
+ r3.push(t3);
129386
129398
  }
129387
- if (!a && i.length !== 0)
129388
- try {
129389
- return currentGraph(e11).derivedGraph(i.map(relTypeToRel), true);
129390
- } catch (t3) {
129391
- if (t3.code === ErrorCode.RELATIONSHIP_NOT_FOUND_0) {
129392
- let n3 = t3.args;
129393
- e11.dataset.diagnostics.push(createError(ErrorCode.RELATIONSHIP_NOT_FOUND_0, r3, undefined, n3?.[0]));
129394
- return;
129395
- }
129396
- throw t3;
129397
- }
129399
+ return r3;
129398
129400
  }
129399
129401
  function constantArrayElements(e11) {
129400
129402
  return isConstantArrayType(e11) ? e11.elementTypes : [];
@@ -129548,7 +129550,7 @@ function classifyFilters(e11, t, n) {
129548
129550
  let r3 = [], i = [];
129549
129551
  return t.filters.forEach((t3) => {
129550
129552
  let a = e11.resolveExpr(t3, n);
129551
- validateExploreFilter(e11, t3, a), !isErrType(a.ty) && (isResultFieldFilter(a) ? r3.push(a) : isTableType(a.ty) ? i.push(desugarTableCondition(e11, a, n)) : involvesTable(a) || i.push(desugarMeasureCondition(e11, desugarSimpleModelCondition(e11, desugarShorthandCondition(e11, a)))));
129553
+ validateExploreFilter(e11, t3, a), !isErrType(a.ty) && (isResultFieldFilter(a) ? r3.push(a) : isTableType(a.ty) ? i.push(desugarTableCondition(e11, a, n)) : referencesAggregateAlias(a) ? e11.dataset.diagnostics.push(createError(ErrorCode.INVALID_CONDITIONAL_EXPRESSION_IN_0, t3.loc, undefined, "filters")) : involvesTable(a) || i.push(desugarMeasureCondition(e11, desugarSimpleModelCondition(e11, desugarShorthandCondition(e11, a)))));
129552
129554
  }), {
129553
129555
  resultFilterNodes: r3,
129554
129556
  contextFilterNodes: i
@@ -129589,7 +129591,10 @@ function resolveDynamicExploreInner(e11, t, n) {
129589
129591
  validateHavingGrouped(e11, n3, t3, li3) && oi3.push(desugarMeasureCondition(e11, t3, di3, true));
129590
129592
  }
129591
129593
  r3.length === 0 && t.measures.length === 0 && e11.dataset.diagnostics.push(createError(ErrorCode.INVALID_EXPRESSION_0, t.loc, undefined, "Explore must have at least one dimension or measure."));
129592
- let fi3 = buildGrainExprMap(r3), pi3 = S3.map((e12) => e12.ty), mi3 = new Set(pi3.map((e12) => e12.fieldName)), hi3 = (e12) => e12.kind === Kind.FUNCTION_CALL && e12.args.length > 0 && e12.args[0].kind === Kind.IDENTIFIER && mi3.has(e12.args[0].name), gi3 = He4.filter(hi3), _i2 = He4.filter((e12) => !hi3(e12)), vi2 = {
129594
+ let fi3 = buildGrainExprMap(r3), pi3 = S3.map((e12) => e12.ty), mi3 = new Set(pi3.map((e12) => e12.fieldName)), hi3 = (e12) => {
129595
+ let t3 = unwrapNot(e12);
129596
+ return t3.kind === Kind.FUNCTION_CALL && t3.args.length > 0 && t3.args[0].kind === Kind.IDENTIFIER && mi3.has(t3.args[0].name);
129597
+ }, gi3 = He4.filter(hi3), _i2 = He4.filter((e12) => !hi3(e12)), vi2 = {
129593
129598
  resolver: e11,
129594
129599
  loc: t.loc,
129595
129600
  dimColumns: i,
@@ -129651,8 +129656,7 @@ function resolveDynamicExploreInner(e11, t, n) {
129651
129656
  ty: U3,
129652
129657
  input: s4[0],
129653
129658
  iterationDepth: iterationDepthOf(s4[0]),
129654
- branches: s4,
129655
- graphId: e11.currentGraphId
129659
+ branches: s4
129656
129660
  };
129657
129661
  } else
129658
129662
  Oi3 = Ei3(buildBranch(vi2, i), i);
@@ -129695,8 +129699,7 @@ function resolveDynamicExploreInner(e11, t, n) {
129695
129699
  ty: Oi3.ty,
129696
129700
  input: Oi3,
129697
129701
  iterationDepth: iterationDepthOf(Oi3),
129698
- by: me3,
129699
- graphId: e11.currentGraphId
129702
+ by: me3
129700
129703
  }), m3) {
129701
129704
  let n3 = i.filter((e12) => l3.has(e12.fieldName)), r4 = ki4 && n3.length > 0 && Ai3 ? buildEmptyChildrenPrefixes(vi2, n3, ji4).map((e12) => e12.node) : undefined;
129702
129705
  Oi3 = {
@@ -129712,8 +129715,7 @@ function resolveDynamicExploreInner(e11, t, n) {
129712
129715
  includeEmptyChildrenRows: ki4,
129713
129716
  emptyChildrenPrefixes: r4,
129714
129717
  outputColumns: S3.length > 0 ? Ni3 : undefined,
129715
- sorts: Ii3 ? Li4 : undefined,
129716
- graphId: e11.currentGraphId
129718
+ sorts: Ii3 ? Li4 : undefined
129717
129719
  };
129718
129720
  }
129719
129721
  return Di3.length === 0 && (Oi3 = Si3(Oi3)), {
@@ -129728,8 +129730,44 @@ function resolveDynamicExploreInner(e11, t, n) {
129728
129730
  function isBareAliasConstantFilter(e11) {
129729
129731
  return e11.length === 2 && e11[0].kind === Kind.IDENTIFIER && e11[0].path.length === 0 && !involvesField(e11[1]);
129730
129732
  }
129733
+ function unwrapNot(e11) {
129734
+ return e11.kind === Kind.FUNCTION_CALL && e11.name.name === Kind.NOT_KEYWORD && e11.args.length === 1 ? unwrapNot(e11.args[0]) : e11;
129735
+ }
129731
129736
  function isResultFieldFilter(e11) {
129732
- return isErrType(e11.ty) || e11.kind !== Kind.FUNCTION_CALL ? false : isBareAliasConstantFilter(e11.args);
129737
+ if (isErrType(e11.ty))
129738
+ return false;
129739
+ let t = unwrapNot(e11);
129740
+ if (t.kind !== Kind.FUNCTION_CALL)
129741
+ return false;
129742
+ if (isBareAliasConstantFilter(t.args))
129743
+ return true;
129744
+ let n = bareAliasLeaves(t);
129745
+ return !!n && n.some(isAggregateAlias);
129746
+ }
129747
+ function bareAliasLeaves(e11) {
129748
+ let t = unwrapNot(e11);
129749
+ if (t.kind !== Kind.FUNCTION_CALL)
129750
+ return;
129751
+ if (isBareAliasConstantFilter(t.args)) {
129752
+ let e12 = t.args[0];
129753
+ return isFieldType(e12.ty) ? [e12.ty] : undefined;
129754
+ }
129755
+ if (t.name.name !== Kind.AND_KEYWORD && t.name.name !== Kind.OR_KEYWORD)
129756
+ return;
129757
+ let n = [];
129758
+ for (let e12 of t.args) {
129759
+ let t3 = bareAliasLeaves(e12);
129760
+ if (!t3)
129761
+ return;
129762
+ n.push(...t3);
129763
+ }
129764
+ return n;
129765
+ }
129766
+ function isAggregateAlias(e11) {
129767
+ return e11.subClass === "aggregate" || e11.subClass === "measure" || e11.subClass === "metric";
129768
+ }
129769
+ function referencesAggregateAlias(e11) {
129770
+ return e11.kind === Kind.IDENTIFIER ? e11.path.length === 0 && isFieldType(e11.ty) && isAggregateAlias(e11.ty) : e11.kind === Kind.FUNCTION_CALL ? e11.args.some(referencesAggregateAlias) : e11.kind === Kind.NAMED_EXPRESSION ? referencesAggregateAlias(e11.expr) : e11.kind === "block" ? referencesAggregateAlias(e11.result) : false;
129733
129771
  }
129734
129772
  function involvesTable(e11) {
129735
129773
  return isTableType(e11.ty) && !e11.ty.isLiteral ? true : e11.kind === Kind.FUNCTION_CALL ? e11.args.some(involvesTable) : e11.kind === Kind.NAMED_EXPRESSION ? involvesTable(e11.expr) : e11.kind === "block" ? involvesTable(e11.result) : false;
@@ -130426,8 +130464,7 @@ function toExpandModel(e11, t) {
130426
130464
  root: n,
130427
130465
  expansions: [],
130428
130466
  expandedTables: [],
130429
- fields: [],
130430
- graphId: t.graphId ?? e11.currentGraphId
130467
+ fields: []
130431
130468
  };
130432
130469
  }
130433
130470
  function addJoins(e11, t, n, r3, i = false, a = [], s3 = /* @__PURE__ */ new Set) {
@@ -130463,8 +130500,7 @@ function joinSource(e11, t, n, r3, i, a = false, s3 = [], c3 = /* @__PURE__ */ n
130463
130500
  root: n.kind === "extend_model" ? n : r3,
130464
130501
  expansions: [],
130465
130502
  expandedTables: [],
130466
- fields: [],
130467
- graphId: n.graphId ?? e11.currentGraphId
130503
+ fields: []
130468
130504
  }, i, !a, s3, c3);
130469
130505
  return l3.expansions.length > 0 || (l3.expandedTables?.length ?? 0) > 0 ? l3 : n;
130470
130506
  }
@@ -130534,10 +130570,10 @@ function expandRefs(e11, t, n, r3, i, a = [], s3) {
130534
130570
  if (c4.predicate.kind === "in_table_condition") {
130535
130571
  if (!a3.every((e12) => l4.has(e12)))
130536
130572
  continue;
130537
- n3.predicates = [...n3.predicates ?? [], makeCondition(e11, cloneResolved(e11, appliedPredicate(c4)), c4.role, c4.graphId)];
130573
+ n3.predicates = [...n3.predicates ?? [], makeCondition(e11, cloneResolved(e11, appliedPredicate(c4)), c4.role)];
130538
130574
  continue;
130539
130575
  }
130540
- let u3 = cloneResolved(e11, appliedPredicate(c4)), f4 = makeCondition(e11, u3, c4.role, c4.graphId);
130576
+ let u3 = cloneResolved(e11, appliedPredicate(c4)), f4 = makeCondition(e11, u3, c4.role);
130541
130577
  joinIntoTable(e11, t, n3, crossModelNames([u3], baseModelName(n3.root)).filter((e12) => !l4.has(e12))) && (c4.targets.some(({ origin: e12 }) => r4.some((t3) => {
130542
130578
  let n4 = originOf(t3.ty);
130543
130579
  return refEq(n4, e12) || isSubtimeFieldOf(n4, e12) || isSubtimeFieldOf(e12, n4);
@@ -130807,10 +130843,10 @@ function normalizeConditions(e11, t, n, r3) {
130807
130843
  if (l3.length !== 0)
130808
130844
  if (t3.isCalendar || l3.some((e12) => reachesFannedModel(n, r3, e12))) {
130809
130845
  let t4 = l3.reduce((t5, n3) => makeCall(e11, "and", [t5, n3], truefalseType, locStub(), locStub()));
130810
- s3.push(makeCondition(e11, t4, c4.role, c4.graphId));
130846
+ s3.push(makeCondition(e11, t4, c4.role));
130811
130847
  } else
130812
130848
  for (let t4 of l3)
130813
- s3.push(makeCondition(e11, t4, c4.role, c4.graphId));
130849
+ s3.push(makeCondition(e11, t4, c4.role));
130814
130850
  }
130815
130851
  let c3 = /* @__PURE__ */ new Set;
130816
130852
  return s3.filter((e12) => {
@@ -130910,7 +130946,7 @@ function restatePlacedFilters(e11, t, n, r3, i) {
130910
130946
  if (r4.predicate.kind === "in_table_condition" || r4.targets.length === 0 || !i.has(r4))
130911
130947
  return false;
130912
130948
  let c4 = condFanEdge(e11, t, s3, r4);
130913
- return c4 !== undefined && n3.backKeys.some((e12) => originEq$1(e12, c4.to)) && r4.targets.every((e12) => a3.has(e12.origin.modelName));
130949
+ return c4 !== undefined && n3.backKeys.some((e12) => originEq$1(e12, c4.to)) && r4.targets.every((e12) => a3.has(e12.origin.modelName)) && treeFitsCondition(e11, t, s3, n3, r4);
130914
130950
  });
130915
130951
  return l4.length <= n3.predicates.length ? n3 : (c3 = true, {
130916
130952
  ...n3,
@@ -130931,6 +130967,36 @@ function existenceTreeModels(e11) {
130931
130967
  }
130932
130968
  return t;
130933
130969
  }
130970
+ function stepAcross(e11, t) {
130971
+ return t.from.modelName === e11 ? t.to.modelName : t.from.modelName;
130972
+ }
130973
+ function existenceTreePathKeys(e11) {
130974
+ let t = /* @__PURE__ */ new Map, n = baseModelName(e11.tree.root);
130975
+ for (let r3 of e11.tree.expansions) {
130976
+ let e12 = n, i = "";
130977
+ for (let n3 of r3.path)
130978
+ e12 = stepAcross(e12, n3), i += `${fanEdgeKey(n3)} -> `, t.has(e12) || t.set(e12, i);
130979
+ }
130980
+ return t;
130981
+ }
130982
+ function treeFitsCondition(e11, t, n, r3, i) {
130983
+ let a = conditionGraph(e11, t, i), s3 = existenceTreePathKeys(r3);
130984
+ for (let t3 of crossModelNames([appliedPredicate(i)], n)) {
130985
+ if (t3 === n)
130986
+ continue;
130987
+ let r4 = joinPathTo(e11, a, n, t3);
130988
+ if (!r4)
130989
+ continue;
130990
+ let i3 = n, c3 = "";
130991
+ for (let e12 of r4) {
130992
+ i3 = stepAcross(i3, e12), c3 += `${fanEdgeKey(e12)} -> `;
130993
+ let t4 = s3.get(i3);
130994
+ if (t4 !== undefined && t4 !== c3)
130995
+ return false;
130996
+ }
130997
+ }
130998
+ return true;
130999
+ }
130934
131000
  function condFanEdge(e11, t, n, r3) {
130935
131001
  let i = conditionGraph(e11, t, r3);
130936
131002
  for (let t3 of import_lodash2.uniq(r3.targets.map((e12) => e12.origin.modelName)).filter((e12) => e12 !== n)) {
@@ -130943,7 +131009,7 @@ function condFanEdge(e11, t, n, r3) {
130943
131009
  }
130944
131010
  }
130945
131011
  function conditionGraph(e11, t, n) {
130946
- return n.role !== "rlp" || n.graphId == null ? t : e11.dataset.graphs.get(n.graphId) ?? t;
131012
+ return n.role === "rlp" ? rlpGraph(e11) : t;
130947
131013
  }
130948
131014
  function applyFilter(e11, t, n, r3, i) {
130949
131015
  let a = conditionGraph(e11, t, r3), s3 = baseModelName(n.root), c3 = new Set([s3, ...n.expansions.filter((e12) => fanIndex(s3, e12.path) < 0).map((e12) => baseModelName(e12.model))]), l3 = import_lodash2.uniq(r3.targets.map((e12) => e12.origin.modelName)).filter((e12) => !c3.has(e12)), u, f3 = false;
@@ -130977,14 +131043,14 @@ function applyFilter(e11, t, n, r3, i) {
130977
131043
  let c4 = (n.expandedTables ?? []).find((e12) => fanEdgeKey(e12.edge) === fanEdgeKey(p3) && e12.expansions.some((e13) => e13.fields.length > 0)), l4 = leafFieldRefs(r3.predicate.row.map((e12) => e12.expr)).some((e12) => originOf(e12.ty)?.modelName === s3);
130978
131044
  if (c4 && !l4) {
130979
131045
  let t4 = crossModelNames(r3.predicate.row.map((e12) => e12.expr), s3), n3 = new Set(expandedTableModels(c4));
130980
- joinIntoTable(e11, a, c4, t4.filter((e12) => !n3.has(e12))) && (c4.pruningPredicates = [...c4.pruningPredicates ?? [], makeCondition(e11, cloneResolved(e11, appliedPredicate(r3)), r3.role, r3.graphId)]);
131046
+ joinIntoTable(e11, a, c4, t4.filter((e12) => !n3.has(e12))) && (c4.pruningPredicates = [...c4.pruningPredicates ?? [], makeCondition(e11, cloneResolved(e11, appliedPredicate(r3)), r3.role)]);
130981
131047
  }
130982
131048
  return {
130983
131049
  ...n,
130984
131050
  existenceFilters: [...m3, t3]
130985
131051
  };
130986
131052
  }
130987
- let S3 = m3.find((e12) => !e12.negated && e12.predicates.every((e13) => e13.kind !== "in_table_condition") && e12.backKeys.some((e13) => originEq$1(e13, p3.to))), w3 = S3 ? conjoinScalarExistenceFilter(e11, a, s3, S3, r3) : buildScalarExistenceFilter(e11, a, s3, [r3], [p3.from.modelName]);
131053
+ let S3 = m3.find((t3) => !t3.negated && t3.predicates.every((e12) => e12.kind !== "in_table_condition") && t3.backKeys.some((e12) => originEq$1(e12, p3.to)) && treeFitsCondition(e11, a, s3, t3, r3)), w3 = S3 ? conjoinScalarExistenceFilter(e11, a, s3, S3, r3) : buildScalarExistenceFilter(e11, a, s3, [r3], [p3.from.modelName]);
130988
131054
  return w3 ? (i.add(r3), {
130989
131055
  ...n,
130990
131056
  existenceFilters: S3 ? m3.map((e12) => e12 === S3 ? w3 : e12) : [...m3, w3]
@@ -131080,25 +131146,23 @@ var Rolling = class {
131080
131146
  applyToRef(e11, t, n) {
131081
131147
  let { g: r3 } = this, i = this.pending;
131082
131148
  this.pending = undefined;
131083
- let a = i ? rollingGrainLayout(r3.resolver, i, r3.grain.map((e12) => e12.expr)) : undefined, s3 = a ? a.columns.map((e12) => e12.expr) : [], c3 = r3.resolver.currentGraphId;
131084
- r3.resolver.currentGraphId = e11.graphId ?? c3;
131085
- let l3 = r3.contextFilters, u, f3 = i?.keepFilters === false || (i?.lowerBounds.size ?? 0) > 0;
131086
- if (i && a && f3 && r3.contextFilters.some((e12) => filterOnRunDimension(e12, i.run.map((e13) => e13.key)))) {
131149
+ let a = i ? rollingGrainLayout(r3.resolver, i, r3.grain.map((e12) => e12.expr)) : undefined, s3 = a ? a.columns.map((e12) => e12.expr) : [], c3 = r3.contextFilters, l3, u = i?.keepFilters === false || (i?.lowerBounds.size ?? 0) > 0;
131150
+ if (i && a && u && r3.contextFilters.some((e12) => filterOnRunDimension(e12, i.run.map((e13) => e13.key)))) {
131087
131151
  let t3 = r3.period.withActive(s3, () => n(modelFieldExprs(r3.resolver, s3)));
131088
- u = {
131152
+ l3 = {
131089
131153
  ...e11,
131090
131154
  reduce: t3
131091
131155
  };
131092
131156
  let a3 = i.run.map((e12) => e12.key);
131093
131157
  r3.contextFilters = r3.contextFilters.filter((e12) => !filterOnRunDimension(e12, a3));
131094
131158
  }
131095
- let p3 = a ? r3.period.withActive(s3, () => n(modelFieldExprs(r3.resolver, s3))) : n(r3.aggGrain());
131096
- r3.contextFilters = l3, r3.resolver.currentGraphId = c3, this.pending = i;
131097
- let m3 = {
131159
+ let f3 = a ? r3.period.withActive(s3, () => n(modelFieldExprs(r3.resolver, s3))) : n(r3.aggGrain());
131160
+ r3.contextFilters = c3, this.pending = i;
131161
+ let p3 = {
131098
131162
  ...e11,
131099
- reduce: p3
131100
- }, S3 = i?.fillMissing ? r3.explore.pivotAxes() : undefined;
131101
- return a ? applyRolling(r3.resolver, m3, a, t, u, S3) : m3;
131163
+ reduce: f3
131164
+ }, m3 = i?.fillMissing ? r3.explore.pivotAxes() : undefined;
131165
+ return a ? applyRolling(r3.resolver, p3, a, t, l3, m3) : p3;
131102
131166
  }
131103
131167
  };
131104
131168
  function rollingGrainLayout(e11, t, n) {
@@ -131198,8 +131262,7 @@ function regroupAtGrain(e11, t, n, r3) {
131198
131262
  ty: createTableType(createRowType([...i.map((e12) => e12.ty), ...t.reduce.aggregates.map((e12) => e12.ty)]), t.reduce.ty.rootModel),
131199
131263
  input: t.reduce.input,
131200
131264
  by: i,
131201
- aggregates: t.reduce.aggregates,
131202
- graphId: t.reduce.graphId
131265
+ aggregates: t.reduce.aggregates
131203
131266
  };
131204
131267
  return {
131205
131268
  ...t,
@@ -131228,8 +131291,7 @@ function distinctAxis(e11, t, n, r3) {
131228
131291
  ty: createTableType(createRowType(a.map((e12) => e12.ty)), t.ty.rootModel),
131229
131292
  input: i,
131230
131293
  by: a,
131231
- aggregates: [],
131232
- graphId: t.graphId
131294
+ aggregates: []
131233
131295
  };
131234
131296
  }
131235
131297
  function fillPivotAnchor(e11, t, n, r3, i) {
@@ -131250,8 +131312,7 @@ function fillPivotAnchor(e11, t, n, r3, i) {
131250
131312
  joinKind: "inner",
131251
131313
  on: f3,
131252
131314
  leftAlias: relationAlias(l3),
131253
- rightAlias: relationAlias(u),
131254
- graphId: t.graphId
131315
+ rightAlias: relationAlias(u)
131255
131316
  }, m3 = (e12) => a[e12] === "row" ? l3 : u, S3 = t.by.some((e12, t3) => a[t3] === undefined);
131256
131317
  if (!r3 && !S3) {
131257
131318
  let n3 = modelFieldExprs(e11, t.by.map((t3, n4) => relationColumnRef(e11, m3(n4), t3.expr)));
@@ -131261,8 +131322,7 @@ function fillPivotAnchor(e11, t, n, r3, i) {
131261
131322
  ty: createTableType(createRowType(n3.map((e12) => e12.ty)), t.ty.rootModel),
131262
131323
  input: p3,
131263
131324
  by: n3,
131264
- aggregates: [],
131265
- graphId: t.graphId
131325
+ aggregates: []
131266
131326
  };
131267
131327
  }
131268
131328
  let w3 = cloneResolved(e11, t), E3 = t.by.map((t3, n3) => a[n3] === undefined ? undefined : call(e11, "null_safe_eq", [relationColumnRef(e11, m3(n3), t3.expr), relationColumnRef(e11, w3, t3.expr)], truefalseType, i)).filter((e12) => e12 !== undefined), N = {
@@ -131274,8 +131334,7 @@ function fillPivotAnchor(e11, t, n, r3, i) {
131274
131334
  joinKind: "left_outer",
131275
131335
  on: E3.reduce((t3, n3) => call(e11, "and", [t3, n3], truefalseType, i)),
131276
131336
  leftAlias: relationAlias(p3),
131277
- rightAlias: relationAlias(w3),
131278
- graphId: t.graphId
131337
+ rightAlias: relationAlias(w3)
131279
131338
  }, I3 = modelFieldExprs(e11, t.by.map((t3, n3) => relationColumnRef(e11, a[n3] === undefined ? w3 : m3(n3), t3.expr))), L3 = t.aggregates.map((t3) => {
131280
131339
  let n3 = t3, r4 = n3.ty.fieldName, a3 = {
131281
131340
  kind: Kind.IDENTIFIER,
@@ -131283,8 +131342,7 @@ function fillPivotAnchor(e11, t, n, r3, i) {
131283
131342
  ty: n3.ty,
131284
131343
  name: r4,
131285
131344
  path: [],
131286
- qualifier: relationAlias(w3),
131287
- graphId: w3.graphId
131345
+ qualifier: relationAlias(w3)
131288
131346
  };
131289
131347
  return {
131290
131348
  ...n3,
@@ -131298,8 +131356,7 @@ function fillPivotAnchor(e11, t, n, r3, i) {
131298
131356
  ty: createTableType(createRowType([...I3.map((e12) => e12.ty), ...L3.map((e12) => e12.ty)]), t.ty.rootModel),
131299
131357
  input: N,
131300
131358
  by: I3,
131301
- aggregates: L3,
131302
- graphId: t.graphId
131359
+ aggregates: L3
131303
131360
  };
131304
131361
  }
131305
131362
  function windowJoin(e11, t, n, r3, i, a, s3) {
@@ -131322,8 +131379,7 @@ function windowJoin(e11, t, n, r3, i, a, s3) {
131322
131379
  joinKind: "inner",
131323
131380
  on: w3,
131324
131381
  leftAlias: relationAlias(c3),
131325
- rightAlias: relationAlias(S3),
131326
- graphId: c3.graphId
131382
+ rightAlias: relationAlias(S3)
131327
131383
  }, N = modelFieldExprs(e11, c3.by.filter((e12, t3) => !i.columns[t3].extra).map((t3) => relationColumnRef(e11, S3, t3.expr))), I3 = relationColumnRef(e11, c3, t, t.column), L3 = isFieldType(t.ty) ? createFieldType(t.column, t.ty.type, undefined, undefined, "aggregate") : t.ty, U3 = {
131328
131384
  kind: Kind.FUNCTION_CALL,
131329
131385
  id: e11.newNodeId(r3),
@@ -131339,8 +131395,7 @@ function windowJoin(e11, t, n, r3, i, a, s3) {
131339
131395
  ty: W3,
131340
131396
  input: E3,
131341
131397
  by: N,
131342
- aggregates: [U3],
131343
- graphId: c3.graphId
131398
+ aggregates: [U3]
131344
131399
  },
131345
131400
  column: t.column
131346
131401
  };
@@ -131535,7 +131590,6 @@ function relationColumnRef(e11, t, n, r3) {
131535
131590
  name: r3 ?? columnAlias(n, 0),
131536
131591
  path: [],
131537
131592
  qualifier: relationAlias(t),
131538
- graphId: t.graphId,
131539
131593
  synthetic: true,
131540
131594
  ...a === undefined ? {} : { timeSpine: a }
131541
131595
  };
@@ -131645,8 +131699,7 @@ function addInheritedPartition(e11, t) {
131645
131699
  id: e11.resolver.newNodeId(r3),
131646
131700
  ty: n3.ty,
131647
131701
  name: makeIdent(e11.resolver, "partition", [], n3.ty, r3),
131648
- expr: n3,
131649
- graphId: e11.resolver.currentGraphId
131702
+ expr: n3
131650
131703
  };
131651
131704
  });
131652
131705
  return i.length > 0 ? {
@@ -131668,8 +131721,7 @@ function partitionByRemainingGrain(e11, t) {
131668
131721
  id: e11.resolver.newNodeId(i),
131669
131722
  ty: n3.ty,
131670
131723
  name: makeIdent(e11.resolver, "partition", [], n3.ty, i),
131671
- expr: n3,
131672
- graphId: e11.resolver.currentGraphId
131724
+ expr: n3
131673
131725
  };
131674
131726
  });
131675
131727
  return a.length > 0 ? {
@@ -131738,15 +131790,13 @@ var Window = class {
131738
131790
  expr: {
131739
131791
  ...e11,
131740
131792
  ty: a
131741
- },
131742
- graphId: t.resolver.currentGraphId
131793
+ }
131743
131794
  }, l3 = {
131744
131795
  kind: "merge",
131745
131796
  id: t.resolver.newNodeId(n),
131746
131797
  ty: createTableType(createRowType([...s3, a]), undefined),
131747
131798
  grains: t.grain.map((e12) => cloneResolved(t.resolver, e12)),
131748
- output: [...t.grain.map((e12) => cloneResolved(t.resolver, e12.expr)), c3],
131749
- graphId: t.resolver.currentGraphId
131799
+ output: [...t.grain.map((e12) => cloneResolved(t.resolver, e12.expr)), c3]
131750
131800
  }, u = t.grain.map((e12) => cloneResolved(t.resolver, e12)), f3 = createFieldType(r3, i, undefined, undefined, "aggregate"), p3 = {
131751
131801
  kind: Kind.FUNCTION_CALL,
131752
131802
  id: t.resolver.newNodeId(n),
@@ -131759,16 +131809,14 @@ var Window = class {
131759
131809
  ty: createTableType(createRowType([...u.map((e12) => e12.ty), f3]), undefined),
131760
131810
  input: l3,
131761
131811
  by: u,
131762
- aggregates: [p3],
131763
- graphId: t.resolver.currentGraphId
131812
+ aggregates: [p3]
131764
131813
  }, S3 = isFieldType(e11.ty) ? createFieldType(r3, e11.ty.type, undefined, undefined, "aggregate") : f3;
131765
131814
  return {
131766
131815
  kind: "computed_ref",
131767
131816
  id: t.resolver.newNodeId(n),
131768
131817
  ty: S3,
131769
131818
  reduce: m3,
131770
- column: r3,
131771
- graphId: t.resolver.currentGraphId
131819
+ column: r3
131772
131820
  };
131773
131821
  }
131774
131822
  foldAgg(e11) {
@@ -131831,8 +131879,7 @@ var Window = class {
131831
131879
  ty: e12.ty,
131832
131880
  name: makeIdent(u.resolver, e12.name, [], e12.ty, l3),
131833
131881
  expr: e12.expr
131834
- }))],
131835
- graphId: u.resolver.currentGraphId
131882
+ }))]
131836
131883
  }, N = e11.map((e12, t3) => {
131837
131884
  let i3 = `__w_${this.windowLodCounter++}`, a3 = createFieldType(i3, numberType), c4 = w3[t3];
131838
131885
  return {
@@ -131962,9 +132009,9 @@ function substituteTimeSpineCondition(e11, t, n) {
131962
132009
  ...t.predicate,
131963
132010
  row: substituteTimeSpineRow(e11, t.predicate.row, n)
131964
132011
  };
131965
- return makeCondition(e11.resolver, r3, t.role, t.graphId);
132012
+ return makeCondition(e11.resolver, r3, t.role);
131966
132013
  }
131967
- return makeCondition(e11.resolver, substituteTimeSpineInExpr(e11, t.predicate, n), t.role, t.graphId);
132014
+ return makeCondition(e11.resolver, substituteTimeSpineInExpr(e11, t.predicate, n), t.role);
131968
132015
  }
131969
132016
  function substituteTimeSpineRow(e11, t, n) {
131970
132017
  return modelFieldExprs(e11.resolver, t.map((t3) => substituteTimeSpineKey(e11, dayGrainCalendarKey(e11, t3.expr), n)));
@@ -132203,9 +132250,9 @@ var Period = class e11 {
132203
132250
  } else
132204
132251
  this.mods.set(s3, {
132205
132252
  ...c3,
132206
- match: makeCondition(t.resolver, shiftFilterByInterval(t, c3.match.predicate, r4), c3.match.role, c3.match.graphId)
132253
+ match: makeCondition(t.resolver, shiftFilterByInterval(t, c3.match.predicate, r4), c3.match.role)
132207
132254
  });
132208
- t.contextFilters = [...u, ...f3.map((e13) => makeCondition(t.resolver, shiftFilterByInterval(t, e13.predicate, r4), e13.role, e13.graphId))];
132255
+ t.contextFilters = [...u, ...f3.map((e13) => makeCondition(t.resolver, shiftFilterByInterval(t, e13.predicate, r4), e13.role))];
132209
132256
  }
132210
132257
  }
132211
132258
  return t.foldExpr(e12.value);
@@ -132237,17 +132284,17 @@ var Period = class e11 {
132237
132284
  if (matchesDim(e12, t.origin))
132238
132285
  return t;
132239
132286
  }
132240
- strictBounds(e12, t, n) {
132287
+ strictBounds(e12, t) {
132241
132288
  if (!this.anyActive)
132242
132289
  return [];
132243
- let r3 = [];
132244
- for (let i of this.mods.values()) {
132245
- if (i.kind !== "relative" || !i.strictDim)
132290
+ let n = [];
132291
+ for (let r3 of this.mods.values()) {
132292
+ if (r3.kind !== "relative" || !r3.strictDim)
132246
132293
  continue;
132247
- let a = e12.filter((e13) => matchesDim(e13, i.origin) && this.isShifted(e13)), s3 = a.length > 0 ? strictClamp(this.g, t, n, i.strictDim, a) : undefined;
132248
- s3 && r3.push(makeCondition(this.g.resolver, s3, "where", n));
132294
+ let i = e12.filter((e13) => matchesDim(e13, r3.origin) && this.isShifted(e13)), a = i.length > 0 ? strictClamp(this.g, t, r3.strictDim, i) : undefined;
132295
+ a && n.push(makeCondition(this.g.resolver, a, "where"));
132249
132296
  }
132250
- return r3;
132297
+ return n;
132251
132298
  }
132252
132299
  isShifted(t) {
132253
132300
  let n = e11.keyOf(t);
@@ -132272,7 +132319,7 @@ var Period = class e11 {
132272
132319
  id: n.resolver.newNodeId(c3),
132273
132320
  ty: nullType
132274
132321
  }, p3 = call(n.resolver, "is", [cloneResolved(n.resolver, s3), f3], truefalseType, c3);
132275
- r3.push(makeCondition(n.resolver, call(n.resolver, "or", [p3, u], truefalseType, c3), "where", n.resolver.currentGraphId));
132322
+ r3.push(makeCondition(n.resolver, call(n.resolver, "or", [p3, u], truefalseType, c3), "where"));
132276
132323
  }
132277
132324
  return r3;
132278
132325
  }
@@ -132327,21 +132374,19 @@ function minStartRef(e12, t) {
132327
132374
  ty: c3,
132328
132375
  name: makeIdent(e12.resolver, "min", [], c3, n),
132329
132376
  args: [cloneResolved(e12.resolver, t)]
132330
- }, u = e12.resolver.currentGraphId, f3 = {
132377
+ }, u = {
132331
132378
  kind: "reduce",
132332
132379
  id: e12.resolver.newNodeId(n),
132333
132380
  ty: createTableType(createRowType([c3]), i.modelName),
132334
132381
  input: makeIdent(e12.resolver, i.modelName, [], a.ty, n),
132335
132382
  by: [],
132336
- aggregates: [l3],
132337
- graphId: u
132338
- }, p3 = {
132383
+ aggregates: [l3]
132384
+ }, f3 = {
132339
132385
  kind: "computed_ref",
132340
132386
  id: e12.resolver.newNodeId(n),
132341
132387
  ty: c3,
132342
- reduce: f3,
132343
- column: s3,
132344
- graphId: u
132388
+ reduce: u,
132389
+ column: s3
132345
132390
  };
132346
132391
  return {
132347
132392
  kind: "lod",
@@ -132351,7 +132396,7 @@ function minStartRef(e12, t) {
132351
132396
  grain: [],
132352
132397
  keepFilters: true,
132353
132398
  exactRangeAnchor: true,
132354
- value: p3
132399
+ value: f3
132355
132400
  };
132356
132401
  }
132357
132402
  function exactPeriodKey(e12, t, n, r3) {
@@ -132415,63 +132460,61 @@ function exactMatch(e12, t) {
132415
132460
  name: makeIdent(e12.resolver, "match", [], truefalseType, n),
132416
132461
  args: [cloneResolved(e12.resolver, t.dim), cloneResolved(e12.resolver, t.interval)]
132417
132462
  };
132418
- return makeCondition(e12.resolver, r3, "where", e12.resolver.currentGraphId);
132463
+ return makeCondition(e12.resolver, r3, "where");
132419
132464
  }
132420
- function strictClamp(e12, t, n, r3, i) {
132421
- if (i.length === 0)
132465
+ function strictClamp(e12, t, n, r3) {
132466
+ if (r3.length === 0)
132422
132467
  return;
132423
- let a = minMaxRefs(e12, t, n, r3);
132424
- if (!a)
132468
+ let i = minMaxRefs(e12, t, n);
132469
+ if (!i)
132425
132470
  return;
132426
- let { minRef: s3, maxRef: c3 } = a, l3 = [];
132427
- for (let t3 of i) {
132428
- let n3 = unwrapNamed(t3), r4 = dateUnitOfGrain(n3), i3 = e12.resolver.dataset.spans.get(n3.id) ?? locStub(), a3 = () => cloneResolved(e12.resolver, n3), u = r4 ? dateTrunc(e12, s3, r4, i3) : s3, f3 = r4 ? dateTrunc(e12, c3, r4, i3) : c3, p3 = call(e12.resolver, ">=", [a3(), u], truefalseType, i3), m3 = call(e12.resolver, "<=", [a3(), f3], truefalseType, i3);
132429
- l3.push(call(e12.resolver, "and", [p3, m3], truefalseType, i3));
132471
+ let { minRef: a, maxRef: s3 } = i, c3 = [];
132472
+ for (let t3 of r3) {
132473
+ let n3 = unwrapNamed(t3), r4 = dateUnitOfGrain(n3), i3 = e12.resolver.dataset.spans.get(n3.id) ?? locStub(), l3 = () => cloneResolved(e12.resolver, n3), u = r4 ? dateTrunc(e12, a, r4, i3) : a, f3 = r4 ? dateTrunc(e12, s3, r4, i3) : s3, p3 = call(e12.resolver, ">=", [l3(), u], truefalseType, i3), m3 = call(e12.resolver, "<=", [l3(), f3], truefalseType, i3);
132474
+ c3.push(call(e12.resolver, "and", [p3, m3], truefalseType, i3));
132430
132475
  }
132431
- return l3.reduce((t3, n3) => {
132476
+ return c3.reduce((t3, n3) => {
132432
132477
  let r4 = e12.resolver.dataset.spans.get(t3.id) ?? locStub();
132433
132478
  return call(e12.resolver, "and", [t3, n3], truefalseType, r4);
132434
132479
  });
132435
132480
  }
132436
- function minMaxRefs(e12, t, n, r3) {
132437
- let i = isFieldType(r3.ty) ? r3.ty : undefined, a = i?.origin, s3 = a == null ? undefined : findModel$1(e12.resolver.dataset, a.modelName);
132438
- if (a == null || s3 == null)
132481
+ function minMaxRefs(e12, t, n) {
132482
+ let r3 = isFieldType(n.ty) ? n.ty : undefined, i = r3?.origin, a = i == null ? undefined : findModel$1(e12.resolver.dataset, i.modelName);
132483
+ if (i == null || a == null)
132439
132484
  return;
132440
- let c3 = (c4) => {
132441
- let l3 = `${c4}_${a.modelName}->${a.fieldName}`, u = createFieldType(l3, i?.type ?? numberType, undefined, undefined, "aggregate"), f3 = {
132485
+ let s3 = (s4) => {
132486
+ let c3 = `${s4}_${i.modelName}->${i.fieldName}`, l3 = createFieldType(c3, r3?.type ?? numberType, undefined, undefined, "aggregate"), u = {
132442
132487
  kind: Kind.FUNCTION_CALL,
132443
132488
  id: e12.resolver.newNodeId(t),
132444
- ty: u,
132445
- name: makeIdent(e12.resolver, c4, [], u, t),
132446
- args: [cloneResolved(e12.resolver, r3)]
132447
- }, p3 = {
132489
+ ty: l3,
132490
+ name: makeIdent(e12.resolver, s4, [], l3, t),
132491
+ args: [cloneResolved(e12.resolver, n)]
132492
+ }, f3 = {
132448
132493
  kind: "reduce",
132449
132494
  id: e12.resolver.newNodeId(t),
132450
- ty: createTableType(createRowType([u]), a.modelName),
132451
- input: makeIdent(e12.resolver, a.modelName, [], s3.ty, t),
132495
+ ty: createTableType(createRowType([l3]), i.modelName),
132496
+ input: makeIdent(e12.resolver, i.modelName, [], a.ty, t),
132452
132497
  by: [],
132453
- aggregates: [f3],
132454
- graphId: n
132455
- }, m3 = {
132498
+ aggregates: [u]
132499
+ }, p3 = {
132456
132500
  kind: "computed_ref",
132457
132501
  id: e12.resolver.newNodeId(t),
132458
- ty: u,
132459
- reduce: p3,
132460
- column: l3,
132461
- graphId: n
132462
- }, S3 = {
132502
+ ty: l3,
132503
+ reduce: f3,
132504
+ column: c3
132505
+ }, m3 = {
132463
132506
  kind: "lod",
132464
132507
  id: e12.resolver.newNodeId(t),
132465
- ty: u,
132508
+ ty: l3,
132466
132509
  modifier: "exclude",
132467
132510
  grain: [],
132468
- value: m3
132511
+ value: p3
132469
132512
  };
132470
- return e12.foldExpr(S3);
132513
+ return e12.foldExpr(m3);
132471
132514
  };
132472
132515
  return {
132473
- minRef: c3("min"),
132474
- maxRef: c3("max")
132516
+ minRef: s3("min"),
132517
+ maxRef: s3("max")
132475
132518
  };
132476
132519
  }
132477
132520
  function dateTrunc(e12, t, n, r3) {
@@ -132572,7 +132615,7 @@ function foldWhere(e12, t) {
132572
132615
  let n = e12.contextFilters, r3 = mergeGrainsOf(t.value), i = t.conditions.map((t3) => {
132573
132616
  let n3 = e12.grain, i3 = inheritsViz(t3) && r3.length === 0;
132574
132617
  inheritsViz(t3) && r3.length > 0 && (e12.grain = r3);
132575
- let a3 = () => e12.suppressGroupedRefCheck(() => makeCondition(e12.resolver, unwrapBlock$1(e12.foldExpr(t3)), "where", e12.resolver.currentGraphId));
132618
+ let a3 = () => e12.suppressGroupedRefCheck(() => makeCondition(e12.resolver, unwrapBlock$1(e12.foldExpr(t3)), "where"));
132576
132619
  i3 && (e12.grain = e12.period.rawKeys(e12.grain));
132577
132620
  let s3 = i3 ? e12.period.withoutShift(a3) : a3();
132578
132621
  return e12.grain = n3, s3;
@@ -132746,6 +132789,44 @@ function dimensionsOnAxis(e12, t) {
132746
132789
  function orderWrapperName(e12) {
132747
132790
  return e12.kind === Kind.FUNCTION_CALL && (e12.name.name.startsWith("asc") || e12.name.name.startsWith("desc")) ? e12.name.name : undefined;
132748
132791
  }
132792
+ var GraphContext = class {
132793
+ g;
132794
+ graphs = [];
132795
+ constructor(e12) {
132796
+ this.g = e12;
132797
+ }
132798
+ currentGraph() {
132799
+ return this.graphs[this.graphs.length - 1] ?? this.baseGraph();
132800
+ }
132801
+ baseGraph() {
132802
+ return baseGraph(this.g.resolver);
132803
+ }
132804
+ rlpGraph() {
132805
+ return rlpGraph(this.g.resolver);
132806
+ }
132807
+ graphFor(e12) {
132808
+ return e12.role === "rlp" ? this.rlpGraph() : this.currentGraph();
132809
+ }
132810
+ newGraph(e12, t) {
132811
+ try {
132812
+ return this.currentGraph().derivedGraph(e12.relationships.map((e13) => ({ ...e13 })), e12.allowNewRelationships);
132813
+ } catch (e13) {
132814
+ if (e13.code !== ErrorCode.RELATIONSHIP_NOT_FOUND_0)
132815
+ throw e13;
132816
+ let n = e13.args;
132817
+ this.g.resolver.dataset.diagnostics.push(createError(ErrorCode.RELATIONSHIP_NOT_FOUND_0, t, undefined, n?.[0]));
132818
+ return;
132819
+ }
132820
+ }
132821
+ withGraph(e12, t) {
132822
+ this.graphs.push(e12);
132823
+ try {
132824
+ return t();
132825
+ } finally {
132826
+ this.graphs.pop();
132827
+ }
132828
+ }
132829
+ };
132749
132830
  function findModelByName(e12, t) {
132750
132831
  let n = e12.globalModule;
132751
132832
  for (let e13 of t.split(".")) {
@@ -132828,6 +132909,7 @@ var GrainFold = class extends HirFold {
132828
132909
  window = new Window(this);
132829
132910
  timeSpine = new TimeSpine(this);
132830
132911
  explore = new Explore(this);
132912
+ graphContext = new GraphContext(this);
132831
132913
  foldedDims = /* @__PURE__ */ new Set;
132832
132914
  foldingDims = /* @__PURE__ */ new Set;
132833
132915
  foldingDimKeys = /* @__PURE__ */ new Set;
@@ -132861,8 +132943,7 @@ var GrainFold = class extends HirFold {
132861
132943
  id: this.resolver.newNodeId(),
132862
132944
  ty: createFieldType(n.name.name, n.ty.type, n.origin, t, "dimension"),
132863
132945
  name: n.name.name,
132864
- path: [],
132865
- graphId: this.resolver.currentGraphId
132946
+ path: []
132866
132947
  };
132867
132948
  return modelFieldExprs(this.resolver, [r3]);
132868
132949
  }
@@ -132893,6 +132974,10 @@ var GrainFold = class extends HirFold {
132893
132974
  foldPivotContext(e12) {
132894
132975
  return this.explore.fold(e12);
132895
132976
  }
132977
+ foldWithRelationships(e12) {
132978
+ let t = this.resolver.dataset.spans.get(e12.id) ?? locStub(), n = this.graphContext.newGraph(e12, t);
132979
+ return n ? this.graphContext.withGraph(n, () => this.foldExpr(e12.value)) : synthIdent(this.resolver, "<with_relationships>", [], errType, t);
132980
+ }
132896
132981
  foldExploreContext(e12) {
132897
132982
  let t = this.resolver.exploreContextFilters;
132898
132983
  this.resolver.exploreContextFilters = e12.filters;
@@ -132923,8 +133008,7 @@ var GrainFold = class extends HirFold {
132923
133008
  ty: createTableType(createRowType(i.map((e13) => e13.ty)), e12.ty.rootModel),
132924
133009
  input: s3,
132925
133010
  by: i,
132926
- aggregates: [],
132927
- graphId: this.resolver.currentGraphId
133011
+ aggregates: []
132928
133012
  };
132929
133013
  break;
132930
133014
  }
@@ -132989,7 +133073,7 @@ var GrainFold = class extends HirFold {
132989
133073
  break;
132990
133074
  }
132991
133075
  case "reduce": {
132992
- let t3 = this.timeSpine.graphWithCalendar(this.resolver.dataset.graphs.get(this.resolver.currentGraphId)), r3 = this.inheritedGrain, i = this.grain, a = this.foldKeys(this.period.applyToKeys(e12.by, e12));
133076
+ let t3 = this.timeSpine.graphWithCalendar(this.graphContext.currentGraph()), r3 = this.inheritedGrain, i = this.grain, a = this.foldKeys(this.period.applyToKeys(e12.by, e12));
132993
133077
  this.inheritedGrain = dedupKeys([...this.inheritedGrain, ...a]), this.grain = a;
132994
133078
  let s3 = this.noSlice;
132995
133079
  this.noSlice = [];
@@ -133015,10 +133099,7 @@ var GrainFold = class extends HirFold {
133015
133099
  resolveJoins(e12) {
133016
133100
  if (e12.kind !== "select" && e12.kind !== "filter" && e12.kind !== "sort")
133017
133101
  return e12;
133018
- let t = this.resolver.dataset.graphs.get(e12.graphId ?? this.resolver.currentGraphId);
133019
- if (!t)
133020
- return e12;
133021
- let n = e12;
133102
+ let t = this.graphContext.currentGraph(), n = e12;
133022
133103
  if (n.input.kind === Kind.IDENTIFIER) {
133023
133104
  let e13 = toExpandModel(this.resolver, n.input);
133024
133105
  e13 && (n = {
@@ -133046,10 +133127,7 @@ var GrainFold = class extends HirFold {
133046
133127
  let n = this.payloadSource;
133047
133128
  if (!n || e12.length === 0)
133048
133129
  return true;
133049
- let r3 = this.resolver.dataset.graphs.get(n.source.graphId ?? this.resolver.currentGraphId);
133050
- if (!r3)
133051
- return true;
133052
- let i = this.collectAccessedFields(e12, n.depth);
133130
+ let r3 = this.graphContext.currentGraph(), i = this.collectAccessedFields(e12, n.depth);
133053
133131
  if (i.length === 0)
133054
133132
  return true;
133055
133133
  let a = this.resolver.dataset.diagnostics.length;
@@ -133143,12 +133221,7 @@ var GrainFold = class extends HirFold {
133143
133221
  if (!t.inline && !isRelation(t.value))
133144
133222
  return e12;
133145
133223
  let n = cloneResolved(this.resolver, t.value);
133146
- if (this.groupKeys && isRelation(n)) {
133147
- let e13 = this.resolver.dataset.graphs.get(n.graphId ?? this.resolver.currentGraphId);
133148
- if (e13)
133149
- return addJoins(this.resolver, e13, n, this.groupKeys);
133150
- }
133151
- return n;
133224
+ return this.groupKeys && isRelation(n) ? addJoins(this.resolver, this.graphContext.currentGraph(), n, this.groupKeys) : n;
133152
133225
  }
133153
133226
  t?.kind === "dimension" && this.foldDimDeclaration(t);
133154
133227
  }
@@ -133171,33 +133244,30 @@ var GrainFold = class extends HirFold {
133171
133244
  let t = toExpandModel(this.resolver, e12);
133172
133245
  if (!t)
133173
133246
  return;
133174
- let n = t.graphId ?? this.resolver.currentGraphId, r3 = this.resolver.dataset.graphs.get(n);
133175
- if (!r3)
133176
- return;
133177
- let i = baseModelName(t.root);
133178
- this.groupKeys && this.diagnoseGroupFanout(r3, i, this.groupKeys);
133179
- let a = this.timeSpine.graphWithCalendar(r3), s3 = this.period.withExactRange(() => effectiveFiltersForModel(this, i));
133180
- s3 = [...s3, ...this.period.dayRoundtripFilters(this.period.rawKeys(this.grain).map((e13) => e13.expr))], s3 = this.applicableRlp(i, s3), s3 = this.applicableFilters(a, i, s3);
133181
- let c3 = normalizeConditions(this.resolver, s3, a, i), l3 = /* @__PURE__ */ new Set, { noSlice: u } = this, { grain: f3 } = this;
133182
- if (u) {
133183
- let e13 = (e14) => e14 === "H.calendar" || r3.canReach(i, e14, {
133247
+ let n = this.graphContext.currentGraph(), r3 = baseModelName(t.root);
133248
+ this.groupKeys && this.diagnoseGroupFanout(n, r3, this.groupKeys);
133249
+ let i = this.timeSpine.graphWithCalendar(n), a = this.period.withExactRange(() => effectiveFiltersForModel(this, r3));
133250
+ a = [...a, ...this.period.dayRoundtripFilters(this.period.rawKeys(this.grain).map((e13) => e13.expr))], a = this.applicableRlp(r3, a), a = this.applicableFilters(i, r3, a);
133251
+ let s3 = normalizeConditions(this.resolver, a, i, r3), c3 = /* @__PURE__ */ new Set, { noSlice: l3 } = this, { grain: u } = this;
133252
+ if (l3) {
133253
+ let e13 = (e14) => e14 === "H.calendar" || n.canReach(r3, e14, {
133184
133254
  allowFanout: true,
133185
133255
  respectFilterDirection: true
133186
- }), t3 = f3.filter((t4) => !exprModels(t4.expr).every(e13));
133256
+ }), t3 = u.filter((t4) => !exprModels(t4.expr).every(e13));
133187
133257
  if (t3.length > 0) {
133188
- f3 = f3.filter((e15) => !t3.includes(e15));
133189
- let e14 = this.noSliceComments(i, t3);
133190
- u.push(...t3.map((t4, n3) => ({
133258
+ u = u.filter((e15) => !t3.includes(e15));
133259
+ let e14 = this.noSliceComments(r3, t3);
133260
+ l3.push(...t3.map((t4, n3) => ({
133191
133261
  key: t4,
133192
133262
  comment: e14[n3]
133193
133263
  })));
133194
133264
  }
133195
133265
  }
133196
- t = addJoins(this.resolver, a, t, f3, true, c3, l3), t.kind === "expand_model" && (t = applyFilters(this.resolver, a, t, c3, l3));
133197
- let p3 = c3.filter((e13) => !l3.has(e13)), m3 = this.resolver.dataset.spans.get(e12.id) ?? locStub(), S3 = p3.flatMap((e13) => e13.predicate.kind === "in_table_condition" ? e13.predicate.row.map((e14) => e14.expr) : []);
133198
- S3.length > 0 && (t = addJoins(this.resolver, r3, t, leafFields(this.resolver, S3))), p3.length > 0 && (t = this.filterInput(t, m3, p3));
133199
- let w3 = this.period.strictBounds(bareLeafKeys(this.resolver, f3, materialisedOrigins(t)).map((e13) => e13.expr), m3, n);
133200
- return w3.length > 0 ? this.filterInput(t, m3, w3) : t;
133266
+ t = addJoins(this.resolver, i, t, u, true, s3, c3), t.kind === "expand_model" && (t = applyFilters(this.resolver, i, t, s3, c3));
133267
+ let f3 = s3.filter((e13) => !c3.has(e13)), p3 = this.resolver.dataset.spans.get(e12.id) ?? locStub(), m3 = f3.flatMap((e13) => e13.predicate.kind === "in_table_condition" ? e13.predicate.row.map((e14) => e14.expr) : []);
133268
+ m3.length > 0 && (t = addJoins(this.resolver, n, t, leafFields(this.resolver, m3))), f3.length > 0 && (t = this.filterInput(t, p3, f3));
133269
+ let S3 = this.period.strictBounds(bareLeafKeys(this.resolver, u, materialisedOrigins(t)).map((e13) => e13.expr), p3);
133270
+ return S3.length > 0 ? this.filterInput(t, p3, S3) : t;
133201
133271
  }
133202
133272
  diagnoseGroupFanout(e12, t, n) {
133203
133273
  let r3 = /* @__PURE__ */ new Set;
@@ -133224,7 +133294,7 @@ var GrainFold = class extends HirFold {
133224
133294
  let t = e12.grain;
133225
133295
  if (e12.axis !== undefined && (t = this.explore.axisExcludeGrain(e12.axis), t.length === 0))
133226
133296
  return this.foldExpr(e12.value);
133227
- let n = this.grain, r3 = this.contextFilters, i = this.resolver.dataset.graphs.get(e12.graphId ?? this.resolver.currentGraphId);
133297
+ let n = this.grain, r3 = this.contextFilters, i = this.graphContext.currentGraph();
133228
133298
  this.grain = lodGrain(this.resolver, e12.modifier, this.grain, t, !!e12.all, i), e12.modifier === "keep" && !e12.all ? this.contextFilters = e12.keepFilters ? r3 : r3.filter((t3) => filterOnKeptGrain(t3, e12.grain)) : e12.modifier === "exclude" && e12.axis === undefined && !e12.all && !e12.keepFilters ? this.contextFilters = r3.filter((e13) => !filterOnExcludedGrain(e13, t, i)) : e12.modifier === "exact_grains" && (e12.keepFilters ? this.foldingDimKeys.size > 0 && (this.contextFilters = this.keepFilterConditions()) : this.contextFilters = []);
133229
133299
  let a = this.inLodBoundary;
133230
133300
  e12.modifier === "exclude" && !e12.all && (this.inLodBoundary = true);
@@ -133245,21 +133315,19 @@ var GrainFold = class extends HirFold {
133245
133315
  try {
133246
133316
  return n.map((e13) => {
133247
133317
  let t3 = this.foldExpr(cloneResolved(this.resolver, e13)), n3 = t3.kind === "block" ? t3.result : t3;
133248
- return makeCondition(this.resolver, n3, "where", this.resolver.currentGraphId);
133318
+ return makeCondition(this.resolver, n3, "where");
133249
133319
  });
133250
133320
  } finally {
133251
133321
  this.grain = r3;
133252
133322
  }
133253
133323
  }
133254
133324
  foldUnique(e12) {
133255
- let t = this.resolver.dataset.spans.get(e12.id) ?? locStub(), n = dedupKeys([...this.period.applyToKeys(this.grain), ...this.foldKeys(e12.keys)]), r3 = createTableType(createRowType(n.map((e13) => e13.ty)), undefined), i = this.resolver.currentGraphId;
133256
- this.resolver.currentGraphId = e12.graphId ?? i;
133257
- let a = this.resolver.dataset.graphs.get(e12.graphId ?? i), s3 = new Set(n.flatMap((e13) => exprModels(e13.expr))), c3 = this.period.withExactRange(() => effectiveFilters(this)), l3 = fanoutFilterModels(c3, s3, a), u = resolveUnique(this.resolver, n, r3, t, l3, c3, (e13) => this.foldGroupedRoot(e13, n, t));
133258
- return this.resolver.currentGraphId = i, logger.debug(`unique #${e12.id} → ${u.kind}`, {
133325
+ let t = this.resolver.dataset.spans.get(e12.id) ?? locStub(), n = dedupKeys([...this.period.applyToKeys(this.grain), ...this.foldKeys(e12.keys)]), r3 = createTableType(createRowType(n.map((e13) => e13.ty)), undefined), i = this.graphContext.currentGraph(), a = new Set(n.flatMap((e13) => exprModels(e13.expr))), s3 = this.period.withExactRange(() => effectiveFilters(this)), c3 = fanoutFilterModels(s3, a, i), l3 = resolveUnique(this.resolver, i, n, r3, t, c3, s3, (e13) => this.foldGroupedRoot(e13, n, t));
133326
+ return logger.debug(`unique #${e12.id} → ${l3.kind}`, {
133259
133327
  ownKeys: e12.keys.length,
133260
133328
  inheritedGrain: this.grain.length,
133261
133329
  keys: n.length
133262
- }), u;
133330
+ }), l3;
133263
133331
  }
133264
133332
  foldGroupedRoot(e12, t, n) {
133265
133333
  let r3 = findModel$1(this.resolver.dataset, e12);
@@ -133274,14 +133342,13 @@ var GrainFold = class extends HirFold {
133274
133342
  ty: createTableType(createRowType(t.map((e13) => e13.ty)), e12),
133275
133343
  input: s3,
133276
133344
  by: t,
133277
- aggregates: [],
133278
- graphId: this.resolver.currentGraphId
133345
+ aggregates: []
133279
133346
  };
133280
133347
  }
133281
133348
  foldComputedRef(e12) {
133282
133349
  let t = this.resolver.dataset.spans.get(e12.id) ?? locStub(), n = this.inGroupedOutput, r3 = this.groupKeys;
133283
133350
  this.inGroupedOutput = false, this.groupKeys = undefined;
133284
- let i = this.rolling.applyToRef(e12, t, (n3) => this.foldExpr(buildAggRelation(this.resolver, e12.reduce.input, n3, e12.reduce.aggregates, e12.reduce.graphId, t)));
133351
+ let i = this.rolling.applyToRef(e12, t, (n3) => this.foldExpr(buildAggRelation(this.resolver, e12.reduce.input, n3, e12.reduce.aggregates, t)));
133285
133352
  return this.groupKeys = r3, this.inGroupedOutput = n, i;
133286
133353
  }
133287
133354
  applicableRlp(e12, t) {
@@ -133327,8 +133394,7 @@ var GrainFold = class extends HirFold {
133327
133394
  id: this.resolver.newNodeId(t),
133328
133395
  ty: e12.ty,
133329
133396
  input: e12,
133330
- predicates: r3,
133331
- graphId: this.resolver.currentGraphId
133397
+ predicates: r3
133332
133398
  };
133333
133399
  }
133334
133400
  };
@@ -133462,8 +133528,7 @@ var TransitionFold = class extends HirFold {
133462
133528
  ty: e12.input.ty,
133463
133529
  input: e12.input,
133464
133530
  parts: a,
133465
- baseMeasure: pickBaseMeasure(e12.input, a),
133466
- graphId: e12.graphId
133531
+ baseMeasure: pickBaseMeasure(e12.input, a)
133467
133532
  }, c3 = e12.by.map((e13) => ({
133468
133533
  ...e13,
133469
133534
  expr: derefMeasure(this.resolver, e13.expr, r3)
@@ -133613,8 +133678,7 @@ var TransitionFold = class extends HirFold {
133613
133678
  ty: r3.ty,
133614
133679
  input: l3,
133615
133680
  parts: c3,
133616
- baseMeasure: pickBaseMeasure(l3, c3),
133617
- graphId: l3.graphId
133681
+ baseMeasure: pickBaseMeasure(l3, c3)
133618
133682
  }, f3 = (e13) => derefMeasure(this.resolver, e13, a);
133619
133683
  return t.kind === "select" ? {
133620
133684
  ...t,
@@ -133686,14 +133750,13 @@ var TransitionFold = class extends HirFold {
133686
133750
  }, { aliasOf: f3, aliasByReduce: p3 } = aliasParts(this.resolver, i), m3 = (e13, t3) => e13.kind === "reduce" ? {
133687
133751
  ...e13,
133688
133752
  alias: p3.get(t3.reduce)
133689
- } : e13, S3 = i.find((e13) => u(e13.reduce.by)), w3 = S3 ? i.filter((e13) => e13 !== S3) : i, E3 = S3 ? m3(this.foldExpr(S3.reduce), S3) : this.filterSynthBase(resolveUnique(this.resolver, e12.grains, createTableType(createRowType(e12.grains.map((e13) => e13.ty)), undefined), t), e12, t), N = w3.map((e13) => m3(this.foldExpr(e13.reduce), e13)).filter((e13) => e13.kind === "reduce"), I3 = {
133753
+ } : e13, S3 = i.find((e13) => u(e13.reduce.by)), w3 = S3 ? i.filter((e13) => e13 !== S3) : i, E3 = S3 ? m3(this.foldExpr(S3.reduce), S3) : this.filterSynthBase(resolveUnique(this.resolver, baseGraph(this.resolver), e12.grains, createTableType(createRowType(e12.grains.map((e13) => e13.ty)), undefined), t), e12, t), N = w3.map((e13) => m3(this.foldExpr(e13.reduce), e13)).filter((e13) => e13.kind === "reduce"), I3 = {
133690
133754
  kind: "transition",
133691
133755
  id: this.resolver.newNodeId(t),
133692
133756
  ty: E3.ty,
133693
133757
  input: E3,
133694
133758
  parts: N,
133695
- coalesce: true,
133696
- graphId: e12.graphId
133759
+ coalesce: true
133697
133760
  };
133698
133761
  logger.info(`merge→transition: root=${S3 ? S3.column : "unique(grains)"}, ${N.length} part(s), ${r3.length - i.length} dup(s) dropped`);
133699
133762
  let L3 = (e13) => {
@@ -133710,7 +133773,6 @@ var TransitionFold = class extends HirFold {
133710
133773
  ty: t3.ty,
133711
133774
  name: t3.column,
133712
133775
  path: [],
133713
- graphId: t3.graphId,
133714
133776
  qualifier: f3(t3.reduce)
133715
133777
  };
133716
133778
  }
@@ -133743,8 +133805,7 @@ var TransitionFold = class extends HirFold {
133743
133805
  ty: e12.input.ty,
133744
133806
  input: e12.input,
133745
133807
  iterationDepth: iterationDepthOf(e12.input),
133746
- predicates: s3,
133747
- graphId: this.resolver.currentGraphId
133808
+ predicates: s3
133748
133809
  };
133749
133810
  return {
133750
133811
  ...e12,
@@ -133769,8 +133830,7 @@ var TransitionFold = class extends HirFold {
133769
133830
  id: this.resolver.newNodeId(t),
133770
133831
  ty: r3,
133771
133832
  name: synthIdent(this.resolver, r3.fieldName || "value", [], r3, t),
133772
- expr: e12,
133773
- graphId: this.resolver.currentGraphId
133833
+ expr: e12
133774
133834
  }, a = createTableType(createRowType([r3]), undefined);
133775
133835
  return makeTransform(this.resolver, "select", [n, i], a, t);
133776
133836
  }
@@ -133859,7 +133919,6 @@ function derefMeasure(e12, t, n) {
133859
133919
  ty: t.ty,
133860
133920
  name: t.column,
133861
133921
  path: [],
133862
- graphId: t.graphId,
133863
133922
  qualifier: n(t.reduce)
133864
133923
  } : t.kind === Kind.NAMED_EXPRESSION ? {
133865
133924
  ...t,
@@ -134044,7 +134103,7 @@ function resolveRowLevelPermissions(e12, t, n) {
134044
134103
  if (!t3)
134045
134104
  continue;
134046
134105
  let a = e12.resolveExpr(t3, n);
134047
- !isErrType(a.ty) && a.kind !== "in_table_condition" && e12.rlpFilters.push(makeCondition(e12, a, "rlp", rlpGraphId(e12)));
134106
+ !isErrType(a.ty) && a.kind !== "in_table_condition" && e12.rlpFilters.push(makeCondition(e12, a, "rlp"));
134048
134107
  }
134049
134108
  }
134050
134109
  function resolveParamRlp(e12, t, n) {
@@ -134169,7 +134228,6 @@ function createResolver(e13, t, n = false, r3 = DEFAULT_DATETIME_CONTEXT, i = tr
134169
134228
  dbType: e13.dataSource.dbtype,
134170
134229
  modelContext: t,
134171
134230
  datetimeContext: r3,
134172
- currentGraphId: 0,
134173
134231
  nextId: 0,
134174
134232
  inBizCal: false,
134175
134233
  typeCheckOnly: c3,
@@ -134202,7 +134260,7 @@ function createResolver(e13, t, n = false, r3 = DEFAULT_DATETIME_CONTEXT, i = tr
134202
134260
  members: /* @__PURE__ */ new Map
134203
134261
  },
134204
134262
  spans: /* @__PURE__ */ new Map,
134205
- graphs: new Map([[0, e13.modelGraph]]),
134263
+ graph: e13.modelGraph,
134206
134264
  diagnostics: [],
134207
134265
  declDeps: /* @__PURE__ */ new Map,
134208
134266
  declsByKey: /* @__PURE__ */ new Map
@@ -134893,7 +134951,7 @@ function rangeToPlan(e13, t, n, r3) {
134893
134951
  }), c3 = t.start ? s3(n ? "<" : ">=", t.start) : undefined, l3 = t.end ? s3(n ? ">" : "<=", t.end) : undefined;
134894
134952
  return c3 && l3 ? t.start > t.end ? a(n) : {
134895
134953
  kind: "call_binary",
134896
- func: "and",
134954
+ func: n ? "or" : "and",
134897
134955
  type: SqlType.TRUEFALSE,
134898
134956
  expr1: c3,
134899
134957
  expr2: l3
@@ -135751,8 +135809,7 @@ function readThroughSelect(e14, t) {
135751
135809
  id: t3.id,
135752
135810
  ty: t3.ty,
135753
135811
  name: a.fieldName,
135754
- path: [],
135755
- graphId: t3.graphId
135812
+ path: []
135756
135813
  }) : i.push(t3));
135757
135814
  }
135758
135815
  return i.length === 0 ? e14 : {
@@ -135801,8 +135858,7 @@ function collapseGrainKeyRefs(e14, t) {
135801
135858
  id: e14.id,
135802
135859
  ty: e14.ty,
135803
135860
  name: n.fieldName,
135804
- path: [],
135805
- graphId: e14.graphId
135861
+ path: []
135806
135862
  } : e14.kind === Kind.FUNCTION_CALL ? {
135807
135863
  ...e14,
135808
135864
  args: e14.args.map((e15) => collapseGrainKeyRefs(e15, t))
@@ -136776,7 +136832,6 @@ function rewriteNestedSubtimes(e14, t) {
136776
136832
  kind: Kind.FUNCTION_CALL,
136777
136833
  id: e14.id,
136778
136834
  ty: e14.ty,
136779
- graphId: e14.graphId,
136780
136835
  name: {
136781
136836
  kind: Kind.IDENTIFIER,
136782
136837
  id: e14.id,
@@ -137007,8 +137062,7 @@ function lowerReduce(e14, t, n) {
137007
137062
  id: e15.id,
137008
137063
  ty: e15.ty,
137009
137064
  name: originKey(t3),
137010
- path: [],
137011
- graphId: e15.graphId
137065
+ path: []
137012
137066
  };
137013
137067
  }
137014
137068
  return e15.kind === Kind.FUNCTION_CALL ? {
@@ -140388,14 +140442,22 @@ function closeOverTemplateRefs(e14, t) {
140388
140442
  let n = new Map(e14.dimensions.map((e15) => [e15.name.name, e15])), r3 = new Set(t), i = [...t];
140389
140443
  for (;i.length > 0; ) {
140390
140444
  let t3 = n.get(i.shift());
140391
- if (t3?.body?.syntax !== "sql")
140392
- continue;
140393
- let { resolved: a } = t3;
140394
- for (let t4 of a && "refs" in a ? a.refs : [])
140395
- (t4.path.length === 0 || t4.path.length === 1 && t4.path[0] === e14.name) && n.has(t4.name) && !r3.has(t4.name) && (r3.add(t4.name), i.push(t4.name));
140445
+ if (t3?.body?.syntax === "sql")
140446
+ for (let a of templateRefs(t3))
140447
+ (a.path.length === 0 || a.path.length === 1 && a.path[0] === e14.name) && n.has(a.name) && !r3.has(a.name) && (r3.add(a.name), i.push(a.name));
140396
140448
  }
140397
140449
  return r3;
140398
140450
  }
140451
+ function templateRefs(e14) {
140452
+ let { resolved: t, body: n } = e14, r3 = t && "refs" in t ? t.refs.map((e15) => ({
140453
+ name: e15.name,
140454
+ path: [...e15.path]
140455
+ })) : [];
140456
+ return n.syntax !== "sql" || typeof n.definition != "string" ? r3 : [...r3, ...parseFieldReferencesInSQL(n.definition).map((e15) => ({
140457
+ name: e15.fieldName,
140458
+ path: e15.modelName ? [e15.modelName] : []
140459
+ }))];
140460
+ }
140399
140461
  function modelParamField(e14) {
140400
140462
  return {
140401
140463
  name: e14.name.name,