barnard59-base 2.0.0 → 2.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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # v1.0.0
2
2
 
3
+ ## 2.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 5327ff0: Filter: bind filter callback function to pipeline context
8
+
9
+ ## 2.0.1
10
+
11
+ ### Patch Changes
12
+
13
+ - 67504df: Remove redundant dependency on `rdf-utils-fs`
14
+
3
15
  ## 2.0.0
4
16
 
5
17
  ### Major Changes
package/filter.js CHANGED
@@ -1,15 +1,15 @@
1
1
  import { obj } from 'through2'
2
2
 
3
3
  function filter(func) {
4
- return obj(function (chunk, encoding, callback) {
4
+ return obj((chunk, encoding, callback) => {
5
5
  Promise.resolve().then(() => {
6
- return func(chunk, encoding)
6
+ return func.call(this, chunk, encoding)
7
7
  }).then(result => {
8
8
  if (result) {
9
- this.push(chunk)
9
+ return callback(null, chunk)
10
10
  }
11
11
 
12
- callback()
12
+ return callback()
13
13
  }).catch(callback)
14
14
  })
15
15
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "barnard59-base",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "Linked Data pipelines",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -30,13 +30,12 @@
30
30
  "through2": "^4.0.2"
31
31
  },
32
32
  "devDependencies": {
33
- "barnard59-core": "^4.0.0",
33
+ "barnard59-core": "^5.0.0",
34
34
  "chai": "^4.3.10",
35
35
  "get-stream": "^6.0.1",
36
36
  "into-stream": "^7.0.0",
37
37
  "isstream": "^0.1.2",
38
38
  "mocha": "^9.0.1",
39
- "rdf-utils-fs": "^2.1.0",
40
39
  "sinon": "^17.0.0"
41
40
  },
42
41
  "engines": {
@@ -0,0 +1,27 @@
1
+ import { deepStrictEqual } from 'assert'
2
+ import { array } from 'get-stream'
3
+ import { Readable } from 'readable-stream'
4
+ import filter from '../filter.js'
5
+
6
+ describe('filter', () => {
7
+ it('should pass pipeline context to callback function', async () => {
8
+ const input = new Readable({
9
+ objectMode: true,
10
+ read: () => {
11
+ input.push('a')
12
+ input.push('b')
13
+ input.push(null)
14
+ },
15
+ })
16
+ const context = {
17
+ variable: new Map().set('condition', 'a'),
18
+ }
19
+
20
+ const outStream = input.pipe(filter.call(context, function (chunk) {
21
+ return this.variable.get('condition') === chunk
22
+ }))
23
+ const output = await array(outStream)
24
+
25
+ deepStrictEqual(output, ['a'])
26
+ })
27
+ })