(items: unknown[], targetBytes: number)
| 94 | } |
| 95 | |
| 96 | function chunkArrayItems(items: unknown[], targetBytes: number): unknown[][] { |
| 97 | const chunks: unknown[][] = [] |
| 98 | let current: unknown[] = [] |
| 99 | let currentBytes = 2 |
| 100 | |
| 101 | for (const item of items) { |
| 102 | const itemBytes = measureArrayElementJsonSize(item) |
| 103 | const separatorBytes = current.length > 0 ? 1 : 0 |
| 104 | if (current.length > 0 && currentBytes + separatorBytes + itemBytes > targetBytes) { |
| 105 | chunks.push(current) |
| 106 | current = [] |
| 107 | currentBytes = 2 |
| 108 | } |
| 109 | |
| 110 | current.push(item) |
| 111 | currentBytes += (current.length > 1 ? 1 : 0) + itemBytes |
| 112 | } |
| 113 | |
| 114 | if (current.length > 0) { |
| 115 | chunks.push(current) |
| 116 | } |
| 117 | |
| 118 | return chunks |
| 119 | } |
| 120 | |
| 121 | async function storeArrayChunks( |
| 122 | items: unknown[], |
no test coverage detected