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

18
dist/index.d.ts vendored
View File

@ -1,16 +1,9 @@
import type { Connection } from "mariadb";
declare global { declare global {
var DSQL_DB_CONN: Connection | undefined;
var DSQL_READ_ONLY_DB_CONN: Connection | undefined;
var DSQL_FULL_ACCESS_DB_CONN: Connection | undefined;
var DSQL_USE_LOCAL: boolean | undefined;
var ERROR_CALLBACK: ErrorCallback | undefined; var ERROR_CALLBACK: ErrorCallback | undefined;
} }
import get from "./package-shared/actions/get"; import get from "./package-shared/actions/get";
import post from "./package-shared/actions/post"; import post from "./package-shared/actions/post";
import getSchema from "./package-shared/actions/get-schema"; import getSchema from "./package-shared/actions/get-schema";
import createUser from "./package-shared/actions/users/add-user";
import updateUser from "./package-shared/actions/users/update-user";
import sqlGenerator from "./package-shared/functions/dsql/sql/sql-generator"; import sqlGenerator from "./package-shared/functions/dsql/sql/sql-generator";
import sqlInsertGenerator from "./package-shared/functions/dsql/sql/sql-insert-generator"; import sqlInsertGenerator from "./package-shared/functions/dsql/sql/sql-insert-generator";
import sqlDeleteGenerator from "./package-shared/functions/dsql/sql/sql-delete-generator"; import sqlDeleteGenerator from "./package-shared/functions/dsql/sql/sql-delete-generator";
@ -27,6 +20,7 @@ import { ErrorCallback } from "./package-shared/types";
import parseEnv from "./package-shared/utils/parse-env"; import parseEnv from "./package-shared/utils/parse-env";
import dbHandler from "./package-shared/functions/backend/dbHandler"; import dbHandler from "./package-shared/functions/backend/dbHandler";
import httpsRequest from "./package-shared/functions/backend/httpsRequest"; import httpsRequest from "./package-shared/functions/backend/httpsRequest";
import handleNodemailer from "./package-shared/functions/backend/handleNodemailer";
/** /**
* Main Export * Main Export
*/ */
@ -51,9 +45,9 @@ declare const datasquirel: {
auth: { auth: {
login: typeof import("./package-shared/actions/users/login-user").default; login: typeof import("./package-shared/actions/users/login-user").default;
get: typeof import("./package-shared/actions/users/get-user").default; get: typeof import("./package-shared/actions/users/get-user").default;
signup: typeof createUser; signup: typeof import("./package-shared/actions/users/add-user").default;
sendEmailCode: typeof import("./package-shared/actions/users/send-email-code").default; sendEmailCode: typeof import("./package-shared/actions/users/send-email-code").default;
update: typeof updateUser; update: typeof import("./package-shared/actions/users/update-user").default;
resetPassword: typeof import("./package-shared/actions/users/reset-password").default; resetPassword: typeof import("./package-shared/actions/users/reset-password").default;
googleLogin: typeof import("./package-shared/actions/users/social/google-auth").default; googleLogin: typeof import("./package-shared/actions/users/social/google-auth").default;
logout: typeof import("./package-shared/actions/users/logout-user").default; logout: typeof import("./package-shared/actions/users/logout-user").default;
@ -155,5 +149,11 @@ declare const datasquirel: {
* General Database Handler * General Database Handler
*/ */
dbHandler: typeof dbHandler; dbHandler: typeof dbHandler;
/**
* Handle Mail
*/
mail: {
mailer: typeof handleNodemailer;
};
}; };
export default datasquirel; export default datasquirel;

28
dist/index.js vendored
View File

@ -26,27 +26,7 @@ const local_user_1 = __importDefault(require("./package-shared/api/user/local-us
const media_1 = __importDefault(require("./package-shared/api/media")); const media_1 = __importDefault(require("./package-shared/api/media"));
const dbHandler_1 = __importDefault(require("./package-shared/functions/backend/dbHandler")); const dbHandler_1 = __importDefault(require("./package-shared/functions/backend/dbHandler"));
const httpsRequest_1 = __importDefault(require("./package-shared/functions/backend/httpsRequest")); const httpsRequest_1 = __importDefault(require("./package-shared/functions/backend/httpsRequest"));
/** const handleNodemailer_1 = __importDefault(require("./package-shared/functions/backend/handleNodemailer"));
* User Functions Object
*/
// const user = {
// createUser: createUser,
// deleteUser,
// loginUser: loginUser,
// sendEmailCode: sendEmailCode,
// logoutUser: logoutUser,
// userAuth: userAuth,
// reAuthUser: reAuthUser,
// updateUser: updateUser,
// getUser: getUser,
// getToken: getToken,
// validateToken: validateToken,
// validateTempEmailCode,
// social: {
// loginWithGoogle: loginWithGoogle,
// loginWithGithub: loginWithGithub,
// },
// };
/** /**
* API Functions Object * API Functions Object
*/ */
@ -111,5 +91,11 @@ const datasquirel = {
* General Database Handler * General Database Handler
*/ */
dbHandler: dbHandler_1.default, dbHandler: dbHandler_1.default,
/**
* Handle Mail
*/
mail: {
mailer: handleNodemailer_1.default,
},
}; };
exports.default = datasquirel; exports.default = datasquirel;

View File

@ -56,6 +56,14 @@ declare const DataTypes: readonly [{
readonly name: "LONGTEXT"; readonly name: "LONGTEXT";
readonly value: "0-255"; readonly value: "0-255";
readonly description: "LONGTEXT is just text with max length 4,294,967,295"; readonly description: "LONGTEXT is just text with max length 4,294,967,295";
}, {
readonly title: "OPTIONS";
readonly name: "ENUM";
readonly description: "String options to be selected from";
}, {
readonly title: "BOOLEAN";
readonly name: "BOOLEAN";
readonly description: "True or False. Represented in the database as 0 or 1";
}, { }, {
readonly title: "DECIMAL"; readonly title: "DECIMAL";
readonly name: "DECIMAL"; readonly name: "DECIMAL";

View File

@ -69,6 +69,16 @@ const DataTypes = [
value: "0-255", value: "0-255",
description: "LONGTEXT is just text with max length 4,294,967,295", description: "LONGTEXT is just text with max length 4,294,967,295",
}, },
{
title: "OPTIONS",
name: "ENUM",
description: "String options to be selected from",
},
{
title: "BOOLEAN",
name: "BOOLEAN",
description: "True or False. Represented in the database as 0 or 1",
},
{ {
title: "DECIMAL", title: "DECIMAL",
name: "DECIMAL", name: "DECIMAL",

View File

@ -68,6 +68,16 @@ const DataTypes = [
value: "0-255", value: "0-255",
description: "LONGTEXT is just text with max length 4,294,967,295", description: "LONGTEXT is just text with max length 4,294,967,295",
}, },
{
title: "OPTIONS",
name: "ENUM",
description: "String options to be selected from",
},
{
title: "BOOLEAN",
name: "BOOLEAN",
description: "True or False. Represented in the database as 0 or 1",
},
{ {
title: "DECIMAL", title: "DECIMAL",
name: "DECIMAL", name: "DECIMAL",

View File

@ -8,4 +8,5 @@ export declare const AppNames: {
readonly WebsocketPathname: "dsql-websocket"; readonly WebsocketPathname: "dsql-websocket";
readonly ReverseProxyForwardURLHeaderName: "x-original-uri"; readonly ReverseProxyForwardURLHeaderName: "x-original-uri";
readonly PrivateAPIAuthHeaderName: "x-api-auth-key"; readonly PrivateAPIAuthHeaderName: "x-api-auth-key";
readonly StaticProxyForwardURLHeaderName: "x-media-path";
}; };

View File

@ -11,4 +11,5 @@ exports.AppNames = {
WebsocketPathname: "dsql-websocket", WebsocketPathname: "dsql-websocket",
ReverseProxyForwardURLHeaderName: "x-original-uri", ReverseProxyForwardURLHeaderName: "x-original-uri",
PrivateAPIAuthHeaderName: "x-api-auth-key", PrivateAPIAuthHeaderName: "x-api-auth-key",
StaticProxyForwardURLHeaderName: "x-media-path",
}; };

View File

@ -4,4 +4,6 @@ export declare const LocalStorageDict: {
CSRF: string; CSRF: string;
CurrentQueue: string; CurrentQueue: string;
DiskUsage: string; DiskUsage: string;
MarkdownEditorDefaultSideBySide: string;
MarkdownEditorDefaultPreview: string;
}; };

View File

@ -11,4 +11,6 @@ exports.LocalStorageDict = {
CSRF: (0, get_csrf_header_name_1.default)(), CSRF: (0, get_csrf_header_name_1.default)(),
CurrentQueue: "current_queue", CurrentQueue: "current_queue",
DiskUsage: "disk_usage", DiskUsage: "disk_usage",
MarkdownEditorDefaultSideBySide: "markdown_editor_default_side_by_side",
MarkdownEditorDefaultPreview: "markdown_editor_default_preview",
}; };

View File

@ -27,6 +27,7 @@ function handleSocialDb(_a) {
var _b; var _b;
try { try {
const finalDbName = database; const finalDbName = database;
const MAX_IMAGE_STRING_LENGTH = 350;
const existingSocialUserQUery = `SELECT * FROM users WHERE email = ? AND social_login='1' AND social_platform = ? `; const existingSocialUserQUery = `SELECT * FROM users WHERE email = ? AND social_login='1' AND social_platform = ? `;
const existingSocialUserValues = [email, social_platform]; const existingSocialUserValues = [email, social_platform];
if (debug) { if (debug) {
@ -103,6 +104,12 @@ function handleSocialDb(_a) {
password: socialHashedPassword, password: socialHashedPassword,
}; };
Object.keys(payload).forEach((key) => { Object.keys(payload).forEach((key) => {
if (key.match(/image/)) {
const imageString = payload[key];
if (!imageString ||
imageString.length > MAX_IMAGE_STRING_LENGTH)
return;
}
data[key] = payload[key]; data[key] = payload[key];
}); });
const newUser = yield (0, addDbEntry_1.default)({ const newUser = yield (0, addDbEntry_1.default)({

View File

@ -1,6 +1,7 @@
import { DSQL_TableSchemaType } from "../../types";
type Param = { type Param = {
unparsedResults: any[]; unparsedResults: any[];
tableSchema?: import("../../types").DSQL_TableSchemaType; tableSchema?: DSQL_TableSchemaType;
}; };
/** /**
* Parse Database results * Parse Database results
@ -9,5 +10,5 @@ type Param = {
* function, decrypts encrypted fields, and returns an updated array with no encrypted * function, decrypts encrypted fields, and returns an updated array with no encrypted
* fields * fields
*/ */
export default function parseDbResults({ unparsedResults, tableSchema, }: Param): Promise<any[] | null>; export default function parseDbResults({ unparsedResults, tableSchema, }: Param): any[] | null;
export {}; export {};

View File

@ -1,14 +1,4 @@
"use strict"; "use strict";
// @ts-check
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) { var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod }; return (mod && mod.__esModule) ? mod : { "default": mod };
}; };
@ -23,54 +13,35 @@ const default_fields_regexp_1 = __importDefault(require("../dsql/default-fields-
* function, decrypts encrypted fields, and returns an updated array with no encrypted * function, decrypts encrypted fields, and returns an updated array with no encrypted
* fields * fields
*/ */
function parseDbResults(_a) { function parseDbResults({ unparsedResults, tableSchema, }) {
return __awaiter(this, arguments, void 0, function* ({ unparsedResults, tableSchema, }) { let parsedResults = [];
/** try {
* Declare variables for (let pr = 0; pr < unparsedResults.length; pr++) {
* let result = unparsedResults[pr];
* @description Declare "results" variable let resultFieldNames = Object.keys(result);
*/ for (let i = 0; i < resultFieldNames.length; i++) {
let parsedResults = []; const resultFieldName = resultFieldNames[i];
try { let resultFieldSchema = tableSchema === null || tableSchema === void 0 ? void 0 : tableSchema.fields.find((fld) => fld.fieldName == resultFieldName);
/** if (resultFieldName === null || resultFieldName === void 0 ? void 0 : resultFieldName.match(default_fields_regexp_1.default)) {
* Declare variables continue;
* }
* @description Declare "results" variable let value = result[resultFieldName];
*/ if (typeof value !== "number" && !value) {
for (let pr = 0; pr < unparsedResults.length; pr++) { continue;
let result = unparsedResults[pr]; }
let resultFieldNames = Object.keys(result); if (resultFieldSchema === null || resultFieldSchema === void 0 ? void 0 : resultFieldSchema.encrypted) {
for (let i = 0; i < resultFieldNames.length; i++) { if (value === null || value === void 0 ? void 0 : value.match(/./)) {
const resultFieldName = resultFieldNames[i]; result[resultFieldName] = (0, decrypt_1.default)({
let resultFieldSchema = tableSchema === null || tableSchema === void 0 ? void 0 : tableSchema.fields[i]; encryptedString: value,
if (resultFieldName === null || resultFieldName === void 0 ? void 0 : resultFieldName.match(default_fields_regexp_1.default)) { });
continue;
}
let value = result[resultFieldName];
if (typeof value !== "number" && !value) {
// parsedResults.push(result);
continue;
}
if (resultFieldSchema === null || resultFieldSchema === void 0 ? void 0 : resultFieldSchema.encrypted) {
if (value === null || value === void 0 ? void 0 : value.match(/./)) {
result[resultFieldName] = (0, decrypt_1.default)({
encryptedString: value,
});
}
} }
} }
parsedResults.push(result);
} }
/** parsedResults.push(result);
* Declare variables
*
* @description Declare "results" variable
*/
return parsedResults;
} }
catch ( /** @type {any} */error) { return parsedResults;
console.log("ERROR in parseDbResults Function =>", error.message); }
return unparsedResults; catch (error) {
} return unparsedResults;
}); }
} }

View File

@ -12,5 +12,5 @@ export default function dbGrabUserResource<T extends {
error: any; error: any;
msg: string | undefined; msg: string | undefined;
}; };
count: number | undefined; count: number | null;
}>; }>;

View File

@ -34,7 +34,7 @@ function dbGrabUserResource(params) {
error: result === null || result === void 0 ? void 0 : result.error, error: result === null || result === void 0 ? void 0 : result.error,
msg: result === null || result === void 0 ? void 0 : result.msg, msg: result === null || result === void 0 ? void 0 : result.msg,
}, },
count: typeof (result === null || result === void 0 ? void 0 : result.count) == "number" ? result.count : undefined, count: typeof (result === null || result === void 0 ? void 0 : result.count) == "number" ? result.count : null,
}; };
}); });
} }

View File

@ -10,11 +10,18 @@ const data_type_parser_1 = __importDefault(require("../../utils/db/schema/data-t
* # Generate Table Column Description * # Generate Table Column Description
*/ */
function generateColumnDescription({ columnData, primaryKeySet, }) { function generateColumnDescription({ columnData, primaryKeySet, }) {
const { fieldName, dataType, nullValue, primaryKey, autoIncrement, defaultValue, defaultValueLiteral, onUpdateLiteral, notNullValue, unique, } = columnData; const { fieldName, dataType, nullValue, primaryKey, autoIncrement, defaultValue, defaultValueLiteral, onUpdateLiteral, notNullValue, unique, options, } = columnData;
let fieldEntryText = ""; let fieldEntryText = "";
const finalDataTypeObject = (0, data_type_parser_1.default)(dataType); const finalDataTypeObject = (0, data_type_parser_1.default)(dataType);
const finalDataType = (0, data_type_constructor_1.default)(finalDataTypeObject.type, finalDataTypeObject.limit, finalDataTypeObject.decimal); const finalDataType = (0, data_type_constructor_1.default)(finalDataTypeObject.type, finalDataTypeObject.limit, finalDataTypeObject.decimal);
fieldEntryText += `\`${fieldName}\` ${finalDataType}`; if (finalDataType.match(/enum/i) && (options === null || options === void 0 ? void 0 : options[0])) {
fieldEntryText += `\`${fieldName}\` ${finalDataType}(${options
.map((opt) => `'${opt}'`)
.join(",")})`;
}
else {
fieldEntryText += `\`${fieldName}\` ${finalDataType}`;
}
if (nullValue) { if (nullValue) {
fieldEntryText += " DEFAULT NULL"; fieldEntryText += " DEFAULT NULL";
} }

View File

@ -91,6 +91,7 @@ export type DSQL_DATASQUIREL_USER_DATABASES = {
db_full_name?: string; db_full_name?: string;
db_image?: string; db_image?: string;
db_description?: string; db_description?: string;
db_long_description?: string;
remote_connected?: number; remote_connected?: number;
remote_connection_type?: string; remote_connection_type?: string;
remote_db_full_name?: string; remote_db_full_name?: string;
@ -118,6 +119,7 @@ export type DSQL_DATASQUIREL_USER_DATABASE_TABLES = {
table_name?: string; table_name?: string;
table_slug?: string; table_slug?: string;
table_description?: string; table_description?: string;
table_long_description?: string;
child_table?: number; child_table?: number;
child_table_parent_database_schema_id?: number; child_table_parent_database_schema_id?: number;
child_table_parent_table_schema_id?: number; child_table_parent_table_schema_id?: number;

View File

@ -65,6 +65,9 @@ export declare const TextFieldTypesArray: readonly [{
}, { }, {
readonly title: "Rich Text"; readonly title: "Rich Text";
readonly value: "richText"; readonly value: "richText";
}, {
readonly title: "Markdown";
readonly value: "markdown";
}, { }, {
readonly title: "JSON"; readonly title: "JSON";
readonly value: "json"; readonly value: "json";
@ -90,6 +93,7 @@ export declare const TextFieldTypesArray: readonly [{
export type DSQL_FieldSchemaType = { export type DSQL_FieldSchemaType = {
id?: number | string; id?: number | string;
fieldName?: string; fieldName?: string;
fieldDescription?: string;
originName?: string; originName?: string;
updatedField?: boolean; updatedField?: boolean;
dataType?: string; dataType?: string;
@ -1259,6 +1263,7 @@ export type DsqlCrudParam<T extends {
countOnly?: boolean; countOnly?: boolean;
dbFullName?: string; dbFullName?: string;
dbName?: string; dbName?: string;
tableSchema?: DSQL_TableSchemaType;
}; };
export type ErrorCallback = (title: string, error: Error, data?: any) => void; export type ErrorCallback = (title: string, error: Error, data?: any) => void;
export interface MariaDBUser { export interface MariaDBUser {
@ -1707,6 +1712,17 @@ export type SiteConfigMain = {
sharp_image_quality?: SiteConfigMainValue; sharp_image_quality?: SiteConfigMainValue;
max_backups?: SiteConfigMainValue; max_backups?: SiteConfigMainValue;
max_disk_usage?: SiteConfigMainValue; max_disk_usage?: SiteConfigMainValue;
api_keys?: SiteConfigMainAPIKeysObject;
target_ai?: AIOptionsObject;
};
export type SiteConfigMainAPIKeysObject = {
[k: string]: SiteConfigMainAPIKeysObjectInfo;
};
export type SiteConfigMainAPIKeysObjectInfo = {
key?: string;
id?: string;
model?: string;
custom_model?: string;
}; };
export type SiteConfigMainValue = { export type SiteConfigMainValue = {
value: number | null; value: number | null;
@ -2051,8 +2067,22 @@ export interface GiteaTreeResTree {
sha: string; sha: string;
url: string; url: string;
} }
export declare const OpsActions: readonly ["exit", "test", "restart-web-app", "restart-db", "restart-all", "clear"]; export declare const OpsActions: readonly ["exit", "test", "restart-web-app", "restart-web-app-container", "restart-db", "restart-all", "clear"];
export type OpsObject = { export type OpsObject = {
action: (typeof OpsActions)[number]; action: (typeof OpsActions)[number];
}; };
export declare const AIOptions: AIOptionsObject[];
export type AIOptionsObject = {
name?: string;
title?: string;
models?: string[];
targetModel?: string;
customModel?: string;
apiKey?: string;
baseUrl?: string;
};
export type AIComponentProps = {
targetAI: AIOptionsObject;
context: any[];
};
export {}; export {};

View File

@ -1,6 +1,6 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.OpsActions = exports.TimeParadigms = exports.UserAPIAuthActions = exports.UserAPIParadigms = exports.TargetMediaParadigms = exports.EnvKeys = exports.AppVersions = exports.APIParadigms = exports.UserSQLPermissions = exports.SQLPermissions = exports.InvitedUserSelectFields = exports.DelegatedUserSelectFields = exports.UserSelectFields = exports.IndexTypes = exports.DefaultSQLValuesLiteral = exports.CurrentlyEditedFieldActions = exports.VideoMimeTypes = exports.FileMimeTypes = exports.ImageMimeTypes = exports.MediaTypes = exports.DockerComposeServices = exports.DatasquirelWindowEvents = exports.WebSocketEvents = exports.QueueJobTypes = exports.SignUpParadigms = exports.UserTypes = exports.QueryFields = exports.DsqlCrudActions = exports.DataCrudRequestMethodsLowerCase = exports.DataCrudRequestMethods = exports.ServerQueryEqualities = exports.ServerQueryOperators = exports.TextFieldTypesArray = exports.UsersOmitedFields = void 0; exports.AIOptions = exports.OpsActions = exports.TimeParadigms = exports.UserAPIAuthActions = exports.UserAPIParadigms = exports.TargetMediaParadigms = exports.EnvKeys = exports.AppVersions = exports.APIParadigms = exports.UserSQLPermissions = exports.SQLPermissions = exports.InvitedUserSelectFields = exports.DelegatedUserSelectFields = exports.UserSelectFields = exports.IndexTypes = exports.DefaultSQLValuesLiteral = exports.CurrentlyEditedFieldActions = exports.VideoMimeTypes = exports.FileMimeTypes = exports.ImageMimeTypes = exports.MediaTypes = exports.DockerComposeServices = exports.DatasquirelWindowEvents = exports.WebSocketEvents = exports.QueueJobTypes = exports.SignUpParadigms = exports.UserTypes = exports.QueryFields = exports.DsqlCrudActions = exports.DataCrudRequestMethodsLowerCase = exports.DataCrudRequestMethods = exports.ServerQueryEqualities = exports.ServerQueryOperators = exports.TextFieldTypesArray = exports.UsersOmitedFields = void 0;
exports.UsersOmitedFields = [ exports.UsersOmitedFields = [
"password", "password",
"social_id", "social_id",
@ -15,6 +15,7 @@ exports.UsersOmitedFields = [
exports.TextFieldTypesArray = [ exports.TextFieldTypesArray = [
{ title: "Plain Text", value: "plain" }, { title: "Plain Text", value: "plain" },
{ title: "Rich Text", value: "richText" }, { title: "Rich Text", value: "richText" },
{ title: "Markdown", value: "markdown" },
{ title: "JSON", value: "json" }, { title: "JSON", value: "json" },
{ title: "YAML", value: "yaml" }, { title: "YAML", value: "yaml" },
{ title: "HTML", value: "html" }, { title: "HTML", value: "html" },
@ -447,7 +448,59 @@ exports.OpsActions = [
"exit", "exit",
"test", "test",
"restart-web-app", "restart-web-app",
"restart-web-app-container",
"restart-db", "restart-db",
"restart-all", "restart-all",
"clear", "clear",
]; ];
exports.AIOptions = [
{
name: "openai",
title: "Open AI",
models: [
"gpt-4.1",
"gpt-4o",
"gpt-4o-audio",
"04-mini",
"o3",
"o3-pro",
"o3-mini",
"o1",
"o1-mini",
"o1-pro",
],
},
{
name: "xai",
title: "X-AI",
baseUrl: "https://api.x.ai/v1",
models: [
"grok-4-0709",
"grok-3",
"grok-3-mini",
"grok-3-fast",
"grok-3-mini-fast",
],
},
{
name: "anthropic",
models: [
"claude-opus-4-0",
"claude-sonnet-4-0",
"claude-3-7-sonnet-latest",
"claude-3-5-sonnet-latest",
"claude-3-5-haiku-latest",
],
},
{
name: "gemini",
models: [
"gemini-2.5-pro",
"gemini-2.5-flash",
"gemini-2.5-flash-lite",
"gemini-2.5-flash-preview-tts",
"gemini-2.5-pro-preview-tts",
"gemini-2.0-flash",
],
},
];

View File

@ -0,0 +1 @@
export default function checkArrayDepth(arr: any[] | any[][] | any[][][] | any, depth: number): boolean;

View File

@ -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));
}

View File

@ -3,4 +3,4 @@ export default function <T extends {
[key: string]: any; [key: string]: any;
} = { } = {
[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>;

View File

@ -15,8 +15,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.default = default_1; exports.default = default_1;
const sql_generator_1 = __importDefault(require("../../functions/dsql/sql/sql-generator")); const sql_generator_1 = __importDefault(require("../../functions/dsql/sql/sql-generator"));
const conn_db_handler_1 = __importDefault(require("../db/conn-db-handler")); 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) { 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; var _b, _c, _d, _e;
let queryObject; let queryObject;
queryObject = (0, sql_generator_1.default)({ 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 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]); const isSuccess = Array.isArray(res) && Array.isArray(res[0]);
return { return {
success: isSuccess, success: isSuccess,
payload: isSuccess ? (countOnly ? null : res[0]) : null, payload: isSuccess ? (countOnly ? null : parsedRes) : null,
batchPayload: isSuccess ? (countOnly ? null : res) : null, batchPayload: isSuccess ? (countOnly ? null : parsedBatchRes) : null,
error: isSuccess ? undefined : res === null || res === void 0 ? void 0 : res.error, 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, errors: res === null || res === void 0 ? void 0 : res.errors,
queryObject: { queryObject: {
sql: queryObject === null || queryObject === void 0 ? void 0 : queryObject.string, sql: queryObject === null || queryObject === void 0 ? void 0 : queryObject.string,

View File

@ -20,7 +20,7 @@ const addDbEntry_1 = __importDefault(require("../../functions/backend/db/addDbEn
const updateDbEntry_1 = __importDefault(require("../../functions/backend/db/updateDbEntry")); const updateDbEntry_1 = __importDefault(require("../../functions/backend/db/updateDbEntry"));
function dsqlCrud(params) { function dsqlCrud(params) {
return __awaiter(this, void 0, void 0, function* () { 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 finalData = (sanitize ? sanitize({ data }) : data);
const finalBatchData = (sanitize ? sanitize({ batchData }) : batchData); const finalBatchData = (sanitize ? sanitize({ batchData }) : batchData);
switch (action) { switch (action) {
@ -35,6 +35,7 @@ function dsqlCrud(params) {
tableName: table, tableName: table,
dbFullName, dbFullName,
debug, debug,
tableSchema,
}); });
return INSERT_RESULT; return INSERT_RESULT;
case "update": case "update":
@ -46,6 +47,7 @@ function dsqlCrud(params) {
identifierColumnName: (targetField || "id"), identifierColumnName: (targetField || "id"),
identifierValue: String(targetValue || targetId), identifierValue: String(targetValue || targetId),
debug, debug,
tableSchema,
}); });
return UPDATE_RESULT; return UPDATE_RESULT;
case "delete": case "delete":

View File

@ -16,6 +16,8 @@ function grabTextFieldType(field, nullReturn) {
return "javascript"; return "javascript";
if (field.shell) if (field.shell)
return "shell"; return "shell";
if (field.markdown)
return "markdown";
if (nullReturn) if (nullReturn)
return undefined; return undefined;
return "plain"; return "plain";

View File

@ -68,13 +68,14 @@ function default_1({ currentDbSchema, currentTableSchema, currentTableSchemaInde
/** /**
* Handle scenario where this table is a child of another * Handle scenario where this table is a child of another
*/ */
if (currentTableSchema.childTable && if (currentTableSchema.childTable && currentTableSchema.childTableDbId) {
currentTableSchema.childTableDbId && const isParentDbCurrentDb = currentTableSchema.childTableDbId == newCurrentDbSchema.id;
currentTableSchema.childTableDbId) { const targetParentDatabase = isParentDbCurrentDb
const targetParentDatabase = (0, grab_required_database_schemas_1.grabPrimaryRequiredDbSchema)({ ? newCurrentDbSchema
dbId: currentTableSchema.childTableDbId, : (0, grab_required_database_schemas_1.grabPrimaryRequiredDbSchema)({
userId, dbId: currentTableSchema.childTableDbId,
}); userId,
});
const targetParentDatabaseTableIndex = targetParentDatabase === null || targetParentDatabase === void 0 ? void 0 : targetParentDatabase.tables.findIndex((tbl) => tbl.id == currentTableSchema.childTableId); const targetParentDatabaseTableIndex = targetParentDatabase === null || targetParentDatabase === void 0 ? void 0 : targetParentDatabase.tables.findIndex((tbl) => tbl.id == currentTableSchema.childTableId);
const targetParentDatabaseTable = typeof targetParentDatabaseTableIndex == "number" const targetParentDatabaseTable = typeof targetParentDatabaseTableIndex == "number"
? targetParentDatabaseTableIndex < 0 ? targetParentDatabaseTableIndex < 0

View File

@ -32,5 +32,7 @@ function setTextFieldType(field, type) {
return Object.assign(Object.assign({}, newField), { javascript: true }); return Object.assign(Object.assign({}, newField), { javascript: true });
if (type == "code") if (type == "code")
return Object.assign(Object.assign({}, newField), { code: true }); return Object.assign(Object.assign({}, newField), { code: true });
if (type == "markdown")
return Object.assign(Object.assign({}, newField), { markdown: true });
return Object.assign({}, newField); return Object.assign({}, newField);
} }

View File

@ -10,4 +10,5 @@ export default function grabDockerResourceIPNumbers(): {
readonly replica_1: 37; readonly replica_1: 37;
readonly replica_2: 38; readonly replica_2: 38;
readonly web_app_post_db_setup: 71; readonly web_app_post_db_setup: 71;
readonly static: 77;
}; };

View File

@ -14,5 +14,6 @@ function grabDockerResourceIPNumbers() {
replica_1: 37, replica_1: 37,
replica_2: 38, replica_2: 38,
web_app_post_db_setup: 71, web_app_post_db_setup: 71,
static: 77,
}; };
} }

View File

@ -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 {};

View File

@ -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;
}

View File

@ -1,10 +1,4 @@
import type { Connection } from "mariadb";
declare global { declare global {
var DSQL_DB_CONN: Connection | undefined;
var DSQL_READ_ONLY_DB_CONN: Connection | undefined;
var DSQL_FULL_ACCESS_DB_CONN: Connection | undefined;
var DSQL_USE_LOCAL: boolean | undefined;
var ERROR_CALLBACK: ErrorCallback | undefined; var ERROR_CALLBACK: ErrorCallback | undefined;
} }
@ -12,9 +6,6 @@ import get from "./package-shared/actions/get";
import post from "./package-shared/actions/post"; import post from "./package-shared/actions/post";
import getSchema from "./package-shared/actions/get-schema"; import getSchema from "./package-shared/actions/get-schema";
import createUser from "./package-shared/actions/users/add-user";
import updateUser from "./package-shared/actions/users/update-user";
import datasquirelClient from "./client"; import datasquirelClient from "./client";
import sqlGenerator from "./package-shared/functions/dsql/sql/sql-generator"; import sqlGenerator from "./package-shared/functions/dsql/sql/sql-generator";
import sqlInsertGenerator from "./package-shared/functions/dsql/sql/sql-insert-generator"; import sqlInsertGenerator from "./package-shared/functions/dsql/sql/sql-insert-generator";
@ -36,28 +27,7 @@ import localUser from "./package-shared/api/user/local-user";
import media from "./package-shared/api/media"; import media from "./package-shared/api/media";
import dbHandler from "./package-shared/functions/backend/dbHandler"; import dbHandler from "./package-shared/functions/backend/dbHandler";
import httpsRequest from "./package-shared/functions/backend/httpsRequest"; import httpsRequest from "./package-shared/functions/backend/httpsRequest";
import handleNodemailer from "./package-shared/functions/backend/handleNodemailer";
/**
* User Functions Object
*/
// const user = {
// createUser: createUser,
// deleteUser,
// loginUser: loginUser,
// sendEmailCode: sendEmailCode,
// logoutUser: logoutUser,
// userAuth: userAuth,
// reAuthUser: reAuthUser,
// updateUser: updateUser,
// getUser: getUser,
// getToken: getToken,
// validateToken: validateToken,
// validateTempEmailCode,
// social: {
// loginWithGoogle: loginWithGoogle,
// loginWithGithub: loginWithGithub,
// },
// };
/** /**
* API Functions Object * API Functions Object
@ -125,6 +95,12 @@ const datasquirel = {
* General Database Handler * General Database Handler
*/ */
dbHandler, dbHandler,
/**
* Handle Mail
*/
mail: {
mailer: handleNodemailer,
},
}; };
export default datasquirel; export default datasquirel;

View File

@ -68,6 +68,16 @@ const DataTypes = [
value: "0-255", value: "0-255",
description: "LONGTEXT is just text with max length 4,294,967,295", description: "LONGTEXT is just text with max length 4,294,967,295",
}, },
{
title: "OPTIONS",
name: "ENUM",
description: "String options to be selected from",
},
{
title: "BOOLEAN",
name: "BOOLEAN",
description: "True or False. Represented in the database as 0 or 1",
},
{ {
title: "DECIMAL", title: "DECIMAL",
name: "DECIMAL", name: "DECIMAL",

View File

@ -8,4 +8,5 @@ export const AppNames = {
WebsocketPathname: "dsql-websocket", WebsocketPathname: "dsql-websocket",
ReverseProxyForwardURLHeaderName: "x-original-uri", ReverseProxyForwardURLHeaderName: "x-original-uri",
PrivateAPIAuthHeaderName: "x-api-auth-key", PrivateAPIAuthHeaderName: "x-api-auth-key",
StaticProxyForwardURLHeaderName: "x-media-path",
} as const; } as const;

View File

@ -6,4 +6,6 @@ export const LocalStorageDict = {
CSRF: getCsrfHeaderName(), CSRF: getCsrfHeaderName(),
CurrentQueue: "current_queue", CurrentQueue: "current_queue",
DiskUsage: "disk_usage", DiskUsage: "disk_usage",
MarkdownEditorDefaultSideBySide: "markdown_editor_default_side_by_side",
MarkdownEditorDefaultPreview: "markdown_editor_default_preview",
}; };

View File

@ -26,6 +26,7 @@ export default async function handleSocialDb({
}: HandleSocialDbFunctionParams): Promise<APIResponseObject> { }: HandleSocialDbFunctionParams): Promise<APIResponseObject> {
try { try {
const finalDbName = database; const finalDbName = database;
const MAX_IMAGE_STRING_LENGTH = 350;
const existingSocialUserQUery = `SELECT * FROM users WHERE email = ? AND social_login='1' AND social_platform = ? `; const existingSocialUserQUery = `SELECT * FROM users WHERE email = ? AND social_login='1' AND social_platform = ? `;
const existingSocialUserValues = [email, social_platform]; const existingSocialUserValues = [email, social_platform];
@ -127,6 +128,14 @@ export default async function handleSocialDb({
}; };
Object.keys(payload).forEach((key) => { Object.keys(payload).forEach((key) => {
if (key.match(/image/)) {
const imageString = payload[key] as string | undefined;
if (
!imageString ||
imageString.length > MAX_IMAGE_STRING_LENGTH
)
return;
}
data[key] = payload[key]; data[key] = payload[key];
}); });

View File

@ -1,11 +1,10 @@
// @ts-check import { DSQL_TableSchemaType } from "../../types";
import decrypt from "../dsql/decrypt"; import decrypt from "../dsql/decrypt";
import defaultFieldsRegexp from "../dsql/default-fields-regexp"; import defaultFieldsRegexp from "../dsql/default-fields-regexp";
type Param = { type Param = {
unparsedResults: any[]; unparsedResults: any[];
tableSchema?: import("../../types").DSQL_TableSchemaType; tableSchema?: DSQL_TableSchemaType;
}; };
/** /**
@ -15,23 +14,13 @@ type Param = {
* function, decrypts encrypted fields, and returns an updated array with no encrypted * function, decrypts encrypted fields, and returns an updated array with no encrypted
* fields * fields
*/ */
export default async function parseDbResults({ export default function parseDbResults({
unparsedResults, unparsedResults,
tableSchema, tableSchema,
}: Param): Promise<any[] | null> { }: Param): any[] | null {
/**
* Declare variables
*
* @description Declare "results" variable
*/
let parsedResults = []; let parsedResults = [];
try { try {
/**
* Declare variables
*
* @description Declare "results" variable
*/
for (let pr = 0; pr < unparsedResults.length; pr++) { for (let pr = 0; pr < unparsedResults.length; pr++) {
let result = unparsedResults[pr]; let result = unparsedResults[pr];
@ -39,7 +28,9 @@ export default async function parseDbResults({
for (let i = 0; i < resultFieldNames.length; i++) { for (let i = 0; i < resultFieldNames.length; i++) {
const resultFieldName = resultFieldNames[i]; const resultFieldName = resultFieldNames[i];
let resultFieldSchema = tableSchema?.fields[i]; let resultFieldSchema = tableSchema?.fields.find(
(fld) => fld.fieldName == resultFieldName
);
if (resultFieldName?.match(defaultFieldsRegexp)) { if (resultFieldName?.match(defaultFieldsRegexp)) {
continue; continue;
@ -48,7 +39,6 @@ export default async function parseDbResults({
let value = result[resultFieldName]; let value = result[resultFieldName];
if (typeof value !== "number" && !value) { if (typeof value !== "number" && !value) {
// parsedResults.push(result);
continue; continue;
} }
@ -64,14 +54,8 @@ export default async function parseDbResults({
parsedResults.push(result); parsedResults.push(result);
} }
/**
* Declare variables
*
* @description Declare "results" variable
*/
return parsedResults; return parsedResults;
} catch (/** @type {any} */ error: any) { } catch (error: any) {
console.log("ERROR in parseDbResults Function =>", error.message);
return unparsedResults; return unparsedResults;
} }
} }

View File

@ -27,6 +27,6 @@ export default async function dbGrabUserResource<
error: result?.error, error: result?.error,
msg: result?.msg, msg: result?.msg,
}, },
count: typeof result?.count == "number" ? result.count : undefined, count: typeof result?.count == "number" ? result.count : null,
}; };
} }

View File

@ -30,6 +30,7 @@ export default function generateColumnDescription({
onUpdateLiteral, onUpdateLiteral,
notNullValue, notNullValue,
unique, unique,
options,
} = columnData; } = columnData;
let fieldEntryText = ""; let fieldEntryText = "";
@ -41,7 +42,13 @@ export default function generateColumnDescription({
finalDataTypeObject.decimal finalDataTypeObject.decimal
); );
fieldEntryText += `\`${fieldName}\` ${finalDataType}`; if (finalDataType.match(/enum/i) && options?.[0]) {
fieldEntryText += `\`${fieldName}\` ${finalDataType}(${options
.map((opt) => `'${opt}'`)
.join(",")})`;
} else {
fieldEntryText += `\`${fieldName}\` ${finalDataType}`;
}
if (nullValue) { if (nullValue) {
fieldEntryText += " DEFAULT NULL"; fieldEntryText += " DEFAULT NULL";

View File

@ -118,6 +118,7 @@ export type DSQL_DATASQUIREL_USER_DATABASES = {
db_full_name?: string; db_full_name?: string;
db_image?: string; db_image?: string;
db_description?: string; db_description?: string;
db_long_description?: string;
remote_connected?: number; remote_connected?: number;
remote_connection_type?: string; remote_connection_type?: string;
remote_db_full_name?: string; remote_db_full_name?: string;
@ -146,6 +147,7 @@ export type DSQL_DATASQUIREL_USER_DATABASE_TABLES = {
table_name?: string; table_name?: string;
table_slug?: string; table_slug?: string;
table_description?: string; table_description?: string;
table_long_description?: string;
child_table?: number; child_table?: number;
child_table_parent_database_schema_id?: number; child_table_parent_database_schema_id?: number;
child_table_parent_table_schema_id?: number; child_table_parent_table_schema_id?: number;

View File

@ -107,6 +107,7 @@ export interface DSQL_ChildrenTablesType {
export const TextFieldTypesArray = [ export const TextFieldTypesArray = [
{ title: "Plain Text", value: "plain" }, { title: "Plain Text", value: "plain" },
{ title: "Rich Text", value: "richText" }, { title: "Rich Text", value: "richText" },
{ title: "Markdown", value: "markdown" },
{ title: "JSON", value: "json" }, { title: "JSON", value: "json" },
{ title: "YAML", value: "yaml" }, { title: "YAML", value: "yaml" },
{ title: "HTML", value: "html" }, { title: "HTML", value: "html" },
@ -119,6 +120,7 @@ export const TextFieldTypesArray = [
export type DSQL_FieldSchemaType = { export type DSQL_FieldSchemaType = {
id?: number | string; id?: number | string;
fieldName?: string; fieldName?: string;
fieldDescription?: string;
originName?: string; originName?: string;
updatedField?: boolean; updatedField?: boolean;
dataType?: string; dataType?: string;
@ -1471,6 +1473,7 @@ export type DsqlCrudParam<
countOnly?: boolean; countOnly?: boolean;
dbFullName?: string; dbFullName?: string;
dbName?: string; dbName?: string;
tableSchema?: DSQL_TableSchemaType;
}; };
export type ErrorCallback = (title: string, error: Error, data?: any) => void; export type ErrorCallback = (title: string, error: Error, data?: any) => void;
@ -2137,6 +2140,19 @@ export type SiteConfigMain = {
sharp_image_quality?: SiteConfigMainValue; sharp_image_quality?: SiteConfigMainValue;
max_backups?: SiteConfigMainValue; max_backups?: SiteConfigMainValue;
max_disk_usage?: SiteConfigMainValue; max_disk_usage?: SiteConfigMainValue;
api_keys?: SiteConfigMainAPIKeysObject;
target_ai?: AIOptionsObject;
};
export type SiteConfigMainAPIKeysObject = {
[k: string]: SiteConfigMainAPIKeysObjectInfo;
};
export type SiteConfigMainAPIKeysObjectInfo = {
key?: string;
id?: string;
model?: string;
custom_model?: string;
}; };
export type SiteConfigMainValue = { export type SiteConfigMainValue = {
@ -2629,6 +2645,7 @@ export const OpsActions = [
"exit", "exit",
"test", "test",
"restart-web-app", "restart-web-app",
"restart-web-app-container",
"restart-db", "restart-db",
"restart-all", "restart-all",
"clear", "clear",
@ -2637,3 +2654,70 @@ export const OpsActions = [
export type OpsObject = { export type OpsObject = {
action: (typeof OpsActions)[number]; action: (typeof OpsActions)[number];
}; };
export const AIOptions: AIOptionsObject[] = [
{
name: "openai",
title: "Open AI",
models: [
"gpt-4.1",
"gpt-4o",
"gpt-4o-audio",
"04-mini",
"o3",
"o3-pro",
"o3-mini",
"o1",
"o1-mini",
"o1-pro",
],
},
{
name: "xai",
title: "X-AI",
baseUrl: "https://api.x.ai/v1",
models: [
"grok-4-0709",
"grok-3",
"grok-3-mini",
"grok-3-fast",
"grok-3-mini-fast",
],
},
{
name: "anthropic",
models: [
"claude-opus-4-0",
"claude-sonnet-4-0",
"claude-3-7-sonnet-latest",
"claude-3-5-sonnet-latest",
"claude-3-5-haiku-latest",
],
},
{
name: "gemini",
models: [
"gemini-2.5-pro",
"gemini-2.5-flash",
"gemini-2.5-flash-lite",
"gemini-2.5-flash-preview-tts",
"gemini-2.5-pro-preview-tts",
"gemini-2.0-flash",
],
},
] as const;
export type AIOptionsObject = {
name?: string;
title?: string;
models?: string[];
targetModel?: string;
customModel?: string;
apiKey?: string;
baseUrl?: string;
};
export type AIComponentProps = {
targetAI: AIOptionsObject;
context: any[];
};

View File

@ -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));
}

View File

@ -1,6 +1,8 @@
import sqlGenerator from "../../functions/dsql/sql/sql-generator"; import sqlGenerator from "../../functions/dsql/sql/sql-generator";
import { APIResponseObject, DsqlCrudParam } from "../../types"; import { APIResponseObject, DsqlCrudParam } from "../../types";
import connDbHandler, { ConnDBHandlerQueryObject } from "../db/conn-db-handler"; import connDbHandler, { ConnDBHandlerQueryObject } from "../db/conn-db-handler";
import checkArrayDepth from "../check-array-depth";
import parseDbResults from "../../functions/backend/parseDbResults";
export default async function < export default async function <
T extends { [key: string]: any } = { [key: string]: any } T extends { [key: string]: any } = { [key: string]: any }
@ -10,6 +12,7 @@ export default async function <
count, count,
countOnly, countOnly,
dbFullName, dbFullName,
tableSchema,
}: Omit< }: Omit<
DsqlCrudParam<T>, DsqlCrudParam<T>,
"action" | "data" | "sanitize" "action" | "data" | "sanitize"
@ -55,13 +58,26 @@ export default async function <
const res = await connDbHandler(undefined, connQueries); 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]); const isSuccess = Array.isArray(res) && Array.isArray(res[0]);
return { return {
success: isSuccess, success: isSuccess,
payload: isSuccess ? (countOnly ? null : res[0]) : null, payload: isSuccess ? (countOnly ? null : parsedRes) : null,
batchPayload: isSuccess ? (countOnly ? null : res) : null, batchPayload: isSuccess ? (countOnly ? null : parsedBatchRes) : null,
error: isSuccess ? undefined : res?.error, error: isSuccess
? undefined
: typeof res == "object" && !Array.isArray(res)
? res?.error
: undefined,
errors: res?.errors, errors: res?.errors,
queryObject: { queryObject: {
sql: queryObject?.string, sql: queryObject?.string,

View File

@ -26,6 +26,7 @@ export default async function dsqlCrud<
batchData, batchData,
deleteKeyValues, deleteKeyValues,
debug, debug,
tableSchema,
} = params; } = params;
const finalData = (sanitize ? sanitize({ data }) : data) as T; const finalData = (sanitize ? sanitize({ data }) : data) as T;
@ -47,6 +48,7 @@ export default async function dsqlCrud<
tableName: table, tableName: table,
dbFullName, dbFullName,
debug, debug,
tableSchema,
}); });
return INSERT_RESULT; return INSERT_RESULT;
@ -60,6 +62,7 @@ export default async function dsqlCrud<
identifierColumnName: (targetField || "id") as string, identifierColumnName: (targetField || "id") as string,
identifierValue: String(targetValue || targetId), identifierValue: String(targetValue || targetId),
debug, debug,
tableSchema,
}); });
return UPDATE_RESULT; return UPDATE_RESULT;

View File

@ -11,6 +11,7 @@ export default function grabTextFieldType(
if (field.css) return "css"; if (field.css) return "css";
if (field.javascript) return "javascript"; if (field.javascript) return "javascript";
if (field.shell) return "shell"; if (field.shell) return "shell";
if (field.markdown) return "markdown";
if (nullReturn) return undefined; if (nullReturn) return undefined;
return "plain"; return "plain";
} }

View File

@ -122,15 +122,16 @@ export default function ({
/** /**
* Handle scenario where this table is a child of another * Handle scenario where this table is a child of another
*/ */
if ( if (currentTableSchema.childTable && currentTableSchema.childTableDbId) {
currentTableSchema.childTable && const isParentDbCurrentDb =
currentTableSchema.childTableDbId && currentTableSchema.childTableDbId == newCurrentDbSchema.id;
currentTableSchema.childTableDbId
) { const targetParentDatabase = isParentDbCurrentDb
const targetParentDatabase = grabPrimaryRequiredDbSchema({ ? newCurrentDbSchema
dbId: currentTableSchema.childTableDbId, : grabPrimaryRequiredDbSchema({
userId, dbId: currentTableSchema.childTableDbId,
}); userId,
});
const targetParentDatabaseTableIndex = const targetParentDatabaseTableIndex =
targetParentDatabase?.tables.findIndex( targetParentDatabase?.tables.findIndex(

View File

@ -26,6 +26,7 @@ export default function setTextFieldType(
if (type == "yaml") return { ...newField, yaml: true }; if (type == "yaml") return { ...newField, yaml: true };
if (type == "javascript") return { ...newField, javascript: true }; if (type == "javascript") return { ...newField, javascript: true };
if (type == "code") return { ...newField, code: true }; if (type == "code") return { ...newField, code: true };
if (type == "markdown") return { ...newField, markdown: true };
return { ...newField }; return { ...newField };
} }

View File

@ -11,5 +11,6 @@ export default function grabDockerResourceIPNumbers() {
replica_1: 37, replica_1: 37,
replica_2: 38, replica_2: 38,
web_app_post_db_setup: 71, web_app_post_db_setup: 71,
static: 77,
} as const; } as const;
} }

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;
}

View File

@ -1,6 +1,6 @@
{ {
"name": "@moduletrace/datasquirel", "name": "@moduletrace/datasquirel",
"version": "5.1.0", "version": "5.1.1",
"description": "Cloud-based SQL data management tool", "description": "Cloud-based SQL data management tool",
"main": "dist/index.js", "main": "dist/index.js",
"bin": { "bin": {