Updates
This commit is contained in:
@@ -2,11 +2,14 @@ import path from "path";
|
||||
|
||||
import { OutgoingHttpHeaders } from "http";
|
||||
import {
|
||||
APIConnectionOptions,
|
||||
APIResponseObject,
|
||||
DataCrudRequestMethods,
|
||||
DataCrudRequestMethodsLowerCase,
|
||||
} from "../../types";
|
||||
import grabHostNames from "../../utils/grab-host-names";
|
||||
import grabHostNames, {
|
||||
GrabHostNamesReturn,
|
||||
} from "../../utils/grab-host-names";
|
||||
import serializeQuery from "../../utils/serialize-query";
|
||||
import { RequestOptions } from "https";
|
||||
import _ from "lodash";
|
||||
@@ -20,6 +23,8 @@ type Param<T = { [k: string]: any }> = {
|
||||
| (typeof DataCrudRequestMethods)[number]
|
||||
| (typeof DataCrudRequestMethodsLowerCase)[number];
|
||||
apiKey?: string;
|
||||
apiConnectionConfig?: APIConnectionOptions;
|
||||
grabbedHostnames?: GrabHostNamesReturn;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -35,10 +40,22 @@ export default async function queryDSQLAPI<
|
||||
path: passedPath,
|
||||
method,
|
||||
apiKey,
|
||||
apiConnectionConfig,
|
||||
grabbedHostnames,
|
||||
}: Param<T>): Promise<APIResponseObject<P>> {
|
||||
const grabedHostNames = grabHostNames({ useDefault });
|
||||
const grabedHostNames =
|
||||
grabbedHostnames || grabHostNames({ useDefault, apiConnectionConfig });
|
||||
const { host, port, scheme } = grabedHostNames;
|
||||
|
||||
const finalAPIKey =
|
||||
apiKey ||
|
||||
apiConnectionConfig?.apiKey ||
|
||||
(!method || method == "GET" || method == "get"
|
||||
? process.env.DSQL_READ_ONLY_API_KEY
|
||||
: undefined) ||
|
||||
process.env.DSQL_FULL_ACCESS_API_KEY ||
|
||||
process.env.DSQL_API_KEY;
|
||||
|
||||
try {
|
||||
/**
|
||||
* Make https request
|
||||
@@ -50,13 +67,7 @@ export default async function queryDSQLAPI<
|
||||
|
||||
let headers: OutgoingHttpHeaders = {
|
||||
"Content-Type": "application/json",
|
||||
Authorization:
|
||||
apiKey ||
|
||||
(!method || method == "GET" || method == "get"
|
||||
? process.env.DSQL_READ_ONLY_API_KEY
|
||||
: undefined) ||
|
||||
process.env.DSQL_FULL_ACCESS_API_KEY ||
|
||||
process.env.DSQL_API_KEY,
|
||||
Authorization: finalAPIKey,
|
||||
};
|
||||
|
||||
if (reqPayload) {
|
||||
|
||||
@@ -1,35 +1,15 @@
|
||||
import fs from "fs";
|
||||
import grabDirNames from "../../utils/backend/names/grab-dir-names";
|
||||
import {
|
||||
DSQL_DatabaseSchemaType,
|
||||
DSQL_FieldSchemaType,
|
||||
DSQL_TableSchemaType,
|
||||
} from "../../types";
|
||||
import { DSQL_DatabaseSchemaType, DSQL_TableSchemaType } from "../../types";
|
||||
import _ from "lodash";
|
||||
import EJSON from "../../utils/ejson";
|
||||
import generateTypeDefinition from "./generate-type-definitions";
|
||||
import { AppNames } from "../../dict/app-names";
|
||||
import defaultFields from "../../data/defaultFields.json";
|
||||
|
||||
type Params = {
|
||||
dbSchema?: DSQL_DatabaseSchemaType;
|
||||
};
|
||||
|
||||
export default function dbSchemaToType(params?: Params): string[] | undefined {
|
||||
let datasquirelSchema;
|
||||
const { mainShemaJSONFilePath, defaultTableFieldsJSONFilePath } =
|
||||
grabDirNames();
|
||||
|
||||
if (params?.dbSchema) {
|
||||
datasquirelSchema = params.dbSchema;
|
||||
} else {
|
||||
const mainSchema = EJSON.parse(
|
||||
fs.readFileSync(mainShemaJSONFilePath, "utf-8")
|
||||
) as DSQL_DatabaseSchemaType[];
|
||||
|
||||
datasquirelSchema = mainSchema.find(
|
||||
(sch) => sch.dbFullName == "datasquirel"
|
||||
);
|
||||
}
|
||||
let datasquirelSchema = params?.dbSchema;
|
||||
|
||||
if (!datasquirelSchema) return;
|
||||
|
||||
@@ -37,10 +17,6 @@ export default function dbSchemaToType(params?: Params): string[] | undefined {
|
||||
.map((tbl) => ` "${tbl.tableName}",`)
|
||||
.join("\n")}\n] as const`;
|
||||
|
||||
const defaultFields = EJSON.parse(
|
||||
fs.readFileSync(defaultTableFieldsJSONFilePath, "utf-8")
|
||||
) as DSQL_FieldSchemaType[];
|
||||
|
||||
const dbTablesSchemas = datasquirelSchema.tables.map((tblSchm) => {
|
||||
let newDefaultFields = _.cloneDeep(defaultFields);
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user