( ops: DocOp[], budgetBytes: number, maxCount: number )
| 123 | * larger than the budget still forms its own chunk (always >= 1 op per chunk). |
| 124 | */ |
| 125 | export function chunkOpsByByteBudget( |
| 126 | ops: DocOp[], |
| 127 | budgetBytes: number, |
| 128 | maxCount: number |
| 129 | ): DocOp[][] { |
| 130 | const chunks: DocOp[][] = [] |
| 131 | let current: DocOp[] = [] |
| 132 | let currentBytes = 0 |
| 133 | for (const op of ops) { |
| 134 | const bytes = estimateOpSizeBytes(op) |
| 135 | if (current.length > 0 && (current.length >= maxCount || currentBytes + bytes > budgetBytes)) { |
| 136 | chunks.push(current) |
| 137 | current = [] |
| 138 | currentBytes = 0 |
| 139 | } |
| 140 | current.push(op) |
| 141 | currentBytes += bytes |
| 142 | } |
| 143 | if (current.length > 0) { |
| 144 | chunks.push(current) |
| 145 | } |
| 146 | return chunks |
| 147 | } |
| 148 | |
| 149 | /** Single-roundtrip liveness check used between batches. */ |
| 150 | async function checkSyncLiveness( |
no test coverage detected