kuzzle 2.15.2 → 2.16.3
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/lib/api/controllers/serverController.js +24 -4
- package/lib/api/funnel.js +19 -0
- package/lib/{config → api}/httpRoutes.js +29 -14
- package/lib/api/openApiGenerator.d.ts +6 -0
- package/lib/api/openApiGenerator.js +167 -126
- package/lib/api/openapi/document/count.yaml +47 -0
- package/lib/api/openapi/document/create.yaml +46 -0
- package/lib/api/openapi/document/createOrReplace.yaml +61 -0
- package/lib/api/openapi/document/delete.yaml +67 -0
- package/lib/api/openapi/document/deleteByQuery.yaml +90 -0
- package/lib/api/openapi/document/exists.yaml +35 -0
- package/lib/api/openapi/document/get.yaml +68 -0
- package/lib/api/openapi/document/index.d.ts +20 -0
- package/lib/api/openapi/document/index.js +55 -0
- package/lib/api/openapi/document/replace.yaml +66 -0
- package/lib/api/openapi/document/scroll.yaml +49 -0
- package/lib/api/openapi/document/update.yaml +78 -0
- package/lib/api/openapi/index.d.ts +2 -0
- package/lib/api/openapi/index.js +18 -0
- package/lib/api/openapi/payloads.yaml +32 -0
- package/lib/api/request/kuzzleRequest.d.ts +32 -0
- package/lib/api/request/kuzzleRequest.js +34 -0
- package/lib/api/request/requestInput.d.ts +2 -0
- package/lib/api/request/requestInput.js +2 -0
- package/lib/config/default.config.js +1 -1
- package/lib/core/network/router.js +33 -0
- package/lib/core/realtime/hotelClerk.d.ts +7 -0
- package/lib/core/realtime/hotelClerk.js +14 -0
- package/lib/util/readYamlFile.d.ts +2 -0
- package/lib/util/readYamlFile.js +10 -0
- package/package-lock.json +160 -175
- package/package.json +11 -25
- package/.kuzzlerc.sample +0 -988
- package/CONTRIBUTING.md +0 -116
- package/bin/.lib/colorOutput.js +0 -71
- package/bin/.upgrades/connectors/es.js +0 -90
- package/bin/.upgrades/connectors/redis.js +0 -112
- package/bin/.upgrades/lib/connectorContext.js +0 -38
- package/bin/.upgrades/lib/context.js +0 -142
- package/bin/.upgrades/lib/formatters.js +0 -103
- package/bin/.upgrades/lib/inquirerExtended.js +0 -46
- package/bin/.upgrades/lib/logger.js +0 -99
- package/bin/.upgrades/lib/progressBar.js +0 -70
- package/bin/.upgrades/versions/v1/checkConfiguration.js +0 -85
- package/bin/.upgrades/versions/v1/index.js +0 -35
- package/bin/.upgrades/versions/v1/upgradeCache.js +0 -149
- package/bin/.upgrades/versions/v1/upgradeStorage.js +0 -450
- package/protocols/available/.gitignore +0 -4
- package/protocols/enabled/.gitignore +0 -4
package/CONTRIBUTING.md
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
# How to contribute to Kuzzle
|
|
2
|
-
|
|
3
|
-
Here are a few rules and guidelines to follow if you want to contribute to Kuzzle and, more importantly, if you want to see your pull requests accepted by Kuzzle team.
|
|
4
|
-
|
|
5
|
-
## Coding style
|
|
6
|
-
|
|
7
|
-
We use most of the [NPM Coding Style](https://www.w3resource.com/npm/npm-coding-style.php) rules, except for these ones:
|
|
8
|
-
|
|
9
|
-
* Semicolons at the end of lines
|
|
10
|
-
* 'Comma first' rule is not followed
|
|
11
|
-
|
|
12
|
-
## Guidelines
|
|
13
|
-
|
|
14
|
-
* Prefer async/await or promises instead of callbacks as often as you can
|
|
15
|
-
* Except for methods invoked before the funnel module: ALWAYS use callbacks there to prevent event loop saturation (i.e. mostly methods handling network connections)
|
|
16
|
-
* Always add/update the corresponding unit and/or functional tests. We won't accept non-tested pull requests.
|
|
17
|
-
* [Documentation and comments are more important than code](http://queue.acm.org/detail.cfm?id=1053354): comment your code, use jsdoc for every new function, add or update markdown documentation if need be. We won't accept undocumented pull requests.
|
|
18
|
-
* Similar to the previous rule: documentation is important, but also is code readability. Write [self-describing code](https://en.wikipedia.org/wiki/Self-documenting).
|
|
19
|
-
|
|
20
|
-
## General rules and principles we'd like you to follow
|
|
21
|
-
|
|
22
|
-
* If you plan to add new features to Kuzzle, make sure that this is for a general improvement to benefit a majority of Kuzzle users. If not, consider making a plugin instead (check our [plugin documentation](https://docs.kuzzle.io/plugins/1))
|
|
23
|
-
* Follow the [KISS Principle](https://en.wikipedia.org/wiki/KISS_principle)
|
|
24
|
-
* Follow [The Boy Scout Rule](https://deviq.com/principles/boy-scout-rule)
|
|
25
|
-
|
|
26
|
-
## Tools
|
|
27
|
-
|
|
28
|
-
For development only, we built a specific docker-compose file: `docker-compose.yml`. You can use it to profile, debug, test a variable on the fly, add breakpoints and so on, thanks to [chrome-devtools](https://developer.chrome.com/devtools).
|
|
29
|
-
Check the logs at the start of Kuzzle using the development docker image to get the appropriate debug URL.
|
|
30
|
-
|
|
31
|
-
How to run the development stack (needs Docker 1.10+ and Docker Compose 1.8+):
|
|
32
|
-
|
|
33
|
-
```bash
|
|
34
|
-
# clone this repository
|
|
35
|
-
git clone git@github.com:kuzzleio/kuzzle.git
|
|
36
|
-
cd kuzzle
|
|
37
|
-
|
|
38
|
-
# Start a kuzzle cluster with development tools enabled
|
|
39
|
-
docker-compose up
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
### ENOSPC error
|
|
43
|
-
|
|
44
|
-
On some Linux environments, you may get `ENOSPC` errors from the filesystem watcher, because of limits set too low.
|
|
45
|
-
|
|
46
|
-
If that happens, simply raise the limits on the number of files that can be watched:
|
|
47
|
-
|
|
48
|
-
`sudo sysctl -w fs.inotify.max_user_watches=524288`
|
|
49
|
-
|
|
50
|
-
That configuration change will last until the next reboot.
|
|
51
|
-
|
|
52
|
-
To make it permanent, add the following line to your `/etc/sysctl.conf` file:
|
|
53
|
-
|
|
54
|
-
```
|
|
55
|
-
fs.inotify.max_user_watches=524288
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
You can now access the Kuzzle HTTP/WebSocket API through the following URL: `http://localhost:7512`.
|
|
59
|
-
This is the entrypoint for the loadbalancer: API requests are then forwarded to kuzzle individual kuzzle nodes (round-robin).
|
|
60
|
-
|
|
61
|
-
For development purposes, nodes can be accessed individually:
|
|
62
|
-
|
|
63
|
-
| Node no. | HTTP/WebSocket port | MQTT port | Chrome Inspect Port |
|
|
64
|
-
|:--------:|:-------------------:|:---------:|:-------------------:|
|
|
65
|
-
| 1 | 17510 | 1883 | 9229 |
|
|
66
|
-
| 2 | 17511 | 11883 | 9230 |
|
|
67
|
-
| 3 | 17512 | 11884 | 9231 |
|
|
68
|
-
|
|
69
|
-
Everytime a modification is detected in the source files, the nodes are automatically restarted.
|
|
70
|
-
|
|
71
|
-
### Kuzzle over SSL
|
|
72
|
-
|
|
73
|
-
[See our complete guide](https://docs.kuzzle.io/core/2/guides/essentials/ssl-support/)
|
|
74
|
-
|
|
75
|
-
The development stack include a endpoint to access Kuzzle API through SSL on port `7443`.
|
|
76
|
-
|
|
77
|
-
The certificates are privately signed, using provided [CA certificate](docker/nginx/kuzzleCA.crt).
|
|
78
|
-
Domains accepted:
|
|
79
|
-
- localhost
|
|
80
|
-
- *.kuzzle.loc
|
|
81
|
-
|
|
82
|
-
You'll need to import the CA certificate to your browser and possibly your system local authorities to make it verified.
|
|
83
|
-
Once done, your browser should not complain when reaching https://localhost:7443.
|
|
84
|
-
The CA certificate is here: [docker/nginx/kuzzleCA.crt](docker/nginx/kuzzleCA.crt)
|
|
85
|
-
|
|
86
|
-
Using node.js, for instance when using the sdk, you'll need to pass the CA cert using the `NODE_EXTRA_CA_CERTS` environment variable:
|
|
87
|
-
|
|
88
|
-
```
|
|
89
|
-
NODE_EXTRA_CA_CERTS=/path/to/certificate/kuzzleCA.crt wscat -c wss://localhost:7443
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
## Create a plugin
|
|
93
|
-
|
|
94
|
-
See our [plugins documentation](https://docs.kuzzle.io/core/2/plugins/)
|
|
95
|
-
|
|
96
|
-
## Running Tests
|
|
97
|
-
|
|
98
|
-
### Using docker, with Kuzzle running in Docker
|
|
99
|
-
|
|
100
|
-
```bash
|
|
101
|
-
$ docker-compose up -d
|
|
102
|
-
|
|
103
|
-
# Wait for Kuzzle stack to be up, and start the entire test suite (long)
|
|
104
|
-
$ npm run test
|
|
105
|
-
|
|
106
|
-
# To launch tests individually:
|
|
107
|
-
|
|
108
|
-
# linter: check that the code is properly written
|
|
109
|
-
$ npm run test:lint
|
|
110
|
-
|
|
111
|
-
# unit tests: test parts of the code individually
|
|
112
|
-
$ npm run test:unit
|
|
113
|
-
|
|
114
|
-
# functional tests: test Kuzzle's API behavior
|
|
115
|
-
$ npm run test:functional
|
|
116
|
-
```
|
package/bin/.lib/colorOutput.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Kuzzle, a backend software, self-hostable and ready to use
|
|
3
|
-
* to power modern apps
|
|
4
|
-
*
|
|
5
|
-
* Copyright 2015-2020 Kuzzle
|
|
6
|
-
* mailto: support AT kuzzle.io
|
|
7
|
-
* website: http://kuzzle.io
|
|
8
|
-
*
|
|
9
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
|
-
* you may not use this file except in compliance with the License.
|
|
11
|
-
* You may obtain a copy of the License at
|
|
12
|
-
*
|
|
13
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
-
*
|
|
15
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
16
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
-
* See the License for the specific language governing permissions and
|
|
19
|
-
* limitations under the License.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
'use strict';
|
|
23
|
-
|
|
24
|
-
const clc = require('cli-color');
|
|
25
|
-
|
|
26
|
-
function noop(str) {
|
|
27
|
-
return str;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
class ColorOutput {
|
|
31
|
-
constructor (opts) {
|
|
32
|
-
// /!\ "opts" might be a string
|
|
33
|
-
const noColors =
|
|
34
|
-
typeof opts === 'object' &&
|
|
35
|
-
opts.parent &&
|
|
36
|
-
opts.parent.noColors;
|
|
37
|
-
|
|
38
|
-
this.format = {
|
|
39
|
-
error: noColors ? noop : clc.red,
|
|
40
|
-
warn: noColors ? noop : clc.yellow,
|
|
41
|
-
notice: noColors ? noop : clc.cyanBright,
|
|
42
|
-
ok: noColors ? noop : clc.green.bold,
|
|
43
|
-
question: noColors ? noop : clc.whiteBright
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/* eslint-disable no-console */
|
|
48
|
-
error(str) {
|
|
49
|
-
console.error(this.format.error(str));
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
warn(str) {
|
|
53
|
-
console.warn(this.format.warn(str));
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
notice(str) {
|
|
57
|
-
console.log(this.format.notice(str));
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
question(str) {
|
|
61
|
-
console.log(this.format.question(str));
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
ok(str) {
|
|
65
|
-
console.log(this.format.ok(str));
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/* eslint-enable no-console */
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
module.exports = ColorOutput;
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Kuzzle, a backend software, self-hostable and ready to use
|
|
3
|
-
* to power modern apps
|
|
4
|
-
*
|
|
5
|
-
* Copyright 2015-2020 Kuzzle
|
|
6
|
-
* mailto: support AT kuzzle.io
|
|
7
|
-
* website: http://kuzzle.io
|
|
8
|
-
*
|
|
9
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
|
-
* you may not use this file except in compliance with the License.
|
|
11
|
-
* You may obtain a copy of the License at
|
|
12
|
-
*
|
|
13
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
-
*
|
|
15
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
16
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
-
* See the License for the specific language governing permissions and
|
|
19
|
-
* limitations under the License.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
'use strict';
|
|
23
|
-
|
|
24
|
-
const { formatWithOptions } = require('util');
|
|
25
|
-
|
|
26
|
-
const { Client } = require('@elastic/elasticsearch');
|
|
27
|
-
const validator = require('validator');
|
|
28
|
-
const _ = require('lodash');
|
|
29
|
-
|
|
30
|
-
const ConnectorContext = require('../lib/connectorContext');
|
|
31
|
-
|
|
32
|
-
let promise = null;
|
|
33
|
-
|
|
34
|
-
async function getEsClient(context) {
|
|
35
|
-
const currentConfiguration = _.get(context.config, 'services.storageEngine.client');
|
|
36
|
-
|
|
37
|
-
if (!currentConfiguration) {
|
|
38
|
-
context.log.error('Missing Kuzzle configuration for Elasticsearch.');
|
|
39
|
-
context.log.error('Missing configuration value: services.storageEngine.client');
|
|
40
|
-
context.log.error('Aborted.');
|
|
41
|
-
process.exit(1);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
context.log.notice('Current Elasticsearch configuration:');
|
|
45
|
-
context.log.print(
|
|
46
|
-
formatWithOptions({ colors: false, depth: null }, currentConfiguration));
|
|
47
|
-
|
|
48
|
-
const answers = await context.inquire.prompt([
|
|
49
|
-
{
|
|
50
|
-
choices: ['source', 'target', 'source and target'],
|
|
51
|
-
default: 'target',
|
|
52
|
-
message: 'For this migration, use this current instance as the data',
|
|
53
|
-
name: 'current',
|
|
54
|
-
type: 'list',
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
default: '',
|
|
58
|
-
message: ({ current }) => `Enter the URL for the ${current === 'source' ? 'target': 'source'} instance:`,
|
|
59
|
-
name: 'url',
|
|
60
|
-
type: 'input',
|
|
61
|
-
validate: url => {
|
|
62
|
-
const opts = {
|
|
63
|
-
protocols: ['http', 'https'],
|
|
64
|
-
require_port: true,
|
|
65
|
-
require_protocol: true,
|
|
66
|
-
require_tld: false,
|
|
67
|
-
require_valid_protocol: true,
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
return validator.isURL(url, opts) || 'A valid URL must be provided. Example: http://<server>:<port>';
|
|
71
|
-
},
|
|
72
|
-
when: ({ current }) => current !== 'source and target'
|
|
73
|
-
}
|
|
74
|
-
]);
|
|
75
|
-
|
|
76
|
-
const current = new Client(currentConfiguration);
|
|
77
|
-
const next = answers.url ? new Client({ node: answers.url }) : current;
|
|
78
|
-
|
|
79
|
-
return answers.current === 'source'
|
|
80
|
-
? new ConnectorContext(context, current, next)
|
|
81
|
-
: new ConnectorContext(context, next, current);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
module.exports = async context => {
|
|
85
|
-
if (promise === null) {
|
|
86
|
-
promise = getEsClient(context);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return promise;
|
|
90
|
-
};
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Kuzzle, a backend software, self-hostable and ready to use
|
|
3
|
-
* to power modern apps
|
|
4
|
-
*
|
|
5
|
-
* Copyright 2015-2020 Kuzzle
|
|
6
|
-
* mailto: support AT kuzzle.io
|
|
7
|
-
* website: http://kuzzle.io
|
|
8
|
-
*
|
|
9
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
|
-
* you may not use this file except in compliance with the License.
|
|
11
|
-
* You may obtain a copy of the License at
|
|
12
|
-
*
|
|
13
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
-
*
|
|
15
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
16
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
-
* See the License for the specific language governing permissions and
|
|
19
|
-
* limitations under the License.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
'use strict';
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
{ formatWithOptions } = require('util'),
|
|
26
|
-
IORedis = require('ioredis'),
|
|
27
|
-
ConnectorContext = require('../lib/connectorContext'),
|
|
28
|
-
_ = require('lodash');
|
|
29
|
-
|
|
30
|
-
let promise = null;
|
|
31
|
-
|
|
32
|
-
async function getRedisClient(context) {
|
|
33
|
-
const currentConfiguration = _.get(context.config, 'services.internalCache');
|
|
34
|
-
|
|
35
|
-
if (!currentConfiguration) {
|
|
36
|
-
context.log.error('Missing Kuzzle configuration for Redis.');
|
|
37
|
-
context.log.error('Missing configuration value: services.internalCache');
|
|
38
|
-
context.log.error('Aborted.');
|
|
39
|
-
process.exit(1);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
context.log.notice('Current Redis configuration:');
|
|
43
|
-
context.log.print(
|
|
44
|
-
formatWithOptions({ colors: false, depth: null }, currentConfiguration));
|
|
45
|
-
|
|
46
|
-
const current = await context.inquire.direct({
|
|
47
|
-
choices: ['source', 'target', 'source and target'],
|
|
48
|
-
default: 'target',
|
|
49
|
-
message: 'For this migration, use this current instance as the data',
|
|
50
|
-
type: 'list',
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
const remaining = current === 'source' ? 'target': 'source';
|
|
54
|
-
let answers = null;
|
|
55
|
-
|
|
56
|
-
if (current !== 'source and target') {
|
|
57
|
-
answers = await context.inquire.prompt([
|
|
58
|
-
{
|
|
59
|
-
default: '',
|
|
60
|
-
message: `${remaining} server name or IP:`,
|
|
61
|
-
name: 'server',
|
|
62
|
-
type: 'input',
|
|
63
|
-
validate: name => name.length > 0 || 'Non-empty string expected'
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
default: '',
|
|
67
|
-
message: `${remaining} server port:`,
|
|
68
|
-
name: 'port',
|
|
69
|
-
type: 'input',
|
|
70
|
-
validate: name => {
|
|
71
|
-
const i = Number.parseFloat(name);
|
|
72
|
-
|
|
73
|
-
if (!Number.isNaN(i) && Number.isInteger(i) && i > 1 && i <= 65535) {
|
|
74
|
-
return true;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return 'Invalid port number';
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
]);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
options = { enableReadyCheck: true, lazyConnect: true },
|
|
85
|
-
client = currentConfiguration.nodes
|
|
86
|
-
? new IORedis.Cluster(currentConfiguration, options)
|
|
87
|
-
: new IORedis(currentConfiguration.node, options);
|
|
88
|
-
|
|
89
|
-
await client.connect();
|
|
90
|
-
|
|
91
|
-
let next;
|
|
92
|
-
|
|
93
|
-
if (answers) {
|
|
94
|
-
next = new IORedis(answers.port, answers.server, options);
|
|
95
|
-
await next.connect();
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
next = client;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return current === 'source'
|
|
102
|
-
? new ConnectorContext(context, client, next)
|
|
103
|
-
: new ConnectorContext(context, next, client);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
module.exports = async context => {
|
|
107
|
-
if (promise === null) {
|
|
108
|
-
promise = getRedisClient(context);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return promise;
|
|
112
|
-
};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Kuzzle, a backend software, self-hostable and ready to use
|
|
3
|
-
* to power modern apps
|
|
4
|
-
*
|
|
5
|
-
* Copyright 2015-2020 Kuzzle
|
|
6
|
-
* mailto: support AT kuzzle.io
|
|
7
|
-
* website: http://kuzzle.io
|
|
8
|
-
*
|
|
9
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
|
-
* you may not use this file except in compliance with the License.
|
|
11
|
-
* You may obtain a copy of the License at
|
|
12
|
-
*
|
|
13
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
-
*
|
|
15
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
16
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
-
* See the License for the specific language governing permissions and
|
|
19
|
-
* limitations under the License.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
'use strict';
|
|
23
|
-
|
|
24
|
-
const UpgradeContext = require('./context');
|
|
25
|
-
|
|
26
|
-
class ConnectorContext extends UpgradeContext {
|
|
27
|
-
constructor(context, source, target) {
|
|
28
|
-
super(context);
|
|
29
|
-
this.source = source;
|
|
30
|
-
this.target = target;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
get inPlace () {
|
|
34
|
-
return this.source === this.target;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
module.exports = ConnectorContext;
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Kuzzle, a backend software, self-hostable and ready to use
|
|
3
|
-
* to power modern apps
|
|
4
|
-
*
|
|
5
|
-
* Copyright 2015-2020 Kuzzle
|
|
6
|
-
* mailto: support AT kuzzle.io
|
|
7
|
-
* website: http://kuzzle.io
|
|
8
|
-
*
|
|
9
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
|
-
* you may not use this file except in compliance with the License.
|
|
11
|
-
* You may obtain a copy of the License at
|
|
12
|
-
*
|
|
13
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
-
*
|
|
15
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
16
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
-
* See the License for the specific language governing permissions and
|
|
19
|
-
* limitations under the License.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
'use strict';
|
|
23
|
-
|
|
24
|
-
const fs = require('fs');
|
|
25
|
-
const path = require('path');
|
|
26
|
-
|
|
27
|
-
const rc = require('rc');
|
|
28
|
-
|
|
29
|
-
const inquirer = require('./inquirerExtended');
|
|
30
|
-
const Logger = require('./logger');
|
|
31
|
-
|
|
32
|
-
const defaultConfiguration = require('../../../lib/config/default.config.js');
|
|
33
|
-
const { version: currentVersion } = require('../../../package.json');
|
|
34
|
-
|
|
35
|
-
class Version {
|
|
36
|
-
constructor() {
|
|
37
|
-
this.from = null;
|
|
38
|
-
this.list = [];
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
class UpgradeContext {
|
|
43
|
-
constructor(args) {
|
|
44
|
-
// copy constructor
|
|
45
|
-
if (args instanceof UpgradeContext) {
|
|
46
|
-
this.config = args.config;
|
|
47
|
-
this.log = args.log;
|
|
48
|
-
this.inquire = args.inquire;
|
|
49
|
-
this.version = args.version;
|
|
50
|
-
this.argv = args.argv;
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
this.config = null;
|
|
54
|
-
this.log = new Logger(args);
|
|
55
|
-
this.inquire = inquirer;
|
|
56
|
-
this.version = null;
|
|
57
|
-
this.argv = args;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async init () {
|
|
62
|
-
await this.loadConfiguration();
|
|
63
|
-
|
|
64
|
-
if (this.config.configs) {
|
|
65
|
-
this.log.ok('Configuration files loaded:');
|
|
66
|
-
this.config.configs.forEach(f => this.log.print(`\t- ${f}`));
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
this.version = await this.getVersions();
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
async loadConfiguration () {
|
|
73
|
-
let cfg;
|
|
74
|
-
|
|
75
|
-
try {
|
|
76
|
-
cfg = rc('kuzzle', JSON.parse(JSON.stringify(defaultConfiguration)));
|
|
77
|
-
this.config = cfg;
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
catch (e) {
|
|
81
|
-
this.log.error(`Cannot load configuration files: ${e.message}`);
|
|
82
|
-
if (this.config === null) {
|
|
83
|
-
this.log.error('Check your configuration files, and restart the upgrade script.');
|
|
84
|
-
process.exit(1);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// If we are here, this means that an error was thrown, due to a change made
|
|
89
|
-
// to configuration files *during* the upgrade (probably because a version
|
|
90
|
-
// upgrade asked the user to modify their configuration files manually)
|
|
91
|
-
// To prevent aborting unnecessarily during the upgrade process, we ask the
|
|
92
|
-
// user to fix the situation
|
|
93
|
-
const retry = await this.inquire.direct({
|
|
94
|
-
default: true,
|
|
95
|
-
message: 'Retry?',
|
|
96
|
-
type: 'confirm'
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
if (!retry) {
|
|
100
|
-
this.log.error('Aborted by user action.');
|
|
101
|
-
process.exit(1);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
await this.loadConfiguration();
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Asks the user the source version to upgrade from
|
|
109
|
-
* @returns {Version}
|
|
110
|
-
*/
|
|
111
|
-
async getVersions () {
|
|
112
|
-
const version = new Version();
|
|
113
|
-
|
|
114
|
-
this.log.print(`Current Kuzzle version: ${currentVersion}`);
|
|
115
|
-
|
|
116
|
-
version.list = fs
|
|
117
|
-
.readdirSync(
|
|
118
|
-
path.resolve(`${__dirname}/../versions`),
|
|
119
|
-
{ withFileTypes: true })
|
|
120
|
-
.filter(entry => entry.isDirectory() && entry.name.match(/^v\d+$/))
|
|
121
|
-
.map(entry => entry.name)
|
|
122
|
-
.sort((a, b) => parseInt(a[0].substring(1))-parseInt(b[0].substring(1)));
|
|
123
|
-
|
|
124
|
-
if (version.list.length === 1) {
|
|
125
|
-
version.from = version.list[0];
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
version.from = await inquirer.direct({
|
|
129
|
-
choices: version.list,
|
|
130
|
-
default: version.list[version.list.length - 1],
|
|
131
|
-
message: 'Migrate from which version',
|
|
132
|
-
type: 'list'
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
version.list = version.list.slice(version.list.indexOf(version.from));
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
return version;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
module.exports = UpgradeContext;
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Kuzzle, a backend software, self-hostable and ready to use
|
|
3
|
-
* to power modern apps
|
|
4
|
-
*
|
|
5
|
-
* Copyright 2015-2020 Kuzzle
|
|
6
|
-
* mailto: support AT kuzzle.io
|
|
7
|
-
* website: http://kuzzle.io
|
|
8
|
-
*
|
|
9
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
|
-
* you may not use this file except in compliance with the License.
|
|
11
|
-
* You may obtain a copy of the License at
|
|
12
|
-
*
|
|
13
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
-
*
|
|
15
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
16
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
-
* See the License for the specific language governing permissions and
|
|
19
|
-
* limitations under the License.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
'use strict';
|
|
23
|
-
|
|
24
|
-
const clc = require('cli-color');
|
|
25
|
-
|
|
26
|
-
class RawFormatter {
|
|
27
|
-
raw (msg) {
|
|
28
|
-
return msg;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
class ColoredFormatter extends RawFormatter {
|
|
33
|
-
error (msg) {
|
|
34
|
-
return clc.red(msg);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
warn (msg) {
|
|
38
|
-
return clc.yellow(msg);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
notice (msg) {
|
|
42
|
-
return clc.cyan(msg);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
ok (msg) {
|
|
46
|
-
return clc.green(msg);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
question (msg) {
|
|
50
|
-
return clc.whiteBright(msg);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
class PrefixedFormatter extends RawFormatter {
|
|
55
|
-
error (msg) {
|
|
56
|
-
return `[ERROR] ${msg}`;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
warn (msg) {
|
|
60
|
-
return `[WARN] ${msg}`;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
notice (msg) {
|
|
64
|
-
return `[i] ${msg}`;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
ok (msg) {
|
|
68
|
-
return `[OK] ${msg}`;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
question (msg) {
|
|
72
|
-
return `[?] ${msg}`;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
class FileFormatter extends PrefixedFormatter {
|
|
77
|
-
error (msg) {
|
|
78
|
-
return Buffer.from(`[${(new Date()).toISOString()}]${super.error(msg)}\n`);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
warn (msg) {
|
|
82
|
-
return Buffer.from(`[${(new Date()).toISOString()}]${super.warn(msg)}\n`);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
notice (msg) {
|
|
86
|
-
return Buffer.from(`[${(new Date()).toISOString()}]${super.notice(msg)}\n`);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
ok (msg) {
|
|
90
|
-
return Buffer.from(`[${(new Date()).toISOString()}]${super.ok(msg)}\n`);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
question (msg) {
|
|
94
|
-
return Buffer.from(`[${(new Date()).toISOString()}]${super.question(msg)}\n`);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// @override
|
|
98
|
-
raw (msg) {
|
|
99
|
-
return Buffer.from(`${msg}\n`);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
module.exports = { ColoredFormatter, FileFormatter, PrefixedFormatter };
|