@flowcore/cli 2.8.1 → 2.9.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.
- package/CHANGELOG.md +15 -0
- package/README.md +7 -5
- package/dist/commands/stream.d.ts +2 -0
- package/dist/commands/stream.js +23 -8
- package/oclif.manifest.json +17 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,21 @@
|
|
|
10
10
|
|
|
11
11
|
* added description to start that includes week ([58687a7](https://github.com/flowcore-io/flowcore-cli/commit/58687a7bbb66aaa5d6da26af88e555cbb1e72467))
|
|
12
12
|
|
|
13
|
+
## [2.9.0](https://github.com/flowcore-io/flowcore-cli/compare/v2.8.2...v2.9.0) (2024-03-07)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
|
|
18
|
+
* add support for sending only the event payload to the destination in processEvents function ([fa44f87](https://github.com/flowcore-io/flowcore-cli/commit/fa44f8742c565df5b7482c21e7a2f0b597e671e0))
|
|
19
|
+
* enhance stream command with max event option ([5bb9ff2](https://github.com/flowcore-io/flowcore-cli/commit/5bb9ff26c6d59007442cab1c1bcb2edae7182858))
|
|
20
|
+
|
|
21
|
+
## [2.8.2](https://github.com/flowcore-io/flowcore-cli/compare/v2.8.1...v2.8.2) (2024-02-28)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### Bug Fixes
|
|
25
|
+
|
|
26
|
+
* show correct info when streaming ([aae6597](https://github.com/flowcore-io/flowcore-cli/commit/aae6597dff983db811cc156592c0b8ac946037a6))
|
|
27
|
+
|
|
13
28
|
## [2.8.1](https://github.com/flowcore-io/flowcore-cli/compare/v2.8.0...v2.8.1) (2024-02-26)
|
|
14
29
|
|
|
15
30
|
|
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ $ npm install -g @flowcore/cli
|
|
|
18
18
|
$ flowcore COMMAND
|
|
19
19
|
running command...
|
|
20
20
|
$ flowcore (--version)
|
|
21
|
-
@flowcore/cli/2.
|
|
21
|
+
@flowcore/cli/2.9.0 linux-x64 node-v20.11.1
|
|
22
22
|
$ flowcore --help [COMMAND]
|
|
23
23
|
USAGE
|
|
24
24
|
$ flowcore COMMAND
|
|
@@ -75,7 +75,7 @@ EXAMPLES
|
|
|
75
75
|
$ flowcore apply -f ./path/to/manifest.yml
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
-
_See code: [src/commands/apply.ts](https://github.com/flowcore-io/flowcore-cli/blob/v2.
|
|
78
|
+
_See code: [src/commands/apply.ts](https://github.com/flowcore-io/flowcore-cli/blob/v2.9.0/src/commands/apply.ts)_
|
|
79
79
|
|
|
80
80
|
## `flowcore autocomplete [SHELL]`
|
|
81
81
|
|
|
@@ -722,8 +722,8 @@ Stream events from a datacore running on the Flowcore Platform
|
|
|
722
722
|
|
|
723
723
|
```
|
|
724
724
|
USAGE
|
|
725
|
-
$ flowcore stream STREAM [--profile <value>] [-d <value>] [-H <value>] [-j] [-l] [-
|
|
726
|
-
<value>] [-t <value>]
|
|
725
|
+
$ flowcore stream STREAM [--profile <value>] [-d <value>] [-H <value>] [-j] [-l] [-m <value>] [-o
|
|
726
|
+
http|log] [-p] [-c] [-s <value>] [-t <value>]
|
|
727
727
|
|
|
728
728
|
ARGUMENTS
|
|
729
729
|
STREAM stream url to connect to
|
|
@@ -734,8 +734,10 @@ FLAGS
|
|
|
734
734
|
-d, --destination=<value> [default: http://localhost:3000/transform] Destination to send events to
|
|
735
735
|
-j, --json Output json only
|
|
736
736
|
-l, --[no-]live Change to live mode when reaching last time bucket
|
|
737
|
+
-m, --max=<value> Maximum number of events to send to the destination
|
|
737
738
|
-o, --output=<option> [default: http] Output format
|
|
738
739
|
<options: http|log>
|
|
740
|
+
-p, --payload Only send the event payload to the destination
|
|
739
741
|
-s, --start=<value> Start time bucket to stream from, example: (1y, 1m, 1w, 1d, 1h, now)
|
|
740
742
|
-t, --timeout=<value> [default: 5000] Timeout in milliseconds to wait for a response from the destination
|
|
741
743
|
--profile=<value> Specify the configuration profile to use
|
|
@@ -753,7 +755,7 @@ EXAMPLES
|
|
|
753
755
|
$ flowcore stream https://flowcore.io/<org>/<data core>/<flow type>/[<event type1>,<event type2>,<event type3>].stream -o log -s 3m
|
|
754
756
|
```
|
|
755
757
|
|
|
756
|
-
_See code: [src/commands/stream.ts](https://github.com/flowcore-io/flowcore-cli/blob/v2.
|
|
758
|
+
_See code: [src/commands/stream.ts](https://github.com/flowcore-io/flowcore-cli/blob/v2.9.0/src/commands/stream.ts)_
|
|
757
759
|
|
|
758
760
|
## `flowcore version`
|
|
759
761
|
|
|
@@ -10,7 +10,9 @@ export default class Stream extends BaseCommand<typeof Stream> {
|
|
|
10
10
|
header: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string[], import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
11
11
|
json: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
|
|
12
12
|
live: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
|
|
13
|
+
max: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<number, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
13
14
|
output: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
15
|
+
payload: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
|
|
14
16
|
scan: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
|
|
15
17
|
start: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
16
18
|
timeout: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<number, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
package/dist/commands/stream.js
CHANGED
|
@@ -31,7 +31,9 @@ export default class Stream extends BaseCommand {
|
|
|
31
31
|
header: Flags.string({ char: 'H', default: [], description: 'header to send with the request, example: (-H \'Authorization: Bearer TOKEN\')', multiple: true }),
|
|
32
32
|
json: Flags.boolean({ char: 'j', description: 'Output json only' }),
|
|
33
33
|
live: Flags.boolean({ allowNo: true, char: 'l', default: true, description: 'Change to live mode when reaching last time bucket' }),
|
|
34
|
+
max: Flags.integer({ char: 'm', default: 0, description: 'Maximum number of events to send to the destination' }),
|
|
34
35
|
output: Flags.string({ char: 'o', default: 'http', description: 'Output format', options: ['http', 'log'] }),
|
|
36
|
+
payload: Flags.boolean({ char: 'p', default: false, description: 'Only send the event payload to the destination' }),
|
|
35
37
|
scan: Flags.boolean({ char: 'c', default: false, description: 'Scan the full time range' }),
|
|
36
38
|
start: Flags.string({ char: 's', description: 'Start time bucket to stream from, example: (1y, 1m, 1w, 1d, 1h, now)' }),
|
|
37
39
|
timeout: Flags.integer({ char: 't', default: 5000, description: 'Timeout in milliseconds to wait for a response from the destination' }),
|
|
@@ -113,8 +115,8 @@ export default class Stream extends BaseCommand {
|
|
|
113
115
|
const observer = new Subject();
|
|
114
116
|
!this.flags.json && this.log(ux.colorize("blackBright", `Starting to stream events for ${dataCoreId} - ${aggregator} - ${eventTypes}, press ${ux.colorize("whiteBright", "ctrl+c")} to stop`));
|
|
115
117
|
// eslint-disable-next-line no-void
|
|
116
|
-
void this.streamEvents(dataCoreId, aggregator, eventTypes, firstTimeBucket, lastTimeBucket, graphqlClient, observer, flags.live, afterEventId);
|
|
117
|
-
await this.processEvents(observer, flags.destination, flags.output, flags.header);
|
|
118
|
+
void this.streamEvents(dataCoreId, aggregator, eventTypes, firstTimeBucket, lastTimeBucket, graphqlClient, observer, flags.live, afterEventId, flags.max);
|
|
119
|
+
await this.processEvents(observer, flags.destination, flags.output, flags.header, flags.payload);
|
|
118
120
|
}
|
|
119
121
|
calculateBuckets(timediff, startTimeBucket) {
|
|
120
122
|
return _.times(timediff + 1, (n) => dayjs(startTimeBucket).add(n, "hour").format(TIME_BUCKET_PATTERN));
|
|
@@ -165,7 +167,7 @@ export default class Stream extends BaseCommand {
|
|
|
165
167
|
}
|
|
166
168
|
return timeBuckets;
|
|
167
169
|
}
|
|
168
|
-
async processEvents(observer, destination, output, header = []) {
|
|
170
|
+
async processEvents(observer, destination, output, header = [], payload = false) {
|
|
169
171
|
let done = false;
|
|
170
172
|
let events = [];
|
|
171
173
|
const warn = this.flags.json ? () => { } : this.warn.bind(this);
|
|
@@ -188,11 +190,12 @@ export default class Stream extends BaseCommand {
|
|
|
188
190
|
events = [];
|
|
189
191
|
while (!processingQueue.isEmpty()) {
|
|
190
192
|
const event = processingQueue.dequeue();
|
|
193
|
+
const outputPayload = payload ? event.payload : event;
|
|
191
194
|
if (output === "log") {
|
|
192
195
|
this.flags.json ? this.log(JSON.stringify({
|
|
193
|
-
event,
|
|
196
|
+
event: outputPayload,
|
|
194
197
|
type: "input",
|
|
195
|
-
}, null, 2)) : this.log(JSON.stringify(
|
|
198
|
+
}, null, 2)) : this.log(JSON.stringify(outputPayload));
|
|
196
199
|
continue;
|
|
197
200
|
}
|
|
198
201
|
!this.flags.json && this.log(`Sending event to ${destination}: ${event.eventId}`);
|
|
@@ -204,7 +207,7 @@ export default class Stream extends BaseCommand {
|
|
|
204
207
|
}
|
|
205
208
|
// eslint-disable-next-line no-await-in-loop
|
|
206
209
|
const result = await Promise.race([fetch(destination, {
|
|
207
|
-
body: JSON.stringify(
|
|
210
|
+
body: JSON.stringify(outputPayload),
|
|
208
211
|
headers: {
|
|
209
212
|
"Content-Type": "application/json",
|
|
210
213
|
...headers,
|
|
@@ -260,7 +263,7 @@ export default class Stream extends BaseCommand {
|
|
|
260
263
|
}
|
|
261
264
|
}
|
|
262
265
|
}
|
|
263
|
-
async streamEvents(dataCoreId, aggregator, eventTypes, firstTimeBucket, lastTimeBucket, graphqlClient, observer, live, afterEventId) {
|
|
266
|
+
async streamEvents(dataCoreId, aggregator, eventTypes, firstTimeBucket, lastTimeBucket, graphqlClient, observer, live, afterEventId, maxEvents = 0) {
|
|
264
267
|
const startTimeBucket = dayjs(firstTimeBucket, TIME_BUCKET_HOUR_PATTERN);
|
|
265
268
|
const currentTime = () => dayjs.utc();
|
|
266
269
|
let liveMode = false;
|
|
@@ -268,6 +271,7 @@ export default class Stream extends BaseCommand {
|
|
|
268
271
|
const timediff = this.calculateTimeDifferenceInHours(lastTimeBucket, startTimeBucket, firstTimeBucket);
|
|
269
272
|
let timeBuckets = [];
|
|
270
273
|
timeBuckets = this.flags.scan ? this.calculateBuckets(timediff, startTimeBucket) : (await this.fetchTimeBuckets(dataCoreId, aggregator, eventTypes, startTimeBucket, lastTimeBucket, graphqlClient));
|
|
274
|
+
let eventsCount = 0;
|
|
271
275
|
// eslint-disable-next-line no-constant-condition
|
|
272
276
|
while (true) {
|
|
273
277
|
const timeBucket = timeBuckets.shift();
|
|
@@ -275,7 +279,7 @@ export default class Stream extends BaseCommand {
|
|
|
275
279
|
ux.error("No time bucket found");
|
|
276
280
|
}
|
|
277
281
|
if (!this.flags.json) {
|
|
278
|
-
ux.action.start(`Fetching events for ${
|
|
282
|
+
ux.action.start(`Fetching events for ${dayjs(timeBucket, TIME_BUCKET_PATTERN)}`);
|
|
279
283
|
}
|
|
280
284
|
let cursor = null;
|
|
281
285
|
let found = false;
|
|
@@ -294,12 +298,23 @@ export default class Stream extends BaseCommand {
|
|
|
294
298
|
dataCoreId,
|
|
295
299
|
eventTypes,
|
|
296
300
|
timeBucket,
|
|
301
|
+
...(maxEvents > 0 ? { pageSize: maxEvents - eventsCount } : {})
|
|
297
302
|
});
|
|
298
303
|
cursor = response.datacore.fetchEvents.cursor;
|
|
299
304
|
for (const event of response.datacore.fetchEvents.events) {
|
|
300
305
|
found = true;
|
|
301
306
|
observer.next(event);
|
|
302
307
|
lastEventId = event.eventId;
|
|
308
|
+
eventsCount++;
|
|
309
|
+
// eslint-disable-next-line max-depth
|
|
310
|
+
if (maxEvents > 0 && eventsCount >= maxEvents) {
|
|
311
|
+
observer.complete();
|
|
312
|
+
// eslint-disable-next-line max-depth
|
|
313
|
+
if (!this.flags.json) {
|
|
314
|
+
ux.action.stop(`Fetched total event count of ${eventsCount}, stopping`);
|
|
315
|
+
}
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
303
318
|
}
|
|
304
319
|
}
|
|
305
320
|
catch (error) {
|
package/oclif.manifest.json
CHANGED
|
@@ -103,6 +103,15 @@
|
|
|
103
103
|
"allowNo": true,
|
|
104
104
|
"type": "boolean"
|
|
105
105
|
},
|
|
106
|
+
"max": {
|
|
107
|
+
"char": "m",
|
|
108
|
+
"description": "Maximum number of events to send to the destination",
|
|
109
|
+
"name": "max",
|
|
110
|
+
"default": 0,
|
|
111
|
+
"hasDynamicHelp": false,
|
|
112
|
+
"multiple": false,
|
|
113
|
+
"type": "option"
|
|
114
|
+
},
|
|
106
115
|
"output": {
|
|
107
116
|
"char": "o",
|
|
108
117
|
"description": "Output format",
|
|
@@ -116,6 +125,13 @@
|
|
|
116
125
|
],
|
|
117
126
|
"type": "option"
|
|
118
127
|
},
|
|
128
|
+
"payload": {
|
|
129
|
+
"char": "p",
|
|
130
|
+
"description": "Only send the event payload to the destination",
|
|
131
|
+
"name": "payload",
|
|
132
|
+
"allowNo": false,
|
|
133
|
+
"type": "boolean"
|
|
134
|
+
},
|
|
119
135
|
"scan": {
|
|
120
136
|
"char": "c",
|
|
121
137
|
"description": "Scan the full time range",
|
|
@@ -157,5 +173,5 @@
|
|
|
157
173
|
]
|
|
158
174
|
}
|
|
159
175
|
},
|
|
160
|
-
"version": "2.
|
|
176
|
+
"version": "2.9.0"
|
|
161
177
|
}
|
package/package.json
CHANGED
|
@@ -90,7 +90,7 @@
|
|
|
90
90
|
"prestart": "npm run build",
|
|
91
91
|
"update-schema": "rover graph introspect https://graph.api.staging.flowcore.io/graphql -o schema.gql"
|
|
92
92
|
},
|
|
93
|
-
"version": "2.
|
|
93
|
+
"version": "2.9.0",
|
|
94
94
|
"bugs": "https://github.com/flowcore-io/flowcore-cli/issues",
|
|
95
95
|
"keywords": [
|
|
96
96
|
"flowcore",
|