kourou 0.19.2 → 0.20.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.
Files changed (53) hide show
  1. package/README.md +148 -108
  2. package/lib/commands/app/scaffold.d.ts +2 -0
  3. package/lib/commands/app/scaffold.js +30 -7
  4. package/lib/commands/app/start-services.js +7 -7
  5. package/lib/commands/collection/export.d.ts +1 -0
  6. package/lib/commands/collection/export.js +24 -7
  7. package/lib/commands/collection/import.js +4 -4
  8. package/lib/commands/config/diff.js +5 -5
  9. package/lib/commands/document/search.js +1 -1
  10. package/lib/commands/es/migrate.js +3 -3
  11. package/lib/commands/file/decrypt.js +2 -2
  12. package/lib/commands/file/encrypt.js +2 -2
  13. package/lib/commands/file/test.js +2 -2
  14. package/lib/commands/import.js +7 -7
  15. package/lib/commands/index/export.d.ts +2 -0
  16. package/lib/commands/index/export.js +13 -5
  17. package/lib/commands/index/import.js +4 -4
  18. package/lib/commands/instance/kill.js +6 -6
  19. package/lib/commands/instance/list.js +1 -1
  20. package/lib/commands/instance/logs.js +3 -3
  21. package/lib/commands/instance/spawn.js +10 -10
  22. package/lib/commands/profile/export.js +2 -2
  23. package/lib/commands/profile/import.js +2 -2
  24. package/lib/commands/realtime/subscribe.js +1 -1
  25. package/lib/commands/role/export.js +2 -3
  26. package/lib/commands/role/import.js +2 -2
  27. package/lib/commands/sdk/execute.js +2 -2
  28. package/lib/commands/sdk/query.js +1 -1
  29. package/lib/commands/user/export-mappings.js +2 -2
  30. package/lib/commands/user/export.js +4 -4
  31. package/lib/commands/user/import-mappings.js +1 -1
  32. package/lib/commands/user/import.js +2 -2
  33. package/lib/commands/vault/add.js +2 -2
  34. package/lib/commands/vault/decrypt.js +2 -2
  35. package/lib/commands/vault/encrypt.js +2 -2
  36. package/lib/commands/vault/show.js +3 -3
  37. package/lib/commands/vault/test.js +1 -1
  38. package/lib/common.d.ts +17 -0
  39. package/lib/common.js +35 -4
  40. package/lib/hooks/command_not_found/api-action.js +2 -2
  41. package/lib/support/dump-collection.d.ts +1 -1
  42. package/lib/support/dump-collection.js +211 -61
  43. package/lib/support/editor.js +3 -3
  44. package/lib/support/execute.js +1 -1
  45. package/lib/support/kuzzle.d.ts +1 -1
  46. package/lib/support/kuzzle.js +1 -0
  47. package/lib/support/restore-collection.js +5 -5
  48. package/lib/support/restore-securities.js +2 -2
  49. package/oclif.manifest.json +1 -1
  50. package/package.json +21 -19
  51. package/templates.tgz +0 -0
  52. package/lib/commands/es/snapshot/restore.d.ts +0 -18
  53. package/lib/commands/es/snapshot/restore.js +0 -52
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.2 linux-x64 node-v12.22.1
28
+ kourou/0.20.0 linux-x64 node-v12.22.9
29
29
  $ kourou --help [COMMAND]
30
30
  USAGE
31
31
  $ kourou COMMAND
@@ -48,7 +48,7 @@ By command line:
48
48
  --ssl [default: true for port 443] Use SSL to connect to Kuzzle
49
49
  --protocol [default: ws] Protocol used to connect to Kuzzle ( `http` or `ws` )
50
50
 
51
- ```
51
+ ```
52
52
 
53
53
  By environment variables:
54
54
  ```
@@ -61,7 +61,7 @@ By environment variables:
61
61
  KUZZLE_SSL Use SSL to connect to Kuzzle
62
62
  KUZZLE_PROTOCOL Protocol used to connect to Kuzzle ( `http` or `ws` )
63
63
 
64
- ```
64
+ ```
65
65
 
66
66
  ## User impersonation
67
67
 
@@ -81,11 +81,11 @@ $ kourou sdk:query auth:getCurrentUser --as gordon --username admin --password a
81
81
 
82
82
  ## Automatic command infering for API actions
83
83
 
84
- When no command is found, Kourou will try to execute the given command with the `sdk:query` command.
84
+ When no command is found, Kourou will try to execute the given command with the `sdk:query` command.
85
85
 
86
86
  The first argument has to be the name of the controller and the action separated by a semicolon (eg `document:create` )
87
87
 
88
- Kourou will try to infer common arguments like `index` , `collection` , `_id` or `body` .
88
+ Kourou will try to infer common arguments like `index` , `collection` , `_id` or `body` .
89
89
 
90
90
  It will automatically infer and accept the following lists of arguments:
91
91
  - `<command> <index>`
@@ -116,7 +116,10 @@ It will automatically infer and accept the following lists of arguments:
116
116
  - `<command> <index> <collection> <id> <body>`
117
117
  - _eg: `kourou document:create iot sensors sigfox-123 '{temperature: 42}'` _
118
118
 
119
- Then any argument will be passed as-is to the `sdk:query` method.
119
+ All other arguments and options will be passed as-is to the `sdk:query` method.
120
+
121
+ > Note: you can pass arguments to the API actions with the `--arg` or `-a` option in your command, e.g.
122
+ > `kourou security:createFirstAdmin '{ ...credentials here... }' -a reset=true`
120
123
 
121
124
  # Commands
122
125
 
@@ -127,6 +130,7 @@ Then any argument will be passed as-is to the `sdk:query` method.
127
130
  * [`kourou api-key:search USER`](#kourou-api-keysearch-user)
128
131
  * [`kourou app:scaffold NAME`](#kourou-appscaffold-name)
129
132
  * [`kourou app:start-services`](#kourou-appstart-services)
133
+ * [`kourou autocomplete [SHELL]`](#kourou-autocomplete-shell)
130
134
  * [`kourou collection:create INDEX COLLECTION [BODY]`](#kourou-collectioncreate-index-collection-body)
131
135
  * [`kourou collection:export INDEX COLLECTION`](#kourou-collectionexport-index-collection)
132
136
  * [`kourou collection:import PATH`](#kourou-collectionimport-path)
@@ -139,7 +143,6 @@ Then any argument will be passed as-is to the `sdk:query` method.
139
143
  * [`kourou es:snapshot:create REPOSITORY NAME`](#kourou-essnapshotcreate-repository-name)
140
144
  * [`kourou es:snapshot:create-repository REPOSITORY LOCATION`](#kourou-essnapshotcreate-repository-repository-location)
141
145
  * [`kourou es:snapshot:list REPOSITORY`](#kourou-essnapshotlist-repository)
142
- * [`kourou es:snapshot:restore REPOSITORY NAME`](#kourou-essnapshotrestore-repository-name)
143
146
  * [`kourou file:decrypt FILE`](#kourou-filedecrypt-file)
144
147
  * [`kourou file:encrypt FILE`](#kourou-fileencrypt-file)
145
148
  * [`kourou file:test FILE`](#kourou-filetest-file)
@@ -312,6 +315,29 @@ OPTIONS
312
315
 
313
316
  _See code: [src/commands/app/start-services.ts](src/commands/app/start-services.ts)_
314
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
+
315
341
  ## `kourou collection:create INDEX COLLECTION [BODY]`
316
342
 
317
343
  Creates a collection
@@ -352,31 +378,58 @@ ARGUMENTS
352
378
  COLLECTION Collection name
353
379
 
354
380
  OPTIONS
355
- --api-key=api-key Kuzzle user api-key
356
- --as=as Impersonate a user
357
- --batch-size=batch-size [default: 2000] Maximum batch size (see limits.documentsFetchCount config)
358
- --editor Open an editor (EDITOR env variable) to edit the query before sending
381
+ --api-key=api-key
382
+ Kuzzle user api-key
359
383
 
360
- --format=format [default: JSONL] "jsonl or kuzzle - kuzzle will export in Kuzzle format usable for internal
361
- fixtures and jsonl allows to import that data back with kourou
384
+ --as=as
385
+ Impersonate a user
362
386
 
363
- --help show CLI help
387
+ --batch-size=batch-size
388
+ [default: 2000] Maximum batch size (see limits.documentsFetchCount config)
364
389
 
365
- --host=host [default: localhost] Kuzzle server host
390
+ --editor
391
+ Open an editor (EDITOR env variable) to edit the query before sending
366
392
 
367
- --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.
368
395
 
369
- --path=path Dump root directory
396
+ Example:
397
+ --fields oneField,anotherField,yetAnotherOne.nested.moarNested
370
398
 
371
- --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.
372
401
 
373
- --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).
374
406
 
375
- --query=query [default: {}] Only dump documents matching the query (JS or JSON format)
407
+ --help
408
+ show CLI help
376
409
 
377
- --ssl Use SSL to connect to Kuzzle
410
+ --host=host
411
+ [default: localhost] Kuzzle server host
378
412
 
379
- --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)
380
433
 
381
434
  EXAMPLES
382
435
  kourou collection:export nyc-open-data yellow-taxi
@@ -610,25 +663,6 @@ OPTIONS
610
663
 
611
664
  _See code: [src/commands/es/snapshot/list.ts](src/commands/es/snapshot/list.ts)_
612
665
 
613
- ## `kourou es:snapshot:restore REPOSITORY NAME`
614
-
615
- Restore a snapshot into an ES instance
616
-
617
- ```
618
- USAGE
619
- $ kourou es:snapshot:restore REPOSITORY NAME
620
-
621
- ARGUMENTS
622
- REPOSITORY ES repository name
623
- NAME ES snapshot name
624
-
625
- OPTIONS
626
- -n, --node=node [default: http://localhost:9200] Elasticsearch server URL
627
- --help show CLI help
628
- ```
629
-
630
- _See code: [src/commands/es/snapshot/restore.ts](src/commands/es/snapshot/restore.ts)_
631
-
632
666
  ## `kourou file:decrypt FILE`
633
667
 
634
668
  Decrypts an encrypted file.
@@ -770,9 +804,15 @@ OPTIONS
770
804
 
771
805
  --protocol=protocol [default: ws] Kuzzle protocol (http or websocket)
772
806
 
807
+ --query=query [default: {}] Only dump documents in collections matching the query (JS or JSON format)
808
+
773
809
  --ssl Use SSL to connect to Kuzzle
774
810
 
775
811
  --username=username [default: anonymous] Kuzzle username (local strategy)
812
+
813
+ EXAMPLES
814
+ kourou index:export nyc-open-data
815
+ kourou index:export nyc-open-data --query '{"range":{"_kuzzle_info.createdAt":{"gt":1632935638866}}}'
776
816
  ```
777
817
 
778
818
  _See code: [src/commands/index/export.ts](src/commands/index/export.ts)_
@@ -1078,29 +1118,29 @@ DESCRIPTION
1078
1118
 
1079
1119
  Code Execution
1080
1120
 
1081
- Provided code will be executed in an async method.
1082
- You can access a connected and authenticated SDK with the "sdk" variable.
1083
- Templated variable passed as the command arguments are also accessible within the same name.
1084
- Returned value will be printed on the standard output (e.g. 'return await sdk.server.now();').
1085
- 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");').
1086
1126
 
1087
1127
  Provide code
1088
1128
 
1089
- code can be passed as an argument
1090
- 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
1091
1131
 
1092
- Examples:
1093
- - kourou sdk:execute 'return await sdk.server.now()'
1094
- - kourou sdk:execute 'return await sdk.index.exists(index)' --var 'index="iot-data"'
1095
- - kourou sdk:execute < snippet.js
1096
- - 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
1097
1137
 
1098
1138
  Other
1099
1139
 
1100
- use the --editor flag to modify the code before executing it
1140
+ use the --editor flag to modify the code before executing it
1101
1141
 
1102
- Examples:
1103
- - kourou sdk:execute 'return await sdk.server.now()' --editor
1142
+ Examples:
1143
+ - kourou sdk:execute 'return await sdk.server.now()' --editor
1104
1144
  ```
1105
1145
 
1106
1146
  _See code: [src/commands/sdk/execute.ts](src/commands/sdk/execute.ts)_
@@ -1151,55 +1191,55 @@ DESCRIPTION
1151
1191
 
1152
1192
  Query arguments
1153
1193
 
1154
- Arguments can be passed and repeated using the --arg or -a flag.
1155
- Index and collection names can be passed with --index (-i) and --collection (-c) flags
1156
- 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.
1157
1197
 
1158
- Examples:
1159
- - 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
1160
1200
 
1161
1201
  Query body
1162
1202
 
1163
- Body can be passed with the --body flag with either a JSON or JS string.
1164
- 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
1165
1205
 
1166
- Examples:
1167
- - kourou sdk:query document:create -i iot -c sensors --body '{creation: Date.now())}'
1168
- - kourou sdk:query admin:loadMappings < mappings.json
1169
- - 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
1170
1210
 
1171
1211
  Other
1172
1212
 
1173
- Use the --editor flag to modify the query before sending it to Kuzzle
1174
- 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
1175
1215
 
1176
- Examples:
1177
- - kourou sdk:query document:create -i iot -c sensors --editor
1178
- - 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'
1179
1219
 
1180
1220
  Default fallback to API action
1181
1221
 
1182
- It's possible to use the "sdk:query" command by only specifying the corresponding controller
1183
- 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.
1184
1224
 
1185
- Kourou will try to infer the first arguments to one the following pattern:
1186
- - <command> <index>
1187
- - <command> <body>
1188
- - <command> <index> <collection>
1189
- - <command> <index> <collection> <id>
1190
- - <command> <index> <collection> <body>
1191
- - <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>
1192
1232
 
1193
- If a flag is given (-i, -c, --body or --id), then the flag value has priority over
1194
- argument infering.
1233
+ If a flag is given (-i, -c, --body or --id), then the flag value has priority over
1234
+ argument infering.
1195
1235
 
1196
- Examples:
1197
- - kourou collection:list iot
1198
- - kourou security:createUser '{ "content": { "profileIds": ["default"] } }' --id yagmur
1199
- - kourou collection:delete iot sensors
1200
- - kourou document:createOrReplace iot sensors sigfox-1 '{}'
1201
- - kourou bulk:import iot sensors '{ bulkData: [...] }'
1202
- - 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
1203
1243
  ```
1204
1244
 
1205
1245
  _See code: [src/commands/sdk/query.ts](src/commands/sdk/query.ts)_
@@ -1234,24 +1274,24 @@ DESCRIPTION
1234
1274
  The users will be exported WITHOUT their credentials since Kuzzzle can't access them.
1235
1275
 
1236
1276
  You can either:
1237
- - Manually re-create credentials for your users
1238
- - 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
1239
1279
  https://github.com/kuzzleio/kuzzle-plugin-auth-passport-local/#optional-properties)
1240
- - 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
1241
1281
 
1242
1282
  Auto-generation of credentials
1243
1283
 
1244
- With the "--generate-credentials" flag, Kourou will add credentials for the "local" strategy.
1245
- By default, the username will be the user ID.
1246
- Use the "generated-username" flag to use an other property than the user ID for the generated username
1247
- 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
1248
1288
 
1249
1289
  Examples:
1250
1290
 
1251
- - kourou user:export
1252
- - kourou user:export --exclude '.*admin.*' --exclude 'supervisor.*'
1253
- - kourou user:export --generate-credentials
1254
- - 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
1255
1295
  ```
1256
1296
 
1257
1297
  _See code: [src/commands/user/export.ts](src/commands/user/export.ts)_
@@ -1413,11 +1453,11 @@ DESCRIPTION
1413
1453
 
1414
1454
  Example:
1415
1455
  {
1416
- aws: {
1417
- s3: {
1418
- keyId: 'b61e267676660c314b006b06'
1419
- }
1420
- }
1456
+ aws: {
1457
+ s3: {
1458
+ keyId: 'b61e267676660c314b006b06'
1459
+ }
1460
+ }
1421
1461
  }
1422
1462
 
1423
1463
  Encrypted secrets are meant to be loaded inside an application with Kuzzle Vault.
@@ -1450,8 +1490,8 @@ DESCRIPTION
1450
1490
  Prints an encrypted secrets file content.
1451
1491
 
1452
1492
  This method can display either:
1453
- - the entire content of the secrets file
1454
- - a single key value
1493
+ - the entire content of the secrets file
1494
+ - a single key value
1455
1495
 
1456
1496
  See https://github.com/kuzzleio/kuzzle-vault/ for more information.
1457
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
  }
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- const path_1 = tslib_1.__importDefault(require("path"));
5
- const fs_1 = tslib_1.__importDefault(require("fs"));
4
+ const path_1 = (0, tslib_1.__importDefault)(require("path"));
5
+ const fs_1 = (0, tslib_1.__importDefault)(require("fs"));
6
6
  const command_1 = require("@oclif/command");
7
- const lodash_1 = tslib_1.__importDefault(require("lodash"));
8
- const chalk_1 = tslib_1.__importDefault(require("chalk"));
9
- const listr_1 = tslib_1.__importDefault(require("listr"));
7
+ const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
8
+ const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
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,13 +16,35 @@ 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
  {
23
46
  title: `Creating directory: ${chalk_1.default.gray(this.args.name + path_1.default.sep)}`,
24
- task: () => execute_1.execute('mkdir', this.args.name)
47
+ task: () => (0, execute_1.execute)('mkdir', this.args.name)
25
48
  },
26
49
  {
27
50
  title: 'Creating and rendering application files',
@@ -29,7 +52,7 @@ class AppScaffold extends common_1.Kommand {
29
52
  },
30
53
  {
31
54
  title: 'Installing dependencies (this can take some time)',
32
- task: () => execute_1.execute('npm', 'run', 'install:docker', { cwd: this.args.name })
55
+ task: () => (0, execute_1.execute)('npm', 'run', 'install:docker', { cwd: this.args.name })
33
56
  },
34
57
  ]);
35
58
  await tasks.run();
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const fs_1 = require("fs");
5
5
  const command_1 = require("@oclif/command");
6
- const chalk_1 = tslib_1.__importDefault(require("chalk"));
7
- const listr_1 = tslib_1.__importDefault(require("listr"));
8
- const node_emoji_1 = tslib_1.__importDefault(require("node-emoji"));
6
+ const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
7
+ const listr_1 = (0, tslib_1.__importDefault)(require("listr"));
8
+ const node_emoji_1 = (0, tslib_1.__importDefault)(require("node-emoji"));
9
9
  const common_1 = require("../../common");
10
10
  const execute_1 = require("../../support/execute");
11
11
  const MIN_DOCO_VERSION = '1.12.0';
@@ -38,11 +38,11 @@ class AppStartServices extends common_1.Kommand {
38
38
  throw new Error(`${node_emoji_1.default.get('shrug')} Your system doesn't satisfy all the prerequisites. Cannot run Kuzzle services.`);
39
39
  }
40
40
  this.log(chalk_1.default.grey(`\nWriting docker-compose file to ${docoFilename}...\n`));
41
- fs_1.writeFileSync(docoFilename, kuzzleServicesFile);
41
+ (0, fs_1.writeFileSync)(docoFilename, kuzzleServicesFile);
42
42
  // clean up
43
- await execute_1.execute('docker-compose', '-f', docoFilename, 'down');
43
+ await (0, execute_1.execute)('docker-compose', '-f', docoFilename, 'down');
44
44
  try {
45
- await execute_1.execute('docker-compose', '-f', docoFilename, 'up', '-d');
45
+ await (0, execute_1.execute)('docker-compose', '-f', docoFilename, 'up', '-d');
46
46
  this.logOk('Elasticsearch and Redis are booting in the background right now.');
47
47
  this.log(chalk_1.default.grey('\nTo watch the logs, run'));
48
48
  this.log(chalk_1.default.grey(` docker-compose -f ${docoFilename} logs -f\n`));
@@ -62,7 +62,7 @@ class AppStartServices extends common_1.Kommand {
62
62
  title: `docker-compose exists and the version is at least ${MIN_DOCO_VERSION}`,
63
63
  task: async () => {
64
64
  try {
65
- const docov = await execute_1.execute('docker-compose', '-v');
65
+ const docov = await (0, execute_1.execute)('docker-compose', '-v');
66
66
  const matches = docov.stdout.match(/[^0-9.]*([0-9.]*).*/);
67
67
  if (matches === null) {
68
68
  throw new Error('Unable to read docker-compose verson. This is weird.');
@@ -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;
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const command_1 = require("@oclif/command");
5
- const fs_1 = tslib_1.__importDefault(require("fs"));
6
- const path_1 = tslib_1.__importDefault(require("path"));
5
+ const fs_1 = (0, tslib_1.__importDefault)(require("fs"));
6
+ const path_1 = (0, tslib_1.__importDefault)(require("path"));
7
7
  const common_1 = require("../../common");
8
8
  const kuzzle_1 = require("../../support/kuzzle");
9
9
  const dump_collection_1 = require("../../support/dump-collection");
@@ -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
- await dump_collection_1.dumpCollectionMappings(this.sdk, this.args.index, this.args.collection, exportPath, this.flags.format);
24
- await dump_collection_1.dumpCollectionData(this.sdk, this.args.index, this.args.collection, Number(this.flags['batch-size']), exportPath, query, this.flags.format);
29
+ await (0, dump_collection_1.dumpCollectionMappings)(this.sdk, this.args.index, this.args.collection, exportPath, 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',
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- const path_1 = tslib_1.__importDefault(require("path"));
5
- const fs_1 = tslib_1.__importDefault(require("fs"));
4
+ const path_1 = (0, tslib_1.__importDefault)(require("path"));
5
+ const fs_1 = (0, tslib_1.__importDefault)(require("fs"));
6
6
  const command_1 = require("@oclif/command");
7
7
  const common_1 = require("../../common");
8
8
  const kuzzle_1 = require("../../support/kuzzle");
@@ -13,9 +13,9 @@ class CollectionImport extends common_1.Kommand {
13
13
  if (!this.flags['no-mappings']) {
14
14
  const mappingsPath = path_1.default.join(this.args.path, 'mappings.json');
15
15
  const dump = JSON.parse(fs_1.default.readFileSync(mappingsPath, 'utf8'));
16
- await restore_collection_1.restoreCollectionMappings(this.sdk, dump, this.flags.index, this.flags.collection);
16
+ await (0, restore_collection_1.restoreCollectionMappings)(this.sdk, dump, this.flags.index, this.flags.collection);
17
17
  }
18
- const { index, collection, total } = await restore_collection_1.restoreCollectionData(this.sdk, this.log.bind(this), Number(this.flags['batch-size']), path_1.default.join(this.args.path, 'documents.jsonl'), this.flags.index, this.flags.collection);
18
+ const { index, collection, total } = await (0, restore_collection_1.restoreCollectionData)(this.sdk, this.log.bind(this), Number(this.flags['batch-size']), path_1.default.join(this.args.path, 'documents.jsonl'), this.flags.index, this.flags.collection);
19
19
  this.logOk(`Successfully imported ${total} documents from "${this.args.path}" in "${index}:${collection}"`);
20
20
  }
21
21
  }
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ConfigKeyDiff = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const command_1 = require("@oclif/command");
6
- const lodash_1 = tslib_1.__importDefault(require("lodash"));
7
- const fs_1 = tslib_1.__importDefault(require("fs"));
8
- const strip_json_comments_1 = tslib_1.__importDefault(require("strip-json-comments"));
6
+ const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
7
+ const fs_1 = (0, tslib_1.__importDefault)(require("fs"));
8
+ const strip_json_comments_1 = (0, tslib_1.__importDefault)(require("strip-json-comments"));
9
9
  const common_1 = require("../../common");
10
10
  class ConfigKeyDiff extends common_1.Kommand {
11
11
  async runSafe() {
@@ -15,8 +15,8 @@ class ConfigKeyDiff extends common_1.Kommand {
15
15
  if (!fs_1.default.existsSync(this.args.second)) {
16
16
  throw new Error(`File "${this.args.second}" does not exists`);
17
17
  }
18
- const first = JSON.parse(strip_json_comments_1.default(fs_1.default.readFileSync(this.args.first, 'utf8')));
19
- const second = JSON.parse(strip_json_comments_1.default(fs_1.default.readFileSync(this.args.second, 'utf8')));
18
+ const first = JSON.parse((0, strip_json_comments_1.default)(fs_1.default.readFileSync(this.args.first, 'utf8')));
19
+ const second = JSON.parse((0, strip_json_comments_1.default)(fs_1.default.readFileSync(this.args.second, 'utf8')));
20
20
  const changes = this._keyChanges(first, second);
21
21
  if (lodash_1.default.isEmpty(changes)) {
22
22
  this.logOk('No differences between keys in the provided configurations');
@@ -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
  }