Update types
This commit is contained in:
parent
fabf2945d7
commit
d774e8d35d
@ -2,31 +2,16 @@
|
||||
|
||||
const runQuery = require("./utils/runQuery");
|
||||
|
||||
/**
|
||||
* @typedef {Object} LocalPostReturn
|
||||
* @property {boolean} success - Did the function run successfully?
|
||||
* @property {*} [payload] - GET request results
|
||||
* @property {string} [msg] - Message
|
||||
* @property {string} [error] - Error Message
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} LocalPostQueryObject
|
||||
* @property {string | import("../../utils/post").PostDataPayload} query - Table Name
|
||||
* @property {string} [tableName] - Table Name
|
||||
* @property {string[]} [queryValues] - GET request results
|
||||
*/
|
||||
|
||||
/**
|
||||
* Make a get request to Datasquirel API
|
||||
* ==============================================================================
|
||||
* @async
|
||||
*
|
||||
* @param {Object} params - Single object passed
|
||||
* @param {LocalPostQueryObject} params.options - SQL Query
|
||||
* @param {import("../../package-shared/types").LocalPostQueryObject} params.options - SQL Query
|
||||
* @param {import("../../package-shared/types").DSQL_DatabaseSchemaType | undefined} [params.dbSchema] - Name of the table to query
|
||||
*
|
||||
* @returns { Promise<LocalPostReturn> } - Return Object
|
||||
* @returns { Promise<import("../../package-shared/types").LocalPostReturn> } - Return Object
|
||||
*/
|
||||
async function localPost({ options, dbSchema }) {
|
||||
try {
|
||||
@ -83,7 +68,6 @@ async function localPost({ options, dbSchema }) {
|
||||
|
||||
return {
|
||||
success: false,
|
||||
payload: null,
|
||||
error: error.message,
|
||||
};
|
||||
}
|
||||
@ -95,7 +79,6 @@ async function localPost({ options, dbSchema }) {
|
||||
|
||||
return {
|
||||
success: false,
|
||||
payload: null,
|
||||
msg: "Something went wrong!",
|
||||
};
|
||||
|
||||
|
@ -6,14 +6,6 @@ const varDatabaseDbHandler = require("../engine/utils/varDatabaseDbHandler");
|
||||
const addDbEntry = require("../query/utils/addDbEntry");
|
||||
const runQuery = require("../query/utils/runQuery");
|
||||
|
||||
/**
|
||||
* @typedef {Object} LocalPostReturn
|
||||
* @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
|
||||
* ==============================================================================
|
||||
@ -25,7 +17,7 @@ const runQuery = require("../query/utils/runQuery");
|
||||
* @param {string} [params.encryptionKey]
|
||||
* @param {string} [params.encryptionSalt]
|
||||
*
|
||||
* @returns { Promise<LocalPostReturn> } - Return Object
|
||||
* @returns { Promise<import("../../package-shared/types").AddUserFunctionReturn> } - Return Object
|
||||
*/
|
||||
async function localAddUser({
|
||||
payload,
|
||||
@ -50,7 +42,7 @@ async function localAddUser({
|
||||
if (!payload?.password) {
|
||||
return {
|
||||
success: false,
|
||||
payload: `Password is required to create an account`,
|
||||
msg: `Password is required to create an account`,
|
||||
};
|
||||
}
|
||||
|
||||
@ -79,7 +71,7 @@ async function localAddUser({
|
||||
if (!fields) {
|
||||
return {
|
||||
success: false,
|
||||
payload: "Could not create users table",
|
||||
msg: "Could not create users table",
|
||||
};
|
||||
}
|
||||
|
||||
@ -100,7 +92,7 @@ async function localAddUser({
|
||||
if (invalidField) {
|
||||
return {
|
||||
success: false,
|
||||
payload: `${invalidField} is not a valid field!`,
|
||||
msg: `${invalidField} is not a valid field!`,
|
||||
};
|
||||
}
|
||||
|
||||
@ -126,7 +118,7 @@ async function localAddUser({
|
||||
if (existingUser && existingUser[0]) {
|
||||
return {
|
||||
success: false,
|
||||
payload: "User Already Exists",
|
||||
msg: "User Already Exists",
|
||||
};
|
||||
}
|
||||
|
||||
@ -157,7 +149,7 @@ async function localAddUser({
|
||||
} else {
|
||||
return {
|
||||
success: false,
|
||||
payload: "Could not create user",
|
||||
msg: "Could not create user",
|
||||
};
|
||||
}
|
||||
|
||||
@ -168,7 +160,6 @@ async function localAddUser({
|
||||
|
||||
return {
|
||||
success: false,
|
||||
payload: null,
|
||||
msg: "Something went wrong!",
|
||||
};
|
||||
|
||||
|
40
package-shared/types/index.d.ts
vendored
40
package-shared/types/index.d.ts
vendored
@ -315,3 +315,43 @@ export interface GetReturn {
|
||||
error?: string;
|
||||
schema?: DSQL_TableSchemaType;
|
||||
}
|
||||
|
||||
interface PostReturn {
|
||||
success: boolean;
|
||||
payload?: PostInsertReturn | Object[] | string;
|
||||
}
|
||||
|
||||
interface PostInsertReturn {
|
||||
fieldCount: number;
|
||||
affectedRows: number;
|
||||
insertId: number;
|
||||
serverStatus: number;
|
||||
warningCount: number;
|
||||
message: string;
|
||||
protocol41: boolean;
|
||||
changedRows: number;
|
||||
}
|
||||
|
||||
interface PostDataPayload {
|
||||
action: "insert" | "update" | "delete";
|
||||
table: string;
|
||||
data?: object;
|
||||
identifierColumnName?: string;
|
||||
identifierValue?: string;
|
||||
duplicateColumnName?: string;
|
||||
duplicateColumnValue?: string;
|
||||
update?: boolean;
|
||||
}
|
||||
|
||||
interface LocalPostReturn {
|
||||
success: boolean;
|
||||
payload?: PostInsertReturn | Object[] | string;
|
||||
msg?: string;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
interface LocalPostQueryObject {
|
||||
query: string | import("../../package-shared/types").PostDataPayload;
|
||||
tableName?: string;
|
||||
queryValues?: string[];
|
||||
}
|
||||
|
@ -353,3 +353,52 @@ const http = require("http");
|
||||
* @property {string} [error] - Error Message
|
||||
* @property {DSQL_TableSchemaType} [schema] - Error Message
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} PostReturn
|
||||
* @property {boolean} success - Did the function run successfully?
|
||||
* @property { PostInsertReturn | Object[] | string } [payload] - The Y Coordinate
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {object} PostInsertReturn
|
||||
* @property {number} fieldCount
|
||||
* @property {number} affectedRows
|
||||
* @property {number} insertId
|
||||
* @property {number} serverStatus
|
||||
* @property {number} warningCount
|
||||
* @property {string} message
|
||||
* @property {boolean} protocol41
|
||||
* @property {number} changedRows
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {object} PostDataPayload
|
||||
* @property {"insert" | "update" | "delete"} action - The target action to take
|
||||
* @property {string} table - Table name(slug) eg "blog_posts"
|
||||
* @property {object} [data] - Table insert payload object => This must have keys that match
|
||||
* table fields
|
||||
* @property {string?} [identifierColumnName] - Table identifier field name => eg. "id" OR "email"
|
||||
* @property {string?} [identifierValue] - Corresponding value of the selected field name => This
|
||||
* checks identifies a the target row for "update" or "delete". Not needed for "insert"
|
||||
* @property {string?} [duplicateColumnName] - Duplicate column name to check for
|
||||
* @property {string?} [duplicateColumnValue] - Duplicate column value to match. If no "update" param
|
||||
* provided, function will return null
|
||||
* @property {boolean?} [update] - Should the "insert" action update the existing entry if indeed
|
||||
* the entry with "duplicateColumnValue" exists?
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} LocalPostReturn
|
||||
* @property {boolean} success - Did the function run successfully?
|
||||
* @property { PostInsertReturn | Object[] | string } [payload] - GET request results
|
||||
* @property {string} [msg] - Message
|
||||
* @property {string} [error] - Error Message
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} LocalPostQueryObject
|
||||
* @property {string | import("../../package-shared/types").PostDataPayload} query - Table Name
|
||||
* @property {string} [tableName] - Table Name
|
||||
* @property {string[]} [queryValues] - GET request results
|
||||
*/
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "datasquirel",
|
||||
"version": "2.2.6",
|
||||
"version": "2.2.7",
|
||||
"description": "Cloud-based SQL data management tool",
|
||||
"main": "index.js",
|
||||
"bin": {
|
||||
|
@ -16,28 +16,6 @@ const localPost = require("../engine/query/post");
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
|
||||
/**
|
||||
* @typedef {Object} PostReturn
|
||||
* @property {boolean} success - Did the function run successfully?
|
||||
* @property {(Object[]|string)} [payload=[]] - The Y Coordinate
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {object} PostDataPayload
|
||||
* @property {"insert" | "update" | "delete"} action - The target action to take
|
||||
* @property {string} table - Table name(slug) eg "blog_posts"
|
||||
* @property {object} [data] - Table insert payload object => This must have keys that match
|
||||
* table fields
|
||||
* @property {string?} [identifierColumnName] - Table identifier field name => eg. "id" OR "email"
|
||||
* @property {string?} [identifierValue] - Corresponding value of the selected field name => This
|
||||
* checks identifies a the target row for "update" or "delete". Not needed for "insert"
|
||||
* @property {string?} [duplicateColumnName] - Duplicate column name to check for
|
||||
* @property {string?} [duplicateColumnValue] - Duplicate column value to match. If no "update" param
|
||||
* provided, function will return null
|
||||
* @property {boolean?} [update] - Should the "insert" action update the existing entry if indeed
|
||||
* the entry with "duplicateColumnValue" exists?
|
||||
*/
|
||||
|
||||
/**
|
||||
* Make a post request to Datasquirel API
|
||||
* ==============================================================================
|
||||
@ -46,11 +24,11 @@ const localPost = require("../engine/query/post");
|
||||
* @param {Object} params - Single object passed
|
||||
* @param {string} [params.key] - FULL ACCESS API Key
|
||||
* @param {string} [params.database] - Database Name
|
||||
* @param {PostDataPayload | string} params.query - SQL query String or Request Object
|
||||
* @param {import("../package-shared/types").PostDataPayload | string} params.query - SQL query String or Request Object
|
||||
* @param {any[]} [params.queryValues] - Query Values if using "?" placeholders
|
||||
* @param {string} [params.tableName] - Name of the table to query
|
||||
*
|
||||
* @returns { Promise<PostReturn> } - Return Object
|
||||
* @returns { Promise<import("../package-shared/types").PostReturn> } - Return Object
|
||||
*/
|
||||
async function post({ key, query, queryValues, database, tableName }) {
|
||||
const scheme = process.env.DSQL_HTTP_SCHEME;
|
||||
|
Loading…
Reference in New Issue
Block a user