From 59c6f6dd40a671ef7800cb0469db2ab2b1d32df4 Mon Sep 17 00:00:00 2001 From: Benjamin Toby Date: Fri, 18 Oct 2024 05:15:04 +0100 Subject: [PATCH] Update types --- engine/engine/addUsersTableToDb.js | 4 +- engine/engine/createDbFromSchema.js | 8 +-- engine/engine/utils/createTable.js | 2 +- engine/engine/utils/dbHandler.js | 2 +- .../engine/utils/generateColumnDescription.js | 2 +- engine/engine/utils/parseDbResults.js | 2 +- engine/engine/utils/supplementTable.js | 2 +- engine/engine/utils/updateTable.js | 18 ++++--- engine/engine/utils/varDatabaseDbHandler.js | 2 +- engine/query/get.js | 2 +- engine/query/post.js | 2 +- engine/query/utils/addDbEntry.js | 2 +- engine/query/utils/deleteDbEntry.js | 2 +- engine/query/utils/runQuery.js | 2 +- engine/query/utils/updateDbEntry.js | 2 +- engine/user/add-user.js | 2 +- engine/user/get-user.js | 2 +- engine/user/reauth-user.js | 2 +- engine/user/send-email-code.js | 2 +- engine/user/social/github-auth.js | 2 +- engine/user/social/google-auth.js | 2 +- engine/user/social/utils/handleSocialDb.js | 2 +- engine/user/update-user.js | 2 +- functions/decrypt.js | 1 + functions/encrypt.js | 1 + package-shared/types/database-schema.td.js | 52 +++++++++++++------ package-shared/types/package-shared-index.js | 13 ++++- package.json | 2 +- users/add-user.js | 2 +- users/get-user.js | 2 +- users/login-user.js | 2 +- users/reauth-user.js | 2 +- users/send-email-code.js | 2 +- users/social/github-auth.js | 2 +- users/social/google-auth.js | 2 +- users/update-user.js | 2 +- utils/get-schema.js | 2 +- utils/get.js | 10 +--- utils/post.js | 2 +- 39 files changed, 97 insertions(+), 72 deletions(-) diff --git a/engine/engine/addUsersTableToDb.js b/engine/engine/addUsersTableToDb.js index bbae881..755ec07 100644 --- a/engine/engine/addUsersTableToDb.js +++ b/engine/engine/addUsersTableToDb.js @@ -22,7 +22,7 @@ const updateApiSchemaFromLocalDb = require("../query/update-api-schema-from-loca * ============================================================================== * * @param {object} params - Single object passed - * @param {import("@/package-shared/types/database-schema.td").DSQL_DatabaseSchemaType | undefined} params.dbSchema - Database Schema Object + * @param {DSQL_DatabaseSchemaType | undefined} params.dbSchema - Database Schema Object * * @returns {Promise<*>} new user auth object payload */ @@ -33,7 +33,7 @@ module.exports = async function addUsersTableToDb({ dbSchema }) { * @description Initialize */ const database = process.env.DSQL_DB_NAME || ""; - /** @type {import("@/package-shared/types/database-schema.td").DSQL_TableSchemaType} */ + /** @type {DSQL_TableSchemaType} */ const userPreset = require("./data/presets/users.json"); try { diff --git a/engine/engine/createDbFromSchema.js b/engine/engine/createDbFromSchema.js index b0e38aa..89e104b 100644 --- a/engine/engine/createDbFromSchema.js +++ b/engine/engine/createDbFromSchema.js @@ -27,7 +27,7 @@ const updateTable = require("./utils/updateTable"); * runs the "dsql create" command. `NOTE`: there must be a "dsql.schema.json" file * in the root of the project for this function to work * - * @param {import("@/package-shared/types/database-schema.td").DSQL_DatabaseSchemaType | undefined} dbSchema - An array of database schema objects + * @param {DSQL_DatabaseSchemaType | undefined} dbSchema - An array of database schema objects */ async function createDbFromSchema(dbSchema) { try { @@ -42,7 +42,7 @@ async function createDbFromSchema(dbSchema) { } for (let i = 0; i < dbSchema.length; i++) { - /** @type {import("@/package-shared/types/database-schema.td").DSQL_DatabaseSchemaType | undefined} */ + /** @type {DSQL_DatabaseSchemaType | undefined} */ const database = dbSchema[i]; if (!database) { @@ -262,11 +262,11 @@ async function createDbFromSchema(dbSchema) { */ await varDatabaseDbHandler({ queryString: `CREATE${ - indexType.match(/fullText/i) + indexType?.match(/fullText/i) ? " FULLTEXT" : "" } INDEX \`${alias}\` ON ${tableName}(${indexTableFields - .map((nm) => nm.value) + ?.map((nm) => nm.value) .map((nm) => `\`${nm}\``) .join( "," diff --git a/engine/engine/utils/createTable.js b/engine/engine/utils/createTable.js index eba4678..874c64c 100644 --- a/engine/engine/utils/createTable.js +++ b/engine/engine/utils/createTable.js @@ -17,7 +17,7 @@ const supplementTable = require("./supplementTable"); * @param {string} param0.tableName * @param {any[]} param0.tableInfoArray * @param {(params: import("./varDatabaseDbHandler").VarDbHandlerParam)=>any} param0.varDatabaseDbHandler - * @param {import("@/package-shared/types/database-schema.td").DSQL_DatabaseSchemaType} [param0.dbSchema] + * @param {DSQL_DatabaseSchemaType} [param0.dbSchema] * @returns */ module.exports = async function createTable({ diff --git a/engine/engine/utils/dbHandler.js b/engine/engine/utils/dbHandler.js index 81b41ea..7daa4bb 100644 --- a/engine/engine/utils/dbHandler.js +++ b/engine/engine/utils/dbHandler.js @@ -65,7 +65,7 @@ const connection = mysql.createConnection({ * @param {object} params - Single Param object containing params * @param {string} params.query - Query String * @param {(string | number)[]} [params.values] - Values - * @param {import("../../../package-shared/types/database-schema.td").DSQL_DatabaseSchemaType} [params.dbSchema] - Database Schema + * @param {DSQL_DatabaseSchemaType} [params.dbSchema] - Database Schema * @param {string} [params.database] - Target Database * @param {string} [params.tableName] - Target Table Name * diff --git a/engine/engine/utils/generateColumnDescription.js b/engine/engine/utils/generateColumnDescription.js index 568db9d..e2dd0b9 100644 --- a/engine/engine/utils/generateColumnDescription.js +++ b/engine/engine/utils/generateColumnDescription.js @@ -11,7 +11,7 @@ * Generate SQL text for Field * ============================================================================== * @param {object} params - Single object params - * @param {import("@/package-shared/types/database-schema.td").DSQL_FieldSchemaType} params.columnData - Field object + * @param {DSQL_FieldSchemaType} params.columnData - Field object * @param {boolean} [params.primaryKeySet] - Table Name(slug) * * @returns {{fieldEntryText: string, newPrimaryKeySet: boolean}} diff --git a/engine/engine/utils/parseDbResults.js b/engine/engine/utils/parseDbResults.js index c1bf767..30bd39c 100644 --- a/engine/engine/utils/parseDbResults.js +++ b/engine/engine/utils/parseDbResults.js @@ -14,7 +14,7 @@ const defaultFieldsRegexp = require("./defaultFieldsRegexp"); * @param {object} params - Single object params * @param {*[]} params.unparsedResults - Array of data objects containing Fields(keys) * and corresponding values of the fields(values) - * @param {import("../../../package-shared/types/database-schema.td").DSQL_TableSchemaType} [params.tableSchema] - Table schema + * @param {DSQL_TableSchemaType} [params.tableSchema] - Table schema * @returns {Promise} */ module.exports = async function parseDbResults({ diff --git a/engine/engine/utils/supplementTable.js b/engine/engine/utils/supplementTable.js index 50b308e..c730f6c 100644 --- a/engine/engine/utils/supplementTable.js +++ b/engine/engine/utils/supplementTable.js @@ -10,7 +10,7 @@ /** * * @param {object} param0 - * @param {import("@/package-shared/types/database-schema.td").DSQL_FieldSchemaType[]} param0.tableInfoArray + * @param {DSQL_FieldSchemaType[]} param0.tableInfoArray * @returns */ module.exports = function supplementTable({ tableInfoArray }) { diff --git a/engine/engine/utils/updateTable.js b/engine/engine/utils/updateTable.js index 3f21de2..dd95b5b 100644 --- a/engine/engine/utils/updateTable.js +++ b/engine/engine/utils/updateTable.js @@ -31,9 +31,9 @@ const schemaPath = path.resolve(process.cwd(), "dsql.schema.json"); * @param {object} params - Single object params * @param {string} params.dbFullName - Database full name => "datasquirel_user_4394_db_name" * @param {string} params.tableName - Table Name(slug) - * @param {import("@/package-shared/types/database-schema.td").DSQL_FieldSchemaType[]} params.tableInfoArray - Table Info Array - * @param {import("@/package-shared/types/database-schema.td").DSQL_DatabaseSchemaType[]} params.dbSchema - Single post - * @param {import("@/package-shared/types/database-schema.td").DSQL_IndexSchemaType[]} [params.tableIndexes] - Table Indexes + * @param {DSQL_FieldSchemaType[]} params.tableInfoArray - Table Info Array + * @param {DSQL_DatabaseSchemaType[]} params.dbSchema - Single post + * @param {DSQL_IndexSchemaType[]} [params.tableIndexes] - Table Indexes * @param {boolean} [params.clone] - Is this a newly cloned table? * @param {number} [params.tableIndex] - The number index of the table in the dbSchema array * @@ -141,7 +141,9 @@ module.exports = async function updateTable({ * @description Check if Field name has been updated */ if (existingEntry[0].updatedField) { - updatedColumnsArray.push(existingEntry[0].fieldName); + updatedColumnsArray.push( + String(existingEntry[0].fieldName) + ); const renameColumn = await varDatabaseDbHandler({ queryString: `ALTER TABLE ${tableName} RENAME COLUMN \`${existingEntry[0].originName}\` TO \`${existingEntry[0].fieldName}\``, @@ -293,9 +295,9 @@ module.exports = async function updateTable({ */ await varDatabaseDbHandler({ queryString: `CREATE${ - indexType.match(/fullText/i) ? " FULLTEXT" : "" + indexType?.match(/fullText/i) ? " FULLTEXT" : "" } INDEX \`${alias}\` ON ${tableName}(${indexTableFields - .map((nm) => nm.value) + ?.map((nm) => nm.value) .map((nm) => `\`${nm}\``) .join(",")}) COMMENT 'schema_index'`, database: dbFullName, @@ -375,7 +377,7 @@ module.exports = async function updateTable({ /** * @description Skip default fields */ - if (fieldName.match(/^id$|^date_/)) continue; + if (fieldName?.match(/^id$|^date_/)) continue; /** * @description Skip columns that have been updated recently */ @@ -424,7 +426,7 @@ module.exports = async function updateTable({ if ( Field === fieldName && !isColumnReordered && - dataType.toUpperCase() === Type.toUpperCase() + dataType?.toUpperCase() === Type.toUpperCase() ) { updateText += `MODIFY COLUMN ${fieldEntryText}`; // continue; diff --git a/engine/engine/utils/varDatabaseDbHandler.js b/engine/engine/utils/varDatabaseDbHandler.js index 6595234..6b8207f 100644 --- a/engine/engine/utils/varDatabaseDbHandler.js +++ b/engine/engine/utils/varDatabaseDbHandler.js @@ -24,7 +24,7 @@ const dbHandler = require("./dbHandler"); * @property {string} queryString - SQL string * @property {string[]} [queryValuesArray] - Values Array * @property {string} database - Database name - * @property {import("@/package-shared/types/database-schema.td").DSQL_TableSchemaType} [tableSchema] - Table schema + * @property {DSQL_TableSchemaType} [tableSchema] - Table schema */ /** diff --git a/engine/query/get.js b/engine/query/get.js index 790240e..c089fdf 100644 --- a/engine/query/get.js +++ b/engine/query/get.js @@ -29,7 +29,7 @@ const runQuery = require("./utils/runQuery"); * * @param {Object} params - Single object passed * @param {LocalQueryObject} params.options - SQL Query - * @param {import("@/package-shared/types/database-schema.td").DSQL_DatabaseSchemaType | undefined} [params.dbSchema] - Name of the table to query + * @param {DSQL_DatabaseSchemaType | undefined} [params.dbSchema] - Name of the table to query * * @returns { Promise } - Return Object */ diff --git a/engine/query/post.js b/engine/query/post.js index 3bc6913..42925c3 100644 --- a/engine/query/post.js +++ b/engine/query/post.js @@ -24,7 +24,7 @@ const runQuery = require("./utils/runQuery"); * * @param {Object} params - Single object passed * @param {LocalPostQueryObject} params.options - SQL Query - * @param {import("@/package-shared/types/database-schema.td").DSQL_DatabaseSchemaType | undefined} [params.dbSchema] - Name of the table to query + * @param {DSQL_DatabaseSchemaType | undefined} [params.dbSchema] - Name of the table to query * * @returns { Promise } - Return Object */ diff --git a/engine/query/utils/addDbEntry.js b/engine/query/utils/addDbEntry.js index 2589777..2234fa6 100644 --- a/engine/query/utils/addDbEntry.js +++ b/engine/query/utils/addDbEntry.js @@ -19,7 +19,7 @@ const updateDbEntry = require("./updateDbEntry"); * @param {string} params.dbFullName - Database full name * @param {string} params.tableName - Table name * @param {*} params.data - Data to add - * @param {import("@/package-shared/types/database-schema.td").DSQL_TableSchemaType} [params.tableSchema] - Table schema + * @param {DSQL_TableSchemaType} [params.tableSchema] - Table schema * @param {string} [params.duplicateColumnName] - Duplicate column name * @param {string} [params.duplicateColumnValue] - Duplicate column value * @param {boolean} [params.update] - Update this row if it exists diff --git a/engine/query/utils/deleteDbEntry.js b/engine/query/utils/deleteDbEntry.js index 1512ae7..2ee498e 100644 --- a/engine/query/utils/deleteDbEntry.js +++ b/engine/query/utils/deleteDbEntry.js @@ -19,7 +19,7 @@ const dbHandler = require("../../engine/utils/dbHandler"); * "Read only" or "Full Access"? Defaults to "Read Only" * @param {string} params.dbFullName - Database full name * @param {string} params.tableName - Table name - * @param {import("@/package-shared/types/database-schema.td").DSQL_TableSchemaType} [params.tableSchema] - Table schema + * @param {DSQL_TableSchemaType} [params.tableSchema] - Table schema * @param {string} params.identifierColumnName - Update row identifier column name * @param {string|number} params.identifierValue - Update row identifier column value * diff --git a/engine/query/utils/runQuery.js b/engine/query/utils/runQuery.js index f544178..38dfac3 100644 --- a/engine/query/utils/runQuery.js +++ b/engine/query/utils/runQuery.js @@ -31,7 +31,7 @@ const varDatabaseDbHandler = require("../../engine/utils/varDatabaseDbHandler"); * @param {string} params.dbFullName - Database full name. Eg. "datasquire_user_2_test" * @param {*} params.query - Query string or object * @param {boolean} [params.readOnly] - Is this operation read only? - * @param {import("@/package-shared/types/database-schema.td").DSQL_DatabaseSchemaType} [params.dbSchema] - Database schema + * @param {DSQL_DatabaseSchemaType} [params.dbSchema] - Database schema * @param {string[]} [params.queryValuesArray] - An optional array of query values if "?" is used in the query string * @param {string} [params.tableName] - Table Name * diff --git a/engine/query/utils/updateDbEntry.js b/engine/query/utils/updateDbEntry.js index bdfae94..076f347 100644 --- a/engine/query/utils/updateDbEntry.js +++ b/engine/query/utils/updateDbEntry.js @@ -21,7 +21,7 @@ const dbHandler = require("../../engine/utils/dbHandler"); * @param {string} params.dbFullName - Database full name * @param {string} params.tableName - Table name * @param {*} params.data - Data to add - * @param {import("@/package-shared/types/database-schema.td").DSQL_TableSchemaType} [params.tableSchema] - Table schema + * @param {DSQL_TableSchemaType} [params.tableSchema] - Table schema * @param {string} params.identifierColumnName - Update row identifier column name * @param {string | number} params.identifierValue - Update row identifier column value * @param {string} params.encryptionKey - Encryption key diff --git a/engine/user/add-user.js b/engine/user/add-user.js index 6de807d..663d52e 100644 --- a/engine/user/add-user.js +++ b/engine/user/add-user.js @@ -21,7 +21,7 @@ const runQuery = require("../query/utils/runQuery"); * * @param {Object} params - Single object passed * @param {import("@/types/user.td").UserDataPayload} params.payload - SQL Query - * @param {import("@/package-shared/types/database-schema.td").DSQL_DatabaseSchemaType | undefined} params.dbSchema - Name of the table to query + * @param {DSQL_DatabaseSchemaType | undefined} params.dbSchema - Name of the table to query * @param {string} [params.encryptionKey] * @param {string} [params.encryptionSalt] * diff --git a/engine/user/get-user.js b/engine/user/get-user.js index 24aa168..00171c3 100644 --- a/engine/user/get-user.js +++ b/engine/user/get-user.js @@ -7,7 +7,7 @@ const varDatabaseDbHandler = require("../engine/utils/varDatabaseDbHandler"); * @param {object} param0 * @param {number} param0.userId * @param {string[]} param0.fields - * @param {import("@/package-shared/types/database-schema.td").DSQL_DatabaseSchemaType | undefined} [param0.dbSchema] + * @param {DSQL_DatabaseSchemaType | undefined} [param0.dbSchema] * @returns */ async function getLocalUser({ userId, fields, dbSchema }) { diff --git a/engine/user/reauth-user.js b/engine/user/reauth-user.js index df9e783..b900985 100644 --- a/engine/user/reauth-user.js +++ b/engine/user/reauth-user.js @@ -7,7 +7,7 @@ const varDatabaseDbHandler = require("../engine/utils/varDatabaseDbHandler"); * @param {object} param0 * @param {*} param0.existingUser * @param {string[]} [param0.additionalFields] - * @param {import("@/package-shared/types/database-schema.td").DSQL_DatabaseSchemaType | undefined} [param0.dbSchema] + * @param {DSQL_DatabaseSchemaType | undefined} [param0.dbSchema] * @returns */ async function localReauthUser({ existingUser, additionalFields, dbSchema }) { diff --git a/engine/user/send-email-code.js b/engine/user/send-email-code.js index 5d76a3b..4ac066d 100644 --- a/engine/user/send-email-code.js +++ b/engine/user/send-email-code.js @@ -10,7 +10,7 @@ const path = require("path"); * * @param {object} param0 * @param {string} param0.email - * @param {import("@/package-shared/types/database-schema.td").DSQL_DatabaseSchemaType | undefined} [param0.dbSchema] + * @param {DSQL_DatabaseSchemaType | undefined} [param0.dbSchema] * @param {string} param0.email_login_field * @param {string} [param0.mail_domain] * @param {string} [param0.mail_username] diff --git a/engine/user/social/github-auth.js b/engine/user/social/github-auth.js index 81509b1..1f34fce 100644 --- a/engine/user/social/github-auth.js +++ b/engine/user/social/github-auth.js @@ -36,7 +36,7 @@ const encryptionSalt = process.env.DSQL_ENCRYPTION_SALT || ""; * @param {string} params.clientId * @param {string} params.clientSecret * @param {object} [params.additionalFields] - * @param {import("@/package-shared/types/database-schema.td").DSQL_DatabaseSchemaType} params.dbSchema + * @param {DSQL_DatabaseSchemaType} params.dbSchema */ async function localGithubAuth({ res, diff --git a/engine/user/social/google-auth.js b/engine/user/social/google-auth.js index 679dc15..1b4176e 100644 --- a/engine/user/social/google-auth.js +++ b/engine/user/social/google-auth.js @@ -44,7 +44,7 @@ const encryptionSalt = process.env.DSQL_ENCRYPTION_SALT || ""; * @param {string} params.clientId - Google client id * @param {http.ServerResponse} params.response - HTTPS response object * @param {object} [params.additionalFields] - Additional Fields to be added to the user object - * @param {import("@/package-shared/types/database-schema.td").DSQL_DatabaseSchemaType} [params.dbSchema] - Database Schema + * @param {DSQL_DatabaseSchemaType} [params.dbSchema] - Database Schema * * @returns { Promise } */ diff --git a/engine/user/social/utils/handleSocialDb.js b/engine/user/social/utils/handleSocialDb.js index c9d2ef6..71cf238 100644 --- a/engine/user/social/utils/handleSocialDb.js +++ b/engine/user/social/utils/handleSocialDb.js @@ -74,7 +74,7 @@ const encryptionSalt = process.env.DSQL_ENCRYPTION_SALT || ""; * res: http.ServerResponse, * supEmail?: string | null, * additionalFields?: object, - * dbSchema: import("@/package-shared/types/database-schema.td").DSQL_DatabaseSchemaType | undefined + * dbSchema: DSQL_DatabaseSchemaType | undefined * }} params - function parameters inside an object * * @returns {Promise} - Response object diff --git a/engine/user/update-user.js b/engine/user/update-user.js index 34b9a8d..b4d43f1 100644 --- a/engine/user/update-user.js +++ b/engine/user/update-user.js @@ -17,7 +17,7 @@ const updateDbEntry = require("../query/utils/updateDbEntry"); * * @param {Object} params - Single object passed * @param {*} params.payload - SQL Query - * @param {import("@/package-shared/types/database-schema.td").DSQL_DatabaseSchemaType | undefined} params.dbSchema - Name of the table to query + * @param {DSQL_DatabaseSchemaType | undefined} params.dbSchema - Name of the table to query * * @returns { Promise } - Return Object */ diff --git a/functions/decrypt.js b/functions/decrypt.js index f4d194c..03c14c5 100644 --- a/functions/decrypt.js +++ b/functions/decrypt.js @@ -31,6 +31,7 @@ const decrypt = ({ encryptedString, encryptionKey, encryptionSalt }) => { let key = scryptSync(encryptionKey, encryptionSalt, 24); let iv = Buffer.alloc(16, 0); + // @ts-ignore const decipher = createDecipheriv(algorithm, key, iv); try { diff --git a/functions/encrypt.js b/functions/encrypt.js index dab1953..9007c7b 100644 --- a/functions/encrypt.js +++ b/functions/encrypt.js @@ -30,6 +30,7 @@ const encrypt = ({ data, encryptionKey, encryptionSalt }) => { let key = scryptSync(password, encryptionSalt, 24); let iv = Buffer.alloc(16, 0); + // @ts-ignore const cipher = createCipheriv(algorithm, key, iv); try { diff --git a/package-shared/types/database-schema.td.js b/package-shared/types/database-schema.td.js index ec4fff9..5f469ca 100644 --- a/package-shared/types/database-schema.td.js +++ b/package-shared/types/database-schema.td.js @@ -16,9 +16,15 @@ * @property {string} [dbDescription] - Database brief description * @property {string} [dbImage] - Database image - Defaults to "/images/default.png" * @property {DSQL_TableSchemaType[]} tables - List of database tables - * @property {{ dbFullName: string }[]} [childrenDatabases] - List of children databases for current database which is parent + * @property {DSQL_ChildrenDatabaseObject[]} [childrenDatabases] - List of children databases for current database which is parent * @property {boolean} [childDatabase] - If current database is a child of a different parent database * @property {string} [childDatabaseDbFullName] - Parent database full name => "datasquirel_user_7_new_database" + * @property {boolean} [updateData] - Should the child database data update when the parent database data is updated? + */ + +/** + * @typedef {object} DSQL_ChildrenDatabaseObject + * @property {string} dbFullName - Database Full name => "datasquirel_user_4_db_name" */ //////////////////////////////////////// @@ -32,6 +38,7 @@ * @property {DSQL_IndexSchemaType[]} [indexes] - List of table indexes, if available * @property {DSQL_ChildrenTablesType[]} [childrenTables] - List of children tables * @property {boolean} [childTable] -If current table is a child clone + * @property {boolean} [updateData] -If the current table data updates with the parent table * @property {string} [childTableName] - Table slug of parent table => "blog_posts" * @property {string} [childTableDbFullName] - Database full name(slug) including datasquirel data => "datasquirel_user_7_new_database" * @property {string} [tableNameOld] - Old table name, incase of renaming table @@ -41,16 +48,17 @@ * @typedef {object} DSQL_ChildrenTablesType * @property {string} dbNameFull - Database full name(slug) including datasquirel data => "datasquirel_user_7_new_database" * @property {string} tableName - Table slug => "blog_posts" + * @property {string} [tableNameFull] */ //////////////////////////////////////// /** * @typedef {object} DSQL_FieldSchemaType - * @property {string} fieldName - Field Name(slug) => "long_description" + * @property {string} [fieldName] - Field Name(slug) => "long_description" * @property {string} [originName] - Field origin name(optional) * @property {boolean} [updatedField] - Has this field been renamed? - * @property {string} dataType - Field Data type => "BIGIN" | "LONGTEXT" | "VARCHAR(***)" | ... + * @property {string} [dataType] - Field Data type => "BIGIN" | "LONGTEXT" | "VARCHAR(***)" | ... * @property {boolean} [nullValue] - Is this a null value or not? * @property {boolean} [notNullValue] - Is this NOT a null value? * @property {boolean} [primaryKey] - Is this the primary key for table? @@ -60,16 +68,31 @@ * @property {string} [defaultValueLiteral] - SQL key word which generates value automatically => "CURRENT_TIMESTAMP" * @property {DSQL_ForeignKeyType} [foreignKey] - Field foreign key reference object * @property {boolean} [richText] - Rich text field - * @property {string | RegExp} [pattern] - Field pattern for validation. Can be a string or a regular expression. Example: "^[a-zA-Z0-9_]*$" - * @property {string} [patternFlags] - Field pattern flags for validation. Example: "i" + * @property {boolean} [json] + * @property {boolean} [yaml] + * @property {boolean} [html] + * @property {boolean} [css] + * @property {boolean} [javascript] + * @property {boolean} [shell] + * @property {boolean} [newTempField] + * @property {boolean} [defaultField] + * @property {boolean} [plainText] + * @property {boolean} [unique] + * @property {string} [pattern] + * @property {string} [patternFlags] + * @property {string} [onUpdate] + * @property {string} [onUpdateLiteral] + * @property {string} [onDelete] + * @property {string} [onDeleteLiteral] + * @property {string[]} [cssFiles] */ /** * @typedef {object} DSQL_ForeignKeyType - * @property {string} foreignKeyName - Unique Name of foreign key - * @property {string} destinationTableName - Reference table name(slug) => "blog_posts" - * @property {string} destinationTableColumnName - Reference column name(slug) => "id" - * @property {string} destinationTableColumnType - Reference table field type => "BIGINT" | "VARCHAR(***)" | ... + * @property {string} [foreignKeyName] - Unique Name of foreign key + * @property {string} [destinationTableName] - Reference table name(slug) => "blog_posts" + * @property {string} [destinationTableColumnName] - Reference column name(slug) => "id" + * @property {string} [destinationTableColumnType] - Reference table field type => "BIGINT" | "VARCHAR(***)" | ... * @property {boolean} [cascadeDelete] - Does the reference table entry delete when this key is deleted? * @property {boolean} [cascadeUpdate] - Does the reference table entry update when this key is updated? */ @@ -78,10 +101,11 @@ /** * @typedef {object} DSQL_IndexSchemaType - * @property {string} indexName - Unique Name of index => "blog_text_index" - * @property {string} indexType - "regular" or "fullText" - * @property {DSQL_IndexTableFieldType[]} indexTableFields - List of Index table fields + * @property {string} [indexName] - Unique Name of index => "blog_text_index" + * @property {string} [indexType] - "regular" or "fullText" + * @property {DSQL_IndexTableFieldType[]} [indexTableFields] - List of Index table fields * @property {string} [alias] - List of Index table fields + * @property {boolean} [newTempIndex] */ /** @@ -89,7 +113,3 @@ * @property {string} value - Table Field Name * @property {string} dataType - Table Field data type "VARCHAR(***)" | "BIGINT" | ... */ - -//////////////////////////////////////// - -exports.DSQL_TableSchemaType = DSQL_TableSchemaType; diff --git a/package-shared/types/package-shared-index.js b/package-shared/types/package-shared-index.js index ab0a51e..60ed1ea 100644 --- a/package-shared/types/package-shared-index.js +++ b/package-shared/types/package-shared-index.js @@ -11,7 +11,7 @@ * @property {string} [email_login_field] * @property {boolean} [token] * @property {boolean} [social] - * @property {import("./database-schema.td").DSQL_DatabaseSchemaType} [dbSchema] + * @property {DSQL_DatabaseSchemaType} [dbSchema] */ /** @@ -23,5 +23,14 @@ * @property {string} [email_login_field] * @property {boolean} [token] * @property {boolean} [social] - * @property {import("./database-schema.td").DSQL_DatabaseSchemaType} [dbSchema] + * @property {DSQL_DatabaseSchemaType} [dbSchema] + */ + +/** + * @typedef {Object} GetReturn + * @property {boolean} success - Did the function run successfully? + * @property {*} [payload] - GET request results + * @property {string} [msg] - Message + * @property {string} [error] - Error Message + * @property {DSQL_TableSchemaType} [schema] - Error Message */ diff --git a/package.json b/package.json index 5649353..6c45fed 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "datasquirel", - "version": "2.1.1", + "version": "2.1.2", "description": "Cloud-based SQL data management tool", "main": "index.js", "bin": { diff --git a/users/add-user.js b/users/add-user.js index 30018be..94b40ed 100644 --- a/users/add-user.js +++ b/users/add-user.js @@ -64,7 +64,7 @@ async function addUser({ DSQL_PASS?.match(/./) && DSQL_DB_NAME?.match(/./) ) { - /** @type {import("@/package-shared/types/database-schema.td").DSQL_DatabaseSchemaType | undefined} */ + /** @type {DSQL_DatabaseSchemaType | undefined} */ let dbSchema; try { diff --git a/users/get-user.js b/users/get-user.js index a8077a8..2d08ad8 100644 --- a/users/get-user.js +++ b/users/get-user.js @@ -83,7 +83,7 @@ async function getUser({ key, userId, database, fields }) { DSQL_PASS?.match(/./) && DSQL_DB_NAME?.match(/./) ) { - /** @type {import("@/package-shared/types/database-schema.td").DSQL_DatabaseSchemaType | undefined} */ + /** @type {DSQL_DatabaseSchemaType | undefined} */ let dbSchema; try { diff --git a/users/login-user.js b/users/login-user.js index a52d8eb..206e034 100644 --- a/users/login-user.js +++ b/users/login-user.js @@ -126,7 +126,7 @@ async function loginUser({ DSQL_PASS?.match(/./) && DSQL_DB_NAME?.match(/./) ) { - /** @type {import("@/package-shared/types/database-schema.td").DSQL_DatabaseSchemaType | undefined} */ + /** @type {DSQL_DatabaseSchemaType | undefined} */ let dbSchema; try { diff --git a/users/reauth-user.js b/users/reauth-user.js index f0f6e16..919be99 100644 --- a/users/reauth-user.js +++ b/users/reauth-user.js @@ -103,7 +103,7 @@ async function reauthUser({ DSQL_PASS?.match(/./) && DSQL_DB_NAME?.match(/./) ) { - /** @type {import("@/package-shared/types/database-schema.td").DSQL_DatabaseSchemaType | undefined} */ + /** @type {DSQL_DatabaseSchemaType | undefined} */ let dbSchema; try { diff --git a/users/send-email-code.js b/users/send-email-code.js index c8874cc..52b1e04 100644 --- a/users/send-email-code.js +++ b/users/send-email-code.js @@ -114,7 +114,7 @@ async function sendEmailCode({ DSQL_PASS?.match(/./) && DSQL_DB_NAME?.match(/./) ) { - /** @type {import("@/package-shared/types/database-schema.td").DSQL_DatabaseSchemaType | undefined} */ + /** @type {DSQL_DatabaseSchemaType | undefined} */ let dbSchema; try { diff --git a/users/social/github-auth.js b/users/social/github-auth.js index da96427..5b744d4 100644 --- a/users/social/github-auth.js +++ b/users/social/github-auth.js @@ -154,7 +154,7 @@ async function githubAuth({ DSQL_PASS?.match(/./) && DSQL_DB_NAME?.match(/./) ) { - /** @type {import("@/package-shared/types/database-schema.td").DSQL_DatabaseSchemaType | undefined | undefined} */ + /** @type {DSQL_DatabaseSchemaType | undefined | undefined} */ let dbSchema; try { diff --git a/users/social/google-auth.js b/users/social/google-auth.js index 3b46819..744707e 100644 --- a/users/social/google-auth.js +++ b/users/social/google-auth.js @@ -150,7 +150,7 @@ async function googleAuth({ DSQL_PASS?.match(/./) && DSQL_DB_NAME?.match(/./) ) { - /** @type {import("@/package-shared/types/database-schema.td").DSQL_DatabaseSchemaType | undefined | undefined} */ + /** @type {DSQL_DatabaseSchemaType | undefined | undefined} */ let dbSchema; try { diff --git a/users/update-user.js b/users/update-user.js index 19703a2..0de51ec 100644 --- a/users/update-user.js +++ b/users/update-user.js @@ -57,7 +57,7 @@ async function updateUser({ key, payload, database }) { DSQL_PASS?.match(/./) && DSQL_DB_NAME?.match(/./) ) { - /** @type {import("@/package-shared/types/database-schema.td").DSQL_DatabaseSchemaType | undefined} */ + /** @type {DSQL_DatabaseSchemaType | undefined} */ let dbSchema; try { diff --git a/utils/get-schema.js b/utils/get-schema.js index dec3e11..de7963c 100644 --- a/utils/get-schema.js +++ b/utils/get-schema.js @@ -18,7 +18,7 @@ const https = require("https"); /** * @typedef {Object} GetSchemaReturn * @property {boolean} success - Did the function run successfully? - * @property {import("@/package-shared/types/database-schema.td").DSQL_DatabaseSchemaType[] | import("@/package-shared/types/database-schema.td").DSQL_DatabaseSchemaType | null} payload - Response payload + * @property {DSQL_DatabaseSchemaType | null} payload - Response payload */ /** diff --git a/utils/get.js b/utils/get.js index afc2b43..dbbeb06 100644 --- a/utils/get.js +++ b/utils/get.js @@ -18,14 +18,6 @@ const localGet = require("../engine/query/get"); /** ****************************************************************************** */ /** ****************************************************************************** */ -/** - * @typedef {Object} GetReturn - * @property {boolean} success - Did the function run successfully? - * @property {*} [payload] - GET request results - * @property {string} [msg] - Message - * @property {string} [error] - Error Message - */ - /** * Make a get request to Datasquirel API * ============================================================================== @@ -66,7 +58,7 @@ async function get({ key, db, query, queryValues, tableName }) { DSQL_PASS?.match(/./) && DSQL_DB_NAME?.match(/./) ) { - /** @type {import("@/package-shared/types/database-schema.td").DSQL_DatabaseSchemaType | undefined} */ + /** @type {DSQL_DatabaseSchemaType | undefined} */ let dbSchema; try { diff --git a/utils/post.js b/utils/post.js index b861c33..051291e 100644 --- a/utils/post.js +++ b/utils/post.js @@ -78,7 +78,7 @@ async function post({ key, query, queryValues, database, tableName }) { DSQL_PASS?.match(/./) && DSQL_DB_NAME?.match(/./) ) { - /** @type {import("@/package-shared/types/database-schema.td").DSQL_DatabaseSchemaType | undefined} */ + /** @type {DSQL_DatabaseSchemaType | undefined} */ let dbSchema; try {