UNPKG

@socketsecurity/lib

Version:

Core utilities and infrastructure for Socket.dev security tools

81 lines (80 loc) 2.64 kB
"use strict"; /* Socket Lib - Built with esbuild */ var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var streams_exports = {}; __export(streams_exports, { parallelEach: () => parallelEach, parallelMap: () => parallelMap, transform: () => transform }); module.exports = __toCommonJS(streams_exports); var import_promises = require("./promises"); let _streamingIterables; // @__NO_SIDE_EFFECTS__ function getStreamingIterables() { if (_streamingIterables === void 0) { _streamingIterables = require("./external/streaming-iterables"); } return _streamingIterables; } // @__NO_SIDE_EFFECTS__ async function parallelEach(iterable, func, options) { for await (const _ of /* @__PURE__ */ parallelMap(iterable, func, options)) { } } // @__NO_SIDE_EFFECTS__ function parallelMap(iterable, func, options) { const streamingIterables = /* @__PURE__ */ getStreamingIterables(); const opts = (0, import_promises.normalizeIterationOptions)(options); const result = streamingIterables?.parallelMap( opts.concurrency, async (item) => { const result2 = await (0, import_promises.pRetry)((...args) => func(args[0]), { ...opts.retries, args: [item] }); return result2; }, iterable ); return result; } // @__NO_SIDE_EFFECTS__ function transform(iterable, func, options) { const streamingIterables = /* @__PURE__ */ getStreamingIterables(); const opts = (0, import_promises.normalizeIterationOptions)(options); const result = streamingIterables?.transform( opts.concurrency, async (item) => { const result2 = await (0, import_promises.pRetry)((...args) => func(args[0]), { ...opts.retries, args: [item] }); return result2; }, iterable ); return result; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { parallelEach, parallelMap, transform });