kourou 0.24.2 → 0.25.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 (132) hide show
  1. package/README.md +98 -12
  2. package/lib/commands/api-key/check.d.ts +3 -3
  3. package/lib/commands/api-key/check.js +5 -7
  4. package/lib/commands/api-key/create.d.ts +3 -3
  5. package/lib/commands/api-key/create.js +8 -10
  6. package/lib/commands/api-key/delete.d.ts +3 -3
  7. package/lib/commands/api-key/delete.js +4 -6
  8. package/lib/commands/api-key/search.d.ts +3 -3
  9. package/lib/commands/api-key/search.js +5 -7
  10. package/lib/commands/app/debug-proxy.d.ts +3 -3
  11. package/lib/commands/app/debug-proxy.js +57 -55
  12. package/lib/commands/app/doctor.d.ts +24 -0
  13. package/lib/commands/app/doctor.js +201 -0
  14. package/lib/commands/app/scaffold.d.ts +2 -2
  15. package/lib/commands/app/scaffold.js +20 -15
  16. package/lib/commands/app/start-services.d.ts +1 -1
  17. package/lib/commands/app/start-services.js +26 -26
  18. package/lib/commands/collection/create.d.ts +3 -3
  19. package/lib/commands/collection/create.js +9 -6
  20. package/lib/commands/collection/export.d.ts +5 -5
  21. package/lib/commands/collection/export.js +25 -26
  22. package/lib/commands/collection/import.d.ts +5 -5
  23. package/lib/commands/collection/import.js +17 -17
  24. package/lib/commands/collection/migrate.d.ts +27 -0
  25. package/lib/commands/collection/migrate.js +43 -0
  26. package/lib/commands/config/diff.d.ts +1 -1
  27. package/lib/commands/config/diff.js +27 -21
  28. package/lib/commands/document/search.d.ts +3 -3
  29. package/lib/commands/document/search.js +20 -20
  30. package/lib/commands/es/aliases/cat.d.ts +12 -0
  31. package/lib/commands/es/aliases/cat.js +36 -0
  32. package/lib/commands/es/indices/cat.d.ts +2 -2
  33. package/lib/commands/es/indices/cat.js +8 -8
  34. package/lib/commands/es/indices/get.d.ts +2 -2
  35. package/lib/commands/es/indices/get.js +7 -7
  36. package/lib/commands/es/indices/insert.d.ts +2 -2
  37. package/lib/commands/es/indices/insert.js +9 -9
  38. package/lib/commands/es/migrate.d.ts +10 -8
  39. package/lib/commands/es/migrate.js +86 -82
  40. package/lib/commands/es/snapshot/create-repository.d.ts +2 -2
  41. package/lib/commands/es/snapshot/create-repository.js +16 -12
  42. package/lib/commands/es/snapshot/create.d.ts +2 -2
  43. package/lib/commands/es/snapshot/create.js +7 -7
  44. package/lib/commands/es/snapshot/list.d.ts +2 -2
  45. package/lib/commands/es/snapshot/list.js +12 -8
  46. package/lib/commands/file/decrypt.d.ts +4 -4
  47. package/lib/commands/file/decrypt.js +21 -21
  48. package/lib/commands/file/encrypt.d.ts +4 -4
  49. package/lib/commands/file/encrypt.js +20 -22
  50. package/lib/commands/file/test.d.ts +3 -3
  51. package/lib/commands/file/test.js +13 -13
  52. package/lib/commands/import.d.ts +5 -5
  53. package/lib/commands/import.js +39 -28
  54. package/lib/commands/index/export.d.ts +5 -4
  55. package/lib/commands/index/export.js +21 -19
  56. package/lib/commands/index/import.d.ts +5 -5
  57. package/lib/commands/index/import.js +21 -19
  58. package/lib/commands/instance/kill.d.ts +2 -2
  59. package/lib/commands/instance/kill.js +34 -34
  60. package/lib/commands/instance/list.d.ts +1 -1
  61. package/lib/commands/instance/list.js +33 -30
  62. package/lib/commands/instance/logs.d.ts +2 -2
  63. package/lib/commands/instance/logs.js +26 -22
  64. package/lib/commands/instance/spawn.d.ts +2 -2
  65. package/lib/commands/instance/spawn.js +46 -40
  66. package/lib/commands/paas/deploy.d.ts +2 -2
  67. package/lib/commands/paas/deploy.js +33 -21
  68. package/lib/commands/paas/init.d.ts +1 -1
  69. package/lib/commands/paas/init.js +10 -6
  70. package/lib/commands/paas/login.d.ts +3 -3
  71. package/lib/commands/paas/login.js +30 -19
  72. package/lib/commands/paas/logs.d.ts +27 -0
  73. package/lib/commands/paas/logs.js +137 -18
  74. package/lib/commands/profile/export.d.ts +3 -3
  75. package/lib/commands/profile/export.js +12 -12
  76. package/lib/commands/profile/import.d.ts +3 -3
  77. package/lib/commands/profile/import.js +6 -8
  78. package/lib/commands/realtime/subscribe.d.ts +3 -3
  79. package/lib/commands/realtime/subscribe.js +25 -25
  80. package/lib/commands/redis/list-keys.d.ts +3 -3
  81. package/lib/commands/redis/list-keys.js +15 -11
  82. package/lib/commands/role/export.d.ts +3 -3
  83. package/lib/commands/role/export.js +11 -11
  84. package/lib/commands/role/import.d.ts +4 -4
  85. package/lib/commands/role/import.js +10 -12
  86. package/lib/commands/sdk/execute.d.ts +5 -5
  87. package/lib/commands/sdk/execute.js +23 -19
  88. package/lib/commands/sdk/query.d.ts +5 -4
  89. package/lib/commands/sdk/query.js +30 -24
  90. package/lib/commands/user/export-mappings.d.ts +3 -3
  91. package/lib/commands/user/export-mappings.js +11 -11
  92. package/lib/commands/user/export.d.ts +6 -6
  93. package/lib/commands/user/export.js +34 -33
  94. package/lib/commands/user/import-mappings.d.ts +3 -3
  95. package/lib/commands/user/import-mappings.js +7 -7
  96. package/lib/commands/user/import.d.ts +3 -3
  97. package/lib/commands/user/import.js +6 -8
  98. package/lib/commands/vault/add.d.ts +3 -3
  99. package/lib/commands/vault/add.js +27 -19
  100. package/lib/commands/vault/decrypt.d.ts +4 -4
  101. package/lib/commands/vault/decrypt.js +24 -20
  102. package/lib/commands/vault/encrypt.d.ts +4 -4
  103. package/lib/commands/vault/encrypt.js +24 -20
  104. package/lib/commands/vault/show.d.ts +3 -3
  105. package/lib/commands/vault/show.js +24 -20
  106. package/lib/commands/vault/test.d.ts +3 -3
  107. package/lib/commands/vault/test.js +16 -12
  108. package/lib/common.d.ts +3 -3
  109. package/lib/common.js +28 -29
  110. package/lib/hooks/command_not_found/api-action.d.ts +2 -2
  111. package/lib/hooks/command_not_found/api-action.js +20 -22
  112. package/lib/index.d.ts +1 -1
  113. package/lib/support/PaasKommand.d.ts +2 -2
  114. package/lib/support/PaasKommand.js +9 -9
  115. package/lib/support/dump-collection.js +50 -41
  116. package/lib/support/editor.js +12 -10
  117. package/lib/support/execute.d.ts +6 -1
  118. package/lib/support/execute.js +9 -8
  119. package/lib/support/kuzzle.d.ts +12 -4
  120. package/lib/support/kuzzle.js +65 -31
  121. package/lib/support/migrate/providers/elasticsearch.d.ts +16 -0
  122. package/lib/support/migrate/providers/elasticsearch.js +74 -0
  123. package/lib/support/migrate/providers/file.d.ts +15 -0
  124. package/lib/support/migrate/providers/file.js +74 -0
  125. package/lib/support/migrate/providers/index.d.ts +12 -0
  126. package/lib/support/migrate/providers/index.js +16 -0
  127. package/lib/support/migrate/types.d.ts +8 -0
  128. package/lib/support/migrate/types.js +2 -0
  129. package/lib/support/restore-collection.d.ts +2 -1
  130. package/lib/support/restore-collection.js +37 -26
  131. package/lib/support/restore-securities.js +22 -19
  132. package/package.json +16 -15
@@ -0,0 +1,24 @@
1
+ import { flags } from "@oclif/command";
2
+ import { Kommand } from "../../common";
3
+ export default class AppDoctor extends Kommand {
4
+ static description: string;
5
+ static flags: {
6
+ host: flags.IOptionFlag<string>;
7
+ port: flags.IOptionFlag<string>;
8
+ ssl: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
9
+ username: flags.IOptionFlag<string>;
10
+ password: flags.IOptionFlag<string | undefined>;
11
+ protocol: flags.IOptionFlag<string>;
12
+ as: flags.IOptionFlag<string | undefined>;
13
+ "api-key": flags.IOptionFlag<string | undefined>;
14
+ help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
15
+ elasticsearch: flags.IOptionFlag<string>;
16
+ };
17
+ static args: never[];
18
+ static readStdin: boolean;
19
+ ELK_MAX_VERSION: number;
20
+ NODEJS_MAX_VERSION: number;
21
+ COMMANDS_PLATFORMS: Record<string, string>;
22
+ LIBRARIES_PLATFORMS: Record<string, string[]>;
23
+ runSafe(): Promise<void>;
24
+ }
@@ -0,0 +1,201 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const command_1 = require("@oclif/command");
5
+ const common_1 = require("../../common");
6
+ const kuzzle_1 = require("../../support/kuzzle");
7
+ const elasticsearch_1 = require("@elastic/elasticsearch");
8
+ const execute_1 = require("../../support/execute");
9
+ const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
10
+ class AppDoctor extends common_1.Kommand {
11
+ constructor() {
12
+ super(...arguments);
13
+ this.ELK_MAX_VERSION = 7.17;
14
+ this.NODEJS_MAX_VERSION = 16;
15
+ // because ocliff we can't use 'as const' inference for object keys and values
16
+ this.COMMANDS_PLATFORMS = {
17
+ linux: "which",
18
+ };
19
+ this.LIBRARIES_PLATFORMS = {
20
+ linux: [
21
+ "curl",
22
+ "gdb",
23
+ "git",
24
+ "gnupg",
25
+ "make",
26
+ "python3",
27
+ "libfontconfig",
28
+ "libzmq3-dev",
29
+ "wget",
30
+ "procps",
31
+ "libunwind-dev",
32
+ ],
33
+ };
34
+ }
35
+ async runSafe() {
36
+ const suggestions = [];
37
+ const [nodeVersion, adminExists, anonymous] = await Promise.all([
38
+ this.sdk.query({ controller: "debug", action: "nodeVersion", }),
39
+ this.sdk.server.adminExists({}),
40
+ this.sdk.security.getRole("anonymous")
41
+ ]);
42
+ this.log(`----------------- DoKtor begin his job ! -----------------`);
43
+ this.log(`General checks`);
44
+ const anonymousNotRestricted = lodash_1.default.isEqual(anonymous.controllers, {
45
+ "*": { actions: { "*": true } },
46
+ });
47
+ if (adminExists) {
48
+ this.logOk(`An admin user exists`);
49
+ }
50
+ else {
51
+ this.logKo("No admin user exists");
52
+ suggestions.push(`Create an admin user ${anonymousNotRestricted ? "and restrict anonymous role " : ""}with
53
+ kourou security:createFirstAdmin '{
54
+ credentials: {
55
+ local: {
56
+ username: "admin",
57
+ password: "password"
58
+ }
59
+ }
60
+ }' ${anonymousNotRestricted ? "-a reset=true" : ""}`);
61
+ }
62
+ if (anonymousNotRestricted && adminExists) {
63
+ this.logKo(`Anonymous role does not restrict access to any controller`);
64
+ suggestions.push(`Restrict anonymous role controllers with
65
+ kourou security:updateRole '{
66
+ "controllers": {
67
+ "auth": {
68
+ "actions": {
69
+ "checkToken": true,
70
+ "getCurrentUser": true,
71
+ "getMyRights": true,
72
+ "login": true
73
+ }
74
+ },
75
+ "server": {
76
+ "actions": {
77
+ "publicApi": true,
78
+ "openapi": true
79
+ }
80
+ }
81
+ }
82
+ }' --id=anonymous
83
+ // or make your own restrictions (see: https://docs.kuzzle.io/core/2/guides/main-concepts/permissions/#roles)`);
84
+ }
85
+ const config = await this.sdk.server.getConfig({});
86
+ if (config) {
87
+ if (config.cluster.enabled) {
88
+ this.logOk(`Cluster is enabled`);
89
+ }
90
+ else {
91
+ this.logKo("Cluster is disabled");
92
+ }
93
+ }
94
+ else {
95
+ this.logInfo("No config found for the server");
96
+ }
97
+ // Redis
98
+ if ("PONG" === (await this.sdk.ms.ping())) {
99
+ this.logOk("Redis Memory Storage is running");
100
+ }
101
+ else {
102
+ this.logKo("=> Redis Memory Storage is not running");
103
+ suggestions.push("Check Redis instance dedicated to memory storage");
104
+ }
105
+ this.logOk(`Kuzzle Version: ${config.version}`);
106
+ this.logOk(`Kuzzle NodeJS version: ${nodeVersion.result}`);
107
+ if (nodeVersion.result > this.NODEJS_MAX_VERSION) {
108
+ this.logKo(`=> Kuzzle NodeJS version is not compatible with Kuzzle (max version is ${this.NODEJS_MAX_VERSION})`);
109
+ }
110
+ this.logOk(`NodeJS Building version: ${process.version}`);
111
+ if (nodeVersion.result !== process.version) {
112
+ this.logKo("=> Kuzzle node version is different from the build node version");
113
+ suggestions.push(`Match Kuzzle NodeJS version ${nodeVersion.result} with the build NodeJS version ${process.version}`);
114
+ }
115
+ let elkVersion;
116
+ try {
117
+ const serverInfo = await this.sdk.server.info({});
118
+ elkVersion = parseFloat(serverInfo.serverInfo.services.publicStorage.version);
119
+ if (elkVersion < this.ELK_MAX_VERSION) {
120
+ this.logOk(`ElasticSearch Version: ${elkVersion} which is compatible with Kuzzle (max version is ${this.ELK_MAX_VERSION})`);
121
+ }
122
+ else {
123
+ this.logKo(`=> ElasticSearch version ${elkVersion} is not compatible with Kuzzle (max version is ${this.ELK_MAX_VERSION})`);
124
+ suggestions.push(`Downgrade ElasticSearch to a compatible version (max: ${this.ELK_MAX_VERSION})`);
125
+ }
126
+ const client = new elasticsearch_1.Client({ node: this.flags.elasticsearch });
127
+ const info = await client.info();
128
+ this.log(`ElasticSearch checks`);
129
+ this.logOk(`Elasticsearch Cluster name: ${info.body.cluster_name}`);
130
+ this.logOk(`ElasticSearch Status: ${info.meta.connection.status}`);
131
+ const nodes = await client.cat.nodes({ format: "json" });
132
+ this.log(`ElasticSearch nodes`);
133
+ console.table(nodes.body.map((i) => ({ node_name: i.name, ip: i.ip })));
134
+ const indices = await client.cat.indices({ format: "json" });
135
+ this.log(`ElasticSearch indices`);
136
+ console.table(indices.body.map((i) => ({
137
+ indice_name: i.index,
138
+ health: i.health,
139
+ status: i.status,
140
+ count_docs: i["docs.count"],
141
+ })));
142
+ }
143
+ catch (e) {
144
+ this.logKo("=> Cannot show more information about ElasticSearch (cluster name, nodes, indices) because it's not accessible");
145
+ }
146
+ let librairies = [];
147
+ let command = "";
148
+ const platform = process.platform.toLowerCase();
149
+ if (platform in this.LIBRARIES_PLATFORMS &&
150
+ platform in this.COMMANDS_PLATFORMS) {
151
+ librairies = this.LIBRARIES_PLATFORMS[platform];
152
+ command = this.COMMANDS_PLATFORMS[platform];
153
+ }
154
+ this.log("Kuzzle related libraries installed");
155
+ const notInstalled = [];
156
+ for (const lib of librairies) {
157
+ try {
158
+ const result = await (0, execute_1.execute)(command, lib);
159
+ if (result.stdout) {
160
+ this.logOk(` ${lib} is installed`);
161
+ }
162
+ }
163
+ catch (e) {
164
+ this.logKo(` => ${lib} is not installed`);
165
+ notInstalled.push(lib);
166
+ }
167
+ }
168
+ if (notInstalled.length) {
169
+ suggestions.push(`Install missing libraries: sudo apt-get install ${notInstalled.join(" ")}`);
170
+ }
171
+ this.log("Docker checks");
172
+ try {
173
+ const docov = await (0, execute_1.execute)("docker-compose", "-v");
174
+ const matches = docov.stdout.match(/[^0-9.]*([0-9.]*).*/);
175
+ if (matches === null || matches.length === 0) {
176
+ this.logKo("Docker Version cannot be found");
177
+ }
178
+ else {
179
+ this.logOk(`Docker Compose Version: ${matches[1]}`);
180
+ }
181
+ }
182
+ catch (error) {
183
+ this.logKo("Docker Compose cannot be found");
184
+ suggestions.push("Install Docker Compose with 'npm run install:docker'");
185
+ }
186
+ this.log(`----------------- DoKtor finish his job ! -----------------`);
187
+ this.log(`He suggest you to check the following points:`);
188
+ for (const suggestion of suggestions) {
189
+ this.logInfo(" => " + suggestion);
190
+ }
191
+ this.log(`-------------------------------------------------------------`);
192
+ }
193
+ }
194
+ exports.default = AppDoctor;
195
+ AppDoctor.description = "Analyze a Kuzzle application";
196
+ AppDoctor.flags = Object.assign({ help: command_1.flags.help(), elasticsearch: command_1.flags.string({
197
+ description: "Elasticsearch server URL",
198
+ default: "http://localhost:9200",
199
+ }) }, kuzzle_1.kuzzleFlags);
200
+ AppDoctor.args = [];
201
+ AppDoctor.readStdin = true;
@@ -1,5 +1,5 @@
1
- import { flags } from '@oclif/command';
2
- import { Kommand } from '../../common';
1
+ import { flags } from "@oclif/command";
2
+ import { Kommand } from "../../common";
3
3
  export default class AppScaffold extends Kommand {
4
4
  static initSdk: boolean;
5
5
  static description: 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 chalk_1 = tslib_1.__importDefault(require("chalk"));
6
- const listr_1 = tslib_1.__importDefault(require("listr"));
5
+ const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
6
+ const listr_1 = (0, tslib_1.__importDefault)(require("listr"));
7
7
  const common_1 = require("../../common");
8
8
  const execute_1 = require("../../support/execute");
9
9
  class AppScaffold extends common_1.Kommand {
@@ -12,32 +12,37 @@ class AppScaffold extends common_1.Kommand {
12
12
  const flavor = this.flags.flavor;
13
13
  const tasks = new listr_1.default([
14
14
  {
15
- title: 'Creating and rendering application files',
16
- task: async () => this.cloneTemplate(flavor, destination)
15
+ title: "Creating and rendering application files",
16
+ task: async () => this.cloneTemplate(flavor, destination),
17
17
  },
18
18
  ]);
19
19
  await tasks.run();
20
- this.log('');
20
+ this.log("");
21
21
  this.logOk(`Scaffolding complete! Use ${chalk_1.default.grey(`cd ${destination} && npm run docker npm install`)} install dependencies and then ${chalk_1.default.grey(`npm run docker:dev`)} to run your application!`);
22
22
  }
23
23
  async cloneTemplate(flavor, destination) {
24
- const templatesDir = '/tmp/project-templates';
25
- await (0, execute_1.execute)('rm', '-rf', templatesDir);
26
- await (0, execute_1.execute)('git', 'clone', '--depth=1', 'https://github.com/kuzzleio/project-templates', '--branch', flavor, '--single-branch', templatesDir);
27
- await (0, execute_1.execute)('cp', '-r', `${templatesDir}/${flavor}`, `${destination}/`);
28
- await (0, execute_1.execute)('rm', '-rf', templatesDir);
24
+ const templatesDir = "/tmp/project-templates";
25
+ await (0, execute_1.execute)("rm", "-rf", templatesDir);
26
+ await (0, execute_1.execute)("git", "clone", "--depth=1", "https://github.com/kuzzleio/project-templates", "--branch", flavor, "--single-branch", templatesDir);
27
+ await (0, execute_1.execute)("cp", "-r", `${templatesDir}/${flavor}`, `${destination}/`);
28
+ await (0, execute_1.execute)("rm", "-rf", templatesDir);
29
29
  }
30
30
  }
31
31
  exports.default = AppScaffold;
32
32
  AppScaffold.initSdk = false;
33
- AppScaffold.description = 'Scaffolds a new Kuzzle application';
33
+ AppScaffold.description = "Scaffolds a new Kuzzle application";
34
34
  AppScaffold.flags = {
35
35
  help: command_1.flags.help(),
36
36
  flavor: command_1.flags.string({
37
- default: 'generic',
38
- description: 'Template flavor ("generic", "iot-platform")'
39
- })
37
+ default: "generic",
38
+ description: `Template flavor ("generic", "iot-platform", "iot-console", "iot-platform").
39
+ Those can be found here: https://github.com/kuzzleio/project-templates`,
40
+ }),
40
41
  };
41
42
  AppScaffold.args = [
42
- { name: 'destination', description: 'Directory to scaffold the app', required: true },
43
+ {
44
+ name: "destination",
45
+ description: "Directory to scaffold the app",
46
+ required: true,
47
+ },
43
48
  ];
@@ -1,4 +1,4 @@
1
- import { Kommand } from '../../common';
1
+ import { Kommand } from "../../common";
2
2
  export default class AppStartServices extends Kommand {
3
3
  static initSdk: boolean;
4
4
  static description: string;
@@ -2,14 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const fs_1 = require("fs");
5
- const path_1 = tslib_1.__importDefault(require("path"));
5
+ const path_1 = (0, tslib_1.__importDefault)(require("path"));
6
6
  const command_1 = require("@oclif/command");
7
- const chalk_1 = tslib_1.__importDefault(require("chalk"));
8
- const listr_1 = tslib_1.__importDefault(require("listr"));
9
- const node_emoji_1 = tslib_1.__importDefault(require("node-emoji"));
7
+ const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
8
+ const listr_1 = (0, tslib_1.__importDefault)(require("listr"));
9
+ const node_emoji_1 = (0, tslib_1.__importDefault)(require("node-emoji"));
10
10
  const common_1 = require("../../common");
11
11
  const execute_1 = require("../../support/execute");
12
- const MIN_DOCO_VERSION = '1.12.0';
12
+ const MIN_DOCO_VERSION = "1.12.0";
13
13
  const kuzzleServicesFile = `
14
14
  version: '3'
15
15
 
@@ -29,49 +29,49 @@ services:
29
29
  class AppStartServices extends common_1.Kommand {
30
30
  async runSafe() {
31
31
  this.createKourouDir();
32
- const docoFilename = path_1.default.join(this.kourouDir, 'kuzzle-services.yml');
33
- const successfullCheck = this.flags.check ?
34
- await this.checkPrerequisites() :
35
- true;
32
+ const docoFilename = path_1.default.join(this.kourouDir, "kuzzle-services.yml");
33
+ const successfullCheck = this.flags.check
34
+ ? await this.checkPrerequisites()
35
+ : true;
36
36
  if (this.flags.check && successfullCheck) {
37
- this.log(`\n${node_emoji_1.default.get('ok_hand')} Prerequisites are ${chalk_1.default.green.bold('OK')}!`);
37
+ this.log(`\n${node_emoji_1.default.get("ok_hand")} Prerequisites are ${chalk_1.default.green.bold("OK")}!`);
38
38
  }
39
39
  else if (this.flags.check && !successfullCheck) {
40
- throw new Error(`${node_emoji_1.default.get('shrug')} Your system doesn't satisfy all the prerequisites. Cannot run Kuzzle services.`);
40
+ throw new Error(`${node_emoji_1.default.get("shrug")} Your system doesn't satisfy all the prerequisites. Cannot run Kuzzle services.`);
41
41
  }
42
42
  this.log(chalk_1.default.grey(`\nWriting docker-compose file to ${docoFilename}...\n`));
43
43
  (0, fs_1.writeFileSync)(docoFilename, kuzzleServicesFile);
44
44
  // clean up
45
- await (0, execute_1.execute)('docker-compose', '-f', docoFilename, 'down');
45
+ await (0, execute_1.execute)("docker-compose", "-f", docoFilename, "down");
46
46
  try {
47
- await (0, execute_1.execute)('docker-compose', '-f', docoFilename, 'up', '-d');
48
- this.logOk('Elasticsearch and Redis are booting in the background right now.');
49
- this.log(chalk_1.default.grey('\nTo watch the logs, run'));
47
+ await (0, execute_1.execute)("docker-compose", "-f", docoFilename, "up", "-d");
48
+ this.logOk("Elasticsearch and Redis are booting in the background right now.");
49
+ this.log(chalk_1.default.grey("\nTo watch the logs, run"));
50
50
  this.log(chalk_1.default.grey(` docker-compose -f ${docoFilename} logs -f\n`));
51
- this.log(' Elasticsearch port: 9200');
52
- this.log(' Redis port: 6379');
51
+ this.log(" Elasticsearch port: 9200");
52
+ this.log(" Redis port: 6379");
53
53
  }
54
54
  catch (error) {
55
55
  this.logKo(` Something went wrong: ${error.message}`);
56
- this.log(chalk_1.default.grey('If you want to investigate the problem, try running'));
56
+ this.log(chalk_1.default.grey("If you want to investigate the problem, try running"));
57
57
  this.log(chalk_1.default.grey(` docker-compose -f ${docoFilename} up\n`));
58
58
  }
59
59
  }
60
60
  async checkPrerequisites() {
61
- this.log(chalk_1.default.grey('Checking prerequisites...'));
61
+ this.log(chalk_1.default.grey("Checking prerequisites..."));
62
62
  const checks = new listr_1.default([
63
63
  {
64
64
  title: `docker-compose exists and the version is at least ${MIN_DOCO_VERSION}`,
65
65
  task: async () => {
66
66
  try {
67
- const docov = await (0, execute_1.execute)('docker-compose', '-v');
67
+ const docov = await (0, execute_1.execute)("docker-compose", "-v");
68
68
  const matches = docov.stdout.match(/[^0-9.]*([0-9.]*).*/);
69
69
  if (matches === null) {
70
- throw new Error('Unable to read docker-compose verson. This is weird.');
70
+ throw new Error("Unable to read docker-compose verson. This is weird.");
71
71
  }
72
72
  const docoVersion = matches.length > 0 ? matches[1] : null;
73
73
  if (docoVersion === null) {
74
- throw new Error('Unable to read docker-compose version. This is weird.');
74
+ throw new Error("Unable to read docker-compose version. This is weird.");
75
75
  }
76
76
  try {
77
77
  if (docoVersion < MIN_DOCO_VERSION) {
@@ -83,10 +83,10 @@ class AppStartServices extends common_1.Kommand {
83
83
  }
84
84
  }
85
85
  catch (error) {
86
- throw new Error('No docker-compose found. Are you sure docker-compose is installed?');
86
+ throw new Error("No docker-compose found. Are you sure docker-compose is installed?");
87
87
  }
88
88
  },
89
- }
89
+ },
90
90
  ]);
91
91
  try {
92
92
  await checks.run();
@@ -100,11 +100,11 @@ class AppStartServices extends common_1.Kommand {
100
100
  }
101
101
  exports.default = AppStartServices;
102
102
  AppStartServices.initSdk = false;
103
- AppStartServices.description = 'Starts Kuzzle services (Elasticsearch and Redis)';
103
+ AppStartServices.description = "Starts Kuzzle services (Elasticsearch and Redis)";
104
104
  AppStartServices.flags = {
105
105
  help: command_1.flags.help(),
106
106
  check: command_1.flags.boolean({
107
- description: 'Check prerequisite before running services',
107
+ description: "Check prerequisite before running services",
108
108
  default: false,
109
109
  }),
110
110
  };
@@ -1,5 +1,5 @@
1
- import { flags } from '@oclif/command';
2
- import { Kommand } from '../../common';
1
+ import { flags } from "@oclif/command";
2
+ import { Kommand } from "../../common";
3
3
  export default class CollectionCreate extends Kommand {
4
4
  static description: string;
5
5
  static flags: {
@@ -10,7 +10,7 @@ export default class CollectionCreate extends Kommand {
10
10
  password: flags.IOptionFlag<string | undefined>;
11
11
  protocol: flags.IOptionFlag<string>;
12
12
  as: flags.IOptionFlag<string | undefined>;
13
- 'api-key': flags.IOptionFlag<string | undefined>;
13
+ "api-key": flags.IOptionFlag<string | undefined>;
14
14
  help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
15
15
  };
16
16
  static args: ({
@@ -5,8 +5,8 @@ const common_1 = require("../../common");
5
5
  const kuzzle_1 = require("../../support/kuzzle");
6
6
  class CollectionCreate extends common_1.Kommand {
7
7
  async runSafe() {
8
- const body = this.stdin ? this.stdin : this.args.body || '{}';
9
- if (!await this.sdk.index.exists(this.args.index)) {
8
+ const body = this.stdin ? this.stdin : this.args.body || "{}";
9
+ if (!(await this.sdk.index.exists(this.args.index))) {
10
10
  await this.sdk.index.create(this.args.index);
11
11
  this.logInfo(`Index "${this.args.index}" created`);
12
12
  }
@@ -15,11 +15,14 @@ class CollectionCreate extends common_1.Kommand {
15
15
  }
16
16
  }
17
17
  exports.default = CollectionCreate;
18
- CollectionCreate.description = 'Creates a collection';
18
+ CollectionCreate.description = "Creates a collection";
19
19
  CollectionCreate.flags = Object.assign({ help: command_1.flags.help() }, kuzzle_1.kuzzleFlags);
20
20
  CollectionCreate.args = [
21
- { name: 'index', description: 'Index name', required: true },
22
- { name: 'collection', description: 'Collection name', required: true },
23
- { name: 'body', description: 'Collection mappings and settings in JS or JSON format. Will be read from STDIN if available' },
21
+ { name: "index", description: "Index name", required: true },
22
+ { name: "collection", description: "Collection name", required: true },
23
+ {
24
+ name: "body",
25
+ description: "Collection mappings and settings in JS or JSON format. Will be read from STDIN if available",
26
+ },
24
27
  ];
25
28
  CollectionCreate.readStdin = true;
@@ -1,5 +1,5 @@
1
- import { flags } from '@oclif/command';
2
- import { Kommand } from '../../common';
1
+ import { flags } from "@oclif/command";
2
+ import { Kommand } from "../../common";
3
3
  export default class CollectionExport extends Kommand {
4
4
  static keepAuth: boolean;
5
5
  static description: string;
@@ -11,15 +11,15 @@ export default class CollectionExport extends Kommand {
11
11
  username: flags.IOptionFlag<string>;
12
12
  password: flags.IOptionFlag<string | undefined>;
13
13
  as: flags.IOptionFlag<string | undefined>;
14
- 'api-key': flags.IOptionFlag<string | undefined>;
14
+ "api-key": flags.IOptionFlag<string | undefined>;
15
15
  help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
16
16
  path: flags.IOptionFlag<string | undefined>;
17
- 'batch-size': flags.IOptionFlag<string>;
17
+ "batch-size": flags.IOptionFlag<string>;
18
18
  query: flags.IOptionFlag<string>;
19
19
  editor: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
20
20
  format: flags.IOptionFlag<string>;
21
21
  fields: flags.IOptionFlag<string | undefined>;
22
- scrollTTL: flags.IOptionFlag<string | undefined>;
22
+ scrollTTL: flags.IOptionFlag<string>;
23
23
  };
24
24
  static args: {
25
25
  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,11 +12,9 @@ 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.');
15
+ const fields = this.flags.fields ? this.flags.fields.split(",") : [];
16
+ if (this.flags.format === "csv" && fields.length === 0) {
17
+ 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
18
  }
21
19
  let query = this.parseJs(this.flags.query);
22
20
  if (this.flags.editor) {
@@ -27,29 +25,29 @@ class CollectionExport extends common_1.Kommand {
27
25
  this.logInfo(`Dumping ${count} of ${countAll} documents from collection "${this.args.index}:${this.args.collection}" in ${exportPath} ...`);
28
26
  fs_1.default.mkdirSync(exportPath, { recursive: true });
29
27
  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, this.flags.scrollTTL);
28
+ 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, this.flags.scrollTTL);
31
29
  this.logOk(`Collection ${this.args.index}:${this.args.collection} dumped`);
32
30
  }
33
31
  }
34
32
  exports.default = CollectionExport;
35
33
  CollectionExport.keepAuth = true;
36
- CollectionExport.description = 'Exports a collection (JSONL format)';
34
+ CollectionExport.description = "Exports a collection (JSONL format)";
37
35
  CollectionExport.flags = Object.assign(Object.assign({ help: command_1.flags.help({}), path: command_1.flags.string({
38
- description: 'Dump root directory',
39
- }), 'batch-size': command_1.flags.string({
40
- description: 'Maximum batch size (see limits.documentsFetchCount config)',
41
- default: '2000'
36
+ description: "Dump root directory",
37
+ }), "batch-size": command_1.flags.string({
38
+ description: "Maximum batch size (see limits.documentsFetchCount config)",
39
+ default: "2000",
42
40
  }), query: command_1.flags.string({
43
- description: 'Only dump documents matching the query (JS or JSON format)',
44
- default: '{}'
41
+ description: "Only dump documents matching the query (JS or JSON format)",
42
+ default: "{}",
45
43
  }), editor: command_1.flags.boolean({
46
- description: 'Open an editor (EDITOR env variable) to edit the query before sending'
44
+ description: "Open an editor (EDITOR env variable) to edit the query before sending",
47
45
  }), format: command_1.flags.string({
48
46
  description: `"kuzzle" will export in Kuzzle format usable for internal fixtures,
49
47
  "jsonl" allows to import that data back with kourou,
50
48
  "csv" allows to import data into Excel (please, specify the fields to export using the --fields option).`,
51
- options: ['jsonl', 'kuzzle', 'csv'],
52
- default: 'jsonl'
49
+ options: ["jsonl", "kuzzle", "csv"],
50
+ default: "jsonl",
53
51
  }), fields: command_1.flags.string({
54
52
  description: `[CSV format only] The list of fields to be included in the CSV export in dot-path format.
55
53
 
@@ -57,19 +55,20 @@ Example:
57
55
  --fields oneField,anotherField,yetAnotherOne.nested.moarNested
58
56
 
59
57
  Note that the '_id' field is always included in the CSV export. Leaving this option empty implies that all
60
- exportable fields in the mapping will be exported.`
58
+ exportable fields in the mapping will be exported.`,
61
59
  }), scrollTTL: command_1.flags.string({
62
60
  description: `The scroll TTL option to pass to the dump operation (which performs a document.search under the hood),
63
- expressed in ms format, e.g. '2s', '1m', '3h'.`
61
+ expressed in ms format, e.g. '2s', '1m', '3h'.`,
62
+ default: "20s",
64
63
  }) }, kuzzle_1.kuzzleFlags), { protocol: command_1.flags.string({
65
- description: 'Kuzzle protocol (http or websocket)',
66
- default: 'ws',
64
+ description: "Kuzzle protocol (http or websocket)",
65
+ default: "ws",
67
66
  }) });
68
67
  CollectionExport.args = [
69
- { name: 'index', description: 'Index name', required: true },
70
- { name: 'collection', description: 'Collection name', required: true },
68
+ { name: "index", description: "Index name", required: true },
69
+ { name: "collection", description: "Collection name", required: true },
71
70
  ];
72
71
  CollectionExport.examples = [
73
- 'kourou collection:export nyc-open-data yellow-taxi',
74
- 'kourou collection:export nyc-open-data yellow-taxi --query \'{ term: { city: "Saigon" } }\'',
72
+ "kourou collection:export nyc-open-data yellow-taxi",
73
+ "kourou collection:export nyc-open-data yellow-taxi --query '{ term: { city: \"Saigon\" } }'",
75
74
  ];
@@ -1,5 +1,5 @@
1
- import { flags } from '@oclif/command';
2
- import { Kommand } from '../../common';
1
+ import { flags } from "@oclif/command";
2
+ import { Kommand } from "../../common";
3
3
  export default class CollectionImport extends Kommand {
4
4
  static keepAuth: boolean;
5
5
  static description: string;
@@ -11,12 +11,12 @@ export default class CollectionImport extends Kommand {
11
11
  username: flags.IOptionFlag<string>;
12
12
  password: flags.IOptionFlag<string | undefined>;
13
13
  as: flags.IOptionFlag<string | undefined>;
14
- 'api-key': flags.IOptionFlag<string | undefined>;
14
+ "api-key": flags.IOptionFlag<string | undefined>;
15
15
  help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
16
- 'batch-size': flags.IOptionFlag<string>;
16
+ "batch-size": flags.IOptionFlag<string>;
17
17
  index: flags.IOptionFlag<string | undefined>;
18
18
  collection: flags.IOptionFlag<string | undefined>;
19
- 'no-mappings': import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
19
+ "no-mappings": import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
20
20
  };
21
21
  static args: {
22
22
  name: string;