@streamr/cli-tools 4.1.0 → 6.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/.eslintignore +3 -0
  2. package/.eslintrc +6 -0
  3. package/CHANGELOG.md +37 -3
  4. package/README.md +52 -27
  5. package/bin/common.ts +94 -0
  6. package/bin/streamr-misc-get-session-token.ts +33 -0
  7. package/bin/streamr-misc.ts +10 -0
  8. package/bin/streamr-mock-data-generate.ts +17 -0
  9. package/bin/streamr-mock-data.ts +10 -0
  10. package/bin/streamr-storage-node-add-stream.ts +32 -0
  11. package/bin/streamr-storage-node-list-stream-parts.ts +38 -0
  12. package/bin/streamr-storage-node-list.ts +52 -0
  13. package/bin/streamr-storage-node-remove-stream.ts +32 -0
  14. package/bin/streamr-storage-node.ts +13 -0
  15. package/bin/streamr-stream-create.ts +35 -0
  16. package/bin/streamr-stream-grant-permission.ts +69 -0
  17. package/bin/streamr-stream-list.ts +33 -0
  18. package/bin/streamr-stream-publish.ts +30 -0
  19. package/bin/streamr-stream-resend.ts +99 -0
  20. package/bin/streamr-stream-revoke-permission.ts +28 -0
  21. package/bin/streamr-stream-show.ts +21 -0
  22. package/bin/streamr-stream-subscribe.ts +23 -0
  23. package/bin/{streamr.js → streamr-stream.ts} +6 -4
  24. package/bin/streamr.ts +13 -0
  25. package/dist/bin/common.d.ts +16 -0
  26. package/dist/bin/common.js +80 -0
  27. package/dist/bin/common.js.map +1 -0
  28. package/dist/bin/streamr-misc-get-session-token.d.ts +2 -0
  29. package/dist/bin/streamr-misc-get-session-token.js +33 -0
  30. package/dist/bin/streamr-misc-get-session-token.js.map +1 -0
  31. package/dist/bin/streamr-misc.d.ts +2 -0
  32. package/dist/bin/streamr-misc.js +15 -0
  33. package/dist/bin/streamr-misc.js.map +1 -0
  34. package/dist/bin/streamr-mock-data-generate.d.ts +2 -0
  35. package/dist/bin/streamr-mock-data-generate.js +21 -0
  36. package/dist/bin/streamr-mock-data-generate.js.map +1 -0
  37. package/dist/bin/streamr-mock-data.d.ts +2 -0
  38. package/dist/bin/streamr-mock-data.js +15 -0
  39. package/dist/bin/streamr-mock-data.js.map +1 -0
  40. package/dist/bin/streamr-storage-node-add-stream.d.ts +2 -0
  41. package/dist/bin/streamr-storage-node-add-stream.js +30 -0
  42. package/dist/bin/streamr-storage-node-add-stream.js.map +1 -0
  43. package/dist/bin/streamr-storage-node-list-stream-parts.d.ts +2 -0
  44. package/dist/bin/streamr-storage-node-list-stream-parts.js +37 -0
  45. package/dist/bin/streamr-storage-node-list-stream-parts.js.map +1 -0
  46. package/dist/bin/streamr-storage-node-list.d.ts +2 -0
  47. package/dist/bin/streamr-storage-node-list.js +48 -0
  48. package/dist/bin/streamr-storage-node-list.js.map +1 -0
  49. package/dist/bin/streamr-storage-node-remove-stream.d.ts +2 -0
  50. package/dist/bin/streamr-storage-node-remove-stream.js +30 -0
  51. package/dist/bin/streamr-storage-node-remove-stream.js.map +1 -0
  52. package/dist/bin/streamr-storage-node.d.ts +2 -0
  53. package/dist/bin/streamr-storage-node.js +18 -0
  54. package/dist/bin/streamr-storage-node.js.map +1 -0
  55. package/dist/bin/streamr-stream-create.d.ts +2 -0
  56. package/dist/bin/streamr-stream-create.js +32 -0
  57. package/dist/bin/streamr-stream-create.js.map +1 -0
  58. package/dist/bin/streamr-stream-grant-permission.d.ts +2 -0
  59. package/dist/bin/streamr-stream-grant-permission.js +68 -0
  60. package/dist/bin/streamr-stream-grant-permission.js.map +1 -0
  61. package/dist/bin/streamr-stream-list.d.ts +2 -0
  62. package/dist/bin/streamr-stream-list.js +37 -0
  63. package/dist/bin/streamr-stream-list.js.map +1 -0
  64. package/dist/bin/streamr-stream-publish.d.ts +2 -0
  65. package/dist/bin/streamr-stream-publish.js +34 -0
  66. package/dist/bin/streamr-stream-publish.js.map +1 -0
  67. package/dist/bin/streamr-stream-resend.d.ts +2 -0
  68. package/dist/bin/streamr-stream-resend.js +95 -0
  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 +26 -0
  72. package/dist/bin/streamr-stream-revoke-permission.js.map +1 -0
  73. package/dist/bin/streamr-stream-show.d.ts +2 -0
  74. package/dist/bin/streamr-stream-show.js +25 -0
  75. package/dist/bin/streamr-stream-show.js.map +1 -0
  76. package/dist/bin/streamr-stream-subscribe.d.ts +2 -0
  77. package/dist/bin/streamr-stream-subscribe.js +27 -0
  78. package/dist/bin/streamr-stream-subscribe.js.map +1 -0
  79. package/dist/bin/streamr-stream.d.ts +2 -0
  80. package/dist/bin/streamr-stream.js +22 -0
  81. package/dist/bin/streamr-stream.js.map +1 -0
  82. package/dist/bin/streamr.d.ts +2 -0
  83. package/dist/bin/streamr.js +18 -0
  84. package/dist/bin/streamr.js.map +1 -0
  85. package/dist/package.json +50 -0
  86. package/dist/src/create.d.ts +2 -0
  87. package/dist/src/create.js +20 -0
  88. package/dist/src/create.js.map +1 -0
  89. package/dist/src/generate.d.ts +1 -0
  90. package/dist/src/generate.js +32 -0
  91. package/dist/src/generate.js.map +1 -0
  92. package/dist/src/list.d.ts +2 -0
  93. package/dist/src/list.js +29 -0
  94. package/dist/src/list.js.map +1 -0
  95. package/dist/src/publish.d.ts +3 -0
  96. package/dist/src/publish.js +35 -0
  97. package/dist/src/publish.js.map +1 -0
  98. package/dist/src/resend.d.ts +4 -0
  99. package/dist/src/resend.js +29 -0
  100. package/dist/src/resend.js.map +1 -0
  101. package/dist/src/show.d.ts +2 -0
  102. package/dist/src/show.js +23 -0
  103. package/dist/src/show.js.map +1 -0
  104. package/dist/src/subscribe.d.ts +2 -0
  105. package/dist/src/subscribe.js +13 -0
  106. package/dist/src/subscribe.js.map +1 -0
  107. package/dist/tsconfig.tsbuildinfo +1 -0
  108. package/package.json +22 -12
  109. package/src/{create.js → create.ts} +7 -2
  110. package/src/{generate.js → generate.ts} +6 -3
  111. package/src/{list.js → list.ts} +6 -4
  112. package/src/{publish.js → publish.ts} +11 -7
  113. package/src/resend.ts +29 -0
  114. package/src/{show.js → show.ts} +8 -2
  115. package/src/subscribe.ts +9 -0
  116. package/tsconfig.json +7 -0
  117. package/bin/common.js +0 -79
  118. package/bin/streamr-create.js +0 -40
  119. package/bin/streamr-generate.js +0 -14
  120. package/bin/streamr-list.js +0 -35
  121. package/bin/streamr-publish.js +0 -28
  122. package/bin/streamr-resend.js +0 -101
  123. package/bin/streamr-show.js +0 -19
  124. package/bin/streamr-subscribe.js +0 -20
  125. package/src/resend.js +0 -43
  126. package/src/subscribe.js +0 -9
package/.eslintignore ADDED
@@ -0,0 +1,3 @@
1
+ node_modules/**
2
+ dist/**
3
+
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,7 +5,38 @@ 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
- ## Changed
8
+ - Add permission commands: `stream grant-permission` and `stream revoke-permission`
9
+ - Remove `typescript` and `ts-node` as run-time dependencies
10
+ - Remove `--msg-chain-id` parameter from `stream resend from`
11
+ - (Breaking) `streamr stream create` argument is a stream ID, not a name
12
+ - Support path notation when defining a stream ID
13
+
14
+ ## [5.0.0] - 2021-05-05
15
+ ### Added
16
+ - Add storage node commands under `streamr storage-node`
17
+
18
+ ### Changed
19
+ - (Breaking) Commands are divided to subcommands: most of the existing command are under `streamr stream`, and `generate` command under `streamr mock-data`
20
+ - `streamr subscribe` is now `streamr stream subscribe`
21
+ - `streamr publish` is now `streamr stream publish`
22
+ - `streamr list` is now `streamr stream list`
23
+ - `streamr show` is now `streamr stream show`
24
+ - `streamr create` is now `streamr stream create`
25
+ - `streamr resend` is now `streamr stream resend`
26
+ - `streamr generate` is now `streamr mock-data generate`
27
+ - Fixed examples of --private-key in README
28
+ - Internal implementation was converted to TypeScript
29
+ - Bump dependency streamr-client to 5.2.1
30
+ - Bump dependency commander to 7.2.0
31
+
32
+ ## [4.1.1] - 2021-02-11
33
+ ### Changed
34
+ - Bump dependency streamr-client to 5.0.0-beta.6
35
+ - Bump dependency commander to ^6.1.0
36
+
37
+ ## [4.1.0] - 2020-10-12
38
+ ### Changed
39
+ - Bump dependency streamr-client to ^4.1.1.
9
40
  - Turn option `--privateKey` into `--private-key` for consistency.
10
41
  - Turn `--apiKey` into `--api-key` for consistency.
11
42
 
@@ -14,7 +45,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
14
45
  - Ethereum authentication with `--privateKey <key>`. This also enables message signing when publishing messages.
15
46
 
16
47
  ### Changed
17
- - (Breaking) Rename command `listen` to `subscribe`.
48
+ - (Breaking) Rename command `listen` to `subscribe`.
18
49
  - (Breaking) API key is now given with `--apiKey <key>`. API keys are deprecated. Option `--privateKey` should be preferred.
19
50
 
20
51
  ## [3.1.1] - 2020-04-16
@@ -40,7 +71,10 @@ ordering and gap filling.
40
71
  - Bump dependency commander to ^4.0.1.
41
72
  - Re-organize README.md and a few touches to Developing section paragraphs.
42
73
 
43
- [Unreleased]: https://github.com/streamr-dev/cli-tools/compare/v4.0.0...HEAD
74
+ [Unreleased]: https://github.com/streamr-dev/cli-tools/compare/v5.0.0...HEAD
75
+ [5.0.0]: https://github.com/streamr-dev/cli-tools/compare/v4.1.1...v5.0.0
76
+ [4.1.1]: https://github.com/streamr-dev/cli-tools/compare/v4.1.0...v4.1.1
77
+ [4.1.0]: https://github.com/streamr-dev/cli-tools/compare/v4.0.0...v4.1.0
44
78
  [4.0.0]: https://github.com/streamr-dev/cli-tools/compare/v3.1.1...v4.0.0
45
79
  [3.1.1]: https://github.com/streamr-dev/cli-tools/compare/v3.1.0...v3.1.1
46
80
  [3.1.0]: https://github.com/streamr-dev/cli-tools/compare/v3.0.1...v3.1.0
package/README.md CHANGED
@@ -1,35 +1,53 @@
1
- # Streamr Command Line Tools
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
+
7
+ # @streamr/cli-tools
2
8
 
3
9
  Command line tool for interacting with [Streamr](https://streamr.network).
4
10
 
5
11
  See [Changelog](CHANGELOG.md) for version information and changes.
6
12
 
7
- ## Installation
13
+ ## Table of Contents
14
+ - [Install](#install)
15
+ - [Use](#use)
16
+ - [Develop](#develop)
17
+ - [Release](#release)
18
+ - [Contribute](#contribute)
19
+
20
+ ## Install
8
21
 
9
22
  ```
10
23
  npm install -g @streamr/cli-tools
11
24
  ```
12
25
 
13
- ## Usage
14
- To get a list of all (sub)commands simply run `streamr`.
26
+ ## Use
27
+ All commands follow pattern `streamr <command> <subcommand>`, e.g.
28
+ ```
29
+ streamr stream subscribe
30
+ streamr mock-data generate
31
+ ```
32
+
33
+ To get a list of all commands simply run `streamr`. To list subcommands run e.g. `streamr stream`
15
34
 
16
- All (sub)commands follow pattern `streamr <command>`.
35
+ Run `streamr <command> <subcommand> --help` to get more information about a a command, its options, and so forth.
17
36
 
18
- Run `streamr help <command>` or `streamr <command> --help` to get more information about a a command, its options, and
19
- so forth.
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.
20
38
 
21
39
  ### subscribe
22
40
  Used to subscribe to a stream and output real-time JSON objects to stdout line-by-line.
23
41
 
24
42
  For example, to subscribe to a public stream such as the tram demo do
25
43
  ```
26
- streamr subscribe 7wa7APtlTq6EC5iTCBy6dw
44
+ streamr stream subscribe streamr.eth/demos/helsinki-trams
27
45
  ```
28
46
 
29
47
  To subscribe to a private stream and authenticate with an Ethereum private key:
30
48
 
31
49
  ```
32
- streamr subscribe streamId --privateKey <key>
50
+ streamr stream subscribe streamId --private-key <key>
33
51
  ```
34
52
 
35
53
  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.
@@ -40,7 +58,7 @@ Used to publish events to a stream from stdin line-by-line. Each line should be
40
58
 
41
59
  Example of use:
42
60
  ```
43
- streamr publish <streamId> --privateKey <key>
61
+ streamr stream publish <streamId> --private-key <key>
44
62
  ```
45
63
 
46
64
  Flag `--dev` or `--stg` can be enabled for the command to operate on pre-defined development or staging environment.
@@ -51,44 +69,51 @@ Generate random JSON objects to stdout line-by-line.
51
69
 
52
70
  Useful for generating test data to be published to a stream with `publish`, e.g.:
53
71
  ```
54
- streamr generate | streamr publish <streamId> --privateKey <key>
72
+ streamr mock-data generate | streamr stream publish <streamId> --private-key <key>
55
73
  ```
56
74
 
57
75
  ### list
58
76
  Fetch a list of streams that are accessible to the user authenticated by the private key
59
77
  ```
60
- streamr list --privateKey <key>
78
+ streamr stream list --private-key <key>
61
79
  ```
62
80
 
63
81
  ### show
64
82
  Show detailed information about a specific stream
65
83
  ```
66
- streamr show <streamId> --privateKey <key>
84
+ streamr stream show <streamId> --private-key <key>
67
85
  ```
68
86
 
69
87
  ### create
70
88
  Create a new stream
71
89
  ```
72
- streamr create <name> --privateKey <key>
90
+ streamr stream create <streamId> --private-key <key>
91
+ ```
92
+ E.g.
73
93
  ```
94
+ streamr stream create /foo/bar
95
+ streamr stream create 0x1234567890123456789012345678901234567890/foobar
96
+ streamr stream create yourdomain.ens/foobar
97
+ ```
98
+
74
99
 
75
100
  ### resend
76
101
  Request a resend of historical data printed as JSON objects to stdout line-by-line.
77
102
 
78
103
  For example, to fetch the 10 latest messages of a public stream such as the tram demo do
79
104
  ```
80
- streamr resend last 10 7wa7APtlTq6EC5iTCBy6dw
105
+ streamr stream resend last 10 streamr.eth/demos/helsinki-trams
81
106
  ```
82
107
 
83
108
 
84
109
  To fetch data starting from a particular date-time
85
110
  ```
86
- streamr resend from 2019-05-10T17:00:00 <streamId> --privateKey <key>
111
+ streamr stream resend from 2019-05-10T17:00:00 <streamId> --private-key <key>
87
112
  ```
88
113
 
89
114
  To fetch data between two date-times
90
115
  ```
91
- streamr resend range 2019-05-10T17:00:00 2019-05-11T21:00:00 <streamId> --privateKey <key>
116
+ streamr stream resend range 2019-05-10T17:00:00 2019-05-11T21:00:00 <streamId> --private-key <key>
92
117
  ```
93
118
 
94
119
  Flag `--dev` or `--stg` can be enabled for the command to operate on pre-defined development or staging environment.
@@ -104,21 +129,21 @@ You can pipe the line-by-line JSON objects output by `subscribe` to
104
129
  your program written in any language. Just make the program read JSON objects
105
130
  from stdin.
106
131
  ```
107
- streamr subscribe 7wa7APtlTq6EC5iTCBy6dw | ruby calculate-average-speed.rb
132
+ streamr stream subscribe streamr.eth/demos/helsinki-trams | ruby calculate-average-speed.rb
108
133
  ```
109
134
 
110
135
  #### Publishing to a stream from any programming language
111
136
  If your program produces JSON objects to stdout (line-by-line), you can
112
137
  redirect it to command `publish` to publish the JSON objects to a stream.
113
138
  ```
114
- python printSensorReadingsAsJson.py | streamr publish <streamId> --privateKey <key>
139
+ python printSensorReadingsAsJson.py | streamr stream publish <streamId> --private-key <key>
115
140
  ```
116
141
 
117
142
  #### Transforming streams
118
143
  You can also subscribe to a stream, apply a transformation, and then pipe the
119
144
  transformed output into another stream.
120
145
  ```
121
- streamr subscribe <sourceStream> | ./calculateMovingAverages | streamr publish <destinationStream> --privateKey <key>
146
+ streamr stream subscribe <sourceStream> | ./calculateMovingAverages | streamr stream publish <destinationStream> --private-key <key>
122
147
  ```
123
148
 
124
149
  Same rules apply here as before. Your program should accept line-by-line JSON
@@ -129,23 +154,23 @@ If you have a working stream in production that you'd also like to use in your
129
154
  development environment, you can combine the `subscribe` and `publish` commands to effectively copy
130
155
  the real-time events.
131
156
  ```
132
- streamr subscribe 7wa7APtlTq6EC5iTCBy6dw | streamr publish --dev <streamId> --privateKey <key>
157
+ streamr stream subscribe streamr.eth/demos/helsinki-trams | streamr stream publish --dev <streamId> --private-key <key>
133
158
  ```
134
159
 
135
160
  And the same for staging environment:
136
161
  ```
137
- streamr subscribe 7wa7APtlTq6EC5iTCBy6dw | streamr publish --stg <streamId> --privateKey <key>
162
+ streamr stream subscribe streamr.eth/demos/helsinki-trams | streamr stream publish --stg <streamId> --private-key <key>
138
163
  ```
139
164
 
140
- ## Contributing
141
- See issues, especially those tagged with "help wanted". We welcome pull requests and issues.
142
-
143
- ## Developing
165
+ ## Develop
144
166
  This project is a thin wrapper around [streamr-client-javascript](https://github.com/streamr-dev/streamr-client-javascript),
145
167
  which does the heavy lifting, while this project concentrates on CLI concerns: parsing and
146
168
  passing arguments, stdin/stdout, errors, and so forth.
147
169
 
148
- ### Releasing to NPM
170
+ ### Release
149
171
  ```
150
172
  npm publish --access=public
151
173
  ```
174
+
175
+ ## Contribute
176
+ See issues, especially those tagged with "help wanted". We welcome pull requests and issues.
package/bin/common.ts ADDED
@@ -0,0 +1,94 @@
1
+ import * as commander from 'commander'
2
+ import { Wallet } from 'ethers'
3
+ import { StreamrClientOptions } from 'streamr-client'
4
+
5
+ export interface EnvironmentOptions {
6
+ dev?: boolean
7
+ stg?: boolean
8
+ httpUrl?: string
9
+ }
10
+
11
+ export interface AuthenticationOptions {
12
+ privateKey?: string
13
+ }
14
+
15
+ export function envOptions(program: commander.Command): commander.Command {
16
+ return program
17
+ .option('--dev', 'use pre-defined development environment')
18
+ .option('--stg', 'use pre-defined staging environment')
19
+ .option('--ws-url <url>', 'alternative websocket url to use')
20
+ .option('--http-url <url>', 'alternative http url to use')
21
+ }
22
+
23
+ export function authOptions(program: commander.Command): commander.Command {
24
+ return program
25
+ .option('--private-key <key>', 'use an Ethereum private key to authenticate')
26
+ }
27
+
28
+ export function exitWithHelpIfArgsNotBetween(program: commander.Command, min: number, max: number): void {
29
+ if (program.args.length < min || program.args.length > max) {
30
+ program.help()
31
+ }
32
+ }
33
+
34
+ export function formStreamrOptionsWithEnv(
35
+ { dev, stg, httpUrl, privateKey }: EnvironmentOptions & AuthenticationOptions
36
+ ): StreamrClientOptions {
37
+ const options: StreamrClientOptions = {}
38
+
39
+ if (dev && stg) {
40
+ console.error('flags --dev and --stg cannot be enabled at the same time')
41
+ process.exit(1)
42
+ }
43
+
44
+ if (dev) {
45
+ options.restUrl = 'http://localhost/api/v1'
46
+ options.storageNodeRegistry = [{
47
+ // "broker-node-storage-1" on Docker environment
48
+ address: '0xde1112f631486CfC759A50196853011528bC5FA0',
49
+ url: 'http://10.200.10.1:8891'
50
+ }]
51
+ } else if (stg) {
52
+ options.restUrl = 'https://staging.streamr.com/api/v1/'
53
+ }
54
+
55
+ if (httpUrl) {
56
+ options.restUrl = httpUrl
57
+ }
58
+
59
+ if (privateKey) {
60
+ options.auth = {
61
+ privateKey
62
+ }
63
+ }
64
+
65
+ return options
66
+ }
67
+
68
+ export function createFnParseInt(name: string): (s: string) => number {
69
+ return (str: string) => {
70
+ const n = parseInt(str, 10)
71
+ if (isNaN(n)) {
72
+ console.error(`${name} must be an integer (was "${str}")`)
73
+ process.exit(1)
74
+ }
75
+ return n
76
+ }
77
+ }
78
+
79
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
80
+ export const getStreamId = (streamIdOrPath: string|undefined, options: any): string|undefined => {
81
+ if (streamIdOrPath === undefined) {
82
+ return undefined
83
+ }
84
+ const PATH_PREFIX = '/'
85
+ if (!streamIdOrPath.startsWith(PATH_PREFIX)) {
86
+ return streamIdOrPath
87
+ }
88
+ const privateKey = options.privateKey
89
+ if (privateKey === undefined) {
90
+ console.error(`relative stream id ${streamIdOrPath} requires authentication`)
91
+ process.exit(1)
92
+ }
93
+ return new Wallet(privateKey).address.toLowerCase() + streamIdOrPath
94
+ }
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander'
3
+ import { StreamrClient } from 'streamr-client'
4
+ import {
5
+ envOptions,
6
+ authOptions,
7
+ exitWithHelpIfArgsNotBetween,
8
+ formStreamrOptionsWithEnv,
9
+ } from './common'
10
+ import pkg from '../package.json'
11
+
12
+ const program = new Command()
13
+ program
14
+ .description('get a session token for the current user')
15
+ authOptions(program)
16
+ envOptions(program)
17
+ .version(pkg.version)
18
+ .action(async (options: any) => {
19
+ const client = new StreamrClient(formStreamrOptionsWithEnv(options))
20
+ try {
21
+ console.info(await client.session.getSessionToken())
22
+ } catch (err) {
23
+ console.error(err)
24
+ process.exit(1)
25
+ }
26
+ })
27
+ .parseAsync(process.argv)
28
+ .catch((e) => {
29
+ console.error(e)
30
+ process.exit(1)
31
+ })
32
+
33
+ exitWithHelpIfArgsNotBetween(program, 0, 0)
@@ -0,0 +1,10 @@
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('miscellaneous subcommands')
9
+ .command('get-session-token', 'get a session token for the current user')
10
+ .parse(process.argv)
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander'
3
+ import { generate } from '../src/generate'
4
+ import { exitWithHelpIfArgsNotBetween, createFnParseInt } from './common'
5
+ import pkg from '../package.json'
6
+
7
+ const program = new Command()
8
+ program
9
+ .description('generate and print semi-random JSON data to stdout')
10
+ .option('-r, --rate <n>', 'rate in milliseconds', createFnParseInt('--rate'), 500)
11
+ .version(pkg.version)
12
+ .action((options: any) => {
13
+ generate(options.rate)
14
+ })
15
+ .parse(process.argv)
16
+
17
+ exitWithHelpIfArgsNotBetween(program, 0, 0)
@@ -0,0 +1,10 @@
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('mock-data subcommands')
9
+ .command('generate', 'generate JSON data')
10
+ .parse(process.argv)
@@ -0,0 +1,32 @@
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
+ getStreamId,
10
+ } from './common'
11
+ import pkg from '../package.json'
12
+
13
+ const program = new Command()
14
+ program
15
+ .arguments('<storageNodeAddress> <streamId>')
16
+ .description('add stream to a storage node')
17
+ authOptions(program)
18
+ envOptions(program)
19
+ .version(pkg.version)
20
+ .action((storageNodeAddress: string, streamIdOrPath: string, options: any) => {
21
+ const client = new StreamrClient(formStreamrOptionsWithEnv(options))
22
+ const streamId = getStreamId(streamIdOrPath, options)!
23
+ client.getStream(streamId)
24
+ .then((stream: Stream) => stream.addToStorageNode(storageNodeAddress))
25
+ .catch((err) => {
26
+ console.error(err)
27
+ process.exit(1)
28
+ })
29
+ })
30
+ .parse(process.argv)
31
+
32
+ exitWithHelpIfArgsNotBetween(program, 2, 2)
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander'
3
+ import { StreamrClient } from 'streamr-client'
4
+ import {
5
+ envOptions,
6
+ authOptions,
7
+ exitWithHelpIfArgsNotBetween,
8
+ formStreamrOptionsWithEnv,
9
+ } from './common'
10
+ import pkg from '../package.json'
11
+ import EasyTable from 'easy-table'
12
+
13
+ const program = new Command()
14
+ program
15
+ .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) => {
24
+ if (streamParts.length > 0) {
25
+ console.info(EasyTable.print(streamParts.map(({ streamId, streamPartition }) => ({
26
+ streamId,
27
+ streamPartition,
28
+ }))))
29
+ }
30
+ return true
31
+ }).catch((err) => {
32
+ console.error(err)
33
+ process.exit(1)
34
+ })
35
+ })
36
+ .parse(process.argv)
37
+
38
+ exitWithHelpIfArgsNotBetween(program, 1, 1)
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander'
3
+ import { StreamrClient } from 'streamr-client'
4
+ import {
5
+ envOptions,
6
+ authOptions,
7
+ exitWithHelpIfArgsNotBetween,
8
+ formStreamrOptionsWithEnv,
9
+ getStreamId,
10
+ } from './common'
11
+ import pkg from '../package.json'
12
+ import EasyTable from 'easy-table'
13
+
14
+ const getStorageNodes = async (streamId: string | undefined, client: StreamrClient): Promise<string[]> => {
15
+ if (streamId !== undefined) {
16
+ const stream = await client.getStream(streamId)
17
+ const storageNodes = await stream.getStorageNodes()
18
+ return storageNodes.map((storageNode) => storageNode.address)
19
+ } else {
20
+ // all storage nodes (currently there is only one)
21
+ const nodes = await client.getNodes()
22
+ return nodes.map((n) => n.address)
23
+ }
24
+ }
25
+
26
+ const program = new Command()
27
+ program
28
+ .description('fetch a list of storage nodes')
29
+ .option('-s, --stream <streamId>', 'only storage nodes which store the given stream (needs authentication)')
30
+
31
+ authOptions(program)
32
+
33
+ envOptions(program)
34
+ .version(pkg.version)
35
+ .action((options: any) => {
36
+ const client = new StreamrClient(formStreamrOptionsWithEnv(options))
37
+ const streamId = getStreamId(options.stream, options)
38
+ getStorageNodes(streamId, client).then((addresses: string[]) => {
39
+ if (addresses.length > 0) {
40
+ console.info(EasyTable.print(addresses.map((address: string) => ({
41
+ address
42
+ }))))
43
+ }
44
+ return true
45
+ }).catch((err) => {
46
+ console.error(err)
47
+ process.exit(1)
48
+ })
49
+ })
50
+ .parse(process.argv)
51
+
52
+ exitWithHelpIfArgsNotBetween(program, 0, 0)
@@ -0,0 +1,32 @@
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
+ getStreamId,
10
+ } from './common'
11
+ import pkg from '../package.json'
12
+
13
+ const program = new Command()
14
+ program
15
+ .arguments('<storageNodeAddress> <streamId>')
16
+ .description('remove stream from a storage node')
17
+ authOptions(program)
18
+ envOptions(program)
19
+ .version(pkg.version)
20
+ .action((storageNodeAddress: string, streamIdOrPath: string, options: any) => {
21
+ const client = new StreamrClient(formStreamrOptionsWithEnv(options))
22
+ const streamId = getStreamId(streamIdOrPath, options)!
23
+ client.getStream(streamId)
24
+ .then((stream: Stream) => stream.removeFromStorageNode(storageNodeAddress))
25
+ .catch((err) => {
26
+ console.error(err)
27
+ process.exit(1)
28
+ })
29
+ })
30
+ .parse(process.argv)
31
+
32
+ exitWithHelpIfArgsNotBetween(program, 2, 2)
@@ -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(process.argv)
@@ -0,0 +1,35 @@
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'
12
+
13
+ const program = new Command()
14
+ program
15
+ .arguments('<streamId>')
16
+ .description('create a new stream')
17
+ .option('-d, --description <description>', 'define a description')
18
+ .option('-c, --config <config>', 'define a configuration as JSON', (s: string) => JSON.parse(s))
19
+ .option('-p, --partitions <count>', 'define a partition count',
20
+ createFnParseInt('--partitions'))
21
+ authOptions(program)
22
+ envOptions(program)
23
+ .version(pkg.version)
24
+ .action((streamIdOrPath: string, options: any) => {
25
+ const body: any = {
26
+ id: streamIdOrPath,
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)