json-stream-stringify
Advanced tools
+554
| import { Readable } from 'stream'; | ||
| function _typeof(obj) { | ||
| if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { | ||
| _typeof = function (obj) { | ||
| return typeof obj; | ||
| }; | ||
| } else { | ||
| _typeof = function (obj) { | ||
| return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
| }; | ||
| } | ||
| return _typeof(obj); | ||
| } | ||
| function _classCallCheck(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 _createClass(Constructor, protoProps, staticProps) { | ||
| if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
| if (staticProps) _defineProperties(Constructor, staticProps); | ||
| return Constructor; | ||
| } | ||
| function _inherits(subClass, superClass) { | ||
| if (typeof superClass !== "function" && superClass !== null) { | ||
| throw new TypeError("Super expression must either be null or a function"); | ||
| } | ||
| subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
| constructor: { | ||
| value: subClass, | ||
| writable: true, | ||
| configurable: true | ||
| } | ||
| }); | ||
| if (superClass) _setPrototypeOf(subClass, superClass); | ||
| } | ||
| function _getPrototypeOf(o) { | ||
| _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { | ||
| return o.__proto__ || Object.getPrototypeOf(o); | ||
| }; | ||
| return _getPrototypeOf(o); | ||
| } | ||
| function _setPrototypeOf(o, p) { | ||
| _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { | ||
| o.__proto__ = p; | ||
| return o; | ||
| }; | ||
| return _setPrototypeOf(o, p); | ||
| } | ||
| function _assertThisInitialized(self) { | ||
| if (self === void 0) { | ||
| throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
| } | ||
| return self; | ||
| } | ||
| function _possibleConstructorReturn(self, call) { | ||
| if (call && (typeof call === "object" || typeof call === "function")) { | ||
| return call; | ||
| } | ||
| return _assertThisInitialized(self); | ||
| } | ||
| var rxEscapable = /[\\"\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g; // table of character substitutions | ||
| var meta = { | ||
| '\b': '\\b', | ||
| '\t': '\\t', | ||
| '\n': '\\n', | ||
| '\f': '\\f', | ||
| '\r': '\\r', | ||
| '"': '\\"', | ||
| '\\': '\\\\' | ||
| }; | ||
| function isReadableStream(value) { | ||
| return typeof value.read === 'function' && typeof value.once === 'function' && typeof value.removeListener === 'function' && _typeof(value._readableState) === 'object'; | ||
| } | ||
| function getType(value) { | ||
| if (!value) return 'Primitive'; | ||
| if (typeof value.then === 'function') return 'Promise'; | ||
| if (isReadableStream(value)) return "Readable".concat(value._readableState.objectMode ? 'Object' : 'String'); | ||
| if (Array.isArray(value)) return 'Array'; | ||
| if (_typeof(value) === 'object' || value instanceof Object) return 'Object'; | ||
| return 'Primitive'; | ||
| } | ||
| var stackItemEnd = { | ||
| Array: ']', | ||
| Object: '}', | ||
| ReadableString: '"', | ||
| ReadableObject: ']' | ||
| }; | ||
| var stackItemOpen = { | ||
| Array: '[', | ||
| Object: '{', | ||
| ReadableString: '"', | ||
| ReadableObject: '[' | ||
| }; | ||
| function escapeString(string) { | ||
| // Modified code, original code by Douglas Crockford | ||
| // Original: https://github.com/douglascrockford/JSON-js/blob/master/json2.js | ||
| // If the string contains no control characters, no quote characters, and no | ||
| // backslash characters, then we can safely slap some quotes around it. | ||
| // Otherwise we must also replace the offending characters with safe escape | ||
| // sequences. | ||
| return string.replace(rxEscapable, function (a) { | ||
| var c = meta[a]; | ||
| return typeof c === 'string' ? c : "\\u".concat(a.charCodeAt(0).toString(16).padStart(4, '0')); | ||
| }); | ||
| } | ||
| function quoteString(string) { | ||
| return "\"".concat(escapeString(string), "\""); | ||
| } | ||
| function readAsPromised(stream, size) { | ||
| var value = stream.read(size); | ||
| if (value === null) { | ||
| return new Promise(function (resolve, reject) { | ||
| var endListener = function endListener() { | ||
| return resolve(null); | ||
| }; | ||
| stream.once('end', endListener); | ||
| stream.once('error', reject); | ||
| stream.once('readable', function () { | ||
| stream.removeListener('end', endListener); | ||
| stream.removeListener('error', reject); | ||
| resolve(stream.read()); | ||
| }); | ||
| }); | ||
| } | ||
| return Promise.resolve(value); | ||
| } | ||
| function recursiveResolve(promise) { | ||
| return promise.then(function (res) { | ||
| var resType = getType(res); | ||
| return resType === 'Promise' ? recursiveResolve(res) : res; | ||
| }); | ||
| } | ||
| var JsonStreamStringify = | ||
| /*#__PURE__*/ | ||
| function (_Readable) { | ||
| _inherits(JsonStreamStringify, _Readable); | ||
| function JsonStreamStringify(value, replacer, spaces, cycle) { | ||
| var _this; | ||
| _classCallCheck(this, JsonStreamStringify); | ||
| _this = _possibleConstructorReturn(this, _getPrototypeOf(JsonStreamStringify).call(this, {})); | ||
| var gap; | ||
| var spaceType = _typeof(spaces); | ||
| if (spaceType === 'string' || spaceType === 'number') { | ||
| gap = Number.isFinite(spaces) ? ' '.repeat(spaces) : spaces; | ||
| } | ||
| Object.assign(_assertThisInitialized(_assertThisInitialized(_this)), { | ||
| visited: cycle ? new WeakMap() : new WeakSet(), | ||
| cycle: cycle, | ||
| stack: [], | ||
| replacerFunction: replacer instanceof Function && replacer, | ||
| replacerArray: Array.isArray(replacer) && replacer, | ||
| gap: gap, | ||
| depth: 0 | ||
| }); | ||
| _this.addToStack(value); | ||
| return _this; | ||
| } | ||
| _createClass(JsonStreamStringify, [{ | ||
| key: "cycler", | ||
| value: function cycler(key, value) { | ||
| var existingPath = this.visited.get(value); | ||
| if (existingPath) { | ||
| return { | ||
| $ref: existingPath | ||
| }; | ||
| } | ||
| var path = this.path(); | ||
| if (key !== undefined) path.push(key); | ||
| path = path.map(function (v) { | ||
| return "[".concat(Number.isInteger(v) ? v : quoteString(v), "]"); | ||
| }); | ||
| this.visited.set(value, path.length ? "$".concat(path.join('')) : '$'); | ||
| return value; | ||
| } | ||
| }, { | ||
| key: "addToStack", | ||
| value: function addToStack(value, key, index) { | ||
| var _this2 = this; | ||
| var realValue = value; | ||
| if (this.replacerFunction) { | ||
| realValue = this.replacerFunction(key || index, realValue, this); | ||
| } // ORDER? | ||
| if (realValue && realValue.toJSON instanceof Function) { | ||
| realValue = realValue.toJSON(); | ||
| } | ||
| if (realValue instanceof Function || _typeof(value) === 'symbol') { | ||
| realValue = undefined; | ||
| } | ||
| if (key !== undefined && this.replacerArray) { | ||
| if (!this.replacerArray.includes(key)) { | ||
| realValue = undefined; | ||
| } | ||
| } | ||
| var type = getType(realValue); | ||
| if (realValue !== undefined && type !== 'Promise' && key) { | ||
| if (this.gap) { | ||
| this._push("\n".concat(this.gap.repeat(this.depth), "\"").concat(escapeString(key), "\": ")); | ||
| } else { | ||
| this._push("\"".concat(escapeString(key), "\":")); | ||
| } | ||
| } | ||
| if (type !== 'Primitive') { | ||
| if (this.cycle) { | ||
| // run cycler | ||
| realValue = this.cycler(key || index, realValue); | ||
| type = getType(realValue); | ||
| } else { | ||
| // check for circular structure | ||
| if (this.visited.has(realValue)) { | ||
| throw Object.assign(new Error('Converting circular structure to JSON'), { | ||
| realValue: realValue, | ||
| key: key || index | ||
| }); | ||
| } | ||
| this.visited.add(realValue); | ||
| } | ||
| } | ||
| if (!key && index > -1 && this.depth && this.gap) this._push("\n".concat(this.gap.repeat(this.depth))); | ||
| var open = stackItemOpen[type]; | ||
| if (open) this._push(open); | ||
| var obj = { | ||
| key: key, | ||
| index: index, | ||
| type: type, | ||
| value: realValue | ||
| }; | ||
| if (type === 'Object') { | ||
| this.depth += 1; | ||
| obj.unread = Object.keys(realValue); | ||
| obj.isEmpty = !obj.unread.length; | ||
| } else if (type === 'Array') { | ||
| this.depth += 1; | ||
| obj.unread = Array.from(Array(realValue.length).keys()); | ||
| obj.isEmpty = !obj.unread.length; | ||
| } else if (type.startsWith('Readable')) { | ||
| this.depth += 1; | ||
| if (realValue._readableState.ended) { | ||
| this.emit('error', new Error('Readable Stream has ended before it was serialized. All stream data have been lost'), realValue, key || index); | ||
| } else if (realValue._readableState.flowing) { | ||
| realValue.pause(); | ||
| this.emit('error', new Error('Readable Stream is in flowing mode, data may have been lost. Trying to pause stream.'), realValue, key || index); | ||
| } | ||
| obj.readCount = 0; | ||
| realValue.once('end', function () { | ||
| obj.end = true; | ||
| _this2.__read(); | ||
| }); | ||
| realValue.once('error', function (err) { | ||
| _this2.error = true; | ||
| _this2.emit('error', err); | ||
| }); | ||
| obj.first = true; | ||
| } | ||
| this.stack.unshift(obj); | ||
| return obj; | ||
| } | ||
| }, { | ||
| key: "removeFromStack", | ||
| value: function removeFromStack(item) { | ||
| var type = item.type; | ||
| var isObject = type === 'Object' || type === 'Array' || type.startsWith('Readable'); | ||
| if (type !== 'Primitive') { | ||
| if (!this.cycle) { | ||
| this.visited.delete(item.value); | ||
| } | ||
| if (isObject) { | ||
| this.depth -= 1; | ||
| } | ||
| } | ||
| var end = stackItemEnd[type]; | ||
| if (isObject && !item.isEmpty && this.gap) this._push("\n".concat(this.gap.repeat(this.depth))); | ||
| if (end) this._push(end); | ||
| if (item.addSeparatorAfterEnd) { | ||
| this._push(','); | ||
| } | ||
| this.stack.splice(this.stack.indexOf(item), 1); | ||
| } | ||
| }, { | ||
| key: "_push", | ||
| value: function _push(data) { | ||
| this.pushCalled = true; | ||
| this.push(data); | ||
| } | ||
| }, { | ||
| key: "processReadableObject", | ||
| value: function processReadableObject(current, size) { | ||
| var _this3 = this; | ||
| if (current.end) { | ||
| this.removeFromStack(current); | ||
| return undefined; | ||
| } | ||
| return readAsPromised(current.value, size).then(function (value) { | ||
| if (value !== null) { | ||
| if (!current.first) { | ||
| _this3._push(','); | ||
| } | ||
| /* eslint-disable no-param-reassign */ | ||
| current.first = false; | ||
| _this3.addToStack(value, undefined, current.readCount); | ||
| current.readCount += 1; | ||
| /* eslint-enable no-param-reassign */ | ||
| } | ||
| }); | ||
| } | ||
| }, { | ||
| key: "processObject", | ||
| value: function processObject(current) { | ||
| if (!current.unread.length) { | ||
| this.removeFromStack(current); | ||
| return; | ||
| } | ||
| var key = current.unread.shift(); | ||
| var value = current.value[key]; | ||
| this.addToStack(value, current.type === 'Object' && key, current.type === 'Array' && key).addSeparatorAfterEnd = !!current.unread.length; | ||
| } | ||
| }, { | ||
| key: "processArray", | ||
| value: function processArray(current) { | ||
| return this.processObject(current); | ||
| } | ||
| }, { | ||
| key: "processPrimitive", | ||
| value: function processPrimitive(current) { | ||
| if (current.value !== undefined) { | ||
| var type = _typeof(current.value); | ||
| var value; | ||
| switch (type) { | ||
| case 'string': | ||
| value = quoteString(current.value); | ||
| break; | ||
| case 'number': | ||
| value = Number.isFinite(current.value) ? String(current.value) : 'null'; | ||
| break; | ||
| case 'boolean': | ||
| case 'null': | ||
| value = String(current.value); | ||
| break; | ||
| case 'object': | ||
| if (!current.value) { | ||
| value = 'null'; | ||
| break; | ||
| } | ||
| /* eslint-disable-next-line no-fallthrough */ | ||
| default: | ||
| // This should never happen, I can't imagine a situation where this executes. | ||
| // If you find a way, please open a ticket or PR | ||
| throw Object.assign(new Error("Unknown type \"".concat(type, "\". Please file an issue!")), { | ||
| value: current.value | ||
| }); | ||
| } | ||
| this._push(value); | ||
| } else if (this.stack[1] && (this.stack[1].type === 'Array' || this.stack[1].type === 'ReadableObject')) { | ||
| this._push('null'); | ||
| } else { | ||
| /* eslint-disable-next-line no-param-reassign */ | ||
| current.addSeparatorAfterEnd = false; | ||
| } | ||
| this.removeFromStack(current); | ||
| } | ||
| }, { | ||
| key: "processReadableString", | ||
| value: function processReadableString(current, size) { | ||
| var _this4 = this; | ||
| if (current.end) { | ||
| this.removeFromStack(current); | ||
| return undefined; | ||
| } | ||
| return readAsPromised(current.value, size).then(function (value) { | ||
| if (value) _this4._push(escapeString(value.toString())); | ||
| }); | ||
| } | ||
| }, { | ||
| key: "processPromise", | ||
| value: function processPromise(current) { | ||
| var _this5 = this; | ||
| return recursiveResolve(current.value).then(function (value) { | ||
| var addSeparatorAfterEnd = current.addSeparatorAfterEnd; | ||
| /* eslint-disable-next-line no-param-reassign */ | ||
| current.addSeparatorAfterEnd = false; | ||
| _this5.removeFromStack(current); | ||
| _this5.addToStack(value, current.key, current.index).addSeparatorAfterEnd = addSeparatorAfterEnd; | ||
| }); | ||
| } | ||
| }, { | ||
| key: "processStackTopItem", | ||
| value: function processStackTopItem(size) { | ||
| var _this6 = this; | ||
| var current = this.stack[0]; | ||
| if (!current || this.error) return Promise.resolve(); | ||
| var out; | ||
| try { | ||
| out = this["process".concat(current.type)](current, size); | ||
| } catch (err) { | ||
| return Promise.reject(err); | ||
| } | ||
| return Promise.resolve(out).then(function () { | ||
| if (_this6.stack.length === 0) { | ||
| _this6.end = true; | ||
| _this6._push(null); | ||
| } | ||
| }); | ||
| } | ||
| }, { | ||
| key: "__read", | ||
| value: function __read(size) { | ||
| var _this7 = this; | ||
| if (this.isRunning || this.error) { | ||
| this.readMore = true; | ||
| return undefined; | ||
| } | ||
| this.isRunning = true; // we must continue to read while push has not been called | ||
| this.readMore = false; | ||
| return this.processStackTopItem(size).then(function () { | ||
| var readAgain = !_this7.end && !_this7.error && (_this7.readMore || !_this7.pushCalled); | ||
| if (readAgain) { | ||
| setImmediate(function () { | ||
| _this7.isRunning = false; | ||
| _this7.__read(); | ||
| }); | ||
| } else { | ||
| _this7.isRunning = false; | ||
| } | ||
| }).catch(function (err) { | ||
| _this7.error = true; | ||
| _this7.emit('error', err); | ||
| }); | ||
| } | ||
| }, { | ||
| key: "_read", | ||
| value: function _read(size) { | ||
| this.pushCalled = false; | ||
| this.__read(size); | ||
| } | ||
| }, { | ||
| key: "path", | ||
| value: function path() { | ||
| return this.stack.map(function (_ref) { | ||
| var key = _ref.key, | ||
| index = _ref.index; | ||
| return key || index; | ||
| }).filter(function (v) { | ||
| return v || v > -1; | ||
| }).reverse(); | ||
| } | ||
| }]); | ||
| return JsonStreamStringify; | ||
| }(Readable); | ||
| export default JsonStreamStringify; | ||
| //# sourceMappingURL=module.js.map |
| {"version":3,"file":"module.js","sources":["../src/JsonStreamStringify.js"],"sourcesContent":["import { Readable } from 'stream';\n\nconst rxEscapable = /[\\\\\"\\u0000-\\u001f\\u007f-\\u009f\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f\\ufeff\\ufff0-\\uffff]/g;\n\n// table of character substitutions\nconst meta = {\n '\\b': '\\\\b',\n '\\t': '\\\\t',\n '\\n': '\\\\n',\n '\\f': '\\\\f',\n '\\r': '\\\\r',\n '\"': '\\\\\"',\n '\\\\': '\\\\\\\\',\n};\n\nfunction isReadableStream(value) {\n return typeof value.read === 'function'\n && typeof value.once === 'function'\n && typeof value.removeListener === 'function'\n && typeof value._readableState === 'object';\n}\n\nfunction getType(value) {\n if (!value) return 'Primitive';\n if (typeof value.then === 'function') return 'Promise';\n if (isReadableStream(value)) return `Readable${value._readableState.objectMode ? 'Object' : 'String'}`;\n if (Array.isArray(value)) return 'Array';\n if (typeof value === 'object' || value instanceof Object) return 'Object';\n return 'Primitive';\n}\n\nconst stackItemEnd = {\n Array: ']',\n Object: '}',\n ReadableString: '\"',\n ReadableObject: ']',\n};\n\nconst stackItemOpen = {\n Array: '[',\n Object: '{',\n ReadableString: '\"',\n ReadableObject: '[',\n};\n\nfunction escapeString(string) {\n // Modified code, original code by Douglas Crockford\n // Original: https://github.com/douglascrockford/JSON-js/blob/master/json2.js\n\n // If the string contains no control characters, no quote characters, and no\n // backslash characters, then we can safely slap some quotes around it.\n // Otherwise we must also replace the offending characters with safe escape\n // sequences.\n\n return string.replace(rxEscapable, (a) => {\n const c = meta[a];\n return typeof c === 'string' ? c : `\\\\u${a.charCodeAt(0).toString(16).padStart(4, '0')}`;\n });\n}\n\nfunction quoteString(string) {\n return `\"${escapeString(string)}\"`;\n}\n\nfunction readAsPromised(stream, size) {\n const value = stream.read(size);\n if (value === null) {\n return new Promise((resolve, reject) => {\n const endListener = () => resolve(null);\n stream.once('end', endListener);\n stream.once('error', reject);\n stream.once('readable', () => {\n stream.removeListener('end', endListener);\n stream.removeListener('error', reject);\n resolve(stream.read());\n });\n });\n }\n return Promise.resolve(value);\n}\n\nfunction recursiveResolve(promise) {\n return promise.then((res) => {\n const resType = getType(res);\n return resType === 'Promise' ? recursiveResolve(res) : res;\n });\n}\n\nclass JsonStreamStringify extends Readable {\n constructor(value, replacer, spaces, cycle) {\n super({});\n let gap;\n const spaceType = typeof spaces;\n if (spaceType === 'string' || spaceType === 'number') {\n gap = Number.isFinite(spaces) ? ' '.repeat(spaces) : spaces;\n }\n Object.assign(this, {\n visited: cycle ? new WeakMap() : new WeakSet(),\n cycle,\n stack: [],\n replacerFunction: replacer instanceof Function && replacer,\n replacerArray: Array.isArray(replacer) && replacer,\n gap,\n depth: 0,\n });\n this.addToStack(value);\n }\n\n cycler(key, value) {\n const existingPath = this.visited.get(value);\n if (existingPath) {\n return {\n $ref: existingPath,\n };\n }\n let path = this.path();\n if (key !== undefined) path.push(key);\n path = path.map(v => `[${(Number.isInteger(v) ? v : quoteString(v))}]`);\n this.visited.set(value, path.length ? `$${path.join('')}` : '$');\n return value;\n }\n\n addToStack(value, key, index) {\n let realValue = value;\n if (this.replacerFunction) {\n realValue = this.replacerFunction(key || index, realValue, this);\n }\n // ORDER?\n if (realValue && realValue.toJSON instanceof Function) {\n realValue = realValue.toJSON();\n }\n if (realValue instanceof Function || typeof value === 'symbol') {\n realValue = undefined;\n }\n if (key !== undefined && this.replacerArray) {\n if (!this.replacerArray.includes(key)) {\n realValue = undefined;\n }\n }\n let type = getType(realValue);\n if (realValue !== undefined && type !== 'Promise' && key) {\n if (this.gap) {\n this._push(`\\n${this.gap.repeat(this.depth)}\"${escapeString(key)}\": `);\n } else {\n this._push(`\"${escapeString(key)}\":`);\n }\n }\n if (type !== 'Primitive') {\n if (this.cycle) {\n // run cycler\n realValue = this.cycler(key || index, realValue);\n type = getType(realValue);\n } else {\n // check for circular structure\n if (this.visited.has(realValue)) {\n throw Object.assign(new Error('Converting circular structure to JSON'), {\n realValue,\n key: key || index,\n });\n }\n this.visited.add(realValue);\n }\n }\n\n if (!key && index > -1 && this.depth && this.gap) this._push(`\\n${this.gap.repeat(this.depth)}`);\n\n const open = stackItemOpen[type];\n if (open) this._push(open);\n\n const obj = {\n key,\n index,\n type,\n value: realValue,\n };\n\n if (type === 'Object') {\n this.depth += 1;\n obj.unread = Object.keys(realValue);\n obj.isEmpty = !obj.unread.length;\n } else if (type === 'Array') {\n this.depth += 1;\n obj.unread = Array.from(Array(realValue.length).keys());\n obj.isEmpty = !obj.unread.length;\n } else if (type.startsWith('Readable')) {\n this.depth += 1;\n if (realValue._readableState.ended) {\n this.emit('error', new Error('Readable Stream has ended before it was serialized. All stream data have been lost'), realValue, key || index);\n } else if (realValue._readableState.flowing) {\n realValue.pause();\n this.emit('error', new Error('Readable Stream is in flowing mode, data may have been lost. Trying to pause stream.'), realValue, key || index);\n }\n obj.readCount = 0;\n realValue.once('end', () => {\n obj.end = true;\n this.__read();\n });\n realValue.once('error', (err) => {\n this.error = true;\n this.emit('error', err);\n });\n obj.first = true;\n }\n this.stack.unshift(obj);\n return obj;\n }\n\n removeFromStack(item) {\n const {\n type,\n } = item;\n const isObject = type === 'Object' || type === 'Array' || type.startsWith('Readable');\n if (type !== 'Primitive') {\n if (!this.cycle) {\n this.visited.delete(item.value);\n }\n if (isObject) {\n this.depth -= 1;\n }\n }\n\n const end = stackItemEnd[type];\n if (isObject && !item.isEmpty && this.gap) this._push(`\\n${this.gap.repeat(this.depth)}`);\n if (end) this._push(end);\n if (item.addSeparatorAfterEnd) {\n this._push(',');\n }\n this.stack.splice(this.stack.indexOf(item), 1);\n }\n\n _push(data) {\n this.pushCalled = true;\n this.push(data);\n }\n\n processReadableObject(current, size) {\n if (current.end) {\n this.removeFromStack(current);\n return undefined;\n }\n return readAsPromised(current.value, size)\n .then((value) => {\n if (value !== null) {\n if (!current.first) {\n this._push(',');\n }\n /* eslint-disable no-param-reassign */\n current.first = false;\n this.addToStack(value, undefined, current.readCount);\n current.readCount += 1;\n /* eslint-enable no-param-reassign */\n }\n });\n }\n\n processObject(current) {\n if (!current.unread.length) {\n this.removeFromStack(current);\n return;\n }\n const key = current.unread.shift();\n const value = current.value[key];\n\n this.addToStack(value, current.type === 'Object' && key, current.type === 'Array' && key).addSeparatorAfterEnd = !!current.unread.length;\n }\n\n processArray(current) {\n return this.processObject(current);\n }\n\n processPrimitive(current) {\n if (current.value !== undefined) {\n const type = typeof current.value;\n let value;\n switch (type) {\n case 'string':\n value = quoteString(current.value);\n break;\n case 'number':\n value = Number.isFinite(current.value) ? String(current.value) : 'null';\n break;\n case 'boolean':\n case 'null':\n value = String(current.value);\n break;\n case 'object':\n if (!current.value) {\n value = 'null';\n break;\n }\n /* eslint-disable-next-line no-fallthrough */\n default:\n // This should never happen, I can't imagine a situation where this executes.\n // If you find a way, please open a ticket or PR\n throw Object.assign(new Error(`Unknown type \"${type}\". Please file an issue!`), {\n value: current.value,\n });\n }\n this._push(value);\n } else if (this.stack[1] && (this.stack[1].type === 'Array' || this.stack[1].type === 'ReadableObject')) {\n this._push('null');\n } else {\n /* eslint-disable-next-line no-param-reassign */\n current.addSeparatorAfterEnd = false;\n }\n this.removeFromStack(current);\n }\n\n processReadableString(current, size) {\n if (current.end) {\n this.removeFromStack(current);\n return undefined;\n }\n return readAsPromised(current.value, size)\n .then((value) => {\n if (value) this._push(escapeString(value.toString()));\n });\n }\n\n processPromise(current) {\n return recursiveResolve(current.value).then((value) => {\n const {\n addSeparatorAfterEnd,\n } = current;\n /* eslint-disable-next-line no-param-reassign */\n current.addSeparatorAfterEnd = false;\n this.removeFromStack(current);\n this.addToStack(value, current.key, current.index)\n .addSeparatorAfterEnd = addSeparatorAfterEnd;\n });\n }\n\n processStackTopItem(size) {\n const current = this.stack[0];\n if (!current || this.error) return Promise.resolve();\n let out;\n try {\n out = this[`process${current.type}`](current, size);\n } catch (err) {\n return Promise.reject(err);\n }\n return Promise.resolve(out)\n .then(() => {\n if (this.stack.length === 0) {\n this.end = true;\n this._push(null);\n }\n });\n }\n\n __read(size) {\n if (this.isRunning || this.error) {\n this.readMore = true;\n return undefined;\n }\n this.isRunning = true;\n\n // we must continue to read while push has not been called\n this.readMore = false;\n return this.processStackTopItem(size)\n .then(() => {\n const readAgain = !this.end && !this.error && (this.readMore || !this.pushCalled);\n if (readAgain) {\n setImmediate(() => {\n this.isRunning = false;\n this.__read();\n });\n } else {\n this.isRunning = false;\n }\n })\n .catch((err) => {\n this.error = true;\n this.emit('error', err);\n });\n }\n\n _read(size) {\n this.pushCalled = false;\n this.__read(size);\n }\n\n path() {\n return this.stack.map(({\n key,\n index,\n }) => key || index).filter(v => v || v > -1).reverse();\n }\n}\n\nexport default JsonStreamStringify;\n"],"names":["rxEscapable","meta","isReadableStream","value","read","once","removeListener","_readableState","getType","then","objectMode","Array","isArray","Object","stackItemEnd","stackItemOpen","escapeString","string","replace","a","c","charCodeAt","toString","padStart","quoteString","readAsPromised","stream","size","Promise","resolve","reject","endListener","recursiveResolve","promise","res","resType","JsonStreamStringify","replacer","spaces","cycle","gap","spaceType","Number","isFinite","repeat","assign","WeakMap","WeakSet","Function","addToStack","key","existingPath","visited","get","path","undefined","push","map","isInteger","v","set","length","join","index","realValue","replacerFunction","toJSON","replacerArray","includes","type","_push","depth","cycler","has","Error","add","open","obj","unread","keys","isEmpty","from","startsWith","ended","emit","flowing","pause","readCount","end","__read","err","error","first","stack","unshift","item","isObject","delete","addSeparatorAfterEnd","splice","indexOf","data","pushCalled","current","removeFromStack","shift","processObject","String","out","isRunning","readMore","processStackTopItem","readAgain","catch","filter","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AAiB,KAAjB;;OATC,EAYJI,KAZI,CAYE,UAACvB,GAAD,EAAS;eACTC,KAAL,GAAa,IAAb;;eACKP,IAAL,CAAU,OAAV,EAAmBM,GAAnB;OAdG,CAAP;;;;0BAkBI/D,MAAM;WACL2E,UAAL,GAAkB,KAAlB;;WACKb,MAAL,CAAY9D,IAAZ;;;;2BAGK;aACE,KAAKkE,KAAL,CAAWpC,GAAX,CAAe;YACpBP,GADoB,QACpBA,GADoB;YAEpBa,KAFoB,QAEpBA,KAFoB;eAGhBb,OAAOa,KAHS;OAAf,EAGamD,MAHb,CAGoB;eAAKvD,KAAKA,IAAI,CAAC,CAAf;OAHpB,EAGsCwD,OAHtC,EAAP;;;;;EAvS8BC;;;;"} |
| import 'core-js/modules/es6.array.filter'; | ||
| import _setImmediate from '@babel/runtime/core-js/set-immediate'; | ||
| import 'core-js/modules/es6.array.index-of'; | ||
| import 'core-js/modules/es6.string.starts-with'; | ||
| import 'core-js/modules/web.dom.iterable'; | ||
| import 'core-js/modules/es6.array.iterator'; | ||
| import _Array$from from '@babel/runtime/core-js/array/from'; | ||
| import _Object$keys from '@babel/runtime/core-js/object/keys'; | ||
| import 'core-js/modules/es7.array.includes'; | ||
| import 'core-js/modules/es6.string.includes'; | ||
| import 'core-js/modules/es6.date.to-json'; | ||
| import _Number$isInteger from '@babel/runtime/core-js/number/is-integer'; | ||
| import 'core-js/modules/es6.array.map'; | ||
| import _WeakSet from '@babel/runtime/core-js/weak-set'; | ||
| import _WeakMap from '@babel/runtime/core-js/weak-map'; | ||
| import _Object$assign from '@babel/runtime/core-js/object/assign'; | ||
| import 'core-js/modules/es6.string.repeat'; | ||
| import _Number$isFinite from '@babel/runtime/core-js/number/is-finite'; | ||
| import _Promise from '@babel/runtime/core-js/promise'; | ||
| import 'core-js/modules/es6.regexp.to-string'; | ||
| import 'core-js/modules/es6.date.to-string'; | ||
| import 'core-js/modules/es7.string.pad-start'; | ||
| import 'core-js/modules/es6.regexp.replace'; | ||
| import 'core-js/modules/es6.array.is-array'; | ||
| import { Readable } from 'stream'; | ||
| function _typeof(obj) { | ||
| if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { | ||
| _typeof = function (obj) { | ||
| return typeof obj; | ||
| }; | ||
| } else { | ||
| _typeof = function (obj) { | ||
| return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
| }; | ||
| } | ||
| return _typeof(obj); | ||
| } | ||
| function _classCallCheck(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 _createClass(Constructor, protoProps, staticProps) { | ||
| if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
| if (staticProps) _defineProperties(Constructor, staticProps); | ||
| return Constructor; | ||
| } | ||
| function _inherits(subClass, superClass) { | ||
| if (typeof superClass !== "function" && superClass !== null) { | ||
| throw new TypeError("Super expression must either be null or a function"); | ||
| } | ||
| subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
| constructor: { | ||
| value: subClass, | ||
| writable: true, | ||
| configurable: true | ||
| } | ||
| }); | ||
| if (superClass) _setPrototypeOf(subClass, superClass); | ||
| } | ||
| function _getPrototypeOf(o) { | ||
| _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { | ||
| return o.__proto__ || Object.getPrototypeOf(o); | ||
| }; | ||
| return _getPrototypeOf(o); | ||
| } | ||
| function _setPrototypeOf(o, p) { | ||
| _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { | ||
| o.__proto__ = p; | ||
| return o; | ||
| }; | ||
| return _setPrototypeOf(o, p); | ||
| } | ||
| function _assertThisInitialized(self) { | ||
| if (self === void 0) { | ||
| throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
| } | ||
| return self; | ||
| } | ||
| function _possibleConstructorReturn(self, call) { | ||
| if (call && (typeof call === "object" || typeof call === "function")) { | ||
| return call; | ||
| } | ||
| return _assertThisInitialized(self); | ||
| } | ||
| var rxEscapable = /[\\"\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g; // table of character substitutions | ||
| var meta = { | ||
| '\b': '\\b', | ||
| '\t': '\\t', | ||
| '\n': '\\n', | ||
| '\f': '\\f', | ||
| '\r': '\\r', | ||
| '"': '\\"', | ||
| '\\': '\\\\' | ||
| }; | ||
| function isReadableStream(value) { | ||
| return typeof value.read === 'function' && typeof value.once === 'function' && typeof value.removeListener === 'function' && _typeof(value._readableState) === 'object'; | ||
| } | ||
| function getType(value) { | ||
| if (!value) return 'Primitive'; | ||
| if (typeof value.then === 'function') return 'Promise'; | ||
| if (isReadableStream(value)) return "Readable".concat(value._readableState.objectMode ? 'Object' : 'String'); | ||
| if (Array.isArray(value)) return 'Array'; | ||
| if (_typeof(value) === 'object' || value instanceof Object) return 'Object'; | ||
| return 'Primitive'; | ||
| } | ||
| var stackItemEnd = { | ||
| Array: ']', | ||
| Object: '}', | ||
| ReadableString: '"', | ||
| ReadableObject: ']' | ||
| }; | ||
| var stackItemOpen = { | ||
| Array: '[', | ||
| Object: '{', | ||
| ReadableString: '"', | ||
| ReadableObject: '[' | ||
| }; | ||
| function escapeString(string) { | ||
| // Modified code, original code by Douglas Crockford | ||
| // Original: https://github.com/douglascrockford/JSON-js/blob/master/json2.js | ||
| // If the string contains no control characters, no quote characters, and no | ||
| // backslash characters, then we can safely slap some quotes around it. | ||
| // Otherwise we must also replace the offending characters with safe escape | ||
| // sequences. | ||
| return string.replace(rxEscapable, function (a) { | ||
| var c = meta[a]; | ||
| return typeof c === 'string' ? c : "\\u".concat(a.charCodeAt(0).toString(16).padStart(4, '0')); | ||
| }); | ||
| } | ||
| function quoteString(string) { | ||
| return "\"".concat(escapeString(string), "\""); | ||
| } | ||
| function readAsPromised(stream, size) { | ||
| var value = stream.read(size); | ||
| if (value === null) { | ||
| return new _Promise(function (resolve, reject) { | ||
| var endListener = function endListener() { | ||
| return resolve(null); | ||
| }; | ||
| stream.once('end', endListener); | ||
| stream.once('error', reject); | ||
| stream.once('readable', function () { | ||
| stream.removeListener('end', endListener); | ||
| stream.removeListener('error', reject); | ||
| resolve(stream.read()); | ||
| }); | ||
| }); | ||
| } | ||
| return _Promise.resolve(value); | ||
| } | ||
| function recursiveResolve(promise) { | ||
| return promise.then(function (res) { | ||
| var resType = getType(res); | ||
| return resType === 'Promise' ? recursiveResolve(res) : res; | ||
| }); | ||
| } | ||
| var JsonStreamStringify = | ||
| /*#__PURE__*/ | ||
| function (_Readable) { | ||
| _inherits(JsonStreamStringify, _Readable); | ||
| function JsonStreamStringify(value, replacer, spaces, cycle) { | ||
| var _this; | ||
| _classCallCheck(this, JsonStreamStringify); | ||
| _this = _possibleConstructorReturn(this, _getPrototypeOf(JsonStreamStringify).call(this, {})); | ||
| var gap; | ||
| var spaceType = _typeof(spaces); | ||
| if (spaceType === 'string' || spaceType === 'number') { | ||
| gap = _Number$isFinite(spaces) ? ' '.repeat(spaces) : spaces; | ||
| } | ||
| _Object$assign(_assertThisInitialized(_assertThisInitialized(_this)), { | ||
| visited: cycle ? new _WeakMap() : new _WeakSet(), | ||
| cycle: cycle, | ||
| stack: [], | ||
| replacerFunction: replacer instanceof Function && replacer, | ||
| replacerArray: Array.isArray(replacer) && replacer, | ||
| gap: gap, | ||
| depth: 0 | ||
| }); | ||
| _this.addToStack(value); | ||
| return _this; | ||
| } | ||
| _createClass(JsonStreamStringify, [{ | ||
| key: "cycler", | ||
| value: function cycler(key, value) { | ||
| var existingPath = this.visited.get(value); | ||
| if (existingPath) { | ||
| return { | ||
| $ref: existingPath | ||
| }; | ||
| } | ||
| var path = this.path(); | ||
| if (key !== undefined) path.push(key); | ||
| path = path.map(function (v) { | ||
| return "[".concat(_Number$isInteger(v) ? v : quoteString(v), "]"); | ||
| }); | ||
| this.visited.set(value, path.length ? "$".concat(path.join('')) : '$'); | ||
| return value; | ||
| } | ||
| }, { | ||
| key: "addToStack", | ||
| value: function addToStack(value, key, index) { | ||
| var _this2 = this; | ||
| var realValue = value; | ||
| if (this.replacerFunction) { | ||
| realValue = this.replacerFunction(key || index, realValue, this); | ||
| } // ORDER? | ||
| if (realValue && realValue.toJSON instanceof Function) { | ||
| realValue = realValue.toJSON(); | ||
| } | ||
| if (realValue instanceof Function || _typeof(value) === 'symbol') { | ||
| realValue = undefined; | ||
| } | ||
| if (key !== undefined && this.replacerArray) { | ||
| if (!this.replacerArray.includes(key)) { | ||
| realValue = undefined; | ||
| } | ||
| } | ||
| var type = getType(realValue); | ||
| if (realValue !== undefined && type !== 'Promise' && key) { | ||
| if (this.gap) { | ||
| this._push("\n".concat(this.gap.repeat(this.depth), "\"").concat(escapeString(key), "\": ")); | ||
| } else { | ||
| this._push("\"".concat(escapeString(key), "\":")); | ||
| } | ||
| } | ||
| if (type !== 'Primitive') { | ||
| if (this.cycle) { | ||
| // run cycler | ||
| realValue = this.cycler(key || index, realValue); | ||
| type = getType(realValue); | ||
| } else { | ||
| // check for circular structure | ||
| if (this.visited.has(realValue)) { | ||
| throw _Object$assign(new Error('Converting circular structure to JSON'), { | ||
| realValue: realValue, | ||
| key: key || index | ||
| }); | ||
| } | ||
| this.visited.add(realValue); | ||
| } | ||
| } | ||
| if (!key && index > -1 && this.depth && this.gap) this._push("\n".concat(this.gap.repeat(this.depth))); | ||
| var open = stackItemOpen[type]; | ||
| if (open) this._push(open); | ||
| var obj = { | ||
| key: key, | ||
| index: index, | ||
| type: type, | ||
| value: realValue | ||
| }; | ||
| if (type === 'Object') { | ||
| this.depth += 1; | ||
| obj.unread = _Object$keys(realValue); | ||
| obj.isEmpty = !obj.unread.length; | ||
| } else if (type === 'Array') { | ||
| this.depth += 1; | ||
| obj.unread = _Array$from(Array(realValue.length).keys()); | ||
| obj.isEmpty = !obj.unread.length; | ||
| } else if (type.startsWith('Readable')) { | ||
| this.depth += 1; | ||
| if (realValue._readableState.ended) { | ||
| this.emit('error', new Error('Readable Stream has ended before it was serialized. All stream data have been lost'), realValue, key || index); | ||
| } else if (realValue._readableState.flowing) { | ||
| realValue.pause(); | ||
| this.emit('error', new Error('Readable Stream is in flowing mode, data may have been lost. Trying to pause stream.'), realValue, key || index); | ||
| } | ||
| obj.readCount = 0; | ||
| realValue.once('end', function () { | ||
| obj.end = true; | ||
| _this2.__read(); | ||
| }); | ||
| realValue.once('error', function (err) { | ||
| _this2.error = true; | ||
| _this2.emit('error', err); | ||
| }); | ||
| obj.first = true; | ||
| } | ||
| this.stack.unshift(obj); | ||
| return obj; | ||
| } | ||
| }, { | ||
| key: "removeFromStack", | ||
| value: function removeFromStack(item) { | ||
| var type = item.type; | ||
| var isObject = type === 'Object' || type === 'Array' || type.startsWith('Readable'); | ||
| if (type !== 'Primitive') { | ||
| if (!this.cycle) { | ||
| this.visited.delete(item.value); | ||
| } | ||
| if (isObject) { | ||
| this.depth -= 1; | ||
| } | ||
| } | ||
| var end = stackItemEnd[type]; | ||
| if (isObject && !item.isEmpty && this.gap) this._push("\n".concat(this.gap.repeat(this.depth))); | ||
| if (end) this._push(end); | ||
| if (item.addSeparatorAfterEnd) { | ||
| this._push(','); | ||
| } | ||
| this.stack.splice(this.stack.indexOf(item), 1); | ||
| } | ||
| }, { | ||
| key: "_push", | ||
| value: function _push(data) { | ||
| this.pushCalled = true; | ||
| this.push(data); | ||
| } | ||
| }, { | ||
| key: "processReadableObject", | ||
| value: function processReadableObject(current, size) { | ||
| var _this3 = this; | ||
| if (current.end) { | ||
| this.removeFromStack(current); | ||
| return undefined; | ||
| } | ||
| return readAsPromised(current.value, size).then(function (value) { | ||
| if (value !== null) { | ||
| if (!current.first) { | ||
| _this3._push(','); | ||
| } | ||
| /* eslint-disable no-param-reassign */ | ||
| current.first = false; | ||
| _this3.addToStack(value, undefined, current.readCount); | ||
| current.readCount += 1; | ||
| /* eslint-enable no-param-reassign */ | ||
| } | ||
| }); | ||
| } | ||
| }, { | ||
| key: "processObject", | ||
| value: function processObject(current) { | ||
| if (!current.unread.length) { | ||
| this.removeFromStack(current); | ||
| return; | ||
| } | ||
| var key = current.unread.shift(); | ||
| var value = current.value[key]; | ||
| this.addToStack(value, current.type === 'Object' && key, current.type === 'Array' && key).addSeparatorAfterEnd = !!current.unread.length; | ||
| } | ||
| }, { | ||
| key: "processArray", | ||
| value: function processArray(current) { | ||
| return this.processObject(current); | ||
| } | ||
| }, { | ||
| key: "processPrimitive", | ||
| value: function processPrimitive(current) { | ||
| if (current.value !== undefined) { | ||
| var type = _typeof(current.value); | ||
| var value; | ||
| switch (type) { | ||
| case 'string': | ||
| value = quoteString(current.value); | ||
| break; | ||
| case 'number': | ||
| value = _Number$isFinite(current.value) ? String(current.value) : 'null'; | ||
| break; | ||
| case 'boolean': | ||
| case 'null': | ||
| value = String(current.value); | ||
| break; | ||
| case 'object': | ||
| if (!current.value) { | ||
| value = 'null'; | ||
| break; | ||
| } | ||
| /* eslint-disable-next-line no-fallthrough */ | ||
| default: | ||
| // This should never happen, I can't imagine a situation where this executes. | ||
| // If you find a way, please open a ticket or PR | ||
| throw _Object$assign(new Error("Unknown type \"".concat(type, "\". Please file an issue!")), { | ||
| value: current.value | ||
| }); | ||
| } | ||
| this._push(value); | ||
| } else if (this.stack[1] && (this.stack[1].type === 'Array' || this.stack[1].type === 'ReadableObject')) { | ||
| this._push('null'); | ||
| } else { | ||
| /* eslint-disable-next-line no-param-reassign */ | ||
| current.addSeparatorAfterEnd = false; | ||
| } | ||
| this.removeFromStack(current); | ||
| } | ||
| }, { | ||
| key: "processReadableString", | ||
| value: function processReadableString(current, size) { | ||
| var _this4 = this; | ||
| if (current.end) { | ||
| this.removeFromStack(current); | ||
| return undefined; | ||
| } | ||
| return readAsPromised(current.value, size).then(function (value) { | ||
| if (value) _this4._push(escapeString(value.toString())); | ||
| }); | ||
| } | ||
| }, { | ||
| key: "processPromise", | ||
| value: function processPromise(current) { | ||
| var _this5 = this; | ||
| return recursiveResolve(current.value).then(function (value) { | ||
| var addSeparatorAfterEnd = current.addSeparatorAfterEnd; | ||
| /* eslint-disable-next-line no-param-reassign */ | ||
| current.addSeparatorAfterEnd = false; | ||
| _this5.removeFromStack(current); | ||
| _this5.addToStack(value, current.key, current.index).addSeparatorAfterEnd = addSeparatorAfterEnd; | ||
| }); | ||
| } | ||
| }, { | ||
| key: "processStackTopItem", | ||
| value: function processStackTopItem(size) { | ||
| var _this6 = this; | ||
| var current = this.stack[0]; | ||
| if (!current || this.error) return _Promise.resolve(); | ||
| var out; | ||
| try { | ||
| out = this["process".concat(current.type)](current, size); | ||
| } catch (err) { | ||
| return _Promise.reject(err); | ||
| } | ||
| return _Promise.resolve(out).then(function () { | ||
| if (_this6.stack.length === 0) { | ||
| _this6.end = true; | ||
| _this6._push(null); | ||
| } | ||
| }); | ||
| } | ||
| }, { | ||
| key: "__read", | ||
| value: function __read(size) { | ||
| var _this7 = this; | ||
| if (this.isRunning || this.error) { | ||
| this.readMore = true; | ||
| return undefined; | ||
| } | ||
| this.isRunning = true; // we must continue to read while push has not been called | ||
| this.readMore = false; | ||
| return this.processStackTopItem(size).then(function () { | ||
| var readAgain = !_this7.end && !_this7.error && (_this7.readMore || !_this7.pushCalled); | ||
| if (readAgain) { | ||
| _setImmediate(function () { | ||
| _this7.isRunning = false; | ||
| _this7.__read(); | ||
| }); | ||
| } else { | ||
| _this7.isRunning = false; | ||
| } | ||
| }).catch(function (err) { | ||
| _this7.error = true; | ||
| _this7.emit('error', err); | ||
| }); | ||
| } | ||
| }, { | ||
| key: "_read", | ||
| value: function _read(size) { | ||
| this.pushCalled = false; | ||
| this.__read(size); | ||
| } | ||
| }, { | ||
| key: "path", | ||
| value: function path() { | ||
| return this.stack.map(function (_ref) { | ||
| var key = _ref.key, | ||
| index = _ref.index; | ||
| return key || index; | ||
| }).filter(function (v) { | ||
| return v || v > -1; | ||
| }).reverse(); | ||
| } | ||
| }]); | ||
| return JsonStreamStringify; | ||
| }(Readable); | ||
| export default JsonStreamStringify; | ||
| //# sourceMappingURL=module.polyfill.js.map |
| {"version":3,"file":"module.polyfill.js","sources":["../src/JsonStreamStringify.js"],"sourcesContent":["import { Readable } from 'stream';\n\nconst rxEscapable = /[\\\\\"\\u0000-\\u001f\\u007f-\\u009f\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f\\ufeff\\ufff0-\\uffff]/g;\n\n// table of character substitutions\nconst meta = {\n '\\b': '\\\\b',\n '\\t': '\\\\t',\n '\\n': '\\\\n',\n '\\f': '\\\\f',\n '\\r': '\\\\r',\n '\"': '\\\\\"',\n '\\\\': '\\\\\\\\',\n};\n\nfunction isReadableStream(value) {\n return typeof value.read === 'function'\n && typeof value.once === 'function'\n && typeof value.removeListener === 'function'\n && typeof value._readableState === 'object';\n}\n\nfunction getType(value) {\n if (!value) return 'Primitive';\n if (typeof value.then === 'function') return 'Promise';\n if (isReadableStream(value)) return `Readable${value._readableState.objectMode ? 'Object' : 'String'}`;\n if (Array.isArray(value)) return 'Array';\n if (typeof value === 'object' || value instanceof Object) return 'Object';\n return 'Primitive';\n}\n\nconst stackItemEnd = {\n Array: ']',\n Object: '}',\n ReadableString: '\"',\n ReadableObject: ']',\n};\n\nconst stackItemOpen = {\n Array: '[',\n Object: '{',\n ReadableString: '\"',\n ReadableObject: '[',\n};\n\nfunction escapeString(string) {\n // Modified code, original code by Douglas Crockford\n // Original: https://github.com/douglascrockford/JSON-js/blob/master/json2.js\n\n // If the string contains no control characters, no quote characters, and no\n // backslash characters, then we can safely slap some quotes around it.\n // Otherwise we must also replace the offending characters with safe escape\n // sequences.\n\n return string.replace(rxEscapable, (a) => {\n const c = meta[a];\n return typeof c === 'string' ? c : `\\\\u${a.charCodeAt(0).toString(16).padStart(4, '0')}`;\n });\n}\n\nfunction quoteString(string) {\n return `\"${escapeString(string)}\"`;\n}\n\nfunction readAsPromised(stream, size) {\n const value = stream.read(size);\n if (value === null) {\n return new Promise((resolve, reject) => {\n const endListener = () => resolve(null);\n stream.once('end', endListener);\n stream.once('error', reject);\n stream.once('readable', () => {\n stream.removeListener('end', endListener);\n stream.removeListener('error', reject);\n resolve(stream.read());\n });\n });\n }\n return Promise.resolve(value);\n}\n\nfunction recursiveResolve(promise) {\n return promise.then((res) => {\n const resType = getType(res);\n return resType === 'Promise' ? recursiveResolve(res) : res;\n });\n}\n\nclass JsonStreamStringify extends Readable {\n constructor(value, replacer, spaces, cycle) {\n super({});\n let gap;\n const spaceType = typeof spaces;\n if (spaceType === 'string' || spaceType === 'number') {\n gap = Number.isFinite(spaces) ? ' '.repeat(spaces) : spaces;\n }\n Object.assign(this, {\n visited: cycle ? new WeakMap() : new WeakSet(),\n cycle,\n stack: [],\n replacerFunction: replacer instanceof Function && replacer,\n replacerArray: Array.isArray(replacer) && replacer,\n gap,\n depth: 0,\n });\n this.addToStack(value);\n }\n\n cycler(key, value) {\n const existingPath = this.visited.get(value);\n if (existingPath) {\n return {\n $ref: existingPath,\n };\n }\n let path = this.path();\n if (key !== undefined) path.push(key);\n path = path.map(v => `[${(Number.isInteger(v) ? v : quoteString(v))}]`);\n this.visited.set(value, path.length ? `$${path.join('')}` : '$');\n return value;\n }\n\n addToStack(value, key, index) {\n let realValue = value;\n if (this.replacerFunction) {\n realValue = this.replacerFunction(key || index, realValue, this);\n }\n // ORDER?\n if (realValue && realValue.toJSON instanceof Function) {\n realValue = realValue.toJSON();\n }\n if (realValue instanceof Function || typeof value === 'symbol') {\n realValue = undefined;\n }\n if (key !== undefined && this.replacerArray) {\n if (!this.replacerArray.includes(key)) {\n realValue = undefined;\n }\n }\n let type = getType(realValue);\n if (realValue !== undefined && type !== 'Promise' && key) {\n if (this.gap) {\n this._push(`\\n${this.gap.repeat(this.depth)}\"${escapeString(key)}\": `);\n } else {\n this._push(`\"${escapeString(key)}\":`);\n }\n }\n if (type !== 'Primitive') {\n if (this.cycle) {\n // run cycler\n realValue = this.cycler(key || index, realValue);\n type = getType(realValue);\n } else {\n // check for circular structure\n if (this.visited.has(realValue)) {\n throw Object.assign(new Error('Converting circular structure to JSON'), {\n realValue,\n key: key || index,\n });\n }\n this.visited.add(realValue);\n }\n }\n\n if (!key && index > -1 && this.depth && this.gap) this._push(`\\n${this.gap.repeat(this.depth)}`);\n\n const open = stackItemOpen[type];\n if (open) this._push(open);\n\n const obj = {\n key,\n index,\n type,\n value: realValue,\n };\n\n if (type === 'Object') {\n this.depth += 1;\n obj.unread = Object.keys(realValue);\n obj.isEmpty = !obj.unread.length;\n } else if (type === 'Array') {\n this.depth += 1;\n obj.unread = Array.from(Array(realValue.length).keys());\n obj.isEmpty = !obj.unread.length;\n } else if (type.startsWith('Readable')) {\n this.depth += 1;\n if (realValue._readableState.ended) {\n this.emit('error', new Error('Readable Stream has ended before it was serialized. All stream data have been lost'), realValue, key || index);\n } else if (realValue._readableState.flowing) {\n realValue.pause();\n this.emit('error', new Error('Readable Stream is in flowing mode, data may have been lost. Trying to pause stream.'), realValue, key || index);\n }\n obj.readCount = 0;\n realValue.once('end', () => {\n obj.end = true;\n this.__read();\n });\n realValue.once('error', (err) => {\n this.error = true;\n this.emit('error', err);\n });\n obj.first = true;\n }\n this.stack.unshift(obj);\n return obj;\n }\n\n removeFromStack(item) {\n const {\n type,\n } = item;\n const isObject = type === 'Object' || type === 'Array' || type.startsWith('Readable');\n if (type !== 'Primitive') {\n if (!this.cycle) {\n this.visited.delete(item.value);\n }\n if (isObject) {\n this.depth -= 1;\n }\n }\n\n const end = stackItemEnd[type];\n if (isObject && !item.isEmpty && this.gap) this._push(`\\n${this.gap.repeat(this.depth)}`);\n if (end) this._push(end);\n if (item.addSeparatorAfterEnd) {\n this._push(',');\n }\n this.stack.splice(this.stack.indexOf(item), 1);\n }\n\n _push(data) {\n this.pushCalled = true;\n this.push(data);\n }\n\n processReadableObject(current, size) {\n if (current.end) {\n this.removeFromStack(current);\n return undefined;\n }\n return readAsPromised(current.value, size)\n .then((value) => {\n if (value !== null) {\n if (!current.first) {\n this._push(',');\n }\n /* eslint-disable no-param-reassign */\n current.first = false;\n this.addToStack(value, undefined, current.readCount);\n current.readCount += 1;\n /* eslint-enable no-param-reassign */\n }\n });\n }\n\n processObject(current) {\n if (!current.unread.length) {\n this.removeFromStack(current);\n return;\n }\n const key = current.unread.shift();\n const value = current.value[key];\n\n this.addToStack(value, current.type === 'Object' && key, current.type === 'Array' && key).addSeparatorAfterEnd = !!current.unread.length;\n }\n\n processArray(current) {\n return this.processObject(current);\n }\n\n processPrimitive(current) {\n if (current.value !== undefined) {\n const type = typeof current.value;\n let value;\n switch (type) {\n case 'string':\n value = quoteString(current.value);\n break;\n case 'number':\n value = Number.isFinite(current.value) ? String(current.value) : 'null';\n break;\n case 'boolean':\n case 'null':\n value = String(current.value);\n break;\n case 'object':\n if (!current.value) {\n value = 'null';\n break;\n }\n /* eslint-disable-next-line no-fallthrough */\n default:\n // This should never happen, I can't imagine a situation where this executes.\n // If you find a way, please open a ticket or PR\n throw Object.assign(new Error(`Unknown type \"${type}\". Please file an issue!`), {\n value: current.value,\n });\n }\n this._push(value);\n } else if (this.stack[1] && (this.stack[1].type === 'Array' || this.stack[1].type === 'ReadableObject')) {\n this._push('null');\n } else {\n /* eslint-disable-next-line no-param-reassign */\n current.addSeparatorAfterEnd = false;\n }\n this.removeFromStack(current);\n }\n\n processReadableString(current, size) {\n if (current.end) {\n this.removeFromStack(current);\n return undefined;\n }\n return readAsPromised(current.value, size)\n .then((value) => {\n if (value) this._push(escapeString(value.toString()));\n });\n }\n\n processPromise(current) {\n return recursiveResolve(current.value).then((value) => {\n const {\n addSeparatorAfterEnd,\n } = current;\n /* eslint-disable-next-line no-param-reassign */\n current.addSeparatorAfterEnd = false;\n this.removeFromStack(current);\n this.addToStack(value, current.key, current.index)\n .addSeparatorAfterEnd = addSeparatorAfterEnd;\n });\n }\n\n processStackTopItem(size) {\n const current = this.stack[0];\n if (!current || this.error) return Promise.resolve();\n let out;\n try {\n out = this[`process${current.type}`](current, size);\n } catch (err) {\n return Promise.reject(err);\n }\n return Promise.resolve(out)\n .then(() => {\n if (this.stack.length === 0) {\n this.end = true;\n this._push(null);\n }\n });\n }\n\n __read(size) {\n if (this.isRunning || this.error) {\n this.readMore = true;\n return undefined;\n }\n this.isRunning = true;\n\n // we must continue to read while push has not been called\n this.readMore = false;\n return this.processStackTopItem(size)\n .then(() => {\n const readAgain = !this.end && !this.error && (this.readMore || !this.pushCalled);\n if (readAgain) {\n setImmediate(() => {\n this.isRunning = false;\n this.__read();\n });\n } else {\n this.isRunning = false;\n }\n })\n .catch((err) => {\n this.error = true;\n this.emit('error', err);\n });\n }\n\n _read(size) {\n this.pushCalled = false;\n this.__read(size);\n }\n\n path() {\n return this.stack.map(({\n key,\n index,\n }) => key || index).filter(v => v || v > -1).reverse();\n }\n}\n\nexport default JsonStreamStringify;\n"],"names":["rxEscapable","meta","isReadableStream","value","read","once","removeListener","_readableState","getType","then","objectMode","Array","isArray","Object","stackItemEnd","stackItemOpen","escapeString","string","replace","a","c","charCodeAt","toString","padStart","quoteString","readAsPromised","stream","size","resolve","reject","endListener","recursiveResolve","promise","res","resType","JsonStreamStringify","replacer","spaces","cycle","gap","spaceType","repeat","Function","addToStack","key","existingPath","visited","get","path","undefined","push","map","v","set","length","join","index","realValue","replacerFunction","toJSON","replacerArray","includes","type","_push","depth","cycler","has","Error","add","open","obj","unread","isEmpty","keys","startsWith","ended","emit","flowing","pause","readCount","end","__read","err","error","first","stack","unshift","item","isObject","delete","addSeparatorAfterEnd","splice","indexOf","data","pushCalled","current","removeFromStack","shift","processObject","String","out","isRunning","readMore","processStackTopItem","readAgain","catch","filter","reverse","Readable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;;0BAkBIvD,MAAM;WACLmE,UAAL,GAAkB,KAAlB;;WACKb,MAAL,CAAYtD,IAAZ;;;;2BAGK;aACE,KAAK0D,KAAL,CAAWlC,GAAX,CAAe;YACpBP,GADoB,QACpBA,GADoB;YAEpBY,KAFoB,QAEpBA,KAFoB;eAGhBZ,OAAOY,KAHS;OAAf,EAGakD,MAHb,CAGoB;eAAKtD,KAAKA,IAAI,CAAC,CAAf;OAHpB,EAGsCuD,OAHtC,EAAP;;;;;EAvS8BC;;;;"} |
+560
| (function (global, factory) { | ||
| typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('stream')) : | ||
| typeof define === 'function' && define.amd ? define(['stream'], factory) : | ||
| (global.jsonStreamStringify = factory(global.stream)); | ||
| }(this, (function (stream) { 'use strict'; | ||
| function _typeof(obj) { | ||
| if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { | ||
| _typeof = function (obj) { | ||
| return typeof obj; | ||
| }; | ||
| } else { | ||
| _typeof = function (obj) { | ||
| return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
| }; | ||
| } | ||
| return _typeof(obj); | ||
| } | ||
| function _classCallCheck(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 _createClass(Constructor, protoProps, staticProps) { | ||
| if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
| if (staticProps) _defineProperties(Constructor, staticProps); | ||
| return Constructor; | ||
| } | ||
| function _inherits(subClass, superClass) { | ||
| if (typeof superClass !== "function" && superClass !== null) { | ||
| throw new TypeError("Super expression must either be null or a function"); | ||
| } | ||
| subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
| constructor: { | ||
| value: subClass, | ||
| writable: true, | ||
| configurable: true | ||
| } | ||
| }); | ||
| if (superClass) _setPrototypeOf(subClass, superClass); | ||
| } | ||
| function _getPrototypeOf(o) { | ||
| _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { | ||
| return o.__proto__ || Object.getPrototypeOf(o); | ||
| }; | ||
| return _getPrototypeOf(o); | ||
| } | ||
| function _setPrototypeOf(o, p) { | ||
| _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { | ||
| o.__proto__ = p; | ||
| return o; | ||
| }; | ||
| return _setPrototypeOf(o, p); | ||
| } | ||
| function _assertThisInitialized(self) { | ||
| if (self === void 0) { | ||
| throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
| } | ||
| return self; | ||
| } | ||
| function _possibleConstructorReturn(self, call) { | ||
| if (call && (typeof call === "object" || typeof call === "function")) { | ||
| return call; | ||
| } | ||
| return _assertThisInitialized(self); | ||
| } | ||
| var rxEscapable = /[\\"\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g; // table of character substitutions | ||
| var meta = { | ||
| '\b': '\\b', | ||
| '\t': '\\t', | ||
| '\n': '\\n', | ||
| '\f': '\\f', | ||
| '\r': '\\r', | ||
| '"': '\\"', | ||
| '\\': '\\\\' | ||
| }; | ||
| function isReadableStream(value) { | ||
| return typeof value.read === 'function' && typeof value.once === 'function' && typeof value.removeListener === 'function' && _typeof(value._readableState) === 'object'; | ||
| } | ||
| function getType(value) { | ||
| if (!value) return 'Primitive'; | ||
| if (typeof value.then === 'function') return 'Promise'; | ||
| if (isReadableStream(value)) return "Readable".concat(value._readableState.objectMode ? 'Object' : 'String'); | ||
| if (Array.isArray(value)) return 'Array'; | ||
| if (_typeof(value) === 'object' || value instanceof Object) return 'Object'; | ||
| return 'Primitive'; | ||
| } | ||
| var stackItemEnd = { | ||
| Array: ']', | ||
| Object: '}', | ||
| ReadableString: '"', | ||
| ReadableObject: ']' | ||
| }; | ||
| var stackItemOpen = { | ||
| Array: '[', | ||
| Object: '{', | ||
| ReadableString: '"', | ||
| ReadableObject: '[' | ||
| }; | ||
| function escapeString(string) { | ||
| // Modified code, original code by Douglas Crockford | ||
| // Original: https://github.com/douglascrockford/JSON-js/blob/master/json2.js | ||
| // If the string contains no control characters, no quote characters, and no | ||
| // backslash characters, then we can safely slap some quotes around it. | ||
| // Otherwise we must also replace the offending characters with safe escape | ||
| // sequences. | ||
| return string.replace(rxEscapable, function (a) { | ||
| var c = meta[a]; | ||
| return typeof c === 'string' ? c : "\\u".concat(a.charCodeAt(0).toString(16).padStart(4, '0')); | ||
| }); | ||
| } | ||
| function quoteString(string) { | ||
| return "\"".concat(escapeString(string), "\""); | ||
| } | ||
| function readAsPromised(stream$$1, size) { | ||
| var value = stream$$1.read(size); | ||
| if (value === null) { | ||
| return new Promise(function (resolve, reject) { | ||
| var endListener = function endListener() { | ||
| return resolve(null); | ||
| }; | ||
| stream$$1.once('end', endListener); | ||
| stream$$1.once('error', reject); | ||
| stream$$1.once('readable', function () { | ||
| stream$$1.removeListener('end', endListener); | ||
| stream$$1.removeListener('error', reject); | ||
| resolve(stream$$1.read()); | ||
| }); | ||
| }); | ||
| } | ||
| return Promise.resolve(value); | ||
| } | ||
| function recursiveResolve(promise) { | ||
| return promise.then(function (res) { | ||
| var resType = getType(res); | ||
| return resType === 'Promise' ? recursiveResolve(res) : res; | ||
| }); | ||
| } | ||
| var JsonStreamStringify = | ||
| /*#__PURE__*/ | ||
| function (_Readable) { | ||
| _inherits(JsonStreamStringify, _Readable); | ||
| function JsonStreamStringify(value, replacer, spaces, cycle) { | ||
| var _this; | ||
| _classCallCheck(this, JsonStreamStringify); | ||
| _this = _possibleConstructorReturn(this, _getPrototypeOf(JsonStreamStringify).call(this, {})); | ||
| var gap; | ||
| var spaceType = _typeof(spaces); | ||
| if (spaceType === 'string' || spaceType === 'number') { | ||
| gap = Number.isFinite(spaces) ? ' '.repeat(spaces) : spaces; | ||
| } | ||
| Object.assign(_assertThisInitialized(_assertThisInitialized(_this)), { | ||
| visited: cycle ? new WeakMap() : new WeakSet(), | ||
| cycle: cycle, | ||
| stack: [], | ||
| replacerFunction: replacer instanceof Function && replacer, | ||
| replacerArray: Array.isArray(replacer) && replacer, | ||
| gap: gap, | ||
| depth: 0 | ||
| }); | ||
| _this.addToStack(value); | ||
| return _this; | ||
| } | ||
| _createClass(JsonStreamStringify, [{ | ||
| key: "cycler", | ||
| value: function cycler(key, value) { | ||
| var existingPath = this.visited.get(value); | ||
| if (existingPath) { | ||
| return { | ||
| $ref: existingPath | ||
| }; | ||
| } | ||
| var path = this.path(); | ||
| if (key !== undefined) path.push(key); | ||
| path = path.map(function (v) { | ||
| return "[".concat(Number.isInteger(v) ? v : quoteString(v), "]"); | ||
| }); | ||
| this.visited.set(value, path.length ? "$".concat(path.join('')) : '$'); | ||
| return value; | ||
| } | ||
| }, { | ||
| key: "addToStack", | ||
| value: function addToStack(value, key, index) { | ||
| var _this2 = this; | ||
| var realValue = value; | ||
| if (this.replacerFunction) { | ||
| realValue = this.replacerFunction(key || index, realValue, this); | ||
| } // ORDER? | ||
| if (realValue && realValue.toJSON instanceof Function) { | ||
| realValue = realValue.toJSON(); | ||
| } | ||
| if (realValue instanceof Function || _typeof(value) === 'symbol') { | ||
| realValue = undefined; | ||
| } | ||
| if (key !== undefined && this.replacerArray) { | ||
| if (!this.replacerArray.includes(key)) { | ||
| realValue = undefined; | ||
| } | ||
| } | ||
| var type = getType(realValue); | ||
| if (realValue !== undefined && type !== 'Promise' && key) { | ||
| if (this.gap) { | ||
| this._push("\n".concat(this.gap.repeat(this.depth), "\"").concat(escapeString(key), "\": ")); | ||
| } else { | ||
| this._push("\"".concat(escapeString(key), "\":")); | ||
| } | ||
| } | ||
| if (type !== 'Primitive') { | ||
| if (this.cycle) { | ||
| // run cycler | ||
| realValue = this.cycler(key || index, realValue); | ||
| type = getType(realValue); | ||
| } else { | ||
| // check for circular structure | ||
| if (this.visited.has(realValue)) { | ||
| throw Object.assign(new Error('Converting circular structure to JSON'), { | ||
| realValue: realValue, | ||
| key: key || index | ||
| }); | ||
| } | ||
| this.visited.add(realValue); | ||
| } | ||
| } | ||
| if (!key && index > -1 && this.depth && this.gap) this._push("\n".concat(this.gap.repeat(this.depth))); | ||
| var open = stackItemOpen[type]; | ||
| if (open) this._push(open); | ||
| var obj = { | ||
| key: key, | ||
| index: index, | ||
| type: type, | ||
| value: realValue | ||
| }; | ||
| if (type === 'Object') { | ||
| this.depth += 1; | ||
| obj.unread = Object.keys(realValue); | ||
| obj.isEmpty = !obj.unread.length; | ||
| } else if (type === 'Array') { | ||
| this.depth += 1; | ||
| obj.unread = Array.from(Array(realValue.length).keys()); | ||
| obj.isEmpty = !obj.unread.length; | ||
| } else if (type.startsWith('Readable')) { | ||
| this.depth += 1; | ||
| if (realValue._readableState.ended) { | ||
| this.emit('error', new Error('Readable Stream has ended before it was serialized. All stream data have been lost'), realValue, key || index); | ||
| } else if (realValue._readableState.flowing) { | ||
| realValue.pause(); | ||
| this.emit('error', new Error('Readable Stream is in flowing mode, data may have been lost. Trying to pause stream.'), realValue, key || index); | ||
| } | ||
| obj.readCount = 0; | ||
| realValue.once('end', function () { | ||
| obj.end = true; | ||
| _this2.__read(); | ||
| }); | ||
| realValue.once('error', function (err) { | ||
| _this2.error = true; | ||
| _this2.emit('error', err); | ||
| }); | ||
| obj.first = true; | ||
| } | ||
| this.stack.unshift(obj); | ||
| return obj; | ||
| } | ||
| }, { | ||
| key: "removeFromStack", | ||
| value: function removeFromStack(item) { | ||
| var type = item.type; | ||
| var isObject = type === 'Object' || type === 'Array' || type.startsWith('Readable'); | ||
| if (type !== 'Primitive') { | ||
| if (!this.cycle) { | ||
| this.visited.delete(item.value); | ||
| } | ||
| if (isObject) { | ||
| this.depth -= 1; | ||
| } | ||
| } | ||
| var end = stackItemEnd[type]; | ||
| if (isObject && !item.isEmpty && this.gap) this._push("\n".concat(this.gap.repeat(this.depth))); | ||
| if (end) this._push(end); | ||
| if (item.addSeparatorAfterEnd) { | ||
| this._push(','); | ||
| } | ||
| this.stack.splice(this.stack.indexOf(item), 1); | ||
| } | ||
| }, { | ||
| key: "_push", | ||
| value: function _push(data) { | ||
| this.pushCalled = true; | ||
| this.push(data); | ||
| } | ||
| }, { | ||
| key: "processReadableObject", | ||
| value: function processReadableObject(current, size) { | ||
| var _this3 = this; | ||
| if (current.end) { | ||
| this.removeFromStack(current); | ||
| return undefined; | ||
| } | ||
| return readAsPromised(current.value, size).then(function (value) { | ||
| if (value !== null) { | ||
| if (!current.first) { | ||
| _this3._push(','); | ||
| } | ||
| /* eslint-disable no-param-reassign */ | ||
| current.first = false; | ||
| _this3.addToStack(value, undefined, current.readCount); | ||
| current.readCount += 1; | ||
| /* eslint-enable no-param-reassign */ | ||
| } | ||
| }); | ||
| } | ||
| }, { | ||
| key: "processObject", | ||
| value: function processObject(current) { | ||
| if (!current.unread.length) { | ||
| this.removeFromStack(current); | ||
| return; | ||
| } | ||
| var key = current.unread.shift(); | ||
| var value = current.value[key]; | ||
| this.addToStack(value, current.type === 'Object' && key, current.type === 'Array' && key).addSeparatorAfterEnd = !!current.unread.length; | ||
| } | ||
| }, { | ||
| key: "processArray", | ||
| value: function processArray(current) { | ||
| return this.processObject(current); | ||
| } | ||
| }, { | ||
| key: "processPrimitive", | ||
| value: function processPrimitive(current) { | ||
| if (current.value !== undefined) { | ||
| var type = _typeof(current.value); | ||
| var value; | ||
| switch (type) { | ||
| case 'string': | ||
| value = quoteString(current.value); | ||
| break; | ||
| case 'number': | ||
| value = Number.isFinite(current.value) ? String(current.value) : 'null'; | ||
| break; | ||
| case 'boolean': | ||
| case 'null': | ||
| value = String(current.value); | ||
| break; | ||
| case 'object': | ||
| if (!current.value) { | ||
| value = 'null'; | ||
| break; | ||
| } | ||
| /* eslint-disable-next-line no-fallthrough */ | ||
| default: | ||
| // This should never happen, I can't imagine a situation where this executes. | ||
| // If you find a way, please open a ticket or PR | ||
| throw Object.assign(new Error("Unknown type \"".concat(type, "\". Please file an issue!")), { | ||
| value: current.value | ||
| }); | ||
| } | ||
| this._push(value); | ||
| } else if (this.stack[1] && (this.stack[1].type === 'Array' || this.stack[1].type === 'ReadableObject')) { | ||
| this._push('null'); | ||
| } else { | ||
| /* eslint-disable-next-line no-param-reassign */ | ||
| current.addSeparatorAfterEnd = false; | ||
| } | ||
| this.removeFromStack(current); | ||
| } | ||
| }, { | ||
| key: "processReadableString", | ||
| value: function processReadableString(current, size) { | ||
| var _this4 = this; | ||
| if (current.end) { | ||
| this.removeFromStack(current); | ||
| return undefined; | ||
| } | ||
| return readAsPromised(current.value, size).then(function (value) { | ||
| if (value) _this4._push(escapeString(value.toString())); | ||
| }); | ||
| } | ||
| }, { | ||
| key: "processPromise", | ||
| value: function processPromise(current) { | ||
| var _this5 = this; | ||
| return recursiveResolve(current.value).then(function (value) { | ||
| var addSeparatorAfterEnd = current.addSeparatorAfterEnd; | ||
| /* eslint-disable-next-line no-param-reassign */ | ||
| current.addSeparatorAfterEnd = false; | ||
| _this5.removeFromStack(current); | ||
| _this5.addToStack(value, current.key, current.index).addSeparatorAfterEnd = addSeparatorAfterEnd; | ||
| }); | ||
| } | ||
| }, { | ||
| key: "processStackTopItem", | ||
| value: function processStackTopItem(size) { | ||
| var _this6 = this; | ||
| var current = this.stack[0]; | ||
| if (!current || this.error) return Promise.resolve(); | ||
| var out; | ||
| try { | ||
| out = this["process".concat(current.type)](current, size); | ||
| } catch (err) { | ||
| return Promise.reject(err); | ||
| } | ||
| return Promise.resolve(out).then(function () { | ||
| if (_this6.stack.length === 0) { | ||
| _this6.end = true; | ||
| _this6._push(null); | ||
| } | ||
| }); | ||
| } | ||
| }, { | ||
| key: "__read", | ||
| value: function __read(size) { | ||
| var _this7 = this; | ||
| if (this.isRunning || this.error) { | ||
| this.readMore = true; | ||
| return undefined; | ||
| } | ||
| this.isRunning = true; // we must continue to read while push has not been called | ||
| this.readMore = false; | ||
| return this.processStackTopItem(size).then(function () { | ||
| var readAgain = !_this7.end && !_this7.error && (_this7.readMore || !_this7.pushCalled); | ||
| if (readAgain) { | ||
| setImmediate(function () { | ||
| _this7.isRunning = false; | ||
| _this7.__read(); | ||
| }); | ||
| } else { | ||
| _this7.isRunning = false; | ||
| } | ||
| }).catch(function (err) { | ||
| _this7.error = true; | ||
| _this7.emit('error', err); | ||
| }); | ||
| } | ||
| }, { | ||
| key: "_read", | ||
| value: function _read(size) { | ||
| this.pushCalled = false; | ||
| this.__read(size); | ||
| } | ||
| }, { | ||
| key: "path", | ||
| value: function path() { | ||
| return this.stack.map(function (_ref) { | ||
| var key = _ref.key, | ||
| index = _ref.index; | ||
| return key || index; | ||
| }).filter(function (v) { | ||
| return v || v > -1; | ||
| }).reverse(); | ||
| } | ||
| }]); | ||
| return JsonStreamStringify; | ||
| }(stream.Readable); | ||
| return JsonStreamStringify; | ||
| }))); | ||
| //# sourceMappingURL=umd.js.map |
| {"version":3,"file":"umd.js","sources":["../src/JsonStreamStringify.js"],"sourcesContent":["import { Readable } from 'stream';\n\nconst rxEscapable = /[\\\\\"\\u0000-\\u001f\\u007f-\\u009f\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f\\ufeff\\ufff0-\\uffff]/g;\n\n// table of character substitutions\nconst meta = {\n '\\b': '\\\\b',\n '\\t': '\\\\t',\n '\\n': '\\\\n',\n '\\f': '\\\\f',\n '\\r': '\\\\r',\n '\"': '\\\\\"',\n '\\\\': '\\\\\\\\',\n};\n\nfunction isReadableStream(value) {\n return typeof value.read === 'function'\n && typeof value.once === 'function'\n && typeof value.removeListener === 'function'\n && typeof value._readableState === 'object';\n}\n\nfunction getType(value) {\n if (!value) return 'Primitive';\n if (typeof value.then === 'function') return 'Promise';\n if (isReadableStream(value)) return `Readable${value._readableState.objectMode ? 'Object' : 'String'}`;\n if (Array.isArray(value)) return 'Array';\n if (typeof value === 'object' || value instanceof Object) return 'Object';\n return 'Primitive';\n}\n\nconst stackItemEnd = {\n Array: ']',\n Object: '}',\n ReadableString: '\"',\n ReadableObject: ']',\n};\n\nconst stackItemOpen = {\n Array: '[',\n Object: '{',\n ReadableString: '\"',\n ReadableObject: '[',\n};\n\nfunction escapeString(string) {\n // Modified code, original code by Douglas Crockford\n // Original: https://github.com/douglascrockford/JSON-js/blob/master/json2.js\n\n // If the string contains no control characters, no quote characters, and no\n // backslash characters, then we can safely slap some quotes around it.\n // Otherwise we must also replace the offending characters with safe escape\n // sequences.\n\n return string.replace(rxEscapable, (a) => {\n const c = meta[a];\n return typeof c === 'string' ? c : `\\\\u${a.charCodeAt(0).toString(16).padStart(4, '0')}`;\n });\n}\n\nfunction quoteString(string) {\n return `\"${escapeString(string)}\"`;\n}\n\nfunction readAsPromised(stream, size) {\n const value = stream.read(size);\n if (value === null) {\n return new Promise((resolve, reject) => {\n const endListener = () => resolve(null);\n stream.once('end', endListener);\n stream.once('error', reject);\n stream.once('readable', () => {\n stream.removeListener('end', endListener);\n stream.removeListener('error', reject);\n resolve(stream.read());\n });\n });\n }\n return Promise.resolve(value);\n}\n\nfunction recursiveResolve(promise) {\n return promise.then((res) => {\n const resType = getType(res);\n return resType === 'Promise' ? recursiveResolve(res) : res;\n });\n}\n\nclass JsonStreamStringify extends Readable {\n constructor(value, replacer, spaces, cycle) {\n super({});\n let gap;\n const spaceType = typeof spaces;\n if (spaceType === 'string' || spaceType === 'number') {\n gap = Number.isFinite(spaces) ? ' '.repeat(spaces) : spaces;\n }\n Object.assign(this, {\n visited: cycle ? new WeakMap() : new WeakSet(),\n cycle,\n stack: [],\n replacerFunction: replacer instanceof Function && replacer,\n replacerArray: Array.isArray(replacer) && replacer,\n gap,\n depth: 0,\n });\n this.addToStack(value);\n }\n\n cycler(key, value) {\n const existingPath = this.visited.get(value);\n if (existingPath) {\n return {\n $ref: existingPath,\n };\n }\n let path = this.path();\n if (key !== undefined) path.push(key);\n path = path.map(v => `[${(Number.isInteger(v) ? v : quoteString(v))}]`);\n this.visited.set(value, path.length ? `$${path.join('')}` : '$');\n return value;\n }\n\n addToStack(value, key, index) {\n let realValue = value;\n if (this.replacerFunction) {\n realValue = this.replacerFunction(key || index, realValue, this);\n }\n // ORDER?\n if (realValue && realValue.toJSON instanceof Function) {\n realValue = realValue.toJSON();\n }\n if (realValue instanceof Function || typeof value === 'symbol') {\n realValue = undefined;\n }\n if (key !== undefined && this.replacerArray) {\n if (!this.replacerArray.includes(key)) {\n realValue = undefined;\n }\n }\n let type = getType(realValue);\n if (realValue !== undefined && type !== 'Promise' && key) {\n if (this.gap) {\n this._push(`\\n${this.gap.repeat(this.depth)}\"${escapeString(key)}\": `);\n } else {\n this._push(`\"${escapeString(key)}\":`);\n }\n }\n if (type !== 'Primitive') {\n if (this.cycle) {\n // run cycler\n realValue = this.cycler(key || index, realValue);\n type = getType(realValue);\n } else {\n // check for circular structure\n if (this.visited.has(realValue)) {\n throw Object.assign(new Error('Converting circular structure to JSON'), {\n realValue,\n key: key || index,\n });\n }\n this.visited.add(realValue);\n }\n }\n\n if (!key && index > -1 && this.depth && this.gap) this._push(`\\n${this.gap.repeat(this.depth)}`);\n\n const open = stackItemOpen[type];\n if (open) this._push(open);\n\n const obj = {\n key,\n index,\n type,\n value: realValue,\n };\n\n if (type === 'Object') {\n this.depth += 1;\n obj.unread = Object.keys(realValue);\n obj.isEmpty = !obj.unread.length;\n } else if (type === 'Array') {\n this.depth += 1;\n obj.unread = Array.from(Array(realValue.length).keys());\n obj.isEmpty = !obj.unread.length;\n } else if (type.startsWith('Readable')) {\n this.depth += 1;\n if (realValue._readableState.ended) {\n this.emit('error', new Error('Readable Stream has ended before it was serialized. All stream data have been lost'), realValue, key || index);\n } else if (realValue._readableState.flowing) {\n realValue.pause();\n this.emit('error', new Error('Readable Stream is in flowing mode, data may have been lost. Trying to pause stream.'), realValue, key || index);\n }\n obj.readCount = 0;\n realValue.once('end', () => {\n obj.end = true;\n this.__read();\n });\n realValue.once('error', (err) => {\n this.error = true;\n this.emit('error', err);\n });\n obj.first = true;\n }\n this.stack.unshift(obj);\n return obj;\n }\n\n removeFromStack(item) {\n const {\n type,\n } = item;\n const isObject = type === 'Object' || type === 'Array' || type.startsWith('Readable');\n if (type !== 'Primitive') {\n if (!this.cycle) {\n this.visited.delete(item.value);\n }\n if (isObject) {\n this.depth -= 1;\n }\n }\n\n const end = stackItemEnd[type];\n if (isObject && !item.isEmpty && this.gap) this._push(`\\n${this.gap.repeat(this.depth)}`);\n if (end) this._push(end);\n if (item.addSeparatorAfterEnd) {\n this._push(',');\n }\n this.stack.splice(this.stack.indexOf(item), 1);\n }\n\n _push(data) {\n this.pushCalled = true;\n this.push(data);\n }\n\n processReadableObject(current, size) {\n if (current.end) {\n this.removeFromStack(current);\n return undefined;\n }\n return readAsPromised(current.value, size)\n .then((value) => {\n if (value !== null) {\n if (!current.first) {\n this._push(',');\n }\n /* eslint-disable no-param-reassign */\n current.first = false;\n this.addToStack(value, undefined, current.readCount);\n current.readCount += 1;\n /* eslint-enable no-param-reassign */\n }\n });\n }\n\n processObject(current) {\n if (!current.unread.length) {\n this.removeFromStack(current);\n return;\n }\n const key = current.unread.shift();\n const value = current.value[key];\n\n this.addToStack(value, current.type === 'Object' && key, current.type === 'Array' && key).addSeparatorAfterEnd = !!current.unread.length;\n }\n\n processArray(current) {\n return this.processObject(current);\n }\n\n processPrimitive(current) {\n if (current.value !== undefined) {\n const type = typeof current.value;\n let value;\n switch (type) {\n case 'string':\n value = quoteString(current.value);\n break;\n case 'number':\n value = Number.isFinite(current.value) ? String(current.value) : 'null';\n break;\n case 'boolean':\n case 'null':\n value = String(current.value);\n break;\n case 'object':\n if (!current.value) {\n value = 'null';\n break;\n }\n /* eslint-disable-next-line no-fallthrough */\n default:\n // This should never happen, I can't imagine a situation where this executes.\n // If you find a way, please open a ticket or PR\n throw Object.assign(new Error(`Unknown type \"${type}\". Please file an issue!`), {\n value: current.value,\n });\n }\n this._push(value);\n } else if (this.stack[1] && (this.stack[1].type === 'Array' || this.stack[1].type === 'ReadableObject')) {\n this._push('null');\n } else {\n /* eslint-disable-next-line no-param-reassign */\n current.addSeparatorAfterEnd = false;\n }\n this.removeFromStack(current);\n }\n\n processReadableString(current, size) {\n if (current.end) {\n this.removeFromStack(current);\n return undefined;\n }\n return readAsPromised(current.value, size)\n .then((value) => {\n if (value) this._push(escapeString(value.toString()));\n });\n }\n\n processPromise(current) {\n return recursiveResolve(current.value).then((value) => {\n const {\n addSeparatorAfterEnd,\n } = current;\n /* eslint-disable-next-line no-param-reassign */\n current.addSeparatorAfterEnd = false;\n this.removeFromStack(current);\n this.addToStack(value, current.key, current.index)\n .addSeparatorAfterEnd = addSeparatorAfterEnd;\n });\n }\n\n processStackTopItem(size) {\n const current = this.stack[0];\n if (!current || this.error) return Promise.resolve();\n let out;\n try {\n out = this[`process${current.type}`](current, size);\n } catch (err) {\n return Promise.reject(err);\n }\n return Promise.resolve(out)\n .then(() => {\n if (this.stack.length === 0) {\n this.end = true;\n this._push(null);\n }\n });\n }\n\n __read(size) {\n if (this.isRunning || this.error) {\n this.readMore = true;\n return undefined;\n }\n this.isRunning = true;\n\n // we must continue to read while push has not been called\n this.readMore = false;\n return this.processStackTopItem(size)\n .then(() => {\n const readAgain = !this.end && !this.error && (this.readMore || !this.pushCalled);\n if (readAgain) {\n setImmediate(() => {\n this.isRunning = false;\n this.__read();\n });\n } else {\n this.isRunning = false;\n }\n })\n .catch((err) => {\n this.error = true;\n this.emit('error', err);\n });\n }\n\n _read(size) {\n this.pushCalled = false;\n this.__read(size);\n }\n\n path() {\n return this.stack.map(({\n key,\n index,\n }) => key || index).filter(v => v || v > -1).reverse();\n }\n}\n\nexport default JsonStreamStringify;\n"],"names":["rxEscapable","meta","isReadableStream","value","read","once","removeListener","_readableState","getType","then","objectMode","Array","isArray","Object","stackItemEnd","ReadableString","ReadableObject","stackItemOpen","escapeString","string","replace","a","c","charCodeAt","toString","padStart","quoteString","readAsPromised","stream","size","Promise","resolve","reject","endListener","recursiveResolve","promise","res","resType","JsonStreamStringify","replacer","spaces","cycle","gap","spaceType","Number","isFinite","repeat","assign","visited","WeakMap","WeakSet","stack","replacerFunction","Function","replacerArray","depth","addToStack","key","existingPath","get","$ref","path","undefined","push","map","isInteger","v","set","length","join","index","realValue","toJSON","includes","type","_push","cycler","has","Error","add","open","obj","unread","keys","isEmpty","from","startsWith","ended","emit","flowing","pause","readCount","end","__read","err","error","first","unshift","item","isObject","delete","addSeparatorAfterEnd","splice","indexOf","data","pushCalled","current","removeFromStack","shift","processObject","String","out","isRunning","readMore","processStackTopItem","readAgain","setImmediate","catch","filter","reverse","Readable"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAEA,IAAMA,cAAc,iIAApB;;EAGA,IAAMC,OAAO;EACX,QAAM,KADK;EAEX,QAAM,KAFK;EAGX,QAAM,KAHK;EAIX,QAAM,KAJK;EAKX,QAAM,KALK;EAMX,OAAK,KANM;EAOX,QAAM;EAPK,CAAb;;EAUA,SAASC,gBAAT,CAA0BC,KAA1B,EAAiC;EAC/B,SAAO,OAAOA,MAAMC,IAAb,KAAsB,UAAtB,IACE,OAAOD,MAAME,IAAb,KAAsB,UADxB,IAEE,OAAOF,MAAMG,cAAb,KAAgC,UAFlC,IAGE,QAAOH,MAAMI,cAAb,MAAgC,QAHzC;EAID;;EAED,SAASC,OAAT,CAAiBL,KAAjB,EAAwB;EACtB,MAAI,CAACA,KAAL,EAAY,OAAO,WAAP;EACZ,MAAI,OAAOA,MAAMM,IAAb,KAAsB,UAA1B,EAAsC,OAAO,SAAP;EACtC,MAAIP,iBAAiBC,KAAjB,CAAJ,EAA6B,yBAA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L,CAAU,OAAV,EAAmBM,GAAnB;EACD,OAfI,CAAP;EAgBD;;;4BAEKjE,MAAM;EACV,WAAK4E,UAAL,GAAkB,KAAlB;;EACA,WAAKZ,MAAL,CAAYhE,IAAZ;EACD;;;6BAEM;EACL,aAAO,KAAKsB,KAAL,CAAWa,GAAX,CAAe;EAAA,YACpBP,GADoB,QACpBA,GADoB;EAAA,YAEpBa,KAFoB,QAEpBA,KAFoB;EAAA,eAGhBb,OAAOa,KAHS;EAAA,OAAf,EAGagD,MAHb,CAGoB;EAAA,eAAKpD,KAAKA,IAAI,CAAC,CAAf;EAAA,OAHpB,EAGsCqD,OAHtC,EAAP;EAID;;;;IA3S+BC;;;;;;;;"} |
+570
| (function (global, factory) { | ||
| typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('core-js/modules/es6.array.filter'), require('@babel/runtime/core-js/set-immediate'), require('core-js/modules/es6.array.index-of'), require('core-js/modules/es6.string.starts-with'), require('core-js/modules/web.dom.iterable'), require('core-js/modules/es6.array.iterator'), require('@babel/runtime/core-js/array/from'), require('@babel/runtime/core-js/object/keys'), require('core-js/modules/es7.array.includes'), require('core-js/modules/es6.string.includes'), require('core-js/modules/es6.date.to-json'), require('@babel/runtime/core-js/number/is-integer'), require('core-js/modules/es6.array.map'), require('@babel/runtime/core-js/weak-set'), require('@babel/runtime/core-js/weak-map'), require('@babel/runtime/core-js/object/assign'), require('core-js/modules/es6.string.repeat'), require('@babel/runtime/core-js/number/is-finite'), require('@babel/runtime/core-js/promise'), require('core-js/modules/es6.regexp.to-string'), require('core-js/modules/es6.date.to-string'), require('core-js/modules/es7.string.pad-start'), require('core-js/modules/es6.regexp.replace'), require('core-js/modules/es6.array.is-array'), require('stream')) : | ||
| typeof define === 'function' && define.amd ? define(['core-js/modules/es6.array.filter', '@babel/runtime/core-js/set-immediate', 'core-js/modules/es6.array.index-of', 'core-js/modules/es6.string.starts-with', 'core-js/modules/web.dom.iterable', 'core-js/modules/es6.array.iterator', '@babel/runtime/core-js/array/from', '@babel/runtime/core-js/object/keys', 'core-js/modules/es7.array.includes', 'core-js/modules/es6.string.includes', 'core-js/modules/es6.date.to-json', '@babel/runtime/core-js/number/is-integer', 'core-js/modules/es6.array.map', '@babel/runtime/core-js/weak-set', '@babel/runtime/core-js/weak-map', '@babel/runtime/core-js/object/assign', 'core-js/modules/es6.string.repeat', '@babel/runtime/core-js/number/is-finite', '@babel/runtime/core-js/promise', 'core-js/modules/es6.regexp.to-string', 'core-js/modules/es6.date.to-string', 'core-js/modules/es7.string.pad-start', 'core-js/modules/es6.regexp.replace', 'core-js/modules/es6.array.is-array', 'stream'], factory) : | ||
| (global.jsonStreamStringify = factory(null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,global.stream)); | ||
| }(this, (function (es6_array_filter,_setImmediate,es6_array_indexOf,es6_string_startsWith,web_dom_iterable,es6_array_iterator,_Array$from,_Object$keys,es7_array_includes,es6_string_includes,es6_date_toJson,_Number$isInteger,es6_array_map,_WeakSet,_WeakMap,_Object$assign,es6_string_repeat,_Number$isFinite,_Promise,es6_regexp_toString,es6_date_toString,es7_string_padStart,es6_regexp_replace,es6_array_isArray,stream) { 'use strict'; | ||
| _setImmediate = _setImmediate && _setImmediate.hasOwnProperty('default') ? _setImmediate['default'] : _setImmediate; | ||
| _Array$from = _Array$from && _Array$from.hasOwnProperty('default') ? _Array$from['default'] : _Array$from; | ||
| _Object$keys = _Object$keys && _Object$keys.hasOwnProperty('default') ? _Object$keys['default'] : _Object$keys; | ||
| _Number$isInteger = _Number$isInteger && _Number$isInteger.hasOwnProperty('default') ? _Number$isInteger['default'] : _Number$isInteger; | ||
| _WeakSet = _WeakSet && _WeakSet.hasOwnProperty('default') ? _WeakSet['default'] : _WeakSet; | ||
| _WeakMap = _WeakMap && _WeakMap.hasOwnProperty('default') ? _WeakMap['default'] : _WeakMap; | ||
| _Object$assign = _Object$assign && _Object$assign.hasOwnProperty('default') ? _Object$assign['default'] : _Object$assign; | ||
| _Number$isFinite = _Number$isFinite && _Number$isFinite.hasOwnProperty('default') ? _Number$isFinite['default'] : _Number$isFinite; | ||
| _Promise = _Promise && _Promise.hasOwnProperty('default') ? _Promise['default'] : _Promise; | ||
| function _typeof(obj) { | ||
| if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { | ||
| _typeof = function (obj) { | ||
| return typeof obj; | ||
| }; | ||
| } else { | ||
| _typeof = function (obj) { | ||
| return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
| }; | ||
| } | ||
| return _typeof(obj); | ||
| } | ||
| function _classCallCheck(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 _createClass(Constructor, protoProps, staticProps) { | ||
| if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
| if (staticProps) _defineProperties(Constructor, staticProps); | ||
| return Constructor; | ||
| } | ||
| function _inherits(subClass, superClass) { | ||
| if (typeof superClass !== "function" && superClass !== null) { | ||
| throw new TypeError("Super expression must either be null or a function"); | ||
| } | ||
| subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
| constructor: { | ||
| value: subClass, | ||
| writable: true, | ||
| configurable: true | ||
| } | ||
| }); | ||
| if (superClass) _setPrototypeOf(subClass, superClass); | ||
| } | ||
| function _getPrototypeOf(o) { | ||
| _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { | ||
| return o.__proto__ || Object.getPrototypeOf(o); | ||
| }; | ||
| return _getPrototypeOf(o); | ||
| } | ||
| function _setPrototypeOf(o, p) { | ||
| _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { | ||
| o.__proto__ = p; | ||
| return o; | ||
| }; | ||
| return _setPrototypeOf(o, p); | ||
| } | ||
| function _assertThisInitialized(self) { | ||
| if (self === void 0) { | ||
| throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
| } | ||
| return self; | ||
| } | ||
| function _possibleConstructorReturn(self, call) { | ||
| if (call && (typeof call === "object" || typeof call === "function")) { | ||
| return call; | ||
| } | ||
| return _assertThisInitialized(self); | ||
| } | ||
| var rxEscapable = /[\\"\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g; // table of character substitutions | ||
| var meta = { | ||
| '\b': '\\b', | ||
| '\t': '\\t', | ||
| '\n': '\\n', | ||
| '\f': '\\f', | ||
| '\r': '\\r', | ||
| '"': '\\"', | ||
| '\\': '\\\\' | ||
| }; | ||
| function isReadableStream(value) { | ||
| return typeof value.read === 'function' && typeof value.once === 'function' && typeof value.removeListener === 'function' && _typeof(value._readableState) === 'object'; | ||
| } | ||
| function getType(value) { | ||
| if (!value) return 'Primitive'; | ||
| if (typeof value.then === 'function') return 'Promise'; | ||
| if (isReadableStream(value)) return "Readable".concat(value._readableState.objectMode ? 'Object' : 'String'); | ||
| if (Array.isArray(value)) return 'Array'; | ||
| if (_typeof(value) === 'object' || value instanceof Object) return 'Object'; | ||
| return 'Primitive'; | ||
| } | ||
| var stackItemEnd = { | ||
| Array: ']', | ||
| Object: '}', | ||
| ReadableString: '"', | ||
| ReadableObject: ']' | ||
| }; | ||
| var stackItemOpen = { | ||
| Array: '[', | ||
| Object: '{', | ||
| ReadableString: '"', | ||
| ReadableObject: '[' | ||
| }; | ||
| function escapeString(string) { | ||
| // Modified code, original code by Douglas Crockford | ||
| // Original: https://github.com/douglascrockford/JSON-js/blob/master/json2.js | ||
| // If the string contains no control characters, no quote characters, and no | ||
| // backslash characters, then we can safely slap some quotes around it. | ||
| // Otherwise we must also replace the offending characters with safe escape | ||
| // sequences. | ||
| return string.replace(rxEscapable, function (a) { | ||
| var c = meta[a]; | ||
| return typeof c === 'string' ? c : "\\u".concat(a.charCodeAt(0).toString(16).padStart(4, '0')); | ||
| }); | ||
| } | ||
| function quoteString(string) { | ||
| return "\"".concat(escapeString(string), "\""); | ||
| } | ||
| function readAsPromised(stream$$1, size) { | ||
| var value = stream$$1.read(size); | ||
| if (value === null) { | ||
| return new _Promise(function (resolve, reject) { | ||
| var endListener = function endListener() { | ||
| return resolve(null); | ||
| }; | ||
| stream$$1.once('end', endListener); | ||
| stream$$1.once('error', reject); | ||
| stream$$1.once('readable', function () { | ||
| stream$$1.removeListener('end', endListener); | ||
| stream$$1.removeListener('error', reject); | ||
| resolve(stream$$1.read()); | ||
| }); | ||
| }); | ||
| } | ||
| return _Promise.resolve(value); | ||
| } | ||
| function recursiveResolve(promise) { | ||
| return promise.then(function (res) { | ||
| var resType = getType(res); | ||
| return resType === 'Promise' ? recursiveResolve(res) : res; | ||
| }); | ||
| } | ||
| var JsonStreamStringify = | ||
| /*#__PURE__*/ | ||
| function (_Readable) { | ||
| _inherits(JsonStreamStringify, _Readable); | ||
| function JsonStreamStringify(value, replacer, spaces, cycle) { | ||
| var _this; | ||
| _classCallCheck(this, JsonStreamStringify); | ||
| _this = _possibleConstructorReturn(this, _getPrototypeOf(JsonStreamStringify).call(this, {})); | ||
| var gap; | ||
| var spaceType = _typeof(spaces); | ||
| if (spaceType === 'string' || spaceType === 'number') { | ||
| gap = _Number$isFinite(spaces) ? ' '.repeat(spaces) : spaces; | ||
| } | ||
| _Object$assign(_assertThisInitialized(_assertThisInitialized(_this)), { | ||
| visited: cycle ? new _WeakMap() : new _WeakSet(), | ||
| cycle: cycle, | ||
| stack: [], | ||
| replacerFunction: replacer instanceof Function && replacer, | ||
| replacerArray: Array.isArray(replacer) && replacer, | ||
| gap: gap, | ||
| depth: 0 | ||
| }); | ||
| _this.addToStack(value); | ||
| return _this; | ||
| } | ||
| _createClass(JsonStreamStringify, [{ | ||
| key: "cycler", | ||
| value: function cycler(key, value) { | ||
| var existingPath = this.visited.get(value); | ||
| if (existingPath) { | ||
| return { | ||
| $ref: existingPath | ||
| }; | ||
| } | ||
| var path = this.path(); | ||
| if (key !== undefined) path.push(key); | ||
| path = path.map(function (v) { | ||
| return "[".concat(_Number$isInteger(v) ? v : quoteString(v), "]"); | ||
| }); | ||
| this.visited.set(value, path.length ? "$".concat(path.join('')) : '$'); | ||
| return value; | ||
| } | ||
| }, { | ||
| key: "addToStack", | ||
| value: function addToStack(value, key, index) { | ||
| var _this2 = this; | ||
| var realValue = value; | ||
| if (this.replacerFunction) { | ||
| realValue = this.replacerFunction(key || index, realValue, this); | ||
| } // ORDER? | ||
| if (realValue && realValue.toJSON instanceof Function) { | ||
| realValue = realValue.toJSON(); | ||
| } | ||
| if (realValue instanceof Function || _typeof(value) === 'symbol') { | ||
| realValue = undefined; | ||
| } | ||
| if (key !== undefined && this.replacerArray) { | ||
| if (!this.replacerArray.includes(key)) { | ||
| realValue = undefined; | ||
| } | ||
| } | ||
| var type = getType(realValue); | ||
| if (realValue !== undefined && type !== 'Promise' && key) { | ||
| if (this.gap) { | ||
| this._push("\n".concat(this.gap.repeat(this.depth), "\"").concat(escapeString(key), "\": ")); | ||
| } else { | ||
| this._push("\"".concat(escapeString(key), "\":")); | ||
| } | ||
| } | ||
| if (type !== 'Primitive') { | ||
| if (this.cycle) { | ||
| // run cycler | ||
| realValue = this.cycler(key || index, realValue); | ||
| type = getType(realValue); | ||
| } else { | ||
| // check for circular structure | ||
| if (this.visited.has(realValue)) { | ||
| throw _Object$assign(new Error('Converting circular structure to JSON'), { | ||
| realValue: realValue, | ||
| key: key || index | ||
| }); | ||
| } | ||
| this.visited.add(realValue); | ||
| } | ||
| } | ||
| if (!key && index > -1 && this.depth && this.gap) this._push("\n".concat(this.gap.repeat(this.depth))); | ||
| var open = stackItemOpen[type]; | ||
| if (open) this._push(open); | ||
| var obj = { | ||
| key: key, | ||
| index: index, | ||
| type: type, | ||
| value: realValue | ||
| }; | ||
| if (type === 'Object') { | ||
| this.depth += 1; | ||
| obj.unread = _Object$keys(realValue); | ||
| obj.isEmpty = !obj.unread.length; | ||
| } else if (type === 'Array') { | ||
| this.depth += 1; | ||
| obj.unread = _Array$from(Array(realValue.length).keys()); | ||
| obj.isEmpty = !obj.unread.length; | ||
| } else if (type.startsWith('Readable')) { | ||
| this.depth += 1; | ||
| if (realValue._readableState.ended) { | ||
| this.emit('error', new Error('Readable Stream has ended before it was serialized. All stream data have been lost'), realValue, key || index); | ||
| } else if (realValue._readableState.flowing) { | ||
| realValue.pause(); | ||
| this.emit('error', new Error('Readable Stream is in flowing mode, data may have been lost. Trying to pause stream.'), realValue, key || index); | ||
| } | ||
| obj.readCount = 0; | ||
| realValue.once('end', function () { | ||
| obj.end = true; | ||
| _this2.__read(); | ||
| }); | ||
| realValue.once('error', function (err) { | ||
| _this2.error = true; | ||
| _this2.emit('error', err); | ||
| }); | ||
| obj.first = true; | ||
| } | ||
| this.stack.unshift(obj); | ||
| return obj; | ||
| } | ||
| }, { | ||
| key: "removeFromStack", | ||
| value: function removeFromStack(item) { | ||
| var type = item.type; | ||
| var isObject = type === 'Object' || type === 'Array' || type.startsWith('Readable'); | ||
| if (type !== 'Primitive') { | ||
| if (!this.cycle) { | ||
| this.visited.delete(item.value); | ||
| } | ||
| if (isObject) { | ||
| this.depth -= 1; | ||
| } | ||
| } | ||
| var end = stackItemEnd[type]; | ||
| if (isObject && !item.isEmpty && this.gap) this._push("\n".concat(this.gap.repeat(this.depth))); | ||
| if (end) this._push(end); | ||
| if (item.addSeparatorAfterEnd) { | ||
| this._push(','); | ||
| } | ||
| this.stack.splice(this.stack.indexOf(item), 1); | ||
| } | ||
| }, { | ||
| key: "_push", | ||
| value: function _push(data) { | ||
| this.pushCalled = true; | ||
| this.push(data); | ||
| } | ||
| }, { | ||
| key: "processReadableObject", | ||
| value: function processReadableObject(current, size) { | ||
| var _this3 = this; | ||
| if (current.end) { | ||
| this.removeFromStack(current); | ||
| return undefined; | ||
| } | ||
| return readAsPromised(current.value, size).then(function (value) { | ||
| if (value !== null) { | ||
| if (!current.first) { | ||
| _this3._push(','); | ||
| } | ||
| /* eslint-disable no-param-reassign */ | ||
| current.first = false; | ||
| _this3.addToStack(value, undefined, current.readCount); | ||
| current.readCount += 1; | ||
| /* eslint-enable no-param-reassign */ | ||
| } | ||
| }); | ||
| } | ||
| }, { | ||
| key: "processObject", | ||
| value: function processObject(current) { | ||
| if (!current.unread.length) { | ||
| this.removeFromStack(current); | ||
| return; | ||
| } | ||
| var key = current.unread.shift(); | ||
| var value = current.value[key]; | ||
| this.addToStack(value, current.type === 'Object' && key, current.type === 'Array' && key).addSeparatorAfterEnd = !!current.unread.length; | ||
| } | ||
| }, { | ||
| key: "processArray", | ||
| value: function processArray(current) { | ||
| return this.processObject(current); | ||
| } | ||
| }, { | ||
| key: "processPrimitive", | ||
| value: function processPrimitive(current) { | ||
| if (current.value !== undefined) { | ||
| var type = _typeof(current.value); | ||
| var value; | ||
| switch (type) { | ||
| case 'string': | ||
| value = quoteString(current.value); | ||
| break; | ||
| case 'number': | ||
| value = _Number$isFinite(current.value) ? String(current.value) : 'null'; | ||
| break; | ||
| case 'boolean': | ||
| case 'null': | ||
| value = String(current.value); | ||
| break; | ||
| case 'object': | ||
| if (!current.value) { | ||
| value = 'null'; | ||
| break; | ||
| } | ||
| /* eslint-disable-next-line no-fallthrough */ | ||
| default: | ||
| // This should never happen, I can't imagine a situation where this executes. | ||
| // If you find a way, please open a ticket or PR | ||
| throw _Object$assign(new Error("Unknown type \"".concat(type, "\". Please file an issue!")), { | ||
| value: current.value | ||
| }); | ||
| } | ||
| this._push(value); | ||
| } else if (this.stack[1] && (this.stack[1].type === 'Array' || this.stack[1].type === 'ReadableObject')) { | ||
| this._push('null'); | ||
| } else { | ||
| /* eslint-disable-next-line no-param-reassign */ | ||
| current.addSeparatorAfterEnd = false; | ||
| } | ||
| this.removeFromStack(current); | ||
| } | ||
| }, { | ||
| key: "processReadableString", | ||
| value: function processReadableString(current, size) { | ||
| var _this4 = this; | ||
| if (current.end) { | ||
| this.removeFromStack(current); | ||
| return undefined; | ||
| } | ||
| return readAsPromised(current.value, size).then(function (value) { | ||
| if (value) _this4._push(escapeString(value.toString())); | ||
| }); | ||
| } | ||
| }, { | ||
| key: "processPromise", | ||
| value: function processPromise(current) { | ||
| var _this5 = this; | ||
| return recursiveResolve(current.value).then(function (value) { | ||
| var addSeparatorAfterEnd = current.addSeparatorAfterEnd; | ||
| /* eslint-disable-next-line no-param-reassign */ | ||
| current.addSeparatorAfterEnd = false; | ||
| _this5.removeFromStack(current); | ||
| _this5.addToStack(value, current.key, current.index).addSeparatorAfterEnd = addSeparatorAfterEnd; | ||
| }); | ||
| } | ||
| }, { | ||
| key: "processStackTopItem", | ||
| value: function processStackTopItem(size) { | ||
| var _this6 = this; | ||
| var current = this.stack[0]; | ||
| if (!current || this.error) return _Promise.resolve(); | ||
| var out; | ||
| try { | ||
| out = this["process".concat(current.type)](current, size); | ||
| } catch (err) { | ||
| return _Promise.reject(err); | ||
| } | ||
| return _Promise.resolve(out).then(function () { | ||
| if (_this6.stack.length === 0) { | ||
| _this6.end = true; | ||
| _this6._push(null); | ||
| } | ||
| }); | ||
| } | ||
| }, { | ||
| key: "__read", | ||
| value: function __read(size) { | ||
| var _this7 = this; | ||
| if (this.isRunning || this.error) { | ||
| this.readMore = true; | ||
| return undefined; | ||
| } | ||
| this.isRunning = true; // we must continue to read while push has not been called | ||
| this.readMore = false; | ||
| return this.processStackTopItem(size).then(function () { | ||
| var readAgain = !_this7.end && !_this7.error && (_this7.readMore || !_this7.pushCalled); | ||
| if (readAgain) { | ||
| _setImmediate(function () { | ||
| _this7.isRunning = false; | ||
| _this7.__read(); | ||
| }); | ||
| } else { | ||
| _this7.isRunning = false; | ||
| } | ||
| }).catch(function (err) { | ||
| _this7.error = true; | ||
| _this7.emit('error', err); | ||
| }); | ||
| } | ||
| }, { | ||
| key: "_read", | ||
| value: function _read(size) { | ||
| this.pushCalled = false; | ||
| this.__read(size); | ||
| } | ||
| }, { | ||
| key: "path", | ||
| value: function path() { | ||
| return this.stack.map(function (_ref) { | ||
| var key = _ref.key, | ||
| index = _ref.index; | ||
| return key || index; | ||
| }).filter(function (v) { | ||
| return v || v > -1; | ||
| }).reverse(); | ||
| } | ||
| }]); | ||
| return JsonStreamStringify; | ||
| }(stream.Readable); | ||
| return JsonStreamStringify; | ||
| }))); | ||
| //# sourceMappingURL=umd.polyfill.js.map |
| {"version":3,"file":"umd.polyfill.js","sources":["../src/JsonStreamStringify.js"],"sourcesContent":["import { Readable } from 'stream';\n\nconst rxEscapable = /[\\\\\"\\u0000-\\u001f\\u007f-\\u009f\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f\\ufeff\\ufff0-\\uffff]/g;\n\n// table of character substitutions\nconst meta = {\n '\\b': '\\\\b',\n '\\t': '\\\\t',\n '\\n': '\\\\n',\n '\\f': '\\\\f',\n '\\r': '\\\\r',\n '\"': '\\\\\"',\n '\\\\': '\\\\\\\\',\n};\n\nfunction isReadableStream(value) {\n return typeof value.read === 'function'\n && typeof value.once === 'function'\n && typeof value.removeListener === 'function'\n && typeof value._readableState === 'object';\n}\n\nfunction getType(value) {\n if (!value) return 'Primitive';\n if (typeof value.then === 'function') return 'Promise';\n if (isReadableStream(value)) return `Readable${value._readableState.objectMode ? 'Object' : 'String'}`;\n if (Array.isArray(value)) return 'Array';\n if (typeof value === 'object' || value instanceof Object) return 'Object';\n return 'Primitive';\n}\n\nconst stackItemEnd = {\n Array: ']',\n Object: '}',\n ReadableString: '\"',\n ReadableObject: ']',\n};\n\nconst stackItemOpen = {\n Array: '[',\n Object: '{',\n ReadableString: '\"',\n ReadableObject: '[',\n};\n\nfunction escapeString(string) {\n // Modified code, original code by Douglas Crockford\n // Original: https://github.com/douglascrockford/JSON-js/blob/master/json2.js\n\n // If the string contains no control characters, no quote characters, and no\n // backslash characters, then we can safely slap some quotes around it.\n // Otherwise we must also replace the offending characters with safe escape\n // sequences.\n\n return string.replace(rxEscapable, (a) => {\n const c = meta[a];\n return typeof c === 'string' ? c : `\\\\u${a.charCodeAt(0).toString(16).padStart(4, '0')}`;\n });\n}\n\nfunction quoteString(string) {\n return `\"${escapeString(string)}\"`;\n}\n\nfunction readAsPromised(stream, size) {\n const value = stream.read(size);\n if (value === null) {\n return new Promise((resolve, reject) => {\n const endListener = () => resolve(null);\n stream.once('end', endListener);\n stream.once('error', reject);\n stream.once('readable', () => {\n stream.removeListener('end', endListener);\n stream.removeListener('error', reject);\n resolve(stream.read());\n });\n });\n }\n return Promise.resolve(value);\n}\n\nfunction recursiveResolve(promise) {\n return promise.then((res) => {\n const resType = getType(res);\n return resType === 'Promise' ? recursiveResolve(res) : res;\n });\n}\n\nclass JsonStreamStringify extends Readable {\n constructor(value, replacer, spaces, cycle) {\n super({});\n let gap;\n const spaceType = typeof spaces;\n if (spaceType === 'string' || spaceType === 'number') {\n gap = Number.isFinite(spaces) ? ' '.repeat(spaces) : spaces;\n }\n Object.assign(this, {\n visited: cycle ? new WeakMap() : new WeakSet(),\n cycle,\n stack: [],\n replacerFunction: replacer instanceof Function && replacer,\n replacerArray: Array.isArray(replacer) && replacer,\n gap,\n depth: 0,\n });\n this.addToStack(value);\n }\n\n cycler(key, value) {\n const existingPath = this.visited.get(value);\n if (existingPath) {\n return {\n $ref: existingPath,\n };\n }\n let path = this.path();\n if (key !== undefined) path.push(key);\n path = path.map(v => `[${(Number.isInteger(v) ? v : quoteString(v))}]`);\n this.visited.set(value, path.length ? `$${path.join('')}` : '$');\n return value;\n }\n\n addToStack(value, key, index) {\n let realValue = value;\n if (this.replacerFunction) {\n realValue = this.replacerFunction(key || index, realValue, this);\n }\n // ORDER?\n if (realValue && realValue.toJSON instanceof Function) {\n realValue = realValue.toJSON();\n }\n if (realValue instanceof Function || typeof value === 'symbol') {\n realValue = undefined;\n }\n if (key !== undefined && this.replacerArray) {\n if (!this.replacerArray.includes(key)) {\n realValue = undefined;\n }\n }\n let type = getType(realValue);\n if (realValue !== undefined && type !== 'Promise' && key) {\n if (this.gap) {\n this._push(`\\n${this.gap.repeat(this.depth)}\"${escapeString(key)}\": `);\n } else {\n this._push(`\"${escapeString(key)}\":`);\n }\n }\n if (type !== 'Primitive') {\n if (this.cycle) {\n // run cycler\n realValue = this.cycler(key || index, realValue);\n type = getType(realValue);\n } else {\n // check for circular structure\n if (this.visited.has(realValue)) {\n throw Object.assign(new Error('Converting circular structure to JSON'), {\n realValue,\n key: key || index,\n });\n }\n this.visited.add(realValue);\n }\n }\n\n if (!key && index > -1 && this.depth && this.gap) this._push(`\\n${this.gap.repeat(this.depth)}`);\n\n const open = stackItemOpen[type];\n if (open) this._push(open);\n\n const obj = {\n key,\n index,\n type,\n value: realValue,\n };\n\n if (type === 'Object') {\n this.depth += 1;\n obj.unread = Object.keys(realValue);\n obj.isEmpty = !obj.unread.length;\n } else if (type === 'Array') {\n this.depth += 1;\n obj.unread = Array.from(Array(realValue.length).keys());\n obj.isEmpty = !obj.unread.length;\n } else if (type.startsWith('Readable')) {\n this.depth += 1;\n if (realValue._readableState.ended) {\n this.emit('error', new Error('Readable Stream has ended before it was serialized. All stream data have been lost'), realValue, key || index);\n } else if (realValue._readableState.flowing) {\n realValue.pause();\n this.emit('error', new Error('Readable Stream is in flowing mode, data may have been lost. Trying to pause stream.'), realValue, key || index);\n }\n obj.readCount = 0;\n realValue.once('end', () => {\n obj.end = true;\n this.__read();\n });\n realValue.once('error', (err) => {\n this.error = true;\n this.emit('error', err);\n });\n obj.first = true;\n }\n this.stack.unshift(obj);\n return obj;\n }\n\n removeFromStack(item) {\n const {\n type,\n } = item;\n const isObject = type === 'Object' || type === 'Array' || type.startsWith('Readable');\n if (type !== 'Primitive') {\n if (!this.cycle) {\n this.visited.delete(item.value);\n }\n if (isObject) {\n this.depth -= 1;\n }\n }\n\n const end = stackItemEnd[type];\n if (isObject && !item.isEmpty && this.gap) this._push(`\\n${this.gap.repeat(this.depth)}`);\n if (end) this._push(end);\n if (item.addSeparatorAfterEnd) {\n this._push(',');\n }\n this.stack.splice(this.stack.indexOf(item), 1);\n }\n\n _push(data) {\n this.pushCalled = true;\n this.push(data);\n }\n\n processReadableObject(current, size) {\n if (current.end) {\n this.removeFromStack(current);\n return undefined;\n }\n return readAsPromised(current.value, size)\n .then((value) => {\n if (value !== null) {\n if (!current.first) {\n this._push(',');\n }\n /* eslint-disable no-param-reassign */\n current.first = false;\n this.addToStack(value, undefined, current.readCount);\n current.readCount += 1;\n /* eslint-enable no-param-reassign */\n }\n });\n }\n\n processObject(current) {\n if (!current.unread.length) {\n this.removeFromStack(current);\n return;\n }\n const key = current.unread.shift();\n const value = current.value[key];\n\n this.addToStack(value, current.type === 'Object' && key, current.type === 'Array' && key).addSeparatorAfterEnd = !!current.unread.length;\n }\n\n processArray(current) {\n return this.processObject(current);\n }\n\n processPrimitive(current) {\n if (current.value !== undefined) {\n const type = typeof current.value;\n let value;\n switch (type) {\n case 'string':\n value = quoteString(current.value);\n break;\n case 'number':\n value = Number.isFinite(current.value) ? String(current.value) : 'null';\n break;\n case 'boolean':\n case 'null':\n value = String(current.value);\n break;\n case 'object':\n if (!current.value) {\n value = 'null';\n break;\n }\n /* eslint-disable-next-line no-fallthrough */\n default:\n // This should never happen, I can't imagine a situation where this executes.\n // If you find a way, please open a ticket or PR\n throw Object.assign(new Error(`Unknown type \"${type}\". Please file an issue!`), {\n value: current.value,\n });\n }\n this._push(value);\n } else if (this.stack[1] && (this.stack[1].type === 'Array' || this.stack[1].type === 'ReadableObject')) {\n this._push('null');\n } else {\n /* eslint-disable-next-line no-param-reassign */\n current.addSeparatorAfterEnd = false;\n }\n this.removeFromStack(current);\n }\n\n processReadableString(current, size) {\n if (current.end) {\n this.removeFromStack(current);\n return undefined;\n }\n return readAsPromised(current.value, size)\n .then((value) => {\n if (value) this._push(escapeString(value.toString()));\n });\n }\n\n processPromise(current) {\n return recursiveResolve(current.value).then((value) => {\n const {\n addSeparatorAfterEnd,\n } = current;\n /* eslint-disable-next-line no-param-reassign */\n current.addSeparatorAfterEnd = false;\n this.removeFromStack(current);\n this.addToStack(value, current.key, current.index)\n .addSeparatorAfterEnd = addSeparatorAfterEnd;\n });\n }\n\n processStackTopItem(size) {\n const current = this.stack[0];\n if (!current || this.error) return Promise.resolve();\n let out;\n try {\n out = this[`process${current.type}`](current, size);\n } catch (err) {\n return Promise.reject(err);\n }\n return Promise.resolve(out)\n .then(() => {\n if (this.stack.length === 0) {\n this.end = true;\n this._push(null);\n }\n });\n }\n\n __read(size) {\n if (this.isRunning || this.error) {\n this.readMore = true;\n return undefined;\n }\n this.isRunning = true;\n\n // we must continue to read while push has not been called\n this.readMore = false;\n return this.processStackTopItem(size)\n .then(() => {\n const readAgain = !this.end && !this.error && (this.readMore || !this.pushCalled);\n if (readAgain) {\n setImmediate(() => {\n this.isRunning = false;\n this.__read();\n });\n } else {\n this.isRunning = false;\n }\n })\n .catch((err) => {\n this.error = true;\n this.emit('error', err);\n });\n }\n\n _read(size) {\n this.pushCalled = false;\n this.__read(size);\n }\n\n path() {\n return this.stack.map(({\n key,\n index,\n }) => key || index).filter(v => v || v > -1).reverse();\n }\n}\n\nexport default JsonStreamStringify;\n"],"names":["rxEscapable","meta","isReadableStream","value","read","once","removeListener","_readableState","getType","then","objectMode","Array","isArray","Object","stackItemEnd","ReadableString","ReadableObject","stackItemOpen","escapeString","string","replace","a","c","charCodeAt","toString","padStart","quoteString","readAsPromised","stream","size","resolve","reject","endListener","recursiveResolve","promise","res","resType","JsonStreamStringify","replacer","spaces","cycle","gap","spaceType","repeat","visited","stack","replacerFunction","Function","replacerArray","depth","addToStack","key","existingPath","get","$ref","path","undefined","push","map","v","set","length","join","index","realValue","toJSON","includes","type","_push","cycler","has","Error","add","open","obj","unread","isEmpty","keys","startsWith","ended","emit","flowing","pause","readCount","end","__read","err","error","first","unshift","item","isObject","delete","addSeparatorAfterEnd","splice","indexOf","data","pushCalled","current","removeFromStack","shift","processObject","String","out","isRunning","readMore","processStackTopItem","readAgain","catch","filter","reverse","Readable"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAEA,IAAMA,cAAc,iIAApB;;EAGA,IAAMC,OAAO;EACX,QAAM,KADK;EAEX,QAAM,KAFK;EAGX,QAAM,KAHK;EAIX,QAAM,KAJK;EAKX,QAAM,KALK;EAMX,OAAK,KANM;EAOX,QAAM;EAPK,CAAb;;EAUA,SAASC,gBAAT,CAA0BC,KAA1B,EAAiC;EAC/B,SAAO,OAAOA,MAAMC,IAAb,KAAsB,UAAtB,IACE,OAAOD,MAAME,IAAb,KAAsB,UADxB,IAEE,OAAOF,MAAMG,cAAb,KAAgC,UAFlC,IAGE,QAAOH,MAAMI,cAAb,MAAgC,QAHzC;EAID;;EAED,SAASC,OAAT,CAAiBL,KAAjB,EAAwB;EACtB,MAAI,CAACA,KAAL,EAAY,OAAO,WAAP;EACZ,MAAI,OAAOA,MAAMM,IAAb,KAAsB,UAA1B,EAAsC,OAAO,SAAP;EACtC,MAAIP,iBAAiBC,KAAjB,CAAJ,EAA6B,yBAAkBA,MAAMI,cAAN,CAAqBG,UAArB,GAAkC,QAAlC,GAA6C,QAA/D;EAC7B,MAAIC,MAAMC,OAAN,CAAcT,KAAd,CAAJ,EAA0B,OAAO,OAAP;EAC1B,MAAI,QAAOA,KAAP,MAAiB,QAAjB,IAA6BA,iBAAiBU,MAAlD,EAA0D,OAAO,QAAP;EAC1D,SAAO,WAAP;EACD;;EAED,IAAMC,eAAe;EACnBH,SAAO,GADY;EAEnBE,UAAQ,GAFW;EAGnBE,kBAAgB,GAHG;EAInBC,kBAAgB;EAJG,CAArB;E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ringify as a readable stream", | ||
| "version": "2.0.0", | ||
| "license": "MIT", | ||
| "author": "Faleij <faleij@gmail.com> (https://github.com/faleij)", | ||
| "repository": { | ||
@@ -9,31 +11,39 @@ "type": "git", | ||
| }, | ||
| "main": "jsonStreamify.js", | ||
| "dependencies": {}, | ||
| "devDependencies": { | ||
| "coveralls": "2.11.9", | ||
| "istanbul": "0.4.3", | ||
| "expect.js": "0.3.1", | ||
| "mocha": "2.4.5" | ||
| "bugs": { | ||
| "url": "https://github.com/faleij/json-stream-stringify/issues" | ||
| }, | ||
| "main": "./umd.js", | ||
| "module": "./module.js", | ||
| "browser": "./umd.js", | ||
| "scripts": { | ||
| "test": "mocha", | ||
| "coverage": "istanbul cover node_modules/mocha/bin/_mocha -- test.js -R spec" | ||
| "lint": "eslint . && echo \"eslint: no lint errors\"", | ||
| "build": "rollup -c rollup.config.js && babel test-src --out-dir test", | ||
| "build:watch": "rollup -c rollup.config.js --watch", | ||
| "test": "mocha -R spec -b", | ||
| "coverage": "nyc npm test", | ||
| "coveralls": "nyc report --reporter=text-lcov | coveralls" | ||
| }, | ||
| "keywords": [ | ||
| "JSON", | ||
| "stringify", | ||
| "stream", | ||
| "string", | ||
| "streamify", | ||
| "read", | ||
| "readable", | ||
| "co", | ||
| "generator", | ||
| "iterable" | ||
| ], | ||
| "author": "Faleij", | ||
| "license": "MIT", | ||
| "engines": { | ||
| "node": ">=4.2.2" | ||
| "devDependencies": { | ||
| "@babel/cli": "^7.0.0-beta.51", | ||
| "@babel/core": "^7.0.0-beta.51", | ||
| "@babel/plugin-transform-runtime": "^7.0.0-beta.51", | ||
| "@babel/polyfill": "^7.0.0-beta.51", | ||
| "@babel/preset-env": "^7.0.0-beta.51", | ||
| "@babel/runtime": "^7.0.0-beta.51", | ||
| "babel-plugin-external-helpers": "^6.22.0", | ||
| "babel-register": "^6.26.0", | ||
| "coveralls": "3.0.1", | ||
| "eslint": "^4.19.1", | ||
| "eslint-config-airbnb": "^17.0.0", | ||
| "eslint-plugin-import": "^2.12.0", | ||
| "eslint-plugin-jsx-a11y": "^6.0.3", | ||
| "eslint-plugin-mocha": "^5.0.0", | ||
| "eslint-plugin-react": "^7.9.1", | ||
| "expect.js": "0.3.1", | ||
| "istanbul": "0.4.5", | ||
| "mocha": "3.5.3", | ||
| "nyc": "12.0.2", | ||
| "rollup": "0.60.4", | ||
| "rollup-plugin-babel": "^4.0.0-beta.5" | ||
| } | ||
| } |
+92
-41
| # JSON Stream Stringify | ||
| [![NPM version][npm-image]][npm-url] | ||
| [![NPM Downloads][downloads-image]][downloads-url] | ||
| [![Dependency Status][dependency-image]][dependency-url] | ||
| [![Build Status][travis-image]][travis-url] | ||
| [![Coverage Status][coveralls-image]][coveralls-url] | ||
| [![License][license-image]](LICENSE) | ||
| [![Gratipay][gratipay-image]][gratipay-url] | ||
| [![Donate][donate-image]][donate-url] | ||
| JSON Stringify as a Readable Stream with rescursive resolving of any readable streams and Promises. | ||
| ## Important and Breaking Changes in v2 | ||
| - Completely rewritten from scratch | ||
| - 100% Code Coverage! 🎉 | ||
| - Space argument finally implemented! 🎉 | ||
| - ⚠️ Cycling is off by default | ||
| - ⚠️ JsonStreamStringify is now a constructor; use ``new`` operator | ||
| - Removed dependency on global JSON.stringify, Async/Await and Generators | ||
| - JsonStreamStringify is now compiled with babel to target ES5 (polyfills needed) | ||
| - Rejected promises and input stream errors are now handled and emitted as errors | ||
| - Added cyclic structure detection to prevent infinite recursion | ||
| ## Main Features | ||
| - Promises are rescursively resolved and the result is piped through JSONStreamStreamify | ||
| - Streams (ObjectMode) are piped through a transform which pipes the data through JSONStreamStreamify (enabling recursive resolving) | ||
| - Streams (Non-ObjectMode) is stringified and piped | ||
| - Promises are rescursively resolved and the result is piped through JsonStreamStringify | ||
| - Streams (Object mode) are recursively read and output as arrays | ||
| - Streams (Non-Object mode) are output as a single string | ||
| - Output is streamed optimally with as small chunks as possible | ||
| - Decycling using Douglas Crockfords Cycle algorithm | ||
| - Great memory management with reference release post process (When a key and value has been processed the value is dereferenced) | ||
| - Stream pressure handling | ||
| - Cycling of cyclical structures and dags using [Douglas Crockfords cycle algorithm](https://github.com/douglascrockford/JSON-js)* | ||
| - Great memory management with reference release after processing and WeakMap/Set reference handling | ||
| - Optimal stream pressure handling | ||
| - Tested and runs on ES5** and ES2015 | ||
| - Bundled as UMD and Module | ||
| \* Off by default since v2 | ||
| \** With polyfills | ||
| ## Install | ||
@@ -25,28 +40,80 @@ | ||
| npm install --save json-stream-stringify | ||
| # Optional if you need polyfills | ||
| # Make sure to include these if you target NodeJS <=v6 or browsers | ||
| npm install --save @babel/polyfill @babel/runtime | ||
| ``` | ||
| ## Usage | ||
| Using Node v8 or later with ESM / Webpack / Browserify / Rollup | ||
| ```javascript | ||
| // No Polyfills | ||
| import JsonStreamStringify from 'JsonStreamStringify'; | ||
| ``` | ||
| ```javascript | ||
| // Polyfilled; loads only needed polyfills from @babel/polyfill @babel/runtime | ||
| import JsonStreamStringify from 'JsonStreamStringify/module.polyfill'; | ||
| ``` | ||
| Using Node >=8 / Other ES2015 environments | ||
| ```javascript | ||
| const JsonStreamStringify = require('JsonStreamStringify'); | ||
| ``` | ||
| Using Node <=6 / Other ES5 environments | ||
| ```javascript | ||
| var JsonStreamStringify = require('JsonStreamStringify/umd.polyfill'); | ||
| ``` | ||
| **Note:** This library is primarily written for LTS versions of NodeJS. Other environments are not tested. | ||
| **Note on non-NodeJS usage:** This module depends on node streams library. Any Streams3 compatible implementation should work - as long as it exports a Readable class, with instances that looks like readable streams. | ||
| **Note on Polyfills:** I have taken measures to minify global pollution of polyfills but this library **does not load polyfills by default** because the polyfills modify native object prototypes and it goes against the [W3C recommendations](https://www.w3.org/2001/tag/doc/polyfills/#advice-for-library-and-framework-authors). | ||
| ## API | ||
| ### JSONStreamStringify(value[, replacer[, spaces[, noDecycle]]]) | ||
| Convert value to JSON string. Returns a readable stream. | ||
| - ``value`` Any data to convert to JSON. | ||
| - ``replacer`` Optional ``Function(key, value)`` or ``Array``. | ||
| As a function the returned value replaces the value associated with the key. [Details](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter) | ||
| ### `new JsonStreamStringify(value[, replacer[, spaces[, cycle]]])` | ||
| Streaming conversion of ``value`` to JSON string. | ||
| **Parameters** | ||
| - ``value`` ``Any`` | ||
| Data to convert to JSON. | ||
| - ``replacer`` Optional ``Function(key, value)`` or ``Array`` | ||
| As a function the returned value replaces the value associated with the key. [Details](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter) | ||
| As an array all other keys are filtered. [Details](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Example_with_an_array) | ||
| - ``spaces`` Optional ``String`` or ``Number`` **Not yet implemented** | ||
| - ``noDecycle`` Optional ``Boolean`` Set to ``true`` to disable decycling. | ||
| - ``spaces`` Optional ``String`` or ``Number`` | ||
| A String or Number object that's used to insert white space into the output JSON string for readability purposes. If this is a Number, it indicates the number of space characters to use as white space. If this is a String, the string is used as white space. If this parameter is not recognized as a finite number or valid string, no white space is used. | ||
| - ``cycle`` Optional ``Boolean`` | ||
| ``true`` enables cycling of cyclical structures and dags. | ||
| To restore cyclical structures; use [Crockfords Retrocycle method](https://github.com/douglascrockford/JSON-js) on the parsed object (not included in this module). | ||
| **Returns** | ||
| - ``JsonStreamStringify`` object that exposes a [Streams3 interface](https://nodejs.org/api/stream.html#stream_class_stream_readable). | ||
| ### jsonStreamStringify#path | ||
| **Returns** | ||
| - ``Array[String, Number]`` | ||
| Current path being serialized as an array of Strings (keys of objects) and Numbers (index into arrays). | ||
| Can be transformed into an mpath with ``.join('.')``. | ||
| Useful in conjunction with ``.on('error', ...)``, for figuring out what path may have caused the error. | ||
| ## Example Usage | ||
| ```javascript | ||
| const JSONStreamStringify = require('json-stream-stringify'); | ||
| const JsonStreamStringify = require('json-stream-stringify'); | ||
| JSONStreamStringify({ | ||
| aPromise: Promise.resolve(Promise.resolve("text")), // Promise may resolve more promises and streams which will be consumed and resolved | ||
| aStream: ReadableObjectStream({a:1}, 'str'), // Stream may write more streams and promises which will be consumed and resolved | ||
| const jsonStream = new JsonStreamStringify({ | ||
| // Promises and Streams may resolve more promises and/or streams which will be consumed and processed into json output | ||
| aPromise: Promise.resolve(Promise.resolve("text")), | ||
| aStream: ReadableObjectStream({a:1}, 'str'), | ||
| arr: [1, 2, Promise.resolve(3), Promise.resolve([4, 5]), ReadableStream('a', 'b', 'c')], | ||
| date: new Date(2016, 0, 2) | ||
| }).pipe(process.stdout); | ||
| }); | ||
| jsonStream.once('error', () => console.log('Error at path', jsonStream.stack.join('.'))); | ||
| jsonStream.pipe(process.stdout); | ||
| ``` | ||
| Output (each line represents a write from JSONStreamStringify) | ||
| Output (each line represents a write from jsonStreamStringify) | ||
| ``` | ||
@@ -92,19 +159,5 @@ { | ||
| ```javascript | ||
| app.get('/api/users', (req, res, next) => JSONStreamStringify(Users.find().stream()).pipe(res)); | ||
| app.get('/api/users', (req, res, next) => new JsonStreamStringify(Users.find().stream()).pipe(res)); | ||
| ``` | ||
| ## TODO | ||
| - Space option | ||
| Feel free to contribute. | ||
| ## Technical Notes | ||
| Uses toJSON when available, and JSON.stringify to stringify everything but objects and arrays. | ||
| Streams with ObjectMode=true are output as arrays while ObjectMode=false output as a concatinated string (each chunk is piped with transforms). | ||
| Circular structures are handled using a WeakMap based implementation of [Douglas Crockfords Decycle method](https://github.com/douglascrockford/JSON-js/blob/master/cycle.js). To restore circular structures; use Crockfords Retrocycle method on the parsed object. | ||
| ## Requirements | ||
| NodeJS >4.2.2 | ||
| # License | ||
@@ -119,4 +172,2 @@ [MIT](LICENSE) | ||
| [downloads-url]: https://npmjs.org/package/json-stream-stringify | ||
| [dependency-image]: https://gemnasium.com/Faleij/json-stream-stringify.svg | ||
| [dependency-url]: https://gemnasium.com/Faleij/json-stream-stringify | ||
| [travis-image]: https://travis-ci.org/Faleij/json-stream-stringify.svg?branch=master | ||
@@ -127,3 +178,3 @@ [travis-url]: https://travis-ci.org/Faleij/json-stream-stringify | ||
| [license-image]: https://img.shields.io/badge/license-MIT-blue.svg | ||
| [gratipay-image]: https://img.shields.io/gratipay/faleij.svg | ||
| [gratipay-url]: https://gratipay.com/faleij/ | ||
| [donate-image]: https://img.shields.io/badge/Donate-PayPal-green.svg | ||
| [donate-url]: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=faleij%40gmail%2ecom&lc=GB&item_name=faleij&item_number=jsonStreamStringify¤cy_code=SEK&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHosted |
-10
| language: node_js | ||
| node_js: | ||
| - '6' | ||
| - '8' | ||
| - '10' | ||
| sudo: false | ||
| script: | ||
| - "npm run coverage" | ||
| after_script: | ||
| - "test -e ./coverage/lcov.info && cat ./coverage/lcov.info | coveralls" |
-69
| 'use strict'; | ||
| const PassThrough = require('stream').PassThrough; | ||
| const isReadableStream = require('./utils').isReadableStream; | ||
| class CoStream extends PassThrough { | ||
| constructor(args) { | ||
| super(); | ||
| this._generator = this._makeGenerator.apply(this, args); | ||
| } | ||
| // You need to implement your logic in this generator | ||
| * _makeGenerator() { | ||
| yield new Error('You need to implement _makeGenerator'); | ||
| } | ||
| // Handle results from generator | ||
| _handle(result) { | ||
| if (result.value === false) { | ||
| // Abort feed | ||
| this._running = false; | ||
| return; | ||
| } | ||
| if (result.value === true) { | ||
| // Continue to feed | ||
| this._handle(this._generator.next()); | ||
| return; | ||
| } | ||
| if (result.done) { | ||
| // Feeding done | ||
| this._done = result.done; | ||
| return this.push(null); | ||
| } | ||
| if (isReadableStream(result.value)) { | ||
| // Pipe streams and continue feeding afterwards | ||
| return result.value.once('end', () => this._handle(this._generator.next())).pipe(this, { | ||
| end: false | ||
| }); | ||
| } | ||
| if (result.value instanceof Promise) { | ||
| // Resolve promises | ||
| return Promise.resolve(result.value).then((res) => { | ||
| this._handle(this._generator.next(res)); | ||
| }); | ||
| } | ||
| } | ||
| // Read from stream | ||
| _read(n) { | ||
| super._read(n); | ||
| if (this._done) { | ||
| return false; | ||
| } | ||
| if (!this._running) { | ||
| this._running = true; | ||
| this._handle(this._generator.next()); | ||
| } | ||
| return !this._done; | ||
| } | ||
| } | ||
| module.exports = CoStream; |
-100
| 'use strict'; | ||
| const Transform = require('stream').Transform; | ||
| const PassThrough = require('stream').PassThrough; | ||
| const CoStream = require('./coStream'); | ||
| const RecursiveIterable = require('./recursiveIterable'); | ||
| const isReadableStream = require('./utils').isReadableStream; | ||
| class JSONStreamify extends CoStream { | ||
| constructor(value, replacer, space, _visited, _stack) { | ||
| super(arguments); | ||
| this._iter = new RecursiveIterable(replacer instanceof Function ? replacer(undefined, value) : value, replacer, space, _visited, _stack); | ||
| } | ||
| * _makeGenerator(value, replacer) { | ||
| let insertSeparator = false; | ||
| for (let obj of this._iter) { | ||
| if (obj.state === 'close') { | ||
| insertSeparator = true; | ||
| yield this.push(obj.type === Object ? '}' : ']'); | ||
| continue; | ||
| } | ||
| if (obj.state === 'open') { | ||
| insertSeparator = false; | ||
| yield this.push(obj.type === Object ? '{' : '['); | ||
| continue; | ||
| } | ||
| if (insertSeparator) { | ||
| yield this.push(','); | ||
| } | ||
| if (obj.key && obj.ctxType !== Array) { | ||
| yield this.push(JSON.stringify(obj.key) + ':'); | ||
| } | ||
| if (isReadableStream(obj.value)) { | ||
| if (!obj.value._readableState.objectMode) { | ||
| // Non Object Mode are emitted as a concatinated string | ||
| yield this.push('"'); | ||
| yield obj.value.pipe(new Transform({ | ||
| transform: (data, enc, next) => { | ||
| this.push(JSON.stringify(data.toString()).slice(1, -1)); | ||
| next(null); | ||
| } | ||
| })); | ||
| yield this.push('"'); | ||
| continue; | ||
| } | ||
| // Object Mode Streams are emitted as arrays | ||
| yield this.push('['); | ||
| let first = true; | ||
| const pass = new PassThrough(); | ||
| let i = 0; | ||
| obj.value.pipe(new Transform({ | ||
| objectMode: true, | ||
| transform: (data, enc, next) => { | ||
| if (!first) { | ||
| pass.push(','); | ||
| } | ||
| first = false; | ||
| let stream = new JSONStreamify(data, this._iter.replacer, this._iter.space, this._iter.visited); | ||
| stream._iter._stack = obj.stack.concat(i++); | ||
| stream._iter._parentCtxType = Array; | ||
| stream.once('end', () => next(null, undefined)).pipe(pass, { | ||
| end: false | ||
| }); | ||
| } | ||
| })).once('end', () => pass.end()).resume(); | ||
| yield pass; | ||
| yield this.push(']'); | ||
| continue; | ||
| } | ||
| if (obj.state === 'circular') { | ||
| yield this.push(JSON.stringify({ $ref: `$${obj.value.map(v => `[${JSON.stringify(v)}]`).join('')}` })); | ||
| } | ||
| if (obj.value instanceof Promise) { | ||
| let childIterator = new RecursiveIterable(yield obj.value, this._iter.replacer, this._iter.space, this._iter.visited, obj.stack.concat(obj.key || []))[Symbol.iterator](); | ||
| obj.value = obj.attachChild(childIterator, obj.key); | ||
| insertSeparator = false; | ||
| continue; | ||
| } | ||
| if (obj.state === 'value') { | ||
| yield this.push(JSON.stringify(obj.value)); | ||
| } | ||
| insertSeparator = true; | ||
| } | ||
| this._iter = undefined; | ||
| } | ||
| } | ||
| module.exports = function (value, replacer, space, noDecycle) { | ||
| return new JSONStreamify(value, replacer, space, noDecycle ? { has: () => false, set: () => undefined } : undefined); | ||
| }; |
| 'use strict'; | ||
| const Readable = require('stream').Readable; | ||
| const isReadableStream = require('./utils').isReadableStream; | ||
| class RecursiveIterable { | ||
| constructor(obj, replacer, space, visited, stack) { | ||
| // Save a copy of the root object so we can be memory effective | ||
| if (obj && typeof obj.toJSON === 'function') { | ||
| obj = obj.toJSON(); | ||
| } | ||
| this.exclude = [Promise, { | ||
| __shouldExclude: isReadableStream | ||
| }]; | ||
| this._stack = stack || []; | ||
| this.visited = visited || new WeakMap(); | ||
| if (this._shouldIterate(obj)) { | ||
| this.isVisited = this.visited.has(obj); | ||
| if (!this.isVisited) { | ||
| // Save only unvisited stack to weakmap | ||
| this.visited.set(obj, this._stack.slice(0)); | ||
| } | ||
| } | ||
| this.obj = this._shouldIterate(obj) && !this.isVisited ? (Array.isArray(obj) ? obj.slice(0) : Object.assign({}, obj)) : obj; | ||
| this.replacerIsArray = Array.isArray(replacer); | ||
| this.replacer = replacer instanceof Function || this.replacerIsArray ? replacer : undefined; | ||
| this.space = space; | ||
| } | ||
| _shouldIterate(val) { | ||
| return val && typeof val === 'object' && !(this.exclude.some(v => v.__shouldExclude instanceof Function ? v.__shouldExclude(val) : val instanceof v)); | ||
| } | ||
| static _getType(obj) { | ||
| return Array.isArray(obj) ? Array : obj instanceof Object ? Object : undefined | ||
| } | ||
| [Symbol.iterator]() { | ||
| let isObject = this._shouldIterate(this.obj); | ||
| let ctxType = RecursiveIterable._getType(this.obj); | ||
| let nextIndex = 0; | ||
| let keys = isObject && (Array.isArray(this.obj) ? Array.from(Array(this.obj.length).keys()) : Object.keys(this.obj)); | ||
| let childIterator; | ||
| let closed = !isObject; | ||
| let opened = closed; | ||
| const attachIterator = (iterator, addToStack) => { | ||
| childIterator = iterator; | ||
| childIterator._stack = this._stack.concat(addToStack || []); | ||
| }; | ||
| const ctx = { | ||
| depth: 0, | ||
| type: ctxType, | ||
| next: () => { | ||
| let child = childIterator && childIterator.next(); | ||
| if (child) { | ||
| if (!child.done) { | ||
| return child; | ||
| } | ||
| childIterator = undefined; | ||
| } | ||
| let state; | ||
| let key; | ||
| let val; | ||
| let type; | ||
| if (!opened) { | ||
| if (this.isVisited) { | ||
| state = 'circular'; | ||
| val = this.visited.get(this.obj); | ||
| opened = closed = true; | ||
| keys.length = 0; | ||
| } else { | ||
| state = 'open'; | ||
| type = ctxType; | ||
| opened = true; | ||
| } | ||
| } else if (!closed && !keys.length) { | ||
| state = 'close'; | ||
| type = ctxType; | ||
| closed = true; | ||
| } else if (keys && keys.length) { | ||
| state = 'value'; | ||
| key = keys.shift(); | ||
| val = this.obj[key]; | ||
| if (this.replacerIsArray && this.replacer.indexOf(key) === -1) { | ||
| return ctx.next(); | ||
| } | ||
| } else if (!isObject && !ctx.done) { | ||
| state = 'value'; | ||
| val = this.obj; | ||
| ctx.done = true; | ||
| } | ||
| if (state === 'value') { | ||
| if (this.replacer && !this.replacerIsArray) { | ||
| val = this.replacer(key, val); | ||
| } | ||
| if (val && typeof val.toJSON === 'function') { | ||
| val = val.toJSON(); | ||
| } | ||
| if (typeof val === 'function') { | ||
| val = undefined; | ||
| } | ||
| if (val === undefined) { | ||
| if (key) { | ||
| // Dereference iterated object | ||
| this.obj[key] = undefined; | ||
| } | ||
| if ((this._parentCtxType ? this._parentCtxType !== Array : true) && ctx.type !== Array) { | ||
| return ctx.next(); | ||
| } | ||
| val = null; | ||
| } | ||
| if (this._shouldIterate(val)) { | ||
| if (this.visited.has(val)) { | ||
| state = 'circular'; | ||
| val = this.visited.get(val); | ||
| } else { | ||
| state = 'child'; | ||
| childIterator = new RecursiveIterable(val, this.replacer, this.space, this.visited, this._stack.concat(key))[Symbol.iterator](); | ||
| childIterator.ctxType = ctx.type; | ||
| childIterator.depth = ctx.depth + 1; | ||
| childIterator.type = RecursiveIterable._getType(val); | ||
| } | ||
| } | ||
| if (key) { | ||
| // Dereference iterated object | ||
| this.obj[key] = undefined; | ||
| } | ||
| } | ||
| return { | ||
| value: { | ||
| depth: ctx.depth, | ||
| key: key, | ||
| value: val, | ||
| state: state, | ||
| stack: this._stack.slice(0), | ||
| type: type, | ||
| ctxType: ctx.type, | ||
| attachChild: attachIterator | ||
| }, | ||
| done: !state | ||
| }; | ||
| } | ||
| }; | ||
| return ctx; | ||
| } | ||
| } | ||
| module.exports = RecursiveIterable; |
-173
| 'use strict'; | ||
| const mocha = require('mocha'); | ||
| const JSONStreamify = require('./jsonStreamify'); | ||
| const Readable = require('stream').Readable; | ||
| const expect = require('expect.js'); | ||
| function createTest(input, expected, ...args) { | ||
| return () => new Promise((resolve, reject) => { | ||
| let str = ''; | ||
| new JSONStreamify(input, ...args).on('data', data => str += data.toString()).once('end', () => { | ||
| try { | ||
| expect(str).to.equal(expected); | ||
| } catch (err) { | ||
| return reject(err); | ||
| } | ||
| resolve(); | ||
| }).once('error', reject); | ||
| }); | ||
| } | ||
| function ReadableStream() { | ||
| const stream = new Readable({ | ||
| objectMode: Array.from(arguments).some(v => typeof v !== 'string') | ||
| }); | ||
| Array.from(arguments).forEach(v => stream.push(v)); | ||
| stream.push(null); | ||
| return stream; | ||
| } | ||
| describe('Streamify', () => { | ||
| const date = new Date(); | ||
| it('null should be null', createTest(null, 'null')); | ||
| it('date should be date.toJSON()', createTest(date, `"${date.toJSON()}"`)); | ||
| it('true should be true', createTest(true, `true`)); | ||
| it('1 should be 1', createTest(1, `1`)); | ||
| it('1 should be 2', createTest(1, `2`, (k, v) => 2)); | ||
| it('{} should be {}', createTest({}, '{}')); | ||
| it('{a:undefined} should be {}', createTest({ | ||
| a: undefined | ||
| }, '{}')); | ||
| it('{a:null} should be {"a":null}', createTest({ | ||
| a: null | ||
| }, '{"a":null}')); | ||
| it('{a:undefined} should be {"a":1}', createTest({ | ||
| a: undefined | ||
| }, '{"a":1}', (k, v) => { | ||
| if (k) { | ||
| expect(k).to.be('a'); | ||
| } | ||
| return k ? 1 : v; | ||
| })); | ||
| it('{a:1,b,2} should be {"b":2}', createTest({ | ||
| a: 1, | ||
| b: 2 | ||
| }, '{"b":2}', ['b'])); | ||
| it('{a:1} should be {"a":1}', createTest({ | ||
| a: 1 | ||
| }, '{"a":1}')); | ||
| it('{a:function(){}} should be {}', createTest({ | ||
| a: function() {} | ||
| }, '{}')); | ||
| it('[function(){}] should be [null]', createTest([function() {}], '[null]')); | ||
| it('{a:date} should be {"a":date.toJSON()}', createTest({ | ||
| a: date | ||
| }, `{"a":"${date.toJSON()}"}`)); | ||
| it('({a:1,b:{c:2}}) should be {"a":1,"b":{"c":2}}', createTest(({ | ||
| a: 1, | ||
| b: { | ||
| c: 2 | ||
| } | ||
| }), '{"a":1,"b":{"c":2}}')); | ||
| it('{a:[1], "b": 2} should be {"a":[1],"b":2}', createTest({ | ||
| a: [1], | ||
| b: 2 | ||
| }, '{"a":[1],"b":2}')); | ||
| it('[] should be []', createTest([], '[]')); | ||
| it('[[[]],[[]]] should be [[[]],[[]]]', createTest([ | ||
| [ | ||
| [] | ||
| ], | ||
| [ | ||
| [] | ||
| ] | ||
| ], '[[[]],[[]]]')); | ||
| it('[1, undefined, 2] should be [1,null,2]', createTest([1, undefined, 2], '[1,null,2]')); | ||
| it(`[1,'a'] should be [1,"a"]`, createTest([1, 'a'], '[1,"a"]')); | ||
| it('Promise(1) should be 1', createTest(Promise.resolve(1), '1')); | ||
| it('Promise(Promise(1)) should be 1', createTest(Promise.resolve(Promise.resolve(1)), '1')); | ||
| it('{a:Promise(1)} should be {"a":1}', createTest({ | ||
| a: Promise.resolve(1) | ||
| }, '{"a":1}')); | ||
| it('ReadableStream(1) should be [1]', createTest(ReadableStream(1), '[1]')); | ||
| it('{a:ReadableStream(1,2,3)} should be {"a":[1,2,3]}', createTest({ | ||
| a: ReadableStream(1, 2, 3) | ||
| }, '{"a":[1,2,3]}')); | ||
| it(`ReadableStream('a', 'b', 'c') should be "abc"`, createTest(ReadableStream('a', 'b', 'c'), '"abc"')); | ||
| it(`ReadableStream({}, 'a', undefined, 'c') should be [{},"a",null,"c"]`, createTest(ReadableStream({}, 'a', undefined, 'c'), '[{},"a",null,"c"]')); | ||
| it(`{ a: ReadableStream({name: 'name', date: date }) } should be {"a":[{"name":"name","date":"${date.toJSON()}"}]}`, createTest({ | ||
| a: ReadableStream({ | ||
| name: 'name', | ||
| date: date | ||
| }) | ||
| }, `{"a":[{"name":"name","date":"${date.toJSON()}"}]}`)); | ||
| it(`{ a: ReadableStream({name: 'name', arr: [], date: date }) } should be {"a":[{"name":"name","arr":[],"date":"${date.toJSON()}"}]}`, createTest({ | ||
| a: ReadableStream({ | ||
| name: 'name', | ||
| arr: [], | ||
| date: date | ||
| }) | ||
| }, `{"a":[{"name":"name","arr":[],"date":"${date.toJSON()}"}]}`)); | ||
| describe('circular structure', function() { | ||
| let circularData0 = {}; | ||
| circularData0.a = circularData0; | ||
| it(`{ a: a } should be {"a":{"$ref":"$"}}`, createTest(circularData0, `{"a":{"$ref":"$"}}`)); | ||
| let circularData1 = {}; | ||
| circularData1.a = circularData1; | ||
| circularData1.b = [circularData1, { | ||
| a: circularData1 | ||
| }] | ||
| circularData1.b[3] = ReadableStream(circularData1.b[1]); | ||
| it('{a: a, b: [a, { a: a },,ReadableStream(b.1)]} should be {"a":{"$ref":"$"},"b":[{"$ref":"$"},{"a":{"$ref":"$"}},null,[{"$ref":"$[\\"b\\"][1]"}]]}', createTest(circularData1, '{"a":{"$ref":"$"},"b":[{"$ref":"$"},{"a":{"$ref":"$"}},null,[{"$ref":"$[\\"b\\"][1]"}]]}')); | ||
| let circularData2 = {}; | ||
| let data2 = { | ||
| a: 'deep' | ||
| }; | ||
| circularData2.a = Promise.resolve({ | ||
| b: data2 | ||
| }); | ||
| circularData2.b = data2; | ||
| it(`{ a: Promise({ b: { a: 'deep' } }), b: a.b } should be {"a":{"b":{"a":"deep"}},"b":{"$ref":"$[\\"a\\"][\\"b\\"]"}}`, createTest(circularData2, `{"a":{"b":{"a":"deep"}},"b":{"$ref":"$[\\"a\\"][\\"b\\"]"}}`)); | ||
| }); | ||
| describe('disable circular', () => { | ||
| let el = { foo: 'bar' }; | ||
| const arr = [el, el]; | ||
| it(`[{"foo":"bar"},{"foo":"bar"}] should be [{"foo":"bar"},{"foo":"bar"}]`, createTest(arr, `[{"foo":"bar"},{"foo":"bar"}]`, undefined, 2, true)); | ||
| }); | ||
| }); |
-10
| 'use strict'; | ||
| module.exports = { | ||
| isReadableStream: function (obj) { | ||
| return obj && | ||
| typeof obj.pipe === 'function' && | ||
| typeof obj._read === 'function' && | ||
| typeof obj._readableState === 'object'; | ||
| } | ||
| }; |
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
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
168007
604.99%11
22.22%1887
339.86%0
-100%177
40.48%21
425%5
Infinity%1
Infinity%