@umbraco/json-models-builders
Version:
Builders and models for Umbraco Sites
112 lines (111 loc) • 3.14 kB
TypeScript
/**
* Utility functions for builder classes to reduce code duplication.
* These functions are designed to be called from within builder methods
* without changing the builder's external API.
*/
/**
* Ensures an ID/key field is set, generating a UUID if not provided.
* Uses consistent null-check pattern across all builders.
*
* @param currentValue - The current value of the id/key field
* @returns The existing value if set, or a new UUID
*/
export declare function ensureIdExists(currentValue: string | undefined | null): string;
/**
* Builds a property validation object with consistent defaults.
* Uses null as the standard default for optional message fields.
*
* @param validation - Object containing validation properties
* @returns Standardized validation object
*/
export declare function buildValidation(validation: {
mandatory?: boolean;
mandatoryMessage?: string;
regEx?: string;
regExMessage?: string;
}): {
mandatory: boolean;
mandatoryMessage: string | null;
regEx: string | null;
regExMessage: string | null;
};
/**
* Builds a container object with consistent defaults.
*
* @param container - Object containing container properties
* @returns Standardized container object
*/
export declare function buildContainer(container: {
id?: string;
parentId?: string;
name?: string;
type?: string;
sortOrder?: number;
}): {
id: string | null;
parent: {
id: string;
} | null;
name: string;
type: string;
sortOrder: number;
};
/**
* Builds a property object for content type builders with consistent defaults.
*
* @param property - Object containing property definition
* @returns Standardized property object
*/
export declare function buildProperty(property: {
id: string;
containerId?: string;
sortOrder?: number;
alias?: string;
name?: string;
description?: string;
dataTypeId?: string;
variesByCulture?: boolean;
variesBySegment?: boolean;
mandatory?: boolean;
mandatoryMessage?: string;
regEx?: string;
regExMessage?: string;
labelOnTop?: boolean;
}): {
id: string;
container: {
id: string | null;
};
sortOrder: number;
alias: string;
name: string;
description: string;
dataType: {
id: string | null;
};
variesByCulture: boolean;
variesBySegment: boolean;
validation: {
mandatory: boolean;
mandatoryMessage: string | null;
regEx: string | null;
regExMessage: string | null;
};
appearance: {
labelOnTop: boolean;
};
};
/**
* Builds a composition reference object with consistent defaults.
*
* @param typeIdField - The field name for the type ID (e.g., 'documentType', 'mediaType', 'memberType')
* @param typeId - The ID value
* @param compositionType - The composition type string
* @returns Standardized composition object
*/
export declare function buildComposition(typeIdField: string, typeId: string | undefined, compositionType?: string): {
[key: string]: {
id: string | null;
} | string;
compositionType: string;
};