contentful-migration
Version:
Migration tooling for contentful
67 lines • 2.68 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.EntrySetTagsAction = void 0;
const action_1 = require("./action");
const _ = __importStar(require("lodash"));
class EntrySetTagsAction extends action_1.APIAction {
constructor(contentTypeId, fields, entryTransformationForTags) {
super();
this.contentTypeId = contentTypeId;
this.fields = fields;
this.setTagsForEntry = entryTransformationForTags;
}
async applyTo(api) {
// TODO: Refactor currently confusing naming!
const entries = await api.getEntriesForContentType(this.contentTypeId);
const tags = await api.getTagsForEnvironment();
const apiTags = [...tags.keys()].map((tagId) => {
return { sys: { id: tagId, type: 'Link', linkType: 'Tag' } };
});
for (const entry of entries) {
const entryFields = _.pick(entry.fields, this.fields);
const entryTags = entry.tags;
let changesForThisEntry = false;
let outputs;
try {
outputs = await this.setTagsForEntry(entryFields, entryTags, apiTags);
}
catch (err) {
await api.recordRuntimeError(err);
continue;
}
if (outputs === undefined) {
continue;
}
changesForThisEntry = true;
entry.tags = outputs;
if (changesForThisEntry) {
await api.saveEntry(entry.id);
}
}
}
}
exports.EntrySetTagsAction = EntrySetTagsAction;
//# sourceMappingURL=entry-set-tags.js.map