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


TypeScript Tyr.parseUid方法代碼示例

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


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

示例1: validate

export function validate(plugin: GraclPlugin, uid: string) {
  try {
    Tyr.parseUid(uid);
  } catch (err) {
    if (
      /must be a single String of 12 bytes or a string of 24 hex characters/.test(
        err.message
      )
    ) {
      plugin.error(`Invalid uid: ${uid}`);
    }
    throw err;
  }
}
開發者ID:CrossLead,項目名稱:tyranid-gracl,代碼行數:14,代碼來源:extractIdAndModel.ts

示例2: extractIdAndModel

export function extractIdAndModel(
  plugin: GraclPlugin,
  doc: Tyr.Document | string
) {
  if (typeof doc === 'string') {
    validate(plugin, doc);
    const components: { [key: string]: {} } = Tyr.parseUid(doc) || {};
    return {
      $uid: doc as string,
      $model: components.collection as Tyr.CollectionInstance
    };
  } else {
    validate(plugin, doc.$uid);
    return {
      $uid: doc.$uid as string,
      $model: doc.$model
    };
  }
}
開發者ID:CrossLead,項目名稱:tyranid-gracl,代碼行數:19,代碼來源:extractIdAndModel.ts

示例3: query


//.........這裏部分代碼省略.........
      } else {
        debugSubjectGraph.set(node.getId(), []);
      }
    }
  }

  // extract all collections that have a relevant permission set for the requested resource
  for (const resource of resourceArray) {
    const { collection, resourcePermissions } = resource;
    const collectionName = collection.def.name;
    const isQueriedCollection = queriedCollectionName === collectionName;

    let queryRestrictionSet = false;
    if (
      queriedCollectionLinkFields.has(collectionName) ||
      isQueriedCollection
    ) {
      const permissionArray = [...resourcePermissions.values()];

      for (const permission of permissionArray) {
        const result = getAccess(permission);
        switch (result.access) {
          // access needs to be exactly true or false
          case true:
          case false:
            const key = result.access ? 'positive' : 'negative';
            const uid = permission.resourceId;
            // if a permission was set by a collection of higher depth, keep it...
            if (alreadySet.has(uid)) {
              continue;
            } else {
              alreadySet.add(uid);
            }
            const resourceObjectId = Tyr.parseUid(uid).id;

            if (debug) {
              (result.access ? debugGraphPositive : debugGraphNegative).set(
                resourceObjectId.toString(),
                {
                  permission: permission.$id as ObjectID,
                  subjectId: permission.subjectId,
                  collectionName: permission.resourceType,
                  ...result
                }
              );
            }

            const accessSet = queryMaps[key].get(collectionName) || new Set();
            if (!queryMaps[key].has(collectionName)) {
              queryMaps[key].set(collectionName, accessSet);
            }
            accessSet.add(resourceObjectId as string);
            break;
        }
        queryRestrictionSet = true;
      }
    } else {
      // otherwise, we need determine how to restricting a query of this object by
      // permissions concerning parents of this object...
      /**
        Example:

        SETUP: want to query for all posts from database, have permissions
          set for access to posts on posts, blogs, and organizations...

        - for the permissions set on posts specifically, we can just add something like...
開發者ID:tyranid-org,項目名稱:tyranid,代碼行數:67,代碼來源:query.ts


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