shared: schema: explicitly use "strictObject"

This commit is contained in:
Jesse Chan
2021-05-20 23:17:53 +08:00
parent 8b8ea2e2f9
commit abf99ba52b
4 changed files with 17 additions and 17 deletions

View File

@@ -1,4 +1,4 @@
import {literal, nativeEnum, number, object, string, union} from 'zod';
import {literal, nativeEnum, number, string, strictObject, union} from 'zod';
import type {infer as zodInfer} from 'zod';
import {AccessLevel} from './constants/Auth';
@@ -8,7 +8,7 @@ export const authMethodSchema = union([literal('default'), literal('none')]);
export type AuthMethod = zodInfer<typeof authMethodSchema>;
export const credentialsSchema = object({
export const credentialsSchema = strictObject({
username: string(),
password: string(),
client: clientConnectionSettingsSchema,
@@ -19,7 +19,7 @@ export type Credentials = zodInfer<typeof credentialsSchema>;
export type UserInDatabase = Required<Credentials> & {_id: string; timestamp: number};
export const authTokenSchema = object({
export const authTokenSchema = strictObject({
username: string(),
// issued at
iat: number(),

View File

@@ -1,7 +1,7 @@
import {literal, number, object, string, union} from 'zod';
import {literal, number, string, strictObject, union} from 'zod';
import type {infer as zodInfer} from 'zod';
const delugeConnectionSettingsSchema = object({
const delugeConnectionSettingsSchema = strictObject({
client: literal('Deluge'),
type: literal('rpc'),
version: literal(1),
@@ -13,7 +13,7 @@ const delugeConnectionSettingsSchema = object({
export type DelugeConnectionSettings = zodInfer<typeof delugeConnectionSettingsSchema>;
const qBittorrentConnectionSettingsSchema = object({
const qBittorrentConnectionSettingsSchema = strictObject({
client: literal('qBittorrent'),
type: literal('web'),
version: literal(1),
@@ -24,7 +24,7 @@ const qBittorrentConnectionSettingsSchema = object({
export type QBittorrentConnectionSettings = zodInfer<typeof qBittorrentConnectionSettingsSchema>;
const rTorrentTCPConnectionSettingsSchema = object({
const rTorrentTCPConnectionSettingsSchema = strictObject({
client: literal('rTorrent'),
type: literal('tcp'),
version: literal(1),
@@ -34,7 +34,7 @@ const rTorrentTCPConnectionSettingsSchema = object({
export type RTorrentTCPConnectionSettings = zodInfer<typeof rTorrentTCPConnectionSettingsSchema>;
const rTorrentSocketConnectionSettingsSchema = object({
const rTorrentSocketConnectionSettingsSchema = strictObject({
client: literal('rTorrent'),
type: literal('socket'),
version: literal(1),
@@ -50,7 +50,7 @@ const rTorrentConnectionSettingsSchema = union([
export type RTorrentConnectionSettings = zodInfer<typeof rTorrentConnectionSettingsSchema>;
const transmissionConnectionSettingsSchema = object({
const transmissionConnectionSettingsSchema = strictObject({
client: literal('Transmission'),
type: literal('rpc'),
version: literal(1),

View File

@@ -14,13 +14,13 @@
// env variable FLOOD_OPTION_port=80 is equivalent to argument --port 80. Use ',' to split
// for arguments that take multiple inputs such as --allowedpath.
import {array, boolean, number, object, string} from 'zod';
import {array, boolean, number, strictObject, string} from 'zod';
import type {infer as zodInfer} from 'zod';
import {authMethodSchema} from './Auth';
import {clientConnectionSettingsSchema} from './ClientConnectionSettings';
export const configSchema = object({
export const configSchema = strictObject({
// CLI argument: --baseuri
// This URI will prefix all of Flood's HTTP requests.
// For example, if you intend to serve from http://example.com/flood, set this to

View File

@@ -1,4 +1,4 @@
import {array, boolean, number, object, record, string} from 'zod';
import {array, boolean, number, record, strictObject, string} from 'zod';
import {noComma} from '../../util/regEx';
import type {infer as zodInfer} from 'zod';
@@ -8,7 +8,7 @@ const TAG_NO_COMMA_MESSAGE = {
};
// POST /api/torrents/add-urls
export const addTorrentByURLSchema = object({
export const addTorrentByURLSchema = strictObject({
// URLs to download torrents from
urls: array(string()).nonempty(),
// Cookies to attach to requests, arrays of strings in the format "name=value" with domain as key
@@ -32,7 +32,7 @@ export const addTorrentByURLSchema = object({
export type AddTorrentByURLOptions = zodInfer<typeof addTorrentByURLSchema>;
// POST /api/torrents/add-files
export const addTorrentByFileSchema = object({
export const addTorrentByFileSchema = strictObject({
// Torrent files in base64
files: array(string()).nonempty(),
// Path of destination
@@ -54,7 +54,7 @@ export const addTorrentByFileSchema = object({
export type AddTorrentByFileOptions = zodInfer<typeof addTorrentByFileSchema>;
// PATCH /api/torrents/tags
export const setTorrentsTagsSchema = object({
export const setTorrentsTagsSchema = strictObject({
// An array of string representing hashes of torrents to operate on
hashes: array(string()).nonempty(),
// An array of string representing tags
@@ -64,7 +64,7 @@ export const setTorrentsTagsSchema = object({
export type SetTorrentsTagsOptions = zodInfer<typeof setTorrentsTagsSchema>;
// POST /api/torrents/reannounce
export const reannounceTorrentsSchema = object({
export const reannounceTorrentsSchema = strictObject({
// An array of string representing hashes of torrents to be reannounced
hashes: array(string()).nonempty(),
});
@@ -72,7 +72,7 @@ export const reannounceTorrentsSchema = object({
export type ReannounceTorrentsOptions = zodInfer<typeof reannounceTorrentsSchema>;
// GET /api/torrents/{hash}/contents/{indices}/data
export const contentTokenSchema = object({
export const contentTokenSchema = strictObject({
username: string(),
hash: string(),
indices: string(),