本文整理汇总了TypeScript中cafy.arr函数的典型用法代码示例。如果您正苦于以下问题:TypeScript arr函数的具体用法?TypeScript arr怎么用?TypeScript arr使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了arr函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: default
export default (params: any, me: ILocalUser) => new Promise(async (res, rej) => {
let user;
// Get 'userId' parameter
const [userId, userIdErr] = $.type(ID).optional.get(params.userId);
if (userIdErr) return rej('invalid userId param');
// Get 'userIds' parameter
const [userIds, userIdsErr] = $.arr($.type(ID)).optional.get(params.userIds);
if (userIdsErr) return rej('invalid userIds param');
// Get 'username' parameter
const [username, usernameErr] = $.str.optional.get(params.username);
if (usernameErr) return rej('invalid username param');
// Get 'host' parameter
const [host, hostErr] = $.str.optional.nullable.get(params.host);
if (hostErr) return rej('invalid host param');
if (userIds) {
const users = await User.find({
_id: {
$in: userIds
}
});
res(await Promise.all(users.map(u => pack(u, me, {
detail: true
}))));
} else {
// Lookup user
if (typeof host === 'string') {
try {
user = await resolveRemoteUser(username, host, cursorOption);
} catch (e) {
console.warn(`failed to resolve remote user: ${e}`);
return rej('failed to resolve remote user');
}
} else {
const q: any = userId !== undefined
? { _id: userId }
: { usernameLower: username.toLowerCase(), host: null };
user = await User.findOne(q, cursorOption);
if (user === null) {
return rej('user not found');
}
}
// Send response
res(await pack(user, me, {
detail: true
}));
}
});
示例2: async
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
// Get 'home' parameter
const [home, homeErr] = $.arr($.obj({
name: $.str,
id: $.str,
data: $.obj()
}).strict()).get(params.home);
if (homeErr) return rej('invalid home param');
await User.update(user._id, {
$set: {
'clientSettings.mobileHome': home
}
});
res();
publishUserStream(user._id, 'mobile_home_updated', home);
});
示例3: async
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
// Get 'nameId' parameter
const [nameId, nameIdErr] = $.str.pipe(isValidNameId).get(params.nameId);
if (nameIdErr) return rej('invalid nameId param');
// Get 'name' parameter
const [name, nameErr] = $.str.get(params.name);
if (nameErr) return rej('invalid name param');
// Get 'description' parameter
const [description, descriptionErr] = $.str.get(params.description);
if (descriptionErr) return rej('invalid description param');
// Get 'permission' parameter
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] = $.str.optional.nullable.get(params.callbackUrl);
if (callbackUrlErr) return rej('invalid callbackUrl param');
// Generate secret
const secret = rndstr('a-zA-Z0-9', 32);
// Create account
const app = await App.insert({
createdAt: new Date(),
userId: user && user._id,
name: name,
nameId: nameId,
nameIdLower: nameId.toLowerCase(),
description: description,
permission: permission,
callbackUrl: callbackUrl,
secret: secret
});
// Response
res(await pack(app));
});
示例4: ms
duration: ms('1hour'),
max: 300,
minInterval: ms('1second')
},
kind: 'note-write',
params: {
visibility: $.str.optional.or(['public', 'home', 'followers', 'specified', 'private']).note({
default: 'public',
desc: {
ja: '投稿の公開範囲'
}
}),
visibleUserIds: $.arr($.type(ID)).optional.unique().min(1).note({
desc: {
ja: '(投稿の公開範囲が specified の場合)投稿を閲覧できるユーザー'
}
}),
text: $.str.optional.nullable.pipe(isValidText).note({
default: null,
desc: {
ja: '投稿内容'
}
}),
cw: $.str.optional.nullable.pipe(isValidCw).note({
desc: {
ja: 'コンテンツの警告。このパラメータを指定すると設定したテキストで投稿のコンテンツを隠す事が出来ます。'
示例5: default
export default (params: any, me: ILocalUser) => new Promise(async (res, rej) => {
// Get 'tag' parameter
const [tag, tagError] = $.str.get(params.tag);
if (tagError) return rej('invalid tag param');
// Get 'includeUserIds' parameter
const [includeUserIds = [], includeUserIdsErr] = $.arr($.type(ID)).optional.get(params.includeUserIds);
if (includeUserIdsErr) return rej('invalid includeUserIds param');
// Get 'excludeUserIds' parameter
const [excludeUserIds = [], excludeUserIdsErr] = $.arr($.type(ID)).optional.get(params.excludeUserIds);
if (excludeUserIdsErr) return rej('invalid excludeUserIds param');
// Get 'includeUserUsernames' parameter
const [includeUserUsernames = [], includeUserUsernamesErr] = $.arr($.str).optional.get(params.includeUserUsernames);
if (includeUserUsernamesErr) return rej('invalid includeUserUsernames param');
// Get 'excludeUserUsernames' parameter
const [excludeUserUsernames = [], excludeUserUsernamesErr] = $.arr($.str).optional.get(params.excludeUserUsernames);
if (excludeUserUsernamesErr) return rej('invalid excludeUserUsernames param');
// Get 'following' parameter
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] = $.str.optional.get(params.mute);
if (muteErr) return rej('invalid mute param');
// Get 'reply' parameter
const [reply = null, replyErr] = $.bool.optional.nullable.get(params.reply);
if (replyErr) return rej('invalid reply param');
// Get 'renote' parameter
const [renote = null, renoteErr] = $.bool.optional.nullable.get(params.renote);
if (renoteErr) return rej('invalid renote param');
// Get 'media' parameter
const [media = null, mediaErr] = $.bool.optional.nullable.get(params.media);
if (mediaErr) return rej('invalid media param');
// Get 'poll' parameter
const [poll = null, pollErr] = $.bool.optional.nullable.get(params.poll);
if (pollErr) return rej('invalid poll param');
// Get 'sinceDate' parameter
const [sinceDate, sinceDateErr] = $.num.optional.get(params.sinceDate);
if (sinceDateErr) throw 'invalid sinceDate param';
// Get 'untilDate' parameter
const [untilDate, untilDateErr] = $.num.optional.get(params.untilDate);
if (untilDateErr) throw 'invalid untilDate param';
// Get 'offset' parameter
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] = $.num.optional.range(1, 30).get(params.limit);
if (limitErr) return rej('invalid limit param');
if (includeUserUsernames != null) {
const ids = (await Promise.all(includeUserUsernames.map(async (username) => {
const _user = await User.findOne({
usernameLower: username.toLowerCase()
});
return _user ? _user._id : null;
}))).filter(id => id != null);
ids.forEach(id => includeUserIds.push(id));
}
if (excludeUserUsernames != null) {
const ids = (await Promise.all(excludeUserUsernames.map(async (username) => {
const _user = await User.findOne({
usernameLower: username.toLowerCase()
});
return _user ? _user._id : null;
}))).filter(id => id != null);
ids.forEach(id => excludeUserIds.push(id));
}
let q: any = {
$and: [{
tagsLower: tag.toLowerCase()
}]
};
const push = (x: any) => q.$and.push(x);
if (includeUserIds && includeUserIds.length != 0) {
push({
userId: {
$in: includeUserIds
}
});
} else if (excludeUserIds && excludeUserIds.length != 0) {
push({
userId: {
//.........这里部分代码省略.........