Skip to content
Source
Sign inSign up

new-task-draft-key.ts

27 lines874 Bytes

1const NEW_TASK_DRAFT_PREFIX = "new-task:";
2​
3export function newTaskDraftKey(draftId: string): string {
4 return `${NEW_TASK_DRAFT_PREFIX}${draftId}`;
5}
6​
7export function isNewTaskDraftKey(draftKey: string): boolean {
8 return draftKey.startsWith(NEW_TASK_DRAFT_PREFIX);
9}
10​
11export function restoredNewTaskDraftKey(messageId: string): string {
12 return newTaskDraftKey(`restored-${messageId}`);
14​
15export function parseLegacyNewTaskDraftKey(
16 draftKey: string,
17): { readonly environmentId: string; readonly projectId: string } | null {
18 if (!isNewTaskDraftKey(draftKey)) {
19 return null;
20 }
21 const scope = draftKey.slice(NEW_TASK_DRAFT_PREFIX.length);
22 const separator = scope.lastIndexOf(":");
23 if (separator <= 0 || separator === scope.length - 1) {
24 return null;
25 }
26 return { environmentId: scope.slice(0, separator), projectId: scope.slice(separator + 1) };