MCPcopy Create free account
hub / github.com/backnotprop/plannotator / loadDraft

Function loadDraft

packages/shared/draft.ts:121–135  ·  view source on GitHub ↗
(key: string)

Source from the content-addressed store, hash-verified

119 * Load a draft from disk. Returns null if not found.
120 */
121export function loadDraft(key: string): object | null {
122 const filePath = draftPath(key);
123 try {
124 if (!existsSync(filePath)) return null;
125 const draft = JSON.parse(readFileSync(filePath, "utf-8"));
126 const draftGeneration = readGeneration((draft as { draftGeneration?: unknown }).draftGeneration);
127 const deletedGeneration = readTombstoneGeneration(key);
128 if (draftGeneration !== null && deletedGeneration !== null && draftGeneration <= deletedGeneration) {
129 return null;
130 }
131 return draft;
132 } catch {
133 return null;
134 }
135}
136
137/**
138 * Delete a draft from disk. No-op if not found.

Callers 7

draft.test.tsFile · 0.90
handleDraftLoadFunction · 0.90
installFetchShimFunction · 0.90
installFetchShimFunction · 0.90
handleDraftRequestFunction · 0.85

Calls 4

draftPathFunction · 0.85
readGenerationFunction · 0.85
readTombstoneGenerationFunction · 0.85
parseMethod · 0.80

Tested by 2

installFetchShimFunction · 0.72
installFetchShimFunction · 0.72