This commit is contained in:
Benjamin Toby 2025-01-25 14:20:25 +01:00
parent 1db9c3a2e7
commit e82bcd0824
91 changed files with 936 additions and 324 deletions

View File

@ -1,5 +1,5 @@
import _ from "lodash";
import getCsrfHeaderName from "../../utils/get-csrf-header-name";
import getCsrfHeaderName from "../../package-shared/actions/get-csrf-header-name";
type FetchApiOptions = {
method:

View File

@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = fetchApi;
const lodash_1 = __importDefault(require("lodash"));
const get_csrf_header_name_1 = __importDefault(require("../../utils/get-csrf-header-name"));
const get_csrf_header_name_1 = __importDefault(require("../../package-shared/actions/get-csrf-header-name"));
/**
* # Fetch API
*/

61
dist/index.d.ts vendored
View File

@ -5,27 +5,24 @@ declare global {
var DSQL_FULL_ACCESS_DB_CONN: ServerlessMysql | undefined;
var DSQL_USE_LOCAL: boolean | undefined;
}
/**
* Imports
*/
import get from "./utils/get";
import post from "./utils/post";
import getSchema from "./utils/get-schema";
import uploadImage from "./utils/upload-image";
import uploadFile from "./utils/upload-file";
import deleteFile from "./utils/delete-file";
import createUser from "./users/add-user";
import updateUser from "./users/update-user";
import loginUser from "./users/login-user";
import sendEmailCode from "./users/send-email-code";
import logoutUser from "./users/logout-user";
import userAuth from "./users/user-auth";
import reAuthUser from "./users/reauth-user";
import getUser from "./users/get-user";
import loginWithGoogle from "./users/social/google-auth";
import loginWithGithub from "./users/social/github-auth";
import getToken from "./users/get-token";
import validateToken from "./users/validate-token";
import get from "./package-shared/actions/get";
import post from "./package-shared/actions/post";
import getSchema from "./package-shared/actions/get-schema";
import uploadImage from "./package-shared/actions/upload-image";
import uploadFile from "./package-shared/actions/upload-file";
import deleteFile from "./package-shared/actions/delete-file";
import createUser from "./package-shared/actions/users/add-user";
import updateUser from "./package-shared/actions/users/update-user";
import loginUser from "./package-shared/actions/users/login-user";
import sendEmailCode from "./package-shared/actions/users/send-email-code";
import logoutUser from "./package-shared/actions/users/logout-user";
import userAuth from "./package-shared/actions/users/user-auth";
import reAuthUser from "./package-shared/actions/users/reauth-user";
import getUser from "./package-shared/actions/users/get-user";
import loginWithGoogle from "./package-shared/actions/users/social/google-auth";
import loginWithGithub from "./package-shared/actions/users/social/github-auth";
import getToken from "./package-shared/actions/users/get-token";
import validateToken from "./package-shared/actions/users/validate-token";
import sqlGenerator from "./package-shared/functions/dsql/sql/sql-generator";
import sqlInsertGenerator from "./package-shared/functions/dsql/sql/sql-insert-generator";
import sqlDeleteGenerator from "./package-shared/functions/dsql/sql/sql-delete-generator";
@ -36,13 +33,21 @@ import connDbHandler from "./package-shared/utils/db/conn-db-handler";
import encrypt from "./package-shared/functions/dsql/encrypt";
import decrypt from "./package-shared/functions/dsql/decrypt";
import hashPassword from "./package-shared/functions/dsql/hashPassword";
import validateTempEmailCode from "./users/validate-temp-email-code";
import deleteUser from "./users/delete-user";
import validateTempEmailCode from "./package-shared/actions/users/validate-temp-email-code";
import deleteUser from "./package-shared/actions/users/delete-user";
import dsqlCrud from "./package-shared/utils/data-fetching/crud";
import dsqlMethodCrud from "./package-shared/utils/data-fetching/method-crud";
/**
* Main Export
*/
declare const datasquirel: {
/**
* Get Action
*/
get: typeof get;
/**
* Post Action
*/
post: typeof post;
media: {
uploadImage: typeof uploadImage;
@ -119,5 +124,15 @@ declare const datasquirel: {
httpRequest: typeof httpRequest;
connDbHandler: typeof connDbHandler;
};
/**
* Run Crud actions `get`, `insert`, `update`, `delete`
* @note *Requires global variables `DSQL_USE_LOCAL` and `DSQL_DB_CONN`
*/
crud: typeof dsqlCrud;
/**
* Run Crud based on request Methods `GET`, `POST`, `PUT`, `PATCH`
* @note *Requires global variables `DSQL_USE_LOCAL` and `DSQL_DB_CONN`
*/
methodCrud: typeof dsqlMethodCrud;
};
export default datasquirel;

64
dist/index.js vendored
View File

@ -3,27 +3,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Imports
*/
const get_1 = __importDefault(require("./utils/get"));
const post_1 = __importDefault(require("./utils/post"));
const get_schema_1 = __importDefault(require("./utils/get-schema"));
const upload_image_1 = __importDefault(require("./utils/upload-image"));
const upload_file_1 = __importDefault(require("./utils/upload-file"));
const delete_file_1 = __importDefault(require("./utils/delete-file"));
const add_user_1 = __importDefault(require("./users/add-user"));
const update_user_1 = __importDefault(require("./users/update-user"));
const login_user_1 = __importDefault(require("./users/login-user"));
const send_email_code_1 = __importDefault(require("./users/send-email-code"));
const logout_user_1 = __importDefault(require("./users/logout-user"));
const user_auth_1 = __importDefault(require("./users/user-auth"));
const reauth_user_1 = __importDefault(require("./users/reauth-user"));
const get_user_1 = __importDefault(require("./users/get-user"));
const google_auth_1 = __importDefault(require("./users/social/google-auth"));
const github_auth_1 = __importDefault(require("./users/social/github-auth"));
const get_token_1 = __importDefault(require("./users/get-token"));
const validate_token_1 = __importDefault(require("./users/validate-token"));
const get_1 = __importDefault(require("./package-shared/actions/get"));
const post_1 = __importDefault(require("./package-shared/actions/post"));
const get_schema_1 = __importDefault(require("./package-shared/actions/get-schema"));
const upload_image_1 = __importDefault(require("./package-shared/actions/upload-image"));
const upload_file_1 = __importDefault(require("./package-shared/actions/upload-file"));
const delete_file_1 = __importDefault(require("./package-shared/actions/delete-file"));
const add_user_1 = __importDefault(require("./package-shared/actions/users/add-user"));
const update_user_1 = __importDefault(require("./package-shared/actions/users/update-user"));
const login_user_1 = __importDefault(require("./package-shared/actions/users/login-user"));
const send_email_code_1 = __importDefault(require("./package-shared/actions/users/send-email-code"));
const logout_user_1 = __importDefault(require("./package-shared/actions/users/logout-user"));
const user_auth_1 = __importDefault(require("./package-shared/actions/users/user-auth"));
const reauth_user_1 = __importDefault(require("./package-shared/actions/users/reauth-user"));
const get_user_1 = __importDefault(require("./package-shared/actions/users/get-user"));
const google_auth_1 = __importDefault(require("./package-shared/actions/users/social/google-auth"));
const github_auth_1 = __importDefault(require("./package-shared/actions/users/social/github-auth"));
const get_token_1 = __importDefault(require("./package-shared/actions/users/get-token"));
const validate_token_1 = __importDefault(require("./package-shared/actions/users/validate-token"));
const client_1 = __importDefault(require("./client"));
const sql_generator_1 = __importDefault(require("./package-shared/functions/dsql/sql/sql-generator"));
const sql_insert_generator_1 = __importDefault(require("./package-shared/functions/dsql/sql/sql-insert-generator"));
@ -35,11 +32,10 @@ const conn_db_handler_1 = __importDefault(require("./package-shared/utils/db/con
const encrypt_1 = __importDefault(require("./package-shared/functions/dsql/encrypt"));
const decrypt_1 = __importDefault(require("./package-shared/functions/dsql/decrypt"));
const hashPassword_1 = __importDefault(require("./package-shared/functions/dsql/hashPassword"));
const validate_temp_email_code_1 = __importDefault(require("./users/validate-temp-email-code"));
const delete_user_1 = __importDefault(require("./users/delete-user"));
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
const validate_temp_email_code_1 = __importDefault(require("./package-shared/actions/users/validate-temp-email-code"));
const delete_user_1 = __importDefault(require("./package-shared/actions/users/delete-user"));
const crud_1 = __importDefault(require("./package-shared/utils/data-fetching/crud"));
const method_crud_1 = __importDefault(require("./package-shared/utils/data-fetching/method-crud"));
/**
* User Functions Object
*/
@ -82,7 +78,13 @@ const sql = {
* Main Export
*/
const datasquirel = {
/**
* Get Action
*/
get: get_1.default,
/**
* Post Action
*/
post: post_1.default,
media,
user,
@ -99,5 +101,15 @@ const datasquirel = {
httpRequest: httpRequest_1.default,
connDbHandler: conn_db_handler_1.default,
},
/**
* Run Crud actions `get`, `insert`, `update`, `delete`
* @note *Requires global variables `DSQL_USE_LOCAL` and `DSQL_DB_CONN`
*/
crud: crud_1.default,
/**
* Run Crud based on request Methods `GET`, `POST`, `PUT`, `PATCH`
* @note *Requires global variables `DSQL_USE_LOCAL` and `DSQL_DB_CONN`
*/
methodCrud: method_crud_1.default,
};
exports.default = datasquirel;

View File

@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = deleteFile;
const grab_host_names_1 = __importDefault(require("../package-shared/utils/grab-host-names"));
const grab_host_names_1 = __importDefault(require("../utils/grab-host-names"));
/**
* # Delete File via API
*/

View File

@ -1,4 +1,4 @@
import { DSQL_DatabaseSchemaType, DSQL_FieldSchemaType, DSQL_TableSchemaType, GetSchemaAPIParam } from "../package-shared/types";
import { DSQL_DatabaseSchemaType, DSQL_FieldSchemaType, DSQL_TableSchemaType, GetSchemaAPIParam } from "../types";
type GetSchemaReturn = {
success: boolean;
payload?: DSQL_DatabaseSchemaType | DSQL_TableSchemaType | DSQL_FieldSchemaType | null;

View File

@ -1,5 +1,4 @@
"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) {
@ -14,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = getSchema;
const grab_host_names_1 = __importDefault(require("../package-shared/utils/grab-host-names"));
const grab_host_names_1 = __importDefault(require("../utils/grab-host-names"));
/**
* # Get Schema for Database, table, or field *
*/

View File

@ -1,4 +1,4 @@
import { ApiGetQueryObject, GetReturn } from "../package-shared/types";
import { ApiGetQueryObject, GetReturn } from "../types";
type Param<T extends {
[k: string]: any;
} = {

View File

@ -15,10 +15,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.default = get;
const path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
const grab_host_names_1 = __importDefault(require("../package-shared/utils/grab-host-names"));
const get_1 = __importDefault(require("../package-shared/functions/api/query/get"));
const serialize_query_1 = __importDefault(require("../package-shared/utils/serialize-query"));
const grab_query_and_values_1 = __importDefault(require("../package-shared/utils/grab-query-and-values"));
const grab_host_names_1 = __importDefault(require("../utils/grab-host-names"));
const get_1 = __importDefault(require("../functions/api/query/get"));
const serialize_query_1 = __importDefault(require("../utils/serialize-query"));
const grab_query_and_values_1 = __importDefault(require("../utils/grab-query-and-values"));
/**
* # Make a get request to Datasquirel API
*/

View File

@ -1,4 +1,4 @@
import { PostDataPayload, PostReturn } from "../package-shared/types";
import { PostDataPayload, PostReturn } from "../types";
type Param = {
key?: string;
database?: string;

View File

@ -16,8 +16,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.default = post;
const path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
const grab_host_names_1 = __importDefault(require("../package-shared/utils/grab-host-names"));
const post_1 = __importDefault(require("../package-shared/functions/api/query/post"));
const grab_host_names_1 = __importDefault(require("../utils/grab-host-names"));
const post_1 = __importDefault(require("../functions/api/query/post"));
/**
* # Make a post request to Datasquirel API
*/
@ -36,7 +36,7 @@ function post(_a) {
(DSQL_DB_PASSWORD === null || DSQL_DB_PASSWORD === void 0 ? void 0 : DSQL_DB_PASSWORD.match(/./)) &&
(DSQL_DB_NAME === null || DSQL_DB_NAME === void 0 ? void 0 : DSQL_DB_NAME.match(/./)) &&
global.DSQL_USE_LOCAL) {
/** @type {import("../package-shared/types").DSQL_DatabaseSchemaType | undefined} */
/** @type {import("../types").DSQL_DatabaseSchemaType | undefined} */
let dbSchema;
try {
const localDbSchemaPath = path_1.default.resolve(process.cwd(), "dsql.schema.json");

View File

@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = uploadImage;
const grab_host_names_1 = __importDefault(require("../package-shared/utils/grab-host-names"));
const grab_host_names_1 = __importDefault(require("../utils/grab-host-names"));
/**
* # Upload File via API
*/

View File

@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = uploadImage;
const grab_host_names_1 = __importDefault(require("../package-shared/utils/grab-host-names"));
const grab_host_names_1 = __importDefault(require("../utils/grab-host-names"));
/**
* # Upload Image via API
*/

View File

@ -1,4 +1,4 @@
import { AddUserFunctionReturn, UserDataPayload } from "../package-shared/types";
import { AddUserFunctionReturn, UserDataPayload } from "../../types";
type Param = {
key?: string;
database?: string;

View File

@ -15,8 +15,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.default = addUser;
const path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
const grab_host_names_1 = __importDefault(require("../package-shared/utils/grab-host-names"));
const api_create_user_1 = __importDefault(require("../package-shared/functions/api/users/api-create-user"));
const grab_host_names_1 = __importDefault(require("../../utils/grab-host-names"));
const api_create_user_1 = __importDefault(require("../../functions/api/users/api-create-user"));
/**
* # Add User to Database
*/
@ -35,7 +35,7 @@ function addUser(_a) {
(DSQL_DB_PASSWORD === null || DSQL_DB_PASSWORD === void 0 ? void 0 : DSQL_DB_PASSWORD.match(/./)) &&
(DSQL_DB_NAME === null || DSQL_DB_NAME === void 0 ? void 0 : DSQL_DB_NAME.match(/./)) &&
global.DSQL_USE_LOCAL) {
/** @type {import("../package-shared/types").DSQL_DatabaseSchemaType | undefined} */
/** @type {import("../../types").DSQL_DatabaseSchemaType | undefined} */
let dbSchema;
try {
const localDbSchemaPath = path_1.default.resolve(process.cwd(), "dsql.schema.json");

View File

@ -1,4 +1,4 @@
import { UpdateUserFunctionReturn } from "../package-shared/types";
import { UpdateUserFunctionReturn } from "../../types";
type Param = {
key?: string;
database?: string;

View File

@ -15,8 +15,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.default = deleteUser;
const path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
const grab_host_names_1 = __importDefault(require("../package-shared/utils/grab-host-names"));
const api_delete_user_1 = __importDefault(require("../package-shared/functions/api/users/api-delete-user"));
const grab_host_names_1 = __importDefault(require("../../utils/grab-host-names"));
const api_delete_user_1 = __importDefault(require("../../functions/api/users/api-delete-user"));
/**
* # Update User
*/
@ -35,7 +35,7 @@ function deleteUser(_a) {
(DSQL_DB_PASSWORD === null || DSQL_DB_PASSWORD === void 0 ? void 0 : DSQL_DB_PASSWORD.match(/./)) &&
(DSQL_DB_NAME === null || DSQL_DB_NAME === void 0 ? void 0 : DSQL_DB_NAME.match(/./)) &&
global.DSQL_USE_LOCAL) {
/** @type {import("../package-shared/types").DSQL_DatabaseSchemaType | undefined} */
/** @type {import("../../types").DSQL_DatabaseSchemaType | undefined} */
let dbSchema;
try {
const localDbSchemaPath = path_1.default.resolve(process.cwd(), "dsql.schema.json");

View File

@ -4,9 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = getToken;
const decrypt_1 = __importDefault(require("../package-shared/functions/dsql/decrypt"));
const get_auth_cookie_names_1 = __importDefault(require("../package-shared/functions/backend/cookies/get-auth-cookie-names"));
const parseCookies_1 = __importDefault(require("../package-shared/utils/backend/parseCookies"));
const decrypt_1 = __importDefault(require("../../functions/dsql/decrypt"));
const get_auth_cookie_names_1 = __importDefault(require("../../functions/backend/cookies/get-auth-cookie-names"));
const parseCookies_1 = __importDefault(require("../../utils/backend/parseCookies"));
/**
* Get just the access token for user
* ==============================================================================

View File

@ -1,4 +1,4 @@
import { GetUserFunctionReturn } from "../package-shared/types";
import { GetUserFunctionReturn } from "../../types";
type Param = {
key: string;
database: string;

View File

@ -15,8 +15,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.default = getUser;
const path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
const grab_host_names_1 = __importDefault(require("../package-shared/utils/grab-host-names"));
const api_get_user_1 = __importDefault(require("../package-shared/functions/api/users/api-get-user"));
const grab_host_names_1 = __importDefault(require("../../utils/grab-host-names"));
const api_get_user_1 = __importDefault(require("../../functions/api/users/api-get-user"));
/**
* # Get User
*/
@ -60,7 +60,7 @@ function getUser(_a) {
(DSQL_DB_PASSWORD === null || DSQL_DB_PASSWORD === void 0 ? void 0 : DSQL_DB_PASSWORD.match(/./)) &&
(DSQL_DB_NAME === null || DSQL_DB_NAME === void 0 ? void 0 : DSQL_DB_NAME.match(/./)) &&
global.DSQL_USE_LOCAL) {
/** @type {import("../package-shared/types").DSQL_DatabaseSchemaType | undefined} */
/** @type {import("../../types").DSQL_DatabaseSchemaType | undefined} */
let dbSchema;
try {
const localDbSchemaPath = path_1.default.resolve(process.cwd(), "dsql.schema.json");

View File

@ -1,5 +1,5 @@
import http from "http";
import { APILoginFunctionReturn } from "../package-shared/types";
import { APILoginFunctionReturn } from "../../types";
type Param = {
key?: string;
database: string;

View File

@ -15,11 +15,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.default = loginUser;
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const encrypt_1 = __importDefault(require("../package-shared/functions/dsql/encrypt"));
const grab_host_names_1 = __importDefault(require("../package-shared/utils/grab-host-names"));
const api_login_1 = __importDefault(require("../package-shared/functions/api/users/api-login"));
const get_auth_cookie_names_1 = __importDefault(require("../package-shared/functions/backend/cookies/get-auth-cookie-names"));
const write_auth_files_1 = require("../package-shared/functions/backend/auth/write-auth-files");
const encrypt_1 = __importDefault(require("../../functions/dsql/encrypt"));
const grab_host_names_1 = __importDefault(require("../../utils/grab-host-names"));
const api_login_1 = __importDefault(require("../../functions/api/users/api-login"));
const get_auth_cookie_names_1 = __importDefault(require("../../functions/backend/cookies/get-auth-cookie-names"));
const write_auth_files_1 = require("../../functions/backend/auth/write-auth-files");
/**
* # Login A user
*/
@ -67,7 +67,7 @@ function loginUser(_a) {
/**
* Initialize HTTP response variable
*/
/** @type {import("../package-shared/types").APILoginFunctionReturn} */
/** @type {import("../../types").APILoginFunctionReturn} */
let httpResponse = {
success: false,
};

View File

@ -4,12 +4,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = logoutUser;
const get_auth_cookie_names_1 = __importDefault(require("../package-shared/functions/backend/cookies/get-auth-cookie-names"));
const decrypt_1 = __importDefault(require("../package-shared/functions/dsql/decrypt"));
const ejson_1 = __importDefault(require("../package-shared/utils/ejson"));
const write_auth_files_1 = require("../package-shared/functions/backend/auth/write-auth-files");
const parseCookies_1 = __importDefault(require("../package-shared/utils/backend/parseCookies"));
const grab_host_names_1 = __importDefault(require("../package-shared/utils/grab-host-names"));
const get_auth_cookie_names_1 = __importDefault(require("../../functions/backend/cookies/get-auth-cookie-names"));
const decrypt_1 = __importDefault(require("../../functions/dsql/decrypt"));
const ejson_1 = __importDefault(require("../../utils/ejson"));
const write_auth_files_1 = require("../../functions/backend/auth/write-auth-files");
const parseCookies_1 = __importDefault(require("../../utils/backend/parseCookies"));
const grab_host_names_1 = __importDefault(require("../../utils/grab-host-names"));
/**
* # Logout user
*/

View File

@ -1,5 +1,5 @@
import http from "http";
import { APILoginFunctionReturn } from "../package-shared/types";
import { APILoginFunctionReturn } from "../../types";
type Param = {
key?: string;
database?: string;

View File

@ -15,12 +15,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.default = reauthUser;
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const encrypt_1 = __importDefault(require("../package-shared/functions/dsql/encrypt"));
const encrypt_1 = __importDefault(require("../../functions/dsql/encrypt"));
const user_auth_1 = __importDefault(require("./user-auth"));
const grab_host_names_1 = __importDefault(require("../package-shared/utils/grab-host-names"));
const api_reauth_user_1 = __importDefault(require("../package-shared/functions/api/users/api-reauth-user"));
const write_auth_files_1 = require("../package-shared/functions/backend/auth/write-auth-files");
const get_auth_cookie_names_1 = __importDefault(require("../package-shared/functions/backend/cookies/get-auth-cookie-names"));
const grab_host_names_1 = __importDefault(require("../../utils/grab-host-names"));
const api_reauth_user_1 = __importDefault(require("../../functions/api/users/api-reauth-user"));
const write_auth_files_1 = require("../../functions/backend/auth/write-auth-files");
const get_auth_cookie_names_1 = __importDefault(require("../../functions/backend/cookies/get-auth-cookie-names"));
/**
* # Reauthorize User
*/
@ -66,7 +66,7 @@ function reauthUser(_a) {
(DSQL_DB_PASSWORD === null || DSQL_DB_PASSWORD === void 0 ? void 0 : DSQL_DB_PASSWORD.match(/./)) &&
(DSQL_DB_NAME === null || DSQL_DB_NAME === void 0 ? void 0 : DSQL_DB_NAME.match(/./)) &&
global.DSQL_USE_LOCAL) {
/** @type {import("../package-shared/types").DSQL_DatabaseSchemaType | undefined} */
/** @type {import("../../types").DSQL_DatabaseSchemaType | undefined} */
let dbSchema;
try {
const localDbSchemaPath = path_1.default.resolve(process.cwd(), "dsql.schema.json");

View File

@ -1,5 +1,5 @@
import http from "http";
import { SendOneTimeCodeEmailResponse } from "../package-shared/types";
import { SendOneTimeCodeEmailResponse } from "../../types";
type Param = {
key?: string;
database?: string;
@ -14,7 +14,7 @@ type Param = {
mail_port?: number;
sender?: string;
user_id?: boolean;
extraCookies?: import("../package-shared/types").CookieObject[];
extraCookies?: import("../../types").CookieObject[];
};
/**
* # Send Email Code to a User

View File

@ -15,8 +15,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.default = sendEmailCode;
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const grab_host_names_1 = __importDefault(require("../package-shared/utils/grab-host-names"));
const api_send_email_code_1 = __importDefault(require("../package-shared/functions/api/users/api-send-email-code"));
const grab_host_names_1 = __importDefault(require("../../utils/grab-host-names"));
const api_send_email_code_1 = __importDefault(require("../../functions/api/users/api-send-email-code"));
/**
* # Send Email Code to a User
*/
@ -40,7 +40,7 @@ function sendEmailCode(_a) {
(DSQL_DB_PASSWORD === null || DSQL_DB_PASSWORD === void 0 ? void 0 : DSQL_DB_PASSWORD.match(/./)) &&
(DSQL_DB_NAME === null || DSQL_DB_NAME === void 0 ? void 0 : DSQL_DB_NAME.match(/./)) &&
global.DSQL_USE_LOCAL) {
/** @type {import("../package-shared/types").DSQL_DatabaseSchemaType | undefined} */
/** @type {import("../../types").DSQL_DatabaseSchemaType | undefined} */
let dbSchema;
try {
const localDbSchemaPath = path_1.default.resolve(process.cwd(), "dsql.schema.json");
@ -67,7 +67,7 @@ function sendEmailCode(_a) {
*
* @description make a request to datasquirel.com
*
* @type {import("../package-shared/types").SendOneTimeCodeEmailResponse}
* @type {import("../../types").SendOneTimeCodeEmailResponse}
*/
const httpResponse = yield new Promise((resolve, reject) => {
const reqPayload = JSON.stringify({

View File

@ -15,9 +15,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.default = githubAuth;
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const encrypt_1 = __importDefault(require("../../package-shared/functions/dsql/encrypt"));
const grab_host_names_1 = __importDefault(require("../../package-shared/utils/grab-host-names"));
const api_github_login_1 = __importDefault(require("../../package-shared/functions/api/users/social/api-github-login"));
const encrypt_1 = __importDefault(require("../../../functions/dsql/encrypt"));
const grab_host_names_1 = __importDefault(require("../../../utils/grab-host-names"));
const api_github_login_1 = __importDefault(require("../../../functions/api/users/social/api-github-login"));
/**
* # SERVER FUNCTION: Login with google Function
*/
@ -65,7 +65,7 @@ function githubAuth(_a) {
(DSQL_DB_USERNAME === null || DSQL_DB_USERNAME === void 0 ? void 0 : DSQL_DB_USERNAME.match(/./)) &&
(DSQL_DB_PASSWORD === null || DSQL_DB_PASSWORD === void 0 ? void 0 : DSQL_DB_PASSWORD.match(/./)) &&
(DSQL_DB_NAME === null || DSQL_DB_NAME === void 0 ? void 0 : DSQL_DB_NAME.match(/./))) {
/** @type {import("../../package-shared/types").DSQL_DatabaseSchemaType | undefined | undefined} */
/** @type {import("../../../types").DSQL_DatabaseSchemaType | undefined | undefined} */
let dbSchema;
try {
const localDbSchemaPath = path_1.default.resolve(process.cwd(), "dsql.schema.json");

View File

@ -1,5 +1,5 @@
import http from "http";
import { APILoginFunctionReturn } from "../../package-shared/types";
import { APILoginFunctionReturn } from "../../../types";
type Param = {
key?: string;
token: string;

View File

@ -13,11 +13,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = googleAuth;
const encrypt_1 = __importDefault(require("../../package-shared/functions/dsql/encrypt"));
const grab_host_names_1 = __importDefault(require("../../package-shared/utils/grab-host-names"));
const api_google_login_1 = __importDefault(require("../../package-shared/functions/api/users/social/api-google-login"));
const get_auth_cookie_names_1 = __importDefault(require("../../package-shared/functions/backend/cookies/get-auth-cookie-names"));
const write_auth_files_1 = require("../../package-shared/functions/backend/auth/write-auth-files");
const encrypt_1 = __importDefault(require("../../../functions/dsql/encrypt"));
const grab_host_names_1 = __importDefault(require("../../../utils/grab-host-names"));
const api_google_login_1 = __importDefault(require("../../../functions/api/users/social/api-google-login"));
const get_auth_cookie_names_1 = __importDefault(require("../../../functions/backend/cookies/get-auth-cookie-names"));
const write_auth_files_1 = require("../../../functions/backend/auth/write-auth-files");
/**
* # SERVER FUNCTION: Login with google Function
*/
@ -88,7 +88,7 @@ function googleAuth(_a) {
* Make https request
*
* @description make a request to datasquirel.com
* @type {{ success: boolean, user: import("../../package-shared/types").DATASQUIREL_LoggedInUser | null, msg?: string, dsqlUserId?: number } | null } - Https response object
* @type {{ success: boolean, user: import("../../../types").DATASQUIREL_LoggedInUser | null, msg?: string, dsqlUserId?: number } | null } - Https response object
*/
httpResponse = yield new Promise((resolve, reject) => {
const reqPayload = JSON.stringify({

View File

@ -1,4 +1,4 @@
import { UpdateUserFunctionReturn } from "../package-shared/types";
import { UpdateUserFunctionReturn } from "../../types";
type Param = {
key?: string;
database?: string;

View File

@ -15,8 +15,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.default = updateUser;
const path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
const grab_host_names_1 = __importDefault(require("../package-shared/utils/grab-host-names"));
const api_update_user_1 = __importDefault(require("../package-shared/functions/api/users/api-update-user"));
const grab_host_names_1 = __importDefault(require("../../utils/grab-host-names"));
const api_update_user_1 = __importDefault(require("../../functions/api/users/api-update-user"));
/**
* # Update User
*/
@ -35,7 +35,7 @@ function updateUser(_a) {
(DSQL_DB_PASSWORD === null || DSQL_DB_PASSWORD === void 0 ? void 0 : DSQL_DB_PASSWORD.match(/./)) &&
(DSQL_DB_NAME === null || DSQL_DB_NAME === void 0 ? void 0 : DSQL_DB_NAME.match(/./)) &&
global.DSQL_USE_LOCAL) {
/** @type {import("../package-shared/types").DSQL_DatabaseSchemaType | undefined} */
/** @type {import("../../types").DSQL_DatabaseSchemaType | undefined} */
let dbSchema;
try {
const localDbSchemaPath = path_1.default.resolve(process.cwd(), "dsql.schema.json");

View File

@ -1,5 +1,5 @@
import http from "http";
import { AuthenticatedUser } from "../package-shared/types";
import { AuthenticatedUser } from "../../types";
type Param = {
request?: http.IncomingMessage & {
[s: string]: any;

View File

@ -4,12 +4,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = userAuth;
const decrypt_1 = __importDefault(require("../package-shared/functions/dsql/decrypt"));
const get_auth_cookie_names_1 = __importDefault(require("../package-shared/functions/backend/cookies/get-auth-cookie-names"));
const write_auth_files_1 = require("../package-shared/functions/backend/auth/write-auth-files");
const parseCookies_1 = __importDefault(require("../package-shared/utils/backend/parseCookies"));
const get_csrf_header_name_1 = __importDefault(require("../utils/get-csrf-header-name"));
const grab_host_names_1 = __importDefault(require("../package-shared/utils/grab-host-names"));
const decrypt_1 = __importDefault(require("../../functions/dsql/decrypt"));
const get_auth_cookie_names_1 = __importDefault(require("../../functions/backend/cookies/get-auth-cookie-names"));
const write_auth_files_1 = require("../../functions/backend/auth/write-auth-files");
const parseCookies_1 = __importDefault(require("../../utils/backend/parseCookies"));
const get_csrf_header_name_1 = __importDefault(require("../../actions/get-csrf-header-name"));
const grab_host_names_1 = __importDefault(require("../../utils/grab-host-names"));
const minuteInMilliseconds = 60000;
const hourInMilliseconds = minuteInMilliseconds * 60;
const dayInMilliseconds = hourInMilliseconds * 24;
@ -76,7 +76,7 @@ function userAuth({ request, req, encryptionKey, encryptionSalt, level, database
*
* @description Grab the payload
*/
/** @type {import("../package-shared/types").DATASQUIREL_LoggedInUser} */
/** @type {import("../../types").DATASQUIREL_LoggedInUser} */
let userObject = JSON.parse(userPayloadJSON);
if (debug) {
console.log("userAuth:userObject:", userObject);

View File

@ -1,5 +1,5 @@
import http from "http";
import { SendOneTimeCodeEmailResponse } from "../package-shared/types";
import { SendOneTimeCodeEmailResponse } from "../../types";
type Param = {
request?: http.IncomingMessage & {
[s: string]: any;

View File

@ -13,10 +13,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = validateTempEmailCode;
const get_auth_cookie_names_1 = __importDefault(require("../package-shared/functions/backend/cookies/get-auth-cookie-names"));
const parseCookies_1 = __importDefault(require("../package-shared/utils/backend/parseCookies"));
const decrypt_1 = __importDefault(require("../package-shared/functions/dsql/decrypt"));
const ejson_1 = __importDefault(require("../package-shared/utils/ejson"));
const get_auth_cookie_names_1 = __importDefault(require("../../functions/backend/cookies/get-auth-cookie-names"));
const parseCookies_1 = __importDefault(require("../../utils/backend/parseCookies"));
const decrypt_1 = __importDefault(require("../../functions/dsql/decrypt"));
const ejson_1 = __importDefault(require("../../utils/ejson"));
/**
* # Verify the temp email code sent to the user's email address
*/

View File

@ -1,4 +1,4 @@
import { DATASQUIREL_LoggedInUser } from "../package-shared/types";
import { DATASQUIREL_LoggedInUser } from "../../types";
type Param = {
token: string;
encryptionKey: string;

View File

@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = validateToken;
const decrypt_1 = __importDefault(require("../package-shared/functions/dsql/decrypt"));
const decrypt_1 = __importDefault(require("../../functions/dsql/decrypt"));
/**
* Validate Token
* ======================================

View File

@ -29,7 +29,6 @@ function apiPost(_a) {
((_b = query === null || query === void 0 ? void 0 : query.action) === null || _b === void 0 ? void 0 : _b.match(/^create |^alter |^drop /i))) {
return { success: false, msg: "Wrong Input" };
}
/** @type {any} */
let results;
/**
* Create new user folder and file

View File

@ -35,7 +35,6 @@ function apiDeleteUser(_a) {
}
const deleteUser = yield (0, deleteDbEntry_1.default)({
dbContext: "Dsql User",
paradigm: "Full Access",
dbFullName,
tableName: "users",
identifierColumnName: "id",

View File

@ -68,7 +68,6 @@ function apiUpdateUser(_a) {
})();
const updateUser = yield (0, updateDbEntry_1.default)({
dbContext: "Dsql User",
paradigm: "Full Access",
dbFullName,
tableName: "users",
identifierColumnName: "id",

View File

@ -16,6 +16,7 @@ exports.default = dbHandler;
const fs_1 = __importDefault(require("fs"));
const serverError_1 = __importDefault(require("./serverError"));
const grab_dsql_connection_1 = __importDefault(require("../../utils/grab-dsql-connection"));
const path_1 = __importDefault(require("path"));
/**
* # Main DB Handler Function
*/
@ -44,7 +45,10 @@ function dbHandler(...args) {
});
}
catch (error) {
fs_1.default.appendFileSync("./.tmp/dbErrorLogs.txt", JSON.stringify(error, null, 4) + "\n" + Date() + "\n\n\n", "utf8");
const tmpFolder = path_1.default.resolve(process.cwd(), "./.tmp");
if (!fs_1.default.existsSync(tmpFolder))
fs_1.default.mkdirSync(tmpFolder, { recursive: true });
fs_1.default.appendFileSync(path_1.default.resolve(tmpFolder, "./dbErrorLogs.txt"), JSON.stringify(error, null, 4) + "\n" + Date() + "\n\n\n", "utf8");
results = null;
(0, serverError_1.default)({
component: "dbHandler",

View File

@ -39,7 +39,10 @@ function dbHandler(_a) {
console.log("ERROR in dbHandler =>", error.message);
console.log(error);
console.log(CONNECTION.config());
fs_1.default.appendFileSync(path_1.default.resolve(__dirname, "../.tmp/dbErrorLogs.txt"), JSON.stringify(error, null, 4) + "\n" + Date() + "\n\n\n", "utf8");
const tmpFolder = path_1.default.resolve(process.cwd(), "./.tmp");
if (!fs_1.default.existsSync(tmpFolder))
fs_1.default.mkdirSync(tmpFolder, { recursive: true });
fs_1.default.appendFileSync(path_1.default.resolve(tmpFolder, "./dbErrorLogs.txt"), JSON.stringify(error, null, 4) + "\n" + Date() + "\n\n\n", "utf8");
results = null;
}
finally {

View File

@ -34,7 +34,29 @@ export interface DSQL_ChildrenTablesType {
tableName: string;
tableNameFull?: string;
}
export interface DSQL_FieldSchemaType {
export declare const TextFieldTypesArray: readonly [{
readonly title: "Plain Text";
readonly value: "plain";
}, {
readonly title: "Rich Text";
readonly value: "richText";
}, {
readonly title: "JSON";
readonly value: "json";
}, {
readonly title: "YAML";
readonly value: "yaml";
}, {
readonly title: "HTML";
readonly value: "html";
}, {
readonly title: "CSS";
readonly value: "css";
}, {
readonly title: "Javascript";
readonly value: "javascript";
}];
export type DSQL_FieldSchemaType = {
fieldName?: string;
originName?: string;
updatedField?: boolean;
@ -47,13 +69,6 @@ export interface DSQL_FieldSchemaType {
defaultValue?: string | number;
defaultValueLiteral?: string;
foreignKey?: DSQL_ForeignKeyType;
richText?: boolean;
json?: boolean;
yaml?: boolean;
html?: boolean;
css?: boolean;
javascript?: boolean;
shell?: boolean;
newTempField?: boolean;
defaultField?: boolean;
plainText?: boolean;
@ -65,7 +80,11 @@ export interface DSQL_FieldSchemaType {
onDelete?: string;
onDeleteLiteral?: string;
cssFiles?: string[];
}
integerLength?: string | number;
decimals?: string | number;
} & {
[key in (typeof TextFieldTypesArray)[number]["value"]]?: boolean;
};
export interface DSQL_ForeignKeyType {
foreignKeyName?: string;
destinationTableName?: string;
@ -784,6 +803,7 @@ export interface MYSQL_user_database_tables_table_def {
table_slug?: string;
table_description?: string;
child_table?: number;
active_data?: 0 | 1;
child_table_parent_database?: string;
child_table_parent_table?: string;
date_created?: string;

View File

@ -1,5 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ServerQueryEqualities = exports.ServerQueryOperators = void 0;
exports.ServerQueryEqualities = exports.ServerQueryOperators = exports.TextFieldTypesArray = void 0;
exports.TextFieldTypesArray = [
{ title: "Plain Text", value: "plain" },
{ title: "Rich Text", value: "richText" },
{ title: "JSON", value: "json" },
{ title: "YAML", value: "yaml" },
{ title: "HTML", value: "html" },
{ title: "CSS", value: "css" },
{ title: "Javascript", value: "javascript" },
];
exports.ServerQueryOperators = ["AND", "OR"];
exports.ServerQueryEqualities = ["EQUAL", "LIKE", "NOT EQUAL"];

View File

@ -0,0 +1,25 @@
import sqlGenerator from "../../functions/dsql/sql/sql-generator";
import { PostReturn, ServerQueryParam, ServerQueryQueryObject } from "../../types";
export declare const DsqlCrudActions: readonly ["insert", "update", "delete", "get"];
export type CrudQueryObject<T extends object = {
[key: string]: any;
}> = ServerQueryParam & {
query: ServerQueryQueryObject<T>;
};
export type CrudParam<T extends object = {
[key: string]: any;
}> = {
action: (typeof DsqlCrudActions)[number];
table: string;
data?: T;
targetId?: string | number;
query?: CrudQueryObject<T>;
sanitize?: (data?: T) => T;
};
export default function dsqlCrud<T extends {
[key: string]: any;
} = {
[key: string]: any;
}>({ action, data, table, targetId, query, sanitize, }: CrudParam<T>): Promise<(PostReturn & {
queryObject?: ReturnType<Awaited<typeof sqlGenerator>>;
}) | null>;

View File

@ -0,0 +1,69 @@
"use strict";
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) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DsqlCrudActions = void 0;
exports.default = dsqlCrud;
const get_1 = __importDefault(require("../../actions/get"));
const post_1 = __importDefault(require("../../actions/post"));
const sql_generator_1 = __importDefault(require("../../functions/dsql/sql/sql-generator"));
exports.DsqlCrudActions = ["insert", "update", "delete", "get"];
function dsqlCrud(_a) {
return __awaiter(this, arguments, void 0, function* ({ action, data, table, targetId, query, sanitize, }) {
const finalData = sanitize ? sanitize(data) : data;
const finalId = targetId;
let queryObject;
switch (action) {
case "get":
queryObject = (0, sql_generator_1.default)({
tableName: table,
genObject: query,
});
const GET_RES = yield (0, get_1.default)({
query: (queryObject === null || queryObject === void 0 ? void 0 : queryObject.string) || "",
queryValues: (queryObject === null || queryObject === void 0 ? void 0 : queryObject.values) || [],
});
return Object.assign(Object.assign({}, GET_RES), { queryObject });
case "insert":
return yield (0, post_1.default)({
query: {
action: "insert",
table,
data: finalData,
},
});
case "update":
data === null || data === void 0 ? true : delete data.id;
return yield (0, post_1.default)({
query: {
action: "update",
table,
identifierColumnName: "id",
identifierValue: String(finalId),
data: finalData,
},
});
case "delete":
return yield (0, post_1.default)({
query: {
action: "delete",
table,
identifierColumnName: "id",
identifierValue: String(finalId),
},
});
default:
return null;
}
});
}

View File

@ -0,0 +1,42 @@
import { DATASQUIREL_LoggedInUser, ServerQueryParam } from "../../types";
export declare const DataCrudRequestMethods: readonly ["GET", "POST", "PUT", "DELETE"];
export type APIDataCrudQuery = ServerQueryParam & {
page?: number;
};
export type CRUDResponseObject<P extends any = any> = {
success: boolean;
payload?: P;
msg?: string;
error?: string;
};
export type ApiDataCrudParam<T extends {
[key: string]: any;
} = {
[key: string]: any;
}> = {
method: (typeof DataCrudRequestMethods)[number];
body?: T;
query?: string | T;
tableName: string;
addUser?: {
field: string;
};
user?: DATASQUIREL_LoggedInUser;
extraData?: T;
transform?: ({ data, existingData, user, }: {
user?: DATASQUIREL_LoggedInUser;
data: T;
existingData?: T;
reqMethod: (typeof DataCrudRequestMethods)[number];
}) => Promise<T>;
existingData?: T;
};
export default function dsqlMethodCrud<T extends {
[key: string]: any;
} = {
[key: string]: any;
}, P extends {
[key: string]: any;
} = {
[key: string]: any;
}>({ method, tableName, addUser, user, extraData, transform, existingData, body, query, }: ApiDataCrudParam<T>): Promise<CRUDResponseObject<P>>;

View File

@ -0,0 +1,122 @@
"use strict";
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) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DataCrudRequestMethods = void 0;
exports.default = dsqlMethodCrud;
const ejson_1 = __importDefault(require("../ejson"));
const crud_1 = __importDefault(require("./crud"));
exports.DataCrudRequestMethods = ["GET", "POST", "PUT", "DELETE"];
function dsqlMethodCrud(_a) {
return __awaiter(this, arguments, void 0, function* ({ method, tableName, addUser, user, extraData, transform, existingData, body, query, }) {
let result = {
success: false,
};
try {
let finalBody = body;
let finalQuery = query;
Object.keys(finalQuery).forEach((key) => {
const value = finalQuery[key];
if (typeof value == "string" && value.match(/^\{|^\[/)) {
finalQuery[key] = ejson_1.default.stringify(value);
}
if (value == "true") {
finalQuery[key] = true;
}
if (value == "false") {
finalQuery[key] = false;
}
});
const LIMIT = finalQuery.limit || 10;
const PAGE = finalQuery.page || 1;
const OFFSET = (PAGE - 1) * LIMIT;
let finalData = Object.assign(Object.assign({}, finalBody.data), extraData);
if (user && addUser) {
finalData = Object.assign(Object.assign({}, finalData), { [addUser.field]: String(user.id) });
}
if (transform) {
finalData = yield transform({
data: finalData,
existingData: existingData,
user,
reqMethod: method,
});
}
switch (method) {
case "GET":
const GET_RESULT = yield (0, crud_1.default)({
action: "get",
table: tableName,
query: Object.assign(Object.assign({}, finalQuery), { query: Object.assign(Object.assign({}, finalQuery.query), { user_id: user
? {
value: String(user.id),
}
: undefined }), limit: LIMIT, offset: OFFSET || undefined }),
});
result = {
success: Boolean(GET_RESULT === null || GET_RESULT === void 0 ? void 0 : GET_RESULT.success),
payload: GET_RESULT === null || GET_RESULT === void 0 ? void 0 : GET_RESULT.payload,
msg: GET_RESULT === null || GET_RESULT === void 0 ? void 0 : GET_RESULT.msg,
error: GET_RESULT === null || GET_RESULT === void 0 ? void 0 : GET_RESULT.error,
};
break;
case "POST":
const POST_RESULT = yield (0, crud_1.default)({
action: "insert",
table: tableName,
data: finalData,
});
result = {
success: Boolean(POST_RESULT === null || POST_RESULT === void 0 ? void 0 : POST_RESULT.success),
payload: POST_RESULT === null || POST_RESULT === void 0 ? void 0 : POST_RESULT.payload,
msg: POST_RESULT === null || POST_RESULT === void 0 ? void 0 : POST_RESULT.msg,
error: POST_RESULT === null || POST_RESULT === void 0 ? void 0 : POST_RESULT.error,
};
break;
case "PUT":
const PUT_RESULT = yield (0, crud_1.default)({
action: "update",
table: tableName,
data: finalData,
targetId: finalBody.data.id,
});
result = {
success: Boolean(PUT_RESULT === null || PUT_RESULT === void 0 ? void 0 : PUT_RESULT.success),
payload: PUT_RESULT === null || PUT_RESULT === void 0 ? void 0 : PUT_RESULT.payload,
msg: PUT_RESULT === null || PUT_RESULT === void 0 ? void 0 : PUT_RESULT.msg,
error: PUT_RESULT === null || PUT_RESULT === void 0 ? void 0 : PUT_RESULT.error,
};
break;
case "DELETE":
const DELETE_RESULT = yield (0, crud_1.default)({
action: "delete",
table: tableName,
targetId: finalBody.data.id,
});
result = {
success: Boolean(DELETE_RESULT === null || DELETE_RESULT === void 0 ? void 0 : DELETE_RESULT.success),
payload: DELETE_RESULT === null || DELETE_RESULT === void 0 ? void 0 : DELETE_RESULT.payload,
msg: DELETE_RESULT === null || DELETE_RESULT === void 0 ? void 0 : DELETE_RESULT.msg,
error: DELETE_RESULT === null || DELETE_RESULT === void 0 ? void 0 : DELETE_RESULT.error,
};
break;
default:
break;
}
return result;
}
catch (error) {
return result;
}
});
}

View File

@ -7,31 +7,28 @@ declare global {
var DSQL_USE_LOCAL: boolean | undefined;
}
/**
* Imports
*/
import get from "./utils/get";
import post from "./utils/post";
import getSchema from "./utils/get-schema";
import get from "./package-shared/actions/get";
import post from "./package-shared/actions/post";
import getSchema from "./package-shared/actions/get-schema";
import uploadImage from "./utils/upload-image";
import uploadFile from "./utils/upload-file";
import deleteFile from "./utils/delete-file";
import uploadImage from "./package-shared/actions/upload-image";
import uploadFile from "./package-shared/actions/upload-file";
import deleteFile from "./package-shared/actions/delete-file";
import createUser from "./users/add-user";
import updateUser from "./users/update-user";
import loginUser from "./users/login-user";
import sendEmailCode from "./users/send-email-code";
import logoutUser from "./users/logout-user";
import createUser from "./package-shared/actions/users/add-user";
import updateUser from "./package-shared/actions/users/update-user";
import loginUser from "./package-shared/actions/users/login-user";
import sendEmailCode from "./package-shared/actions/users/send-email-code";
import logoutUser from "./package-shared/actions/users/logout-user";
import userAuth from "./users/user-auth";
import reAuthUser from "./users/reauth-user";
import getUser from "./users/get-user";
import userAuth from "./package-shared/actions/users/user-auth";
import reAuthUser from "./package-shared/actions/users/reauth-user";
import getUser from "./package-shared/actions/users/get-user";
import loginWithGoogle from "./users/social/google-auth";
import loginWithGithub from "./users/social/github-auth";
import getToken from "./users/get-token";
import validateToken from "./users/validate-token";
import loginWithGoogle from "./package-shared/actions/users/social/google-auth";
import loginWithGithub from "./package-shared/actions/users/social/github-auth";
import getToken from "./package-shared/actions/users/get-token";
import validateToken from "./package-shared/actions/users/validate-token";
import datasquirelClient from "./client";
import sqlGenerator from "./package-shared/functions/dsql/sql/sql-generator";
@ -44,12 +41,10 @@ import connDbHandler from "./package-shared/utils/db/conn-db-handler";
import encrypt from "./package-shared/functions/dsql/encrypt";
import decrypt from "./package-shared/functions/dsql/decrypt";
import hashPassword from "./package-shared/functions/dsql/hashPassword";
import validateTempEmailCode from "./users/validate-temp-email-code";
import deleteUser from "./users/delete-user";
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
import validateTempEmailCode from "./package-shared/actions/users/validate-temp-email-code";
import deleteUser from "./package-shared/actions/users/delete-user";
import dsqlCrud from "./package-shared/utils/data-fetching/crud";
import dsqlMethodCrud from "./package-shared/utils/data-fetching/method-crud";
/**
* User Functions Object
@ -96,7 +91,13 @@ const sql = {
* Main Export
*/
const datasquirel = {
/**
* Get Action
*/
get,
/**
* Post Action
*/
post,
media,
user,
@ -113,6 +114,16 @@ const datasquirel = {
httpRequest,
connDbHandler,
},
/**
* Run Crud actions `get`, `insert`, `update`, `delete`
* @note *Requires global variables `DSQL_USE_LOCAL` and `DSQL_DB_CONN`
*/
crud: dsqlCrud,
/**
* Run Crud based on request Methods `GET`, `POST`, `PUT`, `PATCH`
* @note *Requires global variables `DSQL_USE_LOCAL` and `DSQL_DB_CONN`
*/
methodCrud: dsqlMethodCrud,
};
export default datasquirel;

View File

@ -1,4 +1,4 @@
import grabHostNames from "../package-shared/utils/grab-host-names";
import grabHostNames from "../utils/grab-host-names";
interface Return {
success: boolean;

View File

@ -1,13 +1,11 @@
// @ts-check
import grabHostNames from "../package-shared/utils/grab-host-names";
import grabHostNames from "../utils/grab-host-names";
import {
DSQL_DatabaseSchemaType,
DSQL_FieldSchemaType,
DSQL_TableSchemaType,
GetSchemaAPIParam,
GetSchemaRequestQuery,
} from "../package-shared/types";
} from "../types";
type GetSchemaReturn = {
success: boolean;

View File

@ -1,17 +1,17 @@
import https from "node:https";
import path from "path";
import fs from "fs";
import grabHostNames from "../package-shared/utils/grab-host-names";
import apiGet from "../package-shared/functions/api/query/get";
import serializeQuery from "../package-shared/utils/serialize-query";
import grabHostNames from "../utils/grab-host-names";
import apiGet from "../functions/api/query/get";
import serializeQuery from "../utils/serialize-query";
import {
ApiGetQueryObject,
DSQL_DatabaseSchemaType,
GetReqQueryObject,
GetReturn,
ServerQueryParam,
} from "../package-shared/types";
import apiGetGrabQueryAndValues from "../package-shared/utils/grab-query-and-values";
} from "../types";
import apiGetGrabQueryAndValues from "../utils/grab-query-and-values";
type Param<T extends { [k: string]: any } = { [k: string]: any }> = {
key?: string;

View File

@ -2,9 +2,9 @@
import path from "path";
import fs from "fs";
import grabHostNames from "../package-shared/utils/grab-host-names";
import apiPost from "../package-shared/functions/api/query/post";
import { PostDataPayload, PostReturn } from "../package-shared/types";
import grabHostNames from "../utils/grab-host-names";
import apiPost from "../functions/api/query/post";
import { PostDataPayload, PostReturn } from "../types";
type Param = {
key?: string;
@ -44,10 +44,8 @@ export default async function post({
DSQL_DB_NAME?.match(/./) &&
global.DSQL_USE_LOCAL
) {
/** @type {import("../package-shared/types").DSQL_DatabaseSchemaType | undefined} */
let dbSchema:
| import("../package-shared/types").DSQL_DatabaseSchemaType
| undefined;
/** @type {import("../types").DSQL_DatabaseSchemaType | undefined} */
let dbSchema: import("../types").DSQL_DatabaseSchemaType | undefined;
try {
const localDbSchemaPath = path.resolve(

View File

@ -1,4 +1,4 @@
import grabHostNames from "../package-shared/utils/grab-host-names";
import grabHostNames from "../utils/grab-host-names";
interface Return {
success: boolean;

View File

@ -1,6 +1,6 @@
// @ts-check
import grabHostNames from "../package-shared/utils/grab-host-names";
import grabHostNames from "../utils/grab-host-names";
interface FunctionReturn {
success: boolean;

View File

@ -1,11 +1,8 @@
import path from "path";
import fs from "fs";
import grabHostNames from "../package-shared/utils/grab-host-names";
import apiCreateUser from "../package-shared/functions/api/users/api-create-user";
import {
AddUserFunctionReturn,
UserDataPayload,
} from "../package-shared/types";
import grabHostNames from "../../utils/grab-host-names";
import apiCreateUser from "../../functions/api/users/api-create-user";
import { AddUserFunctionReturn, UserDataPayload } from "../../types";
type Param = {
key?: string;
@ -51,10 +48,8 @@ export default async function addUser({
DSQL_DB_NAME?.match(/./) &&
global.DSQL_USE_LOCAL
) {
/** @type {import("../package-shared/types").DSQL_DatabaseSchemaType | undefined} */
let dbSchema:
| import("../package-shared/types").DSQL_DatabaseSchemaType
| undefined;
/** @type {import("../../types").DSQL_DatabaseSchemaType | undefined} */
let dbSchema: import("../../types").DSQL_DatabaseSchemaType | undefined;
try {
const localDbSchemaPath = path.resolve(

View File

@ -1,8 +1,8 @@
import path from "path";
import fs from "fs";
import grabHostNames from "../package-shared/utils/grab-host-names";
import apiDeleteUser from "../package-shared/functions/api/users/api-delete-user";
import { UpdateUserFunctionReturn } from "../package-shared/types";
import grabHostNames from "../../utils/grab-host-names";
import apiDeleteUser from "../../functions/api/users/api-delete-user";
import { UpdateUserFunctionReturn } from "../../types";
type Param = {
key?: string;
@ -38,10 +38,8 @@ export default async function deleteUser({
DSQL_DB_NAME?.match(/./) &&
global.DSQL_USE_LOCAL
) {
/** @type {import("../package-shared/types").DSQL_DatabaseSchemaType | undefined} */
let dbSchema:
| import("../package-shared/types").DSQL_DatabaseSchemaType
| undefined;
/** @type {import("../../types").DSQL_DatabaseSchemaType | undefined} */
let dbSchema: import("../../types").DSQL_DatabaseSchemaType | undefined;
try {
const localDbSchemaPath = path.resolve(

View File

@ -1,7 +1,7 @@
import http from "http";
import decrypt from "../package-shared/functions/dsql/decrypt";
import getAuthCookieNames from "../package-shared/functions/backend/cookies/get-auth-cookie-names";
import parseCookies from "../package-shared/utils/backend/parseCookies";
import decrypt from "../../functions/dsql/decrypt";
import getAuthCookieNames from "../../functions/backend/cookies/get-auth-cookie-names";
import parseCookies from "../../utils/backend/parseCookies";
type Param = {
request?: http.IncomingMessage;

View File

@ -1,8 +1,8 @@
import path from "path";
import fs from "fs";
import grabHostNames from "../package-shared/utils/grab-host-names";
import apiGetUser from "../package-shared/functions/api/users/api-get-user";
import { GetUserFunctionReturn } from "../package-shared/types";
import grabHostNames from "../../utils/grab-host-names";
import apiGetUser from "../../functions/api/users/api-get-user";
import { GetUserFunctionReturn } from "../../types";
type Param = {
key: string;
@ -69,10 +69,8 @@ export default async function getUser({
DSQL_DB_NAME?.match(/./) &&
global.DSQL_USE_LOCAL
) {
/** @type {import("../package-shared/types").DSQL_DatabaseSchemaType | undefined} */
let dbSchema:
| import("../package-shared/types").DSQL_DatabaseSchemaType
| undefined;
/** @type {import("../../types").DSQL_DatabaseSchemaType | undefined} */
let dbSchema: import("../../types").DSQL_DatabaseSchemaType | undefined;
try {
const localDbSchemaPath = path.resolve(

View File

@ -1,16 +1,16 @@
import http from "http";
import fs from "fs";
import path from "path";
import encrypt from "../package-shared/functions/dsql/encrypt";
import grabHostNames from "../package-shared/utils/grab-host-names";
import apiLoginUser from "../package-shared/functions/api/users/api-login";
import getAuthCookieNames from "../package-shared/functions/backend/cookies/get-auth-cookie-names";
import { writeAuthFile } from "../package-shared/functions/backend/auth/write-auth-files";
import encrypt from "../../functions/dsql/encrypt";
import grabHostNames from "../../utils/grab-host-names";
import apiLoginUser from "../../functions/api/users/api-login";
import getAuthCookieNames from "../../functions/backend/cookies/get-auth-cookie-names";
import { writeAuthFile } from "../../functions/backend/auth/write-auth-files";
import {
APILoginFunctionReturn,
DSQL_DatabaseSchemaType,
PackageUserLoginRequestBody,
} from "../package-shared/types";
} from "../../types";
type Param = {
key?: string;
@ -107,11 +107,10 @@ export default async function loginUser({
* Initialize HTTP response variable
*/
/** @type {import("../package-shared/types").APILoginFunctionReturn} */
let httpResponse: import("../package-shared/types").APILoginFunctionReturn =
{
success: false,
};
/** @type {import("../../types").APILoginFunctionReturn} */
let httpResponse: import("../../types").APILoginFunctionReturn = {
success: false,
};
/**
* Check for local DB settings

View File

@ -1,11 +1,11 @@
import http from "http";
import getAuthCookieNames from "../package-shared/functions/backend/cookies/get-auth-cookie-names";
import decrypt from "../package-shared/functions/dsql/decrypt";
import EJSON from "../package-shared/utils/ejson";
import { deleteAuthFile } from "../package-shared/functions/backend/auth/write-auth-files";
import parseCookies from "../package-shared/utils/backend/parseCookies";
import { DATASQUIREL_LoggedInUser } from "../package-shared/types";
import grabHostNames from "../package-shared/utils/grab-host-names";
import getAuthCookieNames from "../../functions/backend/cookies/get-auth-cookie-names";
import decrypt from "../../functions/dsql/decrypt";
import EJSON from "../../utils/ejson";
import { deleteAuthFile } from "../../functions/backend/auth/write-auth-files";
import parseCookies from "../../utils/backend/parseCookies";
import { DATASQUIREL_LoggedInUser } from "../../types";
import grabHostNames from "../../utils/grab-host-names";
type Param = {
encryptedUserString?: string;

View File

@ -2,17 +2,17 @@ import http from "http";
import https from "https";
import fs from "fs";
import path from "path";
import encrypt from "../package-shared/functions/dsql/encrypt";
import encrypt from "../../functions/dsql/encrypt";
import userAuth from "./user-auth";
import grabHostNames from "../package-shared/utils/grab-host-names";
import apiReauthUser from "../package-shared/functions/api/users/api-reauth-user";
import grabHostNames from "../../utils/grab-host-names";
import apiReauthUser from "../../functions/api/users/api-reauth-user";
import {
writeAuthFile,
deleteAuthFile,
} from "../package-shared/functions/backend/auth/write-auth-files";
import getAuthCookieNames from "../package-shared/functions/backend/cookies/get-auth-cookie-names";
import { APILoginFunctionReturn } from "../package-shared/types";
} from "../../functions/backend/auth/write-auth-files";
import getAuthCookieNames from "../../functions/backend/cookies/get-auth-cookie-names";
import { APILoginFunctionReturn } from "../../types";
type Param = {
key?: string;
@ -92,10 +92,8 @@ export default async function reauthUser({
DSQL_DB_NAME?.match(/./) &&
global.DSQL_USE_LOCAL
) {
/** @type {import("../package-shared/types").DSQL_DatabaseSchemaType | undefined} */
let dbSchema:
| import("../package-shared/types").DSQL_DatabaseSchemaType
| undefined;
/** @type {import("../../types").DSQL_DatabaseSchemaType | undefined} */
let dbSchema: import("../../types").DSQL_DatabaseSchemaType | undefined;
try {
const localDbSchemaPath = path.resolve(

View File

@ -1,9 +1,9 @@
import http from "http";
import fs from "fs";
import path from "path";
import grabHostNames from "../package-shared/utils/grab-host-names";
import apiSendEmailCode from "../package-shared/functions/api/users/api-send-email-code";
import { SendOneTimeCodeEmailResponse } from "../package-shared/types";
import grabHostNames from "../../utils/grab-host-names";
import apiSendEmailCode from "../../functions/api/users/api-send-email-code";
import { SendOneTimeCodeEmailResponse } from "../../types";
type Param = {
key?: string;
@ -17,7 +17,7 @@ type Param = {
mail_port?: number;
sender?: string;
user_id?: boolean;
extraCookies?: import("../package-shared/types").CookieObject[];
extraCookies?: import("../../types").CookieObject[];
};
/**
@ -62,10 +62,8 @@ export default async function sendEmailCode({
DSQL_DB_NAME?.match(/./) &&
global.DSQL_USE_LOCAL
) {
/** @type {import("../package-shared/types").DSQL_DatabaseSchemaType | undefined} */
let dbSchema:
| import("../package-shared/types").DSQL_DatabaseSchemaType
| undefined;
/** @type {import("../../types").DSQL_DatabaseSchemaType | undefined} */
let dbSchema: import("../../types").DSQL_DatabaseSchemaType | undefined;
try {
const localDbSchemaPath = path.resolve(
@ -94,9 +92,9 @@ export default async function sendEmailCode({
*
* @description make a request to datasquirel.com
*
* @type {import("../package-shared/types").SendOneTimeCodeEmailResponse}
* @type {import("../../types").SendOneTimeCodeEmailResponse}
*/
const httpResponse: import("../package-shared/types").SendOneTimeCodeEmailResponse =
const httpResponse: import("../../types").SendOneTimeCodeEmailResponse =
await new Promise((resolve, reject) => {
const reqPayload = JSON.stringify({
email,

View File

@ -1,9 +1,9 @@
import http from "http";
import fs from "fs";
import path from "path";
import encrypt from "../../package-shared/functions/dsql/encrypt";
import grabHostNames from "../../package-shared/utils/grab-host-names";
import apiGithubLogin from "../../package-shared/functions/api/users/social/api-github-login";
import encrypt from "../../../functions/dsql/encrypt";
import grabHostNames from "../../../utils/grab-host-names";
import apiGithubLogin from "../../../functions/api/users/social/api-github-login";
interface FunctionReturn {
success: boolean;
@ -108,9 +108,9 @@ export default async function githubAuth({
DSQL_DB_PASSWORD?.match(/./) &&
DSQL_DB_NAME?.match(/./)
) {
/** @type {import("../../package-shared/types").DSQL_DatabaseSchemaType | undefined | undefined} */
/** @type {import("../../../types").DSQL_DatabaseSchemaType | undefined | undefined} */
let dbSchema:
| import("../../package-shared/types").DSQL_DatabaseSchemaType
| import("../../../types").DSQL_DatabaseSchemaType
| undefined
| undefined;

View File

@ -1,10 +1,10 @@
import http from "http";
import encrypt from "../../package-shared/functions/dsql/encrypt";
import grabHostNames from "../../package-shared/utils/grab-host-names";
import apiGoogleLogin from "../../package-shared/functions/api/users/social/api-google-login";
import getAuthCookieNames from "../../package-shared/functions/backend/cookies/get-auth-cookie-names";
import { writeAuthFile } from "../../package-shared/functions/backend/auth/write-auth-files";
import { APILoginFunctionReturn } from "../../package-shared/types";
import encrypt from "../../../functions/dsql/encrypt";
import grabHostNames from "../../../utils/grab-host-names";
import apiGoogleLogin from "../../../functions/api/users/social/api-google-login";
import getAuthCookieNames from "../../../functions/backend/cookies/get-auth-cookie-names";
import { writeAuthFile } from "../../../functions/backend/auth/write-auth-files";
import { APILoginFunctionReturn } from "../../../types";
type Param = {
key?: string;
@ -111,7 +111,7 @@ export default async function googleAuth({
* Make https request
*
* @description make a request to datasquirel.com
* @type {{ success: boolean, user: import("../../package-shared/types").DATASQUIREL_LoggedInUser | null, msg?: string, dsqlUserId?: number } | null } - Https response object
* @type {{ success: boolean, user: import("../../../types").DATASQUIREL_LoggedInUser | null, msg?: string, dsqlUserId?: number } | null } - Https response object
*/
httpResponse = await new Promise((resolve, reject) => {
const reqPayload = JSON.stringify({

View File

@ -1,8 +1,8 @@
import path from "path";
import fs from "fs";
import grabHostNames from "../package-shared/utils/grab-host-names";
import apiUpdateUser from "../package-shared/functions/api/users/api-update-user";
import { UpdateUserFunctionReturn } from "../package-shared/types";
import grabHostNames from "../../utils/grab-host-names";
import apiUpdateUser from "../../functions/api/users/api-update-user";
import { UpdateUserFunctionReturn } from "../../types";
type Param = {
key?: string;
@ -40,10 +40,8 @@ export default async function updateUser({
DSQL_DB_NAME?.match(/./) &&
global.DSQL_USE_LOCAL
) {
/** @type {import("../package-shared/types").DSQL_DatabaseSchemaType | undefined} */
let dbSchema:
| import("../package-shared/types").DSQL_DatabaseSchemaType
| undefined;
/** @type {import("../../types").DSQL_DatabaseSchemaType | undefined} */
let dbSchema: import("../../types").DSQL_DatabaseSchemaType | undefined;
try {
const localDbSchemaPath = path.resolve(

View File

@ -1,11 +1,11 @@
import http from "http";
import decrypt from "../package-shared/functions/dsql/decrypt";
import getAuthCookieNames from "../package-shared/functions/backend/cookies/get-auth-cookie-names";
import { checkAuthFile } from "../package-shared/functions/backend/auth/write-auth-files";
import parseCookies from "../package-shared/utils/backend/parseCookies";
import { AuthenticatedUser } from "../package-shared/types";
import getCsrfHeaderName from "../utils/get-csrf-header-name";
import grabHostNames from "../package-shared/utils/grab-host-names";
import decrypt from "../../functions/dsql/decrypt";
import getAuthCookieNames from "../../functions/backend/cookies/get-auth-cookie-names";
import { checkAuthFile } from "../../functions/backend/auth/write-auth-files";
import parseCookies from "../../utils/backend/parseCookies";
import { AuthenticatedUser } from "../../types";
import getCsrfHeaderName from "../../actions/get-csrf-header-name";
import grabHostNames from "../../utils/grab-host-names";
const minuteInMilliseconds = 60000;
const hourInMilliseconds = minuteInMilliseconds * 60;
@ -114,8 +114,8 @@ export default function userAuth({
* @description Grab the payload
*/
/** @type {import("../package-shared/types").DATASQUIREL_LoggedInUser} */
let userObject: import("../package-shared/types").DATASQUIREL_LoggedInUser =
/** @type {import("../../types").DATASQUIREL_LoggedInUser} */
let userObject: import("../../types").DATASQUIREL_LoggedInUser =
JSON.parse(userPayloadJSON);
if (debug) {

View File

@ -1,9 +1,9 @@
import http from "http";
import getAuthCookieNames from "../package-shared/functions/backend/cookies/get-auth-cookie-names";
import parseCookies from "../package-shared/utils/backend/parseCookies";
import decrypt from "../package-shared/functions/dsql/decrypt";
import EJSON from "../package-shared/utils/ejson";
import { SendOneTimeCodeEmailResponse } from "../package-shared/types";
import getAuthCookieNames from "../../functions/backend/cookies/get-auth-cookie-names";
import parseCookies from "../../utils/backend/parseCookies";
import decrypt from "../../functions/dsql/decrypt";
import EJSON from "../../utils/ejson";
import { SendOneTimeCodeEmailResponse } from "../../types";
type Param = {
request?: http.IncomingMessage & { [s: string]: any };

View File

@ -1,6 +1,6 @@
import http from "http";
import decrypt from "../package-shared/functions/dsql/decrypt";
import { DATASQUIREL_LoggedInUser } from "../package-shared/types";
import decrypt from "../../functions/dsql/decrypt";
import { DATASQUIREL_LoggedInUser } from "../../types";
type Param = {
token: string;

View File

@ -53,22 +53,40 @@
"title": "TEXT",
"name": "TEXT",
"value": "0-100",
"description": "MEDIUMTEXT is just text with max length 16,777,215",
"maxValue": 127
"description": "MEDIUMTEXT is just text with max length 16,777,215"
},
{
"title": "MEDIUMTEXT",
"name": "MEDIUMTEXT",
"value": "0-255",
"description": "MEDIUMTEXT is just text with max length 16,777,215",
"maxValue": 127
"description": "MEDIUMTEXT is just text with max length 16,777,215"
},
{
"title": "LONGTEXT",
"name": "LONGTEXT",
"value": "0-255",
"description": "LONGTEXT is just text with max length 4,294,967,295",
"maxValue": 127
"description": "LONGTEXT is just text with max length 4,294,967,295"
},
{
"title": "DECIMAL",
"name": "DECIMAL",
"description": "Numbers with decimals",
"integer": "1-100",
"decimals": "1-4"
},
{
"title": "FLOAT",
"name": "FLOAT",
"description": "Numbers with decimals",
"integer": "1-100",
"decimals": "1-4"
},
{
"title": "DOUBLE",
"name": "DOUBLE",
"description": "Numbers with decimals",
"integer": "1-100",
"decimals": "1-4"
},
{
"title": "UUID",

View File

@ -34,7 +34,6 @@ export default async function apiPost({
return { success: false, msg: "Wrong Input" };
}
/** @type {any} */
let results: any;
/**

View File

@ -32,7 +32,6 @@ export default async function apiDeleteUser({
const deleteUser = await deleteDbEntry({
dbContext: "Dsql User",
paradigm: "Full Access",
dbFullName,
tableName: "users",
identifierColumnName: "id",

View File

@ -81,7 +81,6 @@ export default async function apiUpdateUser({
const updateUser = await updateDbEntry({
dbContext: "Dsql User",
paradigm: "Full Access",
dbFullName,
tableName: "users",
identifierColumnName: "id",

View File

@ -1,7 +1,7 @@
import fs from "fs";
import serverError from "./serverError";
import mysql from "serverless-mysql";
import grabDSQLConnection from "../../utils/grab-dsql-connection";
import path from "path";
/**
* # Main DB Handler Function
@ -37,8 +37,12 @@ export default async function dbHandler(...args: any[]) {
);
});
} catch (error: any) {
const tmpFolder = path.resolve(process.cwd(), "./.tmp");
if (!fs.existsSync(tmpFolder))
fs.mkdirSync(tmpFolder, { recursive: true });
fs.appendFileSync(
"./.tmp/dbErrorLogs.txt",
path.resolve(tmpFolder, "./dbErrorLogs.txt"),
JSON.stringify(error, null, 4) + "\n" + Date() + "\n\n\n",
"utf8"
);

View File

@ -1,8 +1,5 @@
import fs from "fs";
import path from "path";
import mysql from "serverless-mysql";
import grabDbSSL from "../../utils/backend/grabDbSSL";
import grabDSQLConnection from "../../utils/grab-dsql-connection";
type Param = {
@ -37,8 +34,12 @@ export default async function dbHandler({
console.log(error);
console.log(CONNECTION.config());
const tmpFolder = path.resolve(process.cwd(), "./.tmp");
if (!fs.existsSync(tmpFolder))
fs.mkdirSync(tmpFolder, { recursive: true });
fs.appendFileSync(
path.resolve(__dirname, "../.tmp/dbErrorLogs.txt"),
path.resolve(tmpFolder, "./dbErrorLogs.txt"),
JSON.stringify(error, null, 4) + "\n" + Date() + "\n\n\n",
"utf8"
);

View File

@ -41,7 +41,17 @@ export interface DSQL_ChildrenTablesType {
tableNameFull?: string;
}
export interface DSQL_FieldSchemaType {
export const TextFieldTypesArray = [
{ title: "Plain Text", value: "plain" },
{ title: "Rich Text", value: "richText" },
{ title: "JSON", value: "json" },
{ title: "YAML", value: "yaml" },
{ title: "HTML", value: "html" },
{ title: "CSS", value: "css" },
{ title: "Javascript", value: "javascript" },
] as const;
export type DSQL_FieldSchemaType = {
fieldName?: string;
originName?: string;
updatedField?: boolean;
@ -54,13 +64,6 @@ export interface DSQL_FieldSchemaType {
defaultValue?: string | number;
defaultValueLiteral?: string;
foreignKey?: DSQL_ForeignKeyType;
richText?: boolean;
json?: boolean;
yaml?: boolean;
html?: boolean;
css?: boolean;
javascript?: boolean;
shell?: boolean;
newTempField?: boolean;
defaultField?: boolean;
plainText?: boolean;
@ -72,7 +75,11 @@ export interface DSQL_FieldSchemaType {
onDelete?: string;
onDeleteLiteral?: string;
cssFiles?: string[];
}
integerLength?: string | number;
decimals?: string | number;
} & {
[key in (typeof TextFieldTypesArray)[number]["value"]]?: boolean;
};
export interface DSQL_ForeignKeyType {
foreignKeyName?: string;
@ -923,6 +930,7 @@ export interface MYSQL_user_database_tables_table_def {
table_slug?: string;
table_description?: string;
child_table?: number;
active_data?: 0 | 1;
child_table_parent_database?: string;
child_table_parent_table?: string;
date_created?: string;

View File

@ -0,0 +1,95 @@
import get from "../../actions/get";
import post from "../../actions/post";
import sqlGenerator from "../../functions/dsql/sql/sql-generator";
import {
PostReturn,
ServerQueryParam,
ServerQueryQueryObject,
} from "../../types";
import numberfy from "../numberfy";
export const DsqlCrudActions = ["insert", "update", "delete", "get"] as const;
export type CrudQueryObject<T extends object = { [key: string]: any }> =
ServerQueryParam & {
query: ServerQueryQueryObject<T>;
};
export type CrudParam<T extends object = { [key: string]: any }> = {
action: (typeof DsqlCrudActions)[number];
table: string;
data?: T;
targetId?: string | number;
query?: CrudQueryObject<T>;
sanitize?: (data?: T) => T;
};
export default async function dsqlCrud<
T extends { [key: string]: any } = { [key: string]: any }
>({
action,
data,
table,
targetId,
query,
sanitize,
}: CrudParam<T>): Promise<
| (PostReturn & {
queryObject?: ReturnType<Awaited<typeof sqlGenerator>>;
})
| null
> {
const finalData = sanitize ? sanitize(data) : data;
const finalId = targetId;
let queryObject: ReturnType<Awaited<typeof sqlGenerator>> | undefined;
switch (action) {
case "get":
queryObject = sqlGenerator({
tableName: table,
genObject: query,
});
const GET_RES = await get({
query: queryObject?.string || "",
queryValues: queryObject?.values || [],
});
return { ...GET_RES, queryObject };
case "insert":
return await post({
query: {
action: "insert",
table,
data: finalData,
},
});
case "update":
delete data?.id;
return await post({
query: {
action: "update",
table,
identifierColumnName: "id",
identifierValue: String(finalId),
data: finalData,
},
});
case "delete":
return await post({
query: {
action: "delete",
table,
identifierColumnName: "id",
identifierValue: String(finalId),
},
});
default:
return null;
}
}

View File

@ -0,0 +1,180 @@
import { DATASQUIREL_LoggedInUser, ServerQueryParam } from "../../types";
import EJSON from "../ejson";
import dsqlCrud from "./crud";
export const DataCrudRequestMethods = ["GET", "POST", "PUT", "DELETE"] as const;
export type APIDataCrudQuery = ServerQueryParam & {
page?: number;
};
export type CRUDResponseObject<P extends any = any> = {
success: boolean;
payload?: P;
msg?: string;
error?: string;
};
export type ApiDataCrudParam<
T extends { [key: string]: any } = { [key: string]: any }
> = {
method: (typeof DataCrudRequestMethods)[number];
body?: T;
query?: string | T;
tableName: string;
addUser?: {
field: string;
};
user?: DATASQUIREL_LoggedInUser;
extraData?: T;
transform?: ({
data,
existingData,
user,
}: {
user?: DATASQUIREL_LoggedInUser;
data: T;
existingData?: T;
reqMethod: (typeof DataCrudRequestMethods)[number];
}) => Promise<T>;
existingData?: T;
};
export default async function dsqlMethodCrud<
T extends { [key: string]: any } = { [key: string]: any },
P extends { [key: string]: any } = { [key: string]: any }
>({
method,
tableName,
addUser,
user,
extraData,
transform,
existingData,
body,
query,
}: ApiDataCrudParam<T>): Promise<CRUDResponseObject<P>> {
let result: CRUDResponseObject = {
success: false,
};
try {
let finalBody = body as any;
let finalQuery = query as any;
Object.keys(finalQuery).forEach((key) => {
const value = finalQuery[key];
if (typeof value == "string" && value.match(/^\{|^\[/)) {
finalQuery[key] = EJSON.stringify(value);
}
if (value == "true") {
finalQuery[key] = true;
}
if (value == "false") {
finalQuery[key] = false;
}
});
const LIMIT = finalQuery.limit || 10;
const PAGE = finalQuery.page || 1;
const OFFSET = (PAGE - 1) * LIMIT;
let finalData = {
...finalBody.data,
...extraData,
} as T;
if (user && addUser) {
finalData = {
...finalData,
[addUser.field]: String(user.id),
};
}
if (transform) {
finalData = await transform({
data: finalData,
existingData: existingData,
user,
reqMethod: method as (typeof DataCrudRequestMethods)[number],
});
}
switch (method) {
case "GET":
const GET_RESULT = await dsqlCrud({
action: "get",
table: tableName,
query: {
...finalQuery,
query: {
...finalQuery.query,
user_id: user
? {
value: String(user.id),
}
: undefined,
},
limit: LIMIT,
offset: OFFSET || undefined,
},
});
result = {
success: Boolean(GET_RESULT?.success),
payload: GET_RESULT?.payload,
msg: GET_RESULT?.msg,
error: GET_RESULT?.error,
};
break;
case "POST":
const POST_RESULT = await dsqlCrud({
action: "insert",
table: tableName,
data: finalData,
});
result = {
success: Boolean(POST_RESULT?.success),
payload: POST_RESULT?.payload,
msg: POST_RESULT?.msg,
error: POST_RESULT?.error,
};
break;
case "PUT":
const PUT_RESULT = await dsqlCrud({
action: "update",
table: tableName,
data: finalData,
targetId: finalBody.data.id,
});
result = {
success: Boolean(PUT_RESULT?.success),
payload: PUT_RESULT?.payload,
msg: PUT_RESULT?.msg,
error: PUT_RESULT?.error,
};
break;
case "DELETE":
const DELETE_RESULT = await dsqlCrud({
action: "delete",
table: tableName,
targetId: finalBody.data.id,
});
result = {
success: Boolean(DELETE_RESULT?.success),
payload: DELETE_RESULT?.payload,
msg: DELETE_RESULT?.msg,
error: DELETE_RESULT?.error,
};
break;
default:
break;
}
return result;
} catch (error) {
return result;
}
}

View File

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

View File

@ -6,6 +6,7 @@ else
msg="$1"
fi
rm -rf dist
tsc
git add .
git commit -m "$msg"

View File

@ -26,7 +26,7 @@
"package-shared/functions/dsql",
"types",
"users",
"utils",
"actions",
"package-shared",
"client"
],