mirror of
https://iceshrimp.dev/crimekillz/iceshrimp-161sh.git
synced 2024-11-22 12:13:48 +01:00
Use cafy
This commit is contained in:
parent
a2b1948d6b
commit
61142e2ae5
@ -66,6 +66,7 @@
|
||||
"autwh": "0.0.1",
|
||||
"bcryptjs": "2.4.3",
|
||||
"body-parser": "1.17.0",
|
||||
"cafy": "1.0.0",
|
||||
"chai": "3.5.0",
|
||||
"chai-http": "3.0.0",
|
||||
"chalk": "1.1.3",
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../../it';
|
||||
import it from 'cafy';
|
||||
import Post from '../../../models/post';
|
||||
import Like from '../../../models/like';
|
||||
|
||||
@ -13,7 +13,7 @@ import Like from '../../../models/like';
|
||||
*/
|
||||
module.exports = (params) => new Promise(async (res, rej) => {
|
||||
// Get 'post_id' parameter
|
||||
const [postId, postIdErr] = it(params.post_id).expect.id().required().qed();
|
||||
const [postId, postIdErr] = it(params.post_id).expect.id().required().get();
|
||||
if (postIdErr) return rej('invalid post_id param');
|
||||
|
||||
// Lookup post
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../../it';
|
||||
import it from 'cafy';
|
||||
import Post from '../../../models/post';
|
||||
import Like from '../../../models/like';
|
||||
|
||||
@ -13,7 +13,7 @@ import Like from '../../../models/like';
|
||||
*/
|
||||
module.exports = (params) => new Promise(async (res, rej) => {
|
||||
// Get 'post_id' parameter
|
||||
const [postId, postIdErr] = it(params.post_id).expect.id().required().qed();
|
||||
const [postId, postIdErr] = it(params.post_id).expect.id().required().get();
|
||||
if (postIdErr) return rej('invalid post_id param');
|
||||
|
||||
// Lookup post
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../../it';
|
||||
import it from 'cafy';
|
||||
import Post from '../../../models/post';
|
||||
|
||||
/**
|
||||
@ -12,7 +12,7 @@ import Post from '../../../models/post';
|
||||
*/
|
||||
module.exports = (params) => new Promise(async (res, rej) => {
|
||||
// Get 'post_id' parameter
|
||||
const [postId, postIdErr] = it(params.post_id).expect.id().required().qed();
|
||||
const [postId, postIdErr] = it(params.post_id).expect.id().required().get();
|
||||
if (postIdErr) return rej('invalid post_id param');
|
||||
|
||||
// Lookup post
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../../it';
|
||||
import it from 'cafy';
|
||||
import Post from '../../../models/post';
|
||||
|
||||
/**
|
||||
@ -12,7 +12,7 @@ import Post from '../../../models/post';
|
||||
*/
|
||||
module.exports = (params) => new Promise(async (res, rej) => {
|
||||
// Get 'post_id' parameter
|
||||
const [postId, postIdErr] = it(params.post_id).expect.id().required().qed();
|
||||
const [postId, postIdErr] = it(params.post_id).expect.id().required().get();
|
||||
if (postIdErr) return rej('invalid post_id param');
|
||||
|
||||
// Lookup post
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../../it';
|
||||
import it from 'cafy';
|
||||
import User from '../../../models/user';
|
||||
import Following from '../../../models/following';
|
||||
|
||||
@ -13,7 +13,7 @@ import Following from '../../../models/following';
|
||||
*/
|
||||
module.exports = (params) => new Promise(async (res, rej) => {
|
||||
// Get 'user_id' parameter
|
||||
const [userId, userIdErr] = it(params.user_id).expect.id().required().qed();
|
||||
const [userId, userIdErr] = it(params.user_id).expect.id().required().get();
|
||||
if (userIdErr) return rej('invalid user_id param');
|
||||
|
||||
// Lookup user
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../../it';
|
||||
import it from 'cafy';
|
||||
import User from '../../../models/user';
|
||||
import Following from '../../../models/following';
|
||||
|
||||
@ -13,7 +13,7 @@ import Following from '../../../models/following';
|
||||
*/
|
||||
module.exports = (params) => new Promise(async (res, rej) => {
|
||||
// Get 'user_id' parameter
|
||||
const [userId, userIdErr] = it(params.user_id).expect.id().required().qed();
|
||||
const [userId, userIdErr] = it(params.user_id).expect.id().required().get();
|
||||
if (userIdErr) return rej('invalid user_id param');
|
||||
|
||||
// Lookup user
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../../it';
|
||||
import it from 'cafy';
|
||||
import User from '../../../models/user';
|
||||
import Like from '../../../models/like';
|
||||
|
||||
@ -13,7 +13,7 @@ import Like from '../../../models/like';
|
||||
*/
|
||||
module.exports = (params) => new Promise(async (res, rej) => {
|
||||
// Get 'user_id' parameter
|
||||
const [userId, userIdErr] = it(params.user_id).expect.id().required().qed();
|
||||
const [userId, userIdErr] = it(params.user_id).expect.id().required().get();
|
||||
if (userIdErr) return rej('invalid user_id param');
|
||||
|
||||
// Lookup user
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../../it';
|
||||
import it from 'cafy';
|
||||
import User from '../../../models/user';
|
||||
import Post from '../../../models/post';
|
||||
|
||||
@ -13,7 +13,7 @@ import Post from '../../../models/post';
|
||||
*/
|
||||
module.exports = (params) => new Promise(async (res, rej) => {
|
||||
// Get 'user_id' parameter
|
||||
const [userId, userIdErr] = it(params.user_id).expect.id().required().qed();
|
||||
const [userId, userIdErr] = it(params.user_id).expect.id().required().get();
|
||||
if (userIdErr) return rej('invalid user_id param');
|
||||
|
||||
// Lookup user
|
||||
|
@ -2,7 +2,7 @@
|
||||
* Module dependencies
|
||||
*/
|
||||
import rndstr from 'rndstr';
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
import App from '../../models/app';
|
||||
import { isValidNameId } from '../../models/app';
|
||||
import serialize from '../../serializers/app';
|
||||
@ -69,24 +69,24 @@ import serialize from '../../serializers/app';
|
||||
*/
|
||||
module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'name_id' parameter
|
||||
const [nameId, nameIdErr] = it(params.name_id).expect.string().required().validate(isValidNameId).qed();
|
||||
const [nameId, nameIdErr] = it(params.name_id).expect.string().required().validate(isValidNameId).get();
|
||||
if (nameIdErr) return rej('invalid name_id param');
|
||||
|
||||
// Get 'name' parameter
|
||||
const [name, nameErr] = it(params.name).expect.string().required().qed();
|
||||
const [name, nameErr] = it(params.name).expect.string().required().get();
|
||||
if (nameErr) return rej('invalid name param');
|
||||
|
||||
// Get 'description' parameter
|
||||
const [description, descriptionErr] = it(params.description).expect.string().required().qed();
|
||||
const [description, descriptionErr] = it(params.description).expect.string().required().get();
|
||||
if (descriptionErr) return rej('invalid description param');
|
||||
|
||||
// Get 'permission' parameter
|
||||
const [permission, permissionErr] = it(params.permission).expect.array().unique().allString().required().qed();
|
||||
const [permission, permissionErr] = it(params.permission).expect.array().unique().allString().required().get();
|
||||
if (permissionErr) return rej('invalid permission param');
|
||||
|
||||
// Get 'callback_url' parameter
|
||||
// TODO: Check it is valid url
|
||||
const [callbackUrl, callbackUrlErr] = it(params.callback_url).expect.nullable.string().default(null).qed();
|
||||
const [callbackUrl = null, callbackUrlErr] = it(params.callback_url).expect.nullable.string().get();
|
||||
if (callbackUrlErr) return rej('invalid callback_url param');
|
||||
|
||||
// Generate secret
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../../it';
|
||||
import it from 'cafy';
|
||||
import App from '../../../models/app';
|
||||
import { isValidNameId } from '../../../models/app';
|
||||
|
||||
@ -42,7 +42,7 @@ import { isValidNameId } from '../../../models/app';
|
||||
*/
|
||||
module.exports = async (params) => new Promise(async (res, rej) => {
|
||||
// Get 'name_id' parameter
|
||||
const [nameId, nameIdErr] = it(params.name_id).expect.string().required().validate(isValidNameId).qed();
|
||||
const [nameId, nameIdErr] = it(params.name_id).expect.string().required().validate(isValidNameId).get();
|
||||
if (nameIdErr) return rej('invalid name_id param');
|
||||
|
||||
// Get exist
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
import App from '../../models/app';
|
||||
import serialize from '../../serializers/app';
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
*/
|
||||
import rndstr from 'rndstr';
|
||||
const crypto = require('crypto');
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
import App from '../../models/app';
|
||||
import AuthSess from '../../models/auth-session';
|
||||
import AccessToken from '../../models/access-token';
|
||||
@ -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] = it(params.token).expect.string().required().qed();
|
||||
const [token, tokenErr] = it(params.token).expect.string().required().get();
|
||||
if (tokenErr) return rej('invalid token param');
|
||||
|
||||
// Fetch token
|
||||
|
@ -2,7 +2,7 @@
|
||||
* Module dependencies
|
||||
*/
|
||||
import * as uuid from 'uuid';
|
||||
import it from '../../../it';
|
||||
import it from 'cafy';
|
||||
import App from '../../../models/app';
|
||||
import AuthSess from '../../../models/auth-session';
|
||||
import config from '../../../../conf';
|
||||
@ -46,7 +46,7 @@ import config from '../../../../conf';
|
||||
*/
|
||||
module.exports = (params) => new Promise(async (res, rej) => {
|
||||
// Get 'app_secret' parameter
|
||||
const [appSecret, appSecretErr] = it(params.app_secret).expect.string().required().qed();
|
||||
const [appSecret, appSecretErr] = it(params.app_secret).expect.string().required().get();
|
||||
if (appSecretErr) return rej('invalid app_secret param');
|
||||
|
||||
// Lookup app
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../../it';
|
||||
import it from 'cafy';
|
||||
import AuthSess from '../../../models/auth-session';
|
||||
import serialize from '../../../serializers/auth-session';
|
||||
|
||||
@ -54,7 +54,7 @@ import serialize from '../../../serializers/auth-session';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'token' parameter
|
||||
const [token, tokenErr] = it(params.token).expect.string().required().qed();
|
||||
const [token, tokenErr] = it(params.token).expect.string().required().get();
|
||||
if (tokenErr) return rej('invalid token param');
|
||||
|
||||
// Lookup session
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../../it';
|
||||
import it from 'cafy';
|
||||
import App from '../../../models/app';
|
||||
import AuthSess from '../../../models/auth-session';
|
||||
import AccessToken from '../../../models/access-token';
|
||||
@ -51,7 +51,7 @@ import serialize from '../../../serializers/user';
|
||||
*/
|
||||
module.exports = (params) => new Promise(async (res, rej) => {
|
||||
// Get 'app_secret' parameter
|
||||
const [appSecret, appSecretErr] = it(params.app_secret).expect.string().required().qed();
|
||||
const [appSecret, appSecretErr] = it(params.app_secret).expect.string().required().get();
|
||||
if (appSecretErr) return rej('invalid app_secret param');
|
||||
|
||||
// Lookup app
|
||||
@ -64,7 +64,7 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
||||
}
|
||||
|
||||
// Get 'token' parameter
|
||||
const [token, tokenErr] = it(params.token).expect.string().required().qed();
|
||||
const [token, tokenErr] = it(params.token).expect.string().required().get();
|
||||
if (tokenErr) return rej('invalid token param');
|
||||
|
||||
// Fetch token
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
import DriveFile from '../../models/drive-file';
|
||||
import serialize from '../../serializers/drive-file';
|
||||
|
||||
@ -15,15 +15,15 @@ import serialize from '../../serializers/drive-file';
|
||||
*/
|
||||
module.exports = (params, user, app) => new Promise(async (res, rej) => {
|
||||
// Get 'limit' parameter
|
||||
const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed();
|
||||
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get();
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'since_id' parameter
|
||||
const [sinceId, sinceIdErr] = it(params.since_id).expect.id().qed();
|
||||
const [sinceId, sinceIdErr] = it(params.since_id).expect.id().get();
|
||||
if (sinceIdErr) return rej('invalid since_id param');
|
||||
|
||||
// Get 'max_id' parameter
|
||||
const [maxId, maxIdErr] = it(params.max_id).expect.id().qed();
|
||||
const [maxId, maxIdErr] = it(params.max_id).expect.id().get();
|
||||
if (maxIdErr) return rej('invalid max_id param');
|
||||
|
||||
// Check if both of since_id and max_id is specified
|
||||
@ -32,7 +32,7 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
|
||||
}
|
||||
|
||||
// Get 'folder_id' parameter
|
||||
const [folderId, folderIdErr] = it(params.folder_id).expect.nullable.id().default(null).qed();
|
||||
const [folderId = null, folderIdErr] = it(params.folder_id).expect.nullable.id().get();
|
||||
if (folderIdErr) return rej('invalid folder_id param');
|
||||
|
||||
// Construct query
|
||||
|
@ -2,7 +2,7 @@
|
||||
* Module dependencies
|
||||
*/
|
||||
import * as fs from 'fs';
|
||||
import it from '../../../it';
|
||||
import it from 'cafy';
|
||||
import { validateFileName } from '../../../models/drive-file';
|
||||
import serialize from '../../../serializers/drive-file';
|
||||
import create from '../../../common/add-file-to-drive';
|
||||
@ -39,7 +39,7 @@ module.exports = (file, params, user) => new Promise(async (res, rej) => {
|
||||
}
|
||||
|
||||
// Get 'folder_id' parameter
|
||||
const [folderId, folderIdErr] = it(params.folder_id).expect.nullable.id().default(null).qed();
|
||||
const [folderId = null, folderIdErr] = it(params.folder_id).expect.nullable.id().get();
|
||||
if (folderIdErr) return rej('invalid folder_id param');
|
||||
|
||||
// Create file
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../../it';
|
||||
import it from 'cafy';
|
||||
import DriveFile from '../../../models/drive-file';
|
||||
import serialize from '../../../serializers/drive-file';
|
||||
|
||||
@ -14,11 +14,11 @@ import serialize from '../../../serializers/drive-file';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'name' parameter
|
||||
const [name, nameErr] = it(params.name).expect.string().required().qed();
|
||||
const [name, nameErr] = it(params.name).expect.string().required().get();
|
||||
if (nameErr) return rej('invalid name param');
|
||||
|
||||
// Get 'folder_id' parameter
|
||||
const [folderId, folderIdErr] = it(params.folder_id).expect.nullable.id().default(null).qed();
|
||||
const [folderId = null, folderIdErr] = it(params.folder_id).expect.nullable.id().get();
|
||||
if (folderIdErr) return rej('invalid folder_id param');
|
||||
|
||||
// Issue query
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../../it';
|
||||
import it from 'cafy';
|
||||
import DriveFile from '../../../models/drive-file';
|
||||
import serialize from '../../../serializers/drive-file';
|
||||
|
||||
@ -14,7 +14,7 @@ import serialize from '../../../serializers/drive-file';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'file_id' parameter
|
||||
const [fileId, fileIdErr] = it(params.file_id).expect.id().required().qed();
|
||||
const [fileId, fileIdErr] = it(params.file_id).expect.id().required().get();
|
||||
if (fileIdErr) return rej('invalid file_id param');
|
||||
|
||||
// Fetch file
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../../it';
|
||||
import it from 'cafy';
|
||||
import DriveFolder from '../../../models/drive-folder';
|
||||
import DriveFile from '../../../models/drive-file';
|
||||
import { validateFileName } from '../../../models/drive-file';
|
||||
@ -17,7 +17,7 @@ import event from '../../../event';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'file_id' parameter
|
||||
const [fileId, fileIdErr] = it(params.file_id).expect.id().required().qed();
|
||||
const [fileId, fileIdErr] = it(params.file_id).expect.id().required().get();
|
||||
if (fileIdErr) return rej('invalid file_id param');
|
||||
|
||||
// Fetch file
|
||||
@ -36,12 +36,12 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
}
|
||||
|
||||
// Get 'name' parameter
|
||||
const [name, nameErr] = it(params.name).expect.string().validate(validateFileName).qed();
|
||||
const [name, nameErr] = it(params.name).expect.string().validate(validateFileName).get();
|
||||
if (nameErr) return rej('invalid name param');
|
||||
if (name) file.name = name;
|
||||
|
||||
// Get 'folder_id' parameter
|
||||
const [folderId, folderIdErr] = it(params.folder_id).expect.nullable.id().qed();
|
||||
const [folderId, folderIdErr] = it(params.folder_id).expect.nullable.id().get();
|
||||
if (folderIdErr) return rej('invalid folder_id param');
|
||||
|
||||
if (folderId !== undefined) {
|
||||
|
@ -3,7 +3,7 @@
|
||||
*/
|
||||
import * as URL from 'url';
|
||||
const download = require('download');
|
||||
import it from '../../../it';
|
||||
import it from 'cafy';
|
||||
import { validateFileName } from '../../../models/drive-file';
|
||||
import serialize from '../../../serializers/drive-file';
|
||||
import create from '../../../common/add-file-to-drive';
|
||||
@ -18,7 +18,7 @@ import create from '../../../common/add-file-to-drive';
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'url' parameter
|
||||
// TODO: Validate this url
|
||||
const [url, urlErr] = it(params.url).expect.string().required().qed();
|
||||
const [url, urlErr] = it(params.url).expect.string().required().get();
|
||||
if (urlErr) return rej('invalid url param');
|
||||
|
||||
let name = URL.parse(url).pathname.split('/').pop();
|
||||
@ -27,7 +27,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
}
|
||||
|
||||
// Get 'folder_id' parameter
|
||||
const [folderId, folderIdErr] = it(params.folder_id).expect.nullable.id().default(null).qed();
|
||||
const [folderId = null, folderIdErr] = it(params.folder_id).expect.nullable.id().get();
|
||||
if (folderIdErr) return rej('invalid folder_id param');
|
||||
|
||||
// Download file
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
import DriveFolder from '../../models/drive-folder';
|
||||
import serialize from '../../serializers/drive-folder';
|
||||
|
||||
@ -15,15 +15,15 @@ import serialize from '../../serializers/drive-folder';
|
||||
*/
|
||||
module.exports = (params, user, app) => new Promise(async (res, rej) => {
|
||||
// Get 'limit' parameter
|
||||
const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed();
|
||||
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get();
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'since_id' parameter
|
||||
const [sinceId, sinceIdErr] = it(params.since_id).expect.id().qed();
|
||||
const [sinceId, sinceIdErr] = it(params.since_id).expect.id().get();
|
||||
if (sinceIdErr) return rej('invalid since_id param');
|
||||
|
||||
// Get 'max_id' parameter
|
||||
const [maxId, maxIdErr] = it(params.max_id).expect.id().qed();
|
||||
const [maxId, maxIdErr] = it(params.max_id).expect.id().get();
|
||||
if (maxIdErr) return rej('invalid max_id param');
|
||||
|
||||
// Check if both of since_id and max_id is specified
|
||||
@ -32,7 +32,7 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
|
||||
}
|
||||
|
||||
// Get 'folder_id' parameter
|
||||
const [folderId, folderIdErr] = it(params.folder_id).expect.nullable.id().default(null).qed();
|
||||
const [folderId = null, folderIdErr] = it(params.folder_id).expect.nullable.id().get();
|
||||
if (folderIdErr) return rej('invalid folder_id param');
|
||||
|
||||
// Construct query
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../../it';
|
||||
import it from 'cafy';
|
||||
import DriveFolder from '../../../models/drive-folder';
|
||||
import { isValidFolderName } from '../../../models/drive-folder';
|
||||
import serialize from '../../../serializers/drive-folder';
|
||||
@ -16,11 +16,11 @@ import event from '../../../event';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'name' parameter
|
||||
const [name, nameErr] = it(params.name).expect.string().validate(isValidFolderName).default('無題のフォルダー').qed();
|
||||
const [name = '無題のフォルダー', nameErr] = it(params.name).expect.string().validate(isValidFolderName).get();
|
||||
if (nameErr) return rej('invalid name param');
|
||||
|
||||
// Get 'parent_id' parameter
|
||||
const [parentId, parentIdErr] = it(params.parent_id).expect.nullable.id().default(null).qed();
|
||||
const [parentId = null, parentIdErr] = it(params.parent_id).expect.nullable.id().get();
|
||||
if (parentIdErr) return rej('invalid parent_id param');
|
||||
|
||||
// If the parent folder is specified
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../../it';
|
||||
import it from 'cafy';
|
||||
import DriveFolder from '../../../models/drive-folder';
|
||||
import serialize from '../../../serializers/drive-folder';
|
||||
|
||||
@ -14,11 +14,11 @@ import serialize from '../../../serializers/drive-folder';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'name' parameter
|
||||
const [name, nameErr] = it(params.name).expect.string().required().qed();
|
||||
const [name, nameErr] = it(params.name).expect.string().required().get();
|
||||
if (nameErr) return rej('invalid name param');
|
||||
|
||||
// Get 'parent_id' parameter
|
||||
const [parentId, parentIdErr] = it(params.parent_id).expect.id().qed();
|
||||
const [parentId, parentIdErr] = it(params.parent_id).expect.id().get();
|
||||
if (parentIdErr) return rej('invalid parent_id param');
|
||||
|
||||
// Issue query
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../../it';
|
||||
import it from 'cafy';
|
||||
import DriveFolder from '../../../models/drive-folder';
|
||||
import serialize from '../../../serializers/drive-folder';
|
||||
|
||||
@ -14,7 +14,7 @@ import serialize from '../../../serializers/drive-folder';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'folder_id' parameter
|
||||
const [folderId, folderIdErr] = it(params.folder_id).expect.id().required().qed();
|
||||
const [folderId, folderIdErr] = it(params.folder_id).expect.id().required().get();
|
||||
if (folderIdErr) return rej('invalid folder_id param');
|
||||
|
||||
// Get folder
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../../it';
|
||||
import it from 'cafy';
|
||||
import DriveFolder from '../../../models/drive-folder';
|
||||
import { isValidFolderName } from '../../../models/drive-folder';
|
||||
import serialize from '../../../serializers/drive-file';
|
||||
@ -16,7 +16,7 @@ import event from '../../../event';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'folder_id' parameter
|
||||
const [folderId, folderIdErr] = it(params.folder_id).expect.id().required().qed();
|
||||
const [folderId, folderIdErr] = it(params.folder_id).expect.id().required().get();
|
||||
if (folderIdErr) return rej('invalid folder_id param');
|
||||
|
||||
// Fetch folder
|
||||
@ -31,12 +31,12 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
}
|
||||
|
||||
// Get 'name' parameter
|
||||
const [name, nameErr] = it(params.name).expect.string().validate(isValidFolderName).qed();
|
||||
const [name, nameErr] = it(params.name).expect.string().validate(isValidFolderName).get();
|
||||
if (nameErr) return rej('invalid name param');
|
||||
if (name) folder.name = name;
|
||||
|
||||
// Get 'parent_id' parameter
|
||||
const [parentId, parentIdErr] = it(params.parent_id).expect.nullable.id().qed();
|
||||
const [parentId, parentIdErr] = it(params.parent_id).expect.nullable.id().get();
|
||||
if (parentIdErr) return rej('invalid parent_id param');
|
||||
if (parentId !== undefined) {
|
||||
if (parentId === null) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
import DriveFile from '../../models/drive-file';
|
||||
import serialize from '../../serializers/drive-file';
|
||||
|
||||
@ -14,15 +14,15 @@ import serialize from '../../serializers/drive-file';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'limit' parameter
|
||||
const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed();
|
||||
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get();
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'since_id' parameter
|
||||
const [sinceId, sinceIdErr] = it(params.since_id).expect.id().qed();
|
||||
const [sinceId, sinceIdErr] = it(params.since_id).expect.id().get();
|
||||
if (sinceIdErr) return rej('invalid since_id param');
|
||||
|
||||
// Get 'max_id' parameter
|
||||
const [maxId, maxIdErr] = it(params.max_id).expect.id().qed();
|
||||
const [maxId, maxIdErr] = it(params.max_id).expect.id().get();
|
||||
if (maxIdErr) return rej('invalid max_id param');
|
||||
|
||||
// Check if both of since_id and max_id is specified
|
||||
@ -31,7 +31,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
}
|
||||
|
||||
// Get 'type' parameter
|
||||
const [type, typeErr] = it(params.type).expect.string().match(/^[a-zA-Z\/\-\*]+$/).qed();
|
||||
const [type, typeErr] = it(params.type).expect.string().match(/^[a-zA-Z\/\-\*]+$/).get();
|
||||
if (typeErr) return rej('invalid type param');
|
||||
|
||||
// Construct query
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
import User from '../../models/user';
|
||||
import Following from '../../models/following';
|
||||
import notify from '../../common/notify';
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
import User from '../../models/user';
|
||||
import Following from '../../models/following';
|
||||
import event from '../../event';
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
import AccessToken from '../../models/access-token';
|
||||
import serialize from '../../serializers/app';
|
||||
|
||||
@ -14,15 +14,15 @@ import serialize from '../../serializers/app';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'limit' parameter
|
||||
const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed();
|
||||
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get();
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'offset' parameter
|
||||
const [offset, offsetErr] = it(params.offset).expect.number().min(0).default(0).qed();
|
||||
const [offset = 0, offsetErr] = it(params.offset).expect.number().min(0).get();
|
||||
if (offsetErr) return rej('invalid offset param');
|
||||
|
||||
// Get 'sort' parameter
|
||||
const [sort, sortError] = it(params.sort).expect.string().or('desc asc').default('desc').qed();
|
||||
const [sort = 'desc', sortError] = it(params.sort).expect.string().or('desc asc').get();
|
||||
if (sortError) return rej('invalid sort param');
|
||||
|
||||
// Get tokens
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
import Favorite from '../../models/favorite';
|
||||
import serialize from '../../serializers/post';
|
||||
|
||||
@ -14,15 +14,15 @@ import serialize from '../../serializers/post';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'limit' parameter
|
||||
const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed();
|
||||
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get();
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'offset' parameter
|
||||
const [offset, offsetErr] = it(params.offset).expect.number().min(0).default(0).qed();
|
||||
const [offset = 0, offsetErr] = it(params.offset).expect.number().min(0).get();
|
||||
if (offsetErr) return rej('invalid offset param');
|
||||
|
||||
// Get 'sort' parameter
|
||||
const [sort, sortError] = it(params.sort).expect.string().or('desc asc').default('desc').qed();
|
||||
const [sort = 'desc', sortError] = it(params.sort).expect.string().or('desc asc').get();
|
||||
if (sortError) return rej('invalid sort param');
|
||||
|
||||
// Get favorites
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
import Notification from '../../models/notification';
|
||||
import serialize from '../../serializers/notification';
|
||||
import getFriends from '../../common/get-friends';
|
||||
@ -15,28 +15,28 @@ import getFriends from '../../common/get-friends';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'following' parameter
|
||||
const [following, followingError] =
|
||||
it(params.following).expect.boolean().default(false).qed();
|
||||
const [following = false, followingError] =
|
||||
it(params.following).expect.boolean().get();
|
||||
if (followingError) return rej('invalid following param');
|
||||
|
||||
// Get 'mark_as_read' parameter
|
||||
const [markAsRead, markAsReadErr] = it(params.mark_as_read).expect.boolean().default(true).qed();
|
||||
const [markAsRead = true, markAsReadErr] = it(params.mark_as_read).expect.boolean().get();
|
||||
if (markAsReadErr) return rej('invalid mark_as_read param');
|
||||
|
||||
// Get 'type' parameter
|
||||
const [type, typeErr] = it(params.type).expect.array().unique().allString().qed();
|
||||
const [type, typeErr] = it(params.type).expect.array().unique().allString().get();
|
||||
if (typeErr) return rej('invalid type param');
|
||||
|
||||
// Get 'limit' parameter
|
||||
const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed();
|
||||
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get();
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'since_id' parameter
|
||||
const [sinceId, sinceIdErr] = it(params.since_id).expect.id().qed();
|
||||
const [sinceId, sinceIdErr] = it(params.since_id).expect.id().get();
|
||||
if (sinceIdErr) return rej('invalid since_id param');
|
||||
|
||||
// Get 'max_id' parameter
|
||||
const [maxId, maxIdErr] = it(params.max_id).expect.id().qed();
|
||||
const [maxId, maxIdErr] = it(params.max_id).expect.id().get();
|
||||
if (maxIdErr) return rej('invalid max_id param');
|
||||
|
||||
// Check if both of since_id and max_id is specified
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
import Signin from '../../models/signin';
|
||||
import serialize from '../../serializers/signin';
|
||||
|
||||
@ -14,15 +14,15 @@ import serialize from '../../serializers/signin';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'limit' parameter
|
||||
const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed();
|
||||
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get();
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'since_id' parameter
|
||||
const [sinceId, sinceIdErr] = it(params.since_id).expect.id().qed();
|
||||
const [sinceId, sinceIdErr] = it(params.since_id).expect.id().get();
|
||||
if (sinceIdErr) return rej('invalid since_id param');
|
||||
|
||||
// Get 'max_id' parameter
|
||||
const [maxId, maxIdErr] = it(params.max_id).expect.id().qed();
|
||||
const [maxId, maxIdErr] = it(params.max_id).expect.id().get();
|
||||
if (maxIdErr) return rej('invalid max_id param');
|
||||
|
||||
// Check if both of since_id and max_id is specified
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
import User from '../../models/user';
|
||||
import { isValidName, isValidDescription, isValidLocation, isValidBirthday } from '../../models/user';
|
||||
import serialize from '../../serializers/user';
|
||||
@ -19,32 +19,32 @@ import config from '../../../conf';
|
||||
*/
|
||||
module.exports = async (params, user, _, isSecure) => new Promise(async (res, rej) => {
|
||||
// Get 'name' parameter
|
||||
const [name, nameErr] = it(params.name).expect.string().validate(isValidName).qed();
|
||||
const [name, nameErr] = it(params.name).expect.string().validate(isValidName).get();
|
||||
if (nameErr) return rej('invalid name param');
|
||||
if (name) user.name = name;
|
||||
|
||||
// Get 'description' parameter
|
||||
const [description, descriptionErr] = it(params.description).expect.nullable.string().validate(isValidDescription).qed();
|
||||
const [description, descriptionErr] = it(params.description).expect.nullable.string().validate(isValidDescription).get();
|
||||
if (descriptionErr) return rej('invalid description param');
|
||||
if (description !== undefined) user.description = description;
|
||||
|
||||
// Get 'location' parameter
|
||||
const [location, locationErr] = it(params.location).expect.nullable.string().validate(isValidLocation).qed();
|
||||
const [location, locationErr] = it(params.location).expect.nullable.string().validate(isValidLocation).get();
|
||||
if (locationErr) return rej('invalid location param');
|
||||
if (location !== undefined) user.location = location;
|
||||
|
||||
// Get 'birthday' parameter
|
||||
const [birthday, birthdayErr] = it(params.birthday).expect.nullable.string().validate(isValidBirthday).qed();
|
||||
const [birthday, birthdayErr] = it(params.birthday).expect.nullable.string().validate(isValidBirthday).get();
|
||||
if (birthdayErr) return rej('invalid birthday param');
|
||||
if (birthday !== undefined) user.birthday = birthday;
|
||||
|
||||
// Get 'avatar_id' parameter
|
||||
const [avatarId, avatarIdErr] = it(params.avatar_id).expect.id().qed();
|
||||
const [avatarId, avatarIdErr] = it(params.avatar_id).expect.id().get();
|
||||
if (avatarIdErr) return rej('invalid avatar_id param');
|
||||
if (avatarId) user.avatar_id = avatarId;
|
||||
|
||||
// Get 'banner_id' parameter
|
||||
const [bannerId, bannerIdErr] = it(params.banner_id).expect.id().qed();
|
||||
const [bannerId, bannerIdErr] = it(params.banner_id).expect.id().get();
|
||||
if (bannerIdErr) return rej('invalid banner_id param');
|
||||
if (bannerId) user.banner_id = bannerId;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
import History from '../../models/messaging-history';
|
||||
import serialize from '../../serializers/messaging-message';
|
||||
|
||||
@ -14,7 +14,7 @@ import serialize from '../../serializers/messaging-message';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'limit' parameter
|
||||
const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed();
|
||||
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get();
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get history
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
import Message from '../../models/messaging-message';
|
||||
import User from '../../models/user';
|
||||
import serialize from '../../serializers/messaging-message';
|
||||
@ -17,7 +17,7 @@ import { publishMessagingStream } from '../../event';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'user_id' parameter
|
||||
const [recipientId, recipientIdErr] = it(params.user_id).expect.id().required().qed();
|
||||
const [recipientId, recipientIdErr] = it(params.user_id).expect.id().required().get();
|
||||
if (recipientIdErr) return rej('invalid user_id param');
|
||||
|
||||
// Fetch recipient
|
||||
@ -34,19 +34,19 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
}
|
||||
|
||||
// Get 'mark_as_read' parameter
|
||||
const [markAsRead, markAsReadErr] = it(params.mark_as_read).expect.boolean().default(true).qed();
|
||||
const [markAsRead = true, markAsReadErr] = it(params.mark_as_read).expect.boolean().get();
|
||||
if (markAsReadErr) return rej('invalid mark_as_read param');
|
||||
|
||||
// Get 'limit' parameter
|
||||
const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed();
|
||||
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get();
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'since_id' parameter
|
||||
const [sinceId, sinceIdErr] = it(params.since_id).expect.id().qed();
|
||||
const [sinceId, sinceIdErr] = it(params.since_id).expect.id().get();
|
||||
if (sinceIdErr) return rej('invalid since_id param');
|
||||
|
||||
// Get 'max_id' parameter
|
||||
const [maxId, maxIdErr] = it(params.max_id).expect.id().qed();
|
||||
const [maxId, maxIdErr] = it(params.max_id).expect.id().get();
|
||||
if (maxIdErr) return rej('invalid max_id param');
|
||||
|
||||
// Check if both of since_id and max_id is specified
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../../it';
|
||||
import it from 'cafy';
|
||||
import Message from '../../../models/messaging-message';
|
||||
import { isValidText } from '../../../models/messaging-message';
|
||||
import History from '../../../models/messaging-history';
|
||||
@ -21,7 +21,7 @@ import config from '../../../../conf';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'user_id' parameter
|
||||
const [recipientId, recipientIdErr] = it(params.user_id).expect.id().required().qed();
|
||||
const [recipientId, recipientIdErr] = it(params.user_id).expect.id().required().get();
|
||||
if (recipientIdErr) return rej('invalid user_id param');
|
||||
|
||||
// Myself
|
||||
@ -43,11 +43,11 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
}
|
||||
|
||||
// Get 'text' parameter
|
||||
const [text, textErr] = it(params.text).expect.string().validate(isValidText).qed();
|
||||
const [text, textErr] = it(params.text).expect.string().validate(isValidText).get();
|
||||
if (textErr) return rej('invalid text');
|
||||
|
||||
// Get 'file_id' parameter
|
||||
const [fileId, fileIdErr] = it(params.file_id).expect.id().qed();
|
||||
const [fileId, fileIdErr] = it(params.file_id).expect.id().get();
|
||||
if (fileIdErr) return rej('invalid file_id param');
|
||||
|
||||
let file = null;
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
import App from '../../models/app';
|
||||
import serialize from '../../serializers/app';
|
||||
|
||||
@ -14,11 +14,11 @@ import serialize from '../../serializers/app';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'limit' parameter
|
||||
const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed();
|
||||
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get();
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'offset' parameter
|
||||
const [offset, offsetErr] = it(params.offset).expect.number().min(0).default(0).qed();
|
||||
const [offset = 0, offsetErr] = it(params.offset).expect.number().min(0).get();
|
||||
if (offsetErr) return rej('invalid offset param');
|
||||
|
||||
const query = {
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
import Notification from '../../models/notification';
|
||||
import serialize from '../../serializers/notification';
|
||||
import event from '../../event';
|
||||
@ -14,7 +14,7 @@ import event from '../../event';
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
const [notificationId, notificationIdErr] = it(params.notification_id).expect.id().required().qed();
|
||||
const [notificationId, notificationIdErr] = it(params.notification_id).expect.id().required().get();
|
||||
if (notificationIdErr) return rej('invalid notification_id param');
|
||||
|
||||
// Get notification
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../it';
|
||||
import it from 'cafy';
|
||||
import Post from '../models/post';
|
||||
import serialize from '../serializers/post';
|
||||
|
||||
@ -13,23 +13,23 @@ import serialize from '../serializers/post';
|
||||
*/
|
||||
module.exports = (params) => new Promise(async (res, rej) => {
|
||||
// Get 'include_replies' parameter
|
||||
const [includeReplies, includeRepliesErr] = it(params.include_replies).expect.boolean().default(true).qed();
|
||||
const [includeReplies = true, includeRepliesErr] = it(params.include_replies).expect.boolean().get();
|
||||
if (includeRepliesErr) return rej('invalid include_replies param');
|
||||
|
||||
// Get 'include_reposts' parameter
|
||||
const [includeReposts, includeRepostsErr] = it(params.include_reposts).expect.boolean().default(true).qed();
|
||||
const [includeReposts = true, includeRepostsErr] = it(params.include_reposts).expect.boolean().get();
|
||||
if (includeRepostsErr) return rej('invalid include_reposts param');
|
||||
|
||||
// Get 'limit' parameter
|
||||
const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed();
|
||||
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get();
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'since_id' parameter
|
||||
const [sinceId, sinceIdErr] = it(params.since_id).expect.id().qed();
|
||||
const [sinceId, sinceIdErr] = it(params.since_id).expect.id().get();
|
||||
if (sinceIdErr) return rej('invalid since_id param');
|
||||
|
||||
// Get 'max_id' parameter
|
||||
const [maxId, maxIdErr] = it(params.max_id).expect.id().qed();
|
||||
const [maxId, maxIdErr] = it(params.max_id).expect.id().get();
|
||||
if (maxIdErr) return rej('invalid max_id param');
|
||||
|
||||
// Check if both of since_id and max_id is specified
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
import Post from '../../models/post';
|
||||
import serialize from '../../serializers/post';
|
||||
|
||||
@ -18,11 +18,11 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
if (postIdErr) return rej('invalid post_id param');
|
||||
|
||||
// Get 'limit' parameter
|
||||
const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed();
|
||||
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get();
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'offset' parameter
|
||||
const [offset, offsetErr] = it(params.offset).expect.number().min(0).default(0).qed();
|
||||
const [offset = 0, offsetErr] = it(params.offset).expect.number().min(0).get();
|
||||
if (offsetErr) return rej('invalid offset param');
|
||||
|
||||
// Lookup post
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
import parse from '../../../common/text';
|
||||
import Post from '../../models/post';
|
||||
import { isValidText } from '../../models/post';
|
||||
@ -23,11 +23,11 @@ import config from '../../../conf';
|
||||
*/
|
||||
module.exports = (params, user, app) => new Promise(async (res, rej) => {
|
||||
// Get 'text' parameter
|
||||
const [text, textErr] = it(params.text).must.be.a.string().validate(isValidText).qed();
|
||||
const [text, textErr] = it(params.text).must.be.a.string().validate(isValidText).get();
|
||||
if (textErr) return rej('invalid text');
|
||||
|
||||
// Get 'media_ids' parameter
|
||||
const [mediaIds, mediaIdsErr] = it(params.media_ids).must.be.an.array().unique().range(1, 4).qed();
|
||||
const [mediaIds, mediaIdsErr] = it(params.media_ids).must.be.an.array().unique().range(1, 4).get();
|
||||
if (mediaIdsErr) return rej('invalid media_ids');
|
||||
|
||||
let files = [];
|
||||
@ -36,7 +36,7 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
|
||||
// forEach だと途中でエラーなどがあっても return できないので
|
||||
// 敢えて for を使っています。
|
||||
for (let i = 0; i < mediaIds.length; i++) {
|
||||
const [mediaId, mediaIdErr] = it(mediaIds[i]).must.be.an.id().required().qed();
|
||||
const [mediaId, mediaIdErr] = it(mediaIds[i]).must.be.an.id().required().get();
|
||||
if (mediaIdErr) return rej('invalid media id');
|
||||
|
||||
// Fetch file
|
||||
@ -59,7 +59,7 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
|
||||
}
|
||||
|
||||
// Get 'repost_id' parameter
|
||||
const [repostId, repostIdErr] = it(params.repost_id).must.be.an.id().qed();
|
||||
const [repostId, repostIdErr] = it(params.repost_id).must.be.an.id().get();
|
||||
if (repostIdErr) return rej('invalid repost_id');
|
||||
|
||||
let repost = null;
|
||||
@ -138,7 +138,7 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
|
||||
if (choice.trim().length > 50) return true;
|
||||
return false;
|
||||
}))
|
||||
.qed();
|
||||
.get();
|
||||
if (pollChoicesErr) return rej('invalid poll choices');
|
||||
|
||||
_poll.choices = pollChoices.map((choice, i) => ({
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../../it';
|
||||
import it from 'cafy';
|
||||
import Favorite from '../../../models/favorite';
|
||||
import Post from '../../../models/post';
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../../it';
|
||||
import it from 'cafy';
|
||||
import Favorite from '../../../models/favorite';
|
||||
import Post from '../../../models/post';
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
import Post from '../../models/post';
|
||||
import Like from '../../models/like';
|
||||
import serialize from '../../serializers/user';
|
||||
@ -19,15 +19,15 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
if (postIdErr) return rej('invalid post_id param');
|
||||
|
||||
// Get 'limit' parameter
|
||||
const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed();
|
||||
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get();
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'offset' parameter
|
||||
const [offset, offsetErr] = it(params.offset).expect.number().min(0).default(0).qed();
|
||||
const [offset = 0, offsetErr] = it(params.offset).expect.number().min(0).get();
|
||||
if (offsetErr) return rej('invalid offset param');
|
||||
|
||||
// Get 'sort' parameter
|
||||
const [sort, sortError] = it(params.sort).expect.string().or('desc asc').default('desc').qed();
|
||||
const [sort = 'desc', sortError] = it(params.sort).expect.string().or('desc asc').get();
|
||||
if (sortError) return rej('invalid sort param');
|
||||
|
||||
// Lookup post
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../../it';
|
||||
import it from 'cafy';
|
||||
import Like from '../../../models/like';
|
||||
import Post from '../../../models/post';
|
||||
import User from '../../../models/user';
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../../it';
|
||||
import it from 'cafy';
|
||||
import Like from '../../../models/like';
|
||||
import Post from '../../../models/post';
|
||||
import User from '../../../models/user';
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
import Post from '../../models/post';
|
||||
import getFriends from '../../common/get-friends';
|
||||
import serialize from '../../serializers/post';
|
||||
@ -15,20 +15,20 @@ import serialize from '../../serializers/post';
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'following' parameter
|
||||
const [following, followingError] =
|
||||
it(params.following).expect.boolean().default(false).qed();
|
||||
const [following = false, followingError] =
|
||||
it(params.following).expect.boolean().get();
|
||||
if (followingError) return rej('invalid following param');
|
||||
|
||||
// Get 'limit' parameter
|
||||
const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed();
|
||||
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get();
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'since_id' parameter
|
||||
const [sinceId, sinceIdErr] = it(params.since_id).expect.id().qed();
|
||||
const [sinceId, sinceIdErr] = it(params.since_id).expect.id().get();
|
||||
if (sinceIdErr) return rej('invalid since_id param');
|
||||
|
||||
// Get 'max_id' parameter
|
||||
const [maxId, maxIdErr] = it(params.max_id).expect.id().qed();
|
||||
const [maxId, maxIdErr] = it(params.max_id).expect.id().get();
|
||||
if (maxIdErr) return rej('invalid max_id param');
|
||||
|
||||
// Check if both of since_id and max_id is specified
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../../it';
|
||||
import it from 'cafy';
|
||||
import Vote from '../../../models/poll-vote';
|
||||
import Post from '../../../models/post';
|
||||
import notify from '../../../common/notify';
|
||||
@ -36,7 +36,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
it(params.choice).expect.string()
|
||||
.required()
|
||||
.validate(c => post.poll.choices.some(x => x.id == c))
|
||||
.qed();
|
||||
.get();
|
||||
if (choiceError) return rej('invalid choice param');
|
||||
|
||||
// if already voted
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
import Post from '../../models/post';
|
||||
import serialize from '../../serializers/post';
|
||||
|
||||
@ -18,15 +18,15 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
if (postIdErr) return rej('invalid post_id param');
|
||||
|
||||
// Get 'limit' parameter
|
||||
const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed();
|
||||
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100)).get();
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'offset' parameter
|
||||
const [offset, offsetErr] = it(params.offset).expect.number().min(0).default(0).qed();
|
||||
const [offset = 0, offsetErr] = it(params.offset).expect.number().min(0).get();
|
||||
if (offsetErr) return rej('invalid offset param');
|
||||
|
||||
// Get 'sort' parameter
|
||||
const [sort, sortError] = it(params.sort).expect.string().or('desc asc').default('desc').qed();
|
||||
const [sort = 'desc', sortError] = it(params.sort).expect.string().or('desc asc').get();
|
||||
if (sortError) return rej('invalid sort param');
|
||||
|
||||
// Lookup post
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
import Post from '../../models/post';
|
||||
import serialize from '../../serializers/post';
|
||||
|
||||
@ -18,15 +18,15 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
if (postIdErr) return rej('invalid post_id param');
|
||||
|
||||
// Get 'limit' parameter
|
||||
const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed();
|
||||
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get();
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'since_id' parameter
|
||||
const [sinceId, sinceIdErr] = it(params.since_id).expect.id().qed();
|
||||
const [sinceId, sinceIdErr] = it(params.since_id).expect.id().get();
|
||||
if (sinceIdErr) return rej('invalid since_id param');
|
||||
|
||||
// Get 'max_id' parameter
|
||||
const [maxId, maxIdErr] = it(params.max_id).expect.id().qed();
|
||||
const [maxId, maxIdErr] = it(params.max_id).expect.id().get();
|
||||
if (maxIdErr) return rej('invalid max_id param');
|
||||
|
||||
// Check if both of since_id and max_id is specified
|
||||
|
@ -2,7 +2,7 @@
|
||||
* Module dependencies
|
||||
*/
|
||||
import * as mongo from 'mongodb';
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
const escapeRegexp = require('escape-regexp');
|
||||
import Post from '../../models/post';
|
||||
import serialize from '../../serializers/post';
|
||||
@ -17,15 +17,15 @@ import config from '../../../conf';
|
||||
*/
|
||||
module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
// Get 'query' parameter
|
||||
const [query, queryError] = it(params.query).expect.string().required().trim().validate(x => x != '').qed();
|
||||
const [query, queryError] = it(params.query).expect.string().required().trim().validate(x => x != '').get();
|
||||
if (queryError) return rej('invalid query param');
|
||||
|
||||
// Get 'offset' parameter
|
||||
const [offset, offsetErr] = it(params.offset).expect.number().min(0).default(0).qed();
|
||||
const [offset = 0, offsetErr] = it(params.offset).expect.number().min(0).get();
|
||||
if (offsetErr) return rej('invalid offset param');
|
||||
|
||||
// Get 'max' parameter
|
||||
const [max, maxErr] = it(params.max).expect.number().range(1, 30).default(10).qed();
|
||||
const [max = 10, maxErr] = it(params.max).expect.number().range(1, 30).get();
|
||||
if (maxErr) return rej('invalid max param');
|
||||
|
||||
// If Elasticsearch is available, search by it
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
import Post from '../../models/post';
|
||||
import serialize from '../../serializers/post';
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
import Post from '../../models/post';
|
||||
import getFriends from '../../common/get-friends';
|
||||
import serialize from '../../serializers/post';
|
||||
@ -16,15 +16,15 @@ import serialize from '../../serializers/post';
|
||||
*/
|
||||
module.exports = (params, user, app) => new Promise(async (res, rej) => {
|
||||
// Get 'limit' parameter
|
||||
const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed();
|
||||
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get();
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'since_id' parameter
|
||||
const [sinceId, sinceIdErr] = it(params.since_id).expect.id().qed();
|
||||
const [sinceId, sinceIdErr] = it(params.since_id).expect.id().get();
|
||||
if (sinceIdErr) return rej('invalid since_id param');
|
||||
|
||||
// Get 'max_id' parameter
|
||||
const [maxId, maxIdErr] = it(params.max_id).expect.id().qed();
|
||||
const [maxId, maxIdErr] = it(params.max_id).expect.id().get();
|
||||
if (maxIdErr) return rej('invalid max_id param');
|
||||
|
||||
// Check if both of since_id and max_id is specified
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
import User from '../../models/user';
|
||||
import { validateUsername } from '../../models/user';
|
||||
|
||||
@ -13,7 +13,7 @@ import { validateUsername } from '../../models/user';
|
||||
*/
|
||||
module.exports = async (params) => new Promise(async (res, rej) => {
|
||||
// Get 'username' parameter
|
||||
const [username, usernameError] = it(params.username).expect.string().required().trim().validate(validateUsername).qed();
|
||||
const [username, usernameError] = it(params.username).expect.string().required().trim().validate(validateUsername).get();
|
||||
if (usernameError) return rej('invalid username param');
|
||||
|
||||
// Get exist
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../it';
|
||||
import it from 'cafy';
|
||||
import User from '../models/user';
|
||||
import serialize from '../serializers/user';
|
||||
|
||||
@ -14,15 +14,15 @@ import serialize from '../serializers/user';
|
||||
*/
|
||||
module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
// Get 'limit' parameter
|
||||
const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed();
|
||||
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get();
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'since_id' parameter
|
||||
const [sinceId, sinceIdErr] = it(params.since_id).expect.id().qed();
|
||||
const [sinceId, sinceIdErr] = it(params.since_id).expect.id().get();
|
||||
if (sinceIdErr) return rej('invalid since_id param');
|
||||
|
||||
// Get 'max_id' parameter
|
||||
const [maxId, maxIdErr] = it(params.max_id).expect.id().qed();
|
||||
const [maxId, maxIdErr] = it(params.max_id).expect.id().get();
|
||||
if (maxIdErr) return rej('invalid max_id param');
|
||||
|
||||
// Check if both of since_id and max_id is specified
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
import User from '../../models/user';
|
||||
import Following from '../../models/following';
|
||||
import serialize from '../../serializers/user';
|
||||
@ -20,15 +20,15 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
if (userIdErr) return rej('invalid user_id param');
|
||||
|
||||
// Get 'iknow' parameter
|
||||
const [iknow, iknowErr] = it(params.iknow).expect.boolean().default(false).qed();
|
||||
const [iknow = false, iknowErr] = it(params.iknow).expect.boolean().get();
|
||||
if (iknowErr) return rej('invalid iknow param');
|
||||
|
||||
// Get 'limit' parameter
|
||||
const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed();
|
||||
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get();
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'cursor' parameter
|
||||
const [cursor, cursorErr] = it(params.cursor).expect.id().default(null).qed();
|
||||
const [cursor = null, cursorErr] = it(params.cursor).expect.id().get();
|
||||
if (cursorErr) return rej('invalid cursor param');
|
||||
|
||||
// Lookup user
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
import User from '../../models/user';
|
||||
import Following from '../../models/following';
|
||||
import serialize from '../../serializers/user';
|
||||
@ -20,15 +20,15 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
if (userIdErr) return rej('invalid user_id param');
|
||||
|
||||
// Get 'iknow' parameter
|
||||
const [iknow, iknowErr] = it(params.iknow).expect.boolean().default(false).qed();
|
||||
const [iknow = false, iknowErr] = it(params.iknow).expect.boolean(.get();
|
||||
if (iknowErr) return rej('invalid iknow param');
|
||||
|
||||
// Get 'limit' parameter
|
||||
const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed();
|
||||
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get();
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'cursor' parameter
|
||||
const [cursor, cursorErr] = it(params.cursor).expect.id().default(null).qed();
|
||||
const [cursor = null, cursorErr] = it(params.cursor).expect.id().get();
|
||||
if (cursorErr) return rej('invalid cursor param');
|
||||
|
||||
// Lookup user
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
import Post from '../../models/post';
|
||||
import User from '../../models/user';
|
||||
import serialize from '../../serializers/post';
|
||||
@ -27,23 +27,23 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
}
|
||||
|
||||
// Get 'include_replies' parameter
|
||||
const [includeReplies, includeRepliesErr] = it(params.include_replies).expect.boolean().default(true).qed();
|
||||
const [includeReplies = true, includeRepliesErr] = it(params.include_replies).expect.boolean().get();
|
||||
if (includeRepliesErr) return rej('invalid include_replies param');
|
||||
|
||||
// Get 'with_media' parameter
|
||||
const [withMedia, withMediaErr] = it(params.with_media).expect.boolean().default(false).qed();
|
||||
const [withMedia = false, withMediaErr] = it(params.with_media).expect.boolean().get();
|
||||
if (withMediaErr) return rej('invalid with_media param');
|
||||
|
||||
// Get 'limit' parameter
|
||||
const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed();
|
||||
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get();
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'since_id' parameter
|
||||
const [sinceId, sinceIdErr] = it(params.since_id).expect.id().qed();
|
||||
const [sinceId, sinceIdErr] = it(params.since_id).expect.id().get();
|
||||
if (sinceIdErr) return rej('invalid since_id param');
|
||||
|
||||
// Get 'max_id' parameter
|
||||
const [maxId, maxIdErr] = it(params.max_id).expect.id().qed();
|
||||
const [maxId, maxIdErr] = it(params.max_id).expect.id().get();
|
||||
if (maxIdErr) return rej('invalid max_id param');
|
||||
|
||||
// Check if both of since_id and max_id is specified
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
import User from '../../models/user';
|
||||
import serialize from '../../serializers/user';
|
||||
import getFriends from '../../common/get-friends';
|
||||
@ -15,11 +15,11 @@ import getFriends from '../../common/get-friends';
|
||||
*/
|
||||
module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
// Get 'limit' parameter
|
||||
const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed();
|
||||
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get();
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'offset' parameter
|
||||
const [offset, offsetErr] = it(params.offset).expect.number().min(0).default(0).qed();
|
||||
const [offset = 0, offsetErr] = it(params.offset).expect.number().min(0).get();
|
||||
if (offsetErr) return rej('invalid offset param');
|
||||
|
||||
// ID list of the user itself and other users who the user follows
|
||||
|
@ -2,7 +2,7 @@
|
||||
* Module dependencies
|
||||
*/
|
||||
import * as mongo from 'mongodb';
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
import User from '../../models/user';
|
||||
import serialize from '../../serializers/user';
|
||||
import config from '../../../conf';
|
||||
@ -17,15 +17,15 @@ const escapeRegexp = require('escape-regexp');
|
||||
*/
|
||||
module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
// Get 'query' parameter
|
||||
const [query, queryError] = it(params.query).expect.string().required().trim().validate(x => x != '').qed();
|
||||
const [query, queryError] = it(params.query).expect.string().required().trim().validate(x => x != '').get();
|
||||
if (queryError) return rej('invalid query param');
|
||||
|
||||
// Get 'offset' parameter
|
||||
const [offset, offsetErr] = it(params.offset).expect.number().min(0).default(0).qed();
|
||||
const [offset = 0, offsetErr] = it(params.offset).expect.number().min(0).get();
|
||||
if (offsetErr) return rej('invalid offset param');
|
||||
|
||||
// Get 'max' parameter
|
||||
const [max, maxErr] = it(params.max).expect.number().range(1, 30).default(10).qed();
|
||||
const [max = 10, maxErr] = it(params.max).expect.number().range(1, 30).get();
|
||||
if (maxErr) return rej('invalid max param');
|
||||
|
||||
// If Elasticsearch is available, search by it
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
import User from '../../models/user';
|
||||
import { validateUsername } from '../../models/user';
|
||||
import serialize from '../../serializers/user';
|
||||
@ -15,15 +15,15 @@ import serialize from '../../serializers/user';
|
||||
*/
|
||||
module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
// Get 'query' parameter
|
||||
const [query, queryError] = it(params.query).expect.string().required().trim().validate(validateUsername).qed();
|
||||
const [query, queryError] = it(params.query).expect.string().required().trim().validate(validateUsername).get();
|
||||
if (queryError) return rej('invalid query param');
|
||||
|
||||
// Get 'offset' parameter
|
||||
const [offset, offsetErr] = it(params.offset).expect.number().min(0).default(0).qed();
|
||||
const [offset = 0, offsetErr] = it(params.offset).expect.number().min(0).get();
|
||||
if (offsetErr) return rej('invalid offset param');
|
||||
|
||||
// Get 'limit' parameter
|
||||
const [limit, limitErr] = it(params.limit).expect.number().range(1, 100).default(10).qed();
|
||||
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get();
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
const users = await User
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import it from '../../it';
|
||||
import it from 'cafy';
|
||||
import User from '../../models/user';
|
||||
import serialize from '../../serializers/user';
|
||||
|
||||
|
584
src/api/it.ts
584
src/api/it.ts
@ -1,584 +0,0 @@
|
||||
/**
|
||||
* it
|
||||
* 楽しいバリデーション
|
||||
*/
|
||||
|
||||
/**
|
||||
* Usage Examples
|
||||
*
|
||||
* const [val, err] = it(x).must.be.a.string().or('asc desc').default('desc').qed();
|
||||
* → xは文字列でなければならず、'asc'または'desc'でなければならない。省略された場合のデフォルトは'desc'とする。
|
||||
*
|
||||
* const [val, err] = it(x).must.be.a.number().required().range(0, 100).qed();
|
||||
* → xは数値でなければならず、かつ0~100の範囲内でなければならない。この値は省略することはできない。
|
||||
*
|
||||
* const [val, err] = it(x).must.be.an.array().unique().required().validate(x => x[0] != 'strawberry pasta').qed();
|
||||
* → xは配列でなければならず、かつ中身が重複していてはならない。この値を省略することはできない。そして配列の最初の要素が'strawberry pasta'という文字列であってはならない。
|
||||
*
|
||||
* ・意味的に矛盾するので、required と default は併用できません。
|
||||
*
|
||||
* ~糖衣構文~
|
||||
* const [val, err] = it(x).must.be.a.string().required().qed();
|
||||
* は
|
||||
* const [val, err] = it(x, 'string', true);
|
||||
* と書けます
|
||||
*
|
||||
* ~BDD風記法~
|
||||
* must.be.a(n) の代わりに expect とも書けます:
|
||||
* const [val, err] = it(x).expect.string().required().qed();
|
||||
*/
|
||||
|
||||
/**
|
||||
* null と undefined の扱い
|
||||
*
|
||||
* 「値が null または undefined」な状態を「値が空である」と表現しています。
|
||||
* 値が空である場合、バリデータやその他の処理メソッドは呼ばれません。
|
||||
*
|
||||
* 内部的には null と undefined を次のように区別しています:
|
||||
* null ... 値が「無い」と明示されている
|
||||
* undefined ... 値を指定していない
|
||||
*
|
||||
* 例えばアカウントのプロフィールを更新するAPIに次のデータを含むリクエストが来たとします:
|
||||
* { name: 'Alice' }
|
||||
* アカウントには本来、他にも birthday といったフィールドがありますが、
|
||||
* このリクエストではそれに触れず、ただ単に name フィールドを更新することを要求しています。
|
||||
* ここで、このリクエストにおける birthday フィールドは undefined なわけですが、
|
||||
* それはnull(=birthdayを未設定にしたい)とは違うものです。
|
||||
* undefined も null も区別しないとしたら、触れていないフィールドまでリセットされることになってしまいます。
|
||||
* ですので、undefined と null は区別しています。
|
||||
*
|
||||
* 明示的に null を許可しない限り、null はエラーになります。
|
||||
* null を許可する場合は nullable をプリフィックスします:
|
||||
* const [val, err] = it(x).must.be.a.nullable.string().required().qed();
|
||||
*/
|
||||
|
||||
import * as mongo from 'mongodb';
|
||||
import hasDuplicates from '../common/has-duplicates';
|
||||
|
||||
type Validator<T> = (value: T) => boolean | Error;
|
||||
|
||||
/**
|
||||
* クエリベース
|
||||
*/
|
||||
abstract class Query {
|
||||
protected value: any;
|
||||
protected error: Error;
|
||||
|
||||
constructor(value: any, nullable: boolean = false) {
|
||||
if (value === null && !nullable) {
|
||||
this.value = undefined;
|
||||
this.error = new Error('must-be-not-a-null');
|
||||
} else {
|
||||
this.value = value;
|
||||
this.error = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected get isUndefined() {
|
||||
return this.value === undefined;
|
||||
}
|
||||
|
||||
protected get isNull() {
|
||||
return this.value === null;
|
||||
}
|
||||
|
||||
protected get isEmpty() {
|
||||
return this.isUndefined || this.isNull;
|
||||
}
|
||||
|
||||
/**
|
||||
* このインスタンスの値が空、またはエラーが存在しているなどして、処理をスキップするべきか否か
|
||||
*/
|
||||
protected get shouldSkip() {
|
||||
return this.error !== null || this.isEmpty;
|
||||
}
|
||||
|
||||
/**
|
||||
* このインスタンスの値が指定されていない(=undefined)ときにエラーにします
|
||||
*/
|
||||
required() {
|
||||
if (this.error === null && this.isUndefined) {
|
||||
this.error = new Error('required');
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* このインスタンスの値が設定されていない(=undefined)ときにデフォルトで設定する値を設定します
|
||||
*/
|
||||
default(value: any) {
|
||||
if (this.isUndefined) {
|
||||
this.value = value;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* このインスタンスの値およびエラーを取得します
|
||||
* *qedはQ.E.D.でもあり'QueryEnD'の略でもある
|
||||
*/
|
||||
qed(): [any, Error] {
|
||||
return [this.value, this.error];
|
||||
}
|
||||
|
||||
/**
|
||||
* このインスタンスの値に対して妥当性を検証します
|
||||
* バリデータが false またはエラーを返した場合エラーにします
|
||||
* @param validator バリデータ
|
||||
*/
|
||||
validate(validator: Validator<any>) {
|
||||
if (this.shouldSkip) return this;
|
||||
const result = validator(this.value);
|
||||
if (result === false) {
|
||||
this.error = new Error('invalid-format');
|
||||
} else if (result instanceof Error) {
|
||||
this.error = result;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
class BooleanQuery extends Query {
|
||||
value: boolean;
|
||||
error: Error;
|
||||
|
||||
constructor(value: any, nullable: boolean = false) {
|
||||
super(value, nullable);
|
||||
if (!this.isEmpty && typeof value != 'boolean') {
|
||||
this.error = new Error('must-be-a-boolean');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* このインスタンスの値が設定されていないときにデフォルトで設定する値を設定します
|
||||
*/
|
||||
default(value: boolean) {
|
||||
return super.default(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* このインスタンスの値およびエラーを取得します
|
||||
*/
|
||||
qed(): [boolean, Error] {
|
||||
return super.qed();
|
||||
}
|
||||
|
||||
/**
|
||||
* このインスタンスの値に対して妥当性を検証します
|
||||
* バリデータが false またはエラーを返した場合エラーにします
|
||||
* @param validator バリデータ
|
||||
*/
|
||||
validate(validator: Validator<boolean>) {
|
||||
return super.validate(validator);
|
||||
}
|
||||
}
|
||||
|
||||
class NumberQuery extends Query {
|
||||
value: number;
|
||||
error: Error;
|
||||
|
||||
constructor(value: any, nullable: boolean = false) {
|
||||
super(value, nullable);
|
||||
if (!this.isEmpty && !Number.isFinite(value)) {
|
||||
this.error = new Error('must-be-a-number');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 値が指定された範囲内にない場合エラーにします
|
||||
* @param min 下限
|
||||
* @param max 上限
|
||||
*/
|
||||
range(min: number, max: number) {
|
||||
if (this.shouldSkip) return this;
|
||||
if (this.value < min || this.value > max) {
|
||||
this.error = new Error('invalid-range');
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* このインスタンスの値が指定された下限より下回っている場合エラーにします
|
||||
* @param value 下限
|
||||
*/
|
||||
min(value: number) {
|
||||
if (this.shouldSkip) return this;
|
||||
if (this.value < value) {
|
||||
this.error = new Error('invalid-range');
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* このインスタンスの値が指定された上限より上回っている場合エラーにします
|
||||
* @param value 上限
|
||||
*/
|
||||
max(value: number) {
|
||||
if (this.shouldSkip) return this;
|
||||
if (this.value > value) {
|
||||
this.error = new Error('invalid-range');
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* このインスタンスの値が設定されていないときにデフォルトで設定する値を設定します
|
||||
*/
|
||||
default(value: number) {
|
||||
return super.default(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* このインスタンスの値およびエラーを取得します
|
||||
*/
|
||||
qed(): [number, Error] {
|
||||
return super.qed();
|
||||
}
|
||||
|
||||
/**
|
||||
* このインスタンスの値に対して妥当性を検証します
|
||||
* バリデータが false またはエラーを返した場合エラーにします
|
||||
* @param validator バリデータ
|
||||
*/
|
||||
validate(validator: Validator<number>) {
|
||||
return super.validate(validator);
|
||||
}
|
||||
}
|
||||
|
||||
class StringQuery extends Query {
|
||||
value: string;
|
||||
error: Error;
|
||||
|
||||
constructor(value: any, nullable: boolean = false) {
|
||||
super(value, nullable);
|
||||
if (!this.isEmpty && typeof value != 'string') {
|
||||
this.error = new Error('must-be-a-string');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 文字数が指定された範囲内にない場合エラーにします
|
||||
* @param min 下限
|
||||
* @param max 上限
|
||||
*/
|
||||
range(min: number, max: number) {
|
||||
if (this.shouldSkip) return this;
|
||||
if (this.value.length < min || this.value.length > max) {
|
||||
this.error = new Error('invalid-range');
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
trim() {
|
||||
if (this.shouldSkip) return this;
|
||||
this.value = this.value.trim();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* このインスタンスの値が設定されていないときにデフォルトで設定する値を設定します
|
||||
*/
|
||||
default(value: string) {
|
||||
return super.default(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* このインスタンスの値およびエラーを取得します
|
||||
*/
|
||||
qed(): [string, Error] {
|
||||
return super.qed();
|
||||
}
|
||||
|
||||
/**
|
||||
* このインスタンスの値に対して妥当性を検証します
|
||||
* バリデータが false またはエラーを返した場合エラーにします
|
||||
* @param validator バリデータ
|
||||
*/
|
||||
validate(validator: Validator<string>) {
|
||||
return super.validate(validator);
|
||||
}
|
||||
|
||||
/**
|
||||
* このインスタンスの文字列が、与えられたパターン内の文字列のどれかと一致するか検証します
|
||||
* どれとも一致しない場合エラーにします
|
||||
* @param pattern 文字列の配列またはスペースで区切られた文字列
|
||||
*/
|
||||
or(pattern: string | string[]) {
|
||||
if (this.shouldSkip) return this;
|
||||
if (typeof pattern == 'string') pattern = pattern.split(' ');
|
||||
const match = pattern.some(x => x === this.value);
|
||||
if (!match) this.error = new Error('not-match-pattern');
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* このインスタンスの文字列が、与えられた正規表現と一致するか検証します
|
||||
* 一致しない場合エラーにします
|
||||
* @param pattern 正規表現
|
||||
*/
|
||||
match(pattern: RegExp) {
|
||||
if (this.shouldSkip) return this;
|
||||
if (!pattern.test(this.value)) this.error = new Error('not-match-pattern');
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
class ArrayQuery extends Query {
|
||||
value: any[];
|
||||
error: Error;
|
||||
|
||||
constructor(value: any, nullable: boolean = false) {
|
||||
super(value, nullable);
|
||||
if (!this.isEmpty && !Array.isArray(value)) {
|
||||
this.error = new Error('must-be-an-array');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 配列の値がユニークでない場合(=重複した項目がある場合)エラーにします
|
||||
*/
|
||||
unique() {
|
||||
if (this.shouldSkip) return this;
|
||||
if (hasDuplicates(this.value)) {
|
||||
this.error = new Error('must-be-unique');
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 配列の長さが指定された範囲内にない場合エラーにします
|
||||
* @param min 下限
|
||||
* @param max 上限
|
||||
*/
|
||||
range(min: number, max: number) {
|
||||
if (this.shouldSkip) return this;
|
||||
if (this.value.length < min || this.value.length > max) {
|
||||
this.error = new Error('invalid-range');
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* このインスタンスの配列内の要素すべてが文字列であるか検証します
|
||||
* ひとつでも文字列以外の要素が存在する場合エラーにします
|
||||
*/
|
||||
allString() {
|
||||
if (this.shouldSkip) return this;
|
||||
if (this.value.some(x => typeof x != 'string')) {
|
||||
this.error = new Error('dirty-array');
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* このインスタンスの値が設定されていないときにデフォルトで設定する値を設定します
|
||||
*/
|
||||
default(value: any[]) {
|
||||
return super.default(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* このインスタンスの値およびエラーを取得します
|
||||
*/
|
||||
qed(): [any[], Error] {
|
||||
return super.qed();
|
||||
}
|
||||
|
||||
/**
|
||||
* このインスタンスの値に対して妥当性を検証します
|
||||
* バリデータが false またはエラーを返した場合エラーにします
|
||||
* @param validator バリデータ
|
||||
*/
|
||||
validate(validator: Validator<any[]>) {
|
||||
return super.validate(validator);
|
||||
}
|
||||
}
|
||||
|
||||
class IdQuery extends Query {
|
||||
value: mongo.ObjectID;
|
||||
error: Error;
|
||||
|
||||
constructor(value: any, nullable: boolean = false) {
|
||||
super(value, nullable);
|
||||
if (!this.isEmpty && (typeof value != 'string' || !mongo.ObjectID.isValid(value))) {
|
||||
this.error = new Error('must-be-an-id');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* このインスタンスの値が設定されていないときにデフォルトで設定する値を設定します
|
||||
*/
|
||||
default(value: mongo.ObjectID) {
|
||||
return super.default(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* このインスタンスの値およびエラーを取得します
|
||||
*/
|
||||
qed(): [mongo.ObjectID, Error] {
|
||||
return super.qed();
|
||||
}
|
||||
|
||||
/**
|
||||
* このインスタンスの値に対して妥当性を検証します
|
||||
* バリデータが false またはエラーを返した場合エラーにします
|
||||
* @param validator バリデータ
|
||||
*/
|
||||
validate(validator: Validator<mongo.ObjectID>) {
|
||||
return super.validate(validator);
|
||||
}
|
||||
}
|
||||
|
||||
class ObjectQuery extends Query {
|
||||
value: any;
|
||||
error: Error;
|
||||
|
||||
constructor(value: any, nullable: boolean = false) {
|
||||
super(value, nullable);
|
||||
if (!this.isEmpty && typeof value != 'object') {
|
||||
this.error = new Error('must-be-an-object');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* このインスタンスの値が設定されていないときにデフォルトで設定する値を設定します
|
||||
*/
|
||||
default(value: any) {
|
||||
return super.default(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* このインスタンスの値およびエラーを取得します
|
||||
*/
|
||||
qed(): [any, Error] {
|
||||
return super.qed();
|
||||
}
|
||||
|
||||
/**
|
||||
* このインスタンスの値に対して妥当性を検証します
|
||||
* バリデータが false またはエラーを返した場合エラーにします
|
||||
* @param validator バリデータ
|
||||
*/
|
||||
validate(validator: Validator<any>) {
|
||||
return super.validate(validator);
|
||||
}
|
||||
}
|
||||
|
||||
type It = {
|
||||
must: {
|
||||
be: {
|
||||
a: {
|
||||
string: () => StringQuery;
|
||||
number: () => NumberQuery;
|
||||
boolean: () => BooleanQuery;
|
||||
nullable: {
|
||||
string: () => StringQuery;
|
||||
number: () => NumberQuery;
|
||||
boolean: () => BooleanQuery;
|
||||
id: () => IdQuery;
|
||||
array: () => ArrayQuery;
|
||||
object: () => ObjectQuery;
|
||||
};
|
||||
};
|
||||
an: {
|
||||
id: () => IdQuery;
|
||||
array: () => ArrayQuery;
|
||||
object: () => ObjectQuery;
|
||||
};
|
||||
};
|
||||
};
|
||||
expect: {
|
||||
string: () => StringQuery;
|
||||
number: () => NumberQuery;
|
||||
boolean: () => BooleanQuery;
|
||||
id: () => IdQuery;
|
||||
array: () => ArrayQuery;
|
||||
object: () => ObjectQuery;
|
||||
nullable: {
|
||||
string: () => StringQuery;
|
||||
number: () => NumberQuery;
|
||||
boolean: () => BooleanQuery;
|
||||
id: () => IdQuery;
|
||||
array: () => ArrayQuery;
|
||||
object: () => ObjectQuery;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
const it = (value: any) => ({
|
||||
must: {
|
||||
be: {
|
||||
a: {
|
||||
string: () => new StringQuery(value),
|
||||
number: () => new NumberQuery(value),
|
||||
boolean: () => new BooleanQuery(value),
|
||||
nullable: {
|
||||
string: () => new StringQuery(value, true),
|
||||
number: () => new NumberQuery(value, true),
|
||||
boolean: () => new BooleanQuery(value, true),
|
||||
id: () => new IdQuery(value, true),
|
||||
array: () => new ArrayQuery(value, true),
|
||||
object: () => new ObjectQuery(value, true)
|
||||
}
|
||||
},
|
||||
an: {
|
||||
id: () => new IdQuery(value),
|
||||
array: () => new ArrayQuery(value),
|
||||
object: () => new ObjectQuery(value)
|
||||
}
|
||||
}
|
||||
},
|
||||
expect: {
|
||||
string: () => new StringQuery(value),
|
||||
number: () => new NumberQuery(value),
|
||||
boolean: () => new BooleanQuery(value),
|
||||
id: () => new IdQuery(value),
|
||||
array: () => new ArrayQuery(value),
|
||||
object: () => new ObjectQuery(value),
|
||||
nullable: {
|
||||
string: () => new StringQuery(value, true),
|
||||
number: () => new NumberQuery(value, true),
|
||||
boolean: () => new BooleanQuery(value, true),
|
||||
id: () => new IdQuery(value, true),
|
||||
array: () => new ArrayQuery(value, true),
|
||||
object: () => new ObjectQuery(value, true)
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
type Type = 'id' | 'string' | 'number' | 'boolean' | 'array' | 'set' | 'object';
|
||||
|
||||
function x(value: any): It;
|
||||
function x(value: any, type: 'id', isRequired?: boolean, validator?: Validator<mongo.ObjectID> | Validator<mongo.ObjectID>[]): [mongo.ObjectID, Error];
|
||||
function x(value: any, type: 'string', isRequired?: boolean, validator?: Validator<string> | Validator<string>[]): [string, Error];
|
||||
function x(value: any, type: 'number', isRequired?: boolean, validator?: Validator<number> | Validator<number>[]): [number, Error];
|
||||
function x(value: any, type: 'boolean', isRequired?: boolean): [boolean, Error];
|
||||
function x(value: any, type: 'array', isRequired?: boolean, validator?: Validator<any[]> | Validator<any[]>[]): [any[], Error];
|
||||
function x(value: any, type: 'set', isRequired?: boolean, validator?: Validator<any[]> | Validator<any[]>[]): [any[], Error];
|
||||
function x(value: any, type: 'object', isRequired?: boolean, validator?: Validator<any> | Validator<any>[]): [any, Error];
|
||||
function x(value: any, type?: Type, isRequired?: boolean, validator?: Validator<any> | Validator<any>[]): any {
|
||||
if (typeof type === 'undefined') return it(value);
|
||||
|
||||
let q: Query = null;
|
||||
|
||||
switch (type) {
|
||||
case 'id': q = it(value).expect.id(); break;
|
||||
case 'string': q = it(value).expect.string(); break;
|
||||
case 'number': q = it(value).expect.number(); break;
|
||||
case 'boolean': q = it(value).expect.boolean(); break;
|
||||
case 'array': q = it(value).expect.array(); break;
|
||||
case 'set': q = it(value).expect.array().unique(); break;
|
||||
case 'object': q = it(value).expect.object(); break;
|
||||
}
|
||||
|
||||
if (isRequired) q = q.required();
|
||||
|
||||
if (validator) {
|
||||
(Array.isArray(validator) ? validator : [validator])
|
||||
.forEach(v => q = q.validate(v));
|
||||
}
|
||||
|
||||
return q;
|
||||
}
|
||||
|
||||
export default x;
|
@ -1 +0,0 @@
|
||||
export default (array: any[]) => (new Set(array)).size !== array.length;
|
15
test/it.js
15
test/it.js
@ -1,15 +0,0 @@
|
||||
/**
|
||||
* it Tests!
|
||||
*/
|
||||
|
||||
const assert = require('assert');
|
||||
|
||||
const _it = require('../built/api/it').default;
|
||||
/*
|
||||
describe('it', () => {
|
||||
it('it must be a string', () => {
|
||||
const [val, err] = _it(42).must.be.a.string().qed();
|
||||
assert.eql
|
||||
});
|
||||
});
|
||||
*/
|
Loading…
Reference in New Issue
Block a user