@contentstack/cli-migration 1.10.2 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/lib/actions/action-list.d.ts +8 -0
- package/lib/actions/action-list.js +31 -0
- package/lib/actions/action-list.js.map +1 -0
- package/lib/actions/index.d.ts +180 -0
- package/lib/actions/index.js +207 -0
- package/lib/actions/index.js.map +1 -0
- package/lib/commands/cm/stacks/migration.d.ts +14 -0
- package/lib/commands/cm/stacks/migration.js +274 -0
- package/lib/commands/cm/stacks/migration.js.map +1 -0
- package/lib/config/api-config.d.ts +13 -0
- package/lib/config/api-config.js +19 -0
- package/lib/config/api-config.js.map +1 -0
- package/lib/config/default-options.d.ts +5 -0
- package/lib/config/default-options.js +8 -0
- package/lib/config/default-options.js.map +1 -0
- package/lib/config/index.d.ts +4 -0
- package/lib/config/index.js +11 -0
- package/lib/config/index.js.map +1 -0
- package/lib/config/master-locale.d.ts +7 -0
- package/lib/config/master-locale.js +11 -0
- package/lib/config/master-locale.js.map +1 -0
- package/lib/modules/base.d.ts +39 -0
- package/lib/modules/base.js +84 -0
- package/lib/modules/base.js.map +1 -0
- package/lib/modules/content-types.d.ts +61 -0
- package/lib/modules/content-types.js +173 -0
- package/lib/modules/content-types.js.map +1 -0
- package/lib/modules/fields.d.ts +179 -0
- package/lib/modules/fields.js +292 -0
- package/lib/modules/fields.js.map +1 -0
- package/lib/modules/index.d.ts +5 -0
- package/lib/modules/index.js +13 -0
- package/lib/modules/index.js.map +1 -0
- package/lib/modules/locale.d.ts +6 -0
- package/lib/modules/locale.js +27 -0
- package/lib/modules/locale.js.map +1 -0
- package/lib/modules/migration.d.ts +50 -0
- package/lib/modules/migration.js +109 -0
- package/lib/modules/migration.js.map +1 -0
- package/lib/modules/parser.d.ts +3 -0
- package/lib/modules/parser.js +93 -0
- package/lib/modules/parser.js.map +1 -0
- package/lib/services/content-types.d.ts +25 -0
- package/lib/services/content-types.js +302 -0
- package/lib/services/content-types.js.map +1 -0
- package/lib/services/index.d.ts +3 -0
- package/lib/services/index.js +9 -0
- package/lib/services/index.js.map +1 -0
- package/lib/services/locales.d.ts +6 -0
- package/lib/services/locales.js +68 -0
- package/lib/services/locales.js.map +1 -0
- package/lib/utils/auto-retry.d.ts +2 -0
- package/lib/utils/auto-retry.js +30 -0
- package/lib/utils/auto-retry.js.map +1 -0
- package/lib/utils/callsite.d.ts +2 -0
- package/lib/utils/callsite.js +21 -0
- package/lib/utils/callsite.js.map +1 -0
- package/lib/utils/constants.d.ts +108 -0
- package/lib/utils/constants.js +206 -0
- package/lib/utils/constants.js.map +1 -0
- package/lib/utils/contentstack-sdk.d.ts +7 -0
- package/lib/utils/contentstack-sdk.js +53 -0
- package/lib/utils/contentstack-sdk.js.map +1 -0
- package/lib/utils/error-helper.d.ts +2 -0
- package/lib/utils/error-helper.js +102 -0
- package/lib/utils/error-helper.js.map +1 -0
- package/lib/utils/fs-helper.d.ts +4 -0
- package/lib/utils/fs-helper.js +37 -0
- package/lib/utils/fs-helper.js.map +1 -0
- package/lib/utils/get-batches.d.ts +2 -0
- package/lib/utils/get-batches.js +8 -0
- package/lib/utils/get-batches.js.map +1 -0
- package/lib/utils/get-config.d.ts +6 -0
- package/lib/utils/get-config.js +11 -0
- package/lib/utils/get-config.js.map +1 -0
- package/lib/utils/group-by.d.ts +1 -0
- package/lib/utils/group-by.js +41 -0
- package/lib/utils/group-by.js.map +1 -0
- package/lib/utils/index.d.ts +18 -0
- package/lib/utils/index.js +39 -0
- package/lib/utils/index.js.map +1 -0
- package/lib/utils/logger.d.ts +4 -0
- package/lib/utils/logger.js +68 -0
- package/lib/utils/logger.js.map +1 -0
- package/lib/utils/map.d.ts +7 -0
- package/lib/utils/map.js +40 -0
- package/lib/utils/map.js.map +1 -0
- package/lib/utils/migration-logger.d.ts +7 -0
- package/lib/utils/migration-logger.js +26 -0
- package/lib/utils/migration-logger.js.map +1 -0
- package/lib/utils/modules.d.ts +2 -0
- package/lib/utils/modules.js +118 -0
- package/lib/utils/modules.js.map +1 -0
- package/lib/utils/object-helper.d.ts +1 -0
- package/lib/utils/object-helper.js +12 -0
- package/lib/utils/object-helper.js.map +1 -0
- package/lib/utils/request.d.ts +9 -0
- package/lib/utils/request.js +78 -0
- package/lib/utils/request.js.map +1 -0
- package/lib/utils/safe-promise.d.ts +2 -0
- package/lib/utils/safe-promise.js +6 -0
- package/lib/utils/safe-promise.js.map +1 -0
- package/lib/utils/schema-helper.d.ts +5 -0
- package/lib/utils/schema-helper.js +36 -0
- package/lib/utils/schema-helper.js.map +1 -0
- package/lib/utils/success-handler.d.ts +2 -0
- package/lib/utils/success-handler.js +12 -0
- package/lib/utils/success-handler.js.map +1 -0
- package/lib/validators/api-error.d.ts +4 -0
- package/lib/validators/api-error.js +17 -0
- package/lib/validators/api-error.js.map +1 -0
- package/lib/validators/base-validator.d.ts +4 -0
- package/lib/validators/base-validator.js +34 -0
- package/lib/validators/base-validator.js.map +1 -0
- package/lib/validators/create-content-type-validator.d.ts +7 -0
- package/lib/validators/create-content-type-validator.js +45 -0
- package/lib/validators/create-content-type-validator.js.map +1 -0
- package/lib/validators/edit-content-type-validator.d.ts +7 -0
- package/lib/validators/edit-content-type-validator.js +44 -0
- package/lib/validators/edit-content-type-validator.js.map +1 -0
- package/lib/validators/field-validator.d.ts +4 -0
- package/lib/validators/field-validator.js +17 -0
- package/lib/validators/field-validator.js.map +1 -0
- package/lib/validators/index.d.ts +8 -0
- package/lib/validators/index.js +19 -0
- package/lib/validators/index.js.map +1 -0
- package/lib/validators/migration-error.d.ts +4 -0
- package/lib/validators/migration-error.js +16 -0
- package/lib/validators/migration-error.js.map +1 -0
- package/lib/validators/schema-validator.d.ts +4 -0
- package/lib/validators/schema-validator.js +19 -0
- package/lib/validators/schema-validator.js.map +1 -0
- package/lib/validators/type-error.d.ts +5 -0
- package/lib/validators/type-error.js +18 -0
- package/lib/validators/type-error.js.map +1 -0
- package/oclif.manifest.json +145 -0
- package/package.json +22 -12
- package/src/actions/action-list.js +0 -32
- package/src/actions/index.js +0 -217
- package/src/commands/cm/stacks/migration.js +0 -316
- package/src/config/api-config.js +0 -18
- package/src/config/default-options.js +0 -7
- package/src/config/index.js +0 -7
- package/src/config/master-locale.js +0 -10
- package/src/modules/base.js +0 -95
- package/src/modules/content-types.js +0 -208
- package/src/modules/fields.js +0 -339
- package/src/modules/index.js +0 -8
- package/src/modules/locale.js +0 -33
- package/src/modules/migration.js +0 -112
- package/src/modules/parser.js +0 -105
- package/src/services/content-types.js +0 -317
- package/src/services/index.js +0 -6
- package/src/services/locales.js +0 -71
- package/src/utils/auto-retry.js +0 -32
- package/src/utils/callsite.js +0 -23
- package/src/utils/constants.js +0 -223
- package/src/utils/contentstack-sdk.js +0 -70
- package/src/utils/error-helper.js +0 -105
- package/src/utils/fs-helper.js +0 -29
- package/src/utils/get-batches.js +0 -7
- package/src/utils/get-config.js +0 -13
- package/src/utils/group-by.js +0 -38
- package/src/utils/index.js +0 -21
- package/src/utils/logger.js +0 -75
- package/src/utils/map.js +0 -40
- package/src/utils/migration-logger.js +0 -21
- package/src/utils/modules.js +0 -134
- package/src/utils/object-helper.js +0 -9
- package/src/utils/request.js +0 -95
- package/src/utils/safe-promise.js +0 -3
- package/src/utils/schema-helper.js +0 -35
- package/src/utils/success-handler.js +0 -12
- package/src/validators/api-error.js +0 -20
- package/src/validators/base-validator.js +0 -39
- package/src/validators/create-content-type-validator.js +0 -54
- package/src/validators/edit-content-type-validator.js +0 -53
- package/src/validators/field-validator.js +0 -21
- package/src/validators/index.js +0 -11
- package/src/validators/migration-error.js +0 -20
- package/src/validators/schema-validator.js +0 -23
- package/src/validators/type-error.js +0 -22
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SDK_ACTIONS = exports.transformEntriesToTypeProperties = exports.deriveLinkedEntriesProperties = exports.transformEntriesProperties = exports.validationAction = exports.contentTypeProperties = exports.batchLimit = exports.actionMapper = exports.successMessageHandler = exports.errorMessageHandler = exports.Entry = exports.ContentType = exports.nonWritableMethods = exports.limit = exports.requests = exports.MAX_RETRY = exports.actions = exports.multiple = exports.taxonomies = exports.field_metadata = exports.reference_to = exports.display_name = exports.unique = exports._default = exports.mandatory = exports.data_type = exports.SOURCE_BRANCH = exports.BRANCH = exports.API_KEY = exports.AUTH_TOKEN = exports.MANAGEMENT_TOKEN = exports.MANAGEMENT_CLIENT = exports.MANAGEMENT_SDK = exports.defaultDataType = exports.version = exports.mapObject = void 0;
|
|
4
|
+
exports.mapObject = new Map();
|
|
5
|
+
exports.version = 3; // TODO: Fetch it from CMA
|
|
6
|
+
exports.defaultDataType = 'text';
|
|
7
|
+
exports.MANAGEMENT_SDK = 'MANAGEMENT_SDK';
|
|
8
|
+
exports.MANAGEMENT_CLIENT = 'MANAGEMENT_CLIENT';
|
|
9
|
+
exports.MANAGEMENT_TOKEN = 'MANAGEMENT_TOKEN';
|
|
10
|
+
exports.AUTH_TOKEN = 'AUTH_TOKEN';
|
|
11
|
+
exports.API_KEY = 'API_KEY';
|
|
12
|
+
exports.BRANCH = 'BRANCH';
|
|
13
|
+
exports.SOURCE_BRANCH = 'SOURCE_BRANCH';
|
|
14
|
+
exports.data_type = 'data_type';
|
|
15
|
+
exports.mandatory = 'mandatory';
|
|
16
|
+
exports._default = 'default';
|
|
17
|
+
exports.unique = 'unique';
|
|
18
|
+
exports.display_name = 'display_name';
|
|
19
|
+
exports.reference_to = 'reference_to';
|
|
20
|
+
exports.field_metadata = 'field_metadata';
|
|
21
|
+
exports.taxonomies = 'taxonomies';
|
|
22
|
+
exports.multiple = 'multiple';
|
|
23
|
+
exports.actions = {
|
|
24
|
+
CUSTOM_TASK: 'CUSTOM_TASK',
|
|
25
|
+
CREATE_CT: 'CREATE_CT',
|
|
26
|
+
DELETE_CT: 'DELETE_CT',
|
|
27
|
+
EDIT_CT: 'EDIT_CT',
|
|
28
|
+
LOCALES: 'LOCALES',
|
|
29
|
+
EDIT_FIELD: 'EDIT_FIELD',
|
|
30
|
+
DELETE_FIELD: 'DELETE_FIELD',
|
|
31
|
+
MOVE_FIELD: 'MOVE_FIELD',
|
|
32
|
+
};
|
|
33
|
+
// Http call max retry
|
|
34
|
+
exports.MAX_RETRY = 3;
|
|
35
|
+
// This key holds the value for http objects in map
|
|
36
|
+
exports.requests = 'REQUESTS';
|
|
37
|
+
exports.limit = 1; // Limit for concurrent tasks executed parallely
|
|
38
|
+
exports.nonWritableMethods = ['GET', 'DELETE'];
|
|
39
|
+
exports.ContentType = 'Content type';
|
|
40
|
+
exports.Entry = 'Entry';
|
|
41
|
+
exports.errorMessageHandler = {
|
|
42
|
+
POST: 'saving',
|
|
43
|
+
GET: 'fetching',
|
|
44
|
+
PUT: 'updating',
|
|
45
|
+
DELETE: 'deleting',
|
|
46
|
+
};
|
|
47
|
+
exports.successMessageHandler = {
|
|
48
|
+
POST: 'saved',
|
|
49
|
+
GET: 'fetched',
|
|
50
|
+
PUT: 'updated',
|
|
51
|
+
DELETE: 'deleted',
|
|
52
|
+
};
|
|
53
|
+
// map key
|
|
54
|
+
exports.actionMapper = 'actions';
|
|
55
|
+
exports.batchLimit = 20;
|
|
56
|
+
exports.contentTypeProperties = ['description', 'title', 'uid', 'options', 'force', 'schema'];
|
|
57
|
+
exports.validationAction = {
|
|
58
|
+
create: 'create',
|
|
59
|
+
edit: 'edit',
|
|
60
|
+
customTask: 'customTask',
|
|
61
|
+
transformEntries: 'transformEntries',
|
|
62
|
+
deriveLinkedEntries: 'deriveLinkedEntries',
|
|
63
|
+
transformEntriesToType: 'transformEntriesToType',
|
|
64
|
+
typeError: 'typeError',
|
|
65
|
+
apiError: 'apiError',
|
|
66
|
+
schema: 'schema',
|
|
67
|
+
__migrationError: 'migrationError',
|
|
68
|
+
field: 'field',
|
|
69
|
+
};
|
|
70
|
+
exports.transformEntriesProperties = [
|
|
71
|
+
{
|
|
72
|
+
name: 'contentType',
|
|
73
|
+
type: 'string',
|
|
74
|
+
mandatory: true,
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
name: 'from',
|
|
78
|
+
type: 'array',
|
|
79
|
+
mandatory: true,
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: 'to',
|
|
83
|
+
type: 'array',
|
|
84
|
+
mandatory: true,
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: 'shouldPublish',
|
|
88
|
+
type: 'boolean',
|
|
89
|
+
mandatory: false,
|
|
90
|
+
dependsOn: 'environments',
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
name: 'environments',
|
|
94
|
+
type: 'array',
|
|
95
|
+
mandatory: false,
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
name: 'transformEntryForLocale',
|
|
99
|
+
type: 'function',
|
|
100
|
+
mandatory: true,
|
|
101
|
+
},
|
|
102
|
+
];
|
|
103
|
+
exports.deriveLinkedEntriesProperties = [
|
|
104
|
+
{
|
|
105
|
+
name: 'contentType',
|
|
106
|
+
type: 'string',
|
|
107
|
+
mandatory: true,
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
name: 'derivedContentType',
|
|
111
|
+
type: 'string',
|
|
112
|
+
mandatory: true,
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
name: 'from',
|
|
116
|
+
type: 'array',
|
|
117
|
+
mandatory: true,
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
name: 'toReferenceField',
|
|
121
|
+
type: 'string',
|
|
122
|
+
mandatory: true,
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
name: 'derivedFields',
|
|
126
|
+
type: 'array',
|
|
127
|
+
mandatory: true,
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
name: 'identityKey',
|
|
131
|
+
type: 'function',
|
|
132
|
+
mandatory: true,
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
name: 'shouldPublish',
|
|
136
|
+
type: 'boolean',
|
|
137
|
+
mandatory: false,
|
|
138
|
+
dependsOn: 'environments',
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
name: 'environments',
|
|
142
|
+
type: 'array',
|
|
143
|
+
mandatory: false,
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
name: 'deriveEntryForLocale',
|
|
147
|
+
type: 'function',
|
|
148
|
+
mandatory: true,
|
|
149
|
+
},
|
|
150
|
+
];
|
|
151
|
+
exports.transformEntriesToTypeProperties = [
|
|
152
|
+
{
|
|
153
|
+
name: 'sourceContentType',
|
|
154
|
+
type: 'string',
|
|
155
|
+
mandatory: true,
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
name: 'targetContentType',
|
|
159
|
+
type: 'string',
|
|
160
|
+
mandatory: true,
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
name: 'from',
|
|
164
|
+
type: 'array',
|
|
165
|
+
mandatory: true,
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
name: 'shouldPublish',
|
|
169
|
+
type: 'boolean',
|
|
170
|
+
mandatory: false,
|
|
171
|
+
dependsOn: 'environments',
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
name: 'environments',
|
|
175
|
+
type: 'array',
|
|
176
|
+
mandatory: false,
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
name: 'removeOldEntries',
|
|
180
|
+
type: 'boolean',
|
|
181
|
+
mandatory: false,
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
name: 'identityKey',
|
|
185
|
+
type: 'function',
|
|
186
|
+
mandatory: true,
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
name: 'transformEntryForLocale',
|
|
190
|
+
type: 'function',
|
|
191
|
+
mandatory: true,
|
|
192
|
+
},
|
|
193
|
+
];
|
|
194
|
+
exports.SDK_ACTIONS = {
|
|
195
|
+
CONTENTTYPE_GET: 'CONTENTTYPE_GET',
|
|
196
|
+
CONTENTTYPE_POST: 'CONTENTTYPE_POST',
|
|
197
|
+
CONTENTTYPE_DELETE: 'CONTENTTYPE_GET',
|
|
198
|
+
CONTENTTYPE_PUT: 'CONTENTTYPE_PUT',
|
|
199
|
+
LOCALES_GET: 'LOCALES_GET',
|
|
200
|
+
ENTRY_GET: 'ENTRY_GET',
|
|
201
|
+
ENTRY_POST: 'ENTRY_POST',
|
|
202
|
+
ENTRY_PUT: 'ENTRY_PUT',
|
|
203
|
+
ENTRY_DELETE: 'ENTRY_DELETE',
|
|
204
|
+
ENTRY_PUBLISH: 'ENTRY_PUBLISH',
|
|
205
|
+
};
|
|
206
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/utils/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,SAAS,GAAG,IAAI,GAAG,EAAe,CAAC;AAEnC,QAAA,OAAO,GAAG,CAAC,CAAC,CAAC,0BAA0B;AAEvC,QAAA,eAAe,GAAG,MAAM,CAAC;AAEzB,QAAA,cAAc,GAAG,gBAAgB,CAAC;AAClC,QAAA,iBAAiB,GAAG,mBAAmB,CAAC;AACxC,QAAA,gBAAgB,GAAG,kBAAkB,CAAC;AACtC,QAAA,UAAU,GAAG,YAAY,CAAC;AAC1B,QAAA,OAAO,GAAG,SAAS,CAAC;AACpB,QAAA,MAAM,GAAG,QAAQ,CAAC;AAClB,QAAA,aAAa,GAAG,eAAe,CAAC;AAEhC,QAAA,SAAS,GAAG,WAAW,CAAC;AACxB,QAAA,SAAS,GAAG,WAAW,CAAC;AACxB,QAAA,QAAQ,GAAG,SAAS,CAAC;AACrB,QAAA,MAAM,GAAG,QAAQ,CAAC;AAClB,QAAA,YAAY,GAAG,cAAc,CAAC;AAC9B,QAAA,YAAY,GAAG,cAAc,CAAC;AAC9B,QAAA,cAAc,GAAG,gBAAgB,CAAC;AAClC,QAAA,UAAU,GAAG,YAAY,CAAC;A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5B,aAAa,EAAE,eAAe;CAC/B,CAAC","sourcesContent":["export const mapObject = new Map<string, any>();\n\nexport const version = 3; // TODO: Fetch it from CMA\n\nexport const defaultDataType = 'text';\n\nexport const MANAGEMENT_SDK = 'MANAGEMENT_SDK';\nexport const MANAGEMENT_CLIENT = 'MANAGEMENT_CLIENT';\nexport const MANAGEMENT_TOKEN = 'MANAGEMENT_TOKEN';\nexport const AUTH_TOKEN = 'AUTH_TOKEN';\nexport const API_KEY = 'API_KEY';\nexport const BRANCH = 'BRANCH';\nexport const SOURCE_BRANCH = 'SOURCE_BRANCH';\n\nexport const data_type = 'data_type';\nexport const mandatory = 'mandatory';\nexport const _default = 'default';\nexport const unique = 'unique';\nexport const display_name = 'display_name';\nexport const reference_to = 'reference_to';\nexport const field_metadata = 'field_metadata';\nexport const taxonomies = 'taxonomies';\nexport const multiple = 'multiple';\n\nexport const actions = {\n CUSTOM_TASK: 'CUSTOM_TASK',\n CREATE_CT: 'CREATE_CT',\n DELETE_CT: 'DELETE_CT',\n EDIT_CT: 'EDIT_CT',\n LOCALES: 'LOCALES',\n EDIT_FIELD: 'EDIT_FIELD',\n DELETE_FIELD: 'DELETE_FIELD',\n MOVE_FIELD: 'MOVE_FIELD',\n};\n\n// Http call max retry\nexport const MAX_RETRY = 3;\n\n// This key holds the value for http objects in map\nexport const requests = 'REQUESTS';\n\nexport const limit = 1; // Limit for concurrent tasks executed parallely\n\nexport const nonWritableMethods = ['GET', 'DELETE'];\n\nexport const ContentType = 'Content type';\nexport const Entry = 'Entry';\n\nexport const errorMessageHandler = {\n POST: 'saving',\n GET: 'fetching',\n PUT: 'updating',\n DELETE: 'deleting',\n};\n\nexport const successMessageHandler = {\n POST: 'saved',\n GET: 'fetched',\n PUT: 'updated',\n DELETE: 'deleted',\n};\n// map key\nexport const actionMapper = 'actions';\n\nexport const batchLimit = 20;\n\nexport const contentTypeProperties = ['description', 'title', 'uid', 'options', 'force', 'schema'];\n\nexport const validationAction = {\n create: 'create',\n edit: 'edit',\n customTask: 'customTask',\n transformEntries: 'transformEntries',\n deriveLinkedEntries: 'deriveLinkedEntries',\n transformEntriesToType: 'transformEntriesToType',\n typeError: 'typeError',\n apiError: 'apiError',\n schema: 'schema',\n __migrationError: 'migrationError',\n field: 'field',\n};\n\nexport const transformEntriesProperties = [\n {\n name: 'contentType',\n type: 'string',\n mandatory: true,\n },\n {\n name: 'from',\n type: 'array',\n mandatory: true,\n },\n {\n name: 'to',\n type: 'array',\n mandatory: true,\n },\n {\n name: 'shouldPublish',\n type: 'boolean',\n mandatory: false,\n dependsOn: 'environments',\n },\n {\n name: 'environments',\n type: 'array',\n mandatory: false,\n },\n {\n name: 'transformEntryForLocale',\n type: 'function',\n mandatory: true,\n },\n];\n\nexport const deriveLinkedEntriesProperties = [\n {\n name: 'contentType',\n type: 'string',\n mandatory: true,\n },\n {\n name: 'derivedContentType',\n type: 'string',\n mandatory: true,\n },\n {\n name: 'from',\n type: 'array',\n mandatory: true,\n },\n {\n name: 'toReferenceField',\n type: 'string',\n mandatory: true,\n },\n {\n name: 'derivedFields',\n type: 'array',\n mandatory: true,\n },\n {\n name: 'identityKey',\n type: 'function',\n mandatory: true,\n },\n {\n name: 'shouldPublish',\n type: 'boolean',\n mandatory: false,\n dependsOn: 'environments',\n },\n {\n name: 'environments',\n type: 'array',\n mandatory: false,\n },\n {\n name: 'deriveEntryForLocale',\n type: 'function',\n mandatory: true,\n },\n];\n\nexport const transformEntriesToTypeProperties = [\n {\n name: 'sourceContentType',\n type: 'string',\n mandatory: true,\n },\n {\n name: 'targetContentType',\n type: 'string',\n mandatory: true,\n },\n {\n name: 'from',\n type: 'array',\n mandatory: true,\n },\n {\n name: 'shouldPublish',\n type: 'boolean',\n mandatory: false,\n dependsOn: 'environments',\n },\n {\n name: 'environments',\n type: 'array',\n mandatory: false,\n },\n {\n name: 'removeOldEntries',\n type: 'boolean',\n mandatory: false,\n },\n {\n name: 'identityKey',\n type: 'function',\n mandatory: true,\n },\n {\n name: 'transformEntryForLocale',\n type: 'function',\n mandatory: true,\n },\n];\n\nexport const SDK_ACTIONS = {\n CONTENTTYPE_GET: 'CONTENTTYPE_GET',\n CONTENTTYPE_POST: 'CONTENTTYPE_POST',\n CONTENTTYPE_DELETE: 'CONTENTTYPE_GET',\n CONTENTTYPE_PUT: 'CONTENTTYPE_PUT',\n LOCALES_GET: 'LOCALES_GET',\n ENTRY_GET: 'ENTRY_GET',\n ENTRY_POST: 'ENTRY_POST',\n ENTRY_PUT: 'ENTRY_PUT',\n ENTRY_DELETE: 'ENTRY_DELETE',\n ENTRY_PUBLISH: 'ENTRY_PUBLISH',\n};\n"]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** Dependencies */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
// Map helper
|
|
5
|
+
const map_1 = require("./map");
|
|
6
|
+
// Constants
|
|
7
|
+
const constants_1 = require("./constants");
|
|
8
|
+
// List of actions
|
|
9
|
+
const { CONTENTTYPE_DELETE, CONTENTTYPE_GET, CONTENTTYPE_POST, CONTENTTYPE_PUT, LOCALES_GET, ENTRY_DELETE, ENTRY_GET, ENTRY_POST, ENTRY_PUBLISH, ENTRY_PUT, } = constants_1.SDK_ACTIONS;
|
|
10
|
+
exports.default = ({ action, id, sdkAction }) => {
|
|
11
|
+
return async (_data) => {
|
|
12
|
+
_data = getData(_data, id, action);
|
|
13
|
+
const mapInstance = (0, map_1.getMapInstance)();
|
|
14
|
+
const managementSdk = (0, map_1.get)(constants_1.MANAGEMENT_SDK, mapInstance);
|
|
15
|
+
const { stack } = managementSdk;
|
|
16
|
+
let response;
|
|
17
|
+
switch (sdkAction) {
|
|
18
|
+
case CONTENTTYPE_GET:
|
|
19
|
+
response = await stack.contentType(id).fetch();
|
|
20
|
+
return response;
|
|
21
|
+
case CONTENTTYPE_POST:
|
|
22
|
+
response = await stack.contentType().create(_data);
|
|
23
|
+
return response;
|
|
24
|
+
case CONTENTTYPE_PUT:
|
|
25
|
+
// const contentType = await stack.contentType(id).fetch();
|
|
26
|
+
response = await stack.contentType(_data).update();
|
|
27
|
+
return response;
|
|
28
|
+
case CONTENTTYPE_DELETE:
|
|
29
|
+
response = await stack.contentType(id).delete();
|
|
30
|
+
return response;
|
|
31
|
+
case LOCALES_GET:
|
|
32
|
+
return response;
|
|
33
|
+
case ENTRY_GET:
|
|
34
|
+
return response;
|
|
35
|
+
case ENTRY_POST:
|
|
36
|
+
return response;
|
|
37
|
+
case ENTRY_PUBLISH:
|
|
38
|
+
return response;
|
|
39
|
+
case ENTRY_DELETE:
|
|
40
|
+
return response;
|
|
41
|
+
case ENTRY_PUT:
|
|
42
|
+
return response;
|
|
43
|
+
default:
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
function getData(_data, id, action) {
|
|
48
|
+
let mapInstance = (0, map_1.getMapInstance)();
|
|
49
|
+
let data = _data ? _data : (0, map_1.getDataWithAction)(id, mapInstance, action);
|
|
50
|
+
// return stringify(data);
|
|
51
|
+
return data;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=contentstack-sdk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contentstack-sdk.js","sourceRoot":"","sources":["../../src/utils/contentstack-sdk.ts"],"names":[],"mappings":";AAAA,mBAAmB;;AAEnB,aAAa;AACb,+BAA+D;AAC/D,YAAY;AACZ,2CAA0D;AAC1D,kBAAkB;AAClB,MAAM,EACJ,kBAAkB,EAClB,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,WAAW,EACX,YAAY,EACZ,SAAS,EACT,UAAU,EACV,aAAa,EACb,SAAS,GACV,GAAG,uBAAW,CAAC;AAEhB,kBAAe,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,EAAqD,EAAE,EAAE;IAC9F,OAAO,KAAK,EAAE,KAAU,EAAE,EAAE;QAC1B,KAAK,GAAG,OAAO,CAAC,KAAK,EA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AAI,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAA,uBAAiB,EAAC,EAAE,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;IAEtE,0BAA0B;IAC1B,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["/** Dependencies */\n\n// Map helper\nimport { getMapInstance, getDataWithAction, get } from './map';\n// Constants\nimport { MANAGEMENT_SDK, SDK_ACTIONS } from './constants';\n// List of actions\nconst {\n CONTENTTYPE_DELETE,\n CONTENTTYPE_GET,\n CONTENTTYPE_POST,\n CONTENTTYPE_PUT,\n LOCALES_GET,\n ENTRY_DELETE,\n ENTRY_GET,\n ENTRY_POST,\n ENTRY_PUBLISH,\n ENTRY_PUT,\n} = SDK_ACTIONS;\n\nexport default ({ action, id, sdkAction }: { action: string; id: string; sdkAction: string }) => {\n return async (_data: any) => {\n _data = getData(_data, id, action);\n\n const mapInstance = getMapInstance();\n const managementSdk = get(MANAGEMENT_SDK, mapInstance);\n const { stack } = managementSdk;\n\n let response: any;\n\n switch (sdkAction) {\n case CONTENTTYPE_GET:\n response = await stack.contentType(id).fetch();\n return response;\n case CONTENTTYPE_POST:\n response = await stack.contentType().create(_data);\n return response;\n case CONTENTTYPE_PUT:\n // const contentType = await stack.contentType(id).fetch();\n response = await stack.contentType(_data).update();\n return response;\n case CONTENTTYPE_DELETE:\n response = await stack.contentType(id).delete();\n return response;\n case LOCALES_GET:\n return response;\n case ENTRY_GET:\n return response;\n case ENTRY_POST:\n return response;\n case ENTRY_PUBLISH:\n return response;\n case ENTRY_DELETE:\n return response;\n case ENTRY_PUT:\n return response;\n default:\n }\n };\n};\n\nfunction getData(_data: any, id: string, action: string): any {\n let mapInstance = getMapInstance();\n\n let data = _data ? _data : getDataWithAction(id, mapInstance, action);\n\n // return stringify(data);\n return data;\n}\n"]}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
// @ts-ignore - no types available
|
|
5
|
+
const cardinal_1 = require("cardinal");
|
|
6
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
7
|
+
const isEmpty_1 = tslib_1.__importDefault(require("lodash/isEmpty"));
|
|
8
|
+
const migration_logger_1 = tslib_1.__importDefault(require("./migration-logger"));
|
|
9
|
+
const fs_helper_1 = require("./fs-helper");
|
|
10
|
+
const group_by_1 = tslib_1.__importDefault(require("./group-by"));
|
|
11
|
+
const getLineWithContext = (lines, lineNumber, context) => {
|
|
12
|
+
const line = lineNumber - 1;
|
|
13
|
+
const firstLine = line > context ? line - context : 0;
|
|
14
|
+
const lastLine = line + context < lines.length ? line + context : lines.length;
|
|
15
|
+
return {
|
|
16
|
+
before: lines.slice(firstLine, line),
|
|
17
|
+
line: lines[line],
|
|
18
|
+
after: lines.slice(line + 1, lastLine + 1),
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
function removeSpecialCharacter(str) {
|
|
22
|
+
return str.replace(/\u001b\[\d+m/g, '');
|
|
23
|
+
}
|
|
24
|
+
exports.default = (errors, filePath) => {
|
|
25
|
+
var _a, _b, _c;
|
|
26
|
+
const logger = new migration_logger_1.default((_a = process.env.CS_CLI_LOG_PATH) !== null && _a !== void 0 ? _a : process.cwd());
|
|
27
|
+
const errorsByFile = (0, group_by_1.default)(errors, 'file');
|
|
28
|
+
const messages = [];
|
|
29
|
+
if (filePath) {
|
|
30
|
+
if (errors.request) {
|
|
31
|
+
errors.data = (_b = errors.request) === null || _b === void 0 ? void 0 : _b.data;
|
|
32
|
+
delete errors.request;
|
|
33
|
+
}
|
|
34
|
+
if (errors.message) {
|
|
35
|
+
delete errors.message;
|
|
36
|
+
}
|
|
37
|
+
logger.log('error', { [filePath]: errors });
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
for (const file of Object.keys(errorsByFile)) {
|
|
41
|
+
const errorLogs = {};
|
|
42
|
+
errorLogs[file] = {};
|
|
43
|
+
const fileContents = (0, fs_helper_1.readFile)(file);
|
|
44
|
+
const highlightedCode = (0, cardinal_1.highlight)(fileContents, { linenos: true });
|
|
45
|
+
const lines = highlightedCode.split('\n');
|
|
46
|
+
const fileErrorsMessage = (0, chalk_1.default) `{red Errors in ${file}}\n\n`;
|
|
47
|
+
errorLogs[file].fileErrorsMessage = fileErrorsMessage.replace(/\u001b\[\d+m/g, '');
|
|
48
|
+
const errorMessages = errorsByFile[file]
|
|
49
|
+
.map((error) => {
|
|
50
|
+
var _a, _b;
|
|
51
|
+
const callsite = error.meta.callsite;
|
|
52
|
+
const context = 2;
|
|
53
|
+
let { before, line, after } = getLineWithContext(lines, callsite.line, context);
|
|
54
|
+
const beforeLines = before.map((_line) => (0, chalk_1.default) `${_line}\n`);
|
|
55
|
+
const afterLines = after.map((_line) => (0, chalk_1.default) `${_line}\n`);
|
|
56
|
+
const highlightedLine = (0, chalk_1.default) `{bold ${line}}\n`;
|
|
57
|
+
before = removeSpecialCharacter(before.join('\n'));
|
|
58
|
+
after = removeSpecialCharacter(after.join('\n'));
|
|
59
|
+
line = removeSpecialCharacter(line);
|
|
60
|
+
errorLogs[file].lines = { before, line, after };
|
|
61
|
+
if (error.request) {
|
|
62
|
+
error.data = (_a = error.request) === null || _a === void 0 ? void 0 : _a.data;
|
|
63
|
+
delete error.request;
|
|
64
|
+
}
|
|
65
|
+
if (error.message) {
|
|
66
|
+
delete error.message;
|
|
67
|
+
}
|
|
68
|
+
const formattedCode = beforeLines + highlightedLine + afterLines;
|
|
69
|
+
if ((_b = error.payload) === null || _b === void 0 ? void 0 : _b.apiError) {
|
|
70
|
+
errorLogs[file].apiError = true;
|
|
71
|
+
errorLogs[file].errorCode = error.payload.apiError.errorCode;
|
|
72
|
+
errorLogs[file].errors = error.payload.apiError.errors;
|
|
73
|
+
errorLogs[file].data = error.data;
|
|
74
|
+
}
|
|
75
|
+
if (error.message && !error.payload.apiError) {
|
|
76
|
+
errorLogs[file].apiError = false;
|
|
77
|
+
errorLogs[file].error = error.message;
|
|
78
|
+
}
|
|
79
|
+
})
|
|
80
|
+
.join('\n');
|
|
81
|
+
messages.push(`${fileErrorsMessage}${errorMessages}`);
|
|
82
|
+
logger.log('error', errorLogs);
|
|
83
|
+
}
|
|
84
|
+
if (errors === null || errors === void 0 ? void 0 : errors.request) {
|
|
85
|
+
errors.data = (_c = errors.request) === null || _c === void 0 ? void 0 : _c.data;
|
|
86
|
+
delete errors.request;
|
|
87
|
+
}
|
|
88
|
+
if (errors === null || errors === void 0 ? void 0 : errors.message) {
|
|
89
|
+
delete errors.message;
|
|
90
|
+
}
|
|
91
|
+
if ((0, isEmpty_1.default)(messages) && errors !== undefined && (0, isEmpty_1.default)(errorsByFile)) {
|
|
92
|
+
logger.log('error', { errors: errors });
|
|
93
|
+
console.log((0, chalk_1.default) `{bold.red migration unsuccessful}`);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
logger.log('error', { error: messages.join('\n') });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// eslint-disable-next-line
|
|
100
|
+
// console.log(chalk`{bold.red Migration unsuccessful}`);
|
|
101
|
+
};
|
|
102
|
+
//# sourceMappingURL=error-helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-helper.js","sourceRoot":"","sources":["../../src/utils/error-helper.ts"],"names":[],"mappings":";;;AAAA,kCAAkC;AAClC,uCAAqC;AACrC,0DAA0B;AAC1B,qEAAqC;AACrC,kFAAiD;AAEjD,2CAAuC;AACvC,kEAAiC;AAEjC,MAAM,kBAAkB,GAAG,CAAC,KAAe,EAAE,UAAkB,EAAE,OAAe,EAAO,EAAE;IACvF,MAAM,IAAI,GAAG,UAAU,GAAG,CAAC,CAAC;IAE5B,MAAM,SAAS,GAAG,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IACtD,M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AG,aAAa,EAAE,CAAC,CAAC;YACtD,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;SAChC;QACD,IAAI,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,OAAO,EAAE;YACnB,MAAM,CAAC,IAAI,GAAG,MAAA,MAAM,CAAC,OAAO,0CAAE,IAAI,CAAC;YACnC,OAAO,MAAM,CAAC,OAAO,CAAC;SACvB;QACD,IAAI,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,OAAO,EAAE;YACnB,OAAO,MAAM,CAAC,OAAO,CAAC;SACvB;QACD,IAAI,IAAA,iBAAO,EAAC,QAAQ,CAAC,IAAI,MAAM,KAAK,SAAS,IAAI,IAAA,iBAAO,EAAC,YAAY,CAAC,EAAE;YACtE,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;YACxC,OAAO,CAAC,GAAG,CAAC,IAAA,eAAK,EAAA,mCAAmC,CAAC,CAAC;SACvD;aAAM;YACL,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;SACrD;KACF;IACD,2BAA2B;IAC3B,yDAAyD;AAC3D,CAAC,CAAC","sourcesContent":["// @ts-ignore - no types available\nimport { highlight } from 'cardinal';\nimport chalk from 'chalk';\nimport isEmpty from 'lodash/isEmpty';\nimport MigrationLogger from './migration-logger';\nimport fs from 'fs';\nimport { readFile } from './fs-helper';\nimport groupBy from './group-by';\n\nconst getLineWithContext = (lines: string[], lineNumber: number, context: number): any => {\n const line = lineNumber - 1;\n\n const firstLine = line > context ? line - context : 0;\n const lastLine = line + context < lines.length ? line + context : lines.length;\n\n return {\n before: lines.slice(firstLine, line),\n line: lines[line],\n after: lines.slice(line + 1, lastLine + 1),\n };\n};\n\nfunction removeSpecialCharacter(str: string): string {\n return str.replace(/\\u001b\\[\\d+m/g, '');\n}\n\nexport default (errors: any, filePath?: string): void => {\n const logger = new MigrationLogger(process.env.CS_CLI_LOG_PATH ?? process.cwd());\n\n const errorsByFile = groupBy(errors, 'file');\n const messages: string[] = [];\n if (filePath) {\n if (errors.request) {\n errors.data = errors.request?.data;\n delete errors.request;\n }\n if (errors.message) {\n delete errors.message;\n }\n logger.log('error', { [filePath]: errors });\n } else {\n for (const file of Object.keys(errorsByFile)) {\n const errorLogs: any = {};\n errorLogs[file] = {};\n const fileContents = readFile(file);\n const highlightedCode = highlight(fileContents, { linenos: true });\n const lines = highlightedCode.split('\\n');\n\n const fileErrorsMessage = chalk`{red Errors in ${file}}\\n\\n`;\n errorLogs[file].fileErrorsMessage = fileErrorsMessage.replace(/\\u001b\\[\\d+m/g, '');\n const errorMessages = errorsByFile[file]\n .map((error: any) => {\n const callsite = error.meta.callsite;\n const context = 2;\n let { before, line, after } = getLineWithContext(lines, callsite.line, context);\n\n const beforeLines = before.map((_line: string) => chalk`${_line}\\n`);\n const afterLines = after.map((_line: string) => chalk`${_line}\\n`);\n const highlightedLine = chalk`{bold ${line}}\\n`;\n\n before = removeSpecialCharacter(before.join('\\n'));\n after = removeSpecialCharacter(after.join('\\n'));\n line = removeSpecialCharacter(line);\n errorLogs[file].lines = { before, line, after };\n if (error.request) {\n error.data = error.request?.data;\n delete error.request;\n }\n if (error.message) {\n delete error.message;\n }\n const formattedCode = beforeLines + highlightedLine + afterLines;\n if (error.payload?.apiError) {\n errorLogs[file].apiError = true;\n errorLogs[file].errorCode = error.payload.apiError.errorCode;\n errorLogs[file].errors = error.payload.apiError.errors;\n errorLogs[file].data = error.data;\n }\n if (error.message && !error.payload.apiError) {\n errorLogs[file].apiError = false;\n errorLogs[file].error = error.message;\n }\n })\n .join('\\n');\n\n messages.push(`${fileErrorsMessage}${errorMessages}`);\n logger.log('error', errorLogs);\n }\n if (errors?.request) {\n errors.data = errors.request?.data;\n delete errors.request;\n }\n if (errors?.message) {\n delete errors.message;\n }\n if (isEmpty(messages) && errors !== undefined && isEmpty(errorsByFile)) {\n logger.log('error', { errors: errors });\n console.log(chalk`{bold.red migration unsuccessful}`);\n } else {\n logger.log('error', { error: messages.join('\\n') });\n }\n }\n // eslint-disable-next-line\n // console.log(chalk`{bold.red Migration unsuccessful}`);\n};\n"]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readJSONFile = exports.readFile = exports.makeDir = exports.existsSyncHelper = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
6
|
+
const existsSyncHelper = (filePath) => (0, fs_1.existsSync)(filePath);
|
|
7
|
+
exports.existsSyncHelper = existsSyncHelper;
|
|
8
|
+
const makeDir = (dirname) => {
|
|
9
|
+
!(0, exports.existsSyncHelper)(dirname) && (0, fs_1.mkdirSync)(dirname, { recursive: true });
|
|
10
|
+
};
|
|
11
|
+
exports.makeDir = makeDir;
|
|
12
|
+
const readFile = (filePath) => {
|
|
13
|
+
if (!(0, fs_1.existsSync)(filePath))
|
|
14
|
+
throw new Error('File does not exist');
|
|
15
|
+
return (0, fs_1.readFileSync)(filePath, 'utf-8');
|
|
16
|
+
};
|
|
17
|
+
exports.readFile = readFile;
|
|
18
|
+
const readJSONFile = (filePath) => {
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
filePath = (0, cli_utilities_1.pathValidator)(filePath);
|
|
21
|
+
(0, fs_1.readFile)(filePath, 'utf-8', (error, data) => {
|
|
22
|
+
if (error) {
|
|
23
|
+
reject(error);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
try {
|
|
27
|
+
resolve(JSON.parse(data));
|
|
28
|
+
}
|
|
29
|
+
catch (parseError) {
|
|
30
|
+
reject(parseError);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
};
|
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C,OAAO,UAAU,EAAE;oBACnB,MAAM,CAAC,UAAU,CAAC,CAAC;iBACpB;aACF;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAfW,QAAA,YAAY,gBAevB","sourcesContent":["import { existsSync, mkdirSync, readFileSync, readFile as fsReadFile } from 'fs';\nimport path from 'path';\nimport { pathValidator } from '@contentstack/cli-utilities';\n\nexport const existsSyncHelper = (filePath: string): boolean => existsSync(filePath);\n\nexport const makeDir = (dirname: string): void => {\n !existsSyncHelper(dirname) && mkdirSync(dirname, { recursive: true });\n};\n\nexport const readFile = (filePath: string): string => {\n if (!existsSync(filePath)) throw new Error('File does not exist');\n return readFileSync(filePath, 'utf-8');\n};\n\nexport const readJSONFile = (filePath: string): Promise<any> => {\n return new Promise((resolve, reject) => {\n filePath = pathValidator(filePath);\n fsReadFile(filePath, 'utf-8', (error: any, data: string) => {\n if (error) {\n reject(error);\n } else {\n try {\n resolve(JSON.parse(data));\n } catch (parseError) {\n reject(parseError);\n }\n }\n });\n });\n};\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = (count, batchLimit) => {
|
|
4
|
+
const partitions = Math.ceil(count / batchLimit);
|
|
5
|
+
// Returns array filled with indexes
|
|
6
|
+
return new Array(partitions).fill(null).map((_, i) => i);
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=get-batches.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-batches.js","sourceRoot":"","sources":["../../src/utils/get-batches.ts"],"names":[],"mappings":";;AAAA,kBAAe,CAAC,KAAa,EAAE,UAAkB,EAAY,EAAE;IAC7D,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC,CAAC;IACjD,oCAAoC;IACpC,OAAO,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;AAC3D,CAAC,CAAC","sourcesContent":["export default (count: number, batchLimit: number): number[] => {\n const partitions = Math.ceil(count / batchLimit);\n // Returns array filled with indexes\n return new Array(partitions).fill(null).map((_, i) => i);\n};\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const config_1 = require("../config");
|
|
4
|
+
exports.default = ({ method, path, sdkAction }) => {
|
|
5
|
+
const config = Object.assign(Object.assign({}, config_1.apiConfig), { path: path ? `${config_1.apiConfig.version}${path}` : config_1.apiConfig.version, method, headers: Object.assign({}, config_1.apiConfig.headers) });
|
|
6
|
+
if (sdkAction !== undefined) {
|
|
7
|
+
config.sdkAction = sdkAction;
|
|
8
|
+
}
|
|
9
|
+
return config;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=get-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-config.js","sourceRoot":"","sources":["../../src/utils/get-config.ts"],"names":[],"mappings":";;AAAA,sCAAsC;AAEtC,kBAAe,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAyD,EAAO,EAAE;IACzG,MAAM,MAAM,mCACP,kBAAS,KACZ,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,kBAAS,CAAC,OAAO,GAAG,IAAI,EAAE,CAAC,CAAC,CAAC,kBAAS,CAAC,OAAO,EAC9D,MAAM,EACN,OAAO,oBAAO,kBAAS,CAAC,OAAO,IAChC,CAAC;IACF,IAAI,SAAS,KAAK,SAAS,EAAE;QAC3B,MAAM,CAAC,SAAS,GAAG,SAAS,CAAC;KAC9B;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC","sourcesContent":["import { apiConfig } from '../config';\n\nexport default ({ method, path, sdkAction }: { method: string; path?: string; sdkAction?: string }): any => {\n const config: any = {\n ...apiConfig,\n path: path ? `${apiConfig.version}${path}` : apiConfig.version,\n method,\n headers: { ...apiConfig.headers },\n };\n if (sdkAction !== undefined) {\n config.sdkAction = sdkAction;\n }\n return config;\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function groupBy(data: any, field: string, i?: number, finalObj?: any, originalArray?: any[]): any;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function groupBy(data, field, i = 0, finalObj = {}, originalArray = []) {
|
|
4
|
+
if (!data)
|
|
5
|
+
return finalObj;
|
|
6
|
+
if (Array.isArray(data)) {
|
|
7
|
+
groupBy(data[i], field, 0, finalObj, data);
|
|
8
|
+
}
|
|
9
|
+
else if (field in data) {
|
|
10
|
+
let dataField = data[field];
|
|
11
|
+
if (dataField in finalObj) {
|
|
12
|
+
finalObj[dataField].push(originalArray[i]);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
finalObj[dataField] = [];
|
|
16
|
+
finalObj[dataField].push(originalArray[i]);
|
|
17
|
+
}
|
|
18
|
+
i++;
|
|
19
|
+
// Breaks when i has been incremented more than length of original array
|
|
20
|
+
if (i !== 0 && i >= originalArray.length)
|
|
21
|
+
return finalObj;
|
|
22
|
+
/**
|
|
23
|
+
* After the field is found only then increment i and inspect next item
|
|
24
|
+
* This will restrict iterating through array just to the length of array
|
|
25
|
+
*/
|
|
26
|
+
groupBy(originalArray[i], field, i, finalObj, originalArray);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
for (let key in data) {
|
|
30
|
+
if (key) {
|
|
31
|
+
let dataKey = data[key];
|
|
32
|
+
if (!Array.isArray(dataKey) && typeof dataKey === 'object') {
|
|
33
|
+
groupBy(dataKey, field, i, finalObj, originalArray);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return finalObj;
|
|
39
|
+
}
|
|
40
|
+
exports.default = groupBy;
|
|
41
|
+
//# sourceMappingURL=group-by.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"group-by.js","sourceRoot":"","sources":["../../src/utils/group-by.ts"],"names":[],"mappings":";;AAAA,SAAwB,OAAO,CAAC,IAAS,EAAE,KAAa,EAAE,IAAY,CAAC,EAAE,WAAgB,EAAE,EAAE,gBAAuB,EAAE;IACpH,IAAI,CAAC,IAAI;QAAE,OAAO,QAAQ,CAAC;IAE3B,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QACvB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;KAC5C;SAAM,IAAI,KAAK,IAAI,IAAI,EAAE;QACxB,IAAI,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;QAC5B,IAAI,SAAS,IAAI,QAAQ,EAAE;YACzB,QAAQ,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;SAC5C;aAAM;YACL,QAAQ,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC;YACzB,QAAQ,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;SAC5C;QAED,CAAC,EAAE,CAAC;QAEJ,wEAAwE;QACxE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,aAAa,CAAC,MAAM;YAAE,OAAO,QAAQ,CAAC;QAC1D;;;WAGG;QACH,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAC;KAC9D;SAAM;QACL,KAAK,IAAI,GAAG,IAAI,IAAI,EAAE;YACpB,IAAI,GAAG,EAAE;gBACP,IAAI,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;gBACxB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;oBAC1D,OAAO,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAC;iBACrD;aACF;SACF;KACF;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC;AAnCD,0BAmCC","sourcesContent":["export default function groupBy(data: any, field: string, i: number = 0, finalObj: any = {}, originalArray: any[] = []): any {\n if (!data) return finalObj;\n\n if (Array.isArray(data)) {\n groupBy(data[i], field, 0, finalObj, data);\n } else if (field in data) {\n let dataField = data[field];\n if (dataField in finalObj) {\n finalObj[dataField].push(originalArray[i]);\n } else {\n finalObj[dataField] = [];\n finalObj[dataField].push(originalArray[i]);\n }\n\n i++;\n\n // Breaks when i has been incremented more than length of original array\n if (i !== 0 && i >= originalArray.length) return finalObj;\n /**\n * After the field is found only then increment i and inspect next item\n * This will restrict iterating through array just to the length of array\n */\n groupBy(originalArray[i], field, i, finalObj, originalArray);\n } else {\n for (let key in data) {\n if (key) {\n let dataKey = data[key];\n if (!Array.isArray(dataKey) && typeof dataKey === 'object') {\n groupBy(dataKey, field, i, finalObj, originalArray);\n }\n }\n }\n }\n\n return finalObj;\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as map from './map';
|
|
2
|
+
import * as constants from './constants';
|
|
3
|
+
import * as schemaHelper from './schema-helper';
|
|
4
|
+
import * as objectHelper from './object-helper';
|
|
5
|
+
import * as fsHelper from './fs-helper';
|
|
6
|
+
import * as logger from './logger';
|
|
7
|
+
import https from './request';
|
|
8
|
+
import safePromise from './safe-promise';
|
|
9
|
+
import getConfig from './get-config';
|
|
10
|
+
import successHandler from './success-handler';
|
|
11
|
+
import getCallsite from './callsite';
|
|
12
|
+
import errorHelper from './error-helper';
|
|
13
|
+
import groupBy from './group-by';
|
|
14
|
+
import getBatches from './get-batches';
|
|
15
|
+
import autoRetry from './auto-retry';
|
|
16
|
+
import contentstackSdk from './contentstack-sdk';
|
|
17
|
+
import installModules from './modules';
|
|
18
|
+
export { map, constants, schemaHelper, objectHelper, fsHelper, logger, https, safePromise, getConfig, successHandler, getCallsite, errorHelper, groupBy, getBatches, autoRetry, contentstackSdk, installModules, };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.installModules = exports.contentstackSdk = exports.autoRetry = exports.getBatches = exports.groupBy = exports.errorHelper = exports.getCallsite = exports.successHandler = exports.getConfig = exports.safePromise = exports.https = exports.logger = exports.fsHelper = exports.objectHelper = exports.schemaHelper = exports.constants = exports.map = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const map = tslib_1.__importStar(require("./map"));
|
|
6
|
+
exports.map = map;
|
|
7
|
+
const constants = tslib_1.__importStar(require("./constants"));
|
|
8
|
+
exports.constants = constants;
|
|
9
|
+
const schemaHelper = tslib_1.__importStar(require("./schema-helper"));
|
|
10
|
+
exports.schemaHelper = schemaHelper;
|
|
11
|
+
const objectHelper = tslib_1.__importStar(require("./object-helper"));
|
|
12
|
+
exports.objectHelper = objectHelper;
|
|
13
|
+
const fsHelper = tslib_1.__importStar(require("./fs-helper"));
|
|
14
|
+
exports.fsHelper = fsHelper;
|
|
15
|
+
const logger = tslib_1.__importStar(require("./logger"));
|
|
16
|
+
exports.logger = logger;
|
|
17
|
+
const request_1 = tslib_1.__importDefault(require("./request"));
|
|
18
|
+
exports.https = request_1.default;
|
|
19
|
+
const safe_promise_1 = tslib_1.__importDefault(require("./safe-promise"));
|
|
20
|
+
exports.safePromise = safe_promise_1.default;
|
|
21
|
+
const get_config_1 = tslib_1.__importDefault(require("./get-config"));
|
|
22
|
+
exports.getConfig = get_config_1.default;
|
|
23
|
+
const success_handler_1 = tslib_1.__importDefault(require("./success-handler"));
|
|
24
|
+
exports.successHandler = success_handler_1.default;
|
|
25
|
+
const callsite_1 = tslib_1.__importDefault(require("./callsite"));
|
|
26
|
+
exports.getCallsite = callsite_1.default;
|
|
27
|
+
const error_helper_1 = tslib_1.__importDefault(require("./error-helper"));
|
|
28
|
+
exports.errorHelper = error_helper_1.default;
|
|
29
|
+
const group_by_1 = tslib_1.__importDefault(require("./group-by"));
|
|
30
|
+
exports.groupBy = group_by_1.default;
|
|
31
|
+
const get_batches_1 = tslib_1.__importDefault(require("./get-batches"));
|
|
32
|
+
exports.getBatches = get_batches_1.default;
|
|
33
|
+
const auto_retry_1 = tslib_1.__importDefault(require("./auto-retry"));
|
|
34
|
+
exports.autoRetry = auto_retry_1.default;
|
|
35
|
+
const contentstack_sdk_1 = tslib_1.__importDefault(require("./contentstack-sdk"));
|
|
36
|
+
exports.contentstackSdk = contentstack_sdk_1.default;
|
|
37
|
+
const modules_1 = tslib_1.__importDefault(require("./modules"));
|
|
38
|
+
exports.installModules = modules_1.default;
|
|
39
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;AAAA,mDAA6B;AAmB3B,kBAAG;AAlBL,+DAAyC;AAmBvC,8BAAS;AAlBX,sEAAgD;AAmB9C,oCAAY;AAlBd,sEAAgD;AAmB9C,oCAAY;AAlBd,8DAAwC;AAmBtC,4BAAQ;AAlBV,yDAAmC;AAmBjC,wBAAM;AAlBR,gEAA8B;AAmB5B,gBAnBK,iBAAK,CAmBL;AAlBP,0EAAyC;AAmBvC,sBAnBK,sBAAW,CAmBL;AAlBb,sEAAqC;AAmBnC,oBAnBK,oBAAS,CAmBL;AAlBX,gFAA+C;AAmB7C,yBAnBK,yBAAc,CAmBL;AAlBhB,kEAAqC;AAmBnC,sBAnBK,kBAAW,CAmBL;AAlBb,0EAAyC;AAmBvC,sBAnBK,sBAAW,CAmBL;AAlBb,kEAAiC;AAmB/B,kBAnBK,kBAAO,CAmBL;AAlBT,wEAAuC;AAmBrC,qBAnBK,qBAAU,CAmBL;AAlBZ,sEAAqC;AAmBnC,oBAnBK,oBAAS,CAmBL;AAlBX,kFAAiD;AAmB/C,0BAnBK,0BAAe,CAmBL;AAlBjB,gEAAuC;AAmBrC,yBAnBK,iBAAc,CAmBL","sourcesContent":["import * as map from './map';\nimport * as constants from './constants';\nimport * as schemaHelper from './schema-helper';\nimport * as objectHelper from './object-helper';\nimport * as fsHelper from './fs-helper';\nimport * as logger from './logger';\nimport https from './request';\nimport safePromise from './safe-promise';\nimport getConfig from './get-config';\nimport successHandler from './success-handler';\nimport getCallsite from './callsite';\nimport errorHelper from './error-helper';\nimport groupBy from './group-by';\nimport getBatches from './get-batches';\nimport autoRetry from './auto-retry';\nimport contentstackSdk from './contentstack-sdk';\nimport installModules from './modules';\n\nexport {\n map,\n constants,\n schemaHelper,\n objectHelper,\n fsHelper,\n logger,\n https,\n safePromise,\n getConfig,\n successHandler,\n getCallsite,\n errorHelper,\n groupBy,\n getBatches,\n autoRetry,\n contentstackSdk,\n installModules,\n};\n"]}
|