@contentstack/cli-migration 1.10.2 → 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 +22 -12
  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
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // Utils
4
+ const utils_1 = require("../utils");
5
+ // Properties
6
+ const { getMapInstance, get } = utils_1.map;
7
+ const { contentTypeProperties } = utils_1.constants;
8
+ const mandatoryKeys = ['uid', 'title', 'description'];
9
+ class CreateContentTypeValidator {
10
+ constructor() {
11
+ // super();
12
+ this.errors = [];
13
+ }
14
+ validate(data) {
15
+ // Validate the latest updated object in the global map object
16
+ const mapInstance = getMapInstance();
17
+ const mapObj = get(data.payload.contentTypeId, mapInstance);
18
+ const actionObj = mapObj[data.payload.action].content_type;
19
+ const userProvidedFields = Object.keys(actionObj);
20
+ for (const key of mandatoryKeys) {
21
+ if (!Object.keys(actionObj).includes(key) || !actionObj[key]) {
22
+ data = Object.assign(Object.assign({}, data), { message: `${key} is missing.` });
23
+ this.errors.push(data);
24
+ }
25
+ }
26
+ // TODO: Fix error messages
27
+ const propertyNames = this.getPropertyNames();
28
+ for (let i = 0; i < userProvidedFields.length; i++) {
29
+ let key = userProvidedFields[i];
30
+ if (!propertyNames.includes(key)) {
31
+ data = Object.assign(Object.assign({}, data), { message: `${key} is not valid property.` });
32
+ this.errors.push(data);
33
+ }
34
+ }
35
+ return this.errors;
36
+ }
37
+ isApplicable(action) {
38
+ return action.type === 'create';
39
+ }
40
+ getPropertyNames() {
41
+ return contentTypeProperties;
42
+ }
43
+ }
44
+ exports.default = CreateContentTypeValidator;
45
+ //# sourceMappingURL=create-content-type-validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-content-type-validator.js","sourceRoot":"","sources":["../../src/validators/create-content-type-validator.ts"],"names":[],"mappings":";;AAAA,QAAQ;AACR,oCAAkD;AAClD,aAAa;AACb,MAAM,EAAE,cAAc,EAAE,GAAG,EAAE,GAAG,WAAI,CAAC;AACrC,MAAM,EAAE,qBAAqB,EAAE,GAAG,iBAAS,CAAC;AAE5C,MAAM,aAAa,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC;AAEtD,MAAqB,0BAA0B;IAG7C;QACE,WAAW;QACX,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;IACnB,CAAC;IAED,QAAQ,CAAC,IAAS;QAChB,8DAA8D;QAC9D,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;QACrC,MAAM,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;QAC5D,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC;QAC3D,MAAM,kBAAkB,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAElD,KAAK,MAAM,GAAG,IAAI,aAAa,EAAE;YAC/B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE;gBAC5D,IAAI,mCAAQ,IAAI,KAAE,OAAO,EAAE,GAAG,GAAG,cAAc,GAAE,CAAC;gBAClD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;aACxB;SACF;QAED,2BAA2B;QAC3B,MAAM,aAAa,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAE9C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,kBAAkB,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YAClD,IAAI,GAAG,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAAC;YAChC,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;gBAChC,IAAI,mCAAQ,IAAI,KAAE,OAAO,EAAE,GAAG,GAAG,yBAAyB,GAAE,CAAC;gBAC7D,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;aACxB;SACF;QACD,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,YAAY,CAAC,MAAW;QACtB,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,CAAC;IAClC,CAAC;IAED,gBAAgB;QACd,OAAO,qBAAqB,CAAC;IAC/B,CAAC;CACF;AA1CD,6CA0CC","sourcesContent":["// Utils\nimport { map as _map, constants } from '../utils';\n// Properties\nconst { getMapInstance, get } = _map;\nconst { contentTypeProperties } = constants;\n\nconst mandatoryKeys = ['uid', 'title', 'description'];\n\nexport default class CreateContentTypeValidator {\n errors: any[];\n\n constructor() {\n // super();\n this.errors = [];\n }\n\n validate(data: any): any[] {\n // Validate the latest updated object in the global map object\n const mapInstance = getMapInstance();\n const mapObj = get(data.payload.contentTypeId, mapInstance);\n const actionObj = mapObj[data.payload.action].content_type;\n const userProvidedFields = Object.keys(actionObj);\n\n for (const key of mandatoryKeys) {\n if (!Object.keys(actionObj).includes(key) || !actionObj[key]) {\n data = { ...data, message: `${key} is missing.` };\n this.errors.push(data);\n }\n }\n\n // TODO: Fix error messages\n const propertyNames = this.getPropertyNames();\n\n for (let i = 0; i < userProvidedFields.length; i++) {\n let key = userProvidedFields[i];\n if (!propertyNames.includes(key)) {\n data = { ...data, message: `${key} is not valid property.` };\n this.errors.push(data);\n }\n }\n return this.errors;\n }\n\n isApplicable(action: any): boolean {\n return action.type === 'create';\n }\n\n getPropertyNames(): string[] {\n return contentTypeProperties;\n }\n}\n"]}
@@ -0,0 +1,7 @@
1
+ export default class EditContentTypeValidator {
2
+ errors: any[];
3
+ constructor();
4
+ validate(data: any): any[];
5
+ isApplicable(action: any): boolean;
6
+ getPropertyNames(): string[];
7
+ }
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // Utils
4
+ const utils_1 = require("../utils");
5
+ // Properties
6
+ const { getMapInstance, get } = utils_1.map;
7
+ const { contentTypeProperties } = utils_1.constants;
8
+ const mandatoryKeys = ['uid', 'title'];
9
+ class EditContentTypeValidator {
10
+ constructor() {
11
+ this.errors = [];
12
+ }
13
+ validate(data) {
14
+ // Validate the latest updated object in the global map object
15
+ const mapInstance = getMapInstance();
16
+ const mapObj = get(data.payload.contentTypeId, mapInstance);
17
+ const actionObj = mapObj[data.payload.action].content_type;
18
+ const userProvidedFields = Object.keys(actionObj);
19
+ for (const key of mandatoryKeys) {
20
+ if (!userProvidedFields.includes(key)) {
21
+ data = Object.assign(Object.assign({}, data), { message: `${key} is missing.` });
22
+ this.errors.push(data);
23
+ }
24
+ }
25
+ // TODO: Fix error messages
26
+ const propertyNames = this.getPropertyNames();
27
+ for (let i = 0; i < userProvidedFields.length; i++) {
28
+ let key = userProvidedFields[i];
29
+ if (!propertyNames.includes(key)) {
30
+ data = Object.assign(Object.assign({}, data), { message: `${key} is not valid property.` });
31
+ this.errors.push(data);
32
+ }
33
+ }
34
+ return this.errors;
35
+ }
36
+ isApplicable(action) {
37
+ return action.type === 'edit';
38
+ }
39
+ getPropertyNames() {
40
+ return contentTypeProperties;
41
+ }
42
+ }
43
+ exports.default = EditContentTypeValidator;
44
+ //# sourceMappingURL=edit-content-type-validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"edit-content-type-validator.js","sourceRoot":"","sources":["../../src/validators/edit-content-type-validator.ts"],"names":[],"mappings":";;AACA,QAAQ;AACR,oCAAkD;AAClD,aAAa;AACb,MAAM,EAAE,cAAc,EAAE,GAAG,EAAE,GAAG,WAAI,CAAC;AACrC,MAAM,EAAE,qBAAqB,EAAE,GAAG,iBAAS,CAAC;AAE5C,MAAM,aAAa,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AAEvC,MAAqB,wBAAwB;IAG3C;QACE,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;IACnB,CAAC;IAED,QAAQ,CAAC,IAAS;QAChB,8DAA8D;QAC9D,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;QACrC,MAAM,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;QAC5D,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC;QAC3D,MAAM,kBAAkB,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAElD,KAAK,MAAM,GAAG,IAAI,aAAa,EAAE;YAC/B,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;gBACrC,IAAI,mCAAQ,IAAI,KAAE,OAAO,EAAE,GAAG,GAAG,cAAc,GAAE,CAAC;gBAClD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;aACxB;SACF;QACD,2BAA2B;QAC3B,MAAM,aAAa,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAE9C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,kBAAkB,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YAClD,IAAI,GAAG,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAAC;YAChC,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;gBAChC,IAAI,mCAAQ,IAAI,KAAE,OAAO,EAAE,GAAG,GAAG,yBAAyB,GAAE,CAAC;gBAC7D,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;aACxB;SACF;QACD,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,YAAY,CAAC,MAAW;QACtB,OAAO,MAAM,CAAC,IAAI,KAAK,MAAM,CAAC;IAChC,CAAC;IAED,gBAAgB;QACd,OAAO,qBAAqB,CAAC;IAC/B,CAAC;CACF;AAxCD,2CAwCC","sourcesContent":["\n// Utils\nimport { map as _map, constants } from '../utils';\n// Properties\nconst { getMapInstance, get } = _map;\nconst { contentTypeProperties } = constants;\n\nconst mandatoryKeys = ['uid', 'title'];\n\nexport default class EditContentTypeValidator {\n errors: any[];\n\n constructor() {\n this.errors = [];\n }\n\n validate(data: any): any[] {\n // Validate the latest updated object in the global map object\n const mapInstance = getMapInstance();\n const mapObj = get(data.payload.contentTypeId, mapInstance);\n const actionObj = mapObj[data.payload.action].content_type;\n const userProvidedFields = Object.keys(actionObj);\n\n for (const key of mandatoryKeys) {\n if (!userProvidedFields.includes(key)) {\n data = { ...data, message: `${key} is missing.` };\n this.errors.push(data);\n }\n }\n // TODO: Fix error messages\n const propertyNames = this.getPropertyNames();\n\n for (let i = 0; i < userProvidedFields.length; i++) {\n let key = userProvidedFields[i];\n if (!propertyNames.includes(key)) {\n data = { ...data, message: `${key} is not valid property.` };\n this.errors.push(data);\n }\n }\n return this.errors;\n }\n\n isApplicable(action: any): boolean {\n return action.type === 'edit';\n }\n\n getPropertyNames(): string[] {\n return contentTypeProperties;\n }\n}\n"]}
@@ -0,0 +1,4 @@
1
+ export default class FieldValidator {
2
+ validate(data: any): any[];
3
+ isApplicable(action: any): boolean;
4
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class FieldValidator {
4
+ validate(data) {
5
+ if (data.payload.field) {
6
+ return [
7
+ Object.assign(Object.assign({}, data), { message: data.payload.field.message }),
8
+ ];
9
+ }
10
+ return [];
11
+ }
12
+ isApplicable(action) {
13
+ return action.type === 'field';
14
+ }
15
+ }
16
+ exports.default = FieldValidator;
17
+ //# sourceMappingURL=field-validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field-validator.js","sourceRoot":"","sources":["../../src/validators/field-validator.ts"],"names":[],"mappings":";;AAAA,MAAqB,cAAc;IACjC,QAAQ,CAAC,IAAS;QAChB,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE;YACtB,OAAO;gDAEA,IAAI,KACP,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO;aAEtC,CAAC;SACH;QACD,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,YAAY,CAAC,MAAW;QACtB,OAAO,MAAM,CAAC,IAAI,KAAK,OAAO,CAAC;IACjC,CAAC;CACF;AAhBD,iCAgBC","sourcesContent":["export default class FieldValidator {\n validate(data: any): any[] {\n if (data.payload.field) {\n return [\n {\n ...data,\n message: data.payload.field.message,\n },\n ];\n }\n return [];\n }\n\n isApplicable(action: any): boolean {\n return action.type === 'field';\n }\n}\n"]}
@@ -0,0 +1,8 @@
1
+ import CreateContentTypeValidator from './create-content-type-validator';
2
+ import EditContentTypeValidator from './edit-content-type-validator';
3
+ import SchemaValidator from './schema-validator';
4
+ import FieldValidator from './field-validator';
5
+ import _TypeError from './type-error';
6
+ import ApiError from './api-error';
7
+ import MigrationError from './migration-error';
8
+ export { CreateContentTypeValidator, EditContentTypeValidator, SchemaValidator, FieldValidator, _TypeError, ApiError, MigrationError, };
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MigrationError = exports.ApiError = exports._TypeError = exports.FieldValidator = exports.SchemaValidator = exports.EditContentTypeValidator = exports.CreateContentTypeValidator = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const create_content_type_validator_1 = tslib_1.__importDefault(require("./create-content-type-validator"));
6
+ exports.CreateContentTypeValidator = create_content_type_validator_1.default;
7
+ const edit_content_type_validator_1 = tslib_1.__importDefault(require("./edit-content-type-validator"));
8
+ exports.EditContentTypeValidator = edit_content_type_validator_1.default;
9
+ const schema_validator_1 = tslib_1.__importDefault(require("./schema-validator"));
10
+ exports.SchemaValidator = schema_validator_1.default;
11
+ const field_validator_1 = tslib_1.__importDefault(require("./field-validator"));
12
+ exports.FieldValidator = field_validator_1.default;
13
+ const type_error_1 = tslib_1.__importDefault(require("./type-error"));
14
+ exports._TypeError = type_error_1.default;
15
+ const api_error_1 = tslib_1.__importDefault(require("./api-error"));
16
+ exports.ApiError = api_error_1.default;
17
+ const migration_error_1 = tslib_1.__importDefault(require("./migration-error"));
18
+ exports.MigrationError = migration_error_1.default;
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/validators/index.ts"],"names":[],"mappings":";;;;AAAA,4GAAyE;AASvE,qCATK,uCAA0B,CASL;AAR5B,wGAAqE;AASnE,mCATK,qCAAwB,CASL;AAR1B,kFAAiD;AAS/C,0BATK,0BAAe,CASL;AARjB,gFAA+C;AAS7C,yBATK,yBAAc,CASL;AARhB,sEAAsC;AASpC,qBATK,oBAAU,CASL;AARZ,oEAAmC;AASjC,mBATK,mBAAQ,CASL;AARV,gFAA+C;AAS7C,yBATK,yBAAc,CASL","sourcesContent":["import CreateContentTypeValidator from './create-content-type-validator';\nimport EditContentTypeValidator from './edit-content-type-validator';\nimport SchemaValidator from './schema-validator';\nimport FieldValidator from './field-validator';\nimport _TypeError from './type-error';\nimport ApiError from './api-error';\nimport MigrationError from './migration-error';\n\nexport {\n CreateContentTypeValidator,\n EditContentTypeValidator,\n SchemaValidator,\n FieldValidator,\n _TypeError,\n ApiError,\n MigrationError,\n};\n"]}
@@ -0,0 +1,4 @@
1
+ export default class MigrationError {
2
+ validate(data: any): any[] | undefined;
3
+ isApplicable(action: any): boolean;
4
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class MigrationError {
4
+ validate(data) {
5
+ if (data.payload.migrationError) {
6
+ return [
7
+ Object.assign(Object.assign({}, data), { message: `${data.payload.migrationError.migrationError.message}` }),
8
+ ];
9
+ }
10
+ }
11
+ isApplicable(action) {
12
+ return action.type === 'migrationError';
13
+ }
14
+ }
15
+ exports.default = MigrationError;
16
+ //# sourceMappingURL=migration-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration-error.js","sourceRoot":"","sources":["../../src/validators/migration-error.ts"],"names":[],"mappings":";;AAAA,MAAqB,cAAc;IACjC,QAAQ,CAAC,IAAS;QAChB,IAAI,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE;YAC/B,OAAO;gDAEA,IAAI,KACP,OAAO,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,cAAc,CAAC,OAAO,EAAE;aAEnE,CAAC;SACH;IACH,CAAC;IAED,YAAY,CAAC,MAAW;QACtB,OAAO,MAAM,CAAC,IAAI,KAAK,gBAAgB,CAAC;IAC1C,CAAC;CACF;AAfD,iCAeC","sourcesContent":["export default class MigrationError {\n validate(data: any): any[] | undefined {\n if (data.payload.migrationError) {\n return [\n {\n ...data,\n message: `${data.payload.migrationError.migrationError.message}`,\n },\n ];\n }\n }\n\n isApplicable(action: any): boolean {\n return action.type === 'migrationError';\n }\n}\n"]}
@@ -0,0 +1,4 @@
1
+ export default class SchemaValidator {
2
+ validate(data: any): any[];
3
+ isApplicable(action: any): boolean;
4
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
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
+ Object.assign(Object.assign({}, data), { message: `${fromField || toField || toReferenceField || deriveField} does not exist on schema.` }),
10
+ ];
11
+ }
12
+ return [];
13
+ }
14
+ isApplicable(action) {
15
+ return action.type === 'schema';
16
+ }
17
+ }
18
+ exports.default = SchemaValidator;
19
+ //# sourceMappingURL=schema-validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema-validator.js","sourceRoot":"","sources":["../../src/validators/schema-validator.ts"],"names":[],"mappings":";;AAAA,MAAqB,eAAe;IAClC,QAAQ,CAAC,IAAS;QAChB,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;QAC3E,qCAAqC;QACrC,IAAI,SAAS,IAAI,OAAO,IAAI,gBAAgB,IAAI,WAAW,EAAE;YAC3D,OAAO;gDAEA,IAAI,KACP,OAAO,EAAE,GAAG,SAAS,IAAI,OAAO,IAAI,gBAAgB,IAAI,WAAW,4BAA4B;aAElG,CAAC;SACH;QACD,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,YAAY,CAAC,MAAW;QACtB,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,CAAC;IAClC,CAAC;CACF;AAlBD,kCAkBC","sourcesContent":["export default class SchemaValidator {\n validate(data: any): any[] {\n const { fromField, toField, toReferenceField, deriveField } = data.payload;\n // const fieldsToValidate = [payload]\n if (fromField || toField || toReferenceField || deriveField) {\n return [\n {\n ...data,\n message: `${fromField || toField || toReferenceField || deriveField} does not exist on schema.`,\n },\n ];\n }\n return [];\n }\n\n isApplicable(action: any): boolean {\n return action.type === 'schema';\n }\n}\n"]}
@@ -0,0 +1,5 @@
1
+ export default class _TypeError {
2
+ constructor();
3
+ validate(data: any): any[];
4
+ isApplicable(action: any): boolean;
5
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class _TypeError {
4
+ constructor() { }
5
+ validate(data) {
6
+ if (data.payload.typeErrors) {
7
+ return [
8
+ Object.assign(Object.assign({}, data), { message: `${data.payload.typeErrors[0]} is not a valid function` }),
9
+ ];
10
+ }
11
+ return [];
12
+ }
13
+ isApplicable(action) {
14
+ return action.type === 'typeError';
15
+ }
16
+ }
17
+ exports.default = _TypeError;
18
+ //# sourceMappingURL=type-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-error.js","sourceRoot":"","sources":["../../src/validators/type-error.ts"],"names":[],"mappings":";;AAAA,MAAqB,UAAU;IAC7B,gBAAe,CAAC;IAEhB,QAAQ,CAAC,IAAS;QAChB,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE;YAC3B,OAAO;gDAEA,IAAI,KACP,OAAO,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,0BAA0B;aAEnE,CAAC;SACH;QACD,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,YAAY,CAAC,MAAW;QACtB,OAAO,MAAM,CAAC,IAAI,KAAK,WAAW,CAAC;IACrC,CAAC;CACF;AAlBD,6BAkBC","sourcesContent":["export default class _TypeError {\n constructor() {}\n\n validate(data: any): any[] {\n if (data.payload.typeErrors) {\n return [\n {\n ...data,\n message: `${data.payload.typeErrors[0]} is not a valid function`,\n },\n ];\n }\n return [];\n }\n\n isApplicable(action: any): boolean {\n return action.type === 'typeError';\n }\n}\n"]}
@@ -0,0 +1,145 @@
1
+ {
2
+ "commands": {
3
+ "cm:stacks:migration": {
4
+ "aliases": [
5
+ "cm:migration"
6
+ ],
7
+ "args": {},
8
+ "description": "Contentstack migration script.",
9
+ "examples": [
10
+ "$ csdx cm:migration --file-path <migration/script/file/path> -k <api-key>",
11
+ "$ csdx cm:migration --file-path <migration/script/file/path> -k <api-key> --branch <target branch name>",
12
+ "$ csdx cm:migration --config <key1>:<value1> <key2>:<value2> ... --file-path <migration/script/file/path>",
13
+ "$ csdx cm:migration --config-file <path/to/json/config/file> --file-path <migration/script/file/path>",
14
+ "$ csdx cm:migration --multiple --file-path <migration/scripts/dir/path> ",
15
+ "$ csdx cm:migration --alias --file-path <migration/script/file/path> -k <api-key>"
16
+ ],
17
+ "flags": {
18
+ "stack-api-key": {
19
+ "char": "k",
20
+ "description": "Use this flag to add the API key of your stack. You must use either the --stack-api-key flag or the --alias flag.",
21
+ "exclusive": [
22
+ "alias"
23
+ ],
24
+ "name": "stack-api-key",
25
+ "hasDynamicHelp": false,
26
+ "multiple": false,
27
+ "type": "option"
28
+ },
29
+ "alias": {
30
+ "char": "a",
31
+ "description": "Use this flag to add the management token alias. You must use either the --alias flag or the --stack-api-key flag.",
32
+ "name": "alias",
33
+ "hasDynamicHelp": false,
34
+ "multiple": false,
35
+ "type": "option"
36
+ },
37
+ "file-path": {
38
+ "description": "Use this flag to provide the path of the file of the migration script.",
39
+ "name": "file-path",
40
+ "hasDynamicHelp": false,
41
+ "multiple": false,
42
+ "type": "option"
43
+ },
44
+ "branch": {
45
+ "char": "B",
46
+ "description": "Use this flag to add the branch name where you want to perform the migration. (target branch name)",
47
+ "name": "branch",
48
+ "hasDynamicHelp": false,
49
+ "multiple": false,
50
+ "type": "option"
51
+ },
52
+ "config-file": {
53
+ "description": "[optional] Path of the JSON configuration file.",
54
+ "name": "config-file",
55
+ "hasDynamicHelp": false,
56
+ "multiple": false,
57
+ "type": "option"
58
+ },
59
+ "config": {
60
+ "description": "[optional] Inline configuration, <key1>:<value1>. Passing an external configuration makes the script re-usable.",
61
+ "name": "config",
62
+ "hasDynamicHelp": false,
63
+ "multiple": true,
64
+ "type": "option"
65
+ },
66
+ "multiple": {
67
+ "description": "This flag helps you to migrate multiple content files in a single instance. Mention the folder path where your migration script files are stored.",
68
+ "name": "multiple",
69
+ "allowNo": false,
70
+ "type": "boolean"
71
+ },
72
+ "api-key": {
73
+ "char": "k",
74
+ "description": "With this flag add the API key of your stack.",
75
+ "exclusive": [
76
+ "alias"
77
+ ],
78
+ "hidden": true,
79
+ "name": "api-key",
80
+ "hasDynamicHelp": false,
81
+ "multiple": false,
82
+ "type": "option"
83
+ },
84
+ "authtoken": {
85
+ "char": "A",
86
+ "dependsOn": [
87
+ "api-key"
88
+ ],
89
+ "description": "Use this flag to use the auth token of the current session. After logging in CLI, an auth token is generated for each new session.",
90
+ "exclusive": [
91
+ "alias"
92
+ ],
93
+ "hidden": true,
94
+ "name": "authtoken",
95
+ "allowNo": false,
96
+ "type": "boolean"
97
+ },
98
+ "management-token-alias": {
99
+ "description": "Alias of the management token.",
100
+ "exclusive": [
101
+ "authtoken"
102
+ ],
103
+ "hidden": true,
104
+ "name": "management-token-alias",
105
+ "hasDynamicHelp": false,
106
+ "multiple": false,
107
+ "type": "option"
108
+ },
109
+ "filePath": {
110
+ "char": "n",
111
+ "description": "Use this flag to provide the path of the file of the migration script provided by the user.",
112
+ "hidden": true,
113
+ "name": "filePath",
114
+ "hasDynamicHelp": false,
115
+ "multiple": false,
116
+ "type": "option"
117
+ },
118
+ "multi": {
119
+ "description": "This flag helps you to migrate multiple content files in a single instance.",
120
+ "hidden": true,
121
+ "name": "multi",
122
+ "allowNo": false,
123
+ "type": "boolean"
124
+ }
125
+ },
126
+ "hasDynamicHelp": false,
127
+ "hiddenAliases": [],
128
+ "id": "cm:stacks:migration",
129
+ "pluginAlias": "@contentstack/cli-migration",
130
+ "pluginName": "@contentstack/cli-migration",
131
+ "pluginType": "core",
132
+ "strict": true,
133
+ "usage": "cm:stacks:migration [-k <value>] [-a <value>] [--file-path <value>] [--branch <value>] [--config-file <value>] [--config <value>] [--multiple]",
134
+ "isESM": false,
135
+ "relativePath": [
136
+ "lib",
137
+ "commands",
138
+ "cm",
139
+ "stacks",
140
+ "migration.js"
141
+ ]
142
+ }
143
+ },
144
+ "version": "1.11.0"
145
+ }
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@contentstack/cli-migration",
3
- "version": "1.10.2",
3
+ "version": "1.11.0",
4
4
  "author": "@contentstack",
5
5
  "bugs": "https://github.com/contentstack/cli/issues",
6
6
  "dependencies": {
7
- "@contentstack/cli-command": "~1.7.1",
8
- "@contentstack/cli-utilities": "~1.16.0",
7
+ "@contentstack/cli-command": "~1.7.2",
8
+ "@contentstack/cli-utilities": "~1.17.1",
9
9
  "@oclif/core": "^4.3.0",
10
10
  "@oclif/plugin-help": "^6.2.28",
11
11
  "async": "^3.2.6",
@@ -18,22 +18,28 @@
18
18
  },
19
19
  "devDependencies": {
20
20
  "@oclif/test": "^4.1.13",
21
+ "@types/mocha": "^8.2.3",
22
+ "@types/node": "^14.18.63",
21
23
  "chai": "^4.5.0",
22
24
  "eslint": "^8.57.1",
23
25
  "eslint-config-oclif": "^6.0.62",
24
26
  "jsdoc-to-markdown": "^8.0.3",
27
+ "mocha": "^10.8.2",
25
28
  "nock": "^13.5.6",
26
29
  "nyc": "^15.1.0",
27
- "oclif": "^4.17.46"
30
+ "oclif": "^4.17.46",
31
+ "sinon": "^19.0.5",
32
+ "source-map-support": "^0.5.21",
33
+ "ts-node": "^10.9.2",
34
+ "typescript": "^4.9.5"
28
35
  },
29
36
  "engines": {
30
37
  "node": ">=8.3.0"
31
38
  },
32
39
  "files": [
40
+ "/lib",
33
41
  "/npm-shrinkwrap.json",
34
- "/oclif.manifest.json",
35
- "/src",
36
- "/yarn.lock"
42
+ "/oclif.manifest.json"
37
43
  ],
38
44
  "homepage": "https://github.com/contentstack/cli",
39
45
  "keywords": [
@@ -41,16 +47,20 @@
41
47
  ],
42
48
  "license": "MIT",
43
49
  "oclif": {
44
- "commands": "./src/commands",
50
+ "commands": "./lib/commands",
45
51
  "bin": "csdx",
46
52
  "repositoryPrefix": "<%- repo %>/blob/main/packages/contentstack-migration/<%- commandPath %>"
47
53
  },
48
54
  "repository": "contentstack/cli",
49
55
  "scripts": {
50
56
  "postpack": "rm -f oclif.manifest.json",
51
- "generate-api-ref-md-doc": "nyc jsdoc2md ./src/modules/* > ./docs/api-reference.md",
52
- "prepack": "oclif manifest && oclif readme && pnpm generate-api-ref-md-doc",
53
- "test": "nyc mocha --timeout 3000 \"test/**/*.test.js\"",
57
+ "generate-api-ref-md-doc": "nyc jsdoc2md ./src/modules/*.ts > ./docs/api-reference.md || true",
58
+ "compile": "tsc -b tsconfig.json",
59
+ "prepack": "pnpm compile && oclif manifest && oclif readme",
60
+ "pretest": "tsc -p test",
61
+ "test": "mocha --forbid-only \"test/unit/**/*.test.ts\"",
62
+ "test:unit": "mocha --timeout 10000 --forbid-only \"test/unit/**/*.test.ts\"",
63
+ "test:unit:report": "nyc --extension .ts mocha --forbid-only \"test/unit/**/*.test.ts\"",
54
64
  "version": "oclif readme && git add README.md",
55
65
  "clean": "rm -rf ./node_modules tsconfig.build.tsbuildinfo"
56
66
  },
@@ -63,4 +73,4 @@
63
73
  "cm:migration": "O-MGRTN"
64
74
  }
65
75
  }
66
- }
76
+ }
@@ -1,32 +0,0 @@
1
- /* eslint-disable no-unused-expressions */
2
- 'use strict';
3
-
4
- class ActionList {
5
- constructor(actionList, typeErrors) {
6
- typeErrors && (this.typeErrors = typeErrors);
7
- actionList && (this.actionList = actionList);
8
- this.validators = [];
9
- }
10
-
11
- addValidators(validator) {
12
- this.validators.push(validator);
13
- }
14
-
15
- validate() {
16
- const { validators, actionList } = this;
17
-
18
- let errors = [];
19
- for (const action of actionList) {
20
- for (const validator of validators) {
21
- if (validator.isApplicable(action)) {
22
- errors = validator.validate(action);
23
- break;
24
- }
25
- }
26
- }
27
-
28
- return errors;
29
- }
30
- }
31
-
32
- module.exports = ActionList;