From 41e2917c92e7c25d759a78e13480912c008ab616 Mon Sep 17 00:00:00 2001 From: prostgles Date: Mon, 22 Jan 2024 22:49:09 +0200 Subject: [PATCH] fix validated row new column --- lib/DboBuilder/TableHandler/DataValidator.ts | 4 +++- package-lock.json | 4 ++-- package.json | 2 +- tests/client_only_queries.ts | 2 +- tests/server/package-lock.json | 2 +- tests/server/testPublish.ts | 5 +++-- 6 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/DboBuilder/TableHandler/DataValidator.ts b/lib/DboBuilder/TableHandler/DataValidator.ts index c6c7c95a..9cca68b6 100644 --- a/lib/DboBuilder/TableHandler/DataValidator.ts +++ b/lib/DboBuilder/TableHandler/DataValidator.ts @@ -168,15 +168,17 @@ const getValidatedRowFieldData = async ({ allowedCols, rows, validationOptions, rows.map(async nonvalidatedRow => { let row = pickKeys(nonvalidatedRow, allowedCols); + const initialRowKeys = Object.keys(row); if (validationOptions.validate) { if(!validationOptions.localParams){ throw "localParams missing for validate"; } row = await validationOptions.validate({ row, dbx: dbTx, localParams: validationOptions.localParams }); } + const keysAddedDuringValidate = Object.keys(row).filter(newKey => !initialRowKeys.includes(newKey)); const getColumn = (fieldName: string) => { - if (!allowedCols.includes(fieldName)) { + if (!allowedCols.concat(keysAddedDuringValidate).includes(fieldName)) { throw `Unexpected/Dissallowed column name: ${fieldName}`; } const column = tableHandler.columns.find(c => c.name === fieldName); diff --git a/package-lock.json b/package-lock.json index 9d94323a..9d19e59c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "prostgles-server", - "version": "4.2.7", + "version": "4.2.8", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "prostgles-server", - "version": "4.2.7", + "version": "4.2.8", "license": "MIT", "dependencies": { "@types/express": "^4.17.13", diff --git a/package.json b/package.json index d30485de..c6888f9e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "prostgles-server", - "version": "4.2.7", + "version": "4.2.8", "description": "", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/tests/client_only_queries.ts b/tests/client_only_queries.ts index 32624a55..f2dc0cb5 100644 --- a/tests/client_only_queries.ts +++ b/tests/client_only_queries.ts @@ -477,7 +477,7 @@ export default async function client_only(db: DBHandlerClient, auth: Auth, log: ]); const cols = await db.insert_rules.getColumns!(); - assert.equal(cols.filter(({ insert, update: u, select: s, delete: d }) => insert && !u && s && !d).length, 3, "Validated getColumns failed") + assert.equal(cols.filter(({ insert, update: u, select: s, delete: d }) => insert && !u && s && !d).length, 2, "Validated getColumns failed") /* Validated insert */ const expectB = await db.insert_rules.insert!({ name: "a" }, { returning: "*" }); diff --git a/tests/server/package-lock.json b/tests/server/package-lock.json index 1cbf0176..e641c7ac 100644 --- a/tests/server/package-lock.json +++ b/tests/server/package-lock.json @@ -21,7 +21,7 @@ }, "../..": { "name": "prostgles-server", - "version": "4.2.7", + "version": "4.2.8", "license": "MIT", "dependencies": { "@types/express": "^4.17.13", diff --git a/tests/server/testPublish.ts b/tests/server/testPublish.ts index 4d8911a5..f6f69533 100644 --- a/tests/server/testPublish.ts +++ b/tests/server/testPublish.ts @@ -93,10 +93,11 @@ export const testPublish: Publish = async ({ user, sid }) => insert_rules: { select: "*", insert: { - fields: "*", + fields: { added: 0 }, returningFields: { name: 1 }, validate: async ({ row }) => { - if(row.name === "a") row.name = "b" + if(row.name === "a") row.name = "b"; + row.added = (new Date()).toUTCString(); return row }, checkFilter: {