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


TypeScript frost-component.MongoProvider类代码示例

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


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

示例1: getfollowers

	async getfollowers(userId: string | ObjectId): Promise<UserDocument[]> {
		const docRaws: IUserRelationDocument[] = await this.db.findArray('api.userRelations', {
			targetUserId: MongoProvider.buildId(userId),
			status: 'following'
		});

		const followers = docRaws.map(docRaw => new UserRelationDocument(docRaw));

		const userPromises = followers.map(async follower => {
			const user = await this.manager.userService.findById(follower.sourceUserId);
			if (!user) {
				console.warn(`not existing user: ${follower.sourceUserId.toHexString()}`);
			}
			return user;
		});

		const usersWithNull = await Promise.all(userPromises);

		const users: UserDocument[] = [];
		for (const userOrNull of usersWithNull) {
			if (userOrNull) users.push(userOrNull);
		}

		return users;
	}
开发者ID:Frost-Dev,项目名称:Frost,代码行数:25,代码来源:UserRelationService.ts

示例2: findArrayByCreatorId

	async findArrayByCreatorId(creatorId: string | ObjectId): Promise<AppDocument[]> {
		const rawAppDocs: IAppDocument[] = await this.db.findArray('api.apps', {
			creatorId: MongoProvider.buildId(creatorId)
		});

		return rawAppDocs.map(rawAppDoc => new AppDocument(rawAppDoc));
	}
开发者ID:Frost-Dev,项目名称:Frost,代码行数:7,代码来源:AppService.ts

示例3: unfollow

	async unfollow(sourceUserId: string | ObjectId, targetUserId: string | ObjectId) {
		const query = {
			sourceUserId: MongoProvider.buildId(sourceUserId),
			targetUserId: MongoProvider.buildId(targetUserId)
		};
		const docSource: IUserRelationDocumentSoruce = {
			sourceUserId: query.sourceUserId,
			targetUserId: query.targetUserId,
			message: undefined,
			status: 'notFollowing'
		};
		const docRaw: IUserRelationDocument = await this.db.upsert('api.userRelations', query, docSource);

		return new UserRelationDocument(docRaw);
	}
开发者ID:Frost-Dev,项目名称:Frost,代码行数:15,代码来源:UserRelationService.ts

示例4: createChatPosting

	async createChatPosting(userId: string | ObjectId, text: string, attachmentIds?: (ObjectId | string)[]): Promise<ChatPostingDocument> {
		const source: IChatPostingDocumentSoruce = {
			type: 'chat',
			userId: MongoProvider.buildId(userId),
			text
		};

		if (attachmentIds) {
			source.attachmentIds = attachmentIds.map(i => MongoProvider.buildId(i));
		}

		const documentRaw: IChatPostingDocument = await this.db.create('api.postings', source);

		return new ChatPostingDocument(documentRaw);
	}
开发者ID:Frost-Dev,项目名称:Frost,代码行数:15,代码来源:PostingService.ts

示例5: find

	async find(appId: string | ObjectId, userId: string | ObjectId, scopes: string[]): Promise<TokenDocument | null> {
		const scopesQuery: any = { $size: scopes.length };
		// NOTE: 空の配列を$allに指定すると検索にヒットしなくなるので、空のときは$allを指定しない
		if (scopes.length != 0) {
			scopesQuery.$all = scopes;
		}

		const tokenDocRaw = await this.db.find('api.tokens', {
			appId: MongoProvider.buildId(appId),
			userId: MongoProvider.buildId(userId),
			scopes: scopesQuery
		});

		return tokenDocRaw ? new TokenDocument(tokenDocRaw) : null;
	}
开发者ID:Frost-Dev,项目名称:Frost,代码行数:15,代码来源:TokenService.ts

示例6: function

/**
 * 保存されているデータフォーマットを確認します。
 *
 * APIのバージョンアップによって保存されるデータの構造が変更される場合があります。
 * 「データフォーマット」は、正常に初期化・データ移行するために必要な識別子です。
*/
export default async function(db: MongoProvider, currentVersion: number): Promise<DataFormatState> {
	const dataFormat = await db.find('meta', { type: 'dataFormat' });

	let docCount = 0;
	docCount += await db.count('api.users', {});
	docCount += await db.count('api.apps', {});
	docCount += await db.count('api.tokens', {});
	docCount += await db.count('api.userRelations', {});
	docCount += await db.count('api.postings', {});
	docCount += await db.count('api.storageFiles', {});


	// データフォーマットが保存されていないとき
	if (!dataFormat) {
		if (docCount == 0) {
			return DataFormatState.needInitialization;
		}
		else {
			return DataFormatState.needMigration;
		}
	}

	// データフォーマットが一致しているとき
	if (dataFormat.value === currentVersion) {
		return DataFormatState.ready;
	}

	// データフォーマットが期待したものであるとき
	if (dataFormat.value < currentVersion) {
		return DataFormatState.needMigration;
	}
	else {
		return DataFormatState.unknown;
	}
}
开发者ID:Frost-Dev,项目名称:Frost,代码行数:41,代码来源:getDataFormatState.ts

示例7: BearerStrategy

	passport.use('accessToken', new BearerStrategy(async (accessToken, done) => {
		try {
			const tokenDocRaw: ITokenDocument = await db.find('api.tokens', { accessToken });
			if (!tokenDocRaw) {
				done(null, false);
				return;
			}
			const tokenDoc = new TokenDocument(tokenDocRaw);

			const userDocRaw: IUserDocument = await db.find('api.users', { _id: tokenDocRaw.userId });
			if (!userDocRaw) {
				done(null, false);
				return;
			}
			const userDoc = new UserDocument(userDocRaw);

			const appDocRaw: IAppDocument = await db.find('api.apps', { _id: tokenDocRaw.appId });
			if (!appDocRaw) {
				done(null, false);
				return;
			}
			const appDoc = new AppDocument(appDocRaw);
			await appDoc.populate(db);
			done(null, userDoc, { app: appDoc, token: tokenDoc } as any);
		}
		catch (err) {
			done(err);
		}
	}));
开发者ID:Frost-Dev,项目名称:Frost,代码行数:29,代码来源:accessTokenStrategy.ts

示例8: clean

	menu.add('initialize (register root app and root user)', () => true, async (ctx) => {
		if (dataFormatState != DataFormatState.needInitialization) {
			const allowClear = await q('(!) are you sure you want to REMOVE ALL COLLECTIONS and ALL DOCUMENTS in target database? (y/n) > ');
			if (!allowClear) {
				return;
			}

			const clean = async (collection: string) => {
				await db.remove(collection, {});
				log(`cleaned ${collection} collection.`);
			};

			await clean('meta');
			await clean('api.apps');
			await clean('api.tokens');
			await clean('api.users');
			await clean('api.userRelations');
			await clean('api.postings');
			await clean('api.storageFiles');
		}

		let appName = await read('app name(default: Frost Web) > ');
		if (appName == '') appName = 'Frost Web';

		const userDoc = await userService.create('frost', null, 'Frost公式', 'オープンソースSNS Frostです。', { root: true });
		log('root user created.');

		await appService.create(appName, userDoc, userDoc.description, AuthScopes.toArray().map(s => s.id), { root: true });
		log('root app created.');

		await db.create('meta', { type: 'dataFormat', value: currentDataVersion });

		await refreshMenu();
	});
开发者ID:Frost-Dev,项目名称:Frost,代码行数:34,代码来源:setupMenu.ts

示例9: create

	async create(screenName: string, password: string | null, name: string, description: string, options?: IUserCreateOptions): Promise<UserDocument> {
		options = options || { };

		if (!options.root && password == null) {
			throw new Error('password is empty');
		}

		let passwordHash = null;
		if (password != null) {
			const salt = randomRange(1, 99999);
			const hash = buildHash(`${password}.${salt}`);
			passwordHash = `${hash}.${salt}`;
		}

		const source: IUserDocumentSoruce = {
			screenName,
			passwordHash,
			name,
			description
		};

		if (options.root) {
			source.root = true;
		}

		const rawDocument: IUserDocument = await this.db.create('api.users', source);

		return new UserDocument(rawDocument);
	}
开发者ID:Frost-Dev,项目名称:Frost,代码行数:29,代码来源:UserService.ts

示例10: findByChatId

	async findByChatId(chatPostingId: string | ObjectId): Promise<ChatPostingDocument | null> {
		const rawDocument: any = await this.db.findById('api.postings', chatPostingId);
		if (rawDocument && rawDocument.type != 'chat') {
			return null;
		}

		return rawDocument ? new ChatPostingDocument(rawDocument) : null;
	}
开发者ID:Frost-Dev,项目名称:Frost,代码行数:8,代码来源:PostingService.ts


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