@prismicio/client
Version:
The official JavaScript + TypeScript client library for Prismic
214 lines (213 loc) • 8.8 kB
TypeScript
import type { Asset } from "./types/api/asset/asset";
import type { MigrationAssetConfig } from "./types/migration/Asset";
import { PrismicMigrationAsset } from "./types/migration/Asset";
import type { MigrationContentRelationship } from "./types/migration/ContentRelationship";
import { PrismicMigrationDocument } from "./types/migration/Document";
import type { ExistingPrismicDocument, PendingPrismicDocument } from "./types/migration/Document";
import type { PrismicDocument } from "./types/value/document";
import type { FilledImageFieldImage } from "./types/value/image";
import type { FilledLinkToMediaField } from "./types/value/linkToMedia";
/**
* Extracts one or more Prismic document types that match a given Prismic
* document type. If no matches are found, no extraction is performed and the
* union of all provided Prismic document types are returned.
*
* @typeParam TDocuments - Prismic document types from which to extract.
* @typeParam TDocumentType - Type(s) to match `TDocuments` against.
*/
type ExtractDocumentType<TDocuments extends {
type: string;
}, TDocumentType extends TDocuments["type"]> = Extract<TDocuments, {
type: TDocumentType;
}> extends never ? TDocuments : Extract<TDocuments, {
type: TDocumentType;
}>;
/**
* A helper that allows preparing your migration to Prismic.
*
* @typeParam TDocuments - Document types that are registered for the Prismic
* repository. Query methods will automatically be typed based on this type.
*/
export declare class Migration<TDocuments extends PrismicDocument = PrismicDocument> {
#private;
/**
* Assets registered in the migration.
*
* @internal
*/
_assets: Map<MigrationAssetConfig["file"], PrismicMigrationAsset>;
/**
* Documents registered in the migration.
*
* @internal
*/
_documents: PrismicMigrationDocument<TDocuments>[];
/**
* Registers an asset to be created in the migration from an asset object.
*
* @remarks
* This method does not create the asset in Prismic media library right away.
* Instead, it registers it in your migration. The asset will be created when
* the migration is executed through the `writeClient.migrate()` method.
*
* @param asset - An asset object from Prismic Asset API.
*
* @returns A migration asset field instance.
*
* @internal
*/
createAsset(asset: Asset): PrismicMigrationAsset;
/**
* Registers an asset to be created in the migration from an image or link to
* media field.
*
* @remarks
* This method does not create the asset in Prismic media library right away.
* Instead, it registers it in your migration. The asset will be created when
* the migration is executed through the `writeClient.migrate()` method.
*
* @param imageOrLinkToMediaField - An image or link to media field from
* Prismic Document API.
*
* @returns A migration asset field instance.
*
* @internal
*/
createAsset(imageOrLinkToMediaField: FilledImageFieldImage | FilledLinkToMediaField): PrismicMigrationAsset;
/**
* Registers an asset to be created in the migration from a file.
*
* @remarks
* This method does not create the asset in Prismic media library right away.
* Instead, it registers it in your migration. The asset will be created when
* the migration is executed through the `writeClient.migrate()` method.
*
* @param file - The URL or content of the file to be created.
* @param filename - The filename of the asset.
* @param params - Additional asset data.
*
* @returns A migration asset field instance.
*/
createAsset(file: MigrationAssetConfig["file"], filename: MigrationAssetConfig["filename"], params?: {
notes?: string;
credits?: string;
alt?: string;
tags?: string[];
}): PrismicMigrationAsset;
/**
* Registers a document to be created in the migration.
*
* @remarks
* This method does not create the document in Prismic right away. Instead, it
* registers it in your migration. The document will be created when the
* migration is executed through the `writeClient.migrate()` method.
*
* @typeParam TType - Type of the Prismic document to create.
*
* @param document - The document to create.
* @param title - The title of the document to create which will be displayed
* in the editor.
* @param params - Document master language document ID.
*
* @returns A migration document instance.
*/
createDocument<TType extends TDocuments["type"]>(document: ExtractDocumentType<PendingPrismicDocument<TDocuments>, TType>, title: string, params?: {
masterLanguageDocument?: MigrationContentRelationship;
}): PrismicMigrationDocument<ExtractDocumentType<TDocuments, TType>>;
/**
* Registers an existing document to be updated in the migration.
*
* @remarks
* This method does not update the document in Prismic right away. Instead, it
* registers it in your migration. The document will be updated when the
* migration is executed through the `writeClient.migrate()` method.
*
* @typeParam TType - Type of Prismic documents to update.
*
* @param document - The document to update.
* @param title - The title of the document to update which will be displayed
* in the editor.
*
* @returns A migration document instance.
*/
updateDocument<TType extends TDocuments["type"]>(document: ExtractDocumentType<ExistingPrismicDocument<TDocuments>, TType>, title?: string): PrismicMigrationDocument<ExtractDocumentType<TDocuments, TType>>;
/**
* Registers a document from another Prismic repository to be created in the
* migration.
*
* @remarks
* This method does not create the document in Prismic right away. Instead, it
* registers it in your migration. The document will be created when the
* migration is executed through the `writeClient.migrate()` method.
*
* @param document - The document from Prismic to create.
* @param title - The title of the document to create which will be displayed
* in the editor.
*
* @returns A migration document instance.
*/
createDocumentFromPrismic<TType extends TDocuments["type"]>(document: ExtractDocumentType<ExistingPrismicDocument<TDocuments>, TType>, title: string): PrismicMigrationDocument<ExtractDocumentType<TDocuments, TType>>;
/**
* Queries a document from the migration instance with a specific UID and
* custom type.
*
* @example
*
* ```ts
* const contentRelationship = migration.createContentRelationship(() =>
* migration.getByUID("blog_post", "my-first-post"),
* )
* ```
*
* @typeParam TType - Type of the Prismic document returned.
*
* @param type - The API ID of the document's custom type.
* @param uid - The UID of the document.
*
* @returns The migration document instance with a UID matching the `uid`
* parameter, if a matching document is found.
*/
getByUID<TType extends TDocuments["type"]>(type: TType, uid: string): PrismicMigrationDocument<ExtractDocumentType<TDocuments, TType>> | undefined;
/**
* Queries a singleton document from the migration instance for a specific
* custom type.
*
* @example
*
* ```ts
* const contentRelationship = migration.createContentRelationship(() =>
* migration.getSingle("settings"),
* )
* ```
*
* @typeParam TType - Type of the Prismic document returned.
*
* @param type - The API ID of the singleton custom type.
*
* @returns The migration document instance for the custom type, if a matching
* document is found.
*/
getSingle<TType extends TDocuments["type"]>(type: TType): PrismicMigrationDocument<ExtractDocumentType<TDocuments, TType>> | undefined;
/**
* Queries a document from the migration instance for a specific original ID.
*
* @example
*
* ```ts
* const contentRelationship = migration.createContentRelationship(() =>
* migration._getByOriginalID("YhdrDxIAACgAcp_b"),
* )
* ```
*
* @typeParam TType - Type of the Prismic document returned.
*
* @param id - The original ID of the Prismic document.
*
* @returns The migration document instance for the original ID, if a matching
* document is found.
*
* @internal
*/
_getByOriginalID<TType extends TDocuments["type"]>(id: string): PrismicMigrationDocument<ExtractDocumentType<TDocuments, TType>> | undefined;
}
export {};