mirror of
https://github.com/spacebarchat/server.git
synced 2024-09-21 18:21:36 +02:00
✨ Schema
This commit is contained in:
parent
1f1743c927
commit
56c9e43777
5
.prettierrc
Normal file
5
.prettierrc
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"tabWidth": 4,
|
||||
"useTabs": true,
|
||||
"printWidth": 140
|
||||
}
|
4
package-lock.json
generated
4
package-lock.json
generated
@ -2289,7 +2289,7 @@
|
||||
},
|
||||
"node_modules/fosscord-server-util": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "git+ssh://git@github.com/fosscord/fosscord-server-util.git#3bdbd9340edf4f3edd728624499dbcaaf08a25ed",
|
||||
"resolved": "git+ssh://git@github.com/fosscord/fosscord-server-util.git#18498d6515e43eb764eb26c9ec3a35ce515c4257",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
@ -8151,7 +8151,7 @@
|
||||
"integrity": "sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ="
|
||||
},
|
||||
"fosscord-server-util": {
|
||||
"version": "git+ssh://git@github.com/fosscord/fosscord-server-util.git#3bdbd9340edf4f3edd728624499dbcaaf08a25ed",
|
||||
"version": "git+ssh://git@github.com/fosscord/fosscord-server-util.git#18498d6515e43eb764eb26c9ec3a35ce515c4257",
|
||||
"from": "fosscord-server-util@github:fosscord/fosscord-server-util",
|
||||
"requires": {
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
|
51
src/schema/Channel.ts
Normal file
51
src/schema/Channel.ts
Normal file
@ -0,0 +1,51 @@
|
||||
import { Length } from "../util/instanceOf";
|
||||
|
||||
export const ChannelModifySchema = {
|
||||
name: new Length(String, 2, 100),
|
||||
type: Number,
|
||||
$topic: new Length(String, 0, 1024),
|
||||
$bitrate: Number,
|
||||
$user_limit: Number,
|
||||
$rate_limit_per_user: new Length(Number, 0, 21600),
|
||||
$position: Number,
|
||||
$permission_overwrites: [
|
||||
{
|
||||
id: BigInt,
|
||||
type: new Length(Number, 0, 1), // either 0 (role) or 1 (member)
|
||||
allow: BigInt,
|
||||
deny: BigInt,
|
||||
},
|
||||
],
|
||||
$parent_id: BigInt,
|
||||
$nsfw: Boolean,
|
||||
};
|
||||
|
||||
export interface ChannelModifySchema {
|
||||
name: string;
|
||||
type: number;
|
||||
topic?: string;
|
||||
bitrate?: number;
|
||||
user_limit?: number;
|
||||
rate_limit_per_user?: Number;
|
||||
position?: number;
|
||||
permission_overwrites?: {
|
||||
id: bigint;
|
||||
type: number;
|
||||
allow: bigint;
|
||||
deny: bigint;
|
||||
}[];
|
||||
parent_id?: bigint;
|
||||
nsfw?: boolean;
|
||||
}
|
||||
|
||||
export const ChannelGuildPositionUpdateSchema = [
|
||||
{
|
||||
id: BigInt,
|
||||
$position: Number,
|
||||
},
|
||||
];
|
||||
|
||||
export type ChannelGuildPositionUpdateSchema = {
|
||||
id: bigint;
|
||||
position?: number;
|
||||
}[];
|
27
src/schema/Message.ts
Normal file
27
src/schema/Message.ts
Normal file
@ -0,0 +1,27 @@
|
||||
export const MessageCreateSchema = {
|
||||
content: String,
|
||||
nonce: Number,
|
||||
tts: Boolean,
|
||||
embed: {},
|
||||
allowed_mentions: [],
|
||||
message_reference: {
|
||||
message_id: BigInt,
|
||||
channel_id: BigInt,
|
||||
guild_id: BigInt,
|
||||
fail_if_not_exists: Boolean,
|
||||
},
|
||||
};
|
||||
|
||||
export interface MessageCreateSchema {
|
||||
content: string;
|
||||
nonce: number;
|
||||
tts: boolean;
|
||||
embed: {};
|
||||
allowed_mentions: [];
|
||||
message_reference: {
|
||||
message_id: bigint;
|
||||
channel_id: bigint;
|
||||
guild_id: bigint;
|
||||
fail_if_not_exists: boolean;
|
||||
};
|
||||
}
|
@ -45,6 +45,7 @@ export interface DefaultOptions {
|
||||
ttsCharacters: number;
|
||||
maxReactions: number;
|
||||
maxAttachmentSize: number;
|
||||
maxBulkDelete: number;
|
||||
};
|
||||
channel: {
|
||||
maxPins: number;
|
||||
@ -124,6 +125,7 @@ export const DefaultOptions: DefaultOptions = {
|
||||
ttsCharacters: 200,
|
||||
maxReactions: 20,
|
||||
maxAttachmentSize: 8388608,
|
||||
maxBulkDelete: 100,
|
||||
},
|
||||
channel: {
|
||||
maxPins: 50,
|
||||
|
@ -8,3 +8,5 @@ export async function emitEvent(payload: Omit<Event, "created_at">) {
|
||||
|
||||
return await new EventModel(obj).save();
|
||||
}
|
||||
|
||||
export async function emitAuditLog(payload: any) {}
|
||||
|
@ -114,35 +114,10 @@ export function instanceOf(
|
||||
}
|
||||
|
||||
if (typeof type === "object") {
|
||||
if (type?.constructor?.name != "Object") {
|
||||
if (type instanceof Tuple) {
|
||||
if ((<Tuple>type).types.some((x) => instanceOf(x, value, { path, optional, errors, req, ref })))
|
||||
return true;
|
||||
throw new FieldError(
|
||||
"BASE_TYPE_CHOICES",
|
||||
req.t("common:field.BASE_TYPE_CHOICES", { types: type.types })
|
||||
);
|
||||
} else if (type instanceof Length) {
|
||||
let length = <Length>type;
|
||||
if (instanceOf(length.type, value, { path, optional, req, ref, errors }) !== true) return errors;
|
||||
let val = ref.obj[ref.key];
|
||||
if ((<Length>type).check(val)) return true;
|
||||
throw new FieldError(
|
||||
"BASE_TYPE_BAD_LENGTH",
|
||||
req.t("common:field.BASE_TYPE_BAD_LENGTH", {
|
||||
length: `${type.min} - ${type.max}`,
|
||||
})
|
||||
);
|
||||
}
|
||||
if (value instanceof type) return true;
|
||||
throw new FieldError("BASE_TYPE_CLASS", req.t("common:field.BASE_TYPE_CLASS", { type }));
|
||||
}
|
||||
if (typeof value !== "object")
|
||||
throw new FieldError("BASE_TYPE_OBJECT", req.t("common:field.BASE_TYPE_OBJECT"));
|
||||
if (typeof value !== "object") throw new FieldError("BASE_TYPE_OBJECT", req.t("common:field.BASE_TYPE_OBJECT"));
|
||||
|
||||
if (Array.isArray(type)) {
|
||||
if (!Array.isArray(value))
|
||||
throw new FieldError("BASE_TYPE_ARRAY", req.t("common:field.BASE_TYPE_ARRAY"));
|
||||
if (!Array.isArray(value)) throw new FieldError("BASE_TYPE_ARRAY", req.t("common:field.BASE_TYPE_ARRAY"));
|
||||
if (!type.length) return true; // type array didn't specify any type
|
||||
|
||||
return (
|
||||
@ -159,6 +134,24 @@ export function instanceOf(
|
||||
);
|
||||
}) || errors
|
||||
);
|
||||
} else if (type?.constructor?.name != "Object") {
|
||||
if (type instanceof Tuple) {
|
||||
if ((<Tuple>type).types.some((x) => instanceOf(x, value, { path, optional, errors, req, ref }))) return true;
|
||||
throw new FieldError("BASE_TYPE_CHOICES", req.t("common:field.BASE_TYPE_CHOICES", { types: type.types }));
|
||||
} else if (type instanceof Length) {
|
||||
let length = <Length>type;
|
||||
if (instanceOf(length.type, value, { path, optional, req, ref, errors }) !== true) return errors;
|
||||
let val = ref.obj[ref.key];
|
||||
if ((<Length>type).check(val)) return true;
|
||||
throw new FieldError(
|
||||
"BASE_TYPE_BAD_LENGTH",
|
||||
req.t("common:field.BASE_TYPE_BAD_LENGTH", {
|
||||
length: `${type.min} - ${type.max}`,
|
||||
})
|
||||
);
|
||||
}
|
||||
if (value instanceof type) return true;
|
||||
throw new FieldError("BASE_TYPE_CLASS", req.t("common:field.BASE_TYPE_CLASS", { type }));
|
||||
}
|
||||
|
||||
const diff = Object.keys(value).missing(
|
||||
|
Loading…
Reference in New Issue
Block a user