@query-farm/vgi 0.13.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -9964,6 +9964,27 @@ function typeToString(type) {
9964
9964
  const s = type.toString?.();
9965
9965
  return s ?? String(type.typeId);
9966
9966
  }
9967
+ function arrowTypeString(type) {
9968
+ if (isNull(type))
9969
+ return "null";
9970
+ if (isBool(type))
9971
+ return "bool";
9972
+ if (isUtf8(type))
9973
+ return "string";
9974
+ if (isBinary(type))
9975
+ return "binary";
9976
+ if (isInt(type)) {
9977
+ const bw = type.bitWidth ?? 32;
9978
+ const signed = type.isSigned ?? type.signed ?? true;
9979
+ return `${signed ? "" : "u"}int${bw}`;
9980
+ }
9981
+ if (isFloat(type)) {
9982
+ const precision = type.precision ?? 2;
9983
+ return precision === 0 ? "halffloat" : precision === 1 ? "float" : "double";
9984
+ }
9985
+ const s = type.toString?.();
9986
+ return (s ?? String(type.typeId)).toLowerCase();
9987
+ }
9967
9988
  function fieldMeta(field3, key) {
9968
9989
  return field3.metadata.get(key);
9969
9990
  }
@@ -10030,6 +10051,61 @@ function functionArgs(fn) {
10030
10051
  }
10031
10052
  return args;
10032
10053
  }
10054
+ function macroDisplayType(m) {
10055
+ return String(m.macro_type).toUpperCase() === "SCALAR" ? "scalar" : "table";
10056
+ }
10057
+ function macroDefaultJson(value) {
10058
+ if (typeof value === "bigint")
10059
+ return value.toString();
10060
+ try {
10061
+ return JSON.stringify(value);
10062
+ } catch {
10063
+ return String(value);
10064
+ }
10065
+ }
10066
+ function macroArgs(m) {
10067
+ const defaults = new Map;
10068
+ const defBytes = m.parameter_default_values;
10069
+ if (defBytes && defBytes.length > 0) {
10070
+ try {
10071
+ const batch = deserializeBatch(defBytes);
10072
+ for (const field3 of batch.schema.fields) {
10073
+ try {
10074
+ defaults.set(field3.name, batch.getChild(field3.name)?.get(0));
10075
+ } catch {}
10076
+ }
10077
+ } catch {}
10078
+ }
10079
+ const schema3 = readSchemaSafe(m.arguments_schema);
10080
+ const fields = schema3 ? schema3.fields : null;
10081
+ const fieldByName = new Map;
10082
+ if (fields)
10083
+ for (const f of fields)
10084
+ fieldByName.set(f.name, f);
10085
+ const names = fields ? fields.map((f) => f.name) : m.parameters;
10086
+ const args = [];
10087
+ for (const name of names) {
10088
+ const field3 = fieldByName.get(name);
10089
+ const arg = field3 !== undefined && !isNull(field3.type) ? { name, type: arrowTypeString(field3.type) } : { name, type: "ANY" };
10090
+ const doc = field3 !== undefined ? fieldMeta(field3, VGI_DOC_KEY) : undefined;
10091
+ if (doc)
10092
+ arg.desc = doc;
10093
+ if (defaults.has(name)) {
10094
+ arg.named = true;
10095
+ arg.default = macroDefaultJson(defaults.get(name));
10096
+ }
10097
+ args.push(arg);
10098
+ }
10099
+ return args;
10100
+ }
10101
+ function macroToObject(m) {
10102
+ return {
10103
+ name: m.name,
10104
+ type: macroDisplayType(m),
10105
+ doc: m.comment ?? "",
10106
+ args: macroArgs(m)
10107
+ };
10108
+ }
10033
10109
  async function schemaContents(iface, aod, name, kind) {
10034
10110
  try {
10035
10111
  if (kind === "TABLE") {
@@ -10049,6 +10125,15 @@ async function schemaFunctions(iface, aod, name) {
10049
10125
  }
10050
10126
  return out;
10051
10127
  }
10128
+ async function schemaMacros(iface, aod, name) {
10129
+ const out = [];
10130
+ for (const kind of ["SCALAR_MACRO", "TABLE_MACRO"]) {
10131
+ try {
10132
+ out.push(...await iface.schemaContentsMacros(aod, name, kind));
10133
+ } catch {}
10134
+ }
10135
+ return out;
10136
+ }
10052
10137
  async function buildSchemas(iface, aod) {
10053
10138
  let schemaInfos;
10054
10139
  try {
@@ -10062,6 +10147,7 @@ async function buildSchemas(iface, aod) {
10062
10147
  const tablesRaw = await schemaContents(iface, aod, si.name, "TABLE");
10063
10148
  const viewsRaw = await schemaContents(iface, aod, si.name, "VIEW");
10064
10149
  const funcsRaw = await schemaFunctions(iface, aod, si.name);
10150
+ const macrosRaw = await schemaMacros(iface, aod, si.name);
10065
10151
  const tables = tablesRaw.map((t) => {
10066
10152
  const schema3 = readSchemaSafe(t.columns);
10067
10153
  return { name: t.name, cols: schema3 ? schema3.fields.length : 0, comment: t.comment ?? "" };
@@ -10072,7 +10158,7 @@ async function buildSchemas(iface, aod) {
10072
10158
  comment: v.comment ?? "",
10073
10159
  def: v.definition
10074
10160
  }));
10075
- const functions = funcsRaw.slice().sort((a, b) => String(a.function_type).localeCompare(String(b.function_type)) || a.name.localeCompare(b.name)).map((fn) => {
10161
+ const functions = funcsRaw.map((fn) => {
10076
10162
  const obj = {
10077
10163
  name: fn.name,
10078
10164
  type: functionDisplayType(fn),
@@ -10084,6 +10170,8 @@ async function buildSchemas(iface, aod) {
10084
10170
  obj.returns = ret;
10085
10171
  return obj;
10086
10172
  });
10173
+ functions.push(...macrosRaw.map((m) => macroToObject(m)));
10174
+ functions.sort((a, b) => String(a.type).localeCompare(String(b.type)) || String(a.name).localeCompare(String(b.name)));
10087
10175
  schemas.push({ name: si.name, tables, views, functions });
10088
10176
  counts.schemas += 1;
10089
10177
  counts.tables += tables.length;
@@ -11388,4 +11476,4 @@ export {
11388
11476
  ArgumentValidationError
11389
11477
  };
11390
11478
 
11391
- //# debugId=FB551171F4FDA15864756E2164756E21
11479
+ //# debugId=55E5F7DD831BB4DD64756E2164756E21