refactor: move brother_node development artifact to dev/test-nodes subdirectory

Development Artifact Cleanup:
 BROTHER_NODE REORGANIZATION: Moved development test node to appropriate location
- dev/test-nodes/brother_node/: Moved from root directory for better organization
- Contains development configuration, test logs, and test chain data
- No impact on production systems - purely development/testing artifact

 DEVELOPMENT ARTIFACTS IDENTIFIED:
- Chain ID: aitbc-brother-chain (test/development chain)
- Ports: 8010 (P2P) and 8011 (RPC) - different from production
- Environment: .env file with test configuration
- Logs: rpc.log and node.log from development testing session (March 15, 2026)

 ROOT DIRECTORY CLEANUP: Removed development clutter from production directory
- brother_node/ moved to dev/test-nodes/brother_node/
- Root directory now contains only production-ready components
- Development artifacts properly organized in dev/ subdirectory

DIRECTORY STRUCTURE IMPROVEMENT:
📁 dev/test-nodes/: Development and testing node configurations
🏗️ Root Directory: Clean production structure with only essential components
🧪 Development Isolation: Test environments separated from production

BENEFITS:
 Clean Production Directory: No development artifacts in root
 Better Organization: Development nodes grouped in dev/ subdirectory
 Clear Separation: Production vs development environments clearly distinguished
 Maintainability: Easier to identify and manage development components

RESULT: Successfully moved brother_node development artifact to dev/test-nodes/ subdirectory, cleaning up the root directory while preserving development testing environment for future use.
This commit is contained in:
2026-03-30 17:09:06 +02:00
parent bf730dcb4a
commit 816e258d4c
11734 changed files with 2001707 additions and 0 deletions

24
dev/env/node_modules/json-stream-stringify/LICENSE generated vendored Executable file
View File

@@ -0,0 +1,24 @@
The MIT License
Copyright (c) 2016 Faleij <faleij@gmail.com>
Permission is hereby granted, free of charge,
to any person obtaining a copy of this software and
associated documentation files (the "Software"), to
deal in the Software without restriction, including
without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom
the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice
shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

204
dev/env/node_modules/json-stream-stringify/README.md generated vendored Executable file
View File

@@ -0,0 +1,204 @@
# JSON Stream Stringify
[![NPM version][npm-image]][npm-url]
[![NPM Downloads][downloads-image]][downloads-url]
[![Build Status][travis-image]][travis-url]
[![Coverage Status][coveralls-image]][coveralls-url]
[![License][license-image]](LICENSE)
[![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 v3.1.0
- Completely rewritten from scratch - again
- Buffer argument added (Stream will not output data untill buffer size is reached - improves speed)
- Dropped support for node <7.10.1 - async supporting environment now required
## Main Features
- 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
- 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**, ES2015**, ES2016 and later
- Bundled as UMD and Module
\* Off by default since v2
\** With [polyfills](#usage)
## Install
```bash
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
### No Polyfills, TS / ESM
```javascript
import { JsonStreamStringify } from 'json-stream-stringify';
```
### Polyfilled, TS / ESM
install @babel/runtime-corejs3 and corejs@3
```javascript
import { JsonStreamStringify } from 'json-stream-stringify/polyfill';
import { JsonStreamStringify } from 'json-stream-stringify/module.polyfill'; // force ESM
```
### Using Node >=8 / Other ES2015 UMD/CommonJS environments
```javascript
const { JsonStreamStringify } = require('json-stream-stringify'); // let module resolution decide UMD or CJS
const { JsonStreamStringify } = require('json-stream-stringify/umd'); // force UMD
const { JsonStreamStringify } = require('json-stream-stringify/cjs'); // force CJS
```
### Using Node <=6 / Other ES5 UMD/CommonJS environments
```javascript
const { JsonStreamStringify } = require('json-stream-stringify/polyfill');
const { JsonStreamStringify } = require('json-stream-stringify/umd/polyfill');
const { JsonStreamStringify } = require('json-stream-stringify/cjs/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
### `new JsonStreamStringify(value[, replacer[, spaces[, cycle[, bufferSize=512]]]])`
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``
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
Get current path begin serialized.
#### Returns
- ``Array[String, Number]``
Array of path 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.
## Complete Example
```javascript
const { JsonStreamStringify } = require('json-stream-stringify');
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)
});
jsonStream.once('error', () => console.log('Error at path', jsonStream.stack.join('.')));
jsonStream.pipe(process.stdout);
```
Output (each line represents a write from jsonStreamStringify)
```text
{
"aPromise":
"text"
"aStream":
[
{
"a":
1
}
,
"str"
]
"arr":
[
1
,
2
,
3
,
[
4
,
5
]
,
"
a
b
c
"
],
"date":
"2016-01-01T23:00:00.000Z"
}
```
## Practical Example with Express + Mongoose
```javascript
app.get('/api/users', (req, res, next) => {
res.type('json'); // Required for proper handling by test frameworks and some clients
new JsonStreamStringify(Users.find().stream()).pipe(res);
});
```
### Why do I not get proper typings? (Missing .on(...), etc.)
install ``@types/readable-stream`` or ``@types/node`` or create your own ``stream.d.ts`` that exports a ``Readable`` class.
## License
[MIT](LICENSE)
Copyright (c) 2016 Faleij [faleij@gmail.com](mailto:faleij@gmail.com)
[npm-image]: http://img.shields.io/npm/v/json-stream-stringify.svg
[npm-url]: https://npmjs.org/package/json-stream-stringify
[downloads-image]: https://img.shields.io/npm/dm/json-stream-stringify.svg
[downloads-url]: https://npmjs.org/package/json-stream-stringify
[travis-image]: https://travis-ci.org/Faleij/json-stream-stringify.svg?branch=master
[travis-url]: https://travis-ci.org/Faleij/json-stream-stringify
[coveralls-image]: https://coveralls.io/repos/Faleij/json-stream-stringify/badge.svg?branch=master&service=github
[coveralls-url]: https://coveralls.io/github/Faleij/json-stream-stringify?branch=master
[license-image]: https://img.shields.io/badge/license-MIT-blue.svg
[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&currency_code=SEK&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHosted

613
dev/env/node_modules/json-stream-stringify/lib/cjs/index.js generated vendored Executable file
View File

@@ -0,0 +1,613 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var stream = require('stream');
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
var _global, _global$JSON;
const 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
const meta = {
'\b': '\\b',
'\t': '\\t',
'\n': '\\n',
'\f': '\\f',
'\r': '\\r',
'"': '\\"',
'\\': '\\\\'
};
function isReadableStream(value) {
return typeof value.read === 'function' && typeof value.pause === 'function' && typeof value.resume === 'function' && typeof value.pipe === 'function' && typeof value.once === 'function' && typeof value.removeListener === 'function';
}
var Types;
(function (Types) {
Types[Types["Array"] = 0] = "Array";
Types[Types["Object"] = 1] = "Object";
Types[Types["ReadableString"] = 2] = "ReadableString";
Types[Types["ReadableObject"] = 3] = "ReadableObject";
Types[Types["Primitive"] = 4] = "Primitive";
Types[Types["Promise"] = 5] = "Promise";
})(Types || (Types = {}));
function getType(value) {
if (!value) return Types.Primitive;
if (typeof value.then === 'function') return Types.Promise;
if (isReadableStream(value)) return value._readableState.objectMode ? Types.ReadableObject : Types.ReadableString;
if (Array.isArray(value)) return Types.Array;
if (typeof value === 'object' || value instanceof Object) return Types.Object;
return Types.Primitive;
}
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, a => {
const c = meta[a];
return typeof c === 'string' ? c : `\\u${a.charCodeAt(0).toString(16).padStart(4, '0')}`;
});
}
let primitiveToJSON;
if (((_global = global) === null || _global === void 0 ? void 0 : (_global$JSON = _global.JSON) === null || _global$JSON === void 0 ? void 0 : _global$JSON.stringify) instanceof Function) {
try {
if (JSON.stringify(global.BigInt ? global.BigInt('123') : '') !== '123') throw new Error();
primitiveToJSON = JSON.stringify;
} catch (err) {
// Add support for bigint for primitiveToJSON
// eslint-disable-next-line no-confusing-arrow
primitiveToJSON = value => typeof value === 'bigint' ? String(value) : JSON.stringify(value);
}
} else {
primitiveToJSON = value => {
switch (typeof value) {
case 'string':
return `"${escapeString(value)}"`;
case 'number':
return Number.isFinite(value) ? String(value) : 'null';
case 'bigint':
return String(value);
case 'boolean':
return value ? 'true' : 'false';
case 'object':
if (!value) {
return 'null';
}
// 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(`Not a primitive "${typeof value}".`), {
value
});
}
};
}
/*
function quoteString(string: string) {
return primitiveToJSON(String(string));
}
*/
const cache = new Map();
function quoteString(string) {
const useCache = string.length < 10000; // eslint-disable-next-line no-lonely-if
if (useCache && cache.has(string)) {
return cache.get(string);
}
const str = primitiveToJSON(String(string));
if (useCache) cache.set(string, str);
return str;
}
function readAsPromised(stream, size) {
var _stream$_readableStat;
const value = stream.read(size);
if (value === null && !(stream.readableEnded || (_stream$_readableStat = stream._readableState) !== null && _stream$_readableStat !== void 0 && _stream$_readableStat.ended)) {
return new Promise((resolve, reject) => {
const endListener = () => resolve(null);
stream.once('end', endListener);
stream.once('error', reject);
stream.once('readable', () => {
stream.removeListener('end', endListener);
stream.removeListener('error', reject);
readAsPromised(stream, size).then(resolve, reject);
});
});
}
return Promise.resolve(value);
}
var ReadState;
(function (ReadState) {
ReadState[ReadState["Inactive"] = 0] = "Inactive";
ReadState[ReadState["Reading"] = 1] = "Reading";
ReadState[ReadState["ReadMore"] = 2] = "ReadMore";
ReadState[ReadState["Consumed"] = 3] = "Consumed";
})(ReadState || (ReadState = {}));
class JsonStreamStringify extends stream.Readable {
constructor(input, replacer, spaces, cycle = false, bufferSize = 512) {
super({
encoding: 'utf8'
});
_defineProperty(this, "cycle", void 0);
_defineProperty(this, "bufferSize", void 0);
_defineProperty(this, "item", void 0);
_defineProperty(this, "indent", void 0);
_defineProperty(this, "root", void 0);
_defineProperty(this, "include", void 0);
_defineProperty(this, "replacer", void 0);
_defineProperty(this, "visited", void 0);
_defineProperty(this, "objectItem", void 0);
_defineProperty(this, "buffer", '');
_defineProperty(this, "bufferLength", 0);
_defineProperty(this, "pushCalled", false);
_defineProperty(this, "readSize", 0);
_defineProperty(this, "prePush", void 0);
_defineProperty(this, "readState", ReadState.Inactive);
this.cycle = cycle;
this.bufferSize = bufferSize;
const spaceType = typeof spaces;
if (spaceType === 'number') {
this.indent = ' '.repeat(spaces);
} else if (spaceType === 'string') {
this.indent = spaces;
}
const replacerType = typeof replacer;
if (replacerType === 'object') {
this.include = replacer;
} else if (replacerType === 'function') {
this.replacer = replacer;
}
this.visited = cycle ? new WeakMap() : [];
this.root = {
value: {
'': input
},
depth: 0,
indent: '',
path: []
};
this.setItem(input, this.root, '');
}
setItem(value, parent, key = '') {
// call toJSON where applicable
if (value && typeof value === 'object' && typeof value.toJSON === 'function') {
value = value.toJSON(key);
} // use replacer if applicable
if (this.replacer) {
value = this.replacer.call(parent.value, key, value);
} // coerece functions and symbols into undefined
if (value instanceof Function || typeof value === 'symbol') {
value = undefined;
}
const type = getType(value);
let path; // check for circular structure
if (!this.cycle && type !== Types.Primitive) {
if (this.visited.some(v => v === value)) {
this.destroy(Object.assign(new Error('Converting circular structure to JSON'), {
value,
key
}));
return;
}
this.visited.push(value);
} else if (this.cycle && type !== Types.Primitive) {
path = this.visited.get(value);
if (path) {
this._push(`{"$ref":"$${path.map(v => `[${Number.isInteger(v) ? v : escapeString(quoteString(v))}]`).join('')}"}`);
this.item = parent;
return;
}
path = parent === this.root ? [] : parent.path.concat(key);
this.visited.set(value, path);
}
if (type === Types.Object) {
this.setObjectItem(value, parent);
} else if (type === Types.Array) {
this.setArrayItem(value, parent);
} else if (type === Types.Primitive) {
if (parent !== this.root && typeof key === 'string') {
// (<any>parent).write(key, primitiveToJSON(value));
if (value === undefined) ; else {
this._push(primitiveToJSON(value));
} // undefined values in objects should be rejected
} else if (value === undefined && typeof key === 'number') {
// undefined values in array should be null
this._push('null');
} else if (value === undefined) ; else {
this._push(primitiveToJSON(value));
}
this.item = parent;
return;
} else if (type === Types.Promise) {
this.setPromiseItem(value, parent, key);
} else if (type === Types.ReadableString) {
this.setReadableStringItem(value, parent);
} else if (type === Types.ReadableObject) {
this.setReadableObjectItem(value, parent);
}
this.item.value = value;
this.item.depth = parent.depth + 1;
if (this.indent) this.item.indent = this.indent.repeat(this.item.depth);
this.item.path = path;
}
setReadableStringItem(input, parent) {
var _input$_readableState, _input$_readableState2;
if (input.readableEnded || (_input$_readableState = input._readableState) !== null && _input$_readableState !== void 0 && _input$_readableState.endEmitted) {
this.emit('error', new Error('Readable Stream has ended before it was serialized. All stream data have been lost'), input, parent.path);
} else if (input.readableFlowing || (_input$_readableState2 = input._readableState) !== null && _input$_readableState2 !== void 0 && _input$_readableState2.flowing) {
input.pause();
this.emit('error', new Error('Readable Stream is in flowing mode, data may have been lost. Trying to pause stream.'), input, parent.path);
}
const that = this;
this.prePush = '"';
this.item = {
type: 'readable string',
async read(size) {
try {
const data = await readAsPromised(input, size);
if (data === null) {
that._push('"');
that.item = parent;
that.unvisit(input);
return;
}
if (data) that._push(escapeString(data.toString()));
} catch (err) {
that.emit('error', err);
that.destroy();
}
}
};
}
setReadableObjectItem(input, parent) {
var _input$_readableState3, _input$_readableState4;
if (input.readableEnded || (_input$_readableState3 = input._readableState) !== null && _input$_readableState3 !== void 0 && _input$_readableState3.endEmitted) {
this.emit('error', new Error('Readable Stream has ended before it was serialized. All stream data have been lost'), input, parent.path);
} else if (input.readableFlowing || (_input$_readableState4 = input._readableState) !== null && _input$_readableState4 !== void 0 && _input$_readableState4.flowing) {
input.pause();
this.emit('error', new Error('Readable Stream is in flowing mode, data may have been lost. Trying to pause stream.'), input, parent.path);
}
const that = this;
this._push('[');
let first = true;
let i = 0;
const item = {
type: 'readable object',
async read() {
try {
let out = '';
const data = await readAsPromised(input);
if (data === null) {
if (i && that.indent) {
out += `\n${parent.indent}`;
}
out += ']';
that._push(out);
that.item = parent;
that.unvisit(input);
return;
}
if (first) first = false;else out += ',';
if (that.indent) out += `\n${item.indent}`;
that.prePush = out;
that.setItem(data, item, i);
i += 1;
} catch (err) {
that.emit('error', err);
that.destroy();
}
}
};
this.item = item;
}
setPromiseItem(input, parent, key) {
const that = this;
let read = false;
this.item = {
async read() {
if (read) return;
try {
read = true;
that.setItem(await input, parent, key);
} catch (err) {
that.emit('error', err);
that.destroy();
}
}
};
}
setArrayItem(input, parent) {
// const entries = input.slice().reverse();
let i = 0;
const len = input.length;
let first = true;
const that = this;
const item = {
read() {
let out = '';
let wasFirst = false;
if (first) {
first = false;
wasFirst = true;
if (!len) {
that._push('[]');
that.unvisit(input);
that.item = parent;
return;
}
out += '[';
}
const entry = input[i];
if (i === len) {
if (that.indent) out += `\n${parent.indent}`;
out += ']';
that._push(out);
that.item = parent;
that.unvisit(input);
return;
}
if (!wasFirst) out += ',';
if (that.indent) out += `\n${item.indent}`;
that._push(out);
that.setItem(entry, item, i);
i += 1;
}
};
this.item = item;
}
unvisit(item) {
if (this.cycle) return;
const _i = this.visited.indexOf(item);
if (_i > -1) this.visited.splice(_i, 1);
}
setObjectItem(input, parent = undefined) {
const keys = Object.keys(input);
let i = 0;
const len = keys.length;
let first = true;
const that = this;
const {
include
} = this;
let hasItems = false;
let key;
const item = {
read() {
var _include$indexOf;
if (i === 0) that._push('{');
if (i === len) {
that.objectItem = undefined;
if (!hasItems) {
that._push('}');
} else {
that._push(`${that.indent ? `\n${parent.indent}` : ''}}`);
}
that.item = parent;
that.unvisit(input);
return;
}
key = keys[i];
if ((include === null || include === void 0 ? void 0 : (_include$indexOf = include.indexOf) === null || _include$indexOf === void 0 ? void 0 : _include$indexOf.call(include, key)) === -1) {
// replacer array excludes this key
i += 1;
return;
}
that.objectItem = item;
i += 1;
that.setItem(input[key], item, key);
},
write() {
const out = `${hasItems && !first ? ',' : ''}${item.indent ? `\n${item.indent}` : ''}${quoteString(key)}:${that.indent ? ' ' : ''}`;
first = false;
hasItems = true;
that.objectItem = undefined;
return out;
}
};
this.item = item;
}
_push(data) {
const out = (this.objectItem ? this.objectItem.write() : '') + data;
if (this.prePush && out.length) {
this.buffer += this.prePush;
this.prePush = undefined;
}
this.buffer += out;
if (this.buffer.length >= this.bufferSize) {
this.pushCalled = !this.push(this.buffer);
this.buffer = '';
this.bufferLength = 0;
return false;
}
return true;
}
async _read(size) {
if (this.readState === ReadState.Consumed) return;
if (this.readState !== ReadState.Inactive) {
this.readState = ReadState.ReadMore;
return;
}
this.readState = ReadState.Reading;
this.pushCalled = false;
let p;
while (!this.pushCalled && this.item !== this.root && this.buffer !== undefined) {
p = this.item.read(size); // eslint-disable-next-line no-await-in-loop
if (p) await p;
}
if (this.buffer === undefined) return;
if (this.item === this.root) {
if (this.buffer.length) this.push(this.buffer);
this.push(null);
this.readState = ReadState.Consumed;
this.cleanup();
return;
}
if (this.readState === ReadState.ReadMore) {
this.readState = ReadState.Inactive;
await this._read(size);
return;
}
this.readState = ReadState.Inactive;
}
cleanup() {
this.readState = ReadState.Consumed;
this.buffer = undefined;
this.visited = undefined;
this.item = undefined;
this.root = undefined;
this.prePush = undefined;
}
destroy(error) {
var _super$destroy;
if (error) this.emit('error', error);
(_super$destroy = super.destroy) === null || _super$destroy === void 0 ? void 0 : _super$destroy.call(this);
this.cleanup();
return this;
}
}
exports.JsonStreamStringify = JsonStreamStringify;
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,610 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
require('core-js/modules/es.regexp.exec.js');
require('core-js/modules/es.string.replace.js');
require('core-js/modules/es.string.pad-start.js');
require('core-js/modules/es.array.iterator.js');
require('core-js/modules/web.dom-collections.iterator.js');
require('core-js/modules/es.promise.js');
require('core-js/modules/web.url.to-json.js');
var stream = require('stream');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var _global, _global$JSON;
const 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
const meta = {
'\b': '\\b',
'\t': '\\t',
'\n': '\\n',
'\f': '\\f',
'\r': '\\r',
'"': '\\"',
'\\': '\\\\'
};
function isReadableStream(value) {
return typeof value.read === 'function' && typeof value.pause === 'function' && typeof value.resume === 'function' && typeof value.pipe === 'function' && typeof value.once === 'function' && typeof value.removeListener === 'function';
}
var Types;
(function (Types) {
Types[Types["Array"] = 0] = "Array";
Types[Types["Object"] = 1] = "Object";
Types[Types["ReadableString"] = 2] = "ReadableString";
Types[Types["ReadableObject"] = 3] = "ReadableObject";
Types[Types["Primitive"] = 4] = "Primitive";
Types[Types["Promise"] = 5] = "Promise";
})(Types || (Types = {}));
function getType(value) {
if (!value) return Types.Primitive;
if (typeof value.then === 'function') return Types.Promise;
if (isReadableStream(value)) return value._readableState.objectMode ? Types.ReadableObject : Types.ReadableString;
if (Array.isArray(value)) return Types.Array;
if (typeof value === 'object' || value instanceof Object) return Types.Object;
return Types.Primitive;
}
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, a => {
const c = meta[a];
return typeof c === 'string' ? c : `\\u${a.charCodeAt(0).toString(16).padStart(4, '0')}`;
});
}
let primitiveToJSON;
if (((_global = global) === null || _global === void 0 ? void 0 : (_global$JSON = _global.JSON) === null || _global$JSON === void 0 ? void 0 : _global$JSON.stringify) instanceof Function) {
try {
if (JSON.stringify(global.BigInt ? global.BigInt('123') : '') !== '123') throw new Error();
primitiveToJSON = JSON.stringify;
} catch (err) {
// Add support for bigint for primitiveToJSON
// eslint-disable-next-line no-confusing-arrow
primitiveToJSON = value => typeof value === 'bigint' ? String(value) : JSON.stringify(value);
}
} else {
primitiveToJSON = value => {
switch (typeof value) {
case 'string':
return `"${escapeString(value)}"`;
case 'number':
return Number.isFinite(value) ? String(value) : 'null';
case 'bigint':
return String(value);
case 'boolean':
return value ? 'true' : 'false';
case 'object':
if (!value) {
return 'null';
}
// 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(`Not a primitive "${typeof value}".`), {
value
});
}
};
}
/*
function quoteString(string: string) {
return primitiveToJSON(String(string));
}
*/
const cache = new Map();
function quoteString(string) {
const useCache = string.length < 10000; // eslint-disable-next-line no-lonely-if
if (useCache && cache.has(string)) {
return cache.get(string);
}
const str = primitiveToJSON(String(string));
if (useCache) cache.set(string, str);
return str;
}
function readAsPromised(stream, size) {
var _stream$_readableStat;
const value = stream.read(size);
if (value === null && !(stream.readableEnded || (_stream$_readableStat = stream._readableState) !== null && _stream$_readableStat !== void 0 && _stream$_readableStat.ended)) {
return new Promise((resolve, reject) => {
const endListener = () => resolve(null);
stream.once('end', endListener);
stream.once('error', reject);
stream.once('readable', () => {
stream.removeListener('end', endListener);
stream.removeListener('error', reject);
readAsPromised(stream, size).then(resolve, reject);
});
});
}
return Promise.resolve(value);
}
var ReadState;
(function (ReadState) {
ReadState[ReadState["Inactive"] = 0] = "Inactive";
ReadState[ReadState["Reading"] = 1] = "Reading";
ReadState[ReadState["ReadMore"] = 2] = "ReadMore";
ReadState[ReadState["Consumed"] = 3] = "Consumed";
})(ReadState || (ReadState = {}));
class JsonStreamStringify extends stream.Readable {
constructor(input, replacer, spaces, cycle = false, bufferSize = 512) {
super({
encoding: 'utf8'
});
_defineProperty__default["default"](this, "cycle", void 0);
_defineProperty__default["default"](this, "bufferSize", void 0);
_defineProperty__default["default"](this, "item", void 0);
_defineProperty__default["default"](this, "indent", void 0);
_defineProperty__default["default"](this, "root", void 0);
_defineProperty__default["default"](this, "include", void 0);
_defineProperty__default["default"](this, "replacer", void 0);
_defineProperty__default["default"](this, "visited", void 0);
_defineProperty__default["default"](this, "objectItem", void 0);
_defineProperty__default["default"](this, "buffer", '');
_defineProperty__default["default"](this, "bufferLength", 0);
_defineProperty__default["default"](this, "pushCalled", false);
_defineProperty__default["default"](this, "readSize", 0);
_defineProperty__default["default"](this, "prePush", void 0);
_defineProperty__default["default"](this, "readState", ReadState.Inactive);
this.cycle = cycle;
this.bufferSize = bufferSize;
const spaceType = typeof spaces;
if (spaceType === 'number') {
this.indent = ' '.repeat(spaces);
} else if (spaceType === 'string') {
this.indent = spaces;
}
const replacerType = typeof replacer;
if (replacerType === 'object') {
this.include = replacer;
} else if (replacerType === 'function') {
this.replacer = replacer;
}
this.visited = cycle ? new WeakMap() : [];
this.root = {
value: {
'': input
},
depth: 0,
indent: '',
path: []
};
this.setItem(input, this.root, '');
}
setItem(value, parent, key = '') {
// call toJSON where applicable
if (value && typeof value === 'object' && typeof value.toJSON === 'function') {
value = value.toJSON(key);
} // use replacer if applicable
if (this.replacer) {
value = this.replacer.call(parent.value, key, value);
} // coerece functions and symbols into undefined
if (value instanceof Function || typeof value === 'symbol') {
value = undefined;
}
const type = getType(value);
let path; // check for circular structure
if (!this.cycle && type !== Types.Primitive) {
if (this.visited.some(v => v === value)) {
this.destroy(Object.assign(new Error('Converting circular structure to JSON'), {
value,
key
}));
return;
}
this.visited.push(value);
} else if (this.cycle && type !== Types.Primitive) {
path = this.visited.get(value);
if (path) {
this._push(`{"$ref":"$${path.map(v => `[${Number.isInteger(v) ? v : escapeString(quoteString(v))}]`).join('')}"}`);
this.item = parent;
return;
}
path = parent === this.root ? [] : parent.path.concat(key);
this.visited.set(value, path);
}
if (type === Types.Object) {
this.setObjectItem(value, parent);
} else if (type === Types.Array) {
this.setArrayItem(value, parent);
} else if (type === Types.Primitive) {
if (parent !== this.root && typeof key === 'string') {
// (<any>parent).write(key, primitiveToJSON(value));
if (value === undefined) ; else {
this._push(primitiveToJSON(value));
} // undefined values in objects should be rejected
} else if (value === undefined && typeof key === 'number') {
// undefined values in array should be null
this._push('null');
} else if (value === undefined) ; else {
this._push(primitiveToJSON(value));
}
this.item = parent;
return;
} else if (type === Types.Promise) {
this.setPromiseItem(value, parent, key);
} else if (type === Types.ReadableString) {
this.setReadableStringItem(value, parent);
} else if (type === Types.ReadableObject) {
this.setReadableObjectItem(value, parent);
}
this.item.value = value;
this.item.depth = parent.depth + 1;
if (this.indent) this.item.indent = this.indent.repeat(this.item.depth);
this.item.path = path;
}
setReadableStringItem(input, parent) {
var _input$_readableState, _input$_readableState2;
if (input.readableEnded || (_input$_readableState = input._readableState) !== null && _input$_readableState !== void 0 && _input$_readableState.endEmitted) {
this.emit('error', new Error('Readable Stream has ended before it was serialized. All stream data have been lost'), input, parent.path);
} else if (input.readableFlowing || (_input$_readableState2 = input._readableState) !== null && _input$_readableState2 !== void 0 && _input$_readableState2.flowing) {
input.pause();
this.emit('error', new Error('Readable Stream is in flowing mode, data may have been lost. Trying to pause stream.'), input, parent.path);
}
const that = this;
this.prePush = '"';
this.item = {
type: 'readable string',
async read(size) {
try {
const data = await readAsPromised(input, size);
if (data === null) {
that._push('"');
that.item = parent;
that.unvisit(input);
return;
}
if (data) that._push(escapeString(data.toString()));
} catch (err) {
that.emit('error', err);
that.destroy();
}
}
};
}
setReadableObjectItem(input, parent) {
var _input$_readableState3, _input$_readableState4;
if (input.readableEnded || (_input$_readableState3 = input._readableState) !== null && _input$_readableState3 !== void 0 && _input$_readableState3.endEmitted) {
this.emit('error', new Error('Readable Stream has ended before it was serialized. All stream data have been lost'), input, parent.path);
} else if (input.readableFlowing || (_input$_readableState4 = input._readableState) !== null && _input$_readableState4 !== void 0 && _input$_readableState4.flowing) {
input.pause();
this.emit('error', new Error('Readable Stream is in flowing mode, data may have been lost. Trying to pause stream.'), input, parent.path);
}
const that = this;
this._push('[');
let first = true;
let i = 0;
const item = {
type: 'readable object',
async read() {
try {
let out = '';
const data = await readAsPromised(input);
if (data === null) {
if (i && that.indent) {
out += `\n${parent.indent}`;
}
out += ']';
that._push(out);
that.item = parent;
that.unvisit(input);
return;
}
if (first) first = false;else out += ',';
if (that.indent) out += `\n${item.indent}`;
that.prePush = out;
that.setItem(data, item, i);
i += 1;
} catch (err) {
that.emit('error', err);
that.destroy();
}
}
};
this.item = item;
}
setPromiseItem(input, parent, key) {
const that = this;
let read = false;
this.item = {
async read() {
if (read) return;
try {
read = true;
that.setItem(await input, parent, key);
} catch (err) {
that.emit('error', err);
that.destroy();
}
}
};
}
setArrayItem(input, parent) {
// const entries = input.slice().reverse();
let i = 0;
const len = input.length;
let first = true;
const that = this;
const item = {
read() {
let out = '';
let wasFirst = false;
if (first) {
first = false;
wasFirst = true;
if (!len) {
that._push('[]');
that.unvisit(input);
that.item = parent;
return;
}
out += '[';
}
const entry = input[i];
if (i === len) {
if (that.indent) out += `\n${parent.indent}`;
out += ']';
that._push(out);
that.item = parent;
that.unvisit(input);
return;
}
if (!wasFirst) out += ',';
if (that.indent) out += `\n${item.indent}`;
that._push(out);
that.setItem(entry, item, i);
i += 1;
}
};
this.item = item;
}
unvisit(item) {
if (this.cycle) return;
const _i = this.visited.indexOf(item);
if (_i > -1) this.visited.splice(_i, 1);
}
setObjectItem(input, parent = undefined) {
const keys = Object.keys(input);
let i = 0;
const len = keys.length;
let first = true;
const that = this;
const {
include
} = this;
let hasItems = false;
let key;
const item = {
read() {
var _include$indexOf;
if (i === 0) that._push('{');
if (i === len) {
that.objectItem = undefined;
if (!hasItems) {
that._push('}');
} else {
that._push(`${that.indent ? `\n${parent.indent}` : ''}}`);
}
that.item = parent;
that.unvisit(input);
return;
}
key = keys[i];
if ((include === null || include === void 0 ? void 0 : (_include$indexOf = include.indexOf) === null || _include$indexOf === void 0 ? void 0 : _include$indexOf.call(include, key)) === -1) {
// replacer array excludes this key
i += 1;
return;
}
that.objectItem = item;
i += 1;
that.setItem(input[key], item, key);
},
write() {
const out = `${hasItems && !first ? ',' : ''}${item.indent ? `\n${item.indent}` : ''}${quoteString(key)}:${that.indent ? ' ' : ''}`;
first = false;
hasItems = true;
that.objectItem = undefined;
return out;
}
};
this.item = item;
}
_push(data) {
const out = (this.objectItem ? this.objectItem.write() : '') + data;
if (this.prePush && out.length) {
this.buffer += this.prePush;
this.prePush = undefined;
}
this.buffer += out;
if (this.buffer.length >= this.bufferSize) {
this.pushCalled = !this.push(this.buffer);
this.buffer = '';
this.bufferLength = 0;
return false;
}
return true;
}
async _read(size) {
if (this.readState === ReadState.Consumed) return;
if (this.readState !== ReadState.Inactive) {
this.readState = ReadState.ReadMore;
return;
}
this.readState = ReadState.Reading;
this.pushCalled = false;
let p;
while (!this.pushCalled && this.item !== this.root && this.buffer !== undefined) {
p = this.item.read(size); // eslint-disable-next-line no-await-in-loop
if (p) await p;
}
if (this.buffer === undefined) return;
if (this.item === this.root) {
if (this.buffer.length) this.push(this.buffer);
this.push(null);
this.readState = ReadState.Consumed;
this.cleanup();
return;
}
if (this.readState === ReadState.ReadMore) {
this.readState = ReadState.Inactive;
await this._read(size);
return;
}
this.readState = ReadState.Inactive;
}
cleanup() {
this.readState = ReadState.Consumed;
this.buffer = undefined;
this.visited = undefined;
this.item = undefined;
this.root = undefined;
this.prePush = undefined;
}
destroy(error) {
var _super$destroy;
if (error) this.emit('error', error);
(_super$destroy = super.destroy) === null || _super$destroy === void 0 ? void 0 : _super$destroy.call(this);
this.cleanup();
return this;
}
}
exports.JsonStreamStringify = JsonStreamStringify;
//# sourceMappingURL=polyfill.js.map

File diff suppressed because one or more lines are too long

609
dev/env/node_modules/json-stream-stringify/lib/esm/index.mjs generated vendored Executable file
View File

@@ -0,0 +1,609 @@
import { Readable } from 'stream';
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
var _global, _global$JSON;
const 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
const meta = {
'\b': '\\b',
'\t': '\\t',
'\n': '\\n',
'\f': '\\f',
'\r': '\\r',
'"': '\\"',
'\\': '\\\\'
};
function isReadableStream(value) {
return typeof value.read === 'function' && typeof value.pause === 'function' && typeof value.resume === 'function' && typeof value.pipe === 'function' && typeof value.once === 'function' && typeof value.removeListener === 'function';
}
var Types;
(function (Types) {
Types[Types["Array"] = 0] = "Array";
Types[Types["Object"] = 1] = "Object";
Types[Types["ReadableString"] = 2] = "ReadableString";
Types[Types["ReadableObject"] = 3] = "ReadableObject";
Types[Types["Primitive"] = 4] = "Primitive";
Types[Types["Promise"] = 5] = "Promise";
})(Types || (Types = {}));
function getType(value) {
if (!value) return Types.Primitive;
if (typeof value.then === 'function') return Types.Promise;
if (isReadableStream(value)) return value._readableState.objectMode ? Types.ReadableObject : Types.ReadableString;
if (Array.isArray(value)) return Types.Array;
if (typeof value === 'object' || value instanceof Object) return Types.Object;
return Types.Primitive;
}
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, a => {
const c = meta[a];
return typeof c === 'string' ? c : `\\u${a.charCodeAt(0).toString(16).padStart(4, '0')}`;
});
}
let primitiveToJSON;
if (((_global = global) === null || _global === void 0 ? void 0 : (_global$JSON = _global.JSON) === null || _global$JSON === void 0 ? void 0 : _global$JSON.stringify) instanceof Function) {
try {
if (JSON.stringify(global.BigInt ? global.BigInt('123') : '') !== '123') throw new Error();
primitiveToJSON = JSON.stringify;
} catch (err) {
// Add support for bigint for primitiveToJSON
// eslint-disable-next-line no-confusing-arrow
primitiveToJSON = value => typeof value === 'bigint' ? String(value) : JSON.stringify(value);
}
} else {
primitiveToJSON = value => {
switch (typeof value) {
case 'string':
return `"${escapeString(value)}"`;
case 'number':
return Number.isFinite(value) ? String(value) : 'null';
case 'bigint':
return String(value);
case 'boolean':
return value ? 'true' : 'false';
case 'object':
if (!value) {
return 'null';
}
// 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(`Not a primitive "${typeof value}".`), {
value
});
}
};
}
/*
function quoteString(string: string) {
return primitiveToJSON(String(string));
}
*/
const cache = new Map();
function quoteString(string) {
const useCache = string.length < 10000; // eslint-disable-next-line no-lonely-if
if (useCache && cache.has(string)) {
return cache.get(string);
}
const str = primitiveToJSON(String(string));
if (useCache) cache.set(string, str);
return str;
}
function readAsPromised(stream, size) {
var _stream$_readableStat;
const value = stream.read(size);
if (value === null && !(stream.readableEnded || (_stream$_readableStat = stream._readableState) !== null && _stream$_readableStat !== void 0 && _stream$_readableStat.ended)) {
return new Promise((resolve, reject) => {
const endListener = () => resolve(null);
stream.once('end', endListener);
stream.once('error', reject);
stream.once('readable', () => {
stream.removeListener('end', endListener);
stream.removeListener('error', reject);
readAsPromised(stream, size).then(resolve, reject);
});
});
}
return Promise.resolve(value);
}
var ReadState;
(function (ReadState) {
ReadState[ReadState["Inactive"] = 0] = "Inactive";
ReadState[ReadState["Reading"] = 1] = "Reading";
ReadState[ReadState["ReadMore"] = 2] = "ReadMore";
ReadState[ReadState["Consumed"] = 3] = "Consumed";
})(ReadState || (ReadState = {}));
class JsonStreamStringify extends Readable {
constructor(input, replacer, spaces, cycle = false, bufferSize = 512) {
super({
encoding: 'utf8'
});
_defineProperty(this, "cycle", void 0);
_defineProperty(this, "bufferSize", void 0);
_defineProperty(this, "item", void 0);
_defineProperty(this, "indent", void 0);
_defineProperty(this, "root", void 0);
_defineProperty(this, "include", void 0);
_defineProperty(this, "replacer", void 0);
_defineProperty(this, "visited", void 0);
_defineProperty(this, "objectItem", void 0);
_defineProperty(this, "buffer", '');
_defineProperty(this, "bufferLength", 0);
_defineProperty(this, "pushCalled", false);
_defineProperty(this, "readSize", 0);
_defineProperty(this, "prePush", void 0);
_defineProperty(this, "readState", ReadState.Inactive);
this.cycle = cycle;
this.bufferSize = bufferSize;
const spaceType = typeof spaces;
if (spaceType === 'number') {
this.indent = ' '.repeat(spaces);
} else if (spaceType === 'string') {
this.indent = spaces;
}
const replacerType = typeof replacer;
if (replacerType === 'object') {
this.include = replacer;
} else if (replacerType === 'function') {
this.replacer = replacer;
}
this.visited = cycle ? new WeakMap() : [];
this.root = {
value: {
'': input
},
depth: 0,
indent: '',
path: []
};
this.setItem(input, this.root, '');
}
setItem(value, parent, key = '') {
// call toJSON where applicable
if (value && typeof value === 'object' && typeof value.toJSON === 'function') {
value = value.toJSON(key);
} // use replacer if applicable
if (this.replacer) {
value = this.replacer.call(parent.value, key, value);
} // coerece functions and symbols into undefined
if (value instanceof Function || typeof value === 'symbol') {
value = undefined;
}
const type = getType(value);
let path; // check for circular structure
if (!this.cycle && type !== Types.Primitive) {
if (this.visited.some(v => v === value)) {
this.destroy(Object.assign(new Error('Converting circular structure to JSON'), {
value,
key
}));
return;
}
this.visited.push(value);
} else if (this.cycle && type !== Types.Primitive) {
path = this.visited.get(value);
if (path) {
this._push(`{"$ref":"$${path.map(v => `[${Number.isInteger(v) ? v : escapeString(quoteString(v))}]`).join('')}"}`);
this.item = parent;
return;
}
path = parent === this.root ? [] : parent.path.concat(key);
this.visited.set(value, path);
}
if (type === Types.Object) {
this.setObjectItem(value, parent);
} else if (type === Types.Array) {
this.setArrayItem(value, parent);
} else if (type === Types.Primitive) {
if (parent !== this.root && typeof key === 'string') {
// (<any>parent).write(key, primitiveToJSON(value));
if (value === undefined) ; else {
this._push(primitiveToJSON(value));
} // undefined values in objects should be rejected
} else if (value === undefined && typeof key === 'number') {
// undefined values in array should be null
this._push('null');
} else if (value === undefined) ; else {
this._push(primitiveToJSON(value));
}
this.item = parent;
return;
} else if (type === Types.Promise) {
this.setPromiseItem(value, parent, key);
} else if (type === Types.ReadableString) {
this.setReadableStringItem(value, parent);
} else if (type === Types.ReadableObject) {
this.setReadableObjectItem(value, parent);
}
this.item.value = value;
this.item.depth = parent.depth + 1;
if (this.indent) this.item.indent = this.indent.repeat(this.item.depth);
this.item.path = path;
}
setReadableStringItem(input, parent) {
var _input$_readableState, _input$_readableState2;
if (input.readableEnded || (_input$_readableState = input._readableState) !== null && _input$_readableState !== void 0 && _input$_readableState.endEmitted) {
this.emit('error', new Error('Readable Stream has ended before it was serialized. All stream data have been lost'), input, parent.path);
} else if (input.readableFlowing || (_input$_readableState2 = input._readableState) !== null && _input$_readableState2 !== void 0 && _input$_readableState2.flowing) {
input.pause();
this.emit('error', new Error('Readable Stream is in flowing mode, data may have been lost. Trying to pause stream.'), input, parent.path);
}
const that = this;
this.prePush = '"';
this.item = {
type: 'readable string',
async read(size) {
try {
const data = await readAsPromised(input, size);
if (data === null) {
that._push('"');
that.item = parent;
that.unvisit(input);
return;
}
if (data) that._push(escapeString(data.toString()));
} catch (err) {
that.emit('error', err);
that.destroy();
}
}
};
}
setReadableObjectItem(input, parent) {
var _input$_readableState3, _input$_readableState4;
if (input.readableEnded || (_input$_readableState3 = input._readableState) !== null && _input$_readableState3 !== void 0 && _input$_readableState3.endEmitted) {
this.emit('error', new Error('Readable Stream has ended before it was serialized. All stream data have been lost'), input, parent.path);
} else if (input.readableFlowing || (_input$_readableState4 = input._readableState) !== null && _input$_readableState4 !== void 0 && _input$_readableState4.flowing) {
input.pause();
this.emit('error', new Error('Readable Stream is in flowing mode, data may have been lost. Trying to pause stream.'), input, parent.path);
}
const that = this;
this._push('[');
let first = true;
let i = 0;
const item = {
type: 'readable object',
async read() {
try {
let out = '';
const data = await readAsPromised(input);
if (data === null) {
if (i && that.indent) {
out += `\n${parent.indent}`;
}
out += ']';
that._push(out);
that.item = parent;
that.unvisit(input);
return;
}
if (first) first = false;else out += ',';
if (that.indent) out += `\n${item.indent}`;
that.prePush = out;
that.setItem(data, item, i);
i += 1;
} catch (err) {
that.emit('error', err);
that.destroy();
}
}
};
this.item = item;
}
setPromiseItem(input, parent, key) {
const that = this;
let read = false;
this.item = {
async read() {
if (read) return;
try {
read = true;
that.setItem(await input, parent, key);
} catch (err) {
that.emit('error', err);
that.destroy();
}
}
};
}
setArrayItem(input, parent) {
// const entries = input.slice().reverse();
let i = 0;
const len = input.length;
let first = true;
const that = this;
const item = {
read() {
let out = '';
let wasFirst = false;
if (first) {
first = false;
wasFirst = true;
if (!len) {
that._push('[]');
that.unvisit(input);
that.item = parent;
return;
}
out += '[';
}
const entry = input[i];
if (i === len) {
if (that.indent) out += `\n${parent.indent}`;
out += ']';
that._push(out);
that.item = parent;
that.unvisit(input);
return;
}
if (!wasFirst) out += ',';
if (that.indent) out += `\n${item.indent}`;
that._push(out);
that.setItem(entry, item, i);
i += 1;
}
};
this.item = item;
}
unvisit(item) {
if (this.cycle) return;
const _i = this.visited.indexOf(item);
if (_i > -1) this.visited.splice(_i, 1);
}
setObjectItem(input, parent = undefined) {
const keys = Object.keys(input);
let i = 0;
const len = keys.length;
let first = true;
const that = this;
const {
include
} = this;
let hasItems = false;
let key;
const item = {
read() {
var _include$indexOf;
if (i === 0) that._push('{');
if (i === len) {
that.objectItem = undefined;
if (!hasItems) {
that._push('}');
} else {
that._push(`${that.indent ? `\n${parent.indent}` : ''}}`);
}
that.item = parent;
that.unvisit(input);
return;
}
key = keys[i];
if ((include === null || include === void 0 ? void 0 : (_include$indexOf = include.indexOf) === null || _include$indexOf === void 0 ? void 0 : _include$indexOf.call(include, key)) === -1) {
// replacer array excludes this key
i += 1;
return;
}
that.objectItem = item;
i += 1;
that.setItem(input[key], item, key);
},
write() {
const out = `${hasItems && !first ? ',' : ''}${item.indent ? `\n${item.indent}` : ''}${quoteString(key)}:${that.indent ? ' ' : ''}`;
first = false;
hasItems = true;
that.objectItem = undefined;
return out;
}
};
this.item = item;
}
_push(data) {
const out = (this.objectItem ? this.objectItem.write() : '') + data;
if (this.prePush && out.length) {
this.buffer += this.prePush;
this.prePush = undefined;
}
this.buffer += out;
if (this.buffer.length >= this.bufferSize) {
this.pushCalled = !this.push(this.buffer);
this.buffer = '';
this.bufferLength = 0;
return false;
}
return true;
}
async _read(size) {
if (this.readState === ReadState.Consumed) return;
if (this.readState !== ReadState.Inactive) {
this.readState = ReadState.ReadMore;
return;
}
this.readState = ReadState.Reading;
this.pushCalled = false;
let p;
while (!this.pushCalled && this.item !== this.root && this.buffer !== undefined) {
p = this.item.read(size); // eslint-disable-next-line no-await-in-loop
if (p) await p;
}
if (this.buffer === undefined) return;
if (this.item === this.root) {
if (this.buffer.length) this.push(this.buffer);
this.push(null);
this.readState = ReadState.Consumed;
this.cleanup();
return;
}
if (this.readState === ReadState.ReadMore) {
this.readState = ReadState.Inactive;
await this._read(size);
return;
}
this.readState = ReadState.Inactive;
}
cleanup() {
this.readState = ReadState.Consumed;
this.buffer = undefined;
this.visited = undefined;
this.item = undefined;
this.root = undefined;
this.prePush = undefined;
}
destroy(error) {
var _super$destroy;
if (error) this.emit('error', error);
(_super$destroy = super.destroy) === null || _super$destroy === void 0 ? void 0 : _super$destroy.call(this);
this.cleanup();
return this;
}
}
export { JsonStreamStringify };
//# sourceMappingURL=index.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,3 @@
{
"type": "module"
}

View File

@@ -0,0 +1,602 @@
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import 'core-js/modules/es.regexp.exec.js';
import 'core-js/modules/es.string.replace.js';
import 'core-js/modules/es.string.pad-start.js';
import 'core-js/modules/es.array.iterator.js';
import 'core-js/modules/web.dom-collections.iterator.js';
import 'core-js/modules/es.promise.js';
import 'core-js/modules/web.url.to-json.js';
import { Readable } from 'stream';
var _global, _global$JSON;
const 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
const meta = {
'\b': '\\b',
'\t': '\\t',
'\n': '\\n',
'\f': '\\f',
'\r': '\\r',
'"': '\\"',
'\\': '\\\\'
};
function isReadableStream(value) {
return typeof value.read === 'function' && typeof value.pause === 'function' && typeof value.resume === 'function' && typeof value.pipe === 'function' && typeof value.once === 'function' && typeof value.removeListener === 'function';
}
var Types;
(function (Types) {
Types[Types["Array"] = 0] = "Array";
Types[Types["Object"] = 1] = "Object";
Types[Types["ReadableString"] = 2] = "ReadableString";
Types[Types["ReadableObject"] = 3] = "ReadableObject";
Types[Types["Primitive"] = 4] = "Primitive";
Types[Types["Promise"] = 5] = "Promise";
})(Types || (Types = {}));
function getType(value) {
if (!value) return Types.Primitive;
if (typeof value.then === 'function') return Types.Promise;
if (isReadableStream(value)) return value._readableState.objectMode ? Types.ReadableObject : Types.ReadableString;
if (Array.isArray(value)) return Types.Array;
if (typeof value === 'object' || value instanceof Object) return Types.Object;
return Types.Primitive;
}
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, a => {
const c = meta[a];
return typeof c === 'string' ? c : `\\u${a.charCodeAt(0).toString(16).padStart(4, '0')}`;
});
}
let primitiveToJSON;
if (((_global = global) === null || _global === void 0 ? void 0 : (_global$JSON = _global.JSON) === null || _global$JSON === void 0 ? void 0 : _global$JSON.stringify) instanceof Function) {
try {
if (JSON.stringify(global.BigInt ? global.BigInt('123') : '') !== '123') throw new Error();
primitiveToJSON = JSON.stringify;
} catch (err) {
// Add support for bigint for primitiveToJSON
// eslint-disable-next-line no-confusing-arrow
primitiveToJSON = value => typeof value === 'bigint' ? String(value) : JSON.stringify(value);
}
} else {
primitiveToJSON = value => {
switch (typeof value) {
case 'string':
return `"${escapeString(value)}"`;
case 'number':
return Number.isFinite(value) ? String(value) : 'null';
case 'bigint':
return String(value);
case 'boolean':
return value ? 'true' : 'false';
case 'object':
if (!value) {
return 'null';
}
// 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(`Not a primitive "${typeof value}".`), {
value
});
}
};
}
/*
function quoteString(string: string) {
return primitiveToJSON(String(string));
}
*/
const cache = new Map();
function quoteString(string) {
const useCache = string.length < 10000; // eslint-disable-next-line no-lonely-if
if (useCache && cache.has(string)) {
return cache.get(string);
}
const str = primitiveToJSON(String(string));
if (useCache) cache.set(string, str);
return str;
}
function readAsPromised(stream, size) {
var _stream$_readableStat;
const value = stream.read(size);
if (value === null && !(stream.readableEnded || (_stream$_readableStat = stream._readableState) !== null && _stream$_readableStat !== void 0 && _stream$_readableStat.ended)) {
return new Promise((resolve, reject) => {
const endListener = () => resolve(null);
stream.once('end', endListener);
stream.once('error', reject);
stream.once('readable', () => {
stream.removeListener('end', endListener);
stream.removeListener('error', reject);
readAsPromised(stream, size).then(resolve, reject);
});
});
}
return Promise.resolve(value);
}
var ReadState;
(function (ReadState) {
ReadState[ReadState["Inactive"] = 0] = "Inactive";
ReadState[ReadState["Reading"] = 1] = "Reading";
ReadState[ReadState["ReadMore"] = 2] = "ReadMore";
ReadState[ReadState["Consumed"] = 3] = "Consumed";
})(ReadState || (ReadState = {}));
class JsonStreamStringify extends Readable {
constructor(input, replacer, spaces, cycle = false, bufferSize = 512) {
super({
encoding: 'utf8'
});
_defineProperty(this, "cycle", void 0);
_defineProperty(this, "bufferSize", void 0);
_defineProperty(this, "item", void 0);
_defineProperty(this, "indent", void 0);
_defineProperty(this, "root", void 0);
_defineProperty(this, "include", void 0);
_defineProperty(this, "replacer", void 0);
_defineProperty(this, "visited", void 0);
_defineProperty(this, "objectItem", void 0);
_defineProperty(this, "buffer", '');
_defineProperty(this, "bufferLength", 0);
_defineProperty(this, "pushCalled", false);
_defineProperty(this, "readSize", 0);
_defineProperty(this, "prePush", void 0);
_defineProperty(this, "readState", ReadState.Inactive);
this.cycle = cycle;
this.bufferSize = bufferSize;
const spaceType = typeof spaces;
if (spaceType === 'number') {
this.indent = ' '.repeat(spaces);
} else if (spaceType === 'string') {
this.indent = spaces;
}
const replacerType = typeof replacer;
if (replacerType === 'object') {
this.include = replacer;
} else if (replacerType === 'function') {
this.replacer = replacer;
}
this.visited = cycle ? new WeakMap() : [];
this.root = {
value: {
'': input
},
depth: 0,
indent: '',
path: []
};
this.setItem(input, this.root, '');
}
setItem(value, parent, key = '') {
// call toJSON where applicable
if (value && typeof value === 'object' && typeof value.toJSON === 'function') {
value = value.toJSON(key);
} // use replacer if applicable
if (this.replacer) {
value = this.replacer.call(parent.value, key, value);
} // coerece functions and symbols into undefined
if (value instanceof Function || typeof value === 'symbol') {
value = undefined;
}
const type = getType(value);
let path; // check for circular structure
if (!this.cycle && type !== Types.Primitive) {
if (this.visited.some(v => v === value)) {
this.destroy(Object.assign(new Error('Converting circular structure to JSON'), {
value,
key
}));
return;
}
this.visited.push(value);
} else if (this.cycle && type !== Types.Primitive) {
path = this.visited.get(value);
if (path) {
this._push(`{"$ref":"$${path.map(v => `[${Number.isInteger(v) ? v : escapeString(quoteString(v))}]`).join('')}"}`);
this.item = parent;
return;
}
path = parent === this.root ? [] : parent.path.concat(key);
this.visited.set(value, path);
}
if (type === Types.Object) {
this.setObjectItem(value, parent);
} else if (type === Types.Array) {
this.setArrayItem(value, parent);
} else if (type === Types.Primitive) {
if (parent !== this.root && typeof key === 'string') {
// (<any>parent).write(key, primitiveToJSON(value));
if (value === undefined) ; else {
this._push(primitiveToJSON(value));
} // undefined values in objects should be rejected
} else if (value === undefined && typeof key === 'number') {
// undefined values in array should be null
this._push('null');
} else if (value === undefined) ; else {
this._push(primitiveToJSON(value));
}
this.item = parent;
return;
} else if (type === Types.Promise) {
this.setPromiseItem(value, parent, key);
} else if (type === Types.ReadableString) {
this.setReadableStringItem(value, parent);
} else if (type === Types.ReadableObject) {
this.setReadableObjectItem(value, parent);
}
this.item.value = value;
this.item.depth = parent.depth + 1;
if (this.indent) this.item.indent = this.indent.repeat(this.item.depth);
this.item.path = path;
}
setReadableStringItem(input, parent) {
var _input$_readableState, _input$_readableState2;
if (input.readableEnded || (_input$_readableState = input._readableState) !== null && _input$_readableState !== void 0 && _input$_readableState.endEmitted) {
this.emit('error', new Error('Readable Stream has ended before it was serialized. All stream data have been lost'), input, parent.path);
} else if (input.readableFlowing || (_input$_readableState2 = input._readableState) !== null && _input$_readableState2 !== void 0 && _input$_readableState2.flowing) {
input.pause();
this.emit('error', new Error('Readable Stream is in flowing mode, data may have been lost. Trying to pause stream.'), input, parent.path);
}
const that = this;
this.prePush = '"';
this.item = {
type: 'readable string',
async read(size) {
try {
const data = await readAsPromised(input, size);
if (data === null) {
that._push('"');
that.item = parent;
that.unvisit(input);
return;
}
if (data) that._push(escapeString(data.toString()));
} catch (err) {
that.emit('error', err);
that.destroy();
}
}
};
}
setReadableObjectItem(input, parent) {
var _input$_readableState3, _input$_readableState4;
if (input.readableEnded || (_input$_readableState3 = input._readableState) !== null && _input$_readableState3 !== void 0 && _input$_readableState3.endEmitted) {
this.emit('error', new Error('Readable Stream has ended before it was serialized. All stream data have been lost'), input, parent.path);
} else if (input.readableFlowing || (_input$_readableState4 = input._readableState) !== null && _input$_readableState4 !== void 0 && _input$_readableState4.flowing) {
input.pause();
this.emit('error', new Error('Readable Stream is in flowing mode, data may have been lost. Trying to pause stream.'), input, parent.path);
}
const that = this;
this._push('[');
let first = true;
let i = 0;
const item = {
type: 'readable object',
async read() {
try {
let out = '';
const data = await readAsPromised(input);
if (data === null) {
if (i && that.indent) {
out += `\n${parent.indent}`;
}
out += ']';
that._push(out);
that.item = parent;
that.unvisit(input);
return;
}
if (first) first = false;else out += ',';
if (that.indent) out += `\n${item.indent}`;
that.prePush = out;
that.setItem(data, item, i);
i += 1;
} catch (err) {
that.emit('error', err);
that.destroy();
}
}
};
this.item = item;
}
setPromiseItem(input, parent, key) {
const that = this;
let read = false;
this.item = {
async read() {
if (read) return;
try {
read = true;
that.setItem(await input, parent, key);
} catch (err) {
that.emit('error', err);
that.destroy();
}
}
};
}
setArrayItem(input, parent) {
// const entries = input.slice().reverse();
let i = 0;
const len = input.length;
let first = true;
const that = this;
const item = {
read() {
let out = '';
let wasFirst = false;
if (first) {
first = false;
wasFirst = true;
if (!len) {
that._push('[]');
that.unvisit(input);
that.item = parent;
return;
}
out += '[';
}
const entry = input[i];
if (i === len) {
if (that.indent) out += `\n${parent.indent}`;
out += ']';
that._push(out);
that.item = parent;
that.unvisit(input);
return;
}
if (!wasFirst) out += ',';
if (that.indent) out += `\n${item.indent}`;
that._push(out);
that.setItem(entry, item, i);
i += 1;
}
};
this.item = item;
}
unvisit(item) {
if (this.cycle) return;
const _i = this.visited.indexOf(item);
if (_i > -1) this.visited.splice(_i, 1);
}
setObjectItem(input, parent = undefined) {
const keys = Object.keys(input);
let i = 0;
const len = keys.length;
let first = true;
const that = this;
const {
include
} = this;
let hasItems = false;
let key;
const item = {
read() {
var _include$indexOf;
if (i === 0) that._push('{');
if (i === len) {
that.objectItem = undefined;
if (!hasItems) {
that._push('}');
} else {
that._push(`${that.indent ? `\n${parent.indent}` : ''}}`);
}
that.item = parent;
that.unvisit(input);
return;
}
key = keys[i];
if ((include === null || include === void 0 ? void 0 : (_include$indexOf = include.indexOf) === null || _include$indexOf === void 0 ? void 0 : _include$indexOf.call(include, key)) === -1) {
// replacer array excludes this key
i += 1;
return;
}
that.objectItem = item;
i += 1;
that.setItem(input[key], item, key);
},
write() {
const out = `${hasItems && !first ? ',' : ''}${item.indent ? `\n${item.indent}` : ''}${quoteString(key)}:${that.indent ? ' ' : ''}`;
first = false;
hasItems = true;
that.objectItem = undefined;
return out;
}
};
this.item = item;
}
_push(data) {
const out = (this.objectItem ? this.objectItem.write() : '') + data;
if (this.prePush && out.length) {
this.buffer += this.prePush;
this.prePush = undefined;
}
this.buffer += out;
if (this.buffer.length >= this.bufferSize) {
this.pushCalled = !this.push(this.buffer);
this.buffer = '';
this.bufferLength = 0;
return false;
}
return true;
}
async _read(size) {
if (this.readState === ReadState.Consumed) return;
if (this.readState !== ReadState.Inactive) {
this.readState = ReadState.ReadMore;
return;
}
this.readState = ReadState.Reading;
this.pushCalled = false;
let p;
while (!this.pushCalled && this.item !== this.root && this.buffer !== undefined) {
p = this.item.read(size); // eslint-disable-next-line no-await-in-loop
if (p) await p;
}
if (this.buffer === undefined) return;
if (this.item === this.root) {
if (this.buffer.length) this.push(this.buffer);
this.push(null);
this.readState = ReadState.Consumed;
this.cleanup();
return;
}
if (this.readState === ReadState.ReadMore) {
this.readState = ReadState.Inactive;
await this._read(size);
return;
}
this.readState = ReadState.Inactive;
}
cleanup() {
this.readState = ReadState.Consumed;
this.buffer = undefined;
this.visited = undefined;
this.item = undefined;
this.root = undefined;
this.prePush = undefined;
}
destroy(error) {
var _super$destroy;
if (error) this.emit('error', error);
(_super$destroy = super.destroy) === null || _super$destroy === void 0 ? void 0 : _super$destroy.call(this);
this.cleanup();
return this;
}
}
export { JsonStreamStringify };
//# sourceMappingURL=polyfill.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,48 @@
import { Readable } from 'stream';
interface Item {
read(size?: number): Promise<void> | void;
depth?: number;
value?: any;
indent?: string;
path?: (string | number)[];
type?: string;
}
declare enum ReadState {
Inactive = 0,
Reading = 1,
ReadMore = 2,
Consumed = 3
}
declare class JsonStreamStringify extends Readable {
private cycle;
private bufferSize;
item?: Item;
indent?: string;
root: Item;
include: string[];
replacer: Function;
visited: [] | WeakMap<any, string[]>;
constructor(input: any, replacer?: Function | any[] | undefined, spaces?: number | string | undefined, cycle?: boolean, bufferSize?: number);
setItem(value: any, parent: Item, key?: string | number): void;
setReadableStringItem(input: Readable, parent: Item): void;
setReadableObjectItem(input: Readable, parent: Item): void;
setPromiseItem(input: Promise<any>, parent: Item, key: any): void;
setArrayItem(input: any[], parent: any): void;
unvisit(item: any): void;
objectItem?: any;
setObjectItem(input: Record<any, any>, parent?: any): void;
buffer: string;
bufferLength: number;
pushCalled: boolean;
readSize: number;
/** if set, this string will be prepended to the next _push call, if the call output is not empty, and set to undefined */
prePush?: string;
private _push;
readState: ReadState;
_read(size?: number): Promise<void>;
private cleanup;
destroy(error?: Error): this;
}
export { JsonStreamStringify };

617
dev/env/node_modules/json-stream-stringify/lib/umd/index.js generated vendored Executable file
View File

@@ -0,0 +1,617 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('stream')) :
typeof define === 'function' && define.amd ? define(['exports', 'stream'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.jsonStreamStringify = {}, global.stream));
})(this, (function (exports, stream) { 'use strict';
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
var _global, _global$JSON;
const 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
const meta = {
'\b': '\\b',
'\t': '\\t',
'\n': '\\n',
'\f': '\\f',
'\r': '\\r',
'"': '\\"',
'\\': '\\\\'
};
function isReadableStream(value) {
return typeof value.read === 'function' && typeof value.pause === 'function' && typeof value.resume === 'function' && typeof value.pipe === 'function' && typeof value.once === 'function' && typeof value.removeListener === 'function';
}
var Types;
(function (Types) {
Types[Types["Array"] = 0] = "Array";
Types[Types["Object"] = 1] = "Object";
Types[Types["ReadableString"] = 2] = "ReadableString";
Types[Types["ReadableObject"] = 3] = "ReadableObject";
Types[Types["Primitive"] = 4] = "Primitive";
Types[Types["Promise"] = 5] = "Promise";
})(Types || (Types = {}));
function getType(value) {
if (!value) return Types.Primitive;
if (typeof value.then === 'function') return Types.Promise;
if (isReadableStream(value)) return value._readableState.objectMode ? Types.ReadableObject : Types.ReadableString;
if (Array.isArray(value)) return Types.Array;
if (typeof value === 'object' || value instanceof Object) return Types.Object;
return Types.Primitive;
}
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, a => {
const c = meta[a];
return typeof c === 'string' ? c : `\\u${a.charCodeAt(0).toString(16).padStart(4, '0')}`;
});
}
let primitiveToJSON;
if (((_global = global) === null || _global === void 0 ? void 0 : (_global$JSON = _global.JSON) === null || _global$JSON === void 0 ? void 0 : _global$JSON.stringify) instanceof Function) {
try {
if (JSON.stringify(global.BigInt ? global.BigInt('123') : '') !== '123') throw new Error();
primitiveToJSON = JSON.stringify;
} catch (err) {
// Add support for bigint for primitiveToJSON
// eslint-disable-next-line no-confusing-arrow
primitiveToJSON = value => typeof value === 'bigint' ? String(value) : JSON.stringify(value);
}
} else {
primitiveToJSON = value => {
switch (typeof value) {
case 'string':
return `"${escapeString(value)}"`;
case 'number':
return Number.isFinite(value) ? String(value) : 'null';
case 'bigint':
return String(value);
case 'boolean':
return value ? 'true' : 'false';
case 'object':
if (!value) {
return 'null';
}
// 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(`Not a primitive "${typeof value}".`), {
value
});
}
};
}
/*
function quoteString(string: string) {
return primitiveToJSON(String(string));
}
*/
const cache = new Map();
function quoteString(string) {
const useCache = string.length < 10000; // eslint-disable-next-line no-lonely-if
if (useCache && cache.has(string)) {
return cache.get(string);
}
const str = primitiveToJSON(String(string));
if (useCache) cache.set(string, str);
return str;
}
function readAsPromised(stream, size) {
var _stream$_readableStat;
const value = stream.read(size);
if (value === null && !(stream.readableEnded || (_stream$_readableStat = stream._readableState) !== null && _stream$_readableStat !== void 0 && _stream$_readableStat.ended)) {
return new Promise((resolve, reject) => {
const endListener = () => resolve(null);
stream.once('end', endListener);
stream.once('error', reject);
stream.once('readable', () => {
stream.removeListener('end', endListener);
stream.removeListener('error', reject);
readAsPromised(stream, size).then(resolve, reject);
});
});
}
return Promise.resolve(value);
}
var ReadState;
(function (ReadState) {
ReadState[ReadState["Inactive"] = 0] = "Inactive";
ReadState[ReadState["Reading"] = 1] = "Reading";
ReadState[ReadState["ReadMore"] = 2] = "ReadMore";
ReadState[ReadState["Consumed"] = 3] = "Consumed";
})(ReadState || (ReadState = {}));
class JsonStreamStringify extends stream.Readable {
constructor(input, replacer, spaces, cycle = false, bufferSize = 512) {
super({
encoding: 'utf8'
});
_defineProperty(this, "cycle", void 0);
_defineProperty(this, "bufferSize", void 0);
_defineProperty(this, "item", void 0);
_defineProperty(this, "indent", void 0);
_defineProperty(this, "root", void 0);
_defineProperty(this, "include", void 0);
_defineProperty(this, "replacer", void 0);
_defineProperty(this, "visited", void 0);
_defineProperty(this, "objectItem", void 0);
_defineProperty(this, "buffer", '');
_defineProperty(this, "bufferLength", 0);
_defineProperty(this, "pushCalled", false);
_defineProperty(this, "readSize", 0);
_defineProperty(this, "prePush", void 0);
_defineProperty(this, "readState", ReadState.Inactive);
this.cycle = cycle;
this.bufferSize = bufferSize;
const spaceType = typeof spaces;
if (spaceType === 'number') {
this.indent = ' '.repeat(spaces);
} else if (spaceType === 'string') {
this.indent = spaces;
}
const replacerType = typeof replacer;
if (replacerType === 'object') {
this.include = replacer;
} else if (replacerType === 'function') {
this.replacer = replacer;
}
this.visited = cycle ? new WeakMap() : [];
this.root = {
value: {
'': input
},
depth: 0,
indent: '',
path: []
};
this.setItem(input, this.root, '');
}
setItem(value, parent, key = '') {
// call toJSON where applicable
if (value && typeof value === 'object' && typeof value.toJSON === 'function') {
value = value.toJSON(key);
} // use replacer if applicable
if (this.replacer) {
value = this.replacer.call(parent.value, key, value);
} // coerece functions and symbols into undefined
if (value instanceof Function || typeof value === 'symbol') {
value = undefined;
}
const type = getType(value);
let path; // check for circular structure
if (!this.cycle && type !== Types.Primitive) {
if (this.visited.some(v => v === value)) {
this.destroy(Object.assign(new Error('Converting circular structure to JSON'), {
value,
key
}));
return;
}
this.visited.push(value);
} else if (this.cycle && type !== Types.Primitive) {
path = this.visited.get(value);
if (path) {
this._push(`{"$ref":"$${path.map(v => `[${Number.isInteger(v) ? v : escapeString(quoteString(v))}]`).join('')}"}`);
this.item = parent;
return;
}
path = parent === this.root ? [] : parent.path.concat(key);
this.visited.set(value, path);
}
if (type === Types.Object) {
this.setObjectItem(value, parent);
} else if (type === Types.Array) {
this.setArrayItem(value, parent);
} else if (type === Types.Primitive) {
if (parent !== this.root && typeof key === 'string') {
// (<any>parent).write(key, primitiveToJSON(value));
if (value === undefined) ; else {
this._push(primitiveToJSON(value));
} // undefined values in objects should be rejected
} else if (value === undefined && typeof key === 'number') {
// undefined values in array should be null
this._push('null');
} else if (value === undefined) ; else {
this._push(primitiveToJSON(value));
}
this.item = parent;
return;
} else if (type === Types.Promise) {
this.setPromiseItem(value, parent, key);
} else if (type === Types.ReadableString) {
this.setReadableStringItem(value, parent);
} else if (type === Types.ReadableObject) {
this.setReadableObjectItem(value, parent);
}
this.item.value = value;
this.item.depth = parent.depth + 1;
if (this.indent) this.item.indent = this.indent.repeat(this.item.depth);
this.item.path = path;
}
setReadableStringItem(input, parent) {
var _input$_readableState, _input$_readableState2;
if (input.readableEnded || (_input$_readableState = input._readableState) !== null && _input$_readableState !== void 0 && _input$_readableState.endEmitted) {
this.emit('error', new Error('Readable Stream has ended before it was serialized. All stream data have been lost'), input, parent.path);
} else if (input.readableFlowing || (_input$_readableState2 = input._readableState) !== null && _input$_readableState2 !== void 0 && _input$_readableState2.flowing) {
input.pause();
this.emit('error', new Error('Readable Stream is in flowing mode, data may have been lost. Trying to pause stream.'), input, parent.path);
}
const that = this;
this.prePush = '"';
this.item = {
type: 'readable string',
async read(size) {
try {
const data = await readAsPromised(input, size);
if (data === null) {
that._push('"');
that.item = parent;
that.unvisit(input);
return;
}
if (data) that._push(escapeString(data.toString()));
} catch (err) {
that.emit('error', err);
that.destroy();
}
}
};
}
setReadableObjectItem(input, parent) {
var _input$_readableState3, _input$_readableState4;
if (input.readableEnded || (_input$_readableState3 = input._readableState) !== null && _input$_readableState3 !== void 0 && _input$_readableState3.endEmitted) {
this.emit('error', new Error('Readable Stream has ended before it was serialized. All stream data have been lost'), input, parent.path);
} else if (input.readableFlowing || (_input$_readableState4 = input._readableState) !== null && _input$_readableState4 !== void 0 && _input$_readableState4.flowing) {
input.pause();
this.emit('error', new Error('Readable Stream is in flowing mode, data may have been lost. Trying to pause stream.'), input, parent.path);
}
const that = this;
this._push('[');
let first = true;
let i = 0;
const item = {
type: 'readable object',
async read() {
try {
let out = '';
const data = await readAsPromised(input);
if (data === null) {
if (i && that.indent) {
out += `\n${parent.indent}`;
}
out += ']';
that._push(out);
that.item = parent;
that.unvisit(input);
return;
}
if (first) first = false;else out += ',';
if (that.indent) out += `\n${item.indent}`;
that.prePush = out;
that.setItem(data, item, i);
i += 1;
} catch (err) {
that.emit('error', err);
that.destroy();
}
}
};
this.item = item;
}
setPromiseItem(input, parent, key) {
const that = this;
let read = false;
this.item = {
async read() {
if (read) return;
try {
read = true;
that.setItem(await input, parent, key);
} catch (err) {
that.emit('error', err);
that.destroy();
}
}
};
}
setArrayItem(input, parent) {
// const entries = input.slice().reverse();
let i = 0;
const len = input.length;
let first = true;
const that = this;
const item = {
read() {
let out = '';
let wasFirst = false;
if (first) {
first = false;
wasFirst = true;
if (!len) {
that._push('[]');
that.unvisit(input);
that.item = parent;
return;
}
out += '[';
}
const entry = input[i];
if (i === len) {
if (that.indent) out += `\n${parent.indent}`;
out += ']';
that._push(out);
that.item = parent;
that.unvisit(input);
return;
}
if (!wasFirst) out += ',';
if (that.indent) out += `\n${item.indent}`;
that._push(out);
that.setItem(entry, item, i);
i += 1;
}
};
this.item = item;
}
unvisit(item) {
if (this.cycle) return;
const _i = this.visited.indexOf(item);
if (_i > -1) this.visited.splice(_i, 1);
}
setObjectItem(input, parent = undefined) {
const keys = Object.keys(input);
let i = 0;
const len = keys.length;
let first = true;
const that = this;
const {
include
} = this;
let hasItems = false;
let key;
const item = {
read() {
var _include$indexOf;
if (i === 0) that._push('{');
if (i === len) {
that.objectItem = undefined;
if (!hasItems) {
that._push('}');
} else {
that._push(`${that.indent ? `\n${parent.indent}` : ''}}`);
}
that.item = parent;
that.unvisit(input);
return;
}
key = keys[i];
if ((include === null || include === void 0 ? void 0 : (_include$indexOf = include.indexOf) === null || _include$indexOf === void 0 ? void 0 : _include$indexOf.call(include, key)) === -1) {
// replacer array excludes this key
i += 1;
return;
}
that.objectItem = item;
i += 1;
that.setItem(input[key], item, key);
},
write() {
const out = `${hasItems && !first ? ',' : ''}${item.indent ? `\n${item.indent}` : ''}${quoteString(key)}:${that.indent ? ' ' : ''}`;
first = false;
hasItems = true;
that.objectItem = undefined;
return out;
}
};
this.item = item;
}
_push(data) {
const out = (this.objectItem ? this.objectItem.write() : '') + data;
if (this.prePush && out.length) {
this.buffer += this.prePush;
this.prePush = undefined;
}
this.buffer += out;
if (this.buffer.length >= this.bufferSize) {
this.pushCalled = !this.push(this.buffer);
this.buffer = '';
this.bufferLength = 0;
return false;
}
return true;
}
async _read(size) {
if (this.readState === ReadState.Consumed) return;
if (this.readState !== ReadState.Inactive) {
this.readState = ReadState.ReadMore;
return;
}
this.readState = ReadState.Reading;
this.pushCalled = false;
let p;
while (!this.pushCalled && this.item !== this.root && this.buffer !== undefined) {
p = this.item.read(size); // eslint-disable-next-line no-await-in-loop
if (p) await p;
}
if (this.buffer === undefined) return;
if (this.item === this.root) {
if (this.buffer.length) this.push(this.buffer);
this.push(null);
this.readState = ReadState.Consumed;
this.cleanup();
return;
}
if (this.readState === ReadState.ReadMore) {
this.readState = ReadState.Inactive;
await this._read(size);
return;
}
this.readState = ReadState.Inactive;
}
cleanup() {
this.readState = ReadState.Consumed;
this.buffer = undefined;
this.visited = undefined;
this.item = undefined;
this.root = undefined;
this.prePush = undefined;
}
destroy(error) {
var _super$destroy;
if (error) this.emit('error', error);
(_super$destroy = super.destroy) === null || _super$destroy === void 0 ? void 0 : _super$destroy.call(this);
this.cleanup();
return this;
}
}
exports.JsonStreamStringify = JsonStreamStringify;
Object.defineProperty(exports, '__esModule', { value: true });
}));
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,606 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@babel/runtime/helpers/defineProperty'), require('core-js/modules/es.regexp.exec.js'), require('core-js/modules/es.string.replace.js'), require('core-js/modules/es.string.pad-start.js'), require('core-js/modules/es.array.iterator.js'), require('core-js/modules/web.dom-collections.iterator.js'), require('core-js/modules/es.promise.js'), require('core-js/modules/web.url.to-json.js'), require('stream')) :
typeof define === 'function' && define.amd ? define(['exports', '@babel/runtime/helpers/defineProperty', 'core-js/modules/es.regexp.exec.js', 'core-js/modules/es.string.replace.js', 'core-js/modules/es.string.pad-start.js', 'core-js/modules/es.array.iterator.js', 'core-js/modules/web.dom-collections.iterator.js', 'core-js/modules/es.promise.js', 'core-js/modules/web.url.to-json.js', 'stream'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.jsonStreamStringify = {}, global._defineProperty, null, null, null, null, null, null, null, global.stream));
})(this, (function (exports, _defineProperty, es_regexp_exec_js, es_string_replace_js, es_string_padStart_js, es_array_iterator_js, web_domCollections_iterator_js, es_promise_js, web_url_toJson_js, stream) { 'use strict';
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var _global, _global$JSON;
const 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
const meta = {
'\b': '\\b',
'\t': '\\t',
'\n': '\\n',
'\f': '\\f',
'\r': '\\r',
'"': '\\"',
'\\': '\\\\'
};
function isReadableStream(value) {
return typeof value.read === 'function' && typeof value.pause === 'function' && typeof value.resume === 'function' && typeof value.pipe === 'function' && typeof value.once === 'function' && typeof value.removeListener === 'function';
}
var Types;
(function (Types) {
Types[Types["Array"] = 0] = "Array";
Types[Types["Object"] = 1] = "Object";
Types[Types["ReadableString"] = 2] = "ReadableString";
Types[Types["ReadableObject"] = 3] = "ReadableObject";
Types[Types["Primitive"] = 4] = "Primitive";
Types[Types["Promise"] = 5] = "Promise";
})(Types || (Types = {}));
function getType(value) {
if (!value) return Types.Primitive;
if (typeof value.then === 'function') return Types.Promise;
if (isReadableStream(value)) return value._readableState.objectMode ? Types.ReadableObject : Types.ReadableString;
if (Array.isArray(value)) return Types.Array;
if (typeof value === 'object' || value instanceof Object) return Types.Object;
return Types.Primitive;
}
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, a => {
const c = meta[a];
return typeof c === 'string' ? c : `\\u${a.charCodeAt(0).toString(16).padStart(4, '0')}`;
});
}
let primitiveToJSON;
if (((_global = global) === null || _global === void 0 ? void 0 : (_global$JSON = _global.JSON) === null || _global$JSON === void 0 ? void 0 : _global$JSON.stringify) instanceof Function) {
try {
if (JSON.stringify(global.BigInt ? global.BigInt('123') : '') !== '123') throw new Error();
primitiveToJSON = JSON.stringify;
} catch (err) {
// Add support for bigint for primitiveToJSON
// eslint-disable-next-line no-confusing-arrow
primitiveToJSON = value => typeof value === 'bigint' ? String(value) : JSON.stringify(value);
}
} else {
primitiveToJSON = value => {
switch (typeof value) {
case 'string':
return `"${escapeString(value)}"`;
case 'number':
return Number.isFinite(value) ? String(value) : 'null';
case 'bigint':
return String(value);
case 'boolean':
return value ? 'true' : 'false';
case 'object':
if (!value) {
return 'null';
}
// 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(`Not a primitive "${typeof value}".`), {
value
});
}
};
}
/*
function quoteString(string: string) {
return primitiveToJSON(String(string));
}
*/
const cache = new Map();
function quoteString(string) {
const useCache = string.length < 10000; // eslint-disable-next-line no-lonely-if
if (useCache && cache.has(string)) {
return cache.get(string);
}
const str = primitiveToJSON(String(string));
if (useCache) cache.set(string, str);
return str;
}
function readAsPromised(stream, size) {
var _stream$_readableStat;
const value = stream.read(size);
if (value === null && !(stream.readableEnded || (_stream$_readableStat = stream._readableState) !== null && _stream$_readableStat !== void 0 && _stream$_readableStat.ended)) {
return new Promise((resolve, reject) => {
const endListener = () => resolve(null);
stream.once('end', endListener);
stream.once('error', reject);
stream.once('readable', () => {
stream.removeListener('end', endListener);
stream.removeListener('error', reject);
readAsPromised(stream, size).then(resolve, reject);
});
});
}
return Promise.resolve(value);
}
var ReadState;
(function (ReadState) {
ReadState[ReadState["Inactive"] = 0] = "Inactive";
ReadState[ReadState["Reading"] = 1] = "Reading";
ReadState[ReadState["ReadMore"] = 2] = "ReadMore";
ReadState[ReadState["Consumed"] = 3] = "Consumed";
})(ReadState || (ReadState = {}));
class JsonStreamStringify extends stream.Readable {
constructor(input, replacer, spaces, cycle = false, bufferSize = 512) {
super({
encoding: 'utf8'
});
_defineProperty__default["default"](this, "cycle", void 0);
_defineProperty__default["default"](this, "bufferSize", void 0);
_defineProperty__default["default"](this, "item", void 0);
_defineProperty__default["default"](this, "indent", void 0);
_defineProperty__default["default"](this, "root", void 0);
_defineProperty__default["default"](this, "include", void 0);
_defineProperty__default["default"](this, "replacer", void 0);
_defineProperty__default["default"](this, "visited", void 0);
_defineProperty__default["default"](this, "objectItem", void 0);
_defineProperty__default["default"](this, "buffer", '');
_defineProperty__default["default"](this, "bufferLength", 0);
_defineProperty__default["default"](this, "pushCalled", false);
_defineProperty__default["default"](this, "readSize", 0);
_defineProperty__default["default"](this, "prePush", void 0);
_defineProperty__default["default"](this, "readState", ReadState.Inactive);
this.cycle = cycle;
this.bufferSize = bufferSize;
const spaceType = typeof spaces;
if (spaceType === 'number') {
this.indent = ' '.repeat(spaces);
} else if (spaceType === 'string') {
this.indent = spaces;
}
const replacerType = typeof replacer;
if (replacerType === 'object') {
this.include = replacer;
} else if (replacerType === 'function') {
this.replacer = replacer;
}
this.visited = cycle ? new WeakMap() : [];
this.root = {
value: {
'': input
},
depth: 0,
indent: '',
path: []
};
this.setItem(input, this.root, '');
}
setItem(value, parent, key = '') {
// call toJSON where applicable
if (value && typeof value === 'object' && typeof value.toJSON === 'function') {
value = value.toJSON(key);
} // use replacer if applicable
if (this.replacer) {
value = this.replacer.call(parent.value, key, value);
} // coerece functions and symbols into undefined
if (value instanceof Function || typeof value === 'symbol') {
value = undefined;
}
const type = getType(value);
let path; // check for circular structure
if (!this.cycle && type !== Types.Primitive) {
if (this.visited.some(v => v === value)) {
this.destroy(Object.assign(new Error('Converting circular structure to JSON'), {
value,
key
}));
return;
}
this.visited.push(value);
} else if (this.cycle && type !== Types.Primitive) {
path = this.visited.get(value);
if (path) {
this._push(`{"$ref":"$${path.map(v => `[${Number.isInteger(v) ? v : escapeString(quoteString(v))}]`).join('')}"}`);
this.item = parent;
return;
}
path = parent === this.root ? [] : parent.path.concat(key);
this.visited.set(value, path);
}
if (type === Types.Object) {
this.setObjectItem(value, parent);
} else if (type === Types.Array) {
this.setArrayItem(value, parent);
} else if (type === Types.Primitive) {
if (parent !== this.root && typeof key === 'string') {
// (<any>parent).write(key, primitiveToJSON(value));
if (value === undefined) ; else {
this._push(primitiveToJSON(value));
} // undefined values in objects should be rejected
} else if (value === undefined && typeof key === 'number') {
// undefined values in array should be null
this._push('null');
} else if (value === undefined) ; else {
this._push(primitiveToJSON(value));
}
this.item = parent;
return;
} else if (type === Types.Promise) {
this.setPromiseItem(value, parent, key);
} else if (type === Types.ReadableString) {
this.setReadableStringItem(value, parent);
} else if (type === Types.ReadableObject) {
this.setReadableObjectItem(value, parent);
}
this.item.value = value;
this.item.depth = parent.depth + 1;
if (this.indent) this.item.indent = this.indent.repeat(this.item.depth);
this.item.path = path;
}
setReadableStringItem(input, parent) {
var _input$_readableState, _input$_readableState2;
if (input.readableEnded || (_input$_readableState = input._readableState) !== null && _input$_readableState !== void 0 && _input$_readableState.endEmitted) {
this.emit('error', new Error('Readable Stream has ended before it was serialized. All stream data have been lost'), input, parent.path);
} else if (input.readableFlowing || (_input$_readableState2 = input._readableState) !== null && _input$_readableState2 !== void 0 && _input$_readableState2.flowing) {
input.pause();
this.emit('error', new Error('Readable Stream is in flowing mode, data may have been lost. Trying to pause stream.'), input, parent.path);
}
const that = this;
this.prePush = '"';
this.item = {
type: 'readable string',
async read(size) {
try {
const data = await readAsPromised(input, size);
if (data === null) {
that._push('"');
that.item = parent;
that.unvisit(input);
return;
}
if (data) that._push(escapeString(data.toString()));
} catch (err) {
that.emit('error', err);
that.destroy();
}
}
};
}
setReadableObjectItem(input, parent) {
var _input$_readableState3, _input$_readableState4;
if (input.readableEnded || (_input$_readableState3 = input._readableState) !== null && _input$_readableState3 !== void 0 && _input$_readableState3.endEmitted) {
this.emit('error', new Error('Readable Stream has ended before it was serialized. All stream data have been lost'), input, parent.path);
} else if (input.readableFlowing || (_input$_readableState4 = input._readableState) !== null && _input$_readableState4 !== void 0 && _input$_readableState4.flowing) {
input.pause();
this.emit('error', new Error('Readable Stream is in flowing mode, data may have been lost. Trying to pause stream.'), input, parent.path);
}
const that = this;
this._push('[');
let first = true;
let i = 0;
const item = {
type: 'readable object',
async read() {
try {
let out = '';
const data = await readAsPromised(input);
if (data === null) {
if (i && that.indent) {
out += `\n${parent.indent}`;
}
out += ']';
that._push(out);
that.item = parent;
that.unvisit(input);
return;
}
if (first) first = false;else out += ',';
if (that.indent) out += `\n${item.indent}`;
that.prePush = out;
that.setItem(data, item, i);
i += 1;
} catch (err) {
that.emit('error', err);
that.destroy();
}
}
};
this.item = item;
}
setPromiseItem(input, parent, key) {
const that = this;
let read = false;
this.item = {
async read() {
if (read) return;
try {
read = true;
that.setItem(await input, parent, key);
} catch (err) {
that.emit('error', err);
that.destroy();
}
}
};
}
setArrayItem(input, parent) {
// const entries = input.slice().reverse();
let i = 0;
const len = input.length;
let first = true;
const that = this;
const item = {
read() {
let out = '';
let wasFirst = false;
if (first) {
first = false;
wasFirst = true;
if (!len) {
that._push('[]');
that.unvisit(input);
that.item = parent;
return;
}
out += '[';
}
const entry = input[i];
if (i === len) {
if (that.indent) out += `\n${parent.indent}`;
out += ']';
that._push(out);
that.item = parent;
that.unvisit(input);
return;
}
if (!wasFirst) out += ',';
if (that.indent) out += `\n${item.indent}`;
that._push(out);
that.setItem(entry, item, i);
i += 1;
}
};
this.item = item;
}
unvisit(item) {
if (this.cycle) return;
const _i = this.visited.indexOf(item);
if (_i > -1) this.visited.splice(_i, 1);
}
setObjectItem(input, parent = undefined) {
const keys = Object.keys(input);
let i = 0;
const len = keys.length;
let first = true;
const that = this;
const {
include
} = this;
let hasItems = false;
let key;
const item = {
read() {
var _include$indexOf;
if (i === 0) that._push('{');
if (i === len) {
that.objectItem = undefined;
if (!hasItems) {
that._push('}');
} else {
that._push(`${that.indent ? `\n${parent.indent}` : ''}}`);
}
that.item = parent;
that.unvisit(input);
return;
}
key = keys[i];
if ((include === null || include === void 0 ? void 0 : (_include$indexOf = include.indexOf) === null || _include$indexOf === void 0 ? void 0 : _include$indexOf.call(include, key)) === -1) {
// replacer array excludes this key
i += 1;
return;
}
that.objectItem = item;
i += 1;
that.setItem(input[key], item, key);
},
write() {
const out = `${hasItems && !first ? ',' : ''}${item.indent ? `\n${item.indent}` : ''}${quoteString(key)}:${that.indent ? ' ' : ''}`;
first = false;
hasItems = true;
that.objectItem = undefined;
return out;
}
};
this.item = item;
}
_push(data) {
const out = (this.objectItem ? this.objectItem.write() : '') + data;
if (this.prePush && out.length) {
this.buffer += this.prePush;
this.prePush = undefined;
}
this.buffer += out;
if (this.buffer.length >= this.bufferSize) {
this.pushCalled = !this.push(this.buffer);
this.buffer = '';
this.bufferLength = 0;
return false;
}
return true;
}
async _read(size) {
if (this.readState === ReadState.Consumed) return;
if (this.readState !== ReadState.Inactive) {
this.readState = ReadState.ReadMore;
return;
}
this.readState = ReadState.Reading;
this.pushCalled = false;
let p;
while (!this.pushCalled && this.item !== this.root && this.buffer !== undefined) {
p = this.item.read(size); // eslint-disable-next-line no-await-in-loop
if (p) await p;
}
if (this.buffer === undefined) return;
if (this.item === this.root) {
if (this.buffer.length) this.push(this.buffer);
this.push(null);
this.readState = ReadState.Consumed;
this.cleanup();
return;
}
if (this.readState === ReadState.ReadMore) {
this.readState = ReadState.Inactive;
await this._read(size);
return;
}
this.readState = ReadState.Inactive;
}
cleanup() {
this.readState = ReadState.Consumed;
this.buffer = undefined;
this.visited = undefined;
this.item = undefined;
this.root = undefined;
this.prePush = undefined;
}
destroy(error) {
var _super$destroy;
if (error) this.emit('error', error);
(_super$destroy = super.destroy) === null || _super$destroy === void 0 ? void 0 : _super$destroy.call(this);
this.cleanup();
return this;
}
}
exports.JsonStreamStringify = JsonStreamStringify;
Object.defineProperty(exports, '__esModule', { value: true });
}));
//# sourceMappingURL=polyfill.js.map

File diff suppressed because one or more lines are too long

121
dev/env/node_modules/json-stream-stringify/package.json generated vendored Executable file
View File

@@ -0,0 +1,121 @@
{
"name": "json-stream-stringify",
"description": "JSON.Stringify as a readable stream",
"version": "3.1.6",
"license": "MIT",
"author": "Faleij <faleij@gmail.com> (https://github.com/faleij)",
"repository": {
"type": "git",
"url": "git+https://github.com/Faleij/json-stream-stringify.git"
},
"bugs": {
"url": "https://github.com/faleij/json-stream-stringify/issues"
},
"files": [
"lib/**/*"
],
"main": "./lib/cjs/index.js",
"module": "./lib/esm/index.mjs",
"umd:main": "./lib/umd/index.js",
"browser": "./lib/umd/index.js",
"types": "./lib/types/index.d.ts",
"nyc": {
"sourceMap": true,
"instrument": true,
"reporter": [
"lcov",
"text"
],
"extension": [
".ts"
],
"exclude": [
"**/*.d.ts",
"test-src/**/*"
]
},
"scripts": {
"lint": "eslint \"src/**/*.ts\" && echo ✅ eslint passed",
"build": "node --max-old-space-size=8192 node_modules/rollup/dist/bin/rollup -c rollup.config.js",
"build:watch": "npm run build -- --watch",
"test": "node node_modules/mocha/bin/mocha --require source-map-support/register -R spec -b \"test/*.spec.js\"",
"coverage": "node node_modules/nyc/bin/nyc.js npm test"
},
"devDependencies": {
"@babel/cli": "^7.18.9",
"@babel/core": "^7.18.9",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-transform-runtime": "^7.18.9",
"@babel/plugin-transform-typescript": "^7.18.8",
"@babel/preset-env": "^7.18.9",
"@babel/preset-typescript": "^7.18.6",
"@rollup/plugin-babel": "^5.3.1",
"@rollup/plugin-node-resolve": "^13.3.0",
"@types/expect.js": "^0.3.29",
"@types/mocha": "^9.1.1",
"@types/readable-stream": "^2.3.14",
"@typescript-eslint/eslint-plugin": "^5.31.0",
"core-js": "^3.24.0",
"coveralls": "3.1.1",
"es-check": "^7.0.0",
"eslint": "^8.20.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-plugin-import": "^2.26.0",
"expect.js": "0.3.1",
"mocha": "^10.2.0",
"nyc": "15.1.0",
"rollup": "2.77.0",
"rollup-plugin-dts": "^4.2.2",
"rollup-plugin-typescript2": "^0.32.1",
"source-map-support": "^0.5.21",
"typescript": "^4.7.4"
},
"volta": {
"node": "18.20.4"
},
"engines": {
"node": ">=7.10.1"
},
"exports": {
".": {
"types": "./lib/types/index.d.ts",
"import": "./lib/esm/index.mjs",
"require": "./lib/umd/index.js"
},
"./polyfill": {
"types": "./lib/types/index.d.ts",
"import": "./lib/esm/index.polyfill.mjs",
"require": "./lib/umd/polyfill.js"
},
"./esm/polyfill": {
"types": "./lib/types/index.d.ts",
"import": "./lib/esm/index.polyfill.mjs",
"require": "./lib/esm/index.polyfill.mjs"
},
"./esm": {
"types": "./lib/types/index.d.ts",
"import": "./lib/esm/index.mjs",
"require": "./lib/esm/index.mjs"
},
"./umd/polyfill": {
"types": "./lib/types/index.d.ts",
"import": "./lib/umd/polyfill.js",
"require": "./lib/umd/polyfill.js"
},
"./umd": {
"types": "./lib/types/index.d.ts",
"import": "./lib/umd/index.js",
"require": "./lib/umd/index.js"
},
"./cjs/polyfill": {
"types": "./lib/types/index.d.ts",
"import": "./lib/cjs/polyfill.js",
"require": "./lib/cjs/polyfill.js"
},
"./cjs": {
"types": "./lib/types/index.d.ts",
"import": "./lib/cjs/index.js",
"require": "./lib/cjs/index.js"
}
}
}