@streamr/cli-tools 103.0.0-rc.0 → 103.0.0-rc.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.
Files changed (60) hide show
  1. package/dist/package.json +12 -6
  2. package/package.json +12 -6
  3. package/bin/streamr-internal-node-info.ts +0 -81
  4. package/bin/streamr-internal-operator-delegate.ts +0 -18
  5. package/bin/streamr-internal-operator-stake.ts +0 -18
  6. package/bin/streamr-internal-operator-undelegate.ts +0 -17
  7. package/bin/streamr-internal-operator-unstake.ts +0 -16
  8. package/bin/streamr-internal-show-sdk-config.ts +0 -11
  9. package/bin/streamr-internal-sponsorship-sponsor.ts +0 -18
  10. package/bin/streamr-internal-token-mint.ts +0 -21
  11. package/bin/streamr-internal-visualize-topology.ts +0 -122
  12. package/bin/streamr-internal.ts +0 -18
  13. package/bin/streamr-mock-data-generate.ts +0 -51
  14. package/bin/streamr-mock-data.ts +0 -10
  15. package/bin/streamr-storage-node-add-stream.ts +0 -13
  16. package/bin/streamr-storage-node-list-streams.ts +0 -21
  17. package/bin/streamr-storage-node-list.ts +0 -23
  18. package/bin/streamr-storage-node-register.ts +0 -14
  19. package/bin/streamr-storage-node-remove-stream.ts +0 -13
  20. package/bin/streamr-storage-node-show.ts +0 -13
  21. package/bin/streamr-storage-node-unregister.ts +0 -11
  22. package/bin/streamr-storage-node.ts +0 -16
  23. package/bin/streamr-stream-create.ts +0 -30
  24. package/bin/streamr-stream-grant-permission.ts +0 -10
  25. package/bin/streamr-stream-publish.ts +0 -78
  26. package/bin/streamr-stream-resend-from.ts +0 -33
  27. package/bin/streamr-stream-resend-last.ts +0 -31
  28. package/bin/streamr-stream-resend-range.ts +0 -39
  29. package/bin/streamr-stream-resend.ts +0 -12
  30. package/bin/streamr-stream-revoke-permission.ts +0 -10
  31. package/bin/streamr-stream-search.ts +0 -62
  32. package/bin/streamr-stream-show.ts +0 -37
  33. package/bin/streamr-stream-subscribe.ts +0 -43
  34. package/bin/streamr-stream.ts +0 -17
  35. package/bin/streamr-wallet-whoami.ts +0 -11
  36. package/bin/streamr-wallet.ts +0 -10
  37. package/bin/streamr.ts +0 -14
  38. package/jest.config.ts +0 -1
  39. package/src/client.ts +0 -34
  40. package/src/command.ts +0 -53
  41. package/src/common.ts +0 -43
  42. package/src/config.ts +0 -56
  43. package/src/logLevel.ts +0 -9
  44. package/src/permission.ts +0 -53
  45. package/src/resend.ts +0 -37
  46. package/test/environment.test.ts +0 -32
  47. package/test/internal-operator.test.ts +0 -57
  48. package/test/internal-sponsorship-sponsor.test.ts +0 -28
  49. package/test/mock-data.test.ts +0 -33
  50. package/test/storage-node.test.ts +0 -62
  51. package/test/stream-create.test.ts +0 -26
  52. package/test/stream-permission.test.ts +0 -29
  53. package/test/stream-publish-subscribe.test.ts +0 -108
  54. package/test/stream-resend.test.ts +0 -66
  55. package/test/stream-search.test.ts +0 -24
  56. package/test/stream-show.test.ts +0 -31
  57. package/test/utils.ts +0 -86
  58. package/test/wallet.test.ts +0 -11
  59. package/tsconfig.json +0 -3
  60. package/tsconfig.node.json +0 -16
@@ -1,30 +0,0 @@
1
- #!/usr/bin/env node
2
- import '../src/logLevel'
3
-
4
- import { StreamrClient } from '@streamr/sdk'
5
- import { createFnParseInt } from '../src/common'
6
- import { createClientCommand, Options as BaseOptions } from '../src/command'
7
-
8
- interface Options extends BaseOptions {
9
- description?: string
10
- streamConfig?: any
11
- partitions?: number
12
- }
13
-
14
- createClientCommand(async (client: StreamrClient, streamIdOrPath: string, options: Options) => {
15
- const body: any = {
16
- id: streamIdOrPath,
17
- description: options.description,
18
- config: options.streamConfig,
19
- partitions: options.partitions
20
- }
21
- const stream = await client.createStream(body)
22
- console.info(JSON.stringify({ id: stream.id, ...await stream.getMetadata() }, null, 2))
23
- })
24
- .arguments('<streamId>')
25
- .description('create a new stream')
26
- .option('-d, --description <description>', 'define a description')
27
- .option('-c, --stream-config <config>', 'define a configuration as JSON', (s: string) => JSON.parse(s))
28
- .option('-p, --partitions <count>', 'define a partition count',
29
- createFnParseInt('--partitions'))
30
- .parseAsync()
@@ -1,10 +0,0 @@
1
- #!/usr/bin/env node
2
- import '../src/logLevel'
3
-
4
- import { PermissionAssignment, Stream } from '@streamr/sdk'
5
- import { runModifyPermissionsCommand } from '../src/permission'
6
-
7
- runModifyPermissionsCommand(
8
- (stream: Stream, assigment: PermissionAssignment) => stream.grantPermissions(assigment),
9
- 'grant'
10
- )
@@ -1,78 +0,0 @@
1
- #!/usr/bin/env node
2
- import '../src/logLevel'
3
-
4
- import { Writable } from 'stream'
5
- import { StreamrClient } from '@streamr/sdk'
6
- import { hexToBinary, wait } from '@streamr/utils'
7
- import es from 'event-stream'
8
- import { createClientCommand, Options as BaseOptions } from '../src/command'
9
-
10
- interface Options extends BaseOptions {
11
- partitionKeyField?: string
12
- }
13
-
14
- const isHexadecimal = (str: string): boolean => {
15
- return /^[0-9a-fA-F]+$/.test(str)
16
- }
17
-
18
- const publishStream = (
19
- stream: string,
20
- partitionKeyField: string | undefined,
21
- client: StreamrClient
22
- ): Writable => {
23
- const writable = new Writable({
24
- objectMode: true,
25
- write: (data: any, _: any, done: any) => {
26
- let message = null
27
- // ignore newlines, etc
28
- if (!data || String(data).trim() === '') {
29
- done()
30
- return
31
- }
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
- }
43
- }
44
- const partitionKey = (partitionKeyField !== undefined && typeof message === 'object') ? message[partitionKeyField] : undefined
45
- client.publish(stream, message, { partitionKey }).then(
46
- () => done(),
47
- (err) => done(err)
48
- )
49
- }
50
- })
51
- return writable
52
- }
53
-
54
- createClientCommand(async (client: StreamrClient, streamId: string, options: Options) => {
55
- const ps = publishStream(streamId, options.partitionKeyField, client)
56
- return new Promise((resolve, reject) => {
57
- process.stdin
58
- .pipe(es.split())
59
- .pipe(ps)
60
- .once('finish', async () => {
61
- // We need to wait some time because the client.publish() may resolve the promise
62
- // before the node has propagated the message. That may happend if the node
63
- // has not yet connected to Tracker when client.publish() is called. In that case
64
- // the message is put to the propagation queue (activeTaskStore.add call in
65
- // network Propagation.ts:59) and the client.publish() promise resolves immeditatelly.
66
- // TODO Remove this wait when NET-604 has been resolved
67
- await wait(2000)
68
- resolve(undefined)
69
- })
70
- // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
71
- .once('error', (err: any) => reject(err) )
72
- })
73
- })
74
- .arguments('<streamId>')
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)')
78
- .parseAsync()
@@ -1,33 +0,0 @@
1
- #!/usr/bin/env node
2
- import '../src/logLevel'
3
-
4
- import { StreamrClient } from '@streamr/sdk'
5
- import { createClientCommand, Options as BaseOptions } from '../src/command'
6
- import { resend } from '../src/resend'
7
-
8
- interface Options extends BaseOptions {
9
- publisherId?: string
10
- disableOrdering: boolean
11
- subscribe: boolean
12
- }
13
-
14
- createClientCommand(async (client: StreamrClient, from: string, streamId: string, options: Options) => {
15
- const resendOptions = {
16
- from: {
17
- timestamp: Date.parse(from),
18
- sequenceNumber: 0
19
- },
20
- publisherId: options.publisherId
21
- }
22
- await resend(streamId, resendOptions, client, options.subscribe)
23
- }, {
24
- clientOptionsFactory: (options) => ({
25
- orderMessages: !options.disableOrdering
26
- })
27
- })
28
- .arguments('<from> <streamId>')
29
- .description('request messages starting from given date-time (format: "YYYY-MM-DDTHH:mm:ss.sssZ")')
30
- .option('--publisher-id <string>', 'filter results by publisher')
31
- .option('-d, --disable-ordering', 'disable ordering of messages by OrderingUtil', false)
32
- .option('-s, --subscribe', 'subscribe in addition to resend', false)
33
- .parseAsync()
@@ -1,31 +0,0 @@
1
- #!/usr/bin/env node
2
- import '../src/logLevel'
3
-
4
- import { StreamrClient } from '@streamr/sdk'
5
- import { createClientCommand, Options as BaseOptions } from '../src/command'
6
- import { resend } from '../src/resend'
7
-
8
- interface Options extends BaseOptions {
9
- disableOrdering: boolean
10
- subscribe: boolean
11
- }
12
-
13
- createClientCommand(async (client: StreamrClient, n: string, streamId: string, options: Options) => {
14
- if (isNaN(n as any)) {
15
- console.error('argument n is not a number')
16
- process.exit(1)
17
- }
18
- const resendOptions = {
19
- last: parseInt(n)
20
- }
21
- await resend(streamId, resendOptions, client, options.subscribe)
22
- }, {
23
- clientOptionsFactory: (options) => ({
24
- orderMessages: !options.disableOrdering
25
- })
26
- })
27
- .arguments('<n> <streamId>')
28
- .description('request last N messages')
29
- .option('-d, --disable-ordering', 'disable ordering of messages by OrderingUtil', false)
30
- .option('-s, --subscribe', 'subscribe in addition to resend', false)
31
- .parseAsync()
@@ -1,39 +0,0 @@
1
- #!/usr/bin/env node
2
- import '../src/logLevel'
3
-
4
- import { StreamrClient } from '@streamr/sdk'
5
- import { createClientCommand, Options as BaseOptions } from '../src/command'
6
- import { assertBothOrNoneDefined, resend } from '../src/resend'
7
-
8
- interface Options extends BaseOptions {
9
- publisherId?: string
10
- msgChainId?: string
11
- subscribe: boolean
12
- }
13
-
14
- createClientCommand(async (client: StreamrClient, from: string, to: string, streamId: string, options: Options) => {
15
- const resendOptions = {
16
- from: {
17
- timestamp: Date.parse(from),
18
- sequenceNumber: 0
19
- },
20
- to: {
21
- timestamp: Date.parse(to),
22
- sequenceNumber: 0
23
- },
24
- publisherId: options.publisherId,
25
- msgChainId: options.msgChainId
26
- }
27
- assertBothOrNoneDefined('publisherId', 'msgChainId', '--publisher-id must be accompanied by option --msg-chain-id', options)
28
- await resend(streamId, resendOptions, client, false)
29
- }, {
30
- clientOptionsFactory: (options) => ({
31
- orderMessages: !options.disableOrdering
32
- })
33
- })
34
- .arguments('<from> <to> <streamId>')
35
- .description('request messages between two given date-times (format: "YYYY-MM-DDTHH:mm:ss.sssZ")')
36
- .option('--publisher-id <string>', 'filter results by publisher')
37
- .option('--msg-chain-id <string>', 'filter results by message chain')
38
- .option('-d, --disable-ordering', 'disable ordering of messages by OrderingUtil', false)
39
- .parseAsync()
@@ -1,12 +0,0 @@
1
- #!/usr/bin/env node
2
- import '../src/logLevel'
3
-
4
- import { createCommand } from '../src/command'
5
-
6
- createCommand()
7
- .usage('<command> [<args>]')
8
- .description('request resend of stream and print JSON messages to stdout line-by-line')
9
- .command('from', 'request messages starting from given date-time')
10
- .command('last', 'request last N messages')
11
- .command('range', 'request messages between two given date-times')
12
- .parse()
@@ -1,10 +0,0 @@
1
- #!/usr/bin/env node
2
- import '../src/logLevel'
3
-
4
- import { PermissionAssignment, Stream } from '@streamr/sdk'
5
- import { runModifyPermissionsCommand } from '../src/permission'
6
-
7
- runModifyPermissionsCommand(
8
- (stream: Stream, assigment: PermissionAssignment) => stream.revokePermissions(assigment),
9
- 'revoke'
10
- )
@@ -1,62 +0,0 @@
1
- #!/usr/bin/env node
2
- import '../src/logLevel'
3
-
4
- import { StreamrClient, SearchStreamsPermissionFilter, StreamPermission } from '@streamr/sdk'
5
- import { createClientCommand, Options as BaseOptions } from '../src/command'
6
- import { Option } from 'commander'
7
- import { getPermission, PERMISSIONS } from '../src/permission'
8
- import { getOptionType, OptionType } from '../src/common'
9
-
10
- interface Options extends BaseOptions {
11
- user?: string | true
12
- public: boolean
13
- all?: StreamPermission[]
14
- any?: StreamPermission[]
15
- }
16
-
17
- const createPermissionFilter = async (
18
- user: string | true | undefined,
19
- allowPublic: boolean | undefined,
20
- allOf: StreamPermission[] | undefined,
21
- anyOf: StreamPermission[] | undefined,
22
- client: StreamrClient
23
- ): Promise<SearchStreamsPermissionFilter | undefined> => {
24
- if (user !== undefined) {
25
- return {
26
- userId: (getOptionType(user) === OptionType.ARGUMENT) ? user as string : await client.getUserId(),
27
- allowPublic: allowPublic ?? false,
28
- allOf,
29
- anyOf
30
- }
31
- } else if ((allowPublic !== undefined) || (allOf !== undefined) || (anyOf !== undefined)) {
32
- console.error('specify a user with "--user" when using "--public", "--all" or "--any"')
33
- process.exit(1)
34
- }
35
- }
36
-
37
- const createPermissionListOption = (id: string) => {
38
- return new Option(`--${id} <permissions>`, 'comma-separated list of permissions')
39
- .choices(Array.from(PERMISSIONS.keys()))
40
- .argParser((value: string) => value.split(',').map((id) => getPermission(id)))
41
- }
42
-
43
- createClientCommand(async (client: StreamrClient, term: string | undefined, options: Options) => {
44
- const permissionFilter = await createPermissionFilter(
45
- options.user,
46
- options.public,
47
- options.all,
48
- options.any,
49
- client
50
- )
51
- const streams = client.searchStreams(term, permissionFilter)
52
- for await (const stream of streams) {
53
- console.info(stream.id)
54
- }
55
- })
56
- .arguments('[term]')
57
- .description('search streams')
58
- .option('--user [user]', 'a stream must have permissions for the given user, defaults to the authenticated user')
59
- .option('--public', 'the permission can be implicit (a public permission to the stream)')
60
- .addOption(createPermissionListOption('all'))
61
- .addOption(createPermissionListOption('any'))
62
- .parseAsync()
@@ -1,37 +0,0 @@
1
- #!/usr/bin/env node
2
- import '../src/logLevel'
3
-
4
- import { StreamrClient } from '@streamr/sdk'
5
- import { createClientCommand, Options as BaseOptions } from '../src/command'
6
- import { getPermissionId } from '../src/permission'
7
- import omit from 'lodash/omit'
8
-
9
- interface Options extends BaseOptions {
10
- includePermissions: boolean
11
- }
12
-
13
- const withRenamedField = (obj: any, from: string, to: string) => {
14
- return {
15
- ...omit(obj, from),
16
- [to]: obj[from]
17
- }
18
- }
19
-
20
- createClientCommand(async (client: StreamrClient, streamId: string, options: Options) => {
21
- const stream = await client.getStream(streamId)
22
- const obj: any = { id: stream.id, ...await stream.getMetadata() }
23
- if (options.includePermissions) {
24
- const assigments = await stream.getPermissions()
25
- obj.permissions = assigments.map((assignment) => {
26
- return {
27
- ...withRenamedField(assignment, 'userId', 'user'),
28
- permissions: assignment.permissions.map(getPermissionId)
29
- }
30
- })
31
- }
32
- console.info(JSON.stringify(obj, null, 2))
33
- })
34
- .arguments('<streamId>')
35
- .description('show detailed information about a stream')
36
- .option('--include-permissions', 'include list of permissions', false)
37
- .parseAsync()
@@ -1,43 +0,0 @@
1
- #!/usr/bin/env node
2
- import '../src/logLevel'
3
-
4
- import omit from 'lodash/omit'
5
- import isString from 'lodash/isString'
6
- import { StreamrClient, MessageMetadata } from '@streamr/sdk'
7
- import { createClientCommand, Options as BaseOptions } from '../src/command'
8
- import { createFnParseInt } from '../src/common'
9
- import { binaryToHex } from '@streamr/utils'
10
-
11
- interface Options extends BaseOptions {
12
- partition: number
13
- disableOrdering: boolean
14
- raw: boolean
15
- withMetadata: boolean
16
- }
17
-
18
- createClientCommand(async (client: StreamrClient, streamId: string, options: Options) => {
19
- const formContent = (content: unknown) => content instanceof Uint8Array ? binaryToHex(content) : content
20
- const formMessage = options.withMetadata
21
- ? (content: unknown, metadata: MessageMetadata) => ({ content: formContent(content), metadata: omit(metadata, 'streamMessage') })
22
- : (content: unknown) => formContent(content)
23
- await client.subscribe({
24
- streamId,
25
- partition: options.partition,
26
- raw: options.raw
27
- }, (content, metadata) => {
28
- const output = formMessage(content, metadata)
29
- console.info(isString(output) ? output : JSON.stringify(output))
30
- })
31
- }, {
32
- autoDestroyClient: false,
33
- clientOptionsFactory: (options) => ({
34
- orderMessages: !options.disableOrdering
35
- })
36
- })
37
- .arguments('<streamId>')
38
- .description('subscribe to a stream, prints JSON messages to stdout line-by-line')
39
- .option('-p, --partition [partition]', 'partition', createFnParseInt('--partition'), 0)
40
- .option('-d, --disable-ordering', 'disable ordering of messages by OrderingUtil', false)
41
- .option('-r, --raw', 'subscribe raw', false)
42
- .option('-m, --with-metadata', 'print each message with its metadata included', false)
43
- .parseAsync()
@@ -1,17 +0,0 @@
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('stream subcommands')
9
- .command('subscribe', 'subscribe to a stream')
10
- .command('publish', 'publish to a stream')
11
- .command('search', 'search for streams')
12
- .command('show', 'info about a stream')
13
- .command('create', 'create a new stream')
14
- .command('resend', 'request resend of a stream')
15
- .command('grant-permission', 'grant permission')
16
- .command('revoke-permission', 'revoke permission')
17
- .parse()
@@ -1,11 +0,0 @@
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
- console.info(await client.getUserId())
9
- })
10
- .description('displays your public address')
11
- .parseAsync()
@@ -1,10 +0,0 @@
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('wallet subcommands')
9
- .command('whoami', 'displays your public address')
10
- .parse()
package/bin/streamr.ts DELETED
@@ -1,14 +0,0 @@
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> <subcommand> [<args>]')
8
- .description('command line tools for interacting with Streamr https://streamr.network')
9
- .command('stream', 'stream subcommands')
10
- .command('storage-node', 'storage node subcommands')
11
- .command('mock-data', 'mock data subcommands')
12
- .command('wallet', 'wallet subcommands')
13
- .command('internal', 'subcommands for internal use')
14
- .parse()
package/jest.config.ts DELETED
@@ -1 +0,0 @@
1
- export { default } from '../../jest.config'
package/src/client.ts DELETED
@@ -1,34 +0,0 @@
1
- import { StreamrClient, StreamrClientConfig } from '@streamr/sdk'
2
- import merge from 'lodash/merge'
3
- import { Options } from './command'
4
- import { getConfig } from './config'
5
-
6
- export const getClientConfig = (commandOptions: Options, overridenOptions: StreamrClientConfig = {}): StreamrClientConfig => {
7
- const configFileJson = getConfig(commandOptions.config)?.client
8
- const environmentOptions = { environment: commandOptions.env }
9
- const authenticationOptions = (commandOptions.privateKey !== undefined) ? { auth: { privateKey: commandOptions.privateKey } } : undefined
10
- return merge(
11
- configFileJson,
12
- environmentOptions,
13
- authenticationOptions,
14
- overridenOptions
15
- )
16
- }
17
-
18
- const addInterruptHandler = (client: StreamrClient) => {
19
- process.on('SIGINT', async () => {
20
- try {
21
- await client.destroy()
22
- } catch {
23
- // no-op
24
- }
25
- process.exit()
26
- })
27
- }
28
-
29
- export const createClient = (commandOptions: Options, overridenOptions: StreamrClientConfig = {}): StreamrClient => {
30
- const config = getClientConfig(commandOptions, overridenOptions)
31
- const client = new StreamrClient(config)
32
- addInterruptHandler(client)
33
- return client
34
- }
package/src/command.ts DELETED
@@ -1,53 +0,0 @@
1
- import { DEFAULT_ENVIRONMENT_ID, ENVIRONMENT_IDS, EnvironmentId, StreamrClientConfig } from '@streamr/sdk'
2
- import commander, { Command } from 'commander'
3
- import pkg from '../package.json'
4
- import { createClient } from './client'
5
- import { createFnParseEnum, formEnumArgValueDescription } from './common'
6
-
7
- export interface Options {
8
- privateKey?: string
9
- config?: string
10
- env?: EnvironmentId
11
- }
12
-
13
- export const createCommand = (): commander.Command => {
14
- return new Command()
15
- .version(pkg.version)
16
- .showHelpAfterError()
17
- .allowExcessArguments(false)
18
- }
19
-
20
- export interface CommandOpts {
21
- autoDestroyClient?: boolean
22
- clientOptionsFactory?: (options: any) => StreamrClientConfig
23
- }
24
-
25
- export const createClientCommand = (
26
- action: (...handleArgs: any[]) => Promise<void>,
27
- opts: CommandOpts = {
28
- autoDestroyClient: true,
29
- clientOptionsFactory: () => ({})
30
- }
31
- ): commander.Command => {
32
- return createCommand()
33
- .option('--private-key <key>', 'use an Ethereum private key to authenticate')
34
- .option('--config <file>', 'read connection and authentication settings from a config file')
35
- .option('--env <environmentId>', `use pre-defined environment (${formEnumArgValueDescription(ENVIRONMENT_IDS, DEFAULT_ENVIRONMENT_ID)})`,
36
- createFnParseEnum('env', ENVIRONMENT_IDS))
37
- .action(async (...args: any[]) => {
38
- const commandOptions = args[args.length - 1].opts()
39
- try {
40
- const client = createClient(commandOptions, opts.clientOptionsFactory!(commandOptions))
41
- try {
42
- await action(...[client].concat(args))
43
- } finally {
44
- if (opts.autoDestroyClient) {
45
- await client.destroy()
46
- }
47
- }
48
- } catch (e: any) {
49
- console.error(e)
50
- process.exit(1)
51
- }
52
- })
53
- }
package/src/common.ts DELETED
@@ -1,43 +0,0 @@
1
- export enum OptionType {
2
- FLAG, // e.g. "--enable"
3
- ARGUMENT // e.g. "--private-key 0x1234"
4
- }
5
-
6
- export const getOptionType = (value: string | boolean): OptionType | never => {
7
- if (typeof value === 'boolean') {
8
- return OptionType.FLAG
9
- } else if (typeof value === 'string') {
10
- return OptionType.ARGUMENT
11
- } else {
12
- throw new Error(`unknown option type (value: ${value})`)
13
- }
14
- }
15
-
16
- export function createFnParseInt(name: string): (s: string) => number {
17
- return (str: string) => {
18
- const n = parseInt(str, 10)
19
- if (isNaN(n)) {
20
- console.error(`${name} must be an integer (was "${str}")`)
21
- process.exit(1)
22
- }
23
- return n
24
- }
25
- }
26
-
27
- export function createFnParseEnum(name: string, allowedValues: string[]): (s: string) => string {
28
- return (value: string) => {
29
- if (!allowedValues.includes(value)) {
30
- console.error(`${name} must be one of: ${allowedValues.map((s) => wrapWithQuotes(s)).join(', ')}`)
31
- process.exit(1)
32
- }
33
- return value
34
- }
35
- }
36
-
37
- export const formEnumArgValueDescription = (allowedValues: string[], defaultValue: string): string => {
38
- return `one of: ${allowedValues.map(wrapWithQuotes).join(', ')}, default: ${wrapWithQuotes(defaultValue)}`
39
- }
40
-
41
- export const wrapWithQuotes = (str: string): string => {
42
- return `"${str}"`
43
- }
package/src/config.ts DELETED
@@ -1,56 +0,0 @@
1
- import path from 'path'
2
- import os from 'os'
3
- import { readFileSync } from 'fs'
4
- import { StreamrClientConfig } from '@streamr/sdk'
5
-
6
- interface Config {
7
- client: StreamrClientConfig
8
- }
9
-
10
- /*
11
- * Validate that the config contains at least one root level element: the "client" block.
12
- * The values of the "client" blocks are validated by StreamrClient when the configuration
13
- * is used.
14
- *
15
- * We don't check other root level elements. It is ok to use a Broker config file as
16
- * a cli-tools config file. In that case the file contains e.g. "plugins" block,
17
- * but cli-tools can just ignore that block.
18
- */
19
- const validateConfig = (config: any, fileName: string): void | never => {
20
- const CLIENT_CONFIG_BLOCK = 'client'
21
- if (config[CLIENT_CONFIG_BLOCK] === undefined) {
22
- throw new Error(`Missing root element "${CLIENT_CONFIG_BLOCK}" in ${fileName}`)
23
- }
24
- }
25
-
26
- const tryReadConfigFile = (fileName: string): Config | undefined | never => {
27
- let content
28
- try {
29
- content = readFileSync(fileName, 'utf8')
30
- } catch {
31
- return undefined
32
- }
33
- const json = JSON.parse(content)
34
- validateConfig(json, fileName)
35
- return json
36
- }
37
-
38
- export const getConfig = (id?: string): Config | undefined => {
39
- const CONFIG_DIRECTORY = path.join(os.homedir(), '.streamr', 'config')
40
- if (id !== undefined) {
41
- const fileNames = [
42
- id,
43
- path.join(CONFIG_DIRECTORY, `${id}.json`),
44
- ]
45
- for (const fileName of fileNames) {
46
- const content = tryReadConfigFile(fileName)
47
- if (content !== undefined) {
48
- return content
49
- }
50
- }
51
- throw new Error('Config file not found')
52
- } else {
53
- const fileName = path.join(CONFIG_DIRECTORY, `default.json`)
54
- return tryReadConfigFile(fileName)
55
- }
56
- }
package/src/logLevel.ts DELETED
@@ -1,9 +0,0 @@
1
- /*
2
- * Minimal logging for NetworkNode and other users of Logger.ts in the network package.
3
- * This file needs to be imported before any of the network package classes
4
- * so that the environment variable is updated before any Logger instances are created.
5
- * The import is needed for the files where network packages are used (typically
6
- * the files which call createClientCommand()).
7
- */
8
-
9
- process.env.LOG_LEVEL = process.env.LOG_LEVEL ?? 'error'