Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [] Add target field validation #731

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions packages/rich-text-types/src/validator/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ export type ValidateData<T extends Node> = (data: T['data'], path: Path) => Vali
export const VOID_CONTENT: GetContentRule<Node> = [];

export class NodeAssertion<T extends Node = Node> {
constructor(
private contentRule: GetContentRule<T>,
private validateData?: ValidateData<T>,
) {}
constructor(private contentRule: GetContentRule<T>, private validateData?: ValidateData<T>) {}

assert(node: T, path: Path): ValidationError[] {
const $ = new ObjectAssertion(node, path);
Expand Down Expand Up @@ -111,6 +108,10 @@ export class EntityLinkAssertion<
const $ = new ObjectAssertion(data, path);

if ($.object('target')) {
const target$ = new ObjectAssertion(data.target, path.of('target'));

target$.noAdditionalProperties(['sys']);
Copy link
Member

@z0al z0al Nov 1, 2024

Choose a reason for hiding this comment

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

Can you please add a test?


const sys$ = new ObjectAssertion(data.target.sys, path.of('target').of('sys'));

if (sys$.object()) {
Expand All @@ -126,7 +127,7 @@ export class EntityLinkAssertion<
}
}

$.catch(...sys$.errors);
$.catch(...target$.errors, ...sys$.errors);
}

$.noAdditionalProperties(['target']);
Expand Down
Loading