Update cafy to 8.0.0 🚀

This commit is contained in:
syuilo 2018-05-02 18:06:16 +09:00
parent 2d266c6946
commit 6c1eae618e
97 changed files with 294 additions and 291 deletions

View file

@ -88,7 +88,7 @@
"autwh": "0.1.0",
"bcryptjs": "2.4.3",
"bootstrap-vue": "2.0.0-rc.6",
"cafy": "7.0.1",
"cafy": "8.0.0",
"chai": "4.1.2",
"chai-http": "4.0.0",
"chalk": "2.4.1",

View file

@ -8,8 +8,8 @@ export const isNotAnId = x => !isAnId(x);
* ID
*/
export default class ID extends Query<mongo.ObjectID> {
constructor(...args) {
super(...args);
constructor() {
super();
this.transform = v => {
if (isAnId(v) && !mongo.ObjectID.prototype.isPrototypeOf(v)) {
@ -19,7 +19,7 @@ export default class ID extends Query<mongo.ObjectID> {
}
};
this.pushValidator(v => {
this.push(v => {
if (!mongo.ObjectID.prototype.isPrototypeOf(v) && isNotAnId(v)) {
return new Error('must-be-an-id');
}

View file

@ -17,7 +17,7 @@ export interface INoteReaction {
reaction: string;
}
export const validateReaction = $().string().or([
export const validateReaction = $.str.or([
'like',
'love',
'laugh',

View file

@ -9,7 +9,7 @@ import Note from '../../../../models/note';
*/
module.exports = params => new Promise(async (res, rej) => {
// Get 'limit' parameter
const [limit = 365, limitErr] = $(params.limit).optional.number().range(1, 365).get();
const [limit = 365, limitErr] = $.num.optional().range(1, 365).get(params.limit);
if (limitErr) return rej('invalid limit param');
const datas = await Note

View file

@ -9,7 +9,7 @@ import User from '../../../../models/user';
*/
module.exports = params => new Promise(async (res, rej) => {
// Get 'limit' parameter
const [limit = 365, limitErr] = $(params.limit).optional.number().range(1, 365).get();
const [limit = 365, limitErr] = $.num.optional().range(1, 365).get(params.limit);
if (limitErr) return rej('invalid limit param');
const users = await User

View file

@ -12,11 +12,11 @@ import Note from '../../../../../models/note';
*/
module.exports = (params) => new Promise(async (res, rej) => {
// Get 'limit' parameter
const [limit = 365, limitErr] = $(params.limit).optional.number().range(1, 365).get();
const [limit = 365, limitErr] = $.num.optional().range(1, 365).get(params.limit);
if (limitErr) return rej('invalid limit param');
// Get 'userId' parameter
const [userId, userIdErr] = $(params.userId).type(ID).get();
const [userId, userIdErr] = $.type(ID).get(params.userId);
if (userIdErr) return rej('invalid userId param');
// Lookup user

View file

@ -10,7 +10,7 @@ import FollowedLog from '../../../../../models/followed-log';
*/
module.exports = (params) => new Promise(async (res, rej) => {
// Get 'userId' parameter
const [userId, userIdErr] = $(params.userId).type(ID).get();
const [userId, userIdErr] = $.type(ID).get(params.userId);
if (userIdErr) return rej('invalid userId param');
// Lookup user

View file

@ -10,7 +10,7 @@ import FollowingLog from '../../../../../models/following-log';
*/
module.exports = (params) => new Promise(async (res, rej) => {
// Get 'userId' parameter
const [userId, userIdErr] = $(params.userId).type(ID).get();
const [userId, userIdErr] = $.type(ID).get(params.userId);
if (userIdErr) return rej('invalid userId param');
// Lookup user

View file

@ -10,7 +10,7 @@ import Note from '../../../../../models/note';
*/
module.exports = (params) => new Promise(async (res, rej) => {
// Get 'userId' parameter
const [userId, userIdErr] = $(params.userId).type(ID).get();
const [userId, userIdErr] = $.type(ID).get(params.userId);
if (userIdErr) return rej('invalid userId param');
// Lookup user

View file

@ -13,7 +13,7 @@ import Reaction from '../../../../../models/note-reaction';
*/
module.exports = (params) => new Promise(async (res, rej) => {
// Get 'userId' parameter
const [userId, userIdErr] = $(params.userId).type(ID).get();
const [userId, userIdErr] = $.type(ID).get(params.userId);
if (userIdErr) return rej('invalid userId param');
// Lookup user

View file

@ -67,24 +67,24 @@ import App, { isValidNameId, pack } from '../../../../models/app';
*/
module.exports = async (params, user) => new Promise(async (res, rej) => {
// Get 'nameId' parameter
const [nameId, nameIdErr] = $(params.nameId).string().pipe(isValidNameId).get();
const [nameId, nameIdErr] = $.str.pipe(isValidNameId).get(params.nameId);
if (nameIdErr) return rej('invalid nameId param');
// Get 'name' parameter
const [name, nameErr] = $(params.name).string().get();
const [name, nameErr] = $.str.get(params.name);
if (nameErr) return rej('invalid name param');
// Get 'description' parameter
const [description, descriptionErr] = $(params.description).string().get();
const [description, descriptionErr] = $.str.get(params.description);
if (descriptionErr) return rej('invalid description param');
// Get 'permission' parameter
const [permission, permissionErr] = $(params.permission).array($().string()).unique().get();
const [permission, permissionErr] = $.arr($.str).unique().get(params.permission);
if (permissionErr) return rej('invalid permission param');
// Get 'callbackUrl' parameter
// TODO: Check it is valid url
const [callbackUrl = null, callbackUrlErr] = $(params.callbackUrl).optional.nullable.string().get();
const [callbackUrl = null, callbackUrlErr] = $.str.optional().nullable().get(params.callbackUrl);
if (callbackUrlErr) return rej('invalid callbackUrl param');
// Generate secret

View file

@ -42,7 +42,7 @@ import { isValidNameId } from '../../../../../models/app';
*/
module.exports = async (params) => new Promise(async (res, rej) => {
// Get 'nameId' parameter
const [nameId, nameIdErr] = $(params.nameId).string().pipe(isValidNameId).get();
const [nameId, nameIdErr] = $.str.pipe(isValidNameId).get(params.nameId);
if (nameIdErr) return rej('invalid nameId param');
// Get exist

View file

@ -41,11 +41,11 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
const isSecure = user != null && app == null;
// Get 'appId' parameter
const [appId, appIdErr] = $(params.appId).optional.type(ID).get();
const [appId, appIdErr] = $.type(ID).optional().get(params.appId);
if (appIdErr) return rej('invalid appId param');
// Get 'nameId' parameter
const [nameId, nameIdErr] = $(params.nameId).optional.string().get();
const [nameId, nameIdErr] = $.str.optional().get(params.nameId);
if (nameIdErr) return rej('invalid nameId param');
if (appId === undefined && nameId === undefined) {

View file

@ -40,7 +40,7 @@ import AccessToken from '../../../../models/access-token';
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'token' parameter
const [token, tokenErr] = $(params.token).string().get();
const [token, tokenErr] = $.str.get(params.token);
if (tokenErr) return rej('invalid token param');
// Fetch token

View file

@ -46,7 +46,7 @@ import config from '../../../../../config';
*/
module.exports = (params) => new Promise(async (res, rej) => {
// Get 'appSecret' parameter
const [appSecret, appSecretErr] = $(params.appSecret).string().get();
const [appSecret, appSecretErr] = $.str.get(params.appSecret);
if (appSecretErr) return rej('invalid appSecret param');
// Lookup app

View file

@ -53,7 +53,7 @@ import AuthSess, { pack } from '../../../../../models/auth-session';
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'token' parameter
const [token, tokenErr] = $(params.token).string().get();
const [token, tokenErr] = $.str.get(params.token);
if (tokenErr) return rej('invalid token param');
// Lookup session

View file

@ -51,7 +51,7 @@ import { pack } from '../../../../../models/user';
*/
module.exports = (params) => new Promise(async (res, rej) => {
// Get 'appSecret' parameter
const [appSecret, appSecretErr] = $(params.appSecret).string().get();
const [appSecret, appSecretErr] = $.str.get(params.appSecret);
if (appSecretErr) return rej('invalid appSecret param');
// Lookup app
@ -64,7 +64,7 @@ module.exports = (params) => new Promise(async (res, rej) => {
}
// Get 'token' parameter
const [token, tokenErr] = $(params.token).string().get();
const [token, tokenErr] = $.str.get(params.token);
if (tokenErr) return rej('invalid token param');
// Fetch token

View file

@ -13,15 +13,15 @@ import Channel, { pack } from '../../../models/channel';
*/
module.exports = (params, me) => new Promise(async (res, rej) => {
// Get 'limit' parameter
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
if (limitErr) return rej('invalid limit param');
// Get 'sinceId' parameter
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).get();
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
if (sinceIdErr) return rej('invalid sinceId param');
// Get 'untilId' parameter
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).get();
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
if (untilIdErr) return rej('invalid untilId param');
// Check if both of sinceId and untilId is specified

View file

@ -11,7 +11,7 @@ import { pack } from '../../../../models/channel';
*/
module.exports = async (params, user) => new Promise(async (res, rej) => {
// Get 'title' parameter
const [title, titleErr] = $(params.title).string().range(1, 100).get();
const [title, titleErr] = $.str.range(1, 100).get(params.title);
if (titleErr) return rej('invalid title param');
// Create a channel

View file

@ -10,15 +10,15 @@ import Note, { pack } from '../../../../models/note';
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'limit' parameter
const [limit = 1000, limitErr] = $(params.limit).optional.number().range(1, 1000).get();
const [limit = 1000, limitErr] = $.num.optional().range(1, 1000).get(params.limit);
if (limitErr) return rej('invalid limit param');
// Get 'sinceId' parameter
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).get();
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
if (sinceIdErr) return rej('invalid sinceId param');
// Get 'untilId' parameter
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).get();
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
if (untilIdErr) return rej('invalid untilId param');
// Check if both of sinceId and untilId is specified
@ -27,7 +27,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
}
// Get 'channelId' parameter
const [channelId, channelIdErr] = $(params.channelId).type(ID).get();
const [channelId, channelIdErr] = $.type(ID).get(params.channelId);
if (channelIdErr) return rej('invalid channelId param');
// Fetch channel

View file

@ -9,7 +9,7 @@ import Channel, { IChannel, pack } from '../../../../models/channel';
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'channelId' parameter
const [channelId, channelIdErr] = $(params.channelId).type(ID).get();
const [channelId, channelIdErr] = $.type(ID).get(params.channelId);
if (channelIdErr) return rej('invalid channelId param');
// Fetch channel

View file

@ -10,7 +10,7 @@ import Watching from '../../../../models/channel-watching';
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'channelId' parameter
const [channelId, channelIdErr] = $(params.channelId).type(ID).get();
const [channelId, channelIdErr] = $.type(ID).get(params.channelId);
if (channelIdErr) return rej('invalid channelId param');
//#region Fetch channel

View file

@ -10,7 +10,7 @@ import Watching from '../../../../models/channel-watching';
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'channelId' parameter
const [channelId, channelIdErr] = $(params.channelId).type(ID).get();
const [channelId, channelIdErr] = $.type(ID).get(params.channelId);
if (channelIdErr) return rej('invalid channelId param');
//#region Fetch channel

View file

@ -9,15 +9,15 @@ import DriveFile, { pack } from '../../../../models/drive-file';
*/
module.exports = async (params, user, app) => {
// Get 'limit' parameter
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
if (limitErr) throw 'invalid limit param';
// Get 'sinceId' parameter
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).get();
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
if (sinceIdErr) throw 'invalid sinceId param';
// Get 'untilId' parameter
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).get();
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
if (untilIdErr) throw 'invalid untilId param';
// Check if both of sinceId and untilId is specified
@ -26,11 +26,11 @@ module.exports = async (params, user, app) => {
}
// Get 'folderId' parameter
const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.type(ID).get();
const [folderId = null, folderIdErr] = $.type(ID).optional().nullable().get(params.folderId);
if (folderIdErr) throw 'invalid folderId param';
// Get 'type' parameter
const [type, typeErr] = $(params.type).optional.string().match(/^[a-zA-Z\/\-\*]+$/).get();
const [type, typeErr] = $.str.optional().match(/^[a-zA-Z\/\-\*]+$/).get(params.type);
if (typeErr) throw 'invalid type param';
// Construct query

View file

@ -29,7 +29,7 @@ module.exports = async (file, params, user): Promise<any> => {
}
// Get 'folderId' parameter
const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.type(ID).get();
const [folderId = null, folderIdErr] = $.type(ID).optional().nullable().get(params.folderId);
if (folderIdErr) throw 'invalid folderId param';
try {

View file

@ -9,11 +9,11 @@ import DriveFile, { pack } from '../../../../../models/drive-file';
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'name' parameter
const [name, nameErr] = $(params.name).string().get();
const [name, nameErr] = $.str.get(params.name);
if (nameErr) return rej('invalid name param');
// Get 'folderId' parameter
const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.type(ID).get();
const [folderId = null, folderIdErr] = $.type(ID).optional().nullable().get(params.folderId);
if (folderIdErr) return rej('invalid folderId param');
// Issue query

View file

@ -9,7 +9,7 @@ import DriveFile, { pack } from '../../../../../models/drive-file';
*/
module.exports = async (params, user) => {
// Get 'fileId' parameter
const [fileId, fileIdErr] = $(params.fileId).type(ID).get();
const [fileId, fileIdErr] = $.type(ID).get(params.fileId);
if (fileIdErr) throw 'invalid fileId param';
// Fetch file

View file

@ -11,7 +11,7 @@ import { publishDriveStream } from '../../../../../publishers/stream';
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'fileId' parameter
const [fileId, fileIdErr] = $(params.fileId).type(ID).get();
const [fileId, fileIdErr] = $.type(ID).get(params.fileId);
if (fileIdErr) return rej('invalid fileId param');
// Fetch file
@ -26,12 +26,12 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
}
// Get 'name' parameter
const [name, nameErr] = $(params.name).optional.string().pipe(validateFileName).get();
const [name, nameErr] = $.str.optional().pipe(validateFileName).get(params.name);
if (nameErr) return rej('invalid name param');
if (name) file.filename = name;
// Get 'folderId' parameter
const [folderId, folderIdErr] = $(params.folderId).optional.nullable.type(ID).get();
const [folderId, folderIdErr] = $.type(ID).optional().nullable().get(params.folderId);
if (folderIdErr) return rej('invalid folderId param');
if (folderId !== undefined) {

View file

@ -11,11 +11,11 @@ import uploadFromUrl from '../../../../../services/drive/upload-from-url';
module.exports = async (params, user): Promise<any> => {
// Get 'url' parameter
// TODO: Validate this url
const [url, urlErr] = $(params.url).string().get();
const [url, urlErr] = $.str.get(params.url);
if (urlErr) throw 'invalid url param';
// Get 'folderId' parameter
const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.type(ID).get();
const [folderId = null, folderIdErr] = $.type(ID).optional().nullable().get(params.folderId);
if (folderIdErr) throw 'invalid folderId param';
return pack(await uploadFromUrl(url, user, folderId));

View file

@ -9,15 +9,15 @@ import DriveFolder, { pack } from '../../../../models/drive-folder';
*/
module.exports = (params, user, app) => new Promise(async (res, rej) => {
// Get 'limit' parameter
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
if (limitErr) return rej('invalid limit param');
// Get 'sinceId' parameter
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).get();
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
if (sinceIdErr) return rej('invalid sinceId param');
// Get 'untilId' parameter
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).get();
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
if (untilIdErr) return rej('invalid untilId param');
// Check if both of sinceId and untilId is specified
@ -26,7 +26,7 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
}
// Get 'folderId' parameter
const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.type(ID).get();
const [folderId = null, folderIdErr] = $.type(ID).optional().nullable().get(params.folderId);
if (folderIdErr) return rej('invalid folderId param');
// Construct query

View file

@ -10,11 +10,11 @@ import { publishDriveStream } from '../../../../../publishers/stream';
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'name' parameter
const [name = '無題のフォルダー', nameErr] = $(params.name).optional.string().pipe(isValidFolderName).get();
const [name = '無題のフォルダー', nameErr] = $.str.optional().pipe(isValidFolderName).get(params.name);
if (nameErr) return rej('invalid name param');
// Get 'parentId' parameter
const [parentId = null, parentIdErr] = $(params.parentId).optional.nullable.type(ID).get();
const [parentId = null, parentIdErr] = $.type(ID).optional().nullable().get(params.parentId);
if (parentIdErr) return rej('invalid parentId param');
// If the parent folder is specified

View file

@ -9,11 +9,11 @@ import DriveFolder, { pack } from '../../../../../models/drive-folder';
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'name' parameter
const [name, nameErr] = $(params.name).string().get();
const [name, nameErr] = $.str.get(params.name);
if (nameErr) return rej('invalid name param');
// Get 'parentId' parameter
const [parentId = null, parentIdErr] = $(params.parentId).optional.nullable.type(ID).get();
const [parentId = null, parentIdErr] = $.type(ID).optional().nullable().get(params.parentId);
if (parentIdErr) return rej('invalid parentId param');
// Issue query

View file

@ -9,7 +9,7 @@ import DriveFolder, { pack } from '../../../../../models/drive-folder';
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'folderId' parameter
const [folderId, folderIdErr] = $(params.folderId).type(ID).get();
const [folderId, folderIdErr] = $.type(ID).get(params.folderId);
if (folderIdErr) return rej('invalid folderId param');
// Get folder

View file

@ -10,7 +10,7 @@ import { publishDriveStream } from '../../../../../publishers/stream';
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'folderId' parameter
const [folderId, folderIdErr] = $(params.folderId).type(ID).get();
const [folderId, folderIdErr] = $.type(ID).get(params.folderId);
if (folderIdErr) return rej('invalid folderId param');
// Fetch folder
@ -25,12 +25,12 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
}
// Get 'name' parameter
const [name, nameErr] = $(params.name).optional.string().pipe(isValidFolderName).get();
const [name, nameErr] = $.str.optional().pipe(isValidFolderName).get(params.name);
if (nameErr) return rej('invalid name param');
if (name) folder.name = name;
// Get 'parentId' parameter
const [parentId, parentIdErr] = $(params.parentId).optional.nullable.type(ID).get();
const [parentId, parentIdErr] = $.type(ID).optional().nullable().get(params.parentId);
if (parentIdErr) return rej('invalid parentId param');
if (parentId !== undefined) {
if (parentId === null) {

View file

@ -9,15 +9,15 @@ import DriveFile, { pack } from '../../../../models/drive-file';
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'limit' parameter
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
if (limitErr) return rej('invalid limit param');
// Get 'sinceId' parameter
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).get();
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
if (sinceIdErr) return rej('invalid sinceId param');
// Get 'untilId' parameter
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).get();
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
if (untilIdErr) return rej('invalid untilId param');
// Check if both of sinceId and untilId is specified
@ -26,7 +26,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
}
// Get 'type' parameter
const [type, typeErr] = $(params.type).optional.string().match(/^[a-zA-Z\/\-\*]+$/).get();
const [type, typeErr] = $.str.optional().match(/^[a-zA-Z\/\-\*]+$/).get(params.type);
if (typeErr) return rej('invalid type param');
// Construct query

View file

@ -13,7 +13,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
const follower = user;
// Get 'userId' parameter
const [userId, userIdErr] = $(params.userId).type(ID).get();
const [userId, userIdErr] = $.type(ID).get(params.userId);
if (userIdErr) return rej('invalid userId param');
// 自分自身

View file

@ -13,7 +13,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
const follower = user;
// Get 'userId' parameter
const [userId, userIdErr] = $(params.userId).type(ID).get();
const [userId, userIdErr] = $.type(ID).get(params.userId);
if (userIdErr) return rej('invalid userId param');
// Check if the followee is yourself

View file

@ -8,7 +8,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
const follower = user;
// Get 'userId' parameter
const [userId, userIdErr] = $(params.userId).type(ID).get();
const [userId, userIdErr] = $.type(ID).get(params.userId);
if (userIdErr) return rej('invalid userId param');
// Fetch following

View file

@ -8,7 +8,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
const follower = user;
// Get 'userId' parameter
const [userId, userIdErr] = $(params.userId).type(ID).get();
const [userId, userIdErr] = $.type(ID).get(params.userId);
if (userIdErr) return rej('invalid userId param');
// Fetch following

View file

@ -7,7 +7,7 @@ import User from '../../../../../models/user';
module.exports = async (params, user) => new Promise(async (res, rej) => {
// Get 'token' parameter
const [token, tokenErr] = $(params.token).string().get();
const [token, tokenErr] = $.str.get(params.token);
if (tokenErr) return rej('invalid token param');
const _token = token.replace(/\s/g, '');

View file

@ -10,7 +10,7 @@ import config from '../../../../../config';
module.exports = async (params, user) => new Promise(async (res, rej) => {
// Get 'password' parameter
const [password, passwordErr] = $(params.password).string().get();
const [password, passwordErr] = $.str.get(params.password);
if (passwordErr) return rej('invalid password param');
// Compare password

View file

@ -7,7 +7,7 @@ import User from '../../../../../models/user';
module.exports = async (params, user) => new Promise(async (res, rej) => {
// Get 'password' parameter
const [password, passwordErr] = $(params.password).string().get();
const [password, passwordErr] = $.str.get(params.password);
if (passwordErr) return rej('invalid password param');
// Compare password

View file

@ -10,15 +10,15 @@ import { pack } from '../../../../models/app';
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'limit' parameter
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
if (limitErr) return rej('invalid limit param');
// Get 'offset' parameter
const [offset = 0, offsetErr] = $(params.offset).optional.number().min(0).get();
const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset);
if (offsetErr) return rej('invalid offset param');
// Get 'sort' parameter
const [sort = 'desc', sortError] = $(params.sort).optional.string().or('desc asc').get();
const [sort = 'desc', sortError] = $.str.optional().or('desc asc').get(params.sort);
if (sortError) return rej('invalid sort param');
// Get tokens

View file

@ -10,11 +10,11 @@ import User from '../../../../models/user';
*/
module.exports = async (params, user) => new Promise(async (res, rej) => {
// Get 'currentPasword' parameter
const [currentPassword, currentPasswordErr] = $(params.currentPasword).string().get();
const [currentPassword, currentPasswordErr] = $.str.get(params.currentPasword);
if (currentPasswordErr) return rej('invalid currentPasword param');
// Get 'newPassword' parameter
const [newPassword, newPasswordErr] = $(params.newPassword).string().get();
const [newPassword, newPasswordErr] = $.str.get(params.newPassword);
if (newPasswordErr) return rej('invalid newPassword param');
// Compare password

View file

@ -9,15 +9,15 @@ import Favorite, { pack } from '../../../../models/favorite';
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'limit' parameter
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
if (limitErr) return rej('invalid limit param');
// Get 'sinceId' parameter
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).get();
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
if (sinceIdErr) return rej('invalid sinceId param');
// Get 'untilId' parameter
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).get();
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
if (untilIdErr) return rej('invalid untilId param');
// Check if both of sinceId and untilId is specified

View file

@ -14,27 +14,27 @@ import read from '../../common/read-notification';
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'following' parameter
const [following = false, followingError] =
$(params.following).optional.boolean().get();
$.bool.optional().get(params.following);
if (followingError) return rej('invalid following param');
// Get 'markAsRead' parameter
const [markAsRead = true, markAsReadErr] = $(params.markAsRead).optional.boolean().get();
const [markAsRead = true, markAsReadErr] = $.bool.optional().get(params.markAsRead);
if (markAsReadErr) return rej('invalid markAsRead param');
// Get 'type' parameter
const [type, typeErr] = $(params.type).optional.array($().string()).unique().get();
const [type, typeErr] = $.arr($.str).optional().unique().get(params.type);
if (typeErr) return rej('invalid type param');
// Get 'limit' parameter
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
if (limitErr) return rej('invalid limit param');
// Get 'sinceId' parameter
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).get();
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
if (sinceIdErr) return rej('invalid sinceId param');
// Get 'untilId' parameter
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).get();
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
if (untilIdErr) return rej('invalid untilId param');
// Check if both of sinceId and untilId is specified

View file

@ -11,7 +11,7 @@ import { pack } from '../../../../models/user';
*/
module.exports = async (params, user) => new Promise(async (res, rej) => {
// Get 'noteId' parameter
const [noteId, noteIdErr] = $(params.noteId).type(ID).get();
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
if (noteIdErr) return rej('invalid noteId param');
// Fetch pinee

View file

@ -12,7 +12,7 @@ import generateUserToken from '../../common/generate-native-user-token';
*/
module.exports = async (params, user) => new Promise(async (res, rej) => {
// Get 'password' parameter
const [password, passwordErr] = $(params.password).string().get();
const [password, passwordErr] = $.str.get(params.password);
if (passwordErr) return rej('invalid password param');
// Compare password

View file

@ -9,15 +9,15 @@ import Signin, { pack } from '../../../../models/signin';
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'limit' parameter
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
if (limitErr) return rej('invalid limit param');
// Get 'sinceId' parameter
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).get();
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
if (sinceIdErr) return rej('invalid sinceId param');
// Get 'untilId' parameter
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).get();
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
if (untilIdErr) return rej('invalid untilId param');
// Check if both of sinceId and untilId is specified

View file

@ -12,42 +12,42 @@ module.exports = async (params, user, app) => new Promise(async (res, rej) => {
const isSecure = user != null && app == null;
// Get 'name' parameter
const [name, nameErr] = $(params.name).optional.nullable.string().pipe(isValidName).get();
const [name, nameErr] = $.str.optional().nullable().pipe(isValidName).get(params.name);
if (nameErr) return rej('invalid name param');
if (name) user.name = name;
// Get 'description' parameter
const [description, descriptionErr] = $(params.description).optional.nullable.string().pipe(isValidDescription).get();
const [description, descriptionErr] = $.str.optional().nullable().pipe(isValidDescription).get(params.description);
if (descriptionErr) return rej('invalid description param');
if (description !== undefined) user.description = description;
// Get 'location' parameter
const [location, locationErr] = $(params.location).optional.nullable.string().pipe(isValidLocation).get();
const [location, locationErr] = $.str.optional().nullable().pipe(isValidLocation).get(params.location);
if (locationErr) return rej('invalid location param');
if (location !== undefined) user.profile.location = location;
// Get 'birthday' parameter
const [birthday, birthdayErr] = $(params.birthday).optional.nullable.string().pipe(isValidBirthday).get();
const [birthday, birthdayErr] = $.str.optional().nullable().pipe(isValidBirthday).get(params.birthday);
if (birthdayErr) return rej('invalid birthday param');
if (birthday !== undefined) user.profile.birthday = birthday;
// Get 'avatarId' parameter
const [avatarId, avatarIdErr] = $(params.avatarId).optional.type(ID).get();
const [avatarId, avatarIdErr] = $.type(ID).optional().get(params.avatarId);
if (avatarIdErr) return rej('invalid avatarId param');
if (avatarId) user.avatarId = avatarId;
// Get 'bannerId' parameter
const [bannerId, bannerIdErr] = $(params.bannerId).optional.type(ID).get();
const [bannerId, bannerIdErr] = $.type(ID).optional().get(params.bannerId);
if (bannerIdErr) return rej('invalid bannerId param');
if (bannerId) user.bannerId = bannerId;
// Get 'isBot' parameter
const [isBot, isBotErr] = $(params.isBot).optional.boolean().get();
const [isBot, isBotErr] = $.bool.optional().get(params.isBot);
if (isBotErr) return rej('invalid isBot param');
if (isBot != null) user.isBot = isBot;
// Get 'autoWatch' parameter
const [autoWatch, autoWatchErr] = $(params.autoWatch).optional.boolean().get();
const [autoWatch, autoWatchErr] = $.bool.optional().get(params.autoWatch);
if (autoWatchErr) return rej('invalid autoWatch param');
if (autoWatch != null) user.settings.autoWatch = autoWatch;

View file

@ -2,7 +2,7 @@
* Module dependencies
*/
import $ from 'cafy';
import User, { pack } from '../../../../models/user';
import User from '../../../../models/user';
import event from '../../../../publishers/stream';
/**
@ -10,11 +10,11 @@ import event from '../../../../publishers/stream';
*/
module.exports = async (params, user) => new Promise(async (res, rej) => {
// Get 'name' parameter
const [name, nameErr] = $(params.name).string().get();
const [name, nameErr] = $.str.get(params.name);
if (nameErr) return rej('invalid name param');
// Get 'value' parameter
const [value, valueErr] = $(params.value).nullable.any().get();
const [value, valueErr] = $.any.nullable().get(params.value);
if (valueErr) return rej('invalid value param');
const x = {};

View file

@ -7,20 +7,22 @@ import event from '../../../../publishers/stream';
module.exports = async (params, user) => new Promise(async (res, rej) => {
// Get 'home' parameter
const [home, homeErr] = $(params.home).optional.array().each(
$().object(true)
.have('name', $().string())
.have('id', $().string())
.have('place', $().string())
.have('data', $().object())).get();
const [home, homeErr] = $.arr(
$.obj.strict()
.have('name', $.str)
.have('id', $.str)
.have('place', $.str)
.have('data', $.obj))
.optional()
.get(params.home);
if (homeErr) return rej('invalid home param');
// Get 'id' parameter
const [id, idErr] = $(params.id).optional.string().get();
const [id, idErr] = $.str.optional().get(params.id);
if (idErr) return rej('invalid id param');
// Get 'data' parameter
const [data, dataErr] = $(params.data).optional.object().get();
const [data, dataErr] = $.obj.optional().get(params.data);
if (dataErr) return rej('invalid data param');
if (home) {

View file

@ -7,19 +7,20 @@ import event from '../../../../publishers/stream';
module.exports = async (params, user) => new Promise(async (res, rej) => {
// Get 'home' parameter
const [home, homeErr] = $(params.home).optional.array().each(
$().object(true)
.have('name', $().string())
.have('id', $().string())
.have('data', $().object())).get();
const [home, homeErr] = $.arr(
$.obj.strict()
.have('name', $.str)
.have('id', $.str)
.have('data', $.obj))
.optional().get(params.home);
if (homeErr) return rej('invalid home param');
// Get 'id' parameter
const [id, idErr] = $(params.id).optional.string().get();
const [id, idErr] = $.str.optional().get(params.id);
if (idErr) return rej('invalid id param');
// Get 'data' parameter
const [data, dataErr] = $(params.data).optional.object().get();
const [data, dataErr] = $.obj.optional().get(params.data);
if (dataErr) return rej('invalid data param');
if (home) {

View file

@ -11,7 +11,7 @@ import { pack } from '../../../../models/messaging-message';
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'limit' parameter
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
if (limitErr) return rej('invalid limit param');
const mute = await Mute.find({

View file

@ -16,7 +16,7 @@ import read from '../../common/read-messaging-message';
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'userId' parameter
const [recipientId, recipientIdErr] = $(params.userId).type(ID).get();
const [recipientId, recipientIdErr] = $.type(ID).get(params.userId);
if (recipientIdErr) return rej('invalid userId param');
// Fetch recipient
@ -33,19 +33,19 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
}
// Get 'markAsRead' parameter
const [markAsRead = true, markAsReadErr] = $(params.markAsRead).optional.boolean().get();
const [markAsRead = true, markAsReadErr] = $.bool.optional().get(params.markAsRead);
if (markAsReadErr) return rej('invalid markAsRead param');
// Get 'limit' parameter
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
if (limitErr) return rej('invalid limit param');
// Get 'sinceId' parameter
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).get();
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
if (sinceIdErr) return rej('invalid sinceId param');
// Get 'untilId' parameter
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).get();
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
if (untilIdErr) return rej('invalid untilId param');
// Check if both of sinceId and untilId is specified

View file

@ -19,7 +19,7 @@ import config from '../../../../../config';
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'userId' parameter
const [recipientId, recipientIdErr] = $(params.userId).type(ID).get();
const [recipientId, recipientIdErr] = $.type(ID).get(params.userId);
if (recipientIdErr) return rej('invalid userId param');
// Myself
@ -41,11 +41,11 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
}
// Get 'text' parameter
const [text, textErr] = $(params.text).optional.string().pipe(isValidText).get();
const [text, textErr] = $.str.optional().pipe(isValidText).get(params.text);
if (textErr) return rej('invalid text');
// Get 'fileId' parameter
const [fileId, fileIdErr] = $(params.fileId).optional.type(ID).get();
const [fileId, fileIdErr] = $.type(ID).optional().get(params.fileId);
if (fileIdErr) return rej('invalid fileId param');
let file = null;

View file

@ -12,7 +12,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
const muter = user;
// Get 'userId' parameter
const [userId, userIdErr] = $(params.userId).type(ID).get();
const [userId, userIdErr] = $.type(ID).get(params.userId);
if (userIdErr) return rej('invalid userId param');
// 自分自身

View file

@ -12,7 +12,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
const muter = user;
// Get 'userId' parameter
const [userId, userIdErr] = $(params.userId).type(ID).get();
const [userId, userIdErr] = $.type(ID).get(params.userId);
if (userIdErr) return rej('invalid userId param');
// Check if the mutee is yourself

View file

@ -11,15 +11,15 @@ import { getFriendIds } from '../../common/get-friends';
*/
module.exports = (params, me) => new Promise(async (res, rej) => {
// Get 'iknow' parameter
const [iknow = false, iknowErr] = $(params.iknow).optional.boolean().get();
const [iknow = false, iknowErr] = $.bool.optional().get(params.iknow);
if (iknowErr) return rej('invalid iknow param');
// Get 'limit' parameter
const [limit = 30, limitErr] = $(params.limit).optional.number().range(1, 100).get();
const [limit = 30, limitErr] = $.num.optional().range(1, 100).get(params.limit);
if (limitErr) return rej('invalid limit param');
// Get 'cursor' parameter
const [cursor = null, cursorErr] = $(params.cursor).optional.type(ID).get();
const [cursor = null, cursorErr] = $.type(ID).optional().get(params.cursor);
if (cursorErr) return rej('invalid cursor param');
// Construct query

View file

@ -9,11 +9,11 @@ import App, { pack } from '../../../../models/app';
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'limit' parameter
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
if (limitErr) return rej('invalid limit param');
// Get 'offset' parameter
const [offset = 0, offsetErr] = $(params.offset).optional.number().min(0).get();
const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset);
if (offsetErr) return rej('invalid offset param');
const query = {

View file

@ -9,35 +9,35 @@ import Note, { pack } from '../../../models/note';
*/
module.exports = (params) => new Promise(async (res, rej) => {
// Get 'reply' parameter
const [reply, replyErr] = $(params.reply).optional.boolean().get();
const [reply, replyErr] = $.bool.optional().get(params.reply);
if (replyErr) return rej('invalid reply param');
// Get 'renote' parameter
const [renote, renoteErr] = $(params.renote).optional.boolean().get();
const [renote, renoteErr] = $.bool.optional().get(params.renote);
if (renoteErr) return rej('invalid renote param');
// Get 'media' parameter
const [media, mediaErr] = $(params.media).optional.boolean().get();
const [media, mediaErr] = $.bool.optional().get(params.media);
if (mediaErr) return rej('invalid media param');
// Get 'poll' parameter
const [poll, pollErr] = $(params.poll).optional.boolean().get();
const [poll, pollErr] = $.bool.optional().get(params.poll);
if (pollErr) return rej('invalid poll param');
// Get 'bot' parameter
//const [bot, botErr] = $(params.bot).optional.boolean().get();
//const [bot, botErr] = $.bool.optional().get(params.bot);
//if (botErr) return rej('invalid bot param');
// Get 'limit' parameter
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
if (limitErr) return rej('invalid limit param');
// Get 'sinceId' parameter
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).get();
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
if (sinceIdErr) return rej('invalid sinceId param');
// Get 'untilId' parameter
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).get();
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
if (untilIdErr) return rej('invalid untilId param');
// Check if both of sinceId and untilId is specified

View file

@ -13,15 +13,15 @@ import Note, { pack } from '../../../../models/note';
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'noteId' parameter
const [noteId, noteIdErr] = $(params.noteId).type(ID).get();
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
if (noteIdErr) return rej('invalid noteId param');
// Get 'limit' parameter
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
if (limitErr) return rej('invalid limit param');
// Get 'offset' parameter
const [offset = 0, offsetErr] = $(params.offset).optional.number().min(0).get();
const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset);
if (offsetErr) return rej('invalid offset param');
// Lookup note

View file

@ -14,11 +14,11 @@ import { IApp } from '../../../../models/app';
*/
module.exports = (params, user: ILocalUser, app: IApp) => new Promise(async (res, rej) => {
// Get 'visibility' parameter
const [visibility = 'public', visibilityErr] = $(params.visibility).optional.string().or(['public', 'home', 'followers', 'specified', 'private']).get();
const [visibility = 'public', visibilityErr] = $.str.optional().or(['public', 'home', 'followers', 'specified', 'private']).get(params.visibility);
if (visibilityErr) return rej('invalid visibility');
// Get 'visibleUserIds' parameter
const [visibleUserIds, visibleUserIdsErr] = $(params.visibleUserIds).optional.array($().type(ID)).unique().min(1).get();
const [visibleUserIds, visibleUserIdsErr] = $.arr($.type(ID)).optional().unique().min(1).get(params.visibleUserIds);
if (visibleUserIdsErr) return rej('invalid visibleUserIds');
let visibleUsers = [];
@ -29,36 +29,36 @@ module.exports = (params, user: ILocalUser, app: IApp) => new Promise(async (res
}
// Get 'text' parameter
const [text = null, textErr] = $(params.text).optional.nullable.string().pipe(isValidText).get();
const [text = null, textErr] = $.str.optional().nullable().pipe(isValidText).get(params.text);
if (textErr) return rej('invalid text');
// Get 'cw' parameter
const [cw, cwErr] = $(params.cw).optional.nullable.string().pipe(isValidCw).get();
const [cw, cwErr] = $.str.optional().nullable().pipe(isValidCw).get(params.cw);
if (cwErr) return rej('invalid cw');
// Get 'viaMobile' parameter
const [viaMobile = false, viaMobileErr] = $(params.viaMobile).optional.boolean().get();
const [viaMobile = false, viaMobileErr] = $.bool.optional().get(params.viaMobile);
if (viaMobileErr) return rej('invalid viaMobile');
// Get 'tags' parameter
const [tags = [], tagsErr] = $(params.tags).optional.array($().string().range(1, 32)).unique().get();
const [tags = [], tagsErr] = $.arr($.str.optional().range(1, 32)).unique().get(params.tags);
if (tagsErr) return rej('invalid tags');
// Get 'geo' parameter
const [geo, geoErr] = $(params.geo).optional.nullable.object(true)
.have('coordinates', $().array().length(2)
.item(0, $().number().range(-180, 180))
.item(1, $().number().range(-90, 90)))
.have('altitude', $().nullable.number())
.have('accuracy', $().nullable.number())
.have('altitudeAccuracy', $().nullable.number())
.have('heading', $().nullable.number().range(0, 360))
.have('speed', $().nullable.number())
.get();
const [geo, geoErr] = $.obj.optional().nullable().strict()
.have('coordinates', $.arr().length(2)
.item(0, $.num.range(-180, 180))
.item(1, $.num.range(-90, 90)))
.have('altitude', $.num.nullable())
.have('accuracy', $.num.nullable())
.have('altitudeAccuracy', $.num.nullable())
.have('heading', $.num.nullable().range(0, 360))
.have('speed', $.num.nullable())
.get(params.geo);
if (geoErr) return rej('invalid geo');
// Get 'mediaIds' parameter
const [mediaIds, mediaIdsErr] = $(params.mediaIds).optional.array($().type(ID)).unique().range(1, 4).get();
const [mediaIds, mediaIdsErr] = $.arr($.type(ID)).optional().unique().range(1, 4).get(params.mediaIds);
if (mediaIdsErr) return rej('invalid mediaIds');
let files = [];
@ -85,7 +85,7 @@ module.exports = (params, user: ILocalUser, app: IApp) => new Promise(async (res
}
// Get 'renoteId' parameter
const [renoteId, renoteIdErr] = $(params.renoteId).optional.type(ID).get();
const [renoteId, renoteIdErr] = $.type(ID).optional().get(params.renoteId);
if (renoteIdErr) return rej('invalid renoteId');
let renote: INote = null;
@ -106,7 +106,7 @@ module.exports = (params, user: ILocalUser, app: IApp) => new Promise(async (res
}
// Get 'replyId' parameter
const [replyId, replyIdErr] = $(params.replyId).optional.type(ID).get();
const [replyId, replyIdErr] = $.type(ID).optional().get(params.replyId);
if (replyIdErr) return rej('invalid replyId');
let reply: INote = null;
@ -127,7 +127,7 @@ module.exports = (params, user: ILocalUser, app: IApp) => new Promise(async (res
}
// Get 'channelId' parameter
const [channelId, channelIdErr] = $(params.channelId).optional.type(ID).get();
const [channelId, channelIdErr] = $.type(ID).optional().get(params.channelId);
if (channelIdErr) return rej('invalid channelId');
let channel: IChannel = null;
@ -168,12 +168,12 @@ module.exports = (params, user: ILocalUser, app: IApp) => new Promise(async (res
}
// Get 'poll' parameter
const [poll, pollErr] = $(params.poll).optional.object(true)
.have('choices', $().array($().string())
const [poll, pollErr] = $.obj.optional().strict()
.have('choices', $.arr($.str)
.unique()
.range(2, 10)
.each(c => c.length > 0 && c.length < 50))
.get();
.get(params.poll);
if (pollErr) return rej('invalid poll');
if (poll) {

View file

@ -10,7 +10,7 @@ import Note from '../../../../../models/note';
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'noteId' parameter
const [noteId, noteIdErr] = $(params.noteId).type(ID).get();
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
if (noteIdErr) return rej('invalid noteId param');
// Get favoritee

View file

@ -10,7 +10,7 @@ import Note from '../../../../../models/note';
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'noteId' parameter
const [noteId, noteIdErr] = $(params.noteId).type(ID).get();
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
if (noteIdErr) return rej('invalid noteId param');
// Get favoritee

View file

@ -11,23 +11,23 @@ import { pack } from '../../../../models/note';
*/
module.exports = async (params, user, app) => {
// Get 'limit' parameter
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
if (limitErr) throw 'invalid limit param';
// Get 'sinceId' parameter
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).get();
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
if (sinceIdErr) throw 'invalid sinceId param';
// Get 'untilId' parameter
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).get();
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
if (untilIdErr) throw 'invalid untilId param';
// Get 'sinceDate' parameter
const [sinceDate, sinceDateErr] = $(params.sinceDate).optional.number().get();
const [sinceDate, sinceDateErr] = $.num.optional().get(params.sinceDate);
if (sinceDateErr) throw 'invalid sinceDate param';
// Get 'untilDate' parameter
const [untilDate, untilDateErr] = $(params.untilDate).optional.number().get();
const [untilDate, untilDateErr] = $.num.optional().get(params.untilDate);
if (untilDateErr) throw 'invalid untilDate param';
// Check if only one of sinceId, untilId, sinceDate, untilDate specified

View file

@ -11,23 +11,23 @@ import { pack } from '../../../../models/note';
*/
module.exports = async (params, user, app) => {
// Get 'limit' parameter
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
if (limitErr) throw 'invalid limit param';
// Get 'sinceId' parameter
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).get();
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
if (sinceIdErr) throw 'invalid sinceId param';
// Get 'untilId' parameter
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).get();
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
if (untilIdErr) throw 'invalid untilId param';
// Get 'sinceDate' parameter
const [sinceDate, sinceDateErr] = $(params.sinceDate).optional.number().get();
const [sinceDate, sinceDateErr] = $.num.optional().get(params.sinceDate);
if (sinceDateErr) throw 'invalid sinceDate param';
// Get 'untilDate' parameter
const [untilDate, untilDateErr] = $(params.untilDate).optional.number().get();
const [untilDate, untilDateErr] = $.num.optional().get(params.untilDate);
if (untilDateErr) throw 'invalid untilDate param';
// Check if only one of sinceId, untilId, sinceDate, untilDate specified

View file

@ -16,19 +16,19 @@ import { pack } from '../../../../models/note';
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'following' parameter
const [following = false, followingError] =
$(params.following).optional.boolean().get();
$.bool.optional().get(params.following);
if (followingError) return rej('invalid following param');
// Get 'limit' parameter
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
if (limitErr) return rej('invalid limit param');
// Get 'sinceId' parameter
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).get();
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
if (sinceIdErr) return rej('invalid sinceId param');
// Get 'untilId' parameter
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).get();
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
if (untilIdErr) return rej('invalid untilId param');
// Check if both of sinceId and untilId is specified

View file

@ -10,11 +10,11 @@ import Note, { pack } from '../../../../../models/note';
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'limit' parameter
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
if (limitErr) return rej('invalid limit param');
// Get 'offset' parameter
const [offset = 0, offsetErr] = $(params.offset).optional.number().min(0).get();
const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset);
if (offsetErr) return rej('invalid offset param');
// Get votes

View file

@ -14,7 +14,7 @@ import notify from '../../../../../publishers/notify';
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'noteId' parameter
const [noteId, noteIdErr] = $(params.noteId).type(ID).get();
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
if (noteIdErr) return rej('invalid noteId param');
// Get votee
@ -32,9 +32,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'choice' parameter
const [choice, choiceError] =
$(params.choice).number()
$.num
.pipe(c => note.poll.choices.some(x => x.id == c))
.get();
.get(params.choice);
if (choiceError) return rej('invalid choice param');
// if already voted

View file

@ -14,19 +14,19 @@ import Reaction, { pack } from '../../../../models/note-reaction';
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'noteId' parameter
const [noteId, noteIdErr] = $(params.noteId).type(ID).get();
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
if (noteIdErr) return rej('invalid noteId param');
// Get 'limit' parameter
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
if (limitErr) return rej('invalid limit param');
// Get 'offset' parameter
const [offset = 0, offsetErr] = $(params.offset).optional.number().min(0).get();
const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset);
if (offsetErr) return rej('invalid offset param');
// Get 'sort' parameter
const [sort = 'desc', sortError] = $(params.sort).optional.string().or('desc asc').get();
const [sort = 'desc', sortError] = $.str.optional().or('desc asc').get(params.sort);
if (sortError) return rej('invalid sort param');
// Lookup note

View file

@ -11,11 +11,11 @@ import { validateReaction } from '../../../../../models/note-reaction';
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'noteId' parameter
const [noteId, noteIdErr] = $(params.noteId).type(ID).get();
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
if (noteIdErr) return rej('invalid noteId param');
// Get 'reaction' parameter
const [reaction, reactionErr] = $(params.reaction).string().pipe(validateReaction.ok).get();
const [reaction, reactionErr] = $.str.pipe(validateReaction.ok).get(params.reaction);
if (reactionErr) return rej('invalid reaction param');
// Fetch reactee

View file

@ -10,7 +10,7 @@ import Note from '../../../../../models/note';
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'noteId' parameter
const [noteId, noteIdErr] = $(params.noteId).type(ID).get();
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
if (noteIdErr) return rej('invalid noteId param');
// Fetch unreactee

View file

@ -13,19 +13,19 @@ import Note, { pack } from '../../../../models/note';
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'noteId' parameter
const [noteId, noteIdErr] = $(params.noteId).type(ID).get();
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
if (noteIdErr) return rej('invalid noteId param');
// Get 'limit' parameter
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
if (limitErr) return rej('invalid limit param');
// Get 'offset' parameter
const [offset = 0, offsetErr] = $(params.offset).optional.number().min(0).get();
const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset);
if (offsetErr) return rej('invalid offset param');
// Get 'sort' parameter
const [sort = 'desc', sortError] = $(params.sort).optional.string().or('desc asc').get();
const [sort = 'desc', sortError] = $.str.optional().or('desc asc').get(params.sort);
if (sortError) return rej('invalid sort param');
// Lookup note

View file

@ -13,19 +13,19 @@ import Note, { pack } from '../../../../models/note';
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'noteId' parameter
const [noteId, noteIdErr] = $(params.noteId).type(ID).get();
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
if (noteIdErr) return rej('invalid noteId param');
// Get 'limit' parameter
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
if (limitErr) return rej('invalid limit param');
// Get 'sinceId' parameter
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).get();
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
if (sinceIdErr) return rej('invalid sinceId param');
// Get 'untilId' parameter
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).get();
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
if (untilIdErr) return rej('invalid untilId param');
// Check if both of sinceId and untilId is specified

View file

@ -18,63 +18,63 @@ import { pack } from '../../../../models/note';
*/
module.exports = (params, me) => new Promise(async (res, rej) => {
// Get 'text' parameter
const [text, textError] = $(params.text).optional.string().get();
const [text, textError] = $.str.optional().get(params.text);
if (textError) return rej('invalid text param');
// Get 'includeUserIds' parameter
const [includeUserIds = [], includeUserIdsErr] = $(params.includeUserIds).optional.array($().type(ID)).get();
const [includeUserIds = [], includeUserIdsErr] = $.arr($.type(ID)).optional().get(params.includeUserIds);
if (includeUserIdsErr) return rej('invalid includeUserIds param');
// Get 'excludeUserIds' parameter
const [excludeUserIds = [], excludeUserIdsErr] = $(params.excludeUserIds).optional.array($().type(ID)).get();
const [excludeUserIds = [], excludeUserIdsErr] = $.arr($.type(ID)).optional().get(params.excludeUserIds);
if (excludeUserIdsErr) return rej('invalid excludeUserIds param');
// Get 'includeUserUsernames' parameter
const [includeUserUsernames = [], includeUserUsernamesErr] = $(params.includeUserUsernames).optional.array($().string()).get();
const [includeUserUsernames = [], includeUserUsernamesErr] = $.arr($.str).optional().get(params.includeUserUsernames);
if (includeUserUsernamesErr) return rej('invalid includeUserUsernames param');
// Get 'excludeUserUsernames' parameter
const [excludeUserUsernames = [], excludeUserUsernamesErr] = $(params.excludeUserUsernames).optional.array($().string()).get();
const [excludeUserUsernames = [], excludeUserUsernamesErr] = $.arr($.str).optional().get(params.excludeUserUsernames);
if (excludeUserUsernamesErr) return rej('invalid excludeUserUsernames param');
// Get 'following' parameter
const [following = null, followingErr] = $(params.following).optional.nullable.boolean().get();
const [following = null, followingErr] = $.bool.optional().nullable().get(params.following);
if (followingErr) return rej('invalid following param');
// Get 'mute' parameter
const [mute = 'mute_all', muteErr] = $(params.mute).optional.string().get();
const [mute = 'mute_all', muteErr] = $.str.optional().get(params.mute);
if (muteErr) return rej('invalid mute param');
// Get 'reply' parameter
const [reply = null, replyErr] = $(params.reply).optional.nullable.boolean().get();
const [reply = null, replyErr] = $.bool.optional().nullable().get(params.reply);
if (replyErr) return rej('invalid reply param');
// Get 'renote' parameter
const [renote = null, renoteErr] = $(params.renote).optional.nullable.boolean().get();
const [renote = null, renoteErr] = $.bool.optional().nullable().get(params.renote);
if (renoteErr) return rej('invalid renote param');
// Get 'media' parameter
const [media = null, mediaErr] = $(params.media).optional.nullable.boolean().get();
const [media = null, mediaErr] = $.bool.optional().nullable().get(params.media);
if (mediaErr) return rej('invalid media param');
// Get 'poll' parameter
const [poll = null, pollErr] = $(params.poll).optional.nullable.boolean().get();
const [poll = null, pollErr] = $.bool.optional().nullable().get(params.poll);
if (pollErr) return rej('invalid poll param');
// Get 'sinceDate' parameter
const [sinceDate, sinceDateErr] = $(params.sinceDate).optional.number().get();
const [sinceDate, sinceDateErr] = $.num.optional().get(params.sinceDate);
if (sinceDateErr) throw 'invalid sinceDate param';
// Get 'untilDate' parameter
const [untilDate, untilDateErr] = $(params.untilDate).optional.number().get();
const [untilDate, untilDateErr] = $.num.optional().get(params.untilDate);
if (untilDateErr) throw 'invalid untilDate param';
// Get 'offset' parameter
const [offset = 0, offsetErr] = $(params.offset).optional.number().min(0).get();
const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset);
if (offsetErr) return rej('invalid offset param');
// Get 'limit' parameter
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 30).get();
const [limit = 10, limitErr] = $.num.optional().range(1, 30).get(params.limit);
if (limitErr) return rej('invalid limit param');
let includeUsers = includeUserIds;

View file

@ -13,7 +13,7 @@ import Note, { pack } from '../../../../models/note';
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'noteId' parameter
const [noteId, noteIdErr] = $(params.noteId).type(ID).get();
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
if (noteIdErr) return rej('invalid noteId param');
// Get note

View file

@ -13,23 +13,23 @@ import { pack } from '../../../../models/note';
*/
module.exports = async (params, user, app) => {
// Get 'limit' parameter
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
if (limitErr) throw 'invalid limit param';
// Get 'sinceId' parameter
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).get();
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
if (sinceIdErr) throw 'invalid sinceId param';
// Get 'untilId' parameter
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).get();
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
if (untilIdErr) throw 'invalid untilId param';
// Get 'sinceDate' parameter
const [sinceDate, sinceDateErr] = $(params.sinceDate).optional.number().get();
const [sinceDate, sinceDateErr] = $.num.optional().get(params.sinceDate);
if (sinceDateErr) throw 'invalid sinceDate param';
// Get 'untilDate' parameter
const [untilDate, untilDateErr] = $(params.untilDate).optional.number().get();
const [untilDate, untilDateErr] = $.num.optional().get(params.untilDate);
if (untilDateErr) throw 'invalid untilDate param';
// Check if only one of sinceId, untilId, sinceDate, untilDate specified
@ -38,11 +38,11 @@ module.exports = async (params, user, app) => {
}
// Get 'includeMyRenotes' parameter
const [includeMyRenotes = true, includeMyRenotesErr] = $(params.includeMyRenotes).optional.boolean().get();
const [includeMyRenotes = true, includeMyRenotesErr] = $.bool.optional().get(params.includeMyRenotes);
if (includeMyRenotesErr) throw 'invalid includeMyRenotes param';
// Get 'includeRenotedMyNotes' parameter
const [includeRenotedMyNotes = true, includeRenotedMyNotesErr] = $(params.includeRenotedMyNotes).optional.boolean().get();
const [includeRenotedMyNotes = true, includeRenotedMyNotesErr] = $.bool.optional().get(params.includeRenotedMyNotes);
if (includeRenotedMyNotesErr) throw 'invalid includeRenotedMyNotes param';
const [followings, watchingChannelIds, mutedUserIds] = await Promise.all([

View file

@ -14,27 +14,27 @@ import Note, { pack } from '../../../../models/note';
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'limit' parameter
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
if (limitErr) return rej('invalid limit param');
// Get 'offset' parameter
const [offset = 0, offsetErr] = $(params.offset).optional.number().min(0).get();
const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset);
if (offsetErr) return rej('invalid offset param');
// Get 'reply' parameter
const [reply, replyErr] = $(params.reply).optional.boolean().get();
const [reply, replyErr] = $.bool.optional().get(params.reply);
if (replyErr) return rej('invalid reply param');
// Get 'renote' parameter
const [renote, renoteErr] = $(params.renote).optional.boolean().get();
const [renote, renoteErr] = $.bool.optional().get(params.renote);
if (renoteErr) return rej('invalid renote param');
// Get 'media' parameter
const [media, mediaErr] = $(params.media).optional.boolean().get();
const [media, mediaErr] = $.bool.optional().get(params.media);
if (mediaErr) return rej('invalid media param');
// Get 'poll' parameter
const [poll, pollErr] = $(params.poll).optional.boolean().get();
const [poll, pollErr] = $.bool.optional().get(params.poll);
if (pollErr) return rej('invalid poll param');
const query = {

View file

@ -12,23 +12,23 @@ import UserList from '../../../../models/user-list';
*/
module.exports = async (params, user, app) => {
// Get 'limit' parameter
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
if (limitErr) throw 'invalid limit param';
// Get 'sinceId' parameter
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).get();
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
if (sinceIdErr) throw 'invalid sinceId param';
// Get 'untilId' parameter
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).get();
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
if (untilIdErr) throw 'invalid untilId param';
// Get 'sinceDate' parameter
const [sinceDate, sinceDateErr] = $(params.sinceDate).optional.number().get();
const [sinceDate, sinceDateErr] = $.num.optional().get(params.sinceDate);
if (sinceDateErr) throw 'invalid sinceDate param';
// Get 'untilDate' parameter
const [untilDate, untilDateErr] = $(params.untilDate).optional.number().get();
const [untilDate, untilDateErr] = $.num.optional().get(params.untilDate);
if (untilDateErr) throw 'invalid untilDate param';
// Check if only one of sinceId, untilId, sinceDate, untilDate specified
@ -37,15 +37,15 @@ module.exports = async (params, user, app) => {
}
// Get 'includeMyRenotes' parameter
const [includeMyRenotes = true, includeMyRenotesErr] = $(params.includeMyRenotes).optional.boolean().get();
const [includeMyRenotes = true, includeMyRenotesErr] = $.bool.optional().get(params.includeMyRenotes);
if (includeMyRenotesErr) throw 'invalid includeMyRenotes param';
// Get 'includeRenotedMyNotes' parameter
const [includeRenotedMyNotes = true, includeRenotedMyNotesErr] = $(params.includeRenotedMyNotes).optional.boolean().get();
const [includeRenotedMyNotes = true, includeRenotedMyNotesErr] = $.bool.optional().get(params.includeRenotedMyNotes);
if (includeRenotedMyNotesErr) throw 'invalid includeRenotedMyNotes param';
// Get 'listId' parameter
const [listId, listIdErr] = $(params.listId).type(ID).get();
const [listId, listIdErr] = $.type(ID).get(params.listId);
if (listIdErr) throw 'invalid listId param';
const [list, mutedUserIds] = await Promise.all([

View file

@ -3,19 +3,19 @@ import OthelloGame, { pack } from '../../../../models/othello-game';
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'my' parameter
const [my = false, myErr] = $(params.my).optional.boolean().get();
const [my = false, myErr] = $.bool.optional().get(params.my);
if (myErr) return rej('invalid my param');
// Get 'limit' parameter
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
if (limitErr) return rej('invalid limit param');
// Get 'sinceId' parameter
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).get();
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
if (sinceIdErr) return rej('invalid sinceId param');
// Get 'untilId' parameter
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).get();
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
if (untilIdErr) return rej('invalid untilId param');
// Check if both of sinceId and untilId is specified

View file

@ -4,7 +4,7 @@ import Othello from '../../../../../othello/core';
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'gameId' parameter
const [gameId, gameIdErr] = $(params.gameId).type(ID).get();
const [gameId, gameIdErr] = $.type(ID).get(params.gameId);
if (gameIdErr) return rej('invalid gameId param');
const game = await OthelloGame.findOne({ _id: gameId });

View file

@ -7,7 +7,7 @@ import { eighteight } from '../../../../othello/maps';
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'userId' parameter
const [childId, childIdErr] = $(params.userId).type(ID).get();
const [childId, childIdErr] = $.type(ID).get(params.userId);
if (childIdErr) return rej('invalid userId param');
// Myself

View file

@ -9,15 +9,15 @@ import Subscription from '../../../../models/sw-subscription';
*/
module.exports = async (params, user, app) => new Promise(async (res, rej) => {
// Get 'endpoint' parameter
const [endpoint, endpointErr] = $(params.endpoint).string().get();
const [endpoint, endpointErr] = $.str.get(params.endpoint);
if (endpointErr) return rej('invalid endpoint param');
// Get 'auth' parameter
const [auth, authErr] = $(params.auth).string().get();
const [auth, authErr] = $.str.get(params.auth);
if (authErr) return rej('invalid auth param');
// Get 'publickey' parameter
const [publickey, publickeyErr] = $(params.publickey).string().get();
const [publickey, publickeyErr] = $.str.get(params.publickey);
if (publickeyErr) return rej('invalid publickey param');
// if already subscribed

View file

@ -13,7 +13,7 @@ import { validateUsername } from '../../../../models/user';
*/
module.exports = async (params) => new Promise(async (res, rej) => {
// Get 'username' parameter
const [username, usernameError] = $(params.username).string().pipe(validateUsername).get();
const [username, usernameError] = $.str.pipe(validateUsername).get(params.username);
if (usernameError) return rej('invalid username param');
// Get exist

View file

@ -9,15 +9,15 @@ import User, { pack } from '../../../models/user';
*/
module.exports = (params, me) => new Promise(async (res, rej) => {
// Get 'limit' parameter
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
if (limitErr) return rej('invalid limit param');
// Get 'offset' parameter
const [offset = 0, offsetErr] = $(params.offset).optional.number().min(0).get();
const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset);
if (offsetErr) return rej('invalid offset param');
// Get 'sort' parameter
const [sort, sortError] = $(params.sort).optional.string().or('+follower|-follower').get();
const [sort, sortError] = $.str.optional().or('+follower|-follower').get(params.sort);
if (sortError) return rej('invalid sort param');
// Construct query

View file

@ -12,19 +12,19 @@ import { getFriendIds } from '../../common/get-friends';
*/
module.exports = (params, me) => new Promise(async (res, rej) => {
// Get 'userId' parameter
const [userId, userIdErr] = $(params.userId).type(ID).get();
const [userId, userIdErr] = $.type(ID).get(params.userId);
if (userIdErr) return rej('invalid userId param');
// Get 'iknow' parameter
const [iknow = false, iknowErr] = $(params.iknow).optional.boolean().get();
const [iknow = false, iknowErr] = $.bool.optional().get(params.iknow);
if (iknowErr) return rej('invalid iknow param');
// Get 'limit' parameter
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
if (limitErr) return rej('invalid limit param');
// Get 'cursor' parameter
const [cursor = null, cursorErr] = $(params.cursor).optional.type(ID).get();
const [cursor = null, cursorErr] = $.type(ID).optional().get(params.cursor);
if (cursorErr) return rej('invalid cursor param');
// Lookup user

View file

@ -16,19 +16,19 @@ import { getFriendIds } from '../../common/get-friends';
*/
module.exports = (params, me) => new Promise(async (res, rej) => {
// Get 'userId' parameter
const [userId, userIdErr] = $(params.userId).type(ID).get();
const [userId, userIdErr] = $.type(ID).get(params.userId);
if (userIdErr) return rej('invalid userId param');
// Get 'iknow' parameter
const [iknow = false, iknowErr] = $(params.iknow).optional.boolean().get();
const [iknow = false, iknowErr] = $.bool.optional().get(params.iknow);
if (iknowErr) return rej('invalid iknow param');
// Get 'limit' parameter
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
if (limitErr) return rej('invalid limit param');
// Get 'cursor' parameter
const [cursor = null, cursorErr] = $(params.cursor).optional.type(ID).get();
const [cursor = null, cursorErr] = $.type(ID).optional().get(params.cursor);
if (cursorErr) return rej('invalid cursor param');
// Lookup user

View file

@ -7,11 +7,11 @@ import User, { pack } from '../../../../models/user';
module.exports = (params, me) => new Promise(async (res, rej) => {
// Get 'userId' parameter
const [userId, userIdErr] = $(params.userId).type(ID).get();
const [userId, userIdErr] = $.type(ID).get(params.userId);
if (userIdErr) return rej('invalid userId param');
// Get 'limit' parameter
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
if (limitErr) return rej('invalid limit param');
// Lookup user

View file

@ -9,7 +9,7 @@ import UserList, { pack } from '../../../../../models/user-list';
*/
module.exports = async (params, user) => new Promise(async (res, rej) => {
// Get 'title' parameter
const [title, titleErr] = $(params.title).string().range(1, 100).get();
const [title, titleErr] = $.str.range(1, 100).get(params.title);
if (titleErr) return rej('invalid title param');
// insert

View file

@ -11,7 +11,7 @@ import { deliver } from '../../../../../queue';
*/
module.exports = async (params, me) => new Promise(async (res, rej) => {
// Get 'listId' parameter
const [listId, listIdErr] = $(params.listId).type(ID).get();
const [listId, listIdErr] = $.type(ID).get(params.listId);
if (listIdErr) return rej('invalid listId param');
// Fetch the list
@ -25,7 +25,7 @@ module.exports = async (params, me) => new Promise(async (res, rej) => {
}
// Get 'userId' parameter
const [userId, userIdErr] = $(params.userId).type(ID).get();
const [userId, userIdErr] = $.type(ID).get(params.userId);
if (userIdErr) return rej('invalid userId param');
// Fetch the user

View file

@ -6,7 +6,7 @@ import UserList, { pack } from '../../../../../models/user-list';
*/
module.exports = async (params, me) => new Promise(async (res, rej) => {
// Get 'listId' parameter
const [listId, listIdErr] = $(params.listId).type(ID).get();
const [listId, listIdErr] = $.type(ID).get(params.listId);
if (listIdErr) return rej('invalid listId param');
// Fetch the list

View file

@ -11,11 +11,11 @@ import User from '../../../../models/user';
*/
module.exports = (params, me) => new Promise(async (res, rej) => {
// Get 'userId' parameter
const [userId, userIdErr] = $(params.userId).optional.type(ID).get();
const [userId, userIdErr] = $.type(ID).optional().get(params.userId);
if (userIdErr) return rej('invalid userId param');
// Get 'username' parameter
const [username, usernameErr] = $(params.username).optional.string().get();
const [username, usernameErr] = $.str.optional().get(params.username);
if (usernameErr) return rej('invalid username param');
if (userId === undefined && username === undefined) {
@ -23,7 +23,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
}
// Get 'host' parameter
const [host, hostErr] = $(params.host).optional.string().get();
const [host, hostErr] = $.str.optional().get(params.host);
if (hostErr) return rej('invalid host param');
if (userId === undefined && host === undefined) {
@ -31,31 +31,31 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
}
// Get 'includeReplies' parameter
const [includeReplies = true, includeRepliesErr] = $(params.includeReplies).optional.boolean().get();
const [includeReplies = true, includeRepliesErr] = $.bool.optional().get(params.includeReplies);
if (includeRepliesErr) return rej('invalid includeReplies param');
// Get 'withMedia' parameter
const [withMedia = false, withMediaErr] = $(params.withMedia).optional.boolean().get();
const [withMedia = false, withMediaErr] = $.bool.optional().get(params.withMedia);
if (withMediaErr) return rej('invalid withMedia param');
// Get 'limit' parameter
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
if (limitErr) return rej('invalid limit param');
// Get 'sinceId' parameter
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).get();
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
if (sinceIdErr) return rej('invalid sinceId param');
// Get 'untilId' parameter
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).get();
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
if (untilIdErr) return rej('invalid untilId param');
// Get 'sinceDate' parameter
const [sinceDate, sinceDateErr] = $(params.sinceDate).optional.number().get();
const [sinceDate, sinceDateErr] = $.num.optional().get(params.sinceDate);
if (sinceDateErr) throw 'invalid sinceDate param';
// Get 'untilDate' parameter
const [untilDate, untilDateErr] = $(params.untilDate).optional.number().get();
const [untilDate, untilDateErr] = $.num.optional().get(params.untilDate);
if (untilDateErr) throw 'invalid untilDate param';
// Check if only one of sinceId, untilId, sinceDate, untilDate specified

View file

@ -16,11 +16,11 @@ import Mute from '../../../../models/mute';
*/
module.exports = (params, me) => new Promise(async (res, rej) => {
// Get 'limit' parameter
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
if (limitErr) return rej('invalid limit param');
// Get 'offset' parameter
const [offset = 0, offsetErr] = $(params.offset).optional.number().min(0).get();
const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset);
if (offsetErr) return rej('invalid offset param');
// ID list of the user itself and other users who the user follows

View file

@ -16,15 +16,15 @@ const escapeRegexp = require('escape-regexp');
*/
module.exports = (params, me) => new Promise(async (res, rej) => {
// Get 'query' parameter
const [query, queryError] = $(params.query).string().pipe(x => x != '').get();
const [query, queryError] = $.str.pipe(x => x != '').get(params.query);
if (queryError) return rej('invalid query param');
// Get 'offset' parameter
const [offset = 0, offsetErr] = $(params.offset).optional.number().min(0).get();
const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset);
if (offsetErr) return rej('invalid offset param');
// Get 'max' parameter
const [max = 10, maxErr] = $(params.max).optional.number().range(1, 30).get();
const [max = 10, maxErr] = $.num.optional().range(1, 30).get(params.max);
if (maxErr) return rej('invalid max param');
// If Elasticsearch is available, search by $

View file

@ -9,15 +9,15 @@ import User, { pack } from '../../../../models/user';
*/
module.exports = (params, me) => new Promise(async (res, rej) => {
// Get 'query' parameter
const [query, queryError] = $(params.query).string().get();
const [query, queryError] = $.str.get(params.query);
if (queryError) return rej('invalid query param');
// Get 'offset' parameter
const [offset = 0, offsetErr] = $(params.offset).optional.number().min(0).get();
const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset);
if (offsetErr) return rej('invalid offset param');
// Get 'limit' parameter
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).get();
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
if (limitErr) return rej('invalid limit param');
const users = await User

View file

@ -14,19 +14,19 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
let user;
// Get 'userId' parameter
const [userId, userIdErr] = $(params.userId).optional.type(ID).get();
const [userId, userIdErr] = $.type(ID).optional().get(params.userId);
if (userIdErr) return rej('invalid userId param');
// Get 'userIds' parameter
const [userIds, userIdsErr] = $(params.userIds).optional.array($().type(ID)).get();
const [userIds, userIdsErr] = $.arr($.type(ID)).optional().get(params.userIds);
if (userIdsErr) return rej('invalid userIds param');
// Get 'username' parameter
const [username, usernameErr] = $(params.username).optional.string().get();
const [username, usernameErr] = $.str.optional().get(params.username);
if (usernameErr) return rej('invalid username param');
// Get 'host' parameter
const [host, hostErr] = $(params.host).nullable.optional.string().get();
const [host, hostErr] = $.str.optional().nullable().get(params.host);
if (hostErr) return rej('invalid host param');
if (userIds) {