This commit is contained in:
Benjamin Toby
2025-07-28 07:23:45 +01:00
parent a429436939
commit 8ac8b8eb51
49 changed files with 475 additions and 177 deletions
@@ -0,0 +1,8 @@
export default function checkArrayDepth(
arr: any[] | any[][] | any[][][] | any,
depth: number
): boolean {
if (!Array.isArray(arr)) return false;
if (depth === 1) return true;
return arr.every((item) => checkArrayDepth(item, depth - 1));
}
+19 -3
View File
@@ -1,6 +1,8 @@
import sqlGenerator from "../../functions/dsql/sql/sql-generator";
import { APIResponseObject, DsqlCrudParam } from "../../types";
import connDbHandler, { ConnDBHandlerQueryObject } from "../db/conn-db-handler";
import checkArrayDepth from "../check-array-depth";
import parseDbResults from "../../functions/backend/parseDbResults";
export default async function <
T extends { [key: string]: any } = { [key: string]: any }
@@ -10,6 +12,7 @@ export default async function <
count,
countOnly,
dbFullName,
tableSchema,
}: Omit<
DsqlCrudParam<T>,
"action" | "data" | "sanitize"
@@ -55,13 +58,26 @@ export default async function <
const res = await connDbHandler(undefined, connQueries);
const parsedRes = checkArrayDepth(res, 2)
? parseDbResults({ unparsedResults: res[0], tableSchema })
: res[0];
const parsedBatchRes = checkArrayDepth(res, 3)
? res.map((_r: any[][]) => {
return parseDbResults({ 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?.error,
payload: isSuccess ? (countOnly ? null : parsedRes) : null,
batchPayload: isSuccess ? (countOnly ? null : parsedBatchRes) : null,
error: isSuccess
? undefined
: typeof res == "object" && !Array.isArray(res)
? res?.error
: undefined,
errors: res?.errors,
queryObject: {
sql: queryObject?.string,
@@ -26,6 +26,7 @@ export default async function dsqlCrud<
batchData,
deleteKeyValues,
debug,
tableSchema,
} = params;
const finalData = (sanitize ? sanitize({ data }) : data) as T;
@@ -47,6 +48,7 @@ export default async function dsqlCrud<
tableName: table,
dbFullName,
debug,
tableSchema,
});
return INSERT_RESULT;
@@ -60,6 +62,7 @@ export default async function dsqlCrud<
identifierColumnName: (targetField || "id") as string,
identifierValue: String(targetValue || targetId),
debug,
tableSchema,
});
return UPDATE_RESULT;
@@ -11,6 +11,7 @@ export default function grabTextFieldType(
if (field.css) return "css";
if (field.javascript) return "javascript";
if (field.shell) return "shell";
if (field.markdown) return "markdown";
if (nullReturn) return undefined;
return "plain";
}
@@ -122,15 +122,16 @@ export default function ({
/**
* Handle scenario where this table is a child of another
*/
if (
currentTableSchema.childTable &&
currentTableSchema.childTableDbId &&
currentTableSchema.childTableDbId
) {
const targetParentDatabase = grabPrimaryRequiredDbSchema({
dbId: currentTableSchema.childTableDbId,
userId,
});
if (currentTableSchema.childTable && currentTableSchema.childTableDbId) {
const isParentDbCurrentDb =
currentTableSchema.childTableDbId == newCurrentDbSchema.id;
const targetParentDatabase = isParentDbCurrentDb
? newCurrentDbSchema
: grabPrimaryRequiredDbSchema({
dbId: currentTableSchema.childTableDbId,
userId,
});
const targetParentDatabaseTableIndex =
targetParentDatabase?.tables.findIndex(
@@ -26,6 +26,7 @@ export default function setTextFieldType(
if (type == "yaml") return { ...newField, yaml: true };
if (type == "javascript") return { ...newField, javascript: true };
if (type == "code") return { ...newField, code: true };
if (type == "markdown") return { ...newField, markdown: true };
return { ...newField };
}
@@ -11,5 +11,6 @@ export default function grabDockerResourceIPNumbers() {
replica_1: 37,
replica_2: 38,
web_app_post_db_setup: 71,
static: 77,
} as const;
}
+37
View File
@@ -0,0 +1,37 @@
import { AIOptions, AIOptionsObject, SiteConfig } from "../types";
type Params = {
userConfig?: SiteConfig | null;
};
export type GrabUserAIConfigReturn = {};
export default function grabUserAIInfo({
userConfig: passedConfig,
}: Params): AIOptionsObject | undefined {
const userConfig: SiteConfig | undefined = passedConfig
? passedConfig
: undefined;
if (!userConfig) return undefined;
const targetAI = userConfig?.main.target_ai;
if (!targetAI?.name || !userConfig?.main.api_keys) return undefined;
const targetAIAPIKey = userConfig.main.api_keys[targetAI.name].key;
if (!targetAIAPIKey) return undefined;
const targetAIOption = AIOptions.find(
(aiOpt) => aiOpt.name == targetAI.name
);
targetAI.apiKey = targetAIAPIKey;
if (targetAIOption?.baseUrl) {
targetAI.baseUrl = targetAIOption.baseUrl;
}
return targetAI;
}