This commit is contained in:
Benjamin Toby
2025-08-13 11:16:28 +01:00
parent a1e56bb1b0
commit 700a704abd
24 changed files with 400 additions and 260 deletions
+5 -2
View File
@@ -1,4 +1,5 @@
import { APIResponseObject, DataCrudRequestMethods, DataCrudRequestMethodsLowerCase } from "../../types";
import { APIConnectionOptions, APIResponseObject, DataCrudRequestMethods, DataCrudRequestMethodsLowerCase } from "../../types";
import { GrabHostNamesReturn } from "../../utils/grab-host-names";
type Param<T = {
[k: string]: any;
}> = {
@@ -8,6 +9,8 @@ type Param<T = {
path: string;
method?: (typeof DataCrudRequestMethods)[number] | (typeof DataCrudRequestMethodsLowerCase)[number];
apiKey?: string;
apiConnectionConfig?: APIConnectionOptions;
grabbedHostnames?: GrabHostNamesReturn;
};
/**
* # Query DSQL API
@@ -16,5 +19,5 @@ export default function queryDSQLAPI<T = {
[k: string]: any;
}, P = {
[k: string]: any;
}>({ body, query, useDefault, path: passedPath, method, apiKey, }: Param<T>): Promise<APIResponseObject<P>>;
}>({ body, query, useDefault, path: passedPath, method, apiKey, apiConnectionConfig, grabbedHostnames, }: Param<T>): Promise<APIResponseObject<P>>;
export {};
+10 -8
View File
@@ -21,9 +21,16 @@ const lodash_1 = __importDefault(require("lodash"));
* # Query DSQL API
*/
function queryDSQLAPI(_a) {
return __awaiter(this, arguments, void 0, function* ({ body, query, useDefault, path: passedPath, method, apiKey, }) {
const grabedHostNames = (0, grab_host_names_1.default)({ useDefault });
return __awaiter(this, arguments, void 0, function* ({ body, query, useDefault, path: passedPath, method, apiKey, apiConnectionConfig, grabbedHostnames, }) {
const grabedHostNames = grabbedHostnames || (0, grab_host_names_1.default)({ useDefault, apiConnectionConfig });
const { host, port, scheme } = grabedHostNames;
const finalAPIKey = apiKey ||
(apiConnectionConfig === null || apiConnectionConfig === void 0 ? void 0 : 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
@@ -34,12 +41,7 @@ function queryDSQLAPI(_a) {
const reqPayload = body ? JSON.stringify(body) : undefined;
let headers = {
"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) {
headers["Content-Length"] = Buffer.from(reqPayload).length;
+3 -14
View File
@@ -4,31 +4,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = dbSchemaToType;
const fs_1 = __importDefault(require("fs"));
const grab_dir_names_1 = __importDefault(require("../../utils/backend/names/grab-dir-names"));
const lodash_1 = __importDefault(require("lodash"));
const ejson_1 = __importDefault(require("../../utils/ejson"));
const generate_type_definitions_1 = __importDefault(require("./generate-type-definitions"));
const app_names_1 = require("../../dict/app-names");
const defaultFields_json_1 = __importDefault(require("../../data/defaultFields.json"));
function dbSchemaToType(params) {
var _a, _b;
let datasquirelSchema;
const { mainShemaJSONFilePath, defaultTableFieldsJSONFilePath } = (0, grab_dir_names_1.default)();
if (params === null || params === void 0 ? void 0 : params.dbSchema) {
datasquirelSchema = params.dbSchema;
}
else {
const mainSchema = ejson_1.default.parse(fs_1.default.readFileSync(mainShemaJSONFilePath, "utf-8"));
datasquirelSchema = mainSchema.find((sch) => sch.dbFullName == "datasquirel");
}
let datasquirelSchema = params === null || params === void 0 ? void 0 : params.dbSchema;
if (!datasquirelSchema)
return;
let tableNames = `export const DsqlTables = [\n${datasquirelSchema.tables
.map((tbl) => ` "${tbl.tableName}",`)
.join("\n")}\n] as const`;
const defaultFields = ejson_1.default.parse(fs_1.default.readFileSync(defaultTableFieldsJSONFilePath, "utf-8"));
const dbTablesSchemas = datasquirelSchema.tables.map((tblSchm) => {
let newDefaultFields = lodash_1.default.cloneDeep(defaultFields);
let newDefaultFields = lodash_1.default.cloneDeep(defaultFields_json_1.default);
return Object.assign(Object.assign({}, tblSchm), { fields: tblSchm.fields.find((fld) => fld.fieldName == "id")
? tblSchm.fields
: [