| 55 | } |
| 56 | |
| 57 | export class CollectionStateManager< |
| 58 | TOutput extends object = Record<string, unknown>, |
| 59 | TKey extends string | number = string | number, |
| 60 | TSchema extends StandardSchemaV1 = StandardSchemaV1, |
| 61 | TInput extends object = TOutput, |
| 62 | > { |
| 63 | public config!: CollectionConfig<TOutput, TKey, TSchema> |
| 64 | public collection!: CollectionImpl<TOutput, TKey, any, TSchema, TInput> |
| 65 | public lifecycle!: CollectionLifecycleManager<TOutput, TKey, TSchema, TInput> |
| 66 | public changes!: CollectionChangesManager<TOutput, TKey, TSchema, TInput> |
| 67 | public indexes!: CollectionIndexesManager<TOutput, TKey, TSchema, TInput> |
| 68 | private _events!: CollectionEventsManager |
| 69 | |
| 70 | // Core state - make public for testing |
| 71 | public transactions: SortedMap<string, Transaction<any>> |
| 72 | public pendingSyncedTransactions: Array< |
| 73 | PendingSyncedTransaction<TOutput, TKey> |
| 74 | > = [] |
| 75 | public syncedData: SortedMap<TKey, TOutput> |
| 76 | public syncedMetadata = new Map<TKey, unknown>() |
| 77 | public syncedCollectionMetadata = new Map<string, unknown>() |
| 78 | |
| 79 | // Optimistic state tracking - make public for testing |
| 80 | public optimisticUpserts = new Map<TKey, TOutput>() |
| 81 | public optimisticDeletes = new Set<TKey>() |
| 82 | public pendingOptimisticUpserts = new Map<TKey, TOutput>() |
| 83 | public pendingOptimisticDeletes = new Set<TKey>() |
| 84 | public pendingOptimisticDirectUpserts = new Set<TKey>() |
| 85 | public pendingOptimisticDirectDeletes = new Set<TKey>() |
| 86 | |
| 87 | /** |
| 88 | * Tracks the origin of confirmed changes for each row. |
| 89 | * 'local' = change originated from this client |
| 90 | * 'remote' = change was received via sync |
| 91 | * |
| 92 | * This is used for the $origin virtual property. |
| 93 | * Note: This only tracks *confirmed* changes, not optimistic ones. |
| 94 | * Optimistic changes are always considered 'local' for $origin. |
| 95 | */ |
| 96 | public rowOrigins = new Map<TKey, VirtualOrigin>() |
| 97 | |
| 98 | /** |
| 99 | * Tracks keys that have pending local changes. |
| 100 | * Used to determine whether sync-confirmed data should have 'local' or 'remote' origin. |
| 101 | * When sync confirms data for a key with pending local changes, it keeps 'local' origin. |
| 102 | */ |
| 103 | public pendingLocalChanges = new Set<TKey>() |
| 104 | public pendingLocalOrigins = new Set<TKey>() |
| 105 | |
| 106 | private virtualPropsCache = new WeakMap< |
| 107 | object, |
| 108 | { |
| 109 | synced: boolean |
| 110 | origin: VirtualOrigin |
| 111 | key: TKey |
| 112 | collectionId: string |
| 113 | enriched: WithVirtualProps<TOutput, TKey> |
| 114 | } |
nothing calls this directly
no test coverage detected