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


TypeScript cafy.type函数代码示例

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


在下文中一共展示了type函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: default

export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
	// Get 'noteId' parameter
	const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
	if (noteIdErr) return rej('invalid noteId param');

	// Get favoritee
	const note = await Note.findOne({
		_id: noteId
	});

	if (note === null) {
		return rej('note not found');
	}

	// if already favorited
	const exist = await Favorite.findOne({
		noteId: note._id,
		userId: user._id
	});

	if (exist !== null) {
		return rej('already favorited');
	}

	// Create favorite
	await Favorite.insert({
		createdAt: new Date(),
		noteId: note._id,
		userId: user._id
	});

	// Send response
	res();
});
开发者ID:ha-dai,项目名称:Misskey,代码行数:34,代码来源:create.ts

示例2: default

export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
	// Get 'noteId' parameter
	const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
	if (noteIdErr) return rej('invalid noteId param');

	// Get 'limit' parameter
	const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
	if (limitErr) return rej('invalid limit param');

	// Get 'offset' parameter
	const [offset = 0, offsetErr] = $.num.optional.min(0).get(params.offset);
	if (offsetErr) return rej('invalid offset param');

	// Lookup note
	const note = await Note.findOne({
		_id: noteId
	});

	if (note === null) {
		return rej('note not found');
	}

	const ids = (note._replyIds || []).slice(offset, offset + limit);

	// Serialize
	res(await Promise.all(ids.map(id => pack(id, user))));
});
开发者ID:ha-dai,项目名称:Misskey,代码行数:27,代码来源:replies.ts

示例3: default

export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
	const follower = user;

	// Get 'userId' parameter
	const [userId, userIdErr] = $.type(ID).get(params.userId);
	if (userIdErr) return rej('invalid userId param');

	// Fetch following
	const following = await Following.findOne({
		followerId: follower._id,
		followeeId: userId
	});

	if (following === null) {
		return rej('following not found');
	}

	// Stalk
	await Following.update({ _id: following._id }, {
		$set: {
			stalk: true
		}
	});

	// Send response
	res();

	// TODO: イベント
});
开发者ID:ha-dai,项目名称:Misskey,代码行数:29,代码来源:stalk.ts

示例4: default

export default (params: any, me: ILocalUser) => new Promise(async (res, rej) => {
	// Get 'iknow' parameter
	const [iknow = false, iknowErr] = $.bool.optional.get(params.iknow);
	if (iknowErr) return rej('invalid iknow param');

	// Get 'limit' parameter
	const [limit = 30, limitErr] = $.num.optional.range(1, 100).get(params.limit);
	if (limitErr) return rej('invalid limit param');

	// Get 'cursor' parameter
	const [cursor = null, cursorErr] = $.type(ID).optional.get(params.cursor);
	if (cursorErr) return rej('invalid cursor param');

	// Construct query
	const query = {
		muterId: me._id,
		deletedAt: { $exists: false }
	} as any;

	if (iknow) {
		// Get my friends
		const myFriends = await getFriendIds(me._id);

		query.muteeId = {
			$in: myFriends
		};
	}

	// カーソルが指定されている場合
	if (cursor) {
		query._id = {
			$lt: cursor
		};
	}

	// Get mutes
	const mutes = await Mute
		.find(query, {
			limit: limit + 1,
			sort: { _id: -1 }
		});

	// 「次のページ」があるかどうか
	const inStock = mutes.length === limit + 1;
	if (inStock) {
		mutes.pop();
	}

	// Serialize
	const users = await Promise.all(mutes.map(async m =>
		await pack(m.muteeId, me, { detail: true })));

	// Response
	res({
		users: users,
		next: inStock ? mutes[mutes.length - 1]._id : null,
	});
});
开发者ID:ha-dai,项目名称:Misskey,代码行数:58,代码来源:list.ts

示例5: default

export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
	// Get 'limit' parameter
	const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
	if (limitErr) return rej('invalid limit param');

	// Get 'sinceId' parameter
	const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId);
	if (sinceIdErr) return rej('invalid sinceId param');

	// Get 'untilId' parameter
	const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId);
	if (untilIdErr) return rej('invalid untilId param');

	// Check if both of sinceId and untilId is specified
	if (sinceId && untilId) {
		return rej('cannot set sinceId and untilId');
	}

	const query = {
		userId: user._id
	} as any;

	const sort = {
		_id: -1
	};

	if (sinceId) {
		sort._id = 1;
		query._id = {
			$gt: sinceId
		};
	} else if (untilId) {
		query._id = {
			$lt: untilId
		};
	}

	// Get favorites
	const favorites = await Favorite
		.find(query, { limit, sort });

	// Serialize
	res(await Promise.all(favorites.map(favorite => pack(favorite, user))));
});
开发者ID:ha-dai,项目名称:Misskey,代码行数:44,代码来源:favorites.ts

示例6: async

/**
 * Create a file from a URL
 */
export default async (params: any, user: ILocalUser): Promise<any> => {
	// Get 'url' parameter
	// TODO: Validate this url
	const [url, urlErr] = $.str.get(params.url);
	if (urlErr) throw 'invalid url param';

	// Get 'folderId' parameter
	const [folderId = null, folderIdErr] = $.type(ID).optional.nullable.get(params.folderId);
	if (folderIdErr) throw 'invalid folderId param';

	return pack(await uploadFromUrl(url, user, folderId));
};
开发者ID:ha-dai,项目名称:Misskey,代码行数:15,代码来源:upload_from_url.ts

示例7: default

export default (params: any) => new Promise(async (res, rej) => {
	// Get 'userId' parameter
	const [userId, userIdErr] = $.type(ID).get(params.userId);
	if (userIdErr) return rej('invalid userId param');

	// Lookup user
	const user = await User.findOne({
		_id: userId
	}, {
		fields: {
			_id: true
		}
	});

	if (user === null) {
		return rej('user not found');
	}

	const today = new Date();
	const graph = [];

	today.setMinutes(0);
	today.setSeconds(0);
	today.setMilliseconds(0);

	let cursorDate = new Date(today.getTime());
	let cursorTime = cursorDate.setDate(new Date(today.getTime()).getDate() + 1);

	for (let i = 0; i < 30; i++) {
		graph.push(FollowedLog.findOne({
			createdAt: { $lt: new Date(cursorTime / 1000) },
			userId: user._id
		}, {
			sort: { createdAt: -1 },
		}).then(log => {
			cursorDate = new Date(today.getTime());
			cursorTime = cursorDate.setDate(today.getDate() - i);

			return {
				date: {
					year: cursorDate.getFullYear(),
					month: cursorDate.getMonth() + 1, // In JavaScript, month is zero-based.
					day: cursorDate.getDate()
				},
				count: log ? log.count : 0
			};
		}));
	}

	res(await Promise.all(graph));
});
开发者ID:ha-dai,项目名称:Misskey,代码行数:51,代码来源:followers.ts

示例8: default

export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
	// Get 'noteId' parameter
	const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
	if (noteIdErr) return rej('invalid noteId param');

	// Get 'limit' parameter
	const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
	if (limitErr) return rej('invalid limit param');

	// Get 'offset' parameter
	const [offset = 0, offsetErr] = $.num.optional.min(0).get(params.offset);
	if (offsetErr) return rej('invalid offset param');

	// Lookup note
	const note = await Note.findOne({
		_id: noteId
	});

	if (note === null) {
		return rej('note not found');
	}

	const conversation: INote[] = [];
	let i = 0;

	async function get(id: any) {
		i++;
		const p = await Note.findOne({ _id: id });

		if (i > offset) {
			conversation.push(p);
		}

		if (conversation.length == limit) {
			return;
		}

		if (p.replyId) {
			await get(p.replyId);
		}
	}

	if (note.replyId) {
		await get(note.replyId);
	}

	// Serialize
	res(await Promise.all(conversation.map(note => pack(note, user))));
});
开发者ID:ha-dai,项目名称:Misskey,代码行数:49,代码来源:conversation.ts

示例9: default

export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
	const muter = user;

	// Get 'userId' parameter
	const [userId, userIdErr] = $.type(ID).get(params.userId);
	if (userIdErr) return rej('invalid userId param');

	// 自分自身
	if (user._id.equals(userId)) {
		return rej('mutee is yourself');
	}

	// Get mutee
	const mutee = await User.findOne({
		_id: userId
	}, {
		fields: {
			data: false,
			profile: false
		}
	});

	if (mutee === null) {
		return rej('user not found');
	}

	// Check if already muting
	const exist = await Mute.findOne({
		muterId: muter._id,
		muteeId: mutee._id
	});

	if (exist !== null) {
		return rej('already muting');
	}

	// Create mute
	await Mute.insert({
		createdAt: new Date(),
		muterId: muter._id,
		muteeId: mutee._id,
	});

	// Send response
	res();
});
开发者ID:ha-dai,项目名称:Misskey,代码行数:46,代码来源:create.ts

示例10: async

export default async (params: any, me: ILocalUser) => new Promise(async (res, rej) => {
	// Get 'listId' parameter
	const [listId, listIdErr] = $.type(ID).get(params.listId);
	if (listIdErr) return rej('invalid listId param');

	// Fetch the list
	const userList = await UserList.findOne({
		_id: listId,
		userId: me._id,
	});

	if (userList == null) {
		return rej('list not found');
	}

	res(await pack(userList));
});
开发者ID:ha-dai,项目名称:Misskey,代码行数:17,代码来源:show.ts


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