当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript cafy.array函数代码示例

本文整理汇总了TypeScript中cafy.array函数的典型用法代码示例。如果您正苦于以下问题:TypeScript array函数的具体用法?TypeScript array怎么用?TypeScript array使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了array函数的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');
	}

};
开发者ID:Frost-Dev,项目名称:Frost,代码行数:16,代码来源:verifyApiConfig.ts

示例2: default

export default (config: IWebAppConfig): void => {

	// verify webapp config
	const verificationConfig = $.obj({
		apiBaseUrl: $.str,
		hostToken: $.obj({
			accessToken: $.str
		}),
		clientToken: $.obj({
			scopes: $.array($.str).unique()
		}),
		recaptcha: $.obj({
			enable: $.boolean,
			siteKey: $.str,
			secretKey: $.str
		})
	});
	if (verificationConfig.nok(config)) {
		throw new Error('invalid webapp config');
	}

};
开发者ID:Frost-Dev,项目名称:Frost,代码行数:22,代码来源:verifyWebAppConfig.ts

示例3: define

import $ from 'cafy';
import { define, AuthScopes, ApiErrorSources } from '../../modules/endpoint';
import { ObjectIdContext } from '../../modules/cafyValidators';
import { PostingResponseObject } from '../../modules/apiResponse/responseObjects';
import { ChatPostingDocument } from '../../modules/documents';

export default define({
	params: {
		text: $.str.range(1, 256).notMatch(/^\s*$/),
		attachmentIds: $.array($.type(ObjectIdContext)).optional,
	},
	scopes: [AuthScopes.postingWrite]
}, async (manager) => {

	const account = manager.authInfo!.user;

	// params
	const text: string = manager.params.text;
	const attachmentIds: string[] | undefined = manager.params.attachmentIds;

	let chatPostingDoc: ChatPostingDocument;
	try {
		chatPostingDoc = await manager.postingService.createChatPosting(account._id, text, attachmentIds);
	}
	catch (err) {
		console.error(err);
		manager.error(ApiErrorSources.serverError, { message: 'failed to create an chat posting' });
		return;
	}

	await chatPostingDoc.populate(manager.db);
开发者ID:Frost-Dev,项目名称:Frost,代码行数:31,代码来源:create-chat.ts

示例4: 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);
开发者ID:Frost-Dev,项目名称:Frost,代码行数:31,代码来源:create.ts

示例5: define

import $ from 'cafy';
import { define, AuthScopes, ApiErrorSources } from '../../../modules/endpoint';
import { TokenResponseObject } from '../../../modules/apiResponse/responseObjects';
import { TokenDocument } from '../../../modules/documents';
import { ObjectIdContext } from '../../../modules/cafyValidators';

export default define({
	params: {
		appId: $.type(ObjectIdContext).optional,
		userId: $.type(ObjectIdContext).optional,
		scopes: $.array($.str).optional.unique(),
		accessToken: $.str.optional // TODO
	},
	scopes: [AuthScopes.authHost]
}, async (manager) => {

	// params
	const appId: string | undefined = manager.params.appId;
	const userId: string | undefined = manager.params.userId;
	const scopes: string[] | undefined = manager.params.scopes;
	const accessToken: string | undefined = manager.params.accessToken;

	let tokenDoc: TokenDocument | null;
	if (accessToken) {
		tokenDoc = await manager.tokenService.findByAccessToken(accessToken);
	}
	else {
		if (!appId) {
			manager.error(ApiErrorSources.missingParam, { paramName: 'appId' });
			return;
		}
开发者ID:Frost-Dev,项目名称:Frost,代码行数:31,代码来源:get.ts

示例6: define

import $ from 'cafy';
import { define, AuthScopes, ApiErrorSources } from '../../../modules/endpoint';
import { TokenResponseObject } from '../../../modules/apiResponse/responseObjects';
import { IAppDocument, IUserDocument, AppDocument, TokenDocument } from '../../../modules/documents';
import { ObjectIdContext } from '../../../modules/cafyValidators';

export default define({
	params: {
		appId: $.type(ObjectIdContext),
		userId: $.type(ObjectIdContext),
		scopes: $.array($.str).unique()
	},
	scopes: [AuthScopes.authHost]
}, async (manager) => {

	// params
	const appId: string = manager.params.appId;
	const userId: string = manager.params.userId;
	const scopes: string[] = manager.params.scopes;

	const appDocRaw: IAppDocument = await manager.db.findById('api.apps', appId);
	if (!appDocRaw) {
		manager.error(ApiErrorSources.appNotFound);
		return;
	}
	const appDoc = new AppDocument(appDocRaw);

	const userDocRaw: IUserDocument = await manager.db.findById('api.users', userId);
	if (!userDocRaw) {
		manager.error(ApiErrorSources.userNotFound);
		return;
开发者ID:Frost-Dev,项目名称:Frost,代码行数:31,代码来源:create.ts


注:本文中的cafy.array函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。