@514labs/moose-lib 0.6.440 → 0.6.442

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.
package/dist/index.mjs CHANGED
@@ -4082,6 +4082,9 @@ function filtersFromTable(table, options) {
4082
4082
  // src/query-layer/query-model.ts
4083
4083
  var applyFilter = filter;
4084
4084
  var identity = (v) => v;
4085
+ function resolveTable(tableOrMv) {
4086
+ return tableOrMv instanceof MaterializedView ? tableOrMv.targetTable : tableOrMv;
4087
+ }
4085
4088
  function transformFilterValue(op, value, transform) {
4086
4089
  switch (op) {
4087
4090
  case "in":
@@ -4100,7 +4103,7 @@ function transformFilterValue(op, value, transform) {
4100
4103
  }
4101
4104
  function defineQueryModel(config) {
4102
4105
  const {
4103
- table,
4106
+ table: tableOrMv,
4104
4107
  dimensions,
4105
4108
  metrics,
4106
4109
  columns: columnDefs,
@@ -4109,6 +4112,7 @@ function defineQueryModel(config) {
4109
4112
  sortable,
4110
4113
  defaults = {}
4111
4114
  } = config;
4115
+ const table = resolveTable(tableOrMv);
4112
4116
  const { maxLimit = 1e3 } = defaults;
4113
4117
  const primaryTableName = table.name;
4114
4118
  const hasJoins = joinDefs != null && Object.keys(joinDefs).length > 0;
@@ -4138,7 +4142,7 @@ function defineQueryModel(config) {
4138
4142
  `Column '${name}' references unknown join '${def.join}'`
4139
4143
  );
4140
4144
  }
4141
- const joinTableName = joinDef.table.name;
4145
+ const joinTableName = resolveTable(joinDef.table).name;
4142
4146
  normalizedColumns[name] = {
4143
4147
  expression: raw(
4144
4148
  `${quoteIdentifier(joinTableName)}.${quoteIdentifier(String(def.column))}`
@@ -4306,9 +4310,10 @@ function defineQueryModel(config) {
4306
4310
  let fromClause = sql`FROM ${table}`;
4307
4311
  for (const [, joinDef] of Object.entries(joinDefs)) {
4308
4312
  const joinType = joinDef.type ?? "LEFT";
4313
+ const joinTable = resolveTable(joinDef.table);
4309
4314
  let onClause;
4310
4315
  if (joinDef.leftKey && joinDef.rightKey) {
4311
- const joinTableName = joinDef.table.name;
4316
+ const joinTableName = joinTable.name;
4312
4317
  onClause = raw(
4313
4318
  `${quoteIdentifier(primaryTableName)}.${quoteIdentifier(joinDef.leftKey)} = ${quoteIdentifier(joinTableName)}.${quoteIdentifier(joinDef.rightKey)}`
4314
4319
  );
@@ -4317,7 +4322,7 @@ function defineQueryModel(config) {
4317
4322
  } else {
4318
4323
  throw new Error("JoinDef must specify either leftKey/rightKey or on");
4319
4324
  }
4320
- fromClause = sql`${fromClause} ${raw(joinType)} JOIN ${joinDef.table} ON ${onClause}`;
4325
+ fromClause = sql`${fromClause} ${raw(joinType)} JOIN ${joinTable} ON ${onClause}`;
4321
4326
  }
4322
4327
  return fromClause;
4323
4328
  }