@contentstack/cli-variants
Version:
Variants plugin
99 lines (98 loc) • 6.1 kB
TypeScript
import VariantAdapter, { VariantHttpClient } from '../utils/variant-api-adapter';
import { ImportConfig, ContentTypeStruct, VariantEntryStruct, ImportHelperMethodsConfig, EntryDataForVariantEntries } from '../types';
export default class VariantEntries extends VariantAdapter<VariantHttpClient<ImportConfig>> {
readonly config: ImportConfig & {
helpers?: ImportHelperMethodsConfig;
};
entriesDirPath: string;
entriesMapperPath: string;
variantEntryBasePath: string;
variantIdList: Record<string, unknown>;
personalizeConfig: ImportConfig['modules']['personalize'];
taxonomies: Record<string, unknown>;
assetUrlMapper: Record<string, any>;
assetUidMapper: Record<string, any>;
entriesUidMapper: Record<string, any>;
private installedExtensions;
private failedVariantPath;
private failedVariantEntries;
private environments;
constructor(config: ImportConfig & {
helpers?: ImportHelperMethodsConfig;
});
/**
* This TypeScript function asynchronously imports backupDir from a JSON file and processes the entries
* for variant entries.
* @returns If the file at the specified file path exists and contains backupDir, the function will parse
* the JSON backupDir and iterate over each entry to import variant entries using the
* `importVariantEntries` method. If the `entriesForVariants` array is empty, the function will log a
* message indicating that no entries were found and return.
*/
import(): Promise<void>;
/**
* The function `importVariantEntries` asynchronously imports variant entries using file system
* utility in TypeScript.
* @param {EntryDataForVariantEntries} entriesForVariant - EntryDataForVariantEntries {
*/
importVariantEntries(entriesForVariant: EntryDataForVariantEntries): Promise<void>;
/**
* The function `handleConcurrency` processes variant entries in batches with a specified concurrency
* level and handles API calls for creating variant entries.
* @param {VariantEntryStruct[]} variantEntries - The `variantEntries` parameter is an array of
* `VariantEntryStruct` objects. It seems like this function is handling concurrency for processing
* these entries in batches. The function chunks the `variantEntries` array into smaller batches and
* then processes each batch asynchronously using `Promise.allSettled`. It also
* @param {EntryDataForVariantEntries} entriesForVariant - The `entriesForVariant` parameter seems to
* be an object containing the following properties:
* @returns The `handleConcurrency` function processes variant entries in batches, creating variant
* entries using the `createVariantEntry` method and handling the API response using
* `Promise.allSettled`. The function also includes logic to handle variant IDs and delays between
* batch processing.
*/
handleConcurrency(contentType: ContentTypeStruct, variantEntries: VariantEntryStruct[], entriesForVariant: EntryDataForVariantEntries): Promise<void>;
/**
* Serializes the change set of a entry variant.
* @param variantEntry - The entry variant to serialize.
* @returns The serialized change set as a record.
*/
serializeChangeSet(variantEntry: VariantEntryStruct): Record<string, any>;
/**
* The function `handleVariantEntryRelationalData` processes relational data for a entry variant
* based on the provided content type and configuration helpers.
* @param {ContentTypeStruct} contentType - The `contentType` parameter in the
* `handleVariantEntryRelationalData` function is of type `ContentTypeStruct`. It is used to define
* the structure of the content type being processed within the function. This parameter likely
* contains information about the schema and configuration of the content type.
* @param {VariantEntryStruct} variantEntry - The `variantEntry` parameter in the
* `handleVariantEntryRelationalData` function is a data structure that represents a entry variant.
* It is of type `VariantEntryStruct` and contains information related to a specific entry variant.
* This function is responsible for performing various operations on the `variantEntry`
* @returns The function `handleVariantEntryRelationalData` returns the `variantEntry` after
* performing various lookups and replacements on it based on the provided `contentType` and
* `config.helpers`.
*/
handleVariantEntryRelationalData(contentType: ContentTypeStruct, variantEntry: VariantEntryStruct): VariantEntryStruct;
/**
* Updates the file fields of a entry variant to support lookup asset logic.
* Lookup asset expects file fields to be an object instead of a string. So here we are updating the file fields to be an object. Object has two keys: `uid` and `filename`. `uid` is the asset UID and `filename` is the name of the file. Used a dummy value for the filename. This is a temporary fix and will be updated in the future.
* @param variantEntry - The entry variant to update.
*/
updateFileFields(variantEntry: VariantEntryStruct): void;
/**
* Publishes variant entries in batch for a given entry UID and content type.
* @param batch - An array of VariantEntryStruct objects representing the variant entries to be published.
* @param entryUid - The UID of the entry for which the variant entries are being published.
* @param content_type - The UID of the content type of the entry.
* @returns A Promise that resolves when all variant entries have been published.
*/
publishVariantEntries(batch: VariantEntryStruct[], entryUid: string, content_type: string): Promise<void>;
/**
* Serializes the publish entries of a variant.
* @param variantEntry - The entry variant to serialize.
* @returns An object containing the serialized publish entries.
*/
serializePublishEntries(variantEntry: VariantEntryStruct): {
environments: Array<string>;
locales: Array<string>;
};
}