(
state: SyncState,
options?: { skipEtagCache?: boolean },
)
| 768 | * Returns true if any files were updated. |
| 769 | */ |
| 770 | export async function pullTeamMemory( |
| 771 | state: SyncState, |
| 772 | options?: { skipEtagCache?: boolean }, |
| 773 | ): Promise<{ |
| 774 | success: boolean |
| 775 | filesWritten: number |
| 776 | /** Number of entries the server returned, regardless of whether they were written to disk. */ |
| 777 | entryCount: number |
| 778 | notModified?: boolean |
| 779 | error?: string |
| 780 | }> { |
| 781 | const skipEtagCache = options?.skipEtagCache ?? false |
| 782 | const startTime = Date.now() |
| 783 | |
| 784 | if (!isUsingOAuth()) { |
| 785 | logPull(startTime, { success: false, errorType: 'no_oauth' }) |
| 786 | return { |
| 787 | success: false, |
| 788 | filesWritten: 0, |
| 789 | entryCount: 0, |
| 790 | error: 'OAuth not available', |
| 791 | } |
| 792 | } |
| 793 | |
| 794 | const repoSlug = await getGithubRepo() |
| 795 | if (!repoSlug) { |
| 796 | logPull(startTime, { success: false, errorType: 'no_repo' }) |
| 797 | return { |
| 798 | success: false, |
| 799 | filesWritten: 0, |
| 800 | entryCount: 0, |
| 801 | error: 'No git remote found', |
| 802 | } |
| 803 | } |
| 804 | |
| 805 | const etag = skipEtagCache ? null : state.lastKnownChecksum |
| 806 | const result = await fetchTeamMemory(state, repoSlug, etag) |
| 807 | if (!result.success) { |
| 808 | logPull(startTime, { |
| 809 | success: false, |
| 810 | errorType: result.errorType, |
| 811 | status: result.httpStatus, |
| 812 | }) |
| 813 | return { |
| 814 | success: false, |
| 815 | filesWritten: 0, |
| 816 | entryCount: 0, |
| 817 | error: result.error, |
| 818 | } |
| 819 | } |
| 820 | if (result.notModified) { |
| 821 | logPull(startTime, { success: true, notModified: true }) |
| 822 | return { success: true, filesWritten: 0, entryCount: 0, notModified: true } |
| 823 | } |
| 824 | if (result.isEmpty || !result.data) { |
| 825 | // Server has no data — clear stale serverChecksums so the next push |
| 826 | // doesn't skip entries it thinks the server already has. |
| 827 | state.serverChecksums.clear() |
no test coverage detected