barnard59-base 1.0.0 → 1.2.0-pmap.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.
@@ -0,0 +1,8 @@
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)
@@ -0,0 +1,5 @@
1
+ ---
2
+ "barnard59-base": minor
3
+ ---
4
+
5
+ Use [parallel-transform](https://npm.im/parallel-transform) to implement the map step (closes #10)
@@ -0,0 +1,11 @@
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
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "mode": "pre",
3
+ "tag": "pmap",
4
+ "initialVersions": {
5
+ "barnard59-base": "1.1.0"
6
+ },
7
+ "changesets": [
8
+ "breezy-yaks-happen"
9
+ ]
10
+ }
package/.editorconfig ADDED
@@ -0,0 +1,3 @@
1
+ [*]
2
+ indent_size = 2
3
+ indent_style = space
@@ -0,0 +1,18 @@
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 }}
@@ -2,17 +2,28 @@ name: CI
2
2
  on: push
3
3
  jobs:
4
4
  test:
5
- runs-on: ubuntu-20.04
5
+ runs-on: ubuntu-latest
6
6
  strategy:
7
7
  matrix:
8
8
  node:
9
- - '14'
9
+ - '18'
10
10
  - '16'
11
11
  steps:
12
- - uses: actions/checkout@v2
13
- - uses: actions/setup-node@v2
12
+ - uses: actions/checkout@v3
13
+ - uses: actions/setup-node@v3
14
14
  with:
15
15
  node-version: ${{ matrix.node }}
16
16
  - run: npm install
17
17
  - run: npm test
18
- - run: npm run coverage
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
@@ -0,0 +1,34 @@
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/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
1
  # v1.0.0
2
2
 
3
+ ## 1.2.0-pmap.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 2c4af8f: Use [parallel-transform](https://npm.im/parallel-transform) to implement the map step
8
+
3
9
  - Moved to JavaScript modules
package/forEach.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { promisify } from 'util'
2
+ import { context } from '@opentelemetry/api'
2
3
  import stream from 'readable-stream'
3
4
  import ReadableToReadable from 'readable-to-readable'
4
5
 
@@ -12,6 +13,10 @@ class ForEach extends Duplex {
12
13
  constructor ({ createPipeline, pipeline, step, variable, variables }) {
13
14
  super({ objectMode: true })
14
15
 
16
+ // Bind the read and write function to the current context so the trace ID
17
+ // gets properly propagated
18
+ this._read = context.bind(context.active(), this._read)
19
+ this._write = context.bind(context.active(), this._write)
15
20
  this.createPipeline = createPipeline
16
21
  this.step = step
17
22
 
package/glob.js CHANGED
@@ -1,12 +1,17 @@
1
1
  import { promisify } from 'util'
2
+ import { SpanStatusCode } from '@opentelemetry/api'
2
3
  import globFn from 'glob'
3
4
  import once from 'lodash/once.js'
4
5
  import { Readable } from 'readable-stream'
6
+ import tracer from './lib/tracer.js'
5
7
 
6
8
  function glob ({ pattern, ...options }) {
7
9
  let filenames = null
8
10
 
11
+ const span = tracer.startSpan('glob')
12
+
9
13
  const init = once(async () => {
14
+ span.addEvent('init')
10
15
  filenames = await promisify(globFn)(pattern, options)
11
16
  })
12
17
 
@@ -26,7 +31,11 @@ function glob ({ pattern, ...options }) {
26
31
 
27
32
  stream._read()
28
33
  } catch (err) {
34
+ span.recordException(err)
35
+ span.setStatus({ code: SpanStatusCode.ERROR, message: err.message })
29
36
  stream.destroy(err)
37
+ } finally {
38
+ span.end()
30
39
  }
31
40
  }
32
41
  })
package/lib/tracer.js ADDED
@@ -0,0 +1,4 @@
1
+ import { trace } from '@opentelemetry/api'
2
+
3
+ const tracer = trace.getTracer('barnard59-base')
4
+ export default tracer
package/map.js CHANGED
@@ -1,17 +1,34 @@
1
- import { obj } from 'through2'
1
+ import transform from 'parallel-transform'
2
2
 
3
- function map (func) {
4
- const context = this
5
- return obj(function (chunk, encoding, callback) {
6
- Promise.resolve()
7
- .then(() => {
8
- return func.call(context, chunk, encoding)
9
- }).then(result => {
10
- this.push(result)
3
+ /**
4
+ * Processes chunks with a transform function
5
+ *
6
+ * @param {Object|Function} options Transform function or complex options
7
+ * @params {Function} options.map Transform function
8
+ * @param {Number} [options.concurrency=1] The max number of concurrent chunks being transformed
9
+ * @param {Boolean} [options.ordered=true] Option to keep order of asynchronously transformed chunks
10
+ * @param {Boolean} [options.objectMode=true] Option to transform chunks in object mode
11
+ * @return {ReadableStream}
12
+ */
13
+ export default function map (options) {
14
+ let func
15
+ let concurrency = 1
16
+ let ordered = true
17
+ let objectMode = true
18
+ if (typeof options === 'function') {
19
+ func = options
20
+ } else {
21
+ func = options.map
22
+ concurrency = options.concurrency || concurrency
23
+ ordered = typeof options.ordered === 'boolean' ? options.ordered : ordered
24
+ objectMode = typeof options.objectMode === 'boolean' ? options.objectMode : objectMode
25
+ }
11
26
 
12
- callback()
13
- }).catch(callback)
27
+ return transform(concurrency, { ordered, objectMode }, (data, callback) => {
28
+ Promise.resolve().then(() => {
29
+ return func.call(this, data)
30
+ }).then(result => {
31
+ callback(null, result)
32
+ }).catch(callback)
14
33
  })
15
34
  }
16
-
17
- export default map
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "barnard59-base",
3
- "version": "1.0.0",
3
+ "version": "1.2.0-pmap.0",
4
4
  "description": "Linked Data pipelines",
5
5
  "main": "index.js",
6
6
  "type": "module",
7
7
  "scripts": {
8
- "coverage": "codecov",
9
- "test": "stricter-standard && c8 --reporter=lcov --reporter=text mocha"
8
+ "lint": "stricter-standard",
9
+ "test": "c8 --reporter=lcov --reporter=text mocha",
10
+ "release": "changeset publish"
10
11
  },
11
12
  "repository": {
12
13
  "type": "git",
@@ -20,16 +21,19 @@
20
21
  },
21
22
  "homepage": "https://github.com/zazuko/barnard59-base",
22
23
  "dependencies": {
24
+ "@opentelemetry/api": "^1.0.1",
23
25
  "duplexify": "^4.1.1",
24
26
  "glob": "^7.1.7",
27
+ "parallel-transform": "^1.2.0",
25
28
  "readable-stream": "^3.0.6",
26
29
  "through2": "^4.0.2"
27
30
  },
28
31
  "devDependencies": {
32
+ "@changesets/cli": "^2.26.1",
29
33
  "barnard59-core": "^1.0.0",
30
34
  "c8": "^7.7.3",
31
- "codecov": "^3.8.2",
32
35
  "get-stream": "^6.0.1",
36
+ "into-stream": "^7.0.0",
33
37
  "isstream": "^0.1.2",
34
38
  "mocha": "^9.0.1",
35
39
  "rdf-utils-fs": "^2.1.0",
package/test/map.test.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { deepStrictEqual } from 'assert'
2
- import { array } from 'get-stream'
2
+ import getStream, { array } from 'get-stream'
3
+ import intoStream from 'into-stream'
3
4
  import { describe, it } from 'mocha'
4
5
  import { Readable } from 'readable-stream'
5
6
  import map from '../map.js'
@@ -24,4 +25,74 @@ describe('map', () => {
24
25
 
25
26
  deepStrictEqual(output, ['foo_a', 'foo_b'])
26
27
  })
28
+
29
+ it('accepts a function as parameter', async () => {
30
+ // given
31
+ const transform = letter => letter.toUpperCase()
32
+ const input = intoStream.object(['a', 'b', 'c'])
33
+
34
+ // when
35
+ const result = await getStream(input.pipe(map(transform)))
36
+
37
+ // then
38
+ deepStrictEqual(result, 'ABC')
39
+ })
40
+
41
+ it('binds pipeline context to transform function', async () => {
42
+ // const
43
+ function transform (letter) {
44
+ return letter + this.suffix
45
+ }
46
+ const input = intoStream.object(['A', 'B', 'C'])
47
+
48
+ // when
49
+ const boundMap = map.bind({ suffix: 'x' })
50
+ const result = await getStream(input.pipe(boundMap(transform)))
51
+
52
+ // then
53
+ deepStrictEqual(result, 'AxBxCx')
54
+ })
55
+
56
+ it('accepts an option to not retain order', async () => {
57
+ // given
58
+ const transform = async letter => {
59
+ if (letter === 'a') {
60
+ await new Promise(resolve => setTimeout(resolve, 10))
61
+ }
62
+
63
+ return letter.toUpperCase()
64
+ }
65
+ const input = intoStream.object(['a', 'b', 'c'])
66
+
67
+ // when
68
+ const result = await getStream(input.pipe(map({
69
+ map: transform,
70
+ ordered: false,
71
+ concurrency: 3
72
+ })))
73
+
74
+ // then
75
+ deepStrictEqual(result, 'BCA')
76
+ })
77
+
78
+ it('retains input order by default', async () => {
79
+ // given
80
+ const transform = async letter => {
81
+ if (letter === 'a') {
82
+ await new Promise(resolve => setTimeout(resolve, 10))
83
+ }
84
+
85
+ return letter.toUpperCase()
86
+ }
87
+ const input = intoStream.object(['a', 'b', 'c'])
88
+
89
+ // when
90
+ const result = await getStream(input.pipe(map({
91
+ map: transform,
92
+ concurrency: 3
93
+ })))
94
+
95
+ // then
96
+ deepStrictEqual(result, 'ABC')
97
+ })
27
98
  })