This commit is contained in:
Benjamin Toby 2025-12-28 18:41:03 +01:00
parent d9f0f74481
commit 83eb4b976f
6 changed files with 16 additions and 3 deletions

View File

@ -3,6 +3,6 @@ export default function checks<T extends {
[k: string]: any; [k: string]: any;
} = { } = {
[k: string]: any; [k: string]: any;
}>({ table, allowedTables, query, body, method, getMiddleware, postMiddleware, putMiddleware, deleteMiddleware, crudMiddleware, }: APIPathsCrudParams<T>): Promise<Pick<APIPathsCrudParams<T>, "query" | "body"> & { }>({ table, allowedTables, query, body, method, getMiddleware, postMiddleware, putMiddleware, deleteMiddleware, crudMiddleware, targetId, }: APIPathsCrudParams<T>): Promise<Pick<APIPathsCrudParams<T>, "query" | "body"> & {
allowedTable: APIPathsParamsAllowedTable; allowedTable: APIPathsParamsAllowedTable;
}>; }>;

View File

@ -15,7 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.default = checks; exports.default = checks;
const lodash_1 = __importDefault(require("lodash")); const lodash_1 = __importDefault(require("lodash"));
function checks(_a) { function checks(_a) {
return __awaiter(this, arguments, void 0, function* ({ table, allowedTables, query, body, method, getMiddleware, postMiddleware, putMiddleware, deleteMiddleware, crudMiddleware, }) { return __awaiter(this, arguments, void 0, function* ({ table, allowedTables, query, body, method, getMiddleware, postMiddleware, putMiddleware, deleteMiddleware, crudMiddleware, targetId, }) {
var _b, _c, _d, _e; var _b, _c, _d, _e;
const allowedTable = allowedTables.find((tbl) => tbl.table == table); const allowedTable = allowedTables.find((tbl) => tbl.table == table);
if (!allowedTable) { if (!allowedTable) {
@ -85,6 +85,7 @@ function checks(_a) {
newQuery = yield getMiddleware({ newQuery = yield getMiddleware({
query: newQuery || {}, query: newQuery || {},
table, table,
targetId,
}); });
} }
if (method !== "GET" && crudMiddleware) { if (method !== "GET" && crudMiddleware) {
@ -92,6 +93,7 @@ function checks(_a) {
body: newBody || {}, body: newBody || {},
query: newQuery || {}, query: newQuery || {},
table, table,
targetId,
}); });
newBody = lodash_1.default.merge(newBody, middRes); newBody = lodash_1.default.merge(newBody, middRes);
} }
@ -100,6 +102,7 @@ function checks(_a) {
body: newBody || {}, body: newBody || {},
query: newQuery || {}, query: newQuery || {},
table, table,
targetId,
}); });
newBody = lodash_1.default.merge(newBody, middRes); newBody = lodash_1.default.merge(newBody, middRes);
} }
@ -108,6 +111,7 @@ function checks(_a) {
body: newBody || {}, body: newBody || {},
query: newQuery || {}, query: newQuery || {},
table, table,
targetId,
}); });
newBody = lodash_1.default.merge(newBody, middRes); newBody = lodash_1.default.merge(newBody, middRes);
} }

View File

@ -2250,6 +2250,7 @@ export type APIPathsParamsGetMiddleware<T extends {
}> = (params: { }> = (params: {
query: APIPathsQuery<T>; query: APIPathsQuery<T>;
table: string; table: string;
targetId?: number | string;
}) => Promise<APIPathsQuery<T>>; }) => Promise<APIPathsQuery<T>>;
export type APIPathsParamsCrudMiddleware<T extends { export type APIPathsParamsCrudMiddleware<T extends {
[k: string]: any; [k: string]: any;
@ -2259,6 +2260,7 @@ export type APIPathsParamsCrudMiddleware<T extends {
body: APIPathsBody<T>; body: APIPathsBody<T>;
query: DsqlCrudQueryObject<T>; query: DsqlCrudQueryObject<T>;
table: K; table: K;
targetId?: number | string;
}) => Promise<APIPathsBody<T> | undefined>; }) => Promise<APIPathsBody<T> | undefined>;
export type APIPathsParamsAllowedTable = { export type APIPathsParamsAllowedTable = {
table: string; table: string;

View File

@ -18,6 +18,7 @@ export default async function checks<
putMiddleware, putMiddleware,
deleteMiddleware, deleteMiddleware,
crudMiddleware, crudMiddleware,
targetId,
}: APIPathsCrudParams<T>): Promise< }: APIPathsCrudParams<T>): Promise<
Pick<APIPathsCrudParams<T>, "query" | "body"> & { Pick<APIPathsCrudParams<T>, "query" | "body"> & {
allowedTable: APIPathsParamsAllowedTable; allowedTable: APIPathsParamsAllowedTable;
@ -126,6 +127,7 @@ export default async function checks<
newQuery = await getMiddleware({ newQuery = await getMiddleware({
query: newQuery || ({} as any), query: newQuery || ({} as any),
table, table,
targetId,
}); });
} }
@ -134,6 +136,7 @@ export default async function checks<
body: newBody || ({} as any), body: newBody || ({} as any),
query: newQuery || {}, query: newQuery || {},
table, table,
targetId,
}); });
newBody = _.merge(newBody, middRes); newBody = _.merge(newBody, middRes);
@ -144,6 +147,7 @@ export default async function checks<
body: newBody || ({} as any), body: newBody || ({} as any),
query: newQuery || {}, query: newQuery || {},
table, table,
targetId,
}); });
newBody = _.merge(newBody, middRes); newBody = _.merge(newBody, middRes);
@ -154,6 +158,7 @@ export default async function checks<
body: newBody || ({} as any), body: newBody || ({} as any),
query: newQuery || {}, query: newQuery || {},
table, table,
targetId,
}); });
newBody = _.merge(newBody, middRes); newBody = _.merge(newBody, middRes);

View File

@ -2915,6 +2915,7 @@ export type APIPathsParamsGetMiddleware<
> = (params: { > = (params: {
query: APIPathsQuery<T>; query: APIPathsQuery<T>;
table: string; table: string;
targetId?: number | string;
}) => Promise<APIPathsQuery<T>>; }) => Promise<APIPathsQuery<T>>;
export type APIPathsParamsCrudMiddleware< export type APIPathsParamsCrudMiddleware<
@ -2924,6 +2925,7 @@ export type APIPathsParamsCrudMiddleware<
body: APIPathsBody<T>; body: APIPathsBody<T>;
query: DsqlCrudQueryObject<T>; query: DsqlCrudQueryObject<T>;
table: K; table: K;
targetId?: number | string;
}) => Promise<APIPathsBody<T> | undefined>; }) => Promise<APIPathsBody<T> | undefined>;
export type APIPathsParamsAllowedTable = { export type APIPathsParamsAllowedTable = {

View File

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