contentful-import 9.0.21 → 9.1.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/dist/index.js +155 -160
- package/dist/parseOptions.js +92 -89
- package/dist/tasks/get-destination-data.js +100 -133
- package/dist/tasks/init-client.js +14 -20
- package/dist/tasks/push-to-space/assets.js +66 -74
- package/dist/tasks/push-to-space/creation.js +134 -183
- package/dist/tasks/push-to-space/publishing.js +86 -86
- package/dist/tasks/push-to-space/push-to-space.js +293 -310
- package/dist/transform/transform-space.js +49 -29
- package/dist/transform/transformers.js +50 -55
- package/dist/usageParams.js +113 -74
- package/dist/utils/headers.js +21 -28
- package/dist/utils/schema.js +62 -71
- package/dist/utils/sort-entries.js +83 -60
- package/dist/utils/sort-locales.js +27 -32
- package/dist/utils/validations.js +42 -45
- package/package.json +12 -18
|
@@ -1,227 +1,178 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
exports.createEntities =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var _getEntityName = _interopRequireDefault(require("contentful-batch-libs/dist/get-entity-name"));
|
|
12
|
-
var _logging = require("contentful-batch-libs/dist/logging");
|
|
13
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createEntries = exports.createLocales = exports.createEntities = void 0;
|
|
7
|
+
const collection_1 = require("lodash/collection");
|
|
8
|
+
const object_1 = require("lodash/object");
|
|
9
|
+
const get_entity_name_1 = __importDefault(require("contentful-batch-libs/dist/get-entity-name"));
|
|
10
|
+
const logging_1 = require("contentful-batch-libs/dist/logging");
|
|
14
11
|
/**
|
|
15
12
|
* Creates a list of entities
|
|
16
13
|
* Applies to all entities except Entries, as the CMA API for those is slightly different
|
|
17
14
|
* See handleCreationErrors for details on what errors reject the promise or not.
|
|
18
15
|
*/
|
|
19
|
-
function createEntities({
|
|
20
|
-
|
|
21
|
-
entities,
|
|
22
|
-
destinationEntitiesById,
|
|
23
|
-
requestQueue
|
|
24
|
-
}) {
|
|
25
|
-
return createEntitiesWithConcurrency({
|
|
26
|
-
context,
|
|
27
|
-
entities,
|
|
28
|
-
destinationEntitiesById,
|
|
29
|
-
requestQueue
|
|
30
|
-
});
|
|
16
|
+
function createEntities({ context, entities, destinationEntitiesById, requestQueue }) {
|
|
17
|
+
return createEntitiesWithConcurrency({ context, entities, destinationEntitiesById, requestQueue });
|
|
31
18
|
}
|
|
32
|
-
|
|
19
|
+
exports.createEntities = createEntities;
|
|
33
20
|
// TODO
|
|
34
21
|
// Locales need to be created in series
|
|
35
|
-
function createLocales({
|
|
36
|
-
|
|
37
|
-
entities,
|
|
38
|
-
destinationEntitiesById,
|
|
39
|
-
requestQueue
|
|
40
|
-
}) {
|
|
41
|
-
return createEntitiesInSequence({
|
|
42
|
-
context,
|
|
43
|
-
entities,
|
|
44
|
-
destinationEntitiesById,
|
|
45
|
-
requestQueue
|
|
46
|
-
});
|
|
22
|
+
function createLocales({ context, entities, destinationEntitiesById, requestQueue }) {
|
|
23
|
+
return createEntitiesInSequence({ context, entities, destinationEntitiesById, requestQueue });
|
|
47
24
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
25
|
+
exports.createLocales = createLocales;
|
|
26
|
+
async function createEntitiesWithConcurrency({ context, entities, destinationEntitiesById, requestQueue }) {
|
|
27
|
+
const pendingCreatedEntities = entities.map((entity) => {
|
|
28
|
+
const destinationEntity = getDestinationEntityForSourceEntity(destinationEntitiesById, entity.transformed);
|
|
29
|
+
const operation = destinationEntity ? 'update' : 'create';
|
|
30
|
+
return requestQueue.add(async () => {
|
|
31
|
+
try {
|
|
32
|
+
const createdEntity = await (destinationEntity
|
|
33
|
+
? updateDestinationWithSourceData(destinationEntity, entity.transformed)
|
|
34
|
+
: createInDestination(context, entity.transformed));
|
|
35
|
+
creationSuccessNotifier(operation, createdEntity);
|
|
36
|
+
return createdEntity;
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
return handleCreationErrors(entity, err);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
65
42
|
});
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
// Filter null values in case of errors
|
|
70
|
-
return createdEntities.filter(entity => entity);
|
|
43
|
+
const createdEntities = await Promise.all(pendingCreatedEntities);
|
|
44
|
+
// Filter null values in case of errors
|
|
45
|
+
return createdEntities.filter((entity) => entity);
|
|
71
46
|
}
|
|
72
|
-
async function createEntitiesInSequence({
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
47
|
+
async function createEntitiesInSequence({ context, entities, destinationEntitiesById, requestQueue }) {
|
|
48
|
+
const createdEntities = [];
|
|
49
|
+
for (const entity of entities) {
|
|
50
|
+
const destinationEntity = getDestinationEntityForSourceEntity(destinationEntitiesById, entity.transformed);
|
|
51
|
+
const operation = destinationEntity ? 'update' : 'create';
|
|
52
|
+
try {
|
|
53
|
+
// Even though we run things in sequence here,
|
|
54
|
+
// we still want to go through the normal rate limiting queue
|
|
55
|
+
const createdEntity = await requestQueue.add(async () => {
|
|
56
|
+
const createdOrUpdatedEntity = await (destinationEntity
|
|
57
|
+
? updateDestinationWithSourceData(destinationEntity, entity.transformed)
|
|
58
|
+
: createInDestination(context, entity.transformed));
|
|
59
|
+
return createdOrUpdatedEntity;
|
|
60
|
+
});
|
|
61
|
+
creationSuccessNotifier(operation, createdEntity);
|
|
62
|
+
createdEntities.push(createdEntity);
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
const maybeSubstituteEntity = handleCreationErrors(entity, err);
|
|
66
|
+
if (maybeSubstituteEntity) {
|
|
67
|
+
createdEntities.push(maybeSubstituteEntity);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
96
70
|
}
|
|
97
|
-
|
|
98
|
-
return createdEntities;
|
|
71
|
+
return createdEntities;
|
|
99
72
|
}
|
|
100
|
-
|
|
101
73
|
/**
|
|
102
74
|
* Creates a list of entries
|
|
103
75
|
*/
|
|
104
|
-
async function createEntries({
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}) {
|
|
110
|
-
const createdEntries = await Promise.all(entities.map(entry => {
|
|
111
|
-
return createEntry({
|
|
112
|
-
entry,
|
|
113
|
-
target: context.target,
|
|
114
|
-
skipContentModel: context.skipContentModel,
|
|
115
|
-
destinationEntitiesById,
|
|
116
|
-
requestQueue
|
|
117
|
-
});
|
|
118
|
-
}));
|
|
119
|
-
return createdEntries.filter(entry => entry);
|
|
76
|
+
async function createEntries({ context, entities, destinationEntitiesById, requestQueue }) {
|
|
77
|
+
const createdEntries = await Promise.all(entities.map((entry) => {
|
|
78
|
+
return createEntry({ entry, target: context.target, skipContentModel: context.skipContentModel, destinationEntitiesById, requestQueue });
|
|
79
|
+
}));
|
|
80
|
+
return createdEntries.filter((entry) => entry);
|
|
120
81
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
destinationEntitiesById,
|
|
149
|
-
requestQueue
|
|
150
|
-
});
|
|
82
|
+
exports.createEntries = createEntries;
|
|
83
|
+
async function createEntry({ entry, target, skipContentModel, destinationEntitiesById, requestQueue }) {
|
|
84
|
+
const contentTypeId = entry.original.sys.contentType.sys.id;
|
|
85
|
+
const destinationEntry = getDestinationEntityForSourceEntity(destinationEntitiesById, entry.transformed);
|
|
86
|
+
const operation = destinationEntry ? 'update' : 'create';
|
|
87
|
+
try {
|
|
88
|
+
const createdOrUpdatedEntry = await requestQueue.add(() => {
|
|
89
|
+
return (destinationEntry
|
|
90
|
+
? updateDestinationWithSourceData(destinationEntry, entry.transformed)
|
|
91
|
+
: createEntryInDestination(target, contentTypeId, entry.transformed));
|
|
92
|
+
});
|
|
93
|
+
creationSuccessNotifier(operation, createdOrUpdatedEntry);
|
|
94
|
+
return createdOrUpdatedEntry;
|
|
95
|
+
}
|
|
96
|
+
catch (err) {
|
|
97
|
+
/* If a field doesn't exist, it means it has been removed from the content types
|
|
98
|
+
* In that case, the field is removed from the entry, and creation is attempted again.
|
|
99
|
+
*/
|
|
100
|
+
if (skipContentModel && err.name === 'UnknownField') {
|
|
101
|
+
const errors = (0, object_1.get)(JSON.parse(err.message), 'details.errors');
|
|
102
|
+
entry.transformed.fields = cleanupUnknownFields(entry.transformed.fields, errors);
|
|
103
|
+
return createEntry({ entry, target, skipContentModel, destinationEntitiesById, requestQueue });
|
|
104
|
+
}
|
|
105
|
+
err.entity = entry;
|
|
106
|
+
logging_1.logEmitter.emit('error', err);
|
|
107
|
+
// No need to pass this entry down to publishing if it wasn't created
|
|
108
|
+
return null;
|
|
151
109
|
}
|
|
152
|
-
err.entity = entry;
|
|
153
|
-
_logging.logEmitter.emit('error', err);
|
|
154
|
-
|
|
155
|
-
// No need to pass this entry down to publishing if it wasn't created
|
|
156
|
-
return null;
|
|
157
|
-
}
|
|
158
110
|
}
|
|
159
111
|
function updateDestinationWithSourceData(destinationEntity, sourceEntity) {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
112
|
+
const plainData = getPlainData(sourceEntity);
|
|
113
|
+
(0, object_1.assign)(destinationEntity, plainData);
|
|
114
|
+
return destinationEntity.update();
|
|
163
115
|
}
|
|
164
116
|
function createInDestination(context, sourceEntity) {
|
|
165
|
-
|
|
166
|
-
type
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
return id ? target[`create${type}WithId`](id, plainData) : target[`create${type}`](plainData);
|
|
117
|
+
const { type, target } = context;
|
|
118
|
+
if (type === 'Tag') {
|
|
119
|
+
// tags are created with a different signature
|
|
120
|
+
return createTagInDestination(context, sourceEntity);
|
|
121
|
+
}
|
|
122
|
+
const id = (0, object_1.get)(sourceEntity, 'sys.id');
|
|
123
|
+
const plainData = getPlainData(sourceEntity);
|
|
124
|
+
return id
|
|
125
|
+
? target[`create${type}WithId`](id, plainData)
|
|
126
|
+
: target[`create${type}`](plainData);
|
|
176
127
|
}
|
|
177
128
|
function createEntryInDestination(space, contentTypeId, sourceEntity) {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
129
|
+
const id = sourceEntity.sys.id;
|
|
130
|
+
const plainData = getPlainData(sourceEntity);
|
|
131
|
+
return id
|
|
132
|
+
? space.createEntryWithId(contentTypeId, id, plainData)
|
|
133
|
+
: space.createEntry(contentTypeId, plainData);
|
|
181
134
|
}
|
|
182
135
|
function createTagInDestination(context, sourceEntity) {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
136
|
+
const id = sourceEntity.sys.id;
|
|
137
|
+
const visibility = sourceEntity.sys.visibility || 'private';
|
|
138
|
+
const name = sourceEntity.name;
|
|
139
|
+
return context.target.createTag(id, name, visibility);
|
|
187
140
|
}
|
|
188
|
-
|
|
189
141
|
/**
|
|
190
142
|
* Handles entity creation errors.
|
|
191
143
|
* If the error is a VersionMismatch the error is thrown and a message is returned
|
|
192
144
|
* instructing the user on what this situation probably means.
|
|
193
145
|
*/
|
|
194
146
|
function handleCreationErrors(entity, err) {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
147
|
+
// Handle the case where a locale already exists and skip it
|
|
148
|
+
if ((0, object_1.get)(err, 'error.sys.id') === 'ValidationFailed') {
|
|
149
|
+
const errors = (0, object_1.get)(err, 'error.details.errors');
|
|
150
|
+
if (errors && errors.length > 0 && errors[0].name === 'taken') {
|
|
151
|
+
return entity;
|
|
152
|
+
}
|
|
200
153
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
// No need to pass this entity down to publishing if it wasn't created
|
|
206
|
-
return null;
|
|
154
|
+
err.entity = entity.original;
|
|
155
|
+
logging_1.logEmitter.emit('error', err);
|
|
156
|
+
// No need to pass this entity down to publishing if it wasn't created
|
|
157
|
+
return null;
|
|
207
158
|
}
|
|
208
159
|
function cleanupUnknownFields(fields, errors) {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
160
|
+
return (0, object_1.omitBy)(fields, (field, fieldId) => {
|
|
161
|
+
return (0, collection_1.find)(errors, (error) => {
|
|
162
|
+
const [, errorFieldId] = error.path;
|
|
163
|
+
return error.name === 'unknown' && errorFieldId === fieldId;
|
|
164
|
+
});
|
|
213
165
|
});
|
|
214
|
-
});
|
|
215
166
|
}
|
|
216
167
|
function getDestinationEntityForSourceEntity(destinationEntitiesById, sourceEntity) {
|
|
217
|
-
|
|
168
|
+
return destinationEntitiesById.get((0, object_1.get)(sourceEntity, 'sys.id')) || null;
|
|
218
169
|
}
|
|
219
170
|
function creationSuccessNotifier(method, createdEntity) {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
171
|
+
const verb = method[0].toUpperCase() + method.substr(1, method.length) + 'd';
|
|
172
|
+
logging_1.logEmitter.emit('info', `${verb} ${createdEntity.sys.type} ${(0, get_entity_name_1.default)(createdEntity)}`);
|
|
173
|
+
return createdEntity;
|
|
223
174
|
}
|
|
224
175
|
function getPlainData(entity) {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
}
|
|
176
|
+
const data = entity.toPlainObject ? entity.toPlainObject() : entity;
|
|
177
|
+
return (0, object_1.omit)(data, 'sys');
|
|
178
|
+
}
|
|
@@ -1,100 +1,100 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
exports.archiveEntities =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var _logging = require("contentful-batch-libs/dist/logging");
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.archiveEntities = exports.publishEntities = void 0;
|
|
7
|
+
const get_entity_name_1 = __importDefault(require("contentful-batch-libs/dist/get-entity-name"));
|
|
8
|
+
const logging_1 = require("contentful-batch-libs/dist/logging");
|
|
11
9
|
/**
|
|
12
10
|
* Publish a list of entities.
|
|
13
11
|
* Does not return a rejected promise in the case of an error, pushing it
|
|
14
12
|
* to an error buffer instead.
|
|
15
13
|
*/
|
|
16
|
-
async function publishEntities({
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
14
|
+
async function publishEntities({ entities, requestQueue }) {
|
|
15
|
+
const entitiesToPublish = entities.filter((entity) => {
|
|
16
|
+
if (!entity || !entity.publish) {
|
|
17
|
+
logging_1.logEmitter.emit('warning', `Unable to publish ${(0, get_entity_name_1.default)(entity)}`);
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
return true;
|
|
21
|
+
});
|
|
22
|
+
if (entitiesToPublish.length === 0) {
|
|
23
|
+
logging_1.logEmitter.emit('info', 'Skipping publishing since zero valid entities passed');
|
|
24
|
+
return [];
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const entity = entities[0].original || entities[0];
|
|
32
|
-
const type = entity.sys.type || 'unknown type';
|
|
33
|
-
_logging.logEmitter.emit('info', `Publishing ${entities.length} ${type}s`);
|
|
34
|
-
const result = await runQueue(entitiesToPublish, [], requestQueue);
|
|
35
|
-
_logging.logEmitter.emit('info', `Successfully published ${result.length} ${type}s`);
|
|
36
|
-
return result;
|
|
26
|
+
const entity = entities[0].original || entities[0];
|
|
27
|
+
const type = entity.sys.type || 'unknown type';
|
|
28
|
+
logging_1.logEmitter.emit('info', `Publishing ${entities.length} ${type}s`);
|
|
29
|
+
const result = await runQueue(entitiesToPublish, [], requestQueue);
|
|
30
|
+
logging_1.logEmitter.emit('info', `Successfully published ${result.length} ${type}s`);
|
|
31
|
+
return result;
|
|
37
32
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
33
|
+
exports.publishEntities = publishEntities;
|
|
34
|
+
async function archiveEntities({ entities, requestQueue }) {
|
|
35
|
+
const entitiesToArchive = entities.filter((entity) => {
|
|
36
|
+
if (!entity || !entity.archive) {
|
|
37
|
+
logging_1.logEmitter.emit('warning', `Unable to archive ${(0, get_entity_name_1.default)(entity)}`);
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
return true;
|
|
41
|
+
});
|
|
42
|
+
if (entitiesToArchive.length === 0) {
|
|
43
|
+
logging_1.logEmitter.emit('info', 'Skipping archiving since zero valid entities passed');
|
|
44
|
+
return [];
|
|
46
45
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
err.entity = entity;
|
|
63
|
-
_logging.logEmitter.emit('error', err);
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
46
|
+
const entity = entities[0].original || entities[0];
|
|
47
|
+
const type = entity.sys.type || 'unknown type';
|
|
48
|
+
logging_1.logEmitter.emit('info', `Archiving ${entities.length} ${type}s`);
|
|
49
|
+
const pendingArchivedEntities = entitiesToArchive.map((entity) => {
|
|
50
|
+
return requestQueue.add(async () => {
|
|
51
|
+
try {
|
|
52
|
+
const archivedEntity = await entity.archive();
|
|
53
|
+
return archivedEntity;
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
err.entity = entity;
|
|
57
|
+
logging_1.logEmitter.emit('error', err);
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
66
61
|
});
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return allArchivedEntities;
|
|
62
|
+
const allPossiblyArchivedEntities = await Promise.all(pendingArchivedEntities);
|
|
63
|
+
const allArchivedEntities = allPossiblyArchivedEntities.filter((entity) => entity);
|
|
64
|
+
logging_1.logEmitter.emit('info', `Successfully archived ${allArchivedEntities.length} ${type}s`);
|
|
65
|
+
return allArchivedEntities;
|
|
72
66
|
}
|
|
67
|
+
exports.archiveEntities = archiveEntities;
|
|
73
68
|
async function runQueue(queue, result = [], requestQueue) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
69
|
+
const publishedEntities = [];
|
|
70
|
+
for (const entity of queue) {
|
|
71
|
+
logging_1.logEmitter.emit('info', `Publishing ${entity.sys.type} ${(0, get_entity_name_1.default)(entity)}`);
|
|
72
|
+
try {
|
|
73
|
+
const publishedEntity = await requestQueue.add(() => entity.publish());
|
|
74
|
+
publishedEntities.push(publishedEntity);
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
err.entity = entity;
|
|
78
|
+
logging_1.logEmitter.emit('error', err);
|
|
79
|
+
}
|
|
83
80
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
81
|
+
result = [
|
|
82
|
+
...result,
|
|
83
|
+
...publishedEntities
|
|
84
|
+
];
|
|
85
|
+
const publishedEntityIds = new Set(publishedEntities.map((entity) => entity.sys.id));
|
|
86
|
+
const unpublishedEntities = queue.filter((entity) => !publishedEntityIds.has(entity.sys.id));
|
|
87
|
+
if (unpublishedEntities.length > 0) {
|
|
88
|
+
if (queue.length === unpublishedEntities.length) {
|
|
89
|
+
// Fail when queue could not publish at least one item
|
|
90
|
+
const unpublishedEntityNames = unpublishedEntities.map(get_entity_name_1.default).join(', ');
|
|
91
|
+
logging_1.logEmitter.emit('error', `Could not publish the following entities: ${unpublishedEntityNames}`);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
// Rerun queue with unpublished entities
|
|
95
|
+
return runQueue(unpublishedEntities, result, requestQueue);
|
|
96
|
+
}
|
|
96
97
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
98
|
+
// Return only published entities + last result
|
|
99
|
+
return result;
|
|
100
|
+
}
|