contentful-import 8.2.23 → 8.2.27

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.
@@ -1,163 +1,135 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.archiveEntities = exports.publishEntities = undefined;
6
+ exports.publishEntities = publishEntities;
7
+ exports.archiveEntities = archiveEntities;
8
+
9
+ var _getEntityName = require("contentful-batch-libs/dist/get-entity-name");
10
+
11
+ var _getEntityName2 = _interopRequireDefault(_getEntityName);
12
+
13
+ var _logging = require("contentful-batch-libs/dist/logging");
14
+
15
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
7
16
 
8
17
  /**
9
18
  * Publish a list of entities.
10
19
  * Does not return a rejected promise in the case of an error, pushing it
11
20
  * to an error buffer instead.
12
21
  */
13
- let publishEntities = exports.publishEntities = (() => {
14
- var _ref = _asyncToGenerator(function* ({ entities, requestQueue }) {
15
- const entitiesToPublish = entities.filter(function (entity) {
16
- if (!entity || !entity.publish) {
17
- _logging.logEmitter.emit('warning', `Unable to publish ${(0, _getEntityName2.default)(entity)}`);
18
- return false;
19
- }
20
- return true;
21
- });
22
-
23
- if (entitiesToPublish.length === 0) {
24
- _logging.logEmitter.emit('info', 'Skipping publishing since zero valid entities passed');
25
- return [];
22
+ async function publishEntities({
23
+ entities,
24
+ requestQueue
25
+ }) {
26
+ const entitiesToPublish = entities.filter(entity => {
27
+ if (!entity || !entity.publish) {
28
+ _logging.logEmitter.emit('warning', `Unable to publish ${(0, _getEntityName2.default)(entity)}`);
29
+
30
+ return false;
26
31
  }
27
32
 
28
- const entity = entities[0].original || entities[0];
29
- const type = entity.sys.type || 'unknown type';
30
- _logging.logEmitter.emit('info', `Publishing ${entities.length} ${type}s`);
31
-
32
- const result = yield runQueue(entitiesToPublish, [], requestQueue);
33
- _logging.logEmitter.emit('info', `Successfully published ${result.length} ${type}s`);
34
- return result;
33
+ return true;
35
34
  });
36
35
 
37
- return function publishEntities(_x) {
38
- return _ref.apply(this, arguments);
39
- };
40
- })();
41
-
42
- let archiveEntities = exports.archiveEntities = (() => {
43
- var _ref2 = _asyncToGenerator(function* ({ entities, requestQueue }) {
44
- const entitiesToArchive = entities.filter(function (entity) {
45
- if (!entity || !entity.archive) {
46
- _logging.logEmitter.emit('warning', `Unable to archive ${(0, _getEntityName2.default)(entity)}`);
47
- return false;
48
- }
49
- return true;
50
- });
36
+ if (entitiesToPublish.length === 0) {
37
+ _logging.logEmitter.emit('info', 'Skipping publishing since zero valid entities passed');
51
38
 
52
- if (entitiesToArchive.length === 0) {
53
- _logging.logEmitter.emit('info', 'Skipping archiving since zero valid entities passed');
54
- return [];
55
- }
39
+ return [];
40
+ }
56
41
 
57
- const entity = entities[0].original || entities[0];
58
- const type = entity.sys.type || 'unknown type';
59
- _logging.logEmitter.emit('info', `Archiving ${entities.length} ${type}s`);
60
-
61
- const pendingArchivedEntities = entitiesToArchive.map(function (entity) {
62
- return requestQueue.add(_asyncToGenerator(function* () {
63
- try {
64
- const archivedEntity = yield entity.archive();
65
- return archivedEntity;
66
- } catch (err) {
67
- err.entity = entity;
68
- _logging.logEmitter.emit('error', err);
69
- return null;
70
- }
71
- }));
72
- });
42
+ const entity = entities[0].original || entities[0];
43
+ const type = entity.sys.type || 'unknown type';
73
44
 
74
- const allPossiblyArchivedEntities = yield Promise.all(pendingArchivedEntities);
75
- const allArchivedEntities = allPossiblyArchivedEntities.filter(function (entity) {
76
- return entity;
77
- });
45
+ _logging.logEmitter.emit('info', `Publishing ${entities.length} ${type}s`);
46
+
47
+ const result = await runQueue(entitiesToPublish, [], requestQueue);
78
48
 
79
- _logging.logEmitter.emit('info', `Successfully archived ${allArchivedEntities.length} ${type}s`);
49
+ _logging.logEmitter.emit('info', `Successfully published ${result.length} ${type}s`);
80
50
 
81
- return allArchivedEntities;
51
+ return result;
52
+ }
53
+
54
+ async function archiveEntities({
55
+ entities,
56
+ requestQueue
57
+ }) {
58
+ const entitiesToArchive = entities.filter(entity => {
59
+ if (!entity || !entity.archive) {
60
+ _logging.logEmitter.emit('warning', `Unable to archive ${(0, _getEntityName2.default)(entity)}`);
61
+
62
+ return false;
63
+ }
64
+
65
+ return true;
82
66
  });
83
67
 
84
- return function archiveEntities(_x2) {
85
- return _ref2.apply(this, arguments);
86
- };
87
- })();
68
+ if (entitiesToArchive.length === 0) {
69
+ _logging.logEmitter.emit('info', 'Skipping archiving since zero valid entities passed');
88
70
 
89
- let runQueue = (() => {
90
- var _ref4 = _asyncToGenerator(function* (queue, result = [], requestQueue) {
91
- const publishedEntities = [];
71
+ return [];
72
+ }
92
73
 
93
- var _iteratorNormalCompletion = true;
94
- var _didIteratorError = false;
95
- var _iteratorError = undefined;
74
+ const entity = entities[0].original || entities[0];
75
+ const type = entity.sys.type || 'unknown type';
96
76
 
97
- try {
98
- for (var _iterator = queue[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
99
- const entity = _step.value;
100
-
101
- _logging.logEmitter.emit('info', `Publishing ${entity.sys.type} ${(0, _getEntityName2.default)(entity)}`);
102
- try {
103
- const publishedEntity = yield requestQueue.add(function () {
104
- return entity.publish();
105
- });
106
- publishedEntities.push(publishedEntity);
107
- } catch (err) {
108
- err.entity = entity;
109
- _logging.logEmitter.emit('error', err);
110
- }
111
- }
112
- } catch (err) {
113
- _didIteratorError = true;
114
- _iteratorError = err;
115
- } finally {
116
- try {
117
- if (!_iteratorNormalCompletion && _iterator.return) {
118
- _iterator.return();
119
- }
120
- } finally {
121
- if (_didIteratorError) {
122
- throw _iteratorError;
123
- }
124
- }
125
- }
77
+ _logging.logEmitter.emit('info', `Archiving ${entities.length} ${type}s`);
126
78
 
127
- result = [...result, ...publishedEntities];
79
+ const pendingArchivedEntities = entitiesToArchive.map(entity => {
80
+ return requestQueue.add(async () => {
81
+ try {
82
+ const archivedEntity = await entity.archive();
83
+ return archivedEntity;
84
+ } catch (err) {
85
+ err.entity = entity;
128
86
 
129
- const publishedEntityIds = new Set(publishedEntities.map(function (entity) {
130
- return entity.sys.id;
131
- }));
132
- const unpublishedEntities = queue.filter(function (entity) {
133
- return !publishedEntityIds.has(entity.sys.id);
134
- });
87
+ _logging.logEmitter.emit('error', err);
135
88
 
136
- if (unpublishedEntities.length > 0) {
137
- if (queue.length === unpublishedEntities.length) {
138
- // Fail when queue could not publish at least one item
139
- const unpublishedEntityNames = unpublishedEntities.map(_getEntityName2.default).join(', ');
140
- _logging.logEmitter.emit('error', `Could not publish the following entities: ${unpublishedEntityNames}`);
141
- } else {
142
- // Rerun queue with unpublished entities
143
- return runQueue(unpublishedEntities, result, requestQueue);
89
+ return null;
144
90
  }
145
- }
146
- // Return only published entities + last result
147
- return result;
91
+ });
148
92
  });
93
+ const allPossiblyArchivedEntities = await Promise.all(pendingArchivedEntities);
94
+ const allArchivedEntities = allPossiblyArchivedEntities.filter(entity => entity);
149
95
 
150
- return function runQueue(_x3) {
151
- return _ref4.apply(this, arguments);
152
- };
153
- })();
96
+ _logging.logEmitter.emit('info', `Successfully archived ${allArchivedEntities.length} ${type}s`);
154
97
 
155
- var _getEntityName = require('contentful-batch-libs/dist/get-entity-name');
98
+ return allArchivedEntities;
99
+ }
156
100
 
157
- var _getEntityName2 = _interopRequireDefault(_getEntityName);
101
+ async function runQueue(queue, result = [], requestQueue) {
102
+ const publishedEntities = [];
158
103
 
159
- var _logging = require('contentful-batch-libs/dist/logging');
104
+ for (const entity of queue) {
105
+ _logging.logEmitter.emit('info', `Publishing ${entity.sys.type} ${(0, _getEntityName2.default)(entity)}`);
106
+
107
+ try {
108
+ const publishedEntity = await requestQueue.add(() => entity.publish());
109
+ publishedEntities.push(publishedEntity);
110
+ } catch (err) {
111
+ err.entity = entity;
112
+
113
+ _logging.logEmitter.emit('error', err);
114
+ }
115
+ }
116
+
117
+ result = [...result, ...publishedEntities];
118
+ const publishedEntityIds = new Set(publishedEntities.map(entity => entity.sys.id));
119
+ const unpublishedEntities = queue.filter(entity => !publishedEntityIds.has(entity.sys.id));
120
+
121
+ if (unpublishedEntities.length > 0) {
122
+ if (queue.length === unpublishedEntities.length) {
123
+ // Fail when queue could not publish at least one item
124
+ const unpublishedEntityNames = unpublishedEntities.map(_getEntityName2.default).join(', ');
125
+
126
+ _logging.logEmitter.emit('error', `Could not publish the following entities: ${unpublishedEntityNames}`);
127
+ } else {
128
+ // Rerun queue with unpublished entities
129
+ return runQueue(unpublishedEntities, result, requestQueue);
130
+ }
131
+ } // Return only published entities + last result
160
132
 
161
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
162
133
 
163
- function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
134
+ return result;
135
+ }