(params)
| 712 | } |
| 713 | |
| 714 | const internalSync: SyncConfig<any>[`sync`] = (params) => { |
| 715 | const { begin, write, commit, markReady, collection, metadata } = params |
| 716 | const persistedMetadata = metadata as |
| 717 | | QuerySyncMetadataWithPersistedScan<any> |
| 718 | | undefined |
| 719 | |
| 720 | // Track whether sync has been started |
| 721 | let syncStarted = false |
| 722 | let startupRetentionSettled = false |
| 723 | const retainedQueriesPendingRevalidation = new Set<string>() |
| 724 | const effectivePersistedGcTimes = new Map<string, number>() |
| 725 | const persistedRetentionTimers = new Map< |
| 726 | string, |
| 727 | ReturnType<typeof setTimeout> |
| 728 | >() |
| 729 | let persistedRetentionMaintenance = Promise.resolve() |
| 730 | |
| 731 | const getRowMetadata = (rowKey: string | number) => { |
| 732 | return (metadata?.row.get(rowKey) ?? |
| 733 | collection._state.syncedMetadata.get(rowKey)) as |
| 734 | | Record<string, unknown> |
| 735 | | undefined |
| 736 | } |
| 737 | |
| 738 | const getPersistedOwners = (rowKey: string | number) => { |
| 739 | const rowMetadata = getRowMetadata(rowKey) |
| 740 | const queryMetadata = rowMetadata?.queryCollection |
| 741 | if (!queryMetadata || typeof queryMetadata !== `object`) { |
| 742 | return new Set<string>() |
| 743 | } |
| 744 | |
| 745 | const owners = (queryMetadata as Record<string, unknown>).owners |
| 746 | if (!owners || typeof owners !== `object`) { |
| 747 | return new Set<string>() |
| 748 | } |
| 749 | |
| 750 | return new Set(Object.keys(owners as Record<string, true>)) |
| 751 | } |
| 752 | |
| 753 | const setPersistedOwners = ( |
| 754 | rowKey: string | number, |
| 755 | owners: Set<string>, |
| 756 | ) => { |
| 757 | if (!metadata) { |
| 758 | return |
| 759 | } |
| 760 | |
| 761 | const currentMetadata = { ...(getRowMetadata(rowKey) ?? {}) } |
| 762 | if (owners.size === 0) { |
| 763 | delete currentMetadata.queryCollection |
| 764 | if (Object.keys(currentMetadata).length === 0) { |
| 765 | metadata.row.delete(rowKey) |
| 766 | } else { |
| 767 | metadata.row.set(rowKey, currentMetadata) |
| 768 | } |
| 769 | return |
| 770 | } |
| 771 |
no test coverage detected