barnard59-base 3.0.0 → 3.1.0
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/CHANGELOG.md +18 -0
- package/filter.js +1 -1
- package/forEach.js +2 -1
- package/glob.js +4 -2
- package/json.js +12 -2
- package/limit.js +3 -2
- package/manifest.ttl +7 -0
- package/map.js +5 -4
- package/offset.js +1 -1
- package/package.json +10 -8
- package/skills/barnard59-base/SKILL.md +90 -0
- package/test/Readable.test.js +2 -2
- package/test/batch.test.js +6 -6
- package/test/concat.test.js +13 -13
- package/test/filter.test.js +5 -4
- package/test/flatten.test.js +12 -11
- package/test/glob.test.js +7 -7
- package/test/json.test.js +25 -0
- package/test/limit.test.js +3 -3
- package/test/map.test.js +12 -11
- package/test/offset.test.js +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# barnard59-base
|
|
2
2
|
|
|
3
|
+
## 3.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#416](https://github.com/zazuko/barnard59/pull/416) [`e12fa2b`](https://github.com/zazuko/barnard59/commit/e12fa2bba0d1c7385473b2a33a54ff1590bdf85a) - Add the `json/parse/document` operation and the `parseDocument` JavaScript export for parsing a complete JSON document from a stream, including documents split across chunks.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- [#415](https://github.com/zazuko/barnard59/pull/415) [`2228ea1`](https://github.com/zazuko/barnard59/commit/2228ea1790ac6b988c6dbcfba4fd4f38e1c6e486) - build(deps): bump glob from 13.0.6 to 14.0.2
|
|
12
|
+
|
|
13
|
+
- [#416](https://github.com/zazuko/barnard59/pull/416) [`f9b9f9e`](https://github.com/zazuko/barnard59/commit/f9b9f9e23b70aa4af2254f2f308246cee0639904) - Add the `barnard59-base` skill for composing and transforming pipeline streams with mapping, filtering, batching, and other base operations.
|
|
14
|
+
|
|
15
|
+
## 3.0.1
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- [#408](https://github.com/zazuko/barnard59/pull/408) [`2359425`](https://github.com/zazuko/barnard59/commit/23594250599bbde63503ae8c0895405df669c922) Thanks [@tpluscode](https://github.com/tpluscode)! - Set the required node version to `>=16.18` in `engines`
|
|
20
|
+
|
|
3
21
|
## 3.0.0
|
|
4
22
|
|
|
5
23
|
### Major Changes
|
package/filter.js
CHANGED
|
@@ -18,7 +18,7 @@ function filter(func, ...args) {
|
|
|
18
18
|
return obj((chunk, encoding, callback) => {
|
|
19
19
|
Promise.resolve().then(() => {
|
|
20
20
|
return func.call(this, chunk, encoding, ...args)
|
|
21
|
-
}).then(result => {
|
|
21
|
+
}).then((result) => {
|
|
22
22
|
if (result) {
|
|
23
23
|
return callback(null, chunk)
|
|
24
24
|
}
|
package/forEach.js
CHANGED
|
@@ -86,7 +86,8 @@ class ForEach extends stream.Duplex {
|
|
|
86
86
|
this.pull = null
|
|
87
87
|
|
|
88
88
|
return callback()
|
|
89
|
-
}
|
|
89
|
+
}
|
|
90
|
+
catch (/** @type {any} */ cause) {
|
|
90
91
|
const err = new Error(`error in forEach sub-pipeline ${this.ptr.value}`)
|
|
91
92
|
|
|
92
93
|
err.stack += `\nCaused by: ${cause.stack}`
|
package/glob.js
CHANGED
|
@@ -42,11 +42,13 @@ function glob({ pattern, ...options }) {
|
|
|
42
42
|
|
|
43
43
|
// @ts-ignore
|
|
44
44
|
stream._read()
|
|
45
|
-
}
|
|
45
|
+
}
|
|
46
|
+
catch (/** @type {any} */ err) {
|
|
46
47
|
span.recordException(err)
|
|
47
48
|
span.setStatus({ code: SpanStatusCode.ERROR, message: err.message })
|
|
48
49
|
stream.destroy(err)
|
|
49
|
-
}
|
|
50
|
+
}
|
|
51
|
+
finally {
|
|
50
52
|
span.end()
|
|
51
53
|
}
|
|
52
54
|
},
|
package/json.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Transform } from 'node:stream'
|
|
1
|
+
import { Duplex, Transform } from 'node:stream'
|
|
2
|
+
import { json } from 'node:stream/consumers'
|
|
2
3
|
|
|
3
4
|
class JsonParse extends Transform {
|
|
4
5
|
constructor() {
|
|
@@ -43,6 +44,15 @@ function parse() {
|
|
|
43
44
|
return new JsonParse()
|
|
44
45
|
}
|
|
45
46
|
|
|
47
|
+
function parseDocument() {
|
|
48
|
+
return Duplex.from(async function* (chunks) {
|
|
49
|
+
const value = await json(chunks)
|
|
50
|
+
if (value !== null) {
|
|
51
|
+
yield value
|
|
52
|
+
}
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
|
|
46
56
|
/**
|
|
47
57
|
* @return {Transform}
|
|
48
58
|
*/
|
|
@@ -50,4 +60,4 @@ function stringify() {
|
|
|
50
60
|
return new JsonStringify()
|
|
51
61
|
}
|
|
52
62
|
|
|
53
|
-
export { parse, stringify }
|
|
63
|
+
export { parse, parseDocument, stringify }
|
package/limit.js
CHANGED
|
@@ -6,13 +6,14 @@ export default function limit(limit) {
|
|
|
6
6
|
/**
|
|
7
7
|
* @param {AsyncIterable<*>} stream
|
|
8
8
|
*/
|
|
9
|
-
return async function
|
|
9
|
+
return async function* (stream) {
|
|
10
10
|
let count = 0
|
|
11
11
|
for await (const chunk of stream) {
|
|
12
12
|
count++
|
|
13
13
|
if (count <= limit) {
|
|
14
14
|
yield chunk
|
|
15
|
-
}
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
16
17
|
break
|
|
17
18
|
}
|
|
18
19
|
}
|
package/manifest.ttl
CHANGED
|
@@ -73,6 +73,13 @@
|
|
|
73
73
|
code:link <node:barnard59-base/json.js#stringify>
|
|
74
74
|
].
|
|
75
75
|
|
|
76
|
+
<json/parse/document> a p:Operation, p:Writable, p:ReadableObjectMode;
|
|
77
|
+
rdfs:label "Parse JSON document";
|
|
78
|
+
rdfs:comment "Reads the input stream as one JSON document and emits the parsed value.";
|
|
79
|
+
code:implementedBy [ a code:EcmaScriptModule;
|
|
80
|
+
code:link <node:barnard59-base/json.js#parseDocument>
|
|
81
|
+
].
|
|
82
|
+
|
|
76
83
|
<limit> a p:Operation, p:WritableObjectMode, p:ReadableObjectMode;
|
|
77
84
|
rdfs:label "Limit";
|
|
78
85
|
rdfs:comment "Limits the amount of forwarded chunks and discards any chunks after reaching the limit.";
|
package/map.js
CHANGED
|
@@ -37,7 +37,8 @@ export default function map(options, ...args) {
|
|
|
37
37
|
let objectMode = true
|
|
38
38
|
if (typeof options === 'function') {
|
|
39
39
|
func = options
|
|
40
|
-
}
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
41
42
|
func = options.map
|
|
42
43
|
concurrency = options.concurrency || concurrency
|
|
43
44
|
ordered = typeof options.ordered === 'boolean' ? options.ordered : ordered
|
|
@@ -47,8 +48,8 @@ export default function map(options, ...args) {
|
|
|
47
48
|
return transform(concurrency, { ordered, objectMode }, (data, callback) => {
|
|
48
49
|
Promise.resolve().then(() => {
|
|
49
50
|
return func.call(this, data, ...args)
|
|
50
|
-
}).then(result => {
|
|
51
|
-
callback(null, result)
|
|
52
|
-
}).catch(callback)
|
|
51
|
+
}).then((result) => {
|
|
52
|
+
return setImmediate(() => callback(null, result))
|
|
53
|
+
}).catch(err => setImmediate(() => callback(err, null)))
|
|
53
54
|
})
|
|
54
55
|
}
|
package/offset.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "barnard59-base",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Linked Data pipelines",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@opentelemetry/api": "^1.9.1",
|
|
27
27
|
"duplexify": "^4.1.1",
|
|
28
|
-
"glob": "^
|
|
28
|
+
"glob": "^14.0.2",
|
|
29
29
|
"onetime": "^6.0.0",
|
|
30
30
|
"parallel-transform": "^1.2.0",
|
|
31
31
|
"readable-to-readable": "^0.1.3",
|
|
@@ -36,19 +36,21 @@
|
|
|
36
36
|
"@types/parallel-transform": "^1.1.4",
|
|
37
37
|
"@types/readable-to-readable": "^0.1.0",
|
|
38
38
|
"@types/through2": "^2.0.41",
|
|
39
|
-
"barnard59-core": "^7.0.
|
|
40
|
-
"chai": "^
|
|
39
|
+
"barnard59-core": "^7.0.1",
|
|
40
|
+
"chai": "^6.3.0",
|
|
41
41
|
"get-stream": "^6.0.1",
|
|
42
42
|
"into-stream": "^7.0.0",
|
|
43
43
|
"is-stream": "^3.0.0",
|
|
44
44
|
"rimraf": "^6.1.3",
|
|
45
|
-
"sinon": "^
|
|
45
|
+
"sinon": "^19"
|
|
46
46
|
},
|
|
47
47
|
"engines": {
|
|
48
|
-
"node": ">=
|
|
48
|
+
"node": ">= 16.8"
|
|
49
49
|
},
|
|
50
50
|
"mocha": {
|
|
51
|
-
"require":
|
|
52
|
-
|
|
51
|
+
"require": [
|
|
52
|
+
"tsx",
|
|
53
|
+
"../../test/mocha-setup.js"
|
|
54
|
+
]
|
|
53
55
|
}
|
|
54
56
|
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: barnard59-base
|
|
3
|
+
description: Use when composing or transforming Barnard59 streams with mapping, filtering, batching, flattening, JSON chunks, standard I/O, globbing, or nested pipelines.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Base stream steps
|
|
7
|
+
|
|
8
|
+
Declare `@prefix op: <https://barnard59.zazuko.com/operations/> .` at the top of your Turtle file. In `p:stepList`, write `[ op:base\/batch (10) ]` to group incoming chunks into batches of ten.
|
|
9
|
+
|
|
10
|
+
For an explicit `p:Step`, link to the JavaScript export with `code:link`. For example, the link for `batch` is `<node:barnard59-base/batch.js#default>`. The other module paths below follow the same pattern.
|
|
11
|
+
|
|
12
|
+
## `streamValues`
|
|
13
|
+
|
|
14
|
+
`Readable.js#from` takes each positional argument as a separate value and emits it as one object-mode chunk. Use `[ op:base\/streamValues ("first" "second") ]` for a fixed list of work items or a small fixture. Passing a list as a single argument emits that list as one chunk.
|
|
15
|
+
|
|
16
|
+
## `glob`
|
|
17
|
+
|
|
18
|
+
`glob.js#default` takes named `pattern` and optional glob settings such as `cwd` and `nodir`. It emits one matched path string per object-mode chunk. Relative patterns start at the working directory unless you set `cwd`. Use `nodir true` for file readers and pass the results to `barnard59-rdf`'s `fs.js#parse` or a `forEach` subpipeline to open the matches.
|
|
19
|
+
|
|
20
|
+
## `stdin`
|
|
21
|
+
|
|
22
|
+
`process.js#stdin` takes no arguments and returns the byte stream from standard input. Put it first when the CLI should accept redirected files or input from a shell pipe. Add a parser when downstream steps expect objects or quads.
|
|
23
|
+
|
|
24
|
+
## `stdout`
|
|
25
|
+
|
|
26
|
+
`process.js#stdout` takes no arguments. It writes incoming bytes to stdout and forwards those bytes downstream. Use it when a pipeline explicitly needs that side effect. A readable CLI pipeline already prints its output by default, so including this step in that path can print the same bytes twice.
|
|
27
|
+
|
|
28
|
+
## `map`
|
|
29
|
+
|
|
30
|
+
`map.js#default` takes a function as the first positional argument or named options with a `map` function. The callback receives `(chunk, ...args)` and may return a value or a promise. Use a regular function to access the pipeline context through `this`.
|
|
31
|
+
|
|
32
|
+
The default is object mode, concurrency `1`, and ordered output. Raise `concurrency` for independent asynchronous work. Set `ordered false` only when downstream steps can accept completion order. In programmatic calls, additional arguments follow the callback or options object.
|
|
33
|
+
|
|
34
|
+
## `filter`
|
|
35
|
+
|
|
36
|
+
`filter.js#default` takes a predicate followed by any additional positional arguments. It calls `predicate(chunk, encoding, ...args)` in the pipeline context and awaits the result. A truthy result forwards the original object-mode chunk. Use `map` when the operation needs to change the chunk as well.
|
|
37
|
+
|
|
38
|
+
## `limit`
|
|
39
|
+
|
|
40
|
+
`limit.js#default` takes a positional chunk count and emits up to the first N chunks. Place it before expensive work to sample a stream or after `filter` to keep the first N matches. It counts the chunks at that point in the pipeline, so a batch counts as one chunk.
|
|
41
|
+
|
|
42
|
+
## `offset`
|
|
43
|
+
|
|
44
|
+
`offset.js#default` takes a positional chunk count and discards the first N chunks before forwarding the remainder. Pair it with `limit` after a source with a stable order for a repeatable slice.
|
|
45
|
+
|
|
46
|
+
## `batch`
|
|
47
|
+
|
|
48
|
+
`batch.js#default` takes a positional size and groups object-mode input into arrays of that size. It emits the final partial array at end of input. A size of `0`, the default, collects all input into one array, so use it for bounded input. Choose boundaries that keep related quads together when batch contents affect query or validation results.
|
|
49
|
+
|
|
50
|
+
## `flatten`
|
|
51
|
+
|
|
52
|
+
`flatten.js#default` takes no arguments. Each chunk must be iterable or implement `forEach`. The step emits its members individually in object mode and expands one level. Place it between dataset or array output and a step that expects one RDF/JS quad per chunk.
|
|
53
|
+
|
|
54
|
+
## `concat`
|
|
55
|
+
|
|
56
|
+
`concat.js#default` takes readable streams as separate positional arguments. It drains them in argument order and exposes one byte stream without inserting separators. For example, `[ op:base\/concat (ex:header ex:body) ]` can join two byte-producing subpipelines.
|
|
57
|
+
|
|
58
|
+
## `concat/object`
|
|
59
|
+
|
|
60
|
+
`concat.js#object` takes the same positional stream arguments and emits their chunks sequentially in object mode. Use it to join quad streams, records, or dataset chunks. Each input chunk is forwarded unchanged, including a grouped dataset.
|
|
61
|
+
|
|
62
|
+
## `combine`
|
|
63
|
+
|
|
64
|
+
`combine.js#default` takes a nonempty array of streams and an optional duplex-options object. It pipes each stream into the next and exposes the first stream's writable side and the last stream's readable side as one duplex. Supply `objectMode` or side-specific stream options when needed. Use `concat` to drain independent sources in sequence.
|
|
65
|
+
|
|
66
|
+
## `forEach`
|
|
67
|
+
|
|
68
|
+
`forEach.js#default` takes a nested pipeline and an optional variable name as positional arguments. It creates a new pipeline for each object-mode input chunk. The nested pipeline inherits the caller's variables, and the named variable receives the current chunk. If the nested pipeline is writable, the chunk is also sent to its input. Its readable output is forwarded before work starts on the next chunk.
|
|
69
|
+
|
|
70
|
+
Define `ex:readOne` as a `p:Pipeline`, then use `[ op:base\/forEach (ex:readOne "filename") ]` after `glob` to open each path through a fresh nested pipeline.
|
|
71
|
+
|
|
72
|
+
## `json/parse`
|
|
73
|
+
|
|
74
|
+
`json.js#parse` takes no arguments. It parses each byte chunk as one complete JSON value and emits the result in object mode.
|
|
75
|
+
|
|
76
|
+
## `json/parse/document`
|
|
77
|
+
|
|
78
|
+
`json.js#parseDocument` takes no arguments. Use `[ op:base\/json\/parse\/document () ]` after a file or HTTP source that yields one bounded JSON document across arbitrary byte chunks. It buffers the stream, then parses the document and emits its value in object mode. A top-level JSON null emits no chunk.
|
|
79
|
+
|
|
80
|
+
## `json/stringify`
|
|
81
|
+
|
|
82
|
+
`json.js#stringify` takes no arguments and emits the JSON serialization of each object-mode chunk as bytes. It adds neither newlines nor array framing. Supply framing separately for JSON Lines or a single JSON document with several values.
|
|
83
|
+
|
|
84
|
+
## `toString`
|
|
85
|
+
|
|
86
|
+
`toString.js#default` takes no arguments. It calls `toString()` on each object-mode input chunk and exposes a byte-mode readable side. Use this for text representations the object already defines. Use `json/stringify` or an RDF serializer when the downstream format requires structured encoding.
|
|
87
|
+
|
|
88
|
+
## `nul`
|
|
89
|
+
|
|
90
|
+
`dev-nul.js#default` takes no arguments and consumes object-mode chunks without producing output. Use it as a terminal sink when upstream work should run to completion and its output can be discarded.
|
package/test/Readable.test.js
CHANGED
|
@@ -4,8 +4,8 @@ import getStream from 'get-stream'
|
|
|
4
4
|
import { expect } from 'chai'
|
|
5
5
|
import * as Readable from '../Readable.js'
|
|
6
6
|
|
|
7
|
-
describe('Readable', ()
|
|
8
|
-
it('should return a readable stream', async ()
|
|
7
|
+
describe('Readable', function () {
|
|
8
|
+
it('should return a readable stream', async function () {
|
|
9
9
|
// given
|
|
10
10
|
const stream = Readable.from(0, 1, 2, 3, 4)
|
|
11
11
|
|
package/test/batch.test.js
CHANGED
|
@@ -4,19 +4,19 @@ import { array } from 'get-stream'
|
|
|
4
4
|
import { isReadableStream as isReadable, isWritableStream as isWritable } from 'is-stream'
|
|
5
5
|
import batch from '../batch.js'
|
|
6
6
|
|
|
7
|
-
describe('batch', ()
|
|
8
|
-
it('should be a function', ()
|
|
7
|
+
describe('batch', function () {
|
|
8
|
+
it('should be a function', function () {
|
|
9
9
|
strictEqual(typeof batch, 'function')
|
|
10
10
|
})
|
|
11
11
|
|
|
12
|
-
it('should return a duplex stream', async ()
|
|
12
|
+
it('should return a duplex stream', async function () {
|
|
13
13
|
const result = batch()
|
|
14
14
|
|
|
15
15
|
strictEqual(isWritable(result), true)
|
|
16
16
|
strictEqual(isReadable(result), true)
|
|
17
17
|
})
|
|
18
18
|
|
|
19
|
-
it('should do nothing if there are no input chunks', async ()
|
|
19
|
+
it('should do nothing if there are no input chunks', async function () {
|
|
20
20
|
const input = Readable({
|
|
21
21
|
objectMode: true,
|
|
22
22
|
read: () => {
|
|
@@ -29,7 +29,7 @@ describe('batch', () => {
|
|
|
29
29
|
deepStrictEqual(result, [])
|
|
30
30
|
})
|
|
31
31
|
|
|
32
|
-
it('should split input in batches', async ()
|
|
32
|
+
it('should split input in batches', async function () {
|
|
33
33
|
const expected = [['a', 'b'], ['c', 'd'], ['e']]
|
|
34
34
|
const input = Readable({
|
|
35
35
|
objectMode: true,
|
|
@@ -43,7 +43,7 @@ describe('batch', () => {
|
|
|
43
43
|
deepStrictEqual(result, expected)
|
|
44
44
|
})
|
|
45
45
|
|
|
46
|
-
it('should emit a single batch', async ()
|
|
46
|
+
it('should emit a single batch', async function () {
|
|
47
47
|
const expected = [['a', 'b', 'c', 'd', 'e']]
|
|
48
48
|
const input = Readable({
|
|
49
49
|
objectMode: true,
|
package/test/concat.test.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { deepStrictEqual, strictEqual, rejects } from 'assert'
|
|
1
|
+
import { deepStrictEqual, strictEqual, rejects } from 'node:assert'
|
|
2
2
|
import { Readable } from 'node:stream'
|
|
3
3
|
import getStream, { array } from 'get-stream'
|
|
4
4
|
import { isReadableStream as isReadable, isWritableStream as isWritable } from 'is-stream'
|
|
5
5
|
import concat, { object } from '../concat.js'
|
|
6
6
|
|
|
7
|
-
describe('concat', ()
|
|
8
|
-
it('should be a function', ()
|
|
7
|
+
describe('concat', function () {
|
|
8
|
+
it('should be a function', function () {
|
|
9
9
|
strictEqual(typeof concat, 'function')
|
|
10
10
|
})
|
|
11
11
|
|
|
12
|
-
it('should return a Readable', ()
|
|
12
|
+
it('should return a Readable', function () {
|
|
13
13
|
const s = concat(new Readable({ read: () => {} }))
|
|
14
14
|
|
|
15
15
|
strictEqual(isReadable(s), true)
|
|
16
16
|
strictEqual(isWritable(s), false)
|
|
17
17
|
})
|
|
18
18
|
|
|
19
|
-
it('should process one stream after another', async ()
|
|
19
|
+
it('should process one stream after another', async function () {
|
|
20
20
|
let end0 = null
|
|
21
21
|
let start1 = null
|
|
22
22
|
|
|
@@ -43,7 +43,7 @@ describe('concat', () => {
|
|
|
43
43
|
strictEqual(end0 <= start1, true)
|
|
44
44
|
})
|
|
45
45
|
|
|
46
|
-
it('should emit chunks from all streams in order', async ()
|
|
46
|
+
it('should emit chunks from all streams in order', async function () {
|
|
47
47
|
const stream0 = new Readable({
|
|
48
48
|
read: () => {
|
|
49
49
|
stream0.push('a')
|
|
@@ -67,7 +67,7 @@ describe('concat', () => {
|
|
|
67
67
|
strictEqual(result, 'abcd')
|
|
68
68
|
})
|
|
69
69
|
|
|
70
|
-
it('should forward error events', async ()
|
|
70
|
+
it('should forward error events', async function () {
|
|
71
71
|
const stream0 = new Readable({
|
|
72
72
|
read: () => {
|
|
73
73
|
stream0.destroy(new Error('test'))
|
|
@@ -87,19 +87,19 @@ describe('concat', () => {
|
|
|
87
87
|
await rejects(() => getStream(s))
|
|
88
88
|
})
|
|
89
89
|
|
|
90
|
-
describe('object', ()
|
|
91
|
-
it('should be a function', ()
|
|
90
|
+
describe('object', function () {
|
|
91
|
+
it('should be a function', function () {
|
|
92
92
|
strictEqual(typeof object, 'function')
|
|
93
93
|
})
|
|
94
94
|
|
|
95
|
-
it('should return a Readable', ()
|
|
95
|
+
it('should return a Readable', function () {
|
|
96
96
|
const s = object(new Readable({ read: () => {} }))
|
|
97
97
|
|
|
98
98
|
strictEqual(isReadable(s), true)
|
|
99
99
|
strictEqual(isWritable(s), false)
|
|
100
100
|
})
|
|
101
101
|
|
|
102
|
-
it('should process one stream after another', async ()
|
|
102
|
+
it('should process one stream after another', async function () {
|
|
103
103
|
let end0 = null
|
|
104
104
|
let start1 = null
|
|
105
105
|
|
|
@@ -126,7 +126,7 @@ describe('concat', () => {
|
|
|
126
126
|
strictEqual(end0 <= start1, true)
|
|
127
127
|
})
|
|
128
128
|
|
|
129
|
-
it('should emit chunks from all streams in order', async ()
|
|
129
|
+
it('should emit chunks from all streams in order', async function () {
|
|
130
130
|
const stream0 = new Readable({
|
|
131
131
|
objectMode: true,
|
|
132
132
|
read: () => {
|
|
@@ -152,7 +152,7 @@ describe('concat', () => {
|
|
|
152
152
|
deepStrictEqual(result, ['a', 'b', 'c', 'd'])
|
|
153
153
|
})
|
|
154
154
|
|
|
155
|
-
it('should forward error events', async ()
|
|
155
|
+
it('should forward error events', async function () {
|
|
156
156
|
const stream0 = new Readable({
|
|
157
157
|
objectMode: true,
|
|
158
158
|
read: () => {
|
package/test/filter.test.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable mocha/no-nested-tests */
|
|
2
|
+
import { deepStrictEqual } from 'node:assert'
|
|
2
3
|
import { Readable } from 'node:stream'
|
|
3
4
|
import { array } from 'get-stream'
|
|
4
5
|
import filter from '../filter.js'
|
|
5
6
|
|
|
6
|
-
describe('filter', ()
|
|
7
|
-
it('should pass pipeline context to callback function', async ()
|
|
7
|
+
describe('filter', function () {
|
|
8
|
+
it('should pass pipeline context to callback function', async function () {
|
|
8
9
|
// given
|
|
9
10
|
const input = new Readable({
|
|
10
11
|
objectMode: true,
|
|
@@ -28,7 +29,7 @@ describe('filter', () => {
|
|
|
28
29
|
deepStrictEqual(output, ['a'])
|
|
29
30
|
})
|
|
30
31
|
|
|
31
|
-
it('should pass additional arguments to callback function', async ()
|
|
32
|
+
it('should pass additional arguments to callback function', async function () {
|
|
32
33
|
// given
|
|
33
34
|
const input = new Readable({
|
|
34
35
|
objectMode: true,
|
package/test/flatten.test.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { deepStrictEqual, strictEqual } from 'assert'
|
|
1
|
+
import { deepStrictEqual, strictEqual } from 'node:assert'
|
|
2
2
|
import { Readable } from 'node:stream'
|
|
3
3
|
import { array } from 'get-stream'
|
|
4
4
|
import { isReadableStream as isReadable, isWritableStream as isWritable } from 'is-stream'
|
|
5
5
|
import flatten from '../flatten.js'
|
|
6
6
|
|
|
7
|
-
describe('flatten', ()
|
|
8
|
-
it('should be a function', ()
|
|
7
|
+
describe('flatten', function () {
|
|
8
|
+
it('should be a function', function () {
|
|
9
9
|
strictEqual(typeof flatten, 'function')
|
|
10
10
|
})
|
|
11
11
|
|
|
12
|
-
it('should return a duplex stream', async ()
|
|
12
|
+
it('should return a duplex stream', async function () {
|
|
13
13
|
const result = flatten()
|
|
14
14
|
|
|
15
15
|
strictEqual(isWritable(result), true)
|
|
16
16
|
strictEqual(isReadable(result), true)
|
|
17
17
|
})
|
|
18
18
|
|
|
19
|
-
it('should do nothing if there are no input chunks', async ()
|
|
19
|
+
it('should do nothing if there are no input chunks', async function () {
|
|
20
20
|
const input = Readable({
|
|
21
21
|
objectMode: true,
|
|
22
22
|
read: () => {
|
|
@@ -29,8 +29,8 @@ describe('flatten', () => {
|
|
|
29
29
|
deepStrictEqual(result, [])
|
|
30
30
|
})
|
|
31
31
|
|
|
32
|
-
it('should flatten object with a iterator interface', async ()
|
|
33
|
-
const toIterator = input => {
|
|
32
|
+
it('should flatten object with a iterator interface', async function () {
|
|
33
|
+
const toIterator = (input) => {
|
|
34
34
|
return {
|
|
35
35
|
[Symbol.iterator]: input[Symbol.iterator].bind(input),
|
|
36
36
|
}
|
|
@@ -50,8 +50,8 @@ describe('flatten', () => {
|
|
|
50
50
|
deepStrictEqual(result, expected)
|
|
51
51
|
})
|
|
52
52
|
|
|
53
|
-
it('should flatten object with a forEach method', async ()
|
|
54
|
-
const toForEach = input => {
|
|
53
|
+
it('should flatten object with a forEach method', async function () {
|
|
54
|
+
const toForEach = (input) => {
|
|
55
55
|
return {
|
|
56
56
|
forEach: input.forEach.bind(input),
|
|
57
57
|
}
|
|
@@ -71,7 +71,7 @@ describe('flatten', () => {
|
|
|
71
71
|
deepStrictEqual(result, expected)
|
|
72
72
|
})
|
|
73
73
|
|
|
74
|
-
it('should emit an error if the chunks don\'t implement Symbol.iterator or .forEach', async ()
|
|
74
|
+
it('should emit an error if the chunks don\'t implement Symbol.iterator or .forEach', async function () {
|
|
75
75
|
let error = null
|
|
76
76
|
const input = Readable({
|
|
77
77
|
objectMode: true,
|
|
@@ -83,7 +83,8 @@ describe('flatten', () => {
|
|
|
83
83
|
|
|
84
84
|
try {
|
|
85
85
|
await array(input.pipe(flatten()))
|
|
86
|
-
}
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
87
88
|
error = err
|
|
88
89
|
}
|
|
89
90
|
|
package/test/glob.test.js
CHANGED
|
@@ -4,10 +4,10 @@ import sinon from 'sinon'
|
|
|
4
4
|
import { expect } from 'chai'
|
|
5
5
|
import glob from '../glob.js'
|
|
6
6
|
|
|
7
|
-
describe('glob', ()
|
|
7
|
+
describe('glob', function () {
|
|
8
8
|
let logger
|
|
9
9
|
|
|
10
|
-
beforeEach(()
|
|
10
|
+
beforeEach(function () {
|
|
11
11
|
logger = {
|
|
12
12
|
debug: sinon.spy(),
|
|
13
13
|
info: sinon.spy(),
|
|
@@ -18,14 +18,14 @@ describe('glob', () => {
|
|
|
18
18
|
}
|
|
19
19
|
})
|
|
20
20
|
|
|
21
|
-
it('should return a Readable stream', ()
|
|
21
|
+
it('should return a Readable stream', function () {
|
|
22
22
|
const s = glob.call({ logger }, { pattern: 'test/support/*' })
|
|
23
23
|
|
|
24
24
|
expect(isReadable(s)).to.be.true
|
|
25
25
|
expect(isWritable(s)).to.be.false
|
|
26
26
|
})
|
|
27
27
|
|
|
28
|
-
it('should emit each file name as a chunk', async ()
|
|
28
|
+
it('should emit each file name as a chunk', async function () {
|
|
29
29
|
const s = glob.call({ logger }, { pattern: '../../test/e2e/definitions/foreach/*' })
|
|
30
30
|
|
|
31
31
|
const filenames = await array(s)
|
|
@@ -37,7 +37,7 @@ describe('glob', () => {
|
|
|
37
37
|
])
|
|
38
38
|
})
|
|
39
39
|
|
|
40
|
-
it('should forward additional options', async ()
|
|
40
|
+
it('should forward additional options', async function () {
|
|
41
41
|
const s = glob.call({ logger }, {
|
|
42
42
|
cwd: '../../test/e2e/definitions/foreach',
|
|
43
43
|
pattern: '*',
|
|
@@ -52,7 +52,7 @@ describe('glob', () => {
|
|
|
52
52
|
])
|
|
53
53
|
})
|
|
54
54
|
|
|
55
|
-
it('should warn when no files are matched', async ()
|
|
55
|
+
it('should warn when no files are matched', async function () {
|
|
56
56
|
const s = glob.call({ logger }, {
|
|
57
57
|
cwd: '../../test/e2e/definitions/foreach',
|
|
58
58
|
pattern: 'foobar',
|
|
@@ -63,7 +63,7 @@ describe('glob', () => {
|
|
|
63
63
|
expect(logger.warn).to.have.been.called
|
|
64
64
|
})
|
|
65
65
|
|
|
66
|
-
it('should not warn files have been matched', async ()
|
|
66
|
+
it('should not warn files have been matched', async function () {
|
|
67
67
|
const s = glob.call({ logger }, {
|
|
68
68
|
cwd: '../../test/e2e/definitions/foreach',
|
|
69
69
|
pattern: '*',
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Readable } from 'node:stream'
|
|
2
|
+
import { pipeline } from 'node:stream/promises'
|
|
3
|
+
import { deepStrictEqual, rejects } from 'node:assert/strict'
|
|
4
|
+
import getStream from 'get-stream'
|
|
5
|
+
import { parseDocument } from '../json.js'
|
|
6
|
+
|
|
7
|
+
describe('json/parse/document', function () {
|
|
8
|
+
it('parses one document across chunk and UTF-8 character boundaries', async function () {
|
|
9
|
+
const input = Buffer.from('{"city":"Łódź"}')
|
|
10
|
+
const split = input.indexOf(Buffer.from('Ł')) + 1
|
|
11
|
+
const values = await pipeline(Readable.from([input.subarray(0, split), input.subarray(split)]), parseDocument(), stream => getStream.array(stream))
|
|
12
|
+
|
|
13
|
+
deepStrictEqual(values, [{ city: 'Łódź' }])
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
it('rejects a truncated document', async function () {
|
|
17
|
+
await rejects(pipeline(Readable.from(['{"city":']), parseDocument(), stream => getStream.array(stream)), SyntaxError)
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it('treats a top-level null as no output, like the chunk parser', async function () {
|
|
21
|
+
const values = await pipeline(Readable.from(['null']), parseDocument(), stream => getStream.array(stream))
|
|
22
|
+
|
|
23
|
+
deepStrictEqual(values, [])
|
|
24
|
+
})
|
|
25
|
+
})
|
package/test/limit.test.js
CHANGED
|
@@ -3,14 +3,14 @@ import { expect } from 'chai'
|
|
|
3
3
|
import getStream from 'get-stream'
|
|
4
4
|
import limit from '../limit.js'
|
|
5
5
|
|
|
6
|
-
describe('limit', ()
|
|
7
|
-
it('should return generator', ()
|
|
6
|
+
describe('limit', function () {
|
|
7
|
+
it('should return generator', function () {
|
|
8
8
|
const step = limit(1)
|
|
9
9
|
|
|
10
10
|
expect(step).to.be.instanceOf(Function)
|
|
11
11
|
})
|
|
12
12
|
|
|
13
|
-
it('stop processing chunks when limit is reached', async ()
|
|
13
|
+
it('stop processing chunks when limit is reached', async function () {
|
|
14
14
|
// given
|
|
15
15
|
const step = limit(1)
|
|
16
16
|
|
package/test/map.test.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable mocha/no-nested-tests */
|
|
2
|
+
import { deepStrictEqual } from 'node:assert'
|
|
2
3
|
import { Readable } from 'node:stream'
|
|
3
4
|
import getStream, { array } from 'get-stream'
|
|
4
5
|
import intoStream from 'into-stream'
|
|
5
6
|
import map from '../map.js'
|
|
6
7
|
|
|
7
|
-
describe('map', ()
|
|
8
|
-
it('should pass pipeline context to mapper function', async ()
|
|
8
|
+
describe('map', function () {
|
|
9
|
+
it('should pass pipeline context to mapper function', async function () {
|
|
9
10
|
const input = new Readable({
|
|
10
11
|
read: () => {
|
|
11
12
|
input.push('a')
|
|
@@ -25,7 +26,7 @@ describe('map', () => {
|
|
|
25
26
|
deepStrictEqual(output, ['foo_a', 'foo_b'])
|
|
26
27
|
})
|
|
27
28
|
|
|
28
|
-
it('should pass optional arguments to mapper function', async ()
|
|
29
|
+
it('should pass optional arguments to mapper function', async function () {
|
|
29
30
|
const input = new Readable({
|
|
30
31
|
read: () => {
|
|
31
32
|
input.push('a')
|
|
@@ -41,7 +42,7 @@ describe('map', () => {
|
|
|
41
42
|
deepStrictEqual(output, ['foo_a', 'foo_b'])
|
|
42
43
|
})
|
|
43
44
|
|
|
44
|
-
it('should pass optional arguments to mapper function when used with options object', async ()
|
|
45
|
+
it('should pass optional arguments to mapper function when used with options object', async function () {
|
|
45
46
|
const input = new Readable({
|
|
46
47
|
read: () => {
|
|
47
48
|
input.push('a')
|
|
@@ -59,7 +60,7 @@ describe('map', () => {
|
|
|
59
60
|
deepStrictEqual(output, ['foo_a', 'foo_b'])
|
|
60
61
|
})
|
|
61
62
|
|
|
62
|
-
it('accepts a function as parameter', async ()
|
|
63
|
+
it('accepts a function as parameter', async function () {
|
|
63
64
|
// given
|
|
64
65
|
const transform = letter => letter.toUpperCase()
|
|
65
66
|
const input = intoStream.object(['a', 'b', 'c'])
|
|
@@ -71,7 +72,7 @@ describe('map', () => {
|
|
|
71
72
|
deepStrictEqual(result, 'ABC')
|
|
72
73
|
})
|
|
73
74
|
|
|
74
|
-
it('binds pipeline context to transform function', async ()
|
|
75
|
+
it('binds pipeline context to transform function', async function () {
|
|
75
76
|
// const
|
|
76
77
|
function transform(letter) {
|
|
77
78
|
return letter + this.suffix
|
|
@@ -86,9 +87,9 @@ describe('map', () => {
|
|
|
86
87
|
deepStrictEqual(result, 'AxBxCx')
|
|
87
88
|
})
|
|
88
89
|
|
|
89
|
-
it('accepts an option to not retain order', async ()
|
|
90
|
+
it('accepts an option to not retain order', async function () {
|
|
90
91
|
// given
|
|
91
|
-
const transform = async letter => {
|
|
92
|
+
const transform = async (letter) => {
|
|
92
93
|
if (letter === 'a') {
|
|
93
94
|
await new Promise(resolve => setTimeout(resolve, 10))
|
|
94
95
|
}
|
|
@@ -108,9 +109,9 @@ describe('map', () => {
|
|
|
108
109
|
deepStrictEqual(result, 'BCA')
|
|
109
110
|
})
|
|
110
111
|
|
|
111
|
-
it('retains input order by default', async ()
|
|
112
|
+
it('retains input order by default', async function () {
|
|
112
113
|
// given
|
|
113
|
-
const transform = async letter => {
|
|
114
|
+
const transform = async (letter) => {
|
|
114
115
|
if (letter === 'a') {
|
|
115
116
|
await new Promise(resolve => setTimeout(resolve, 10))
|
|
116
117
|
}
|
package/test/offset.test.js
CHANGED
|
@@ -3,14 +3,14 @@ import { expect } from 'chai'
|
|
|
3
3
|
import getStream from 'get-stream'
|
|
4
4
|
import offset from '../offset.js'
|
|
5
5
|
|
|
6
|
-
describe('offset', ()
|
|
7
|
-
it('should return generator', ()
|
|
6
|
+
describe('offset', function () {
|
|
7
|
+
it('should return generator', function () {
|
|
8
8
|
const step = offset(1)
|
|
9
9
|
|
|
10
10
|
expect(step).to.be.instanceOf(Function)
|
|
11
11
|
})
|
|
12
12
|
|
|
13
|
-
it('stop processing chunks when limit is reached', async ()
|
|
13
|
+
it('stop processing chunks when limit is reached', async function () {
|
|
14
14
|
// given
|
|
15
15
|
const step = offset(2)
|
|
16
16
|
|