@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
@@ -0,0 +1,173 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ /* eslint-disable camelcase */
5
+ const fields_1 = tslib_1.__importDefault(require("./fields"));
6
+ // Services
7
+ const services_1 = require("../services");
8
+ // Config
9
+ const config_1 = require("../config");
10
+ // Utils
11
+ const utils_1 = require("../utils");
12
+ // Base class
13
+ const base_1 = tslib_1.__importDefault(require("./base"));
14
+ // Properties
15
+ const { getMapInstance, set, get } = utils_1.map;
16
+ const { actions, validationAction } = utils_1.constants;
17
+ const { getUid } = utils_1.schemaHelper;
18
+ const { create, edit } = validationAction;
19
+ /**
20
+ * ContentType class
21
+ * @class ContentType
22
+ * @augments Base
23
+ */
24
+ class ContentType extends base_1.default {
25
+ constructor() {
26
+ super();
27
+ this.contentTypeService = new services_1.ContentTypeService();
28
+ }
29
+ /**
30
+ * Creates content type by passing content type name and options
31
+ * @param {string} id Content type UID
32
+ * @param {Object} opts Optional: Content type fields definition
33
+ * @returns {Field} instance of Field
34
+ * @example
35
+ * module.exports = ({migration}) => {
36
+ * const blog = migration
37
+ * .createContentType('blog')
38
+ * .title('blog title')
39
+ * .description('blog 1')
40
+ * blog.createField('title').display_name('Title').data_type('text').mandatory(true);
41
+ * }
42
+ */
43
+ createContentType(id, opts = {}) {
44
+ const callsite = (0, utils_1.getCallsite)();
45
+ // base class method
46
+ let options = Object.assign(Object.assign({}, config_1.defaultOptions), opts);
47
+ delete options.title;
48
+ delete options.description;
49
+ this.dispatch(callsite, id, opts, create);
50
+ const { title, description } = opts;
51
+ const mapInstance = getMapInstance();
52
+ const { CREATE_CT } = actions;
53
+ const uid = getUid(id);
54
+ const ctObj = { content_type: { title, uid, description, options } };
55
+ const ctActionObj = { [CREATE_CT]: ctObj };
56
+ const { contentTypeService } = this;
57
+ // Sets data to post in map object
58
+ set(id, mapInstance, ctActionObj);
59
+ // Sets action and id in content type service
60
+ contentTypeService.setIdAndAction(id, CREATE_CT);
61
+ const tasks = [contentTypeService.postContentTypes.bind(contentTypeService, callsite, id, CREATE_CT)];
62
+ const req = {
63
+ title: `Adding content type: ${id}`,
64
+ failMessage: `Failed to create content type: ${id}`,
65
+ successMessage: `Successfully added content type: ${id}`,
66
+ tasks,
67
+ };
68
+ let field = new fields_1.default(id, CREATE_CT, contentTypeService, req);
69
+ // TODO: should find better way to attach content type level methods
70
+ field.singleton = this.singleton;
71
+ field.isPage = this.isPage;
72
+ return field;
73
+ }
74
+ /**
75
+ * Set content type to singleton or multiple
76
+ * @param {boolean} value set value true to set content type as singleton default it is multiple
77
+ * @returns {ContentType} instance of ContentType for chaining
78
+ */
79
+ singleton(value) {
80
+ const mapInstance = getMapInstance();
81
+ const { id, action } = this;
82
+ const contentType = get(id, mapInstance);
83
+ contentType[action].content_type.options.singleton = value;
84
+ return this;
85
+ }
86
+ /**
87
+ * Set content type to singleton or multiple
88
+ * @param {boolean} value set value false to set content type as content as block default true
89
+ * @returns {ContentType} instance of ContentType for chaining
90
+ */
91
+ isPage(value) {
92
+ const mapInstance = getMapInstance();
93
+ const { id, action } = this;
94
+ const contentType = get(id, mapInstance);
95
+ contentType[action].content_type.options.is_page = value;
96
+ return this;
97
+ }
98
+ /**
99
+ * Edits content type by passing content type name and options
100
+ * @param {string} id Content type UID
101
+ * @param {Object} opts Optional: Content type fields definition
102
+ * @returns {Field} instance of Field
103
+ * @example
104
+ * module.exports = ({migration}) => {
105
+ * const blog = migration.editContentType('blog');
106
+ * blog.description('Changed description');
107
+ * }
108
+ */
109
+ editContentType(id, opts = {}) {
110
+ let options = Object.assign(Object.assign({}, config_1.defaultOptions), opts);
111
+ delete options.title;
112
+ delete options.description;
113
+ const callsite = (0, utils_1.getCallsite)();
114
+ // base class method
115
+ this.dispatch(callsite, id, {}, edit);
116
+ const { title, description } = opts;
117
+ const mapInstance = getMapInstance();
118
+ const { EDIT_CT } = actions;
119
+ const uid = id;
120
+ const ctObj = { content_type: { title, uid, description, options } };
121
+ const ctActionObj = { [EDIT_CT]: ctObj };
122
+ const { contentTypeService } = this;
123
+ // Sets data to update in map object
124
+ let ctAction = get(id, mapInstance);
125
+ set(id, mapInstance, Object.assign(Object.assign({}, ctActionObj), ctAction));
126
+ // Sets action and id in content type service
127
+ contentTypeService.setIdAndAction(id, EDIT_CT);
128
+ const tasks = [
129
+ contentTypeService.fetchContentType.bind(contentTypeService, callsite, id),
130
+ contentTypeService.applyActionsOnFields.bind(contentTypeService, callsite),
131
+ contentTypeService.editContentType.bind(contentTypeService, callsite),
132
+ ];
133
+ const req = {
134
+ title: `Editing content type: ${id}`,
135
+ failMessage: `Failed to edit content type: ${id}`,
136
+ successMessage: `Successfully updated content type: ${id}`,
137
+ tasks,
138
+ };
139
+ // Keeping the same instance of contentTypeService in Field class
140
+ let fieldI = new fields_1.default(id, EDIT_CT, contentTypeService, req);
141
+ // TODO: should find better way to attach content type level methods
142
+ fieldI.singleton = this.singleton;
143
+ fieldI.isPage = this.isPage;
144
+ return fieldI;
145
+ }
146
+ /**
147
+ * Deletes content type by passing content type name
148
+ * @param {string} id Content type UID
149
+ * @returns {Field} instance of Field
150
+ * @example
151
+ * module.exports = {migrations} => {
152
+ * const blog = migrations.deleteContentType('blog');
153
+ * }
154
+ */
155
+ deleteContentType(id) {
156
+ const callsite = (0, utils_1.getCallsite)();
157
+ const mapInstance = getMapInstance();
158
+ const { DELETE_CT } = actions;
159
+ const uid = getUid(id);
160
+ const ctObj = { content_type: { uid, force: false } }; // keep by default false
161
+ const ctActionObj = { [DELETE_CT]: ctObj };
162
+ const { contentTypeService } = this;
163
+ // Sets data to delete in map object
164
+ set(id, mapInstance, ctActionObj);
165
+ // Sets action and id in content type service
166
+ contentTypeService.setIdAndAction(id, DELETE_CT);
167
+ const tasks = [contentTypeService.deleteContentType.bind(contentTypeService, callsite)];
168
+ const req = { title: 'Deleting content type', tasks };
169
+ return new fields_1.default(id, DELETE_CT, contentTypeService, req);
170
+ }
171
+ }
172
+ exports.default = ContentType;
173
+ //# sourceMappingURL=content-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-types.js","sourceRoot":"","sources":["../../src/modules/content-types.ts"],"names":[],"mappings":";;;AAAA,8BAA8B;AAC9B,8DAA6B;AAE7B,WAAW;AACX,0CAAiD;AAEjD,SAAS;AACT,sCAA2C;AAE3C,QAAQ;AACR,oCAA6E;AAE7E,aAAa;AACb,0DAA0B;AAE1B,aAAa;AACb,MAAM,EAAE,cAAc,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,WAAI,CAAC;AAC1C,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,GAAG,iBAAS,CAAC;AAChD,MAAM,EAAE,MAAM,EAAE,GAAG,oBAAY,CAAC;AAChC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,gBAAgB,CAAC;AAE1C;;;;GAIG;AACH,MAAqB,WAAY,SAAQ,cAAI;IAG3C;QACE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,kBAAkB,GAAG,IAAI,6BAAkB,EAAE,CAAC;IACrD,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,iBAAiB,CAAC,EAAU,EAAE,OAAY,EAAE;QAC1C,MAAM,QAAQ,GAAG,IAAA,mBAAW,GAAE,CAAC;QAC/B,oBAAoB;QACpB,IAAI,OAAO,mCAAa,uBAAc,GAAK,IAAI,CAAE,CAAC;QAClD,OAAO,OAAO,CAAC,KAAK,CAAC;QACrB,OAAO,OAAO,CAAC,WAAW,CAAC;QAC3B,IAAI,CAAC,QAAQ,CA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,cAAc,EAAE,CAAC;QAErC,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;QAE9B,MAAM,GAAG,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;QAEvB,MAAM,KAAK,GAAG,EAAE,YAAY,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,wBAAwB;QAE/E,MAAM,WAAW,GAAG,EAAE,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,CAAC;QAE3C,MAAM,EAAE,kBAAkB,EAAE,GAAG,IAAI,CAAC;QAEpC,oCAAoC;QACpC,GAAG,CAAC,EAAE,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;QAClC,6CAA6C;QAC7C,kBAAkB,CAAC,cAAc,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC;QAEjD,MAAM,KAAK,GAAG,CAAC,kBAAkB,CAAC,iBAAiB,CAAC,IAAI,CAAC,kBAAkB,EAAE,QAAQ,CAAC,CAAC,CAAC;QAExF,MAAM,GAAG,GAAG,EAAE,KAAK,EAAE,uBAAuB,EAAE,KAAK,EAAE,CAAC;QAEtD,OAAO,IAAI,gBAAK,CAAC,EAAE,EAAE,SAAS,EAAE,kBAAkB,EAAE,GAAG,CAAC,CAAC;IAC3D,CAAC;CACF;AAnLD,8BAmLC","sourcesContent":["/* eslint-disable camelcase */\nimport Field from './fields';\n\n// Services\nimport { ContentTypeService } from '../services';\n\n// Config\nimport { defaultOptions } from '../config';\n\n// Utils\nimport { map as _map, schemaHelper, constants, getCallsite } from '../utils';\n\n// Base class\nimport Base from './base';\n\n// Properties\nconst { getMapInstance, set, get } = _map;\nconst { actions, validationAction } = constants;\nconst { getUid } = schemaHelper;\nconst { create, edit } = validationAction;\n\n/**\n * ContentType class\n * @class ContentType\n * @augments Base\n */\nexport default class ContentType extends Base {\n contentTypeService: ContentTypeService;\n\n constructor() {\n super();\n this.contentTypeService = new ContentTypeService();\n }\n\n /**\n * Creates content type by passing content type name and options\n * @param {string} id Content type UID\n * @param {Object} opts Optional: Content type fields definition\n * @returns {Field} instance of Field\n * @example\n * module.exports = ({migration}) => {\n * const blog = migration\n * .createContentType('blog')\n * .title('blog title')\n * .description('blog 1')\n * blog.createField('title').display_name('Title').data_type('text').mandatory(true);\n * }\n */\n createContentType(id: string, opts: any = {}): Field {\n const callsite = getCallsite();\n // base class method\n let options: any = { ...defaultOptions, ...opts };\n delete options.title;\n delete options.description;\n this.dispatch(callsite, id, opts, create);\n const { title, description } = opts;\n const mapInstance = getMapInstance();\n\n const { CREATE_CT } = actions;\n const uid = getUid(id);\n\n const ctObj = { content_type: { title, uid, description, options } };\n\n const ctActionObj = { [CREATE_CT]: ctObj };\n\n const { contentTypeService } = this;\n // Sets data to post in map object\n set(id, mapInstance, ctActionObj);\n // Sets action and id in content type service\n contentTypeService.setIdAndAction(id, CREATE_CT);\n const tasks = [contentTypeService.postContentTypes.bind(contentTypeService, callsite, id, CREATE_CT)];\n const req = {\n title: `Adding content type: ${id}`,\n failMessage: `Failed to create content type: ${id}`,\n successMessage: `Successfully added content type: ${id}`,\n tasks,\n };\n let field = new Field(id, CREATE_CT, contentTypeService, req);\n // TODO: should find better way to attach content type level methods\n (field as any).singleton = this.singleton;\n (field as any).isPage = this.isPage;\n return field;\n }\n\n /**\n * Set content type to singleton or multiple\n * @param {boolean} value set value true to set content type as singleton default it is multiple\n * @returns {ContentType} instance of ContentType for chaining\n */\n singleton(value: boolean): this {\n const mapInstance = getMapInstance();\n const { id, action } = this;\n const contentType = get(id as string, mapInstance);\n\n contentType[action as string].content_type.options.singleton = value;\n return this;\n }\n\n /**\n * Set content type to singleton or multiple\n * @param {boolean} value set value false to set content type as content as block default true\n * @returns {ContentType} instance of ContentType for chaining\n */\n isPage(value: boolean): this {\n const mapInstance = getMapInstance();\n const { id, action } = this;\n const contentType = get(id as string, mapInstance);\n\n contentType[action as string].content_type.options.is_page = value;\n return this;\n }\n\n /**\n * Edits content type by passing content type name and options\n * @param {string} id Content type UID\n * @param {Object} opts Optional: Content type fields definition\n * @returns {Field} instance of Field\n * @example\n * module.exports = ({migration}) => {\n * const blog = migration.editContentType('blog');\n * blog.description('Changed description');\n * }\n */\n editContentType(id: string, opts: any = {}): Field {\n let options: any = { ...defaultOptions, ...opts };\n delete options.title;\n delete options.description;\n\n const callsite = getCallsite();\n // base class method\n this.dispatch(callsite, id, {}, edit);\n const { title, description } = opts;\n const mapInstance = getMapInstance();\n\n const { EDIT_CT } = actions;\n\n const uid = id;\n\n const ctObj = { content_type: { title, uid, description, options } };\n const ctActionObj = { [EDIT_CT]: ctObj };\n\n const { contentTypeService } = this;\n\n // Sets data to update in map object\n let ctAction = get(id, mapInstance);\n\n set(id, mapInstance, { ...ctActionObj, ...ctAction });\n // Sets action and id in content type service\n contentTypeService.setIdAndAction(id, EDIT_CT);\n const tasks = [\n contentTypeService.fetchContentType.bind(contentTypeService, callsite, id),\n contentTypeService.applyActionsOnFields.bind(contentTypeService, callsite),\n contentTypeService.editContentType.bind(contentTypeService, callsite),\n ];\n\n const req = {\n title: `Editing content type: ${id}`,\n failMessage: `Failed to edit content type: ${id}`,\n successMessage: `Successfully updated content type: ${id}`,\n tasks,\n };\n\n // Keeping the same instance of contentTypeService in Field class\n let fieldI = new Field(id, EDIT_CT, contentTypeService, req);\n // TODO: should find better way to attach content type level methods\n (fieldI as any).singleton = this.singleton;\n (fieldI as any).isPage = this.isPage;\n return fieldI;\n }\n\n /**\n * Deletes content type by passing content type name\n * @param {string} id Content type UID\n * @returns {Field} instance of Field\n * @example\n * module.exports = {migrations} => {\n * const blog = migrations.deleteContentType('blog');\n * }\n */\n deleteContentType(id: string): Field {\n const callsite = getCallsite();\n\n const mapInstance = getMapInstance();\n\n const { DELETE_CT } = actions;\n\n const uid = getUid(id);\n\n const ctObj = { content_type: { uid, force: false } }; // keep by default false\n\n const ctActionObj = { [DELETE_CT]: ctObj };\n\n const { contentTypeService } = this;\n\n // Sets data to delete in map object\n set(id, mapInstance, ctActionObj);\n // Sets action and id in content type service\n contentTypeService.setIdAndAction(id, DELETE_CT);\n\n const tasks = [contentTypeService.deleteContentType.bind(contentTypeService, callsite)];\n\n const req = { title: 'Deleting content type', tasks };\n\n return new Field(id, DELETE_CT, contentTypeService, req);\n }\n}\n"]}
@@ -0,0 +1,179 @@
1
+ import Base from './base';
2
+ /**
3
+ * Field class
4
+ * @class Field
5
+ */
6
+ export default class Field extends Base {
7
+ uid: string;
8
+ action: string;
9
+ contentTypeService: any;
10
+ request: any;
11
+ field: string | undefined;
12
+ fieldToMove: string | undefined;
13
+ singleton?: (value: boolean) => this;
14
+ isPage?: (value: boolean) => this;
15
+ constructor(uid: string, action: string, contentTypeService: any, request: any);
16
+ /**
17
+ * @typedef {Object} Task
18
+ * @param {string} title - Title for custom task
19
+ * @param {function[]} task - array of async function to be executed
20
+ * @param {string} failMessage message to be printed when task fails
21
+ * @param {string} successMessage - message to be printed when task succeeds
22
+ */
23
+ /**
24
+ * Creates a field with provided uid.
25
+ * @param {string} field Field name to be created
26
+ * @param {Object} opts Options to be passed
27
+ * @returns {Field} current instance of field object to chain further methods.
28
+ * @example
29
+ * module.exports =({ migration })=> {
30
+ * const blog = migration.editContentType('blog');
31
+ *
32
+ * blog.createField('author')
33
+ * .display_name('Author')
34
+ * .data_type('text')
35
+ * .mandatory(false);
36
+ * };
37
+ *
38
+ * Create a taxonomy field
39
+ *
40
+ * module.exports =({ migration })=> {
41
+ * const blog = migration.editContentType('blog');
42
+ *
43
+ * blog.createField('taxonomies')
44
+ * .display_name('Taxonomy1')
45
+ * .data_type('taxonomy')
46
+ * .taxonomies([{ "taxonomy_uid": "test_taxonomy1", "max_terms": 2, "mandatory": false}])
47
+ * .multiple(true)
48
+ * .mandatory(false);
49
+ * };
50
+ */
51
+ createField(field: string, opts?: any): this;
52
+ /**
53
+ * Edits the field with provided uid.
54
+ * @param {string} field Field name to be edited
55
+ * @param {Object} opts Options to be passed
56
+ * @returns {Field} current instance of field object to chain further methods.
57
+ * @example
58
+ * module.exports =({ migration })=> {
59
+ * const blog = migration.editContentType('blog');
60
+ *
61
+ * blog.editField('uniqueid')
62
+ * .display_name('Unique ID')
63
+ * .mandatory(false);
64
+ * };
65
+ */
66
+ editField(field: string, opts?: any): this;
67
+ /**
68
+ * Delete a field from the content type
69
+ * @param {string} field Field uid to be deleted
70
+ * @returns {Field} current instance of field object to chain further methods.
71
+ * @example
72
+ * module.exports =({ migration })=> {
73
+ * const blog = migration.editContentType('blog');
74
+ *
75
+ * blog.deleteField('uniqueid');
76
+ * };
77
+ */
78
+ deleteField(field: string): this;
79
+ /**
80
+ * Move the field (position of the field in the editor)
81
+ * @param {string} field Field uid to be moved
82
+ * @returns {Field} current instance of field object to chain further methods.
83
+ * @example
84
+ * module.exports = ({migration}) => {
85
+ * const blog = migration.editContentType('blog');
86
+ *
87
+ * blog.createField('credits')
88
+ * .display_name('Credits')
89
+ * .data_type('text')
90
+ * .mandatory(false);
91
+ *
92
+ * blog.createField('references')
93
+ * .display_name('References')
94
+ * .data_type('text')
95
+ * .mandatory(false);
96
+ *
97
+ * blog.moveField('uniqueid').toTheBottom();
98
+ * blog.moveField('references').beforeField('credits');
99
+ * blog.moveField('author').toTheTop();
100
+ * blog.moveField('url').afterField('author');
101
+ * };
102
+ */
103
+ moveField(field: string): this;
104
+ updateContentTypeSchema(field: string, subAction?: string): void;
105
+ /**
106
+ *
107
+ * @param {string} value set display name for the field
108
+ * @returns {Field} current instance of field object to chain further methods.
109
+ */
110
+ display_name(value: string): this;
111
+ /**
112
+ *
113
+ * @param {string} value Set data type of the field e.g. text, json, boolean
114
+ * @returns {Field} current instance of field object to chain further methods.
115
+ */
116
+ data_type(value: string): this;
117
+ /**
118
+ *
119
+ * @param {boolean} value set true when field is mandatory
120
+ * @returns {Field} current instance of field object to chain further methods.
121
+ */
122
+ mandatory(value: boolean): this;
123
+ /**
124
+ *
125
+ * @param {string|boolean|number} value set true when field is mandatory
126
+ * @returns {Field} current instance of field object to chain further methods.
127
+ */
128
+ default(value: string | boolean | number): this;
129
+ /**
130
+ *
131
+ * @param {boolean} value set true if field is unique
132
+ * @returns {Field} current instance of field object to chain further methods.
133
+ */
134
+ unique(value: boolean): this;
135
+ /**
136
+ *
137
+ * @param {string | string[]} value uid of reference content type set array if ref_multipleContentType true
138
+ * @see {@link ref_multipleContentType}
139
+ * @returns {Field} current instance of field object to chain further methods.
140
+ */
141
+ reference_to(value: string | string[]): this;
142
+ /**
143
+ *
144
+ * @param {string} value set true if accepts multiple entries as reference
145
+ * @returns {Field} current instance of field object to chain further methods.
146
+ */
147
+ ref_multiple(value: boolean): this;
148
+ /**
149
+ * The 'taxonomies' property should contain at least one taxonomy object
150
+ * @param {string | string[]} value list of taxonomies.
151
+ * @returns {Field} current instance of field object to chain further methods.
152
+ */
153
+ taxonomies(value: any): this;
154
+ /**
155
+ *
156
+ * @param {boolean} value set true if field is multiple
157
+ * @returns {Field} current instance of field object to chain further methods.
158
+ */
159
+ multiple(value: boolean): this;
160
+ /**
161
+ *
162
+ * @param {boolean} value set true if refer to multiple content types
163
+ * @returns {Field} current instance of field object to chain further methods.
164
+ */
165
+ ref_multipleContentType(value: boolean): this;
166
+ toTheBottom(): void;
167
+ toTheTop(): void;
168
+ afterField(field: string): void;
169
+ beforeField(field: string): void;
170
+ buildSchema(prop: string, field: string, value: any): void;
171
+ /**
172
+ * Once you add the fields to content type you can call this method to get the task definition
173
+ * @returns {Task} This task definition is to pass to migration.addTask()
174
+ * @example
175
+ * migration.addTask(foo.getTaskDefinition())
176
+ */
177
+ getTaskDefinition(): any;
178
+ getSchemaFromOptions(opts: any, field: string): void;
179
+ }
@@ -0,0 +1,292 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ // Utils
5
+ const utils_1 = require("../utils");
6
+ // Utils Properties
7
+ const { getMapInstance, get } = utils_1.map;
8
+ const { getSchema } = utils_1.schemaHelper;
9
+ const { data_type, mandatory, _default, unique, display_name, field_metadata, reference_to, actions: _actions, taxonomies, multiple, } = utils_1.constants;
10
+ // Base class
11
+ const base_1 = tslib_1.__importDefault(require("./base"));
12
+ /**
13
+ * Field class
14
+ * @class Field
15
+ */
16
+ class Field extends base_1.default {
17
+ // prop, value
18
+ constructor(uid, action, contentTypeService, request) {
19
+ super(uid);
20
+ this.uid = uid;
21
+ this.action = action;
22
+ this.contentTypeService = contentTypeService;
23
+ this.request = request;
24
+ }
25
+ /**
26
+ * @typedef {Object} Task
27
+ * @param {string} title - Title for custom task
28
+ * @param {function[]} task - array of async function to be executed
29
+ * @param {string} failMessage message to be printed when task fails
30
+ * @param {string} successMessage - message to be printed when task succeeds
31
+ */
32
+ /**
33
+ * Creates a field with provided uid.
34
+ * @param {string} field Field name to be created
35
+ * @param {Object} opts Options to be passed
36
+ * @returns {Field} current instance of field object to chain further methods.
37
+ * @example
38
+ * module.exports =({ migration })=> {
39
+ * const blog = migration.editContentType('blog');
40
+ *
41
+ * blog.createField('author')
42
+ * .display_name('Author')
43
+ * .data_type('text')
44
+ * .mandatory(false);
45
+ * };
46
+ *
47
+ * Create a taxonomy field
48
+ *
49
+ * module.exports =({ migration })=> {
50
+ * const blog = migration.editContentType('blog');
51
+ *
52
+ * blog.createField('taxonomies')
53
+ * .display_name('Taxonomy1')
54
+ * .data_type('taxonomy')
55
+ * .taxonomies([{ "taxonomy_uid": "test_taxonomy1", "max_terms": 2, "mandatory": false}])
56
+ * .multiple(true)
57
+ * .mandatory(false);
58
+ * };
59
+ */
60
+ createField(field, opts) {
61
+ this.updateContentTypeSchema(field);
62
+ // Build schema from options provided
63
+ if (opts && Object.keys(opts).length) {
64
+ this.getSchemaFromOptions(opts, field);
65
+ return this;
66
+ }
67
+ return this;
68
+ }
69
+ /**
70
+ * Edits the field with provided uid.
71
+ * @param {string} field Field name to be edited
72
+ * @param {Object} opts Options to be passed
73
+ * @returns {Field} current instance of field object to chain further methods.
74
+ * @example
75
+ * module.exports =({ migration })=> {
76
+ * const blog = migration.editContentType('blog');
77
+ *
78
+ * blog.editField('uniqueid')
79
+ * .display_name('Unique ID')
80
+ * .mandatory(false);
81
+ * };
82
+ */
83
+ editField(field, opts) {
84
+ const { EDIT_FIELD } = _actions;
85
+ this.updateContentTypeSchema(field, EDIT_FIELD);
86
+ // Build schema from options provided
87
+ if (opts && Object.keys(opts).length) {
88
+ this.getSchemaFromOptions(opts, field);
89
+ return this;
90
+ }
91
+ return this;
92
+ }
93
+ /**
94
+ * Delete a field from the content type
95
+ * @param {string} field Field uid to be deleted
96
+ * @returns {Field} current instance of field object to chain further methods.
97
+ * @example
98
+ * module.exports =({ migration })=> {
99
+ * const blog = migration.editContentType('blog');
100
+ *
101
+ * blog.deleteField('uniqueid');
102
+ * };
103
+ */
104
+ deleteField(field) {
105
+ const { DELETE_FIELD } = _actions;
106
+ this.updateContentTypeSchema(field, DELETE_FIELD);
107
+ return this;
108
+ }
109
+ /**
110
+ * Move the field (position of the field in the editor)
111
+ * @param {string} field Field uid to be moved
112
+ * @returns {Field} current instance of field object to chain further methods.
113
+ * @example
114
+ * module.exports = ({migration}) => {
115
+ * const blog = migration.editContentType('blog');
116
+ *
117
+ * blog.createField('credits')
118
+ * .display_name('Credits')
119
+ * .data_type('text')
120
+ * .mandatory(false);
121
+ *
122
+ * blog.createField('references')
123
+ * .display_name('References')
124
+ * .data_type('text')
125
+ * .mandatory(false);
126
+ *
127
+ * blog.moveField('uniqueid').toTheBottom();
128
+ * blog.moveField('references').beforeField('credits');
129
+ * blog.moveField('author').toTheTop();
130
+ * blog.moveField('url').afterField('author');
131
+ * };
132
+ */
133
+ moveField(field) {
134
+ this.fieldToMove = field;
135
+ return this;
136
+ }
137
+ updateContentTypeSchema(field, subAction) {
138
+ const mapInstance = getMapInstance();
139
+ const { uid, action } = this;
140
+ const contentType = get(uid, mapInstance);
141
+ let contentTypeSchema = contentType[action].content_type.schema;
142
+ contentTypeSchema = contentTypeSchema || [];
143
+ const schemaObj = getSchema(field, subAction);
144
+ contentTypeSchema.push(schemaObj);
145
+ contentType[action].content_type.schema = contentTypeSchema;
146
+ this.field = schemaObj.uid;
147
+ }
148
+ // changeFieldId(currentId, newId) { }
149
+ /**
150
+ *
151
+ * @param {string} value set display name for the field
152
+ * @returns {Field} current instance of field object to chain further methods.
153
+ */
154
+ display_name(value) {
155
+ this.buildSchema(display_name, this.field, value);
156
+ return this;
157
+ }
158
+ /**
159
+ *
160
+ * @param {string} value Set data type of the field e.g. text, json, boolean
161
+ * @returns {Field} current instance of field object to chain further methods.
162
+ */
163
+ data_type(value) {
164
+ this.buildSchema(data_type, this.field, value);
165
+ return this;
166
+ }
167
+ /**
168
+ *
169
+ * @param {boolean} value set true when field is mandatory
170
+ * @returns {Field} current instance of field object to chain further methods.
171
+ */
172
+ mandatory(value) {
173
+ this.buildSchema(mandatory, this.field, value);
174
+ return this;
175
+ }
176
+ /**
177
+ *
178
+ * @param {string|boolean|number} value set true when field is mandatory
179
+ * @returns {Field} current instance of field object to chain further methods.
180
+ */
181
+ default(value) {
182
+ this.buildSchema(_default, this.field, value);
183
+ return this;
184
+ }
185
+ /**
186
+ *
187
+ * @param {boolean} value set true if field is unique
188
+ * @returns {Field} current instance of field object to chain further methods.
189
+ */
190
+ unique(value) {
191
+ this.buildSchema(unique, this.field, value);
192
+ return this;
193
+ }
194
+ /**
195
+ *
196
+ * @param {string | string[]} value uid of reference content type set array if ref_multipleContentType true
197
+ * @see {@link ref_multipleContentType}
198
+ * @returns {Field} current instance of field object to chain further methods.
199
+ */
200
+ reference_to(value) {
201
+ this.buildSchema(reference_to, this.field, value);
202
+ return this;
203
+ }
204
+ /**
205
+ *
206
+ * @param {string} value set true if accepts multiple entries as reference
207
+ * @returns {Field} current instance of field object to chain further methods.
208
+ */
209
+ ref_multiple(value) {
210
+ this.buildSchema(field_metadata, this.field, { ref_multiple: value, ref_multiple_content_types: true });
211
+ return this;
212
+ }
213
+ /**
214
+ * The 'taxonomies' property should contain at least one taxonomy object
215
+ * @param {string | string[]} value list of taxonomies.
216
+ * @returns {Field} current instance of field object to chain further methods.
217
+ */
218
+ taxonomies(value) {
219
+ this.buildSchema(taxonomies, this.field, value);
220
+ return this;
221
+ }
222
+ /**
223
+ *
224
+ * @param {boolean} value set true if field is multiple
225
+ * @returns {Field} current instance of field object to chain further methods.
226
+ */
227
+ multiple(value) {
228
+ this.buildSchema(multiple, this.field, value);
229
+ return this;
230
+ }
231
+ /**
232
+ *
233
+ * @param {boolean} value set true if refer to multiple content types
234
+ * @returns {Field} current instance of field object to chain further methods.
235
+ */
236
+ ref_multipleContentType(value) {
237
+ this.buildSchema(field_metadata, this.field, { ref_multiple_content_types: value });
238
+ return this;
239
+ }
240
+ toTheBottom() {
241
+ const { fieldToMove, contentTypeService } = this;
242
+ if (!fieldToMove)
243
+ throw new Error('Cannot access this method directly.');
244
+ contentTypeService.getActions({ action: 'toTheBottom', fieldToMove });
245
+ }
246
+ toTheTop() {
247
+ const { fieldToMove, contentTypeService } = this;
248
+ if (!fieldToMove)
249
+ throw new Error('Cannot access this method directly.');
250
+ contentTypeService.getActions({ action: 'toTheTop', fieldToMove });
251
+ }
252
+ afterField(field) {
253
+ const { fieldToMove, contentTypeService } = this;
254
+ if (!fieldToMove)
255
+ throw new Error('Cannot access this method directly.');
256
+ contentTypeService.getActions({ action: 'afterField', fieldToMove, against: field });
257
+ }
258
+ beforeField(field) {
259
+ const { fieldToMove, contentTypeService } = this;
260
+ if (!fieldToMove)
261
+ throw new Error('Cannot access this method directly.');
262
+ contentTypeService.getActions({ action: 'beforeField', fieldToMove, against: field });
263
+ }
264
+ buildSchema(prop, field, value) {
265
+ const mapInstance = getMapInstance();
266
+ const { uid, action } = this;
267
+ const contentType = get(uid, mapInstance);
268
+ for (const _schema of contentType[action].content_type.schema) {
269
+ if (_schema.uid === field) {
270
+ _schema[prop] = value;
271
+ break;
272
+ }
273
+ }
274
+ }
275
+ /**
276
+ * Once you add the fields to content type you can call this method to get the task definition
277
+ * @returns {Task} This task definition is to pass to migration.addTask()
278
+ * @example
279
+ * migration.addTask(foo.getTaskDefinition())
280
+ */
281
+ getTaskDefinition() {
282
+ return this.request;
283
+ }
284
+ getSchemaFromOptions(opts, field) {
285
+ const allKeys = Object.keys(opts);
286
+ allKeys.forEach((_key) => {
287
+ this.buildSchema(_key, field, opts[_key]);
288
+ });
289
+ }
290
+ }
291
+ exports.default = Field;
292
+ //# sourceMappingURL=fields.js.map