bfj 6.1.0 → 7.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc +2 -0
- package/.gitlab-ci.yml +25 -0
- package/AUTHORS +1 -1
- package/CONTRIBUTING.md +4 -4
- package/HISTORY.md +48 -0
- package/README.md +28 -19
- package/package.json +17 -17
- package/src/datastream.js +1 -1
- package/src/eventify.js +13 -6
- package/src/jsonstream.js +1 -1
- package/src/match.js +16 -0
- package/src/parse.js +2 -2
- package/src/read.js +1 -1
- package/src/unpipe.js +1 -1
- package/test/integration.js +6 -2
- package/test/unit/eventify.js +352 -73
- package/test/unit/match.js +140 -0
- package/test/unit/walk.js +114 -115
- package/.travis.yml +0 -12
package/.eslintrc
CHANGED
package/.gitlab-ci.yml
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
cache:
|
|
2
|
+
key: "$CI_JOB_NAME"
|
|
3
|
+
untracked: true
|
|
4
|
+
paths:
|
|
5
|
+
- node_modules/
|
|
6
|
+
|
|
7
|
+
before_script:
|
|
8
|
+
- npm install
|
|
9
|
+
|
|
10
|
+
.test_template: &npm_test
|
|
11
|
+
script:
|
|
12
|
+
- npm run lint
|
|
13
|
+
- npm test
|
|
14
|
+
|
|
15
|
+
test:node8:
|
|
16
|
+
image: node:8
|
|
17
|
+
<<: *npm_test
|
|
18
|
+
|
|
19
|
+
test:node10:
|
|
20
|
+
image: node:10
|
|
21
|
+
<<: *npm_test
|
|
22
|
+
|
|
23
|
+
test:node12:
|
|
24
|
+
image: node:12
|
|
25
|
+
<<: *npm_test
|
package/AUTHORS
CHANGED
package/CONTRIBUTING.md
CHANGED
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
if the change is one that you think
|
|
31
31
|
needs some discussion.
|
|
32
32
|
|
|
33
|
-
[readme]: https://
|
|
34
|
-
[authors]: https://
|
|
35
|
-
[newissue]: https://
|
|
36
|
-
[issues]: https://
|
|
33
|
+
[readme]: https://gitlab.com/philbooth/bfj/blob/master/README.md
|
|
34
|
+
[authors]: https://gitlab.com/philbooth/bfj/blob/master/AUTHORS
|
|
35
|
+
[newissue]: https://gitlab.com/philbooth/bfj/issues/new
|
|
36
|
+
[issues]: https://gitlab.com/philbooth/bfj/issues
|
|
37
37
|
|
package/HISTORY.md
CHANGED
|
@@ -1,5 +1,53 @@
|
|
|
1
1
|
# History
|
|
2
2
|
|
|
3
|
+
## 7.0.1
|
|
4
|
+
|
|
5
|
+
### Bug fixes
|
|
6
|
+
|
|
7
|
+
* match: prevent mismatched properties when minDepth is set (4efaf1a)
|
|
8
|
+
|
|
9
|
+
## 7.0.0
|
|
10
|
+
|
|
11
|
+
### Breaking changes
|
|
12
|
+
|
|
13
|
+
* package: limit to node 8+ (cc42139)
|
|
14
|
+
|
|
15
|
+
### New features
|
|
16
|
+
|
|
17
|
+
* match: support minDepth option to improve performance (6d79fe4)
|
|
18
|
+
|
|
19
|
+
### Refactorings
|
|
20
|
+
|
|
21
|
+
* code: prefer spread syntax to Object.assign (5544086)
|
|
22
|
+
* code: prefer Object.entries to iterate keys and values (d101317)
|
|
23
|
+
|
|
24
|
+
### Other changes
|
|
25
|
+
|
|
26
|
+
* package: test in node 12 (9bf4e6b)
|
|
27
|
+
* git: ignore test/*.json (e87eaf7)
|
|
28
|
+
|
|
29
|
+
## 6.1.2
|
|
30
|
+
|
|
31
|
+
### Bug fixes
|
|
32
|
+
|
|
33
|
+
* eventify: escape object keys (910ad08)
|
|
34
|
+
|
|
35
|
+
### Other changes
|
|
36
|
+
|
|
37
|
+
* package: update deps (aafb4ff)
|
|
38
|
+
|
|
39
|
+
## 6.1.1
|
|
40
|
+
|
|
41
|
+
### Bug fixes
|
|
42
|
+
|
|
43
|
+
* eventify: don't serialise NaN or infinities (3c50fe4)
|
|
44
|
+
|
|
45
|
+
### Other changes
|
|
46
|
+
|
|
47
|
+
* deps: npm update (b3c86d0)
|
|
48
|
+
* project: add package lock file (63df27d)
|
|
49
|
+
* project: migrate to gitlab (26746a0)
|
|
50
|
+
|
|
3
51
|
## 6.1.0
|
|
4
52
|
|
|
5
53
|
### New features
|
package/README.md
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
# BFJ
|
|
2
2
|
|
|
3
|
-
[](https://gitlab.com/philbooth/bfj/pipelines)
|
|
4
|
+
[](https://www.npmjs.com/package/bfj)
|
|
5
|
+
[](https://www.npmjs.com/package/bfj)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
7
|
|
|
7
8
|
Big-Friendly JSON. Asynchronous streaming functions for large JSON data sets.
|
|
8
9
|
|
|
@@ -141,7 +142,7 @@ Or if you just want
|
|
|
141
142
|
the git repo:
|
|
142
143
|
|
|
143
144
|
```
|
|
144
|
-
git clone git@
|
|
145
|
+
git clone git@gitlab.com:philbooth/bfj.git
|
|
145
146
|
```
|
|
146
147
|
|
|
147
148
|
## How do I read a JSON file?
|
|
@@ -279,6 +280,17 @@ Predicate functions will be called with three arguments:
|
|
|
279
280
|
If the result of the predicate is a truthy value
|
|
280
281
|
then the item will be deemed a match.
|
|
281
282
|
|
|
283
|
+
In addition to the regular options
|
|
284
|
+
accepted by other parsing functions,
|
|
285
|
+
you can also specify `minDepth`
|
|
286
|
+
to only apply the selector
|
|
287
|
+
to certain depths.
|
|
288
|
+
This can improve performance
|
|
289
|
+
and memory usage,
|
|
290
|
+
if you know that
|
|
291
|
+
you're not interested in
|
|
292
|
+
parsing top-level items.
|
|
293
|
+
|
|
282
294
|
If there are any syntax errors in the JSON,
|
|
283
295
|
a `dataError` event will be emitted.
|
|
284
296
|
If any other errors occur,
|
|
@@ -920,21 +932,18 @@ with the command
|
|
|
920
932
|
|
|
921
933
|
## What versions of Node.js does it support?
|
|
922
934
|
|
|
923
|
-
As of [version `
|
|
935
|
+
As of [version `7.0.0`](HISTORY.md#700),
|
|
936
|
+
only Node.js versions 8 or greater
|
|
937
|
+
are supported.
|
|
938
|
+
|
|
939
|
+
Between versions [`3.0.0`](HISTORY.md#300)
|
|
940
|
+
and [`6.1.2`](HISTORY.md#612),
|
|
924
941
|
only Node.js versions 6 or greater
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
A separate `node-4` branch was maintained
|
|
932
|
-
until version `5.4.1`,
|
|
933
|
-
which had feature parity version-for-version
|
|
934
|
-
with releases from `master`.
|
|
935
|
-
Releases from the `node-4` branch
|
|
936
|
-
are available in npm
|
|
937
|
-
under the package name [`bfj-node4`](https://www.npmjs.com/package/bfj-node4).
|
|
942
|
+
were supported.
|
|
943
|
+
|
|
944
|
+
Until [version `2.1.2`](HISTORY.md#212),
|
|
945
|
+
only Node.js versions 4 or greater
|
|
946
|
+
were supported.
|
|
938
947
|
|
|
939
948
|
## What license is it released under?
|
|
940
949
|
|
|
@@ -958,5 +967,5 @@ under the package name [`bfj-node4`](https://www.npmjs.com/package/bfj-node4).
|
|
|
958
967
|
[mocha]: https://mochajs.org/
|
|
959
968
|
[chai]: http://chaijs.com/
|
|
960
969
|
[proxyquire]: https://github.com/thlorenz/proxyquire
|
|
961
|
-
[spooks]: https://
|
|
970
|
+
[spooks]: https://gitlab.com/philbooth/spooks.js
|
|
962
971
|
[license]: COPYING
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bfj",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.1",
|
|
4
4
|
"description": "Big-friendly JSON. Asynchronous streaming functions for large JSON data sets.",
|
|
5
|
-
"homepage": "https://
|
|
6
|
-
"bugs": "https://
|
|
5
|
+
"homepage": "https://gitlab.com/philbooth/bfj",
|
|
6
|
+
"bugs": "https://gitlab.com/philbooth/bfj/issues",
|
|
7
7
|
"license": "MIT",
|
|
8
|
-
"author": "Phil Booth (https://
|
|
8
|
+
"author": "Phil Booth (https://gitlab.com/philbooth)",
|
|
9
9
|
"main": "./src",
|
|
10
10
|
"keywords": [
|
|
11
11
|
"json",
|
|
@@ -23,25 +23,25 @@
|
|
|
23
23
|
],
|
|
24
24
|
"repository": {
|
|
25
25
|
"type": "git",
|
|
26
|
-
"url": "https://
|
|
26
|
+
"url": "https://gitlab.com/philbooth/bfj.git"
|
|
27
27
|
},
|
|
28
28
|
"engines": {
|
|
29
|
-
"node": ">=
|
|
29
|
+
"node": ">= 8.0.0"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"bluebird": "^3.5.
|
|
33
|
-
"check-types": "^
|
|
34
|
-
"hoopy": "^0.1.
|
|
35
|
-
"tryer": "^1.0.
|
|
32
|
+
"bluebird": "^3.5.5",
|
|
33
|
+
"check-types": "^8.0.3",
|
|
34
|
+
"hoopy": "^0.1.4",
|
|
35
|
+
"tryer": "^1.0.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
38
|
+
"chai": "^4.2.0",
|
|
39
|
+
"eslint": "^6.0.1",
|
|
40
|
+
"mocha": "^6.1.4",
|
|
41
|
+
"please-release-me": "^2.1.2",
|
|
42
|
+
"proxyquire": "^2.1.0",
|
|
43
|
+
"request": "^2.88.0",
|
|
44
|
+
"spooks": "^2.0.0"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
47
|
"lint": "eslint src",
|
package/src/datastream.js
CHANGED
package/src/eventify.js
CHANGED
|
@@ -110,7 +110,7 @@ function eventify (data, options = {}) {
|
|
|
110
110
|
})
|
|
111
111
|
|
|
112
112
|
function after (coerced) {
|
|
113
|
-
if (
|
|
113
|
+
if (isInvalid(coerced)) {
|
|
114
114
|
return
|
|
115
115
|
}
|
|
116
116
|
|
|
@@ -205,8 +205,15 @@ function eventify (data, options = {}) {
|
|
|
205
205
|
})
|
|
206
206
|
}
|
|
207
207
|
|
|
208
|
-
function
|
|
209
|
-
|
|
208
|
+
function isInvalid (datum) {
|
|
209
|
+
const type = typeof datum
|
|
210
|
+
return !! invalidTypes[type] || (
|
|
211
|
+
type === 'number' && ! isValidNumber(datum)
|
|
212
|
+
)
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function isValidNumber (datum) {
|
|
216
|
+
return datum > Number.NEGATIVE_INFINITY && datum < Number.POSITIVE_INFINITY
|
|
210
217
|
}
|
|
211
218
|
|
|
212
219
|
function literal (datum) {
|
|
@@ -232,7 +239,7 @@ function eventify (data, options = {}) {
|
|
|
232
239
|
function array (datum) {
|
|
233
240
|
// For an array, collection:object and collection:array are the same.
|
|
234
241
|
return collection(datum, datum, 'array', item => {
|
|
235
|
-
if (
|
|
242
|
+
if (isInvalid(item)) {
|
|
236
243
|
return proceed(null)
|
|
237
244
|
}
|
|
238
245
|
|
|
@@ -286,11 +293,11 @@ function eventify (data, options = {}) {
|
|
|
286
293
|
return collection(datum, Object.keys(datum), 'object', key => {
|
|
287
294
|
const item = datum[key]
|
|
288
295
|
|
|
289
|
-
if (
|
|
296
|
+
if (isInvalid(item)) {
|
|
290
297
|
return Promise.resolve()
|
|
291
298
|
}
|
|
292
299
|
|
|
293
|
-
return emit(events.property, key)
|
|
300
|
+
return emit(events.property, escapeString(key))
|
|
294
301
|
.then(() => proceed(item))
|
|
295
302
|
})
|
|
296
303
|
}
|
package/src/jsonstream.js
CHANGED
package/src/match.js
CHANGED
|
@@ -25,6 +25,11 @@ module.exports = match
|
|
|
25
25
|
* passed, both the key and the value are passed to it as
|
|
26
26
|
* arguments.
|
|
27
27
|
*
|
|
28
|
+
* @option minDepth: Number indicating the minimum depth to apply the selector
|
|
29
|
+
* to. The default is `0`, but setting it to a higher value
|
|
30
|
+
* can improve performance and reduce memory usage by
|
|
31
|
+
* eliminating the need to actualise top-level items.
|
|
32
|
+
*
|
|
28
33
|
* @option numbers: Boolean, indicating whether numerical keys (e.g. array
|
|
29
34
|
* indices) should be coerced to strings before testing the
|
|
30
35
|
* match. Only applies if the `selector` argument is a string
|
|
@@ -62,6 +67,9 @@ function match (stream, selector, options = {}) {
|
|
|
62
67
|
let length = 0
|
|
63
68
|
let index = 0
|
|
64
69
|
|
|
70
|
+
const minDepth = options.minDepth || 0
|
|
71
|
+
check.assert.greaterOrEqual(minDepth, 0)
|
|
72
|
+
|
|
65
73
|
if (check.function(selector)) {
|
|
66
74
|
selectorFunction = selector
|
|
67
75
|
selector = null
|
|
@@ -152,6 +160,10 @@ function match (stream, selector, options = {}) {
|
|
|
152
160
|
}
|
|
153
161
|
|
|
154
162
|
function property (name) {
|
|
163
|
+
if (scopes.length < minDepth) {
|
|
164
|
+
return
|
|
165
|
+
}
|
|
166
|
+
|
|
155
167
|
properties.push(name)
|
|
156
168
|
}
|
|
157
169
|
|
|
@@ -162,6 +174,10 @@ function match (stream, selector, options = {}) {
|
|
|
162
174
|
function value (v) {
|
|
163
175
|
let key
|
|
164
176
|
|
|
177
|
+
if (scopes.length < minDepth) {
|
|
178
|
+
return
|
|
179
|
+
}
|
|
180
|
+
|
|
165
181
|
if (scopes.length > 0) {
|
|
166
182
|
const scope = scopes[scopes.length - 1]
|
|
167
183
|
|
package/src/parse.js
CHANGED
|
@@ -161,8 +161,8 @@ function parse (stream, options = {}) {
|
|
|
161
161
|
|
|
162
162
|
function transform (obj, key) {
|
|
163
163
|
if (obj && typeof obj === 'object') {
|
|
164
|
-
Object.
|
|
165
|
-
obj[
|
|
164
|
+
Object.entries(obj).forEach(([ k, v ]) => {
|
|
165
|
+
obj[k] = transform(v, k)
|
|
166
166
|
})
|
|
167
167
|
}
|
|
168
168
|
|
package/src/read.js
CHANGED
|
@@ -22,5 +22,5 @@ module.exports = read
|
|
|
22
22
|
* @option Promise: The promise constructor to use, defaults to bluebird.
|
|
23
23
|
**/
|
|
24
24
|
function read (path, options) {
|
|
25
|
-
return parse(fs.createReadStream(path, options),
|
|
25
|
+
return parse(fs.createReadStream(path, options), { ...options, ndjson: false })
|
|
26
26
|
}
|
package/src/unpipe.js
CHANGED
|
@@ -29,7 +29,7 @@ function unpipe (callback, options) {
|
|
|
29
29
|
|
|
30
30
|
const jsonstream = new stream.PassThrough()
|
|
31
31
|
|
|
32
|
-
parse(jsonstream,
|
|
32
|
+
parse(jsonstream, { ...options, ndjson: false })
|
|
33
33
|
.then(data => callback(null, data))
|
|
34
34
|
.catch(error => callback(error))
|
|
35
35
|
|
package/test/integration.js
CHANGED
|
@@ -229,7 +229,11 @@ suite('integration:', () => {
|
|
|
229
229
|
}))
|
|
230
230
|
results = []
|
|
231
231
|
errors = []
|
|
232
|
-
const datastream = bfj.match(
|
|
232
|
+
const datastream = bfj.match(
|
|
233
|
+
fs.createReadStream(file),
|
|
234
|
+
(k, v) => k === 'baz' || v === 'blee',
|
|
235
|
+
{ minDepth: 1 }
|
|
236
|
+
)
|
|
233
237
|
datastream.on('data', item => results.push(item))
|
|
234
238
|
datastream.on('error', error => errors.push(error))
|
|
235
239
|
datastream.on('end', done)
|
|
@@ -305,7 +309,7 @@ suite('integration:', () => {
|
|
|
305
309
|
|
|
306
310
|
setup(done => {
|
|
307
311
|
const jsonstream = new stream.PassThrough()
|
|
308
|
-
request({ url: 'https://
|
|
312
|
+
request({ url: 'https://gitlab.com/philbooth/bfj/raw/master/package.json' })
|
|
309
313
|
.pipe(bfj.unpipe((err, res) => {
|
|
310
314
|
error = err
|
|
311
315
|
result = res
|