@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 @@
1
+ {"version":3,"file":"fields.js","sourceRoot":"","sources":["../../src/modules/fields.ts"],"names":[],"mappings":";;;AAAA,QAAQ;AACR,oCAAgE;AAEhE,mBAAmB;AACnB,MAAM,EAAE,cAAc,EAAE,GAAG,EAAE,GAAG,WAAI,CAAC;AACrC,MAAM,EAAE,SAAS,EAAE,GAAG,oBAAY,CAAC;AACnC,MAAM,EACJ,SAAS,EACT,SAAS,EACT,QAAQ,EACR,MAAM,EACN,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,OAAO,EAAE,QAAQ,EACjB,UAAU,EACV,QAAQ,GACT,GAAG,iBAAS,CAAC;AAEd,aAAa;AACb,0DAA0B;AAE1B;;;GAGG;AACH,MAAqB,KAAM,SAAQ,cAAI;IAUrC,cAAc;IACd,YAAY,GAAW,EAAE,MAAc,EAAE,kBAAuB,EAAE,OAAY;QAC5E,KAAK,CAAC,GAAG,CAAC,CAAC;QACX,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;QAC7C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED;;;;;;OAMG;IAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,WAAW,CAAC,KAAa,EAAE,IAAU;QACnC,IAAI,CAAC,uBAAuB,CAAC,KAAK,CAAC,CAAC;QAEpC,qCAAqC;QACrC,IAAI,IAAI,IAA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AAW,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAC5C,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAlUD,wBAkUC","sourcesContent":["// Utils\nimport { map as _map, schemaHelper, constants } from '../utils';\n\n// Utils Properties\nconst { getMapInstance, get } = _map;\nconst { getSchema } = schemaHelper;\nconst {\n data_type,\n mandatory,\n _default,\n unique,\n display_name,\n field_metadata,\n reference_to,\n actions: _actions,\n taxonomies,\n multiple,\n} = constants;\n\n// Base class\nimport Base from './base';\n\n/**\n * Field class\n * @class Field\n */\nexport default class Field extends Base {\n uid: string;\n action: string;\n contentTypeService: any;\n request: any;\n field: string | undefined;\n fieldToMove: string | undefined;\n singleton?: (value: boolean) => this;\n isPage?: (value: boolean) => this;\n\n // prop, value\n constructor(uid: string, action: string, contentTypeService: any, request: any) {\n super(uid);\n this.uid = uid;\n this.action = action;\n this.contentTypeService = contentTypeService;\n this.request = request;\n }\n\n /**\n * @typedef {Object} Task\n * @param {string} title - Title for custom task\n * @param {function[]} task - array of async function to be executed\n * @param {string} failMessage message to be printed when task fails\n * @param {string} successMessage - message to be printed when task succeeds\n */\n\n /**\n * Creates a field with provided uid.\n * @param {string} field Field name to be created\n * @param {Object} opts Options to be passed\n * @returns {Field} current instance of field object to chain further methods.\n * @example\n * module.exports =({ migration })=> {\n * const blog = migration.editContentType('blog');\n *\n * blog.createField('author')\n * .display_name('Author')\n * .data_type('text')\n * .mandatory(false);\n * };\n * \n * Create a taxonomy field\n * \n * module.exports =({ migration })=> {\n * const blog = migration.editContentType('blog');\n *\n * blog.createField('taxonomies')\n * .display_name('Taxonomy1')\n * .data_type('taxonomy')\n * .taxonomies([{ \"taxonomy_uid\": \"test_taxonomy1\", \"max_terms\": 2, \"mandatory\": false}])\n * .multiple(true)\n * .mandatory(false);\n * };\n */\n createField(field: string, opts?: any): this {\n this.updateContentTypeSchema(field);\n\n // Build schema from options provided\n if (opts && Object.keys(opts).length) {\n this.getSchemaFromOptions(opts, field);\n return this;\n }\n return this;\n }\n\n /**\n * Edits the field with provided uid.\n * @param {string} field Field name to be edited\n * @param {Object} opts Options to be passed\n * @returns {Field} current instance of field object to chain further methods.\n * @example\n * module.exports =({ migration })=> {\n * const blog = migration.editContentType('blog');\n *\n * blog.editField('uniqueid')\n * .display_name('Unique ID')\n * .mandatory(false);\n * };\n */\n editField(field: string, opts?: any): this {\n const { EDIT_FIELD } = _actions;\n this.updateContentTypeSchema(field, EDIT_FIELD);\n\n // Build schema from options provided\n if (opts && Object.keys(opts).length) {\n this.getSchemaFromOptions(opts, field);\n return this;\n }\n return this;\n }\n\n /**\n * Delete a field from the content type\n * @param {string} field Field uid to be deleted\n * @returns {Field} current instance of field object to chain further methods.\n * @example\n * module.exports =({ migration })=> {\n * const blog = migration.editContentType('blog');\n *\n * blog.deleteField('uniqueid');\n * };\n */\n deleteField(field: string): this {\n const { DELETE_FIELD } = _actions;\n this.updateContentTypeSchema(field, DELETE_FIELD);\n\n return this;\n }\n\n /**\n * Move the field (position of the field in the editor)\n * @param {string} field Field uid to be moved\n * @returns {Field} current instance of field object to chain further methods.\n * @example\n * module.exports = ({migration}) => {\n * const blog = migration.editContentType('blog');\n *\n * blog.createField('credits')\n * .display_name('Credits')\n * .data_type('text')\n * .mandatory(false);\n *\n * blog.createField('references')\n * .display_name('References')\n * .data_type('text')\n * .mandatory(false);\n *\n * blog.moveField('uniqueid').toTheBottom();\n * blog.moveField('references').beforeField('credits');\n * blog.moveField('author').toTheTop();\n * blog.moveField('url').afterField('author');\n * };\n */\n moveField(field: string): this {\n this.fieldToMove = field;\n return this;\n }\n\n updateContentTypeSchema(field: string, subAction?: string): void {\n const mapInstance = getMapInstance();\n\n const { uid, action } = this;\n\n const contentType = get(uid, mapInstance);\n\n let contentTypeSchema = contentType[action].content_type.schema;\n contentTypeSchema = contentTypeSchema || [];\n\n const schemaObj = getSchema(field, subAction);\n contentTypeSchema.push(schemaObj);\n\n contentType[action].content_type.schema = contentTypeSchema;\n\n this.field = schemaObj.uid;\n }\n\n // changeFieldId(currentId, newId) { }\n\n /**\n *\n * @param {string} value set display name for the field\n * @returns {Field} current instance of field object to chain further methods.\n */\n display_name(value: string): this {\n this.buildSchema(display_name, this.field as string, value);\n return this;\n }\n\n /**\n *\n * @param {string} value Set data type of the field e.g. text, json, boolean\n * @returns {Field} current instance of field object to chain further methods.\n */\n data_type(value: string): this {\n this.buildSchema(data_type, this.field as string, value);\n return this;\n }\n\n /**\n *\n * @param {boolean} value set true when field is mandatory\n * @returns {Field} current instance of field object to chain further methods.\n */\n mandatory(value: boolean): this {\n this.buildSchema(mandatory, this.field as string, value);\n return this;\n }\n\n /**\n *\n * @param {string|boolean|number} value set true when field is mandatory\n * @returns {Field} current instance of field object to chain further methods.\n */\n default(value: string | boolean | number): this {\n this.buildSchema(_default, this.field as string, value);\n return this;\n }\n\n /**\n *\n * @param {boolean} value set true if field is unique\n * @returns {Field} current instance of field object to chain further methods.\n */\n unique(value: boolean): this {\n this.buildSchema(unique, this.field as string, value);\n return this;\n }\n\n /**\n *\n * @param {string | string[]} value uid of reference content type set array if ref_multipleContentType true\n * @see {@link ref_multipleContentType}\n * @returns {Field} current instance of field object to chain further methods.\n */\n reference_to(value: string | string[]): this {\n this.buildSchema(reference_to, this.field as string, value);\n return this;\n }\n\n /**\n *\n * @param {string} value set true if accepts multiple entries as reference\n * @returns {Field} current instance of field object to chain further methods.\n */\n ref_multiple(value: boolean): this {\n this.buildSchema(field_metadata, this.field as string, { ref_multiple: value, ref_multiple_content_types: true });\n return this;\n }\n\n /**\n * The 'taxonomies' property should contain at least one taxonomy object\n * @param {string | string[]} value list of taxonomies.\n * @returns {Field} current instance of field object to chain further methods.\n */\n taxonomies(value: any): this {\n this.buildSchema(taxonomies, this.field as string, value);\n return this;\n }\n\n /**\n *\n * @param {boolean} value set true if field is multiple\n * @returns {Field} current instance of field object to chain further methods.\n */\n multiple(value: boolean): this {\n this.buildSchema(multiple, this.field as string, value);\n return this;\n }\n\n /**\n *\n * @param {boolean} value set true if refer to multiple content types\n * @returns {Field} current instance of field object to chain further methods.\n */\n ref_multipleContentType(value: boolean): this {\n this.buildSchema(field_metadata, this.field as string, { ref_multiple_content_types: value });\n return this;\n }\n\n toTheBottom(): void {\n const { fieldToMove, contentTypeService } = this;\n\n if (!fieldToMove) throw new Error('Cannot access this method directly.');\n\n contentTypeService.getActions({ action: 'toTheBottom', fieldToMove });\n }\n\n toTheTop(): void {\n const { fieldToMove, contentTypeService } = this;\n if (!fieldToMove) throw new Error('Cannot access this method directly.');\n\n contentTypeService.getActions({ action: 'toTheTop', fieldToMove });\n }\n\n afterField(field: string): void {\n const { fieldToMove, contentTypeService } = this;\n\n if (!fieldToMove) throw new Error('Cannot access this method directly.');\n\n contentTypeService.getActions({ action: 'afterField', fieldToMove, against: field });\n }\n\n beforeField(field: string): void {\n const { fieldToMove, contentTypeService } = this;\n\n if (!fieldToMove) throw new Error('Cannot access this method directly.');\n\n contentTypeService.getActions({ action: 'beforeField', fieldToMove, against: field });\n }\n\n buildSchema(prop: string, field: string, value: any): void {\n const mapInstance = getMapInstance();\n\n const { uid, action } = this;\n\n const contentType = get(uid, mapInstance);\n\n for (const _schema of contentType[action].content_type.schema) {\n if (_schema.uid === field) {\n _schema[prop] = value;\n break;\n }\n }\n }\n\n /**\n * Once you add the fields to content type you can call this method to get the task definition\n * @returns {Task} This task definition is to pass to migration.addTask()\n * @example\n * migration.addTask(foo.getTaskDefinition())\n */\n getTaskDefinition(): any {\n return this.request;\n }\n\n getSchemaFromOptions(opts: any, field: string): void {\n const allKeys = Object.keys(opts);\n allKeys.forEach((_key: string) => {\n this.buildSchema(_key, field, opts[_key]);\n });\n }\n}\n"]}
@@ -0,0 +1,5 @@
1
+ import ContentType from './content-types';
2
+ import Field from './fields';
3
+ import Migration from './migration';
4
+ import Parser from './parser';
5
+ export { ContentType, Field, Migration, Parser };
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Parser = exports.Migration = exports.Field = exports.ContentType = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const content_types_1 = tslib_1.__importDefault(require("./content-types"));
6
+ exports.ContentType = content_types_1.default;
7
+ const fields_1 = tslib_1.__importDefault(require("./fields"));
8
+ exports.Field = fields_1.default;
9
+ const migration_1 = tslib_1.__importDefault(require("./migration"));
10
+ exports.Migration = migration_1.default;
11
+ const parser_1 = tslib_1.__importDefault(require("./parser"));
12
+ exports.Parser = parser_1.default;
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/modules/index.ts"],"names":[],"mappings":";;;;AAAA,4EAA0C;AAKjC,sBALF,uBAAW,CAKE;AAJpB,8DAA6B;AAIP,gBAJf,gBAAK,CAIe;AAH3B,oEAAoC;AAGP,oBAHtB,mBAAS,CAGsB;AAFtC,8DAA8B;AAEU,iBAFjC,gBAAM,CAEiC","sourcesContent":["import ContentType from './content-types';\nimport Field from './fields';\nimport Migration from './migration';\nimport Parser from './parser';\n\nexport { ContentType, Field, Migration, Parser };\n"]}
@@ -0,0 +1,6 @@
1
+ import { LocaleService } from '../services';
2
+ export default class Locale {
3
+ localeService: LocaleService;
4
+ constructor();
5
+ fetchLocales(callback?: (err: Error | null, result: any) => void): Promise<any>;
6
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // Service
4
+ const services_1 = require("../services");
5
+ // Config
6
+ const config_1 = require("../config");
7
+ // Utils
8
+ const utils_1 = require("../utils");
9
+ class Locale {
10
+ constructor() {
11
+ this.localeService = new services_1.LocaleService();
12
+ }
13
+ async fetchLocales(callback) {
14
+ let { master_locale } = config_1.masterLocale;
15
+ let { localeService } = this;
16
+ let [err, result] = await (0, utils_1.safePromise)(localeService.getLocale());
17
+ if (err)
18
+ throw new Error(err);
19
+ // Use default code, if no result is found
20
+ result = result.length ? result : [master_locale];
21
+ if (callback)
22
+ return callback(null, result);
23
+ return result;
24
+ }
25
+ }
26
+ exports.default = Locale;
27
+ //# sourceMappingURL=locale.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locale.js","sourceRoot":"","sources":["../../src/modules/locale.ts"],"names":[],"mappings":";;AAAA,UAAU;AACV,0CAA4C;AAE5C,SAAS;AACT,sCAAyC;AAEzC,QAAQ;AACR,oCAAuC;AAEvC,MAAqB,MAAM;IAGzB;QACE,IAAI,CAAC,aAAa,GAAG,IAAI,wBAAa,EAAE,CAAC;IAC3C,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,QAAmD;QACpE,IAAI,EAAE,aAAa,EAAE,GAAG,qBAAY,CAAC;QAErC,IAAI,EAAE,aAAa,EAAE,GAAG,IAAI,CAAC;QAC7B,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,MAAM,IAAA,mBAAW,EAAC,aAAa,CAAC,SAAS,EAAE,CAAC,CAAC;QAEjE,IAAI,GAAG;YAAE,MAAM,IAAI,KAAK,CAAC,GAAU,CAAC,CAAC;QAErC,0CAA0C;QAC1C,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC;QAElD,IAAI,QAAQ;YAAE,OAAO,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAC5C,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AArBD,yBAqBC","sourcesContent":["// Service\nimport { LocaleService } from '../services';\n\n// Config\nimport { masterLocale } from '../config';\n\n// Utils\nimport { safePromise } from '../utils';\n\nexport default class Locale {\n localeService: LocaleService;\n\n constructor() {\n this.localeService = new LocaleService();\n }\n\n async fetchLocales(callback?: (err: Error | null, result: any) => void): Promise<any> {\n let { master_locale } = masterLocale;\n\n let { localeService } = this;\n let [err, result] = await safePromise(localeService.getLocale());\n\n if (err) throw new Error(err as any);\n\n // Use default code, if no result is found\n result = result.length ? result : [master_locale];\n\n if (callback) return callback(null, result);\n return result;\n }\n}\n"]}
@@ -0,0 +1,50 @@
1
+ declare const Migration_base: {
2
+ new (): {
3
+ contentTypeService: import("../services").ContentTypeService;
4
+ createContentType(id: string, opts?: any): import("./fields").default;
5
+ singleton(value: boolean): any;
6
+ isPage(value: boolean): any;
7
+ editContentType(id: string, opts?: any): import("./fields").default;
8
+ deleteContentType(id: string): import("./fields").default;
9
+ id: string;
10
+ action: string;
11
+ actions: any[];
12
+ title(value: string): any;
13
+ description(value: string): any;
14
+ force(value: boolean): any;
15
+ dispatch(callsite: any, id: string, opts: any, method: string): void;
16
+ getActions(): any[];
17
+ };
18
+ };
19
+ /**
20
+ * Migration class
21
+ * @class Migration
22
+ */
23
+ export default class Migration extends Migration_base {
24
+ /**
25
+ * Adds custom task in migration to execute.
26
+ * @param {Object} taskDescription Task title and task function to execute
27
+ * @param {string} taskDescription.title Title for custom task
28
+ * @param {array} taskDescription.task async function to be executed
29
+ * @param {string} taskDescription.failMessage message to be printed when task fails
30
+ * @param {string} taskDescription.successMessage message to be printed when task succeeds
31
+ * @example
32
+ *
33
+ * let first = 'binding glue'
34
+ * let second = 'second glue'
35
+ * let tasks = {
36
+ * title:'My First custom task',
37
+ * successMessage: 'Custom success message',
38
+ * failMessage: 'Custom fail message'
39
+ * task: async (params)=>{
40
+ * const {first, second} = params
41
+ * const a = await stackSDKInstance.fetch();
42
+ * },
43
+ * }
44
+ * migration.addTask(task)
45
+ */
46
+ addTask(taskDescription: any): void;
47
+ run(): Promise<void>;
48
+ getTasks(_requests: any[]): Promise<any[]>;
49
+ }
50
+ export {};
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const utils_1 = require("../utils");
5
+ // @ts-ignore - no types available
6
+ const listr_1 = tslib_1.__importDefault(require("listr"));
7
+ // @ts-ignore - no types available
8
+ const async_1 = require("async");
9
+ const { requests } = utils_1.constants;
10
+ // Properties
11
+ const { getMapInstance, set, get } = utils_1.map;
12
+ const content_types_1 = tslib_1.__importDefault(require("./content-types"));
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(content_types_1.default) {
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 = (0, utils_1.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))
51
+ tasks = [tasks];
52
+ if (task && !Array.isArray(task)) {
53
+ tasks = [task];
54
+ }
55
+ this.contentTypeService.base.dispatch(callsite, null, null, tasks);
56
+ let _requests = get(requests, mapInstance);
57
+ const req = {
58
+ title: title,
59
+ failedTitle: failMessage || `Failed to execute task: ${title}`,
60
+ successTitle: successMessage || `Successfully executed task: ${title}`,
61
+ tasks,
62
+ };
63
+ _requests.push(req);
64
+ set(requests, mapInstance, _requests);
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_1.default(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)
76
+ process.send({ errorOccurred: true });
77
+ });
78
+ }
79
+ async getTasks(_requests) {
80
+ const _tasks = [];
81
+ const results = [];
82
+ const taskFn = (reqObj) => {
83
+ const { failedTitle, successTitle, tasks } = reqObj;
84
+ return async (ctx, _task) => {
85
+ const [err, result] = await (0, utils_1.safePromise)((0, async_1.waterfall)(tasks));
86
+ if (err) {
87
+ ctx.error = true;
88
+ _task.title = failedTitle;
89
+ throw err;
90
+ }
91
+ result && results.push(result);
92
+ _task.title = successTitle;
93
+ return result;
94
+ };
95
+ };
96
+ for (const element of _requests) {
97
+ let reqObj = element;
98
+ const { title } = reqObj;
99
+ const task = {
100
+ title: title,
101
+ task: taskFn(reqObj),
102
+ };
103
+ _tasks.push(task);
104
+ }
105
+ return _tasks;
106
+ }
107
+ }
108
+ exports.default = Migration;
109
+ //# sourceMappingURL=migration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration.js","sourceRoot":"","sources":["../../src/modules/migration.ts"],"names":[],"mappings":";;;AAAA,oCAA4E;AAC5E,kCAAkC;AAClC,0DAA0B;AAC1B,kCAAkC;AAClC,iCAAkC;AAClC,MAAM,EAAE,QAAQ,EAAE,GAAG,iBAAS,CAAC;AAE/B,aAAa;AACb,MAAM,EAAE,cAAc,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,WAAI,CAAC;AAE1C,4EAA0C;AAE1C,qEAAqE;AACrE,MAAM,UAAU,GAAG,CAAC,MAA0B,EAAE,EAAE,CAAC,KAAM,SAAQ,MAAM;CAAG,CAAC;AAE3E;;;GAGG;AACH,MAAqB,SAAU,SAAQ,UAAU,CAAC,uBAAW,CAAC;IAC5D;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,OAAO,CAAC,eAAoB;QAC1B,MAAM,EAAE,KAAK,EAAE,WAAW,EA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,IAAI,CAAC,CAAC;SACnB;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AA1FD,4BA0FC","sourcesContent":["import { map as _map, getCallsite, constants, safePromise } from '../utils';\n// @ts-ignore - no types available\nimport Listr from 'listr';\n// @ts-ignore - no types available\nimport { waterfall } from 'async';\nconst { requests } = constants;\n\n// Properties\nconst { getMapInstance, set, get } = _map;\n\nimport ContentType from './content-types';\n\n// Merge all classes containing migration methods into a single class\nconst _Migration = (_Class: typeof ContentType) => class extends _Class {};\n\n/**\n * Migration class\n * @class Migration\n */\nexport default class Migration extends _Migration(ContentType) {\n /**\n * Adds custom task in migration to execute.\n * @param {Object} taskDescription Task title and task function to execute\n * @param {string} taskDescription.title Title for custom task\n * @param {array} taskDescription.task async function to be executed\n * @param {string} taskDescription.failMessage message to be printed when task fails\n * @param {string} taskDescription.successMessage message to be printed when task succeeds\n * @example\n *\n * let first = 'binding glue'\n * let second = 'second glue'\n * let tasks = {\n * title:'My First custom task',\n * successMessage: 'Custom success message',\n * failMessage: 'Custom fail message'\n * task: async (params)=>{\n * const {first, second} = params\n * const a = await stackSDKInstance.fetch();\n * },\n * }\n * migration.addTask(task)\n */\n addTask(taskDescription: any): void {\n const { title, failMessage, successMessage } = taskDescription;\n let { tasks, task } = taskDescription;\n const callsite = getCallsite();\n const mapInstance = getMapInstance();\n // eslint-disable-next-line no-warning-comments\n // TODO: Make it better to accept only single task\n if (tasks && !Array.isArray(tasks)) tasks = [tasks];\n if (task && !Array.isArray(task)) {\n tasks = [task];\n }\n (this as any).contentTypeService.base.dispatch(callsite, null, null, tasks);\n let _requests = get(requests, mapInstance);\n const req = {\n title: title,\n failedTitle: failMessage || `Failed to execute task: ${title}`,\n successTitle: successMessage || `Successfully executed task: ${title}`,\n tasks,\n };\n _requests.push(req);\n set(requests, mapInstance, _requests);\n }\n\n async run(): Promise<void> {\n const mapInstance = getMapInstance();\n let _requests = get(requests, mapInstance);\n // Make calls from here\n const tasks = await this.getTasks(_requests);\n const listr = new Listr(tasks);\n await listr.run().catch((error: any) => {\n (this as any).handleErrors(error);\n // When the process is child, send error message to parent\n if (process.send) process.send({ errorOccurred: true });\n });\n }\n\n async getTasks(_requests: any[]): Promise<any[]> {\n const _tasks: any[] = [];\n const results: any[] = [];\n const taskFn = (reqObj: any) => {\n const { failedTitle, successTitle, tasks } = reqObj;\n\n return async (ctx: any, _task: any) => {\n const [err, result] = await safePromise(waterfall(tasks));\n if (err) {\n ctx.error = true;\n _task.title = failedTitle;\n throw err;\n }\n result && results.push(result);\n _task.title = successTitle;\n return result;\n };\n };\n\n for (const element of _requests) {\n let reqObj = element;\n const { title } = reqObj;\n const task = {\n title: title,\n task: taskFn(reqObj),\n };\n _tasks.push(task);\n }\n\n return _tasks;\n }\n}\n"]}
@@ -0,0 +1,3 @@
1
+ export default class Parser {
2
+ getMigrationParser(migrationFunc: any): Promise<any>;
3
+ }
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const migration_1 = tslib_1.__importDefault(require("./migration"));
5
+ const validators_1 = require("../validators");
6
+ // eslint-disable-next-line no-warning-comments
7
+ // TODO: Need a better way to combine classes
8
+ const base_1 = tslib_1.__importDefault(require("./base"));
9
+ const actions_1 = require("../actions");
10
+ // Utils
11
+ const utils_1 = require("../utils");
12
+ // map properties
13
+ const { getMapInstance, get } = utils_1.map;
14
+ // Constants
15
+ const { actionMapper, MANAGEMENT_SDK, MANAGEMENT_TOKEN, AUTH_TOKEN, API_KEY, BRANCH, MANAGEMENT_CLIENT, SOURCE_BRANCH, } = utils_1.constants;
16
+ class Parser {
17
+ async getMigrationParser(migrationFunc) {
18
+ const migration = new migration_1.default();
19
+ const mapInstance = getMapInstance();
20
+ const parseResult = {};
21
+ let typeErrors = [];
22
+ // migrations
23
+ try {
24
+ const stackSDKInstance = get(MANAGEMENT_SDK, mapInstance);
25
+ const managementToken = get(MANAGEMENT_TOKEN, mapInstance);
26
+ const authToken = get(AUTH_TOKEN, mapInstance);
27
+ const apiKey = get(API_KEY, mapInstance);
28
+ const branch = get(BRANCH, mapInstance);
29
+ const managementAPIClient = get(MANAGEMENT_CLIENT, mapInstance);
30
+ const externalConfigPath = get('config-path', mapInstance);
31
+ const externalConfig = get('config', mapInstance);
32
+ let externalFileConfig;
33
+ if (typeof externalConfigPath == 'string') {
34
+ externalFileConfig = await utils_1.fsHelper.readJSONFile(externalConfigPath);
35
+ }
36
+ const config = Object.assign({}, externalFileConfig, externalConfig);
37
+ await migrationFunc({
38
+ migration,
39
+ stackSDKInstance,
40
+ managementAPIClient,
41
+ managementToken,
42
+ authToken,
43
+ apiKey,
44
+ branch,
45
+ config,
46
+ });
47
+ }
48
+ catch (error) {
49
+ if (error instanceof TypeError) {
50
+ if (error.message.includes('is not a function')) {
51
+ const base = new base_1.default();
52
+ // eslint-disable-next-line
53
+ const [, filename, line] = error.stack.match(/\/([\/\w-_\.]+\.js):(\d*):(\d*)/);
54
+ const callsite = {
55
+ getFileName: () => `/${filename}`,
56
+ getLineNumber: () => line,
57
+ };
58
+ const errMsgString = error.message.split(' ');
59
+ const typeErrorFirstStr = errMsgString[0].split('.');
60
+ const typeErrorFunction = typeErrorFirstStr[typeErrorFirstStr.length - 1];
61
+ typeErrors.push(typeErrorFunction);
62
+ base.dispatch(callsite, null, { typeErrors }, 'typeError');
63
+ }
64
+ }
65
+ else {
66
+ console.log('Error', error);
67
+ // eslint-disable-next-line
68
+ const [, filename, line] = error.stack.match(/\/([\/\w-_\.]+\.js):(\d*):(\d*)/);
69
+ const callsite = {
70
+ getFileName: () => `/${filename}`,
71
+ getLineNumber: () => line,
72
+ };
73
+ const base = new base_1.default();
74
+ typeErrors = [error];
75
+ base.dispatch(callsite, null, { typeErrors }, 'typeError');
76
+ }
77
+ }
78
+ const actions = get(actionMapper, mapInstance);
79
+ const actionList = new actions_1.ActionList(actions);
80
+ actionList.addValidators(new validators_1.CreateContentTypeValidator());
81
+ actionList.addValidators(new validators_1.FieldValidator());
82
+ actionList.addValidators(new validators_1._TypeError());
83
+ actionList.addValidators(new validators_1.EditContentTypeValidator());
84
+ const hasErrors = actionList.validate();
85
+ if (hasErrors.length > 0) {
86
+ parseResult.hasErrors = hasErrors;
87
+ return parseResult;
88
+ }
89
+ return parseResult;
90
+ }
91
+ }
92
+ exports.default = Parser;
93
+ //# sourceMappingURL=parser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/modules/parser.ts"],"names":[],"mappings":";;;AAAA,oEAAoC;AAEpC,8CAAiH;AACjH,+CAA+C;AAC/C,6CAA6C;AAC7C,0DAA0B;AAE1B,wCAAwC;AACxC,QAAQ;AACR,oCAA4D;AAC5D,iBAAiB;AACjB,MAAM,EAAE,cAAc,EAAE,GAAG,EAAE,GAAG,WAAI,CAAC;AACrC,YAAY;AACZ,MAAM,EACJ,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,UAAU,EACV,OAAO,EACP,MAAM,EACN,iBAAiB,EACjB,aAAa,GACd,GAAG,iBAAS,CAAC;AAEd,MAAqB,MAAM;IACzB,KAAK,CAAC,kBAAkB,CAAC,aAAkB;QACzC,MAAM,SAAS,GAAG,IAAI,mBAAS,EAAE,CAAC;QAClC,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;QACrC,MAAM,WAAW,GAAQ,EAAE,CAAC;QAC5B,IAAI,UAAU,GAAU,EAAE,CAAC;QAC3B,aAAa;QACb,IAAI;YACF,MAAM,gBAAgB,GAAG,GAAG,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC;YAC1D,MAAM,eAAe,GAAG,GAAG,CAAC,gBAAgB,EAAE,WAAW,CAAC,CAAC;YAC3D,MAAM,SAAS,GAAG,GAAG,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;YAC/C,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;YACzC,MAAM,MAAM,GAAG,GAAG,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U,CAAC,QAAQ,EAAE,CAAC;QAExC,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE;YACxB,WAAW,CAAC,SAAS,GAAG,SAAS,CAAC;YAClC,OAAO,WAAW,CAAC;SACpB;QACD,OAAO,WAAW,CAAC;IACrB,CAAC;CACF;AA5ED,yBA4EC","sourcesContent":["import Migration from './migration';\n\nimport { CreateContentTypeValidator, EditContentTypeValidator, _TypeError, FieldValidator } from '../validators';\n// eslint-disable-next-line no-warning-comments\n// TODO: Need a better way to combine classes\nimport Base from './base';\n\nimport { ActionList } from '../actions';\n// Utils\nimport { map as _map, constants, fsHelper } from '../utils';\n// map properties\nconst { getMapInstance, get } = _map;\n// Constants\nconst {\n actionMapper,\n MANAGEMENT_SDK,\n MANAGEMENT_TOKEN,\n AUTH_TOKEN,\n API_KEY,\n BRANCH,\n MANAGEMENT_CLIENT,\n SOURCE_BRANCH,\n} = constants;\n\nexport default class Parser {\n async getMigrationParser(migrationFunc: any): Promise<any> {\n const migration = new Migration();\n const mapInstance = getMapInstance();\n const parseResult: any = {};\n let typeErrors: any[] = [];\n // migrations\n try {\n const stackSDKInstance = get(MANAGEMENT_SDK, mapInstance);\n const managementToken = get(MANAGEMENT_TOKEN, mapInstance);\n const authToken = get(AUTH_TOKEN, mapInstance);\n const apiKey = get(API_KEY, mapInstance);\n const branch = get(BRANCH, mapInstance);\n const managementAPIClient = get(MANAGEMENT_CLIENT, mapInstance);\n const externalConfigPath = get('config-path', mapInstance);\n const externalConfig = get('config', mapInstance);\n let externalFileConfig: any;\n if (typeof externalConfigPath == 'string') {\n externalFileConfig = await fsHelper.readJSONFile(externalConfigPath);\n }\n const config = Object.assign({}, externalFileConfig, externalConfig);\n await migrationFunc({\n migration,\n stackSDKInstance,\n managementAPIClient,\n managementToken,\n authToken,\n apiKey,\n branch,\n config,\n });\n } catch (error: any) {\n if (error instanceof TypeError) {\n if (error.message.includes('is not a function')) {\n const base = new Base();\n // eslint-disable-next-line\n const [, filename, line] = error.stack.match(/\\/([\\/\\w-_\\.]+\\.js):(\\d*):(\\d*)/);\n const callsite = {\n getFileName: () => `/${filename}`,\n getLineNumber: () => line,\n };\n const errMsgString = error.message.split(' ');\n const typeErrorFirstStr = errMsgString[0].split('.');\n const typeErrorFunction = typeErrorFirstStr[typeErrorFirstStr.length - 1];\n typeErrors.push(typeErrorFunction);\n base.dispatch(callsite, null, { typeErrors }, 'typeError');\n }\n } else {\n console.log('Error', error);\n // eslint-disable-next-line\n const [, filename, line] = error.stack.match(/\\/([\\/\\w-_\\.]+\\.js):(\\d*):(\\d*)/);\n const callsite = {\n getFileName: () => `/${filename}`,\n getLineNumber: () => line,\n };\n const base = new Base();\n typeErrors = [error];\n base.dispatch(callsite, null, { typeErrors }, 'typeError');\n }\n }\n const actions = get(actionMapper, mapInstance);\n const actionList = new ActionList(actions);\n\n actionList.addValidators(new CreateContentTypeValidator());\n actionList.addValidators(new FieldValidator());\n actionList.addValidators(new _TypeError());\n actionList.addValidators(new EditContentTypeValidator());\n\n const hasErrors = actionList.validate();\n\n if (hasErrors.length > 0) {\n parseResult.hasErrors = hasErrors;\n return parseResult;\n }\n return parseResult;\n }\n}\n"]}
@@ -0,0 +1,25 @@
1
+ import Base from '../modules/base';
2
+ export default class ContentTypeService {
3
+ moveFieldActions: any[];
4
+ base: Base;
5
+ stackSDKInstance: any;
6
+ id: string | undefined;
7
+ action: string | undefined;
8
+ constructor();
9
+ fetchContentType(callsite: any, id: string): Promise<any>;
10
+ postContentTypes(callsite: any, id: string, action: string): Promise<any>;
11
+ editContentType(callsite: any, data: any): Promise<any>;
12
+ deleteContentType(callsite: any): Promise<any>;
13
+ applyActionsOnFields(callsite: any, data: any, cb?: (err: any, data?: any) => void): any;
14
+ getActions(action: any): void;
15
+ setIdAndAction(id: string, action: string): void;
16
+ mergeEditSchema(schema?: any[]): any[];
17
+ toTheTop(schema: any[], actionObj: any): any[];
18
+ toTheBottom(schema: any[], actionObj: any): any[];
19
+ afterField(schema: any[], actionObj: any): any[];
20
+ beforeField(schema: any[], actionObj: any): any[];
21
+ getValidated(schema: any[], actionObj: any): {
22
+ isValid: boolean;
23
+ missingField: string | null;
24
+ };
25
+ }