@streamr/cli-tools 5.0.0 → 6.0.0-alpha.2

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.
Files changed (134) hide show
  1. package/.eslintignore +2 -0
  2. package/.eslintrc +6 -0
  3. package/CHANGELOG.md +20 -0
  4. package/README.md +42 -17
  5. package/bin/streamr-mock-data-generate.ts +38 -8
  6. package/bin/streamr-mock-data.ts +1 -1
  7. package/bin/streamr-storage-node-add-stream.ts +8 -22
  8. package/bin/streamr-storage-node-list-stream-parts.ts +18 -30
  9. package/bin/streamr-storage-node-list.ts +17 -36
  10. package/bin/streamr-storage-node-remove-stream.ts +8 -22
  11. package/bin/streamr-storage-node.ts +1 -1
  12. package/bin/streamr-stream-create.ts +17 -29
  13. package/bin/streamr-stream-grant-permission.ts +10 -0
  14. package/bin/streamr-stream-publish.ts +54 -21
  15. package/bin/streamr-stream-resend-from.ts +26 -0
  16. package/bin/streamr-stream-resend-last.ts +25 -0
  17. package/bin/streamr-stream-resend-range.ts +32 -0
  18. package/bin/streamr-stream-resend.ts +7 -102
  19. package/bin/streamr-stream-revoke-permission.ts +10 -0
  20. package/bin/streamr-stream-search.ts +17 -0
  21. package/bin/streamr-stream-show.ts +16 -16
  22. package/bin/streamr-stream-subscribe.ts +16 -16
  23. package/bin/streamr-stream.ts +3 -1
  24. package/bin/streamr.ts +1 -1
  25. package/dist/bin/streamr-mock-data-generate.d.ts +2 -0
  26. package/dist/bin/streamr-mock-data-generate.js +36 -9
  27. package/dist/bin/streamr-mock-data-generate.js.map +1 -0
  28. package/dist/bin/streamr-mock-data.d.ts +2 -0
  29. package/dist/bin/streamr-mock-data.js +2 -1
  30. package/dist/bin/streamr-mock-data.js.map +1 -0
  31. package/dist/bin/streamr-storage-node-add-stream.d.ts +2 -0
  32. package/dist/bin/streamr-storage-node-add-stream.js +9 -20
  33. package/dist/bin/streamr-storage-node-add-stream.js.map +1 -0
  34. package/dist/bin/streamr-storage-node-list-stream-parts.d.ts +2 -0
  35. package/dist/bin/streamr-storage-node-list-stream-parts.js +18 -24
  36. package/dist/bin/streamr-storage-node-list-stream-parts.js.map +1 -0
  37. package/dist/bin/streamr-storage-node-list.d.ts +2 -0
  38. package/dist/bin/streamr-storage-node-list.js +17 -30
  39. package/dist/bin/streamr-storage-node-list.js.map +1 -0
  40. package/dist/bin/streamr-storage-node-remove-stream.d.ts +2 -0
  41. package/dist/bin/streamr-storage-node-remove-stream.js +9 -20
  42. package/dist/bin/streamr-storage-node-remove-stream.js.map +1 -0
  43. package/dist/bin/streamr-storage-node.d.ts +2 -0
  44. package/dist/bin/streamr-storage-node.js +2 -1
  45. package/dist/bin/streamr-storage-node.js.map +1 -0
  46. package/dist/bin/streamr-stream-create.d.ts +2 -0
  47. package/dist/bin/streamr-stream-create.js +15 -23
  48. package/dist/bin/streamr-stream-create.js.map +1 -0
  49. package/dist/bin/streamr-stream-grant-permission.d.ts +2 -0
  50. package/dist/bin/streamr-stream-grant-permission.js +7 -0
  51. package/dist/bin/streamr-stream-grant-permission.js.map +1 -0
  52. package/dist/bin/streamr-stream-list.d.ts +2 -0
  53. package/dist/bin/streamr-stream-list.js +20 -18
  54. package/dist/bin/streamr-stream-list.js.map +1 -0
  55. package/dist/bin/streamr-stream-publish.d.ts +2 -0
  56. package/dist/bin/streamr-stream-publish.js +50 -23
  57. package/dist/bin/streamr-stream-publish.js.map +1 -0
  58. package/dist/bin/streamr-stream-resend-from.d.ts +2 -0
  59. package/dist/bin/streamr-stream-resend-from.js +27 -0
  60. package/dist/bin/streamr-stream-resend-from.js.map +1 -0
  61. package/dist/bin/streamr-stream-resend-last.d.ts +2 -0
  62. package/dist/bin/streamr-stream-resend-last.js +26 -0
  63. package/dist/bin/streamr-stream-resend-last.js.map +1 -0
  64. package/dist/bin/streamr-stream-resend-range.d.ts +2 -0
  65. package/dist/bin/streamr-stream-resend-range.js +33 -0
  66. package/dist/bin/streamr-stream-resend-range.js.map +1 -0
  67. package/dist/bin/streamr-stream-resend.d.ts +2 -0
  68. package/dist/bin/streamr-stream-resend.js +9 -97
  69. package/dist/bin/streamr-stream-resend.js.map +1 -0
  70. package/dist/bin/streamr-stream-revoke-permission.d.ts +2 -0
  71. package/dist/bin/streamr-stream-revoke-permission.js +7 -0
  72. package/dist/bin/streamr-stream-revoke-permission.js.map +1 -0
  73. package/dist/bin/streamr-stream-search.d.ts +2 -0
  74. package/dist/bin/streamr-stream-search.js +21 -0
  75. package/dist/bin/streamr-stream-search.js.map +1 -0
  76. package/dist/bin/streamr-stream-show.d.ts +2 -0
  77. package/dist/bin/streamr-stream-show.js +16 -15
  78. package/dist/bin/streamr-stream-show.js.map +1 -0
  79. package/dist/bin/streamr-stream-subscribe.d.ts +2 -0
  80. package/dist/bin/streamr-stream-subscribe.js +18 -20
  81. package/dist/bin/streamr-stream-subscribe.js.map +1 -0
  82. package/dist/bin/streamr-stream.d.ts +2 -0
  83. package/dist/bin/streamr-stream.js +4 -1
  84. package/dist/bin/streamr-stream.js.map +1 -0
  85. package/dist/bin/streamr.d.ts +2 -0
  86. package/dist/bin/streamr.js +2 -1
  87. package/dist/bin/streamr.js.map +1 -0
  88. package/dist/package.json +20 -9
  89. package/dist/src/client.d.ts +3 -0
  90. package/dist/src/client.js +33 -0
  91. package/dist/src/client.js.map +1 -0
  92. package/dist/src/command.d.ts +8 -0
  93. package/dist/src/command.js +45 -0
  94. package/dist/src/command.js.map +1 -0
  95. package/dist/src/common.d.ts +6 -0
  96. package/dist/src/common.js +15 -0
  97. package/dist/src/common.js.map +1 -0
  98. package/dist/src/config.d.ts +6 -0
  99. package/dist/src/config.js +58 -0
  100. package/dist/src/config.js.map +1 -0
  101. package/dist/src/logLevel.d.ts +0 -0
  102. package/dist/src/logLevel.js +11 -0
  103. package/dist/src/logLevel.js.map +1 -0
  104. package/dist/src/permission.d.ts +4 -0
  105. package/dist/src/permission.js +48 -0
  106. package/dist/src/permission.js.map +1 -0
  107. package/dist/src/resend.d.ts +3 -0
  108. package/dist/src/resend.js +13 -23
  109. package/dist/src/resend.js.map +1 -0
  110. package/dist/tsconfig.tsbuildinfo +1 -0
  111. package/package.json +20 -9
  112. package/src/client.ts +32 -0
  113. package/src/command.ts +45 -0
  114. package/src/common.ts +16 -0
  115. package/src/config.ts +56 -0
  116. package/src/logLevel.ts +9 -0
  117. package/src/permission.ts +49 -0
  118. package/src/resend.ts +22 -27
  119. package/tsconfig.json +13 -12
  120. package/bin/common.ts +0 -91
  121. package/bin/streamr-stream-list.ts +0 -29
  122. package/dist/bin/common.js +0 -76
  123. package/dist/src/create.js +0 -17
  124. package/dist/src/generate.js +0 -31
  125. package/dist/src/list.js +0 -27
  126. package/dist/src/publish.js +0 -35
  127. package/dist/src/show.js +0 -21
  128. package/dist/src/subscribe.js +0 -12
  129. package/src/create.ts +0 -15
  130. package/src/generate.ts +0 -30
  131. package/src/list.ts +0 -21
  132. package/src/publish.ts +0 -38
  133. package/src/show.ts +0 -18
  134. package/src/subscribe.ts +0 -9
package/.eslintignore ADDED
@@ -0,0 +1,2 @@
1
+ node_modules/**
2
+ dist/**
package/.eslintrc ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "extends": "eslint-config-streamr-ts",
3
+ "rules": {
4
+ "no-console": "off"
5
+ }
6
+ }
package/CHANGELOG.md CHANGED
@@ -5,6 +5,26 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
7
  ## [Unreleased]
8
+ - Add permission commands: `stream grant-permission` and `stream revoke-permission`
9
+ - Remove `typescript` and `ts-node` as run-time dependencies
10
+ - (Breaking) Remove `--msg-chain-id` parameter from `stream resend from`
11
+ - (Breaking) `stream create` argument is a stream ID, not a name
12
+ - Support path notation when defining a stream ID
13
+ - (Breaking) Remove `misc get-session-token` command
14
+ - (Breaking) Change permission names and arguments:
15
+ - renamed `--operation` to `--permission` in `stream list`
16
+ - the data format of `permissions` returned by `--include-permissions` of `stream show`
17
+ - enum values updated for all commands: `subscribe`, `publish`, `edit`, `delete` and `grant`
18
+ - (Breaking) Remove `lastUpdated` and `name` columns from `stream list` output
19
+ - (Breaking) Modify configuration management:
20
+ - can read config from `~/.streamr/config/default.json`
21
+ - `--config` argument added
22
+ - `--stg`, `--http-url` and `--ws-url` arguments removed
23
+ - (Breaking) Rename `--config` argument to `--stream-config` in `stream create`
24
+ - (Breaking) Remove `stream list` command
25
+ - Add `stream search` command
26
+ - Bump dependency streamr-client to 6.1.0
27
+ - Bump dependency commander to 8.3.0
8
28
 
9
29
  ## [5.0.0] - 2021-05-05
10
30
  ### Added
package/README.md CHANGED
@@ -1,3 +1,9 @@
1
+ <p align="center">
2
+ <a href="https://streamr.network">
3
+ <img alt="Streamr" src="https://raw.githubusercontent.com/streamr-dev/network-monorepo/main/packages/client/readme-header-img.png" width="1320" />
4
+ </a>
5
+ </p>
6
+
1
7
  # @streamr/cli-tools
2
8
 
3
9
  Command line tool for interacting with [Streamr](https://streamr.network).
@@ -28,12 +34,14 @@ To get a list of all commands simply run `streamr`. To list subcommands run e.g.
28
34
 
29
35
  Run `streamr <command> <subcommand> --help` to get more information about a a command, its options, and so forth.
30
36
 
37
+ If there is a stream parameter in a command, it can be defined as a full id (e.g. `0x1234567890123456789012345678901234567890/foo/bar`) or a path (e.g. `/foo/bar`). If path notation is used, the stream ID is made by prefixing the authenticated Ethereum address (`--private-key <key>`) to the path.
38
+
31
39
  ### subscribe
32
40
  Used to subscribe to a stream and output real-time JSON objects to stdout line-by-line.
33
41
 
34
42
  For example, to subscribe to a public stream such as the tram demo do
35
43
  ```
36
- streamr stream subscribe 7wa7APtlTq6EC5iTCBy6dw
44
+ streamr stream subscribe streamr.eth/demos/helsinki-trams
37
45
  ```
38
46
 
39
47
  To subscribe to a private stream and authenticate with an Ethereum private key:
@@ -42,9 +50,6 @@ To subscribe to a private stream and authenticate with an Ethereum private key:
42
50
  streamr stream subscribe streamId --private-key <key>
43
51
  ```
44
52
 
45
- Flag `--dev` or `--stg` can be enabled for the command to operate on pre-defined development or staging environment. Alternatively, you can give `--ws-url <url>` and `--http-url <url>` to connect to any custom network.
46
-
47
-
48
53
  ### publish
49
54
  Used to publish events to a stream from stdin line-by-line. Each line should be a valid JSON object.
50
55
 
@@ -53,8 +58,6 @@ Example of use:
53
58
  streamr stream publish <streamId> --private-key <key>
54
59
  ```
55
60
 
56
- Flag `--dev` or `--stg` can be enabled for the command to operate on pre-defined development or staging environment.
57
-
58
61
 
59
62
  ### generate
60
63
  Generate random JSON objects to stdout line-by-line.
@@ -79,15 +82,22 @@ streamr stream show <streamId> --private-key <key>
79
82
  ### create
80
83
  Create a new stream
81
84
  ```
82
- streamr stream create <name> --private-key <key>
85
+ streamr stream create <streamId> --private-key <key>
86
+ ```
87
+ E.g.
83
88
  ```
89
+ streamr stream create /foo/bar
90
+ streamr stream create 0x1234567890123456789012345678901234567890/foobar
91
+ streamr stream create yourdomain.ens/foobar
92
+ ```
93
+
84
94
 
85
95
  ### resend
86
96
  Request a resend of historical data printed as JSON objects to stdout line-by-line.
87
97
 
88
98
  For example, to fetch the 10 latest messages of a public stream such as the tram demo do
89
99
  ```
90
- streamr stream resend last 10 7wa7APtlTq6EC5iTCBy6dw
100
+ streamr stream resend last 10 streamr.eth/demos/helsinki-trams
91
101
  ```
92
102
 
93
103
 
@@ -101,8 +111,28 @@ To fetch data between two date-times
101
111
  streamr stream resend range 2019-05-10T17:00:00 2019-05-11T21:00:00 <streamId> --private-key <key>
102
112
  ```
103
113
 
104
- Flag `--dev` or `--stg` can be enabled for the command to operate on pre-defined development or staging environment.
114
+ #### Configuration
105
115
 
116
+ User can specify environment and authentication details with the following command line arguments:
117
+ - `--private-key <key>`, e.g. `--private-key 0x1234567890123456789012345678901234567890123456789012345678901234`
118
+ - `--config <file>`, e.g. `--config foobar.json`
119
+ - `--dev` use the pre-defined [development environment](https://github.com/streamr-dev/streamr-docker-dev)
120
+
121
+ The `--config` argument tries to read a configuration file from the current working directory (either without a file extension, or with `.json` extension added). It also tries to read it from `~/.streamr/config/${id}.json` dotfile.
122
+
123
+ If no `--config` argument is specified, default settings are read from `~/.streamr/config/default.json`, if that file exists.
124
+
125
+ The configuration file is a JSON. It has one root-level property `client`, which contains any configuration properties for the [streamr-client-javascript](https://github.com/streamr-dev/network-monorepo/blob/main/packages/client/) client. Example:
126
+ ```
127
+ {
128
+ "client": {
129
+ "auth": {
130
+ "privateKey": ...
131
+ },
132
+ "publishWithSignature": "always"
133
+ }
134
+ }
135
+ ```
106
136
 
107
137
  ### Examples: Piping with subscribe and publish
108
138
 
@@ -114,7 +144,7 @@ You can pipe the line-by-line JSON objects output by `subscribe` to
114
144
  your program written in any language. Just make the program read JSON objects
115
145
  from stdin.
116
146
  ```
117
- streamr stream subscribe 7wa7APtlTq6EC5iTCBy6dw | ruby calculate-average-speed.rb
147
+ streamr stream subscribe streamr.eth/demos/helsinki-trams | ruby calculate-average-speed.rb
118
148
  ```
119
149
 
120
150
  #### Publishing to a stream from any programming language
@@ -139,16 +169,11 @@ If you have a working stream in production that you'd also like to use in your
139
169
  development environment, you can combine the `subscribe` and `publish` commands to effectively copy
140
170
  the real-time events.
141
171
  ```
142
- streamr stream subscribe 7wa7APtlTq6EC5iTCBy6dw | streamr stream publish --dev <streamId> --private-key <key>
143
- ```
144
-
145
- And the same for staging environment:
146
- ```
147
- streamr stream subscribe 7wa7APtlTq6EC5iTCBy6dw | streamr stream publish --stg <streamId> --private-key <key>
172
+ streamr stream subscribe streamr.eth/demos/helsinki-trams | streamr stream publish --dev <streamId> --private-key <key>
148
173
  ```
149
174
 
150
175
  ## Develop
151
- This project is a thin wrapper around [streamr-client-javascript](https://github.com/streamr-dev/streamr-client-javascript),
176
+ This project is a thin wrapper around [streamr-client-javascript](https://github.com/streamr-dev/network-monorepo/blob/main/packages/client/),
152
177
  which does the heavy lifting, while this project concentrates on CLI concerns: parsing and
153
178
  passing arguments, stdin/stdout, errors, and so forth.
154
179
 
@@ -1,17 +1,47 @@
1
1
  #!/usr/bin/env node
2
- import { Command } from 'commander';
3
- import { generate } from '../src/generate'
4
- import { exitWithHelpIfArgsNotBetween, createFnParseInt } from './common'
5
2
  import pkg from '../package.json'
3
+ import { createFnParseInt } from '../src/common'
4
+ import { createCommand } from '../src/command'
6
5
 
7
- const program = new Command();
8
- program
6
+ // From: https://stackoverflow.com/questions/10726909/random-alpha-numeric-string-in-javascript
7
+ function randomString(
8
+ length: number,
9
+ chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
10
+ ): string {
11
+ let result = ''
12
+ for (let i = length; i > 0; --i) {
13
+ result += chars[Math.floor(Math.random() * chars.length)]
14
+ }
15
+ return result
16
+ }
17
+
18
+ function genArray<T>(size: number, elementFn: () => T): T[] {
19
+ const arr = []
20
+ for (let i=0; i < size; ++i) {
21
+ arr.push(elementFn())
22
+ }
23
+ return arr
24
+ }
25
+
26
+ export const generate = (rate: number): void => {
27
+ setInterval(() => {
28
+ console.info(JSON.stringify({
29
+ someText: randomString(64),
30
+ aNumber: Math.random() * 10000,
31
+ bNumber: Math.random(),
32
+ yesOrNo: Math.random() > 0.5,
33
+ arrayOfStrings: genArray(Math.floor(Math.random() * 20), () => randomString(8)),
34
+ arrayOfIntegers: genArray(Math.floor(Math.random() * 10), () => Math.floor(Math.random() * 100))
35
+
36
+ }))
37
+ }, rate)
38
+ }
39
+
40
+ createCommand()
9
41
  .description('generate and print semi-random JSON data to stdout')
10
42
  .option('-r, --rate <n>', 'rate in milliseconds', createFnParseInt('--rate'), 500)
11
43
  .version(pkg.version)
12
44
  .action((options: any) => {
13
45
  generate(options.rate)
14
46
  })
15
- .parse(process.argv)
16
-
17
- exitWithHelpIfArgsNotBetween(program, 0, 0)
47
+ .parse()
@@ -7,4 +7,4 @@ program
7
7
  .usage('<command> [<args>]')
8
8
  .description('mock-data subcommands')
9
9
  .command('generate', 'generate JSON data')
10
- .parse(process.argv)
10
+ .parse()
@@ -1,26 +1,12 @@
1
1
  #!/usr/bin/env node
2
- import { Command } from 'commander';
3
- import { StreamrClient, Stream } from 'streamr-client'
4
- import {
5
- envOptions,
6
- authOptions,
7
- exitWithHelpIfArgsNotBetween,
8
- formStreamrOptionsWithEnv,
9
- } from './common'
10
- import pkg from '../package.json'
2
+ import '../src/logLevel'
3
+ import StreamrClient from 'streamr-client'
4
+ import { createClientCommand } from '../src/command'
11
5
 
12
- const program = new Command();
13
- program
6
+ createClientCommand(async (client: StreamrClient, storageNodeAddress: string, streamId: string) => {
7
+ const stream = await client.getStream(streamId)
8
+ await stream.addToStorageNode(storageNodeAddress)
9
+ })
14
10
  .arguments('<storageNodeAddress> <streamId>')
15
11
  .description('add stream to a storage node')
16
- authOptions(program)
17
- envOptions(program)
18
- .version(pkg.version)
19
- .action((storageNodeAddress: string, streamId: string, options: any) => {
20
- const client = new StreamrClient(formStreamrOptionsWithEnv(options))
21
- client.getStream(streamId)
22
- .then((stream: Stream) => stream.addToStorageNode(storageNodeAddress))
23
- })
24
- .parse(process.argv)
25
-
26
- exitWithHelpIfArgsNotBetween(program, 2, 2)
12
+ .parseAsync()
@@ -1,34 +1,22 @@
1
1
  #!/usr/bin/env node
2
- import { Command } from 'commander';
3
- import { StreamrClient, StreamPart } from 'streamr-client'
4
- import {
5
- envOptions,
6
- authOptions,
7
- exitWithHelpIfArgsNotBetween,
8
- formStreamrOptionsWithEnv,
9
- } from './common'
10
- import pkg from '../package.json'
2
+ import '../src/logLevel'
11
3
  import EasyTable from 'easy-table'
4
+ import StreamrClient from 'streamr-client'
5
+ import { createClientCommand } from '../src/command'
6
+ import { StreamPartIDUtils } from 'streamr-client-protocol'
12
7
 
13
- const program = new Command();
14
- program
8
+ createClientCommand((async (client: StreamrClient, storageNodeAddress: string) => {
9
+ const streamParts = await client.getStreamPartsByStorageNode(storageNodeAddress)
10
+ if (streamParts.length > 0) {
11
+ console.info(EasyTable.print(streamParts.map((streamPartId) => {
12
+ const [streamId, streamPartition] = StreamPartIDUtils.getStreamIDAndPartition(streamPartId)
13
+ return {
14
+ streamId,
15
+ streamPartition
16
+ }
17
+ })))
18
+ }
19
+ }))
15
20
  .arguments('<storageNodeAddress>')
16
- .description('list streams parts in a storage node')
17
- authOptions(program)
18
- envOptions(program)
19
- .version(pkg.version)
20
- .action((storageNodeAddress: string, options: any) => {
21
- const client = new StreamrClient(formStreamrOptionsWithEnv(options))
22
- client.getStreamPartsByStorageNode(storageNodeAddress)
23
- .then((streamParts: StreamPart[]) => {
24
- if (streamParts.length > 0) {
25
- console.info(EasyTable.print(streamParts.map((streamPart: StreamPart) => ({
26
- streamId: streamPart.getStreamId(),
27
- streamPartition: streamPart.getStreamPartition()
28
- }))))
29
- }
30
- })
31
- })
32
- .parse(process.argv)
33
-
34
- exitWithHelpIfArgsNotBetween(program, 1, 1)
21
+ .description('list stream parts in a storage node')
22
+ .parseAsync()
@@ -1,46 +1,27 @@
1
1
  #!/usr/bin/env node
2
- import { Command } from 'commander';
3
- import { StreamrClient, StreamPart } from 'streamr-client'
4
- import {
5
- envOptions,
6
- authOptions,
7
- exitWithHelpIfArgsNotBetween,
8
- formStreamrOptionsWithEnv,
9
- } from './common'
10
- import pkg from '../package.json'
2
+ import '../src/logLevel'
3
+ import { StreamrClient } from 'streamr-client'
11
4
  import EasyTable from 'easy-table'
5
+ import { createClientCommand } from '../src/command'
12
6
 
13
- const getStorageNodes = async (streamId: string|undefined, client: StreamrClient) => {
7
+ const getStorageNodes = async (streamId: string | undefined, client: StreamrClient): Promise<string[]> => {
14
8
  if (streamId !== undefined) {
15
- return client.getStream(streamId)
16
- .then(stream => stream.getStorageNodes())
17
- .then(storegeNodes => {
18
- return storegeNodes.map(storageNode => storageNode.getAddress())
19
- })
9
+ const stream = await client.getStream(streamId)
10
+ return stream.getStorageNodes()
20
11
  } else {
21
- // all storage nodes (currently there is only one)
22
- // @ts-expect-error
23
- return [client.options.storageNode.address]
12
+ return client.getAllStorageNodes()
24
13
  }
25
14
  }
26
15
 
27
- const program = new Command();
28
- program
16
+ createClientCommand(async (client: StreamrClient, options: any) => {
17
+ const streamId = options.stream
18
+ const addresses = await getStorageNodes(streamId, client)
19
+ if (addresses.length > 0) {
20
+ console.info(EasyTable.print(addresses.map((address: string) => ({
21
+ address
22
+ }))))
23
+ }
24
+ })
29
25
  .description('fetch a list of storage nodes')
30
26
  .option('-s, --stream <streamId>', 'only storage nodes which store the given stream (needs authentication)')
31
- authOptions(program)
32
- envOptions(program)
33
- .version(pkg.version)
34
- .action((options: any) => {
35
- const client = new StreamrClient(formStreamrOptionsWithEnv(options))
36
- getStorageNodes(options.stream, client).then((addresses: string[]) => {
37
- if (addresses.length > 0) {
38
- console.info(EasyTable.print(addresses.map((address: string) => ({
39
- address
40
- }))))
41
- }
42
- })
43
- })
44
- .parse(process.argv)
45
-
46
- exitWithHelpIfArgsNotBetween(program, 0, 0)
27
+ .parseAsync()
@@ -1,26 +1,12 @@
1
1
  #!/usr/bin/env node
2
- import { Command } from 'commander';
3
- import { StreamrClient, Stream } from 'streamr-client'
4
- import {
5
- envOptions,
6
- authOptions,
7
- exitWithHelpIfArgsNotBetween,
8
- formStreamrOptionsWithEnv,
9
- } from './common'
10
- import pkg from '../package.json'
2
+ import '../src/logLevel'
3
+ import StreamrClient from 'streamr-client'
4
+ import { createClientCommand } from '../src/command'
11
5
 
12
- const program = new Command();
13
- program
6
+ createClientCommand(async (client: StreamrClient, storageNodeAddress: string, streamId: string) => {
7
+ const stream = await client.getStream(streamId)
8
+ await stream.removeFromStorageNode(storageNodeAddress)
9
+ })
14
10
  .arguments('<storageNodeAddress> <streamId>')
15
11
  .description('remove stream from a storage node')
16
- authOptions(program)
17
- envOptions(program)
18
- .version(pkg.version)
19
- .action((storageNodeAddress: string, streamId: string, options: any) => {
20
- const client = new StreamrClient(formStreamrOptionsWithEnv(options))
21
- client.getStream(streamId)
22
- .then((stream: Stream) => stream.removeFromStorageNode(storageNodeAddress))
23
- })
24
- .parse(process.argv)
25
-
26
- exitWithHelpIfArgsNotBetween(program, 2, 2)
12
+ .parseAsync()
@@ -10,4 +10,4 @@ program
10
10
  .command('add-stream', 'add stream')
11
11
  .command('remove-stream', 'remove stream')
12
12
  .command('list-stream-parts', 'list stream parts in a storage node')
13
- .parse(process.argv)
13
+ .parse()
@@ -1,35 +1,23 @@
1
1
  #!/usr/bin/env node
2
- import { Command } from 'commander';
3
- import { create } from '../src/create'
4
- import {
5
- envOptions,
6
- authOptions,
7
- exitWithHelpIfArgsNotBetween,
8
- formStreamrOptionsWithEnv,
9
- createFnParseInt
10
- } from './common'
11
- import pkg from '../package.json'
2
+ import '../src/logLevel'
3
+ import StreamrClient from 'streamr-client'
4
+ import { createFnParseInt } from '../src/common'
5
+ import { createClientCommand } from '../src/command'
12
6
 
13
- const program = new Command();
14
- program
15
- .arguments('<name>')
7
+ createClientCommand(async (client: StreamrClient, streamIdOrPath: string, options: any) => {
8
+ const body: any = {
9
+ id: streamIdOrPath,
10
+ description: options.description,
11
+ config: options.streamConfig,
12
+ partitions: options.partitions
13
+ }
14
+ const stream = await client.createStream(body)
15
+ console.info(JSON.stringify(stream.toObject(), null, 2))
16
+ })
17
+ .arguments('<streamId>')
16
18
  .description('create a new stream')
17
19
  .option('-d, --description <description>', 'define a description')
18
- .option('-c, --config <config>', 'define a configuration as JSON', (s: string) => JSON.parse(s))
20
+ .option('-c, --stream-config <config>', 'define a configuration as JSON', (s: string) => JSON.parse(s))
19
21
  .option('-p, --partitions <count>', 'define a partition count',
20
22
  createFnParseInt('--partitions'))
21
- authOptions(program)
22
- envOptions(program)
23
- .version(pkg.version)
24
- .action((name: string, options: any) => {
25
- const body: any = {
26
- name,
27
- description: options.description,
28
- config: options.config,
29
- partitions: options.partitions
30
- }
31
- create(body, formStreamrOptionsWithEnv(options))
32
- })
33
- .parse(process.argv)
34
-
35
- exitWithHelpIfArgsNotBetween(program, 1, 1)
23
+ .parseAsync()
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ import '../src/logLevel'
3
+ import { Stream, StreamPermission } from 'streamr-client'
4
+ import { runModifyPermissionsCommand } from '../src/permission'
5
+
6
+ runModifyPermissionsCommand(
7
+ (stream: Stream, permission: StreamPermission, target: string) => stream.grantUserPermission(permission, target),
8
+ (stream: Stream, permission: StreamPermission) => stream.grantPublicPermission(permission),
9
+ 'grant'
10
+ )
@@ -1,29 +1,62 @@
1
1
  #!/usr/bin/env node
2
- import { Command } from 'commander';
2
+ import '../src/logLevel'
3
+ import { Writable } from 'stream'
4
+ import { StreamrClient } from 'streamr-client'
5
+ import { wait } from 'streamr-test-utils'
3
6
  import es from 'event-stream'
4
- import { publishStream } from '../src/publish'
5
- import { envOptions, authOptions, exitWithHelpIfArgsNotBetween, formStreamrOptionsWithEnv } from './common'
6
- import pkg from '../package.json'
7
+ import { createClientCommand } from '../src/command'
7
8
 
8
- const program = new Command();
9
- program
10
- .arguments('<streamId>')
11
- .description('publish to a stream by reading JSON messages from stdin line-by-line')
12
- .option('-k, --partition-key <string>', 'field name in each message to use for assigning the message to a stream partition')
13
- authOptions(program)
14
- envOptions(program)
15
- .version(pkg.version)
16
- .action((streamId: string, options: any) => {
17
- const ps = publishStream(streamId, options.partitionKey, formStreamrOptionsWithEnv(options))
9
+ const publishStream = (
10
+ stream: string,
11
+ partitionKey: string | undefined,
12
+ client: StreamrClient
13
+ ): Writable => {
14
+ const writable = new Writable({
15
+ objectMode: true,
16
+ write: (data: any, _: any, done: any) => {
17
+ let json = null
18
+ // ignore newlines, etc
19
+ if (!data || String(data).trim() === '') {
20
+ done()
21
+ return
22
+ }
23
+ try {
24
+ json = JSON.parse(data)
25
+ } catch (e) {
26
+ console.error(data.toString())
27
+ done(e)
28
+ return
29
+ }
30
+ // @ts-expect-error TODO: the last argument here looks wrong, should be just `partitionKey`?
31
+ client.publish(stream, json, Date.now(), json[partitionKey]).then(
32
+ () => done(),
33
+ (err) => done(err)
34
+ )
35
+ }
36
+ })
37
+ return writable
38
+ }
39
+
40
+ createClientCommand(async (client: StreamrClient, streamId: string, options: any) => {
41
+ const ps = publishStream(streamId, options.partitionKey, client)
42
+ return new Promise((resolve, reject) => {
18
43
  process.stdin
19
44
  .pipe(es.split())
20
45
  .pipe(ps)
21
- .on('error', (err: any) => {
22
- console.error(err)
23
- process.exit(1)
24
- // process.stdin.pipe(ps) recover pipe to continue execution
46
+ .once('finish', async () => {
47
+ // We need to wait some time because the client.publish() may resolve the promise
48
+ // before the node has propagated the message. That may happend if the node
49
+ // has not yet connected to Tracker when client.publish() is called. In that case
50
+ // the message is put to the propagation queue (activeTaskStore.add call in
51
+ // network Propagation.ts:59) and the client.publish() promise resolves immeditatelly.
52
+ // TODO Remove this wait when NET-604 has been resolved
53
+ await wait(2000)
54
+ resolve(undefined)
25
55
  })
56
+ .once('error', (err: any) => reject(err) )
26
57
  })
27
- .parse(process.argv)
28
-
29
- exitWithHelpIfArgsNotBetween(program, 1, 1)
58
+ })
59
+ .arguments('<streamId>')
60
+ .description('publish to a stream by reading JSON messages from stdin line-by-line')
61
+ .option('-k, --partition-key <string>', 'field name in each message to use for assigning the message to a stream partition')
62
+ .parseAsync()
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env node
2
+ import '../src/logLevel'
3
+ import StreamrClient from 'streamr-client'
4
+ import { createClientCommand } from '../src/command'
5
+ import { resend } from '../src/resend'
6
+
7
+ createClientCommand(async (client: StreamrClient, from: string, streamId: string, options: any) => {
8
+ const resendOptions = {
9
+ from: {
10
+ timestamp: Date.parse(from),
11
+ sequenceNumber: 0
12
+ },
13
+ publisherId: options.publisherId
14
+ }
15
+ await resend(streamId, resendOptions, client, options.subscribe)
16
+ }, {
17
+ clientOptionsFactory: (options) => ({
18
+ orderMessages: !options.disableOrdering
19
+ })
20
+ })
21
+ .arguments('<from> <streamId>')
22
+ .description('request messages starting from given date-time (format: "YYYY-MM-DDTHH:mm:ss.sssZ")')
23
+ .option('--publisher-id <string>', 'filter results by publisher')
24
+ .option('-d, --disable-ordering', 'disable ordering of messages by OrderingUtil', false)
25
+ .option('-s, --subscribe', 'subscribe in addition to resend', false)
26
+ .parseAsync()
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env node
2
+ import '../src/logLevel'
3
+ import StreamrClient from 'streamr-client'
4
+ import { createClientCommand } from '../src/command'
5
+ import { resend } from '../src/resend'
6
+
7
+ createClientCommand(async (client: StreamrClient, n: string, streamId: string, options: any) => {
8
+ if (isNaN(n as any)) {
9
+ console.error('argument n is not a number')
10
+ process.exit(1)
11
+ }
12
+ const resendOptions = {
13
+ last: parseInt(n)
14
+ }
15
+ await resend(streamId, resendOptions, client, options.subscribe)
16
+ }, {
17
+ clientOptionsFactory: (options) => ({
18
+ orderMessages: !options.disableOrdering
19
+ })
20
+ })
21
+ .arguments('<n> <streamId>')
22
+ .description('request last N messages')
23
+ .option('-d, --disable-ordering', 'disable ordering of messages by OrderingUtil', false)
24
+ .option('-s, --subscribe', 'subscribe in addition to resend', false)
25
+ .parseAsync()
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env node
2
+ import '../src/logLevel'
3
+ import { StreamrClient } from 'streamr-client'
4
+ import { createClientCommand } from '../src/command'
5
+ import { assertBothOrNoneDefined, resend } from '../src/resend'
6
+
7
+ createClientCommand(async (client: StreamrClient, from: string, to: string, streamId: string, options: any) => {
8
+ const resendOptions = {
9
+ from: {
10
+ timestamp: Date.parse(from),
11
+ sequenceNumber: 0
12
+ },
13
+ to: {
14
+ timestamp: Date.parse(to),
15
+ sequenceNumber: 0
16
+ },
17
+ publisherId: options.publisherId,
18
+ msgChainId: options.msgChainId
19
+ }
20
+ assertBothOrNoneDefined('publisherId', 'msgChainId', '--publisher-id must be accompanied by option --msg-chain-id', options)
21
+ await resend(streamId, resendOptions, client, false)
22
+ }, {
23
+ clientOptionsFactory: (options) => ({
24
+ orderMessages: !options.disableOrdering
25
+ })
26
+ })
27
+ .arguments('<from> <to> <streamId>')
28
+ .description('request messages between two given date-times (format: "YYYY-MM-DDTHH:mm:ss.sssZ")')
29
+ .option('--publisher-id <string>', 'filter results by publisher')
30
+ .option('--msg-chain-id <string>', 'filter results by message chain')
31
+ .option('-d, --disable-ordering', 'disable ordering of messages by OrderingUtil', false)
32
+ .parseAsync()