datasquirel/package-shared/api/schema/get.ts
Benjamin Toby 700a704abd Updates
2025-08-13 11:16:28 +01:00

57 lines
1.3 KiB
TypeScript

import path from "path";
import queryDSQLAPI from "../../functions/api/query-dsql-api";
import {
APIConnectionOptions,
APIResponseObject,
DSQL_DatabaseSchemaType,
DSQL_FieldSchemaType,
DSQL_TableSchemaType,
} from "../../types";
import grabAPIBasePath from "../../utils/grab-api-base-path";
import { GrabHostNamesReturn } from "../../utils/grab-host-names";
type Params = {
dbName: string;
tableName?: string;
fieldName?: string;
apiKey?: string;
apiConnectionConfig?: APIConnectionOptions;
grabbedHostnames?: GrabHostNamesReturn;
useDefault?: boolean;
};
export default async function <
T extends
| DSQL_DatabaseSchemaType
| DSQL_TableSchemaType
| DSQL_FieldSchemaType = DSQL_DatabaseSchemaType
>({
dbName,
tableName,
apiKey,
useDefault,
fieldName,
apiConnectionConfig,
grabbedHostnames,
}: Params): Promise<APIResponseObject<T>> {
const basePath = grabAPIBasePath({ paradigm: "schema" });
const finalPath = path.join(
basePath,
dbName,
tableName || "",
fieldName || ""
);
const GET_RES = await queryDSQLAPI<any, T>({
method: "GET",
path: finalPath,
apiKey,
useDefault,
apiConnectionConfig,
grabbedHostnames,
});
return GET_RES;
}