@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/bin/common.js DELETED
@@ -1,79 +0,0 @@
1
- function envOptions(program) {
2
- return program
3
- .option('--dev', 'use pre-defined development environment')
4
- .option('--stg', 'use pre-defined staging environment')
5
- .option('--ws-url <url>', 'alternative websocket url to use')
6
- .option('--http-url <url>', 'alternative http url to use')
7
- }
8
-
9
- function authOptions(program) {
10
- return program
11
- .option('--private-key <key>', 'use an Ethereum private key to authenticate')
12
- .option('--api-key <key>', 'use an API key to authenticate (deprecated)')
13
- }
14
-
15
- function exitWitHelpIfArgsNotBetween(program, min, max) {
16
- if (program.args.length < min || program.args.length > max) {
17
- program.help()
18
- }
19
- }
20
-
21
- function formStreamrOptionsWithEnv({ dev, stg, wsUrl, httpUrl, privateKey, apiKey }) {
22
- const options = {}
23
-
24
- if (dev && stg) {
25
- console.error('flags --dev and --stg cannot be enabled at the same time')
26
- process.exit(1)
27
- }
28
-
29
- if (dev) {
30
- options.url = 'ws://localhost/api/v1/ws'
31
- options.restUrl = 'http://localhost/api/v1'
32
- } else if (stg) {
33
- options.url = 'wss://staging.streamr.com/api/v1/ws'
34
- options.restUrl = 'https://staging.streamr.com/api/v1/'
35
- }
36
-
37
- if (wsUrl) {
38
- options.url = wsUrl
39
- }
40
- if (httpUrl) {
41
- options.restUrl = httpUrl
42
- }
43
-
44
- if (privateKey && apiKey) {
45
- console.error('flags --privateKey and --apiKey cannot be used at the same time')
46
- process.exit(1)
47
- }
48
-
49
- if (privateKey) {
50
- options.auth = {
51
- privateKey
52
- }
53
- } else if (apiKey) {
54
- options.auth = {
55
- apiKey
56
- }
57
- }
58
-
59
- return options
60
- }
61
-
62
- function createFnParseInt(name) {
63
- return (str) => {
64
- const n = parseInt(str, 10)
65
- if (isNaN(n)) {
66
- console.error(`${name} must be an integer (was "${str}")`)
67
- process.exit(1)
68
- }
69
- return n
70
- }
71
- }
72
-
73
- module.exports = {
74
- envOptions,
75
- authOptions,
76
- exitWitHelpIfArgsNotBetween,
77
- formStreamrOptionsWithEnv,
78
- createFnParseInt
79
- }
@@ -1,40 +0,0 @@
1
- #!/usr/bin/env node
2
- const program = require('commander')
3
- const create = require('../src/create')
4
- const {
5
- envOptions,
6
- authOptions,
7
- exitWitHelpIfArgsNotBetween,
8
- formStreamrOptionsWithEnv,
9
- createFnParseInt
10
- } = require('./common')
11
-
12
- program
13
- .usage('<name>')
14
- .description('create a new stream')
15
- .option('-d, --description <description>', 'define a description')
16
- .option('-c, --config <config>', 'define a configuration as JSON', (s) => JSON.parse(s))
17
- .option('-p, --partitions <count>', 'define a partition count',
18
- createFnParseInt('--partitions'))
19
- authOptions(program)
20
- envOptions(program)
21
- .version(require('../package.json').version)
22
- .parse(process.argv)
23
-
24
- exitWitHelpIfArgsNotBetween(program, 1, 1)
25
-
26
- const body = {
27
- name: program.args[0]
28
- }
29
- if ("description" in program) {
30
- body.description = program.description
31
- }
32
- if ("config" in program) {
33
- body.config = program.config
34
- }
35
- if ("partitions" in program) {
36
- body.partitions = program.partitions
37
- }
38
-
39
- const options = formStreamrOptionsWithEnv(program)
40
- create(body, options)
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env node
2
- const program = require('commander')
3
- const generate = require('../src/generate')
4
- const { exitWitHelpIfArgsNotBetween, createFnParseInt } = require('./common')
5
-
6
- program
7
- .description('generate and print semi-random JSON data to stdout')
8
- .option('-r, --rate <n>', 'rate in milliseconds', createFnParseInt('--rate'), 500)
9
- .version(require('../package.json').version)
10
- .parse(process.argv)
11
-
12
- exitWitHelpIfArgsNotBetween(program, 0, 0)
13
-
14
- generate(program.rate)
@@ -1,35 +0,0 @@
1
- #!/usr/bin/env node
2
- const program = require('commander')
3
- const list = require('../src/list')
4
- const { envOptions, authOptions, exitWitHelpIfArgsNotBetween, formStreamrOptionsWithEnv } = require('./common')
5
-
6
- program
7
- .description('fetch a list of streams that are accessible by the authenticated user')
8
- .option('-s, --search [term]', 'search for term in name or description')
9
- .option('-o, --operation [permission]', 'filter by permission', /^(stream_get|stream_subscribe|stream_publish|stream_delete|stream_share)$/i, 'stream_get')
10
- .option('--public-access', 'include publicly available streams')
11
- .option('--no-granted-access', 'exclude streams that user has directly granted permissions to')
12
- authOptions(program)
13
- envOptions(program)
14
- .version(require('../package.json').version)
15
- .parse(process.argv)
16
-
17
- exitWitHelpIfArgsNotBetween(program, 0, 0)
18
-
19
- const query = {
20
- operation: program.operation,
21
- noConfig: true
22
- }
23
- if ("publicAccess" in program) {
24
- query.publicAccess = program.publicAccess
25
- }
26
- if ("search" in program) {
27
- query.search = program.search
28
- }
29
- if ("grantedAccess" in program) {
30
- query.grantedAccess = program.grantedAccess
31
- }
32
-
33
- const options = formStreamrOptionsWithEnv(program);
34
- list(query, options)
35
-
@@ -1,28 +0,0 @@
1
- #!/usr/bin/env node
2
- const es = require('event-stream')
3
- const program = require('commander')
4
- const publishStream = require('../src/publish')
5
- const { envOptions, authOptions, exitWitHelpIfArgsNotBetween, formStreamrOptionsWithEnv } = require('./common')
6
-
7
- program
8
- .usage('<streamId>')
9
- .description('publish to a stream by reading JSON messages from stdin line-by-line')
10
- .option('-k, --partition-key <string>', 'field name in each message to use for assigning the message to a stream partition')
11
- authOptions(program)
12
- envOptions(program)
13
- .version(require('../package.json').version)
14
- .parse(process.argv)
15
-
16
- exitWitHelpIfArgsNotBetween(program, 1, 1)
17
-
18
- const options = formStreamrOptionsWithEnv(program)
19
- const ps = publishStream(program.args[0], program.partitionKey, options)
20
- process.stdin
21
- .pipe(es.split())
22
- .pipe(ps)
23
- .on('error', (err) => {
24
- console.error(err)
25
- process.exit(1)
26
- // process.stdin.pipe(ps) recover pipe to continue execution
27
- })
28
-
@@ -1,101 +0,0 @@
1
- #!/usr/bin/env node
2
- const program = require('commander')
3
- const resend = require('../src/resend')
4
- const { envOptions, authOptions, exitWitHelpIfArgsNotBetween, formStreamrOptionsWithEnv } = require('./common')
5
-
6
- function handlePublisherIdAndMsgChainId(cmd, resendOptions) {
7
- if ('publisherId' in cmd && !('msgChainId' in cmd)) {
8
- console.error('option --publisher-id must be accompanied by option --msg-chain-id')
9
- process.exit(1)
10
- }
11
- if ('msgChainId' in cmd && !('publisherId' in cmd)) {
12
- console.error('option --msg-chain-id must be accompanied by option --publisher-id')
13
- process.exit(1)
14
- }
15
- if ('publisherId' in cmd) {
16
- resendOptions.publisherId = cmd.publisherId
17
- }
18
- if ('msgChainId' in cmd) {
19
- resendOptions.msgChainId = cmd.msgChainId
20
- }
21
- }
22
-
23
- program
24
- .usage('<command> [<args>]')
25
- .description('request resend of stream and print JSON messages to stdout line-by-line')
26
-
27
- program
28
- .command('last <n> <streamId>')
29
- .description('request last N messages')
30
- .option('-d, --disable-ordering', 'disable ordering of messages by OrderingUtil', false)
31
- .option('-s, --subscribe', 'subscribe in addition to resend', false)
32
- .action((n, streamId, cmd) => {
33
- if (isNaN(n)) {
34
- console.error('argument n is not a number')
35
- process.exit(1)
36
- }
37
- const resendOptions = {
38
- last: parseInt(n)
39
- }
40
- const options = formStreamrOptionsWithEnv(cmd.parent)
41
- options.orderMessages = !cmd.disableOrdering
42
- options.subscribe = cmd.subscribe
43
- resend(streamId, resendOptions, options)
44
- })
45
-
46
- program
47
- .command('from <from> <streamId>')
48
- .description('request messages starting from given date-time (format: "YYYY-MM-DDTHH:mm:ss.sssZ")')
49
- .option('--publisher-id <string>', 'filter results by publisher')
50
- .option('--msg-chain-id <string>', 'filter results by message chain')
51
- .option('-d, --disable-ordering', 'disable ordering of messages by OrderingUtil', false)
52
- .option('-s, --subscribe', 'subscribe in addition to resend', false)
53
- .action((from, streamId, cmd) => {
54
- const resendOptions = {
55
- from: {
56
- timestamp: Date.parse(from),
57
- sequenceNumber: 0
58
- }
59
- }
60
- handlePublisherIdAndMsgChainId(cmd, resendOptions)
61
- const options = formStreamrOptionsWithEnv(cmd.parent)
62
- options.orderMessages = !cmd.disableOrdering
63
- options.subscribe = cmd.subscribe
64
- resend(streamId, resendOptions, options)
65
- })
66
-
67
- program
68
- .command('range <from> <to> <streamId>')
69
- .description('request messages between two given date-times (format: "YYYY-MM-DDTHH:mm:ss.sssZ")')
70
- .option('--publisher-id <string>', 'filter results by publisher')
71
- .option('--msg-chain-id <string>', 'filter results by message chain')
72
- .option('-d, --disable-ordering', 'disable ordering of messages by OrderingUtil', false)
73
- .action((from, to, streamId, cmd) => {
74
- const resendOptions = {
75
- from: {
76
- timestamp: Date.parse(from),
77
- sequenceNumber: 0
78
- },
79
- to: {
80
- timestamp: Date.parse(to),
81
- sequenceNumber: 0
82
- },
83
- }
84
- handlePublisherIdAndMsgChainId(cmd, resendOptions)
85
- const options = formStreamrOptionsWithEnv(cmd.parent)
86
- options.orderMessages = !cmd.disableOrdering
87
- resend(streamId, resendOptions, options)
88
- })
89
-
90
- program
91
- .on('command:*', (invalidCommand) => {
92
- console.error(`invalid command: ${invalidCommand}`)
93
- process.exit(1)
94
- })
95
-
96
- authOptions(program)
97
- envOptions(program)
98
- .version(require('../package.json').version)
99
- .parse(process.argv)
100
-
101
- exitWitHelpIfArgsNotBetween(program, 1, Number.MAX_VALUE)
@@ -1,19 +0,0 @@
1
- #!/usr/bin/env node
2
- const program = require('commander')
3
- const show = require('../src/show')
4
- const { envOptions, authOptions, exitWitHelpIfArgsNotBetween, formStreamrOptionsWithEnv } = require('./common')
5
-
6
- program
7
- .usage('<streamId>')
8
- .description('show detailed information about a stream')
9
- .option('--include-permissions', 'include list of permissions (requires SHARE permission)')
10
- authOptions(program)
11
- envOptions(program)
12
- .version(require('../package.json').version)
13
- .parse(process.argv)
14
-
15
- exitWitHelpIfArgsNotBetween(program, 1, 1)
16
-
17
- const options = formStreamrOptionsWithEnv(program);
18
- show(program.args[0], program.includePermissions, options)
19
-
@@ -1,20 +0,0 @@
1
- #!/usr/bin/env node
2
- const program = require('commander')
3
- const subscribe = require('../src/subscribe')
4
- const { envOptions, authOptions, exitWitHelpIfArgsNotBetween, formStreamrOptionsWithEnv, createFnParseInt } = require('./common')
5
-
6
- program
7
- .usage('<streamId>')
8
- .description('subscribe to a stream, prints JSON messages to stdout line-by-line')
9
- .option('-p, --partition [partition]', 'partition', createFnParseInt('--partition'), 0)
10
- .option('-d, --disable-ordering', 'disable ordering of messages by OrderingUtil', false)
11
- authOptions(program)
12
- envOptions(program)
13
- .version(require('../package.json').version)
14
- .parse(process.argv)
15
-
16
- exitWitHelpIfArgsNotBetween(program, 1, 1)
17
-
18
- const options = formStreamrOptionsWithEnv(program)
19
- options.orderMessages = !program.disableOrdering
20
- subscribe(program.args[0], program.partition, options)
package/src/resend.js DELETED
@@ -1,43 +0,0 @@
1
- const StreamrClient = require('streamr-client')
2
-
3
- module.exports = async function resend(streamId, resendOpts, streamrOptions) {
4
- const options = { ...streamrOptions }
5
- const client = new StreamrClient(options)
6
-
7
- let sub
8
- try {
9
- const subscribeOpts = {
10
- stream: streamId,
11
- resend: resendOpts
12
- }
13
- const handler = (message) => {
14
- console.info(JSON.stringify(message))
15
- }
16
-
17
- if (options.subscribe) {
18
- sub = await client.subscribe(subscribeOpts, handler)
19
- } else {
20
- sub = await client.resend(subscribeOpts, handler)
21
- }
22
- } catch (err) {
23
- console.error(err.message ? err.message : err)
24
- process.exit(1)
25
- }
26
-
27
- sub.on('error', (err) => {
28
- console.error(err)
29
- process.exit(1)
30
- })
31
-
32
- sub.on('resent', () => {
33
- if (!options.subscribe) {
34
- process.exit(0)
35
- }
36
- })
37
-
38
- sub.on('no_resend', () => {
39
- if (!options.subscribe) {
40
- process.exit(0)
41
- }
42
- })
43
- }
package/src/subscribe.js DELETED
@@ -1,9 +0,0 @@
1
- const StreamrClient = require('streamr-client')
2
-
3
- module.exports = function subscribe(stream, partition, streamrOptions) {
4
- const options = { ...streamrOptions }
5
- new StreamrClient(options).subscribe({
6
- stream,
7
- partition,
8
- }, (message, streamMessage) => console.info(JSON.stringify(message)))
9
- }