MCPcopy Index your code
hub / github.com/nodejs/node / normalizeAsyncValue

Function normalizeAsyncValue

lib/internal/streams/iter/from.js:266–330  ·  view source on GitHub ↗

* Normalize an async streamable yield value to Uint8Array chunks. * Recursively flattens arrays, iterables, async iterables, promises, * and protocol conversions. * @yields {Uint8Array}

(value)

Source from the content-addressed store, hash-verified

264 * @yields {Uint8Array}
265 */
266async function* normalizeAsyncValue(value) {
267 // Handle promises first
268 if (isPromise(value)) {
269 const resolved = await value;
270 yield* normalizeAsyncValue(resolved);
271 return;
272 }
273
274 // Handle primitives
275 if (isPrimitiveChunk(value)) {
276 yield primitiveToUint8Array(value);
277 return;
278 }
279
280 // Handle ToAsyncStreamable protocol (check before ToStreamable)
281 if (hasProtocol(value, toAsyncStreamable)) {
282 const result = FunctionPrototypeCall(value[toAsyncStreamable], value);
283 if (isPromise(result)) {
284 yield* normalizeAsyncValue(await result);
285 } else {
286 yield* normalizeAsyncValue(result);
287 }
288 return;
289 }
290
291 // Handle ToStreamable protocol
292 if (hasProtocol(value, toStreamable)) {
293 const result = FunctionPrototypeCall(value[toStreamable], value);
294 yield* normalizeAsyncValue(result);
295 return;
296 }
297
298 // Handle arrays (which are also iterable, but check first for efficiency)
299 if (ArrayIsArray(value)) {
300 for (let i = 0; i < value.length; i++) {
301 yield* normalizeAsyncValue(value[i]);
302 }
303 return;
304 }
305
306 // Handle async iterables (check before sync iterables since some objects
307 // have both)
308 if (isAsyncIterable(value)) {
309 for await (const item of value) {
310 yield* normalizeAsyncValue(item);
311 }
312 return;
313 }
314
315 // Handle sync iterables
316 if (isSyncIterable(value)) {
317 for (const item of value) {
318 yield* normalizeAsyncValue(item);
319 }
320 return;
321 }
322
323 // Reject: no valid conversion

Callers 3

normalizeBatchFunction · 0.85
normalizeAsyncSourceFunction · 0.85
pipeToFunction · 0.85

Calls 5

isPrimitiveChunkFunction · 0.85
primitiveToUint8ArrayFunction · 0.85
hasProtocolFunction · 0.85
isAsyncIterableFunction · 0.70
isSyncIterableFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…