Updates
This commit is contained in:
@@ -0,0 +1 @@
|
||||
export default function checkArrayDepth(arr: any[] | any[][] | any[][][] | any, depth: number): boolean;
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = checkArrayDepth;
|
||||
function checkArrayDepth(arr, depth) {
|
||||
if (!Array.isArray(arr))
|
||||
return false;
|
||||
if (depth === 1)
|
||||
return true;
|
||||
return arr.every((item) => checkArrayDepth(item, depth - 1));
|
||||
}
|
||||
+1
-1
@@ -3,4 +3,4 @@ export default function <T extends {
|
||||
[key: string]: any;
|
||||
} = {
|
||||
[key: string]: any;
|
||||
}>({ table, query, count, countOnly, dbFullName, }: Omit<DsqlCrudParam<T>, "action" | "data" | "sanitize">): Promise<APIResponseObject>;
|
||||
}>({ table, query, count, countOnly, dbFullName, tableSchema, }: Omit<DsqlCrudParam<T>, "action" | "data" | "sanitize">): Promise<APIResponseObject>;
|
||||
|
||||
+18
-4
@@ -15,8 +15,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = default_1;
|
||||
const sql_generator_1 = __importDefault(require("../../functions/dsql/sql/sql-generator"));
|
||||
const conn_db_handler_1 = __importDefault(require("../db/conn-db-handler"));
|
||||
const check_array_depth_1 = __importDefault(require("../check-array-depth"));
|
||||
const parseDbResults_1 = __importDefault(require("../../functions/backend/parseDbResults"));
|
||||
function default_1(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ table, query, count, countOnly, dbFullName, }) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ table, query, count, countOnly, dbFullName, tableSchema, }) {
|
||||
var _b, _c, _d, _e;
|
||||
let queryObject;
|
||||
queryObject = (0, sql_generator_1.default)({
|
||||
@@ -53,12 +55,24 @@ function default_1(_a) {
|
||||
];
|
||||
}
|
||||
const res = yield (0, conn_db_handler_1.default)(undefined, connQueries);
|
||||
const parsedRes = (0, check_array_depth_1.default)(res, 2)
|
||||
? (0, parseDbResults_1.default)({ unparsedResults: res[0], tableSchema })
|
||||
: res[0];
|
||||
const parsedBatchRes = (0, check_array_depth_1.default)(res, 3)
|
||||
? res.map((_r) => {
|
||||
return (0, parseDbResults_1.default)({ unparsedResults: _r[0], tableSchema });
|
||||
})
|
||||
: res;
|
||||
const isSuccess = Array.isArray(res) && Array.isArray(res[0]);
|
||||
return {
|
||||
success: isSuccess,
|
||||
payload: isSuccess ? (countOnly ? null : res[0]) : null,
|
||||
batchPayload: isSuccess ? (countOnly ? null : res) : null,
|
||||
error: isSuccess ? undefined : res === null || res === void 0 ? void 0 : res.error,
|
||||
payload: isSuccess ? (countOnly ? null : parsedRes) : null,
|
||||
batchPayload: isSuccess ? (countOnly ? null : parsedBatchRes) : null,
|
||||
error: isSuccess
|
||||
? undefined
|
||||
: typeof res == "object" && !Array.isArray(res)
|
||||
? res === null || res === void 0 ? void 0 : res.error
|
||||
: undefined,
|
||||
errors: res === null || res === void 0 ? void 0 : res.errors,
|
||||
queryObject: {
|
||||
sql: queryObject === null || queryObject === void 0 ? void 0 : queryObject.string,
|
||||
|
||||
+3
-1
@@ -20,7 +20,7 @@ const addDbEntry_1 = __importDefault(require("../../functions/backend/db/addDbEn
|
||||
const updateDbEntry_1 = __importDefault(require("../../functions/backend/db/updateDbEntry"));
|
||||
function dsqlCrud(params) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const { action, data, table, targetValue, sanitize, targetField, targetId, dbFullName, deleteData, batchData, deleteKeyValues, debug, } = params;
|
||||
const { action, data, table, targetValue, sanitize, targetField, targetId, dbFullName, deleteData, batchData, deleteKeyValues, debug, tableSchema, } = params;
|
||||
const finalData = (sanitize ? sanitize({ data }) : data);
|
||||
const finalBatchData = (sanitize ? sanitize({ batchData }) : batchData);
|
||||
switch (action) {
|
||||
@@ -35,6 +35,7 @@ function dsqlCrud(params) {
|
||||
tableName: table,
|
||||
dbFullName,
|
||||
debug,
|
||||
tableSchema,
|
||||
});
|
||||
return INSERT_RESULT;
|
||||
case "update":
|
||||
@@ -46,6 +47,7 @@ function dsqlCrud(params) {
|
||||
identifierColumnName: (targetField || "id"),
|
||||
identifierValue: String(targetValue || targetId),
|
||||
debug,
|
||||
tableSchema,
|
||||
});
|
||||
return UPDATE_RESULT;
|
||||
case "delete":
|
||||
|
||||
@@ -16,6 +16,8 @@ function grabTextFieldType(field, nullReturn) {
|
||||
return "javascript";
|
||||
if (field.shell)
|
||||
return "shell";
|
||||
if (field.markdown)
|
||||
return "markdown";
|
||||
if (nullReturn)
|
||||
return undefined;
|
||||
return "plain";
|
||||
|
||||
+8
-7
@@ -68,13 +68,14 @@ function default_1({ currentDbSchema, currentTableSchema, currentTableSchemaInde
|
||||
/**
|
||||
* Handle scenario where this table is a child of another
|
||||
*/
|
||||
if (currentTableSchema.childTable &&
|
||||
currentTableSchema.childTableDbId &&
|
||||
currentTableSchema.childTableDbId) {
|
||||
const targetParentDatabase = (0, grab_required_database_schemas_1.grabPrimaryRequiredDbSchema)({
|
||||
dbId: currentTableSchema.childTableDbId,
|
||||
userId,
|
||||
});
|
||||
if (currentTableSchema.childTable && currentTableSchema.childTableDbId) {
|
||||
const isParentDbCurrentDb = currentTableSchema.childTableDbId == newCurrentDbSchema.id;
|
||||
const targetParentDatabase = isParentDbCurrentDb
|
||||
? newCurrentDbSchema
|
||||
: (0, grab_required_database_schemas_1.grabPrimaryRequiredDbSchema)({
|
||||
dbId: currentTableSchema.childTableDbId,
|
||||
userId,
|
||||
});
|
||||
const targetParentDatabaseTableIndex = targetParentDatabase === null || targetParentDatabase === void 0 ? void 0 : targetParentDatabase.tables.findIndex((tbl) => tbl.id == currentTableSchema.childTableId);
|
||||
const targetParentDatabaseTable = typeof targetParentDatabaseTableIndex == "number"
|
||||
? targetParentDatabaseTableIndex < 0
|
||||
|
||||
@@ -32,5 +32,7 @@ function setTextFieldType(field, type) {
|
||||
return Object.assign(Object.assign({}, newField), { javascript: true });
|
||||
if (type == "code")
|
||||
return Object.assign(Object.assign({}, newField), { code: true });
|
||||
if (type == "markdown")
|
||||
return Object.assign(Object.assign({}, newField), { markdown: true });
|
||||
return Object.assign({}, newField);
|
||||
}
|
||||
|
||||
@@ -10,4 +10,5 @@ export default function grabDockerResourceIPNumbers(): {
|
||||
readonly replica_1: 37;
|
||||
readonly replica_2: 38;
|
||||
readonly web_app_post_db_setup: 71;
|
||||
readonly static: 77;
|
||||
};
|
||||
|
||||
@@ -14,5 +14,6 @@ function grabDockerResourceIPNumbers() {
|
||||
replica_1: 37,
|
||||
replica_2: 38,
|
||||
web_app_post_db_setup: 71,
|
||||
static: 77,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
import { AIOptionsObject, SiteConfig } from "../types";
|
||||
type Params = {
|
||||
userConfig?: SiteConfig | null;
|
||||
};
|
||||
export type GrabUserAIConfigReturn = {};
|
||||
export default function grabUserAIInfo({ userConfig: passedConfig, }: Params): AIOptionsObject | undefined;
|
||||
export {};
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = grabUserAIInfo;
|
||||
const types_1 = require("../types");
|
||||
function grabUserAIInfo({ userConfig: passedConfig, }) {
|
||||
const userConfig = passedConfig
|
||||
? passedConfig
|
||||
: undefined;
|
||||
if (!userConfig)
|
||||
return undefined;
|
||||
const targetAI = userConfig === null || userConfig === void 0 ? void 0 : userConfig.main.target_ai;
|
||||
if (!(targetAI === null || targetAI === void 0 ? void 0 : targetAI.name) || !(userConfig === null || userConfig === void 0 ? void 0 : userConfig.main.api_keys))
|
||||
return undefined;
|
||||
const targetAIAPIKey = userConfig.main.api_keys[targetAI.name].key;
|
||||
if (!targetAIAPIKey)
|
||||
return undefined;
|
||||
const targetAIOption = types_1.AIOptions.find((aiOpt) => aiOpt.name == targetAI.name);
|
||||
targetAI.apiKey = targetAIAPIKey;
|
||||
if (targetAIOption === null || targetAIOption === void 0 ? void 0 : targetAIOption.baseUrl) {
|
||||
targetAI.baseUrl = targetAIOption.baseUrl;
|
||||
}
|
||||
return targetAI;
|
||||
}
|
||||
Reference in New Issue
Block a user