X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/18a8117437056f65e3c9d84b0231c5f64b1346d1..da050efb3aea15f768e1873f80459e55a56f55e7:/src/models/resource.ts diff --git a/src/models/resource.ts b/src/models/resource.ts index 2d72fbcd82..b8156cf2d1 100644 --- a/src/models/resource.ts +++ b/src/models/resource.ts @@ -10,15 +10,70 @@ export interface Resource { modifiedByUserUuid: string; modifiedAt: string; href: string; - kind: string; + kind: ResourceKind; etag: string; } +export interface TrashableResource extends Resource { + trashAt: string; + deleteAt: string; + isTrashed: boolean; +} + export enum ResourceKind { - Collection = "arvados#collection", - ContainerRequest = "arvados#containerRequest", - Group = "arvados#group", - Process = "arvados#containerRequest", - Project = "arvados#group", - Workflow = "arvados#workflow" + COLLECTION = "arvados#collection", + CONTAINER = "arvados#container", + CONTAINER_REQUEST = "arvados#containerRequest", + GROUP = "arvados#group", + LOG = "arvados#log", + PROCESS = "arvados#containerRequest", + PROJECT = "arvados#group", + USER = "arvados#user", + WORKFLOW = "arvados#workflow", + NONE = "arvados#none" +} + +export enum ResourceObjectType { + COLLECTION = '4zz18', + CONTAINER = 'dz642', + CONTAINER_REQUEST = 'xvhdp', + GROUP = 'j7d0g', + LOG = '57u5n', + USER = 'tpzed', + WORKFLOW = '7fd4e', } + +export const RESOURCE_UUID_PATTERN = '.{5}-.{5}-.{15}'; +export const RESOURCE_UUID_REGEX = new RegExp(RESOURCE_UUID_PATTERN); + +export const isResourceUuid = (uuid: string) => + RESOURCE_UUID_REGEX.test(uuid); + +export const extractUuidObjectType = (uuid: string) => { + const match = RESOURCE_UUID_REGEX.exec(uuid); + return match + ? match[0].split('-')[1] + : undefined; +}; + +export const extractUuidKind = (uuid: string = '') => { + const objectType = extractUuidObjectType(uuid); + switch (objectType) { + case ResourceObjectType.USER: + return ResourceKind.USER; + case ResourceObjectType.GROUP: + return ResourceKind.GROUP; + case ResourceObjectType.COLLECTION: + return ResourceKind.COLLECTION; + case ResourceObjectType.CONTAINER_REQUEST: + return ResourceKind.CONTAINER_REQUEST; + case ResourceObjectType.CONTAINER: + return ResourceKind.CONTAINER; + case ResourceObjectType.LOG: + return ResourceKind.LOG; + case ResourceObjectType.WORKFLOW: + return ResourceKind.WORKFLOW; + default: + return undefined; + } +};