|
| 1 | +import type { AccountStorageV3 } from "../storage.js"; |
| 2 | + |
| 3 | +export async function loadExperimentalSyncTargetEntry(params: { |
| 4 | + loadExperimentalSyncTargetState: (args: { |
| 5 | + detectTarget: () => ReturnType< |
| 6 | + typeof import("../oc-chatgpt-target-detection.js").detectOcChatgptMultiAuthTarget |
| 7 | + >; |
| 8 | + readJson: (path: string) => Promise<unknown>; |
| 9 | + normalizeAccountStorage: (value: unknown) => AccountStorageV3 | null; |
| 10 | + }) => Promise< |
| 11 | + | { |
| 12 | + kind: "blocked-ambiguous"; |
| 13 | + detection: ReturnType< |
| 14 | + typeof import("../oc-chatgpt-target-detection.js").detectOcChatgptMultiAuthTarget |
| 15 | + >; |
| 16 | + } |
| 17 | + | { |
| 18 | + kind: "blocked-none"; |
| 19 | + detection: ReturnType< |
| 20 | + typeof import("../oc-chatgpt-target-detection.js").detectOcChatgptMultiAuthTarget |
| 21 | + >; |
| 22 | + } |
| 23 | + | { kind: "error"; message: string } |
| 24 | + | { |
| 25 | + kind: "target"; |
| 26 | + detection: ReturnType< |
| 27 | + typeof import("../oc-chatgpt-target-detection.js").detectOcChatgptMultiAuthTarget |
| 28 | + >; |
| 29 | + destination: AccountStorageV3 | null; |
| 30 | + } |
| 31 | + >; |
| 32 | + detectTarget: () => ReturnType< |
| 33 | + typeof import("../oc-chatgpt-target-detection.js").detectOcChatgptMultiAuthTarget |
| 34 | + >; |
| 35 | + readFileWithRetry: ( |
| 36 | + path: string, |
| 37 | + options: { |
| 38 | + retryableCodes: Set<string>; |
| 39 | + maxAttempts: number; |
| 40 | + sleep: (ms: number) => Promise<void>; |
| 41 | + }, |
| 42 | + ) => Promise<string>; |
| 43 | + normalizeAccountStorage: (value: unknown) => AccountStorageV3 | null; |
| 44 | + sleep: (ms: number) => Promise<void>; |
| 45 | +}): ReturnType<typeof params.loadExperimentalSyncTargetState> { |
| 46 | + return params.loadExperimentalSyncTargetState({ |
| 47 | + detectTarget: params.detectTarget, |
| 48 | + readJson: async (path) => |
| 49 | + JSON.parse( |
| 50 | + await params.readFileWithRetry(path, { |
| 51 | + retryableCodes: new Set([ |
| 52 | + "EBUSY", |
| 53 | + "EPERM", |
| 54 | + "EAGAIN", |
| 55 | + "ENOTEMPTY", |
| 56 | + "EACCES", |
| 57 | + ]), |
| 58 | + maxAttempts: 4, |
| 59 | + sleep: params.sleep, |
| 60 | + }), |
| 61 | + ), |
| 62 | + normalizeAccountStorage: params.normalizeAccountStorage, |
| 63 | + }); |
| 64 | +} |
0 commit comments