@streamr/cli-tools 5.0.0 → 6.0.0-alpha.2

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 (134) hide show
  1. package/.eslintignore +2 -0
  2. package/.eslintrc +6 -0
  3. package/CHANGELOG.md +20 -0
  4. package/README.md +42 -17
  5. package/bin/streamr-mock-data-generate.ts +38 -8
  6. package/bin/streamr-mock-data.ts +1 -1
  7. package/bin/streamr-storage-node-add-stream.ts +8 -22
  8. package/bin/streamr-storage-node-list-stream-parts.ts +18 -30
  9. package/bin/streamr-storage-node-list.ts +17 -36
  10. package/bin/streamr-storage-node-remove-stream.ts +8 -22
  11. package/bin/streamr-storage-node.ts +1 -1
  12. package/bin/streamr-stream-create.ts +17 -29
  13. package/bin/streamr-stream-grant-permission.ts +10 -0
  14. package/bin/streamr-stream-publish.ts +54 -21
  15. package/bin/streamr-stream-resend-from.ts +26 -0
  16. package/bin/streamr-stream-resend-last.ts +25 -0
  17. package/bin/streamr-stream-resend-range.ts +32 -0
  18. package/bin/streamr-stream-resend.ts +7 -102
  19. package/bin/streamr-stream-revoke-permission.ts +10 -0
  20. package/bin/streamr-stream-search.ts +17 -0
  21. package/bin/streamr-stream-show.ts +16 -16
  22. package/bin/streamr-stream-subscribe.ts +16 -16
  23. package/bin/streamr-stream.ts +3 -1
  24. package/bin/streamr.ts +1 -1
  25. package/dist/bin/streamr-mock-data-generate.d.ts +2 -0
  26. package/dist/bin/streamr-mock-data-generate.js +36 -9
  27. package/dist/bin/streamr-mock-data-generate.js.map +1 -0
  28. package/dist/bin/streamr-mock-data.d.ts +2 -0
  29. package/dist/bin/streamr-mock-data.js +2 -1
  30. package/dist/bin/streamr-mock-data.js.map +1 -0
  31. package/dist/bin/streamr-storage-node-add-stream.d.ts +2 -0
  32. package/dist/bin/streamr-storage-node-add-stream.js +9 -20
  33. package/dist/bin/streamr-storage-node-add-stream.js.map +1 -0
  34. package/dist/bin/streamr-storage-node-list-stream-parts.d.ts +2 -0
  35. package/dist/bin/streamr-storage-node-list-stream-parts.js +18 -24
  36. package/dist/bin/streamr-storage-node-list-stream-parts.js.map +1 -0
  37. package/dist/bin/streamr-storage-node-list.d.ts +2 -0
  38. package/dist/bin/streamr-storage-node-list.js +17 -30
  39. package/dist/bin/streamr-storage-node-list.js.map +1 -0
  40. package/dist/bin/streamr-storage-node-remove-stream.d.ts +2 -0
  41. package/dist/bin/streamr-storage-node-remove-stream.js +9 -20
  42. package/dist/bin/streamr-storage-node-remove-stream.js.map +1 -0
  43. package/dist/bin/streamr-storage-node.d.ts +2 -0
  44. package/dist/bin/streamr-storage-node.js +2 -1
  45. package/dist/bin/streamr-storage-node.js.map +1 -0
  46. package/dist/bin/streamr-stream-create.d.ts +2 -0
  47. package/dist/bin/streamr-stream-create.js +15 -23
  48. package/dist/bin/streamr-stream-create.js.map +1 -0
  49. package/dist/bin/streamr-stream-grant-permission.d.ts +2 -0
  50. package/dist/bin/streamr-stream-grant-permission.js +7 -0
  51. package/dist/bin/streamr-stream-grant-permission.js.map +1 -0
  52. package/dist/bin/streamr-stream-list.d.ts +2 -0
  53. package/dist/bin/streamr-stream-list.js +20 -18
  54. package/dist/bin/streamr-stream-list.js.map +1 -0
  55. package/dist/bin/streamr-stream-publish.d.ts +2 -0
  56. package/dist/bin/streamr-stream-publish.js +50 -23
  57. package/dist/bin/streamr-stream-publish.js.map +1 -0
  58. package/dist/bin/streamr-stream-resend-from.d.ts +2 -0
  59. package/dist/bin/streamr-stream-resend-from.js +27 -0
  60. package/dist/bin/streamr-stream-resend-from.js.map +1 -0
  61. package/dist/bin/streamr-stream-resend-last.d.ts +2 -0
  62. package/dist/bin/streamr-stream-resend-last.js +26 -0
  63. package/dist/bin/streamr-stream-resend-last.js.map +1 -0
  64. package/dist/bin/streamr-stream-resend-range.d.ts +2 -0
  65. package/dist/bin/streamr-stream-resend-range.js +33 -0
  66. package/dist/bin/streamr-stream-resend-range.js.map +1 -0
  67. package/dist/bin/streamr-stream-resend.d.ts +2 -0
  68. package/dist/bin/streamr-stream-resend.js +9 -97
  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 +7 -0
  72. package/dist/bin/streamr-stream-revoke-permission.js.map +1 -0
  73. package/dist/bin/streamr-stream-search.d.ts +2 -0
  74. package/dist/bin/streamr-stream-search.js +21 -0
  75. package/dist/bin/streamr-stream-search.js.map +1 -0
  76. package/dist/bin/streamr-stream-show.d.ts +2 -0
  77. package/dist/bin/streamr-stream-show.js +16 -15
  78. package/dist/bin/streamr-stream-show.js.map +1 -0
  79. package/dist/bin/streamr-stream-subscribe.d.ts +2 -0
  80. package/dist/bin/streamr-stream-subscribe.js +18 -20
  81. package/dist/bin/streamr-stream-subscribe.js.map +1 -0
  82. package/dist/bin/streamr-stream.d.ts +2 -0
  83. package/dist/bin/streamr-stream.js +4 -1
  84. package/dist/bin/streamr-stream.js.map +1 -0
  85. package/dist/bin/streamr.d.ts +2 -0
  86. package/dist/bin/streamr.js +2 -1
  87. package/dist/bin/streamr.js.map +1 -0
  88. package/dist/package.json +20 -9
  89. package/dist/src/client.d.ts +3 -0
  90. package/dist/src/client.js +33 -0
  91. package/dist/src/client.js.map +1 -0
  92. package/dist/src/command.d.ts +8 -0
  93. package/dist/src/command.js +45 -0
  94. package/dist/src/command.js.map +1 -0
  95. package/dist/src/common.d.ts +6 -0
  96. package/dist/src/common.js +15 -0
  97. package/dist/src/common.js.map +1 -0
  98. package/dist/src/config.d.ts +6 -0
  99. package/dist/src/config.js +58 -0
  100. package/dist/src/config.js.map +1 -0
  101. package/dist/src/logLevel.d.ts +0 -0
  102. package/dist/src/logLevel.js +11 -0
  103. package/dist/src/logLevel.js.map +1 -0
  104. package/dist/src/permission.d.ts +4 -0
  105. package/dist/src/permission.js +48 -0
  106. package/dist/src/permission.js.map +1 -0
  107. package/dist/src/resend.d.ts +3 -0
  108. package/dist/src/resend.js +13 -23
  109. package/dist/src/resend.js.map +1 -0
  110. package/dist/tsconfig.tsbuildinfo +1 -0
  111. package/package.json +20 -9
  112. package/src/client.ts +32 -0
  113. package/src/command.ts +45 -0
  114. package/src/common.ts +16 -0
  115. package/src/config.ts +56 -0
  116. package/src/logLevel.ts +9 -0
  117. package/src/permission.ts +49 -0
  118. package/src/resend.ts +22 -27
  119. package/tsconfig.json +13 -12
  120. package/bin/common.ts +0 -91
  121. package/bin/streamr-stream-list.ts +0 -29
  122. package/dist/bin/common.js +0 -76
  123. package/dist/src/create.js +0 -17
  124. package/dist/src/generate.js +0 -31
  125. package/dist/src/list.js +0 -27
  126. package/dist/src/publish.js +0 -35
  127. package/dist/src/show.js +0 -21
  128. package/dist/src/subscribe.js +0 -12
  129. package/src/create.ts +0 -15
  130. package/src/generate.ts +0 -30
  131. package/src/list.ts +0 -21
  132. package/src/publish.ts +0 -38
  133. package/src/show.ts +0 -18
  134. package/src/subscribe.ts +0 -9
package/src/resend.ts CHANGED
@@ -1,10 +1,23 @@
1
- import { StreamrClient, StreamrClientOptions } from 'streamr-client'
1
+ import { StreamrClient, ResendOptions } from 'streamr-client'
2
2
 
3
- export const resend = async (streamId: string, resendOpts: any, streamrOptions: StreamrClientOptions & { subscribe?: boolean }) => {
4
- const options = { ...streamrOptions }
5
- const client = new StreamrClient(options)
3
+ export const assertBothOrNoneDefined = (
4
+ option1: string,
5
+ option2: string,
6
+ errorMessage: string,
7
+ commandOptions: Record<string, unknown>
8
+ ): void | never => {
9
+ if ((option1 in commandOptions && !(option2 in commandOptions)) || (option2 in commandOptions && !(option1 in commandOptions))) {
10
+ console.error(`option ${errorMessage}`)
11
+ process.exit(1)
12
+ }
13
+ }
6
14
 
7
- let sub
15
+ export const resend = async (
16
+ streamId: string,
17
+ resendOpts: ResendOptions,
18
+ client: StreamrClient,
19
+ subscribe: boolean
20
+ ): Promise<void> => {
8
21
  try {
9
22
  const subscribeOpts = {
10
23
  stream: streamId,
@@ -13,31 +26,13 @@ export const resend = async (streamId: string, resendOpts: any, streamrOptions:
13
26
  const handler = (message: any) => {
14
27
  console.info(JSON.stringify(message))
15
28
  }
16
-
17
- if (options.subscribe) {
18
- sub = await client.subscribe(subscribeOpts, handler)
29
+ if (subscribe) {
30
+ await client.subscribe(subscribeOpts, handler)
19
31
  } else {
20
- sub = await client.resend(subscribeOpts, handler)
32
+ await client.resend(subscribeOpts, handler)
21
33
  }
22
34
  } catch (err) {
23
35
  console.error(err.message ? err.message : err)
24
36
  process.exit(1)
25
37
  }
26
-
27
- sub.on('error', (err: any) => {
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
- }
38
+ }
package/tsconfig.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
- "compilerOptions": {
3
- "target": "esnext",
4
- "module": "commonjs",
5
- "strict": true,
6
- "noImplicitAny": true,
7
- "outDir": "dist",
8
- "rootDirs": ["src", "bin"],
9
- "resolveJsonModule": true,
10
- "esModuleInterop": true,
11
- "skipLibCheck": true,
12
- "forceConsistentCasingInFileNames": true
13
- }
2
+ "extends": "@streamr/dev-config/ts/tsconfig.node.json",
3
+ "compilerOptions": {
4
+ "composite": true,
5
+ "outDir": "dist"
6
+ },
7
+ "include": [
8
+ "package.json",
9
+ "src/**/*",
10
+ "bin/**/*"
11
+ ],
12
+ "references": [
13
+ { "path": "../client/tsconfig.node.json" }
14
+ ]
14
15
  }
package/bin/common.ts DELETED
@@ -1,91 +0,0 @@
1
- import * as commander from 'commander'
2
- import { StreamrClientOptions } from 'streamr-client'
3
-
4
- export interface EnvironmentOptions {
5
- dev?: boolean
6
- stg?: boolean
7
- wsUrl?: string
8
- httpUrl?: string
9
- }
10
-
11
- export interface AuthenticationOptions {
12
- privateKey?: string
13
- apiKey?: string
14
- }
15
-
16
- export function envOptions(program: commander.Command) {
17
- return program
18
- .option('--dev', 'use pre-defined development environment')
19
- .option('--stg', 'use pre-defined staging environment')
20
- .option('--ws-url <url>', 'alternative websocket url to use')
21
- .option('--http-url <url>', 'alternative http url to use')
22
- }
23
-
24
- export function authOptions(program: commander.Command) {
25
- return program
26
- .option('--private-key <key>', 'use an Ethereum private key to authenticate')
27
- .option('--api-key <key>', 'use an API key to authenticate (deprecated)')
28
- }
29
-
30
- export function exitWithHelpIfArgsNotBetween(program: commander.Command, min: number, max: number) {
31
- if (program.args.length < min || program.args.length > max) {
32
- program.help()
33
- }
34
- }
35
-
36
- export function formStreamrOptionsWithEnv({ dev, stg, wsUrl, httpUrl, privateKey, apiKey }: EnvironmentOptions & AuthenticationOptions) {
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.url = 'ws://localhost/api/v1/ws'
46
- options.restUrl = 'http://localhost/api/v1'
47
- options.storageNode = {
48
- // "broker-node-storage-1" on Docker environment
49
- address: '0xde1112f631486CfC759A50196853011528bC5FA0',
50
- url: 'http://10.200.10.1:8891'
51
- }
52
- } else if (stg) {
53
- options.url = 'wss://staging.streamr.com/api/v1/ws'
54
- options.restUrl = 'https://staging.streamr.com/api/v1/'
55
- }
56
-
57
- if (wsUrl) {
58
- options.url = wsUrl
59
- }
60
- if (httpUrl) {
61
- options.restUrl = httpUrl
62
- }
63
-
64
- if (privateKey && apiKey) {
65
- console.error('flags --privateKey and --apiKey cannot be used at the same time')
66
- process.exit(1)
67
- }
68
-
69
- if (privateKey) {
70
- options.auth = {
71
- privateKey
72
- }
73
- } else if (apiKey) {
74
- options.auth = {
75
- apiKey
76
- }
77
- }
78
-
79
- return options
80
- }
81
-
82
- export function createFnParseInt(name: string) {
83
- return (str: string) => {
84
- const n = parseInt(str, 10)
85
- if (isNaN(n)) {
86
- console.error(`${name} must be an integer (was "${str}")`)
87
- process.exit(1)
88
- }
89
- return n
90
- }
91
- }
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env node
2
- import { Command, Option } from 'commander';
3
- import { list } from '../src/list'
4
- import { envOptions, authOptions, exitWithHelpIfArgsNotBetween, formStreamrOptionsWithEnv } from './common'
5
- import pkg from '../package.json'
6
-
7
- const program = new Command();
8
- program
9
- .description('fetch a list of streams that are accessible by the authenticated user')
10
- .option('-s, --search [term]', 'search for term in name or description')
11
- .addOption(new Option('-o, --operation [permission]', 'filter by permission').choices(['stream_get','stream_subscribe','stream_publish','stream_delete','stream_share']).default('stream_get'))
12
- .option('--public-access', 'include publicly available streams')
13
- .option('--no-granted-access', 'exclude streams that user has directly granted permissions to')
14
- authOptions(program)
15
- envOptions(program)
16
- .version(pkg.version)
17
- .action((options: any) => {
18
- const query: any = {
19
- operation: options.operation,
20
- noConfig: true,
21
- publicAccess: options.publicAccess,
22
- search: options.search,
23
- grantedAccess: options.grantedAccess
24
- }
25
- list(query, formStreamrOptionsWithEnv(options))
26
- })
27
- .parse(process.argv)
28
-
29
- exitWithHelpIfArgsNotBetween(program, 0, 0)
@@ -1,76 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createFnParseInt = exports.formStreamrOptionsWithEnv = exports.exitWithHelpIfArgsNotBetween = exports.authOptions = exports.envOptions = void 0;
4
- function envOptions(program) {
5
- return program
6
- .option('--dev', 'use pre-defined development environment')
7
- .option('--stg', 'use pre-defined staging environment')
8
- .option('--ws-url <url>', 'alternative websocket url to use')
9
- .option('--http-url <url>', 'alternative http url to use');
10
- }
11
- exports.envOptions = envOptions;
12
- function authOptions(program) {
13
- return program
14
- .option('--private-key <key>', 'use an Ethereum private key to authenticate')
15
- .option('--api-key <key>', 'use an API key to authenticate (deprecated)');
16
- }
17
- exports.authOptions = authOptions;
18
- function exitWithHelpIfArgsNotBetween(program, min, max) {
19
- if (program.args.length < min || program.args.length > max) {
20
- program.help();
21
- }
22
- }
23
- exports.exitWithHelpIfArgsNotBetween = exitWithHelpIfArgsNotBetween;
24
- function formStreamrOptionsWithEnv({ dev, stg, wsUrl, httpUrl, privateKey, apiKey }) {
25
- const options = {};
26
- if (dev && stg) {
27
- console.error('flags --dev and --stg cannot be enabled at the same time');
28
- process.exit(1);
29
- }
30
- if (dev) {
31
- options.url = 'ws://localhost/api/v1/ws';
32
- options.restUrl = 'http://localhost/api/v1';
33
- options.storageNode = {
34
- // "broker-node-storage-1" on Docker environment
35
- address: '0xde1112f631486CfC759A50196853011528bC5FA0',
36
- url: 'http://10.200.10.1:8891'
37
- };
38
- }
39
- else if (stg) {
40
- options.url = 'wss://staging.streamr.com/api/v1/ws';
41
- options.restUrl = 'https://staging.streamr.com/api/v1/';
42
- }
43
- if (wsUrl) {
44
- options.url = wsUrl;
45
- }
46
- if (httpUrl) {
47
- options.restUrl = httpUrl;
48
- }
49
- if (privateKey && apiKey) {
50
- console.error('flags --privateKey and --apiKey cannot be used at the same time');
51
- process.exit(1);
52
- }
53
- if (privateKey) {
54
- options.auth = {
55
- privateKey
56
- };
57
- }
58
- else if (apiKey) {
59
- options.auth = {
60
- apiKey
61
- };
62
- }
63
- return options;
64
- }
65
- exports.formStreamrOptionsWithEnv = formStreamrOptionsWithEnv;
66
- function createFnParseInt(name) {
67
- return (str) => {
68
- const n = parseInt(str, 10);
69
- if (isNaN(n)) {
70
- console.error(`${name} must be an integer (was "${str}")`);
71
- process.exit(1);
72
- }
73
- return n;
74
- };
75
- }
76
- exports.createFnParseInt = createFnParseInt;
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.create = void 0;
4
- const streamr_client_1 = require("streamr-client");
5
- const create = (body, streamrOptions) => {
6
- const options = { ...streamrOptions };
7
- const client = new streamr_client_1.StreamrClient(options);
8
- client.createStream(body).then((stream) => {
9
- // @ts-expect-error
10
- console.info(JSON.stringify(stream.toObject(), null, 2));
11
- process.exit(0);
12
- }).catch((err) => {
13
- console.error(err.message ? err.message : err);
14
- process.exit(1);
15
- });
16
- };
17
- exports.create = create;
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generate = void 0;
4
- // From: https://stackoverflow.com/questions/10726909/random-alpha-numeric-string-in-javascript
5
- function randomString(length, chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') {
6
- let result = '';
7
- for (let i = length; i > 0; --i) {
8
- result += chars[Math.floor(Math.random() * chars.length)];
9
- }
10
- return result;
11
- }
12
- function genArray(size, elementFn) {
13
- const arr = [];
14
- for (let i = 0; i < size; ++i) {
15
- arr.push(elementFn());
16
- }
17
- return arr;
18
- }
19
- const generate = (rate) => {
20
- setInterval(() => {
21
- console.info(JSON.stringify({
22
- someText: randomString(64),
23
- aNumber: Math.random() * 10000,
24
- bNumber: Math.random(),
25
- yesOrNo: Math.random() > 0.5,
26
- arrayOfStrings: genArray(Math.floor(Math.random() * 20), () => randomString(8)),
27
- arrayOfIntegers: genArray(Math.floor(Math.random() * 10), () => Math.floor(Math.random() * 100))
28
- }));
29
- }, rate);
30
- };
31
- exports.generate = generate;
package/dist/src/list.js DELETED
@@ -1,27 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.list = void 0;
7
- const streamr_client_1 = require("streamr-client");
8
- const easy_table_1 = __importDefault(require("easy-table"));
9
- const list = (query, streamrOptions) => {
10
- const options = { ...streamrOptions };
11
- const client = new streamr_client_1.StreamrClient(options);
12
- client.listStreams(query).then((streams) => {
13
- if (streams.length > 0) {
14
- // @ts-expect-error
15
- console.info(easy_table_1.default.print(streams.map(({ id, name, lastUpdated }) => ({
16
- lastUpdated,
17
- id,
18
- name
19
- }))));
20
- }
21
- process.exit(0);
22
- }, (err) => {
23
- console.error(err.message ? err.message : err);
24
- process.exit(1);
25
- });
26
- };
27
- exports.list = list;
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.publishStream = void 0;
4
- const stream_1 = require("stream");
5
- const streamr_client_1 = require("streamr-client");
6
- const publishStream = (stream, partitionKey, streamrOptions) => {
7
- const options = { ...streamrOptions };
8
- const client = new streamr_client_1.StreamrClient(options);
9
- const writable = new stream_1.Writable({
10
- objectMode: true,
11
- write: (data, _, done) => {
12
- let json = null;
13
- // ignore newlines, etc
14
- if (!data || String(data).trim() === '') {
15
- done();
16
- return;
17
- }
18
- try {
19
- json = JSON.parse(data);
20
- }
21
- catch (e) {
22
- console.error(data.toString());
23
- done(e);
24
- return;
25
- }
26
- // @ts-expect-error
27
- client.publish(stream, json, Date.now(), json[partitionKey]).then(() => done(), (err) => done(err));
28
- }
29
- });
30
- client.on('error', (err) => writable.emit('error', err));
31
- // disconnect client when upstream pipe ends and data flushed
32
- writable.once('finish', () => client.ensureDisconnected());
33
- return writable;
34
- };
35
- exports.publishStream = publishStream;
package/dist/src/show.js DELETED
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.show = void 0;
4
- const streamr_client_1 = require("streamr-client");
5
- const show = (streamId, includePermissions, streamrOptions) => {
6
- const options = { ...streamrOptions };
7
- const client = new streamr_client_1.StreamrClient(options);
8
- client.getStream(streamId).then(async (stream) => {
9
- // @ts-expect-error
10
- const obj = stream.toObject();
11
- if (includePermissions) {
12
- obj.permissions = await stream.getPermissions();
13
- }
14
- console.info(JSON.stringify(obj, null, 2));
15
- process.exit(0);
16
- }).catch((err) => {
17
- console.error(err.message ? err.message : err);
18
- process.exit(1);
19
- });
20
- };
21
- exports.show = show;
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.subscribe = void 0;
4
- const streamr_client_1 = require("streamr-client");
5
- const subscribe = (stream, partition, streamrOptions) => {
6
- const options = { ...streamrOptions };
7
- new streamr_client_1.StreamrClient(options).subscribe({
8
- stream,
9
- partition,
10
- }, (message, streamMessage) => console.info(JSON.stringify(message)));
11
- };
12
- exports.subscribe = subscribe;
package/src/create.ts DELETED
@@ -1,15 +0,0 @@
1
- import { StreamProperties, StreamrClient } from 'streamr-client'
2
-
3
- export const create = (body: any, streamrOptions: StreamProperties) => {
4
- const options = { ...streamrOptions }
5
-
6
- const client = new StreamrClient(options)
7
- client.createStream(body).then((stream) => {
8
- // @ts-expect-error
9
- console.info(JSON.stringify(stream.toObject(), null, 2))
10
- process.exit(0)
11
- }).catch((err) => {
12
- console.error(err.message ? err.message : err)
13
- process.exit(1)
14
- })
15
- }
package/src/generate.ts DELETED
@@ -1,30 +0,0 @@
1
- // From: https://stackoverflow.com/questions/10726909/random-alpha-numeric-string-in-javascript
2
- function randomString(length: number, chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') {
3
- let result = ''
4
- for (let i = length; i > 0; --i) {
5
- result += chars[Math.floor(Math.random() * chars.length)]
6
- }
7
- return result
8
- }
9
-
10
- function genArray(size: number, elementFn: () => any) {
11
- const arr = []
12
- for (let i=0; i < size; ++i) {
13
- arr.push(elementFn())
14
- }
15
- return arr
16
- }
17
-
18
- export const generate = (rate: number) => {
19
- setInterval(() => {
20
- console.info(JSON.stringify({
21
- someText: randomString(64),
22
- aNumber: Math.random() * 10000,
23
- bNumber: Math.random(),
24
- yesOrNo: Math.random() > 0.5,
25
- arrayOfStrings: genArray(Math.floor(Math.random() * 20), () => randomString(8)),
26
- arrayOfIntegers: genArray(Math.floor(Math.random() * 10), () => Math.floor(Math.random() * 100))
27
-
28
- }))
29
- }, rate)
30
- }
package/src/list.ts DELETED
@@ -1,21 +0,0 @@
1
- import { StreamListQuery, StreamrClient, StreamrClientOptions } from 'streamr-client'
2
- import EasyTable from 'easy-table'
3
-
4
- export const list = (query: StreamListQuery, streamrOptions: StreamrClientOptions) => {
5
- const options = { ...streamrOptions }
6
- const client = new StreamrClient(options)
7
- client.listStreams(query).then((streams) => {
8
- if (streams.length > 0) {
9
- // @ts-expect-error
10
- console.info(EasyTable.print(streams.map(({id, name, lastUpdated}) => ({
11
- lastUpdated,
12
- id,
13
- name
14
- }))))
15
- }
16
- process.exit(0)
17
- }, (err) => {
18
- console.error(err.message ? err.message : err)
19
- process.exit(1)
20
- })
21
- }
package/src/publish.ts DELETED
@@ -1,38 +0,0 @@
1
- import { Writable } from 'stream'
2
- import { StreamrClient, StreamrClientOptions } from 'streamr-client'
3
-
4
- export const publishStream = (stream: string, partitionKey: string|undefined, streamrOptions: StreamrClientOptions) => {
5
- const options = { ...streamrOptions }
6
-
7
- const client = new StreamrClient(options)
8
- const writable = new Writable({
9
- objectMode: true,
10
- write: (data: any, _: any, done: any) => {
11
- let json = null
12
- // ignore newlines, etc
13
- if (!data || String(data).trim() === '') {
14
- done()
15
- return
16
- }
17
-
18
- try {
19
- json = JSON.parse(data)
20
- } catch (e) {
21
- console.error(data.toString())
22
- done(e)
23
- return
24
- }
25
-
26
- // @ts-expect-error
27
- client.publish(stream, json, Date.now(), json[partitionKey]).then(
28
- () => done(),
29
- (err) => done(err)
30
- )
31
- }
32
- })
33
-
34
- client.on('error', (err) => writable.emit('error', err))
35
- // disconnect client when upstream pipe ends and data flushed
36
- writable.once('finish', () => client.ensureDisconnected())
37
- return writable
38
- }
package/src/show.ts DELETED
@@ -1,18 +0,0 @@
1
- import { StreamrClient, StreamrClientOptions } from 'streamr-client'
2
-
3
- export const show = (streamId: string, includePermissions: boolean|undefined, streamrOptions: StreamrClientOptions) => {
4
- const options = { ...streamrOptions }
5
- const client = new StreamrClient(options)
6
- client.getStream(streamId).then(async (stream) => {
7
- // @ts-expect-error
8
- const obj = stream.toObject()
9
- if (includePermissions) {
10
- obj.permissions = await stream.getPermissions()
11
- }
12
- console.info(JSON.stringify(obj, null, 2))
13
- process.exit(0)
14
- }).catch((err) => {
15
- console.error(err.message ? err.message : err)
16
- process.exit(1)
17
- })
18
- }
package/src/subscribe.ts DELETED
@@ -1,9 +0,0 @@
1
- import { StreamrClient, StreamrClientOptions } from 'streamr-client'
2
-
3
- export const subscribe = (stream: string, partition: number, streamrOptions: StreamrClientOptions) => {
4
- const options = { ...streamrOptions }
5
- new StreamrClient(options).subscribe({
6
- stream,
7
- partition,
8
- }, (message, streamMessage) => console.info(JSON.stringify(message)))
9
- }