當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript ObjectID.toString方法代碼示例

本文整理匯總了TypeScript中mongodb.ObjectID.toString方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript ObjectID.toString方法的具體用法?TypeScript ObjectID.toString怎麽用?TypeScript ObjectID.toString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在mongodb.ObjectID的用法示例。


在下文中一共展示了ObjectID.toString方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: Set

      const addIdsToQueryMap = (access: boolean) => (id: string | ObjectID) => {
        const accessString = access ? 'positive' : 'negative';
        const altAccessString = access ? 'negative' : 'positive';
        const resourceUid = Tyr.byName[linkedCollectionName].idToUid(id);

        if (alreadySet.has(resourceUid)) {
          return;
        } else {
          alreadySet.add(resourceUid);
        }

        const accessSet =
          queryMaps[accessString].get(linkedCollectionName) || new Set();
        if (!queryMaps[accessString].has(linkedCollectionName)) {
          queryMaps[accessString].set(linkedCollectionName, accessSet);
        }

        // if the id was set previously, by a lower level link,
        // dont override the lower level
        const map = queryMaps[altAccessString].get(linkedCollectionName);

        if (!map || !map.has(id.toString())) {
          accessSet.add(id as string);
        }
      };
開發者ID:tyranid-org,項目名稱:tyranid,代碼行數:25,代碼來源:query.ts

示例2: async

	connection.on('message', async (data) => {
		const msg = JSON.parse(data.utf8Data);

		switch (msg.type) {
			case 'read':
					if (!msg.id) {
						return;
					}

					const id = new mongodb.ObjectID(msg.id);

					// Fetch message
					// SELECT _id, user_id, is_read
					const message = await Message.findOne({
						_id: id,
						recipient_id: user._id
					}, {
						fields: {
							_id: true,
							user_id: true,
							is_read: true
						}
					});

					if (message == null) {
						return;
					}

					if (message.is_read) {
						return;
					}

					// Update documents
					await Message.update({
						_id: id
					}, {
						$set: { is_read: true }
					});

					// Publish event
					publishMessagingStream(message.user_id, user._id, 'read', id.toString());
				break;
		}
	});
開發者ID:syuilo,項目名稱:misskey-core,代碼行數:44,代碼來源:messaging.ts

示例3: getExplainationsForId

/**
 * given a node in the debug graph,
 * find the path of nodes leading to a permission
 */
function getExplainationsForId(
  id: ObjectID,
  subjectId: string,
  subjectGraph: Map<string, string[]>,
  graph: DebugGraph,
  type: ExplainationType,
  property: string
): Explaination[] {
  const node = graph.get(id.toString());

  if (!node) {
    throw new Error(`No node found for id = ${id}`);
  }

  const nodeUid = toUid(node.collectionName, id);

  const out: Explaination[] = [];

  /**
   * the node itself represents a direct permission
   */
  if (!('parents' in node)) {
    const subjectPaths = getSubjectPaths(
      subjectId,
      node.subjectId,
      subjectGraph
    );
    const resourcePath = [nodeUid];

    for (const path of subjectPaths) {
      out.push({
        permissionId: node.permission.toString(),
        subjectPath: path,
        permissionType: node.type,
        property,
        resourcePath,
        type: ExplainationType.ALLOW
      });
    }

    return out;
  }

  /**
   * recurse up parent chain, building explaination objects with uid path
   */

  let currentNodes = [
    {
      type,
      resourcePath: [nodeUid],
      parents: Array.from(node.parents)
    }
  ];

  while (currentNodes.length) {
    const nextNodes: (Explaination & { parents: string[] })[] = [];

    for (const current of currentNodes) {
      const { parents, resourcePath } = current;

      for (const parent of parents) {
        const next = graph.get(parent);

        if (!next) {
          throw new Error(`No node found for parentId = ${parent}`);
        }

        const parentUid = toUid(next.collectionName, parent);
        const nextPath = [...resourcePath, parentUid];

        if (!('parents' in next)) {
          const subjectPaths = getSubjectPaths(
            subjectId,
            next.subjectId,
            subjectGraph
          );

          for (const subjectPath of subjectPaths) {
            out.push({
              type,
              resourcePath: nextPath,
              subjectPath,
              permissionId: next.permission.toString(),
              permissionType: next.type,
              property
            });
          }
        } else {
          nextNodes.push({
            type,
            resourcePath: nextPath,
            subjectPath: [],
            parents: Array.from(next.parents)
          });
        }
//.........這裏部分代碼省略.........
開發者ID:tyranid-org,項目名稱:tyranid,代碼行數:101,代碼來源:explain.ts

示例4: id

 get id(): string {
   return this._id.toString();
 }
開發者ID:sebthieti,項目名稱:jogplayer-online,代碼行數:3,代碼來源:user.model.ts


注:本文中的mongodb.ObjectID.toString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。