barnard59-base 2.3.0 → 2.4.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 +13 -0
- package/Readable.d.ts +6 -0
- package/Readable.js +4 -0
- package/batch.d.ts +7 -0
- package/batch.js +34 -0
- package/glob.d.ts +2 -2
- package/glob.js +3 -4
- package/index.d.ts +3 -1
- package/index.js +3 -1
- package/manifest.ttl +8 -1
- package/package.json +5 -6
- package/test/batch.test.js +59 -0
- package/test/glob.test.js +4 -9
- /package/{nul.d.ts → dev-nul.d.ts} +0 -0
- /package/{nul.js → dev-nul.js} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# barnard59-base
|
|
2
2
|
|
|
3
|
+
## 2.4.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- d48f198: Update [glob](https://npm.im/glob) to v10
|
|
8
|
+
- 94551a4: Missing type declarations for `batch.js` and `Readable.js`
|
|
9
|
+
|
|
10
|
+
## 2.4.0
|
|
11
|
+
|
|
12
|
+
### Minor Changes
|
|
13
|
+
|
|
14
|
+
- 7456a6a: added batch operation
|
|
15
|
+
|
|
3
16
|
## 2.3.0
|
|
4
17
|
|
|
5
18
|
### Minor Changes
|
package/Readable.d.ts
ADDED
package/Readable.js
CHANGED
package/batch.d.ts
ADDED
package/batch.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Transform } from 'readable-stream'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {number} [size]
|
|
5
|
+
* @return {Transform}
|
|
6
|
+
*/
|
|
7
|
+
function batch(size = 0) {
|
|
8
|
+
/** @type {any[]} */
|
|
9
|
+
let array = []
|
|
10
|
+
const maxSize = Number(size)
|
|
11
|
+
return new Transform({
|
|
12
|
+
readableObjectMode: true,
|
|
13
|
+
writableObjectMode: true,
|
|
14
|
+
readableHighWaterMark: maxSize,
|
|
15
|
+
writableHighWaterMark: maxSize,
|
|
16
|
+
transform(item, _encoding, callback) {
|
|
17
|
+
array.push(item)
|
|
18
|
+
if (array.length === maxSize) {
|
|
19
|
+
this.push(array)
|
|
20
|
+
array = []
|
|
21
|
+
}
|
|
22
|
+
callback()
|
|
23
|
+
},
|
|
24
|
+
/**
|
|
25
|
+
* @this {Transform}
|
|
26
|
+
*/
|
|
27
|
+
flush(callback) {
|
|
28
|
+
if (array.length > 0) this.push(array)
|
|
29
|
+
callback()
|
|
30
|
+
},
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export default batch
|
package/glob.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export default glob;
|
|
2
2
|
/**
|
|
3
3
|
* @this {import('barnard59-core').Context}
|
|
4
|
-
* @param {{ pattern: string } & import('glob').
|
|
4
|
+
* @param {{ pattern: string } & Omit<import('glob').GlobOptions, 'withFileTypes'>} options
|
|
5
5
|
* @return {Readable}
|
|
6
6
|
*/
|
|
7
7
|
declare function glob(this: import("barnard59-core").Context, { pattern, ...options }: {
|
|
8
8
|
pattern: string;
|
|
9
|
-
} & import('glob').
|
|
9
|
+
} & Omit<import('glob').GlobOptions, 'withFileTypes'>): Readable;
|
|
10
10
|
import { Readable } from 'readable-stream';
|
package/glob.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { promisify } from 'node:util'
|
|
2
1
|
import { SpanStatusCode } from '@opentelemetry/api'
|
|
3
|
-
import globFn from 'glob'
|
|
2
|
+
import { glob as globFn } from 'glob'
|
|
4
3
|
import onetime from 'onetime'
|
|
5
4
|
import { Readable } from 'readable-stream'
|
|
6
5
|
import tracer from './lib/tracer.js'
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* @this {import('barnard59-core').Context}
|
|
10
|
-
* @param {{ pattern: string } & import('glob').
|
|
9
|
+
* @param {{ pattern: string } & Omit<import('glob').GlobOptions, 'withFileTypes'>} options
|
|
11
10
|
* @return {Readable}
|
|
12
11
|
*/
|
|
13
12
|
function glob({ pattern, ...options }) {
|
|
@@ -19,7 +18,7 @@ function glob({ pattern, ...options }) {
|
|
|
19
18
|
|
|
20
19
|
const init = onetime(async () => {
|
|
21
20
|
span.addEvent('init')
|
|
22
|
-
filenames = await
|
|
21
|
+
filenames = await globFn(pattern, options)
|
|
23
22
|
return filenames.length === 0
|
|
24
23
|
})
|
|
25
24
|
|
package/index.d.ts
CHANGED
|
@@ -5,9 +5,11 @@ export { default as forEach } from "./forEach.js";
|
|
|
5
5
|
export { default as glob } from "./glob.js";
|
|
6
6
|
export { default as limit } from "./limit.js";
|
|
7
7
|
export { default as map } from "./map.js";
|
|
8
|
-
export { default as nul } from "./nul.js";
|
|
8
|
+
export { default as nul } from "./dev-nul.js";
|
|
9
9
|
export { default as offset } from "./offset.js";
|
|
10
10
|
export * from "./process.js";
|
|
11
11
|
export { default as toString } from "./toString.js";
|
|
12
|
+
export { default as batch } from "./batch.js";
|
|
13
|
+
export { from as streamValues } from "./Readable.js";
|
|
12
14
|
export { default as concat, object as concatObject } from "./concat.js";
|
|
13
15
|
export { parse as jsonParse, stringify as jsonStringify } from "./json.js";
|
package/index.js
CHANGED
|
@@ -7,7 +7,9 @@ export { default as glob } from './glob.js'
|
|
|
7
7
|
export { parse as jsonParse, stringify as jsonStringify } from './json.js'
|
|
8
8
|
export { default as limit } from './limit.js'
|
|
9
9
|
export { default as map } from './map.js'
|
|
10
|
-
export { default as nul } from './nul.js'
|
|
10
|
+
export { default as nul } from './dev-nul.js'
|
|
11
11
|
export { default as offset } from './offset.js'
|
|
12
12
|
export * from './process.js'
|
|
13
13
|
export { default as toString } from './toString.js'
|
|
14
|
+
export { default as batch } from './batch.js'
|
|
15
|
+
export { from as streamValues } from './Readable.js'
|
package/manifest.ttl
CHANGED
|
@@ -31,6 +31,13 @@
|
|
|
31
31
|
code:link <node:barnard59-base/filter.js#default>
|
|
32
32
|
].
|
|
33
33
|
|
|
34
|
+
<batch> a p:Operation, p:WritableObjectMode, p:ReadableObjectMode;
|
|
35
|
+
rdfs:label "Batch";
|
|
36
|
+
rdfs:comment "Groups incoming items into arrays of the given size.";
|
|
37
|
+
code:implementedBy [ a code:EcmaScriptModule;
|
|
38
|
+
code:link <node:barnard59-base/batch.js#default>
|
|
39
|
+
].
|
|
40
|
+
|
|
34
41
|
<flatten> a p:Operation, p:WritableObjectMode, p:ReadableObjectMode;
|
|
35
42
|
rdfs:label "Flatten";
|
|
36
43
|
rdfs:comment "Separates incoming arrays into their elements and emits each element as a single chunk.";
|
|
@@ -84,7 +91,7 @@
|
|
|
84
91
|
rdfs:label "/dev/null";
|
|
85
92
|
rdfs:comment "Dummy output stream, just like /dev/null.";
|
|
86
93
|
code:implementedBy [ a code:EcmaScriptModule;
|
|
87
|
-
code:link <node:barnard59-base/nul.js#default>
|
|
94
|
+
code:link <node:barnard59-base/dev-nul.js#default>
|
|
88
95
|
].
|
|
89
96
|
|
|
90
97
|
<offset> a p:Operation, p:WritableObjectMode, p:ReadableObjectMode;
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "barnard59-base",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.1",
|
|
4
4
|
"description": "Linked Data pipelines",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"test": "mocha",
|
|
9
|
-
"prebuild": "rimraf *.d.ts",
|
|
9
|
+
"prebuild": "rimraf -g *.d.ts",
|
|
10
10
|
"build": "tsc",
|
|
11
11
|
"prepack": "npm run build"
|
|
12
12
|
},
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@opentelemetry/api": "^1.0.1",
|
|
27
27
|
"duplexify": "^4.1.1",
|
|
28
|
-
"glob": "^
|
|
28
|
+
"glob": "^10",
|
|
29
29
|
"onetime": "^6.0.0",
|
|
30
30
|
"parallel-transform": "^1.2.0",
|
|
31
31
|
"readable-stream": "^3.0.6",
|
|
@@ -34,12 +34,11 @@
|
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/duplexify": "^3.6.4",
|
|
37
|
-
"@types/glob": "^7.2.0",
|
|
38
37
|
"@types/parallel-transform": "^1.1.4",
|
|
39
|
-
"@types/readable-stream": "^4.0.
|
|
38
|
+
"@types/readable-stream": "^4.0.11",
|
|
40
39
|
"@types/readable-to-readable": "^0.1.0",
|
|
41
40
|
"@types/through2": "^2.0.41",
|
|
42
|
-
"barnard59-core": "^
|
|
41
|
+
"barnard59-core": "^6.0.0",
|
|
43
42
|
"chai": "^4.3.10",
|
|
44
43
|
"get-stream": "^6.0.1",
|
|
45
44
|
"into-stream": "^7.0.0",
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { deepStrictEqual, strictEqual } from 'node:assert'
|
|
2
|
+
import { array } from 'get-stream'
|
|
3
|
+
import { isReadableStream as isReadable, isWritableStream as isWritable } from 'is-stream'
|
|
4
|
+
import { Readable } from 'readable-stream'
|
|
5
|
+
import batch from '../batch.js'
|
|
6
|
+
|
|
7
|
+
describe('batch', () => {
|
|
8
|
+
it('should be a function', () => {
|
|
9
|
+
strictEqual(typeof batch, 'function')
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
it('should return a duplex stream', async () => {
|
|
13
|
+
const result = batch()
|
|
14
|
+
|
|
15
|
+
strictEqual(isWritable(result), true)
|
|
16
|
+
strictEqual(isReadable(result), true)
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it('should do nothing if there are no input chunks', async () => {
|
|
20
|
+
const input = Readable({
|
|
21
|
+
objectMode: true,
|
|
22
|
+
read: () => {
|
|
23
|
+
input.push(null)
|
|
24
|
+
},
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
const result = await array(input.pipe(batch()))
|
|
28
|
+
|
|
29
|
+
deepStrictEqual(result, [])
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
it('should split input in batches', async () => {
|
|
33
|
+
const expected = [['a', 'b'], ['c', 'd'], ['e']]
|
|
34
|
+
const input = Readable({
|
|
35
|
+
objectMode: true,
|
|
36
|
+
read: () => {
|
|
37
|
+
['a', 'b', 'c', 'd', 'e', null].forEach(item => input.push(item))
|
|
38
|
+
},
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
const result = await array(input.pipe(batch(2)))
|
|
42
|
+
|
|
43
|
+
deepStrictEqual(result, expected)
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it('should emit a single batch', async () => {
|
|
47
|
+
const expected = [['a', 'b', 'c', 'd', 'e']]
|
|
48
|
+
const input = Readable({
|
|
49
|
+
objectMode: true,
|
|
50
|
+
read: () => {
|
|
51
|
+
['a', 'b', 'c', 'd', 'e', null].forEach(item => input.push(item))
|
|
52
|
+
},
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
const result = await array(input.pipe(batch(0)))
|
|
56
|
+
|
|
57
|
+
deepStrictEqual(result, expected)
|
|
58
|
+
})
|
|
59
|
+
})
|
package/test/glob.test.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { deepStrictEqual, strictEqual } from 'assert'
|
|
2
1
|
import { array } from 'get-stream'
|
|
3
2
|
import { isReadableStream as isReadable, isWritableStream as isWritable } from 'is-stream'
|
|
4
3
|
import sinon from 'sinon'
|
|
@@ -19,15 +18,11 @@ describe('glob', () => {
|
|
|
19
18
|
}
|
|
20
19
|
})
|
|
21
20
|
|
|
22
|
-
it('should be a function', () => {
|
|
23
|
-
strictEqual(typeof glob, 'function')
|
|
24
|
-
})
|
|
25
|
-
|
|
26
21
|
it('should return a Readable stream', () => {
|
|
27
22
|
const s = glob.call({ logger }, { pattern: 'test/support/*' })
|
|
28
23
|
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
expect(isReadable(s)).to.be.true
|
|
25
|
+
expect(isWritable(s)).to.be.false
|
|
31
26
|
})
|
|
32
27
|
|
|
33
28
|
it('should emit each file name as a chunk', async () => {
|
|
@@ -35,7 +30,7 @@ describe('glob', () => {
|
|
|
35
30
|
|
|
36
31
|
const filenames = await array(s)
|
|
37
32
|
|
|
38
|
-
|
|
33
|
+
expect(filenames).to.contain.all.members([
|
|
39
34
|
'../../test/e2e/definitions/foreach/csv-duplicate.ttl',
|
|
40
35
|
'../../test/e2e/definitions/foreach/with-handler.ttl',
|
|
41
36
|
'../../test/e2e/definitions/foreach/with-variable.ttl',
|
|
@@ -50,7 +45,7 @@ describe('glob', () => {
|
|
|
50
45
|
|
|
51
46
|
const filenames = await array(s)
|
|
52
47
|
|
|
53
|
-
|
|
48
|
+
expect(filenames).to.contain.all.members([
|
|
54
49
|
'csv-duplicate.ttl',
|
|
55
50
|
'with-handler.ttl',
|
|
56
51
|
'with-variable.ttl',
|
|
File without changes
|
/package/{nul.js → dev-nul.js}
RENAMED
|
File without changes
|