@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,208 +0,0 @@
1
- /* eslint-disable camelcase */
2
- 'use strict';
3
-
4
- const Field = require('./fields');
5
-
6
- // Services
7
- const { ContentTypeService } = require('../services');
8
-
9
- // Config
10
- const { defaultOptions } = require('../config');
11
-
12
- // Utils
13
- const { map: _map, schemaHelper, constants, getCallsite } = require('../utils');
14
-
15
- // Base class
16
- const Base = require('./base');
17
-
18
- // Properties
19
- const { getMapInstance, set, get } = _map;
20
- const { actions, validationAction } = constants;
21
- const { getUid } = schemaHelper;
22
- const { create, edit } = validationAction;
23
-
24
- /**
25
- * ContentType class
26
- * @class ContentType
27
- * @augments Base
28
- */
29
- class ContentType extends Base {
30
- constructor() {
31
- super();
32
- this.contentTypeService = new ContentTypeService();
33
- }
34
-
35
- /**
36
- * Creates content type by passing content type name and options
37
- * @param {string} id Content type UID
38
- * @param {Object} opts Optional: Content type fields definition
39
- * @returns {Field} instance of Field
40
- * @example
41
- * module.exports = ({migration}) => {
42
- * const blog = migration
43
- * .createContentType('blog')
44
- * .title('blog title')
45
- * .description('blog 1')
46
- * blog.createField('title').display_name('Title').data_type('text').mandatory(true);
47
- * }
48
- */
49
- createContentType(id, opts = {}) {
50
- const callsite = getCallsite();
51
- // base class method
52
- let options = { ...defaultOptions, ...opts };
53
- delete options.title;
54
- delete options.description;
55
- this.dispatch(callsite, id, opts, create);
56
- const { title, description } = opts;
57
- const mapInstance = getMapInstance();
58
-
59
- const { CREATE_CT } = actions;
60
- const uid = getUid(id);
61
-
62
- const ctObj = { content_type: { title, uid, description, options } };
63
-
64
- const ctActionObj = { [CREATE_CT]: ctObj };
65
-
66
- const { contentTypeService } = this;
67
- // Sets data to post in map object
68
- set(id, mapInstance, ctActionObj);
69
- // Sets action and id in content type service
70
- contentTypeService.setIdAndAction(id, CREATE_CT);
71
- const tasks = [contentTypeService.postContentTypes.bind(contentTypeService, callsite, id, CREATE_CT)];
72
- const req = {
73
- title: `Adding content type: ${id}`,
74
- failMessage: `Failed to create content type: ${id}`,
75
- successMessage: `Successfully added content type: ${id}`,
76
- tasks,
77
- };
78
- let field = new Field(id, CREATE_CT, contentTypeService, req);
79
- // TODO: should find better way to attach content type level methods
80
- field.singleton = this.singleton;
81
- field.isPage = this.isPage;
82
- return field;
83
- }
84
-
85
- /**
86
- * Set content type to singleton or multiple
87
- * @param {boolean} value set value true to set content type as singleton default it is multiple
88
- * @returns {ContentType} instance of ContentType for chaining
89
- */
90
- singleton(value) {
91
- const mapInstance = getMapInstance();
92
- const { id, action } = this;
93
- const contentType = get(id, mapInstance);
94
-
95
- contentType[action].content_type.options.singleton = value;
96
- return this;
97
- }
98
-
99
- /**
100
- * Set content type to singleton or multiple
101
- * @param {boolean} value set value false to set content type as content as block default true
102
- * @returns {ContentType} instance of ContentType for chaining
103
- */
104
- isPage(value) {
105
- const mapInstance = getMapInstance();
106
- const { id, action } = this;
107
- const contentType = get(id, mapInstance);
108
-
109
- contentType[action].content_type.options.is_page = value;
110
- return this;
111
- }
112
-
113
- /**
114
- * Edits content type by passing content type name and options
115
- * @param {string} id Content type UID
116
- * @param {Object} opts Optional: Content type fields definition
117
- * @returns {Field} instance of Field
118
- * @example
119
- * module.exports = ({migration}) => {
120
- * const blog = migration.editContentType('blog');
121
- * blog.description('Changed description');
122
- * }
123
- */
124
- editContentType(id, opts = {}) {
125
- let options = { ...defaultOptions, ...opts };
126
- delete options.title;
127
- delete options.description;
128
-
129
- const callsite = getCallsite();
130
- // base class method
131
- this.dispatch(callsite, id, {}, edit);
132
- const { title, description } = opts;
133
- const mapInstance = getMapInstance();
134
-
135
- const { EDIT_CT } = actions;
136
-
137
- const uid = id;
138
-
139
- const ctObj = { content_type: { title, uid, description, options } };
140
- const ctActionObj = { [EDIT_CT]: ctObj };
141
-
142
- const { contentTypeService } = this;
143
-
144
- // Sets data to update in map object
145
- let ctAction = get(id, mapInstance);
146
-
147
- set(id, mapInstance, { ...ctActionObj, ...ctAction });
148
- // Sets action and id in content type service
149
- contentTypeService.setIdAndAction(id, EDIT_CT);
150
- const tasks = [
151
- contentTypeService.fetchContentType.bind(contentTypeService, callsite, id),
152
- contentTypeService.applyActionsOnFields.bind(contentTypeService, callsite),
153
- contentTypeService.editContentType.bind(contentTypeService, callsite),
154
- ];
155
-
156
- const req = {
157
- title: `Editing content type: ${id}`,
158
- failMessage: `Failed to edit content type: ${id}`,
159
- successMessage: `Successfully updated content type: ${id}`,
160
- tasks,
161
- };
162
-
163
- // Keeping the same instance of contentTypeService in Field class
164
- let fieldI = new Field(id, EDIT_CT, contentTypeService, req);
165
- // TODO: should find better way to attach content type level methods
166
- fieldI.singleton = this.singleton;
167
- fieldI.isPage = this.isPage;
168
- return fieldI;
169
- }
170
-
171
- /**
172
- * Deletes content type by passing content type name
173
- * @param {string} id Content type UID
174
- * @returns {Field} instance of Field
175
- * @example
176
- * module.exports = {migrations} => {
177
- * const blog = migrations.deleteContentType('blog');
178
- * }
179
- */
180
- deleteContentType(id) {
181
- const callsite = getCallsite();
182
-
183
- const mapInstance = getMapInstance();
184
-
185
- const { DELETE_CT } = actions;
186
-
187
- const uid = getUid(id);
188
-
189
- const ctObj = { content_type: { uid, force: false } }; // keep by default false
190
-
191
- const ctActionObj = { [DELETE_CT]: ctObj };
192
-
193
- const { contentTypeService } = this;
194
-
195
- // Sets data to delete in map object
196
- set(id, mapInstance, ctActionObj);
197
- // Sets action and id in content type service
198
- contentTypeService.setIdAndAction(id, DELETE_CT);
199
-
200
- const tasks = [contentTypeService.deleteContentType.bind(contentTypeService, callsite)];
201
-
202
- const req = { title: 'Deleting content type', tasks };
203
-
204
- return new Field(id, DELETE_CT, contentTypeService, req);
205
- }
206
- }
207
-
208
- module.exports = ContentType;
@@ -1,339 +0,0 @@
1
- 'use strict';
2
-
3
- const { keys } = Object;
4
- // Utils
5
- const { map: _map, schemaHelper, constants } = require('../utils');
6
-
7
- // Utils Properties
8
- const { getMapInstance, get } = _map;
9
- const { getSchema } = schemaHelper;
10
- const {
11
- data_type,
12
- mandatory,
13
- _default,
14
- unique,
15
- display_name,
16
- field_metadata,
17
- reference_to,
18
- actions: _actions,
19
- taxonomies,
20
- multiple,
21
- } = constants;
22
-
23
- // Base class
24
- const Base = require('./base');
25
-
26
- /**
27
- * Field class
28
- * @class Field
29
- */
30
- class Field extends Base {
31
- // prop, value
32
- constructor(uid, action, contentTypeService, request) {
33
- super(uid);
34
- this.uid = uid;
35
- this.action = action;
36
- this.contentTypeService = contentTypeService;
37
- this.request = request;
38
- }
39
-
40
- /**
41
- * @typedef {Object} Task
42
- * @param {string} title - Title for custom task
43
- * @param {function[]} task - array of async function to be executed
44
- * @param {string} failMessage message to be printed when task fails
45
- * @param {string} successMessage - message to be printed when task succeeds
46
- */
47
-
48
- /**
49
- * Creates a field with provided uid.
50
- * @param {string} field Field name to be created
51
- * @param {Object} opts Options to be passed
52
- * @returns {Field} current instance of field object to chain further methods.
53
- * @example
54
- * module.exports =({ migration })=> {
55
- * const blog = migration.editContentType('blog');
56
- *
57
- * blog.createField('author')
58
- * .display_name('Author')
59
- * .data_type('text')
60
- * .mandatory(false);
61
- * };
62
- *
63
- * Create a taxonomy field
64
- *
65
- * module.exports =({ migration })=> {
66
- * const blog = migration.editContentType('blog');
67
- *
68
- * blog.createField('taxonomies')
69
- * .display_name('Taxonomy1')
70
- * .data_type('taxonomy')
71
- * .taxonomies([{ "taxonomy_uid": "test_taxonomy1", "max_terms": 2, "mandatory": false}])
72
- * .multiple(true)
73
- * .mandatory(false);
74
- * };
75
- */
76
- createField(field, opts) {
77
- this.updateContentTypeSchema(field);
78
-
79
- // Build schema from options provided
80
- if (opts && keys(opts).length) return this.getSchemaFromOptions(opts, field);
81
- return this;
82
- }
83
-
84
- /**
85
- * Edits the field with provided uid.
86
- * @param {string} field Field name to be edited
87
- * @param {Object} opts Options to be passed
88
- * @returns {Field} current instance of field object to chain further methods.
89
- * @example
90
- * module.exports =({ migration })=> {
91
- * const blog = migration.editContentType('blog');
92
- *
93
- * blog.editField('uniqueid')
94
- * .display_name('Unique ID')
95
- * .mandatory(false);
96
- * };
97
- */
98
- editField(field, opts) {
99
- const { EDIT_FIELD } = _actions;
100
- this.updateContentTypeSchema(field, EDIT_FIELD);
101
-
102
- // Build schema from options provided
103
- if (opts && keys(opts).length) return this.getSchemaFromOptions(opts, field);
104
- return this;
105
- }
106
-
107
- /**
108
- * Delete a field from the content type
109
- * @param {string} field Field uid to be deleted
110
- * @returns {Field} current instance of field object to chain further methods.
111
- * @example
112
- * module.exports =({ migration })=> {
113
- * const blog = migration.editContentType('blog');
114
- *
115
- * blog.deleteField('uniqueid');
116
- * };
117
- */
118
- deleteField(field) {
119
- const { DELETE_FIELD } = _actions;
120
- this.updateContentTypeSchema(field, DELETE_FIELD);
121
-
122
- return this;
123
- }
124
-
125
- /**
126
- * Move the field (position of the field in the editor)
127
- * @param {string} field Field uid to be moved
128
- * @returns {Field} current instance of field object to chain further methods.
129
- * @example
130
- * module.exports = ({migration}) => {
131
- * const blog = migration.editContentType('blog');
132
- *
133
- * blog.createField('credits')
134
- * .display_name('Credits')
135
- * .data_type('text')
136
- * .mandatory(false);
137
- *
138
- * blog.createField('references')
139
- * .display_name('References')
140
- * .data_type('text')
141
- * .mandatory(false);
142
- *
143
- * blog.moveField('uniqueid').toTheBottom();
144
- * blog.moveField('references').beforeField('credits');
145
- * blog.moveField('author').toTheTop();
146
- * blog.moveField('url').afterField('author');
147
- * };
148
- */
149
- moveField(field) {
150
- this.fieldToMove = field;
151
- return this;
152
- }
153
-
154
- updateContentTypeSchema(field, subAction) {
155
- const mapInstance = getMapInstance();
156
-
157
- const { uid, action } = this;
158
-
159
- const contentType = get(uid, mapInstance);
160
-
161
- let contentTypeSchema = contentType[action].content_type.schema;
162
- contentTypeSchema = contentTypeSchema || [];
163
-
164
- const schemaObj = getSchema(field, subAction);
165
- contentTypeSchema.push(schemaObj);
166
-
167
- contentType[action].content_type.schema = contentTypeSchema;
168
-
169
- this.field = schemaObj.uid;
170
- }
171
-
172
- // changeFieldId(currentId, newId) { }
173
-
174
- /**
175
- *
176
- * @param {string} value set display name for the field
177
- * @returns {Field} current instance of field object to chain further methods.
178
- */
179
- display_name(value) {
180
- this.buildSchema(display_name, this.field, value);
181
- return this;
182
- }
183
-
184
- /**
185
- *
186
- * @param {string} value Set data type of the field e.g. text, json, boolean
187
- * @returns {Field} current instance of field object to chain further methods.
188
- */
189
- data_type(value) {
190
- this.buildSchema(data_type, this.field, value);
191
- return this;
192
- }
193
-
194
- /**
195
- *
196
- * @param {boolean} value set true when field is mandatory
197
- * @returns {Field} current instance of field object to chain further methods.
198
- */
199
- mandatory(value) {
200
- this.buildSchema(mandatory, this.field, value);
201
- return this;
202
- }
203
-
204
- /**
205
- *
206
- * @param {string|boolean|number} value set true when field is mandatory
207
- * @returns {Field} current instance of field object to chain further methods.
208
- */
209
- default(value) {
210
- this.buildSchema(_default, this.field, value);
211
- return this;
212
- }
213
-
214
- /**
215
- *
216
- * @param {boolean} value set true if field is unique
217
- * @returns {Field} current instance of field object to chain further methods.
218
- */
219
- unique(value) {
220
- this.buildSchema(unique, this.field, value);
221
- return this;
222
- }
223
-
224
- /**
225
- *
226
- * @param {string | string[]} value uid of reference content type set array if ref_multipleContentType true
227
- * @see {@link ref_multipleContentType}
228
- * @returns {Field} current instance of field object to chain further methods.
229
- */
230
- reference_to(value) {
231
- this.buildSchema(reference_to, this.field, value);
232
- return this;
233
- }
234
-
235
- /**
236
- *
237
- * @param {string} value set true if accepts multiple entries as reference
238
- * @returns {Field} current instance of field object to chain further methods.
239
- */
240
- ref_multiple(value) {
241
- this.buildSchema(field_metadata, this.field, { ref_multiple: value, ref_multiple_content_types: true });
242
- return this;
243
- }
244
-
245
- /**
246
- * The 'taxonomies' property should contain at least one taxonomy object
247
- * @param {string | string[]} value list of taxonomies.
248
- * @returns {Field} current instance of field object to chain further methods.
249
- */
250
- taxonomies(value) {
251
- this.buildSchema(taxonomies, this.field, value);
252
- return this;
253
- }
254
-
255
- /**
256
- *
257
- * @param {boolean} value set true if field is multiple
258
- * @returns {Field} current instance of field object to chain further methods.
259
- */
260
- multiple(value) {
261
- this.buildSchema(multiple, this.field, value);
262
- return this;
263
- }
264
-
265
- /**
266
- *
267
- * @param {boolean} value set true if refer to multiple content types
268
- * @returns {Field} current instance of field object to chain further methods.
269
- */
270
- ref_multipleContentType(value) {
271
- this.buildSchema(field_metadata, this.field, { ref_multiple_content_types: value });
272
- return this;
273
- }
274
-
275
- toTheBottom() {
276
- const { fieldToMove, contentTypeService } = this;
277
-
278
- if (!fieldToMove) throw new Error('Cannot access this method directly.');
279
-
280
- contentTypeService.getActions({ action: 'toTheBottom', fieldToMove });
281
- }
282
-
283
- toTheTop() {
284
- const { fieldToMove, contentTypeService } = this;
285
- if (!fieldToMove) throw new Error('Cannot access this method directly.');
286
-
287
- contentTypeService.getActions({ action: 'toTheTop', fieldToMove });
288
- }
289
-
290
- afterField(field) {
291
- const { fieldToMove, contentTypeService } = this;
292
-
293
- if (!fieldToMove) throw new Error('Cannot access this method directly.');
294
-
295
- contentTypeService.getActions({ action: 'afterField', fieldToMove, against: field });
296
- }
297
-
298
- beforeField(field) {
299
- const { fieldToMove, contentTypeService } = this;
300
-
301
- if (!fieldToMove) throw new Error('Cannot access this method directly.');
302
-
303
- contentTypeService.getActions({ action: 'beforeField', fieldToMove, against: field });
304
- }
305
-
306
- buildSchema(prop, field, value) {
307
- const mapInstance = getMapInstance();
308
-
309
- const { uid, action } = this;
310
-
311
- const contentType = get(uid, mapInstance);
312
-
313
- for (const _schema of contentType[action].content_type.schema) {
314
- if (_schema.uid === field) {
315
- _schema[prop] = value;
316
- break;
317
- }
318
- }
319
- }
320
-
321
- /**
322
- * Once you add the fields to content type you can call this method to get the task definition
323
- * @returns {Task} This task definition is to pass to migration.addTask()
324
- * @example
325
- * migration.addTask(foo.getTaskDefinition())
326
- */
327
- getTaskDefinition() {
328
- return this.request;
329
- }
330
-
331
- getSchemaFromOptions(opts, field) {
332
- const allKeys = keys(opts);
333
- allKeys.forEach((_key) => {
334
- this.buildSchema(_key, field, opts[_key]);
335
- });
336
- }
337
- }
338
-
339
- module.exports = Field;
@@ -1,8 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = {
4
- ContentType: require('./content-types'),
5
- Field: require('./fields'),
6
- Migration: require('./migration'),
7
- Parser: require('./parser'),
8
- };
@@ -1,33 +0,0 @@
1
- 'use strict';
2
-
3
- // Service
4
- const { LocaleService } = require('../services');
5
-
6
- // Config
7
- const { masterLocale } = require('../config');
8
-
9
- // Utils
10
- const { safePromise } = require('../utils');
11
-
12
- class Locale {
13
- constructor() {
14
- this.localeService = new LocaleService();
15
- }
16
-
17
- async fetchLocales(callback) {
18
- let { master_locale } = masterLocale;
19
-
20
- let { localeService } = this;
21
- let [err, result] = await safePromise(localeService.getLocale());
22
-
23
- if (err) throw new Error(err);
24
-
25
- // Use default code, if no result is found
26
- result = result.length ? result : [master_locale];
27
-
28
- if (callback) return callback(null, result);
29
- return result;
30
- }
31
- }
32
-
33
- module.exports = Locale;
@@ -1,112 +0,0 @@
1
- 'use strict';
2
-
3
- const { map: _map, getCallsite, constants, safePromise } = require('../utils');
4
- const Listr = require('listr');
5
- const { waterfall } = require('async');
6
- const { requests } = constants;
7
-
8
- // Properties
9
- const { getMapInstance, set, get } = _map;
10
-
11
- const ContentType = require('./content-types');
12
-
13
- // Merge all classes containing migration methods into a single class
14
- const _Migration = (_Class) => class extends _Class {};
15
-
16
- /**
17
- * Migration class
18
- * @class Migration
19
- */
20
- class Migration extends _Migration(ContentType) {
21
- /**
22
- * Adds custom task in migration to execute.
23
- * @param {Object} taskDescription Task title and task function to execute
24
- * @param {string} taskDescription.title Title for custom task
25
- * @param {array} taskDescription.task async function to be executed
26
- * @param {string} taskDescription.failMessage message to be printed when task fails
27
- * @param {string} taskDescription.successMessage message to be printed when task succeeds
28
- * @example
29
- *
30
- * let first = 'binding glue'
31
- * let second = 'second glue'
32
- * let tasks = {
33
- * title:'My First custom task',
34
- * successMessage: 'Custom success message',
35
- * failMessage: 'Custom fail message'
36
- * task: async (params)=>{
37
- * const {first, second} = params
38
- * const a = await stackSDKInstance.fetch();
39
- * },
40
- * }
41
- * migration.addTask(task)
42
- */
43
- addTask(taskDescription) {
44
- const { title, failMessage, successMessage } = taskDescription;
45
- let { tasks, task } = taskDescription;
46
- const callsite = getCallsite();
47
- const mapInstance = getMapInstance();
48
- // eslint-disable-next-line no-warning-comments
49
- // TODO: Make it better to accept only single task
50
- if (tasks && !Array.isArray(tasks)) tasks = [tasks];
51
- if (task && !Array.isArray(task)) {
52
- tasks = [task];
53
- }
54
- this.contentTypeService.base.dispatch(callsite, null, null, tasks);
55
- let _requests = get(requests, mapInstance);
56
- const req = {
57
- title: title,
58
- failedTitle: failMessage || `Failed to execute task: ${title}`,
59
- successTitle: successMessage || `Successfully executed task: ${title}`,
60
- tasks,
61
- };
62
- _requests.push(req);
63
- set(requests, mapInstance, _requests);
64
- }
65
-
66
- async run() {
67
- const mapInstance = getMapInstance();
68
- let _requests = get(requests, mapInstance);
69
- // Make calls from here
70
- const tasks = await this.getTasks(_requests);
71
- const listr = new Listr(tasks);
72
- await listr.run().catch((error) => {
73
- this.handleErrors(error);
74
- // When the process is child, send error message to parent
75
- if (process.send) process.send({ errorOccurred: true });
76
- });
77
- }
78
-
79
- async getTasks(_requests) {
80
- const _tasks = [];
81
- const results = [];
82
- const taskFn = (reqObj) => {
83
- const { failedTitle, successTitle, tasks } = reqObj;
84
-
85
- return async (ctx, _task) => {
86
- const [err, result] = await safePromise(waterfall(tasks));
87
- if (err) {
88
- ctx.error = true;
89
- _task.title = failedTitle;
90
- throw err;
91
- }
92
- result && results.push(result);
93
- _task.title = successTitle;
94
- return result;
95
- }
96
- }
97
-
98
- for (const element of _requests) {
99
- let reqObj = element;
100
- const { title } = reqObj;
101
- const task = {
102
- title: title,
103
- task: taskFn(reqObj)
104
- };
105
- _tasks.push(task);
106
- }
107
-
108
- return _tasks;
109
- }
110
- }
111
-
112
- module.exports = Migration;