Open History to see the last commit
1const NEW_TASK_DRAFT_PREFIX = "new-task:";
2
3/** Every new-task draft key: `new-task:<draftId>`. */
4export function newTaskDraftKey(draftId: string): string {
5 return `${NEW_TASK_DRAFT_PREFIX}${draftId}`;
6}
7
8export function isNewTaskDraftKey(draftKey: string): boolean {
9 return draftKey.startsWith(NEW_TASK_DRAFT_PREFIX);
10}
11
12/**
13 * Builds before drafts were id-keyed used `new-task:<environmentId>:<projectId>`,
14 * one slot per project. Ids are UUIDs and never contain a colon, so a colon
15 * after the prefix marks the legacy shape. Returns the split scope, or null
16 * when the key is not legacy.
17 */
18export function parseLegacyNewTaskDraftKey(
19 draftKey: string,
20): { readonly environmentId: string; readonly projectId: string } | null {
21 if (!isNewTaskDraftKey(draftKey)) {
22 return null;
23 }
24 const scope = draftKey.slice(NEW_TASK_DRAFT_PREFIX.length);
25 const separator = scope.lastIndexOf(":");
26 if (separator <= 0 || separator === scope.length - 1) {
27 return null;
28 }
29 return { environmentId: scope.slice(0, separator), projectId: scope.slice(separator + 1) };
30}