@contentstack/cli-migration 0.1.1-beta.1 → 1.0.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.
- package/LICENSE +21 -0
- package/README.md +33 -25
- package/oclif.manifest.json +1 -1
- package/package.json +17 -12
- package/src/actions/action-list.js +11 -11
- package/src/actions/index.js +33 -34
- package/src/commands/cm/stacks/migration.js +299 -0
- package/src/config/api-config.js +5 -6
- package/src/config/default-options.js +2 -2
- package/src/config/index.js +2 -2
- package/src/config/master-locale.js +2 -2
- package/src/modules/base.js +33 -33
- package/src/modules/content-types.js +76 -76
- package/src/modules/fields.js +73 -73
- package/src/modules/index.js +2 -2
- package/src/modules/locale.js +13 -13
- package/src/modules/migration.js +45 -46
- package/src/modules/parser.js +68 -47
- package/src/services/content-types.js +160 -163
- package/src/services/index.js +2 -2
- package/src/services/locales.js +33 -35
- package/src/utils/auto-retry.js +14 -12
- package/src/utils/callsite.js +14 -14
- package/src/utils/constants.js +35 -33
- package/src/utils/contentstack-sdk.js +42 -43
- package/src/utils/error-handler.js +8 -8
- package/src/utils/error-helper.js +41 -40
- package/src/utils/fs-helper.js +24 -10
- package/src/utils/get-batches.js +4 -4
- package/src/utils/get-config.js +6 -6
- package/src/utils/group-by.js +17 -17
- package/src/utils/index.js +2 -2
- package/src/utils/logger.js +42 -52
- package/src/utils/object-helper.js +7 -7
- package/src/utils/safe-promise.js +2 -2
- package/src/utils/schema-helper.js +12 -12
- package/src/utils/success-handler.js +5 -5
- package/src/validators/api-error.js +10 -8
- package/src/validators/base-validator.js +14 -14
- package/src/validators/create-content-type-validator.js +21 -25
- package/src/validators/edit-content-type-validator.js +21 -24
- package/src/validators/field-validator.js +10 -8
- package/src/validators/index.js +2 -2
- package/src/validators/migration-error.js +9 -7
- package/src/validators/schema-validator.js +11 -9
- package/src/validators/type-error.js +11 -10
- package/src/commands/cm/migration.js +0 -182
package/src/utils/logger.js
CHANGED
|
@@ -1,84 +1,74 @@
|
|
|
1
|
-
'use strict'
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
const {createLogger, format, transports} = require('winston')
|
|
4
|
-
const {resolve, join} = require('path')
|
|
5
|
-
const {slice} = Array.prototype
|
|
6
|
-
const {stringify} = JSON
|
|
3
|
+
const { createLogger, format, transports } = require('winston');
|
|
4
|
+
const { resolve, join } = require('path');
|
|
5
|
+
const { slice } = Array.prototype;
|
|
6
|
+
const { stringify } = JSON;
|
|
7
7
|
|
|
8
|
-
const {combine, label, printf, colorize} = format
|
|
8
|
+
const { combine, label, printf, colorize } = format;
|
|
9
9
|
|
|
10
10
|
// FS helper
|
|
11
|
-
const {makeDir} = require('./fs-helper')
|
|
11
|
+
const { makeDir } = require('./fs-helper');
|
|
12
12
|
|
|
13
|
-
const {NODE_ENV} = process.env
|
|
13
|
+
const { NODE_ENV } = process.env;
|
|
14
14
|
|
|
15
15
|
function getString(args) {
|
|
16
|
-
let str = ''
|
|
16
|
+
let str = '';
|
|
17
17
|
if (args && args.length > 0) {
|
|
18
|
-
str = args
|
|
19
|
-
item && typeof item === 'object' ?
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
)
|
|
23
|
-
.join(' ')
|
|
24
|
-
.trim()
|
|
18
|
+
str = args
|
|
19
|
+
.map((item) => (item && typeof item === 'object' ? stringify(item) : item))
|
|
20
|
+
.join(' ')
|
|
21
|
+
.trim();
|
|
25
22
|
}
|
|
26
|
-
return str
|
|
23
|
+
return str;
|
|
27
24
|
}
|
|
28
25
|
|
|
29
|
-
const customFormat = printf(({level, message}) => {
|
|
30
|
-
return `${level}: ${message}
|
|
31
|
-
})
|
|
26
|
+
const customFormat = printf(({ level, message }) => {
|
|
27
|
+
return `${level}: ${message}`;
|
|
28
|
+
});
|
|
32
29
|
|
|
33
30
|
function init(logFileName) {
|
|
34
|
-
const logsDir = resolve('logs')
|
|
31
|
+
const logsDir = resolve('logs');
|
|
35
32
|
// Create dir if does not exist
|
|
36
|
-
makeDir(logsDir)
|
|
33
|
+
makeDir(logsDir);
|
|
37
34
|
|
|
38
|
-
const logPath = join(logsDir, logFileName + '.log')
|
|
35
|
+
const logPath = join(logsDir, logFileName + '.log');
|
|
39
36
|
const logger = createLogger({
|
|
40
|
-
format: combine(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
customFormat
|
|
44
|
-
),
|
|
45
|
-
transports: [
|
|
46
|
-
new transports.File({filename: logPath}),
|
|
47
|
-
new transports.Console(),
|
|
48
|
-
],
|
|
49
|
-
})
|
|
37
|
+
format: combine(colorize(), label({ label: 'Migration' }), customFormat),
|
|
38
|
+
transports: [new transports.File({ filename: logPath }), new transports.Console()],
|
|
39
|
+
});
|
|
50
40
|
|
|
51
|
-
let args
|
|
52
|
-
let logString
|
|
41
|
+
let args;
|
|
42
|
+
let logString;
|
|
53
43
|
|
|
54
44
|
return {
|
|
55
45
|
log: function () {
|
|
56
|
-
args = slice.call(arguments)
|
|
57
|
-
logString = getString(args)
|
|
58
|
-
logString && logger.log('info', logString)
|
|
46
|
+
args = slice.call(arguments);
|
|
47
|
+
logString = getString(args);
|
|
48
|
+
logString && logger.log('info', logString);
|
|
59
49
|
},
|
|
60
50
|
warn: function () {
|
|
61
|
-
args = slice.call(arguments)
|
|
62
|
-
logString = getString(args)
|
|
63
|
-
logString && logger.log('warn', logString)
|
|
51
|
+
args = slice.call(arguments);
|
|
52
|
+
logString = getString(args);
|
|
53
|
+
logString && logger.log('warn', logString);
|
|
64
54
|
},
|
|
65
55
|
error: function () {
|
|
66
|
-
args = slice.call(arguments)
|
|
67
|
-
logString = getString(args)
|
|
68
|
-
logString && logger.log('error', logString)
|
|
56
|
+
args = slice.call(arguments);
|
|
57
|
+
logString = getString(args);
|
|
58
|
+
logString && logger.log('error', logString);
|
|
69
59
|
},
|
|
70
60
|
debug: function () {
|
|
71
|
-
args = slice.call(arguments)
|
|
72
|
-
logString = getString(args)
|
|
73
|
-
logString && logger.log('debug', logString)
|
|
61
|
+
args = slice.call(arguments);
|
|
62
|
+
logString = getString(args);
|
|
63
|
+
logString && logger.log('debug', logString);
|
|
74
64
|
},
|
|
75
|
-
}
|
|
65
|
+
};
|
|
76
66
|
}
|
|
77
67
|
|
|
78
|
-
exports.success = init('success').log
|
|
68
|
+
exports.success = init('success').log;
|
|
79
69
|
if (NODE_ENV === 'test') {
|
|
80
|
-
exports.error = init('warn').warn
|
|
70
|
+
exports.error = init('warn').warn;
|
|
81
71
|
} else {
|
|
82
|
-
exports.error = init('error').error
|
|
72
|
+
exports.error = init('error').error;
|
|
83
73
|
}
|
|
84
|
-
exports.warn = init('warn').warn
|
|
74
|
+
exports.warn = init('warn').warn;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
'use strict'
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
3
|
exports.getEntryObj = (fields, obj) => {
|
|
4
|
-
let entryObj = {}
|
|
5
|
-
fields.forEach(field => {
|
|
6
|
-
entryObj[field] = obj[field]
|
|
7
|
-
})
|
|
8
|
-
return entryObj
|
|
9
|
-
}
|
|
4
|
+
let entryObj = {};
|
|
5
|
+
fields.forEach((field) => {
|
|
6
|
+
entryObj[field] = obj[field];
|
|
7
|
+
});
|
|
8
|
+
return entryObj;
|
|
9
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
'use strict'
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
module.exports = promise => promise.then(res => [null, res]).catch(err => [err])
|
|
3
|
+
module.exports = (promise) => promise.then((res) => [null, res]).catch((err) => [err]);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/* eslint-disable camelcase */
|
|
2
|
-
'use strict'
|
|
2
|
+
'use strict';
|
|
3
3
|
|
|
4
|
-
const {version, defaultDataType, actions} = require('./constants')
|
|
4
|
+
const { version, defaultDataType, actions } = require('./constants');
|
|
5
5
|
|
|
6
6
|
exports.getSchema = (field, subAction) => {
|
|
7
|
-
const {EDIT_FIELD, DELETE_FIELD} = actions
|
|
7
|
+
const { EDIT_FIELD, DELETE_FIELD } = actions;
|
|
8
8
|
|
|
9
9
|
const schema = {
|
|
10
10
|
display_name: field,
|
|
@@ -17,19 +17,19 @@ exports.getSchema = (field, subAction) => {
|
|
|
17
17
|
// isDelete: !!isDelete,
|
|
18
18
|
isDelete: subAction === DELETE_FIELD,
|
|
19
19
|
isEdit: subAction === EDIT_FIELD,
|
|
20
|
-
}
|
|
21
|
-
return schema
|
|
22
|
-
}
|
|
20
|
+
};
|
|
21
|
+
return schema;
|
|
22
|
+
};
|
|
23
23
|
|
|
24
|
-
exports.getUid = data => data.split(' ').join('_').toLowerCase()
|
|
24
|
+
exports.getUid = (data) => data.split(' ').join('_').toLowerCase();
|
|
25
25
|
|
|
26
|
-
exports.getMandatoryVal = data => data.toLowerCase() === 'title' || data.toLowerCase() === 'url'
|
|
26
|
+
exports.getMandatoryVal = (data) => data.toLowerCase() === 'title' || data.toLowerCase() === 'url';
|
|
27
27
|
|
|
28
|
-
exports.getUniqueVal = data => data.toLowerCase() === 'title' || data.toLowerCase() === 'url'
|
|
28
|
+
exports.getUniqueVal = (data) => data.toLowerCase() === 'title' || data.toLowerCase() === 'url';
|
|
29
29
|
|
|
30
|
-
exports.getFieldMetaData = data => {
|
|
30
|
+
exports.getFieldMetaData = (data) => {
|
|
31
31
|
return {
|
|
32
32
|
_default: this.getMandatoryVal(data),
|
|
33
33
|
version,
|
|
34
|
-
}
|
|
35
|
-
}
|
|
34
|
+
};
|
|
35
|
+
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
'use strict'
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
const {success} = require('./logger')
|
|
4
|
-
const {successMessageHandler} = require('./constants')
|
|
3
|
+
const { success } = require('./logger');
|
|
4
|
+
const { successMessageHandler } = require('./constants');
|
|
5
5
|
|
|
6
6
|
module.exports = (data, type, method) => {
|
|
7
7
|
if (data && type && method) {
|
|
8
8
|
//success(`Successfully ${successMessageHandler[method]} ${type}: ${data}`);
|
|
9
9
|
} else {
|
|
10
|
-
success(`${type} successfully completed`)
|
|
10
|
+
success(`${type} successfully completed`);
|
|
11
11
|
}
|
|
12
|
-
}
|
|
12
|
+
};
|
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
'use strict'
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
3
|
class ApiError {
|
|
4
4
|
validate(data) {
|
|
5
5
|
if (data.payload.apiError) {
|
|
6
|
-
return [
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
return [
|
|
7
|
+
{
|
|
8
|
+
...data,
|
|
9
|
+
message: `${data.payload.apiError.error_message}`,
|
|
10
|
+
},
|
|
11
|
+
];
|
|
10
12
|
}
|
|
11
|
-
return []
|
|
13
|
+
return [];
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
isApplicable(action) {
|
|
15
|
-
return action.type === 'apiError'
|
|
17
|
+
return action.type === 'apiError';
|
|
16
18
|
}
|
|
17
19
|
}
|
|
18
|
-
module.exports = ApiError
|
|
20
|
+
module.exports = ApiError;
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
'use strict'
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
const {keys} = Object
|
|
3
|
+
const { keys } = Object;
|
|
4
4
|
class BaseValidator {
|
|
5
5
|
commonValidate(properties, data) {
|
|
6
|
-
const errors = []
|
|
7
|
-
const opts = data.payload.options
|
|
8
|
-
const dataKeys = keys(opts)
|
|
6
|
+
const errors = [];
|
|
7
|
+
const opts = data.payload.options;
|
|
8
|
+
const dataKeys = keys(opts);
|
|
9
9
|
|
|
10
10
|
for (let i = 0; i < properties.length; i++) {
|
|
11
|
-
let prop = properties[i]
|
|
11
|
+
let prop = properties[i];
|
|
12
12
|
// Check if property is mandatory but not present in user specified params
|
|
13
13
|
if (prop.mandatory && !dataKeys.includes(prop.name)) {
|
|
14
|
-
errors.push({...data, message: `${prop.name} is required.`})
|
|
14
|
+
errors.push({ ...data, message: `${prop.name} is required.` });
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
if (prop.name in opts) {
|
|
18
|
-
const dataType = this.getDataType(opts[prop.name])
|
|
18
|
+
const dataType = this.getDataType(opts[prop.name]);
|
|
19
19
|
if (dataType !== prop.type) {
|
|
20
|
-
errors.push({...data, message: `${prop.name} is a ${dataType} type`})
|
|
20
|
+
errors.push({ ...data, message: `${prop.name} is a ${dataType} type` });
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
if (prop.dependsOn && !(prop.dependsOn in opts) && opts[prop.name]) {
|
|
24
|
-
errors.push({...data, message: `${prop.dependsOn} is required with ${prop.name}`})
|
|
24
|
+
errors.push({ ...data, message: `${prop.dependsOn} is required with ${prop.name}` });
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
return errors
|
|
29
|
+
return errors;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
getDataType(data) {
|
|
33
33
|
if (Array.isArray(data)) {
|
|
34
|
-
return 'array'
|
|
34
|
+
return 'array';
|
|
35
35
|
}
|
|
36
|
-
return typeof data
|
|
36
|
+
return typeof data;
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
module.exports = BaseValidator
|
|
39
|
+
module.exports = BaseValidator;
|
|
@@ -1,58 +1,54 @@
|
|
|
1
|
-
'use strict'
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
const {keys} = Object
|
|
3
|
+
const { keys } = Object;
|
|
4
4
|
// Utils
|
|
5
|
-
const {map: _map, constants} = require('../utils')
|
|
5
|
+
const { map: _map, constants } = require('../utils');
|
|
6
6
|
// Properties
|
|
7
|
-
const {getMapInstance, get} = _map
|
|
8
|
-
const {contentTypeProperties} = constants
|
|
7
|
+
const { getMapInstance, get } = _map;
|
|
8
|
+
const { contentTypeProperties } = constants;
|
|
9
9
|
|
|
10
|
-
const mandatoryKeys = [
|
|
11
|
-
'uid',
|
|
12
|
-
'title',
|
|
13
|
-
'description',
|
|
14
|
-
]
|
|
10
|
+
const mandatoryKeys = ['uid', 'title', 'description'];
|
|
15
11
|
|
|
16
12
|
class CreateContentTypeValidator {
|
|
17
13
|
constructor() {
|
|
18
14
|
// super();
|
|
19
|
-
this.errors = []
|
|
15
|
+
this.errors = [];
|
|
20
16
|
}
|
|
21
17
|
|
|
22
18
|
validate(data) {
|
|
23
19
|
// Validate the latest updated object in the global map object
|
|
24
|
-
const mapInstance = getMapInstance()
|
|
25
|
-
const mapObj = get(data.payload.contentTypeId, mapInstance)
|
|
26
|
-
const actionObj = mapObj[data.payload.action].content_type
|
|
27
|
-
const userProvidedFields = keys(actionObj)
|
|
20
|
+
const mapInstance = getMapInstance();
|
|
21
|
+
const mapObj = get(data.payload.contentTypeId, mapInstance);
|
|
22
|
+
const actionObj = mapObj[data.payload.action].content_type;
|
|
23
|
+
const userProvidedFields = keys(actionObj);
|
|
28
24
|
|
|
29
25
|
for (const key of mandatoryKeys) {
|
|
30
26
|
if (!keys(actionObj).includes(key) || !actionObj[key]) {
|
|
31
|
-
data = {...data, message: `${key} is missing.`}
|
|
32
|
-
this.errors.push(data)
|
|
27
|
+
data = { ...data, message: `${key} is missing.` };
|
|
28
|
+
this.errors.push(data);
|
|
33
29
|
}
|
|
34
30
|
}
|
|
35
31
|
|
|
36
32
|
// TODO: Fix error messages
|
|
37
|
-
const propertyNames = this.getPropertyNames()
|
|
33
|
+
const propertyNames = this.getPropertyNames();
|
|
38
34
|
|
|
39
35
|
for (let i = 0; i < userProvidedFields.length; i++) {
|
|
40
|
-
let key = userProvidedFields[i]
|
|
36
|
+
let key = userProvidedFields[i];
|
|
41
37
|
if (!propertyNames.includes(key)) {
|
|
42
|
-
data = {...data, message: `${key} is not valid property.`}
|
|
43
|
-
this.errors.push(data)
|
|
38
|
+
data = { ...data, message: `${key} is not valid property.` };
|
|
39
|
+
this.errors.push(data);
|
|
44
40
|
}
|
|
45
41
|
}
|
|
46
|
-
return this.errors
|
|
42
|
+
return this.errors;
|
|
47
43
|
}
|
|
48
44
|
|
|
49
45
|
isApplicable(action) {
|
|
50
|
-
return action.type === 'create'
|
|
46
|
+
return action.type === 'create';
|
|
51
47
|
}
|
|
52
48
|
|
|
53
49
|
getPropertyNames() {
|
|
54
|
-
return contentTypeProperties
|
|
50
|
+
return contentTypeProperties;
|
|
55
51
|
}
|
|
56
52
|
}
|
|
57
53
|
|
|
58
|
-
module.exports = CreateContentTypeValidator
|
|
54
|
+
module.exports = CreateContentTypeValidator;
|
|
@@ -1,56 +1,53 @@
|
|
|
1
|
-
'use strict'
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
const {keys} = Object
|
|
3
|
+
const { keys } = Object;
|
|
4
4
|
|
|
5
5
|
// Utils
|
|
6
|
-
const {map: _map, constants} = require('../utils')
|
|
6
|
+
const { map: _map, constants } = require('../utils');
|
|
7
7
|
// Properties
|
|
8
|
-
const {getMapInstance, get} = _map
|
|
9
|
-
const {contentTypeProperties} = constants
|
|
8
|
+
const { getMapInstance, get } = _map;
|
|
9
|
+
const { contentTypeProperties } = constants;
|
|
10
10
|
|
|
11
|
-
const mandatoryKeys = [
|
|
12
|
-
'uid',
|
|
13
|
-
'title',
|
|
14
|
-
]
|
|
11
|
+
const mandatoryKeys = ['uid', 'title'];
|
|
15
12
|
|
|
16
13
|
class EditContentTypeValidator {
|
|
17
14
|
constructor() {
|
|
18
|
-
this.errors = []
|
|
15
|
+
this.errors = [];
|
|
19
16
|
}
|
|
20
17
|
|
|
21
18
|
validate(data) {
|
|
22
19
|
// Validate the latest updated object in the global map object
|
|
23
|
-
const mapInstance = getMapInstance()
|
|
24
|
-
const mapObj = get(data.payload.contentTypeId, mapInstance)
|
|
25
|
-
const actionObj = mapObj[data.payload.action].content_type
|
|
26
|
-
const userProvidedFields = keys(actionObj)
|
|
20
|
+
const mapInstance = getMapInstance();
|
|
21
|
+
const mapObj = get(data.payload.contentTypeId, mapInstance);
|
|
22
|
+
const actionObj = mapObj[data.payload.action].content_type;
|
|
23
|
+
const userProvidedFields = keys(actionObj);
|
|
27
24
|
|
|
28
25
|
for (const key of mandatoryKeys) {
|
|
29
26
|
if (!userProvidedFields.includes(key)) {
|
|
30
|
-
data = {...data, message: `${key} is missing.`}
|
|
31
|
-
this.errors.push(data)
|
|
27
|
+
data = { ...data, message: `${key} is missing.` };
|
|
28
|
+
this.errors.push(data);
|
|
32
29
|
}
|
|
33
30
|
}
|
|
34
31
|
// TODO: Fix error messages
|
|
35
|
-
const propertyNames = this.getPropertyNames()
|
|
32
|
+
const propertyNames = this.getPropertyNames();
|
|
36
33
|
|
|
37
34
|
for (let i = 0; i < userProvidedFields.length; i++) {
|
|
38
|
-
let key = userProvidedFields[i]
|
|
35
|
+
let key = userProvidedFields[i];
|
|
39
36
|
if (!propertyNames.includes(key)) {
|
|
40
|
-
data = {...data, message: `${key} is not valid property.`}
|
|
41
|
-
this.errors.push(data)
|
|
37
|
+
data = { ...data, message: `${key} is not valid property.` };
|
|
38
|
+
this.errors.push(data);
|
|
42
39
|
}
|
|
43
40
|
}
|
|
44
|
-
return this.errors
|
|
41
|
+
return this.errors;
|
|
45
42
|
}
|
|
46
43
|
|
|
47
44
|
isApplicable(action) {
|
|
48
|
-
return action.type === 'edit'
|
|
45
|
+
return action.type === 'edit';
|
|
49
46
|
}
|
|
50
47
|
|
|
51
48
|
getPropertyNames() {
|
|
52
|
-
return contentTypeProperties
|
|
49
|
+
return contentTypeProperties;
|
|
53
50
|
}
|
|
54
51
|
}
|
|
55
52
|
|
|
56
|
-
module.exports = EditContentTypeValidator
|
|
53
|
+
module.exports = EditContentTypeValidator;
|
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
'use strict'
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
3
|
class FieldValidator {
|
|
4
4
|
validate(data) {
|
|
5
5
|
if (data.payload.field) {
|
|
6
|
-
return [
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
return [
|
|
7
|
+
{
|
|
8
|
+
...data,
|
|
9
|
+
message: data.payload.field.message,
|
|
10
|
+
},
|
|
11
|
+
];
|
|
10
12
|
}
|
|
11
|
-
return []
|
|
13
|
+
return [];
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
isApplicable(action) {
|
|
15
|
-
return action.type === 'field'
|
|
17
|
+
return action.type === 'field';
|
|
16
18
|
}
|
|
17
19
|
}
|
|
18
20
|
|
|
19
|
-
module.exports = FieldValidator
|
|
21
|
+
module.exports = FieldValidator;
|
package/src/validators/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
'use strict'
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
3
|
module.exports = {
|
|
4
4
|
CreateContentTypeValidator: require('./create-content-type-validator'),
|
|
@@ -8,4 +8,4 @@ module.exports = {
|
|
|
8
8
|
_TypeError: require('./type-error'),
|
|
9
9
|
ApiError: require('./api-error'),
|
|
10
10
|
MigrationError: require('./migration-error'),
|
|
11
|
-
}
|
|
11
|
+
};
|
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
'use strict'
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
3
|
class MigrationError {
|
|
4
4
|
validate(data) {
|
|
5
5
|
if (data.payload.migrationError) {
|
|
6
|
-
return [
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
return [
|
|
7
|
+
{
|
|
8
|
+
...data,
|
|
9
|
+
message: `${data.payload.migrationError.migrationError.message}`,
|
|
10
|
+
},
|
|
11
|
+
];
|
|
10
12
|
}
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
isApplicable(action) {
|
|
14
|
-
return action.type === 'migrationError'
|
|
16
|
+
return action.type === 'migrationError';
|
|
15
17
|
}
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
module.exports = MigrationError
|
|
20
|
+
module.exports = MigrationError;
|
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
'use strict'
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
3
|
class SchemaValidator {
|
|
4
4
|
validate(data) {
|
|
5
|
-
const {fromField, toField, toReferenceField, deriveField} = data.payload
|
|
5
|
+
const { fromField, toField, toReferenceField, deriveField } = data.payload;
|
|
6
6
|
// const fieldsToValidate = [payload]
|
|
7
7
|
if (fromField || toField || toReferenceField || deriveField) {
|
|
8
|
-
return [
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
return [
|
|
9
|
+
{
|
|
10
|
+
...data,
|
|
11
|
+
message: `${fromField || toField || toReferenceField || deriveField} does not exist on schema.`,
|
|
12
|
+
},
|
|
13
|
+
];
|
|
12
14
|
}
|
|
13
|
-
return []
|
|
15
|
+
return [];
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
isApplicable(action) {
|
|
17
|
-
return action.type === 'schema'
|
|
19
|
+
return action.type === 'schema';
|
|
18
20
|
}
|
|
19
21
|
}
|
|
20
22
|
|
|
21
|
-
module.exports = SchemaValidator
|
|
23
|
+
module.exports = SchemaValidator;
|
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
'use strict'
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
3
|
class _TypeError {
|
|
4
|
-
constructor() {
|
|
5
|
-
}
|
|
4
|
+
constructor() {}
|
|
6
5
|
|
|
7
6
|
validate(data) {
|
|
8
7
|
if (data.payload.typeErrors) {
|
|
9
|
-
return [
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
return [
|
|
9
|
+
{
|
|
10
|
+
...data,
|
|
11
|
+
message: `${data.payload.typeErrors[0]} is not a valid function`,
|
|
12
|
+
},
|
|
13
|
+
];
|
|
13
14
|
}
|
|
14
|
-
return []
|
|
15
|
+
return [];
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
isApplicable(action) {
|
|
18
|
-
return action.type === 'typeError'
|
|
19
|
+
return action.type === 'typeError';
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
|
-
module.exports = _TypeError
|
|
22
|
+
module.exports = _TypeError;
|