sqljson-query
Advanced tools
Comparing version 1.7.2 to 1.7.3
@@ -7,3 +7,18 @@ import { QueryGroupSpec } from './query-specs'; | ||
export * from './dbmd/relations-md-source-generator'; | ||
export interface QueryGenerationOptions { | ||
dbmdFile: string; | ||
sqlOutputDir: string; | ||
sqlSpecOutputDir?: string; | ||
queryPropsMdOutputDir?: string; | ||
tsOutputDir?: string | null; | ||
javaBaseOutputDir?: string | null; | ||
javaPackage?: string | null; | ||
javaEmitRecords?: boolean | null; | ||
tsTypesHeaderFile?: string; | ||
javaHeaderFile?: string | null; | ||
sqlResourcePath?: string; | ||
} | ||
export declare function generateQueriesWithArgvOptions(queryGroupSpec: QueryGroupSpec, args: string[]): Promise<void>; | ||
export declare function generateQueriesWithOptions(queryGroupSpec: QueryGroupSpec, opts: QueryGenerationOptions): Promise<void>; | ||
export declare function generateQuerySources(querySpecs: QueryGroupSpec | string, // string should be a path to a json file or js module file | ||
dbmdFile: string, opts: SourceGenerationOptions): Promise<void>; |
@@ -29,4 +29,5 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.generateQuerySources = void 0; | ||
exports.generateQuerySources = exports.generateQueriesWithOptions = exports.generateQueriesWithArgvOptions = void 0; | ||
const path = __importStar(require("path")); | ||
const fs_1 = require("fs"); | ||
const mod_1 = require("./util/mod"); | ||
@@ -44,2 +45,83 @@ const dbmd_1 = require("./dbmd"); | ||
__exportStar(require("./dbmd/relations-md-source-generator"), exports); | ||
async function generateQueriesWithArgvOptions(queryGroupSpec, args) { | ||
var _a, _b; | ||
const requiredOptions = [ | ||
'dbmd', | ||
'sqlDir' | ||
]; | ||
const optionalOptions = [ | ||
'sqlSpecDir', | ||
'propsMdDir', | ||
'sqlResourcePath', | ||
'tsQueriesDir', 'tsTypesHeader', | ||
'javaBaseDir', 'javaQueriesPkg', 'javaTypesHeader', 'javaEmitRecords' | ||
]; | ||
const parsedArgs = (0, mod_1.parseArgs)(args, requiredOptions, optionalOptions, 0); | ||
if (typeof parsedArgs === 'string') // arg parsing error | ||
throw new Error(parsedArgs); | ||
const opts = { | ||
dbmdFile: parsedArgs['dbmd'], | ||
sqlOutputDir: parsedArgs['sqlDir'], | ||
sqlSpecOutputDir: parsedArgs['sqlSpecDir'], | ||
queryPropsMdOutputDir: parsedArgs['propsMdDir'], | ||
tsOutputDir: parsedArgs['tsQueriesDir'], | ||
javaBaseOutputDir: parsedArgs['javaBaseDir'], | ||
javaPackage: (_a = parsedArgs['javaQueriesPkg']) !== null && _a !== void 0 ? _a : '', | ||
javaEmitRecords: (0, mod_1.parseBoolOption)((_b = parsedArgs['javaEmitRecords']) !== null && _b !== void 0 ? _b : 'true', 'javaEmitRecords'), | ||
tsTypesHeaderFile: parsedArgs['tsTypesHeader'], | ||
javaTypesHeaderFile: parsedArgs['javaTypesHeader'], | ||
sqlResourcePath: parsedArgs['sqlResourcePath'], | ||
}; | ||
generateQueriesWithOptions(queryGroupSpec, opts); | ||
} | ||
exports.generateQueriesWithArgvOptions = generateQueriesWithArgvOptions; | ||
async function generateQueriesWithOptions(queryGroupSpec, opts) { | ||
// Generate SQL source files if specified. | ||
var _a, _b, _c; | ||
const javaOutputDir = opts.javaBaseOutputDir | ||
? `${opts.javaBaseOutputDir}/${(0, mod_1.replaceAll)((_a = opts.javaPackage) !== null && _a !== void 0 ? _a : '', '.', '/')}` | ||
: null; | ||
if (opts.sqlOutputDir == null) | ||
throw new Error('SQL output directory is required.'); | ||
if (opts.tsOutputDir == null && javaOutputDir == null) | ||
throw new Error('An output directory argument for result types is required.'); | ||
await fs_1.promises.mkdir(opts.sqlOutputDir, { recursive: true }); | ||
if (opts.sqlSpecOutputDir) | ||
await fs_1.promises.mkdir(opts.sqlSpecOutputDir, { recursive: true }); | ||
if (opts.queryPropsMdOutputDir) | ||
await fs_1.promises.mkdir(opts.queryPropsMdOutputDir, { recursive: true }); | ||
// Generate TS query/result-type source files if specified. | ||
if (opts.tsOutputDir) { | ||
await fs_1.promises.mkdir(opts.tsOutputDir, { recursive: true }); | ||
console.log(`Writing TS source files to ${opts.tsOutputDir}.`); | ||
await generateQuerySources(queryGroupSpec, opts.dbmdFile, { | ||
sourceLanguage: 'TS', | ||
resultTypesOutputDir: opts.tsOutputDir, | ||
sqlSpecOutputDir: opts.sqlSpecOutputDir, | ||
queryPropertiesOutputDir: opts.queryPropsMdOutputDir, | ||
sqlOutputDir: opts.sqlOutputDir, | ||
typesHeaderFile: opts.tsTypesHeaderFile, | ||
sqlResourcePathPrefix: opts.sqlResourcePath, | ||
}); | ||
} | ||
// Generate Java sources if specified. | ||
if (javaOutputDir) { | ||
await fs_1.promises.mkdir(javaOutputDir, { recursive: true }); | ||
console.log(`Writing Java query source files to ${javaOutputDir}.`); | ||
await generateQuerySources(queryGroupSpec, opts.dbmdFile, { | ||
sourceLanguage: 'Java', | ||
resultTypesOutputDir: javaOutputDir, | ||
sqlSpecOutputDir: opts.sqlSpecOutputDir, | ||
queryPropertiesOutputDir: opts.queryPropsMdOutputDir, | ||
sqlOutputDir: opts.sqlOutputDir, | ||
javaOptions: { | ||
javaPackage: (_b = opts.javaPackage) !== null && _b !== void 0 ? _b : '', | ||
emitRecords: (_c = opts.javaEmitRecords) !== null && _c !== void 0 ? _c : true | ||
}, | ||
typesHeaderFile: opts.tsTypesHeaderFile, | ||
sqlResourcePathPrefix: opts.sqlResourcePath, | ||
}); | ||
} | ||
} | ||
exports.generateQueriesWithOptions = generateQueriesWithOptions; | ||
async function generateQuerySources(querySpecs, // string should be a path to a json file or js module file | ||
@@ -46,0 +128,0 @@ dbmdFile, opts) { |
import minimist from 'minimist'; | ||
export declare function parseArgs(args: string[], requiredNamedArgs: string[], optionalNamedArgs: string[], minPositionalArgs: number, maxPositionalArgs?: number | null | undefined): minimist.ParsedArgs | 'help' | string; | ||
export declare function parseAppArgs(requiredNamedArgs: string[], optionalNamedArgs: string[], minPositionalArgs: number, maxPositionalArgs?: number | null | undefined): minimist.ParsedArgs | 'help' | string; | ||
export declare function parseBoolOption(valStr: string, optionName: string): boolean; |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parseAppArgs = exports.parseArgs = void 0; | ||
exports.parseBoolOption = exports.parseAppArgs = exports.parseArgs = void 0; | ||
const minimist_1 = __importDefault(require("minimist")); | ||
@@ -40,2 +40,12 @@ function parseArgs(args, requiredNamedArgs, optionalNamedArgs, minPositionalArgs, maxPositionalArgs = null) { | ||
exports.parseAppArgs = parseAppArgs; | ||
function parseBoolOption(valStr, optionName) { | ||
const valLc = valStr.toLowerCase(); | ||
if (valLc === 'true' || valLc === 't' || valLc === '1') | ||
return true; | ||
else if (valLc === 'false' || valLc === 'f' || valLc === '0') | ||
return false; | ||
else | ||
throw new Error(`Could not parse value "${valStr}" for boolean option ${optionName}.`); | ||
} | ||
exports.parseBoolOption = parseBoolOption; | ||
//# sourceMappingURL=args.js.map |
{ | ||
"name": "sqljson-query", | ||
"version": "1.7.2", | ||
"version": "1.7.3", | ||
"description": "Command line tool to generate SQL/JSON queries and Typescript types for query results.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1719750
9708
12