From f95cf21ffdf523d87f814e6607ba19619f01f43f Mon Sep 17 00:00:00 2001 From: Benjamin Toby Date: Fri, 26 Dec 2025 10:33:46 +0100 Subject: [PATCH] Updates --- .../actions/users/social/google-auth.js | 2 +- .../api-paths/functions/delete-result.d.ts | 2 +- .../api-paths/functions/delete-result.js | 4 +- .../api-paths/functions/put-result.d.ts | 2 +- .../api-paths/functions/put-result.js | 4 +- dist/package-shared/api-paths/index.js | 34 ++++++++++++-- dist/package-shared/api-paths/utils/checks.js | 4 ++ dist/package-shared/types/index.d.ts | 5 ++- .../actions/users/social/google-auth.ts | 2 +- .../api-paths/functions/delete-result.ts | 3 +- .../api-paths/functions/put-result.ts | 3 +- package-shared/api-paths/index.ts | 45 +++++++++++++++++-- package-shared/api-paths/utils/checks.ts | 4 ++ package-shared/types/index.ts | 6 ++- package.json | 2 +- 15 files changed, 99 insertions(+), 23 deletions(-) diff --git a/dist/package-shared/actions/users/social/google-auth.js b/dist/package-shared/actions/users/social/google-auth.js index 27ef4ff..6b60cc7 100644 --- a/dist/package-shared/actions/users/social/google-auth.js +++ b/dist/package-shared/actions/users/social/google-auth.js @@ -90,7 +90,7 @@ function googleAuth(_a) { * * @description make a request to datasquirel.com */ - if ((httpResponse === null || httpResponse === void 0 ? void 0 : httpResponse.success) && (httpResponse === null || httpResponse === void 0 ? void 0 : httpResponse.payload) && database) { + if ((httpResponse === null || httpResponse === void 0 ? void 0 : httpResponse.success) && (httpResponse === null || httpResponse === void 0 ? void 0 : httpResponse.singleRes) && database) { (0, post_login_response_handler_1.default)({ database, httpResponse, diff --git a/dist/package-shared/api-paths/functions/delete-result.d.ts b/dist/package-shared/api-paths/functions/delete-result.d.ts index 16829a9..afb57ef 100644 --- a/dist/package-shared/api-paths/functions/delete-result.d.ts +++ b/dist/package-shared/api-paths/functions/delete-result.d.ts @@ -3,4 +3,4 @@ export default function ({ table, body, targetId, }: APIPathsCrudParams): Promise; +}>({ table, body, targetId, query, }: APIPathsCrudParams): Promise; diff --git a/dist/package-shared/api-paths/functions/delete-result.js b/dist/package-shared/api-paths/functions/delete-result.js index bb6b08d..10dded8 100644 --- a/dist/package-shared/api-paths/functions/delete-result.js +++ b/dist/package-shared/api-paths/functions/delete-result.js @@ -15,11 +15,11 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.default = default_1; const crud_1 = __importDefault(require("../../utils/data-fetching/crud")); function default_1(_a) { - return __awaiter(this, arguments, void 0, function* ({ table, body, targetId, }) { + return __awaiter(this, arguments, void 0, function* ({ table, body, targetId, query, }) { if (!targetId && !(body === null || body === void 0 ? void 0 : body.searchQuery)) { throw new Error(`Target ID or \`searchQuery\` field is required to delete Data.`); } - const DELETE_RESLT = yield (0, crud_1.default)(Object.assign(Object.assign({}, body === null || body === void 0 ? void 0 : body.crudParams), { action: "delete", table, query: body === null || body === void 0 ? void 0 : body.searchQuery, targetId })); + const DELETE_RESLT = yield (0, crud_1.default)(Object.assign(Object.assign({}, body === null || body === void 0 ? void 0 : body.crudParams), { action: "delete", table, query: query === null || query === void 0 ? void 0 : query.searchQuery, targetId })); return DELETE_RESLT; }); } diff --git a/dist/package-shared/api-paths/functions/put-result.d.ts b/dist/package-shared/api-paths/functions/put-result.d.ts index 16829a9..afb57ef 100644 --- a/dist/package-shared/api-paths/functions/put-result.d.ts +++ b/dist/package-shared/api-paths/functions/put-result.d.ts @@ -3,4 +3,4 @@ export default function ({ table, body, targetId, }: APIPathsCrudParams): Promise; +}>({ table, body, targetId, query, }: APIPathsCrudParams): Promise; diff --git a/dist/package-shared/api-paths/functions/put-result.js b/dist/package-shared/api-paths/functions/put-result.js index 04147d6..a6e00a9 100644 --- a/dist/package-shared/api-paths/functions/put-result.js +++ b/dist/package-shared/api-paths/functions/put-result.js @@ -15,11 +15,11 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.default = default_1; const crud_1 = __importDefault(require("../../utils/data-fetching/crud")); function default_1(_a) { - return __awaiter(this, arguments, void 0, function* ({ table, body, targetId, }) { + return __awaiter(this, arguments, void 0, function* ({ table, body, targetId, query, }) { if (!targetId && !(body === null || body === void 0 ? void 0 : body.searchQuery)) { throw new Error(`Target ID or \`searchQuery\` field is required to update Data.`); } - const PUT_RESULT = yield (0, crud_1.default)(Object.assign(Object.assign({}, body === null || body === void 0 ? void 0 : body.crudParams), { action: "update", table, data: body === null || body === void 0 ? void 0 : body.data, query: body === null || body === void 0 ? void 0 : body.searchQuery, targetId })); + const PUT_RESULT = yield (0, crud_1.default)(Object.assign(Object.assign({}, body === null || body === void 0 ? void 0 : body.crudParams), { action: "update", table, data: body === null || body === void 0 ? void 0 : body.data, query: query === null || query === void 0 ? void 0 : query.searchQuery, targetId })); return PUT_RESULT; }); } diff --git a/dist/package-shared/api-paths/index.js b/dist/package-shared/api-paths/index.js index c21258d..0daddae 100644 --- a/dist/package-shared/api-paths/index.js +++ b/dist/package-shared/api-paths/index.js @@ -22,6 +22,7 @@ const put_result_1 = __importDefault(require("./functions/put-result")); const delete_result_1 = __importDefault(require("./functions/delete-result")); function apiCrudHandler(params) { return __awaiter(this, void 0, void 0, function* () { + var _a, _b; try { const { auth, method } = params; const isAuthorized = yield (auth === null || auth === void 0 ? void 0 : auth()); @@ -34,17 +35,42 @@ function apiCrudHandler(params) { crudParams.body = checkedObj.body; crudParams.allowedTable = checkedObj.allowedTable; crudParams.url = url; + const finalSearchQuery = lodash_1.default.merge((_a = crudParams.query) === null || _a === void 0 ? void 0 : _a.searchQuery, (_b = crudParams.body) === null || _b === void 0 ? void 0 : _b.searchQuery); + if (finalSearchQuery) { + crudParams.query = Object.assign(Object.assign({}, crudParams.query), { searchQuery: finalSearchQuery }); + } if (targetId) { if (crudParams.query) { - if (crudParams.query.crudParams) { - crudParams.query.crudParams.targetId = targetId; + if (crudParams.query.searchQuery) { + crudParams.query.searchQuery = lodash_1.default.merge(crudParams.query.searchQuery, { + query: { + id: { + value: String(targetId), + }, + }, + }); } else { - crudParams.query.crudParams = { - targetId, + crudParams.query.searchQuery = { + query: { + id: { + value: String(targetId), + }, + }, }; } } + else { + crudParams.query = { + searchQuery: { + query: { + id: { + value: String(targetId), + }, + }, + }, + }; + } } switch (method) { case "GET": diff --git a/dist/package-shared/api-paths/utils/checks.js b/dist/package-shared/api-paths/utils/checks.js index a069251..a87e383 100644 --- a/dist/package-shared/api-paths/utils/checks.js +++ b/dist/package-shared/api-paths/utils/checks.js @@ -57,6 +57,7 @@ function checks(_a) { const middRes = yield crudMiddleware({ body: newBody || {}, query: newQuery || {}, + table, }); newBody = lodash_1.default.merge(newBody, middRes); } @@ -64,6 +65,7 @@ function checks(_a) { const middRes = yield postMiddleware({ body: newBody || {}, query: newQuery || {}, + table, }); newBody = lodash_1.default.merge(newBody, middRes); } @@ -71,6 +73,7 @@ function checks(_a) { const middRes = yield putMiddleware({ body: newBody || {}, query: newQuery || {}, + table, }); newBody = lodash_1.default.merge(newBody, middRes); } @@ -78,6 +81,7 @@ function checks(_a) { const middRes = yield deleteMiddleware({ body: newBody || {}, query: newQuery || {}, + table, }); newBody = lodash_1.default.merge(newBody, middRes); } diff --git a/dist/package-shared/types/index.d.ts b/dist/package-shared/types/index.d.ts index 067a71b..14a2c11 100644 --- a/dist/package-shared/types/index.d.ts +++ b/dist/package-shared/types/index.d.ts @@ -2255,10 +2255,11 @@ export type APIPathsParamsCrudMiddleware = (params: { +}, K extends string = string> = (params: { body: APIPathsBody; query: DsqlCrudQueryObject; -}) => Promise>; + table: K; +}) => Promise | undefined>; export type APIPathsParamsAllowedTable = { table: string; allowedFields?: (string | RegExp)[]; diff --git a/package-shared/actions/users/social/google-auth.ts b/package-shared/actions/users/social/google-auth.ts index b9ecd73..98eb98e 100644 --- a/package-shared/actions/users/social/google-auth.ts +++ b/package-shared/actions/users/social/google-auth.ts @@ -106,7 +106,7 @@ export default async function googleAuth({ * * @description make a request to datasquirel.com */ - if (httpResponse?.success && httpResponse?.payload && database) { + if (httpResponse?.success && httpResponse?.singleRes && database) { postLoginResponseHandler({ database, httpResponse, diff --git a/package-shared/api-paths/functions/delete-result.ts b/package-shared/api-paths/functions/delete-result.ts index 50cc183..c5076b2 100644 --- a/package-shared/api-paths/functions/delete-result.ts +++ b/package-shared/api-paths/functions/delete-result.ts @@ -7,6 +7,7 @@ export default async function < table, body, targetId, + query, }: APIPathsCrudParams): Promise { if (!targetId && !body?.searchQuery) { throw new Error( @@ -18,7 +19,7 @@ export default async function < ...body?.crudParams, action: "delete", table, - query: body?.searchQuery, + query: query?.searchQuery, targetId, }); diff --git a/package-shared/api-paths/functions/put-result.ts b/package-shared/api-paths/functions/put-result.ts index 71d0438..1d975ad 100644 --- a/package-shared/api-paths/functions/put-result.ts +++ b/package-shared/api-paths/functions/put-result.ts @@ -7,6 +7,7 @@ export default async function < table, body, targetId, + query, }: APIPathsCrudParams): Promise { if (!targetId && !body?.searchQuery) { throw new Error( @@ -19,7 +20,7 @@ export default async function < action: "update", table, data: body?.data, - query: body?.searchQuery, + query: query?.searchQuery, targetId, }); diff --git a/package-shared/api-paths/index.ts b/package-shared/api-paths/index.ts index acb65df..8c26821 100644 --- a/package-shared/api-paths/index.ts +++ b/package-shared/api-paths/index.ts @@ -3,6 +3,8 @@ import { APIPathsCrudParams, APIPathsParams, APIResponseObject, + DsqlCrudQueryObject, + ServerQueryQueryObject, } from "../types"; import getResult from "./functions/get-result"; import { grabPathData } from "./utils/grab-path-data"; @@ -38,15 +40,50 @@ export default async function apiCrudHandler< crudParams.allowedTable = checkedObj.allowedTable; crudParams.url = url; + const finalSearchQuery = _.merge( + crudParams.query?.searchQuery, + crudParams.body?.searchQuery + ); + + if (finalSearchQuery) { + crudParams.query = { + ...crudParams.query, + searchQuery: finalSearchQuery, + }; + } + if (targetId) { if (crudParams.query) { - if (crudParams.query.crudParams) { - crudParams.query.crudParams.targetId = targetId; + if (crudParams.query.searchQuery) { + crudParams.query.searchQuery = _.merge< + DsqlCrudQueryObject, + DsqlCrudQueryObject + >(crudParams.query.searchQuery, { + query: { + id: { + value: String(targetId), + }, + } as ServerQueryQueryObject, + }); } else { - crudParams.query.crudParams = { - targetId, + crudParams.query.searchQuery = { + query: { + id: { + value: String(targetId), + }, + } as ServerQueryQueryObject, }; } + } else { + crudParams.query = { + searchQuery: { + query: { + id: { + value: String(targetId), + }, + } as ServerQueryQueryObject, + }, + }; } } diff --git a/package-shared/api-paths/utils/checks.ts b/package-shared/api-paths/utils/checks.ts index a20997a..0953936 100644 --- a/package-shared/api-paths/utils/checks.ts +++ b/package-shared/api-paths/utils/checks.ts @@ -77,6 +77,7 @@ export default async function checks< const middRes = await crudMiddleware({ body: newBody || ({} as any), query: newQuery || {}, + table, }); newBody = _.merge(newBody, middRes); @@ -86,6 +87,7 @@ export default async function checks< const middRes = await postMiddleware({ body: newBody || ({} as any), query: newQuery || {}, + table, }); newBody = _.merge(newBody, middRes); @@ -95,6 +97,7 @@ export default async function checks< const middRes = await putMiddleware({ body: newBody || ({} as any), query: newQuery || {}, + table, }); newBody = _.merge(newBody, middRes); @@ -104,6 +107,7 @@ export default async function checks< const middRes = await deleteMiddleware({ body: newBody || ({} as any), query: newQuery || {}, + table, }); newBody = _.merge(newBody, middRes); diff --git a/package-shared/types/index.ts b/package-shared/types/index.ts index 0923ddf..b5782f1 100644 --- a/package-shared/types/index.ts +++ b/package-shared/types/index.ts @@ -2915,11 +2915,13 @@ export type APIPathsParamsGetMiddleware< > = (params: { query: APIPathsQuery }) => Promise>; export type APIPathsParamsCrudMiddleware< - T extends { [k: string]: any } = { [k: string]: any } + T extends { [k: string]: any } = { [k: string]: any }, + K extends string = string > = (params: { body: APIPathsBody; query: DsqlCrudQueryObject; -}) => Promise>; + table: K; +}) => Promise | undefined>; export type APIPathsParamsAllowedTable = { table: string; diff --git a/package.json b/package.json index 323708c..20181aa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@moduletrace/datasquirel", - "version": "5.6.0", + "version": "5.6.1", "description": "Cloud-based SQL data management tool", "main": "dist/index.js", "bin": {