(
seed: {
rows?: ReadonlyMap<string, TItem>
rowMetadata?: ReadonlyMap<string, unknown>
collectionMetadata?: ReadonlyMap<string, unknown>
} = {},
)
| 99 | } |
| 100 | |
| 101 | function createPersistedQueryAdapter<TItem extends { id: string }>( |
| 102 | seed: { |
| 103 | rows?: ReadonlyMap<string, TItem> |
| 104 | rowMetadata?: ReadonlyMap<string, unknown> |
| 105 | collectionMetadata?: ReadonlyMap<string, unknown> |
| 106 | } = {}, |
| 107 | ) { |
| 108 | const rows = new Map(seed.rows) |
| 109 | const rowMetadata = new Map(seed.rowMetadata) |
| 110 | const collectionMetadata = new Map(seed.collectionMetadata) |
| 111 | |
| 112 | return { |
| 113 | rows, |
| 114 | rowMetadata, |
| 115 | collectionMetadata, |
| 116 | loadSubset: async () => |
| 117 | Array.from(rows.values()).map((value) => ({ |
| 118 | key: value.id, |
| 119 | value, |
| 120 | metadata: rowMetadata.get(value.id), |
| 121 | })), |
| 122 | loadCollectionMetadata: async () => |
| 123 | Array.from(collectionMetadata.entries()).map(([key, value]) => ({ |
| 124 | key, |
| 125 | value, |
| 126 | })), |
| 127 | scanRows: async () => |
| 128 | Array.from(rows.values()).map((value) => ({ |
| 129 | key: value.id, |
| 130 | value, |
| 131 | metadata: rowMetadata.get(value.id), |
| 132 | })), |
| 133 | applyCommittedTx: async (_collectionId: string, tx: any) => { |
| 134 | if (tx.truncate) { |
| 135 | rows.clear() |
| 136 | rowMetadata.clear() |
| 137 | } |
| 138 | for (const mutation of tx.mutations) { |
| 139 | if (mutation.type === `delete`) { |
| 140 | rows.delete(mutation.key) |
| 141 | rowMetadata.delete(mutation.key) |
| 142 | } else { |
| 143 | rows.set(mutation.key, mutation.value) |
| 144 | } |
| 145 | } |
| 146 | for (const mutation of tx.rowMetadataMutations ?? []) { |
| 147 | if (mutation.type === `delete`) { |
| 148 | rowMetadata.delete(mutation.key) |
| 149 | } else { |
| 150 | rowMetadata.set(mutation.key, mutation.value) |
| 151 | } |
| 152 | } |
| 153 | for (const mutation of tx.collectionMetadataMutations ?? []) { |
| 154 | if (mutation.type === `delete`) { |
| 155 | collectionMetadata.delete(mutation.key) |
| 156 | } else { |
| 157 | collectionMetadata.set(mutation.key, mutation.value) |
| 158 | } |
no test coverage detected
searching dependent graphs…