mirror of
https://github.com/hexastack/hexabot
synced 2025-02-23 04:48:51 +00:00
feat: channelSchema validation with zod
This commit is contained in:
parent
e341f2d3da
commit
011bc69db9
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2024 Hexastack. All rights reserved.
|
* Copyright © 2025 Hexastack. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
|
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
|
||||||
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
|
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
|
||||||
@ -12,18 +12,21 @@ import {
|
|||||||
ValidatorConstraint,
|
ValidatorConstraint,
|
||||||
ValidatorConstraintInterface,
|
ValidatorConstraintInterface,
|
||||||
} from 'class-validator';
|
} from 'class-validator';
|
||||||
|
import { z } from 'zod';
|
||||||
|
|
||||||
export function isChannelData(channel: any) {
|
export const channelSchema = z.object({
|
||||||
return (
|
name: z.string(),
|
||||||
typeof channel === 'object' &&
|
});
|
||||||
channel.name &&
|
|
||||||
typeof channel.name === 'string'
|
export type Channel = z.infer<typeof channelSchema>;
|
||||||
);
|
|
||||||
|
export function isChannelData(channel: Channel) {
|
||||||
|
return channelSchema.safeParse(channel).success;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ValidatorConstraint({ async: false })
|
@ValidatorConstraint({ async: false })
|
||||||
export class ChannelDataValidator implements ValidatorConstraintInterface {
|
export class ChannelDataValidator implements ValidatorConstraintInterface {
|
||||||
validate(channel: any) {
|
validate(channel: Channel) {
|
||||||
return isChannelData(channel);
|
return isChannelData(channel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user