Updates
This commit is contained in:
Vendored
+87
-90
@@ -1,5 +1,38 @@
|
||||
#! /usr/bin/env node
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
@@ -13,116 +46,80 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const fs_1 = __importStar(require("fs"));
|
||||
const __1 = __importDefault(require(".."));
|
||||
const util_1 = require("util");
|
||||
const db_schema_to_type_1 = __importDefault(require("../package-shared/functions/dsql/db-schema-to-type"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const debug_log_1 = __importDefault(require("../package-shared/utils/logging/debug-log"));
|
||||
const parse_env_1 = __importDefault(require("../package-shared/utils/parse-env"));
|
||||
const args = (0, util_1.parseArgs)({
|
||||
args: process.argv,
|
||||
options: {
|
||||
apiKey: {
|
||||
type: "string",
|
||||
default: process.env.DSQL_FULL_ACCESS_API_KEY,
|
||||
short: "k",
|
||||
},
|
||||
database: {
|
||||
type: "string",
|
||||
default: process.env.DSQL_DB_NAME,
|
||||
short: "d",
|
||||
},
|
||||
userid: {
|
||||
type: "string",
|
||||
default: process.env.DSQL_API_USER_ID,
|
||||
short: "i",
|
||||
},
|
||||
outfile: {
|
||||
type: "string",
|
||||
short: "o",
|
||||
},
|
||||
envfile: {
|
||||
type: "string",
|
||||
short: "e",
|
||||
},
|
||||
debug: {
|
||||
type: "boolean",
|
||||
short: "u",
|
||||
},
|
||||
},
|
||||
strict: false,
|
||||
});
|
||||
let appendedEnv = {};
|
||||
if (args.values.envfile && typeof args.values.envfile == "string") {
|
||||
const finalEnvPath = path_1.default.resolve(process.cwd(), args.values.envfile);
|
||||
if (fs_1.default.existsSync(finalEnvPath)) {
|
||||
const parsedEnv = (0, parse_env_1.default)(finalEnvPath);
|
||||
appendedEnv = (parsedEnv || {});
|
||||
if (args.values.debug) {
|
||||
(0, debug_log_1.default)({
|
||||
log: appendedEnv,
|
||||
label: "Appended env",
|
||||
title: "Schema to Typedef",
|
||||
addTime: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
const app_names_1 = require("../package-shared/dict/app-names");
|
||||
const configFileName = app_names_1.AppNames["SchemaToTypeDefConfigFileName"];
|
||||
const configFilePath = path_1.default.join(process.cwd(), configFileName);
|
||||
if (!fs_1.default.existsSync(configFilePath)) {
|
||||
(0, debug_log_1.default)({
|
||||
log: `Config File doesn't exist. Please add a '${app_names_1.AppNames["SchemaToTypeDefConfigFileName"]}' in the working directory with relevant configurations.`,
|
||||
addTime: true,
|
||||
type: "error",
|
||||
});
|
||||
process.exit(1);
|
||||
}
|
||||
const config = JSON.parse((0, fs_1.readFileSync)(path_1.default.join(process.cwd(), configFileName), "utf-8"));
|
||||
if (!config.database) {
|
||||
(0, debug_log_1.default)({
|
||||
log: `Config File needs a 'database' value.`,
|
||||
addTime: true,
|
||||
type: "error",
|
||||
});
|
||||
process.exit(1);
|
||||
}
|
||||
if (!config.outDir && !config.outFile) {
|
||||
(0, debug_log_1.default)({
|
||||
log: `Config File needs a 'outDir' or 'outFile' value.`,
|
||||
addTime: true,
|
||||
type: "error",
|
||||
});
|
||||
process.exit(1);
|
||||
}
|
||||
if (!config.apiConnectionConfig) {
|
||||
(0, debug_log_1.default)({
|
||||
log: `Config File needs a 'apiConnectionConfig' value. This value needs an 'apiKey' value.`,
|
||||
addTime: true,
|
||||
type: "error",
|
||||
});
|
||||
process.exit(1);
|
||||
}
|
||||
if (!config.apiConnectionConfig.apiKey) {
|
||||
(0, debug_log_1.default)({
|
||||
log: `Config value 'apiConnectionConfig' needs an 'apiKey' value.`,
|
||||
addTime: true,
|
||||
type: "error",
|
||||
});
|
||||
process.exit(1);
|
||||
}
|
||||
const finalEnv = Object.assign(Object.assign({}, process.env), appendedEnv);
|
||||
process.env = Object.assign(Object.assign({}, process.env), appendedEnv);
|
||||
(() => __awaiter(void 0, void 0, void 0, function* () {
|
||||
try {
|
||||
const key = args.values.apiKey || finalEnv["DSQL_FULL_ACCESS_API_KEY"];
|
||||
const database = args.values.database || finalEnv["DSQL_DB_NAME"];
|
||||
const user_id = args.values.userid || finalEnv["DSQL_API_USER_ID"] || "1";
|
||||
if (args.values.debug) {
|
||||
if (config.debug) {
|
||||
(0, debug_log_1.default)({
|
||||
log: args.values,
|
||||
label: "Arguments",
|
||||
title: "Schema to Typedef",
|
||||
addTime: true,
|
||||
});
|
||||
(0, debug_log_1.default)({
|
||||
log: process.env.DSQL_FULL_ACCESS_API_KEY,
|
||||
label: "process.env.DSQL_FULL_ACCESS_API_KEY",
|
||||
title: "Schema to Typedef",
|
||||
addTime: true,
|
||||
});
|
||||
(0, debug_log_1.default)({
|
||||
log: process.env.DSQL_DB_NAME,
|
||||
label: "process.env.DSQL_DB_NAME",
|
||||
title: "Schema to Typedef",
|
||||
log: config,
|
||||
label: "Config",
|
||||
addTime: true,
|
||||
});
|
||||
}
|
||||
if (!database || typeof database !== "string")
|
||||
throw new Error("Database name is required");
|
||||
if (!key || typeof key !== "string")
|
||||
throw new Error("API key is required");
|
||||
if (!args.values.outfile || typeof args.values.outfile !== "string")
|
||||
throw new Error("Outfile are required");
|
||||
if (!user_id || typeof user_id !== "string")
|
||||
throw new Error("Outfile are required");
|
||||
const schema = yield __1.default.getSchema({
|
||||
key,
|
||||
database,
|
||||
user_id,
|
||||
env: finalEnv,
|
||||
const schemaRes = yield __1.default.api.schema.get({
|
||||
dbName: config.database || "",
|
||||
apiConnectionConfig: config.apiConnectionConfig,
|
||||
});
|
||||
const dbSchema = schema.payload;
|
||||
if (args.values.debug) {
|
||||
const dbSchema = schemaRes.payload;
|
||||
if (config.debug) {
|
||||
(0, debug_log_1.default)({
|
||||
log: schema,
|
||||
log: schemaRes,
|
||||
label: "schema",
|
||||
title: "Schema to Typedef",
|
||||
addTime: true,
|
||||
});
|
||||
}
|
||||
if (!dbSchema)
|
||||
throw new Error("No schema found");
|
||||
const definitions = (0, db_schema_to_type_1.default)({ dbSchema });
|
||||
const finalOutfile = path_1.default.resolve(process.cwd(), args.values.outfile);
|
||||
const finalOutfile = path_1.default.resolve(process.cwd(), config.outDir ? config.outDir + "/dsql.ts" : config.outFile || "");
|
||||
const ourfileDir = path_1.default.dirname(finalOutfile);
|
||||
if (!fs_1.default.existsSync(ourfileDir)) {
|
||||
fs_1.default.mkdirSync(ourfileDir, { recursive: true });
|
||||
|
||||
Reference in New Issue
Block a user