stack-base-iterator
Advanced tools
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| Object.defineProperty(exports, "default", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return createProcessor; | ||
| } | ||
| }); | ||
| var _asynccompat = /*#__PURE__*/ _interop_require_default(require("async-compat")); | ||
| function _interop_require_default(obj) { | ||
| return obj && obj.__esModule ? obj : { | ||
| default: obj | ||
| }; | ||
| } | ||
| var isError = function(e) { | ||
| return e && e.stack && e.message; | ||
| }; | ||
| function processDone(err, options, callback) { | ||
| // mark this iteration done | ||
| options.err = options.err || err; | ||
| options.done = true; | ||
| // process done | ||
| if (!options.done || options.counter > 0) return false; | ||
| callback(options.err, options.done); | ||
| return true; | ||
| } | ||
| function processResult(err, keep, options, callback) { | ||
| options.counter--; | ||
| // mark this iteration done | ||
| if (err && _asynccompat.default.defaultValue(options.error(err), false) || !err && !_asynccompat.default.defaultValue(keep, true)) { | ||
| options.err = options.err || err; | ||
| options.done = true; | ||
| } | ||
| // process done | ||
| if (!options.done || options.counter > 0) return false; | ||
| callback(options.err, options.done); | ||
| return true; | ||
| } | ||
| function createProcessor(next, options, callback) { | ||
| var isProcessing = false; | ||
| return function processor(doneOrErr) { | ||
| if (doneOrErr && processDone(isError(doneOrErr) ? doneOrErr : null, options, callback)) return; | ||
| if (isProcessing) return; | ||
| isProcessing = true; | ||
| var counter = 0; | ||
| while(options.counter < options.concurrency){ | ||
| if (options.done || options.stop(counter++)) break; | ||
| if (options.total >= options.limit) return processDone(null, options, callback); | ||
| options.total++; | ||
| options.counter++; | ||
| next(function(err, value) { | ||
| if (err || value === null) { | ||
| return !processResult(err, false, options, callback) && !isProcessing ? processor() : undefined; | ||
| } | ||
| _asynccompat.default.asyncFunction(options.each, options.callbacks, value, function(err, keep) { | ||
| return !processResult(err, keep, options, callback) && !isProcessing ? processor() : undefined; | ||
| }); | ||
| }); | ||
| } | ||
| isProcessing = false; | ||
| }; | ||
| } | ||
| if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') { | ||
| Object.defineProperty(exports.default, '__esModule', { value: true }); | ||
| for (var key in exports) exports.default[key] = exports[key]; | ||
| module.exports = exports.default; | ||
| } |
| {"version":3,"sources":["createProcessor.mjs"],"sourcesContent":["import compat from 'async-compat';\n\nconst isError = (e) => e && e.stack && e.message;\n\nfunction processDone(err, options, callback) {\n // mark this iteration done\n options.err = options.err || err;\n options.done = true;\n\n // process done\n if (!options.done || options.counter > 0) return false;\n callback(options.err, options.done);\n return true;\n}\n\nfunction processResult(err, keep, options, callback) {\n options.counter--;\n\n // mark this iteration done\n if ((err && compat.defaultValue(options.error(err), false)) || (!err && !compat.defaultValue(keep, true))) {\n options.err = options.err || err;\n options.done = true;\n }\n\n // process done\n if (!options.done || options.counter > 0) return false;\n callback(options.err, options.done);\n return true;\n}\n\nexport default function createProcessor(next, options, callback) {\n let isProcessing = false;\n return function processor(doneOrErr) {\n if (doneOrErr && processDone(isError(doneOrErr) ? doneOrErr : null, options, callback)) return;\n if (isProcessing) return;\n isProcessing = true;\n\n let counter = 0;\n while (options.counter < options.concurrency) {\n if (options.done || options.stop(counter++)) break;\n if (options.total >= options.limit) return processDone(null, options, callback);\n options.total++;\n options.counter++;\n\n next((err, value) => {\n if (err || value === null) {\n return !processResult(err, false, options, callback) && !isProcessing ? processor() : undefined;\n }\n compat.asyncFunction(options.each, options.callbacks, value, (err, keep) => (!processResult(err, keep, options, callback) && !isProcessing ? processor() : undefined));\n });\n }\n\n isProcessing = false;\n };\n}\n"],"names":["createProcessor","isError","e","stack","message","processDone","err","options","callback","done","counter","processResult","keep","compat","defaultValue","error","next","isProcessing","processor","doneOrErr","concurrency","stop","total","limit","value","undefined","asyncFunction","each","callbacks"],"mappings":";;;;+BA8BA;;;eAAwBA;;;kEA9BL;;;;;;AAEnB,IAAMC,UAAU,SAACC;WAAMA,KAAKA,EAAEC,KAAK,IAAID,EAAEE,OAAO;;A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SAACV,KAAKkB;gBACT,IAAIlB,OAAOkB,UAAU,MAAM;oBACzB,OAAO,CAACb,cAAcL,KAAK,OAAOC,SAASC,aAAa,CAACS,eAAeC,cAAcO;gBACxF;gBACAZ,oBAAM,CAACa,aAAa,CAACnB,QAAQoB,IAAI,EAAEpB,QAAQqB,SAAS,EAAEJ,OAAO,SAAClB,KAAKM;2BAAU,CAACD,cAAcL,KAAKM,MAAML,SAASC,aAAa,CAACS,eAAeC,cAAcO;;YAC7J;QACF;QAEAR,eAAe;IACjB;AACF"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| Object.defineProperty(exports, "default", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return drainStack; | ||
| } | ||
| }); | ||
| var _processOrQueue = /*#__PURE__*/ _interop_require_default(require("./processOrQueue.js")); | ||
| function _interop_require_default(obj) { | ||
| return obj && obj.__esModule ? obj : { | ||
| default: obj | ||
| }; | ||
| } | ||
| function canProcess(iterator) { | ||
| if (iterator.done || !iterator.stack.length) return false; | ||
| if (iterator.queued.length) return true; | ||
| if (!iterator.processors.length) return false; | ||
| iterator.processors.first()(false); | ||
| if (iterator.done) return false; | ||
| return iterator.queued.length; | ||
| } | ||
| function drainStack(iterator) { | ||
| while(canProcess(iterator)){ | ||
| (0, _processOrQueue.default)(iterator, iterator.queued.pop()); | ||
| } | ||
| } | ||
| if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') { | ||
| Object.defineProperty(exports.default, '__esModule', { value: true }); | ||
| for (var key in exports) exports.default[key] = exports[key]; | ||
| module.exports = exports.default; | ||
| } |
| {"version":3,"sources":["drainStack.mjs"],"sourcesContent":["import processOrQueue from './processOrQueue.mjs';\n\nfunction canProcess(iterator) {\n if (iterator.done || !iterator.stack.length) return false;\n if (iterator.queued.length) return true;\n if (!iterator.processors.length) return false;\n iterator.processors.first()(false);\n if (iterator.done) return false;\n return iterator.queued.length;\n}\n\nexport default function drainStack(iterator) {\n while (canProcess(iterator)) {\n processOrQueue(iterator, iterator.queued.pop());\n }\n}\n"],"names":["drainStack","canProcess","iterator","done","stack","length","queued","processors","first","processOrQueue","pop"],"mappings":";;;;+BAWA;;;eAAwBA;;;qEAXG;;;;;;AAE3B,SAASC,WAAWC,QAAQ;IAC1B,IAAIA,SAASC,IAAI,IAAI,CAACD,SAASE,KAAK,CAACC,MAAM,EAAE,OAAO;IACpD,IAAIH,SAASI,MAAM,CAACD,MAAM,EAAE,OAAO;IACnC,IAAI,CAACH,SAASK,UAAU,CAACF,MAAM,EAAE,OAAO;IACxCH,SAASK,UAAU,CAACC,KAAK,GAAG;IAC5B,IAAIN,SAASC,IAAI,EAAE,OAAO;IAC1B,OAAOD,SAASI,MAAM,CAACD,MAAM;AAC/B;AAEe,SAASL,WAAWE,QAAQ;IACzC,MAAOD,WAAWC,UAAW;QAC3BO,IAAAA,uBAAc,EAACP,UAAUA,SAASI,MAAM,CAACI,GAAG;IAC9C;AACF"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| Object.defineProperty(exports, "default", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return fifoRemove; | ||
| } | ||
| }); | ||
| function fifoRemove(fifo, value) { | ||
| for(var node = fifo.node; node; node = fifo.next(node)){ | ||
| if (node.value === value) { | ||
| fifo.remove(node); | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
| if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') { | ||
| Object.defineProperty(exports.default, '__esModule', { value: true }); | ||
| for (var key in exports) exports.default[key] = exports[key]; | ||
| module.exports = exports.default; | ||
| } |
| {"version":3,"sources":["fifoRemove.mjs"],"sourcesContent":["export default function fifoRemove(fifo, value) {\n for (let node = fifo.node; node; node = fifo.next(node)) {\n if (node.value === value) {\n fifo.remove(node);\n return true;\n }\n }\n return false;\n}\n"],"names":["fifoRemove","fifo","value","node","next","remove"],"mappings":";;;;+BAAA;;;eAAwBA;;;AAAT,SAASA,WAAWC,IAAI,EAAEC,KAAK;IAC5C,IAAK,IAAIC,OAAOF,KAAKE,IAAI,EAAEA,MAAMA,OAAOF,KAAKG,IAAI,CAACD,MAAO;QACvD,IAAIA,KAAKD,KAAK,KAAKA,OAAO;YACxBD,KAAKI,MAAM,CAACF;YACZ,OAAO;QACT;IACF;IACA,OAAO;AACT"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| Object.defineProperty(exports, "default", { | ||
| enumerable: true, | ||
| get: function() { | ||
| return StackBaseIterator; | ||
| } | ||
| }); | ||
| var _fifo = /*#__PURE__*/ _interop_require_default(require("fifo")); | ||
| var _justextend = /*#__PURE__*/ _interop_require_default(require("just-extend")); | ||
| var _once = /*#__PURE__*/ _interop_require_default(require("once")); | ||
| var _createProcessor = /*#__PURE__*/ _interop_require_default(require("./createProcessor.js")); | ||
| var _drainStack = /*#__PURE__*/ _interop_require_default(require("./drainStack.js")); | ||
| var _fifoRemove = /*#__PURE__*/ _interop_require_default(require("./fifoRemove.js")); | ||
| var _processOrQueue = /*#__PURE__*/ _interop_require_default(require("./processOrQueue.js")); | ||
| function _class_call_check(instance, Constructor) { | ||
| if (!(instance instanceof Constructor)) { | ||
| throw new TypeError("Cannot call a class as a function"); | ||
| } | ||
| } | ||
| function _defineProperties(target, props) { | ||
| for(var i = 0; i < props.length; i++){ | ||
| var descriptor = props[i]; | ||
| descriptor.enumerable = descriptor.enumerable || false; | ||
| descriptor.configurable = true; | ||
| if ("value" in descriptor) descriptor.writable = true; | ||
| Object.defineProperty(target, descriptor.key, descriptor); | ||
| } | ||
| } | ||
| function _create_class(Constructor, protoProps, staticProps) { | ||
| if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
| if (staticProps) _defineProperties(Constructor, staticProps); | ||
| return Constructor; | ||
| } | ||
| function _interop_require_default(obj) { | ||
| return obj && obj.__esModule ? obj : { | ||
| default: obj | ||
| }; | ||
| } | ||
| var StackBaseIterator = /*#__PURE__*/ function() { | ||
| "use strict"; | ||
| function StackBaseIterator(options) { | ||
| _class_call_check(this, StackBaseIterator); | ||
| options = options || {}; | ||
| this.options = (0, _justextend.default)({}, options); | ||
| this.options.error = options.error || function defaultError(err) { | ||
| return !!err; // fail on errors | ||
| }; | ||
| this.queued = (0, _fifo.default)(); | ||
| this.processors = (0, _fifo.default)(); | ||
| this.stack = (0, _fifo.default)(); | ||
| this.entries = (0, _fifo.default)(); | ||
| this.links = (0, _fifo.default)(); | ||
| this.processing = (0, _fifo.default)(); | ||
| } | ||
| _create_class(StackBaseIterator, [ | ||
| { | ||
| key: "destroy", | ||
| value: function destroy(err) { | ||
| if (this.destroyed) throw new Error("Already destroyed"); | ||
| this.destroyed = true; | ||
| this.end(err); | ||
| } | ||
| }, | ||
| { | ||
| key: "push", | ||
| value: function push(item) { | ||
| if (this.done) return console.log("Attempting to push on a done iterator"); | ||
| this.stack.push(item); | ||
| (0, _drainStack.default)(this); | ||
| } | ||
| }, | ||
| { | ||
| key: "end", | ||
| value: function end(err) { | ||
| if (this.done) return; | ||
| this.done = true; | ||
| while(this.processors.length)this.processors.pop()(err || true); | ||
| while(this.processing.length)err ? this.processing.pop()(err) : this.processing.pop()(null, null); | ||
| while(this.queued.length)err ? this.queued.pop()(err) : this.queued.pop()(null, null); | ||
| while(this.stack.length)this.stack.pop(); | ||
| } | ||
| }, | ||
| { | ||
| key: "next", | ||
| value: function next(callback) { | ||
| if (typeof callback === "function") return (0, _processOrQueue.default)(this, (0, _once.default)(callback)); | ||
| var self = this; | ||
| return new Promise(function nextPromise(resolve, reject) { | ||
| self.next(function nextCallback(err, result) { | ||
| err ? reject(err) : resolve(result); | ||
| }); | ||
| }); | ||
| } | ||
| }, | ||
| { | ||
| key: "forEach", | ||
| value: function forEach(fn, options, callback) { | ||
| var self = this; | ||
| if (typeof fn !== "function") throw new Error("Missing each function"); | ||
| if (typeof options === "function") { | ||
| callback = options; | ||
| options = {}; | ||
| } | ||
| if (typeof callback === "function") { | ||
| if (this.done) return callback(null, true); | ||
| options = options || {}; | ||
| options = { | ||
| each: fn, | ||
| callbacks: options.callbacks || false, | ||
| concurrency: options.concurrency || 1, | ||
| limit: options.limit || Infinity, | ||
| error: options.error || function defaultError() { | ||
| return true; // default is exit on error | ||
| }, | ||
| total: 0, | ||
| counter: 0, | ||
| stop: function stop() { | ||
| return self.done || self.queued.length >= self.stack.length; | ||
| } | ||
| }; | ||
| var processor = (0, _createProcessor.default)(this.next.bind(this), options, function processorCallback(err) { | ||
| if (!self.destroyed) (0, _fifoRemove.default)(self.processors, processor); | ||
| processor = null; | ||
| options = null; | ||
| var done = !self.stack.length; | ||
| if ((err || done) && !self.done) self.end(err); | ||
| return callback(err, self.done || done); | ||
| }); | ||
| this.processors.push(processor); | ||
| processor(); | ||
| return; | ||
| } | ||
| return new Promise(function forEachPromise(resolve, reject) { | ||
| self.forEach(fn, options, function forEachCallback(err, done) { | ||
| err ? reject(err) : resolve(done); | ||
| }); | ||
| }); | ||
| } | ||
| } | ||
| ]); | ||
| return StackBaseIterator; | ||
| }(); | ||
| if (typeof Symbol !== "undefined" && Symbol.asyncIterator) { | ||
| StackBaseIterator.prototype[Symbol.asyncIterator] = function asyncIterator() { | ||
| var self = this; | ||
| return { | ||
| next: function next() { | ||
| return self.next().then(function nextCallback(value) { | ||
| return Promise.resolve({ | ||
| value: value, | ||
| done: value === null | ||
| }); | ||
| }); | ||
| }, | ||
| destroy: function destroy() { | ||
| self.destroy(); | ||
| return Promise.resolve(); | ||
| } | ||
| }; | ||
| }; | ||
| } | ||
| if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') { | ||
| Object.defineProperty(exports.default, '__esModule', { value: true }); | ||
| for (var key in exports) exports.default[key] = exports[key]; | ||
| module.exports = exports.default; | ||
| } |
| {"version":3,"sources":["index.mjs"],"sourcesContent":["import FIFO from 'fifo';\nimport assign from 'just-extend';\nimport once from 'once';\n\nimport createProcesor from './createProcessor.mjs';\nimport drainStack from './drainStack.mjs';\nimport fifoRemove from './fifoRemove.mjs';\nimport processOrQueue from './processOrQueue.mjs';\n\nexport default class StackBaseIterator {\n constructor(options) {\n options = options || {};\n this.options = assign({}, options);\n this.options.error =\n options.error ||\n function defaultError(err) {\n return !!err; // fail on errors\n };\n\n this.queued = FIFO();\n this.processors = FIFO();\n this.stack = FIFO();\n this.entries = FIFO();\n this.links = FIFO();\n this.processing = FIFO();\n }\n\n destroy(err) {\n if (this.destroyed) throw new Error('Already destroyed');\n this.destroyed = true;\n this.end(err);\n }\n\n push(item) {\n if (this.done) return console.log('Attempting to push on a done iterator');\n this.stack.push(item);\n drainStack(this);\n }\n\n end(err) {\n if (this.done) return;\n this.done = true;\n while (this.processors.length) this.processors.pop()(err || true);\n while (this.processing.length) err ? this.processing.pop()(err) : this.processing.pop()(null, null);\n while (this.queued.length) err ? this.queued.pop()(err) : this.queued.pop()(null, null);\n while (this.stack.length) this.stack.pop();\n }\n\n next(callback) {\n if (typeof callback === 'function') return processOrQueue(this, once(callback));\n\n const self = this;\n return new Promise(function nextPromise(resolve, reject) {\n self.next(function nextCallback(err, result) {\n err ? reject(err) : resolve(result);\n });\n });\n }\n\n forEach(fn, options, callback) {\n const self = this;\n if (typeof fn !== 'function') throw new Error('Missing each function');\n if (typeof options === 'function') {\n callback = options;\n options = {};\n }\n\n if (typeof callback === 'function') {\n if (this.done) return callback(null, true);\n options = options || {};\n options = {\n each: fn,\n callbacks: options.callbacks || false,\n concurrency: options.concurrency || 1,\n limit: options.limit || Infinity,\n error:\n options.error ||\n function defaultError() {\n return true; // default is exit on error\n },\n total: 0,\n counter: 0,\n stop: function stop() {\n return self.done || self.queued.length >= self.stack.length;\n },\n };\n\n let processor = createProcesor(this.next.bind(this), options, function processorCallback(err) {\n if (!self.destroyed) fifoRemove(self.processors, processor);\n processor = null;\n options = null;\n const done = !self.stack.length;\n if ((err || done) && !self.done) self.end(err);\n return callback(err, self.done || done);\n });\n this.processors.push(processor);\n processor();\n return;\n }\n\n return new Promise(function forEachPromise(resolve, reject) {\n self.forEach(fn, options, function forEachCallback(err, done) {\n err ? reject(err) : resolve(done);\n });\n });\n }\n}\n\nif (typeof Symbol !== 'undefined' && Symbol.asyncIterator) {\n StackBaseIterator.prototype[Symbol.asyncIterator] = function asyncIterator() {\n const self = this;\n return {\n next: function next() {\n return self.next().then(function nextCallback(value) {\n return Promise.resolve({ value: value, done: value === null });\n });\n },\n destroy: function destroy() {\n self.destroy();\n return Promise.resolve();\n },\n };\n };\n}\n"],"names":["StackBaseIterator","options","assign","error","defaultError","err","queued","FIFO","processors","stack","entries","links","processing","destroy","destroyed","Error","end","push","item","done","console","log","drainStack","length","pop","next","callback","processOrQueue","once","self","Promise","nextPromise","resolve","reject","nextCallback","result","forEach","fn","each","callbacks","concurrency","limit","Infinity","total","counter","stop","processor","createProcesor","bind","processorCallback","fifoRemove","forEachPromise","forEachCallback","Symbol","asyncIterator","prototype","then","value"],"mappings":";;;;;;;eASqBA;;;2DATJ;iEACE;2DACF;sEAEU;iEACJ;iEACA;qEACI;;;;;;;;;;;;;;;;;;;;;;;;;AAEZ,IAAA,AAAMA,kCAAD,AAAL;;aAAMA,kBACPC,OAAO;gCADAD;QAEjBC,UAAUA,WAAW,CAAC;QACtB,IAAI,CAACA,OAAO,GAAGC,IAAAA,mBAAM,EAAC,CAAC,GAAGD;QAC1B,IAAI,CAACA,OAAO,CAACE,KAAK,GAChBF,QAAQE,KAAK,IACb,SAASC,aAAaC,GAAG;YACvB,OAAO,CAAC,CAACA,KAAK,iBAAiB;QACjC;QAEF,IAAI,CAACC,MAAM,GAAGC,IAAAA,aAAI;QAClB,IAAI,CAACC,UAAU,GAAGD,IAAAA,aAAI;QACtB,IAAI,CAACE,KAAK,GAAGF,IAAAA,aAAI;QACjB,IAAI,CAACG,OAAO,GAAGH,IAAAA,aAAI;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AG,KAAM,CAACU,KAAKV,IAAI,EAAEU,KAAKb,GAAG,CAACX;wBAC1C,OAAOqB,SAASrB,KAAKwB,KAAKV,IAAI,IAAIA;oBACpC;oBACA,IAAI,CAACX,UAAU,CAACS,IAAI,CAAC6B;oBACrBA;oBACA;gBACF;gBAEA,OAAO,IAAIhB,QAAQ,SAASqB,eAAenB,OAAO,EAAEC,MAAM;oBACxDJ,KAAKO,OAAO,CAACC,IAAIpC,SAAS,SAASmD,gBAAgB/C,GAAG,EAAEc,IAAI;wBAC1Dd,MAAM4B,OAAO5B,OAAO2B,QAAQb;oBAC9B;gBACF;YACF;;;WAhGmBnB;;AAmGrB,IAAI,OAAOqD,WAAW,eAAeA,OAAOC,aAAa,EAAE;IACzDtD,kBAAkBuD,SAAS,CAACF,OAAOC,aAAa,CAAC,GAAG,SAASA;QAC3D,IAAMzB,OAAO,IAAI;QACjB,OAAO;YACLJ,MAAM,SAASA;gBACb,OAAOI,KAAKJ,IAAI,GAAG+B,IAAI,CAAC,SAAStB,aAAauB,KAAK;oBACjD,OAAO3B,QAAQE,OAAO,CAAC;wBAAEyB,OAAOA;wBAAOtC,MAAMsC,UAAU;oBAAK;gBAC9D;YACF;YACA5C,SAAS,SAASA;gBAChBgB,KAAKhB,OAAO;gBACZ,OAAOiB,QAAQE,OAAO;YACxB;QACF;IACF;AACF"} |
| {"type":"commonjs"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| var _asynccompat = /*#__PURE__*/ _interop_require_default(require("async-compat")); | ||
| var _fifoRemove = /*#__PURE__*/ _interop_require_default(require("./fifoRemove.js")); | ||
| function _interop_require_default(obj) { | ||
| return obj && obj.__esModule ? obj : { | ||
| default: obj | ||
| }; | ||
| } | ||
| module.exports = function processOrQueue(iterator, callback) { | ||
| if (iterator.done) return callback(null, null); | ||
| // nothing to process so queue | ||
| if (!iterator.stack.length) return iterator.queued.unshift(callback); | ||
| // process next | ||
| var next = iterator.stack.pop(); | ||
| iterator.processing.push(callback); | ||
| next(iterator, function nextCallback(err, result) { | ||
| if (iterator.done) return callback(null, null); | ||
| (0, _fifoRemove.default)(iterator.processing, callback); | ||
| if (err && _asynccompat.default.defaultValue(iterator.options.error(err), true)) err = null; // skip error | ||
| // done is based on stack being empty and not error state as the user may choose to skip the error | ||
| var done = !iterator.stack.length && iterator.processing.length <= 0; | ||
| !done && !err && !result ? processOrQueue(iterator, callback) : callback(err, result || null); | ||
| if (done && !iterator.done) iterator.end(); // end | ||
| }); | ||
| }; | ||
| if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') { | ||
| Object.defineProperty(exports.default, '__esModule', { value: true }); | ||
| for (var key in exports) exports.default[key] = exports[key]; | ||
| module.exports = exports.default; | ||
| } |
| {"version":3,"sources":["processOrQueue.mjs"],"sourcesContent":["import compat from 'async-compat';\n\nimport fifoRemove from './fifoRemove.mjs';\n\nmodule.exports = function processOrQueue(iterator, callback) {\n if (iterator.done) return callback(null, null);\n\n // nothing to process so queue\n if (!iterator.stack.length) return iterator.queued.unshift(callback);\n\n // process next\n const next = iterator.stack.pop();\n iterator.processing.push(callback);\n next(iterator, function nextCallback(err, result) {\n if (iterator.done) return callback(null, null);\n fifoRemove(iterator.processing, callback);\n if (err && compat.defaultValue(iterator.options.error(err), true)) err = null; // skip error\n\n // done is based on stack being empty and not error state as the user may choose to skip the error\n const done = !iterator.stack.length && iterator.processing.length <= 0;\n !done && !err && !result ? processOrQueue(iterator, callback) : callback(err, result || null);\n if (done && !iterator.done) iterator.end(); // end\n });\n};\n"],"names":["module","exports","processOrQueue","iterator","callback","done","stack","length","queued","unshift","next","pop","processing","push","nextCallback","err","result","fifoRemove","compat","defaultValue","options","error","end"],"mappings":";;;;kEAAmB;iEAEI;;;;;;AAEvBA,OAAOC,OAAO,GAAG,SAASC,eAAeC,QAAQ,EAAEC,QAAQ;IACzD,IAAID,SAASE,IAAI,EAAE,OAAOD,SAAS,MAAM;IAEzC,8BAA8B;IAC9B,IAAI,CAACD,SAASG,KAAK,CAACC,MAAM,EAAE,OAAOJ,SAASK,MAAM,CAACC,OAAO,CAACL;IAE3D,eAAe;IACf,IAAMM,OAAOP,SAASG,KAAK,CAACK,GAAG;IAC/BR,SAASS,UAAU,CAACC,IAAI,CAACT;IACzBM,KAAKP,UAAU,SAASW,aAAaC,GAAG,EAAEC,MAAM;QAC9C,IAAIb,SAASE,IAAI,EAAE,OAAOD,SAAS,MAAM;QACzCa,IAAAA,mBAAU,EAACd,SAASS,UAAU,EAAER;QAChC,IAAIW,OAAOG,oBAAM,CAACC,YAAY,CAAChB,SAASiB,OAAO,CAACC,KAAK,CAACN,MAAM,OAAOA,MAAM,MAAM,aAAa;QAE5F,kGAAkG;QAClG,IAAMV,OAAO,CAACF,SAASG,KAAK,CAACC,MAAM,IAAIJ,SAASS,UAAU,CAACL,MAAM,IAAI;QACrE,CAACF,QAAQ,CAACU,OAAO,CAACC,SAASd,eAAeC,UAAUC,YAAYA,SAASW,KAAKC,UAAU;QACxF,IAAIX,QAAQ,CAACF,SAASE,IAAI,EAAEF,SAASmB,GAAG,IAAI,MAAM;IACpD;AACF"} |
| import compat from 'async-compat'; | ||
| const isError = (e)=>e && e.stack && e.message; | ||
| function processDone(err, options, callback) { | ||
| // mark this iteration done | ||
| options.err = options.err || err; | ||
| options.done = true; | ||
| // process done | ||
| if (!options.done || options.counter > 0) return false; | ||
| callback(options.err, options.done); | ||
| return true; | ||
| } | ||
| function processResult(err, keep, options, callback) { | ||
| options.counter--; | ||
| // mark this iteration done | ||
| if (err && compat.defaultValue(options.error(err), false) || !err && !compat.defaultValue(keep, true)) { | ||
| options.err = options.err || err; | ||
| options.done = true; | ||
| } | ||
| // process done | ||
| if (!options.done || options.counter > 0) return false; | ||
| callback(options.err, options.done); | ||
| return true; | ||
| } | ||
| export default function createProcessor(next, options, callback) { | ||
| let isProcessing = false; | ||
| return function processor(doneOrErr) { | ||
| if (doneOrErr && processDone(isError(doneOrErr) ? doneOrErr : null, options, callback)) return; | ||
| if (isProcessing) return; | ||
| isProcessing = true; | ||
| let counter = 0; | ||
| while(options.counter < options.concurrency){ | ||
| if (options.done || options.stop(counter++)) break; | ||
| if (options.total >= options.limit) return processDone(null, options, callback); | ||
| options.total++; | ||
| options.counter++; | ||
| next((err, value)=>{ | ||
| if (err || value === null) { | ||
| return !processResult(err, false, options, callback) && !isProcessing ? processor() : undefined; | ||
| } | ||
| compat.asyncFunction(options.each, options.callbacks, value, (err, keep)=>!processResult(err, keep, options, callback) && !isProcessing ? processor() : undefined); | ||
| }); | ||
| } | ||
| isProcessing = false; | ||
| }; | ||
| } |
| {"version":3,"sources":["createProcessor.mjs"],"sourcesContent":["import compat from 'async-compat';\n\nconst isError = (e) => e && e.stack && e.message;\n\nfunction processDone(err, options, callback) {\n // mark this iteration done\n options.err = options.err || err;\n options.done = true;\n\n // process done\n if (!options.done || options.counter > 0) return false;\n callback(options.err, options.done);\n return true;\n}\n\nfunction processResult(err, keep, options, callback) {\n options.counter--;\n\n // mark this iteration done\n if ((err && compat.defaultValue(options.error(err), false)) || (!err && !compat.defaultValue(keep, true))) {\n options.err = options.err || err;\n options.done = true;\n }\n\n // process done\n if (!options.done || options.counter > 0) return false;\n callback(options.err, options.done);\n return true;\n}\n\nexport default function createProcessor(next, options, callback) {\n let isProcessing = false;\n return function processor(doneOrErr) {\n if (doneOrErr && processDone(isError(doneOrErr) ? doneOrErr : null, options, callback)) return;\n if (isProcessing) return;\n isProcessing = true;\n\n let counter = 0;\n while (options.counter < options.concurrency) {\n if (options.done || options.stop(counter++)) break;\n if (options.total >= options.limit) return processDone(null, options, callback);\n options.total++;\n options.counter++;\n\n next((err, value) => {\n if (err || value === null) {\n return !processResult(err, false, options, callback) && !isProcessing ? processor() : undefined;\n }\n compat.asyncFunction(options.each, options.callbacks, value, (err, keep) => (!processResult(err, keep, options, callback) && !isProcessing ? processor() : undefined));\n });\n }\n\n isProcessing = false;\n };\n}\n"],"names":["compat","isError","e","stack","message","processDone","err","options","callback","done","counter","processResult","keep","defaultValue","error","createProcessor","next","isProcessing","processor","doneOrErr","concurrency","stop","total","limit","value","undefined","asyncFunction","each","callbacks"],"mappings":"AAAA,OAAOA,YAAY,eAAe;AAElC,MAAMC,UAAU,CAACC,IAAMA,KAAKA,EAAEC,KAAK,IAAID,EAAEE,OAAO;AAEhD,SAASC,YAAYC,GAAG,EAAEC,OAAO,EAAEC,QAAQ;IACzC,2BAA2B;IAC3BD,QAAQD,GAAG,GAAGC,QAAQD,GAAG,IAAIA;IAC7BC,QAAQE,IAAI,GAAG;IAEf,eAAe;IACf,IAAI,CAACF,QAAQE,IAAI,IAAIF,QAAQG,OAAO,GAAG,GAAG,OAAO;IACjDF,SAASD,QAAQD,GAAG,EAAEC,QAAQE,IAAI;IAClC,OAAO;AACT;AAEA,SAASE,cAAcL,GAAG,EAAEM,IAAI,EAAEL,OAAO,EAAEC,QAAQ;IACjDD,QAAQG,OAAO;IAEf,2BAA2B;IAC3B,IAAI,AAACJ,OAAON,OAAOa,YAAY,CAACN,QAAQO,KAAK,CAACR,MAAM,UAAY,CAACA,OAAO,CAACN,OAAOa,YAAY,CAACD,MAAM,OAAQ;QACzGL,QAAQD,GAAG,GAAGC,QAAQD,GAAG,IAAIA;QAC7BC,QAAQE,IAAI,GAAG;IACjB;IAEA,eAAe;IACf,IAAI,CAACF,QAAQE,IAAI,IAAIF,QAAQG,OAAO,GAAG,GAAG,OAAO;IACjDF,SAASD,QAAQD,GAAG,EAAEC,QAAQE,IAAI;IAClC,OAAO;AACT;AAEA,eAAe,SAASM,gBAAgBC,IAAI,EAAET,OAAO,EAAEC,QAAQ;IAC7D,IAAIS,eAAe;IACnB,OAAO,SAASC,UAAUC,SAAS;QACjC,IAAIA,aAAad,YAAYJ,QAAQkB,aAAaA,YAAY,MAAMZ,SAASC,WAAW;QACxF,IAAIS,cAAc;QAClBA,eAAe;QAEf,IAAIP,UAAU;QACd,MAAOH,QAAQG,OAAO,GAAGH,QAAQa,WAAW,CAAE;YAC5C,IAAIb,QAAQE,IAAI,IAAIF,QAAQc,IAAI,CAACX,YAAY;YAC7C,IAAIH,QAAQe,KAAK,IAAIf,QAAQgB,KAAK,EAAE,OAAOlB,YAAY,MAAME,SAASC;YACtED,QAAQe,KAAK;YACbf,QAAQG,OAAO;YAEfM,KAAK,CAACV,KAAKkB;gBACT,IAAIlB,OAAOkB,UAAU,MAAM;oBACzB,OAAO,CAACb,cAAcL,KAAK,OAAOC,SAASC,aAAa,CAACS,eAAeC,cAAcO;gBACxF;gBACAzB,OAAO0B,aAAa,CAACnB,QAAQoB,IAAI,EAAEpB,QAAQqB,SAAS,EAAEJ,OAAO,CAAClB,KAAKM,OAAU,CAACD,cAAcL,KAAKM,MAAML,SAASC,aAAa,CAACS,eAAeC,cAAcO;YAC7J;QACF;QAEAR,eAAe;IACjB;AACF"} |
| import processOrQueue from './processOrQueue.mjs'; | ||
| function canProcess(iterator) { | ||
| if (iterator.done || !iterator.stack.length) return false; | ||
| if (iterator.queued.length) return true; | ||
| if (!iterator.processors.length) return false; | ||
| iterator.processors.first()(false); | ||
| if (iterator.done) return false; | ||
| return iterator.queued.length; | ||
| } | ||
| export default function drainStack(iterator) { | ||
| while(canProcess(iterator)){ | ||
| processOrQueue(iterator, iterator.queued.pop()); | ||
| } | ||
| } |
| {"version":3,"sources":["drainStack.mjs"],"sourcesContent":["import processOrQueue from './processOrQueue.mjs';\n\nfunction canProcess(iterator) {\n if (iterator.done || !iterator.stack.length) return false;\n if (iterator.queued.length) return true;\n if (!iterator.processors.length) return false;\n iterator.processors.first()(false);\n if (iterator.done) return false;\n return iterator.queued.length;\n}\n\nexport default function drainStack(iterator) {\n while (canProcess(iterator)) {\n processOrQueue(iterator, iterator.queued.pop());\n }\n}\n"],"names":["processOrQueue","canProcess","iterator","done","stack","length","queued","processors","first","drainStack","pop"],"mappings":"AAAA,OAAOA,oBAAoB,uBAAuB;AAElD,SAASC,WAAWC,QAAQ;IAC1B,IAAIA,SAASC,IAAI,IAAI,CAACD,SAASE,KAAK,CAACC,MAAM,EAAE,OAAO;IACpD,IAAIH,SAASI,MAAM,CAACD,MAAM,EAAE,OAAO;IACnC,IAAI,CAACH,SAASK,UAAU,CAACF,MAAM,EAAE,OAAO;IACxCH,SAASK,UAAU,CAACC,KAAK,GAAG;IAC5B,IAAIN,SAASC,IAAI,EAAE,OAAO;IAC1B,OAAOD,SAASI,MAAM,CAACD,MAAM;AAC/B;AAEA,eAAe,SAASI,WAAWP,QAAQ;IACzC,MAAOD,WAAWC,UAAW;QAC3BF,eAAeE,UAAUA,SAASI,MAAM,CAACI,GAAG;IAC9C;AACF"} |
| export default function fifoRemove(fifo, value) { | ||
| for(let node = fifo.node; node; node = fifo.next(node)){ | ||
| if (node.value === value) { | ||
| fifo.remove(node); | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } |
| {"version":3,"sources":["fifoRemove.mjs"],"sourcesContent":["export default function fifoRemove(fifo, value) {\n for (let node = fifo.node; node; node = fifo.next(node)) {\n if (node.value === value) {\n fifo.remove(node);\n return true;\n }\n }\n return false;\n}\n"],"names":["fifoRemove","fifo","value","node","next","remove"],"mappings":"AAAA,eAAe,SAASA,WAAWC,IAAI,EAAEC,KAAK;IAC5C,IAAK,IAAIC,OAAOF,KAAKE,IAAI,EAAEA,MAAMA,OAAOF,KAAKG,IAAI,CAACD,MAAO;QACvD,IAAIA,KAAKD,KAAK,KAAKA,OAAO;YACxBD,KAAKI,MAAM,CAACF;YACZ,OAAO;QACT;IACF;IACA,OAAO;AACT"} |
| import FIFO from 'fifo'; | ||
| import assign from 'just-extend'; | ||
| import once from 'once'; | ||
| import createProcesor from './createProcessor.mjs'; | ||
| import drainStack from './drainStack.mjs'; | ||
| import fifoRemove from './fifoRemove.mjs'; | ||
| import processOrQueue from './processOrQueue.mjs'; | ||
| let StackBaseIterator = class StackBaseIterator { | ||
| destroy(err) { | ||
| if (this.destroyed) throw new Error('Already destroyed'); | ||
| this.destroyed = true; | ||
| this.end(err); | ||
| } | ||
| push(item) { | ||
| if (this.done) return console.log('Attempting to push on a done iterator'); | ||
| this.stack.push(item); | ||
| drainStack(this); | ||
| } | ||
| end(err) { | ||
| if (this.done) return; | ||
| this.done = true; | ||
| while(this.processors.length)this.processors.pop()(err || true); | ||
| while(this.processing.length)err ? this.processing.pop()(err) : this.processing.pop()(null, null); | ||
| while(this.queued.length)err ? this.queued.pop()(err) : this.queued.pop()(null, null); | ||
| while(this.stack.length)this.stack.pop(); | ||
| } | ||
| next(callback) { | ||
| if (typeof callback === 'function') return processOrQueue(this, once(callback)); | ||
| const self = this; | ||
| return new Promise(function nextPromise(resolve, reject) { | ||
| self.next(function nextCallback(err, result) { | ||
| err ? reject(err) : resolve(result); | ||
| }); | ||
| }); | ||
| } | ||
| forEach(fn, options, callback) { | ||
| const self = this; | ||
| if (typeof fn !== 'function') throw new Error('Missing each function'); | ||
| if (typeof options === 'function') { | ||
| callback = options; | ||
| options = {}; | ||
| } | ||
| if (typeof callback === 'function') { | ||
| if (this.done) return callback(null, true); | ||
| options = options || {}; | ||
| options = { | ||
| each: fn, | ||
| callbacks: options.callbacks || false, | ||
| concurrency: options.concurrency || 1, | ||
| limit: options.limit || Infinity, | ||
| error: options.error || function defaultError() { | ||
| return true; // default is exit on error | ||
| }, | ||
| total: 0, | ||
| counter: 0, | ||
| stop: function stop() { | ||
| return self.done || self.queued.length >= self.stack.length; | ||
| } | ||
| }; | ||
| let processor = createProcesor(this.next.bind(this), options, function processorCallback(err) { | ||
| if (!self.destroyed) fifoRemove(self.processors, processor); | ||
| processor = null; | ||
| options = null; | ||
| const done = !self.stack.length; | ||
| if ((err || done) && !self.done) self.end(err); | ||
| return callback(err, self.done || done); | ||
| }); | ||
| this.processors.push(processor); | ||
| processor(); | ||
| return; | ||
| } | ||
| return new Promise(function forEachPromise(resolve, reject) { | ||
| self.forEach(fn, options, function forEachCallback(err, done) { | ||
| err ? reject(err) : resolve(done); | ||
| }); | ||
| }); | ||
| } | ||
| constructor(options){ | ||
| options = options || {}; | ||
| this.options = assign({}, options); | ||
| this.options.error = options.error || function defaultError(err) { | ||
| return !!err; // fail on errors | ||
| }; | ||
| this.queued = FIFO(); | ||
| this.processors = FIFO(); | ||
| this.stack = FIFO(); | ||
| this.entries = FIFO(); | ||
| this.links = FIFO(); | ||
| this.processing = FIFO(); | ||
| } | ||
| }; | ||
| export { StackBaseIterator as default }; | ||
| if (typeof Symbol !== 'undefined' && Symbol.asyncIterator) { | ||
| StackBaseIterator.prototype[Symbol.asyncIterator] = function asyncIterator() { | ||
| const self = this; | ||
| return { | ||
| next: function next() { | ||
| return self.next().then(function nextCallback(value) { | ||
| return Promise.resolve({ | ||
| value: value, | ||
| done: value === null | ||
| }); | ||
| }); | ||
| }, | ||
| destroy: function destroy() { | ||
| self.destroy(); | ||
| return Promise.resolve(); | ||
| } | ||
| }; | ||
| }; | ||
| } |
| {"version":3,"sources":["index.mjs"],"sourcesContent":["import FIFO from 'fifo';\nimport assign from 'just-extend';\nimport once from 'once';\n\nimport createProcesor from './createProcessor.mjs';\nimport drainStack from './drainStack.mjs';\nimport fifoRemove from './fifoRemove.mjs';\nimport processOrQueue from './processOrQueue.mjs';\n\nexport default class StackBaseIterator {\n constructor(options) {\n options = options || {};\n this.options = assign({}, options);\n this.options.error =\n options.error ||\n function defaultError(err) {\n return !!err; // fail on errors\n };\n\n this.queued = FIFO();\n this.processors = FIFO();\n this.stack = FIFO();\n this.entries = FIFO();\n this.links = FIFO();\n this.processing = FIFO();\n }\n\n destroy(err) {\n if (this.destroyed) throw new Error('Already destroyed');\n this.destroyed = true;\n this.end(err);\n }\n\n push(item) {\n if (this.done) return console.log('Attempting to push on a done iterator');\n this.stack.push(item);\n drainStack(this);\n }\n\n end(err) {\n if (this.done) return;\n this.done = true;\n while (this.processors.length) this.processors.pop()(err || true);\n while (this.processing.length) err ? this.processing.pop()(err) : this.processing.pop()(null, null);\n while (this.queued.length) err ? this.queued.pop()(err) : this.queued.pop()(null, null);\n while (this.stack.length) this.stack.pop();\n }\n\n next(callback) {\n if (typeof callback === 'function') return processOrQueue(this, once(callback));\n\n const self = this;\n return new Promise(function nextPromise(resolve, reject) {\n self.next(function nextCallback(err, result) {\n err ? reject(err) : resolve(result);\n });\n });\n }\n\n forEach(fn, options, callback) {\n const self = this;\n if (typeof fn !== 'function') throw new Error('Missing each function');\n if (typeof options === 'function') {\n callback = options;\n options = {};\n }\n\n if (typeof callback === 'function') {\n if (this.done) return callback(null, true);\n options = options || {};\n options = {\n each: fn,\n callbacks: options.callbacks || false,\n concurrency: options.concurrency || 1,\n limit: options.limit || Infinity,\n error:\n options.error ||\n function defaultError() {\n return true; // default is exit on error\n },\n total: 0,\n counter: 0,\n stop: function stop() {\n return self.done || self.queued.length >= self.stack.length;\n },\n };\n\n let processor = createProcesor(this.next.bind(this), options, function processorCallback(err) {\n if (!self.destroyed) fifoRemove(self.processors, processor);\n processor = null;\n options = null;\n const done = !self.stack.length;\n if ((err || done) && !self.done) self.end(err);\n return callback(err, self.done || done);\n });\n this.processors.push(processor);\n processor();\n return;\n }\n\n return new Promise(function forEachPromise(resolve, reject) {\n self.forEach(fn, options, function forEachCallback(err, done) {\n err ? reject(err) : resolve(done);\n });\n });\n }\n}\n\nif (typeof Symbol !== 'undefined' && Symbol.asyncIterator) {\n StackBaseIterator.prototype[Symbol.asyncIterator] = function asyncIterator() {\n const self = this;\n return {\n next: function next() {\n return self.next().then(function nextCallback(value) {\n return Promise.resolve({ value: value, done: value === null });\n });\n },\n destroy: function destroy() {\n self.destroy();\n return Promise.resolve();\n },\n };\n };\n}\n"],"names":["FIFO","assign","once","createProcesor","drainStack","fifoRemove","processOrQueue","StackBaseIterator","destroy","err","destroyed","Error","end","push","item","done","console","log","stack","processors","length","pop","processing","queued","next","callback","self","Promise","nextPromise","resolve","reject","nextCallback","result","forEach","fn","options","each","callbacks","concurrency","limit","Infinity","error","defaultError","total","counter","stop","processor","bind","processorCallback","forEachPromise","forEachCallback","constructor","entries","links","Symbol","asyncIterator","prototype","then","value"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,OAAOC,YAAY,cAAc;AACjC,OAAOC,UAAU,OAAO;AAExB,OAAOC,oBAAoB,wBAAwB;AACnD,OAAOC,gBAAgB,mBAAmB;AAC1C,OAAOC,gBAAgB,mBAAmB;AAC1C,OAAOC,oBAAoB,uBAAuB;AAEnC,IAAA,AAAMC,oBAAN,MAAMA;IAkBnBC,QAAQC,GAAG,EAAE;QACX,IAAI,IAAI,CAACC,SAAS,EAAE,MAAM,IAAIC,MAAM;QACpC,IAAI,CAACD,SAAS,GAAG;QACjB,IAAI,CAACE,GAAG,CAACH;IACX;IAEAI,KAAKC,IAAI,EAAE;QACT,IAAI,IAAI,CAACC,IAAI,EAAE,OAAOC,QAAQC,GAAG,CAAC;QAClC,IAAI,CAACC,KAAK,CAACL,IAAI,CAACC;QAChBV,WAAW,IAAI;IACjB;IAEAQ,IAAIH,GAAG,EAAE;QACP,IAAI,IAAI,CAACM,IAAI,EAAE;QACf,IAAI,CAACA,IAAI,GAAG;QACZ,MAAO,IAAI,CAACI,UAAU,CAACC,MAAM,CAAE,IAAI,CAACD,UAAU,CAACE,GAAG,GAAGZ,OAAO;QAC5D,MAAO,IAAI,CAACa,UAAU,CAACF,MAAM,CAAEX,MAAM,IAAI,CAACa,UAAU,CAACD,GAAG,GAAGZ,OAAO,IAAI,CAACa,UAAU,CAACD,GAAG,GAAG,MAAM;QAC9F,MAAO,IAAI,CAACE,MAAM,CAACH,MAAM,CAAEX,MAAM,IAAI,CAACc,MAAM,CAACF,GAAG,GAAGZ,OAAO,IAAI,CAACc,MAAM,CAACF,GAAG,GAAG,MAAM;QAClF,MAAO,IAAI,CAACH,KAAK,CAACE,MAAM,CAAE,IAAI,CAACF,KAAK,CAACG,GAAG;IAC1C;IAEAG,KAAKC,QAAQ,EAAE;QACb,IAAI,OAAOA,aAAa,YAAY,OAAOnB,eAAe,IAAI,EAAEJ,K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{"type":"module"} |
| import compat from 'async-compat'; | ||
| import fifoRemove from './fifoRemove.mjs'; | ||
| module.exports = function processOrQueue(iterator, callback) { | ||
| if (iterator.done) return callback(null, null); | ||
| // nothing to process so queue | ||
| if (!iterator.stack.length) return iterator.queued.unshift(callback); | ||
| // process next | ||
| const next = iterator.stack.pop(); | ||
| iterator.processing.push(callback); | ||
| next(iterator, function nextCallback(err, result) { | ||
| if (iterator.done) return callback(null, null); | ||
| fifoRemove(iterator.processing, callback); | ||
| if (err && compat.defaultValue(iterator.options.error(err), true)) err = null; // skip error | ||
| // done is based on stack being empty and not error state as the user may choose to skip the error | ||
| const done = !iterator.stack.length && iterator.processing.length <= 0; | ||
| !done && !err && !result ? processOrQueue(iterator, callback) : callback(err, result || null); | ||
| if (done && !iterator.done) iterator.end(); // end | ||
| }); | ||
| }; |
| {"version":3,"sources":["processOrQueue.mjs"],"sourcesContent":["import compat from 'async-compat';\n\nimport fifoRemove from './fifoRemove.mjs';\n\nmodule.exports = function processOrQueue(iterator, callback) {\n if (iterator.done) return callback(null, null);\n\n // nothing to process so queue\n if (!iterator.stack.length) return iterator.queued.unshift(callback);\n\n // process next\n const next = iterator.stack.pop();\n iterator.processing.push(callback);\n next(iterator, function nextCallback(err, result) {\n if (iterator.done) return callback(null, null);\n fifoRemove(iterator.processing, callback);\n if (err && compat.defaultValue(iterator.options.error(err), true)) err = null; // skip error\n\n // done is based on stack being empty and not error state as the user may choose to skip the error\n const done = !iterator.stack.length && iterator.processing.length <= 0;\n !done && !err && !result ? processOrQueue(iterator, callback) : callback(err, result || null);\n if (done && !iterator.done) iterator.end(); // end\n });\n};\n"],"names":["compat","fifoRemove","module","exports","processOrQueue","iterator","callback","done","stack","length","queued","unshift","next","pop","processing","push","nextCallback","err","result","defaultValue","options","error","end"],"mappings":"AAAA,OAAOA,YAAY,eAAe;AAElC,OAAOC,gBAAgB,mBAAmB;AAE1CC,OAAOC,OAAO,GAAG,SAASC,eAAeC,QAAQ,EAAEC,QAAQ;IACzD,IAAID,SAASE,IAAI,EAAE,OAAOD,SAAS,MAAM;IAEzC,8BAA8B;IAC9B,IAAI,CAACD,SAASG,KAAK,CAACC,MAAM,EAAE,OAAOJ,SAASK,MAAM,CAACC,OAAO,CAACL;IAE3D,eAAe;IACf,MAAMM,OAAOP,SAASG,KAAK,CAACK,GAAG;IAC/BR,SAASS,UAAU,CAACC,IAAI,CAACT;IACzBM,KAAKP,UAAU,SAASW,aAAaC,GAAG,EAAEC,MAAM;QAC9C,IAAIb,SAASE,IAAI,EAAE,OAAOD,SAAS,MAAM;QACzCL,WAAWI,SAASS,UAAU,EAAER;QAChC,IAAIW,OAAOjB,OAAOmB,YAAY,CAACd,SAASe,OAAO,CAACC,KAAK,CAACJ,MAAM,OAAOA,MAAM,MAAM,aAAa;QAE5F,kGAAkG;QAClG,MAAMV,OAAO,CAACF,SAASG,KAAK,CAACC,MAAM,IAAIJ,SAASS,UAAU,CAACL,MAAM,IAAI;QACrE,CAACF,QAAQ,CAACU,OAAO,CAACC,SAASd,eAAeC,UAAUC,YAAYA,SAASW,KAAKC,UAAU;QACxF,IAAIX,QAAQ,CAACF,SAASE,IAAI,EAAEF,SAASiB,GAAG,IAAI,MAAM;IACpD;AACF"} |
| export default function createProcessor(next: any, options: any, callback: any): (doneOrErr: any) => boolean; |
| export default function drainStack(iterator: any): void; |
| export default function fifoRemove(fifo: any, value: any): boolean; |
| export default class StackBaseIterator { | ||
| constructor(options: any); | ||
| options: object; | ||
| queued: FIFO<any>; | ||
| processors: FIFO<any>; | ||
| stack: FIFO<any>; | ||
| entries: FIFO<any>; | ||
| links: FIFO<any>; | ||
| processing: FIFO<any>; | ||
| destroy(err: any): void; | ||
| destroyed: boolean; | ||
| push(item: any): void; | ||
| end(err: any): void; | ||
| done: boolean; | ||
| next(callback: any): any; | ||
| forEach(fn: any, options: any, callback: any): any; | ||
| } | ||
| import FIFO from 'fifo'; |
| export {}; |
+34
-21
| { | ||
| "name": "stack-base-iterator", | ||
| "version": "0.1.7", | ||
| "version": "1.0.0", | ||
| "description": "Base iterator for values retrieved using a stack of async functions returning values", | ||
@@ -19,36 +19,49 @@ "keywords": [ | ||
| "author": "Kevin Malakoff <kmalakoff@gmail.com> (https://github.com/kmalakoff)", | ||
| "main": "lib/index.js", | ||
| "type": "module", | ||
| "exports": { | ||
| ".": { | ||
| "import": "./dist/esm/index.mjs", | ||
| "require": "./dist/cjs/index.js", | ||
| "types": "./dist/types/index.d.ts" | ||
| }, | ||
| "./*": "./*" | ||
| }, | ||
| "main": "dist/cjs/index.js", | ||
| "module": "dist/esm/index.mjs", | ||
| "types": "dist/types/index.d.ts", | ||
| "files": [ | ||
| "lib" | ||
| "dist" | ||
| ], | ||
| "scripts": { | ||
| "format": "prettier --write .", | ||
| "lint": "eslint .", | ||
| "prepublishOnly": "dtd \"npm run lint\" \"depcheck\"", | ||
| "test": "mocha-compat test/spec/**/*.test.js --no-timeouts" | ||
| "build": "tsds build", | ||
| "deploy": "tsds deploy", | ||
| "format": "biome check --apply-unsafe src/ test/", | ||
| "test": "tsds test:node --timeout=10000", | ||
| "test:engines": "nvu engines npm test", | ||
| "version": "tsds version" | ||
| }, | ||
| "dependencies": { | ||
| "async-compat": "^1.4.6", | ||
| "async-compat": "^1.4.7", | ||
| "fifo": "^2.4.1", | ||
| "inherits": "^2.0.4", | ||
| "just-extend": "^6.0.1", | ||
| "maximize-iterator": "^2.6.5", | ||
| "just-extend": "^6.2.0", | ||
| "once": "^1.4.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@typescript-eslint/parser": "^5.30.0", | ||
| "depcheck": "^1.4.3", | ||
| "dis-dat": "^0.1.6", | ||
| "eslint": "^8.18.0", | ||
| "eslint-config-prettier": "^8.5.0", | ||
| "eslint-config-standard": "^17.0.0", | ||
| "eslint-plugin-import": "^2.26.0", | ||
| "eslint-plugin-n": "^15.2.3", | ||
| "eslint-plugin-promise": "^6.0.0", | ||
| "mocha-compat": "^3.5.5", | ||
| "prettier": "^2.7.1" | ||
| "@biomejs/biome": "^1.5.3", | ||
| "@types/mocha": "^10.0.6", | ||
| "@types/node": "^20.11.19", | ||
| "depcheck": "^1.4.7", | ||
| "ts-dev-stack": "^0.13.0" | ||
| }, | ||
| "engines": { | ||
| "node": ">=0.8" | ||
| }, | ||
| "tsds": { | ||
| "source": "src/index.mjs", | ||
| "targets": [ | ||
| "cjs", | ||
| "esm" | ||
| ] | ||
| } | ||
| } |
+0
-1
@@ -81,3 +81,2 @@ ## stack-base-iterator | ||
| var assert = require('assert'); | ||
| var Queue = require('queue-cb'); | ||
| var BaseIterator = require('stack-base-iterator')); | ||
@@ -84,0 +83,0 @@ |
| var processOrQueue = require('./processOrQueue'); | ||
| function canProcess(iterator) { | ||
| if (iterator.done || !iterator.stack.length) return false; | ||
| if (iterator.queued.length) return true; | ||
| if (!iterator.processors.length) return false; | ||
| iterator.processors.first()(false); | ||
| if (iterator.done) return false; | ||
| return iterator.queued.length; | ||
| } | ||
| module.exports = function drainStack(iterator) { | ||
| while (canProcess(iterator)) { | ||
| processOrQueue(iterator, iterator.queued.pop()); | ||
| } | ||
| }; |
| module.exports = function fifoRemove(fifo, value) { | ||
| for (var node = fifo.node; node; node = fifo.next(node)) { | ||
| if (node.value === value) { | ||
| fifo.remove(node); | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| }; |
| module.exports = require('./StackBaseIterator'); |
| var compat = require('async-compat'); | ||
| var fifoRemove = require('./fifoRemove'); | ||
| module.exports = function processOrQueue(iterator, callback) { | ||
| if (iterator.done) return callback(null, null); | ||
| // nothing to process so queue | ||
| if (!iterator.stack.length) return iterator.queued.unshift(callback); | ||
| // process next | ||
| var next = iterator.stack.pop(); | ||
| iterator.processing.push(callback); | ||
| next(iterator, function nextCallback(err, result) { | ||
| if (iterator.done) return callback(null, null); | ||
| fifoRemove(iterator.processing, callback); | ||
| if (err && compat.defaultValue(iterator.options.error(err), true)) err = null; // skip error | ||
| // done is based on stack being empty and not error state as the user may choose to skip the error | ||
| var done = !iterator.stack.length && iterator.processing.length <= 0; | ||
| !done && !err && !result ? processOrQueue(iterator, callback) : callback(err, result || null); | ||
| if (done && !iterator.done) iterator.end(); // end | ||
| }); | ||
| }; |
| var FIFO = require('fifo'); | ||
| var once = require('once'); | ||
| var assign = require('just-extend'); | ||
| var createProcesor = require('maximize-iterator/lib/createProcessor'); | ||
| var fifoRemove = require('./fifoRemove'); | ||
| var drainStack = require('./drainStack'); | ||
| var processOrQueue = require('./processOrQueue'); | ||
| function StackBaseIterator(options) { | ||
| if (!(this instanceof StackBaseIterator)) return new StackBaseIterator(options); | ||
| options = options || {}; | ||
| var self = this; | ||
| self.options = assign({}, options); | ||
| self.options.error = | ||
| options.error || | ||
| function defaultError(err) { | ||
| return !!err; // fail on errors | ||
| }; | ||
| self.queued = FIFO(); | ||
| self.processors = FIFO(); | ||
| self.stack = FIFO(); | ||
| self.entries = FIFO(); | ||
| self.links = FIFO(); | ||
| self.processing = FIFO(); | ||
| } | ||
| StackBaseIterator.prototype.destroy = function destroy(err) { | ||
| if (this.destroyed) throw new Error('Already destroyed'); | ||
| this.destroyed = true; | ||
| this.end(err); | ||
| }; | ||
| StackBaseIterator.prototype.push = function push(item) { | ||
| if (this.done) return console.log('Attempting to push on a done iterator'); | ||
| this.stack.push(item); | ||
| drainStack(this); | ||
| }; | ||
| StackBaseIterator.prototype.end = function end(err) { | ||
| if (this.done) return; | ||
| this.done = true; | ||
| while (this.processors.length) this.processors.pop()(err || true); | ||
| while (this.processing.length) err ? this.processing.pop()(err) : this.processing.pop()(null, null); | ||
| while (this.queued.length) err ? this.queued.pop()(err) : this.queued.pop()(null, null); | ||
| while (this.stack.length) this.stack.pop(); | ||
| }; | ||
| StackBaseIterator.prototype.next = function next(callback) { | ||
| if (typeof callback === 'function') return processOrQueue(this, once(callback)); | ||
| var self = this; | ||
| return new Promise(function nextPromise(resolve, reject) { | ||
| self.next(function nextCallback(err, result) { | ||
| err ? reject(err) : resolve(result); | ||
| }); | ||
| }); | ||
| }; | ||
| StackBaseIterator.prototype.forEach = function forEach(fn, options, callback) { | ||
| var self = this; | ||
| if (typeof fn !== 'function') throw new Error('Missing each function'); | ||
| if (typeof options === 'function') { | ||
| callback = options; | ||
| options = {}; | ||
| } | ||
| if (typeof callback === 'function') { | ||
| if (this.done) return callback(null, true); | ||
| options = options || {}; | ||
| options = { | ||
| each: fn, | ||
| callbacks: options.callbacks || false, | ||
| concurrency: options.concurrency || 1, | ||
| limit: options.limit || Infinity, | ||
| error: | ||
| options.error || | ||
| function defaultError() { | ||
| return true; // default is exit on error | ||
| }, | ||
| total: 0, | ||
| counter: 0, | ||
| stop: function stop() { | ||
| return self.done || self.queued.length >= self.stack.length; | ||
| }, | ||
| }; | ||
| var processor = createProcesor(this.next.bind(this), options, function processorCallback(err) { | ||
| if (!self.destroyed) fifoRemove(self.processors, processor); | ||
| processor = null; | ||
| options = null; | ||
| var done = !self.stack.length; | ||
| if ((err || done) && !self.done) self.end(err); | ||
| return callback(err, self.done || done); | ||
| }); | ||
| this.processors.push(processor); | ||
| processor(); | ||
| return; | ||
| } | ||
| return new Promise(function forEachPromise(resolve, reject) { | ||
| self.forEach(fn, options, function forEachCallback(err, done) { | ||
| err ? reject(err) : resolve(done); | ||
| }); | ||
| }); | ||
| }; | ||
| if (typeof Symbol !== 'undefined' && Symbol.asyncIterator) { | ||
| StackBaseIterator.prototype[Symbol.asyncIterator] = function asyncIterator() { | ||
| var self = this; | ||
| return { | ||
| next: function next() { | ||
| return self.next().then(function nextCallback(value) { | ||
| return Promise.resolve({ value: value, done: value === null }); | ||
| }); | ||
| }, | ||
| destroy: function destroy() { | ||
| self.destroy(); | ||
| return Promise.resolve(); | ||
| }, | ||
| }; | ||
| }; | ||
| } | ||
| module.exports = StackBaseIterator; |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
56860
470.54%5
-16.67%5
-54.55%30
275%522
236.77%0
-100%Yes
NaN104
-0.95%1
Infinity%- Removed
- Removed
- Removed
Updated
Updated