@lakeql/cli 0.3.0 → 0.4.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/cli.mjs +6 -5
- package/dist/index.d.mts +40 -0
- package/dist/index.mjs +1 -0
- package/package.json +9 -4
package/dist/cli.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{Command as e,Option as t}from"@commander-js/extra-typings";import{readPackage as n}from"read-pkg";import{existsSync as r
|
|
3
|
-
`)}function
|
|
2
|
+
import{Command as e,Option as t}from"@commander-js/extra-typings";import{readPackage as n}from"read-pkg";import{existsSync as r}from"node:fs";import{mkdir as i,readFile as a,rm as o,writeFile as s}from"node:fs/promises";import c from"node:path";import{confirm as l,multiselect as u,question as d,select as f,validators as p}from"@topcli/prompts";import{loadConfig as m}from"c12";import{generateCode as h}from"@lakeql/file-generator";import{generateConfig as g}from"@lakeql/file-generator/config";import{generateInterface as _}from"@lakeql/file-generator/interface";import{generateQuerySchema as ee}from"@lakeql/file-generator/query-schema";import{generateModel as te}from"@lakeql/schema-generator/graphql-schema";import{generateJsonSchemaFromFields as ne}from"@lakeql/schema-generator/json-schema";import{generateConfigReqistry as v}from"@lakeql/file-generator/config-registry";import{globby as y}from"globby";import{camelCase as b,upperFirst as x}from"lodash-es";import S from"typescript";import{endpointDefinitionSchema as C,findDuplicateFieldNames as re}from"@lakeql/schema-generator/endpoint-schema";import{TrinoClient as w}from"@lakeql/trino-client";import{ClimtTable as T}from"climt";import{createEnv as E}from"@t3-oss/env-core";import D from"dotenv";import{enum as O,number as ie,string as k}from"zod/v4";import{error as A}from"@lakeql/logger/console";import{Listr as ae}from"listr2";import{parseColumns as oe}from"@lakeql/column-parser";import{convertTrinoResponse as j}from"@lakeql/response-transformer";import M from"kleur";function N(e,t=0){let n=[],r=` `.repeat(t+1);for(let i of e)if(i.type===`Object`)n.push(`${r}${i.name}: Object`),i.fields&&n.push(N(i.fields,t+1));else if(i.type===`Array`){let e=i.items?.type??`Unknown`;n.push(`${r}${i.name}: Array<${e}>`),i.items?.type===`Object`&&i.items.fields&&n.push(N(i.items.fields,t+1))}else n.push(`${r}${i.name}: ${i.type}`);return n.filter(e=>e.length>0).join(`
|
|
3
|
+
`)}function P(){return process.env.INIT_CWD??process.cwd()}const se={sourcePath:`.`};async function ce(){let{config:e}=await m({name:`lakeql`,cwd:P(),defaults:se,packageJson:!1,globalRc:!1,rcFile:!1,dotenv:!1});return e}async function F(e){let t=await ce(),n=P(),r=e??t.sourcePath;return c.isAbsolute(r)?r:c.resolve(n,r)}const I=new t(`--catalog <catalog>`,`catalog to use`).env(`HIVE_CATALOG`),L=new t(`--schema <schema>`,`schema to use`),le=new t(`--table <table>`,`table to use`),ue=new t(`--type <type>`,`Show tables or views`),R=new t(`--source-path <path>`,"Base path for generated code (resolved from the command invocation directory). Files are created in `schemas/generated|custom` inside this path.").default(P(),`command invocation directory`),de=new t(`--skip-registry`,`Skip config registry generation`).default(!1);function fe(){return new e(`create-registry`).description("Generates the config registry to ensure the type-safety while using `createPermission`").addOption(R).action(async({sourcePath:e})=>{await z(e!==process.env.INIT_CWD&&e!==process.cwd()?e:void 0)})}async function z(e){let t=await F(e),n=await h({fileName:`config-registry.ts`,nodes:v({configPaths:(await y(`schemas/**/config.ts`,{cwd:t,onlyFiles:!0})).map(e=>{let t=c.parse(e);return c.join(t.dir,t.name)})})});r(c.join(t,`config-registry.ts`))&&await o(c.join(t,`config-registry.ts`),{force:!0,recursive:!0}),await s(c.join(t,`config-registry.ts`),n.text)}function pe(e,t){return{baseClassName:`${x(b(e))}_${x(b(t))}`,queryName:`${b(e)}${x(b(t))}`,mutationName:`create${b(e)}${x(b(t))}`}}const{factory:B}=S;function V(e){return B.createIdentifier(e)}function H(e){return V(e)}function U(e){return B.createStringLiteral(e)}function W(e,t){return B.createPropertyAssignment(V(e),t)}function G(e,t=!0){return B.createObjectLiteralExpression(e,t)}function me(e){return e?B.createTrue():B.createFalse()}function he(e){return B.createParameterDeclaration(void 0,void 0,V(e))}function K(e,t,n){return B.createArrowFunction(n?.async?[B.createToken(S.SyntaxKind.AsyncKeyword)]:void 0,void 0,e.map(e=>typeof e==`string`?he(e):e),void 0,B.createToken(S.SyntaxKind.EqualsGreaterThanToken),t)}function ge(e){return B.createParenthesizedExpression(e)}function _e(e,t=!0){return K([`t`],ge(G(e,t)))}function q(e,t){return B.createPropertyAccessExpression(typeof e==`string`?V(e):e,V(t))}function ve(e,t=[],n){return B.createCallExpression(e,n,t)}function J(e,t,n=[],r){return ve(q(e,t),n,r)}function ye(e,t=[],n){return J(`builder`,e,t,n)}function be(e,t){return B.createVariableStatement(void 0,B.createVariableDeclarationList([B.createVariableDeclaration(V(e),void 0,void 0,t)],S.NodeFlags.Const))}function Y(e,t,n){return B.createImportDeclaration(void 0,B.createImportClause(n?.typeOnly??!1,void 0,B.createNamedImports(t.map(e=>B.createImportSpecifier(!1,void 0,V(e))))),U(e))}function xe(e,t,n){return B.createImportDeclaration(void 0,B.createImportClause(n?.typeOnly??!1,V(t),void 0),U(e))}function Se({models:e,mutationName:t,mutationConfig:n,hasValidations:r,fieldDefinitions:i}){if(!n)return[];let a=Object.values(e).find(e=>e.root);if(!a)return[];let o=Ce(i),s=Object.values(e).filter(e=>!e.root);return[...we(r),...s.map(t=>Te(t,e,o)),Te(a,e,o),ke(t,a,r)]}function Ce(e){let t=new Map;if(!e)return t;for(let n of e){let e=n.options?.required===!0;t.set(n.name,e)}return t}function we(e){let t=[Y(`@lakeql/adapters`,[`executeWritePipeline`]),Y(`@lakeql/trino-client`,[`TrinoClient`]),Y(`@lakeql/api/builder`,[`builder`]),Y(`~/env`,[`env`]),Y(`./config`,[`hiveConfig`,`storageConfig`]),xe(`./json-schema.json`,`jsonSchema`)];return e&&t.push(Y(`./validations`,[`validationSchema`])),t}function Te(e,t,n){let r=`${e.modelName}Input`,i=Object.values(e.fields).map(e=>Ee(e,t,n));return be(r,ye(`inputType`,[U(r),G([W(`fields`,_e(i))])]))}function Ee(e,t,n){let r=W(`required`,me(n.get(e.name)??!0));if(e.isArray){let t=e.graphqlType.replace(/^\[/u,``).replace(/\]$/u,``),n=Oe(t);if(n)return W(e.name,J(`t`,n,[G([r],!1)]));let i=`${t}Input`;return W(e.name,J(`t`,`field`,[G([W(`type`,S.factory.createArrayLiteralExpression([H(i)])),r],!1)]))}let i=De(e.graphqlType);if(i)return W(e.name,J(`t`,i,[G([r],!1)]));if(Object.keys(t).includes(e.graphqlType)){let t=`${e.graphqlType}Input`;return W(e.name,J(`t`,`field`,[G([W(`type`,H(t)),r],!1)]))}return W(e.name,J(`t`,`string`,[G([r],!1)]))}function De(e){switch(e){case`String`:return`string`;case`Int`:return`int`;case`Float`:return`float`;case`Boolean`:return`boolean`;default:return}}function Oe(e){switch(e){case`String`:return`stringList`;case`Int`:return`intList`;case`Float`:return`floatList`;case`Boolean`:return`booleanList`;default:return}}function ke(e,t,n){let r=`${t.modelName}Input`,i=[];n&&i.push(S.factory.createExpressionStatement(J(`validationSchema`,`parse`,[H(`input`)]))),i.push(S.factory.createVariableStatement(void 0,S.factory.createVariableDeclarationList([S.factory.createVariableDeclaration(H(`trinoClient`),void 0,void 0,S.factory.createNewExpression(H(`TrinoClient`),void 0,[G([W(`host`,q(`env`,`HIVE_HOST`)),W(`port`,q(`env`,`HIVE_PORT`)),W(`auth`,G([W(`type`,U(`basic`)),W(`username`,q(`env`,`HIVE_USERNAME`)),W(`password`,q(`env`,`HIVE_PASSWORD`))],!1)),W(`catalog`,q(`env`,`HIVE_CATALOG`)),W(`source`,q(`env`,`HIVE_SOURCE`))])]))],S.NodeFlags.Const)));let a=S.factory.createAwaitExpression(ve(H(`executeWritePipeline`),[G([W(`records`,H(`input`)),W(`jsonSchema`,S.factory.createAsExpression(H(`jsonSchema`),S.factory.createKeywordTypeNode(S.SyntaxKind.AnyKeyword))),W(`config`,G([W(`loadStrategy`,q(`storageConfig`,`loadStrategy`)),W(`bucket`,q(`storageConfig`,`bucket`)),W(`basePath`,q(`storageConfig`,`basePath`)),W(`table`,G([W(`catalog`,q(`hiveConfig`,`catalog`)),W(`schema`,q(`hiveConfig`,`schema`)),W(`tableName`,q(`hiveConfig`,`tableName`))],!1)),W(`trinoClient`,H(`trinoClient`))]))])]));i.push(S.factory.createExpressionStatement(a)),i.push(S.factory.createReturnStatement(S.factory.createTrue()));let o=S.factory.createBlock(i,!0),s=K([he(`_root`),S.factory.createParameterDeclaration(void 0,void 0,S.factory.createObjectBindingPattern([S.factory.createBindingElement(void 0,void 0,S.factory.createIdentifier(`input`))]))],o,{async:!0}),c=W(e,J(`t`,`boolean`,[G([W(`args`,G([W(`input`,J(`t`,`arg`,[G([W(`type`,H(r)),W(`required`,me(!0))],!1)]))],!1)),W(`resolve`,s)])]));return S.factory.createExpressionStatement(ye(`mutationFields`,[_e([c])]))}function X(e){if(typeof e!=`object`||!e)return e;if(Array.isArray(e))return e.map(X);let t={},n=Object.keys(e).toSorted();for(let r of n)t[r]=X(e[r]);return t}function Ae(e){let t=X(e);return`${JSON.stringify(t,null,2).replaceAll(`\r
|
|
4
4
|
`,`
|
|
5
|
-
`)}\n`}async function je(e){let{definition:t,outputDir:n,skipRegistry:
|
|
6
|
-
`);console.error(`Error: Validation failed for ${s}:\n${e}`),process.exit(1)}let p=f.data,m=
|
|
5
|
+
`)}\n`}async function je(e){let{definition:t,outputDir:n,skipRegistry:a,sourcePathOverride:l}=e,{catalog:u,schema:d,tableName:f,fields:p}=t,{baseClassName:m,queryName:v,mutationName:y}=pe(d,f),b=ne(p),x=te({isRoot:!0,models:{},name:m,source:b}),S=Object.values(x).find(e=>e.root===!0),C=S?.fields?Object.values(S.fields).filter(e=>e.filter===!0).map(e=>({name:e.name,type:e.graphqlType})):[],re=[...new Set(C.map(e=>e.type))],w=[...new Set(Object.values(x).filter(e=>e.transformFields.length>0).flatMap(e=>e.transformFields))],T=[...new Set(Object.values(x).filter(e=>e.dateTimeFields.length>0).flatMap(e=>e.dateTimeFields))],E=await h({fileName:`config.ts`,nodes:g({catalog:u,queryName:v,schema:d,tableName:f,mutationName:[y],storageConfig:t.mutation?{loadStrategy:t.mutation.loadStrategy,type:t.mutation.type,bucket:t.mutation.bucket,basePath:t.mutation.basePath,region:t.mutation.region,endpoint:t.mutation.endpoint}:void 0})}),D=await h({fileName:`interface.ts`,nodes:_(x)}),O=await h({fileName:`query-schema.ts`,nodes:ee({dateTimeFields:T,filterFields:C,filterTypes:re,models:x,queryName:v,transformFields:w})}),ie=p.some(e=>e.options?.validations&&e.options.validations.length>0),k=Se({models:x,mutationName:y,mutationConfig:t.mutation,hasValidations:ie,fieldDefinitions:p}),A=``;k.length>0&&(A=(await h({fileName:`mutation-schema.ts`,nodes:k})).text);let ae=Ae(b),oe=Ae(t),j=[{fileName:`config.ts`,content:E.text},{fileName:`interface.ts`,content:D.text},{fileName:`query-schema.ts`,content:O.text},{fileName:`json-schema.json`,content:ae},{fileName:`endpoint.json`,content:oe}];A&&j.push({fileName:`mutation-schema.ts`,content:A}),r(n)&&await o(n,{force:!0,recursive:!0}),await i(n,{recursive:!0});for(let e of j)await s(c.join(n,e.fileName),e.content);return a||await z(l),{files:j,outputDir:n}}function Me(){return new e(`create-endpoint`).description(`Create a custom endpoint from a JSON definition file`).addOption(new t(`--from-file <path>`,`Path to a JSON definition file conforming to the Endpoint_Definition_Format`).makeOptionMandatory(!0)).addOption(R).addOption(de).addOption(new t(`--force`,`Overwrite existing files without prompting`).default(!1)).action(async e=>{let{fromFile:t,sourcePath:n,skipRegistry:i,force:o}=e,s=c.isAbsolute(t)?t:c.resolve(process.cwd(),t);r(s)||(console.error(`Error: File not found: ${s}`),process.exit(1));let u;try{u=await a(s,`utf-8`)}catch(e){let t=e instanceof Error?e.message:String(e);console.error(`Error: Cannot read file: ${s}: ${t}`),process.exit(1)}let d;try{d=JSON.parse(u)}catch(e){let t=e instanceof Error?e.message:String(e);console.error(`Error: Invalid JSON in ${s}: ${t}`),process.exit(1)}let f=C.safeParse(d);if(!f.success){let e=f.error.issues.map(e=>` - ${e.path.length>0?e.path.join(`.`):`root`}: ${e.message}`).join(`
|
|
6
|
+
`);console.error(`Error: Validation failed for ${s}:\n${e}`),process.exit(1)}let p=f.data,m=re(p.fields);if(m.length>0){let e=m.map(e=>{let t=e.path.length>0?e.path.join(`.`):`root`;return` - Duplicate field "${e.name}" at level: ${t}`}).join(`
|
|
7
7
|
`);console.error(`Error: Validation failed for ${s}:\n${e}`),process.exit(1)}console.log(`
|
|
8
8
|
Loaded definition summary:`),console.log(` tableName: ${p.tableName}`),console.log(` catalog: ${p.catalog}`),console.log(` schema: ${p.schema}`);let h=p.mutation?p.mutation.loadStrategy:`disabled`;console.log(` mutation: ${h}`),console.log(`
|
|
9
|
-
Fields:`),console.log(
|
|
9
|
+
Fields:`),console.log(N(p.fields)),console.log(``);let g=await F(n===process.cwd()?void 0:n),_=c.join(g,`schemas/custom`,p.catalog,p.schema,p.tableName);r(_)&&!o&&(await l(`Directory "${_}" already exists. Overwrite?`)||(console.log(`Aborted.`),process.exit(0))),await je({definition:p,outputDir:_,skipRegistry:i,sourcePathOverride:n===process.cwd()?void 0:n}),console.log(`Endpoint generated successfully at: ${_}`)})}let Ne;function Pe(){return D.config({path:`../../.env`}),E({runtimeEnv:process.env,server:{HIVE_CATALOG:k().min(1),HIVE_HOST:k(),HIVE_PASSWORD:k().min(1),HIVE_PORT:k().transform(e=>Number.parseInt(e,10)).pipe(ie()),HIVE_SOURCE:k().optional(),HIVE_USERNAME:k().min(1),LOG_LEVEL:O([`info`,`warn`,`error`,`debug`]).default(`warn`)}})}function Z(){return Ne||=Pe(),Ne}function Fe(){let t=new e(`list-columns`);return t.description(`Lists the columns for the specified table`).addOption(I).addOption(L.makeOptionMandatory()).addOption(le.makeOptionMandatory()).action(async({catalog:e,schema:t,table:n})=>{let r=Z(),i=e??r.HIVE_CATALOG,a=new w({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=await a.schemas({catalog:i});o=await f(`Choose a schema from the ${i} catalog`,{autocomplete:!0,choices:e})}let s=n;if(s===void 0){let e=await a.tables({catalog:i,schema:o});s=await f(`Choose a table from "${i}.${o}"`,{autocomplete:!0,choices:e})}let c=(await a.columns({catalog:i,schema:o,table:s})).map(([e,t,n,r])=>({description:r,extra:n,name:e,type:t})),l=new T;l.column(`Column Name`,`name`),l.column(`Type`,`type`),l.column(`Extra`,`extra`),l.column(`Description`,`description`),l.render(c)}),t}function Ie(){let t=new e(`list-schemas`);return t.description(`Lists the available schemas for the configured catalog`).addOption(I).action(async({catalog:e})=>{let t=Z(),n=e??t.HIVE_CATALOG,r=await new w({auth:{password:t.HIVE_PASSWORD,type:`basic`,username:t.HIVE_USERNAME},catalog:n,host:t.HIVE_HOST,port:t.HIVE_PORT}).schemas({catalog:n}),i=new T;i.column(`Schema Name`,`s`),i.render(r.map(e=>({s:e})))}),t}function Le(){let t=new e(`list-tables`);return t.description(`Lists the available tables for the configured catalog/schema`).addOption(I).addOption(L).action(async({catalog:e,schema:t})=>{let n=Z(),r=e??n.HIVE_CATALOG,i=new w({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=await i.schemas({catalog:r});a=await f(`Choose a schema from the ${r} catalog`,{autocomplete:!0,choices:e})}let o=await i.tables({catalog:r,schema:a}),s=new T;s.column(`Table Name`,`t`),s.render(o.map(e=>({t:e})))}),t}function Re(){let t=new e(`list-views`);return t.description(`Lists the available views for the configured catalog/schema`).addOption(I).addOption(L).action(async({catalog:e,schema:t})=>{let n=Z(),r=e??n.HIVE_CATALOG,i=new w({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=await i.schemas({catalog:r});a=await f(`Choose a schema from the ${r} catalog`,{choices:e})}let o=await i.views({catalog:r,schema:a}),s=new T;s.column(`View Name`,`v`),s.render(o.map(e=>({v:e})))}),t}function ze(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 Be(e,t){return typeof t==`string`?{name:e,type:ze(t)}:Array.isArray(t)?{name:e,type:`Array`,items:Ve(t)}:typeof t==`object`&&t?{name:e,type:`Object`,fields:Q(t)}:{name:e,type:`String`}}function Ve(e){if(e.length===0)return{type:`String`};let[t]=e;return typeof t==`string`?{type:ze(t)}:typeof t==`object`&&t&&!Array.isArray(t)?{type:`Object`,fields:Q(t)}:{type:`String`}}function Q(e){let t=[];for(let[n,r]of Object.entries(e))t.push(Be(n,r));return t}function He(e){let{tableName:t,catalog:n,schema:r,parsedColumns:i}=e;return{version:`1.0`,tableName:t,catalog:n,schema:r,fields:Q(i),mutation:!1}}async function $(e){let{trinoClient:t,catalog:n,schema:r,tables:i,resolvedTargetPath:a,skipRegistry:o,sourcePathOverride:s}=e;for(let e of i)await je({definition:He({tableName:e,catalog:n,schema:r,parsedColumns:oe((await t.columns({catalog:n,schema:r,table:e})).map(e=>j({keys:[`name`,`type`,`extra`,`description`],values:e})))}),outputDir:c.join(a,`schemas/generated`,n,r,e),skipRegistry:o,sourcePathOverride:s})}async function Ue(e){let t=P(),n;if(e){let r=c.isAbsolute(e)?e:c.resolve(t,e),i=c.parse(r);n=c.join(i.dir,i.name)}let{config:r}=await m({name:`import`,cwd:t,configFile:n,defaults:{default:[]},packageJson:!1,globalRc:!1,rcFile:!1,dotenv:!1}),i=r;return Array.isArray(i)?i:i&&typeof i==`object`&&`default`in i&&Array.isArray(i.default)?i.default:[]}async function We(e){let{configPath:t,catalog:n,sourcePathOverride:r,skipRegistry:i}=e,a=Z(),o=await F(r),s=await Ue(t);if(s.length===0){console.log(`No entries found in bulk config.`);return}await new ae([{title:`Pull data`,task:(e,t)=>t.newListr(s.map(e=>{let t=n??e.catalog??a.HIVE_CATALOG,i=(e.tables?.length??0)+(e.views?.length??0);return{title:`${t}/${e.schema} — ${i} item(s)`,task:async(n,s)=>{let c=new w({auth:{password:a.HIVE_PASSWORD,type:`basic`,username:a.HIVE_USERNAME},catalog:t,host:a.HIVE_HOST,port:a.HIVE_PORT});e.tables&&e.tables.length>0&&(s.output=`Pulling ${e.tables.length} table(s)...`,await $({trinoClient:c,catalog:t,schema:e.schema,tables:e.tables,resolvedTargetPath:o,skipRegistry:!0,sourcePathOverride:r})),e.views&&e.views.length>0&&(s.output=`Pulling ${e.views.length} view(s)...`,await $({trinoClient:c,catalog:t,schema:e.schema,tables:e.views,resolvedTargetPath:o,skipRegistry:!0,sourcePathOverride:r})),s.title=`${t}/${e.schema} — ${i} item(s) pulled`}}}),{concurrent:!0,exitOnError:!1})},{title:`Create registry`,enabled:!i,task:async()=>{await z(r)}}],{concurrent:!1,exitOnError:!0}).run()}const Ge=new t(`--bulk`,`Run in bulk mode using a config file`).default(!1),Ke=new t(`--bulk-config <path>`,`Path to the bulk import config file (default: import.config.{mjs,ts,js,json})`);function qe(){let t=new e(`pull`),n=t.description(`Interactive query endpoint generation based on a remote table`).addOption(I).addOption(ue).addOption(L.makeOptionMandatory(!1)).addOption(le.makeOptionMandatory(!1).default([]).argParser((e,t)=>[...t,e])).addOption(de).addOption(R).addOption(Ge).addOption(Ke);return n.action(async e=>{let{skipRegistry:n,sourcePath:r,bulk:i,bulkConfig:a}=e,o=r===(process.env.INIT_CWD??process.cwd())?void 0:r;if(i){await We({configPath:a,catalog:e.catalog,sourcePathOverride:o,skipRegistry:n});return}let s=Z(),c=e.catalog??s.HIVE_CATALOG,{schema:l,table:d,type:m}=e,h=await F(o),g=new w({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 g.schemas({catalog:c});l=await f(`Choose a schema from the ${c} catalog`,{autocomplete:!0,choices:e})}if(d.length===0&&(m??=await f(`What do you want to see from ${c}/${l}`,{choices:[{label:`Show tables`,value:`tables`},{label:`Show views`,value:`views`}]})),d.length===0){m??=`tables`;let e=[];e=m===`views`?await g.views({catalog:c,schema:l}):await g.tables({catalog:c,schema:l}),e.length===0&&t.error(A(`There are no ${m} in schema '${c}.${l}'.`),{exitCode:0}),d=await u(`Choose the ${m} to pull`,{autocomplete:!0,choices:e,validators:[p.required()]})}await $({trinoClient:g,catalog:c,schema:l,tables:[...d],resolvedTargetPath:h,skipRegistry:n,sourcePathOverride:o})}),n}const Je=[`lakeql.config.mjs`,`lakeql.config.ts`,`lakeql.config.json`];function Ye(e){return`/** @type {import('@lakeql/cli').LakeQLConfig} */\nexport default {\n${Object.entries(e).map(([e,t])=>` ${e}: ${JSON.stringify(t)},`).join(`
|
|
10
|
+
`)}\n}\n`}function Xe(e){for(let t of Je)if(r(c.join(e,t)))return t;return null}function Ze(){return new e(`init`).description(`Initialize a lakeql config file`).action(async()=>{let e=P(),t=Xe(e);if(t&&await f(`${t} already exists. Overwrite?`,{choices:[{label:`Yes`,value:`yes`},{label:`No`,value:`no`}]})===`no`){console.log(M.yellow(`Aborted.`));return}let n=await f(`Config format:`,{choices:[{label:`lakeql.config.mjs (recommended)`,value:`mjs`},{label:`lakeql.config.json`,value:`json`}]}),i=r(c.join(e,`src`)),a;if(i)a=`src`,console.log(M.cyan(`Detected src/ directory — generated code will be placed in src/`));else{let e=await f(`Where should generated code be placed?`,{choices:[{label:`./ (project root)`,value:`.`},{label:`Custom path`,value:`__custom__`}]});a=e,e===`__custom__`&&(a=await d(`Enter the source path (relative to project root):`,{defaultValue:`.`}))}let o={sourcePath:a},l=n===`mjs`?`lakeql.config.mjs`:`lakeql.config.json`,u=c.join(e,l);await s(u,n===`mjs`?Ye(o):`${JSON.stringify(o,null,2)}\n`),console.log(M.green(`Created ${l} at ${u}`))})}async function Qe(){let t=await n(),r=new e;r.configureHelp({sortSubcommands:!0}),r.name(`lakeql-cli`).description(`LakeQL CLI`).version(t.version).addCommand(Ie()).addCommand(Le()).addCommand(Re()).addCommand(Fe()).addCommand(qe()).addCommand(Me()).addCommand(fe()).addCommand(Ze()),await r.parseAsync()}Qe().catch(()=>{process.exit(1)});export{};
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
//#region src/bulk-pull-config.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Configuration for a single pull entry in a bulk import.
|
|
4
|
+
*/
|
|
5
|
+
interface BulkPullEntry {
|
|
6
|
+
/** The schema to pull from. */
|
|
7
|
+
schema: string;
|
|
8
|
+
/** Optional catalog override. Falls back to CLI --catalog or ENV. */
|
|
9
|
+
catalog?: string;
|
|
10
|
+
/** List of tables to pull. */
|
|
11
|
+
tables?: string[];
|
|
12
|
+
/** List of views to pull. */
|
|
13
|
+
views?: string[];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Bulk pull configuration — a simple array of pull entries.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```js
|
|
20
|
+
* // import.config.mjs
|
|
21
|
+
* /** @type {import('@lakeql/cli').BulkPullConfig} *\/
|
|
22
|
+
* export default [
|
|
23
|
+
* { schema: "schema1", tables: ["table1", "table2"] },
|
|
24
|
+
* { schema: "schema2", catalog: "other", views: ["view1"] },
|
|
25
|
+
* ]
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
type BulkPullConfig = BulkPullEntry[];
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/config.d.ts
|
|
31
|
+
interface LakeQLConfig {
|
|
32
|
+
/**
|
|
33
|
+
* Base path for code generation (schemas, config-registry, etc.).
|
|
34
|
+
* Relative paths are resolved from the project root (where the config file lives).
|
|
35
|
+
* @default "."
|
|
36
|
+
*/
|
|
37
|
+
sourcePath: string;
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
export type { BulkPullConfig, BulkPullEntry, LakeQLConfig };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lakeql/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "CLI for introspecting Trino schemas and generating type-safe GraphQL endpoints",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -38,6 +38,10 @@
|
|
|
38
38
|
"sideEffects": false,
|
|
39
39
|
"exports": {
|
|
40
40
|
".": {
|
|
41
|
+
"import": "./dist/index.mjs",
|
|
42
|
+
"types": "./dist/index.d.mts"
|
|
43
|
+
},
|
|
44
|
+
"./cli": {
|
|
41
45
|
"import": "./dist/cli.mjs"
|
|
42
46
|
}
|
|
43
47
|
},
|
|
@@ -45,22 +49,23 @@
|
|
|
45
49
|
"@commander-js/extra-typings": "15.0.0",
|
|
46
50
|
"@t3-oss/env-core": "0.13.11",
|
|
47
51
|
"@topcli/prompts": "3.1.0",
|
|
52
|
+
"c12": "4.0.0-beta.5",
|
|
48
53
|
"climt": "0.2.0",
|
|
49
54
|
"commander": "15.0.0",
|
|
50
55
|
"dotenv": "17.4.2",
|
|
51
56
|
"globby": "16.2.0",
|
|
52
57
|
"handlebars": "4.7.9",
|
|
53
58
|
"kleur": "4.1.5",
|
|
59
|
+
"listr2": "10.2.1",
|
|
54
60
|
"lodash-es": "4.18.1",
|
|
55
|
-
"ora": "9.4.0",
|
|
56
61
|
"read-pkg": "10.1.0",
|
|
57
62
|
"zod": "4.4.3",
|
|
58
63
|
"@lakeql/column-parser": "0.1.2",
|
|
59
|
-
"@lakeql/
|
|
64
|
+
"@lakeql/helpers": "0.1.2",
|
|
60
65
|
"@lakeql/logger": "0.1.2",
|
|
61
66
|
"@lakeql/response-transformer": "0.1.2",
|
|
62
|
-
"@lakeql/helpers": "0.1.2",
|
|
63
67
|
"@lakeql/schema-generator": "0.3.0",
|
|
68
|
+
"@lakeql/file-generator": "0.1.5",
|
|
64
69
|
"@lakeql/trino-client": "0.3.0"
|
|
65
70
|
},
|
|
66
71
|
"devDependencies": {
|