kourou 0.19.3 → 0.20.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -25,7 +25,7 @@ $ npm install -g kourou
25
25
  $ kourou COMMAND
26
26
  running command...
27
27
  $ kourou (-v|--version|version)
28
- kourou/0.19.3 linux-x64 node-v14.17.0
28
+ kourou/0.20.1 linux-x64 node-v12.22.9
29
29
  $ kourou --help [COMMAND]
30
30
  USAGE
31
31
  $ kourou COMMAND
@@ -130,6 +130,7 @@ All other arguments and options will be passed as-is to the `sdk:query` method.
130
130
  * [`kourou api-key:search USER`](#kourou-api-keysearch-user)
131
131
  * [`kourou app:scaffold NAME`](#kourou-appscaffold-name)
132
132
  * [`kourou app:start-services`](#kourou-appstart-services)
133
+ * [`kourou autocomplete [SHELL]`](#kourou-autocomplete-shell)
133
134
  * [`kourou collection:create INDEX COLLECTION [BODY]`](#kourou-collectioncreate-index-collection-body)
134
135
  * [`kourou collection:export INDEX COLLECTION`](#kourou-collectionexport-index-collection)
135
136
  * [`kourou collection:import PATH`](#kourou-collectionimport-path)
@@ -142,7 +143,6 @@ All other arguments and options will be passed as-is to the `sdk:query` method.
142
143
  * [`kourou es:snapshot:create REPOSITORY NAME`](#kourou-essnapshotcreate-repository-name)
143
144
  * [`kourou es:snapshot:create-repository REPOSITORY LOCATION`](#kourou-essnapshotcreate-repository-repository-location)
144
145
  * [`kourou es:snapshot:list REPOSITORY`](#kourou-essnapshotlist-repository)
145
- * [`kourou es:snapshot:restore REPOSITORY NAME`](#kourou-essnapshotrestore-repository-name)
146
146
  * [`kourou file:decrypt FILE`](#kourou-filedecrypt-file)
147
147
  * [`kourou file:encrypt FILE`](#kourou-fileencrypt-file)
148
148
  * [`kourou file:test FILE`](#kourou-filetest-file)
@@ -315,6 +315,29 @@ OPTIONS
315
315
 
316
316
  _See code: [src/commands/app/start-services.ts](src/commands/app/start-services.ts)_
317
317
 
318
+ ## `kourou autocomplete [SHELL]`
319
+
320
+ display autocomplete installation instructions
321
+
322
+ ```
323
+ USAGE
324
+ $ kourou autocomplete [SHELL]
325
+
326
+ ARGUMENTS
327
+ SHELL shell type
328
+
329
+ OPTIONS
330
+ -r, --refresh-cache Refresh cache (ignores displaying instructions)
331
+
332
+ EXAMPLES
333
+ $ kourou autocomplete
334
+ $ kourou autocomplete bash
335
+ $ kourou autocomplete zsh
336
+ $ kourou autocomplete --refresh-cache
337
+ ```
338
+
339
+ _See code: [@oclif/plugin-autocomplete](https://github.com/oclif/plugin-autocomplete/blob/v0.3.0/src/commands/autocomplete/index.ts)_
340
+
318
341
  ## `kourou collection:create INDEX COLLECTION [BODY]`
319
342
 
320
343
  Creates a collection
@@ -355,31 +378,58 @@ ARGUMENTS
355
378
  COLLECTION Collection name
356
379
 
357
380
  OPTIONS
358
- --api-key=api-key Kuzzle user api-key
359
- --as=as Impersonate a user
360
- --batch-size=batch-size [default: 2000] Maximum batch size (see limits.documentsFetchCount config)
361
- --editor Open an editor (EDITOR env variable) to edit the query before sending
381
+ --api-key=api-key
382
+ Kuzzle user api-key
362
383
 
363
- --format=format [default: JSONL] "jsonl or kuzzle - kuzzle will export in Kuzzle format usable for internal
364
- fixtures and jsonl allows to import that data back with kourou
384
+ --as=as
385
+ Impersonate a user
365
386
 
366
- --help show CLI help
387
+ --batch-size=batch-size
388
+ [default: 2000] Maximum batch size (see limits.documentsFetchCount config)
367
389
 
368
- --host=host [default: localhost] Kuzzle server host
390
+ --editor
391
+ Open an editor (EDITOR env variable) to edit the query before sending
369
392
 
370
- --password=password Kuzzle user password
393
+ --fields=fields
394
+ [CSV format only] The list of fields to be included in the CSV export in dot-path format.
371
395
 
372
- --path=path Dump root directory
396
+ Example:
397
+ --fields oneField,anotherField,yetAnotherOne.nested.moarNested
373
398
 
374
- --port=port [default: 7512] Kuzzle server port
399
+ Note that the '_id' field is always included in the CSV export. Leaving this option empty implies that all
400
+ exportable fields in the mapping will be exported.
375
401
 
376
- --protocol=protocol [default: ws] Kuzzle protocol (http or websocket)
402
+ --format=jsonl|kuzzle|csv
403
+ [default: jsonl] "kuzzle" will export in Kuzzle format usable for internal fixtures,
404
+ "jsonl" allows to import that data back with kourou,
405
+ "csv" allows to import data into Excel (please, specify the fields to export using the --fields option).
377
406
 
378
- --query=query [default: {}] Only dump documents matching the query (JS or JSON format)
407
+ --help
408
+ show CLI help
379
409
 
380
- --ssl Use SSL to connect to Kuzzle
410
+ --host=host
411
+ [default: localhost] Kuzzle server host
381
412
 
382
- --username=username [default: anonymous] Kuzzle username (local strategy)
413
+ --password=password
414
+ Kuzzle user password
415
+
416
+ --path=path
417
+ Dump root directory
418
+
419
+ --port=port
420
+ [default: 7512] Kuzzle server port
421
+
422
+ --protocol=protocol
423
+ [default: ws] Kuzzle protocol (http or websocket)
424
+
425
+ --query=query
426
+ [default: {}] Only dump documents matching the query (JS or JSON format)
427
+
428
+ --ssl
429
+ Use SSL to connect to Kuzzle
430
+
431
+ --username=username
432
+ [default: anonymous] Kuzzle username (local strategy)
383
433
 
384
434
  EXAMPLES
385
435
  kourou collection:export nyc-open-data yellow-taxi
@@ -613,25 +663,6 @@ OPTIONS
613
663
 
614
664
  _See code: [src/commands/es/snapshot/list.ts](src/commands/es/snapshot/list.ts)_
615
665
 
616
- ## `kourou es:snapshot:restore REPOSITORY NAME`
617
-
618
- Restore a snapshot into an ES instance
619
-
620
- ```
621
- USAGE
622
- $ kourou es:snapshot:restore REPOSITORY NAME
623
-
624
- ARGUMENTS
625
- REPOSITORY ES repository name
626
- NAME ES snapshot name
627
-
628
- OPTIONS
629
- -n, --node=node [default: http://localhost:9200] Elasticsearch server URL
630
- --help show CLI help
631
- ```
632
-
633
- _See code: [src/commands/es/snapshot/restore.ts](src/commands/es/snapshot/restore.ts)_
634
-
635
666
  ## `kourou file:decrypt FILE`
636
667
 
637
668
  Decrypts an encrypted file.
@@ -713,7 +744,7 @@ OPTIONS
713
744
  --all see all commands in CLI
714
745
  ```
715
746
 
716
- _See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v3.2.3/src/commands/help.ts)_
747
+ _See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v3.2.2/src/commands/help.ts)_
717
748
 
718
749
  ## `kourou import PATH`
719
750
 
@@ -1087,29 +1118,29 @@ DESCRIPTION
1087
1118
 
1088
1119
  Code Execution
1089
1120
 
1090
- Provided code will be executed in an async method.
1091
- You can access a connected and authenticated SDK with the "sdk" variable.
1092
- Templated variable passed as the command arguments are also accessible within the same name.
1093
- Returned value will be printed on the standard output (e.g. 'return await sdk.server.now();').
1094
- Errors will be caught and printed on the error output (e.g. 'throw new Error("failure");').
1121
+ Provided code will be executed in an async method.
1122
+ You can access a connected and authenticated SDK with the "sdk" variable.
1123
+ Templated variable passed as the command arguments are also accessible within the same name.
1124
+ Returned value will be printed on the standard output (e.g. 'return await sdk.server.now();').
1125
+ Errors will be caught and printed on the error output (e.g. 'throw new Error("failure");').
1095
1126
 
1096
1127
  Provide code
1097
1128
 
1098
- code can be passed as an argument
1099
- code will be read from STDIN if available
1129
+ code can be passed as an argument
1130
+ code will be read from STDIN if available
1100
1131
 
1101
- Examples:
1102
- - kourou sdk:execute 'return await sdk.server.now()'
1103
- - kourou sdk:execute 'return await sdk.index.exists(index)' --var 'index="iot-data"'
1104
- - kourou sdk:execute < snippet.js
1105
- - echo 'return await sdk.server.now()' | kourou sdk:execute
1132
+ Examples:
1133
+ - kourou sdk:execute 'return await sdk.server.now()'
1134
+ - kourou sdk:execute 'return await sdk.index.exists(index)' --var 'index="iot-data"'
1135
+ - kourou sdk:execute < snippet.js
1136
+ - echo 'return await sdk.server.now()' | kourou sdk:execute
1106
1137
 
1107
1138
  Other
1108
1139
 
1109
- use the --editor flag to modify the code before executing it
1140
+ use the --editor flag to modify the code before executing it
1110
1141
 
1111
- Examples:
1112
- - kourou sdk:execute 'return await sdk.server.now()' --editor
1142
+ Examples:
1143
+ - kourou sdk:execute 'return await sdk.server.now()' --editor
1113
1144
  ```
1114
1145
 
1115
1146
  _See code: [src/commands/sdk/execute.ts](src/commands/sdk/execute.ts)_
@@ -1160,55 +1191,55 @@ DESCRIPTION
1160
1191
 
1161
1192
  Query arguments
1162
1193
 
1163
- Arguments can be passed and repeated using the --arg or -a flag.
1164
- Index and collection names can be passed with --index (-i) and --collection (-c) flags
1165
- ID can be passed with the --id flag.
1194
+ Arguments can be passed and repeated using the --arg or -a flag.
1195
+ Index and collection names can be passed with --index (-i) and --collection (-c) flags
1196
+ ID can be passed with the --id flag.
1166
1197
 
1167
- Examples:
1168
- - kourou sdk:query document:delete -i iot -c sensors -a refresh=wait_for
1198
+ Examples:
1199
+ - kourou sdk:query document:delete -i iot -c sensors -a refresh=wait_for
1169
1200
 
1170
1201
  Query body
1171
1202
 
1172
- Body can be passed with the --body flag with either a JSON or JS string.
1173
- Body will be read from STDIN if available
1203
+ Body can be passed with the --body flag with either a JSON or JS string.
1204
+ Body will be read from STDIN if available
1174
1205
 
1175
- Examples:
1176
- - kourou sdk:query document:create -i iot -c sensors --body '{creation: Date.now())}'
1177
- - kourou sdk:query admin:loadMappings < mappings.json
1178
- - echo '{dynamic: "strict"}' | kourou sdk:query collection:create -i iot -c sensors
1206
+ Examples:
1207
+ - kourou sdk:query document:create -i iot -c sensors --body '{creation: Date.now())}'
1208
+ - kourou sdk:query admin:loadMappings < mappings.json
1209
+ - echo '{dynamic: "strict"}' | kourou sdk:query collection:create -i iot -c sensors
1179
1210
 
1180
1211
  Other
1181
1212
 
1182
- Use the --editor flag to modify the query before sending it to Kuzzle
1183
- Use the --display flag to display a specific property of the response
1213
+ Use the --editor flag to modify the query before sending it to Kuzzle
1214
+ Use the --display flag to display a specific property of the response
1184
1215
 
1185
- Examples:
1186
- - kourou sdk:query document:create -i iot -c sensors --editor
1187
- - kourou sdk:query server:now --display 'result.now'
1216
+ Examples:
1217
+ - kourou sdk:query document:create -i iot -c sensors --editor
1218
+ - kourou sdk:query server:now --display 'result.now'
1188
1219
 
1189
1220
  Default fallback to API action
1190
1221
 
1191
- It's possible to use the "sdk:query" command by only specifying the corresponding controller
1192
- and action as first argument.
1222
+ It's possible to use the "sdk:query" command by only specifying the corresponding controller
1223
+ and action as first argument.
1193
1224
 
1194
- Kourou will try to infer the first arguments to one the following pattern:
1195
- - <command> <index>
1196
- - <command> <body>
1197
- - <command> <index> <collection>
1198
- - <command> <index> <collection> <id>
1199
- - <command> <index> <collection> <body>
1200
- - <command> <index> <collection> <id> <body>
1225
+ Kourou will try to infer the first arguments to one the following pattern:
1226
+ - <command> <index>
1227
+ - <command> <body>
1228
+ - <command> <index> <collection>
1229
+ - <command> <index> <collection> <id>
1230
+ - <command> <index> <collection> <body>
1231
+ - <command> <index> <collection> <id> <body>
1201
1232
 
1202
- If a flag is given (-i, -c, --body or --id), then the flag value has priority over
1203
- argument infering.
1233
+ If a flag is given (-i, -c, --body or --id), then the flag value has priority over
1234
+ argument infering.
1204
1235
 
1205
- Examples:
1206
- - kourou collection:list iot
1207
- - kourou security:createUser '{ "content": { "profileIds": ["default"] } }' --id yagmur
1208
- - kourou collection:delete iot sensors
1209
- - kourou document:createOrReplace iot sensors sigfox-1 '{}'
1210
- - kourou bulk:import iot sensors '{ bulkData: [...] }'
1211
- - kourou admin:loadMappings < mappings.json
1236
+ Examples:
1237
+ - kourou collection:list iot
1238
+ - kourou security:createUser '{ "content": { "profileIds": ["default"] } }' --id yagmur
1239
+ - kourou collection:delete iot sensors
1240
+ - kourou document:createOrReplace iot sensors sigfox-1 '{}'
1241
+ - kourou bulk:import iot sensors '{ bulkData: [...] }'
1242
+ - kourou admin:loadMappings < mappings.json
1212
1243
  ```
1213
1244
 
1214
1245
  _See code: [src/commands/sdk/query.ts](src/commands/sdk/query.ts)_
@@ -1243,24 +1274,24 @@ DESCRIPTION
1243
1274
  The users will be exported WITHOUT their credentials since Kuzzzle can't access them.
1244
1275
 
1245
1276
  You can either:
1246
- - Manually re-create credentials for your users
1247
- - Use the "mustChangePasswordIfSetByAdmin" option Kuzzle password policies (see
1277
+ - Manually re-create credentials for your users
1278
+ - Use the "mustChangePasswordIfSetByAdmin" option Kuzzle password policies (see
1248
1279
  https://github.com/kuzzleio/kuzzle-plugin-auth-passport-local/#optional-properties)
1249
- - Use the "--generate-credentials" flag to auto-generate credentials for your users
1280
+ - Use the "--generate-credentials" flag to auto-generate credentials for your users
1250
1281
 
1251
1282
  Auto-generation of credentials
1252
1283
 
1253
- With the "--generate-credentials" flag, Kourou will add credentials for the "local" strategy.
1254
- By default, the username will be the user ID.
1255
- Use the "generated-username" flag to use an other property than the user ID for the generated username
1256
- The password will be a strong random 40 characters string
1284
+ With the "--generate-credentials" flag, Kourou will add credentials for the "local" strategy.
1285
+ By default, the username will be the user ID.
1286
+ Use the "generated-username" flag to use an other property than the user ID for the generated username
1287
+ The password will be a strong random 40 characters string
1257
1288
 
1258
1289
  Examples:
1259
1290
 
1260
- - kourou user:export
1261
- - kourou user:export --exclude '.*admin.*' --exclude 'supervisor.*'
1262
- - kourou user:export --generate-credentials
1263
- - kourou user:export --generate-credentials --generated-username content.email
1291
+ - kourou user:export
1292
+ - kourou user:export --exclude '.*admin.*' --exclude 'supervisor.*'
1293
+ - kourou user:export --generate-credentials
1294
+ - kourou user:export --generate-credentials --generated-username content.email
1264
1295
  ```
1265
1296
 
1266
1297
  _See code: [src/commands/user/export.ts](src/commands/user/export.ts)_
@@ -1422,11 +1453,11 @@ DESCRIPTION
1422
1453
 
1423
1454
  Example:
1424
1455
  {
1425
- aws: {
1426
- s3: {
1427
- keyId: 'b61e267676660c314b006b06'
1428
- }
1429
- }
1456
+ aws: {
1457
+ s3: {
1458
+ keyId: 'b61e267676660c314b006b06'
1459
+ }
1460
+ }
1430
1461
  }
1431
1462
 
1432
1463
  Encrypted secrets are meant to be loaded inside an application with Kuzzle Vault.
@@ -1459,8 +1490,8 @@ DESCRIPTION
1459
1490
  Prints an encrypted secrets file content.
1460
1491
 
1461
1492
  This method can display either:
1462
- - the entire content of the secrets file
1463
- - a single key value
1493
+ - the entire content of the secrets file
1494
+ - a single key value
1464
1495
 
1465
1496
  See https://github.com/kuzzleio/kuzzle-vault/ for more information.
1466
1497
 
@@ -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 ${path_1.default} ...`);
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: '"jsonl or kuzzle - kuzzle will export in Kuzzle format usable for internal fixtures and jsonl allows to import that data back with kourou',
42
- default: 'JSONL'
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
  }
@@ -21,7 +21,6 @@ class RoleDump extends common_1.Kommand {
21
21
  }
22
22
  async _dumpRoles() {
23
23
  const options = {
24
- scroll: '3s',
25
24
  size: 100
26
25
  };
27
26
  let result = await this.sdk.security.searchRoles({}, options);
package/lib/common.d.ts CHANGED
@@ -27,3 +27,20 @@ export declare abstract class Kommand extends Command {
27
27
  fromEditor(defaultContent: Record<string, unknown> | string, options?: EditorParams): Record<string, unknown>;
28
28
  parseJs(input?: string): any;
29
29
  }
30
+ /**
31
+ * An iteration-order-safe version of lodash.values
32
+ *
33
+ * @param object The object containing the values
34
+ * @param fields The field names to pick in the right order
35
+ * @returns The values in the same order as the fields
36
+ * @see https://lodash.com/docs/4.17.15#values
37
+ */
38
+ export declare function pickValues(object: any, fields: string[]): any[];
39
+ /**
40
+ * Formats the value for correct CSV output, avoiding to return
41
+ * values that would badly serialize in CSV.
42
+ *
43
+ * @param value The value to format
44
+ * @returns The value or a string telling the value is not scalar
45
+ */
46
+ export declare function formatValueForCSV(value: any): any;
package/lib/common.js CHANGED
@@ -1,11 +1,13 @@
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"));
9
11
  const kuzzle_1 = require("./support/kuzzle");
10
12
  const editor_1 = require("./support/editor");
11
13
  class Kommand extends command_1.Command {
@@ -86,6 +88,9 @@ class Kommand extends command_1.Command {
86
88
  ? ` (https://docs.kuzzle.io/core/2/api/errors/error-codes/${error.id.split('.')[0]})`
87
89
  : '';
88
90
  this.logKo(`Error stack: \n${stack || error.message}\n\nError status: ${error.status}\n\nError id: ${error.id}${errorLink}`);
91
+ for (const err of error.errors) {
92
+ this.logKo(`${err.document._id} : ${err.reason}`);
93
+ }
89
94
  }
90
95
  finally {
91
96
  this.sdk.disconnect();
@@ -131,3 +136,29 @@ class Kommand extends command_1.Command {
131
136
  exports.Kommand = Kommand;
132
137
  Kommand.initSdk = true;
133
138
  Kommand.readStdin = false;
139
+ /**
140
+ * An iteration-order-safe version of lodash.values
141
+ *
142
+ * @param object The object containing the values
143
+ * @param fields The field names to pick in the right order
144
+ * @returns The values in the same order as the fields
145
+ * @see https://lodash.com/docs/4.17.15#values
146
+ */
147
+ function pickValues(object, fields) {
148
+ return fields.map(f => formatValueForCSV((0, get_1.default)(object, f)));
149
+ }
150
+ exports.pickValues = pickValues;
151
+ /**
152
+ * Formats the value for correct CSV output, avoiding to return
153
+ * values that would badly serialize in CSV.
154
+ *
155
+ * @param value The value to format
156
+ * @returns The value or a string telling the value is not scalar
157
+ */
158
+ function formatValueForCSV(value) {
159
+ if ((0, isObject_1.default)(value)) {
160
+ return '[NOT_SCALAR]';
161
+ }
162
+ return value;
163
+ }
164
+ 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<unknown>;
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>;