@egi/smart-db 2.5.3 → 2.5.4

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.
@@ -1 +1 @@
1
- import fs from"fs";import _ from"lodash";import process from"process";import{SmartDbBetterSqlite3}from"../drivers/smart-db-better-sqlite3";import{SmartDbOracle}from"../drivers/smart-db-oracle";import{OracleCatModel}from"../models/oracle-cat-model";import{SmartDbCoreTableModel}from"../models/smart-db-core-table-model";import{SqliteMasterModel}from"../models/sqlite-master-model";import{IN,NE,NOT_LIKE}from"../smart-db-globals";function getType(e){let t;return t=e?e.match(/varchar/i)||e.match(/text/i)?"string":e.match(/integer\(1\)/i)?"boolean":e.match(/date/i)?"Date":e.match(/integer/i)||e.match(/number/i)?"number":e.match(/long/i)||e.match(/raw/i)?"any":"SqlValueType":"SqlValueType",t}function getRelations(e){return new Promise((async(t,r)=>{e instanceof SmartDbOracle?e.getAll(OracleCatModel,{type:IN(["TABLE","VIEW"]),name:NOT_LIKE("BIN$%")}).then((a=>{a?t(a.map((e=>e.name.toLowerCase()))):r(e.getLastError())})).catch((e=>{r(e)})):e instanceof SmartDbBetterSqlite3?e.getAll(SqliteMasterModel,{type:IN(["table","view"]),name:NE("sqlite_sequence")}).then((a=>{a?t(a.map((e=>e.name))):r(e.getLastError())})).catch((e=>{r(e)})):r("unimplemented database type")}))}async function extractDbApi(e){console.log(`extract interface from '${e.db.getDbConnector()}' to '${e.modelDirectory}'`);const t=["break","case","catch","class","const","continue","debugger","default","delete","do","else","enum","export","extends","false","finally","for","function","If","import","in","instanceOf","new","null","return","super","switch","this","throw","true","try","typeOf","var","void","while","with"];fs.existsSync(e.modelDirectory)||fs.mkdirSync(e.modelDirectory,{recursive:!0}),getRelations(e.db).then((async r=>{let a=[];if((e.skipCoreTables||e.justCoreTables)&&await e.db.exists(SmartDbCoreTableModel)){const t=await e.db.getAll(SmartDbCoreTableModel);if(!1===t)throw e.db.getLastError();t.forEach((e=>{a.push(e.name)}))}const n=[];for(const s of r){let r=!0;if(e.justCoreTables?r=a.includes(s):e.skipCoreTables&&(r=!a.includes(s)),r){const r=s[0].toUpperCase()+_.camelCase(s.substring(1))+"Model",a=[];console.log("working on",s),await e.db.getTableInfo(s).then((o=>{const i=o.fields;let l=!1,c="",m="",p="",d="",b="";const u=s.toLowerCase().replace(/[^[a-z0-9]/g,"-")+"-model";if(n.push({className:r,fileName:u}),c+="/* eslint-disable @typescript-eslint/member-ordering */\n",c+="// noinspection JSUnusedGlobalSymbols\n",i){e.abstractModelModule==e.smartDbInterfaces?e.separateApi?(p+=`import {GenericModelData} from "${e.abstractModelModule}";\n`,b+=`import {AbstractModel, ModelAttributeMap} from "${e.abstractModelModule}";\n`,b+=`import {${r}Data} from "./${u}-api";\n`):b+=`import {AbstractModel, GenericModelData, ModelAttributeMap} from "${e.abstractModelModule}";\n`:e.separateApi?(p+=`import {GenericModelData} from "${e.smartDbInterfaces}";\n`,b+=`import {ModelAttributeMap} from "${e.smartDbInterfaces}";\n`,b+=`import {AbstractModel} from "${e.abstractModelModule}";\n`,b+=`import {${r}Data} from "./${u}-api";\n`):(b+=`import {GenericModelData, ModelAttributeMap} from "${e.smartDbInterfaces}";\n`,b+=`import {AbstractModel} from "${e.abstractModelModule}";\n`),m+=`export interface ${r}Data extends GenericModelData {\n`;let n,o="",f="",h=!1;const g=[];i.forEach((e=>{const t=e.name.match(/([a-z0-9]{1,4})_/i);e.isPk&&(o=e.name,t&&(f=t[1])),t?g.includes(t[1])||g.push(t[1]):h=!0})),f||h||1!=g.length||(f=g[0]),f&&(n=new RegExp(`^${f}_(.*)$`));const y={};i.forEach((t=>{const r=getType(t.type);let o;l||"SqlValueType"!=r||(p+=`import {SqlValueType} from "${e.smartDbInterfaces}";\n`,b+=`import {SqlValueType} from "${e.smartDbInterfaces}";\n`,l=!0);const i=n&&t.name.match(n);o=i?_.camelCase(i[1]):_.camelCase(t.name);let c=!0;if(o!=t.name&&(a.push({name:o,attribute:o,type:r,typeScriptStyle:c,alias:t.name}),c=!1),o!=t.name.toLowerCase()&&(a.push({name:t.name.toLowerCase(),attribute:o,type:r,physical:void 0!==t.cid&&t.name==t.name.toLowerCase(),typeScriptStyle:c}),c=!1),o!=t.name.toUpperCase()&&a.push({name:t.name.toUpperCase(),attribute:o,type:r,physical:void 0!==t.cid&&t.name==t.name.toUpperCase(),typeScriptStyle:c}),t.cid){const e=a.find((e=>e.physical&&e.name.toLowerCase()==t.name.toLowerCase()));e||a.push({name:t.name,attribute:o,type:r,physical:!0,typeScriptStyle:c})}y[o]=r,"user"==s&&"name"==o&&(m+=" // @ts-ignore"),m+=` ${o}?: ${r};\n`})),m+="}\n",d+=`export class ${r} extends AbstractModel<${r}, ${r}Data> {\n`,_.forEach(y,((e,t)=>{d+=` private _${t}?: ${e};\n`})),"user"==s&&(d+=" private _hash?: string;\n",d+=" private _privileges?: string[];\n"),d+="\n",d+=" static readonly attributeMap: ModelAttributeMap = {\n",a.forEach(((e,t)=>{t>0&&(d+=",\n"),d+=` ${e.name}: {\n`,e.physical&&(d+=" physical: true,\n"),e.alias&&(d+=` alias: "${e.alias}",\n`),e.virtual&&(d+=" virtual: true,\n"),e.typeScriptStyle&&(d+=" typeScriptStyle: true,\n"),d+=` type: "${e.type}",\n`,d+=` attribute: "_${e.attribute}"\n`,d+=" }"})),d+="\n",d+=" };\n",d+="\n",d+=" static getClassName(): string {\n",d+=` return "${r}";\n`,d+=" }\n",d+="\n",d+=" static getTableName(): string {\n",d+=` return "${s}";\n`,d+=" }\n",d+="\n",d+=" static getPrimaryKey(): string {\n",d+=` return "${o}";\n`,d+=" }\n",d+="\n",d+=` static from(other: ${r} | ${r}Data): ${r} {\n`,d+=` let value: ${r} = null;\n`,d+=" if (other) {\n",d+=` value = new ${r}();\n`,d+=` if (other instanceof ${r}) {\n`,d+=" Object.assign(value, other);\n",d+=" } else {\n",d+=" value.assign(other);\n",d+=" }\n",d+=" }\n",d+=" return value;\n",d+=" }\n",d+="\n",d+=` constructor(data?: ${r} | ${r}Data) {\n`,d+=" super();\n",d+=" if (data) {\n",d+=" this.assign(data);\n",d+=" }\n",d+=" }\n",d+="\n",d+=` public clone(): ${r} {\n`,d+=` return ${r}.from(this);\n`,d+=" }\n",d+="\n",d+=" public getClassName(): string {\n",d+=` return "${r}";\n`,d+=" }\n",d+="\n",d+=" public getTableName(): string {\n",d+=` return "${s}";\n`,d+=" }\n",d+="\n",d+=" public getPrimaryKey(): string {\n",d+=` return "${o}";\n`,d+=" }\n",d+="\n",d+=" public getAttributeMap(): ModelAttributeMap {\n",d+=` return ${r}.attributeMap;\n`,d+=" }\n",a.forEach((e=>{let r;d+="\n",r=e.name.length<3||e.name.match(/_/)?"FunctionNamingConventionJS":"",""!==r&&(d+=` // noinspection ${r}\n`),d+=` get ${e.name}(): ${e.type} {\n`,d+=` return this._${e.attribute};\n`,d+=" }\n\n",""!==r&&(d+=` // noinspection ${r}\n`);let a=e.attribute;t.includes(a)&&(a="value"),d+=` set ${e.name}(${a}: ${e.type}) {\n`,d+=` this._${a} = ${a};\n`,d+=" }\n"})),"user"==s&&(d+="\n",d+=" get hash(): string {\n",d+=" return this._hash;\n",d+=" }\n\n",d+=" set hash(hash: string) {\n",d+=" this._hash = hash;\n",d+=" }\n",d+="\n",d+=" get privileges(): string[] {\n",d+=" return this._privileges;\n",d+=" }\n\n",d+=" set privileges(p: string[]) {\n",d+=" this._privileges = p;\n",d+=" }\n"),d+="}\n",e.separateApi?(m=c+"\n"+p+"\n"+m,fs.writeFileSync(`${e.modelDirectory}/${u+"-api.ts"}`,m),d=c+"\n"+b+"\n"+d):d=c+"\n"+b+"\n"+m+"\n"+d,fs.writeFileSync(`${e.modelDirectory}/${u+".ts"}`,d)}else console.log("error: table has no fields")})).catch((e=>{console.error(e),process.abort()}))}}let s=`import {AbstractModel} from "${e.abstractModelModule}";\n`;_.forEach(n,(e=>{s+=`import {${e.className}} from "./${e.fileName}";\n`})),s+="\n",s+="interface SmartDbDictionaryEntry {\n",s+=" cls: "+n.map((e=>"typeof "+e.className)).join(" |\n "),s+=";\n",s+="}\n\n",s+="export class SmartDbDictionary {\n",s+=" static models: { [relation: string]: SmartDbDictionaryEntry; } = {\n",_.forEach(n,(e=>{s+=` ${e.className}: {\n`,s+=` cls: ${e.className}\n`,s+=" },\n"})),s=s.substring(0,s.length-2)+"\n",s+=" };\n",s+="}\n",fs.writeFileSync(`${e.modelDirectory}/smart-db-dictionary.ts`,s)})).catch((e=>{console.error("extraction error",e)}))}(async()=>{let e=!1;const t=Array.from(process.argv);let r,a,n,s=!1;for(t.shift(),t.shift();t[0]&&"--"==t[0].substring(0,2);)"--separate-api"==t[0]?(e=!0,t.shift()):"--connector"==t[0]?(r=t[1],t.shift(),t.shift()):"--username"==t[0]?(a=t[1],t.shift(),t.shift()):"--password"==t[0]?(r=t[1],t.shift(),t.shift()):"--create"==t[0]?(s=!0,t.shift()):(console.error(`unknown option '${t[2]}'`),process.exit(-1));if(r||(r=process.env.ORACLE_SID),a||(a=process.env.ORA_USER),n||(n=process.env.ORA_PASS),r&&t.length<=1){let o;a&&n?o=new SmartDbOracle(r,{user:a,password:n,noDbLogging:!0}):s||fs.existsSync(r)?o=new SmartDbBetterSqlite3(r,{verbose:(e,...t)=>{console.log("DB LOG",e,...t)}}):(console.error(`ERROR: missing sqlite3 database file ${r}`),process.exit(-1)),1==t.length?o.onReady().subscribe((async r=>{if(r){o.getLogger().setDbLogging(!1);const r={skipCoreTables:!0,modelDirectory:t[0],smartDbInterfaces:"@egi/smart-db",abstractModelModule:"@egi/smart-db",separateApi:e,db:o};await extractDbApi(r)}})):fs.existsSync("src/helpers/extract-db-api.ts")?o.onReady().subscribe((t=>{if(t){const t={justCoreTables:!0,modelDirectory:"src/models/generated",smartDbInterfaces:"../smart-db-interfaces",abstractModelModule:"./abstract-model",separateApi:e,db:o};t.db.initDb({module:"smart-db-core",sqlFilesDirectory:"assets/sqlite3"}).then((async()=>{await extractDbApi(t)}))}else console.error("unable to connect to database")})):console.log("command must be run at the root directory of the smart-db project")}else console.log("USAGE: extract-db-api --connector {db-connector|path-to-db} [{options}] {target-models-directory}\n"),console.log("Options are: [--username {username}]"),console.log(" [--password {password}]"),console.log(" [--create"),console.log(" [--separate-api]")})();
1
+ import fs from"fs";import _ from"lodash";import process from"process";import{SmartDbBetterSqlite3}from"../drivers/smart-db-better-sqlite3";import{SmartDbOracle}from"../drivers/smart-db-oracle";import{OracleCatModel}from"../models/oracle-cat-model";import{SmartDbCoreTableModel}from"../models/smart-db-core-table-model";import{SqliteMasterModel}from"../models/sqlite-master-model";import{IN,NE,NOT_LIKE}from"../smart-db-globals";function getType(e){let t;return t=e?e.match(/varchar/i)||e.match(/text/i)?"string":e.match(/integer\(1\)/i)?"boolean":e.match(/date/i)?"Date":e.match(/integer/i)||e.match(/number/i)?"number":e.match(/long/i)||e.match(/raw/i)?"any":"SqlValueType":"SqlValueType",t}function getRelations(e){return new Promise((async(t,r)=>{e instanceof SmartDbOracle?e.getAll(OracleCatModel,{type:IN(["TABLE","VIEW"]),name:NOT_LIKE("BIN$%")}).then((a=>{a?t(a.map((e=>e.name.toLowerCase()))):r(e.getLastError())})).catch((e=>{r(e)})):e instanceof SmartDbBetterSqlite3?e.getAll(SqliteMasterModel,{type:IN(["table","view"]),name:NE("sqlite_sequence")}).then((a=>{a?t(a.map((e=>e.name))):r(e.getLastError())})).catch((e=>{r(e)})):r("unimplemented database type")}))}async function extractDbApi(e){console.log(`extract interface from '${e.db.getDbConnector()}' to '${e.modelDirectory}'`);const t=["break","case","catch","class","const","continue","debugger","default","delete","do","else","enum","export","extends","false","finally","for","function","If","import","in","instanceOf","new","null","return","super","switch","this","throw","true","try","typeOf","var","void","while","with"];fs.existsSync(e.modelDirectory)||fs.mkdirSync(e.modelDirectory,{recursive:!0}),getRelations(e.db).then((async r=>{let a=[];if((e.skipCoreTables||e.justCoreTables)&&await e.db.exists(SmartDbCoreTableModel)){const t=await e.db.getAll(SmartDbCoreTableModel);if(!1===t)throw e.db.getLastError();t.forEach((e=>{a.push(e.name)}))}const n=[];for(const s of r){let r=!0;if(e.justCoreTables?r=a.includes(s):e.skipCoreTables&&(r=!a.includes(s)),r){const r=s[0].toUpperCase()+_.camelCase(s.substring(1))+"Model",a=[];console.log("working on",s),await e.db.getTableInfo(s).then((o=>{const i=o.fields;let l=!1,c="",m="",p="",d="",b="";const u=s.toLowerCase().replace(/[^[a-z0-9]/g,"-")+"-model";if(n.push({className:r,fileName:u}),c+="/* eslint-disable @typescript-eslint/member-ordering */\n",c+="// noinspection JSUnusedGlobalSymbols\n",i){e.abstractModelModule==e.smartDbInterfaces?e.separateApi?(p+=`import {GenericModelData} from "${e.abstractModelModule}";\n`,b+=`import {AbstractModel, ModelAttributeMap} from "${e.abstractModelModule}";\n`,b+=`import {${r}Data} from "./${u}-api";\n`):b+=`import {AbstractModel, GenericModelData, ModelAttributeMap} from "${e.abstractModelModule}";\n`:e.separateApi?(p+=`import {GenericModelData} from "${e.smartDbInterfaces}";\n`,b+=`import {ModelAttributeMap} from "${e.smartDbInterfaces}";\n`,b+=`import {AbstractModel} from "${e.abstractModelModule}";\n`,b+=`import {${r}Data} from "./${u}-api";\n`):(b+=`import {GenericModelData, ModelAttributeMap} from "${e.smartDbInterfaces}";\n`,b+=`import {AbstractModel} from "${e.abstractModelModule}";\n`),m+=`export interface ${r}Data extends GenericModelData {\n`;let n,o="",f="",h=!1;const g=[];i.forEach((e=>{const t=e.name.match(/([a-z0-9]{1,4})_/i);e.isPk&&(o=e.name,t&&(f=t[1])),t?g.includes(t[1])||g.push(t[1]):h=!0})),f||h||1!=g.length||(f=g[0]),f&&(n=new RegExp(`^${f}_(.*)$`));const y={};i.forEach((t=>{const r=getType(t.type);let o;l||"SqlValueType"!=r||(p+=`import {SqlValueType} from "${e.smartDbInterfaces}";\n`,b+=`import {SqlValueType} from "${e.smartDbInterfaces}";\n`,l=!0);const i=n&&t.name.match(n);o=i?_.camelCase(i[1]):_.camelCase(t.name);let c=!0;if(o!=t.name&&(a.push({name:o,attribute:o,type:r,typeScriptStyle:c,alias:t.name}),c=!1),o!=t.name.toLowerCase()&&(a.push({name:t.name.toLowerCase(),attribute:o,type:r,physical:void 0!==t.cid&&t.name==t.name.toLowerCase(),typeScriptStyle:c}),c=!1),o!=t.name.toUpperCase()&&a.push({name:t.name.toUpperCase(),attribute:o,type:r,physical:void 0!==t.cid&&t.name==t.name.toUpperCase(),typeScriptStyle:c}),t.cid){const e=a.find((e=>e.physical&&e.name.toLowerCase()==t.name.toLowerCase()));e||a.push({name:t.name,attribute:o,type:r,physical:!0,typeScriptStyle:c})}y[o]=r,"user"==s&&"name"==o&&(m+=" // @ts-ignore"),m+=` ${o}?: ${r};\n`})),m+="}\n",d+=`export class ${r} extends AbstractModel<${r}, ${r}Data> {\n`,_.forEach(y,((e,t)=>{d+=` private _${t}?: ${e};\n`})),"user"==s&&(d+=" private _hash?: string;\n",d+=" private _privileges?: string[];\n"),d+="\n",d+=" static readonly attributeMap: ModelAttributeMap = {\n",a.forEach(((e,t)=>{t>0&&(d+=",\n"),d+=` ${e.name}: {\n`,e.physical&&(d+=" physical: true,\n"),e.alias&&(d+=` alias: "${e.alias}",\n`),e.virtual&&(d+=" virtual: true,\n"),e.typeScriptStyle&&(d+=" typeScriptStyle: true,\n"),d+=` type: "${e.type}",\n`,d+=` attribute: "_${e.attribute}"\n`,d+=" }"})),d+="\n",d+=" };\n",d+="\n",d+=" static getClassName(): string {\n",d+=` return "${r}";\n`,d+=" }\n",d+="\n",d+=" static getTableName(): string {\n",d+=` return "${s}";\n`,d+=" }\n",d+="\n",d+=" static getPrimaryKey(): string {\n",d+=` return "${o}";\n`,d+=" }\n",d+="\n",d+=` static from(other: ${r} | ${r}Data): ${r} {\n`,d+=` let value: ${r} = null;\n`,d+=" if (other) {\n",d+=` value = new ${r}();\n`,d+=` if (other instanceof ${r}) {\n`,d+=" Object.assign(value, other);\n",d+=" } else {\n",d+=" value.assign(other);\n",d+=" }\n",d+=" }\n",d+=" return value;\n",d+=" }\n",d+="\n",d+=` constructor(data?: ${r} | ${r}Data) {\n`,d+=" super();\n",d+=" if (data) {\n",d+=" this.assign(data);\n",d+=" }\n",d+=" }\n",d+="\n",d+=` public clone(): ${r} {\n`,d+=` return ${r}.from(this);\n`,d+=" }\n",d+="\n",d+=" public getClassName(): string {\n",d+=` return "${r}";\n`,d+=" }\n",d+="\n",d+=" public getTableName(): string {\n",d+=` return "${s}";\n`,d+=" }\n",d+="\n",d+=" public getPrimaryKey(): string {\n",d+=` return "${o}";\n`,d+=" }\n",d+="\n",d+=" public getAttributeMap(): ModelAttributeMap {\n",d+=` return ${r}.attributeMap;\n`,d+=" }\n",a.forEach((e=>{let r;d+="\n",r=e.name.length<3||e.name.match(/_/)?"FunctionNamingConventionJS":"",""!==r&&(d+=` // noinspection ${r}\n`),d+=` get ${e.name}(): ${e.type} {\n`,d+=` return this._${e.attribute};\n`,d+=" }\n\n",""!==r&&(d+=` // noinspection ${r}\n`);let a=e.attribute;t.includes(a)&&(a="value"),d+=` set ${e.name}(${a}: ${e.type}) {\n`,d+=` this._${e.attribute} = ${a};\n`,d+=" }\n"})),"user"==s&&(d+="\n",d+=" get hash(): string {\n",d+=" return this._hash;\n",d+=" }\n\n",d+=" set hash(hash: string) {\n",d+=" this._hash = hash;\n",d+=" }\n",d+="\n",d+=" get privileges(): string[] {\n",d+=" return this._privileges;\n",d+=" }\n\n",d+=" set privileges(p: string[]) {\n",d+=" this._privileges = p;\n",d+=" }\n"),d+="}\n",e.separateApi?(m=c+"\n"+p+"\n"+m,fs.writeFileSync(`${e.modelDirectory}/${u+"-api.ts"}`,m),d=c+"\n"+b+"\n"+d):d=c+"\n"+b+"\n"+m+"\n"+d,fs.writeFileSync(`${e.modelDirectory}/${u+".ts"}`,d)}else console.log("error: table has no fields")})).catch((e=>{console.error(e),process.abort()}))}}let s=`import {AbstractModel} from "${e.abstractModelModule}";\n`;_.forEach(n,(e=>{s+=`import {${e.className}} from "./${e.fileName}";\n`})),s+="\n",s+="interface SmartDbDictionaryEntry {\n",s+=" cls: "+n.map((e=>"typeof "+e.className)).join(" |\n "),s+=";\n",s+="}\n\n",s+="export class SmartDbDictionary {\n",s+=" static models: { [relation: string]: SmartDbDictionaryEntry; } = {\n",_.forEach(n,(e=>{s+=` ${e.className}: {\n`,s+=` cls: ${e.className}\n`,s+=" },\n"})),s=s.substring(0,s.length-2)+"\n",s+=" };\n",s+="}\n",fs.writeFileSync(`${e.modelDirectory}/smart-db-dictionary.ts`,s)})).catch((e=>{console.error("extraction error",e)}))}(async()=>{let e=!1;const t=Array.from(process.argv);let r,a,n,s=!1;for(t.shift(),t.shift();t[0]&&"--"==t[0].substring(0,2);)"--separate-api"==t[0]?(e=!0,t.shift()):"--connector"==t[0]?(r=t[1],t.shift(),t.shift()):"--username"==t[0]?(a=t[1],t.shift(),t.shift()):"--password"==t[0]?(r=t[1],t.shift(),t.shift()):"--create"==t[0]?(s=!0,t.shift()):(console.error(`unknown option '${t[2]}'`),process.exit(-1));if(r||(r=process.env.ORACLE_SID),a||(a=process.env.ORA_USER),n||(n=process.env.ORA_PASS),r&&t.length<=1){let o;a&&n?o=new SmartDbOracle(r,{user:a,password:n,noDbLogging:!0}):s||fs.existsSync(r)?o=new SmartDbBetterSqlite3(r,{verbose:(e,...t)=>{console.log("DB LOG",e,...t)}}):(console.error(`ERROR: missing sqlite3 database file ${r}`),process.exit(-1)),1==t.length?o.onReady().subscribe((async r=>{if(r){o.getLogger().setDbLogging(!1);const r={skipCoreTables:!0,modelDirectory:t[0],smartDbInterfaces:"@egi/smart-db",abstractModelModule:"@egi/smart-db",separateApi:e,db:o};await extractDbApi(r)}})):fs.existsSync("src/helpers/extract-db-api.ts")?o.onReady().subscribe((t=>{if(t){const t={justCoreTables:!0,modelDirectory:"src/models/generated",smartDbInterfaces:"../smart-db-interfaces",abstractModelModule:"./abstract-model",separateApi:e,db:o};t.db.initDb({module:"smart-db-core",sqlFilesDirectory:"assets/sqlite3"}).then((async()=>{await extractDbApi(t)}))}else console.error("unable to connect to database")})):console.log("command must be run at the root directory of the smart-db project")}else console.log("USAGE: extract-db-api --connector {db-connector|path-to-db} [{options}] {target-models-directory}\n"),console.log("Options are: [--username {username}]"),console.log(" [--password {password}]"),console.log(" [--create"),console.log(" [--separate-api]")})();
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract-db-api.js","sourceRoot":"","sources":["../../src/helpers/extract-db-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,CAAC,MAAM,QAAQ,CAAC;AAEvB,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAC,oBAAoB,EAAC,MAAM,oCAAoC,CAAC;AACxE,OAAO,EAAC,aAAa,EAAC,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAC,cAAc,EAAC,MAAM,4BAA4B,CAAC;AAE1D,OAAO,EAAC,qBAAqB,EAAC,MAAM,qCAAqC,CAAC;AAC1E,OAAO,EAAC,iBAAiB,EAAC,MAAM,+BAA+B,CAAC;AAEhE,OAAO,EAAC,EAAE,EAAE,EAAE,EAAE,QAAQ,EAAC,MAAM,qBAAqB,CAAC;AAkBrD,gCAAgC;AAChC,SAAS,OAAO,CAAC,OAAe;IAC5B,IAAI,IAAY,CAAC;IAEjB,IAAI,OAAO,EAAE;QACT,IAAI,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE;YACrD,IAAI,GAAG,QAAQ,CAAC;SACnB;aAAM,IAAI,OAAO,CAAC,KAAK,CAAC,eAAe,CAAC,EAAE;YACvC,IAAI,GAAG,SAAS,CAAC;SACpB;aAAM,IAAI,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE;YAC/B,IAAI,GAAG,MAAM,CAAC;SACjB;aAAM,IAAI,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC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AAC,CAAC;iBAC/B;YACL,CAAC,CAAC,CAAC;SACN;aAAM,IAAI,EAAE,CAAC,UAAU,CAAC,+BAA+B,CAAC,EAAE;YACvD,EAAE,CAAC,OAAO,EAAE,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE;gBAC7B,IAAI,KAAK,EAAE;oBACP,MAAM,cAAc,GAAmB;wBACnC,cAAc,EAAE,IAAI;wBACpB,cAAc,EAAE,sBAAsB;wBACtC,iBAAiB,EAAE,wBAAwB;wBAC3C,mBAAmB,EAAE,kBAAkB;wBACvC,WAAW,EAAE,WAAW;wBACxB,EAAE,EAAE,EAAE;qBACT,CAAC;oBAEF,cAAc,CAAC,EAAE,CAAC,MAAM,CAAC;wBACrB,MAAM,EAAE,eAAe;wBACvB,iBAAiB,EAAE,gBAAgB;qBACtC,CAAC,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE;wBACf,MAAM,YAAY,CAAC,cAAc,CAAC,CAAC;oBACvC,CAAC,CAAC,CAAC;iBACN;qBAAM;oBACH,OAAO,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAA;iBACjD;YACL,CAAC,CAAC,CAAC;SACN;aAAM;YACH,OAAO,CAAC,GAAG,CAAC,mEAAmE,CAAC,CAAC;SACpF;KACJ;SAAM;QACH,OAAO,CAAC,GAAG,CAAC,qGAAqG,CAAC,CAAC;QACnH,OAAO,CAAC,GAAG,CAAC,8CAA8C,CAAC,CAAC;QAC5D,OAAO,CAAC,GAAG,CAAC,8CAA8C,CAAC,CAAC;QAC5D,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;QAC9C,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAC;KACxD;AACL,CAAC,CAAC,EAAE,CAAC","sourcesContent":["import fs from \"fs\";\nimport _ from \"lodash\";\n\nimport process from \"process\";\nimport {SmartDbBetterSqlite3} from \"../drivers/smart-db-better-sqlite3\";\nimport {SmartDbOracle} from \"../drivers/smart-db-oracle\";\nimport {OracleCatModel} from \"../models/oracle-cat-model\";\n\nimport {SmartDbCoreTableModel} from \"../models/smart-db-core-table-model\";\nimport {SqliteMasterModel} from \"../models/sqlite-master-model\";\nimport {SmartDb} from \"../smart-db\";\nimport {IN, NE, NOT_LIKE} from \"../smart-db-globals\";\nimport {AttributeInfo} from \"../smart-db-interfaces\";\n\ninterface AnalysisAttributeInfo extends AttributeInfo {\n name: string;\n attribute: string;\n}\n\ninterface ExtractOptions {\n db: SmartDb;\n modelDirectory: string;\n smartDbInterfaces: string;\n abstractModelModule: string;\n skipCoreTables?: boolean;\n justCoreTables?: boolean;\n separateApi: boolean;\n}\n\n// noinspection NestedFunctionJS\nfunction getType(rowType: string): string {\n let type: string;\n\n if (rowType) {\n if (rowType.match(/varchar/i) || rowType.match(/text/i)) {\n type = \"string\";\n } else if (rowType.match(/integer\\(1\\)/i)) {\n type = \"boolean\";\n } else if (rowType.match(/date/i)) {\n type = \"Date\";\n } else if (rowType.match(/integer/i) || rowType.match(/number/i)) {\n type = \"number\";\n } else if (rowType.match(/long/i)) {\n type = \"any\";\n } else if (rowType.match(/raw/i)) {\n type = \"any\";\n } else {\n type = \"SqlValueType\";\n }\n } else {\n type = \"SqlValueType\";\n }\n\n return type;\n}\n\nfunction getRelations(db: SmartDb): Promise<string[]> {\n return new Promise<string[]>(async (resolve, reject) => {\n\n if (db instanceof SmartDbOracle) {\n db.getAll(OracleCatModel, {\n type: IN([\"TABLE\", \"VIEW\"]),\n name: NOT_LIKE(\"BIN$%\")\n }).then((tables) => {\n if (tables) {\n resolve(tables.map((row) => row.name.toLowerCase()));\n } else {\n reject(db.getLastError());\n }\n }).catch((error) => {\n reject(error);\n });\n } else if (db instanceof SmartDbBetterSqlite3) {\n db.getAll(SqliteMasterModel, {\n type: IN([\"table\", \"view\"]),\n name: NE(\"sqlite_sequence\")\n }).then((tables) => {\n if (tables) {\n resolve(tables.map((row) => row.name));\n } else {\n reject(db.getLastError());\n }\n }).catch((error) => {\n reject(error);\n });\n } else {\n reject(\"unimplemented database type\");\n }\n });\n}\n\nasync function extractDbApi(options: ExtractOptions) {\n console.log(`extract interface from '${options.db.getDbConnector()}' to '${options.modelDirectory}'`);\n\n const reservedWords = [\"break\", \"case\", \"catch\", \"class\", \"const\", \"continue\", \"debugger\", \"default\", \"delete\", \"do\", \"else\", \"enum\", \"export\", \"extends\", \"false\", \"finally\", \"for\", \"function\", \"If\", \"import\", \"in\", \"instanceOf\", \"new\", \"null\", \"return\", \"super\", \"switch\", \"this\", \"throw\", \"true\", \"try\", \"typeOf\", \"var\", \"void\", \"while\", \"with\"];\n if (!fs.existsSync(options.modelDirectory)) {\n fs.mkdirSync(options.modelDirectory, {\n recursive: true\n });\n }\n\n getRelations(options.db).then(async (tables) => {\n let coreTables: string[] = [];\n if (options.skipCoreTables || options.justCoreTables) {\n if (await options.db.exists(SmartDbCoreTableModel)) {\n const coreTableRows = await options.db.getAll(SmartDbCoreTableModel);\n if (coreTableRows === false) {\n throw options.db.getLastError();\n } else {\n coreTableRows.forEach((row) => {\n coreTables.push(row.name);\n });\n }\n }\n }\n\n const dictionaryRelations: { className: string, fileName: string }[] = [];\n\n for (const tableName of tables) {\n let useTable: boolean = true;\n if (options.justCoreTables) {\n useTable = coreTables.includes(tableName);\n } else if (options.skipCoreTables) {\n useTable = !coreTables.includes(tableName);\n }\n\n if (useTable) {\n const className = tableName[0].toUpperCase() + _.camelCase(tableName.substring(1)) + \"Model\";\n\n const fieldsInfos: AnalysisAttributeInfo[] = [];\n\n console.log(\"working on\", tableName);\n await options.db.getTableInfo(tableName).then((info) => {\n const fields = info.fields;\n\n let hasSqlValueType = false;\n let header = \"\";\n let apiData = \"\";\n let apiImports = \"\";\n let modelData = \"\";\n let modelImports = \"\";\n\n const filenameBase = tableName.toLowerCase().replace(/[^[a-z0-9]/g, \"-\") + \"-model\";\n dictionaryRelations.push({className: className, fileName: filenameBase});\n\n header += \"/* eslint-disable @typescript-eslint/member-ordering */\\n\";\n header += \"// noinspection JSUnusedGlobalSymbols\\n\";\n\n if (fields) {\n if (options.abstractModelModule == options.smartDbInterfaces) {\n if (options.separateApi) {\n apiImports += `import {GenericModelData} from \"${options.abstractModelModule}\";\\n`;\n modelImports += `import {AbstractModel, ModelAttributeMap} from \"${options.abstractModelModule}\";\\n`;\n modelImports += `import {${className}Data} from \"./${filenameBase}-api\";\\n`;\n } else {\n modelImports += `import {AbstractModel, GenericModelData, ModelAttributeMap} from \"${options.abstractModelModule}\";\\n`;\n }\n } else {\n if (options.separateApi) {\n apiImports += `import {GenericModelData} from \"${options.smartDbInterfaces}\";\\n`;\n modelImports += `import {ModelAttributeMap} from \"${options.smartDbInterfaces}\";\\n`;\n modelImports += `import {AbstractModel} from \"${options.abstractModelModule}\";\\n`;\n modelImports += `import {${className}Data} from \"./${filenameBase}-api\";\\n`;\n } else {\n modelImports += `import {GenericModelData, ModelAttributeMap} from \"${options.smartDbInterfaces}\";\\n`;\n modelImports += `import {AbstractModel} from \"${options.abstractModelModule}\";\\n`;\n }\n }\n\n apiData += `export interface ${className}Data extends GenericModelData {\\n`;\n\n let pkName = \"\";\n let fieldPrefix = \"\";\n let prefixRegex: RegExp;\n let hasColumnWithoutPrefix = false;\n const prefixes: string[] = [];\n fields.forEach((field) => {\n const prefixMatch = field.name.match(/([a-z0-9]{1,4})_/i);\n\n if (field.isPk) {\n pkName = field.name as string;\n if (prefixMatch) {\n fieldPrefix = prefixMatch[1];\n }\n }\n\n if (prefixMatch) {\n if (!prefixes.includes(prefixMatch[1])) {\n prefixes.push(prefixMatch[1]);\n }\n } else {\n hasColumnWithoutPrefix = true;\n }\n\n });\n\n if (!fieldPrefix && !hasColumnWithoutPrefix && prefixes.length == 1) {\n fieldPrefix = prefixes[0];\n }\n\n if (fieldPrefix) {\n prefixRegex = new RegExp(`^${fieldPrefix}_(.*)$`);\n }\n\n const attributes: Record<string, string> = {};\n\n fields.forEach((row) => {\n const type = getType(row.type);\n if (!hasSqlValueType && type == \"SqlValueType\") {\n apiImports += `import {SqlValueType} from \"${options.smartDbInterfaces}\";\\n`;\n modelImports += `import {SqlValueType} from \"${options.smartDbInterfaces}\";\\n`;\n hasSqlValueType = true;\n }\n\n let attribute: string;\n\n const prefixMatch = prefixRegex && row.name.match(prefixRegex);\n if (prefixMatch) {\n attribute = _.camelCase(prefixMatch[1]);\n } else {\n attribute = _.camelCase(row.name);\n }\n\n let typeScriptStyle = true;\n\n if (attribute != row.name) {\n fieldsInfos.push({\n name: attribute,\n attribute: attribute,\n type: type,\n typeScriptStyle: typeScriptStyle,\n alias: row.name\n });\n\n typeScriptStyle = false;\n }\n\n if (attribute != row.name.toLowerCase()) {\n fieldsInfos.push({\n name: row.name.toLowerCase(),\n attribute: attribute,\n type: type,\n physical: row.cid !== undefined && row.name == row.name.toLowerCase(),\n typeScriptStyle: typeScriptStyle\n });\n\n typeScriptStyle = false;\n }\n\n if (attribute != row.name.toUpperCase()) {\n fieldsInfos.push({\n name: row.name.toUpperCase(),\n attribute: attribute,\n type: type,\n physical: row.cid !== undefined && row.name == row.name.toUpperCase(),\n typeScriptStyle: typeScriptStyle\n });\n }\n\n if (row.cid) {\n const physical = fieldsInfos.find((info) => {\n return info.physical && info.name.toLowerCase() == row.name.toLowerCase();\n });\n\n if (!physical) {\n fieldsInfos.push({\n name: row.name,\n attribute: attribute,\n type: type,\n physical: true,\n typeScriptStyle: typeScriptStyle\n });\n }\n }\n\n attributes[attribute] = type;\n\n if (tableName == \"user\" && attribute == \"name\") {\n apiData += \" // @ts-ignore\";\n }\n apiData += ` ${attribute}?: ${type};\\n`;\n });\n\n apiData += \"}\\n\";\n\n modelData += `export class ${className} extends AbstractModel<${className}, ${className}Data> {\\n`;\n\n _.forEach(attributes, (type, attribute) => {\n modelData += ` private _${attribute}?: ${type};\\n`;\n });\n\n if (tableName == \"user\") {\n modelData += ` private _hash?: string;\\n`;\n modelData += ` private _privileges?: string[];\\n`;\n }\n\n\n modelData += \"\\n\";\n\n modelData += \" static readonly attributeMap: ModelAttributeMap = {\\n\";\n\n fieldsInfos.forEach((info, idx) => {\n if (idx > 0) {\n modelData += \",\\n\";\n }\n\n modelData += ` ${info.name}: {\\n`;\n\n if (info.physical) {\n modelData += \" physical: true,\\n\";\n }\n\n if (info.alias) {\n modelData += ` alias: \"${info.alias}\",\\n`;\n }\n\n if (info.virtual) {\n modelData += \" virtual: true,\\n\";\n }\n\n if (info.typeScriptStyle) {\n modelData += \" typeScriptStyle: true,\\n\";\n }\n\n modelData += ` type: \"${info.type}\",\\n`;\n modelData += ` attribute: \"_${info.attribute}\"\\n`;\n modelData += \" }\";\n });\n\n modelData += \"\\n\";\n modelData += \" };\\n\";\n\n modelData += \"\\n\";\n modelData += \" static getClassName(): string {\\n\";\n modelData += ` return \"${className}\";\\n`;\n modelData += \" }\\n\";\n\n modelData += \"\\n\";\n modelData += \" static getTableName(): string {\\n\";\n modelData += ` return \"${tableName}\";\\n`;\n modelData += \" }\\n\";\n\n modelData += \"\\n\";\n modelData += \" static getPrimaryKey(): string {\\n\";\n modelData += ` return \"${pkName}\";\\n`;\n modelData += \" }\\n\";\n\n modelData += \"\\n\";\n modelData += ` static from(other: ${className} | ${className}Data): ${className} {\\n`;\n modelData += ` let value: ${className} = null;\\n`;\n modelData += \" if (other) {\\n\";\n modelData += ` value = new ${className}();\\n`;\n modelData += ` if (other instanceof ${className}) {\\n`;\n modelData += \" Object.assign(value, other);\\n\";\n modelData += \" } else {\\n\";\n modelData += \" value.assign(other);\\n\";\n modelData += \" }\\n\";\n modelData += \" }\\n\";\n modelData += \" return value;\\n\";\n modelData += \" }\\n\";\n\n modelData += \"\\n\";\n modelData += ` constructor(data?: ${className} | ${className}Data) {\\n`;\n modelData += \" super();\\n\";\n modelData += \" if (data) {\\n\";\n modelData += \" this.assign(data);\\n\";\n modelData += \" }\\n\";\n modelData += \" }\\n\";\n\n\n modelData += \"\\n\";\n modelData += ` public clone(): ${className} {\\n`;\n modelData += ` return ${className}.from(this);\\n`;\n modelData += \" }\\n\";\n\n modelData += \"\\n\";\n modelData += \" public getClassName(): string {\\n\";\n modelData += ` return \"${className}\";\\n`;\n modelData += \" }\\n\";\n\n modelData += \"\\n\";\n modelData += \" public getTableName(): string {\\n\";\n modelData += ` return \"${tableName}\";\\n`;\n modelData += \" }\\n\";\n\n modelData += \"\\n\";\n modelData += \" public getPrimaryKey(): string {\\n\";\n modelData += ` return \"${pkName}\";\\n`;\n modelData += \" }\\n\";\n\n modelData += \"\\n\";\n modelData += \" public getAttributeMap(): ModelAttributeMap {\\n\";\n modelData += ` return ${className}.attributeMap;\\n`;\n modelData += \" }\\n\";\n\n fieldsInfos.forEach((info) => {\n modelData += \"\\n\";\n\n let noInspection: string;\n\n if (info.name.length < 3 || info.name.match(/_/)) {\n noInspection = \"FunctionNamingConventionJS\";\n } else {\n noInspection = \"\";\n }\n\n if (noInspection !== \"\") {\n modelData += ` // noinspection ${noInspection}\\n`;\n }\n\n modelData += ` get ${info.name}(): ${info.type} {\\n`;\n modelData += ` return this._${info.attribute};\\n`;\n modelData += \" }\\n\\n\";\n\n if (noInspection !== \"\") {\n modelData += ` // noinspection ${noInspection}\\n`;\n }\n\n let paramName = info.attribute;\n if (reservedWords.includes(paramName)) {\n paramName = \"value\";\n }\n\n modelData += ` set ${info.name}(${paramName}: ${info.type}) {\\n`;\n modelData += ` this._${info.attribute} = ${paramName};\\n`;\n modelData += \" }\\n\";\n });\n\n if (tableName == \"user\") {\n modelData += \"\\n\";\n modelData += ` get hash(): string {\\n`;\n modelData += ` return this._hash;\\n`;\n modelData += \" }\\n\\n\";\n modelData += ` set hash(hash: string) {\\n`;\n modelData += ` this._hash = hash;\\n`;\n modelData += \" }\\n\";\n modelData += \"\\n\";\n modelData += ` get privileges(): string[] {\\n`;\n modelData += ` return this._privileges;\\n`;\n modelData += \" }\\n\\n\";\n modelData += ` set privileges(p: string[]) {\\n`;\n modelData += ` this._privileges = p;\\n`;\n modelData += \" }\\n\";\n }\n\n modelData += \"}\\n\";\n\n if (options.separateApi) {\n apiData = header + \"\\n\" + apiImports + \"\\n\" + apiData;\n\n fs.writeFileSync(`${options.modelDirectory}/${filenameBase + \"-api.ts\"}`, apiData);\n\n modelData = header + \"\\n\" + modelImports + \"\\n\" + modelData;\n } else {\n modelData = header + \"\\n\" + modelImports + \"\\n\" + apiData + \"\\n\" + modelData;\n }\n\n fs.writeFileSync(`${options.modelDirectory}/${filenameBase + \".ts\"}`, modelData);\n } else {\n console.log(\"error: table has no fields\");\n }\n }).catch((err) => {\n console.error(err);\n process.abort();\n });\n }\n }\n\n let smartDbDictionaryFile = `import {AbstractModel} from \"${options.abstractModelModule}\";\\n`;\n\n _.forEach(dictionaryRelations, (relation) => {\n smartDbDictionaryFile += `import {${relation.className}} from \"./${relation.fileName}\";\\n`;\n });\n\n smartDbDictionaryFile += \"\\n\";\n smartDbDictionaryFile += \"interface SmartDbDictionaryEntry {\\n\";\n\n smartDbDictionaryFile += \" cls: \" + dictionaryRelations.map((relation) => {\n return \"typeof \" + relation.className;\n }).join(\" |\\n \");\n\n smartDbDictionaryFile += \";\\n\";\n smartDbDictionaryFile += \"}\\n\\n\";\n\n smartDbDictionaryFile += \"export class SmartDbDictionary {\\n\";\n smartDbDictionaryFile += \" static models: { [relation: string]: SmartDbDictionaryEntry; } = {\\n\";\n\n _.forEach(dictionaryRelations, (relation) => {\n smartDbDictionaryFile += ` ${relation.className}: {\\n`;\n smartDbDictionaryFile += ` cls: ${relation.className}\\n`;\n smartDbDictionaryFile += ` },\\n`;\n });\n\n smartDbDictionaryFile = smartDbDictionaryFile.substring(0, smartDbDictionaryFile.length - 2) + \"\\n\";\n\n smartDbDictionaryFile += \" };\\n\";\n smartDbDictionaryFile += \"}\\n\";\n\n fs.writeFileSync(`${options.modelDirectory}/smart-db-dictionary.ts`, smartDbDictionaryFile);\n\n }).catch((error) => {\n console.error(\"extraction error\", error);\n });\n}\n\n(async () => {\n let separateApi: boolean = false;\n const args: string[] = Array.from(process.argv);\n let connector: string;\n let username: string;\n let password: string;\n let createDatabase: boolean = false;\n args.shift();\n args.shift();\n while (args[0] && args[0].substring(0, 2) == \"--\") {\n if (args[0] == \"--separate-api\") {\n separateApi = true;\n args.shift();\n } else if (args[0] == \"--connector\") {\n connector = args[1];\n args.shift();\n args.shift();\n } else if (args[0] == \"--username\") {\n username = args[1];\n args.shift();\n args.shift();\n } else if (args[0] == \"--password\") {\n connector = args[1];\n args.shift();\n args.shift();\n } else if (args[0] == \"--create\") {\n createDatabase = true;\n args.shift();\n } else {\n console.error(`unknown option '${args[2]}'`);\n process.exit(-1);\n }\n }\n\n if (!connector) {\n connector = process.env.ORACLE_SID;\n }\n\n if (!username) {\n username = process.env.ORA_USER;\n }\n\n if (!password) {\n password = process.env.ORA_PASS;\n }\n\n if (connector && args.length <= 1) {\n let db: SmartDb;\n if (username && password) {\n db = new SmartDbOracle(connector, {\n user: username,\n password: password,\n noDbLogging: true\n });\n } else if (createDatabase || fs.existsSync(connector)) {\n db = new SmartDbBetterSqlite3(connector, {\n verbose: (message?: any, ...additionalArgs: any[]) => {\n console.log(\"DB LOG\", message, ...additionalArgs);\n }\n });\n } else {\n console.error(`ERROR: missing sqlite3 database file ${connector}`);\n process.exit(-1);\n }\n\n if (args.length == 1) {\n db.onReady().subscribe(async (ready) => {\n if (ready) {\n db.getLogger().setDbLogging(false);\n const options: ExtractOptions = {\n skipCoreTables: true,\n modelDirectory: args[0],\n smartDbInterfaces: \"@egi/smart-db\",\n abstractModelModule: \"@egi/smart-db\",\n separateApi: separateApi,\n db: db\n };\n\n await extractDbApi(options);\n }\n });\n } else if (fs.existsSync(\"src/helpers/extract-db-api.ts\")) {\n db.onReady().subscribe((ready) => {\n if (ready) {\n const smartDbOptions: ExtractOptions = {\n justCoreTables: true,\n modelDirectory: \"src/models/generated\",\n smartDbInterfaces: \"../smart-db-interfaces\",\n abstractModelModule: \"./abstract-model\",\n separateApi: separateApi,\n db: db\n };\n\n smartDbOptions.db.initDb({\n module: \"smart-db-core\",\n sqlFilesDirectory: \"assets/sqlite3\"\n }).then(async () => {\n await extractDbApi(smartDbOptions);\n });\n } else {\n console.error(\"unable to connect to database\")\n }\n });\n } else {\n console.log(\"command must be run at the root directory of the smart-db project\");\n }\n } else {\n console.log(\"USAGE: extract-db-api --connector {db-connector|path-to-db} [{options}] {target-models-directory}\\n\");\n console.log(\"Options are: [--username {username}]\");\n console.log(\" [--password {password}]\");\n console.log(\" [--create\");\n console.log(\" [--separate-api]\");\n }\n})();\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@egi/smart-db",
3
- "version": "2.5.3",
3
+ "version": "2.5.4",
4
4
  "description": "Unified Smart DB Access",
5
5
  "author": "Marcel Egloff",
6
6
  "type": "module",