1414 --accent-2 : # a52121; --on-accent : # fdf6ef; --ai : # 256b3c; --ai-soft : # d6e7db; --on-ai : # f2faf4;
1515 --cup-soft : # e6f1ea; --cup : # 2f8f4e; --cup-2 : # 27713f; --on-cup : # f2faf4;
1616 --code-bg : # 1f1e18; --code-ink : # f3efe2; --ok : # 3f9142; --hit : # fff4c2;
17- --k-table : # 0e7c86; --k-view : # 7a4fd0; --k-scalar : # 2f8f4e; --k-tablefn : # 9a6500; --k-agg : # c05a2a; --k-tio : # b03a6e; --type-color : # 0e7c86;
17+ --k-table : # 0e7c86; --k-view : # 7a4fd0; --k-scalar : # 2f8f4e; --k-tablefn : # 9a6500; --k-agg : # c05a2a; --k-tio : # b03a6e; --k-macro : # 2b6cb0 ; -- type-color: # 0e7c86;
1818 --tint : 6% ; --tint-hover : 11% ; --tint-open : 15% ; --edge : 24% ; --edge-hover : 46% ; --edge-open : 56% ;
1919 --radius : 14px ; --row-radius : 9px ;
2020 --mono : ui-monospace, "SF Mono" , Menlo, monospace;
2828 --accent-2 : # ee9a94; --on-accent : # 1a120f; --ai : # 5cba74; --ai-soft : # 16231a; --on-ai : # 0f1a10;
2929 --cup-soft : # 1b271e; --cup : # 6fce87; --cup-2 : # 82d897; --on-cup : # 10200f;
3030 --code-bg : # 100f0a; --code-ink : # ece7d6; --hit : # 4a4222;
31- --k-table : # 4fc7d0; --k-view : # b39ae8; --k-scalar : # 6fce87; --k-tablefn : # e0b055; --k-agg : # e69264; --k-tio : # e084ad; --type-color : # 5bbfc7;
31+ --k-table : # 4fc7d0; --k-view : # b39ae8; --k-scalar : # 6fce87; --k-tablefn : # e0b055; --k-agg : # e69264; --k-tio : # e084ad; --k-macro : # 7fb3e8 ; -- type-color: # 5bbfc7;
3232 --tint : 12% ; --tint-hover : 20% ; --tint-open : 26% ; --edge : 32% ; --edge-hover : 56% ; --edge-open : 68% ;
3333 }
3434 }
199199 . grp . tri { color : var ( --muted ) ; }
200200 . k-table { --kc : var ( --k-table ) ; } . k-view { --kc : var ( --k-view ) ; } . k-scalar { --kc : var ( --k-scalar ) ; }
201201 . k-tablefn { --kc : var ( --k-tablefn ) ; } . k-agg { --kc : var ( --k-agg ) ; } . k-tio { --kc : var ( --k-tio ) ; }
202+ . k-macro { --kc : var ( --k-macro ) ; }
202203
203204 /* level 3: object rows as tinted cards */
204205 details . tbl , details . fn {
@@ -504,9 +505,21 @@ <h1 id="worker-name">—</h1>
504505 const r = fnReturns(f);
505506 if (r) out.returns = r;
506507 return out;
508+ // Macros get their own buckets rather than folding into scalar/table. They
509+ // are a different thing to call: DuckDB expands them inline as SQL, so they
510+ // cost no RPC round-trip and run identically on every transport. Merging
511+ // them also misreported the catalog — vgi-open-meteo has six scalar macros
512+ // and zero scalar functions, and the page listed all six under "Scalar
513+ // functions".
514+ //
515+ // Their parameters carry names only. A DuckDB macro is untyped, so the
516+ // protocol has no type to send and this used to invent `ANY` for each one —
517+ // which reads as "accepts any type" when it means "no type exists". Leaving
518+ // it unset lets the signature and the argument card omit it, and keeps ANY
519+ // meaning what it says on a genuinely polymorphic function argument.
507520 }).concat((macrosRaw||[]).map(m=> ({
508- name: m.name, type: String(m.macro_type).startsWith('TABLE') ? 'table ' : 'scalar ',
509- doc: m.comment || '', args: (m.parameters||[]).map(p=> ({name:p, type:'ANY' }))
521+ name: m.name, type: String(m.macro_type).startsWith('TABLE') ? 'table_macro ' : 'scalar_macro ',
522+ doc: m.comment || '', args: (m.parameters||[]).map(p=> ({name:p}))
510523 })));
511524 functions.sort((a,b)=> a.type===b.type ? byName(a,b) : (a.type< b.type?-1:1));
512525 const entry = {name: si.name, tables, views, functions};
@@ -522,7 +535,7 @@ <h1 id="worker-name">—</h1>
522535 data_versions: (info.releases||[]).map(r=> Object.assign({spec:r.version}, r.summary?{label:r.summary}:{})),
523536 attach_options: [],
524537 tags: {},
525- counts: {schemas:0,tables:0,views:0,functions:0},
538+ counts: {schemas:0,tables:0,views:0,functions:0,macros:0 },
526539 schemas: [],
527540 _aod: null
528541 };
@@ -552,11 +565,16 @@ <h1 id="worker-name">—</h1>
552565 const schemaInfos = (await client.schemas(cat._aod)).slice()
553566 .sort((a,b)=> a.name< b.name?-1:a.name> b.name?1:0);
554567 cat.schemas = await Promise.all(schemaInfos.map(si=> schemaEntry(cat._aod, si)));
568+ // `s.functions` holds both, so macros are counted apart rather than inflating
569+ // the function count — vgi-open-meteo reads "13 functions · 6 macros", not
570+ // "19 functions" when it has no scalar functions at all.
571+ const isMacro = f => f.type === 'scalar_macro' || f.type === 'table_macro';
555572 cat.counts = {
556573 schemas: cat.schemas.length,
557574 tables: cat.schemas.reduce((n,s)=> n+s.tables.length,0),
558575 views: cat.schemas.reduce((n,s)=> n+s.views.length,0),
559- functions: cat.schemas.reduce((n,s)=> n+s.functions.length,0)
576+ functions: cat.schemas.reduce((n,s)=> n+s.functions.filter(f=> !isMacro(f)).length,0),
577+ macros: cat.schemas.reduce((n,s)=> n+s.functions.filter(isMacro).length,0)
560578 };
561579 return cat;
562580}
@@ -837,12 +855,17 @@ <h1 id="worker-name">—</h1>
837855const FN_TYPES = [['scalar','Scalar functions','function','k-scalar'],
838856 ['table','Table functions','function','k-tablefn'],
839857 ['aggregate','Aggregate functions','aggregate','k-agg'],
840- ['table_in_out','Table in-out functions','tio','k-tio']];
858+ ['table_in_out','Table in-out functions','tio','k-tio'],
859+ ['scalar_macro','Scalar macros','function','k-macro'],
860+ ['table_macro','Table macros','function','k-macro']];
841861function argCard(a){
842862 const def = (a.default!==undefined && a.default!==null) ? '< span class ="arg-def "> default '+esc(a.default)+'</ span > ' : '';
843863 const desc = a.desc ? esc(a.desc) : '';
844864 const meta = (desc||def) ? '< div class ="col-comment "> '+desc+(desc&&def?' · ':'')+def+'</ div > ' : '';
845- return '< div class ="col-item "> < div class ="col "> < span class ="col-name "> '+esc(a.name)+(a.named?'< span class ="arg-kind "> :=</ span > ':'')+'</ span > < span class ="col-type "> '+esc(duckdbType(a.type))+'</ span > </ div > '+meta+'</ div > ';
865+ // A macro parameter has no type at all, and `duckdbType(undefined)` returns
866+ // undefined — printed, that renders the literal string "undefined".
867+ const type = a.type ? '< span class ="col-type "> '+esc(duckdbType(a.type))+'</ span > ' : '';
868+ return '< div class ="col-item "> < div class ="col "> < span class ="col-name "> '+esc(a.name)+(a.named?'< span class ="arg-kind "> :=</ span > ':'')+'</ span > '+type+'</ div > '+meta+'</ div > ';
846869}
847870function fnRow(f, iconName){
848871 const pos = f.args.filter(a=> !a.named), named = f.args.filter(a=> a.named);
@@ -885,7 +908,8 @@ <h1 id="worker-name">—</h1>
885908 const asof = (c.data_versions && c.data_versions.length)
886909 ? ' · < span class ="asof "> as of '+esc(currentSpec(c) || 'latest ('+latestSpec(c)+')')+'</ span > ' : '';
887910 document.getElementById('cat-sub').innerHTML =
888- cc.schemas+' schemas · '+cc.tables+' tables · '+cc.views+' views · '+cc.functions+' functions'+asof;
911+ cc.schemas+' schemas · '+cc.tables+' tables · '+cc.views+' views · '+cc.functions+' functions'+
912+ (cc.macros?' · '+cc.macros+' macro'+(cc.macros!==1?'s':''):'')+asof;
889913
890914 if (c.attach_error){
891915 // Say why the catalog could not be listed. An empty tree here would read
@@ -896,9 +920,12 @@ <h1 id="worker-name">—</h1>
896920
897921 const single = c.schemas.length===1;
898922 root.innerHTML = c.schemas.map(s=> {
923+ const sMacros = s.functions.filter(f=> f.type==='scalar_macro'||f.type==='table_macro').length;
924+ const sFns = s.functions.length - sMacros;
899925 const sub = [ s.tables.length+' table'+(s.tables.length!==1?'s':''),
900926 s.views.length? s.views.length+' view'+(s.views.length!==1?'s':''):null,
901- s.functions.length? s.functions.length+' function'+(s.functions.length!==1?'s':''):null
927+ sFns? sFns+' function'+(sFns!==1?'s':''):null,
928+ sMacros? sMacros+' macro'+(sMacros!==1?'s':''):null
902929 ].filter(Boolean).join(' · ');
903930 const openAttr = (single && s.tables.length< =8) ? ' open' : '';
904931 const tblGrp = s.tables.length ? '< div class ="grp k-table "> < div class ="glabel "> '+icon('table')+'Tables</ div > '+
0 commit comments