async-iterator-to-stream
Advanced tools
Comparing version 1.0.2 to 1.0.3
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } | ||
var _symbol = _interopRequireDefault(require("@babel/runtime/core-js/symbol")); | ||
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } | ||
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); | ||
const _require = require('readable-stream'), | ||
Readable = _require.Readable; | ||
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); | ||
const getSymbol = typeof Symbol === 'function' ? name => { | ||
const symbol = Symbol[name]; | ||
return symbol !== undefined ? symbol : `@@${name}`; | ||
} : name => `@@${name}`; | ||
const $$asyncIterator = asyncIteratorToStream.$$asyncIterator = getSymbol('asyncIterator'); | ||
const $$iterator = asyncIteratorToStream.$$iterator = getSymbol('iterator'); | ||
var _require = require('readable-stream'), | ||
Readable = _require.Readable; | ||
const resolveToIterator = value => { | ||
let tmp; | ||
var next = function () { | ||
var _ref = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(iterator, arg) { | ||
var cursor, value, success; | ||
return _regenerator.default.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
cursor = iterator.next(arg); | ||
if (!(typeof cursor.then === 'function')) { | ||
_context.next = 3; | ||
break; | ||
} | ||
return _context.abrupt("return", cursor); | ||
case 3: | ||
if (!(!cursor.done && (value = cursor.value) != null && typeof value.then === 'function')) { | ||
_context.next = 18; | ||
break; | ||
} | ||
success = false; | ||
_context.prev = 5; | ||
_context.next = 8; | ||
return value; | ||
case 8: | ||
value = _context.sent; | ||
success = true; | ||
_context.next = 15; | ||
break; | ||
case 12: | ||
_context.prev = 12; | ||
_context.t0 = _context["catch"](5); | ||
cursor = iterator.throw(_context.t0); | ||
case 15: | ||
if (success) { | ||
cursor = iterator.next(value); | ||
} | ||
_context.next = 3; | ||
break; | ||
case 18: | ||
return _context.abrupt("return", cursor); | ||
case 19: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, this, [[5, 12]]); | ||
})); | ||
return function next(_x, _x2) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}(); | ||
var getSymbol = typeof _symbol.default === 'function' ? function (name) { | ||
var symbol = _symbol.default[name]; | ||
return symbol !== undefined ? symbol : "@@" + name; | ||
} : function (name) { | ||
return "@@" + name; | ||
}; | ||
var $$asyncIterator = asyncIteratorToStream.$$asyncIterator = getSymbol('asyncIterator'); | ||
var $$iterator = asyncIteratorToStream.$$iterator = getSymbol('iterator'); | ||
var resolveToIterator = function resolveToIterator(value) { | ||
var tmp; | ||
if (typeof (tmp = value[$$asyncIterator]) === 'function') { | ||
@@ -108,152 +40,83 @@ return tmp.call(value); | ||
var iterator = resolveToIterator(iterable); | ||
var readable = options instanceof Readable ? options : new Readable(options); | ||
const then = iterable.then; | ||
readable._destroy = function () { | ||
var _ref2 = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee2(error, cb) { | ||
return _regenerator.default.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
if (!(error != null)) { | ||
_context2.next = 12; | ||
break; | ||
} | ||
if (typeof then === 'function') { | ||
return then.call(iterable, iterable => asyncIteratorToStream(iterable, options)); | ||
} | ||
if (!('throw' in iterator)) { | ||
_context2.next = 10; | ||
break; | ||
} | ||
const iterator = resolveToIterator(iterable); | ||
const isGenerator = 'return' in iterator; | ||
const readable = options instanceof Readable ? options : new Readable(options); | ||
_context2.prev = 2; | ||
_context2.next = 5; | ||
return iterator.throw(error); | ||
case 5: | ||
_context2.next = 10; | ||
break; | ||
case 7: | ||
_context2.prev = 7; | ||
_context2.t0 = _context2["catch"](2); | ||
return _context2.abrupt("return", cb(_context2.t0)); | ||
case 10: | ||
_context2.next = 21; | ||
break; | ||
case 12: | ||
if (!('return' in iterator)) { | ||
_context2.next = 21; | ||
break; | ||
} | ||
_context2.prev = 13; | ||
_context2.next = 16; | ||
return iterator.return(); | ||
case 16: | ||
_context2.next = 21; | ||
break; | ||
case 18: | ||
_context2.prev = 18; | ||
_context2.t1 = _context2["catch"](13); | ||
cb(_context2.t1); | ||
case 21: | ||
cb(error); | ||
case 22: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
if (isGenerator) { | ||
readable._destroy = function () { | ||
var _ref = _asyncToGenerator(function* (error, cb) { | ||
try { | ||
yield error != null ? iterator.throw(error) : iterator.return(); | ||
} catch (error) { | ||
return cb(error); | ||
} | ||
}, _callee2, this, [[2, 7], [13, 18]]); | ||
})); | ||
return function (_x3, _x4) { | ||
return _ref2.apply(this, arguments); | ||
}; | ||
}(); | ||
cb(error); | ||
}); | ||
readable._read = function (size) { | ||
var running = false; | ||
return function (_x, _x2) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}(); | ||
} | ||
var read = readable._read = function () { | ||
var _ref3 = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee3(size) { | ||
var canPush, cursor, value; | ||
return _regenerator.default.wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
if (!running) { | ||
_context3.next = 2; | ||
break; | ||
} | ||
let running = false; | ||
return _context3.abrupt("return"); | ||
readable._read = function () { | ||
var _ref2 = _asyncToGenerator(function* (size) { | ||
if (running) { | ||
return; | ||
} | ||
case 2: | ||
running = true; | ||
_context3.prev = 3; | ||
canPush = true; | ||
running = true; | ||
case 5: | ||
_context3.next = 7; | ||
return next(iterator, size); | ||
try { | ||
let value; | ||
case 7: | ||
cursor = _context3.sent; | ||
do { | ||
let cursor = iterator.next(size); | ||
if (!cursor.done) { | ||
_context3.next = 10; | ||
break; | ||
} | ||
if (typeof cursor.then === 'function') { | ||
cursor = yield cursor; | ||
} else { | ||
while (!cursor.done && (value = cursor.value) != null && typeof value.then === 'function') { | ||
let success = false; | ||
return _context3.abrupt("return", readable.push(null)); | ||
try { | ||
value = yield value; | ||
success = true; | ||
} catch (error) { | ||
cursor = iterator.throw(error); | ||
} | ||
case 10: | ||
value = cursor.value; | ||
if (value !== undefined) { | ||
canPush = readable.push(value); | ||
} | ||
case 12: | ||
if (canPush) { | ||
_context3.next = 5; | ||
break; | ||
} | ||
case 13: | ||
_context3.next = 18; | ||
break; | ||
case 15: | ||
_context3.prev = 15; | ||
_context3.t0 = _context3["catch"](3); | ||
readable.emit('error', _context3.t0); | ||
case 18: | ||
_context3.prev = 18; | ||
running = false; | ||
return _context3.finish(18); | ||
case 21: | ||
case "end": | ||
return _context3.stop(); | ||
if (success) { | ||
cursor = iterator.next(value); | ||
} | ||
} | ||
} | ||
}, _callee3, this, [[3, 15, 18, 21]]); | ||
})); | ||
return function (_x5) { | ||
return _ref3.apply(this, arguments); | ||
}; | ||
}(); | ||
if (cursor.done) { | ||
return readable.push(null); | ||
} | ||
return read(size); | ||
}; | ||
value = cursor.value; | ||
} while (value === undefined || readable.push(value)); | ||
} catch (error) { | ||
process.nextTick(readable.emit.bind(readable, 'error', error)); | ||
} finally { | ||
running = false; | ||
} | ||
}); | ||
return function (_x3) { | ||
return _ref2.apply(this, arguments); | ||
}; | ||
}(); | ||
return readable; | ||
@@ -264,7 +127,5 @@ } | ||
asyncIteratorToStream.obj = function (iterable, options) { | ||
return asyncIteratorToStream(iterable, (0, _extends2.default)({ | ||
objectMode: true | ||
}, options)); | ||
}; | ||
asyncIteratorToStream.obj = (iterable, options) => asyncIteratorToStream(iterable, _extends({ | ||
objectMode: true | ||
}, options)); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "async-iterator-to-stream", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"license": "ISC", | ||
@@ -28,24 +28,18 @@ "description": "Convert an async iterator/iterable to a readable stream", | ||
], | ||
"browserslist": [ | ||
">2%" | ||
], | ||
"engines": { | ||
"node": ">=4" | ||
"node": ">=6" | ||
}, | ||
"dependencies": { | ||
"@babel/runtime": "^7.0.0-beta.42", | ||
"readable-stream": "^2.3.5" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.0.0-beta.42", | ||
"@babel/core": "^7.0.0-beta.42", | ||
"@babel/plugin-transform-runtime": "^7.0.0-beta.42", | ||
"@babel/preset-env": "^7.0.0-beta.42", | ||
"@babel/preset-flow": "^7.0.0-beta.42", | ||
"@babel/cli": "7.0.0-beta.52", | ||
"@babel/core": "7.0.0-beta.52", | ||
"@babel/preset-env": "7.0.0-beta.52", | ||
"babel-core": "^7.0.0-bridge.0", | ||
"babel-eslint": "^8.2.2", | ||
"babel-jest": "^21", | ||
"babel-jest": "^23.2.0", | ||
"babel-plugin-lodash": "^3.3.2", | ||
"cross-env": "^5.1.4", | ||
"eslint": "^4.19.1", | ||
"eslint": "^5.1.0", | ||
"eslint-config-standard": "^11.0.0", | ||
@@ -56,5 +50,4 @@ "eslint-plugin-import": "^2.9.0", | ||
"eslint-plugin-standard": "^3.0.1", | ||
"flow-bin": "^0.68.0", | ||
"husky": "^0.14.3", | ||
"jest": "^21", | ||
"jest": "^23.3.0", | ||
"rimraf": "^2.6.2" | ||
@@ -68,8 +61,7 @@ }, | ||
"dev-test": "jest --bail --watch", | ||
"posttest": "jest", | ||
"prebuild": "npm run clean", | ||
"predev": "npm run prebuild", | ||
"prepublishOnly": "npm run build", | ||
"pretest": "eslint --ignore-path .gitignore --fix .", | ||
"test": "flow status" | ||
"pretest": "eslint --ignore-path .gitignore .", | ||
"test": "jest" | ||
}, | ||
@@ -76,0 +68,0 @@ "jest": { |
@@ -81,15 +81,15 @@ # async-iterator-to-stream [![Build Status](https://travis-ci.org/JsCommunity/async-iterator-to-stream.png?branch=master)](https://travis-ci.org/JsCommunity/async-iterator-to-stream) | ||
# Install dependencies | ||
> yarn | ||
> npm | ||
# Run the tests | ||
> yarn test | ||
> npm test | ||
# Continuously compile | ||
> yarn dev | ||
> npm run dev | ||
# Continuously run the tests | ||
> yarn dev-test | ||
> npm run dev-test | ||
# Build for production | ||
> yarn build | ||
> npm run build | ||
``` | ||
@@ -96,0 +96,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1
17
15049
100
1
- Removed@babel/runtime@^7.0.0-beta.42
- Removed@babel/runtime@7.26.0(transitive)
- Removedregenerator-runtime@0.14.1(transitive)