@contentstack/cli-migration 1.10.3 → 1.11.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 (183) hide show
  1. package/README.md +2 -2
  2. package/lib/actions/action-list.d.ts +8 -0
  3. package/lib/actions/action-list.js +31 -0
  4. package/lib/actions/action-list.js.map +1 -0
  5. package/lib/actions/index.d.ts +180 -0
  6. package/lib/actions/index.js +207 -0
  7. package/lib/actions/index.js.map +1 -0
  8. package/lib/commands/cm/stacks/migration.d.ts +14 -0
  9. package/lib/commands/cm/stacks/migration.js +274 -0
  10. package/lib/commands/cm/stacks/migration.js.map +1 -0
  11. package/lib/config/api-config.d.ts +13 -0
  12. package/lib/config/api-config.js +19 -0
  13. package/lib/config/api-config.js.map +1 -0
  14. package/lib/config/default-options.d.ts +5 -0
  15. package/lib/config/default-options.js +8 -0
  16. package/lib/config/default-options.js.map +1 -0
  17. package/lib/config/index.d.ts +4 -0
  18. package/lib/config/index.js +11 -0
  19. package/lib/config/index.js.map +1 -0
  20. package/lib/config/master-locale.d.ts +7 -0
  21. package/lib/config/master-locale.js +11 -0
  22. package/lib/config/master-locale.js.map +1 -0
  23. package/lib/modules/base.d.ts +39 -0
  24. package/lib/modules/base.js +84 -0
  25. package/lib/modules/base.js.map +1 -0
  26. package/lib/modules/content-types.d.ts +61 -0
  27. package/lib/modules/content-types.js +173 -0
  28. package/lib/modules/content-types.js.map +1 -0
  29. package/lib/modules/fields.d.ts +179 -0
  30. package/lib/modules/fields.js +292 -0
  31. package/lib/modules/fields.js.map +1 -0
  32. package/lib/modules/index.d.ts +5 -0
  33. package/lib/modules/index.js +13 -0
  34. package/lib/modules/index.js.map +1 -0
  35. package/lib/modules/locale.d.ts +6 -0
  36. package/lib/modules/locale.js +27 -0
  37. package/lib/modules/locale.js.map +1 -0
  38. package/lib/modules/migration.d.ts +50 -0
  39. package/lib/modules/migration.js +109 -0
  40. package/lib/modules/migration.js.map +1 -0
  41. package/lib/modules/parser.d.ts +3 -0
  42. package/lib/modules/parser.js +93 -0
  43. package/lib/modules/parser.js.map +1 -0
  44. package/lib/services/content-types.d.ts +25 -0
  45. package/lib/services/content-types.js +302 -0
  46. package/lib/services/content-types.js.map +1 -0
  47. package/lib/services/index.d.ts +3 -0
  48. package/lib/services/index.js +9 -0
  49. package/lib/services/index.js.map +1 -0
  50. package/lib/services/locales.d.ts +6 -0
  51. package/lib/services/locales.js +68 -0
  52. package/lib/services/locales.js.map +1 -0
  53. package/lib/utils/auto-retry.d.ts +2 -0
  54. package/lib/utils/auto-retry.js +30 -0
  55. package/lib/utils/auto-retry.js.map +1 -0
  56. package/lib/utils/callsite.d.ts +2 -0
  57. package/lib/utils/callsite.js +21 -0
  58. package/lib/utils/callsite.js.map +1 -0
  59. package/lib/utils/constants.d.ts +108 -0
  60. package/lib/utils/constants.js +206 -0
  61. package/lib/utils/constants.js.map +1 -0
  62. package/lib/utils/contentstack-sdk.d.ts +7 -0
  63. package/lib/utils/contentstack-sdk.js +53 -0
  64. package/lib/utils/contentstack-sdk.js.map +1 -0
  65. package/lib/utils/error-helper.d.ts +2 -0
  66. package/lib/utils/error-helper.js +102 -0
  67. package/lib/utils/error-helper.js.map +1 -0
  68. package/lib/utils/fs-helper.d.ts +4 -0
  69. package/lib/utils/fs-helper.js +37 -0
  70. package/lib/utils/fs-helper.js.map +1 -0
  71. package/lib/utils/get-batches.d.ts +2 -0
  72. package/lib/utils/get-batches.js +8 -0
  73. package/lib/utils/get-batches.js.map +1 -0
  74. package/lib/utils/get-config.d.ts +6 -0
  75. package/lib/utils/get-config.js +11 -0
  76. package/lib/utils/get-config.js.map +1 -0
  77. package/lib/utils/group-by.d.ts +1 -0
  78. package/lib/utils/group-by.js +41 -0
  79. package/lib/utils/group-by.js.map +1 -0
  80. package/lib/utils/index.d.ts +18 -0
  81. package/lib/utils/index.js +39 -0
  82. package/lib/utils/index.js.map +1 -0
  83. package/lib/utils/logger.d.ts +4 -0
  84. package/lib/utils/logger.js +68 -0
  85. package/lib/utils/logger.js.map +1 -0
  86. package/lib/utils/map.d.ts +7 -0
  87. package/lib/utils/map.js +40 -0
  88. package/lib/utils/map.js.map +1 -0
  89. package/lib/utils/migration-logger.d.ts +7 -0
  90. package/lib/utils/migration-logger.js +26 -0
  91. package/lib/utils/migration-logger.js.map +1 -0
  92. package/lib/utils/modules.d.ts +2 -0
  93. package/lib/utils/modules.js +118 -0
  94. package/lib/utils/modules.js.map +1 -0
  95. package/lib/utils/object-helper.d.ts +1 -0
  96. package/lib/utils/object-helper.js +12 -0
  97. package/lib/utils/object-helper.js.map +1 -0
  98. package/lib/utils/request.d.ts +9 -0
  99. package/lib/utils/request.js +78 -0
  100. package/lib/utils/request.js.map +1 -0
  101. package/lib/utils/safe-promise.d.ts +2 -0
  102. package/lib/utils/safe-promise.js +6 -0
  103. package/lib/utils/safe-promise.js.map +1 -0
  104. package/lib/utils/schema-helper.d.ts +5 -0
  105. package/lib/utils/schema-helper.js +36 -0
  106. package/lib/utils/schema-helper.js.map +1 -0
  107. package/lib/utils/success-handler.d.ts +2 -0
  108. package/lib/utils/success-handler.js +12 -0
  109. package/lib/utils/success-handler.js.map +1 -0
  110. package/lib/validators/api-error.d.ts +4 -0
  111. package/lib/validators/api-error.js +17 -0
  112. package/lib/validators/api-error.js.map +1 -0
  113. package/lib/validators/base-validator.d.ts +4 -0
  114. package/lib/validators/base-validator.js +34 -0
  115. package/lib/validators/base-validator.js.map +1 -0
  116. package/lib/validators/create-content-type-validator.d.ts +7 -0
  117. package/lib/validators/create-content-type-validator.js +45 -0
  118. package/lib/validators/create-content-type-validator.js.map +1 -0
  119. package/lib/validators/edit-content-type-validator.d.ts +7 -0
  120. package/lib/validators/edit-content-type-validator.js +44 -0
  121. package/lib/validators/edit-content-type-validator.js.map +1 -0
  122. package/lib/validators/field-validator.d.ts +4 -0
  123. package/lib/validators/field-validator.js +17 -0
  124. package/lib/validators/field-validator.js.map +1 -0
  125. package/lib/validators/index.d.ts +8 -0
  126. package/lib/validators/index.js +19 -0
  127. package/lib/validators/index.js.map +1 -0
  128. package/lib/validators/migration-error.d.ts +4 -0
  129. package/lib/validators/migration-error.js +16 -0
  130. package/lib/validators/migration-error.js.map +1 -0
  131. package/lib/validators/schema-validator.d.ts +4 -0
  132. package/lib/validators/schema-validator.js +19 -0
  133. package/lib/validators/schema-validator.js.map +1 -0
  134. package/lib/validators/type-error.d.ts +5 -0
  135. package/lib/validators/type-error.js +18 -0
  136. package/lib/validators/type-error.js.map +1 -0
  137. package/oclif.manifest.json +145 -0
  138. package/package.json +21 -11
  139. package/src/actions/action-list.js +0 -32
  140. package/src/actions/index.js +0 -217
  141. package/src/commands/cm/stacks/migration.js +0 -316
  142. package/src/config/api-config.js +0 -18
  143. package/src/config/default-options.js +0 -7
  144. package/src/config/index.js +0 -7
  145. package/src/config/master-locale.js +0 -10
  146. package/src/modules/base.js +0 -95
  147. package/src/modules/content-types.js +0 -208
  148. package/src/modules/fields.js +0 -339
  149. package/src/modules/index.js +0 -8
  150. package/src/modules/locale.js +0 -33
  151. package/src/modules/migration.js +0 -112
  152. package/src/modules/parser.js +0 -105
  153. package/src/services/content-types.js +0 -317
  154. package/src/services/index.js +0 -6
  155. package/src/services/locales.js +0 -71
  156. package/src/utils/auto-retry.js +0 -32
  157. package/src/utils/callsite.js +0 -23
  158. package/src/utils/constants.js +0 -223
  159. package/src/utils/contentstack-sdk.js +0 -70
  160. package/src/utils/error-helper.js +0 -105
  161. package/src/utils/fs-helper.js +0 -29
  162. package/src/utils/get-batches.js +0 -7
  163. package/src/utils/get-config.js +0 -13
  164. package/src/utils/group-by.js +0 -38
  165. package/src/utils/index.js +0 -21
  166. package/src/utils/logger.js +0 -75
  167. package/src/utils/map.js +0 -40
  168. package/src/utils/migration-logger.js +0 -21
  169. package/src/utils/modules.js +0 -134
  170. package/src/utils/object-helper.js +0 -9
  171. package/src/utils/request.js +0 -95
  172. package/src/utils/safe-promise.js +0 -3
  173. package/src/utils/schema-helper.js +0 -35
  174. package/src/utils/success-handler.js +0 -12
  175. package/src/validators/api-error.js +0 -20
  176. package/src/validators/base-validator.js +0 -39
  177. package/src/validators/create-content-type-validator.js +0 -54
  178. package/src/validators/edit-content-type-validator.js +0 -53
  179. package/src/validators/field-validator.js +0 -21
  180. package/src/validators/index.js +0 -11
  181. package/src/validators/migration-error.js +0 -20
  182. package/src/validators/schema-validator.js +0 -23
  183. package/src/validators/type-error.js +0 -22
@@ -1,134 +0,0 @@
1
- const fs = require('fs');
2
- const { spawnSync } = require('child_process');
3
- const path = require('path');
4
- const { sanitizePath } = require('@contentstack/cli-utilities');
5
- const os = require('os');
6
- const { builtinModules } = require('module');
7
-
8
- const internalModules = new Set(builtinModules);
9
-
10
- function checkWritePermissionToDirectory(directory) {
11
- try {
12
- fs.accessSync(directory, fs.constants.W_OK);
13
- return true;
14
- } catch (err) {
15
- console.log(`Permission denied. You do not have the necessary write access for this directory.`);
16
- return false;
17
- }
18
- }
19
-
20
- function doesPackageJsonExist(directory) {
21
- return fs.existsSync(path.join(sanitizePath(directory), 'package.json'));
22
- }
23
-
24
- function scanDirectory(directory) {
25
- return fs.readdirSync(directory);
26
- }
27
-
28
- function scanFileForDependencies(directory, files) {
29
- const dependencies = new Set();
30
-
31
- files.forEach((file) => {
32
- const filePath = path.join(sanitizePath(directory), sanitizePath(file));
33
- if (path.extname(filePath) === '.js') {
34
- const fileContent = fs.readFileSync(filePath, 'utf-8');
35
- findModulesSync(fileContent).forEach((dep) => dependencies.add(dep));
36
- }
37
- });
38
-
39
- return [...dependencies];
40
- }
41
-
42
- function createPackageJson(directory) {
43
- const templateString = `{
44
- "name": "MigrationPackage",
45
- "version": "1.0.0",
46
- "main": "",
47
- "scripts": {},
48
- "keywords": [],
49
- "author": "",
50
- "license": "ISC",
51
- "description": ""
52
- }`;
53
-
54
- fs.writeFileSync(path.join(sanitizePath(directory), 'package.json'), templateString);
55
- }
56
-
57
- function installDependencies(dependencies, directory) {
58
- const installedDependencies = new Set();
59
-
60
- dependencies.forEach((dep) => {
61
- if (!internalModules.has(dep)) {
62
- const pkg = dep.startsWith('@') ? dep : dep.split('/')[0];
63
- if (!installedDependencies.has(pkg)) {
64
- executeShellCommand(pkg, directory);
65
- installedDependencies.add(pkg);
66
- }
67
- }
68
- });
69
- }
70
-
71
- function executeShellCommand(pkg, directory = '') {
72
- try {
73
- const result = spawnSync(`npm`, ['i', pkg], { stdio: 'inherit', cwd: directory, shell: false });
74
- if (result?.error) throw result.error;
75
- console.log(`Command executed successfully`);
76
- } catch (error) {
77
- console.error(`Command execution failed. Error: ${error?.message}`);
78
- }
79
- }
80
- async function installModules(filePath, multiple) {
81
- const files = multiple ? [] : [path.basename(filePath)];
82
- const dirPath = multiple ? filePath : path.dirname(filePath);
83
-
84
- if (checkWritePermissionToDirectory(dirPath)) {
85
- if (multiple) {
86
- files.push(...scanDirectory(dirPath));
87
- }
88
-
89
- if (files.length === 0) {
90
- console.log(`Error: Could not locate files needed to create package.json. Exiting the process.`);
91
- return true;
92
- }
93
-
94
- const dependencies = scanFileForDependencies(dirPath, files);
95
-
96
- if (!doesPackageJsonExist(dirPath)) {
97
- console.log(`package.json not found. Creating a new package.json...`);
98
- createPackageJson(dirPath);
99
- }
100
-
101
- installDependencies(dependencies, dirPath);
102
- } else {
103
- console.log(`You don't have write permission to the directory`);
104
- return false;
105
- }
106
-
107
- console.log(`All dependencies installed successfully.`);
108
- return true;
109
- }
110
-
111
- function findModulesSync(data) {
112
- try {
113
- const requireRegex = /require\(['"`](.*?)['"`]\)/g;
114
- const importRegex = /import\s+(?:(?:[\w*\s{},]*)\s+from\s+)?['"`](.*?)['"`]/g;
115
-
116
- const modules = new Set();
117
- let match;
118
-
119
- while ((match = requireRegex.exec(data)) !== null) {
120
- modules.add(match[1]);
121
- }
122
-
123
- while ((match = importRegex.exec(data)) !== null) {
124
- modules.add(match[1]);
125
- }
126
-
127
- return [...modules];
128
- } catch (error) {
129
- console.error(`Error reading file: ${error.message}`);
130
- return [];
131
- }
132
- }
133
-
134
- module.exports = installModules;
@@ -1,9 +0,0 @@
1
- 'use strict';
2
-
3
- exports.getEntryObj = (fields, obj) => {
4
- let entryObj = {};
5
- fields.forEach((field) => {
6
- entryObj[field] = obj[field];
7
- });
8
- return entryObj;
9
- };
@@ -1,95 +0,0 @@
1
- 'use strict'
2
-
3
- // Dependencies
4
- const {request} = require('https')
5
- const {stringify, parse} = JSON
6
-
7
- // Map helper
8
- const {getMapInstance, getDataWithAction} = require('./map')
9
-
10
- // constants
11
- const {actions, nonWritableMethods} = require('./constants')
12
-
13
- // Properties
14
- const {DELETE_CT} = actions
15
-
16
- module.exports = ({
17
- hostname,
18
- path,
19
- headers,
20
- method,
21
- id,
22
- action,
23
- }) => {
24
- let options = {
25
- hostname,
26
- path,
27
- headers,
28
- method,
29
- id,
30
- action,
31
- }
32
- return _data => {
33
- // get data here using id and action
34
- let data = getData(_data, id, action, method)
35
- // Special handling for non writable methods
36
- options = getNewOptions(options, data, action, method)
37
-
38
- return new Promise((resolve, reject) => {
39
- const req = request(options, res => {
40
- let response = ''
41
-
42
- res.on('data', _res => {
43
- response += _res.toString()
44
- })
45
-
46
- res.on('end', () => {
47
- try {
48
- response = parse(response)
49
- resolve(response)
50
- } catch (err) {
51
- reject('Error while parsing response!')
52
- // throw new Error('Error while parsing response!');
53
- }
54
- })
55
- })
56
-
57
- req.on('error', err => {
58
- reject(err)
59
- })
60
-
61
- !nonWritableMethods.includes(method) && req.write(data)
62
- req.end()
63
- })
64
- }
65
- }
66
-
67
- function getData(_data, id, action, method) {
68
- if (method === 'GET') return
69
- // if (!nonWritableMethods.includes(method)) {
70
- let mapInstance = getMapInstance()
71
-
72
- let data = _data ? _data : getDataWithAction(id, mapInstance, action)
73
- return stringify(data)
74
- }
75
-
76
- function getNewOptions(options, data, action, method) {
77
- // Special handling for delete method
78
- if (action === DELETE_CT) {
79
- try {
80
- data = parse(data)
81
- } catch (err) {
82
- throw 'Error while parsing data for delete operation'
83
- }
84
- options.path = `${options.path}?force=${data.content_type.force}`
85
- }
86
-
87
- if (!nonWritableMethods.includes(method)) {
88
- options.headers['Content-Length'] = data.length
89
- } else {
90
- delete options.headers['Content-Type']
91
- delete options.headers['Content-Length']
92
- }
93
-
94
- return options
95
- }
@@ -1,3 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = (promise) => promise.then((res) => [null, res]).catch((err) => [err]);
@@ -1,35 +0,0 @@
1
- /* eslint-disable camelcase */
2
- 'use strict';
3
-
4
- const { version, defaultDataType, actions } = require('./constants');
5
-
6
- exports.getSchema = (field, subAction) => {
7
- const { EDIT_FIELD, DELETE_FIELD } = actions;
8
-
9
- const schema = {
10
- display_name: field,
11
- uid: this.getUid(field),
12
- data_type: defaultDataType, // This will be overridden if user specifies data type
13
- mandatory: this.getMandatoryVal(field),
14
- unique: this.getUniqueVal(field),
15
- field_metadata: this.getFieldMetaData(field),
16
- non_localizable: false,
17
- // isDelete: !!isDelete,
18
- isDelete: subAction === DELETE_FIELD,
19
- isEdit: subAction === EDIT_FIELD,
20
- };
21
- return schema;
22
- };
23
-
24
- exports.getUid = (data) => data.split(' ').join('_').toLowerCase();
25
-
26
- exports.getMandatoryVal = (data) => data.toLowerCase() === 'title' || data.toLowerCase() === 'url';
27
-
28
- exports.getUniqueVal = (data) => data.toLowerCase() === 'title' || data.toLowerCase() === 'url';
29
-
30
- exports.getFieldMetaData = (data) => {
31
- return {
32
- _default: this.getMandatoryVal(data),
33
- version,
34
- };
35
- };
@@ -1,12 +0,0 @@
1
- 'use strict';
2
-
3
- const { success } = require('./logger');
4
- const { successMessageHandler } = require('./constants');
5
-
6
- module.exports = (data, type, method) => {
7
- if (data && type && method) {
8
- //success(`Successfully ${successMessageHandler[method]} ${type}: ${data}`);
9
- } else {
10
- success(`${type} successfully completed`);
11
- }
12
- };
@@ -1,20 +0,0 @@
1
- 'use strict';
2
-
3
- class ApiError {
4
- validate(data) {
5
- if (data.payload.apiError) {
6
- return [
7
- {
8
- ...data,
9
- message: `${data.payload.apiError.error_message}`,
10
- },
11
- ];
12
- }
13
- return [];
14
- }
15
-
16
- isApplicable(action) {
17
- return action.type === 'apiError';
18
- }
19
- }
20
- module.exports = ApiError;
@@ -1,39 +0,0 @@
1
- 'use strict';
2
-
3
- const { keys } = Object;
4
- class BaseValidator {
5
- commonValidate(properties, data) {
6
- const errors = [];
7
- const opts = data.payload.options;
8
- const dataKeys = keys(opts);
9
-
10
- for (let i = 0; i < properties.length; i++) {
11
- let prop = properties[i];
12
- // Check if property is mandatory but not present in user specified params
13
- if (prop.mandatory && !dataKeys.includes(prop.name)) {
14
- errors.push({ ...data, message: `${prop.name} is required.` });
15
- }
16
-
17
- if (prop.name in opts) {
18
- const dataType = this.getDataType(opts[prop.name]);
19
- if (dataType !== prop.type) {
20
- errors.push({ ...data, message: `${prop.name} is a ${dataType} type` });
21
- }
22
-
23
- if (prop.dependsOn && !(prop.dependsOn in opts) && opts[prop.name]) {
24
- errors.push({ ...data, message: `${prop.dependsOn} is required with ${prop.name}` });
25
- }
26
- }
27
- }
28
-
29
- return errors;
30
- }
31
-
32
- getDataType(data) {
33
- if (Array.isArray(data)) {
34
- return 'array';
35
- }
36
- return typeof data;
37
- }
38
- }
39
- module.exports = BaseValidator;
@@ -1,54 +0,0 @@
1
- 'use strict';
2
-
3
- const { keys } = Object;
4
- // Utils
5
- const { map: _map, constants } = require('../utils');
6
- // Properties
7
- const { getMapInstance, get } = _map;
8
- const { contentTypeProperties } = constants;
9
-
10
- const mandatoryKeys = ['uid', 'title', 'description'];
11
-
12
- class CreateContentTypeValidator {
13
- constructor() {
14
- // super();
15
- this.errors = [];
16
- }
17
-
18
- validate(data) {
19
- // Validate the latest updated object in the global map object
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);
24
-
25
- for (const key of mandatoryKeys) {
26
- if (!keys(actionObj).includes(key) || !actionObj[key]) {
27
- data = { ...data, message: `${key} is missing.` };
28
- this.errors.push(data);
29
- }
30
- }
31
-
32
- // TODO: Fix error messages
33
- const propertyNames = this.getPropertyNames();
34
-
35
- for (let i = 0; i < userProvidedFields.length; i++) {
36
- let key = userProvidedFields[i];
37
- if (!propertyNames.includes(key)) {
38
- data = { ...data, message: `${key} is not valid property.` };
39
- this.errors.push(data);
40
- }
41
- }
42
- return this.errors;
43
- }
44
-
45
- isApplicable(action) {
46
- return action.type === 'create';
47
- }
48
-
49
- getPropertyNames() {
50
- return contentTypeProperties;
51
- }
52
- }
53
-
54
- module.exports = CreateContentTypeValidator;
@@ -1,53 +0,0 @@
1
- 'use strict';
2
-
3
- const { keys } = Object;
4
-
5
- // Utils
6
- const { map: _map, constants } = require('../utils');
7
- // Properties
8
- const { getMapInstance, get } = _map;
9
- const { contentTypeProperties } = constants;
10
-
11
- const mandatoryKeys = ['uid', 'title'];
12
-
13
- class EditContentTypeValidator {
14
- constructor() {
15
- this.errors = [];
16
- }
17
-
18
- validate(data) {
19
- // Validate the latest updated object in the global map object
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);
24
-
25
- for (const key of mandatoryKeys) {
26
- if (!userProvidedFields.includes(key)) {
27
- data = { ...data, message: `${key} is missing.` };
28
- this.errors.push(data);
29
- }
30
- }
31
- // TODO: Fix error messages
32
- const propertyNames = this.getPropertyNames();
33
-
34
- for (let i = 0; i < userProvidedFields.length; i++) {
35
- let key = userProvidedFields[i];
36
- if (!propertyNames.includes(key)) {
37
- data = { ...data, message: `${key} is not valid property.` };
38
- this.errors.push(data);
39
- }
40
- }
41
- return this.errors;
42
- }
43
-
44
- isApplicable(action) {
45
- return action.type === 'edit';
46
- }
47
-
48
- getPropertyNames() {
49
- return contentTypeProperties;
50
- }
51
- }
52
-
53
- module.exports = EditContentTypeValidator;
@@ -1,21 +0,0 @@
1
- 'use strict';
2
-
3
- class FieldValidator {
4
- validate(data) {
5
- if (data.payload.field) {
6
- return [
7
- {
8
- ...data,
9
- message: data.payload.field.message,
10
- },
11
- ];
12
- }
13
- return [];
14
- }
15
-
16
- isApplicable(action) {
17
- return action.type === 'field';
18
- }
19
- }
20
-
21
- module.exports = FieldValidator;
@@ -1,11 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = {
4
- CreateContentTypeValidator: require('./create-content-type-validator'),
5
- EditContentTypeValidator: require('./edit-content-type-validator'),
6
- SchemaValidator: require('./schema-validator'),
7
- FieldValidator: require('./field-validator'),
8
- _TypeError: require('./type-error'),
9
- ApiError: require('./api-error'),
10
- MigrationError: require('./migration-error'),
11
- };
@@ -1,20 +0,0 @@
1
- 'use strict';
2
-
3
- class MigrationError {
4
- validate(data) {
5
- if (data.payload.migrationError) {
6
- return [
7
- {
8
- ...data,
9
- message: `${data.payload.migrationError.migrationError.message}`,
10
- },
11
- ];
12
- }
13
- }
14
-
15
- isApplicable(action) {
16
- return action.type === 'migrationError';
17
- }
18
- }
19
-
20
- module.exports = MigrationError;
@@ -1,23 +0,0 @@
1
- 'use strict';
2
-
3
- class SchemaValidator {
4
- validate(data) {
5
- const { fromField, toField, toReferenceField, deriveField } = data.payload;
6
- // const fieldsToValidate = [payload]
7
- if (fromField || toField || toReferenceField || deriveField) {
8
- return [
9
- {
10
- ...data,
11
- message: `${fromField || toField || toReferenceField || deriveField} does not exist on schema.`,
12
- },
13
- ];
14
- }
15
- return [];
16
- }
17
-
18
- isApplicable(action) {
19
- return action.type === 'schema';
20
- }
21
- }
22
-
23
- module.exports = SchemaValidator;
@@ -1,22 +0,0 @@
1
- 'use strict';
2
-
3
- class _TypeError {
4
- constructor() {}
5
-
6
- validate(data) {
7
- if (data.payload.typeErrors) {
8
- return [
9
- {
10
- ...data,
11
- message: `${data.payload.typeErrors[0]} is not a valid function`,
12
- },
13
- ];
14
- }
15
- return [];
16
- }
17
-
18
- isApplicable(action) {
19
- return action.type === 'typeError';
20
- }
21
- }
22
- module.exports = _TypeError;