MCPcopy Index your code
hub / github.com/simstudioai/sim / chunkArrayItems

Function chunkArrayItems

apps/sim/lib/execution/payloads/large-array-manifest.ts:96–119  ·  view source on GitHub ↗
(items: unknown[], targetBytes: number)

Source from the content-addressed store, hash-verified

94}
95
96function 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
121async function storeArrayChunks(
122 items: unknown[],

Callers 1

storeArrayChunksFunction · 0.85

Calls 2

pushMethod · 0.45

Tested by

no test coverage detected