@malloydata/malloyyo 0.2.6 → 0.2.7

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/index.js +30 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1449,6 +1449,29 @@ function srcNudge(modelRef, source) {
1449
1449
  };
1450
1450
  };
1451
1451
  }
1452
+ function definedNamesIn(malloy) {
1453
+ const names = /* @__PURE__ */ new Set();
1454
+ const re = /\b([A-Za-z_]\w*)\s+is\b/g;
1455
+ let m;
1456
+ while ((m = re.exec(malloy)) !== null) names.add(m[1]);
1457
+ return names;
1458
+ }
1459
+ function queryFieldFix(modelRef, source, malloy) {
1460
+ const defined = definedNamesIn(malloy);
1461
+ const nudge = srcNudge(modelRef, source);
1462
+ return (p) => {
1463
+ if (p.code !== "field-not-found") return p;
1464
+ const name = /'([^']+)'/.exec(p.message)?.[1];
1465
+ if (name && defined.has(name)) {
1466
+ return {
1467
+ ...p,
1468
+ message: `'${name}' is defined in this query, but one field can't reference another in the same stage. To build a value from other aggregates (a ratio, a share), declare the parts in an \`extend:\` block (measures can reference each other), then use them.`,
1469
+ help_topic: "explore/query-examples"
1470
+ };
1471
+ }
1472
+ return nudge(p);
1473
+ };
1474
+ }
1452
1475
  function sourceAsMalloy(s) {
1453
1476
  return s?.body ? `source: ${s.body}` : "";
1454
1477
  }
@@ -1638,7 +1661,12 @@ function exploreQueryTool(host, opts) {
1638
1661
  }
1639
1662
  try {
1640
1663
  return await host.withModel(modelRef, async (m) => {
1641
- const res = await executeQuery(m, args, srcNudge(modelRef, source), opts.result);
1664
+ const res = await executeQuery(
1665
+ m,
1666
+ args,
1667
+ queryFieldFix(modelRef, source, argString(args, "malloy")),
1668
+ opts.result
1669
+ );
1642
1670
  if (!execute) return { ...res, model_ref: modelRef };
1643
1671
  const { sql, ...rest } = res;
1644
1672
  const out = { ...rest, model_ref: modelRef };
@@ -1849,7 +1877,7 @@ async function serveMcp(opts) {
1849
1877
  }
1850
1878
 
1851
1879
  // package.json
1852
- var version = "0.2.6";
1880
+ var version = "0.2.7";
1853
1881
 
1854
1882
  // src/index.ts
1855
1883
  function shortSha(sha) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/malloyyo",
3
- "version": "0.2.6",
3
+ "version": "0.2.7",
4
4
  "description": "Publish Malloy models to a Malloyyo instance",
5
5
  "license": "MIT",
6
6
  "repository": {