@streamr/cli-tools 8.3.0 → 8.3.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 CHANGED
@@ -20,6 +20,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
20
20
  ### Security
21
21
 
22
22
 
23
+ ## [8.3.1] - 2023-05-03
24
+
25
+ ### Fixed
26
+
27
+ - Fix `stream create` ouput (now valid JSON without extra characters)
28
+
29
+
23
30
  ## [7.0.0] - 2022-11-15
24
31
 
25
32
  ### Changed
@@ -149,7 +156,8 @@ ordering and gap filling.
149
156
  - Re-organize README.md and a few touches to Developing section paragraphs.
150
157
 
151
158
 
152
- [Unreleased]: https://github.com/streamr-dev/network/compare/cli-tools%2fv7.0.0...HEAD
159
+ [Unreleased]: https://github.com/streamr-dev/network/compare/cli-tools%2fv8.3.1...HEAD
160
+ [8.3.1]: https://github.com/streamr-dev/network/compare/cli-tools%2fv7.0.0...cli-tools%2fv8.3.1
153
161
  [7.0.0]: https://github.com/streamr-dev/network/compare/cli-tools%2fv6.1.1...cli-tools%2fv7.0.0
154
162
  [6.1.1]: https://github.com/streamr-dev/network/compare/cli-tools%2fv6.1.0...cli-tools%2fv6.1.1
155
163
  [6.1.0]: https://github.com/streamr-dev/network/compare/cli-tools%2fv6.0.0...cli-tools%2fv6.1.0
@@ -12,7 +12,7 @@ createClientCommand(async (client: StreamrClient, streamIdOrPath: string, option
12
12
  partitions: options.partitions
13
13
  }
14
14
  const stream = await client.createStream(body)
15
- console.info({ id: stream.id, ...stream.getMetadata() }, null, 2)
15
+ console.info(JSON.stringify({ id: stream.id, ...stream.getMetadata() }, null, 2))
16
16
  })
17
17
  .arguments('<streamId>')
18
18
  .description('create a new stream')
@@ -12,7 +12,7 @@ const command_1 = require("../src/command");
12
12
  partitions: options.partitions
13
13
  };
14
14
  const stream = await client.createStream(body);
15
- console.info({ id: stream.id, ...stream.getMetadata() }, null, 2);
15
+ console.info(JSON.stringify({ id: stream.id, ...stream.getMetadata() }, null, 2));
16
16
  })
17
17
  .arguments('<streamId>')
18
18
  .description('create a new stream')
@@ -1 +1 @@
1
- {"version":3,"file":"streamr-stream-create.js","sourceRoot":"","sources":["../../bin/streamr-stream-create.ts"],"names":[],"mappings":";;;AACA,2BAAwB;AAExB,0CAAgD;AAChD,4CAAoD;AAEpD,IAAA,6BAAmB,EAAC,KAAK,EAAE,MAAqB,EAAE,cAAsB,EAAE,OAAY,EAAE,EAAE;IACtF,MAAM,IAAI,GAAQ;QACd,EAAE,EAAE,cAAc;QAClB,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,MAAM,EAAE,OAAO,CAAC,YAAY;QAC5B,UAAU,EAAE,OAAO,CAAC,UAAU;KACjC,CAAA;IACD,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,CAAA;IAC9C,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,GAAG,MAAM,CAAC,WAAW,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;AACrE,CAAC,CAAC;KACG,SAAS,CAAC,YAAY,CAAC;KACvB,WAAW,CAAC,qBAAqB,CAAC;KAClC,MAAM,CAAC,iCAAiC,EAAE,sBAAsB,CAAC;KACjE,MAAM,CAAC,8BAA8B,EAAE,gCAAgC,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;KACtG,MAAM,CAAC,0BAA0B,EAAE,0BAA0B,EAC1D,IAAA,yBAAgB,EAAC,cAAc,CAAC,CAAC;KACpC,UAAU,EAAE,CAAA"}
1
+ {"version":3,"file":"streamr-stream-create.js","sourceRoot":"","sources":["../../bin/streamr-stream-create.ts"],"names":[],"mappings":";;;AACA,2BAAwB;AAExB,0CAAgD;AAChD,4CAAoD;AAEpD,IAAA,6BAAmB,EAAC,KAAK,EAAE,MAAqB,EAAE,cAAsB,EAAE,OAAY,EAAE,EAAE;IACtF,MAAM,IAAI,GAAQ;QACd,EAAE,EAAE,cAAc;QAClB,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,MAAM,EAAE,OAAO,CAAC,YAAY;QAC5B,UAAU,EAAE,OAAO,CAAC,UAAU;KACjC,CAAA;IACD,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,CAAA;IAC9C,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,GAAG,MAAM,CAAC,WAAW,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAA;AACrF,CAAC,CAAC;KACG,SAAS,CAAC,YAAY,CAAC;KACvB,WAAW,CAAC,qBAAqB,CAAC;KAClC,MAAM,CAAC,iCAAiC,EAAE,sBAAsB,CAAC;KACjE,MAAM,CAAC,8BAA8B,EAAE,gCAAgC,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;KACtG,MAAM,CAAC,0BAA0B,EAAE,0BAA0B,EAC1D,IAAA,yBAAgB,EAAC,cAAc,CAAC,CAAC;KACpC,UAAU,EAAE,CAAA"}
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamr/cli-tools",
3
- "version": "8.3.0",
3
+ "version": "8.3.1",
4
4
  "description": "Command line tools for Streamr",
5
5
  "repository": {
6
6
  "type": "git",
@@ -15,7 +15,7 @@
15
15
  "check": "tsc -p ./tsconfig.json --noEmit",
16
16
  "clean": "jest --clearCache || true; rm -rf dist *.tsbuildinfo node_modules/.cache || true",
17
17
  "eslint": "eslint --cache --cache-location=node_modules/.cache/.eslintcache/ '*/**/*.{js,ts}'",
18
- "test": "echo \"Error: no test specified\" && exit 1"
18
+ "test": "npm run build && jest --forceExit"
19
19
  },
20
20
  "keywords": [
21
21
  "streamr",
@@ -28,15 +28,18 @@
28
28
  "dependencies": {
29
29
  "@ethersproject/wallet": "^5.5.0",
30
30
  "@snapshot-labs/snapshot.js": "^0.4.43",
31
- "@streamr/utils": "8.3.0",
31
+ "@streamr/utils": "8.3.1",
32
32
  "commander": "^10.0.1",
33
33
  "easy-table": "^1.1.1",
34
34
  "event-stream": "^4.0.1",
35
35
  "lodash": "^4.17.21",
36
- "streamr-client": "8.3.0"
36
+ "streamr-client": "8.3.1"
37
37
  },
38
38
  "devDependencies": {
39
+ "@streamr/test-utils": "8.3.1",
39
40
  "@types/event-stream": "^4.0.0",
40
- "@types/lodash": "^4.14.175"
41
+ "@types/lodash": "^4.14.175",
42
+ "@types/merge2": "^1.4.0",
43
+ "merge2": "^1.4.1"
41
44
  }
42
45
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamr/cli-tools",
3
- "version": "8.3.0",
3
+ "version": "8.3.1",
4
4
  "description": "Command line tools for Streamr",
5
5
  "repository": {
6
6
  "type": "git",
@@ -15,7 +15,7 @@
15
15
  "check": "tsc -p ./tsconfig.json --noEmit",
16
16
  "clean": "jest --clearCache || true; rm -rf dist *.tsbuildinfo node_modules/.cache || true",
17
17
  "eslint": "eslint --cache --cache-location=node_modules/.cache/.eslintcache/ '*/**/*.{js,ts}'",
18
- "test": "echo \"Error: no test specified\" && exit 1"
18
+ "test": "npm run build && jest --forceExit"
19
19
  },
20
20
  "keywords": [
21
21
  "streamr",
@@ -28,15 +28,18 @@
28
28
  "dependencies": {
29
29
  "@ethersproject/wallet": "^5.5.0",
30
30
  "@snapshot-labs/snapshot.js": "^0.4.43",
31
- "@streamr/utils": "8.3.0",
31
+ "@streamr/utils": "8.3.1",
32
32
  "commander": "^10.0.1",
33
33
  "easy-table": "^1.1.1",
34
34
  "event-stream": "^4.0.1",
35
35
  "lodash": "^4.17.21",
36
- "streamr-client": "8.3.0"
36
+ "streamr-client": "8.3.1"
37
37
  },
38
38
  "devDependencies": {
39
+ "@streamr/test-utils": "8.3.1",
39
40
  "@types/event-stream": "^4.0.0",
40
- "@types/lodash": "^4.14.175"
41
+ "@types/lodash": "^4.14.175",
42
+ "@types/merge2": "^1.4.0",
43
+ "merge2": "^1.4.1"
41
44
  }
42
45
  }
@@ -0,0 +1,19 @@
1
+ import { collect } from '@streamr/utils'
2
+ import 'jest-extended'
3
+ import { startCommand } from './utils'
4
+
5
+ describe('mock-data', () => {
6
+
7
+ it('generate', async () => {
8
+ const abortController = new AbortController()
9
+ const outputIterable = startCommand('mock-data generate', {
10
+ abortSignal: abortController.signal,
11
+ devEnvironment: false
12
+ })
13
+ const firstLine = (await collect(outputIterable, 1))[0]
14
+ abortController.abort()
15
+ const json = JSON.parse(firstLine)
16
+ expect(json).toBeObject()
17
+ })
18
+
19
+ })
@@ -0,0 +1,32 @@
1
+ import { fetchPrivateKeyWithGas } from '@streamr/test-utils'
2
+ import 'jest-extended'
3
+ import { StreamID } from 'streamr-client'
4
+ import { DOCKER_DEV_STORAGE_NODE, createTestClient, runCommand } from './utils'
5
+
6
+ const isStored = async (streamId: StreamID): Promise<boolean> => {
7
+ const output = await runCommand(`storage-node list-streams ${DOCKER_DEV_STORAGE_NODE}`)
8
+ return output.join().includes(streamId)
9
+ }
10
+
11
+ describe('storage node', () => {
12
+
13
+ it('add and remove stream', async () => {
14
+ const privateKey = await fetchPrivateKeyWithGas()
15
+ const client = createTestClient(privateKey)
16
+ const stream = await client.createStream(`/${Date.now()}`)
17
+ await client.destroy()
18
+ await runCommand(`storage-node add-stream ${DOCKER_DEV_STORAGE_NODE} ${stream.id}`, {
19
+ privateKey
20
+ })
21
+ expect(await isStored(stream.id)).toBeTrue()
22
+ await runCommand(`storage-node remove-stream ${DOCKER_DEV_STORAGE_NODE} ${stream.id}`, {
23
+ privateKey
24
+ })
25
+ expect(await isStored(stream.id)).toBeFalse()
26
+ }, 80 * 1000)
27
+
28
+ it('list nodes', async () => {
29
+ const outputLines = await runCommand('storage-node list')
30
+ expect(outputLines[2]).toEqual(DOCKER_DEV_STORAGE_NODE.toLowerCase())
31
+ })
32
+ })
@@ -0,0 +1,26 @@
1
+ import { Wallet } from '@ethersproject/wallet'
2
+ import { fetchPrivateKeyWithGas } from '@streamr/test-utils'
3
+ import { createTestClient, runCommand } from './utils'
4
+
5
+ describe('create stream', () => {
6
+
7
+ it('happy path', async () => {
8
+ const privateKey = await fetchPrivateKeyWithGas()
9
+ const address = new Wallet(privateKey).address.toLowerCase()
10
+ const path = `/${Date.now()}`
11
+ const streamId = `${address}${path}`
12
+ const outputLines = await runCommand(`stream create ${path}`, {
13
+ privateKey
14
+ })
15
+ const outputJson = JSON.parse(outputLines.join(''))
16
+ expect(outputJson).toMatchObject({
17
+ id: streamId,
18
+ partitions: 1
19
+ })
20
+ const client = createTestClient()
21
+ const stream = await client.getStream(streamId)
22
+ expect(stream.getMetadata().partitions).toBe(1)
23
+ await client.destroy()
24
+ }, 20 * 1000)
25
+
26
+ })
@@ -0,0 +1,29 @@
1
+ import { fetchPrivateKeyWithGas, randomEthereumAddress } from '@streamr/test-utils'
2
+ import 'jest-extended'
3
+ import { StreamPermission } from 'streamr-client'
4
+ import { createTestClient, runCommand } from './utils'
5
+
6
+ describe('permission', () => {
7
+
8
+ it('grant and revoke', async () => {
9
+ const privateKey = await fetchPrivateKeyWithGas()
10
+ const client = createTestClient(privateKey)
11
+ const stream = await client.createStream(`/${Date.now()}`)
12
+ const otherUser = randomEthereumAddress()
13
+ const hasPermission = () => client.hasPermission({
14
+ user: otherUser,
15
+ permission: StreamPermission.PUBLISH,
16
+ streamId: stream.id,
17
+ allowPublic: false
18
+ })
19
+ await runCommand(`stream grant-permission ${stream.id} ${otherUser} publish`, {
20
+ privateKey
21
+ })
22
+ expect(await hasPermission()).toBeTrue()
23
+ await runCommand(`stream revoke-permission ${stream.id} ${otherUser} publish`, {
24
+ privateKey
25
+ })
26
+ expect(await hasPermission()).toBeFalse()
27
+ await client.destroy()
28
+ }, 40 * 1000)
29
+ })
@@ -0,0 +1,35 @@
1
+ import { Wallet } from '@ethersproject/wallet'
2
+ import { fetchPrivateKeyWithGas } from '@streamr/test-utils'
3
+ import { collect } from '@streamr/utils'
4
+ import { StreamPermission } from 'streamr-client'
5
+ import { createTestClient, runCommand, startCommand } from './utils'
6
+
7
+ describe('publish and subscribe', () => {
8
+
9
+ it('happy path', async () => {
10
+ const publisherPrivateKey = await fetchPrivateKeyWithGas()
11
+ const subscriberPrivateKey = await fetchPrivateKeyWithGas()
12
+ const client = createTestClient(publisherPrivateKey)
13
+ const stream = await client.createStream(`/${Date.now()}`)
14
+ await stream.grantPermissions({
15
+ user: new Wallet(subscriberPrivateKey).address,
16
+ permissions: [StreamPermission.SUBSCRIBE]
17
+ })
18
+ const subscriberAbortController = new AbortController()
19
+ const subscriberOutputIterable = startCommand(`stream subscribe ${stream.id}`, {
20
+ privateKey: subscriberPrivateKey,
21
+ abortSignal: subscriberAbortController.signal
22
+ })
23
+ setImmediate(async () => {
24
+ await runCommand(`stream publish ${stream.id}`, {
25
+ inputLines: [JSON.stringify({ foo: 123 })],
26
+ privateKey: publisherPrivateKey
27
+ })
28
+ })
29
+ const receivedMessage = (await collect(subscriberOutputIterable, 1))[0]
30
+ subscriberAbortController.abort()
31
+ expect(JSON.parse(receivedMessage)).toEqual({
32
+ foo: 123
33
+ })
34
+ }, 40 * 1000)
35
+ })
@@ -0,0 +1,66 @@
1
+ import { fetchPrivateKeyWithGas } from '@streamr/test-utils'
2
+ import range from 'lodash/range'
3
+ import { Message, Stream } from 'streamr-client'
4
+ import { DOCKER_DEV_STORAGE_NODE, createTestClient, runCommand } from './utils'
5
+ import { wait } from '@streamr/utils'
6
+
7
+ const parseJSONs = (lines: string[]): any[] => {
8
+ return lines.map((line) => JSON.parse(line))
9
+ }
10
+
11
+ describe('resend stream', () => {
12
+
13
+ let privateKey: string
14
+ let stream: Stream
15
+ const messages: Message[] = []
16
+
17
+ beforeAll(async () => {
18
+ privateKey = await fetchPrivateKeyWithGas()
19
+ const client = createTestClient(privateKey)
20
+ stream = await client.createStream(`/${Date.now()}`)
21
+ await stream.addToStorageNode(DOCKER_DEV_STORAGE_NODE)
22
+ for (const msgId of range(10)) {
23
+ await wait(10) // to prevent duplicate timestamps (to make test assertions simpler)
24
+ const msg = await stream.publish({ msgId })
25
+ messages.push(msg)
26
+ }
27
+ await wait(1000)
28
+ await client.destroy()
29
+ }, 20 * 1000)
30
+
31
+ it('last', async () => {
32
+ const outputLines = await runCommand(`stream resend last 3 ${stream.id}`, {
33
+ privateKey
34
+ })
35
+ expect(parseJSONs(outputLines)).toEqual([
36
+ { msgId: 7 },
37
+ { msgId: 8 },
38
+ { msgId: 9 }
39
+ ])
40
+ }, 20 * 1000)
41
+
42
+ it('from', async () => {
43
+ const minTimestamp = new Date(messages[8].timestamp).toISOString()
44
+ const outputLines = await runCommand(`stream resend from ${minTimestamp} ${stream.id}`, {
45
+ privateKey
46
+ })
47
+ expect(parseJSONs(outputLines)).toEqual([
48
+ { msgId: 8 },
49
+ { msgId: 9 }
50
+ ])
51
+ }, 20 * 1000)
52
+
53
+ it('range', async () => {
54
+ const minTimestamp = new Date(messages[2].timestamp).toISOString()
55
+ const maxTimestamp = new Date(messages[4].timestamp).toISOString()
56
+ const outputLines = await runCommand(`stream resend range ${minTimestamp} ${maxTimestamp} ${stream.id}`, {
57
+ privateKey
58
+ })
59
+ expect(parseJSONs(outputLines)).toEqual([
60
+ { msgId: 2 },
61
+ { msgId: 3 },
62
+ { msgId: 4 }
63
+ ])
64
+ }, 20 * 1000)
65
+
66
+ })
@@ -0,0 +1,20 @@
1
+ import { fetchPrivateKeyWithGas } from '@streamr/test-utils'
2
+ import { randomString } from '@streamr/utils'
3
+ import { createTestClient, runCommand } from './utils'
4
+
5
+ describe('search streams', () => {
6
+
7
+ it('happy path', async () => {
8
+ const testId = randomString(10)
9
+ const client = createTestClient(await fetchPrivateKeyWithGas())
10
+ const stream1 = await client.createStream(`/${testId}-1`)
11
+ const stream2 = await client.createStream(`/${testId}-2`)
12
+ await client.destroy()
13
+ const outputLines = await runCommand(`stream search ${testId}`)
14
+ expect(outputLines).toEqual([
15
+ stream1.id,
16
+ stream2.id
17
+ ])
18
+ }, 20 * 1000)
19
+
20
+ })
@@ -0,0 +1,30 @@
1
+ import { Wallet } from '@ethersproject/wallet'
2
+ import { fetchPrivateKeyWithGas } from '@streamr/test-utils'
3
+ import { createTestClient, runCommand } from './utils'
4
+
5
+ describe('show stream', () => {
6
+
7
+ it('happy path', async () => {
8
+ const creatorPrivateKey = await fetchPrivateKeyWithGas()
9
+ const client = createTestClient(creatorPrivateKey)
10
+ const stream = await client.createStream(`/${Date.now()}`)
11
+ await client.destroy()
12
+ const outputLines = await runCommand(`stream show ${stream.id} --include-permissions`)
13
+ const outputJson = JSON.parse(outputLines.join(''))
14
+ expect(outputJson).toMatchObject({
15
+ id: stream.id,
16
+ partitions: 1,
17
+ permissions: [{
18
+ permissions: [
19
+ 'edit',
20
+ 'delete',
21
+ 'publish',
22
+ 'subscribe',
23
+ 'grant'
24
+ ],
25
+ user: new Wallet(creatorPrivateKey).address.toLowerCase()
26
+ }]
27
+ })
28
+ }, 20 * 1000)
29
+
30
+ })
package/test/utils.ts ADDED
@@ -0,0 +1,74 @@
1
+ import { collect } from '@streamr/utils'
2
+ import { spawn } from 'child_process'
3
+ import merge2 from 'merge2'
4
+ import { CONFIG_TEST, StreamrClient } from 'streamr-client'
5
+
6
+ export const DOCKER_DEV_STORAGE_NODE = '0xde1112f631486CfC759A50196853011528bC5FA0'
7
+
8
+ export interface StartCommandOptions {
9
+ privateKey?: string
10
+ devEnvironment?: boolean
11
+ inputLines?: string[]
12
+ abortSignal?: AbortSignal
13
+ }
14
+
15
+ export const runCommand = async (commandLine: string, opts?: StartCommandOptions): Promise<string[]> => {
16
+ const lines = startCommand(commandLine, opts)
17
+ return await collect(lines)
18
+ }
19
+
20
+ export async function* startCommand(commandLine: string, opts?: StartCommandOptions): AsyncGenerator<string> {
21
+ const args: string[] = ['dist/bin/streamr.js']
22
+ args.push(...commandLine.split(' '))
23
+ if (opts?.privateKey !== undefined) {
24
+ args.push('--private-key', opts.privateKey)
25
+ }
26
+ if (opts?.devEnvironment !== false) {
27
+ args.push('--dev')
28
+ }
29
+ const executable = spawn(`node`, args, {
30
+ signal: opts?.abortSignal,
31
+ env: {
32
+ PATH: process.env.PATH
33
+ }
34
+ })
35
+ executable.on('error', (err: any) => {
36
+ // expected error when AbortSignal#abort is called
37
+ if (err.code !== 'ABORT_ERR') {
38
+ console.error(err)
39
+ }
40
+ })
41
+ const outputs = merge2(executable.stdout, executable.stderr)
42
+ if (opts?.inputLines !== undefined) {
43
+ setImmediate(() => {
44
+ executable.stdin.write(opts.inputLines!.join('\n') + '\n')
45
+ })
46
+ }
47
+ yield* lines(outputs[Symbol.asyncIterator]())
48
+ }
49
+
50
+ async function* lines(src: AsyncIterable<Buffer>): AsyncGenerator<string, any, any> {
51
+ let buffer = ''
52
+ for await (const chunk of src) {
53
+ buffer += chunk.toString('utf-8')
54
+ while (true) {
55
+ const delimeterPos = buffer.indexOf('\n')
56
+ if (delimeterPos === -1) {
57
+ break
58
+ }
59
+ const line = buffer.substring(0, delimeterPos)
60
+ yield line
61
+ buffer = buffer.substring(delimeterPos + 1)
62
+ }
63
+ }
64
+ if (buffer !== '') {
65
+ yield buffer
66
+ }
67
+ }
68
+
69
+ export const createTestClient = (privateKey?: string): StreamrClient => {
70
+ return new StreamrClient({
71
+ ...CONFIG_TEST,
72
+ auth: (privateKey !== undefined) ? { privateKey } : undefined
73
+ })
74
+ }
@@ -0,0 +1,11 @@
1
+ import { runCommand } from './utils'
2
+
3
+ describe('wallet', () => {
4
+
5
+ it('whoami', async () => {
6
+ const outputLines = await runCommand('wallet whoami')
7
+ expect(outputLines.length).toBe(1)
8
+ expect(outputLines[0]).toMatch(/^0x[0-9a-f]{40}$/)
9
+ })
10
+
11
+ })