@contentstack/cli-migration 0.1.1-beta.3 → 1.0.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.
- package/LICENSE +21 -0
- package/README.md +22 -27
- package/oclif.manifest.json +1 -1
- package/package.json +16 -11
- package/src/actions/action-list.js +11 -11
- package/src/actions/index.js +33 -34
- package/src/commands/cm/{migration.js → stacks/migration.js} +102 -74
- package/src/config/api-config.js +8 -9
- package/src/config/default-options.js +2 -2
- package/src/config/index.js +2 -2
- package/src/config/master-locale.js +2 -2
- package/src/modules/base.js +33 -33
- package/src/modules/content-types.js +76 -76
- package/src/modules/fields.js +73 -73
- package/src/modules/index.js +2 -2
- package/src/modules/locale.js +13 -13
- package/src/modules/migration.js +45 -46
- package/src/modules/parser.js +65 -52
- package/src/services/content-types.js +160 -163
- package/src/services/index.js +2 -2
- package/src/services/locales.js +33 -35
- package/src/utils/auto-retry.js +14 -12
- package/src/utils/callsite.js +14 -14
- package/src/utils/constants.js +108 -115
- package/src/utils/contentstack-sdk.js +42 -43
- package/src/utils/error-handler.js +8 -8
- package/src/utils/error-helper.js +41 -40
- package/src/utils/fs-helper.js +12 -12
- package/src/utils/get-batches.js +4 -4
- package/src/utils/get-config.js +6 -6
- package/src/utils/group-by.js +17 -17
- package/src/utils/index.js +2 -2
- package/src/utils/logger.js +42 -52
- package/src/utils/object-helper.js +7 -7
- package/src/utils/safe-promise.js +2 -2
- package/src/utils/schema-helper.js +12 -12
- package/src/utils/success-handler.js +5 -5
- package/src/validators/api-error.js +10 -8
- package/src/validators/base-validator.js +14 -14
- package/src/validators/create-content-type-validator.js +21 -25
- package/src/validators/edit-content-type-validator.js +21 -24
- package/src/validators/field-validator.js +10 -8
- package/src/validators/index.js +2 -2
- package/src/validators/migration-error.js +9 -7
- package/src/validators/schema-validator.js +11 -9
- package/src/validators/type-error.js +11 -10
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
/* eslint-disable camelcase */
|
|
2
|
-
'use strict'
|
|
2
|
+
'use strict';
|
|
3
3
|
|
|
4
|
-
const Field = require('./fields')
|
|
4
|
+
const Field = require('./fields');
|
|
5
5
|
|
|
6
6
|
// Services
|
|
7
|
-
const {ContentTypeService} = require('../services')
|
|
7
|
+
const { ContentTypeService } = require('../services');
|
|
8
8
|
|
|
9
9
|
// Config
|
|
10
|
-
const {defaultOptions} = require('../config')
|
|
10
|
+
const { defaultOptions } = require('../config');
|
|
11
11
|
|
|
12
12
|
// Utils
|
|
13
|
-
const {map: _map, schemaHelper, constants, getCallsite} = require('../utils')
|
|
13
|
+
const { map: _map, schemaHelper, constants, getCallsite } = require('../utils');
|
|
14
14
|
|
|
15
15
|
// Base class
|
|
16
|
-
const Base = require('./base')
|
|
16
|
+
const Base = require('./base');
|
|
17
17
|
|
|
18
18
|
// Properties
|
|
19
|
-
const {getMapInstance, set, get} = _map
|
|
20
|
-
const {actions, validationAction} = constants
|
|
21
|
-
const {getUid} = schemaHelper
|
|
22
|
-
const {create, edit} = validationAction
|
|
19
|
+
const { getMapInstance, set, get } = _map;
|
|
20
|
+
const { actions, validationAction } = constants;
|
|
21
|
+
const { getUid } = schemaHelper;
|
|
22
|
+
const { create, edit } = validationAction;
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* ContentType class
|
|
@@ -28,8 +28,8 @@ const {create, edit} = validationAction
|
|
|
28
28
|
*/
|
|
29
29
|
class ContentType extends Base {
|
|
30
30
|
constructor() {
|
|
31
|
-
super()
|
|
32
|
-
this.contentTypeService = new ContentTypeService()
|
|
31
|
+
super();
|
|
32
|
+
this.contentTypeService = new ContentTypeService();
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
/**
|
|
@@ -45,39 +45,39 @@ class ContentType extends Base {
|
|
|
45
45
|
* }
|
|
46
46
|
*/
|
|
47
47
|
createContentType(id, opts = {}) {
|
|
48
|
-
const callsite = getCallsite()
|
|
48
|
+
const callsite = getCallsite();
|
|
49
49
|
// base class method
|
|
50
|
-
let options = {...defaultOptions, ...opts}
|
|
51
|
-
delete options.title
|
|
52
|
-
delete options.description
|
|
53
|
-
this.dispatch(callsite, id, opts, create)
|
|
54
|
-
const {title, description} = opts
|
|
55
|
-
const mapInstance = getMapInstance()
|
|
50
|
+
let options = { ...defaultOptions, ...opts };
|
|
51
|
+
delete options.title;
|
|
52
|
+
delete options.description;
|
|
53
|
+
this.dispatch(callsite, id, opts, create);
|
|
54
|
+
const { title, description } = opts;
|
|
55
|
+
const mapInstance = getMapInstance();
|
|
56
56
|
|
|
57
|
-
const {CREATE_CT} = actions
|
|
58
|
-
const uid = getUid(id)
|
|
57
|
+
const { CREATE_CT } = actions;
|
|
58
|
+
const uid = getUid(id);
|
|
59
59
|
|
|
60
|
-
const ctObj = {content_type: {title, uid, description, options}}
|
|
60
|
+
const ctObj = { content_type: { title, uid, description, options } };
|
|
61
61
|
|
|
62
|
-
const ctActionObj = {[CREATE_CT]: ctObj}
|
|
62
|
+
const ctActionObj = { [CREATE_CT]: ctObj };
|
|
63
63
|
|
|
64
|
-
const {contentTypeService} = this
|
|
64
|
+
const { contentTypeService } = this;
|
|
65
65
|
// Sets data to post in map object
|
|
66
|
-
set(id, mapInstance, ctActionObj)
|
|
66
|
+
set(id, mapInstance, ctActionObj);
|
|
67
67
|
// Sets action and id in content type service
|
|
68
|
-
contentTypeService.setIdAndAction(id, CREATE_CT)
|
|
69
|
-
const tasks = [contentTypeService.postContentTypes.bind(contentTypeService, callsite, id, CREATE_CT)]
|
|
68
|
+
contentTypeService.setIdAndAction(id, CREATE_CT);
|
|
69
|
+
const tasks = [contentTypeService.postContentTypes.bind(contentTypeService, callsite, id, CREATE_CT)];
|
|
70
70
|
const req = {
|
|
71
71
|
title: `Adding content type: ${id}`,
|
|
72
72
|
failMessage: `Failed to create content type: ${id}`,
|
|
73
73
|
successMessage: `Successfully added content type: ${id}`,
|
|
74
74
|
tasks,
|
|
75
|
-
}
|
|
76
|
-
let field = new Field(id, CREATE_CT, contentTypeService, req)
|
|
75
|
+
};
|
|
76
|
+
let field = new Field(id, CREATE_CT, contentTypeService, req);
|
|
77
77
|
// TODO: should find better way to attach content type level methods
|
|
78
|
-
field.singleton = this.singleton
|
|
79
|
-
field.isPage = this.isPage
|
|
80
|
-
return field
|
|
78
|
+
field.singleton = this.singleton;
|
|
79
|
+
field.isPage = this.isPage;
|
|
80
|
+
return field;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
/**
|
|
@@ -86,12 +86,12 @@ class ContentType extends Base {
|
|
|
86
86
|
* @returns {ContentType} instance of ContentType for chaining
|
|
87
87
|
*/
|
|
88
88
|
singleton(value) {
|
|
89
|
-
const mapInstance = getMapInstance()
|
|
90
|
-
const {id, action} = this
|
|
91
|
-
const contentType = get(id, mapInstance)
|
|
89
|
+
const mapInstance = getMapInstance();
|
|
90
|
+
const { id, action } = this;
|
|
91
|
+
const contentType = get(id, mapInstance);
|
|
92
92
|
|
|
93
|
-
contentType[action].content_type.options.singleton = value
|
|
94
|
-
return this
|
|
93
|
+
contentType[action].content_type.options.singleton = value;
|
|
94
|
+
return this;
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
/**
|
|
@@ -100,12 +100,12 @@ class ContentType extends Base {
|
|
|
100
100
|
* @returns {ContentType} instance of ContentType for chaining
|
|
101
101
|
*/
|
|
102
102
|
isPage(value) {
|
|
103
|
-
const mapInstance = getMapInstance()
|
|
104
|
-
const {id, action} = this
|
|
105
|
-
const contentType = get(id, mapInstance)
|
|
103
|
+
const mapInstance = getMapInstance();
|
|
104
|
+
const { id, action } = this;
|
|
105
|
+
const contentType = get(id, mapInstance);
|
|
106
106
|
|
|
107
|
-
contentType[action].content_type.options.is_page = value
|
|
108
|
-
return this
|
|
107
|
+
contentType[action].content_type.options.is_page = value;
|
|
108
|
+
return this;
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
/**
|
|
@@ -122,50 +122,50 @@ class ContentType extends Base {
|
|
|
122
122
|
* }
|
|
123
123
|
*/
|
|
124
124
|
editContentType(id, opts = {}) {
|
|
125
|
-
let options = {...defaultOptions, ...opts}
|
|
126
|
-
delete options.title
|
|
127
|
-
delete options.description
|
|
125
|
+
let options = { ...defaultOptions, ...opts };
|
|
126
|
+
delete options.title;
|
|
127
|
+
delete options.description;
|
|
128
128
|
|
|
129
|
-
const callsite = getCallsite()
|
|
129
|
+
const callsite = getCallsite();
|
|
130
130
|
// base class method
|
|
131
|
-
this.dispatch(callsite, id, {}, edit)
|
|
132
|
-
const {title, description} = opts
|
|
133
|
-
const mapInstance = getMapInstance()
|
|
131
|
+
this.dispatch(callsite, id, {}, edit);
|
|
132
|
+
const { title, description } = opts;
|
|
133
|
+
const mapInstance = getMapInstance();
|
|
134
134
|
|
|
135
|
-
const {EDIT_CT} = actions
|
|
135
|
+
const { EDIT_CT } = actions;
|
|
136
136
|
|
|
137
|
-
const uid = id
|
|
137
|
+
const uid = id;
|
|
138
138
|
|
|
139
|
-
const ctObj = {content_type: {title, uid, description, options}}
|
|
140
|
-
const ctActionObj = {[EDIT_CT]: ctObj}
|
|
139
|
+
const ctObj = { content_type: { title, uid, description, options } };
|
|
140
|
+
const ctActionObj = { [EDIT_CT]: ctObj };
|
|
141
141
|
|
|
142
|
-
const {contentTypeService} = this
|
|
142
|
+
const { contentTypeService } = this;
|
|
143
143
|
|
|
144
144
|
// Sets data to update in map object
|
|
145
|
-
let ctAction = get(id, mapInstance)
|
|
145
|
+
let ctAction = get(id, mapInstance);
|
|
146
146
|
|
|
147
|
-
set(id, mapInstance, {...ctActionObj, ...ctAction})
|
|
147
|
+
set(id, mapInstance, { ...ctActionObj, ...ctAction });
|
|
148
148
|
// Sets action and id in content type service
|
|
149
|
-
contentTypeService.setIdAndAction(id, EDIT_CT)
|
|
149
|
+
contentTypeService.setIdAndAction(id, EDIT_CT);
|
|
150
150
|
const tasks = [
|
|
151
151
|
contentTypeService.fetchContentType.bind(contentTypeService, callsite, id),
|
|
152
152
|
contentTypeService.applyActionsOnFields.bind(contentTypeService, callsite),
|
|
153
153
|
contentTypeService.editContentType.bind(contentTypeService, callsite),
|
|
154
|
-
]
|
|
154
|
+
];
|
|
155
155
|
|
|
156
156
|
const req = {
|
|
157
157
|
title: `Editing content type: ${id}`,
|
|
158
158
|
failMessage: `Failed to edit content type: ${id}`,
|
|
159
159
|
successMessage: `Successfully updated content type: ${id}`,
|
|
160
160
|
tasks,
|
|
161
|
-
}
|
|
161
|
+
};
|
|
162
162
|
|
|
163
163
|
// Keeping the same instance of contentTypeService in Field class
|
|
164
|
-
let fieldI = new Field(id, EDIT_CT, contentTypeService, req)
|
|
164
|
+
let fieldI = new Field(id, EDIT_CT, contentTypeService, req);
|
|
165
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
|
|
166
|
+
fieldI.singleton = this.singleton;
|
|
167
|
+
fieldI.isPage = this.isPage;
|
|
168
|
+
return fieldI;
|
|
169
169
|
}
|
|
170
170
|
|
|
171
171
|
/**
|
|
@@ -178,31 +178,31 @@ class ContentType extends Base {
|
|
|
178
178
|
* }
|
|
179
179
|
*/
|
|
180
180
|
deleteContentType(id) {
|
|
181
|
-
const callsite = getCallsite()
|
|
181
|
+
const callsite = getCallsite();
|
|
182
182
|
|
|
183
|
-
const mapInstance = getMapInstance()
|
|
183
|
+
const mapInstance = getMapInstance();
|
|
184
184
|
|
|
185
|
-
const {DELETE_CT} = actions
|
|
185
|
+
const { DELETE_CT } = actions;
|
|
186
186
|
|
|
187
|
-
const uid = getUid(id)
|
|
187
|
+
const uid = getUid(id);
|
|
188
188
|
|
|
189
|
-
const ctObj = {content_type: {uid, force: false}} // keep by default false
|
|
189
|
+
const ctObj = { content_type: { uid, force: false } }; // keep by default false
|
|
190
190
|
|
|
191
|
-
const ctActionObj = {[DELETE_CT]: ctObj}
|
|
191
|
+
const ctActionObj = { [DELETE_CT]: ctObj };
|
|
192
192
|
|
|
193
|
-
const {contentTypeService} = this
|
|
193
|
+
const { contentTypeService } = this;
|
|
194
194
|
|
|
195
195
|
// Sets data to delete in map object
|
|
196
|
-
set(id, mapInstance, ctActionObj)
|
|
196
|
+
set(id, mapInstance, ctActionObj);
|
|
197
197
|
// Sets action and id in content type service
|
|
198
|
-
contentTypeService.setIdAndAction(id, DELETE_CT)
|
|
198
|
+
contentTypeService.setIdAndAction(id, DELETE_CT);
|
|
199
199
|
|
|
200
|
-
const tasks = [contentTypeService.deleteContentType.bind(contentTypeService, callsite)]
|
|
200
|
+
const tasks = [contentTypeService.deleteContentType.bind(contentTypeService, callsite)];
|
|
201
201
|
|
|
202
|
-
const req = {title: 'Deleting content type', tasks}
|
|
202
|
+
const req = { title: 'Deleting content type', tasks };
|
|
203
203
|
|
|
204
|
-
return new Field(id, DELETE_CT, contentTypeService, req)
|
|
204
|
+
return new Field(id, DELETE_CT, contentTypeService, req);
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
207
|
|
|
208
|
-
module.exports = ContentType
|
|
208
|
+
module.exports = ContentType;
|
package/src/modules/fields.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
'use strict'
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
const {keys} = Object
|
|
3
|
+
const { keys } = Object;
|
|
4
4
|
// Utils
|
|
5
|
-
const {map: _map, schemaHelper, constants} = require('../utils')
|
|
5
|
+
const { map: _map, schemaHelper, constants } = require('../utils');
|
|
6
6
|
|
|
7
7
|
// Utils Properties
|
|
8
|
-
const {getMapInstance, get} = _map
|
|
9
|
-
const {getSchema} = schemaHelper
|
|
8
|
+
const { getMapInstance, get } = _map;
|
|
9
|
+
const { getSchema } = schemaHelper;
|
|
10
10
|
const {
|
|
11
11
|
data_type,
|
|
12
12
|
mandatory,
|
|
@@ -16,10 +16,10 @@ const {
|
|
|
16
16
|
field_metadata,
|
|
17
17
|
reference_to,
|
|
18
18
|
actions: _actions,
|
|
19
|
-
} = constants
|
|
19
|
+
} = constants;
|
|
20
20
|
|
|
21
21
|
// Base class
|
|
22
|
-
const Base = require('./base')
|
|
22
|
+
const Base = require('./base');
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* Field class
|
|
@@ -28,11 +28,11 @@ const Base = require('./base')
|
|
|
28
28
|
class Field extends Base {
|
|
29
29
|
// prop, value
|
|
30
30
|
constructor(uid, action, contentTypeService, request) {
|
|
31
|
-
super(uid)
|
|
32
|
-
this.uid = uid
|
|
33
|
-
this.action = action
|
|
34
|
-
this.contentTypeService = contentTypeService
|
|
35
|
-
this.request = request
|
|
31
|
+
super(uid);
|
|
32
|
+
this.uid = uid;
|
|
33
|
+
this.action = action;
|
|
34
|
+
this.contentTypeService = contentTypeService;
|
|
35
|
+
this.request = request;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
/**
|
|
@@ -41,7 +41,7 @@ class Field extends Base {
|
|
|
41
41
|
* @param {function[]} task - array of async function to be executed
|
|
42
42
|
* @param {string} failMessage message to be printed when task fails
|
|
43
43
|
* @param {string} successMessage - message to be printed when task succeeds
|
|
44
|
-
|
|
44
|
+
*/
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
47
|
* Creates a field with provided uid.
|
|
@@ -59,11 +59,11 @@ class Field extends Base {
|
|
|
59
59
|
* };
|
|
60
60
|
*/
|
|
61
61
|
createField(field, opts) {
|
|
62
|
-
this.updateContentTypeSchema(field)
|
|
62
|
+
this.updateContentTypeSchema(field);
|
|
63
63
|
|
|
64
64
|
// Build schema from options provided
|
|
65
|
-
if (opts && keys(opts).length) return this.getSchemaFromOptions(opts, field)
|
|
66
|
-
return this
|
|
65
|
+
if (opts && keys(opts).length) return this.getSchemaFromOptions(opts, field);
|
|
66
|
+
return this;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
/**
|
|
@@ -81,12 +81,12 @@ class Field extends Base {
|
|
|
81
81
|
* };
|
|
82
82
|
*/
|
|
83
83
|
editField(field, opts) {
|
|
84
|
-
const {EDIT_FIELD} = _actions
|
|
85
|
-
this.updateContentTypeSchema(field, EDIT_FIELD)
|
|
84
|
+
const { EDIT_FIELD } = _actions;
|
|
85
|
+
this.updateContentTypeSchema(field, EDIT_FIELD);
|
|
86
86
|
|
|
87
87
|
// Build schema from options provided
|
|
88
|
-
if (opts && keys(opts).length) return this.getSchemaFromOptions(opts, field)
|
|
89
|
-
return this
|
|
88
|
+
if (opts && keys(opts).length) return this.getSchemaFromOptions(opts, field);
|
|
89
|
+
return this;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
/**
|
|
@@ -101,10 +101,10 @@ class Field extends Base {
|
|
|
101
101
|
* };
|
|
102
102
|
*/
|
|
103
103
|
deleteField(field) {
|
|
104
|
-
const {DELETE_FIELD} = _actions
|
|
105
|
-
this.updateContentTypeSchema(field, DELETE_FIELD)
|
|
104
|
+
const { DELETE_FIELD } = _actions;
|
|
105
|
+
this.updateContentTypeSchema(field, DELETE_FIELD);
|
|
106
106
|
|
|
107
|
-
return this
|
|
107
|
+
return this;
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
/**
|
|
@@ -132,26 +132,26 @@ class Field extends Base {
|
|
|
132
132
|
* };
|
|
133
133
|
*/
|
|
134
134
|
moveField(field) {
|
|
135
|
-
this.fieldToMove = field
|
|
136
|
-
return this
|
|
135
|
+
this.fieldToMove = field;
|
|
136
|
+
return this;
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
updateContentTypeSchema(field, subAction) {
|
|
140
|
-
const mapInstance = getMapInstance()
|
|
140
|
+
const mapInstance = getMapInstance();
|
|
141
141
|
|
|
142
|
-
const {uid, action} = this
|
|
142
|
+
const { uid, action } = this;
|
|
143
143
|
|
|
144
|
-
const contentType = get(uid, mapInstance)
|
|
144
|
+
const contentType = get(uid, mapInstance);
|
|
145
145
|
|
|
146
|
-
let contentTypeSchema = contentType[action].content_type.schema
|
|
147
|
-
contentTypeSchema = contentTypeSchema || []
|
|
146
|
+
let contentTypeSchema = contentType[action].content_type.schema;
|
|
147
|
+
contentTypeSchema = contentTypeSchema || [];
|
|
148
148
|
|
|
149
|
-
const schemaObj = getSchema(field, subAction)
|
|
150
|
-
contentTypeSchema.push(schemaObj)
|
|
149
|
+
const schemaObj = getSchema(field, subAction);
|
|
150
|
+
contentTypeSchema.push(schemaObj);
|
|
151
151
|
|
|
152
|
-
contentType[action].content_type.schema = contentTypeSchema
|
|
152
|
+
contentType[action].content_type.schema = contentTypeSchema;
|
|
153
153
|
|
|
154
|
-
this.field = schemaObj.uid
|
|
154
|
+
this.field = schemaObj.uid;
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
// changeFieldId(currentId, newId) { }
|
|
@@ -162,8 +162,8 @@ class Field extends Base {
|
|
|
162
162
|
* @returns {Field} current instance of field object to chain further methods.
|
|
163
163
|
*/
|
|
164
164
|
display_name(value) {
|
|
165
|
-
this.buildSchema(display_name, this.field, value)
|
|
166
|
-
return this
|
|
165
|
+
this.buildSchema(display_name, this.field, value);
|
|
166
|
+
return this;
|
|
167
167
|
}
|
|
168
168
|
|
|
169
169
|
/**
|
|
@@ -172,8 +172,8 @@ class Field extends Base {
|
|
|
172
172
|
* @returns {Field} current instance of field object to chain further methods.
|
|
173
173
|
*/
|
|
174
174
|
data_type(value) {
|
|
175
|
-
this.buildSchema(data_type, this.field, value)
|
|
176
|
-
return this
|
|
175
|
+
this.buildSchema(data_type, this.field, value);
|
|
176
|
+
return this;
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
/**
|
|
@@ -182,8 +182,8 @@ class Field extends Base {
|
|
|
182
182
|
* @returns {Field} current instance of field object to chain further methods.
|
|
183
183
|
*/
|
|
184
184
|
mandatory(value) {
|
|
185
|
-
this.buildSchema(mandatory, this.field, value)
|
|
186
|
-
return this
|
|
185
|
+
this.buildSchema(mandatory, this.field, value);
|
|
186
|
+
return this;
|
|
187
187
|
}
|
|
188
188
|
|
|
189
189
|
/**
|
|
@@ -192,8 +192,8 @@ class Field extends Base {
|
|
|
192
192
|
* @returns {Field} current instance of field object to chain further methods.
|
|
193
193
|
*/
|
|
194
194
|
default(value) {
|
|
195
|
-
this.buildSchema(_default, this.field, value)
|
|
196
|
-
return this
|
|
195
|
+
this.buildSchema(_default, this.field, value);
|
|
196
|
+
return this;
|
|
197
197
|
}
|
|
198
198
|
|
|
199
199
|
/**
|
|
@@ -202,8 +202,8 @@ class Field extends Base {
|
|
|
202
202
|
* @returns {Field} current instance of field object to chain further methods.
|
|
203
203
|
*/
|
|
204
204
|
unique(value) {
|
|
205
|
-
this.buildSchema(unique, this.field, value)
|
|
206
|
-
return this
|
|
205
|
+
this.buildSchema(unique, this.field, value);
|
|
206
|
+
return this;
|
|
207
207
|
}
|
|
208
208
|
|
|
209
209
|
/**
|
|
@@ -213,8 +213,8 @@ class Field extends Base {
|
|
|
213
213
|
* @returns {Field} current instance of field object to chain further methods.
|
|
214
214
|
*/
|
|
215
215
|
reference_to(value) {
|
|
216
|
-
this.buildSchema(reference_to, this.field, value)
|
|
217
|
-
return this
|
|
216
|
+
this.buildSchema(reference_to, this.field, value);
|
|
217
|
+
return this;
|
|
218
218
|
}
|
|
219
219
|
|
|
220
220
|
/**
|
|
@@ -223,8 +223,8 @@ class Field extends Base {
|
|
|
223
223
|
* @returns {Field} current instance of field object to chain further methods.
|
|
224
224
|
*/
|
|
225
225
|
ref_multiple(value) {
|
|
226
|
-
this.buildSchema(field_metadata, this.field, {ref_multiple: value, ref_multiple_content_types: true})
|
|
227
|
-
return this
|
|
226
|
+
this.buildSchema(field_metadata, this.field, { ref_multiple: value, ref_multiple_content_types: true });
|
|
227
|
+
return this;
|
|
228
228
|
}
|
|
229
229
|
|
|
230
230
|
/**
|
|
@@ -233,52 +233,52 @@ class Field extends Base {
|
|
|
233
233
|
* @returns {Field} current instance of field object to chain further methods.
|
|
234
234
|
*/
|
|
235
235
|
ref_multipleContentType(value) {
|
|
236
|
-
this.buildSchema(field_metadata, this.field, {ref_multiple_content_types: value})
|
|
237
|
-
return this
|
|
236
|
+
this.buildSchema(field_metadata, this.field, { ref_multiple_content_types: value });
|
|
237
|
+
return this;
|
|
238
238
|
}
|
|
239
239
|
|
|
240
240
|
toTheBottom() {
|
|
241
|
-
const {fieldToMove, contentTypeService} = this
|
|
241
|
+
const { fieldToMove, contentTypeService } = this;
|
|
242
242
|
|
|
243
|
-
if (!fieldToMove) throw new Error('Cannot access this method directly.')
|
|
243
|
+
if (!fieldToMove) throw new Error('Cannot access this method directly.');
|
|
244
244
|
|
|
245
|
-
contentTypeService.getActions({action: 'toTheBottom', fieldToMove})
|
|
245
|
+
contentTypeService.getActions({ action: 'toTheBottom', fieldToMove });
|
|
246
246
|
}
|
|
247
247
|
|
|
248
248
|
toTheTop() {
|
|
249
|
-
const {fieldToMove, contentTypeService} = this
|
|
250
|
-
if (!fieldToMove) throw new Error('Cannot access this method directly.')
|
|
249
|
+
const { fieldToMove, contentTypeService } = this;
|
|
250
|
+
if (!fieldToMove) throw new Error('Cannot access this method directly.');
|
|
251
251
|
|
|
252
|
-
contentTypeService.getActions({action: 'toTheTop', fieldToMove})
|
|
252
|
+
contentTypeService.getActions({ action: 'toTheTop', fieldToMove });
|
|
253
253
|
}
|
|
254
254
|
|
|
255
255
|
afterField(field) {
|
|
256
|
-
const {fieldToMove, contentTypeService} = this
|
|
256
|
+
const { fieldToMove, contentTypeService } = this;
|
|
257
257
|
|
|
258
|
-
if (!fieldToMove) throw new Error('Cannot access this method directly.')
|
|
258
|
+
if (!fieldToMove) throw new Error('Cannot access this method directly.');
|
|
259
259
|
|
|
260
|
-
contentTypeService.getActions({action: 'afterField', fieldToMove, against: field})
|
|
260
|
+
contentTypeService.getActions({ action: 'afterField', fieldToMove, against: field });
|
|
261
261
|
}
|
|
262
262
|
|
|
263
263
|
beforeField(field) {
|
|
264
|
-
const {fieldToMove, contentTypeService} = this
|
|
264
|
+
const { fieldToMove, contentTypeService } = this;
|
|
265
265
|
|
|
266
|
-
if (!fieldToMove) throw new Error('Cannot access this method directly.')
|
|
266
|
+
if (!fieldToMove) throw new Error('Cannot access this method directly.');
|
|
267
267
|
|
|
268
|
-
contentTypeService.getActions({action: 'beforeField', fieldToMove, against: field})
|
|
268
|
+
contentTypeService.getActions({ action: 'beforeField', fieldToMove, against: field });
|
|
269
269
|
}
|
|
270
270
|
|
|
271
271
|
buildSchema(prop, field, value) {
|
|
272
|
-
const mapInstance = getMapInstance()
|
|
272
|
+
const mapInstance = getMapInstance();
|
|
273
273
|
|
|
274
|
-
const {uid, action} = this
|
|
274
|
+
const { uid, action } = this;
|
|
275
275
|
|
|
276
|
-
const contentType = get(uid, mapInstance)
|
|
276
|
+
const contentType = get(uid, mapInstance);
|
|
277
277
|
|
|
278
278
|
for (const _schema of contentType[action].content_type.schema) {
|
|
279
279
|
if (_schema.uid === field) {
|
|
280
|
-
_schema[prop] = value
|
|
281
|
-
break
|
|
280
|
+
_schema[prop] = value;
|
|
281
|
+
break;
|
|
282
282
|
}
|
|
283
283
|
}
|
|
284
284
|
}
|
|
@@ -290,15 +290,15 @@ class Field extends Base {
|
|
|
290
290
|
* migration.addTask(foo.getTaskDefinition())
|
|
291
291
|
*/
|
|
292
292
|
getTaskDefinition() {
|
|
293
|
-
return this.request
|
|
293
|
+
return this.request;
|
|
294
294
|
}
|
|
295
295
|
|
|
296
296
|
getSchemaFromOptions(opts, field) {
|
|
297
|
-
const allKeys = keys(opts)
|
|
298
|
-
allKeys.forEach(_key => {
|
|
299
|
-
this.buildSchema(_key, field, opts[_key])
|
|
300
|
-
})
|
|
297
|
+
const allKeys = keys(opts);
|
|
298
|
+
allKeys.forEach((_key) => {
|
|
299
|
+
this.buildSchema(_key, field, opts[_key]);
|
|
300
|
+
});
|
|
301
301
|
}
|
|
302
302
|
}
|
|
303
303
|
|
|
304
|
-
module.exports = Field
|
|
304
|
+
module.exports = Field;
|
package/src/modules/index.js
CHANGED
package/src/modules/locale.js
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
'use strict'
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
3
|
// Service
|
|
4
|
-
const {LocaleService} = require('../services')
|
|
4
|
+
const { LocaleService } = require('../services');
|
|
5
5
|
|
|
6
6
|
// Config
|
|
7
|
-
const {masterLocale} = require('../config')
|
|
7
|
+
const { masterLocale } = require('../config');
|
|
8
8
|
|
|
9
9
|
// Utils
|
|
10
|
-
const {safePromise} = require('../utils')
|
|
10
|
+
const { safePromise } = require('../utils');
|
|
11
11
|
|
|
12
12
|
class Locale {
|
|
13
13
|
constructor() {
|
|
14
|
-
this.localeService = new LocaleService()
|
|
14
|
+
this.localeService = new LocaleService();
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
async fetchLocales(callback) {
|
|
18
|
-
let {master_locale} = masterLocale
|
|
18
|
+
let { master_locale } = masterLocale;
|
|
19
19
|
|
|
20
|
-
let {localeService} = this
|
|
21
|
-
let [err, result] = await safePromise(localeService.getLocale())
|
|
20
|
+
let { localeService } = this;
|
|
21
|
+
let [err, result] = await safePromise(localeService.getLocale());
|
|
22
22
|
|
|
23
|
-
if (err) throw new Error(err)
|
|
23
|
+
if (err) throw new Error(err);
|
|
24
24
|
|
|
25
25
|
// Use default code, if no result is found
|
|
26
|
-
result = result.length ? result : [master_locale]
|
|
26
|
+
result = result.length ? result : [master_locale];
|
|
27
27
|
|
|
28
|
-
if (callback) return callback(null, result)
|
|
29
|
-
return result
|
|
28
|
+
if (callback) return callback(null, result);
|
|
29
|
+
return result;
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
module.exports = Locale
|
|
33
|
+
module.exports = Locale;
|