@streamr/cli-tools 4.1.1 → 6.0.0-alpha.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/.eslintignore +2 -0
- package/.eslintrc +6 -0
- package/CHANGELOG.md +41 -2
- package/README.md +58 -30
- package/{src/generate.js → bin/streamr-mock-data-generate.ts} +20 -3
- package/bin/streamr-mock-data.ts +10 -0
- package/bin/streamr-storage-node-add-stream.ts +12 -0
- package/bin/streamr-storage-node-list-stream-parts.ts +22 -0
- package/bin/streamr-storage-node-list.ts +27 -0
- package/bin/streamr-storage-node-remove-stream.ts +12 -0
- package/bin/streamr-storage-node.ts +13 -0
- package/bin/streamr-stream-create.ts +23 -0
- package/bin/streamr-stream-grant-permission.ts +10 -0
- package/bin/streamr-stream-publish.ts +62 -0
- package/bin/streamr-stream-resend-from.ts +26 -0
- package/bin/streamr-stream-resend-last.ts +25 -0
- package/bin/streamr-stream-resend-range.ts +32 -0
- package/bin/streamr-stream-resend.ts +11 -0
- package/bin/streamr-stream-revoke-permission.ts +10 -0
- package/bin/streamr-stream-search.ts +17 -0
- package/bin/streamr-stream-show.ts +20 -0
- package/bin/streamr-stream-subscribe.ts +22 -0
- package/bin/{streamr.js → streamr-stream.ts} +7 -5
- package/bin/streamr.ts +12 -0
- package/dist/bin/streamr-mock-data-generate.d.ts +2 -0
- package/dist/bin/streamr-mock-data-generate.js +47 -0
- package/dist/bin/streamr-mock-data-generate.js.map +1 -0
- package/dist/bin/streamr-mock-data.d.ts +2 -0
- package/dist/bin/streamr-mock-data.js +15 -0
- package/dist/bin/streamr-mock-data.js.map +1 -0
- package/dist/bin/streamr-storage-node-add-stream.d.ts +2 -0
- package/dist/bin/streamr-storage-node-add-stream.js +13 -0
- package/dist/bin/streamr-storage-node-add-stream.js.map +1 -0
- package/dist/bin/streamr-storage-node-list-stream-parts.d.ts +2 -0
- package/dist/bin/streamr-storage-node-list-stream-parts.js +26 -0
- package/dist/bin/streamr-storage-node-list-stream-parts.js.map +1 -0
- package/dist/bin/streamr-storage-node-list.d.ts +2 -0
- package/dist/bin/streamr-storage-node-list.js +31 -0
- package/dist/bin/streamr-storage-node-list.js.map +1 -0
- package/dist/bin/streamr-storage-node-remove-stream.d.ts +2 -0
- package/dist/bin/streamr-storage-node-remove-stream.js +13 -0
- package/dist/bin/streamr-storage-node-remove-stream.js.map +1 -0
- package/dist/bin/streamr-storage-node.d.ts +2 -0
- package/dist/bin/streamr-storage-node.js +18 -0
- package/dist/bin/streamr-storage-node.js.map +1 -0
- package/dist/bin/streamr-stream-create.d.ts +2 -0
- package/dist/bin/streamr-stream-create.js +23 -0
- package/dist/bin/streamr-stream-create.js.map +1 -0
- package/dist/bin/streamr-stream-grant-permission.d.ts +2 -0
- package/dist/bin/streamr-stream-grant-permission.js +7 -0
- package/dist/bin/streamr-stream-grant-permission.js.map +1 -0
- package/dist/bin/streamr-stream-list.d.ts +2 -0
- package/dist/bin/streamr-stream-list.js +34 -0
- package/dist/bin/streamr-stream-list.js.map +1 -0
- package/dist/bin/streamr-stream-publish.d.ts +2 -0
- package/dist/bin/streamr-stream-publish.js +59 -0
- package/dist/bin/streamr-stream-publish.js.map +1 -0
- package/dist/bin/streamr-stream-resend-from.d.ts +2 -0
- package/dist/bin/streamr-stream-resend-from.js +27 -0
- package/dist/bin/streamr-stream-resend-from.js.map +1 -0
- package/dist/bin/streamr-stream-resend-last.d.ts +2 -0
- package/dist/bin/streamr-stream-resend-last.js +26 -0
- package/dist/bin/streamr-stream-resend-last.js.map +1 -0
- package/dist/bin/streamr-stream-resend-range.d.ts +2 -0
- package/dist/bin/streamr-stream-resend-range.js +33 -0
- package/dist/bin/streamr-stream-resend-range.js.map +1 -0
- package/dist/bin/streamr-stream-resend.d.ts +2 -0
- package/dist/bin/streamr-stream-resend.js +13 -0
- package/dist/bin/streamr-stream-resend.js.map +1 -0
- package/dist/bin/streamr-stream-revoke-permission.d.ts +2 -0
- package/dist/bin/streamr-stream-revoke-permission.js +7 -0
- package/dist/bin/streamr-stream-revoke-permission.js.map +1 -0
- package/dist/bin/streamr-stream-search.d.ts +2 -0
- package/dist/bin/streamr-stream-search.js +21 -0
- package/dist/bin/streamr-stream-search.js.map +1 -0
- package/dist/bin/streamr-stream-show.d.ts +2 -0
- package/dist/bin/streamr-stream-show.js +24 -0
- package/dist/bin/streamr-stream-show.js.map +1 -0
- package/dist/bin/streamr-stream-subscribe.d.ts +2 -0
- package/dist/bin/streamr-stream-subscribe.js +23 -0
- package/dist/bin/streamr-stream-subscribe.js.map +1 -0
- package/dist/bin/streamr-stream.d.ts +2 -0
- package/dist/bin/streamr-stream.js +22 -0
- package/dist/bin/streamr-stream.js.map +1 -0
- package/dist/bin/streamr.d.ts +2 -0
- package/dist/bin/streamr.js +17 -0
- package/dist/bin/streamr.js.map +1 -0
- package/dist/package.json +53 -0
- package/dist/src/client.d.ts +3 -0
- package/dist/src/client.js +33 -0
- package/dist/src/client.js.map +1 -0
- package/dist/src/command.d.ts +8 -0
- package/dist/src/command.js +45 -0
- package/dist/src/command.js.map +1 -0
- package/dist/src/common.d.ts +6 -0
- package/dist/src/common.js +15 -0
- package/dist/src/common.js.map +1 -0
- package/dist/src/config.d.ts +6 -0
- package/dist/src/config.js +58 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/logLevel.d.ts +0 -0
- package/dist/src/logLevel.js +11 -0
- package/dist/src/logLevel.js.map +1 -0
- package/dist/src/permission.d.ts +4 -0
- package/dist/src/permission.js +48 -0
- package/dist/src/permission.js.map +1 -0
- package/dist/src/resend.d.ts +3 -0
- package/dist/src/resend.js +33 -0
- package/dist/src/resend.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +25 -12
- package/src/client.ts +32 -0
- package/src/command.ts +45 -0
- package/src/common.ts +16 -0
- package/src/config.ts +56 -0
- package/src/logLevel.ts +9 -0
- package/src/permission.ts +49 -0
- package/src/resend.ts +38 -0
- package/tsconfig.json +15 -0
- package/bin/common.js +0 -79
- package/bin/streamr-create.js +0 -41
- package/bin/streamr-generate.js +0 -14
- package/bin/streamr-list.js +0 -35
- package/bin/streamr-publish.js +0 -28
- package/bin/streamr-resend.js +0 -101
- package/bin/streamr-show.js +0 -19
- package/bin/streamr-subscribe.js +0 -20
- package/src/create.js +0 -14
- package/src/list.js +0 -20
- package/src/publish.js +0 -37
- package/src/resend.js +0 -43
- package/src/show.js +0 -17
- package/src/subscribe.js +0 -9
package/.eslintignore
ADDED
package/.eslintrc
ADDED
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,44 @@ 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
|
|
28
|
+
|
|
29
|
+
## [5.0.0] - 2021-05-05
|
|
30
|
+
### Added
|
|
31
|
+
- Add storage node commands under `streamr storage-node`
|
|
32
|
+
|
|
33
|
+
### Changed
|
|
34
|
+
- (Breaking) Commands are divided to subcommands: most of the existing command are under `streamr stream`, and `generate` command under `streamr mock-data`
|
|
35
|
+
- `streamr subscribe` is now `streamr stream subscribe`
|
|
36
|
+
- `streamr publish` is now `streamr stream publish`
|
|
37
|
+
- `streamr list` is now `streamr stream list`
|
|
38
|
+
- `streamr show` is now `streamr stream show`
|
|
39
|
+
- `streamr create` is now `streamr stream create`
|
|
40
|
+
- `streamr resend` is now `streamr stream resend`
|
|
41
|
+
- `streamr generate` is now `streamr mock-data generate`
|
|
42
|
+
- Fixed examples of --private-key in README
|
|
43
|
+
- Internal implementation was converted to TypeScript
|
|
44
|
+
- Bump dependency streamr-client to 5.2.1
|
|
45
|
+
- Bump dependency commander to 7.2.0
|
|
8
46
|
|
|
9
47
|
## [4.1.1] - 2021-02-11
|
|
10
48
|
### Changed
|
|
@@ -22,7 +60,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
22
60
|
- Ethereum authentication with `--privateKey <key>`. This also enables message signing when publishing messages.
|
|
23
61
|
|
|
24
62
|
### Changed
|
|
25
|
-
-
|
|
63
|
+
- (Breaking) Rename command `listen` to `subscribe`.
|
|
26
64
|
- (Breaking) API key is now given with `--apiKey <key>`. API keys are deprecated. Option `--privateKey` should be preferred.
|
|
27
65
|
|
|
28
66
|
## [3.1.1] - 2020-04-16
|
|
@@ -48,7 +86,8 @@ ordering and gap filling.
|
|
|
48
86
|
- Bump dependency commander to ^4.0.1.
|
|
49
87
|
- Re-organize README.md and a few touches to Developing section paragraphs.
|
|
50
88
|
|
|
51
|
-
[Unreleased]: https://github.com/streamr-dev/cli-tools/compare/
|
|
89
|
+
[Unreleased]: https://github.com/streamr-dev/cli-tools/compare/v5.0.0...HEAD
|
|
90
|
+
[5.0.0]: https://github.com/streamr-dev/cli-tools/compare/v4.1.1...v5.0.0
|
|
52
91
|
[4.1.1]: https://github.com/streamr-dev/cli-tools/compare/v4.1.0...v4.1.1
|
|
53
92
|
[4.1.0]: https://github.com/streamr-dev/cli-tools/compare/v4.0.0...v4.1.0
|
|
54
93
|
[4.0.0]: https://github.com/streamr-dev/cli-tools/compare/v3.1.1...v4.0.0
|
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).
|
|
@@ -18,88 +24,115 @@ npm install -g @streamr/cli-tools
|
|
|
18
24
|
```
|
|
19
25
|
|
|
20
26
|
## Use
|
|
21
|
-
|
|
27
|
+
All commands follow pattern `streamr <command> <subcommand>`, e.g.
|
|
28
|
+
```
|
|
29
|
+
streamr stream subscribe
|
|
30
|
+
streamr mock-data generate
|
|
31
|
+
```
|
|
22
32
|
|
|
23
|
-
|
|
33
|
+
To get a list of all commands simply run `streamr`. To list subcommands run e.g. `streamr stream`
|
|
24
34
|
|
|
25
|
-
Run `streamr
|
|
26
|
-
|
|
35
|
+
Run `streamr <command> <subcommand> --help` to get more information about a a command, its options, and so forth.
|
|
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.
|
|
27
38
|
|
|
28
39
|
### subscribe
|
|
29
40
|
Used to subscribe to a stream and output real-time JSON objects to stdout line-by-line.
|
|
30
41
|
|
|
31
42
|
For example, to subscribe to a public stream such as the tram demo do
|
|
32
43
|
```
|
|
33
|
-
streamr subscribe
|
|
44
|
+
streamr stream subscribe streamr.eth/demos/helsinki-trams
|
|
34
45
|
```
|
|
35
46
|
|
|
36
47
|
To subscribe to a private stream and authenticate with an Ethereum private key:
|
|
37
48
|
|
|
38
49
|
```
|
|
39
|
-
streamr subscribe streamId --
|
|
50
|
+
streamr stream subscribe streamId --private-key <key>
|
|
40
51
|
```
|
|
41
52
|
|
|
42
|
-
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.
|
|
43
|
-
|
|
44
|
-
|
|
45
53
|
### publish
|
|
46
54
|
Used to publish events to a stream from stdin line-by-line. Each line should be a valid JSON object.
|
|
47
55
|
|
|
48
56
|
Example of use:
|
|
49
57
|
```
|
|
50
|
-
streamr publish <streamId> --
|
|
58
|
+
streamr stream publish <streamId> --private-key <key>
|
|
51
59
|
```
|
|
52
60
|
|
|
53
|
-
Flag `--dev` or `--stg` can be enabled for the command to operate on pre-defined development or staging environment.
|
|
54
|
-
|
|
55
61
|
|
|
56
62
|
### generate
|
|
57
63
|
Generate random JSON objects to stdout line-by-line.
|
|
58
64
|
|
|
59
65
|
Useful for generating test data to be published to a stream with `publish`, e.g.:
|
|
60
66
|
```
|
|
61
|
-
streamr generate | streamr publish <streamId> --
|
|
67
|
+
streamr mock-data generate | streamr stream publish <streamId> --private-key <key>
|
|
62
68
|
```
|
|
63
69
|
|
|
64
70
|
### list
|
|
65
71
|
Fetch a list of streams that are accessible to the user authenticated by the private key
|
|
66
72
|
```
|
|
67
|
-
streamr list --
|
|
73
|
+
streamr stream list --private-key <key>
|
|
68
74
|
```
|
|
69
75
|
|
|
70
76
|
### show
|
|
71
77
|
Show detailed information about a specific stream
|
|
72
78
|
```
|
|
73
|
-
streamr show <streamId> --
|
|
79
|
+
streamr stream show <streamId> --private-key <key>
|
|
74
80
|
```
|
|
75
81
|
|
|
76
82
|
### create
|
|
77
83
|
Create a new stream
|
|
78
84
|
```
|
|
79
|
-
streamr create <
|
|
85
|
+
streamr stream create <streamId> --private-key <key>
|
|
86
|
+
```
|
|
87
|
+
E.g.
|
|
88
|
+
```
|
|
89
|
+
streamr stream create /foo/bar
|
|
90
|
+
streamr stream create 0x1234567890123456789012345678901234567890/foobar
|
|
91
|
+
streamr stream create yourdomain.ens/foobar
|
|
80
92
|
```
|
|
81
93
|
|
|
94
|
+
|
|
82
95
|
### resend
|
|
83
96
|
Request a resend of historical data printed as JSON objects to stdout line-by-line.
|
|
84
97
|
|
|
85
98
|
For example, to fetch the 10 latest messages of a public stream such as the tram demo do
|
|
86
99
|
```
|
|
87
|
-
streamr resend last 10
|
|
100
|
+
streamr stream resend last 10 streamr.eth/demos/helsinki-trams
|
|
88
101
|
```
|
|
89
102
|
|
|
90
103
|
|
|
91
104
|
To fetch data starting from a particular date-time
|
|
92
105
|
```
|
|
93
|
-
streamr resend from 2019-05-10T17:00:00 <streamId> --
|
|
106
|
+
streamr stream resend from 2019-05-10T17:00:00 <streamId> --private-key <key>
|
|
94
107
|
```
|
|
95
108
|
|
|
96
109
|
To fetch data between two date-times
|
|
97
110
|
```
|
|
98
|
-
streamr resend range 2019-05-10T17:00:00 2019-05-11T21:00:00 <streamId> --
|
|
111
|
+
streamr stream resend range 2019-05-10T17:00:00 2019-05-11T21:00:00 <streamId> --private-key <key>
|
|
99
112
|
```
|
|
100
113
|
|
|
101
|
-
|
|
114
|
+
#### Configuration
|
|
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.
|
|
102
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
|
+
```
|
|
103
136
|
|
|
104
137
|
### Examples: Piping with subscribe and publish
|
|
105
138
|
|
|
@@ -111,21 +144,21 @@ You can pipe the line-by-line JSON objects output by `subscribe` to
|
|
|
111
144
|
your program written in any language. Just make the program read JSON objects
|
|
112
145
|
from stdin.
|
|
113
146
|
```
|
|
114
|
-
streamr subscribe
|
|
147
|
+
streamr stream subscribe streamr.eth/demos/helsinki-trams | ruby calculate-average-speed.rb
|
|
115
148
|
```
|
|
116
149
|
|
|
117
150
|
#### Publishing to a stream from any programming language
|
|
118
151
|
If your program produces JSON objects to stdout (line-by-line), you can
|
|
119
152
|
redirect it to command `publish` to publish the JSON objects to a stream.
|
|
120
153
|
```
|
|
121
|
-
python printSensorReadingsAsJson.py | streamr publish <streamId> --
|
|
154
|
+
python printSensorReadingsAsJson.py | streamr stream publish <streamId> --private-key <key>
|
|
122
155
|
```
|
|
123
156
|
|
|
124
157
|
#### Transforming streams
|
|
125
158
|
You can also subscribe to a stream, apply a transformation, and then pipe the
|
|
126
159
|
transformed output into another stream.
|
|
127
160
|
```
|
|
128
|
-
streamr subscribe <sourceStream> | ./calculateMovingAverages | streamr publish <destinationStream> --
|
|
161
|
+
streamr stream subscribe <sourceStream> | ./calculateMovingAverages | streamr stream publish <destinationStream> --private-key <key>
|
|
129
162
|
```
|
|
130
163
|
|
|
131
164
|
Same rules apply here as before. Your program should accept line-by-line JSON
|
|
@@ -136,16 +169,11 @@ If you have a working stream in production that you'd also like to use in your
|
|
|
136
169
|
development environment, you can combine the `subscribe` and `publish` commands to effectively copy
|
|
137
170
|
the real-time events.
|
|
138
171
|
```
|
|
139
|
-
streamr subscribe
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
And the same for staging environment:
|
|
143
|
-
```
|
|
144
|
-
streamr subscribe 7wa7APtlTq6EC5iTCBy6dw | streamr publish --stg <streamId> --privateKey <key>
|
|
172
|
+
streamr stream subscribe streamr.eth/demos/helsinki-trams | streamr stream publish --dev <streamId> --private-key <key>
|
|
145
173
|
```
|
|
146
174
|
|
|
147
175
|
## Develop
|
|
148
|
-
This project is a thin wrapper around [streamr-client-javascript](https://github.com/streamr-dev/
|
|
176
|
+
This project is a thin wrapper around [streamr-client-javascript](https://github.com/streamr-dev/network-monorepo/blob/main/packages/client/),
|
|
149
177
|
which does the heavy lifting, while this project concentrates on CLI concerns: parsing and
|
|
150
178
|
passing arguments, stdin/stdout, errors, and so forth.
|
|
151
179
|
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import pkg from '../package.json'
|
|
3
|
+
import { createFnParseInt } from '../src/common'
|
|
4
|
+
import { createCommand } from '../src/command'
|
|
5
|
+
|
|
1
6
|
// From: https://stackoverflow.com/questions/10726909/random-alpha-numeric-string-in-javascript
|
|
2
|
-
function randomString(
|
|
7
|
+
function randomString(
|
|
8
|
+
length: number,
|
|
9
|
+
chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
|
10
|
+
): string {
|
|
3
11
|
let result = ''
|
|
4
12
|
for (let i = length; i > 0; --i) {
|
|
5
13
|
result += chars[Math.floor(Math.random() * chars.length)]
|
|
@@ -7,7 +15,7 @@ function randomString(length, chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDE
|
|
|
7
15
|
return result
|
|
8
16
|
}
|
|
9
17
|
|
|
10
|
-
function genArray(size, elementFn) {
|
|
18
|
+
function genArray<T>(size: number, elementFn: () => T): T[] {
|
|
11
19
|
const arr = []
|
|
12
20
|
for (let i=0; i < size; ++i) {
|
|
13
21
|
arr.push(elementFn())
|
|
@@ -15,7 +23,7 @@ function genArray(size, elementFn) {
|
|
|
15
23
|
return arr
|
|
16
24
|
}
|
|
17
25
|
|
|
18
|
-
|
|
26
|
+
export const generate = (rate: number): void => {
|
|
19
27
|
setInterval(() => {
|
|
20
28
|
console.info(JSON.stringify({
|
|
21
29
|
someText: randomString(64),
|
|
@@ -28,3 +36,12 @@ module.exports = (rate) => {
|
|
|
28
36
|
}))
|
|
29
37
|
}, rate)
|
|
30
38
|
}
|
|
39
|
+
|
|
40
|
+
createCommand()
|
|
41
|
+
.description('generate and print semi-random JSON data to stdout')
|
|
42
|
+
.option('-r, --rate <n>', 'rate in milliseconds', createFnParseInt('--rate'), 500)
|
|
43
|
+
.version(pkg.version)
|
|
44
|
+
.action((options: any) => {
|
|
45
|
+
generate(options.rate)
|
|
46
|
+
})
|
|
47
|
+
.parse()
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import '../src/logLevel'
|
|
3
|
+
import StreamrClient from 'streamr-client'
|
|
4
|
+
import { createClientCommand } from '../src/command'
|
|
5
|
+
|
|
6
|
+
createClientCommand(async (client: StreamrClient, storageNodeAddress: string, streamId: string) => {
|
|
7
|
+
const stream = await client.getStream(streamId)
|
|
8
|
+
await stream.addToStorageNode(storageNodeAddress)
|
|
9
|
+
})
|
|
10
|
+
.arguments('<storageNodeAddress> <streamId>')
|
|
11
|
+
.description('add stream to a storage node')
|
|
12
|
+
.parseAsync()
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import '../src/logLevel'
|
|
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'
|
|
7
|
+
|
|
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
|
+
}))
|
|
20
|
+
.arguments('<storageNodeAddress>')
|
|
21
|
+
.description('list stream parts in a storage node')
|
|
22
|
+
.parseAsync()
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import '../src/logLevel'
|
|
3
|
+
import { StreamrClient } from 'streamr-client'
|
|
4
|
+
import EasyTable from 'easy-table'
|
|
5
|
+
import { createClientCommand } from '../src/command'
|
|
6
|
+
|
|
7
|
+
const getStorageNodes = async (streamId: string | undefined, client: StreamrClient): Promise<string[]> => {
|
|
8
|
+
if (streamId !== undefined) {
|
|
9
|
+
const stream = await client.getStream(streamId)
|
|
10
|
+
return stream.getStorageNodes()
|
|
11
|
+
} else {
|
|
12
|
+
return client.getAllStorageNodes()
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
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
|
+
})
|
|
25
|
+
.description('fetch a list of storage nodes')
|
|
26
|
+
.option('-s, --stream <streamId>', 'only storage nodes which store the given stream (needs authentication)')
|
|
27
|
+
.parseAsync()
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import '../src/logLevel'
|
|
3
|
+
import StreamrClient from 'streamr-client'
|
|
4
|
+
import { createClientCommand } from '../src/command'
|
|
5
|
+
|
|
6
|
+
createClientCommand(async (client: StreamrClient, storageNodeAddress: string, streamId: string) => {
|
|
7
|
+
const stream = await client.getStream(streamId)
|
|
8
|
+
await stream.removeFromStorageNode(storageNodeAddress)
|
|
9
|
+
})
|
|
10
|
+
.arguments('<storageNodeAddress> <streamId>')
|
|
11
|
+
.description('remove stream from a storage node')
|
|
12
|
+
.parseAsync()
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { program } from 'commander'
|
|
3
|
+
import pkg from '../package.json'
|
|
4
|
+
|
|
5
|
+
program
|
|
6
|
+
.version(pkg.version)
|
|
7
|
+
.usage('<command> [<args>]')
|
|
8
|
+
.description('storage node subcommands')
|
|
9
|
+
.command('list', 'list storage nodes')
|
|
10
|
+
.command('add-stream', 'add stream')
|
|
11
|
+
.command('remove-stream', 'remove stream')
|
|
12
|
+
.command('list-stream-parts', 'list stream parts in a storage node')
|
|
13
|
+
.parse()
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import '../src/logLevel'
|
|
3
|
+
import StreamrClient from 'streamr-client'
|
|
4
|
+
import { createFnParseInt } from '../src/common'
|
|
5
|
+
import { createClientCommand } from '../src/command'
|
|
6
|
+
|
|
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>')
|
|
18
|
+
.description('create a new stream')
|
|
19
|
+
.option('-d, --description <description>', 'define a description')
|
|
20
|
+
.option('-c, --stream-config <config>', 'define a configuration as JSON', (s: string) => JSON.parse(s))
|
|
21
|
+
.option('-p, --partitions <count>', 'define a partition count',
|
|
22
|
+
createFnParseInt('--partitions'))
|
|
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
|
+
)
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import '../src/logLevel'
|
|
3
|
+
import { Writable } from 'stream'
|
|
4
|
+
import { StreamrClient } from 'streamr-client'
|
|
5
|
+
import { wait } from 'streamr-test-utils'
|
|
6
|
+
import es from 'event-stream'
|
|
7
|
+
import { createClientCommand } from '../src/command'
|
|
8
|
+
|
|
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) => {
|
|
43
|
+
process.stdin
|
|
44
|
+
.pipe(es.split())
|
|
45
|
+
.pipe(ps)
|
|
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)
|
|
55
|
+
})
|
|
56
|
+
.once('error', (err: any) => reject(err) )
|
|
57
|
+
})
|
|
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()
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import '../src/logLevel'
|
|
3
|
+
import { createCommand } from '../src/command'
|
|
4
|
+
|
|
5
|
+
createCommand()
|
|
6
|
+
.usage('<command> [<args>]')
|
|
7
|
+
.description('request resend of stream and print JSON messages to stdout line-by-line')
|
|
8
|
+
.command('from', 'request messages starting from given date-time')
|
|
9
|
+
.command('last', 'request last N messages')
|
|
10
|
+
.command('range', 'request messages between two given date-times')
|
|
11
|
+
.parse()
|
|
@@ -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.revokeUserPermission(permission, target),
|
|
8
|
+
(stream: Stream, permission: StreamPermission) => stream.revokePublicPermission(permission),
|
|
9
|
+
'revoke'
|
|
10
|
+
)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import '../src/logLevel'
|
|
3
|
+
import EasyTable from 'easy-table'
|
|
4
|
+
import StreamrClient from 'streamr-client'
|
|
5
|
+
import { createClientCommand } from '../src/command'
|
|
6
|
+
|
|
7
|
+
createClientCommand(async (client: StreamrClient, term: string) => {
|
|
8
|
+
const streams = await client.searchStreams(term)
|
|
9
|
+
if (streams.length > 0) {
|
|
10
|
+
console.info(EasyTable.print(streams.map(({id}) => ({
|
|
11
|
+
id
|
|
12
|
+
}))))
|
|
13
|
+
}
|
|
14
|
+
})
|
|
15
|
+
.arguments('<term>')
|
|
16
|
+
.description('search streams')
|
|
17
|
+
.parseAsync()
|