diff --git a/src/Migration.ts b/src/Migration.ts index 0f70372d..0d673441 100644 --- a/src/Migration.ts +++ b/src/Migration.ts @@ -63,12 +63,14 @@ export class Migration { * * @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 + * 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 @@ -78,13 +80,15 @@ export class Migration { * * @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 + * 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, @@ -95,7 +99,7 @@ export class Migration { * * @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 + * 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. @@ -121,7 +125,7 @@ export class Migration { * * @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 + * Instead, it registers it in your migration. The asset will be created when * the migration is executed through the `writeClient.migrate()` method. * * @returns A migration asset field instance. @@ -227,7 +231,7 @@ export class Migration { * Registers a document to be created in the migration. * * @remarks - * This method does not create the document in Prismic right away. Instead it + * 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. * @@ -236,20 +240,20 @@ export class Migration { * @param document - The document to create. * @param title - The title of the document to create which will be displayed * in the editor. - * @param options - Document master language document ID. + * @param params - Document master language document ID. * * @returns A migration document instance. */ createDocument( document: ExtractDocumentType, TType>, title: string, - options?: { + params?: { masterLanguageDocument?: MigrationContentRelationship }, ): PrismicMigrationDocument> { const doc = new PrismicMigrationDocument< ExtractDocumentType - >(document, title, options) + >(document, title, params) this._documents.push(doc) @@ -260,21 +264,22 @@ export class Migration { * Registers an existing document to be updated in the migration. * * @remarks - * This method does not update the document in Prismic right away. Instead it + * 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 documentTitle - The title of the document to update which will be - * displayed in the editor. + * @param title - The title of the document to update which will be displayed + * in the editor. * * @returns A migration document instance. */ updateDocument( document: ExtractDocumentType, TType>, - title: string, + // Title is optional for existing documents as we might not want to update it. + title?: string, ): PrismicMigrationDocument> { const doc = new PrismicMigrationDocument< ExtractDocumentType @@ -286,17 +291,17 @@ export class Migration { } /** - * Registers a document to be created in the migration. + * 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 + * 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 to create. + * @param document - The document from Prismic to create. * @param title - The title of the document to create which will be displayed * in the editor. - * @param options - Document master language document ID. * * @returns A migration document instance. */ @@ -413,7 +418,7 @@ export class Migration { return { link_type: LinkType.Document, - id: () => this.getByOriginalID(input.id), + id: () => this._getByOriginalID(input.id), // TODO: Remove when link text PR is merged // @ts-expect-error - Future-proofing for link text text: input.text, @@ -497,7 +502,7 @@ export class Migration { * * ```ts * const contentRelationship = migration.createContentRelationship(() => - * migration.getByOriginalID("YhdrDxIAACgAcp_b"), + * migration._getByOriginalID("YhdrDxIAACgAcp_b"), * ) * ``` * @@ -507,8 +512,10 @@ export class Migration { * * @returns The migration document instance for the original ID, if a matching * document is found. + * + * @internal */ - getByOriginalID( + _getByOriginalID( id: string, ): | PrismicMigrationDocument> diff --git a/src/WriteClient.ts b/src/WriteClient.ts index 1d642db2..0c689032 100644 --- a/src/WriteClient.ts +++ b/src/WriteClient.ts @@ -447,14 +447,14 @@ export class WriteClient< if (maybeOriginalID) { masterLanguageDocumentID = - migration.getByOriginalID(maybeOriginalID)?.document.id + migration._getByOriginalID(maybeOriginalID)?.document.id } } const { id } = await this.createDocument( // We'll upload docuements data later on. { ...doc.document, data: {} }, - doc.title, + doc.title!, { masterLanguageDocumentID, ...fetchParams, diff --git a/src/types/migration/Document.ts b/src/types/migration/Document.ts index 45d0a007..3bcfddf3 100644 --- a/src/types/migration/Document.ts +++ b/src/types/migration/Document.ts @@ -103,7 +103,7 @@ export class PrismicMigrationDocument< /** * The name of the document displayed in the editor. */ - title: string + title?: string /** * The link to the master language document to relate the document to if any. @@ -126,22 +126,22 @@ export class PrismicMigrationDocument< * * @param document - The document to be sent to the Migration API. * @param title - The name of the document displayed in the editor. - * @param options - Parameters to create/update the document with on the + * @param params - Parameters to create/update the document with on the * Migration API. * * @returns A Prismic migration document instance. */ constructor( document: MigrationDocument, - title: string, - options?: { + title?: string, + params?: { masterLanguageDocument?: MigrationContentRelationship originalPrismicDocument?: ExistingPrismicDocument }, ) { this.document = document this.title = title - this.masterLanguageDocument = options?.masterLanguageDocument - this.originalPrismicDocument = options?.originalPrismicDocument + this.masterLanguageDocument = params?.masterLanguageDocument + this.originalPrismicDocument = params?.originalPrismicDocument } }