Skip to content

Use zod schemas from sbvr-types to perform early validation before passing to hooks#1017

Open
Page- wants to merge 1 commit into
masterfrom
validate-before-hooks
Open

Use zod schemas from sbvr-types to perform early validation before passing to hooks#1017
Page- wants to merge 1 commit into
masterfrom
validate-before-hooks

Conversation

@Page-

@Page- Page- commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

This means hooks will receive validated data that they can trust to be of the expected type and improve the developer experience along with safety

https://balena.fibery.io/Work/Project/1002

Change-type: minor

@Page- Page- requested a review from a team June 23, 2026 15:33
@Page- Page- force-pushed the validate-before-hooks branch 9 times, most recently from 9c49739 to 86cc5e5 Compare June 30, 2026 13:48
@Page- Page- changed the title WIP: Use zod schemas from sbvr-types to perform early validation before passing to hooks Use zod schemas from sbvr-types to perform early validation before passing to hooks Jun 30, 2026
@Page- Page- changed the title Use zod schemas from sbvr-types to perform early validation before passing to hooks WIP: Use zod schemas from sbvr-types to perform early validation before passing to hooks Jun 30, 2026
const body = {
session_id: sid,
data,
data: { ...data },

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this now necessary?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it's an instance of the Session class which is not a valid "record", ie it's not just an object, but can be converted to one for as far as we care, and this is the easiest way to convert it now that we actually validate it before coercing it

@Page- Page- force-pushed the validate-before-hooks branch from 86cc5e5 to cbe40ea Compare June 30, 2026 15:34
@Page- Page- force-pushed the validate-before-hooks branch 3 times, most recently from d444a02 to 5efc64b Compare June 30, 2026 16:19
@Page- Page- changed the title WIP: Use zod schemas from sbvr-types to perform early validation before passing to hooks Use zod schemas from sbvr-types to perform early validation before passing to hooks Jul 3, 2026
@Page- Page- force-pushed the validate-before-hooks branch from 5efc64b to 0ba78c6 Compare July 8, 2026 14:12
@Page- Page- marked this pull request as ready for review July 8, 2026 14:12
@Page- Page- enabled auto-merge July 8, 2026 14:12
…ssing to hooks

Update @balena/sbvr-types from 11.1.4 to 11.3.0

This means hooks will receive validated data that they can trust to be
of the expected type and improve the developer experience along with
safety

https://balena.fibery.io/Work/Project/1002

Change-type: minor
@Page- Page- force-pushed the validate-before-hooks branch from 0ba78c6 to 5c2f438 Compare July 8, 2026 15:38
prop !== 'validator' &&
Object.hasOwn(obj, prop) &&
obj[prop] !== null &&
!['object', 'function'].includes(typeof obj[prop])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we're not freezing nested objects? Also, could !Object.isFrozen() help here?

}
};

export const stringifyIgnoreValidator = (key: string, value: any) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't mind a quick comment about the point of this function, it took me a minute to realize what it was doing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants