barnard59-base 1.2.0-pmap.0 → 1.2.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/CHANGELOG.md +8 -2
- package/combine.js +1 -1
- package/concat.js +4 -4
- package/filter.js +1 -1
- package/flatten.js +1 -1
- package/forEach.js +8 -8
- package/glob.js +4 -4
- package/json.js +8 -8
- package/limit.js +1 -1
- package/map.js +1 -1
- package/nul.js +3 -3
- package/offset.js +1 -1
- package/package.json +9 -12
- package/stdout.js +2 -2
- package/test/concat.test.js +12 -13
- package/test/flatten.test.js +6 -7
- package/test/glob.test.js +9 -10
- package/test/map.test.js +5 -6
- package/toReadable.js +4 -4
- package/toString.js +4 -4
- package/.changeset/README.md +0 -8
- package/.changeset/breezy-yaks-happen.md +0 -5
- package/.changeset/config.json +0 -11
- package/.changeset/pre.json +0 -10
- package/.editorconfig +0 -3
- package/.github/workflows/add-to-backlog.yml +0 -18
- package/.github/workflows/ci.yaml +0 -29
- package/.github/workflows/release.yaml +0 -34
- package/test/forEach.e2e.test.js +0 -44
- package/test/support/data/test.csv +0 -12
- package/test/support/definitions/e2e/foreach-csv-duplicate.ttl +0 -46
- package/test/support/definitions/e2e/foreach-with-handler.ttl +0 -38
- package/test/support/definitions/e2e/foreach-with-variable.ttl +0 -42
- package/test/support/loadPipelineDefinition.js +0 -15
- package/test/support/namespaces.js +0 -7
- package/test/support/operations/duplicate.js +0 -22
- package/test/support/operations/inlineTransform.js +0 -21
- package/test/support/operations/iterateDirectory.js +0 -30
- package/test/support/operations/parseCsv.js +0 -49
- package/test/support/operations/serializeJson.js +0 -37
package/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
# v1.0.0
|
|
2
2
|
|
|
3
|
-
## 1.2.
|
|
3
|
+
## 1.2.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 4bbf8f2: Added missing dependency on `readable-to-readable`, and replaced `lodash/once.js` with `onetime` (also missing as dependency)
|
|
8
|
+
|
|
9
|
+
## 1.2.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
|
6
12
|
|
|
7
|
-
- 2c4af8f: Use [parallel-transform](https://npm.im/parallel-transform) to implement the map step
|
|
13
|
+
- 2c4af8f: Use [parallel-transform](https://npm.im/parallel-transform) to implement the map step (closes #10)
|
|
8
14
|
|
|
9
15
|
- Moved to JavaScript modules
|
package/combine.js
CHANGED
package/concat.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { finished, Readable } from 'readable-stream'
|
|
2
2
|
|
|
3
3
|
class ConcatStream extends Readable {
|
|
4
|
-
constructor
|
|
4
|
+
constructor(streams, { objectMode = false } = {}) {
|
|
5
5
|
super({ objectMode })
|
|
6
6
|
|
|
7
7
|
this.streams = streams
|
|
@@ -10,7 +10,7 @@ class ConcatStream extends Readable {
|
|
|
10
10
|
this.next()
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
_read
|
|
13
|
+
_read() {
|
|
14
14
|
if (!this.current) {
|
|
15
15
|
return this.push(null)
|
|
16
16
|
}
|
|
@@ -26,7 +26,7 @@ class ConcatStream extends Readable {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
next
|
|
29
|
+
next() {
|
|
30
30
|
this.current = this.streams.shift()
|
|
31
31
|
|
|
32
32
|
if (this.current) {
|
|
@@ -37,7 +37,7 @@ class ConcatStream extends Readable {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
function factory
|
|
40
|
+
function factory(...streams) {
|
|
41
41
|
return new ConcatStream(streams)
|
|
42
42
|
}
|
|
43
43
|
|
package/filter.js
CHANGED
package/flatten.js
CHANGED
package/forEach.js
CHANGED
|
@@ -5,12 +5,12 @@ import ReadableToReadable from 'readable-to-readable'
|
|
|
5
5
|
|
|
6
6
|
const { finished, Duplex } = stream
|
|
7
7
|
|
|
8
|
-
async function nextLoop
|
|
8
|
+
async function nextLoop() {
|
|
9
9
|
return new Promise(resolve => setTimeout(resolve, 0))
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
class ForEach extends Duplex {
|
|
13
|
-
constructor
|
|
13
|
+
constructor({ createPipeline, pipeline, step, variable, variables }) {
|
|
14
14
|
super({ objectMode: true })
|
|
15
15
|
|
|
16
16
|
// Bind the read and write function to the current context so the trace ID
|
|
@@ -31,15 +31,15 @@ class ForEach extends Duplex {
|
|
|
31
31
|
this.pull = null
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
get subPipeline
|
|
34
|
+
get subPipeline() {
|
|
35
35
|
return this.step.children[0]
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
set subPipeline
|
|
38
|
+
set subPipeline(subPipeline) {
|
|
39
39
|
this.step.children[0] = subPipeline
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
async _write
|
|
42
|
+
async _write(chunk, encoding, callback) {
|
|
43
43
|
try {
|
|
44
44
|
const variables = new Map(this.variables)
|
|
45
45
|
|
|
@@ -69,7 +69,7 @@ class ForEach extends Duplex {
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
async _read
|
|
72
|
+
async _read() {
|
|
73
73
|
if (this._writableState.finished) {
|
|
74
74
|
return this.push(null)
|
|
75
75
|
}
|
|
@@ -84,13 +84,13 @@ class ForEach extends Duplex {
|
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
function factory
|
|
87
|
+
function factory(pipeline, variable) {
|
|
88
88
|
return new ForEach({
|
|
89
89
|
pipeline,
|
|
90
90
|
createPipeline: this.createPipeline,
|
|
91
91
|
step: this.step,
|
|
92
92
|
variable,
|
|
93
|
-
variables: this.variables
|
|
93
|
+
variables: this.variables,
|
|
94
94
|
})
|
|
95
95
|
}
|
|
96
96
|
|
package/glob.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { promisify } from 'util'
|
|
2
2
|
import { SpanStatusCode } from '@opentelemetry/api'
|
|
3
3
|
import globFn from 'glob'
|
|
4
|
-
import
|
|
4
|
+
import onetime from 'onetime'
|
|
5
5
|
import { Readable } from 'readable-stream'
|
|
6
6
|
import tracer from './lib/tracer.js'
|
|
7
7
|
|
|
8
|
-
function glob
|
|
8
|
+
function glob({ pattern, ...options }) {
|
|
9
9
|
let filenames = null
|
|
10
10
|
|
|
11
11
|
const span = tracer.startSpan('glob')
|
|
12
12
|
|
|
13
|
-
const init =
|
|
13
|
+
const init = onetime(async () => {
|
|
14
14
|
span.addEvent('init')
|
|
15
15
|
filenames = await promisify(globFn)(pattern, options)
|
|
16
16
|
})
|
|
@@ -37,7 +37,7 @@ function glob ({ pattern, ...options }) {
|
|
|
37
37
|
} finally {
|
|
38
38
|
span.end()
|
|
39
39
|
}
|
|
40
|
-
}
|
|
40
|
+
},
|
|
41
41
|
})
|
|
42
42
|
|
|
43
43
|
return stream
|
package/json.js
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
1
|
import { Transform } from 'readable-stream'
|
|
2
2
|
|
|
3
3
|
class JsonParse extends Transform {
|
|
4
|
-
constructor
|
|
4
|
+
constructor() {
|
|
5
5
|
super({
|
|
6
6
|
writableObjectMode: false,
|
|
7
|
-
readableObjectMode: true
|
|
7
|
+
readableObjectMode: true,
|
|
8
8
|
})
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
_transform
|
|
11
|
+
_transform(chunk, encoding, callback) {
|
|
12
12
|
callback(null, JSON.parse(chunk.toString()))
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
class JsonStringify extends Transform {
|
|
17
|
-
constructor
|
|
17
|
+
constructor() {
|
|
18
18
|
super({
|
|
19
19
|
writableObjectMode: true,
|
|
20
|
-
readableObjectMode: false
|
|
20
|
+
readableObjectMode: false,
|
|
21
21
|
})
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
_transform
|
|
24
|
+
_transform(chunk, encoding, callback) {
|
|
25
25
|
callback(null, JSON.stringify(chunk))
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
function parse
|
|
29
|
+
function parse() {
|
|
30
30
|
return new JsonParse()
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
function stringify
|
|
33
|
+
function stringify() {
|
|
34
34
|
return new JsonStringify()
|
|
35
35
|
}
|
|
36
36
|
|
package/limit.js
CHANGED
|
@@ -5,7 +5,7 @@ import { obj } from 'through2'
|
|
|
5
5
|
* @param {number} limit Limit the amount of chunks passed through the pipe.
|
|
6
6
|
* @memberof module:barnard59
|
|
7
7
|
*/
|
|
8
|
-
function limit
|
|
8
|
+
function limit(limit) {
|
|
9
9
|
const t = obj(function (chunk, encoding, callback) {
|
|
10
10
|
t.count++
|
|
11
11
|
|
package/map.js
CHANGED
|
@@ -10,7 +10,7 @@ import transform from 'parallel-transform'
|
|
|
10
10
|
* @param {Boolean} [options.objectMode=true] Option to transform chunks in object mode
|
|
11
11
|
* @return {ReadableStream}
|
|
12
12
|
*/
|
|
13
|
-
export default function map
|
|
13
|
+
export default function map(options) {
|
|
14
14
|
let func
|
|
15
15
|
let concurrency = 1
|
|
16
16
|
let ordered = true
|
package/nul.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { Writable } from 'readable-stream'
|
|
2
2
|
|
|
3
3
|
class Nul extends Writable {
|
|
4
|
-
constructor
|
|
4
|
+
constructor() {
|
|
5
5
|
super({ objectMode: true })
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
_write
|
|
8
|
+
_write(chunk, encoding, callback) {
|
|
9
9
|
callback()
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
function factory
|
|
13
|
+
function factory() {
|
|
14
14
|
return new Nul()
|
|
15
15
|
}
|
|
16
16
|
|
package/offset.js
CHANGED
package/package.json
CHANGED
|
@@ -1,43 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "barnard59-base",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Linked Data pipelines",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"
|
|
9
|
-
"test": "c8 --reporter=lcov --reporter=text mocha",
|
|
10
|
-
"release": "changeset publish"
|
|
8
|
+
"test": "mocha"
|
|
11
9
|
},
|
|
12
10
|
"repository": {
|
|
13
11
|
"type": "git",
|
|
14
|
-
"url": "git://github.com/zazuko/barnard59
|
|
12
|
+
"url": "git://github.com/zazuko/barnard59.git",
|
|
13
|
+
"directory": "packages/base"
|
|
15
14
|
},
|
|
16
15
|
"keywords": [],
|
|
17
16
|
"author": "Thomas Bergwinkl <bergi@axolotlfarm.org> (https://www.bergnet.org/people/bergi/card#me)",
|
|
18
17
|
"license": "MIT",
|
|
19
18
|
"bugs": {
|
|
20
|
-
"url": "https://github.com/zazuko/barnard59
|
|
19
|
+
"url": "https://github.com/zazuko/barnard59/issues"
|
|
21
20
|
},
|
|
22
|
-
"homepage": "https://github.com/zazuko/barnard59
|
|
21
|
+
"homepage": "https://github.com/zazuko/barnard59",
|
|
23
22
|
"dependencies": {
|
|
24
23
|
"@opentelemetry/api": "^1.0.1",
|
|
25
24
|
"duplexify": "^4.1.1",
|
|
26
25
|
"glob": "^7.1.7",
|
|
26
|
+
"onetime": "^6.0.0",
|
|
27
27
|
"parallel-transform": "^1.2.0",
|
|
28
28
|
"readable-stream": "^3.0.6",
|
|
29
|
+
"readable-to-readable": "^0.1.3",
|
|
29
30
|
"through2": "^4.0.2"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
|
-
"@changesets/cli": "^2.26.1",
|
|
33
|
-
"barnard59-core": "^1.0.0",
|
|
34
|
-
"c8": "^7.7.3",
|
|
35
33
|
"get-stream": "^6.0.1",
|
|
36
34
|
"into-stream": "^7.0.0",
|
|
37
35
|
"isstream": "^0.1.2",
|
|
38
36
|
"mocha": "^9.0.1",
|
|
39
|
-
"rdf-utils-fs": "^2.1.0"
|
|
40
|
-
"stricter-standard": "^0.2.0"
|
|
37
|
+
"rdf-utils-fs": "^2.1.0"
|
|
41
38
|
},
|
|
42
39
|
"engines": {
|
|
43
40
|
"node": ">= 14.0.0"
|
package/stdout.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Transform } from 'readable-stream'
|
|
2
2
|
|
|
3
3
|
class StdOut extends Transform {
|
|
4
|
-
_transform
|
|
4
|
+
_transform(chunk, encoding, callback) {
|
|
5
5
|
process.stdout.write(chunk, encoding)
|
|
6
6
|
|
|
7
7
|
callback(null, chunk)
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
function factory
|
|
11
|
+
function factory() {
|
|
12
12
|
return new StdOut()
|
|
13
13
|
}
|
|
14
14
|
|
package/test/concat.test.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { deepStrictEqual, strictEqual, rejects } from 'assert'
|
|
2
2
|
import getStream, { array } from 'get-stream'
|
|
3
3
|
import { isReadable, isWritable } from 'isstream'
|
|
4
|
-
import { describe, it } from 'mocha'
|
|
5
4
|
import { Readable } from 'readable-stream'
|
|
6
5
|
import concat, { object } from '../concat.js'
|
|
7
6
|
|
|
@@ -27,14 +26,14 @@ describe('concat', () => {
|
|
|
27
26
|
end0 = Date.now()
|
|
28
27
|
stream0.push(null)
|
|
29
28
|
}, 50)
|
|
30
|
-
}
|
|
29
|
+
},
|
|
31
30
|
})
|
|
32
31
|
|
|
33
32
|
const stream1 = new Readable({
|
|
34
33
|
read: () => {
|
|
35
34
|
start1 = Date.now()
|
|
36
35
|
stream1.push(null)
|
|
37
|
-
}
|
|
36
|
+
},
|
|
38
37
|
})
|
|
39
38
|
|
|
40
39
|
const s = concat(stream0, stream1)
|
|
@@ -50,7 +49,7 @@ describe('concat', () => {
|
|
|
50
49
|
stream0.push('a')
|
|
51
50
|
stream0.push('b')
|
|
52
51
|
stream0.push(null)
|
|
53
|
-
}
|
|
52
|
+
},
|
|
54
53
|
})
|
|
55
54
|
|
|
56
55
|
const stream1 = new Readable({
|
|
@@ -58,7 +57,7 @@ describe('concat', () => {
|
|
|
58
57
|
stream1.push('c')
|
|
59
58
|
stream1.push('d')
|
|
60
59
|
stream1.push(null)
|
|
61
|
-
}
|
|
60
|
+
},
|
|
62
61
|
})
|
|
63
62
|
|
|
64
63
|
const s = concat(stream0, stream1)
|
|
@@ -72,7 +71,7 @@ describe('concat', () => {
|
|
|
72
71
|
const stream0 = new Readable({
|
|
73
72
|
read: () => {
|
|
74
73
|
stream0.destroy(new Error('test'))
|
|
75
|
-
}
|
|
74
|
+
},
|
|
76
75
|
})
|
|
77
76
|
|
|
78
77
|
const stream1 = new Readable({
|
|
@@ -80,7 +79,7 @@ describe('concat', () => {
|
|
|
80
79
|
stream1.push('c')
|
|
81
80
|
stream1.push('d')
|
|
82
81
|
stream1.push(null)
|
|
83
|
-
}
|
|
82
|
+
},
|
|
84
83
|
})
|
|
85
84
|
|
|
86
85
|
const s = concat(stream0, stream1)
|
|
@@ -110,14 +109,14 @@ describe('concat', () => {
|
|
|
110
109
|
end0 = Date.now()
|
|
111
110
|
stream0.push(null)
|
|
112
111
|
}, 50)
|
|
113
|
-
}
|
|
112
|
+
},
|
|
114
113
|
})
|
|
115
114
|
|
|
116
115
|
const stream1 = new Readable({
|
|
117
116
|
read: () => {
|
|
118
117
|
start1 = Date.now()
|
|
119
118
|
stream1.push(null)
|
|
120
|
-
}
|
|
119
|
+
},
|
|
121
120
|
})
|
|
122
121
|
|
|
123
122
|
const s = object(stream0, stream1)
|
|
@@ -134,7 +133,7 @@ describe('concat', () => {
|
|
|
134
133
|
stream0.push('a')
|
|
135
134
|
stream0.push('b')
|
|
136
135
|
stream0.push(null)
|
|
137
|
-
}
|
|
136
|
+
},
|
|
138
137
|
})
|
|
139
138
|
|
|
140
139
|
const stream1 = new Readable({
|
|
@@ -143,7 +142,7 @@ describe('concat', () => {
|
|
|
143
142
|
stream1.push('c')
|
|
144
143
|
stream1.push('d')
|
|
145
144
|
stream1.push(null)
|
|
146
|
-
}
|
|
145
|
+
},
|
|
147
146
|
})
|
|
148
147
|
|
|
149
148
|
const s = object(stream0, stream1)
|
|
@@ -158,7 +157,7 @@ describe('concat', () => {
|
|
|
158
157
|
objectMode: true,
|
|
159
158
|
read: () => {
|
|
160
159
|
stream0.destroy(new Error('test'))
|
|
161
|
-
}
|
|
160
|
+
},
|
|
162
161
|
})
|
|
163
162
|
|
|
164
163
|
const stream1 = new Readable({
|
|
@@ -167,7 +166,7 @@ describe('concat', () => {
|
|
|
167
166
|
stream1.push('c')
|
|
168
167
|
stream1.push('d')
|
|
169
168
|
stream1.push(null)
|
|
170
|
-
}
|
|
169
|
+
},
|
|
171
170
|
})
|
|
172
171
|
|
|
173
172
|
const s = object(stream0, stream1)
|
package/test/flatten.test.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { deepStrictEqual, strictEqual } from 'assert'
|
|
2
2
|
import { array } from 'get-stream'
|
|
3
3
|
import { isReadable, isWritable } from 'isstream'
|
|
4
|
-
import { describe, it } from 'mocha'
|
|
5
4
|
import { Readable } from 'readable-stream'
|
|
6
5
|
import flatten from '../flatten.js'
|
|
7
6
|
|
|
@@ -22,7 +21,7 @@ describe('flatten', () => {
|
|
|
22
21
|
objectMode: true,
|
|
23
22
|
read: () => {
|
|
24
23
|
input.push(null)
|
|
25
|
-
}
|
|
24
|
+
},
|
|
26
25
|
})
|
|
27
26
|
|
|
28
27
|
const result = await array(input.pipe(flatten()))
|
|
@@ -33,7 +32,7 @@ describe('flatten', () => {
|
|
|
33
32
|
it('should flatten object with a iterator interface', async () => {
|
|
34
33
|
const toIterator = input => {
|
|
35
34
|
return {
|
|
36
|
-
[Symbol.iterator]: input[Symbol.iterator].bind(input)
|
|
35
|
+
[Symbol.iterator]: input[Symbol.iterator].bind(input),
|
|
37
36
|
}
|
|
38
37
|
}
|
|
39
38
|
const expected = ['a', 'b', 'c', 'd']
|
|
@@ -43,7 +42,7 @@ describe('flatten', () => {
|
|
|
43
42
|
input.push(toIterator(['a', 'b']))
|
|
44
43
|
input.push(toIterator(['c', 'd']))
|
|
45
44
|
input.push(null)
|
|
46
|
-
}
|
|
45
|
+
},
|
|
47
46
|
})
|
|
48
47
|
|
|
49
48
|
const result = await array(input.pipe(flatten()))
|
|
@@ -54,7 +53,7 @@ describe('flatten', () => {
|
|
|
54
53
|
it('should flatten object with a forEach method', async () => {
|
|
55
54
|
const toForEach = input => {
|
|
56
55
|
return {
|
|
57
|
-
forEach: input.forEach.bind(input)
|
|
56
|
+
forEach: input.forEach.bind(input),
|
|
58
57
|
}
|
|
59
58
|
}
|
|
60
59
|
const expected = ['a', 'b', 'c', 'd']
|
|
@@ -64,7 +63,7 @@ describe('flatten', () => {
|
|
|
64
63
|
input.push(toForEach(['a', 'b']))
|
|
65
64
|
input.push(toForEach(['c', 'd']))
|
|
66
65
|
input.push(null)
|
|
67
|
-
}
|
|
66
|
+
},
|
|
68
67
|
})
|
|
69
68
|
|
|
70
69
|
const result = await array(input.pipe(flatten()))
|
|
@@ -79,7 +78,7 @@ describe('flatten', () => {
|
|
|
79
78
|
read: () => {
|
|
80
79
|
input.push({})
|
|
81
80
|
input.push(null)
|
|
82
|
-
}
|
|
81
|
+
},
|
|
83
82
|
})
|
|
84
83
|
|
|
85
84
|
try {
|
package/test/glob.test.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { deepStrictEqual, strictEqual } from 'assert'
|
|
2
2
|
import { array } from 'get-stream'
|
|
3
3
|
import { isReadable, isWritable } from 'isstream'
|
|
4
|
-
import { describe, it } from 'mocha'
|
|
5
4
|
import glob from '../glob.js'
|
|
6
5
|
|
|
7
6
|
describe('glob', () => {
|
|
@@ -17,29 +16,29 @@ describe('glob', () => {
|
|
|
17
16
|
})
|
|
18
17
|
|
|
19
18
|
it('should emit each file name as a chunk', async () => {
|
|
20
|
-
const s = glob({ pattern: 'test/
|
|
19
|
+
const s = glob({ pattern: '../../test/e2e/definitions/foreach/*' })
|
|
21
20
|
|
|
22
21
|
const filenames = await array(s)
|
|
23
22
|
|
|
24
23
|
deepStrictEqual(filenames, [
|
|
25
|
-
'test/
|
|
26
|
-
'test/
|
|
27
|
-
'test/
|
|
24
|
+
'../../test/e2e/definitions/foreach/csv-duplicate.ttl',
|
|
25
|
+
'../../test/e2e/definitions/foreach/with-handler.ttl',
|
|
26
|
+
'../../test/e2e/definitions/foreach/with-variable.ttl',
|
|
28
27
|
])
|
|
29
28
|
})
|
|
30
29
|
|
|
31
30
|
it('should forward additional options', async () => {
|
|
32
31
|
const s = glob({
|
|
33
|
-
cwd: 'test/
|
|
34
|
-
pattern: '*'
|
|
32
|
+
cwd: '../../test/e2e/definitions/foreach',
|
|
33
|
+
pattern: '*',
|
|
35
34
|
})
|
|
36
35
|
|
|
37
36
|
const filenames = await array(s)
|
|
38
37
|
|
|
39
38
|
deepStrictEqual(filenames, [
|
|
40
|
-
'
|
|
41
|
-
'
|
|
42
|
-
'
|
|
39
|
+
'csv-duplicate.ttl',
|
|
40
|
+
'with-handler.ttl',
|
|
41
|
+
'with-variable.ttl',
|
|
43
42
|
])
|
|
44
43
|
})
|
|
45
44
|
})
|
package/test/map.test.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { deepStrictEqual } from 'assert'
|
|
2
2
|
import getStream, { array } from 'get-stream'
|
|
3
3
|
import intoStream from 'into-stream'
|
|
4
|
-
import { describe, it } from 'mocha'
|
|
5
4
|
import { Readable } from 'readable-stream'
|
|
6
5
|
import map from '../map.js'
|
|
7
6
|
|
|
@@ -12,10 +11,10 @@ describe('map', () => {
|
|
|
12
11
|
input.push('a')
|
|
13
12
|
input.push('b')
|
|
14
13
|
input.push(null)
|
|
15
|
-
}
|
|
14
|
+
},
|
|
16
15
|
})
|
|
17
16
|
const context = {
|
|
18
|
-
variable: new Map().set('prefix', 'foo_')
|
|
17
|
+
variable: new Map().set('prefix', 'foo_'),
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
const outStream = input.pipe(map.call(context, function (chunk) {
|
|
@@ -40,7 +39,7 @@ describe('map', () => {
|
|
|
40
39
|
|
|
41
40
|
it('binds pipeline context to transform function', async () => {
|
|
42
41
|
// const
|
|
43
|
-
function transform
|
|
42
|
+
function transform(letter) {
|
|
44
43
|
return letter + this.suffix
|
|
45
44
|
}
|
|
46
45
|
const input = intoStream.object(['A', 'B', 'C'])
|
|
@@ -68,7 +67,7 @@ describe('map', () => {
|
|
|
68
67
|
const result = await getStream(input.pipe(map({
|
|
69
68
|
map: transform,
|
|
70
69
|
ordered: false,
|
|
71
|
-
concurrency: 3
|
|
70
|
+
concurrency: 3,
|
|
72
71
|
})))
|
|
73
72
|
|
|
74
73
|
// then
|
|
@@ -89,7 +88,7 @@ describe('map', () => {
|
|
|
89
88
|
// when
|
|
90
89
|
const result = await getStream(input.pipe(map({
|
|
91
90
|
map: transform,
|
|
92
|
-
concurrency: 3
|
|
91
|
+
concurrency: 3,
|
|
93
92
|
})))
|
|
94
93
|
|
|
95
94
|
// then
|
package/toReadable.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import Readable from 'readable-stream'
|
|
2
2
|
|
|
3
3
|
class ToReadable extends Readable {
|
|
4
|
-
constructor
|
|
4
|
+
constructor(content, { objectMode = false } = {}) {
|
|
5
5
|
super({
|
|
6
6
|
objectMode,
|
|
7
|
-
read: () => {}
|
|
7
|
+
read: () => {},
|
|
8
8
|
})
|
|
9
9
|
|
|
10
10
|
this.push(content)
|
|
@@ -12,11 +12,11 @@ class ToReadable extends Readable {
|
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
function stringToReadable
|
|
15
|
+
function stringToReadable(str) {
|
|
16
16
|
return new ToReadable(str)
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
function objectToReadable
|
|
19
|
+
function objectToReadable(obj) {
|
|
20
20
|
return new ToReadable(obj, { objectMode: true })
|
|
21
21
|
}
|
|
22
22
|
|
package/toString.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { Transform } from 'readable-stream'
|
|
2
2
|
|
|
3
3
|
class ToString extends Transform {
|
|
4
|
-
constructor
|
|
4
|
+
constructor() {
|
|
5
5
|
super({
|
|
6
6
|
writableObjectMode: true,
|
|
7
|
-
readableObjectMode: false
|
|
7
|
+
readableObjectMode: false,
|
|
8
8
|
})
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
_transform
|
|
11
|
+
_transform(chunk, encoding, callback) {
|
|
12
12
|
callback(null, chunk.toString())
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
function factory
|
|
16
|
+
function factory() {
|
|
17
17
|
return new ToString()
|
|
18
18
|
}
|
|
19
19
|
|
package/.changeset/README.md
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
# Changesets
|
|
2
|
-
|
|
3
|
-
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
|
|
4
|
-
with multi-package repos, or single-package repos to help you version and publish your code. You can
|
|
5
|
-
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
|
|
6
|
-
|
|
7
|
-
We have a quick list of common questions to get you started engaging with this project in
|
|
8
|
-
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
|
package/.changeset/config.json
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://unpkg.com/@changesets/config@2.3.0/schema.json",
|
|
3
|
-
"changelog": "@changesets/cli/changelog",
|
|
4
|
-
"commit": false,
|
|
5
|
-
"fixed": [],
|
|
6
|
-
"linked": [],
|
|
7
|
-
"access": "public",
|
|
8
|
-
"baseBranch": "master",
|
|
9
|
-
"updateInternalDependencies": "patch",
|
|
10
|
-
"ignore": []
|
|
11
|
-
}
|
package/.changeset/pre.json
DELETED
package/.editorconfig
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
name: Add issues to shared backlog
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
issues:
|
|
5
|
-
types:
|
|
6
|
-
- opened
|
|
7
|
-
pull_request:
|
|
8
|
-
types:
|
|
9
|
-
- opened
|
|
10
|
-
|
|
11
|
-
jobs:
|
|
12
|
-
add-to-project:
|
|
13
|
-
runs-on: ubuntu-latest
|
|
14
|
-
steps:
|
|
15
|
-
- uses: actions/add-to-project@v0.4.0
|
|
16
|
-
with:
|
|
17
|
-
project-url: https://github.com/orgs/zazuko/projects/23
|
|
18
|
-
github-token: ${{ secrets.BACKLOG_PAT }}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
name: CI
|
|
2
|
-
on: push
|
|
3
|
-
jobs:
|
|
4
|
-
test:
|
|
5
|
-
runs-on: ubuntu-latest
|
|
6
|
-
strategy:
|
|
7
|
-
matrix:
|
|
8
|
-
node:
|
|
9
|
-
- '18'
|
|
10
|
-
- '16'
|
|
11
|
-
steps:
|
|
12
|
-
- uses: actions/checkout@v3
|
|
13
|
-
- uses: actions/setup-node@v3
|
|
14
|
-
with:
|
|
15
|
-
node-version: ${{ matrix.node }}
|
|
16
|
-
- run: npm install
|
|
17
|
-
- run: npm test
|
|
18
|
-
- name: Codecov
|
|
19
|
-
uses: codecov/codecov-action@v3
|
|
20
|
-
with:
|
|
21
|
-
token: ${{ secrets.CODECOV_TOKEN }}
|
|
22
|
-
|
|
23
|
-
lint:
|
|
24
|
-
runs-on: ubuntu-latest
|
|
25
|
-
steps:
|
|
26
|
-
- uses: actions/checkout@v3
|
|
27
|
-
- uses: actions/setup-node@v3
|
|
28
|
-
- run: npm ci
|
|
29
|
-
- run: npm run lint
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
name: Release
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches:
|
|
6
|
-
- master
|
|
7
|
-
- prerelease
|
|
8
|
-
|
|
9
|
-
concurrency: ${{ github.workflow }}-${{ github.ref }}
|
|
10
|
-
|
|
11
|
-
jobs:
|
|
12
|
-
release:
|
|
13
|
-
name: Release
|
|
14
|
-
runs-on: ubuntu-latest
|
|
15
|
-
steps:
|
|
16
|
-
- name: Checkout Repo
|
|
17
|
-
uses: actions/checkout@v3
|
|
18
|
-
|
|
19
|
-
- uses: actions/setup-node@v3
|
|
20
|
-
with:
|
|
21
|
-
node-version: 18
|
|
22
|
-
|
|
23
|
-
- name: Install Dependencies
|
|
24
|
-
run: npm ci
|
|
25
|
-
|
|
26
|
-
- name: Create Release Pull Request or Publish to npm
|
|
27
|
-
id: changesets
|
|
28
|
-
uses: changesets/action@v1
|
|
29
|
-
with:
|
|
30
|
-
# This expects you to have a script called release which does a build for your packages and calls changeset publish
|
|
31
|
-
publish: yarn release
|
|
32
|
-
env:
|
|
33
|
-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
34
|
-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/test/forEach.e2e.test.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { deepStrictEqual, strictEqual } from 'assert'
|
|
2
|
-
import { resolve } from 'path'
|
|
3
|
-
import { createPipeline } from 'barnard59-core'
|
|
4
|
-
import getStream from 'get-stream'
|
|
5
|
-
import { describe, it } from 'mocha'
|
|
6
|
-
import loadPipelineDefinition from './support/loadPipelineDefinition.js'
|
|
7
|
-
|
|
8
|
-
describe('forEach', () => {
|
|
9
|
-
it('should execute the example correctly', async () => {
|
|
10
|
-
const ptr = await loadPipelineDefinition('e2e/foreach-csv-duplicate')
|
|
11
|
-
const pipeline = createPipeline(ptr, { basePath: resolve('test') })
|
|
12
|
-
|
|
13
|
-
const out = JSON.parse(await getStream(pipeline.stream))
|
|
14
|
-
|
|
15
|
-
strictEqual(out.length, 24)
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
/*
|
|
19
|
-
* This pipeline verifies that a variable can be imperatively
|
|
20
|
-
* added during pipeline execution of a forEach step
|
|
21
|
-
* */
|
|
22
|
-
it('should preserve variables set during forEach execution', async () => {
|
|
23
|
-
const ptr = await loadPipelineDefinition('e2e/foreach-with-handler')
|
|
24
|
-
const pipeline = createPipeline(ptr, { basePath: resolve('test') })
|
|
25
|
-
|
|
26
|
-
const out = await getStream.array(pipeline.stream)
|
|
27
|
-
|
|
28
|
-
strictEqual(out.length > 0, true)
|
|
29
|
-
strictEqual(out[0] !== out[1], true)
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
it('should be able to access variables from higher scopes', async () => {
|
|
33
|
-
const ptr = await loadPipelineDefinition('e2e/foreach-with-variable')
|
|
34
|
-
const pipeline = createPipeline(ptr, { basePath: resolve('test') })
|
|
35
|
-
|
|
36
|
-
const out = await getStream.array(pipeline.stream)
|
|
37
|
-
|
|
38
|
-
deepStrictEqual(out, [
|
|
39
|
-
'/root/test/support/definitions/e2e/foreach-csv-duplicate.ttl',
|
|
40
|
-
'/root/test/support/definitions/e2e/foreach-with-handler.ttl',
|
|
41
|
-
'/root/test/support/definitions/e2e/foreach-with-variable.ttl'
|
|
42
|
-
])
|
|
43
|
-
})
|
|
44
|
-
})
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
columnA1,columnB1,columnC1
|
|
2
|
-
columnA2,columnB2,columnC2
|
|
3
|
-
columnA3,columnB3,columnC3
|
|
4
|
-
columnA4,columnB4,columnC4
|
|
5
|
-
columnA1,columnB1,columnC1
|
|
6
|
-
columnA2,columnB2,columnC2
|
|
7
|
-
columnA3,columnB3,columnC3
|
|
8
|
-
columnA4,columnB4,columnC4
|
|
9
|
-
columnA1,columnB1,columnC1
|
|
10
|
-
columnA2,columnB2,columnC2
|
|
11
|
-
columnA3,columnB3,columnC3
|
|
12
|
-
columnA4,columnB4,columnC4
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
@base <http://example.org/pipeline/>.
|
|
2
|
-
@prefix code: <https://code.described.at/>.
|
|
3
|
-
@prefix p: <https://pipeline.described.at/>.
|
|
4
|
-
|
|
5
|
-
<> a p:Pipeline, p:Readable;
|
|
6
|
-
p:variables [
|
|
7
|
-
p:variable [ a p:Variable;
|
|
8
|
-
p:name "filename" ;
|
|
9
|
-
p:value "test/support/data/test.csv"
|
|
10
|
-
]
|
|
11
|
-
];
|
|
12
|
-
p:steps [
|
|
13
|
-
p:stepList (<readFile> <parseCsv> <forEach> <serializeJson>)
|
|
14
|
-
].
|
|
15
|
-
|
|
16
|
-
<readFile> a p:Step;
|
|
17
|
-
code:implementedBy [ a code:EcmaScriptModule;
|
|
18
|
-
code:link <node:fs#createReadStream>
|
|
19
|
-
];
|
|
20
|
-
code:arguments ("${filename}"^^code:EcmaScriptTemplateLiteral).
|
|
21
|
-
|
|
22
|
-
<parseCsv> a p:Step;
|
|
23
|
-
code:implementedBy [ a code:EcmaScriptModule;
|
|
24
|
-
code:link <file:support/operations/parseCsv.js#default>
|
|
25
|
-
].
|
|
26
|
-
|
|
27
|
-
<forEach> a p:Step ;
|
|
28
|
-
code:implementedBy [ a code:EcmaScriptModule;
|
|
29
|
-
code:link <file:../forEach.js#default>
|
|
30
|
-
];
|
|
31
|
-
code:arguments (<subPipeline>).
|
|
32
|
-
|
|
33
|
-
<serializeJson> a p:Step;
|
|
34
|
-
code:implementedBy [ a code:EcmaScriptModule;
|
|
35
|
-
code:link <file:support/operations/serializeJson.js#default>
|
|
36
|
-
].
|
|
37
|
-
|
|
38
|
-
<subPipeline> a p:Pipeline, p:ReadableObjectMode, p:WritableObjectMode;
|
|
39
|
-
p:steps [
|
|
40
|
-
p:stepList (<duplicate>)
|
|
41
|
-
].
|
|
42
|
-
|
|
43
|
-
<duplicate> a p:Step;
|
|
44
|
-
code:implementedBy [ a code:EcmaScriptModule;
|
|
45
|
-
code:link <file:support/operations/duplicate.js#default>
|
|
46
|
-
].
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
@base <http://example.org/pipeline/>.
|
|
2
|
-
@prefix code: <https://code.described.at/>.
|
|
3
|
-
@prefix p: <https://pipeline.described.at/>.
|
|
4
|
-
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
|
|
5
|
-
|
|
6
|
-
<> a p:Pipeline, p:Readable;
|
|
7
|
-
p:steps [
|
|
8
|
-
p:stepList (<iterateDirectory> <printLength>)
|
|
9
|
-
] .
|
|
10
|
-
|
|
11
|
-
<iterateDirectory> a p:Step;
|
|
12
|
-
code:implementedBy [ a code:EcmaScriptModule;
|
|
13
|
-
code:link <file:support/operations/iterateDirectory.js#default>
|
|
14
|
-
];
|
|
15
|
-
code:arguments ("support/definitions/e2e").
|
|
16
|
-
|
|
17
|
-
<printLength> a p:Step;
|
|
18
|
-
code:implementedBy [ a code:EcmaScriptModule;
|
|
19
|
-
code:link <file:../forEach.js#default>
|
|
20
|
-
];
|
|
21
|
-
code:arguments (<Print> "file").
|
|
22
|
-
|
|
23
|
-
<Print> a p:Pipeline, p:ReadableObjectMode;
|
|
24
|
-
p:steps [
|
|
25
|
-
p:stepList (<readFile> <getLength>)
|
|
26
|
-
].
|
|
27
|
-
|
|
28
|
-
<readFile> a p:Step;
|
|
29
|
-
code:implementedBy [ a code:EcmaScriptModule;
|
|
30
|
-
code:link <node:fs#createReadStream>
|
|
31
|
-
];
|
|
32
|
-
code:arguments ("file"^^p:VariableName).
|
|
33
|
-
|
|
34
|
-
<getLength> a p:Step;
|
|
35
|
-
code:implementedBy [ a code:EcmaScriptModule;
|
|
36
|
-
code:link <file:support/operations/inlineTransform.js#default>
|
|
37
|
-
];
|
|
38
|
-
code:arguments ("_ => this.variables.get('file')"^^code:EcmaScript).
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
@base <http://example.org/pipeline/>.
|
|
2
|
-
@prefix code: <https://code.described.at/>.
|
|
3
|
-
@prefix p: <https://pipeline.described.at/>.
|
|
4
|
-
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
|
|
5
|
-
|
|
6
|
-
<> a p:Pipeline, p:ReadableObjectMode;
|
|
7
|
-
p:variables [
|
|
8
|
-
p:variable [ a p:Variable;
|
|
9
|
-
p:name "root";
|
|
10
|
-
p:value "/root/"
|
|
11
|
-
]
|
|
12
|
-
];
|
|
13
|
-
p:steps [
|
|
14
|
-
p:stepList (<glob> <loop>)
|
|
15
|
-
] .
|
|
16
|
-
|
|
17
|
-
<glob> a p:Step;
|
|
18
|
-
code:implementedBy [ a code:EcmaScriptModule;
|
|
19
|
-
code:link <file:../glob.js#default>
|
|
20
|
-
];
|
|
21
|
-
code:arguments [
|
|
22
|
-
code:name "pattern";
|
|
23
|
-
code:value "test/support/definitions/e2e/*"
|
|
24
|
-
].
|
|
25
|
-
|
|
26
|
-
<loop> a p:Step;
|
|
27
|
-
code:implementedBy [ a code:EcmaScriptModule;
|
|
28
|
-
code:link <file:../forEach.js#default>
|
|
29
|
-
];
|
|
30
|
-
code:arguments (<printFilename>).
|
|
31
|
-
|
|
32
|
-
<printFilename> a p:Pipeline, p:WritableObjectMode, p:ReadableObjectMode;
|
|
33
|
-
p:steps [
|
|
34
|
-
p:stepList (<rootAndFilename>)
|
|
35
|
-
].
|
|
36
|
-
|
|
37
|
-
<rootAndFilename> a p:Step;
|
|
38
|
-
code:implementedBy [ a code:EcmaScriptModule;
|
|
39
|
-
code:link <file:../map.js#default>
|
|
40
|
-
];
|
|
41
|
-
code:arguments ("filename => this.variables.get('root') + filename"^^code:EcmaScript).
|
|
42
|
-
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { resolve } from 'path'
|
|
2
|
-
import clownface from 'clownface'
|
|
3
|
-
import rdf from 'rdf-ext'
|
|
4
|
-
import fromFile from 'rdf-utils-fs/fromFile.js'
|
|
5
|
-
import ns from './namespaces.js'
|
|
6
|
-
|
|
7
|
-
async function loadPipelineDefinition (name, { term = ns.ex('') } = {}) {
|
|
8
|
-
const filename = resolve(`test/support/definitions/${name}.ttl`)
|
|
9
|
-
const stream = fromFile(filename)
|
|
10
|
-
const dataset = await rdf.dataset().import(stream)
|
|
11
|
-
|
|
12
|
-
return clownface({ dataset, term })
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export default loadPipelineDefinition
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import stream from 'readable-stream'
|
|
2
|
-
|
|
3
|
-
const { Transform } = stream
|
|
4
|
-
|
|
5
|
-
class Duplicator extends Transform {
|
|
6
|
-
constructor () {
|
|
7
|
-
super({ objectMode: true })
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
_transform (chunk, encoding, callback) {
|
|
11
|
-
this.push(chunk)
|
|
12
|
-
this.push(chunk)
|
|
13
|
-
|
|
14
|
-
callback()
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function factory () {
|
|
19
|
-
return new Duplicator()
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export default factory
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import stream from 'readable-stream'
|
|
2
|
-
|
|
3
|
-
const { Transform } = stream
|
|
4
|
-
|
|
5
|
-
class InlineTransformer extends Transform {
|
|
6
|
-
constructor (func) {
|
|
7
|
-
super({ objectMode: true })
|
|
8
|
-
|
|
9
|
-
this.transform = func
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
_transform (chunk, encoding, callback) {
|
|
13
|
-
callback(null, this.transform(chunk))
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function factory (func) {
|
|
18
|
-
return new InlineTransformer(func)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export default factory
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { readdir } from 'fs'
|
|
2
|
-
import { resolve } from 'path'
|
|
3
|
-
import stream from 'readable-stream'
|
|
4
|
-
|
|
5
|
-
const { Readable } = stream
|
|
6
|
-
|
|
7
|
-
class FileIterator extends Readable {
|
|
8
|
-
constructor (dirName, basePath) {
|
|
9
|
-
super({
|
|
10
|
-
objectMode: true,
|
|
11
|
-
read: () => {}
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
const directory = resolve(basePath, dirName)
|
|
15
|
-
|
|
16
|
-
readdir(directory, (e, files) => {
|
|
17
|
-
files.forEach(file => {
|
|
18
|
-
this.push(resolve(directory, file))
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
this.push(null)
|
|
22
|
-
})
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function factory (dirName) {
|
|
27
|
-
return new FileIterator(dirName, this.basePath)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export default factory
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import stream from 'readable-stream'
|
|
2
|
-
|
|
3
|
-
const { Transform } = stream
|
|
4
|
-
|
|
5
|
-
class CsvParser extends Transform {
|
|
6
|
-
constructor () {
|
|
7
|
-
super({ readableObjectMode: true })
|
|
8
|
-
|
|
9
|
-
this.content = ''
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
_transform (chunk, encoding, callback) {
|
|
13
|
-
this.content += chunk.toString()
|
|
14
|
-
|
|
15
|
-
this.nextLine()
|
|
16
|
-
|
|
17
|
-
callback()
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
_flush (callback) {
|
|
21
|
-
if (this.content) {
|
|
22
|
-
this.pushLine(this.content)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
callback()
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
nextLine () {
|
|
29
|
-
const index = this.content.indexOf('\n')
|
|
30
|
-
|
|
31
|
-
if (index === -1) {
|
|
32
|
-
return
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
this.pushLine(this.content.substring(0, index))
|
|
36
|
-
this.content = this.content.substring(index + 1)
|
|
37
|
-
this.nextLine()
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
pushLine (line) {
|
|
41
|
-
this.push(line.split(','))
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function factory () {
|
|
46
|
-
return new CsvParser()
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export default factory
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import stream from 'readable-stream'
|
|
2
|
-
|
|
3
|
-
const { Transform } = stream
|
|
4
|
-
|
|
5
|
-
class JsonSerializer extends Transform {
|
|
6
|
-
constructor () {
|
|
7
|
-
super({ writableObjectMode: true })
|
|
8
|
-
|
|
9
|
-
this.first = true
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
_transform (chunk, encoding, callback) {
|
|
13
|
-
if (this.first) {
|
|
14
|
-
this.push('[\n')
|
|
15
|
-
|
|
16
|
-
this.first = false
|
|
17
|
-
} else {
|
|
18
|
-
this.push(',\n')
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
this.push(JSON.stringify(chunk))
|
|
22
|
-
|
|
23
|
-
callback()
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
_flush (callback) {
|
|
27
|
-
this.push('\n]')
|
|
28
|
-
|
|
29
|
-
callback()
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function factory () {
|
|
34
|
-
return new JsonSerializer()
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export default factory
|