本文整理汇总了TypeScript中cafy.str.pipe方法的典型用法代码示例。如果您正苦于以下问题:TypeScript str.pipe方法的具体用法?TypeScript str.pipe怎么用?TypeScript str.pipe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cafy.str
的用法示例。
在下文中一共展示了str.pipe方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: default
export default (config: IApiConfig): void => {
const allScopes = AuthScopes.toArray();
// verify api config
const verificationConfig = $.obj({
appSecretKey: $.str,
hostToken: $.obj({
scopes: $.array($.str.pipe(scope => allScopes.find(s => s.id == scope) != null)).unique()
})
});
if (verificationConfig.nok(config)) {
throw new Error('invalid api config');
}
};
示例2: async
export default async (params: any) => 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 exist
const exist = await App
.count({
nameIdLower: nameId.toLowerCase()
}, {
limit: 1
});
// Reply
res({
available: exist === 0
});
});
示例3: async
export default async (params: any) => new Promise(async (res, rej) => {
// Get 'username' parameter
const [username, usernameError] = $.str.pipe(validateUsername).get(params.username);
if (usernameError) return rej('invalid username param');
// Get exist
const exist = await User
.count({
host: null,
usernameLower: username.toLowerCase()
}, {
limit: 1
});
// Reply
res({
available: exist === 0
});
});
示例4: 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));
});
示例5: isAvailableScope
import $ from 'cafy';
import { define, AuthScopes, ApiErrorSources } from '../../modules/endpoint';
import { AppResponseObject } from '../../modules/apiResponse/responseObjects';
import { AppDocument } from '../../modules/documents';
function isAvailableScope(scopeId: string): boolean {
const scope = AuthScopes.toArray().find(s => s.id == scopeId);
return scope != null && scope.grantable;
}
export default define({
params: {
name: $.str.range(1, 32),
description: $.str.optional.max(256),
scopes: $.array($.str.pipe(scope => isAvailableScope(scope))).optional.unique()
},
scopes: [AuthScopes.appCreate]
}, async (manager) => {
const account = manager.authInfo!.user;
// params
const name: string = manager.params.name;
const description: string = manager.params.description || '';
const scopes: string[] = manager.params.scopes || [];
// if app name is duplicated
const tempApp = await manager.db.find('api.apps', { name: name });
if (tempApp) {
manager.error(ApiErrorSources.duplicatedAppName);
示例6: default
ja: '指定した投稿にリアクションします。',
en: 'React to a note.'
},
requireCredential: true,
kind: 'reaction-write',
params: {
noteId: $.type(ID).note({
desc: {
ja: '対象の投稿'
}
}),
reaction: $.str.pipe(validateReaction.ok).note({
desc: {
ja: 'リアクションの種類'
}
})
}
};
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// Fetch reactee
const note = await Note.findOne({
_id: ps.noteId
});