Add float/base64str types for ajv

This commit is contained in:
Rory&
2026-09-05 18:17:34 +02:00
parent 3eb94c7366
commit 855c274813
6 changed files with 33 additions and 7 deletions
Binary file not shown.
Binary file not shown.
+12
View File
@@ -19,3 +19,15 @@
export type StringStringDictionary = {
[key: string]: string;
};
/**
* @TJS-type: number
* @TJS-format: float
*/
export type float = number;
/**
* @TJS-type: string
* @TJS-format: byte
*/
export type base64str = string;
+2 -1
View File
@@ -43,7 +43,7 @@ export const ajv = new Ajv({
allErrors: true,
parseDate: true,
allowDate: true,
schemas: schemas,
// schemas: schemas,
coerceTypes: true,
messages: true,
strict: true,
@@ -52,6 +52,7 @@ export const ajv = new Ajv({
});
addFormats(ajv);
ajv.addSchema(schemas);
export function validateSchema<G extends object>(schema: string, data: G): G {
const valid = ajv.validate(schema, data);
+3 -3
View File
@@ -16,7 +16,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { PartialUser } from "@spacebar/schemas";
import { base64str, float, PartialUser } from "@spacebar/schemas";
export interface PublicAttachment {
filename: string;
@@ -39,8 +39,8 @@ export interface PublicAttachment {
placeholder?: string;
// voice messages
duration_secs?: number;
waveform?: string; // base64 byte array
duration_secs?: float;
waveform?: base64str; // base64 byte array
// clips
title?: string; // clips only? Documentation kinda sucks...
@@ -17,14 +17,27 @@
*/
import { Snowflake } from "../Identifiers";
import { InteractionType, AllowedMentions, MessageReference, ApplicationCommandType, BaseMessageComponents, Embed, PollAnswer, PollMedia, PublicUser } from "@spacebar/schemas";
import {
InteractionType,
AllowedMentions,
MessageReference,
ApplicationCommandType,
BaseMessageComponents,
Embed,
PollAnswer,
PollMedia,
PublicUser,
float,
base64str,
} from "@spacebar/schemas";
export type BaseMessageCreateAttachment = {
filename: string;
title?: string; // clips only?
description?: string; // alt text
duration_secs?: number; //flat
waveform?: string; //base64 byte array
duration_secs?: float; //flat
waveform?: base64str; //base64 byte array
is_clip?: boolean;
is_thumbnail?: boolean;