@lakeql/cli 0.7.4 → 0.7.6
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/cli.mjs +5 -4
- package/package.json +8 -8
package/dist/cli.mjs
CHANGED
|
@@ -7,8 +7,9 @@ import{a as e,c as t,i as n,l as r,n as i,o as a,r as o,s,t as c,u as l}from"./p
|
|
|
7
7
|
`);throw new M(`Validation failed for ${a}.`,{code:`ENDPOINT_DUPLICATE_FIELDS`,details:[e]})}console.log(`\n${p(`Loaded definition summary:`)}`),console.log(p(`tableName: ${l.tableName}`)),console.log(p(`catalog: ${l.catalog}`)),console.log(p(`schema: ${l.schema}`));let f=l.mutation?l.mutation.loadStrategy:`disabled`;console.log(p(`mutation: ${f}`)),console.log(`\n${p(`Fields:`)}`),console.log(p(q(l.fields))),console.log(``);let h=await F(n===process.cwd()?void 0:n),g=d.join(h,`schemas/custom`,l.catalog,l.schema,l.tableName);if(_(g)&&!i&&!await b(`Directory "${g}" already exists. Overwrite?`))throw N(`Aborted: endpoint generation was not confirmed.`);await Ye({definition:l,outputDir:g,skipRegistry:r,sourcePathOverride:n===process.cwd()?void 0:n}),console.log(m(`Endpoint generated successfully at: ${g}`))})}async function J(e){try{return(await te(e,{withFileTypes:!0})).filter(e=>e.isDirectory()).map(e=>e.name).toSorted()}catch{return[]}}async function Ze(e){let t=d.join(e,`schemas`,`generated`);if(!_(t))throw new M(`No generated schemas found at "${t}".`,{code:`GENERATE_IMPORT_CONFIG_NO_SCHEMAS`,hint:"Run `lakeql-cli pull` first to generate schemas.",exitCode:1});let n=await J(t);if(n.length===0)throw new M(`No catalogs found in "${t}".`,{code:`GENERATE_IMPORT_CONFIG_EMPTY`,hint:"Run `lakeql-cli pull` first to generate schemas.",exitCode:1});return(await Promise.all(n.map(async e=>{let n=d.join(t,e),r=await J(n);return(await Promise.all(r.map(async t=>{let r=await J(d.join(n,t));return r.length>0?{catalog:e,schema:t,tables:r}:null}))).filter(e=>e!==null)}))).flat()}function Qe(e){let t=[`/** @type {import('@lakeql/cli').BulkPullConfig} */`,`export default [`];for(let n of e){let e=JSON.stringify(n.tables,null,2).split(`
|
|
8
8
|
`).map((e,t)=>t===0?e:` ${e}`).join(`
|
|
9
9
|
`);t.push(` {`),t.push(` catalog: ${JSON.stringify(n.catalog)},`),t.push(` schema: ${JSON.stringify(n.schema)},`),t.push(` tables: ${e},`),t.push(` },`)}return t.push(`]`),t.push(``),t.join(`
|
|
10
|
-
`)}function $e(){let e=a();return e.action(async e=>{let{sourcePath:t,output:n,force:i}=e,a=Qe(await Ze(await F(t===(process.env.INIT_CWD??process.cwd())?void 0:t))),o=d.isAbsolute(n)?n:d.resolve(r(),n);if(!i&&_(o)&&(console.log(h(`File "${o}" already exists.`)),!await b(`Overwrite "${o}"?`)))throw N(`Aborted: import config generation was not confirmed.`);await ee(d.dirname(o),{recursive:!0}),await y(o,a,`utf-8`),console.log(m(`Written to "${o}".`))}),e}let et;function tt(){return me({runtimeEnv:process.env,server:{HIVE_CATALOG:A().min(1),HIVE_HOST:A(),HIVE_PASSWORD:A().min(1),HIVE_PORT:A().transform(e=>Number.parseInt(e,10)).pipe(_e()),HIVE_SOURCE:A().optional(),HIVE_USERNAME:A().min(1),LOG_LEVEL:ge([`info`,`warn`,`error`,`debug`]).default(`warn`)}})}function Y(){return et||=tt(),et}function nt(){let t=e();return t.action(async({catalog:e,schema:t,table:n})=>{let r=Y(),i=e??r.HIVE_CATALOG,a=new O({auth:{password:r.HIVE_PASSWORD,type:`basic`,username:r.HIVE_USERNAME},catalog:i,host:r.HIVE_HOST,port:r.HIVE_PORT}),o=t;if(o===void 0){let e;try{e=await a.schemas({catalog:i})}catch(e){throw P(`list schemas`,`list-columns (catalog=${i})`,e)}o=await x(`Choose a schema from the ${i} catalog`,{autocomplete:!0,choices:e})}let s=n;if(s===void 0){let e;try{e=await a.tables({catalog:i,schema:o})}catch(e){throw P(`list tables`,`list-columns (catalog=${i}, schema=${o})`,e)}s=await x(`Choose a table from "${i}.${o}"`,{autocomplete:!0,choices:e})}let c;try{c=await a.columns({catalog:i,schema:o,table:s})}catch(e){throw P(`list columns`,`list-columns (catalog=${i}, schema=${o}, table=${s})`,e)}let l=c.map(([e,t,n,r])=>({description:r,extra:n,name:e,type:t})),u=new k;u.column(`Column Name`,`name`),u.column(`Type`,`type`),u.column(`Extra`,`extra`),u.column(`Description`,`description`),u.render(l)}),t}function rt(){let e=n();return e.action(async({catalog:e})=>{let t=Y(),n=e??t.HIVE_CATALOG,r=new O({auth:{password:t.HIVE_PASSWORD,type:`basic`,username:t.HIVE_USERNAME},catalog:n,host:t.HIVE_HOST,port:t.HIVE_PORT}),i;try{i=await r.schemas({catalog:n})}catch(e){throw P(`list schemas`,`list-schemas (catalog=${n})`,e)}let a=new k;a.column(`Schema Name`,`s`),a.render(i.map(e=>({s:e})))}),e}function it(){let e=o();return e.action(async({catalog:e,schema:t})=>{let n=Y(),r=e??n.HIVE_CATALOG,i=new O({auth:{password:n.HIVE_PASSWORD,type:`basic`,username:n.HIVE_USERNAME},catalog:r,host:n.HIVE_HOST,port:n.HIVE_PORT}),a=t;if(a===void 0){let e;try{e=await i.schemas({catalog:r})}catch(e){throw P(`list schemas`,`list-tables (catalog=${r})`,e)}a=await x(`Choose a schema from the ${r} catalog`,{autocomplete:!0,choices:e})}let o;try{o=await i.tables({catalog:r,schema:a})}catch(e){throw P(`list tables`,`list-tables (catalog=${r}, schema=${a})`,e)}let s=new k;s.column(`Table Name`,`t`),s.render(o.map(e=>({t:e})))}),e}function at(){let e=i();return e.action(async({catalog:e,schema:t})=>{let n=Y(),r=e??n.HIVE_CATALOG,i=new O({auth:{password:n.HIVE_PASSWORD,type:`basic`,username:n.HIVE_USERNAME},catalog:r,host:n.HIVE_HOST,port:n.HIVE_PORT}),a=t;if(a===void 0){let e;try{e=await i.schemas({catalog:r})}catch(e){throw P(`list schemas`,`list-views (catalog=${r})`,e)}a=await x(`Choose a schema from the ${r} catalog`,{choices:e})}let o;try{o=await i.views({catalog:r,schema:a})}catch(e){throw P(`list views`,`list-views (catalog=${r}, schema=${a})`,e)}let s=new k;s.column(`View Name`,`v`),s.render(o.map(e=>({v:e})))}),e}const ot=j.object({schema:j.string().min(1),catalog:j.string().min(1).optional(),tables:j.array(j.string().min(1)).optional(),views:j.array(j.string().min(1)).optional()}).superRefine((e,t)=>{let n=Array.isArray(e.tables)&&e.tables.length>0,r=Array.isArray(e.views)&&e.views.length>0;!n&&!r&&t.addIssue({code:`custom`,message:`At least one non-empty list is required: tables or views.`,path:[`tables`]})}),st=j.array(ot);function X(e){return st.parse(e)}function ct(e){switch(e.replaceAll(/[^a-zA-Z]/gu,``)){case`varchar`:return`String`;case`decimal`:case`double`:case`float`:return`Float`;case`integer`:case`bigint`:return`Integer`;case`boolean`:return`Boolean`;case`timestamp`:return`DateTime`;case`date`:return`Date`;default:return`String`}}function lt(e,t){return typeof t==`string`?{name:e,type:ct(t)}:Array.isArray(t)?{name:e,type:`Array`,items:ut(t)}:typeof t==`object`&&t?{name:e,type:`Object`,fields:Z(t)}:{name:e,type:`String`}}function ut(e){if(e.length===0)return{type:`String`};let[t]=e;return typeof t==`string`?{type:ct(t)}:typeof t==`object`&&t&&!Array.isArray(t)?{type:`Object`,fields:Z(t)}:{type:`String`}}function Z(e){let t=[];for(let[n,r]of Object.entries(e))t.push(lt(n,r));return t}function dt(e){let{tableName:t,catalog:n,schema:r,parsedColumns:i}=e;return{version:`1.0`,tableName:t,catalog:n,schema:r,fields:Z(i),mutation:!1}}async function Q(e){let{trinoClient:t,catalog:n,schema:r,tables:i,resolvedTargetPath:a,skipRegistry:o,sourcePathOverride:s,onItemStart:c,onItemFinish:l}=e;for(let e of i){let i=!1;c?.(e);try{await Ye({definition:dt({tableName:e,catalog:n,schema:r,parsedColumns:ye((await t.columns({catalog:n,schema:r,table:e})).map(e=>be({keys:[`name`,`type`,`extra`,`description`],values:e})))}),outputDir:d.join(a,`schemas/generated`,n,r,e),skipRegistry:o,sourcePathOverride:s}),i=!0}finally{l?.(e,i)}}}function ft(e){let t=0,n=[],r=()=>{--t,n.shift()?.()};return async function(i){t>=e&&await new Promise(e=>{n.push(e)}),t+=1;try{return await i()}finally{r()}}}async function
|
|
11
|
-
`),r=f.size>5?`\n ... +${f.size-5} more active`:``;u.output=`Completed ${d}/${a} | Active ${f.size}/${p}${n?`\n${n}${r}`:``}`};c&&m();let h=new O({auth:{password:o.HIVE_PASSWORD,type:`basic`,username:o.HIVE_USERNAME},catalog:t,host:o.HIVE_HOST,port:o.HIVE_PORT}),g=async(n,r)=>{try{await l(()=>Q({trinoClient:h,catalog:t,schema:e.schema,tables:[n],resolvedTargetPath:s,skipRegistry:!0,sourcePathOverride:i}))}catch(i){throw P(r===`tables`?`pull tables`:`pull views`,`bulk pull (catalog=${t}, schema=${e.schema}, ${r}=${n})`,i)}};if(c){let n=[...e.tables?.map(e=>({itemKind:`tables`,itemName:e}))??[],...e.views?.map(e=>({itemKind:`views`,itemName:e}))??[]],r=async()=>{for(;n.length>0;){let e=n.shift();if(!e)return;f.add(e.itemName),m();try{await g(e.itemName,e.itemKind),d+=1}
|
|
12
|
-
`)
|
|
13
|
-
`)
|
|
10
|
+
`)}function $e(){let e=a();return e.action(async e=>{let{sourcePath:t,output:n,force:i}=e,a=Qe(await Ze(await F(t===(process.env.INIT_CWD??process.cwd())?void 0:t))),o=d.isAbsolute(n)?n:d.resolve(r(),n);if(!i&&_(o)&&(console.log(h(`File "${o}" already exists.`)),!await b(`Overwrite "${o}"?`)))throw N(`Aborted: import config generation was not confirmed.`);await ee(d.dirname(o),{recursive:!0}),await y(o,a,`utf-8`),console.log(m(`Written to "${o}".`))}),e}let et;function tt(){return me({runtimeEnv:process.env,server:{HIVE_CATALOG:A().min(1),HIVE_HOST:A(),HIVE_PASSWORD:A().min(1),HIVE_PORT:A().transform(e=>Number.parseInt(e,10)).pipe(_e()),HIVE_SOURCE:A().optional(),HIVE_USERNAME:A().min(1),LOG_LEVEL:ge([`info`,`warn`,`error`,`debug`]).default(`warn`)}})}function Y(){return et||=tt(),et}function nt(){let t=e();return t.action(async({catalog:e,schema:t,table:n})=>{let r=Y(),i=e??r.HIVE_CATALOG,a=new O({auth:{password:r.HIVE_PASSWORD,type:`basic`,username:r.HIVE_USERNAME},catalog:i,host:r.HIVE_HOST,port:r.HIVE_PORT}),o=t;if(o===void 0){let e;try{e=await a.schemas({catalog:i})}catch(e){throw P(`list schemas`,`list-columns (catalog=${i})`,e)}o=await x(`Choose a schema from the ${i} catalog`,{autocomplete:!0,choices:e})}let s=n;if(s===void 0){let e;try{e=await a.tables({catalog:i,schema:o})}catch(e){throw P(`list tables`,`list-columns (catalog=${i}, schema=${o})`,e)}s=await x(`Choose a table from "${i}.${o}"`,{autocomplete:!0,choices:e})}let c;try{c=await a.columns({catalog:i,schema:o,table:s})}catch(e){throw P(`list columns`,`list-columns (catalog=${i}, schema=${o}, table=${s})`,e)}let l=c.map(([e,t,n,r])=>({description:r,extra:n,name:e,type:t})),u=new k;u.column(`Column Name`,`name`),u.column(`Type`,`type`),u.column(`Extra`,`extra`),u.column(`Description`,`description`),u.render(l)}),t}function rt(){let e=n();return e.action(async({catalog:e})=>{let t=Y(),n=e??t.HIVE_CATALOG,r=new O({auth:{password:t.HIVE_PASSWORD,type:`basic`,username:t.HIVE_USERNAME},catalog:n,host:t.HIVE_HOST,port:t.HIVE_PORT}),i;try{i=await r.schemas({catalog:n})}catch(e){throw P(`list schemas`,`list-schemas (catalog=${n})`,e)}let a=new k;a.column(`Schema Name`,`s`),a.render(i.map(e=>({s:e})))}),e}function it(){let e=o();return e.action(async({catalog:e,schema:t})=>{let n=Y(),r=e??n.HIVE_CATALOG,i=new O({auth:{password:n.HIVE_PASSWORD,type:`basic`,username:n.HIVE_USERNAME},catalog:r,host:n.HIVE_HOST,port:n.HIVE_PORT}),a=t;if(a===void 0){let e;try{e=await i.schemas({catalog:r})}catch(e){throw P(`list schemas`,`list-tables (catalog=${r})`,e)}a=await x(`Choose a schema from the ${r} catalog`,{autocomplete:!0,choices:e})}let o;try{o=await i.tables({catalog:r,schema:a})}catch(e){throw P(`list tables`,`list-tables (catalog=${r}, schema=${a})`,e)}let s=new k;s.column(`Table Name`,`t`),s.render(o.map(e=>({t:e})))}),e}function at(){let e=i();return e.action(async({catalog:e,schema:t})=>{let n=Y(),r=e??n.HIVE_CATALOG,i=new O({auth:{password:n.HIVE_PASSWORD,type:`basic`,username:n.HIVE_USERNAME},catalog:r,host:n.HIVE_HOST,port:n.HIVE_PORT}),a=t;if(a===void 0){let e;try{e=await i.schemas({catalog:r})}catch(e){throw P(`list schemas`,`list-views (catalog=${r})`,e)}a=await x(`Choose a schema from the ${r} catalog`,{choices:e})}let o;try{o=await i.views({catalog:r,schema:a})}catch(e){throw P(`list views`,`list-views (catalog=${r}, schema=${a})`,e)}let s=new k;s.column(`View Name`,`v`),s.render(o.map(e=>({v:e})))}),e}const ot=j.object({schema:j.string().min(1),catalog:j.string().min(1).optional(),tables:j.array(j.string().min(1)).optional(),views:j.array(j.string().min(1)).optional()}).superRefine((e,t)=>{let n=Array.isArray(e.tables)&&e.tables.length>0,r=Array.isArray(e.views)&&e.views.length>0;!n&&!r&&t.addIssue({code:`custom`,message:`At least one non-empty list is required: tables or views.`,path:[`tables`]})}),st=j.array(ot);function X(e){return st.parse(e)}function ct(e){switch(e.replaceAll(/[^a-zA-Z]/gu,``)){case`varchar`:return`String`;case`decimal`:case`double`:case`float`:return`Float`;case`integer`:case`bigint`:return`Integer`;case`boolean`:return`Boolean`;case`timestamp`:return`DateTime`;case`date`:return`Date`;default:return`String`}}function lt(e,t){return typeof t==`string`?{name:e,type:ct(t)}:Array.isArray(t)?{name:e,type:`Array`,items:ut(t)}:typeof t==`object`&&t?{name:e,type:`Object`,fields:Z(t)}:{name:e,type:`String`}}function ut(e){if(e.length===0)return{type:`String`};let[t]=e;return typeof t==`string`?{type:ct(t)}:typeof t==`object`&&t&&!Array.isArray(t)?{type:`Object`,fields:Z(t)}:{type:`String`}}function Z(e){let t=[];for(let[n,r]of Object.entries(e))t.push(lt(n,r));return t}function dt(e){let{tableName:t,catalog:n,schema:r,parsedColumns:i}=e;return{version:`1.0`,tableName:t,catalog:n,schema:r,fields:Z(i),mutation:!1}}async function Q(e){let{trinoClient:t,catalog:n,schema:r,tables:i,resolvedTargetPath:a,skipRegistry:o,sourcePathOverride:s,onItemStart:c,onItemFinish:l}=e;for(let e of i){let i=!1;c?.(e);try{await Ye({definition:dt({tableName:e,catalog:n,schema:r,parsedColumns:ye((await t.columns({catalog:n,schema:r,table:e})).map(e=>be({keys:[`name`,`type`,`extra`,`description`],values:e})))}),outputDir:d.join(a,`schemas/generated`,n,r,e),skipRegistry:o,sourcePathOverride:s}),i=!0}finally{l?.(e,i)}}}function ft(e){let t=e,n;for(let e=0;e<10;e+=1)if(t instanceof Error)t.message&&(n=t.message),t=t.cause;else if(typeof t==`object`&&t){let e=t.message;typeof e==`string`&&(n=e),t=t.cause}else break;return n}function pt(e){let t=0,n=[],r=()=>{--t,n.shift()?.()};return async function(i){t>=e&&await new Promise(e=>{n.push(e)}),t+=1;try{return await i()}finally{r()}}}async function mt(e){let t=r(),n;if(e){let r=d.isAbsolute(e)?e:d.resolve(t,e),i=d.parse(r);n=d.join(i.dir,i.name)}let{config:i}=await S({name:`import`,cwd:t,configFile:n,packageJson:!1,globalRc:!1,rcFile:!1,dotenv:!1}),a=i;return Array.isArray(a)?X(a):a&&typeof a==`object`&&`default`in a&&Array.isArray(a.default)?X(a.default):X([])}async function ht(e){let{configPath:t,catalog:n,concurrency:r=8,sourcePathOverride:i,skipRegistry:a}=e,o=Y(),s=await F(i),c;try{c=await mt(t)}catch(e){throw e instanceof he?new M(`Invalid bulk pull config.`,{code:`BULK_CONFIG_INVALID`,details:e.issues.map(e=>` - ${e.path.length>0?e.path.join(`.`):`root`}: ${e.message}`),hint:`Ensure each entry defines a schema and at least one non-empty list: tables or views.`,cause:e}):e}if(c.length===0){console.log(p(`No entries found in bulk config.`));return}let l=pt(r);await new ve([{title:`Pull data`,task:(e,t)=>t.newListr(c.map(e=>{let t=n??e.catalog??o.HIVE_CATALOG,a=(e.tables?.length??0)+(e.views?.length??0),c=a>10;return{title:`${t}/${e.schema} — ${a} item(s)`,task:async(n,u)=>{let d=0,f=new Set,p=Math.min(r,a),m=()=>{let n=[...f].slice(0,5).map(n=>` - ${t}.${e.schema}.${n}`).join(`
|
|
11
|
+
`),r=f.size>5?`\n ... +${f.size-5} more active`:``;u.output=`Completed ${d}/${a} | Active ${f.size}/${p}${n?`\n${n}${r}`:``}`};c&&m();let h=new O({auth:{password:o.HIVE_PASSWORD,type:`basic`,username:o.HIVE_USERNAME},catalog:t,host:o.HIVE_HOST,port:o.HIVE_PORT}),g=async(n,r)=>{try{await l(()=>Q({trinoClient:h,catalog:t,schema:e.schema,tables:[n],resolvedTargetPath:s,skipRegistry:!0,sourcePathOverride:i}))}catch(i){throw P(r===`tables`?`pull tables`:`pull views`,`bulk pull (catalog=${t}, schema=${e.schema}, ${r}=${n})`,i)}};if(c){let n=[...e.tables?.map(e=>({itemKind:`tables`,itemName:e}))??[],...e.views?.map(e=>({itemKind:`views`,itemName:e}))??[]],r=[],i=async()=>{for(;n.length>0;){let e=n.shift();if(!e)return;f.add(e.itemName),m();try{await g(e.itemName,e.itemKind),d+=1}catch(t){r.push({itemName:e.itemName,itemKind:e.itemKind,error:t instanceof Error?t:Error(String(t))})}finally{f.delete(e.itemName),m()}}};if(await Promise.all(Array.from({length:p},()=>i())),r.length>0){let n=r.map(({itemName:e,itemKind:t,error:n})=>`${e} (${t}): ${ft(n)||n.message}`),i=r[0]?.error;throw i?new M(`${t}/${e.schema} — ${d}/${a} item(s) pulled.\nFailed items:\n - ${n.join(`
|
|
12
|
+
- `)}`,{code:`BULK_PULL_PARTIAL_FAILURE`,cause:i}):Error(`Failed to collect error information`)}u.output=`Completed ${d}/${a}`,u.title=`${t}/${e.schema} — ${a} item(s) pulled`;return}if(e.tables&&e.tables.length>0){let{tables:n}=e;u.output=`Pulling ${n.length} table(s)...`;try{await l(()=>Q({trinoClient:h,catalog:t,schema:e.schema,tables:n,resolvedTargetPath:s,skipRegistry:!0,sourcePathOverride:i}))}catch(r){throw P(`pull tables`,`bulk pull (catalog=${t}, schema=${e.schema}, tables=${n.join(`,`)})`,r)}}if(e.views&&e.views.length>0){let{views:n}=e;u.output=`Pulling ${n.length} view(s)...`;try{await l(()=>Q({trinoClient:h,catalog:t,schema:e.schema,tables:n,resolvedTargetPath:s,skipRegistry:!0,sourcePathOverride:i}))}catch(r){throw P(`pull views`,`bulk pull (catalog=${t}, schema=${e.schema}, views=${n.join(`,`)})`,r)}}u.title=`${t}/${e.schema} — ${a} item(s) pulled`}}}),{concurrent:!0,exitOnError:!1})},{title:`Create registry`,enabled:!a,task:async()=>{await I(i)}}],{concurrent:!1,exitOnError:!0}).run()}async function gt(e,t,n){try{return await n()}catch(n){throw P(e,t,n)}}function _t(){let e=c();return e.action(async e=>{let{skipRegistry:t,sourcePath:n,bulk:r,bulkConfig:i,concurrency:a=8}=e,o=n===(process.env.INIT_CWD??process.cwd())?void 0:n;if(r){await ht({configPath:i,catalog:e.catalog,concurrency:a,sourcePathOverride:o,skipRegistry:t});return}let s=Y(),c=e.catalog??s.HIVE_CATALOG,{schema:l,table:u,type:d}=e,f=await F(o),h=new O({auth:{password:s.HIVE_PASSWORD,type:`basic`,username:s.HIVE_USERNAME},catalog:c,host:s.HIVE_HOST,port:s.HIVE_PORT});if(!l){let e=await gt(`list schemas`,`pull (catalog=${c})`,()=>h.schemas({catalog:c}));l=await x(`Choose a schema from the ${c} catalog`,{autocomplete:!0,choices:e})}if(u.length===0&&(d??=await x(`What do you want to see from ${c}/${l}`,{choices:[{label:`Show tables`,value:`tables`},{label:`Show views`,value:`views`}]})),u.length===0){d??=`tables`;let e=[];if(e=await gt(d===`views`?`list views`:`list tables`,`pull (catalog=${c}, schema=${l})`,()=>d===`views`?h.views({catalog:c,schema:l}):h.tables({catalog:c,schema:l})),e.length===0)throw new M(`No ${d} found in schema '${c}.${l}'.`,{code:`PULL_NO_RESULTS`,hint:`Use a different schema or check permissions for '${c}.${l}'.`,exitCode:0});u=await re(`Choose the ${d} to pull`,{autocomplete:!0,choices:e,validators:[ae.required()]})}console.log(p(`Pulling ${u.length} item(s) from ${c}.${l} into ${f}/schemas/generated...`));let g=u.length>10;await new ve([{title:`Pull ${u.length} item(s)`,task:async(e,t)=>{if(!g)return t.newListr(u.map(e=>({title:`${c}.${l}.${e}`,task:async()=>{await Q({trinoClient:h,catalog:c,schema:l,tables:[e],resolvedTargetPath:f,skipRegistry:!0,sourcePathOverride:o})}})),{concurrent:u.length>1?Math.min(a,u.length):!1,exitOnError:!0});let n=[...u],r=new Set,i=0,s=Math.min(a,u.length),d=()=>{let e=[...r].slice(0,5).map(e=>` - ${c}.${l}.${e}`).join(`
|
|
13
|
+
`),n=r.size>5?`\n ... +${r.size-5} more active`:``;t.output=`Completed ${i}/${u.length} | Active ${r.size}/${s}${e?`\n${e}${n}`:``}`};d();let p=async()=>{for(;n.length>0;){let e=n.shift();if(!e)return;r.add(e),d(),await Q({trinoClient:h,catalog:c,schema:l,tables:[e],resolvedTargetPath:f,skipRegistry:!0,sourcePathOverride:o}),r.delete(e),i+=1,d()}};await Promise.all(Array.from({length:s},()=>p())),t.output=`Completed ${i}/${u.length}`}},{title:`Create registry`,enabled:!t,task:async()=>{await I(o)}}],{concurrent:!1,exitOnError:!0}).run(),console.log(m(`Pull completed: ${u.length} item(s) generated under ${f}/schemas/generated/${c}/${l}`))}),e}const vt=[`lakeql.config.mjs`,`lakeql.config.ts`,`lakeql.config.json`];function yt(e){return`/** @type {import('@lakeql/cli').LakeQLConfig} */\nexport default {\n${Object.entries(e).map(([e,t])=>` ${e}: ${JSON.stringify(t)},`).join(`
|
|
14
|
+
`)}\n}\n`}function bt(e){for(let t of vt)if(_(d.join(e,t)))return t;return null}function xt(){return l().action(async()=>{let e=r(),t=bt(e);if(t&&await x(`${t} already exists. Overwrite?`,{choices:[{label:`Yes`,value:`yes`},{label:`No`,value:`no`}]})===`no`){console.log(p(`Aborted.`));return}let n=await x(`Config format:`,{choices:[{label:`lakeql.config.mjs (recommended)`,value:`mjs`},{label:`lakeql.config.json`,value:`json`}]}),i=_(d.join(e,`src`)),a;if(i)a=`src`,console.log(p(`Detected src/ directory - generated code will be placed in src/`));else{let e=await x(`Where should generated code be placed?`,{choices:[{label:`./ (project root)`,value:`.`},{label:`Custom path`,value:`__custom__`}]});a=e,e===`__custom__`&&(a=await ie(`Enter the source path (relative to project root):`,{defaultValue:`.`}))}let o={sourcePath:a},s=n===`mjs`?`lakeql.config.mjs`:`lakeql.config.json`,c=d.join(e,s);await y(c,n===`mjs`?yt(o):`${JSON.stringify(o,null,2)}\n`),console.log(m(`Created ${s} at ${c}`))})}function St(e){let t=new u;return t.configureHelp({sortSubcommands:!0}),t.name(`lakeql-cli`).description(`LakeQL CLI`).version(e.version).addCommand(rt()).addCommand(it()).addCommand(at()).addCommand(nt()).addCommand(_t()).addCommand(Xe()).addCommand(Oe()).addCommand($e()).addCommand(xt()),t}async function Ct(e=process.argv.slice(2),t){let n=St(t??await g());return e.length===0?(n.outputHelp(),0):(await n.parseAsync(e,{from:`user`}),0)}function $(e){if(!(typeof e!=`object`||!e))return e}function wt(e){let t=$(e),n=t?.message;for(;t?.cause;){let e=$(t.cause);if(!e)break;e.message&&(n=e.message),t=e}return n}function Tt(e){if(e instanceof M&&e.code)return e.code;let t=$(e);return t?.code?t.code:$(t?.cause)?.code}function Et(e){if(e instanceof M&&e.hint)return e.hint;let t=wt(e)?.toLowerCase()??``,n=Tt(e);if(t.includes(`fetch failed`)||n===`ECONNREFUSED`||n===`ENOTFOUND`||n===`ETIMEDOUT`)return`Could not reach Trino. Verify HIVE_HOST/HIVE_PORT and that the Trino endpoint is reachable from your network.`;if(t.includes(`invalid environment variables`)||t.includes(`required`))return`Missing or invalid environment variables. Set HIVE_HOST, HIVE_PORT, HIVE_USERNAME, HIVE_PASSWORD and HIVE_CATALOG.`}function Dt(e){let t=[e instanceof M&&e.exitCode===0?`LakeQL CLI aborted.`:`LakeQL CLI failed.`],n=e instanceof Error?e.message:typeof e==`string`?e:`Unknown error`;t.push(`Reason: ${n}`),e instanceof M&&e.details?.length&&t.push(...e.details);let r=wt(e);r&&r!==n&&t.push(`Root cause: ${r}`);let i=Tt(e);i&&t.push(`Error code: ${i}`);let a=Et(e);return a&&t.push(`Hint: ${a}`),t}Ct().catch(e=>{let t=xe(e)?N():e,n=Dt(t),r=t instanceof M&&t.exitCode===0?h:f,i=n.map((e,t)=>t===0?r(e):p(e)).join(`
|
|
14
15
|
`);console.error(i);let a=t instanceof M?t.exitCode:1;process.exit(a)});export{};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lakeql/cli",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.6",
|
|
4
4
|
"description": "CLI for introspecting Trino schemas and generating type-safe GraphQL endpoints",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -58,17 +58,17 @@
|
|
|
58
58
|
"commander": "15.0.0",
|
|
59
59
|
"globby": "16.2.0",
|
|
60
60
|
"handlebars": "4.7.9",
|
|
61
|
-
"listr2": "10.2.
|
|
61
|
+
"listr2": "10.2.2",
|
|
62
62
|
"lodash-es": "4.18.1",
|
|
63
63
|
"read-pkg": "10.1.0",
|
|
64
64
|
"zod": "4.4.3",
|
|
65
|
-
"@lakeql/file-generator": "0.1.
|
|
66
|
-
"@lakeql/helpers": "0.1.5",
|
|
67
|
-
"@lakeql/logger": "0.2.2",
|
|
65
|
+
"@lakeql/file-generator": "0.1.12",
|
|
68
66
|
"@lakeql/column-parser": "0.1.5",
|
|
69
|
-
"@lakeql/
|
|
70
|
-
"@lakeql/
|
|
71
|
-
"@lakeql/
|
|
67
|
+
"@lakeql/helpers": "0.1.6",
|
|
68
|
+
"@lakeql/logger": "0.2.2",
|
|
69
|
+
"@lakeql/response-transformer": "0.1.6",
|
|
70
|
+
"@lakeql/schema-generator": "0.4.5",
|
|
71
|
+
"@lakeql/trino-client": "0.4.1"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
74
|
"@types/lodash-es": "4.17.12",
|