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O,QAAU,MAGjB,OAAO,QAAQ,KAAO,KAAK,KAC3B,OAAO,QAAQ,KAAO,KAAK,KAC3B,OAAO,QAAQ,KAAO,KAAK,KAE3B,OAAO,QAAQ,YAAc,KAAK,YAClC,OAAO,QAAQ,WAAa,KAAK,WACjC,OAAO,QAAQ,MAAQ,KAAK,MAC5B,OAAO,QAAQ,aAAe,KAAK,aACnC,OAAO,QAAQ,cAAgB,KAAK,cAEpC,OAAO,QAAQ,WAAa,KAAK,WACjC,OAAO,QAAQ,KAAO,KAAK,KAC3B,OAAO,QAAQ,OAAS,KAAK,OAC7B,OAAO,QAAQ,cAAgB,KAAK,cACpC,OAAO,QAAQ,gBAAkB,KAAK,gBAEtC,OAAO,QAAQ,YAAc,KAAK,YAClC,OAAO,QAAQ,UAAY,KAAK,UAChC,OAAO,QAAQ,YAAc,KAAK,YAElC,OAAO,QAAQ,YAAc,KAAK,YAClC,OAAO,QAAQ,eAAiB,KAAK,eACrC,OAAO,QAAQ,gBAAkB,KAAK,gBACtC,OAAO,QAAQ,gBAAkB,KAAK,gBACtC,OAAO,QAAQ,kBAAoB,KAAK,kBAExC,OAAO,QAAQ,OAAS,KAAK,OAC7B,OAAO,QAAQ,cAAgB,KAAK,cACpC,OAAO,QAAQ,YAAc,KAAK,YAClC,OAAO,QAAQ,eAAiB,KAAK,eAErC,OAAO,QAAQ,MAAQ,MACvB,OAAO,QAAQ,eAAiB,MAChC,OAAO,QAAQ,IAAM,IACrB,OAAO,QAAQ,SAAW,SAE1B,OAAO,QAAQ,WAAa","file":"/npm/stream-chain@3.4.0/src/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/stream-chain@3.4.0/src/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","// @ts-self-types=\"./index.d.ts\"\n\n'use strict';\n\nconst {Readable, Writable, Duplex} = require('node:stream');\nconst defs = require('./defs');\nconst gen = require('./gen');\nconst asStream = require('./asStream');\n\n// is*NodeStream functions taken from https://github.com/nodejs/node/blob/master/lib/internal/streams/utils.js\nconst isReadableNodeStream = obj =>\n  obj &&\n  typeof obj.pipe === 'function' &&\n  typeof obj.on === 'function' &&\n  (!obj._writableState ||\n    (typeof obj._readableState === 'object' ? obj._readableState.readable : null) !== false) && // Duplex\n  (!obj._writableState || obj._readableState); // Writable has .pipe.\n\nconst isWritableNodeStream = obj =>\n  obj &&\n  typeof obj.write === 'function' &&\n  typeof obj.on === 'function' &&\n  (!obj._readableState ||\n    (typeof obj._writableState === 'object' ? obj._writableState.writable : null) !== false); // Duplex\n\nconst isDuplexNodeStream = obj =>\n  obj &&\n  typeof obj.pipe === 'function' &&\n  obj._readableState &&\n  typeof obj.on === 'function' &&\n  typeof obj.write === 'function';\n\nconst isReadableWebStream = obj =>\n  obj && globalThis.ReadableStream && obj instanceof globalThis.ReadableStream;\n\nconst isWritableWebStream = obj =>\n  obj && globalThis.WritableStream && obj instanceof globalThis.WritableStream;\n\nconst isDuplexWebStream = obj =>\n  obj &&\n  globalThis.ReadableStream &&\n  obj.readable instanceof globalThis.ReadableStream &&\n  globalThis.WritableStream &&\n  obj.writable instanceof globalThis.WritableStream;\n\nconst groupFunctions = (output, fn, index, fns) => {\n  if (\n    isDuplexNodeStream(fn) ||\n    (!index && isReadableNodeStream(fn)) ||\n    (index === fns.length - 1 && isWritableNodeStream(fn))\n  ) {\n    output.push(fn);\n    return output;\n  }\n  if (isDuplexWebStream(fn)) {\n    output.push(Duplex.fromWeb(fn, {objectMode: true}));\n    return output;\n  }\n  if (!index && isReadableWebStream(fn)) {\n    output.push(Readable.fromWeb(fn, {objectMode: true}));\n    return output;\n  }\n  if (index === fns.length - 1 && isWritableWebStream(fn)) {\n    output.push(Writable.fromWeb(fn, {objectMode: true}));\n    return output;\n  }\n  if (typeof fn != 'function')\n    throw TypeError('Item #' + index + ' is not a proper stream, nor a function.');\n  if (!output.length) output.push([]);\n  const last = output[output.length - 1];\n  if (Array.isArray(last)) {\n    last.push(fn);\n  } else {\n    output.push([fn]);\n  }\n  return output;\n};\n\nconst produceStreams = item => {\n  if (Array.isArray(item)) {\n    if (!item.length) return null;\n    if (item.length == 1) return item[0] && chain.asStream(item[0]);\n    return chain.asStream(chain.gen(...item));\n  }\n  return item;\n};\n\nconst wrapFunctions = (fn, index, fns) => {\n  if (\n    isDuplexNodeStream(fn) ||\n    (!index && isReadableNodeStream(fn)) ||\n    (index === fns.length - 1 && isWritableNodeStream(fn))\n  ) {\n    return fn; // an acceptable stream\n  }\n  if (isDuplexWebStream(fn)) {\n    return Duplex.fromWeb(fn, {objectMode: true});\n  }\n  if (!index && isReadableWebStream(fn)) {\n    return Readable.fromWeb(fn, {objectMode: true});\n  }\n  if (index === fns.length - 1 && isWritableWebStream(fn)) {\n    return Writable.fromWeb(fn, {objectMode: true});\n  }\n  if (typeof fn == 'function') return chain.asStream(fn); // a function\n  throw TypeError('Item #' + index + ' is not a proper stream, nor a function.');\n};\n\n// default implementation of required stream methods\n\nconst write = (input, chunk, encoding, callback) => {\n  let error = null;\n  try {\n    input.write(chunk, encoding, e => callback(e || error));\n  } catch (e) {\n    error = e;\n  }\n};\n\nconst final = (input, callback) => {\n  let error = null;\n  try {\n    input.end(null, null, e => callback(e || error));\n  } catch (e) {\n    error = e;\n  }\n};\n\nconst read = output => {\n  output.resume();\n};\n\n// the chain creator\n\nconst chain = (fns, options) => {\n  if (!Array.isArray(fns) || !fns.length) {\n    throw TypeError(\"Chain's first argument should be a non-empty array.\");\n  }\n\n  fns = fns.flat(Infinity).filter(fn => fn);\n\n  const streams = (\n      options && options.noGrouping\n        ? fns.map(wrapFunctions)\n        : fns\n            .map(fn => (defs.isFunctionList(fn) ? defs.getFunctionList(fn) : fn))\n            .flat(Infinity)\n            .reduce(groupFunctions, [])\n            .map(produceStreams)\n    ).filter(s => s),\n    input = streams[0],\n    output = streams.reduce((output, item) => (output && output.pipe(item)) || item);\n\n  let stream = null; // will be assigned later\n\n  let writeMethod = (chunk, encoding, callback) => write(input, chunk, encoding, callback),\n    finalMethod = callback => final(input, callback),\n    readMethod = () => read(output);\n\n  if (!isWritableNodeStream(input)) {\n    writeMethod = (_1, _2, callback) => callback(null);\n    finalMethod = callback => callback(null);\n    input.on('end', () => stream.end());\n  }\n\n  if (isReadableNodeStream(output)) {\n    output.on('data', chunk => !stream.push(chunk) && output.pause());\n    output.on('end', () => stream.push(null));\n  } else {\n    readMethod = () => {}; // nop\n    output.on('finish', () => stream.push(null));\n  }\n\n  stream = new Duplex(\n    Object.assign({writableObjectMode: true, readableObjectMode: true}, options, {\n      readable: isReadableNodeStream(output),\n      writable: isWritableNodeStream(input),\n      write: writeMethod,\n      final: finalMethod,\n      read: readMethod\n    })\n  );\n  stream.streams = streams;\n  stream.input = input;\n  stream.output = output;\n\n  if (!isReadableNodeStream(output)) {\n    stream.resume();\n  }\n\n  // connect events\n  if (!options || !options.skipEvents) {\n    streams.forEach(item => item.on('error', error => stream.emit('error', error)));\n  }\n\n  return stream;\n};\n\nconst dataSource = fn => {\n  if (typeof fn == 'function') return fn;\n  if (fn) {\n    if (typeof fn[Symbol.asyncIterator] == 'function') return fn[Symbol.asyncIterator].bind(fn);\n    if (typeof fn[Symbol.iterator] == 'function') return fn[Symbol.iterator].bind(fn);\n  }\n  throw new TypeError('The argument should be a function or an iterable object.');\n};\n\nmodule.exports = chain;\n\n// from defs.js\nmodule.exports.none = defs.none;\nmodule.exports.stop = defs.stop;\nmodule.exports.Stop = defs.Stop;\n\nmodule.exports.finalSymbol = defs.finalSymbol;\nmodule.exports.finalValue = defs.finalValue;\nmodule.exports.final = defs.final;\nmodule.exports.isFinalValue = defs.isFinalValue;\nmodule.exports.getFinalValue = defs.getFinalValue;\n\nmodule.exports.manySymbol = defs.manySymbol;\nmodule.exports.many = defs.many;\nmodule.exports.isMany = defs.isMany;\nmodule.exports.getManyValues = defs.getManyValues;\nmodule.exports.getFunctionList = defs.getFunctionList;\n\nmodule.exports.flushSymbol = defs.flushSymbol;\nmodule.exports.flushable = defs.flushable;\nmodule.exports.isFlushable = defs.isFlushable;\n\nmodule.exports.fListSymbol = defs.fListSymbol;\nmodule.exports.isFunctionList = defs.isFunctionList;\nmodule.exports.getFunctionList = defs.getFunctionList;\nmodule.exports.setFunctionList = defs.setFunctionList;\nmodule.exports.clearFunctionList = defs.clearFunctionList;\n\nmodule.exports.toMany = defs.toMany;\nmodule.exports.normalizeMany = defs.normalizeMany;\nmodule.exports.combineMany = defs.combineMany;\nmodule.exports.combineManyMut = defs.combineManyMut;\n\nmodule.exports.chain = chain;          // for compatibility with 2.x\nmodule.exports.chainUnchecked = chain; // for TypeScript to bypass type checks\nmodule.exports.gen = gen;\nmodule.exports.asStream = asStream;\n\nmodule.exports.dataSource = dataSource;\n"]}