@malloydata/malloyyo 0.2.64 → 0.2.66

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 +41 -7
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ import { dirname, join } from "node:path";
11
11
  import { fileURLToPath } from "node:url";
12
12
 
13
13
  // package.json
14
- var version = "0.2.64";
14
+ var version = "0.2.66";
15
15
 
16
16
  // src/update-check.ts
17
17
  var UPDATE_CHECK_ARGV = "__update-check";
@@ -1247,6 +1247,36 @@ function jsonRows(result) {
1247
1247
  }
1248
1248
  return result.data.toObject().map((row) => jsonValue(row));
1249
1249
  }
1250
+ function columnType(t) {
1251
+ switch (t.kind) {
1252
+ case "number_type":
1253
+ return t.subtype ? { type: "number", subtype: t.subtype } : { type: "number" };
1254
+ case "date_type":
1255
+ case "timestamp_type":
1256
+ case "timestamptz_type": {
1257
+ const type = t.kind.replace(/_type$/, "");
1258
+ return t.timeframe ? { type, timeframe: t.timeframe } : { type };
1259
+ }
1260
+ case "record_type":
1261
+ return { type: "record", fields: t.fields.map((f) => ({ name: f.name, ...columnType(f.type) })) };
1262
+ case "array_type": {
1263
+ const el = columnType(t.element_type);
1264
+ return el.type === "record" ? { type: "array", fields: el.fields } : { type: "array", element: el };
1265
+ }
1266
+ default:
1267
+ return { type: t.kind.replace(/_type$/, "") };
1268
+ }
1269
+ }
1270
+ function resultColumns(result) {
1271
+ if (!result.hasSchema) return void 0;
1272
+ const out = [];
1273
+ for (const f of result.toStableResult().schema.fields) {
1274
+ if (f.kind === "dimension" || f.kind === "measure" || f.kind === "calculate") {
1275
+ out.push({ name: f.name, ...columnType(f.type) });
1276
+ }
1277
+ }
1278
+ return out;
1279
+ }
1250
1280
  function rowLimitTruncation(rowLimit) {
1251
1281
  return {
1252
1282
  reason: "row_limit",
@@ -1296,6 +1326,8 @@ async function executeMaterialized(query, opts, loadProblems, decorate = (p) =>
1296
1326
  total_time_ms: t2 - t0,
1297
1327
  problems: loadProblems
1298
1328
  };
1329
+ const columns = resultColumns(results);
1330
+ if (columns) out.columns = columns;
1299
1331
  if (rows.length === rowLimit) out.truncated = rowLimitTruncation(rowLimit);
1300
1332
  if (opts.stableResult) out.stable_result = API.util.wrapResult(results);
1301
1333
  return out;
@@ -2151,22 +2183,23 @@ function describeSourceTool(host) {
2151
2183
  const modelRef = r.model_ref;
2152
2184
  try {
2153
2185
  return await host.withModel(modelRef, async (m) => {
2186
+ const ref = m.ref ?? modelRef;
2154
2187
  const compiled = await compile(m.runtime, m.entry, { readSource: m.readSource });
2155
2188
  if (!compiled.ok || !compiled.model) {
2156
- return { ok: false, model_ref: modelRef, source, problems: compiled.problems };
2189
+ return { ok: false, model_ref: ref, source, problems: compiled.problems };
2157
2190
  }
2158
2191
  const built = buildSourceDescribe(compiled.model, source);
2159
2192
  if (!built) {
2160
2193
  const available = Object.keys(compiled.model.sources);
2161
2194
  return {
2162
2195
  ok: false,
2163
- model_ref: modelRef,
2196
+ model_ref: ref,
2164
2197
  source,
2165
2198
  problems: [
2166
2199
  ...compiled.problems,
2167
2200
  codeProblem(
2168
2201
  "source-not-found",
2169
- `No source named '${source}' in '${modelRef}'. Sources: ${available.join(", ") || "(none)"}.`
2202
+ `No source named '${source}' in '${ref}'. Sources: ${available.join(", ") || "(none)"}.`
2170
2203
  )
2171
2204
  ]
2172
2205
  };
@@ -2174,7 +2207,7 @@ function describeSourceTool(host) {
2174
2207
  const malloy_text = sourceAsMalloy(compiled.model.sources[source]);
2175
2208
  const base = {
2176
2209
  ok: true,
2177
- model_ref: modelRef,
2210
+ model_ref: ref,
2178
2211
  source,
2179
2212
  guidance: prompts.explore.guidance,
2180
2213
  described_source: built.described_source,
@@ -2249,15 +2282,16 @@ function exploreQueryTool(host, opts) {
2249
2282
  }
2250
2283
  try {
2251
2284
  return await host.withModel(modelRef, async (m) => {
2285
+ const ref = m.ref ?? modelRef;
2252
2286
  const res = await executeQuery(
2253
2287
  m,
2254
2288
  args,
2255
2289
  queryFieldFix(modelRef, source, argString(args, "malloy")),
2256
2290
  opts.result
2257
2291
  );
2258
- if (!execute) return { ...res, model_ref: modelRef };
2292
+ if (!execute) return { ...res, model_ref: ref };
2259
2293
  const { sql, ...rest } = res;
2260
- const out = { ...rest, model_ref: modelRef };
2294
+ const out = { ...rest, model_ref: ref };
2261
2295
  if (sql !== void 0) out[HOST_ONLY] = { sql };
2262
2296
  return out;
2263
2297
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/malloyyo",
3
- "version": "0.2.64",
3
+ "version": "0.2.66",
4
4
  "description": "Publish Malloy models to a Malloyyo instance",
5
5
  "license": "MIT",
6
6
  "repository": {