@streamr/cli-tools 101.1.2 → 102.0.0-beta.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/README.md +1 -1
- package/bin/streamr-internal-node-info.ts +81 -0
- package/bin/streamr-internal-operator-delegate.ts +18 -0
- package/bin/streamr-internal-operator-stake.ts +18 -0
- package/bin/streamr-internal-operator-undelegate.ts +17 -0
- package/bin/streamr-internal-operator-unstake.ts +16 -0
- package/bin/streamr-internal-show-sdk-config.ts +11 -0
- package/bin/streamr-internal-sponsorship-sponsor.ts +18 -0
- package/bin/streamr-internal-visualize-topology.ts +1 -1
- package/bin/streamr-internal.ts +7 -0
- package/bin/streamr-mock-data-generate.ts +26 -13
- package/bin/streamr-mock-data.ts +1 -1
- package/bin/streamr-storage-node-add-stream.ts +1 -0
- package/bin/streamr-storage-node-list-streams.ts +4 -3
- package/bin/streamr-storage-node-list.ts +1 -0
- package/bin/streamr-storage-node-remove-stream.ts +1 -0
- package/bin/streamr-stream-create.ts +2 -1
- package/bin/streamr-stream-grant-permission.ts +1 -0
- package/bin/streamr-stream-publish.ts +24 -12
- package/bin/streamr-stream-resend-from.ts +1 -0
- package/bin/streamr-stream-resend-last.ts +1 -0
- package/bin/streamr-stream-resend-range.ts +1 -0
- package/bin/streamr-stream-resend.ts +1 -0
- package/bin/streamr-stream-revoke-permission.ts +1 -0
- package/bin/streamr-stream-search.ts +3 -2
- package/bin/streamr-stream-show.ts +11 -2
- package/bin/streamr-stream-subscribe.ts +2 -1
- package/bin/streamr-wallet-whoami.ts +2 -1
- package/dist/bin/streamr-internal-node-info.d.ts +5 -0
- package/dist/bin/streamr-internal-node-info.js +75 -0
- package/dist/bin/streamr-internal-node-info.js.map +1 -0
- package/dist/bin/streamr-internal-operator-delegate.d.ts +2 -0
- package/dist/bin/streamr-internal-operator-delegate.js +14 -0
- package/dist/bin/streamr-internal-operator-delegate.js.map +1 -0
- package/dist/bin/streamr-internal-operator-stake.d.ts +2 -0
- package/dist/bin/streamr-internal-operator-stake.js +15 -0
- package/dist/bin/streamr-internal-operator-stake.js.map +1 -0
- package/dist/bin/streamr-internal-operator-undelegate.d.ts +2 -0
- package/dist/bin/streamr-internal-operator-undelegate.js +14 -0
- package/dist/bin/streamr-internal-operator-undelegate.js.map +1 -0
- package/dist/bin/streamr-internal-operator-unstake.d.ts +2 -0
- package/dist/bin/streamr-internal-operator-unstake.js +14 -0
- package/dist/bin/streamr-internal-operator-unstake.js.map +1 -0
- package/dist/bin/streamr-internal-show-sdk-config.d.ts +2 -0
- package/dist/bin/streamr-internal-show-sdk-config.js +11 -0
- package/dist/bin/streamr-internal-show-sdk-config.js.map +1 -0
- package/dist/bin/streamr-internal-sponsorship-sponsor.d.ts +2 -0
- package/dist/bin/streamr-internal-sponsorship-sponsor.js +14 -0
- package/dist/bin/streamr-internal-sponsorship-sponsor.js.map +1 -0
- package/dist/bin/streamr-internal-visualize-topology.js +1 -1
- package/dist/bin/streamr-internal-visualize-topology.js.map +1 -1
- package/dist/bin/streamr-internal.js +7 -0
- package/dist/bin/streamr-internal.js.map +1 -1
- package/dist/bin/streamr-mock-data-generate.d.ts +10 -1
- package/dist/bin/streamr-mock-data-generate.js +29 -15
- package/dist/bin/streamr-mock-data-generate.js.map +1 -1
- package/dist/bin/streamr-mock-data.js +1 -1
- package/dist/bin/streamr-mock-data.js.map +1 -1
- package/dist/bin/streamr-storage-node-add-stream.js.map +1 -1
- package/dist/bin/streamr-storage-node-list-streams.js +3 -3
- package/dist/bin/streamr-storage-node-list-streams.js.map +1 -1
- package/dist/bin/streamr-storage-node-list.js.map +1 -1
- package/dist/bin/streamr-storage-node-remove-stream.js.map +1 -1
- package/dist/bin/streamr-stream-create.js +1 -1
- package/dist/bin/streamr-stream-create.js.map +1 -1
- package/dist/bin/streamr-stream-grant-permission.js.map +1 -1
- package/dist/bin/streamr-stream-publish.js +22 -11
- package/dist/bin/streamr-stream-publish.js.map +1 -1
- package/dist/bin/streamr-stream-resend-from.js.map +1 -1
- package/dist/bin/streamr-stream-resend-last.js.map +1 -1
- package/dist/bin/streamr-stream-resend-range.js.map +1 -1
- package/dist/bin/streamr-stream-resend.js.map +1 -1
- package/dist/bin/streamr-stream-revoke-permission.js.map +1 -1
- package/dist/bin/streamr-stream-search.js +2 -2
- package/dist/bin/streamr-stream-search.js.map +1 -1
- package/dist/bin/streamr-stream-show.js +9 -2
- package/dist/bin/streamr-stream-show.js.map +1 -1
- package/dist/bin/streamr-stream-subscribe.js +1 -1
- package/dist/bin/streamr-stream-subscribe.js.map +1 -1
- package/dist/bin/streamr-wallet-whoami.js +1 -1
- package/dist/bin/streamr-wallet-whoami.js.map +1 -1
- package/dist/package.json +13 -9
- package/dist/src/client.d.ts +1 -1
- package/dist/src/client.js +3 -4
- package/dist/src/client.js.map +1 -1
- package/dist/src/command.d.ts +3 -3
- package/dist/src/command.js +3 -1
- package/dist/src/command.js.map +1 -1
- package/dist/src/common.d.ts +3 -0
- package/dist/src/common.js +20 -2
- package/dist/src/common.js.map +1 -1
- package/dist/src/permission.js +1 -1
- package/dist/src/permission.js.map +1 -1
- package/jest.config.ts +1 -0
- package/package.json +13 -9
- package/src/client.ts +3 -4
- package/src/command.ts +5 -3
- package/src/common.ts +18 -0
- package/src/permission.ts +1 -1
- package/test/environment.test.ts +32 -0
- package/test/internal-operator.test.ts +57 -0
- package/test/internal-sponsorship-sponsor.test.ts +28 -0
- package/test/mock-data.test.ts +14 -0
- package/test/storage-node.test.ts +3 -3
- package/test/stream-create.test.ts +1 -1
- package/test/stream-permission.test.ts +3 -3
- package/test/stream-publish-subscribe.test.ts +1 -1
- package/test/stream-resend.test.ts +1 -1
- package/test/utils.ts +5 -5
- package/tsconfig.json +1 -14
- package/tsconfig.node.json +16 -0
- package/.eslintignore +0 -2
- package/.eslintrc +0 -6
package/README.md
CHANGED
|
@@ -169,7 +169,7 @@ You must pass either the `--private-key` or `--config` option.
|
|
|
169
169
|
User can specify environment and authentication details with the following command line arguments:
|
|
170
170
|
- `--private-key <key>`, e.g. `--private-key 0x1234567890123456789012345678901234567890123456789012345678901234`
|
|
171
171
|
- `--config <file>`, e.g. `--config foobar.json`
|
|
172
|
-
- `--
|
|
172
|
+
- `--env` use a pre-defined environment, e.g. `--env dev2` to use the [development environment](https://github.com/streamr-dev/streamr-docker-dev)
|
|
173
173
|
|
|
174
174
|
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.
|
|
175
175
|
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import '../src/logLevel'
|
|
3
|
+
|
|
4
|
+
import { DhtNode, PeerDescriptor, toDhtAddress, toNodeId } from '@streamr/dht'
|
|
5
|
+
import StreamrClient, { DhtAddress } from '@streamr/sdk'
|
|
6
|
+
import { NetworkNode, NodeInfo, StreamPartitionInfo } from '@streamr/trackerless-network'
|
|
7
|
+
import { binaryToHex, ChangeFieldType, Logger } from '@streamr/utils'
|
|
8
|
+
import { createClientCommand } from '../src/command'
|
|
9
|
+
import semver from 'semver'
|
|
10
|
+
|
|
11
|
+
const logger = new Logger(module)
|
|
12
|
+
|
|
13
|
+
export type NormalizedNodeInfo = ChangeFieldType<
|
|
14
|
+
NodeInfo,
|
|
15
|
+
'streamPartitions',
|
|
16
|
+
Omit<StreamPartitionInfo, 'deprecatedContentDeliveryLayerNeighbors'>[]>
|
|
17
|
+
|
|
18
|
+
const toNormalizeNodeInfo = (info: NodeInfo): NormalizedNodeInfo => {
|
|
19
|
+
const isLegacyFormat = semver.satisfies(semver.coerce(info.applicationVersion)!, '< 102.0.0')
|
|
20
|
+
return {
|
|
21
|
+
...info,
|
|
22
|
+
streamPartitions: info.streamPartitions.map((sp: StreamPartitionInfo) => ({
|
|
23
|
+
...sp,
|
|
24
|
+
contentDeliveryLayerNeighbors: !isLegacyFormat
|
|
25
|
+
? sp.contentDeliveryLayerNeighbors
|
|
26
|
+
: sp.deprecatedContentDeliveryLayerNeighbors.map((n) => ({
|
|
27
|
+
peerDescriptor: n
|
|
28
|
+
}))
|
|
29
|
+
}))
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const createPeerDescriptorOutput = (peerDescriptor: PeerDescriptor) => {
|
|
34
|
+
return {
|
|
35
|
+
nodeId: toNodeId(peerDescriptor),
|
|
36
|
+
type: peerDescriptor.type,
|
|
37
|
+
udp: peerDescriptor.udp,
|
|
38
|
+
tcp: peerDescriptor.tcp,
|
|
39
|
+
websocket: peerDescriptor.websocket,
|
|
40
|
+
region: peerDescriptor.region,
|
|
41
|
+
ipAddress: peerDescriptor.ipAddress,
|
|
42
|
+
publicKey: (peerDescriptor.publicKey !== undefined) ? binaryToHex(peerDescriptor.publicKey) : undefined,
|
|
43
|
+
signature: (peerDescriptor.signature !== undefined) ? binaryToHex(peerDescriptor.signature) : undefined
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const createNodeInfoOutput = (nodeInfo: NormalizedNodeInfo) => {
|
|
48
|
+
return {
|
|
49
|
+
peerDescriptor: createPeerDescriptorOutput(nodeInfo.peerDescriptor),
|
|
50
|
+
controlLayer: {
|
|
51
|
+
neighbors: nodeInfo.controlLayer.neighbors.map((n) => toNodeId(n)),
|
|
52
|
+
connections: nodeInfo.controlLayer.connections.map((n) => toNodeId(n))
|
|
53
|
+
},
|
|
54
|
+
streamPartitions: nodeInfo.streamPartitions.map((sp) => ({
|
|
55
|
+
id: sp.id,
|
|
56
|
+
controlLayerNeighbors: sp.controlLayerNeighbors.map((n) => toNodeId(n)),
|
|
57
|
+
contentDeliveryLayerNeighbors: sp.contentDeliveryLayerNeighbors.map((n) => ({
|
|
58
|
+
nodeId: toNodeId(n.peerDescriptor),
|
|
59
|
+
rtt: n.rtt
|
|
60
|
+
}))
|
|
61
|
+
})),
|
|
62
|
+
applicationVersion: nodeInfo.applicationVersion
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
createClientCommand(async (client: StreamrClient, nodeId: string) => {
|
|
67
|
+
const networkNode = await client.getNode().getNode() as NetworkNode
|
|
68
|
+
const controlLayerNode = networkNode.stack.getControlLayerNode()
|
|
69
|
+
const peerDescriptors = await (controlLayerNode as DhtNode).findClosestNodesFromDht(nodeId as DhtAddress)
|
|
70
|
+
const peerDescriptor = peerDescriptors.find((pd) => toDhtAddress(pd.nodeId) === nodeId)
|
|
71
|
+
if (peerDescriptor !== undefined) {
|
|
72
|
+
const info = await networkNode.stack.fetchNodeInfo(peerDescriptor)
|
|
73
|
+
const normalizedInfo = toNormalizeNodeInfo(info)
|
|
74
|
+
console.info(JSON.stringify(createNodeInfoOutput(normalizedInfo), undefined, 4))
|
|
75
|
+
} else {
|
|
76
|
+
logger.error('No peer descriptor found')
|
|
77
|
+
}
|
|
78
|
+
})
|
|
79
|
+
.description('show detailed information about a node')
|
|
80
|
+
.arguments('nodeId')
|
|
81
|
+
.parseAsync()
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import '../src/logLevel'
|
|
3
|
+
|
|
4
|
+
import { StreamrClient, _operatorContractUtils } from '@streamr/sdk'
|
|
5
|
+
import { createClientCommand } from '../src/command'
|
|
6
|
+
import { parseEther } from 'ethers'
|
|
7
|
+
|
|
8
|
+
createClientCommand(async (client: StreamrClient, operatorAddress: string, dataTokenAmount: string) => {
|
|
9
|
+
await _operatorContractUtils.delegate(
|
|
10
|
+
await client.getSigner(),
|
|
11
|
+
operatorAddress,
|
|
12
|
+
parseEther(dataTokenAmount),
|
|
13
|
+
_operatorContractUtils.getTestTokenContract()
|
|
14
|
+
)
|
|
15
|
+
})
|
|
16
|
+
.description('delegate funds to an operator')
|
|
17
|
+
.arguments('<operatorAddress> <dataTokenAmount>')
|
|
18
|
+
.parseAsync()
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import '../src/logLevel'
|
|
3
|
+
|
|
4
|
+
import { StreamrClient, _operatorContractUtils } from '@streamr/sdk'
|
|
5
|
+
import { createClientCommand } from '../src/command'
|
|
6
|
+
import { parseEther } from 'ethers'
|
|
7
|
+
|
|
8
|
+
createClientCommand(async (client: StreamrClient, operatorContractAddress: string, sponsorshipAddress: string, dataTokenAmount: string) => {
|
|
9
|
+
const operatorContract = _operatorContractUtils.getOperatorContract(operatorContractAddress).connect(await client.getSigner())
|
|
10
|
+
await _operatorContractUtils.stake(
|
|
11
|
+
operatorContract,
|
|
12
|
+
sponsorshipAddress,
|
|
13
|
+
parseEther(dataTokenAmount)
|
|
14
|
+
)
|
|
15
|
+
})
|
|
16
|
+
.description('stake funds to a sponsorship')
|
|
17
|
+
.arguments('<operatorContractAddress> <sponsorshipAddress> <dataTokenAmount>')
|
|
18
|
+
.parseAsync()
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import '../src/logLevel'
|
|
3
|
+
|
|
4
|
+
import { StreamrClient, _operatorContractUtils } from '@streamr/sdk'
|
|
5
|
+
import { createClientCommand } from '../src/command'
|
|
6
|
+
import { parseEther } from 'ethers'
|
|
7
|
+
|
|
8
|
+
createClientCommand(async (client: StreamrClient, operatorAddress: string, dataTokenAmount: string) => {
|
|
9
|
+
await _operatorContractUtils.undelegate(
|
|
10
|
+
await client.getSigner(),
|
|
11
|
+
_operatorContractUtils.getOperatorContract(operatorAddress),
|
|
12
|
+
parseEther(dataTokenAmount)
|
|
13
|
+
)
|
|
14
|
+
})
|
|
15
|
+
.description('undelegate funds from an operator')
|
|
16
|
+
.arguments('<operatorAddress> <dataTokenAmount>')
|
|
17
|
+
.parseAsync()
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import '../src/logLevel'
|
|
3
|
+
|
|
4
|
+
import { StreamrClient, _operatorContractUtils } from '@streamr/sdk'
|
|
5
|
+
import { createClientCommand } from '../src/command'
|
|
6
|
+
|
|
7
|
+
createClientCommand(async (client: StreamrClient, operatorContractAddress: string, sponsorshipAddress: string) => {
|
|
8
|
+
const operatorContract = _operatorContractUtils.getOperatorContract(operatorContractAddress).connect(await client.getSigner())
|
|
9
|
+
await _operatorContractUtils.unstake(
|
|
10
|
+
operatorContract,
|
|
11
|
+
sponsorshipAddress
|
|
12
|
+
)
|
|
13
|
+
})
|
|
14
|
+
.arguments('<operatorContractAddress> <sponsorshipAddress>')
|
|
15
|
+
.description('unstake all funds from a sponsorship')
|
|
16
|
+
.parseAsync()
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import '../src/logLevel'
|
|
3
|
+
|
|
4
|
+
import StreamrClient from '@streamr/sdk'
|
|
5
|
+
import { createClientCommand } from '../src/command'
|
|
6
|
+
|
|
7
|
+
createClientCommand(async (client: StreamrClient) => {
|
|
8
|
+
const config = client.getConfig()
|
|
9
|
+
console.info(JSON.stringify(config, undefined, 4))
|
|
10
|
+
})
|
|
11
|
+
.parseAsync()
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import '../src/logLevel'
|
|
3
|
+
|
|
4
|
+
import { StreamrClient, _operatorContractUtils } from '@streamr/sdk'
|
|
5
|
+
import { createClientCommand } from '../src/command'
|
|
6
|
+
import { parseEther } from 'ethers'
|
|
7
|
+
|
|
8
|
+
createClientCommand(async (client: StreamrClient, sponsorshipAddress: string, dataTokenAmount: string) => {
|
|
9
|
+
await _operatorContractUtils.sponsor(
|
|
10
|
+
await client.getSigner(),
|
|
11
|
+
sponsorshipAddress,
|
|
12
|
+
parseEther(dataTokenAmount),
|
|
13
|
+
_operatorContractUtils.getTestTokenContract()
|
|
14
|
+
)
|
|
15
|
+
})
|
|
16
|
+
.description('sponsor a stream')
|
|
17
|
+
.arguments('<sponsorshipAddress> <tokenAmount>')
|
|
18
|
+
.parseAsync()
|
|
@@ -117,6 +117,6 @@ createCommand()
|
|
|
117
117
|
? fs.readFileSync(topologyDefinitionFile, 'utf-8')
|
|
118
118
|
: await readStdin()
|
|
119
119
|
// TODO could validate the content
|
|
120
|
-
console.
|
|
120
|
+
console.info(createGraph(JSON.parse(topologyDefinition) as Topology))
|
|
121
121
|
})
|
|
122
122
|
.parse()
|
package/bin/streamr-internal.ts
CHANGED
|
@@ -6,5 +6,12 @@ program
|
|
|
6
6
|
.version(pkg.version)
|
|
7
7
|
.usage('<command> [<args>]')
|
|
8
8
|
.description('subcommands for internal use, the API of the commands may change')
|
|
9
|
+
.command('node-info', 'info about a node')
|
|
9
10
|
.command('visualize-topology', 'visualize network topology')
|
|
11
|
+
.command('show-sdk-config', 'show config used by internal StreamrClient')
|
|
12
|
+
.command('sponsorship-sponsor', 'sponsor a sponsorship')
|
|
13
|
+
.command('operator-delegate', 'delegate funds to an operator')
|
|
14
|
+
.command('operator-undelegate', 'undelegate funds from an operator')
|
|
15
|
+
.command('operator-stake', 'stake operator\'s funds to a sponsorship')
|
|
16
|
+
.command('operator-unstake', 'unstake all operator\'s funds from a sponsorship')
|
|
10
17
|
.parse()
|
|
@@ -2,9 +2,13 @@
|
|
|
2
2
|
import { createFnParseInt } from '../src/common'
|
|
3
3
|
import { createCommand, Options as BaseOptions } from '../src/command'
|
|
4
4
|
import { randomString } from '@streamr/utils'
|
|
5
|
+
import crypto from 'crypto'
|
|
5
6
|
|
|
6
7
|
interface Options extends BaseOptions {
|
|
7
8
|
rate: number
|
|
9
|
+
binary: boolean
|
|
10
|
+
minLength: number
|
|
11
|
+
maxLength: number
|
|
8
12
|
}
|
|
9
13
|
|
|
10
14
|
function genArray<T>(size: number, elementFn: () => T): T[] {
|
|
@@ -15,24 +19,33 @@ function genArray<T>(size: number, elementFn: () => T): T[] {
|
|
|
15
19
|
return arr
|
|
16
20
|
}
|
|
17
21
|
|
|
18
|
-
export const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
export const generateJson = (): string => {
|
|
23
|
+
return JSON.stringify({
|
|
24
|
+
someText: randomString(64),
|
|
25
|
+
aNumber: Math.random() * 10000,
|
|
26
|
+
bNumber: Math.random(),
|
|
27
|
+
yesOrNo: Math.random() > 0.5,
|
|
28
|
+
arrayOfStrings: genArray(Math.floor(Math.random() * 20), () => randomString(8)),
|
|
29
|
+
arrayOfIntegers: genArray(Math.floor(Math.random() * 10), () => Math.floor(Math.random() * 100))
|
|
30
|
+
})
|
|
31
|
+
}
|
|
27
32
|
|
|
28
|
-
|
|
29
|
-
|
|
33
|
+
export const generateBinary = ({ minLength, maxLength }: Options): string => {
|
|
34
|
+
const length = Math.floor(Math.random() * (maxLength - minLength + 1)) + minLength
|
|
35
|
+
const buffer = crypto.randomBytes(length)
|
|
36
|
+
return buffer.toString('hex')
|
|
30
37
|
}
|
|
31
38
|
|
|
32
39
|
createCommand()
|
|
33
|
-
.description('generate and print semi-random JSON data to stdout')
|
|
40
|
+
.description('generate and print semi-random JSON data or random binary data (hexadecimal) to stdout')
|
|
34
41
|
.option('-r, --rate <n>', 'rate in milliseconds', createFnParseInt('--rate'), 500)
|
|
42
|
+
.option('--binary', 'generate binary data instead of JSON')
|
|
43
|
+
.option('--min-length <n>', 'minimum message length in bytes (only for binary data)', createFnParseInt('--min-length'), 512)
|
|
44
|
+
.option('--max-length <n>', 'maximum message length in bytes (only for binary data)', createFnParseInt('--max-length'), 4096)
|
|
35
45
|
.action((options: Options) => {
|
|
36
|
-
generate
|
|
46
|
+
const generate = options.binary ? generateBinary : generateJson
|
|
47
|
+
setInterval(() => {
|
|
48
|
+
console.info(generate(options))
|
|
49
|
+
}, options.rate)
|
|
37
50
|
})
|
|
38
51
|
.parse()
|
package/bin/streamr-mock-data.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import '../src/logLevel'
|
|
3
|
+
|
|
3
4
|
import EasyTable from 'easy-table'
|
|
4
5
|
import { StreamrClient } from '@streamr/sdk'
|
|
5
6
|
import { createClientCommand } from '../src/command'
|
|
@@ -7,12 +8,12 @@ import { createClientCommand } from '../src/command'
|
|
|
7
8
|
createClientCommand((async (client: StreamrClient, storageNodeAddress: string) => {
|
|
8
9
|
const { streams } = await client.getStoredStreams(storageNodeAddress)
|
|
9
10
|
if (streams.length > 0) {
|
|
10
|
-
console.info(EasyTable.print(streams.map((stream) => {
|
|
11
|
+
console.info(EasyTable.print(await Promise.all(streams.map(async (stream) => {
|
|
11
12
|
return {
|
|
12
13
|
id: stream.id,
|
|
13
|
-
partitions: stream.
|
|
14
|
+
partitions: await stream.getPartitionCount()
|
|
14
15
|
}
|
|
15
|
-
})))
|
|
16
|
+
}))))
|
|
16
17
|
}
|
|
17
18
|
}))
|
|
18
19
|
.arguments('<storageNodeAddress>')
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import '../src/logLevel'
|
|
3
|
+
|
|
3
4
|
import { StreamrClient } from '@streamr/sdk'
|
|
4
5
|
import { createFnParseInt } from '../src/common'
|
|
5
6
|
import { createClientCommand, Options as BaseOptions } from '../src/command'
|
|
@@ -18,7 +19,7 @@ createClientCommand(async (client: StreamrClient, streamIdOrPath: string, option
|
|
|
18
19
|
partitions: options.partitions
|
|
19
20
|
}
|
|
20
21
|
const stream = await client.createStream(body)
|
|
21
|
-
console.info(JSON.stringify({ id: stream.id, ...stream.getMetadata() }, null, 2))
|
|
22
|
+
console.info(JSON.stringify({ id: stream.id, ...await stream.getMetadata() }, null, 2))
|
|
22
23
|
})
|
|
23
24
|
.arguments('<streamId>')
|
|
24
25
|
.description('create a new stream')
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import '../src/logLevel'
|
|
3
|
+
|
|
3
4
|
import { Writable } from 'stream'
|
|
4
5
|
import { StreamrClient } from '@streamr/sdk'
|
|
5
|
-
import { wait } from '@streamr/utils'
|
|
6
|
+
import { hexToBinary, wait } from '@streamr/utils'
|
|
6
7
|
import es from 'event-stream'
|
|
7
8
|
import { createClientCommand, Options as BaseOptions } from '../src/command'
|
|
8
9
|
|
|
@@ -10,6 +11,10 @@ interface Options extends BaseOptions {
|
|
|
10
11
|
partitionKeyField?: string
|
|
11
12
|
}
|
|
12
13
|
|
|
14
|
+
const isHexadecimal = (str: string): boolean => {
|
|
15
|
+
return /^[0-9a-fA-F]+$/.test(str)
|
|
16
|
+
}
|
|
17
|
+
|
|
13
18
|
const publishStream = (
|
|
14
19
|
stream: string,
|
|
15
20
|
partitionKeyField: string | undefined,
|
|
@@ -18,21 +23,26 @@ const publishStream = (
|
|
|
18
23
|
const writable = new Writable({
|
|
19
24
|
objectMode: true,
|
|
20
25
|
write: (data: any, _: any, done: any) => {
|
|
21
|
-
let
|
|
26
|
+
let message = null
|
|
22
27
|
// ignore newlines, etc
|
|
23
28
|
if (!data || String(data).trim() === '') {
|
|
24
29
|
done()
|
|
25
30
|
return
|
|
26
31
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
const trimmedData = String(data).trim()
|
|
33
|
+
if (isHexadecimal(trimmedData)) {
|
|
34
|
+
message = hexToBinary(trimmedData)
|
|
35
|
+
} else {
|
|
36
|
+
try {
|
|
37
|
+
message = JSON.parse(trimmedData)
|
|
38
|
+
} catch (e) {
|
|
39
|
+
console.error(data.toString())
|
|
40
|
+
done(e)
|
|
41
|
+
return
|
|
42
|
+
}
|
|
33
43
|
}
|
|
34
|
-
const partitionKey = (partitionKeyField !== undefined) ?
|
|
35
|
-
client.publish(stream,
|
|
44
|
+
const partitionKey = (partitionKeyField !== undefined && typeof message === 'object') ? message[partitionKeyField] : undefined
|
|
45
|
+
client.publish(stream, message, { partitionKey }).then(
|
|
36
46
|
() => done(),
|
|
37
47
|
(err) => done(err)
|
|
38
48
|
)
|
|
@@ -57,10 +67,12 @@ createClientCommand(async (client: StreamrClient, streamId: string, options: Opt
|
|
|
57
67
|
await wait(2000)
|
|
58
68
|
resolve(undefined)
|
|
59
69
|
})
|
|
70
|
+
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
60
71
|
.once('error', (err: any) => reject(err) )
|
|
61
72
|
})
|
|
62
73
|
})
|
|
63
74
|
.arguments('<streamId>')
|
|
64
|
-
.description('publish to a stream by reading JSON messages from stdin line-by-line')
|
|
65
|
-
|
|
75
|
+
.description('publish to a stream by reading JSON messages from stdin line-by-line or hexadecimal strings for binary data')
|
|
76
|
+
// eslint-disable-next-line max-len
|
|
77
|
+
.option('-k, --partition-key-field <string>', 'field name in each message to use for assigning the message to a stream partition (only for JSON data)')
|
|
66
78
|
.parseAsync()
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import '../src/logLevel'
|
|
3
|
+
|
|
3
4
|
import { StreamrClient, SearchStreamsPermissionFilter, StreamPermission } from '@streamr/sdk'
|
|
4
5
|
import { createClientCommand, Options as BaseOptions } from '../src/command'
|
|
5
6
|
import { Option } from 'commander'
|
|
@@ -22,7 +23,7 @@ const createPermissionFilter = async (
|
|
|
22
23
|
): Promise<SearchStreamsPermissionFilter | undefined> => {
|
|
23
24
|
if (user !== undefined) {
|
|
24
25
|
return {
|
|
25
|
-
|
|
26
|
+
userId: (getOptionType(user) === OptionType.ARGUMENT) ? user as string : await client.getUserId(),
|
|
26
27
|
allowPublic: allowPublic ?? false,
|
|
27
28
|
allOf,
|
|
28
29
|
anyOf
|
|
@@ -49,7 +50,7 @@ createClientCommand(async (client: StreamrClient, term: string | undefined, opti
|
|
|
49
50
|
)
|
|
50
51
|
const streams = client.searchStreams(term, permissionFilter)
|
|
51
52
|
for await (const stream of streams) {
|
|
52
|
-
console.
|
|
53
|
+
console.info(stream.id)
|
|
53
54
|
}
|
|
54
55
|
})
|
|
55
56
|
.arguments('[term]')
|
|
@@ -1,21 +1,30 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import '../src/logLevel'
|
|
3
|
+
|
|
3
4
|
import { StreamrClient } from '@streamr/sdk'
|
|
4
5
|
import { createClientCommand, Options as BaseOptions } from '../src/command'
|
|
5
6
|
import { getPermissionId } from '../src/permission'
|
|
7
|
+
import { omit } from 'lodash'
|
|
6
8
|
|
|
7
9
|
interface Options extends BaseOptions {
|
|
8
10
|
includePermissions: boolean
|
|
9
11
|
}
|
|
10
12
|
|
|
13
|
+
const withRenamedField = (obj: any, from: string, to: string) => {
|
|
14
|
+
return {
|
|
15
|
+
...omit(obj, from),
|
|
16
|
+
[to]: obj[from]
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
11
20
|
createClientCommand(async (client: StreamrClient, streamId: string, options: Options) => {
|
|
12
21
|
const stream = await client.getStream(streamId)
|
|
13
|
-
const obj: any = { id: stream.id, ...stream.getMetadata() }
|
|
22
|
+
const obj: any = { id: stream.id, ...await stream.getMetadata() }
|
|
14
23
|
if (options.includePermissions) {
|
|
15
24
|
const assigments = await stream.getPermissions()
|
|
16
25
|
obj.permissions = assigments.map((assignment) => {
|
|
17
26
|
return {
|
|
18
|
-
...assignment,
|
|
27
|
+
...withRenamedField(assignment, 'userId', 'user'),
|
|
19
28
|
permissions: assignment.permissions.map(getPermissionId)
|
|
20
29
|
}
|
|
21
30
|
})
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import '../src/logLevel'
|
|
3
|
+
|
|
3
4
|
import omit from 'lodash/omit'
|
|
4
5
|
import isString from 'lodash/isString'
|
|
5
6
|
import { StreamrClient, MessageMetadata } from '@streamr/sdk'
|
|
@@ -15,7 +16,7 @@ interface Options extends BaseOptions {
|
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
createClientCommand(async (client: StreamrClient, streamId: string, options: Options) => {
|
|
18
|
-
const formContent = (content: unknown) =>
|
|
19
|
+
const formContent = (content: unknown) => content instanceof Uint8Array ? binaryToHex(content) : content
|
|
19
20
|
const formMessage = options.withMetadata
|
|
20
21
|
? (content: unknown, metadata: MessageMetadata) => ({ content: formContent(content), metadata: omit(metadata, 'streamMessage') })
|
|
21
22
|
: (content: unknown) => formContent(content)
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import '../src/logLevel'
|
|
3
|
+
|
|
3
4
|
import { StreamrClient } from '@streamr/sdk'
|
|
4
5
|
import { createClientCommand } from '../src/command'
|
|
5
6
|
|
|
6
7
|
createClientCommand(async (client: StreamrClient) => {
|
|
7
|
-
console.info(await client.
|
|
8
|
+
console.info(await client.getUserId())
|
|
8
9
|
})
|
|
9
10
|
.description('displays your public address')
|
|
10
11
|
.parseAsync()
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import '../src/logLevel';
|
|
3
|
+
import { NodeInfo, StreamPartitionInfo } from '@streamr/trackerless-network';
|
|
4
|
+
import { ChangeFieldType } from '@streamr/utils';
|
|
5
|
+
export type NormalizedNodeInfo = ChangeFieldType<NodeInfo, 'streamPartitions', Omit<StreamPartitionInfo, 'deprecatedContentDeliveryLayerNeighbors'>[]>;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
require("../src/logLevel");
|
|
8
|
+
const dht_1 = require("@streamr/dht");
|
|
9
|
+
const utils_1 = require("@streamr/utils");
|
|
10
|
+
const command_1 = require("../src/command");
|
|
11
|
+
const semver_1 = __importDefault(require("semver"));
|
|
12
|
+
const logger = new utils_1.Logger(module);
|
|
13
|
+
const toNormalizeNodeInfo = (info) => {
|
|
14
|
+
const isLegacyFormat = semver_1.default.satisfies(semver_1.default.coerce(info.applicationVersion), '< 102.0.0');
|
|
15
|
+
return {
|
|
16
|
+
...info,
|
|
17
|
+
streamPartitions: info.streamPartitions.map((sp) => ({
|
|
18
|
+
...sp,
|
|
19
|
+
contentDeliveryLayerNeighbors: !isLegacyFormat
|
|
20
|
+
? sp.contentDeliveryLayerNeighbors
|
|
21
|
+
: sp.deprecatedContentDeliveryLayerNeighbors.map((n) => ({
|
|
22
|
+
peerDescriptor: n
|
|
23
|
+
}))
|
|
24
|
+
}))
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
const createPeerDescriptorOutput = (peerDescriptor) => {
|
|
28
|
+
return {
|
|
29
|
+
nodeId: (0, dht_1.toNodeId)(peerDescriptor),
|
|
30
|
+
type: peerDescriptor.type,
|
|
31
|
+
udp: peerDescriptor.udp,
|
|
32
|
+
tcp: peerDescriptor.tcp,
|
|
33
|
+
websocket: peerDescriptor.websocket,
|
|
34
|
+
region: peerDescriptor.region,
|
|
35
|
+
ipAddress: peerDescriptor.ipAddress,
|
|
36
|
+
publicKey: (peerDescriptor.publicKey !== undefined) ? (0, utils_1.binaryToHex)(peerDescriptor.publicKey) : undefined,
|
|
37
|
+
signature: (peerDescriptor.signature !== undefined) ? (0, utils_1.binaryToHex)(peerDescriptor.signature) : undefined
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
const createNodeInfoOutput = (nodeInfo) => {
|
|
41
|
+
return {
|
|
42
|
+
peerDescriptor: createPeerDescriptorOutput(nodeInfo.peerDescriptor),
|
|
43
|
+
controlLayer: {
|
|
44
|
+
neighbors: nodeInfo.controlLayer.neighbors.map((n) => (0, dht_1.toNodeId)(n)),
|
|
45
|
+
connections: nodeInfo.controlLayer.connections.map((n) => (0, dht_1.toNodeId)(n))
|
|
46
|
+
},
|
|
47
|
+
streamPartitions: nodeInfo.streamPartitions.map((sp) => ({
|
|
48
|
+
id: sp.id,
|
|
49
|
+
controlLayerNeighbors: sp.controlLayerNeighbors.map((n) => (0, dht_1.toNodeId)(n)),
|
|
50
|
+
contentDeliveryLayerNeighbors: sp.contentDeliveryLayerNeighbors.map((n) => ({
|
|
51
|
+
nodeId: (0, dht_1.toNodeId)(n.peerDescriptor),
|
|
52
|
+
rtt: n.rtt
|
|
53
|
+
}))
|
|
54
|
+
})),
|
|
55
|
+
applicationVersion: nodeInfo.applicationVersion
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
(0, command_1.createClientCommand)(async (client, nodeId) => {
|
|
59
|
+
const networkNode = await client.getNode().getNode();
|
|
60
|
+
const controlLayerNode = networkNode.stack.getControlLayerNode();
|
|
61
|
+
const peerDescriptors = await controlLayerNode.findClosestNodesFromDht(nodeId);
|
|
62
|
+
const peerDescriptor = peerDescriptors.find((pd) => (0, dht_1.toDhtAddress)(pd.nodeId) === nodeId);
|
|
63
|
+
if (peerDescriptor !== undefined) {
|
|
64
|
+
const info = await networkNode.stack.fetchNodeInfo(peerDescriptor);
|
|
65
|
+
const normalizedInfo = toNormalizeNodeInfo(info);
|
|
66
|
+
console.info(JSON.stringify(createNodeInfoOutput(normalizedInfo), undefined, 4));
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
logger.error('No peer descriptor found');
|
|
70
|
+
}
|
|
71
|
+
})
|
|
72
|
+
.description('show detailed information about a node')
|
|
73
|
+
.arguments('nodeId')
|
|
74
|
+
.parseAsync();
|
|
75
|
+
//# sourceMappingURL=streamr-internal-node-info.js.map
|