This commit is contained in:
Benjamin Toby 2025-12-26 10:33:46 +01:00
parent 0e5b5fea6e
commit f95cf21ffd
15 changed files with 99 additions and 23 deletions

View File

@ -90,7 +90,7 @@ function googleAuth(_a) {
* *
* @description make a request to datasquirel.com * @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)({ (0, post_login_response_handler_1.default)({
database, database,
httpResponse, httpResponse,

View File

@ -3,4 +3,4 @@ export default function <T extends {
[k: string]: any; [k: string]: any;
} = { } = {
[k: string]: any; [k: string]: any;
}>({ table, body, targetId, }: APIPathsCrudParams<T>): Promise<APIResponseObject>; }>({ table, body, targetId, query, }: APIPathsCrudParams<T>): Promise<APIResponseObject>;

View File

@ -15,11 +15,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.default = default_1; exports.default = default_1;
const crud_1 = __importDefault(require("../../utils/data-fetching/crud")); const crud_1 = __importDefault(require("../../utils/data-fetching/crud"));
function default_1(_a) { 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)) { if (!targetId && !(body === null || body === void 0 ? void 0 : body.searchQuery)) {
throw new Error(`Target ID or \`searchQuery\` field is required to delete Data.`); 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; return DELETE_RESLT;
}); });
} }

View File

@ -3,4 +3,4 @@ export default function <T extends {
[k: string]: any; [k: string]: any;
} = { } = {
[k: string]: any; [k: string]: any;
}>({ table, body, targetId, }: APIPathsCrudParams<T>): Promise<APIResponseObject>; }>({ table, body, targetId, query, }: APIPathsCrudParams<T>): Promise<APIResponseObject>;

View File

@ -15,11 +15,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.default = default_1; exports.default = default_1;
const crud_1 = __importDefault(require("../../utils/data-fetching/crud")); const crud_1 = __importDefault(require("../../utils/data-fetching/crud"));
function default_1(_a) { 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)) { if (!targetId && !(body === null || body === void 0 ? void 0 : body.searchQuery)) {
throw new Error(`Target ID or \`searchQuery\` field is required to update Data.`); 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; return PUT_RESULT;
}); });
} }

View File

@ -22,6 +22,7 @@ const put_result_1 = __importDefault(require("./functions/put-result"));
const delete_result_1 = __importDefault(require("./functions/delete-result")); const delete_result_1 = __importDefault(require("./functions/delete-result"));
function apiCrudHandler(params) { function apiCrudHandler(params) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
var _a, _b;
try { try {
const { auth, method } = params; const { auth, method } = params;
const isAuthorized = yield (auth === null || auth === void 0 ? void 0 : auth()); const isAuthorized = yield (auth === null || auth === void 0 ? void 0 : auth());
@ -34,17 +35,42 @@ function apiCrudHandler(params) {
crudParams.body = checkedObj.body; crudParams.body = checkedObj.body;
crudParams.allowedTable = checkedObj.allowedTable; crudParams.allowedTable = checkedObj.allowedTable;
crudParams.url = url; 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 (targetId) {
if (crudParams.query) { if (crudParams.query) {
if (crudParams.query.crudParams) { if (crudParams.query.searchQuery) {
crudParams.query.crudParams.targetId = targetId; crudParams.query.searchQuery = lodash_1.default.merge(crudParams.query.searchQuery, {
query: {
id: {
value: String(targetId),
},
},
});
} }
else { else {
crudParams.query.crudParams = { crudParams.query.searchQuery = {
targetId, query: {
id: {
value: String(targetId),
},
},
}; };
} }
} }
else {
crudParams.query = {
searchQuery: {
query: {
id: {
value: String(targetId),
},
},
},
};
}
} }
switch (method) { switch (method) {
case "GET": case "GET":

View File

@ -57,6 +57,7 @@ function checks(_a) {
const middRes = yield crudMiddleware({ const middRes = yield crudMiddleware({
body: newBody || {}, body: newBody || {},
query: newQuery || {}, query: newQuery || {},
table,
}); });
newBody = lodash_1.default.merge(newBody, middRes); newBody = lodash_1.default.merge(newBody, middRes);
} }
@ -64,6 +65,7 @@ function checks(_a) {
const middRes = yield postMiddleware({ const middRes = yield postMiddleware({
body: newBody || {}, body: newBody || {},
query: newQuery || {}, query: newQuery || {},
table,
}); });
newBody = lodash_1.default.merge(newBody, middRes); newBody = lodash_1.default.merge(newBody, middRes);
} }
@ -71,6 +73,7 @@ function checks(_a) {
const middRes = yield putMiddleware({ const middRes = yield putMiddleware({
body: newBody || {}, body: newBody || {},
query: newQuery || {}, query: newQuery || {},
table,
}); });
newBody = lodash_1.default.merge(newBody, middRes); newBody = lodash_1.default.merge(newBody, middRes);
} }
@ -78,6 +81,7 @@ function checks(_a) {
const middRes = yield deleteMiddleware({ const middRes = yield deleteMiddleware({
body: newBody || {}, body: newBody || {},
query: newQuery || {}, query: newQuery || {},
table,
}); });
newBody = lodash_1.default.merge(newBody, middRes); newBody = lodash_1.default.merge(newBody, middRes);
} }

View File

@ -2255,10 +2255,11 @@ export type APIPathsParamsCrudMiddleware<T extends {
[k: string]: any; [k: string]: any;
} = { } = {
[k: string]: any; [k: string]: any;
}> = (params: { }, K extends string = string> = (params: {
body: APIPathsBody<T>; body: APIPathsBody<T>;
query: DsqlCrudQueryObject<T>; query: DsqlCrudQueryObject<T>;
}) => Promise<APIPathsBody<T>>; table: K;
}) => Promise<APIPathsBody<T> | undefined>;
export type APIPathsParamsAllowedTable = { export type APIPathsParamsAllowedTable = {
table: string; table: string;
allowedFields?: (string | RegExp)[]; allowedFields?: (string | RegExp)[];

View File

@ -106,7 +106,7 @@ export default async function googleAuth({
* *
* @description make a request to datasquirel.com * @description make a request to datasquirel.com
*/ */
if (httpResponse?.success && httpResponse?.payload && database) { if (httpResponse?.success && httpResponse?.singleRes && database) {
postLoginResponseHandler({ postLoginResponseHandler({
database, database,
httpResponse, httpResponse,

View File

@ -7,6 +7,7 @@ export default async function <
table, table,
body, body,
targetId, targetId,
query,
}: APIPathsCrudParams<T>): Promise<APIResponseObject> { }: APIPathsCrudParams<T>): Promise<APIResponseObject> {
if (!targetId && !body?.searchQuery) { if (!targetId && !body?.searchQuery) {
throw new Error( throw new Error(
@ -18,7 +19,7 @@ export default async function <
...body?.crudParams, ...body?.crudParams,
action: "delete", action: "delete",
table, table,
query: body?.searchQuery, query: query?.searchQuery,
targetId, targetId,
}); });

View File

@ -7,6 +7,7 @@ export default async function <
table, table,
body, body,
targetId, targetId,
query,
}: APIPathsCrudParams<T>): Promise<APIResponseObject> { }: APIPathsCrudParams<T>): Promise<APIResponseObject> {
if (!targetId && !body?.searchQuery) { if (!targetId && !body?.searchQuery) {
throw new Error( throw new Error(
@ -19,7 +20,7 @@ export default async function <
action: "update", action: "update",
table, table,
data: body?.data, data: body?.data,
query: body?.searchQuery, query: query?.searchQuery,
targetId, targetId,
}); });

View File

@ -3,6 +3,8 @@ import {
APIPathsCrudParams, APIPathsCrudParams,
APIPathsParams, APIPathsParams,
APIResponseObject, APIResponseObject,
DsqlCrudQueryObject,
ServerQueryQueryObject,
} from "../types"; } from "../types";
import getResult from "./functions/get-result"; import getResult from "./functions/get-result";
import { grabPathData } from "./utils/grab-path-data"; import { grabPathData } from "./utils/grab-path-data";
@ -38,15 +40,50 @@ export default async function apiCrudHandler<
crudParams.allowedTable = checkedObj.allowedTable; crudParams.allowedTable = checkedObj.allowedTable;
crudParams.url = url; crudParams.url = url;
const finalSearchQuery = _.merge(
crudParams.query?.searchQuery,
crudParams.body?.searchQuery
);
if (finalSearchQuery) {
crudParams.query = {
...crudParams.query,
searchQuery: finalSearchQuery,
};
}
if (targetId) { if (targetId) {
if (crudParams.query) { if (crudParams.query) {
if (crudParams.query.crudParams) { if (crudParams.query.searchQuery) {
crudParams.query.crudParams.targetId = targetId; crudParams.query.searchQuery = _.merge<
DsqlCrudQueryObject<T>,
DsqlCrudQueryObject<T>
>(crudParams.query.searchQuery, {
query: {
id: {
value: String(targetId),
},
} as ServerQueryQueryObject<T, string>,
});
} else { } else {
crudParams.query.crudParams = { crudParams.query.searchQuery = {
targetId, query: {
id: {
value: String(targetId),
},
} as ServerQueryQueryObject<T, string>,
}; };
} }
} else {
crudParams.query = {
searchQuery: {
query: {
id: {
value: String(targetId),
},
} as ServerQueryQueryObject<T, string>,
},
};
} }
} }

View File

@ -77,6 +77,7 @@ export default async function checks<
const middRes = await crudMiddleware({ const middRes = await crudMiddleware({
body: newBody || ({} as any), body: newBody || ({} as any),
query: newQuery || {}, query: newQuery || {},
table,
}); });
newBody = _.merge(newBody, middRes); newBody = _.merge(newBody, middRes);
@ -86,6 +87,7 @@ export default async function checks<
const middRes = await postMiddleware({ const middRes = await postMiddleware({
body: newBody || ({} as any), body: newBody || ({} as any),
query: newQuery || {}, query: newQuery || {},
table,
}); });
newBody = _.merge(newBody, middRes); newBody = _.merge(newBody, middRes);
@ -95,6 +97,7 @@ export default async function checks<
const middRes = await putMiddleware({ const middRes = await putMiddleware({
body: newBody || ({} as any), body: newBody || ({} as any),
query: newQuery || {}, query: newQuery || {},
table,
}); });
newBody = _.merge(newBody, middRes); newBody = _.merge(newBody, middRes);
@ -104,6 +107,7 @@ export default async function checks<
const middRes = await deleteMiddleware({ const middRes = await deleteMiddleware({
body: newBody || ({} as any), body: newBody || ({} as any),
query: newQuery || {}, query: newQuery || {},
table,
}); });
newBody = _.merge(newBody, middRes); newBody = _.merge(newBody, middRes);

View File

@ -2915,11 +2915,13 @@ export type APIPathsParamsGetMiddleware<
> = (params: { query: APIPathsQuery<T> }) => Promise<DsqlCrudQueryObject<T>>; > = (params: { query: APIPathsQuery<T> }) => Promise<DsqlCrudQueryObject<T>>;
export type APIPathsParamsCrudMiddleware< export type APIPathsParamsCrudMiddleware<
T extends { [k: string]: any } = { [k: string]: any } T extends { [k: string]: any } = { [k: string]: any },
K extends string = string
> = (params: { > = (params: {
body: APIPathsBody<T>; body: APIPathsBody<T>;
query: DsqlCrudQueryObject<T>; query: DsqlCrudQueryObject<T>;
}) => Promise<APIPathsBody<T>>; table: K;
}) => Promise<APIPathsBody<T> | undefined>;
export type APIPathsParamsAllowedTable = { export type APIPathsParamsAllowedTable = {
table: string; table: string;

View File

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