UNPKG

@umbraco/json-models-builders

Version:
165 lines 6.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DocumentTypeBuilder = void 0; const documentTypePropertyBuilder_1 = require("./documentTypePropertyBuilder"); const documentTypeContainerBuilder_1 = require("./documentTypeContainerBuilder"); const documentTypeAllowedDocumentTypeBuilder_1 = require("./documentTypeAllowedDocumentTypeBuilder"); const documentTypeCompositionBuilder_1 = require("./documentTypeCompositionBuilder"); const documentTypeAllowedTemplateBuilder_1 = require("./documentTypeAllowedTemplateBuilder"); const AliasHelper_1 = require("../../helpers/AliasHelper"); const BuilderUtils_1 = require("../../helpers/BuilderUtils"); class DocumentTypeBuilder { alias; name; description; icon; allowedAsRoot; variesByCulture; variesBySegment; collectionId; isElement; documentTypePropertyBuilder; documentTypeAllowedDocumentTypeBuilder; documentTypeAllowedTemplateBuilder; documentTypeCompositionBuilder; documentTypeContainerBuilder; id; folderId; defaultTemplateId; preventCleanup; keepAllVersionsNewerThanDays; keepLatestVersionPerDayForDays; allowedInLibrary; constructor() { this.documentTypePropertyBuilder = []; this.documentTypeAllowedDocumentTypeBuilder = []; this.documentTypeAllowedTemplateBuilder = []; this.documentTypeCompositionBuilder = []; this.documentTypeContainerBuilder = []; } withAlias(alias) { this.alias = alias; return this; } withName(name) { this.name = name; return this; } withDescription(description) { this.description = description; return this; } withIcon(icon) { this.icon = icon; return this; } withAllowedAsRoot(allowedAsRoot) { this.allowedAsRoot = allowedAsRoot; return this; } withVariesByCulture(variesByCulture) { this.variesByCulture = variesByCulture; return this; } withVariesBySegment(variesBySegment) { this.variesBySegment = variesBySegment; return this; } withIsElement(isElement) { this.isElement = isElement; return this; } addProperty() { const builder = new documentTypePropertyBuilder_1.DocumentTypePropertyBuilder(this); this.documentTypePropertyBuilder.push(builder); return builder; } addContainer() { const builder = new documentTypeContainerBuilder_1.DocumentTypeContainerBuilder(this); this.documentTypeContainerBuilder.push(builder); return builder; } addAllowedDocumentType() { const builder = new documentTypeAllowedDocumentTypeBuilder_1.DocumentTypeAllowedDocumentTypeBuilder(this); this.documentTypeAllowedDocumentTypeBuilder.push(builder); return builder; } addAllowedTemplateId() { const builder = new documentTypeAllowedTemplateBuilder_1.DocumentTypeAllowedTemplateBuilder(this); this.documentTypeAllowedTemplateBuilder.push(builder); return builder; } addComposition() { const builder = new documentTypeCompositionBuilder_1.DocumentTypeCompositionBuilder(this); this.documentTypeCompositionBuilder.push(builder); return builder; } withId(id) { this.id = id; return this; } withDefaultTemplateId(defaultTemplateId) { this.defaultTemplateId = defaultTemplateId; return this; } withPreventCleanup(preventCleanup) { this.preventCleanup = preventCleanup; return this; } withKeepAllVersionsNewerThanDays(keepAllVersionsNewerThanDays) { this.keepAllVersionsNewerThanDays = keepAllVersionsNewerThanDays; return this; } withKeepLatestVersionPerDayForDays(keepLatestVersionPerDayForDays) { this.keepLatestVersionPerDayForDays = keepLatestVersionPerDayForDays; return this; } withCollectionId(collectionId) { this.collectionId = collectionId; return this; } withAllowedInLibrary(allowedInLibrary) { this.allowedInLibrary = allowedInLibrary; return this; } build() { this.id = (0, BuilderUtils_1.ensureIdExists)(this.id); return { alias: this.alias || AliasHelper_1.AliasHelper.toAlias(this.name), name: this.name || '', description: this.description || '', icon: this.icon || 'icon-document', allowedAsRoot: this.allowedAsRoot || false, allowedInLibrary: this.allowedInLibrary || false, variesByCulture: this.variesByCulture || false, variesBySegment: this.variesBySegment || false, collection: this.collectionId ? { id: this.collectionId } : null, isElement: this.isElement || false, properties: this.documentTypePropertyBuilder.map((builder) => { return builder.build(); }) || [], containers: this.documentTypeContainerBuilder.map((builder) => { return builder.build(); }) || [], allowedDocumentTypes: this.documentTypeAllowedDocumentTypeBuilder.map((builder) => { return builder.build(); }) || [], compositions: this.documentTypeCompositionBuilder.map((builder) => { return builder.build(); }) || [], id: this.id, folder: this.folderId ? { id: this.folderId } : null, allowedTemplates: this.documentTypeAllowedTemplateBuilder.map((builder) => { return builder.build(); }) || [], defaultTemplate: this.defaultTemplateId ? { id: this.defaultTemplateId } : null, cleanup: { preventCleanup: this.preventCleanup || false, keepAllVersionsNewerThanDays: this.keepAllVersionsNewerThanDays || null, keepLatestVersionPerDayForDays: this.keepLatestVersionPerDayForDays || null } }; } } exports.DocumentTypeBuilder = DocumentTypeBuilder; //# sourceMappingURL=documentTypeBuilder.js.map