kourou 0.19.4 → 0.20.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.
- package/README.md +118 -104
- package/lib/commands/app/scaffold.d.ts +2 -0
- package/lib/commands/app/scaffold.js +23 -0
- package/lib/commands/collection/export.d.ts +1 -0
- package/lib/commands/collection/export.js +21 -4
- package/lib/commands/document/search.js +1 -1
- package/lib/commands/role/export.js +0 -1
- package/lib/common.d.ts +19 -0
- package/lib/common.js +55 -12
- package/lib/support/dump-collection.d.ts +1 -1
- package/lib/support/dump-collection.js +207 -57
- package/oclif.manifest.json +1 -1
- package/package.json +19 -18
- package/templates.tgz +0 -0
- package/lib/commands/es/snapshot/restore.d.ts +0 -18
- package/lib/commands/es/snapshot/restore.js +0 -52
package/README.md
CHANGED
|
@@ -13,6 +13,7 @@ The CLI that helps you manage your Kuzzle instances.
|
|
|
13
13
|
* [Commands](#commands)
|
|
14
14
|
* [Where does this weird name come from?](#where-does-this-weird-name-come-from)
|
|
15
15
|
* [Have fun with a quine](#have-fun-with-a-quine)
|
|
16
|
+
* [Analytics](#analytics)
|
|
16
17
|
<!-- tocstop -->
|
|
17
18
|
|
|
18
19
|
:warning: This project is currently in beta and breaking changes may occur until the 1.0.0
|
|
@@ -25,7 +26,7 @@ $ npm install -g kourou
|
|
|
25
26
|
$ kourou COMMAND
|
|
26
27
|
running command...
|
|
27
28
|
$ kourou (-v|--version|version)
|
|
28
|
-
kourou/0.
|
|
29
|
+
kourou/0.20.2 linux-x64 node-v12.22.10
|
|
29
30
|
$ kourou --help [COMMAND]
|
|
30
31
|
USAGE
|
|
31
32
|
$ kourou COMMAND
|
|
@@ -143,7 +144,6 @@ All other arguments and options will be passed as-is to the `sdk:query` method.
|
|
|
143
144
|
* [`kourou es:snapshot:create REPOSITORY NAME`](#kourou-essnapshotcreate-repository-name)
|
|
144
145
|
* [`kourou es:snapshot:create-repository REPOSITORY LOCATION`](#kourou-essnapshotcreate-repository-repository-location)
|
|
145
146
|
* [`kourou es:snapshot:list REPOSITORY`](#kourou-essnapshotlist-repository)
|
|
146
|
-
* [`kourou es:snapshot:restore REPOSITORY NAME`](#kourou-essnapshotrestore-repository-name)
|
|
147
147
|
* [`kourou file:decrypt FILE`](#kourou-filedecrypt-file)
|
|
148
148
|
* [`kourou file:encrypt FILE`](#kourou-fileencrypt-file)
|
|
149
149
|
* [`kourou file:test FILE`](#kourou-filetest-file)
|
|
@@ -379,31 +379,58 @@ ARGUMENTS
|
|
|
379
379
|
COLLECTION Collection name
|
|
380
380
|
|
|
381
381
|
OPTIONS
|
|
382
|
-
--api-key=api-key
|
|
383
|
-
|
|
384
|
-
--batch-size=batch-size [default: 2000] Maximum batch size (see limits.documentsFetchCount config)
|
|
385
|
-
--editor Open an editor (EDITOR env variable) to edit the query before sending
|
|
382
|
+
--api-key=api-key
|
|
383
|
+
Kuzzle user api-key
|
|
386
384
|
|
|
387
|
-
--
|
|
388
|
-
|
|
385
|
+
--as=as
|
|
386
|
+
Impersonate a user
|
|
389
387
|
|
|
390
|
-
--
|
|
388
|
+
--batch-size=batch-size
|
|
389
|
+
[default: 2000] Maximum batch size (see limits.documentsFetchCount config)
|
|
391
390
|
|
|
392
|
-
--
|
|
391
|
+
--editor
|
|
392
|
+
Open an editor (EDITOR env variable) to edit the query before sending
|
|
393
393
|
|
|
394
|
-
--
|
|
394
|
+
--fields=fields
|
|
395
|
+
[CSV format only] The list of fields to be included in the CSV export in dot-path format.
|
|
395
396
|
|
|
396
|
-
|
|
397
|
+
Example:
|
|
398
|
+
--fields oneField,anotherField,yetAnotherOne.nested.moarNested
|
|
397
399
|
|
|
398
|
-
|
|
400
|
+
Note that the '_id' field is always included in the CSV export. Leaving this option empty implies that all
|
|
401
|
+
exportable fields in the mapping will be exported.
|
|
399
402
|
|
|
400
|
-
--
|
|
403
|
+
--format=jsonl|kuzzle|csv
|
|
404
|
+
[default: jsonl] "kuzzle" will export in Kuzzle format usable for internal fixtures,
|
|
405
|
+
"jsonl" allows to import that data back with kourou,
|
|
406
|
+
"csv" allows to import data into Excel (please, specify the fields to export using the --fields option).
|
|
401
407
|
|
|
402
|
-
--
|
|
408
|
+
--help
|
|
409
|
+
show CLI help
|
|
403
410
|
|
|
404
|
-
--
|
|
411
|
+
--host=host
|
|
412
|
+
[default: localhost] Kuzzle server host
|
|
405
413
|
|
|
406
|
-
--
|
|
414
|
+
--password=password
|
|
415
|
+
Kuzzle user password
|
|
416
|
+
|
|
417
|
+
--path=path
|
|
418
|
+
Dump root directory
|
|
419
|
+
|
|
420
|
+
--port=port
|
|
421
|
+
[default: 7512] Kuzzle server port
|
|
422
|
+
|
|
423
|
+
--protocol=protocol
|
|
424
|
+
[default: ws] Kuzzle protocol (http or websocket)
|
|
425
|
+
|
|
426
|
+
--query=query
|
|
427
|
+
[default: {}] Only dump documents matching the query (JS or JSON format)
|
|
428
|
+
|
|
429
|
+
--ssl
|
|
430
|
+
Use SSL to connect to Kuzzle
|
|
431
|
+
|
|
432
|
+
--username=username
|
|
433
|
+
[default: anonymous] Kuzzle username (local strategy)
|
|
407
434
|
|
|
408
435
|
EXAMPLES
|
|
409
436
|
kourou collection:export nyc-open-data yellow-taxi
|
|
@@ -637,25 +664,6 @@ OPTIONS
|
|
|
637
664
|
|
|
638
665
|
_See code: [src/commands/es/snapshot/list.ts](src/commands/es/snapshot/list.ts)_
|
|
639
666
|
|
|
640
|
-
## `kourou es:snapshot:restore REPOSITORY NAME`
|
|
641
|
-
|
|
642
|
-
Restore a snapshot into an ES instance
|
|
643
|
-
|
|
644
|
-
```
|
|
645
|
-
USAGE
|
|
646
|
-
$ kourou es:snapshot:restore REPOSITORY NAME
|
|
647
|
-
|
|
648
|
-
ARGUMENTS
|
|
649
|
-
REPOSITORY ES repository name
|
|
650
|
-
NAME ES snapshot name
|
|
651
|
-
|
|
652
|
-
OPTIONS
|
|
653
|
-
-n, --node=node [default: http://localhost:9200] Elasticsearch server URL
|
|
654
|
-
--help show CLI help
|
|
655
|
-
```
|
|
656
|
-
|
|
657
|
-
_See code: [src/commands/es/snapshot/restore.ts](src/commands/es/snapshot/restore.ts)_
|
|
658
|
-
|
|
659
667
|
## `kourou file:decrypt FILE`
|
|
660
668
|
|
|
661
669
|
Decrypts an encrypted file.
|
|
@@ -737,7 +745,7 @@ OPTIONS
|
|
|
737
745
|
--all see all commands in CLI
|
|
738
746
|
```
|
|
739
747
|
|
|
740
|
-
_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v3.2.
|
|
748
|
+
_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v3.2.2/src/commands/help.ts)_
|
|
741
749
|
|
|
742
750
|
## `kourou import PATH`
|
|
743
751
|
|
|
@@ -1111,29 +1119,29 @@ DESCRIPTION
|
|
|
1111
1119
|
|
|
1112
1120
|
Code Execution
|
|
1113
1121
|
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1122
|
+
Provided code will be executed in an async method.
|
|
1123
|
+
You can access a connected and authenticated SDK with the "sdk" variable.
|
|
1124
|
+
Templated variable passed as the command arguments are also accessible within the same name.
|
|
1125
|
+
Returned value will be printed on the standard output (e.g. 'return await sdk.server.now();').
|
|
1126
|
+
Errors will be caught and printed on the error output (e.g. 'throw new Error("failure");').
|
|
1119
1127
|
|
|
1120
1128
|
Provide code
|
|
1121
1129
|
|
|
1122
|
-
|
|
1123
|
-
|
|
1130
|
+
code can be passed as an argument
|
|
1131
|
+
code will be read from STDIN if available
|
|
1124
1132
|
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1133
|
+
Examples:
|
|
1134
|
+
- kourou sdk:execute 'return await sdk.server.now()'
|
|
1135
|
+
- kourou sdk:execute 'return await sdk.index.exists(index)' --var 'index="iot-data"'
|
|
1136
|
+
- kourou sdk:execute < snippet.js
|
|
1137
|
+
- echo 'return await sdk.server.now()' | kourou sdk:execute
|
|
1130
1138
|
|
|
1131
1139
|
Other
|
|
1132
1140
|
|
|
1133
|
-
|
|
1141
|
+
use the --editor flag to modify the code before executing it
|
|
1134
1142
|
|
|
1135
|
-
|
|
1136
|
-
|
|
1143
|
+
Examples:
|
|
1144
|
+
- kourou sdk:execute 'return await sdk.server.now()' --editor
|
|
1137
1145
|
```
|
|
1138
1146
|
|
|
1139
1147
|
_See code: [src/commands/sdk/execute.ts](src/commands/sdk/execute.ts)_
|
|
@@ -1184,55 +1192,55 @@ DESCRIPTION
|
|
|
1184
1192
|
|
|
1185
1193
|
Query arguments
|
|
1186
1194
|
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1195
|
+
Arguments can be passed and repeated using the --arg or -a flag.
|
|
1196
|
+
Index and collection names can be passed with --index (-i) and --collection (-c) flags
|
|
1197
|
+
ID can be passed with the --id flag.
|
|
1190
1198
|
|
|
1191
|
-
|
|
1192
|
-
|
|
1199
|
+
Examples:
|
|
1200
|
+
- kourou sdk:query document:delete -i iot -c sensors -a refresh=wait_for
|
|
1193
1201
|
|
|
1194
1202
|
Query body
|
|
1195
1203
|
|
|
1196
|
-
|
|
1197
|
-
|
|
1204
|
+
Body can be passed with the --body flag with either a JSON or JS string.
|
|
1205
|
+
Body will be read from STDIN if available
|
|
1198
1206
|
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1207
|
+
Examples:
|
|
1208
|
+
- kourou sdk:query document:create -i iot -c sensors --body '{creation: Date.now())}'
|
|
1209
|
+
- kourou sdk:query admin:loadMappings < mappings.json
|
|
1210
|
+
- echo '{dynamic: "strict"}' | kourou sdk:query collection:create -i iot -c sensors
|
|
1203
1211
|
|
|
1204
1212
|
Other
|
|
1205
1213
|
|
|
1206
|
-
|
|
1207
|
-
|
|
1214
|
+
Use the --editor flag to modify the query before sending it to Kuzzle
|
|
1215
|
+
Use the --display flag to display a specific property of the response
|
|
1208
1216
|
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1217
|
+
Examples:
|
|
1218
|
+
- kourou sdk:query document:create -i iot -c sensors --editor
|
|
1219
|
+
- kourou sdk:query server:now --display 'result.now'
|
|
1212
1220
|
|
|
1213
1221
|
Default fallback to API action
|
|
1214
1222
|
|
|
1215
|
-
|
|
1216
|
-
|
|
1223
|
+
It's possible to use the "sdk:query" command by only specifying the corresponding controller
|
|
1224
|
+
and action as first argument.
|
|
1217
1225
|
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1226
|
+
Kourou will try to infer the first arguments to one the following pattern:
|
|
1227
|
+
- <command> <index>
|
|
1228
|
+
- <command> <body>
|
|
1229
|
+
- <command> <index> <collection>
|
|
1230
|
+
- <command> <index> <collection> <id>
|
|
1231
|
+
- <command> <index> <collection> <body>
|
|
1232
|
+
- <command> <index> <collection> <id> <body>
|
|
1225
1233
|
|
|
1226
|
-
|
|
1227
|
-
|
|
1234
|
+
If a flag is given (-i, -c, --body or --id), then the flag value has priority over
|
|
1235
|
+
argument infering.
|
|
1228
1236
|
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1237
|
+
Examples:
|
|
1238
|
+
- kourou collection:list iot
|
|
1239
|
+
- kourou security:createUser '{ "content": { "profileIds": ["default"] } }' --id yagmur
|
|
1240
|
+
- kourou collection:delete iot sensors
|
|
1241
|
+
- kourou document:createOrReplace iot sensors sigfox-1 '{}'
|
|
1242
|
+
- kourou bulk:import iot sensors '{ bulkData: [...] }'
|
|
1243
|
+
- kourou admin:loadMappings < mappings.json
|
|
1236
1244
|
```
|
|
1237
1245
|
|
|
1238
1246
|
_See code: [src/commands/sdk/query.ts](src/commands/sdk/query.ts)_
|
|
@@ -1267,24 +1275,24 @@ DESCRIPTION
|
|
|
1267
1275
|
The users will be exported WITHOUT their credentials since Kuzzzle can't access them.
|
|
1268
1276
|
|
|
1269
1277
|
You can either:
|
|
1270
|
-
|
|
1271
|
-
|
|
1278
|
+
- Manually re-create credentials for your users
|
|
1279
|
+
- Use the "mustChangePasswordIfSetByAdmin" option Kuzzle password policies (see
|
|
1272
1280
|
https://github.com/kuzzleio/kuzzle-plugin-auth-passport-local/#optional-properties)
|
|
1273
|
-
|
|
1281
|
+
- Use the "--generate-credentials" flag to auto-generate credentials for your users
|
|
1274
1282
|
|
|
1275
1283
|
Auto-generation of credentials
|
|
1276
1284
|
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1285
|
+
With the "--generate-credentials" flag, Kourou will add credentials for the "local" strategy.
|
|
1286
|
+
By default, the username will be the user ID.
|
|
1287
|
+
Use the "generated-username" flag to use an other property than the user ID for the generated username
|
|
1288
|
+
The password will be a strong random 40 characters string
|
|
1281
1289
|
|
|
1282
1290
|
Examples:
|
|
1283
1291
|
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1292
|
+
- kourou user:export
|
|
1293
|
+
- kourou user:export --exclude '.*admin.*' --exclude 'supervisor.*'
|
|
1294
|
+
- kourou user:export --generate-credentials
|
|
1295
|
+
- kourou user:export --generate-credentials --generated-username content.email
|
|
1288
1296
|
```
|
|
1289
1297
|
|
|
1290
1298
|
_See code: [src/commands/user/export.ts](src/commands/user/export.ts)_
|
|
@@ -1446,11 +1454,11 @@ DESCRIPTION
|
|
|
1446
1454
|
|
|
1447
1455
|
Example:
|
|
1448
1456
|
{
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1457
|
+
aws: {
|
|
1458
|
+
s3: {
|
|
1459
|
+
keyId: 'b61e267676660c314b006b06'
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1454
1462
|
}
|
|
1455
1463
|
|
|
1456
1464
|
Encrypted secrets are meant to be loaded inside an application with Kuzzle Vault.
|
|
@@ -1483,8 +1491,8 @@ DESCRIPTION
|
|
|
1483
1491
|
Prints an encrypted secrets file content.
|
|
1484
1492
|
|
|
1485
1493
|
This method can display either:
|
|
1486
|
-
|
|
1487
|
-
|
|
1494
|
+
- the entire content of the secrets file
|
|
1495
|
+
- a single key value
|
|
1488
1496
|
|
|
1489
1497
|
See https://github.com/kuzzleio/kuzzle-vault/ for more information.
|
|
1490
1498
|
|
|
@@ -1542,3 +1550,9 @@ $ kourou sdk:execute --print-raw '(
|
|
|
1542
1550
|
```
|
|
1543
1551
|
|
|
1544
1552
|
(Kuzzle must be accessible and running in local)
|
|
1553
|
+
|
|
1554
|
+
# Analytics
|
|
1555
|
+
|
|
1556
|
+
We use a custom Open Source analytics backend (you can check the code [here](https://gihtub.com/kuzzleio/kepler)) to record the use of Kourou by users.
|
|
1557
|
+
Collected metrics will allow us to study the use of our products in order to improve them. We do not collect any personal data about users.
|
|
1558
|
+
You can disable usage metrics collection by setting the `KOUROU_USAGE` environment variable to `false`.
|
|
@@ -10,6 +10,8 @@ export default class AppScaffold extends Kommand {
|
|
|
10
10
|
description: string;
|
|
11
11
|
required: boolean;
|
|
12
12
|
}[];
|
|
13
|
+
checkKebabCase(name: string): boolean;
|
|
14
|
+
convertToKebabCase(name: string): string;
|
|
13
15
|
runSafe(): Promise<void>;
|
|
14
16
|
renderTemplates(directory: string, templatePath: string): Promise<void>;
|
|
15
17
|
}
|
|
@@ -7,6 +7,7 @@ const command_1 = require("@oclif/command");
|
|
|
7
7
|
const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
|
|
8
8
|
const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
|
|
9
9
|
const listr_1 = (0, tslib_1.__importDefault)(require("listr"));
|
|
10
|
+
const inquirer_1 = (0, tslib_1.__importDefault)(require("inquirer"));
|
|
10
11
|
const common_1 = require("../../common");
|
|
11
12
|
const execute_1 = require("../../support/execute");
|
|
12
13
|
const templatesDir = path_1.default.join(__dirname, '..', '..', '..', 'templates');
|
|
@@ -15,8 +16,30 @@ const TEMPLATED_ENTRIES = [
|
|
|
15
16
|
'app.ts',
|
|
16
17
|
'README.md'
|
|
17
18
|
];
|
|
19
|
+
const KEBAB_CASE_REGEX = /^[a-z-\d]+$/;
|
|
18
20
|
class AppScaffold extends common_1.Kommand {
|
|
21
|
+
checkKebabCase(name) {
|
|
22
|
+
return KEBAB_CASE_REGEX.test(name);
|
|
23
|
+
}
|
|
24
|
+
convertToKebabCase(name) {
|
|
25
|
+
return name.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
|
|
26
|
+
}
|
|
19
27
|
async runSafe() {
|
|
28
|
+
if (!this.checkKebabCase(this.args.name)) {
|
|
29
|
+
this.logKo(`The application name must be in kebab-case`);
|
|
30
|
+
const kebabCasedName = this.convertToKebabCase(this.args.name);
|
|
31
|
+
const response = await inquirer_1.default.prompt([
|
|
32
|
+
{
|
|
33
|
+
name: 'kebabCaseConversion',
|
|
34
|
+
type: 'confirm',
|
|
35
|
+
message: `Would you like to convert "${this.args.name}" to "${kebabCasedName}"`
|
|
36
|
+
}
|
|
37
|
+
]);
|
|
38
|
+
if (!response.kebabCaseConversion) {
|
|
39
|
+
process.exit(0);
|
|
40
|
+
}
|
|
41
|
+
this.args.name = kebabCasedName;
|
|
42
|
+
}
|
|
20
43
|
const templatePath = path_1.default.join(templatesDir, 'app-scaffold', 'ts');
|
|
21
44
|
const tasks = new listr_1.default([
|
|
22
45
|
{
|
|
@@ -17,6 +17,7 @@ export default class CollectionExport extends Kommand {
|
|
|
17
17
|
query: flags.IOptionFlag<string>;
|
|
18
18
|
editor: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
19
19
|
format: flags.IOptionFlag<string>;
|
|
20
|
+
fields: flags.IOptionFlag<string | undefined>;
|
|
20
21
|
};
|
|
21
22
|
static args: {
|
|
22
23
|
name: string;
|
|
@@ -12,16 +12,22 @@ class CollectionExport extends common_1.Kommand {
|
|
|
12
12
|
const exportPath = this.flags.path
|
|
13
13
|
? path_1.default.join(this.flags.path, this.args.index)
|
|
14
14
|
: this.args.index;
|
|
15
|
+
const fields = this.flags.fields
|
|
16
|
+
? this.flags.fields.split(',')
|
|
17
|
+
: [];
|
|
18
|
+
if (this.flags.format === 'csv' && fields.length === 0) {
|
|
19
|
+
this.logInfo('It looks like you are exporting to CSV but you did not select any field. All exportable fields in the mapping will be exported.');
|
|
20
|
+
}
|
|
15
21
|
let query = this.parseJs(this.flags.query);
|
|
16
22
|
if (this.flags.editor) {
|
|
17
23
|
query = this.fromEditor(query, { json: true });
|
|
18
24
|
}
|
|
19
25
|
const countAll = await this.sdk.document.count(this.args.index, this.args.collection);
|
|
20
26
|
const count = await this.sdk.document.count(this.args.index, this.args.collection, { query });
|
|
21
|
-
this.logInfo(`Dumping ${count} of ${countAll} documents from collection "${this.args.index}:${this.args.collection}" in ${
|
|
27
|
+
this.logInfo(`Dumping ${count} of ${countAll} documents from collection "${this.args.index}:${this.args.collection}" in ${exportPath} ...`);
|
|
22
28
|
fs_1.default.mkdirSync(exportPath, { recursive: true });
|
|
23
29
|
await (0, dump_collection_1.dumpCollectionMappings)(this.sdk, this.args.index, this.args.collection, exportPath, this.flags.format);
|
|
24
|
-
await (0, dump_collection_1.dumpCollectionData)(this.sdk, this.args.index, this.args.collection, Number(this.flags['batch-size']), exportPath, query, this.flags.format);
|
|
30
|
+
await (0, dump_collection_1.dumpCollectionData)(this.sdk, this.args.index, this.args.collection, Number(this.flags['batch-size']), exportPath, query, this.flags.format, fields);
|
|
25
31
|
this.logOk(`Collection ${this.args.index}:${this.args.collection} dumped`);
|
|
26
32
|
}
|
|
27
33
|
}
|
|
@@ -38,8 +44,19 @@ CollectionExport.flags = Object.assign(Object.assign({ help: command_1.flags.hel
|
|
|
38
44
|
}), editor: command_1.flags.boolean({
|
|
39
45
|
description: 'Open an editor (EDITOR env variable) to edit the query before sending'
|
|
40
46
|
}), format: command_1.flags.string({
|
|
41
|
-
description:
|
|
42
|
-
|
|
47
|
+
description: `"kuzzle" will export in Kuzzle format usable for internal fixtures,
|
|
48
|
+
"jsonl" allows to import that data back with kourou,
|
|
49
|
+
"csv" allows to import data into Excel (please, specify the fields to export using the --fields option).`,
|
|
50
|
+
options: ['jsonl', 'kuzzle', 'csv'],
|
|
51
|
+
default: 'jsonl'
|
|
52
|
+
}), fields: command_1.flags.string({
|
|
53
|
+
description: `[CSV format only] The list of fields to be included in the CSV export in dot-path format.
|
|
54
|
+
|
|
55
|
+
Example:
|
|
56
|
+
--fields oneField,anotherField,yetAnotherOne.nested.moarNested
|
|
57
|
+
|
|
58
|
+
Note that the '_id' field is always included in the CSV export. Leaving this option empty implies that all
|
|
59
|
+
exportable fields in the mapping will be exported.`
|
|
43
60
|
}) }, kuzzle_1.kuzzleFlags), { protocol: command_1.flags.string({
|
|
44
61
|
description: 'Kuzzle protocol (http or websocket)',
|
|
45
62
|
default: 'ws',
|
|
@@ -24,7 +24,7 @@ class DocumentSearch extends common_1.Kommand {
|
|
|
24
24
|
request = this.fromEditor(request, { json: true });
|
|
25
25
|
}
|
|
26
26
|
const { result } = await this.sdk.query(request);
|
|
27
|
-
for (const document of result === null || result === void 0 ? void 0 : result.hits) {
|
|
27
|
+
for (const document of (result === null || result === void 0 ? void 0 : result.hits) || []) {
|
|
28
28
|
this.logInfo(`Document ID: ${document._id}`);
|
|
29
29
|
this.log(`Content: ${JSON.stringify(document._source, null, 2)}`);
|
|
30
30
|
}
|
package/lib/common.d.ts
CHANGED
|
@@ -4,12 +4,14 @@ import { EditorParams } from './support/editor';
|
|
|
4
4
|
export declare abstract class Kommand extends Command {
|
|
5
5
|
protected sdk: KuzzleSDK;
|
|
6
6
|
private exitCode;
|
|
7
|
+
private analytics;
|
|
7
8
|
args: any;
|
|
8
9
|
flags: any;
|
|
9
10
|
static initSdk: boolean;
|
|
10
11
|
static readStdin: boolean;
|
|
11
12
|
stdin: string | undefined;
|
|
12
13
|
sdkOptions: any;
|
|
14
|
+
constructor(argv: any, config: any);
|
|
13
15
|
printCommand(): void;
|
|
14
16
|
log(message?: string): void;
|
|
15
17
|
logOk(message: string): void;
|
|
@@ -27,3 +29,20 @@ export declare abstract class Kommand extends Command {
|
|
|
27
29
|
fromEditor(defaultContent: Record<string, unknown> | string, options?: EditorParams): Record<string, unknown>;
|
|
28
30
|
parseJs(input?: string): any;
|
|
29
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* An iteration-order-safe version of lodash.values
|
|
34
|
+
*
|
|
35
|
+
* @param object The object containing the values
|
|
36
|
+
* @param fields The field names to pick in the right order
|
|
37
|
+
* @returns The values in the same order as the fields
|
|
38
|
+
* @see https://lodash.com/docs/4.17.15#values
|
|
39
|
+
*/
|
|
40
|
+
export declare function pickValues(object: any, fields: string[]): any[];
|
|
41
|
+
/**
|
|
42
|
+
* Formats the value for correct CSV output, avoiding to return
|
|
43
|
+
* values that would badly serialize in CSV.
|
|
44
|
+
*
|
|
45
|
+
* @param value The value to format
|
|
46
|
+
* @returns The value or a string telling the value is not scalar
|
|
47
|
+
*/
|
|
48
|
+
export declare function formatValueForCSV(value: any): any;
|
package/lib/common.js
CHANGED
|
@@ -1,21 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Kommand = void 0;
|
|
3
|
+
exports.formatValueForCSV = exports.pickValues = exports.Kommand = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const command_1 = require("@oclif/command");
|
|
6
6
|
const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
|
|
7
7
|
const node_emoji_1 = (0, tslib_1.__importDefault)(require("node-emoji"));
|
|
8
8
|
const fs_1 = (0, tslib_1.__importDefault)(require("fs"));
|
|
9
|
+
const get_1 = (0, tslib_1.__importDefault)(require("lodash/get"));
|
|
10
|
+
const isObject_1 = (0, tslib_1.__importDefault)(require("lodash/isObject"));
|
|
11
|
+
const kepler_companion_1 = (0, tslib_1.__importDefault)(require("kepler-companion"));
|
|
9
12
|
const kuzzle_1 = require("./support/kuzzle");
|
|
10
13
|
const editor_1 = require("./support/editor");
|
|
11
14
|
class Kommand extends command_1.Command {
|
|
12
|
-
constructor() {
|
|
13
|
-
super(
|
|
15
|
+
constructor(argv, config) {
|
|
16
|
+
super(argv, config);
|
|
14
17
|
// Instantiate a dummy SDK to avoid the this.sdk notation everywhere -_-
|
|
15
18
|
this.sdk = new kuzzle_1.KuzzleSDK({ host: 'nowhere' });
|
|
16
19
|
this.exitCode = 0;
|
|
20
|
+
this.analytics = new kepler_companion_1.default();
|
|
17
21
|
this.stdin = undefined;
|
|
18
22
|
this.sdkOptions = {};
|
|
23
|
+
if (process.env.KOUROU_USAGE
|
|
24
|
+
&& process.env.KOUROU_USAGE !== 'true') {
|
|
25
|
+
this.analytics.turnOff();
|
|
26
|
+
}
|
|
19
27
|
}
|
|
20
28
|
printCommand() {
|
|
21
29
|
const klass = this.constructor;
|
|
@@ -70,15 +78,21 @@ class Kommand extends command_1.Command {
|
|
|
70
78
|
this.sdk = new kuzzle_1.KuzzleSDK(Object.assign(Object.assign(Object.assign({}, this.flags), this.sdkOptions), { appName: this.config.name, appVersion: this.config.version }));
|
|
71
79
|
await this.sdk.init(this);
|
|
72
80
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
const runCmd = () => {
|
|
82
|
+
if (this.flags.as) {
|
|
83
|
+
this.logInfo(`Impersonate user "${this.flags.as}"`);
|
|
84
|
+
return this.sdk.impersonate(this.flags.as, async () => {
|
|
85
|
+
return this.runSafe();
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
return this.runSafe();
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
await Promise.all([
|
|
93
|
+
this.analytics.track({ action: kommand.id, product: this.config.name, version: this.config.version }),
|
|
94
|
+
runCmd()
|
|
95
|
+
]);
|
|
82
96
|
}
|
|
83
97
|
catch (error) {
|
|
84
98
|
const stack = error.kuzzleStack || error.stack;
|
|
@@ -86,6 +100,9 @@ class Kommand extends command_1.Command {
|
|
|
86
100
|
? ` (https://docs.kuzzle.io/core/2/api/errors/error-codes/${error.id.split('.')[0]})`
|
|
87
101
|
: '';
|
|
88
102
|
this.logKo(`Error stack: \n${stack || error.message}\n\nError status: ${error.status}\n\nError id: ${error.id}${errorLink}`);
|
|
103
|
+
for (const err of error.errors) {
|
|
104
|
+
this.logKo(`${err.document._id} : ${err.reason}`);
|
|
105
|
+
}
|
|
89
106
|
}
|
|
90
107
|
finally {
|
|
91
108
|
this.sdk.disconnect();
|
|
@@ -131,3 +148,29 @@ class Kommand extends command_1.Command {
|
|
|
131
148
|
exports.Kommand = Kommand;
|
|
132
149
|
Kommand.initSdk = true;
|
|
133
150
|
Kommand.readStdin = false;
|
|
151
|
+
/**
|
|
152
|
+
* An iteration-order-safe version of lodash.values
|
|
153
|
+
*
|
|
154
|
+
* @param object The object containing the values
|
|
155
|
+
* @param fields The field names to pick in the right order
|
|
156
|
+
* @returns The values in the same order as the fields
|
|
157
|
+
* @see https://lodash.com/docs/4.17.15#values
|
|
158
|
+
*/
|
|
159
|
+
function pickValues(object, fields) {
|
|
160
|
+
return fields.map(f => formatValueForCSV((0, get_1.default)(object, f)));
|
|
161
|
+
}
|
|
162
|
+
exports.pickValues = pickValues;
|
|
163
|
+
/**
|
|
164
|
+
* Formats the value for correct CSV output, avoiding to return
|
|
165
|
+
* values that would badly serialize in CSV.
|
|
166
|
+
*
|
|
167
|
+
* @param value The value to format
|
|
168
|
+
* @returns The value or a string telling the value is not scalar
|
|
169
|
+
*/
|
|
170
|
+
function formatValueForCSV(value) {
|
|
171
|
+
if ((0, isObject_1.default)(value)) {
|
|
172
|
+
return '[NOT_SCALAR]';
|
|
173
|
+
}
|
|
174
|
+
return value;
|
|
175
|
+
}
|
|
176
|
+
exports.formatValueForCSV = formatValueForCSV;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function dumpCollectionData(sdk: any, index: string, collection: string, batchSize: number, destPath: string, query?: any, format?: string): Promise<
|
|
1
|
+
export declare function dumpCollectionData(sdk: any, index: string, collection: string, batchSize: number, destPath: string, query?: any, format?: string, fields?: string[]): Promise<void>;
|
|
2
2
|
export declare function dumpCollectionMappings(sdk: any, index: string, collection: string, destPath: string, format?: string): Promise<void>;
|