Updates
This commit is contained in:
parent
ba1a4aeeb8
commit
ee23d71b66
19
dist/engine/schema-to-typedef.js
vendored
19
dist/engine/schema-to-typedef.js
vendored
@ -33,6 +33,11 @@ const args = (0, util_1.parseArgs)({
|
|||||||
default: process.env.DSQL_DB_NAME,
|
default: process.env.DSQL_DB_NAME,
|
||||||
short: "d",
|
short: "d",
|
||||||
},
|
},
|
||||||
|
userid: {
|
||||||
|
type: "string",
|
||||||
|
default: process.env.DSQL_API_USER_ID,
|
||||||
|
short: "i",
|
||||||
|
},
|
||||||
outfile: {
|
outfile: {
|
||||||
type: "string",
|
type: "string",
|
||||||
short: "o",
|
short: "o",
|
||||||
@ -64,10 +69,12 @@ if (args.values.envfile && typeof args.values.envfile == "string") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const finalEnv = Object.assign(Object.assign({}, process.env), appendedEnv);
|
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* () {
|
(() => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
try {
|
try {
|
||||||
const key = args.values.apiKey || finalEnv["DSQL_FULL_ACCESS_API_KEY"];
|
const key = args.values.apiKey || finalEnv["DSQL_FULL_ACCESS_API_KEY"];
|
||||||
const database = args.values.database || finalEnv["DSQL_DB_NAME"];
|
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 (args.values.debug) {
|
||||||
(0, debug_log_1.default)({
|
(0, debug_log_1.default)({
|
||||||
log: args.values,
|
log: args.values,
|
||||||
@ -94,12 +101,22 @@ const finalEnv = Object.assign(Object.assign({}, process.env), appendedEnv);
|
|||||||
throw new Error("API key is required");
|
throw new Error("API key is required");
|
||||||
if (!args.values.outfile || typeof args.values.outfile !== "string")
|
if (!args.values.outfile || typeof args.values.outfile !== "string")
|
||||||
throw new Error("Outfile are required");
|
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({
|
const schema = yield __1.default.getSchema({
|
||||||
key,
|
key,
|
||||||
database,
|
database,
|
||||||
user_id: 1,
|
user_id,
|
||||||
});
|
});
|
||||||
const dbSchema = schema.payload;
|
const dbSchema = schema.payload;
|
||||||
|
if (args.values.debug) {
|
||||||
|
(0, debug_log_1.default)({
|
||||||
|
log: schema,
|
||||||
|
label: "schema",
|
||||||
|
title: "Schema to Typedef",
|
||||||
|
addTime: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
if (!dbSchema)
|
if (!dbSchema)
|
||||||
throw new Error("No schema found");
|
throw new Error("No schema found");
|
||||||
const definitions = (0, db_schema_to_type_1.default)({ dbSchema });
|
const definitions = (0, db_schema_to_type_1.default)({ dbSchema });
|
||||||
|
2
dist/package-shared/actions/get-schema.d.ts
vendored
2
dist/package-shared/actions/get-schema.d.ts
vendored
@ -6,5 +6,5 @@ type GetSchemaReturn = {
|
|||||||
/**
|
/**
|
||||||
* # Get Schema for Database, table, or field *
|
* # Get Schema for Database, table, or field *
|
||||||
*/
|
*/
|
||||||
export default function getSchema({ key, database, field, table, user_id, }: GetSchemaAPIParam): Promise<GetSchemaReturn>;
|
export default function getSchema({ key, database, field, table, user_id, env, }: GetSchemaAPIParam): Promise<GetSchemaReturn>;
|
||||||
export {};
|
export {};
|
||||||
|
4
dist/package-shared/actions/get-schema.js
vendored
4
dist/package-shared/actions/get-schema.js
vendored
@ -18,8 +18,8 @@ const grab_host_names_1 = __importDefault(require("../utils/grab-host-names"));
|
|||||||
* # Get Schema for Database, table, or field *
|
* # Get Schema for Database, table, or field *
|
||||||
*/
|
*/
|
||||||
function getSchema(_a) {
|
function getSchema(_a) {
|
||||||
return __awaiter(this, arguments, void 0, function* ({ key, database, field, table, user_id, }) {
|
return __awaiter(this, arguments, void 0, function* ({ key, database, field, table, user_id, env, }) {
|
||||||
const grabedHostNames = (0, grab_host_names_1.default)();
|
const grabedHostNames = (0, grab_host_names_1.default)({ env });
|
||||||
const { host, port, scheme } = grabedHostNames;
|
const { host, port, scheme } = grabedHostNames;
|
||||||
/**
|
/**
|
||||||
* Make https request
|
* Make https request
|
||||||
|
3
dist/package-shared/types/index.d.ts
vendored
3
dist/package-shared/types/index.d.ts
vendored
@ -290,6 +290,9 @@ export interface GetSchemaRequestQuery {
|
|||||||
table?: string;
|
table?: string;
|
||||||
field?: string;
|
field?: string;
|
||||||
user_id?: string | number;
|
user_id?: string | number;
|
||||||
|
env?: {
|
||||||
|
[k: string]: string;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
export interface GetSchemaAPICredentialsParam {
|
export interface GetSchemaAPICredentialsParam {
|
||||||
key: string;
|
key: string;
|
||||||
|
@ -8,6 +8,9 @@ type GrabHostNamesReturn = {
|
|||||||
};
|
};
|
||||||
type Param = {
|
type Param = {
|
||||||
userId?: string | number;
|
userId?: string | number;
|
||||||
|
env?: {
|
||||||
|
[k: string]: string;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* # Grab Names For Query
|
* # Grab Names For Query
|
||||||
|
18
dist/package-shared/utils/grab-host-names.js
vendored
18
dist/package-shared/utils/grab-host-names.js
vendored
@ -12,19 +12,21 @@ const http_1 = __importDefault(require("http"));
|
|||||||
*/
|
*/
|
||||||
function grabHostNames(param) {
|
function grabHostNames(param) {
|
||||||
var _a, _b;
|
var _a, _b;
|
||||||
const scheme = process.env.DSQL_HTTP_SCHEME;
|
const finalEnv = (param === null || param === void 0 ? void 0 : param.env)
|
||||||
const localHost = process.env.DSQL_LOCAL_HOST;
|
? Object.assign(Object.assign({}, process.env), param.env) : process.env;
|
||||||
const localHostPort = process.env.DSQL_LOCAL_HOST_PORT;
|
const scheme = finalEnv["DSQL_HTTP_SCHEME"];
|
||||||
const remoteHost = ((_a = process.env.DSQL_API_REMOTE_HOST) === null || _a === void 0 ? void 0 : _a.match(/.*\..*/))
|
const localHost = finalEnv["DSQL_LOCAL_HOST"];
|
||||||
? process.env.DSQL_API_REMOTE_HOST
|
const localHostPort = finalEnv["DSQL_LOCAL_HOST_PORT"];
|
||||||
|
const remoteHost = ((_a = finalEnv["DSQL_API_REMOTE_HOST"]) === null || _a === void 0 ? void 0 : _a.match(/.*\..*/))
|
||||||
|
? finalEnv["DSQL_API_REMOTE_HOST"]
|
||||||
: undefined;
|
: undefined;
|
||||||
const remoteHostPort = ((_b = process.env.DSQL_API_REMOTE_HOST_PORT) === null || _b === void 0 ? void 0 : _b.match(/./))
|
const remoteHostPort = ((_b = finalEnv["DSQL_API_REMOTE_HOST_PORT"]) === null || _b === void 0 ? void 0 : _b.match(/./))
|
||||||
? process.env.DSQL_API_REMOTE_HOST_PORT
|
? finalEnv["DSQL_API_REMOTE_HOST_PORT"]
|
||||||
: undefined;
|
: undefined;
|
||||||
return {
|
return {
|
||||||
host: remoteHost || localHost || "datasquirel.com",
|
host: remoteHost || localHost || "datasquirel.com",
|
||||||
port: remoteHostPort || localHostPort || 443,
|
port: remoteHostPort || localHostPort || 443,
|
||||||
scheme: (scheme === null || scheme === void 0 ? void 0 : scheme.match(/^http$/i)) ? http_1.default : https_1.default,
|
scheme: (scheme === null || scheme === void 0 ? void 0 : scheme.match(/^http$/i)) ? http_1.default : https_1.default,
|
||||||
user_id: (param === null || param === void 0 ? void 0 : param.userId) || String(process.env.DSQL_API_USER_ID || 0),
|
user_id: (param === null || param === void 0 ? void 0 : param.userId) || String(finalEnv["DSQL_API_USER_ID"] || 0),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,11 @@ const args = parseArgs({
|
|||||||
default: process.env.DSQL_DB_NAME,
|
default: process.env.DSQL_DB_NAME,
|
||||||
short: "d",
|
short: "d",
|
||||||
},
|
},
|
||||||
|
userid: {
|
||||||
|
type: "string",
|
||||||
|
default: process.env.DSQL_API_USER_ID,
|
||||||
|
short: "i",
|
||||||
|
},
|
||||||
outfile: {
|
outfile: {
|
||||||
type: "string",
|
type: "string",
|
||||||
short: "o",
|
short: "o",
|
||||||
@ -58,11 +63,14 @@ if (args.values.envfile && typeof args.values.envfile == "string") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const finalEnv = { ...process.env, ...appendedEnv };
|
const finalEnv = { ...process.env, ...appendedEnv };
|
||||||
|
process.env = { ...process.env, ...appendedEnv };
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
const key = args.values.apiKey || finalEnv["DSQL_FULL_ACCESS_API_KEY"];
|
const key = args.values.apiKey || finalEnv["DSQL_FULL_ACCESS_API_KEY"];
|
||||||
const database = args.values.database || finalEnv["DSQL_DB_NAME"];
|
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 (args.values.debug) {
|
||||||
debugLog({
|
debugLog({
|
||||||
@ -91,15 +99,26 @@ const finalEnv = { ...process.env, ...appendedEnv };
|
|||||||
throw new Error("API key is required");
|
throw new Error("API key is required");
|
||||||
if (!args.values.outfile || typeof args.values.outfile !== "string")
|
if (!args.values.outfile || typeof args.values.outfile !== "string")
|
||||||
throw new Error("Outfile are required");
|
throw new Error("Outfile are required");
|
||||||
|
if (!user_id || typeof user_id !== "string")
|
||||||
|
throw new Error("Outfile are required");
|
||||||
|
|
||||||
const schema = await datasquirel.getSchema({
|
const schema = await datasquirel.getSchema({
|
||||||
key,
|
key,
|
||||||
database,
|
database,
|
||||||
user_id: 1,
|
user_id,
|
||||||
});
|
});
|
||||||
|
|
||||||
const dbSchema = schema.payload as DSQL_DatabaseSchemaType | undefined;
|
const dbSchema = schema.payload as DSQL_DatabaseSchemaType | undefined;
|
||||||
|
|
||||||
|
if (args.values.debug) {
|
||||||
|
debugLog({
|
||||||
|
log: schema,
|
||||||
|
label: "schema",
|
||||||
|
title: "Schema to Typedef",
|
||||||
|
addTime: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (!dbSchema) throw new Error("No schema found");
|
if (!dbSchema) throw new Error("No schema found");
|
||||||
|
|
||||||
const definitions = dbSchemaToType({ dbSchema });
|
const definitions = dbSchemaToType({ dbSchema });
|
||||||
|
@ -25,8 +25,9 @@ export default async function getSchema({
|
|||||||
field,
|
field,
|
||||||
table,
|
table,
|
||||||
user_id,
|
user_id,
|
||||||
|
env,
|
||||||
}: GetSchemaAPIParam): Promise<GetSchemaReturn> {
|
}: GetSchemaAPIParam): Promise<GetSchemaReturn> {
|
||||||
const grabedHostNames = grabHostNames();
|
const grabedHostNames = grabHostNames({ env });
|
||||||
const { host, port, scheme } = grabedHostNames;
|
const { host, port, scheme } = grabedHostNames;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -305,6 +305,7 @@ export interface GetSchemaRequestQuery {
|
|||||||
table?: string;
|
table?: string;
|
||||||
field?: string;
|
field?: string;
|
||||||
user_id?: string | number;
|
user_id?: string | number;
|
||||||
|
env?: { [k: string]: string };
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GetSchemaAPICredentialsParam {
|
export interface GetSchemaAPICredentialsParam {
|
||||||
|
@ -12,26 +12,31 @@ type GrabHostNamesReturn = {
|
|||||||
|
|
||||||
type Param = {
|
type Param = {
|
||||||
userId?: string | number;
|
userId?: string | number;
|
||||||
|
env?: { [k: string]: string };
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* # Grab Names For Query
|
* # Grab Names For Query
|
||||||
*/
|
*/
|
||||||
export default function grabHostNames(param?: Param): GrabHostNamesReturn {
|
export default function grabHostNames(param?: Param): GrabHostNamesReturn {
|
||||||
const scheme = process.env.DSQL_HTTP_SCHEME;
|
const finalEnv = param?.env
|
||||||
const localHost = process.env.DSQL_LOCAL_HOST;
|
? { ...process.env, ...param.env }
|
||||||
const localHostPort = process.env.DSQL_LOCAL_HOST_PORT;
|
: process.env;
|
||||||
const remoteHost = process.env.DSQL_API_REMOTE_HOST?.match(/.*\..*/)
|
|
||||||
? process.env.DSQL_API_REMOTE_HOST
|
const scheme = finalEnv["DSQL_HTTP_SCHEME"];
|
||||||
|
const localHost = finalEnv["DSQL_LOCAL_HOST"];
|
||||||
|
const localHostPort = finalEnv["DSQL_LOCAL_HOST_PORT"];
|
||||||
|
const remoteHost = finalEnv["DSQL_API_REMOTE_HOST"]?.match(/.*\..*/)
|
||||||
|
? finalEnv["DSQL_API_REMOTE_HOST"]
|
||||||
: undefined;
|
: undefined;
|
||||||
const remoteHostPort = process.env.DSQL_API_REMOTE_HOST_PORT?.match(/./)
|
const remoteHostPort = finalEnv["DSQL_API_REMOTE_HOST_PORT"]?.match(/./)
|
||||||
? process.env.DSQL_API_REMOTE_HOST_PORT
|
? finalEnv["DSQL_API_REMOTE_HOST_PORT"]
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
host: remoteHost || localHost || "datasquirel.com",
|
host: remoteHost || localHost || "datasquirel.com",
|
||||||
port: remoteHostPort || localHostPort || 443,
|
port: remoteHostPort || localHostPort || 443,
|
||||||
scheme: scheme?.match(/^http$/i) ? http : https,
|
scheme: scheme?.match(/^http$/i) ? http : https,
|
||||||
user_id: param?.userId || String(process.env.DSQL_API_USER_ID || 0),
|
user_id: param?.userId || String(finalEnv["DSQL_API_USER_ID"] || 0),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@moduletrace/datasquirel",
|
"name": "@moduletrace/datasquirel",
|
||||||
"version": "4.3.5",
|
"version": "4.3.6",
|
||||||
"description": "Cloud-based SQL data management tool",
|
"description": "Cloud-based SQL data management tool",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
Loading…
Reference in New Issue
Block a user